1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-07-12 21:10:02 -04:00
commit 794b5a232f
3099 changed files with 238212 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
public class IoEngineFxt {
IoEngine EngineOf(Io_url url) {return IoEnginePool._.Get_by(url.Info().EngineKey());}
public void tst_ExistsPaths(boolean expd, Io_url... ary) {
for (Io_url fil : ary) {
if (fil.Type_dir())
Tfds.Eq(expd, EngineOf(fil).ExistsDir(fil), "ExistsDir failed; dir={0}", fil);
else
Tfds.Eq(expd, EngineOf(fil).ExistsFil_api(fil), "ExistsFil failed; fil={0}", fil);
}
}
public void tst_LoadFilStr(Io_url fil, String expd) {Tfds.Eq(expd, EngineOf(fil).LoadFilStr(IoEngine_xrg_loadFilStr.new_(fil)));}
public void run_SaveFilText(Io_url fil, String expd) {EngineOf(fil).SaveFilText_api(IoEngine_xrg_saveFilStr.new_(fil, expd));}
public void run_UpdateFilModifiedTime(Io_url fil, DateAdp modifiedTime) {EngineOf(fil).UpdateFilModifiedTime(fil, modifiedTime);}
public void tst_QueryFilReadOnly(Io_url fil, boolean expd) {Tfds.Eq(expd, EngineOf(fil).QueryFil(fil).ReadOnly());}
public IoEngineFxt tst_QueryFil_size(Io_url fil, long expd) {Tfds.Eq(expd, EngineOf(fil).QueryFil(fil).Size()); return this;}
public IoEngineFxt tst_QueryFil_modifiedTime(Io_url fil, DateAdp expd) {Tfds.Eq_date(expd, EngineOf(fil).QueryFil(fil).ModifiedTime()); return this;}
public IoItmDir tst_ScanDir(Io_url dir, Io_url... expd) {
IoItmDir dirItem = EngineOf(dir).QueryDir(dir);
Io_url[] actl = new Io_url[dirItem.SubDirs().Count() + dirItem.SubFils().Count()];
for (int i = 0; i < dirItem.SubDirs().Count(); i++) {
IoItmDir subDir = IoItmDir_.as_(dirItem.SubDirs().Get_at(i));
actl[i] = subDir.Url();
}
for (int i = 0; i < dirItem.SubFils().Count(); i++) {
IoItmFil subFil = IoItmFil_.as_(dirItem.SubFils().Get_at(i));
actl[i + dirItem.SubDirs().Count()] = subFil.Url();
}
Tfds.Eq_ary_str(expd, actl);
return dirItem;
}
public static IoEngineFxt new_() {
IoEngineFxt rv = new IoEngineFxt();
return rv;
}
public IoEngineFxt() {}
}

View File

@@ -0,0 +1,79 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public abstract class IoEngine_dir_basic_base {
@Before public void setup() {
engine = engine_();
fx = IoEngineFxt.new_();
setup_hook();
} protected IoEngine engine; @gplx.Internal protected IoEngineFxt fx; protected Io_url fil, root;
protected abstract IoEngine engine_();
protected abstract void setup_hook();
@Test @gplx.Virtual public void CreateDir() {
fx.tst_ExistsPaths(false, root);
engine.CreateDir(root);
fx.tst_ExistsPaths(true, root);
}
@Test public void DeleteDir() {
engine.CreateDir(root);
fx.tst_ExistsPaths(true, root);
engine.DeleteDir(root);
fx.tst_ExistsPaths(false, root);
}
@Test public void CreateDir_createAllOwners() {
Io_url subDir = root.GenSubDir_nest("sub1");
fx.tst_ExistsPaths(false, subDir, subDir.OwnerDir());
engine.CreateDir(subDir);
fx.tst_ExistsPaths(true, subDir, subDir.OwnerDir());
}
// @Test public void DeleteDir_missing_fail() {
// try {engine.DeleteDir(root);}
// catch {return;}
// Tfds.Fail_expdError();
// }
@Test public void DeleteDir_missing_pass() {
engine.DeleteDir(root);
}
@Test @gplx.Virtual public void ScanDir() {
Io_url fil = root.GenSubFil("fil1.txt"); fx.run_SaveFilText(fil, "test");
Io_url dir1 = root.GenSubDir_nest("dir1"); engine.CreateDir(dir1);
Io_url dir1_1 = dir1.GenSubDir_nest("dir1_1"); engine.CreateDir(dir1_1); // NOTE: QueryDir should not recurse by default; dir1_1 should not be returned below
fx.tst_ScanDir(root, dir1, fil);
}
@Test public void MoveDir() {
Io_url src = root.GenSubDir_nest("src"), trg = root.GenSubDir_nest("trg");
engine.CreateDir(src);
fx.tst_ExistsPaths(true, src); fx.tst_ExistsPaths(false, trg);
engine.MoveDir(src, trg);
fx.tst_ExistsPaths(false, src); fx.tst_ExistsPaths(true, trg);
}
@Test @gplx.Virtual public void CopyDir() {
Io_url src = root.GenSubDir_nest("src"), trg = root.GenSubDir_nest("trg");
engine.CreateDir(src);
fx.tst_ExistsPaths(true, src); fx.tst_ExistsPaths(false, trg);
engine.CopyDir(src, trg);
fx.tst_ExistsPaths(true, src, trg);
}
}

View File

@@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoEngine_dir_basic_memory_tst extends IoEngine_dir_basic_base {
@Override protected void setup_hook() {
root = Io_url_.mem_dir_("mem");
} @Override protected IoEngine engine_() {return IoEngine_.Mem_init_();}
}

View File

@@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoEngine_dir_basic_system_tst extends IoEngine_dir_basic_base {
@Override protected void setup_hook() {
root = Tfds.RscDir.GenSubDir_nest("100_core", "ioEngineTest", "_temp");
IoEngine_xrg_deleteDir.new_(root).Recur_().ReadOnlyFails_off().Exec();
} @Override protected IoEngine engine_() {return IoEngine_system.new_();}
@Test @Override public void ScanDir() {
super.ScanDir();
}
}

View File

