1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Embeddable: Fix if_exists

This commit is contained in:
gnosygnu
2016-11-24 08:53:07 -05:00
parent dae3be97ec
commit fcbdf8bbd8
1352 changed files with 7 additions and 88517 deletions

View File

@@ -1,57 +0,0 @@
/*
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;
import org.junit.*;
public class GfoMsg_rdr_tst {
@Before public void setup() {
msg = msg_().Add("a", "1").Add("b", "2").Add("c", "3");
ctx.Match("init", "init");
} GfoMsg msg; GfsCtx ctx = GfsCtx.new_();
@Test public void Key() {
tst_Msg(msg, "a", "1");
tst_Msg(msg, "b", "2");
tst_Msg(msg, "c", "3");
tst_Msg(msg, "d", null);
}
@Test public void Pos() {
msg = msg_().Add("", "1").Add("", "2").Add("", "3");
tst_Msg(msg, "", "1");
tst_Msg(msg, "", "2");
tst_Msg(msg, "", "3");
tst_Msg(msg, "", null);
}
@Test public void OutOfOrder() {
tst_Msg(msg, "c", "3");
tst_Msg(msg, "b", "2");
tst_Msg(msg, "a", "1");
}
@Test public void Key3_Pos1_Pos2() {
msg = msg_().Add("", "1").Add("", "2").Add("c", "3");
tst_Msg(msg, "c", "3");
tst_Msg(msg, "", "1");
tst_Msg(msg, "", "2");
}
@Test public void MultipleEmpty() {
msg = msg_().Add("", "1").Add("", "2").Add("", "3");
tst_Msg(msg, "", "1");
tst_Msg(msg, "", "2");
tst_Msg(msg, "", "3");
}
GfoMsg msg_() {return GfoMsg_.new_parse_("test");}
void tst_Msg(GfoMsg m, String k, String expd) {Tfds.Eq(expd, m.ReadStrOr(k, null));}
}

View File

@@ -1,32 +0,0 @@
/*
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;
public class GfoTreeBldr_fxt {
public List_adp Atrs() {return atrs;} List_adp atrs = List_adp_.New();
public List_adp Subs() {return subs;} List_adp subs = List_adp_.New();
public GfoTreeBldr_fxt atr_(Object key, Object val) {
atrs.Add(new Object[] {key, val});
return this;
}
public GfoTreeBldr_fxt sub_(GfoTreeBldr_fxt... ary) {
for (GfoTreeBldr_fxt sub : ary)
subs.Add(sub);
return this;
}
public static GfoTreeBldr_fxt new_() {return new GfoTreeBldr_fxt();} GfoTreeBldr_fxt() {}
}

View File

@@ -1,79 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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

@@ -1,24 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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

@@ -1,28 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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

@@ -1,126 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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() {
// Console_adp__mem dialog = Console_adp__mem.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_(Console_adp__mem 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

@@ -1,36 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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

@@ -1,25 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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

@@ -1,176 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.texts.*;/*EncodingAdp_*/ import gplx.core.ios.streams.*;
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");
Err_.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) {Err_.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 = Datetime_now.Dflt_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

@@ -1,57 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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.Instance;
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

@@ -1,58 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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.Instance;
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

@@ -1,106 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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) {Err_.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) {Err_.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

@@ -1,28 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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.Instance.InitEngine_mem_("mem2");
return Io_url_.mem_dir_("mem2");
}
}

View File

@@ -1,28 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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

@@ -1,49 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
import org.junit.*;
public class IoEngine_stream_xfer_tst {
@Before public void setup() {
srcEngine = IoEngine_memory.new_("mock1");
trgEngine = IoEngine_memory.new_("mock2");
IoEnginePool.Instance.Add_if_dupe_use_nth(srcEngine); IoEnginePool.Instance.Add_if_dupe_use_nth(trgEngine);
IoUrlInfoRegy.Instance.Reg(IoUrlInfo_.mem_("mem1/", srcEngine.Key()));
IoUrlInfoRegy.Instance.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

@@ -1,65 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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.Instance.SaveFilStr(url, url.Raw());
return ary;
}
void tst_ExecPathAry(IoEngine_xrg_queryDir finder, Io_url... expd) {Tfds.Eq_ary(expd, finder.ExecAsUrlAry());}
}

View File

@@ -1,32 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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

@@ -1,40 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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

@@ -1,58 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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

@@ -1,55 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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

@@ -1,31 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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