@@ -0,0 +1,126 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public abstract class IoEngine_dir_deep_base {
@Before public void setup() {
engine = engine_();
fx = IoEngineFxt.new_();
setup_hook();
setup_paths();
setup_objs();
} protected IoEngine engine; protected Io_url fil, root; @gplx.Internal protected IoEngineFxt fx;
protected abstract IoEngine engine_();
protected abstract void setup_hook();
@Test @gplx.Virtual public void SearchDir() {
Io_url[] expd = paths_(src_dir0a, src_fil0a, src_dir0a_dir0a, src_dir0a_fil0a);
Io_url[] actl = IoEngine_xrg_queryDir.new_(src).Recur_().DirInclude_().ExecAsUrlAry();
Tfds.Eq_ary(expd, actl);
}
@Test @gplx.Virtual public void MoveDirDeep() {
fx.tst_ExistsPaths(true, srcTree); fx.tst_ExistsPaths(false, trgTree);
engine.MoveDirDeep(IoEngine_xrg_xferDir.move_(src, trg).Recur_());
fx.tst_ExistsPaths(false, srcTree);
fx.tst_ExistsPaths(true, trgTree);
}
@Test @gplx.Virtual public void CopyDir() {
fx.tst_ExistsPaths(true, srcTree); fx.tst_ExistsPaths(false, trgTree);
engine.CopyDir(src, trg);
fx.tst_ExistsPaths(true, srcTree);
fx.tst_ExistsPaths(true, trgTree);
}
@Test @gplx.Virtual public void DeleteDir() {
fx.tst_ExistsPaths(true, srcTree);
engine.DeleteDirDeep(IoEngine_xrg_deleteDir.new_(src).Recur_());
fx.tst_ExistsPaths(false, srcTree);
}
// @Test public virtual void CopyDir_IgnoreExisting() {
// fx.tst_ExistsPaths(true, srcTree); fx.tst_ExistsPaths(false, trgTree);
// engine.SaveFilStr(trg_dir0a_fil0a, "x"); // NOTE: this file is different than src counterpart; should be overwritten by Copy
// fx.tst_ExistsPaths(true, trg_dir0a, trg_dir0a_fil0a);
//
// engine.CopyDir(src, trg);
// fx.tst_ExistsPaths(true, srcTree);
// fx.tst_ExistsPaths(true, trgTree);
// }
// @Test public virtual void CopyDir_IgnoreExistingReadOnlyFile() {
// fx.tst_ExistsPaths(true, srcTree); fx.tst_ExistsPaths(false, trgTree);
// engine.SaveFilStr(trg_fil0a, "x"); // NOTE: this file is different than src counterpart; should be overwritten by Copy
// fx.tst_ExistsPaths(true, trg_fil0a);
// engine.UpdateFilAttrib(trg_fil0a, IoItmAttrib.ReadOnlyFile);
//
// engine.CopyDir(src, trg);
// fx.tst_ExistsPaths(true, srcTree);
// fx.tst_ExistsPaths(true, trgTree);
// }
// @Test public void MoveDir_IgnoreExisting() {
// fx.tst_ExistsPaths(true, srcTree);
// fx.tst_ExistsPaths(false, trgTree);
// engine.SaveFilStr(trg_dir0a_fil0a, @"x"); // NOTE: this file is different than src counterpart; should be overwritten by Copy
// fx.tst_ExistsPaths(true, trg_dir0a, trg_dir0a_fil0a);
//
// engine.MoveDir(src, trg);
//
// fx.tst_ExistsPaths(true, srcTree);
// fx.tst_ExistsPaths(true, trgTree);
// }
// @Test public virtual void ProgressUi() {
// ConsoleDlg_dev dialog = ConsoleDlg_dev.new_();
// engine.SearchDir(src).Recur_().Prog_(dialog).ExecAsDir();
//
// Tfds.Eq(dialog.Written.Count, 3); // 3 levels
// tst_(dialog, 0, "scan", src);
// tst_(dialog, 1, "scan", src_dir0a);
// tst_(dialog, 2, "scan", src_dir0a_dir0a);
// }
// void tst_(ConsoleDlg_dev dialog, int i, String s, Io_url root) {
// Object o = dialog.Written.Get_at(i);
// IoStatusArgs args = (IoStatusArgs)o;
// Tfds.Eq(s, args.Op);
// Tfds.Eq(root, args.Path);
// }
protected Io_url src, src_dir0a, src_dir0a_dir0a;
Io_url src_fil0a, src_dir0a_fil0a;
protected Io_url trg, trg_dir0a, trg_dir0a_dir0a;
Io_url trg_fil0a, trg_dir0a_fil0a;
Io_url[] srcTree, trgTree;
Io_url[] paths_(Io_url... ary) {return ary;}
protected void setup_paths() {
src = root.GenSubDir_nest("src");
src_dir0a = root.GenSubDir_nest("src", "dir0a");
src_dir0a_dir0a = root.GenSubDir_nest("src", "dir0a", "dir0a");
src_fil0a = root.GenSubFil_nest("src", "fil0a.txt");
src_dir0a_fil0a = root.GenSubFil_nest("src", "dir0a", "fil0a.txt");
trg = root.GenSubDir_nest("trg");
trg_dir0a = root.GenSubDir_nest("trg", "dir0a");
trg_dir0a_dir0a = root.GenSubDir_nest("trg", "dir0a", "dir0a");
trg_fil0a = root.GenSubFil_nest("trg", "fil0a.txt");
trg_dir0a_fil0a = root.GenSubFil_nest("trg", "dir0a", "fil0a.txt");
srcTree = new Io_url[] {src, src_dir0a, src_dir0a_dir0a, src_fil0a, src_dir0a_fil0a};
trgTree = new Io_url[] {trg, trg_dir0a, trg_dir0a_dir0a, trg_fil0a, trg_dir0a_fil0a};
}
void setup_objs() {
fx.run_SaveFilText(src_fil0a, "src_fil0a"); // NOTE: automatically creates src
fx.run_SaveFilText(src_dir0a_fil0a, "src_dir0a_fil0a"); // NOTE: automatically creates src_dir0a_dir0a
fx.tst_ExistsPaths(true, src_fil0a);
engine.CreateDir(src_dir0a_dir0a);
}
}

View File

@@ -0,0 +1,36 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoEngine_dir_deep_memory_tst extends IoEngine_dir_deep_base {
@Override protected void setup_hook() {
root = Io_url_.mem_dir_("mem/root");
} @Override protected IoEngine engine_() {return IoEngine_.Mem_init_();}
@Test @Override public void SearchDir() {
super.SearchDir();
}
@Test @Override public void MoveDirDeep() {
super.MoveDirDeep();
}
@Test @Override public void CopyDir() {
super.CopyDir();
}
@Test @Override public void DeleteDir() {
super.DeleteDir();
}
}

View File

@@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoEngine_dir_deep_system_tst extends IoEngine_dir_deep_base {
@Override protected void setup_hook() {
root = Tfds.RscDir.GenSubDir_nest("100_core", "ioEngineTest", "_temp");
IoEngine_xrg_deleteDir.new_(root).Recur_().ReadOnlyFails_off().Exec();
} @Override protected IoEngine engine_() {return IoEngine_.Sys;}
}

View File

@@ -0,0 +1,176 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*; import gplx.texts.*;/*EncodingAdp_*/
public abstract class IoEngine_fil_basic_base {
@Before public void setup() {
engine = engine_();
fx = IoEngineFxt.new_();
setup_hook();
} protected IoEngine engine; protected IoEngineFxt fx; protected Io_url fil, root;
protected abstract IoEngine engine_();
protected abstract void setup_hook();
@Test @gplx.Virtual public void ExistsFil() {
fx.tst_ExistsPaths(false, fil);
}
@Test @gplx.Virtual public void ExistsFil_deep() {
fx.tst_ExistsPaths(false, root.GenSubFil_nest("dir1", "dir2", "fil1.txt"));
}
@Test @gplx.Virtual public void SaveFilStr() {
fx.tst_ExistsPaths(false, fil, fil.OwnerDir());
fx.run_SaveFilText(fil, "text");
fx.tst_ExistsPaths(true, fil, fil.OwnerDir());
}
@Test @gplx.Virtual public void SaveFilText_autoCreateOwnerDir() {
fil = fil.OwnerDir().GenSubFil_nest("sub1", "fil1.txt");
fx.tst_ExistsPaths(false, fil, fil.OwnerDir());
fx.run_SaveFilText(fil, "text");
fx.tst_ExistsPaths(true, fil, fil.OwnerDir());
}
@Test @gplx.Virtual public void SaveFilText_overwrite() {
fx.run_SaveFilText(fil, "text");
fx.tst_ExistsPaths(true, fil);
fx.run_SaveFilText(fil, "changed");
fx.tst_LoadFilStr(fil, "changed");
}
@Test @gplx.Virtual public void SaveFilText_append() {
fx.run_SaveFilText(fil, "text");
engine.SaveFilText_api(IoEngine_xrg_saveFilStr.new_(fil, "appended").Append_());
fx.tst_LoadFilStr(fil, "text" + "appended");
}
@Test @gplx.Virtual public void SaveFilText_caseInsensitive() {
if (root.Info().CaseSensitive()) return;
Io_url lcase = root.GenSubFil_nest("dir", "fil.txt");
Io_url ucase = root.GenSubFil_nest("DIR", "FIL.TXT");
fx.run_SaveFilText(lcase, "text");
fx.tst_ExistsPaths(true, lcase, ucase);
fx.tst_LoadFilStr(lcase, "text");
fx.tst_LoadFilStr(ucase, "text");
}
@Test @gplx.Virtual public void SaveFilText_readOnlyFails() {
fx.run_SaveFilText(fil, "text");
engine.UpdateFilAttrib(fil, IoItmAttrib.readOnly_());
try {fx.run_SaveFilText(fil, "changed");}
catch (Exception exc) {
fx.tst_LoadFilStr(fil, "text");
Exc_.Noop(exc);
return;
}
Tfds.Fail_expdError();
}
@Test @gplx.Virtual public void LoadFilStr() {
fx.run_SaveFilText(fil, "text");
fx.tst_LoadFilStr(fil, "text");
}
@Test @gplx.Virtual public void LoadFilStr_missingIgnored() {
Tfds.Eq("", engine.LoadFilStr(IoEngine_xrg_loadFilStr.new_(fil).MissingIgnored_()));
}
@Test @gplx.Virtual public void UpdateFilAttrib() {
fx.run_SaveFilText(fil, "text");
fx.tst_QueryFilReadOnly(fil, false);
engine.UpdateFilAttrib(fil, IoItmAttrib.readOnly_());
fx.tst_QueryFilReadOnly(fil, true);
}
@Test @gplx.Virtual public void DeleteFil() {
fx.run_SaveFilText(fil, "text");
fx.tst_ExistsPaths(true, fil);
engine.DeleteFil_api(IoEngine_xrg_deleteFil.new_(fil));
fx.tst_ExistsPaths(false, fil);
}
@Test @gplx.Virtual public void DeleteFil_missing_pass() {
fil = root.GenSubFil("fileThatDoesntExist.txt");
engine.DeleteFil_api(IoEngine_xrg_deleteFil.new_(fil).MissingFails_off());
fx.tst_ExistsPaths(false, fil);
}
@Test @gplx.Virtual public void DeleteFil_readOnly_fail() {
fx.run_SaveFilText(fil, "text");
engine.UpdateFilAttrib(fil, IoItmAttrib.readOnly_());
try {engine.DeleteFil_api(IoEngine_xrg_deleteFil.new_(fil));}
catch (Exception exc) {Exc_.Noop(exc);
fx.tst_ExistsPaths(true, fil);
return;
}
Tfds.Fail_expdError();
}
@Test @gplx.Virtual public void DeleteFil_readOnly_pass() {
fx.run_SaveFilText(fil, "text");
engine.UpdateFilAttrib(fil, IoItmAttrib.readOnly_());
engine.DeleteFil_api(IoEngine_xrg_deleteFil.new_(fil).ReadOnlyFails_off());
fx.tst_ExistsPaths(false, fil);
}
@Test @gplx.Virtual public void QueryFil_size() {
fx.run_SaveFilText(fil, "text");
fx.tst_QueryFil_size(fil, String_.Len("text"));
}
@Test @gplx.Virtual public void UpdateFilModifiedTime() {
fx.run_SaveFilText(fil, "text");
DateAdp time = Tfds.Now_time0_add_min(10);
engine.UpdateFilModifiedTime(fil, time);
fx.tst_QueryFil_modifiedTime(fil, time);
}
@Test @gplx.Virtual public void OpenStreamRead() {
fx.run_SaveFilText(fil, "text");
int textLen = String_.Len("text");
byte[] buffer = new byte[textLen];
IoStream stream = IoStream_.Null;
try {
stream = engine.OpenStreamRead(fil);
stream.Read(buffer, 0, textLen);
}
finally {stream.Rls();}
String actl = String_.new_u8(buffer);
Tfds.Eq("text", actl);
}
@Test @gplx.Virtual public void OpenStreamWrite() {
IoStream stream = IoEngine_xrg_openWrite.new_(fil).Exec();
byte[] buffer = Bry_.new_u8("text");
int textLen = String_.Len("text");
stream.Write(buffer, 0, textLen);
stream.Rls();
fx.tst_LoadFilStr(fil, "text");
}
// @Test public virtual void OpenStreamWrite_in_place() {
// byte[] buffer = Bry_.new_u8("a|b|c");
// IoStream stream = IoEngine_xrg_openWrite.new_(fil).Exec();
// stream.Write(buffer, 0, buffer.length);
// stream.Rls();
//
// buffer = Bry_.new_u8("B");
// stream = IoEngine_xrg_openWrite.new_(fil).Exec();
// stream.Seek(2);
// stream.Write(buffer, 0, buffer.length);
// stream.Rls();
//
// fx.tst_LoadFilStr(fil, "a|B|c");
// }
}