@@ -1,98 +0,0 @@
/*
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.core.ios; import gplx.*; import gplx.core.*;
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() {}
}

View File

@@ -1,48 +0,0 @@
/*
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.core.stores; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
public class GfoNdeRdr_read_tst {
@Test public void ReadInt() {
rdr = rdr_(IntClassXtn.Instance, "id", 1);
Tfds.Eq(rdr.ReadInt("id"), 1);
}
@Test public void ReadIntOr() {
rdr = rdr_(IntClassXtn.Instance, "id", 1);
Tfds.Eq(rdr.ReadIntOr("id", -1), 1);
}
@Test public void ReadIntElse_minus1() {
rdr = rdr_(IntClassXtn.Instance, "id", null);
Tfds.Eq(rdr.ReadIntOr("id", -1), -1);
}
@Test public void ReadInt_parse() {
rdr = rdr_(StringClassXtn.Instance, "id", "1");
Tfds.Eq(rdr.ReadInt("id"), 1);
}
@Test public void ReadIntElse_parse() {
rdr = rdr_(StringClassXtn.Instance, "id", "2");
Tfds.Eq(rdr.ReadIntOr("id", -1), 2);
}
GfoNdeRdr rdr_(ClassXtn type, String key, Object val) { // makes rdr with one row and one val
GfoFldList flds = GfoFldList_.new_().Add(key, type);
GfoNde row = GfoNde_.vals_(flds, new Object[] {val});
boolean parse = type == StringClassXtn.Instance; // assumes type is either StringClassXtn or IntClassXtn
return GfoNdeRdr_.leaf_(row, parse);
}
GfoNdeRdr rdr;
}

View File

@@ -1,189 +0,0 @@
/*
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.core.stores; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.gfo_ndes.*;
public class GfoNdeRdr_tst {
@Test public void Subs_leafs() {
root =
fx.root_
( fx.row_vals_(0)
, fx.row_vals_(1)
, fx.row_vals_(2)
);
tst_NdeVals(root, 0, 1, 2);
}
@Test public void Subs_ndes() {
root =
fx.root_
( leaf_("", 0)
, leaf_("", 1)
, leaf_("", 2)
);
tst_NdeVals(root, 0, 1, 2);
}
@Test public void Subs_mix() {
root =
fx.root_
( leaf_("", 0)
, fx.row_vals_(1)
, fx.row_vals_(2)
);
tst_NdeVals(root, 0, 1, 2);
}
@Test public void Subs_rdr() {
root =
fx.root_
( fx.row_vals_(0)
);
rootRdr = GfoNdeRdr_.root_parseNot_(root);
DataRdr rdr = rootRdr.Subs();
Tfds.Eq_true(rdr.MoveNextPeer());
Tfds.Eq(0, rdr.ReadAt(0));
Tfds.Eq_false(rdr.MoveNextPeer());
}
@Test public void MoveNextPeer_implicit() {
root =
fx.root_
( fx.csv_dat_
( fx.row_vals_(0)
, fx.row_vals_(1)
, fx.row_vals_(2)
)
);
GfoNdeRdr rootRdr = GfoNdeRdr_.root_parseNot_(root);
DataRdr subsRdr = rootRdr.Subs(); // pos=-1; bof
DataRdr subRdr = subsRdr.Subs(); // MoveNextPeer not needed; implicitly moves to pos=0
tst_RdrVals(subRdr, Object_.Ary(0, 1, 2));
}
@Test public void MoveNextPeer_explicit() {
root =
fx.root_
( fx.csv_dat_
( fx.row_vals_(0)
, fx.row_vals_(1)
, fx.row_vals_(2)
)
);
GfoNdeRdr rootRdr = GfoNdeRdr_.root_parseNot_(root);
DataRdr subsRdr = rootRdr.Subs(); // pos=-1; bof
Tfds.Eq_true(subsRdr.MoveNextPeer()); // explicitly moves to pos=0
DataRdr subRdr = subsRdr.Subs();
tst_RdrVals(subRdr, Object_.Ary(0, 1, 2));
}
@Test public void Xpath_basic() {
root = fx.root_
( leaf_("root", 0)
, leaf_("root", 1)
, leaf_("root", 2)
);
tst_Xpath_all(root, "root", 0, 1, 2);
}
@Test public void Xpath_nested() {
root = fx.root_
( fx.tbl_("owner"
, leaf_("root", 0)
, leaf_("root", 1)
, leaf_("root", 2)
));
tst_Xpath_all(root, "owner/root", 0, 1, 2);
}
@Test public void Xpath_null() {
root = fx.root_
( leaf_("match", 0)
);
rootRdr = GfoNdeRdr_.root_parseNot_(root);
DataRdr sub = rootRdr.Subs_byName("no_match");
Tfds.Eq_false(sub.MoveNextPeer());
}
@Test public void Xpath_moveFirst_basic() {
root = fx.root_
( leaf_("nde0", 0)
);
tst_Xpath_first(root, "nde0", 0);
}
@Test public void Xpath_moveFirst_shallow() {
root = fx.root_
( leaf_("nde0", 0)
, leaf_("nde1", 1)
, leaf_("nde2", 2)
);
tst_Xpath_first(root, "nde2", 2);
}
@Test public void Xpath_moveFirst_nested() {
root = fx.root_
( node_("nde0", Object_.Ary("0")
, leaf_("nde00", "00")
));
tst_Xpath_first(root, "nde0", "0");
tst_Xpath_first(root, "nde0/nde00", "00");
}
@Test public void Xpath_moveFirst_nested_similarName() {
root = fx.root_
( node_("nde0", Object_.Ary("0")
, leaf_("nde00", "00")
)
, node_("nde1", Object_.Ary("1")
, leaf_("nde00", "10")
));
tst_Xpath_first(root, "nde1/nde00", "10");
}
@Test public void Xpath_moveFirst_many() {
root = fx.root_
( leaf_("root", 0)
, leaf_("root", 1)
, leaf_("root", 2)
);
tst_Xpath_first(root, "root", 0); // returns first
}
@Test public void Xpath_moveFirst_null() {
root = fx.root_
( leaf_("nde0", 0)
, leaf_("nde1", 1)
, leaf_("nde2", 2)
);
rootRdr = GfoNdeRdr_.root_parseNot_(root);
DataRdr rdr = rootRdr.Subs_byName("nde3");
Tfds.Eq_false(rdr.MoveNextPeer());
}
GfoNde leaf_(String name, Object... vals) {return GfoNde_.nde_(name, vals, GfoNde_.Ary_empty);}
GfoNde node_(String name, Object[] vals, GfoNde... subs) {return GfoNde_.nde_(name, vals, subs);}
void tst_NdeVals(GfoNde nde, Object... exptVals) {
DataRdr rdr = GfoNdeRdr_.root_parseNot_(nde);
tst_RdrVals(rdr.Subs(), exptVals);
}
void tst_RdrVals(DataRdr rdr, Object[] exptVals) {
int count = 0;
while (rdr.MoveNextPeer()) {
Object actl = rdr.ReadAt(0);
Tfds.Eq(actl, exptVals[count++]);
}
Tfds.Eq(count, exptVals.length);
}
void tst_Xpath_first(GfoNde root, String xpath, Object expt) {
DataRdr rdr = GfoNdeRdr_.root_parseNot_(root);
DataRdr sel = rdr.Subs_byName_moveFirst(xpath);
Object actl = sel.ReadAt(0);
Tfds.Eq(actl, expt);
}
void tst_Xpath_all(GfoNde root, String xpath, Object... exptVals) {
DataRdr rdr = GfoNdeRdr_.root_parseNot_(root);
tst_RdrVals(rdr.Subs_byName(xpath), exptVals);
}
GfoNde root; DataRdr rootRdr; GfoNdeFxt fx = GfoNdeFxt.new_();
}

View File

@@ -1,102 +0,0 @@
/*
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.core.stores.xmls; import gplx.*; import gplx.core.*; import gplx.core.stores.*;
import org.junit.*;
public class XmlDataRdr_tst {
@Test public void Read() {
DataRdr rdr = fx.rdr_("<title id=\"1\" name=\"first\" profiled=\"false\" />");
Tfds.Eq(rdr.NameOfNode(), "title");
Tfds.Eq(rdr.ReadStr("name"), "first");
Tfds.Eq(rdr.ReadInt("id"), 1);
Tfds.Eq(rdr.ReadBool("profiled"), false);
}
@Test public void None() {
DataRdr rdr = fx.rdr_
( "<root>"
, "<find/>"
, "</root>"
);
fx.tst_Subs_ByName(rdr, "no_nde", "no_atr");
}
@Test public void One() {
DataRdr rdr = fx.rdr_
( "<root>"
, "<find id=\"f0\" />"
, "</root>"
);
fx.tst_Subs_ByName(rdr, "find", "id", "f0");
}
@Test public void One_IgnoreOthers() {
DataRdr rdr = fx.rdr_
( "<root>"
, "<find id=\"f0\" />"
, "<skip id=\"s0\" />"
, "</root>"
);
fx.tst_Subs_ByName(rdr, "find", "id", "f0");
}
@Test public void Many() {
DataRdr rdr = fx.rdr_
( "<root>"
, "<find id=\"f0\" />"
, "<find id=\"f1\" />"
, "</root>"
);
fx.tst_Subs_ByName(rdr, "find", "id", "f0", "f1");
}
@Test public void Nested() {
DataRdr rdr = fx.rdr_
( "<root>"
, "<sub1>"
, "<find id=\"f0\" />"
, "<find id=\"f1\" />"
, "</sub1>"
, "</root>"
);
fx.tst_Subs_ByName(rdr, "sub1/find", "id", "f0", "f1");
}
@Test public void Nested_IgnoreOthers() {
DataRdr rdr = fx.rdr_
( "<root>"
, "<sub1>"
, "<find id=\"f0\" />"
, "<skip id=\"s0\" />"
, "</sub1>"
, "<sub1>"
, "<find id=\"f1\" />" // NOTE: find across ndes
, "<skip id=\"s1\" />"
, "</sub1>"
, "</root>"
);
fx.tst_Subs_ByName(rdr, "sub1/find", "id", "f0", "f1");
}
XmlDataRdr_fxt fx = XmlDataRdr_fxt.new_();
}
class XmlDataRdr_fxt {
public DataRdr rdr_(String... ary) {return XmlDataRdr_.text_(String_.Concat(ary));}
public void tst_Subs_ByName(DataRdr rdr, String xpath, String key, String... expdAry) {
DataRdr subRdr = rdr.Subs_byName(xpath);
List_adp list = List_adp_.New();
while (subRdr.MoveNextPeer())
list.Add(subRdr.Read(key));
String[] actlAry = list.To_str_ary();
Tfds.Eq_ary(actlAry, expdAry);
}
public static XmlDataRdr_fxt new_() {return new XmlDataRdr_fxt();} XmlDataRdr_fxt() {}
}

View File

@@ -1,95 +0,0 @@
/*
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.core.stores.xmls; import gplx.*; import gplx.core.*; import gplx.core.stores.*;
import org.junit.*;
public class XmlDataWtr_tst {
@Before public void setup() {
wtr = XmlDataWtr.new_();
}
@Test public void WriteNodeBgn() {
wtr.WriteNodeBgn("chapter");
tst_XStr(wtr, "<chapter />", String_.CrLf);
}
@Test public void Attributes() {
wtr.WriteNodeBgn("chapter");
wtr.WriteData("id", 1);
wtr.WriteData("name", "first");
tst_XStr(wtr, "<chapter id=\"1\" name=\"first\" />", String_.CrLf);
}
@Test public void Subs() {
wtr.WriteNodeBgn("title");
wtr.WriteNodeBgn("chapters");
wtr.WriteNodeBgn("chapter");
tst_XStr(wtr
, "<title>", String_.CrLf
, "<chapters>", String_.CrLf
, "<chapter />", String_.CrLf
, "</chapters>", String_.CrLf
, "</title>", String_.CrLf
);
}
@Test public void Subs_Iterate() {
wtr.WriteNodeBgn("titles");
for (int title = 1; title <= 2; title++) {
wtr.WriteNodeBgn("title");
wtr.WriteData("id", title);
wtr.WriteNodeBgn("chapters");
wtr.WriteNodeEnd(); // chapters
wtr.WriteNodeEnd(); // title
}
wtr.WriteNodeEnd(); //titles
tst_XStr(wtr
, "<titles>", String_.CrLf
, "<title id=\"1\">", String_.CrLf
, "<chapters />", String_.CrLf
, "</title>", String_.CrLf
, "<title id=\"2\">", String_.CrLf
, "<chapters />", String_.CrLf
, "</title>", String_.CrLf
, "</titles>", String_.CrLf
);
}
@Test public void Peers() {
wtr.WriteNodeBgn("title");
wtr.WriteNodeBgn("chapters");
wtr.WriteNodeEnd();
wtr.WriteNodeBgn("audioStreams");
tst_XStr(wtr
, "<title>", String_.CrLf
, "<chapters />", String_.CrLf
, "<audioStreams />", String_.CrLf
, "</title>", String_.CrLf
);
}
@Test public void AtrsWithNesting() {
wtr.WriteNodeBgn("title");
wtr.WriteData("id", 1);
wtr.WriteData("name", "first");
wtr.WriteNodeBgn("chapters");
tst_XStr(wtr
, "<title id=\"1\" name=\"first\">", String_.CrLf
, "<chapters />", String_.CrLf
, "</title>", String_.CrLf
);
}
void tst_XStr(XmlDataWtr wtr, String... parts) {
String expd = String_.Concat(parts);
Tfds.Eq(expd, wtr.To_str());
}
XmlDataWtr wtr;
}