View File

@@ -0,0 +1,57 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoEngine_fil_basic_memory_tst extends IoEngine_fil_basic_base {
@Override protected IoEngine engine_() {return IoEngine_.Mem_init_();}
@Override protected void setup_hook() {
root = Io_url_.mem_dir_("mem");
fil = root.GenSubFil_nest("root", "fil.txt");
}
@Test @Override public void OpenStreamRead() {
super.OpenStreamRead ();
}
@Test @Override public void SaveFilText_overwrite() {
super.SaveFilText_overwrite();
// bugfix: verify changed file in ownerDir's hash
IoItmDir dirItm = fx.tst_ScanDir(fil.OwnerDir(), fil);
IoItmFil_mem filItm = (IoItmFil_mem)dirItm.SubFils().Get_at(0);
Tfds.Eq(filItm.Text(), "changed");
}
@Test public void RecycleFil() {
fx.run_SaveFilText(fil, "text");
fx.tst_ExistsPaths(true, fil);
IoRecycleBin bin = IoRecycleBin._;
List_adp list = Tfds.RscDir.XtoNames();
// foreach (String s in list)
// Tfds.Write(s);
list.Del_at(0); // remove drive
IoEngine_xrg_recycleFil recycleXrg = bin.Send_xrg(fil)
.RootDirNames_(list)
.AppName_("gplx.test").Time_(DateAdp_.parse_gplx("20100102_115559123")).Uuid_(Guid_adp_.parse_("467ffb41-cdfe-402f-b22b-be855425784b"));
recycleXrg.Exec();
fx.tst_ExistsPaths(false, fil);
fx.tst_ExistsPaths(true, recycleXrg.RecycleUrl());
bin.Recover(recycleXrg.RecycleUrl());
fx.tst_ExistsPaths(true, fil);
fx.tst_ExistsPaths(false, recycleXrg.RecycleUrl());
}
}

View File

@@ -0,0 +1,58 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoEngine_fil_basic_system_tst extends IoEngine_fil_basic_base {
@Override protected void setup_hook() {
root = Tfds.RscDir.GenSubDir_nest("100_core", "ioEngineTest", "_temp");
fil = root.GenSubFil("fil.txt");
IoEngine_xrg_deleteDir.new_(fil.OwnerDir()).Recur_().ReadOnlyFails_off().Exec();
} @Override protected IoEngine engine_() {return IoEngine_system.new_();}
@Test public void ExistsFil_IgnoreDifferentCasing() {
if (root.Info().CaseSensitive()) return;
fx.run_SaveFilText(fil, "text");
fx.tst_ExistsPaths(true, fil);
fx.tst_ExistsPaths(true, fil.OwnerDir().GenSubFil("FIL.txt"));
}
@Test @gplx.Virtual public void RecycleFil() {
fx.run_SaveFilText(fil, "text");
fx.tst_ExistsPaths(true, fil);
IoRecycleBin bin = IoRecycleBin._;
List_adp list = root.XtoNames(); list.Del_at(0); // remove drive
IoEngine_xrg_recycleFil recycleXrg = bin.Send_xrg(fil)
.RootDirNames_(list)
.AppName_("gplx.test").Time_(DateAdp_.parse_gplx("20100102_115559123")).Uuid_(Guid_adp_.parse_("467ffb41-cdfe-402f-b22b-be855425784b"));
recycleXrg.Exec();
fx.tst_ExistsPaths(false, fil);
fx.tst_ExistsPaths(true, recycleXrg.RecycleUrl());
bin.Recover(recycleXrg.RecycleUrl());
fx.tst_ExistsPaths(true, fil);
fx.tst_ExistsPaths(false, recycleXrg.RecycleUrl());
}
@Test @Override public void DeleteFil_missing_pass() {
super.DeleteFil_missing_pass();
}
@Test @Override public void DeleteFil_readOnly_pass() {
super.DeleteFil_readOnly_pass ();
}
@Test @Override public void SaveFilText_readOnlyFails() {
super.SaveFilText_readOnlyFails();
}
}

View File

@@ -0,0 +1,106 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public abstract class IoEngine_fil_xfer_base {
@Before public void setup() {
engine = engine_();
fx = IoEngineFxt.new_();
setup_hook();
src = root.GenSubFil("src.txt"); trg = root.GenSubFil("trg.txt");
} protected IoEngine engine; @gplx.Internal protected IoEngineFxt fx; protected Io_url src, trg, root;
DateAdp srcModifiedTime = DateAdp_.parse_gplx("2010.04.12 20.26.01.000"), trgModifiedTime = DateAdp_.parse_gplx("2010.04.01 01.01.01.000");
protected abstract IoEngine engine_();
protected abstract void setup_hook();
protected abstract Io_url AltRoot();
@Test @gplx.Virtual public void CopyFil() {
fx.run_SaveFilText(src, "src"); fx.run_UpdateFilModifiedTime(src, srcModifiedTime);
fx.tst_ExistsPaths(true, src);
fx.tst_ExistsPaths(false, trg);
IoEngine_xrg_xferFil.copy_(src, trg).Exec();
fx.tst_ExistsPaths(true, src, trg);
fx.tst_LoadFilStr(trg, "src");
fx.tst_QueryFil_modifiedTime(trg, srcModifiedTime);
}
@Test @gplx.Virtual public void CopyFil_overwrite_fail() {
fx.run_SaveFilText(src, "src");
fx.run_SaveFilText(trg, "trg");
try {IoEngine_xrg_xferFil.copy_(src, trg).Exec();}
catch (Exception exc) {Exc_.Noop(exc);
fx.tst_ExistsPaths(true, src, trg);
fx.tst_LoadFilStr(trg, "trg");
return;
}
Tfds.Fail_expdError();
}
@Test @gplx.Virtual public void CopyFil_overwrite_pass() {
fx.run_SaveFilText(src, "src"); fx.run_UpdateFilModifiedTime(src, srcModifiedTime);
fx.run_SaveFilText(trg, "trg"); fx.run_UpdateFilModifiedTime(trg, trgModifiedTime);
IoEngine_xrg_xferFil.copy_(src, trg).Overwrite_().Exec();
fx.tst_ExistsPaths(true, src, trg);
fx.tst_LoadFilStr(trg, "src");
fx.tst_QueryFil_modifiedTime(trg, srcModifiedTime);
}
@Test @gplx.Virtual public void MoveFil() {
fx.run_SaveFilText(src, "src");
fx.tst_ExistsPaths(true, src);
fx.tst_ExistsPaths(false, trg);
IoEngine_xrg_xferFil.move_(src, trg).Exec();
fx.tst_ExistsPaths(false, src);
fx.tst_ExistsPaths(true, trg);
}
@Test @gplx.Virtual public void MoveFil_overwrite_fail() {
fx.run_SaveFilText(src, "src");
fx.run_SaveFilText(trg, "trg");
try {IoEngine_xrg_xferFil.move_(src, trg).Exec();}
catch (Exception exc) {Exc_.Noop(exc);
fx.tst_ExistsPaths(true, src);
fx.tst_ExistsPaths(true, trg);
fx.tst_LoadFilStr(trg, "trg");
return;
}
Tfds.Fail_expdError();
}
@Test @gplx.Virtual public void MoveFil_overwrite_pass() {
fx.run_SaveFilText(src, "src"); fx.run_UpdateFilModifiedTime(src, srcModifiedTime);
fx.run_SaveFilText(trg, "trg"); fx.run_UpdateFilModifiedTime(trg, trgModifiedTime);
IoEngine_xrg_xferFil.move_(src, trg).Overwrite_().Exec();
fx.tst_ExistsPaths(false, src);
fx.tst_ExistsPaths(true, trg);
fx.tst_LoadFilStr(trg, "src");
fx.tst_QueryFil_modifiedTime(trg, srcModifiedTime);
}
@Test @gplx.Virtual public void MoveFil_betweenDrives() {
IoEngine_xrg_deleteDir.new_(AltRoot()).Recur_().ReadOnlyFails_off().Exec();
src = root.GenSubFil_nest("dir", "fil1a.txt");
trg = AltRoot().GenSubFil_nest("dir", "fil1b.txt");
fx.run_SaveFilText(src, "src");
fx.tst_ExistsPaths(true, src);
fx.tst_ExistsPaths(false, trg);
IoEngine_xrg_xferFil.move_(src, trg).Exec();
fx.tst_ExistsPaths(false, src);
fx.tst_ExistsPaths(true, trg);
}
}

View File

@@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoEngine_fil_xfer_memory_tst extends IoEngine_fil_xfer_base {
@Override protected void setup_hook() {
root = Io_url_.mem_dir_("mem");
} @Override protected IoEngine engine_() {return IoEngine_.Mem_init_();}
@Override protected Io_url AltRoot() {
Io_mgr.I.InitEngine_mem_("mem2");
return Io_url_.mem_dir_("mem2");
}
}

View File

@@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoEngine_fil_xfer_system_tst extends IoEngine_fil_xfer_base {
@Override protected void setup_hook() {
root = Tfds.RscDir.GenSubDir_nest("100_core", "ioEngineTest", "_temp");
IoEngine_xrg_deleteDir.new_(root.OwnerDir()).Recur_().ReadOnlyFails_off().Exec();
} @Override protected IoEngine engine_() {return IoEngine_system.new_();}
@Override protected Io_url AltRoot() {
return Tfds.RscDir.GenSubDir_nest("100_core", "ioEngineTest", "_temp");
}
}

View File

@@ -0,0 +1,49 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoEngine_stream_xfer_tst {
@Before public void setup() {
srcEngine = IoEngine_memory.new_("mock1");
trgEngine = IoEngine_memory.new_("mock2");
IoEnginePool._.Add_if_dupe_use_nth(srcEngine); IoEnginePool._.Add_if_dupe_use_nth(trgEngine);
IoUrlInfoRegy._.Reg(IoUrlInfo_.mem_("mem1/", srcEngine.Key()));
IoUrlInfoRegy._.Reg(IoUrlInfo_.mem_("mem2/", trgEngine.Key()));
srcDir = Io_url_.mem_dir_("mem1/dir"); trgDir = Io_url_.mem_dir_("mem2/dir");
}
@Test public void TransferBetween() {
Io_url srcPath = srcDir.GenSubFil("fil.txt");
Io_url trgPath = trgDir.GenSubFil("fil.txt");
tst_TransferStreams(srcEngine, srcPath, trgEngine, trgPath);
}
void tst_TransferStreams(IoEngine srcEngine, Io_url srcPath, IoEngine trgEngine, Io_url trgPath) {
srcEngine.SaveFilText_api(IoEngine_xrg_saveFilStr.new_(srcPath, "test1"));
trgEngine.DeleteFil_api(IoEngine_xrg_deleteFil.new_(trgPath)); // make sure file is deleted
fx.tst_ExistsPaths(true, srcPath);
fx.tst_ExistsPaths(false, trgPath);
IoEngineUtl utl = IoEngineUtl.new_();
utl.BufferLength_set(4);
utl.XferFil(srcEngine, IoEngine_xrg_xferFil.copy_(srcPath, trgPath));
fx.tst_ExistsPaths(true, srcPath, trgPath);
fx.tst_LoadFilStr(trgPath, "test1");
}
IoEngineFxt fx = IoEngineFxt.new_();
Io_url srcDir, trgDir;
IoEngine srcEngine, trgEngine;
}

View File

@@ -0,0 +1,65 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoEngine_xrg_queryDir_tst {
@Before public void setup() {
engine = IoEngine_.Mem_init_();
} IoEngine engine; Io_url[] ary;
@Test public void Basic() {
ary = save_text_(fil_("fil1.txt"));
tst_ExecPathAry(finder_(), ary);
}
@Test public void FilPath() {
ary = save_text_(fil_("fil1.txt"), fil_("fil2.jpg"), fil_("fil3.txt"));
tst_ExecPathAry(finder_(), ary); // default: all files
tst_ExecPathAry(finder_().FilPath_("*.txt") // findPattern of *.txt
, fil_("fil1.txt"), fil_("fil3.txt"));
}
@Test public void Recur() {
ary = save_text_(fil_("fil1.txt"), fil_("dirA", "fil1A.jpg"));
tst_ExecPathAry(finder_(), fil_("fil1.txt")); // default: no recursion
tst_ExecPathAry(finder_().Recur_(), ary); // recurse
}
@Test public void DirPattern() {
save_text_(fil_("fil1.txt"), fil_("dirA", "fil1A.jpg"));
tst_ExecPathAry(finder_(), fil_("fil1.txt")); // default: files only
tst_ExecPathAry(finder_().DirInclude_() // include dirs; NOTE: fil1A not returned b/c Recur_ is not true
, dir_("dirA"), fil_("fil1.txt"));
}
@Test public void Sort_by() {
save_text_(fil_("fil2a.txt"), fil_("fil1.txt"));
tst_ExecPathAry(finder_() // default: sortByAscOrder
, fil_("fil1.txt"), fil_("fil2a.txt"));
}
IoEngine_xrg_queryDir finder_() {return IoEngine_xrg_queryDir.new_(Io_url_.mem_dir_("mem/root"));}// NOTE: not in setup b/c finder must be newed several times inside test method
Io_url fil_(String... ary) {return Io_url_.mem_dir_("mem/root").GenSubFil_nest(ary);}
Io_url dir_(String... ary) {return Io_url_.mem_dir_("mem/root").GenSubDir_nest(ary);}
Io_url[] save_text_(Io_url... ary) {
for (Io_url url : ary)
Io_mgr.I.SaveFilStr(url, url.Raw());
return ary;
}
void tst_ExecPathAry(IoEngine_xrg_queryDir finder, Io_url... expd) {Tfds.Eq_ary(expd, finder.ExecAsUrlAry());}
}

View File

@@ -0,0 +1,32 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoEngine_xrg_recycleFil_tst {
@Before public void setup() {
IoEngine_.Mem_init_();
}
@Test public void GenRecycleUrl() {
tst_GenRecycleUrl(recycle_(), Io_url_.mem_fil_("mem/z_trash/20100102/gplx.images;115559123;;fil.txt"));
tst_GenRecycleUrl(recycle_().Uuid_include_(), Io_url_.mem_fil_("mem/z_trash/20100102/gplx.images;115559123;467ffb41-cdfe-402f-b22b-be855425784b;fil.txt"));
}
IoEngine_xrg_recycleFil recycle_() {return IoEngine_xrg_recycleFil.gplx_(Io_url_.mem_fil_("mem/dir/fil.txt")).AppName_("gplx.images").Uuid_(Guid_adp_.parse_("467ffb41-cdfe-402f-b22b-be855425784b")).Time_(DateAdp_.parse_gplx("20100102_115559123"));}
void tst_GenRecycleUrl(IoEngine_xrg_recycleFil xrg, Io_url expd) {
Tfds.Eq(expd, xrg.RecycleUrl());
}
}

View File

@@ -0,0 +1,40 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoItmDir_FetchDeepOrNull_tst {
@Before public void setup() {
drive = Io_url_.mem_dir_("mem");
rootDir = bldr.dir_(drive, bldr.dir_(drive.GenSubDir("sub1")));
} IoItm_fxt bldr = IoItm_fxt.new_(); Io_url drive; IoItmDir rootDir;
@Test public void FetchDeepOrNull() {
tst_FetchDeepOrNull(rootDir, drive.GenSubDir("sub1"), true);
tst_FetchDeepOrNull(rootDir, drive.GenSubDir("sub2"), false);
tst_FetchDeepOrNull(rootDir.SubDirs().Get_at(0), drive.GenSubDir("sub1"), true);
tst_FetchDeepOrNull(rootDir.SubDirs().Get_at(0), drive.GenSubDir("sub2"), false);
}
void tst_FetchDeepOrNull(Object rootDirObj, Io_url find, boolean expdFound) {
IoItmDir rootDir = IoItmDir_.as_(rootDirObj);
IoItmDir actlDir = rootDir.FetchDeepOrNull(find);
if (actlDir == null) {
if (expdFound) Tfds.Fail("actlDir is null, but expd dir to be found");
else return; // actlDir is null but expdFound was false; return;
}
Tfds.Eq(find.Raw(), actlDir.Url().Raw());
}
}

View File

@@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
public class IoItm_fxt {
public IoItmFil fil_wnt_(String s) {return fil_(Io_url_.wnt_fil_(s));}
public IoItmFil fil_(Io_url url) {return IoItmFil_.new_(url, 1, DateAdp_.parse_gplx("2001-01-01"), DateAdp_.parse_gplx("2001-01-01"));}
public IoItmDir dir_wnt_(String s) {return dir_(Io_url_.wnt_dir_(s));}
public IoItmDir dir_(Io_url url, IoItm_base... ary) {
IoItmDir rv = IoItmDir_.top_(url);
for (IoItm_base itm : ary) {
if (itm.Type_dir())
rv.SubDirs().Add(itm);
else
rv.SubFils().Add(itm);
}
return rv;
}
public static IoItm_fxt new_() {return new IoItm_fxt();} IoItm_fxt() {}
}

View File

@@ -0,0 +1,58 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoUrlInfo_alias_tst {
IoUrlInfo_alias alias;
@Test public void MapWntToWnt() {
Make("usr:\\", "D:\\usr\\");
tst_Xto_api("usr:\\dir\\fil.txt", "D:\\usr\\dir\\fil.txt");
tst_OwnerDir("usr:\\dir\\", "usr:\\");
tst_OwnerDir("usr:\\", "");
tst_NameOnly("usr:\\", "usr");
}
@Test public void MapToLnx() {
Make("usr:\\", "/home/");
tst_Xto_api("usr:\\dir\\fil.txt", "/home/dir/fil.txt");
}
@Test public void MapLnxToWnt() {
Make("usr:/", "C:\\usr\\");
tst_Xto_api("usr:/dir/fil.txt", "C:\\usr\\dir\\fil.txt");
}
@Test public void WntToWnt() {
Make("C:\\", "X:\\");
tst_Xto_api("C:\\dir\\fil.txt", "X:\\dir\\fil.txt");
tst_NameOnly("C:\\", "C");
}
@Test public void WntToLnx() {
Make("C:\\", "/home/");
tst_Xto_api("C:\\dir\\fil.txt", "/home/dir/fil.txt");
}
@Test public void LnxToWnt() {
Make("/home/", "C:\\");
tst_Xto_api("/home/dir/fil.txt", "C:\\dir\\fil.txt");
tst_NameOnly("/home/", "home");
tst_NameOnly("/", "root");
}
void tst_Xto_api(String raw, String expd) {Tfds.Eq(expd, alias.Xto_api(raw));}
void tst_OwnerDir(String raw, String expd) {Tfds.Eq(expd, alias.OwnerDir(raw));}
void tst_NameOnly(String raw, String expd) {Tfds.Eq(expd, alias.NameOnly(raw));}
void Make(String srcDir, String trgDir) {
alias = IoUrlInfo_alias.new_(srcDir, trgDir, IoEngine_.SysKey);
}
}

View File

@@ -0,0 +1,55 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoUrl_lnx_tst {
IoUrlFxt fx = IoUrlFxt.new_();
@Test public void Raw() {
fx.tst_Xto_gplx(Io_url_.lnx_dir_("/home/"), "/home/");
fx.tst_Xto_gplx(Io_url_.lnx_dir_("/home"), "/home/"); // add /
fx.tst_Xto_gplx(Io_url_.lnx_dir_("/"), "/");
fx.tst_Xto_gplx(Io_url_.lnx_fil_("/home/fil.txt"), "/home/fil.txt");
}
@Test public void Xto_api() {
fx.tst_Xto_api(Io_url_.lnx_fil_("/home/fil.txt"), "/home/fil.txt");
fx.tst_Xto_api(Io_url_.lnx_dir_("/home/"), "/home"); // del /
fx.tst_Xto_api(Io_url_.lnx_dir_("/"), "/");
}
@Test public void OwnerRoot() {
fx.tst_OwnerRoot(Io_url_.lnx_dir_("/home/fil.txt"), "/");
fx.tst_OwnerRoot(Io_url_.lnx_dir_("/home"), "/");
fx.tst_OwnerRoot(Io_url_.lnx_dir_("root"), "/");
}
@Test public void XtoNames() {
fx.tst_XtoNames(Io_url_.lnx_dir_("/home/fil.txt"), fx.ary_("root", "home", "fil.txt"));
fx.tst_XtoNames(Io_url_.lnx_dir_("/home"), fx.ary_("root", "home"));
}
@Test public void IsDir() {
fx.tst_IsDir(Io_url_.lnx_dir_("/home"), true);
fx.tst_IsDir(Io_url_.lnx_fil_("/home/file.txt"), false);
}
@Test public void OwnerDir() {
fx.tst_OwnerDir(Io_url_.lnx_dir_("/home/lnxusr"), Io_url_.lnx_dir_("/home"));
fx.tst_OwnerDir(Io_url_.lnx_dir_("/fil.txt"), Io_url_.lnx_dir_("/"));
fx.tst_OwnerDir(Io_url_.lnx_dir_("/"), Io_url_.Empty);
}
@Test public void NameAndExt() {
fx.tst_NameAndExt(Io_url_.lnx_fil_("/fil.txt"), "fil.txt");
fx.tst_NameAndExt(Io_url_.lnx_dir_("/dir"), "dir/");
}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoUrl_map_tst {
IoUrlFxt fx = IoUrlFxt.new_();
@Test public void Xto_api() {
IoUrlInfo inf = IoUrlInfo_.alias_("tst:\\", "C:\\tst\\", IoEngine_.SysKey);
fx.tst_Xto_api(Io_url_.new_inf_("tst:\\dir\\fil.txt", inf), "C:\\tst\\dir\\fil.txt");
fx.tst_Xto_api(Io_url_.new_inf_("tst:\\dir\\", inf), "C:\\tst\\dir"); // no trailing \
}
@Test public void Xto_api_wce() {
IoUrlInfo inf = IoUrlInfo_.alias_("wce:\\", "\\SD Card\\", IoEngine_.SysKey);
fx.tst_Xto_api(Io_url_.new_inf_("wce:\\dir\\", inf), "\\SD Card\\dir");
}
}

View File

@@ -0,0 +1,98 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoUrl_wnt_tst {
IoUrlFxt fx = IoUrlFxt.new_();
@Test public void Raw() {
fx.tst_Xto_gplx(Io_url_.wnt_fil_("C:\\dir\\fil.txt"), "C:\\dir\\fil.txt");
fx.tst_Xto_gplx(Io_url_.wnt_dir_("C:\\dir\\"), "C:\\dir\\");
fx.tst_Xto_gplx(Io_url_.wnt_dir_("C:\\dir") , "C:\\dir\\"); // add \
}
@Test public void Xto_api() {
fx.tst_Xto_api(Io_url_.wnt_fil_("C:\\fil.txt"), "C:\\fil.txt");
fx.tst_Xto_api(Io_url_.wnt_dir_("C:\\dir\\"), "C:\\dir"); // del \
fx.tst_Xto_api(Io_url_.wnt_dir_("C:"), "C:");
}
@Test public void OwnerRoot() {
fx.tst_OwnerRoot(Io_url_.wnt_dir_("C:\\dir") , "C:\\");
fx.tst_OwnerRoot(Io_url_.wnt_dir_("C:\\fil.png") , "C:\\");
fx.tst_OwnerRoot(Io_url_.wnt_dir_("C:") , "C:\\");
}
@Test public void IsDir() {
fx.tst_IsDir(Io_url_.wnt_dir_("C:\\dir\\"), true);
fx.tst_IsDir(Io_url_.wnt_fil_("C:\\dir"), false);
fx.tst_IsDir(Io_url_.wnt_fil_("C:\\fil.txt"), false);
}
@Test public void OwnerDir() {
fx.tst_OwnerDir(Io_url_.wnt_dir_("C:\\dir\\sub1"), Io_url_.wnt_dir_("C:\\dir"));
fx.tst_OwnerDir(Io_url_.wnt_fil_("C:\\fil.txt"), Io_url_.wnt_dir_("C:"));
fx.tst_OwnerDir(Io_url_.wnt_dir_("C:"), Io_url_.Empty);
// fx.tst_OwnerDir(Io_url_.wnt_fil_("press enter to select this folder"), Io_url_.Empty);
}
@Test public void NameAndExt() {
fx.tst_NameAndExt(Io_url_.wnt_fil_("C:\\fil.txt"), "fil.txt");
fx.tst_NameAndExt(Io_url_.wnt_dir_("C:\\dir"), "dir\\");
}
@Test public void NameOnly() {
fx.tst_NameOnly(Io_url_.wnt_fil_("C:\\fil.txt"), "fil");
fx.tst_NameOnly(Io_url_.wnt_dir_("C:\\dir"), "dir");
fx.tst_NameOnly(Io_url_.wnt_dir_("C:"), "C");
}
@Test public void Ext() {
fx.tst_Ext(Io_url_.wnt_fil_("C:\\fil.txt"), ".txt"); // fil
fx.tst_Ext(Io_url_.wnt_fil_("C:\\fil.multiple.txt"), ".txt"); // multiple ext
fx.tst_Ext(Io_url_.wnt_fil_("C:\\fil"), ""); // no ext
fx.tst_Ext(Io_url_.wnt_dir_("C:\\dir"), "\\"); // dir
}
@Test public void GenSubDir_nest() {
fx.tst_GenSubDir_nest(Io_url_.wnt_dir_("C:"), fx.ary_("dir1", "sub1"), Io_url_.wnt_dir_("C:\\dir1\\sub1"));
}
@Test public void GenNewExt() {
fx.tst_GenNewExt(Io_url_.wnt_fil_("C:\\fil.gif"), ".png", Io_url_.wnt_fil_("C:\\fil.png")); // basic
fx.tst_GenNewExt(Io_url_.wnt_fil_("C:\\fil.tst.gif"), ".png", Io_url_.wnt_fil_("C:\\fil.tst.png")); // last in multiple dotted
}
@Test public void GenRelUrl_orEmpty() {
fx.tst_GenRelUrl_orEmpty(Io_url_.wnt_fil_("C:\\root\\fil.txt") , Io_url_.wnt_dir_("C:\\root") , "fil.txt"); // fil
fx.tst_GenRelUrl_orEmpty(Io_url_.wnt_dir_("C:\\root\\dir") , Io_url_.wnt_dir_("C:\\root") , "dir\\"); // dir
fx.tst_GenRelUrl_orEmpty(Io_url_.wnt_fil_("C:\\root\\dir\\fil.txt") , Io_url_.wnt_dir_("C:\\root") , "dir\\fil.txt"); // fil: nested1
fx.tst_GenRelUrl_orEmpty(Io_url_.wnt_fil_("C:\\root\\dir\\fil.txt") , Io_url_.wnt_dir_("C:") , "root\\dir\\fil.txt"); // fil: nested2
}
@Test public void GenParallel() {
fx.tst_GenParallel(Io_url_.wnt_fil_("C:\\root1\\fil.txt"), Io_url_.wnt_dir_("C:\\root1"), Io_url_.wnt_dir_("D:\\root2"), Io_url_.wnt_fil_("D:\\root2\\fil.txt"));
fx.tst_GenParallel(Io_url_.wnt_dir_("C:\\root1\\dir") , Io_url_.wnt_dir_("C:\\root1"), Io_url_.wnt_dir_("D:\\root2"), Io_url_.wnt_dir_("D:\\root2\\dir"));
}
}
class IoUrlFxt {
public void tst_Xto_api(Io_url url, String expd) {Tfds.Eq(expd, url.Xto_api());}
public void tst_OwnerRoot(Io_url url, String expd) {Tfds.Eq(expd, url.OwnerRoot().Raw());}
public void tst_XtoNames(Io_url url, String... expdAry) {Tfds.Eq_ary(expdAry, url.XtoNames().To_str_ary());}
public void tst_NameAndExt(Io_url url, String expd) {Tfds.Eq(expd, url.NameAndExt());}
public void tst_Xto_gplx(Io_url url, String expd) {Tfds.Eq(expd, url.Raw());}
public void tst_IsDir(Io_url url, boolean expd) {Tfds.Eq(expd, url.Type_dir());}
public void tst_OwnerDir(Io_url url, Io_url expd) {Tfds.Eq_url(expd, url.OwnerDir());}
public void tst_NameOnly(Io_url url, String expd) {Tfds.Eq(expd, url.NameOnly());}
public void tst_Ext(Io_url url, String expd) {Tfds.Eq(expd, url.Ext());}
public void tst_GenSubDir_nest(Io_url rootDir, String[] parts, Io_url expd) {Tfds.Eq(expd, rootDir.GenSubDir_nest(parts));}
public void tst_GenNewExt(Io_url url, String ext, Io_url expd) {Tfds.Eq_url(expd, url.GenNewExt(ext));}
public void tst_GenRelUrl_orEmpty(Io_url url, Io_url rootDir, String expd) {Tfds.Eq(expd, url.GenRelUrl_orEmpty(rootDir));}
public void tst_GenParallel(Io_url url, Io_url oldRoot, Io_url newRoot, Io_url expd) {Tfds.Eq_url(expd, url.GenParallel(oldRoot, newRoot));}
public String[] ary_(String... ary) {return String_.Ary(ary);}
public static IoUrlFxt new_() {return new IoUrlFxt();} IoUrlFxt() {}
}