mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Html: Move get_elem_val to xo.elem
This commit is contained in:
92
400_xowa/src/gplx/xowa/bldrs/Db_mgr_fxt.java
Normal file
92
400_xowa/src/gplx/xowa/bldrs/Db_mgr_fxt.java
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.primitives.*; import gplx.core.strings.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.bldrs.infos.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*;
|
||||
public class Db_mgr_fxt {
|
||||
public Db_mgr_fxt Ctor_fsys() {bldr_fxt = new Xob_fxt().Ctor(Xoa_test_.Url_root().GenSubDir("root")); return this;}
|
||||
public Db_mgr_fxt Ctor_mem() {bldr_fxt = new Xob_fxt().Ctor_mem(); return this;} private Xob_fxt bldr_fxt;
|
||||
public Xowd_page_itm page_(int id, String modified_on, boolean type_redirect, int text_len) {return new Xowd_page_itm().Id_(id).Modified_on_(DateAdp_.parse_gplx(modified_on)).Redirected_(type_redirect).Text_len_(text_len);}
|
||||
public Xowe_wiki Wiki() {return bldr_fxt.Wiki();}
|
||||
public Xob_bldr Bldr() {return bldr_fxt.Bldr();}
|
||||
public Db_mgr_fxt doc_ary_(Xowd_page_itm... v) {bldr_fxt.doc_ary_(v); return this;}
|
||||
public Xowd_page_itm doc_(int id, String date, String title, String text) {return bldr_fxt.doc_(id, date, title, text);}
|
||||
public Xowd_page_itm doc_wo_date_(int id, String title, String text) {return bldr_fxt.doc_(id, "2012-01-02 03:04", title, text);}
|
||||
public Xowd_page_itm doc_ttl_(int id, String title) {return bldr_fxt.doc_(id, "2012-01-02 03:04", title, "IGNORE");}
|
||||
public Db_mgr_fxt Init_fil(String url, String raw) {return Init_fil(Io_url_.new_fil_(url), raw);}
|
||||
public Db_mgr_fxt Init_fil(Io_url url, String raw) {Io_mgr.Instance.SaveFilStr(url, raw); return this;}
|
||||
public Db_mgr_fxt Exec_run(Xob_page_wkr wkr) {bldr_fxt.Run(wkr); return this;}
|
||||
public Db_mgr_fxt Exec_run(Xob_cmd cmd) {bldr_fxt.Run_cmds(cmd); return this;}
|
||||
public Db_mgr_fxt Exec_run(Xobd_parser_wkr wkr) {bldr_fxt.Run(wkr); return this;}
|
||||
public void Init_page_insert(Int_obj_ref page_id_next, int ns_id, String[] ttls) {
|
||||
Xowe_wiki wiki = this.Wiki();
|
||||
int len = ttls.length;
|
||||
DateAdp modified_on = Datetime_now.Dflt_add_min_(0);
|
||||
Xowd_page_tbl tbl_page = wiki.Db_mgr_as_sql().Core_data_mgr().Tbl__page();
|
||||
tbl_page.Insert_bgn();
|
||||
for (int i = 0; i < len; i++) {
|
||||
String ttl = ttls[i];
|
||||
int page_id = page_id_next.Val();
|
||||
tbl_page.Insert_cmd_by_batch(page_id, ns_id, Bry_.new_u8(ttl), false, modified_on, 0, page_id, 0, 0, -1);
|
||||
page_id_next.Val_add(1);
|
||||
}
|
||||
tbl_page.Insert_end();
|
||||
}
|
||||
public void Test_load_ttl(int ns_id, String ttl_str, Xowd_page_itm expd) {
|
||||
Xowe_wiki wiki = bldr_fxt.Wiki();
|
||||
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
|
||||
byte[] ttl_bry = Bry_.new_a7(ttl_str);
|
||||
wiki.Db_mgr_as_sql().Load_mgr().Load_by_ttl(actl, ns, ttl_bry);
|
||||
Tfds.Eq(expd.Id(), actl.Id());
|
||||
Tfds.Eq_date(expd.Modified_on(), actl.Modified_on());
|
||||
Tfds.Eq(expd.Redirected(), actl.Redirected());
|
||||
Tfds.Eq(expd.Text_len(), actl.Text_len());
|
||||
} private Xowd_page_itm actl = new Xowd_page_itm();
|
||||
public void Test_load_page(int ns_id, int page_id, String expd) {
|
||||
Xowe_wiki wiki = bldr_fxt.Wiki();
|
||||
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
|
||||
wiki.Db_mgr_as_sql().Load_mgr().Load_page(actl.Id_(page_id), ns);
|
||||
Tfds.Eq(expd, String_.new_a7(actl.Text()));
|
||||
}
|
||||
int[] Xto_int_ary(List_adp rslts) {
|
||||
int len = rslts.Count();
|
||||
int[] rv = new int[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_page_itm page = (Xowd_page_itm)rslts.Get_at(i);
|
||||
rv[i] = page.Id();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Test_file(String url, String expd) {
|
||||
String actl = Io_mgr.Instance.LoadFilStr(url);
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
public void Init_db_sqlite() {
|
||||
Xowe_wiki wiki = this.Wiki();
|
||||
Db_conn_pool.Instance.Rls_all();
|
||||
Db_conn_bldr.Instance.Reg_default_sqlite();
|
||||
Io_mgr.Instance.DeleteDir_cmd(wiki.Fsys_mgr().Root_dir()).MissingIgnored_().Exec();
|
||||
wiki.Db_mgr_create_as_sql().Core_data_mgr().Init_by_make(Xowd_core_db_props.Test, Xob_info_session.Test);
|
||||
Io_mgr.Instance.SaveFilStr(wiki.Import_cfg().Src_dir().GenSubFil("a.xml"), "<test/>");
|
||||
}
|
||||
public void Rls() {
|
||||
this.Wiki().Db_mgr_as_sql().Core_data_mgr().Rls();
|
||||
}
|
||||
}
|
||||
77
400_xowa/src/gplx/xowa/bldrs/Xob_base_fxt.java
Normal file
77
400_xowa/src/gplx/xowa/bldrs/Xob_base_fxt.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.ios.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xob_base_fxt {
|
||||
public Xob_base_fxt Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
bldr = Xoa_app_fxt.bldr_(app);
|
||||
}
|
||||
this.Init_(bldr, wiki);
|
||||
Clear_hook();
|
||||
return this;
|
||||
}
|
||||
@gplx.Virtual public void Clear_hook() {}
|
||||
public Xob_base_fxt Init_(Xob_bldr bldr, Xowe_wiki wiki) {this.bldr = bldr; this.wiki = wiki; return this;}
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xob_bldr Bldr() {return bldr;} private Xob_bldr bldr;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Gfo_invk Bldr_itm() {return bldr_itm;} Gfo_invk bldr_itm;
|
||||
public Xowd_page_itm page_(String ttl) {return page_(ttl, "");}
|
||||
public Xowd_page_itm page_(String ttl, String text) {return new Xowd_page_itm().Ttl_(Bry_.new_u8(ttl), wiki.Ns_mgr()).Text_(Bry_.new_u8(text));}
|
||||
public Io_fil_chkr meta_(String url, String data) {return new Io_fil_chkr(Io_url_.mem_fil_(url), data);}
|
||||
public void Init_fxts(Xob_bldr bldr, Xowe_wiki wiki, Xob_base_fxt... fxt_ary) {
|
||||
int fxt_ary_len = fxt_ary.length;
|
||||
for (int i = 0; i < fxt_ary_len; i++)
|
||||
fxt_ary[i].Init_(bldr, wiki);
|
||||
}
|
||||
public Xob_base_fxt Init_fil(String url, String raw) {return Init_fil(Io_url_.new_fil_(url), raw);}
|
||||
public Xob_base_fxt Init_fil(Io_url url, String raw) {Io_mgr.Instance.SaveFilStr(url, raw); return this;}
|
||||
public Xob_base_fxt Exec_cmd(String cmd_key, GfoMsg... msgs) {
|
||||
Xob_cmd cmd = (Xob_cmd)bldr.Cmd_mgr().Add_cmd(wiki, cmd_key);
|
||||
this.bldr_itm = cmd;
|
||||
int len = msgs.length;
|
||||
GfsCtx ctx = GfsCtx.new_();
|
||||
for (int i = 0; i < len; i++) {
|
||||
GfoMsg msg = msgs[i];
|
||||
cmd.Invk(ctx, GfsCtx.Ikey_null, msg.Key(), msg);
|
||||
}
|
||||
Run_cmd(bldr, cmd);
|
||||
return this;
|
||||
}
|
||||
public Xob_base_fxt Test_fil(String url, String expd) {return Test_fil(Io_url_.new_fil_(url), expd);}
|
||||
public Xob_base_fxt Test_fil(Io_url url, String expd) {
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(url));
|
||||
return this;
|
||||
}
|
||||
public static void Run_cmd(Xob_bldr bldr, Xob_cmd cmd) {
|
||||
cmd.Cmd_bgn(bldr);
|
||||
cmd.Cmd_run();
|
||||
cmd.Cmd_end();
|
||||
}
|
||||
public static void Run_wkr(Xob_bldr bldr, Xob_page_wkr wkr, Xowd_page_itm[] page_ary) {
|
||||
wkr.Page_wkr__bgn();
|
||||
int page_ary_len = page_ary.length;
|
||||
for (int i = 0; i < page_ary_len; i++) {
|
||||
Xowd_page_itm page = page_ary[i];
|
||||
wkr.Page_wkr__run(page);
|
||||
}
|
||||
wkr.Page_wkr__end();
|
||||
}
|
||||
}
|
||||
152
400_xowa/src/gplx/xowa/bldrs/Xob_fxt.java
Normal file
152
400_xowa/src/gplx/xowa/bldrs/Xob_fxt.java
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.tests.*; import gplx.core.ios.*; import gplx.core.times.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.bldrs.cmds.texts.tdbs.*;
|
||||
import gplx.xowa.bldrs.wkrs.*;
|
||||
public class Xob_fxt {
|
||||
public Xob_fxt Ctor_mem() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
return Ctor(Io_url_.mem_dir_("mem/xowa/"));
|
||||
}
|
||||
public Xob_fxt Ctor(Io_url root_dir) {
|
||||
Db_conn_bldr.Instance.Reg_default_sqlite();
|
||||
app = Xoa_app_fxt.Make__app__edit("linux", root_dir);
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
bldr = Xoa_app_fxt.bldr_(app);
|
||||
return this;
|
||||
}
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xob_bldr Bldr() {return bldr;} private Xob_bldr bldr;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Io_url fil_ns_title(int ns_id, int idx) {return wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_ttl, ns_id, idx);}
|
||||
public Io_url fil_ns_page(int ns_id, int idx) {return wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_page, ns_id, idx);}
|
||||
public Io_url fil_ns_sttl(int ns_id, int idx) {return wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_search_ttl, ns_id, idx);}
|
||||
public Io_url fil_site(byte tid, int idx) {return wiki.Tdb_fsys_mgr().Url_site_fil(tid, idx);}
|
||||
public Io_url fil_site_ctg(int idx) {return wiki.Tdb_fsys_mgr().Url_site_fil(Xotdb_dir_info_.Tid_category, idx);}
|
||||
public Io_url fil_site_id(int idx) {return wiki.Tdb_fsys_mgr().Url_site_fil(Xotdb_dir_info_.Tid_id, idx);}
|
||||
public Io_url fil_reg(byte tid) {return wiki.Tdb_fsys_mgr().Url_site_reg(tid);}
|
||||
public Io_url fil_reg(int ns_id, byte tid) {return wiki.Tdb_fsys_mgr().Url_ns_reg(Int_.To_str_pad_bgn_zero(ns_id, 3), tid);}
|
||||
public Xob_fxt Fil_expd(Io_url url, String... expd) {
|
||||
String text = String_.Concat_lines_nl_skip_last(expd); // skipLast b/c if trailing line wanted, easier to pass in extra argument for ""
|
||||
expd_list.Add(new Io_fil_chkr(url, text));
|
||||
return this;
|
||||
} List_adp expd_list = List_adp_.New();
|
||||
public Xob_fxt Fil_skip(Io_url... urls) {
|
||||
for (int i = 0; i < urls.length; i++)
|
||||
skip_list.Add(urls[i]);
|
||||
return this;
|
||||
} List_adp skip_list = List_adp_.New();
|
||||
public Xob_fxt doc_ary_(Xowd_page_itm... v) {doc_ary = v; return this;} private Xowd_page_itm[] doc_ary;
|
||||
public Xowd_page_itm doc_wo_date_(int id, String title, String text) {return doc_(id, "2012-01-02 13:14", title, text);}
|
||||
public Xowd_page_itm doc_(int id, String date, String title, String text) {
|
||||
Xowd_page_itm rv = new Xowd_page_itm().Id_(id).Ttl_(Bry_.new_u8(title), wiki.Ns_mgr()).Text_(Bry_.new_u8(text));
|
||||
int[] modified_on = new int[7];
|
||||
dateParser.Parse_iso8651_like(modified_on, date);
|
||||
rv.Modified_on_(DateAdp_.seg_(modified_on));
|
||||
return rv;
|
||||
}
|
||||
public Xob_fxt Run_id() {
|
||||
Xob_make_id_wkr wkr = new Xob_make_id_wkr(bldr, wiki);
|
||||
Run(wkr);
|
||||
return this;
|
||||
}
|
||||
private void Run_wkr(Xob_page_wkr wkr) {
|
||||
wkr.Page_wkr__bgn();
|
||||
for (int i = 0; i < doc_ary.length; i++) {
|
||||
Xowd_page_itm page = doc_ary[i];
|
||||
wkr.Page_wkr__run(page);
|
||||
}
|
||||
wkr.Page_wkr__end();
|
||||
}
|
||||
private void tst_fils(Io_url[] ary) {
|
||||
Io_fil[] actls = Get_actl(ary);
|
||||
Io_fil_chkr[] expds = (Io_fil_chkr[])expd_list.To_ary(Io_fil_chkr.class);
|
||||
tst_mgr.Tst_ary("all", expds, actls);
|
||||
}
|
||||
Io_fil[] Get_actl(Io_url[] ary) {
|
||||
int len = ary.length;
|
||||
Io_fil[] rv = new Io_fil[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Io_url url = ary[i];
|
||||
String data = Io_mgr.Instance.LoadFilStr(url);
|
||||
rv[i] = new Io_fil(url, data);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xob_fxt Run_tmpl_dump() {
|
||||
Xob_parse_dump_templates_cmd wkr = new Xob_parse_dump_templates_cmd(bldr, wiki);
|
||||
Run_wkr(wkr);
|
||||
tst_fils(wkr.Dump_url_gen().Prv_urls());
|
||||
return this;
|
||||
}
|
||||
public Xob_fxt Run(Xobd_parser_wkr... wkrs) {
|
||||
Xobd_parser parser_wkr = new Xobd_parser(bldr);
|
||||
int len = wkrs.length;
|
||||
for (int i = 0; i < len; i++)
|
||||
parser_wkr.Wkr_add(wkrs[i]);
|
||||
Run(parser_wkr);
|
||||
return this;
|
||||
}
|
||||
public Xob_fxt Run(Xob_page_wkr... wkrs) {
|
||||
int doc_ary_len = doc_ary.length;
|
||||
for (int j = 0; j < wkrs.length; j++) {
|
||||
Xob_page_wkr wkr = wkrs[j];
|
||||
wkr.Page_wkr__bgn();
|
||||
for (int i = 0; i < doc_ary_len; i++) {
|
||||
Xowd_page_itm page = doc_ary[i];
|
||||
wkr.Page_wkr__run(page);
|
||||
}
|
||||
wkr.Page_wkr__end();
|
||||
}
|
||||
Test_expd_files();
|
||||
return this;
|
||||
}
|
||||
public Xob_fxt Run_cmds(Xob_cmd... cmds) {
|
||||
for (int j = 0; j < cmds.length; j++) {
|
||||
Xob_cmd cmd = cmds[j];
|
||||
cmd.Cmd_bgn(bldr);
|
||||
cmd.Cmd_run();
|
||||
cmd.Cmd_end();
|
||||
}
|
||||
Test_expd_files();
|
||||
return this;
|
||||
}
|
||||
private void Test_expd_files() {
|
||||
if (expd_list.Count() > 0) {
|
||||
Io_fil_chkr[] expd = (Io_fil_chkr[])expd_list.To_ary(Io_fil_chkr.class);
|
||||
Io_fil[] actl = wiki_();
|
||||
tst_mgr.Tst_ary("all", expd, actl);
|
||||
}
|
||||
}
|
||||
Io_fil[] wiki_() {
|
||||
List_adp rv = List_adp_.New();
|
||||
wiki_fil_add(rv, wiki.Tdb_fsys_mgr().Ns_dir());
|
||||
wiki_fil_add(rv, wiki.Tdb_fsys_mgr().Site_dir());
|
||||
rv.Sort();
|
||||
return (Io_fil[])rv.To_ary(Io_fil.class);
|
||||
}
|
||||
private void wiki_fil_add(List_adp list, Io_url root_dir) {
|
||||
Io_url[] ary = Io_mgr.Instance.QueryDir_args(root_dir).Recur_().ExecAsUrlAry();
|
||||
for (int i = 0; i < ary.length; i++) {
|
||||
Io_url url = ary[i];
|
||||
Io_fil fil = new Io_fil(url, Io_mgr.Instance.LoadFilStr_args(url).MissingIgnored_().Exec());
|
||||
list.Add(fil);
|
||||
}
|
||||
}
|
||||
Tst_mgr tst_mgr = new Tst_mgr();
|
||||
DateAdp_parser dateParser = DateAdp_parser.new_();
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.texts.tdbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.cmds.texts.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.portal.*; import gplx.xowa.wikis.xwikis.*;
|
||||
public class Xob_init_base_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xob_init_base_fxt fxt = new Xob_init_base_fxt();
|
||||
@Test public void Dirty_wiki_itms() {
|
||||
Xoae_app app = fxt.App(); Xowe_wiki wiki = fxt.Wiki();
|
||||
Xoa_available_wikis_mgr wikis_list = fxt.App().Gui_mgr().Html_mgr().Portal_mgr().Wikis();
|
||||
Tfds.Eq("", wikis_list.Itms_as_html()); // assert
|
||||
Xow_xwiki_itm xwiki_itm = app.Usere().Wiki().Xwiki_mgr().Add_by_atrs("en.wikipedia.org", "en.wikipedia.org");
|
||||
xwiki_itm.Offline_(Bool_.Y); // simulate add via Available_from_fsys; DATE:2014-09-21
|
||||
Tfds.Eq("", wikis_list.Itms_as_html()); // still empty
|
||||
new Xob_init_tdb(app.Bldr(), wiki).Cmd_end(); // mock "init" task
|
||||
Tfds.Eq("\n <li><a href=\"/site/en.wikipedia.org/\" class='xowa-hover-off'>en.wikipedia.org</a></li>", wikis_list.Itms_as_html()); // no longer empty
|
||||
}
|
||||
}
|
||||
class Xob_init_base_fxt {
|
||||
public void Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
}
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
}
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.texts.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.cmds.texts.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xob_siteinfo_parser__tst {
|
||||
private final Xob_siteinfo_parser__fxt fxt = new Xob_siteinfo_parser__fxt();
|
||||
@Test public void Basic__simplewikt() { // PURPOSE: basic test of siteinfo parse; DATE:2015-11-01
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( " <siteinfo>"
|
||||
, " <sitename>Wiktionary</sitename>"
|
||||
, " <dbname>simplewiktionary</dbname>"
|
||||
, " <super>https://simple.wiktionary.org/wiki/Main_Page</super>"
|
||||
, " <generator>MediaWiki 1.27.0-wmf.3</generator>"
|
||||
, " <case>case-sensitive</case>"
|
||||
, " <namespaces>"
|
||||
, " <namespace key=\"-2\" case=\"case-sensitive\">Media</namespace>"
|
||||
, " <namespace key=\"-1\" case=\"first-letter\">Special</namespace>"
|
||||
, " <namespace key=\"0\" case=\"case-sensitive\" />"
|
||||
, " <namespace key=\"1\" case=\"case-sensitive\">Talk</namespace>"
|
||||
, " <namespace key=\"2\" case=\"first-letter\">User</namespace>"
|
||||
, " <namespace key=\"3\" case=\"first-letter\">User talk</namespace>"
|
||||
, " <namespace key=\"4\" case=\"case-sensitive\">Wiktionary</namespace>"
|
||||
, " <namespace key=\"5\" case=\"case-sensitive\">Wiktionary talk</namespace>"
|
||||
, " <namespace key=\"6\" case=\"case-sensitive\">File</namespace>"
|
||||
, " <namespace key=\"7\" case=\"case-sensitive\">File talk</namespace>"
|
||||
, " <namespace key=\"8\" case=\"first-letter\">MediaWiki</namespace>"
|
||||
, " <namespace key=\"9\" case=\"first-letter\">MediaWiki talk</namespace>"
|
||||
, " <namespace key=\"10\" case=\"case-sensitive\">Template</namespace>"
|
||||
, " <namespace key=\"11\" case=\"case-sensitive\">Template talk</namespace>"
|
||||
, " <namespace key=\"12\" case=\"case-sensitive\">Help</namespace>"
|
||||
, " <namespace key=\"13\" case=\"case-sensitive\">Help talk</namespace>"
|
||||
, " <namespace key=\"14\" case=\"case-sensitive\">Category</namespace>"
|
||||
, " <namespace key=\"15\" case=\"case-sensitive\">Category talk</namespace>"
|
||||
, " <namespace key=\"828\" case=\"case-sensitive\">Module</namespace>"
|
||||
, " <namespace key=\"829\" case=\"case-sensitive\">Module talk</namespace>"
|
||||
, " <namespace key=\"2300\" case=\"case-sensitive\">Gadget</namespace>"
|
||||
, " <namespace key=\"2301\" case=\"case-sensitive\">Gadget talk</namespace>"
|
||||
, " <namespace key=\"2302\" case=\"case-sensitive\">Gadget definition</namespace>"
|
||||
, " <namespace key=\"2303\" case=\"case-sensitive\">Gadget definition talk</namespace>"
|
||||
, " <namespace key=\"2600\" case=\"first-letter\">Topic</namespace>"
|
||||
, " </namespaces>"
|
||||
, " </siteinfo>"
|
||||
), String_.Concat_lines_nl
|
||||
( "Main_Page|case-sensitive|Wiktionary|simplewiktionary|MediaWiki 1.27.0-wmf.3"
|
||||
, "-2|case-sensitive|Media"
|
||||
, "-1|first-letter|Special"
|
||||
, "0|case-sensitive|"
|
||||
, "1|case-sensitive|Talk"
|
||||
, "2|first-letter|User"
|
||||
, "3|first-letter|User talk"
|
||||
, "4|case-sensitive|Wiktionary"
|
||||
, "5|case-sensitive|Wiktionary talk"
|
||||
, "6|case-sensitive|File"
|
||||
, "7|case-sensitive|File talk"
|
||||
, "8|first-letter|MediaWiki"
|
||||
, "9|first-letter|MediaWiki talk"
|
||||
, "10|case-sensitive|Template"
|
||||
, "11|case-sensitive|Template talk"
|
||||
, "12|case-sensitive|Help"
|
||||
, "13|case-sensitive|Help talk"
|
||||
, "14|case-sensitive|Category"
|
||||
, "15|case-sensitive|Category talk"
|
||||
, "828|case-sensitive|Module"
|
||||
, "829|case-sensitive|Module talk"
|
||||
, "2300|case-sensitive|Gadget"
|
||||
, "2301|case-sensitive|Gadget talk"
|
||||
, "2302|case-sensitive|Gadget definition"
|
||||
, "2303|case-sensitive|Gadget definition talk"
|
||||
, "2600|first-letter|Topic"
|
||||
, "2601|first-letter|2601" // NOTE: Topic_talk doesn't exist in <siteinfo>, but added by XOWA b/c every subj ns must have a talk ns
|
||||
));
|
||||
}
|
||||
@Test public void Case_dflt() { // PURPOSE: missing case should use dflt DATE:2015-11-01
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( " <siteinfo>"
|
||||
, " <case>case-sensitive</case>"
|
||||
, " <namespaces>"
|
||||
, " <namespace key=\"-2\">Media</namespace>"
|
||||
, " </namespaces>"
|
||||
, " </siteinfo>"
|
||||
), String_.Concat_lines_nl
|
||||
( "Main_Page|case-sensitive|||"
|
||||
, "-2|case-sensitive|Media"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xob_siteinfo_parser__fxt {
|
||||
private final Xow_ns_mgr ns_mgr = new Xow_ns_mgr(gplx.xowa.langs.cases.Xol_case_mgr_.U8());
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public void Test__parse(String src_str, String expd) {
|
||||
Xob_siteinfo_nde nde = Xob_siteinfo_parser_.Parse(src_str, ns_mgr);
|
||||
nde.To_bfr(bfr);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.core.ios.*; import gplx.langs.htmls.encoders.*; import gplx.xowa.wikis.data.*; import gplx.xowa.files.downloads.*;
|
||||
import gplx.xowa.wikis.data.fetchers.*;
|
||||
public class Xoa_css_extractor_basic_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_css_extractor_fxt fxt = new Xoa_css_extractor_fxt();
|
||||
@Test public void Logo_download() {
|
||||
fxt.Init_fil("mem/http/en.wikipedia.org" , Xoa_css_extractor_fxt.Main_page_html);
|
||||
fxt.Init_fil("mem/http/wiki.png" , "download");
|
||||
fxt.Exec_logo_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/logo.png", "download");
|
||||
}
|
||||
@Test public void Logo_download_mw_wiki_logo() {
|
||||
fxt.Init_fil("mem/http/en.wikipedia.org" , "");
|
||||
fxt.Init_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/a/wiki.png" , "download");
|
||||
fxt.Init_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css" , ".mw-wiki-logo{background-image:url(\"//a/wiki.png\");");
|
||||
fxt.Exec_logo_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/logo.png" , "download");
|
||||
}
|
||||
@Test public void Logo_failover() {
|
||||
fxt.Init_fil("mem/xowa/bin/any/html/xowa/import/logo.png" , "failover");
|
||||
fxt.Exec_logo_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/logo.png", "failover");
|
||||
}
|
||||
@Test public void Css_common_download_failover() {
|
||||
fxt.Css_installer().Opt_download_css_common_(true);
|
||||
fxt.Init_fil("mem/xowa/bin/any/html/xowa/import/xowa_common_ltr.css", "failover");
|
||||
fxt.Exec_css_common_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css", "failover");
|
||||
}
|
||||
@Test public void Css_common_copy() {
|
||||
fxt.Css_installer().Opt_download_css_common_(false);
|
||||
fxt.Init_fil("mem/xowa/bin/any/html/xowa/import/xowa_common_ltr.css", "failover");
|
||||
fxt.Exec_css_common_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css", "failover");
|
||||
}
|
||||
@Test public void Css_common_copy_specific_wiki() { // PURPOSE: css for specific wiki
|
||||
fxt.Css_installer().Opt_download_css_common_(false).Wiki_code_(Bry_.new_a7("enwiki"));
|
||||
fxt.Init_fil("mem/xowa/bin/any/html/xowa/import/xowa_common_override/xowa_common_enwiki.css", "failover");
|
||||
fxt.Exec_css_common_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css", "failover");
|
||||
}
|
||||
@Test public void Css_scrape_download() {
|
||||
fxt.Css_installer().Url_encoder_(Gfo_url_encoder_.Http_url);
|
||||
fxt.Init_fil("mem/http/en.wikipedia.org" , Xoa_css_extractor_fxt.Main_page_html);
|
||||
fxt.Init_fil("mem/http/en.wikipedia.org/common.css" , "download");
|
||||
fxt.Init_fil("mem/http/www/a&0|b,c" , "data=css_0");
|
||||
fxt.Init_fil("mem/http/www/a&1|b,c" , "data=css_1");
|
||||
fxt.Exec_css_mainpage_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css", String_.Concat_lines_nl
|
||||
( "/*XOWA:mem/http/www/a&0|b,c*/"
|
||||
, "data=css_0"
|
||||
, ""
|
||||
, "/*XOWA:mem/http/www/a&1|b,c*/"
|
||||
, "data=css_1"
|
||||
));
|
||||
}
|
||||
@Test public void Css_scrape_failover() {
|
||||
fxt.Init_fil("mem/xowa/bin/any/html/xowa/import/xowa_common_ltr.css", "failover");
|
||||
fxt.Exec_css_mainpage_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css", "failover");
|
||||
}
|
||||
}
|
||||
class Xoa_css_extractor_fxt {
|
||||
public void Clear() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Test();
|
||||
css_installer = new Xoa_css_extractor();
|
||||
css_installer.Download_xrg().Trg_engine_key_(IoEngine_.MemKey);
|
||||
css_installer
|
||||
.Usr_dlg_(usr_dlg)
|
||||
.Wiki_domain_(Bry_.new_a7("en.wikipedia.org"))
|
||||
.Protocol_prefix_("mem/http/")
|
||||
.Mainpage_url_("mem/http/en.wikipedia.org")
|
||||
.Failover_dir_(Io_url_.new_any_("mem/xowa/bin/any/html/xowa/import/")) // "mem/xowa/user/anonymous/wiki/home/html/"
|
||||
.Wiki_html_dir_(Io_url_.new_any_("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/"))
|
||||
;
|
||||
page_fetcher = new Xow_page_fetcher_test();
|
||||
css_installer.Page_fetcher_(page_fetcher);
|
||||
Xoa_css_img_downloader css_img_downloader = new Xoa_css_img_downloader();
|
||||
css_img_downloader.Ctor(usr_dlg, new Xof_download_wkr_test(), Bry_.new_a7("mem/http/"));
|
||||
css_installer.Css_img_downloader_(css_img_downloader);
|
||||
} private Xow_page_fetcher_test page_fetcher;
|
||||
public Xoa_css_extractor Css_installer() {return css_installer;} private Xoa_css_extractor css_installer;
|
||||
public void Init_page(int ns_id, String ttl, String text) {
|
||||
page_fetcher.Add(ns_id, Bry_.new_a7(ttl), Bry_.new_a7(text));
|
||||
}
|
||||
public void Init_fil_empty(String url) {Init_fil(url, "");}
|
||||
public void Init_fil(String url, String text) {Io_mgr.Instance.SaveFilStr(url, text);}
|
||||
public void Test_fil(String url, String expd) {Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(Io_url_.new_any_(url)));}
|
||||
public void Exec_logo_setup() {
|
||||
css_installer.Mainpage_download();
|
||||
css_installer.Logo_setup();
|
||||
}
|
||||
public void Exec_css_common_setup() {
|
||||
css_installer.Mainpage_download();
|
||||
css_installer.Css_common_setup();
|
||||
}
|
||||
public void Exec_css_wiki_setup() {css_installer.Css_wiki_setup();}
|
||||
public void Exec_css_mainpage_setup() {
|
||||
css_installer.Mainpage_download();
|
||||
css_installer.Css_scrape_setup();
|
||||
}
|
||||
public static String Main_page_html = String_.Concat_lines_nl
|
||||
( "<html>"
|
||||
, " <head>"
|
||||
, " <link rel=\"stylesheet\" href=\"www/a&0%7Cb%2Cc\" />"
|
||||
, " <link rel=\"stylesheet\" href=\"www/a&1%7Cb%2Cc\" />"
|
||||
, " </head>"
|
||||
, " <body>"
|
||||
, " <div id=\"p-logo\" role=\"banner\"><a style=\"background-image: url(wiki.png);\""
|
||||
, " </body>"
|
||||
, "</html>"
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.core.ios.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xoa_css_extractor_wiki_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_css_extractor_fxt fxt = new Xoa_css_extractor_fxt();
|
||||
@Test public void Css_wiki_generate() {
|
||||
fxt.Init_page(Xow_ns_.Tid__mediawiki, "Common.css" , "css_0");
|
||||
fxt.Init_page(Xow_ns_.Tid__mediawiki, "Vector.css" , "css_1");
|
||||
fxt.Exec_css_wiki_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css", String_.Concat_lines_nl
|
||||
( "/*XOWA:MediaWiki:Common.css*/"
|
||||
, "css_0"
|
||||
, ""
|
||||
, "/*XOWA:MediaWiki:Vector.css*/"
|
||||
, "css_1"
|
||||
));
|
||||
}
|
||||
@Test public void Css_wiki_missing() {
|
||||
fxt.Exec_css_wiki_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css", "");
|
||||
}
|
||||
@Test public void Css_wiki_tab() { // PURPOSE: swap out 	 for xdat files
|
||||
fxt.Init_page(Xow_ns_.Tid__mediawiki, "Common.css" , "a	b");
|
||||
fxt.Exec_css_wiki_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css", String_.Concat_lines_nl
|
||||
( "/*XOWA:MediaWiki:Common.css*/"
|
||||
, "a\tb"
|
||||
));
|
||||
}
|
||||
}
|
||||
181
400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_img_downloader_tst.java
Normal file
181
400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_img_downloader_tst.java
Normal file
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.xowa.files.downloads.*;
|
||||
public class Xoa_css_img_downloader_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_css_img_downloader_fxt fxt = new Xoa_css_img_downloader_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_css_convert
|
||||
( "x {url(\"//site/a.jpg\")} y {url(\"//site/b.jpg\")}"
|
||||
, "x {url(\"site/a.jpg\")} y {url(\"site/b.jpg\")}"
|
||||
, "site/a.jpg"
|
||||
, "site/b.jpg"
|
||||
);
|
||||
}
|
||||
@Test public void Unquoted() {
|
||||
fxt.Test_css_convert
|
||||
( "x {url(//site/a.jpg)}"
|
||||
, "x {url(\"site/a.jpg\")}"
|
||||
, "site/a.jpg"
|
||||
);
|
||||
}
|
||||
@Test public void Http() {
|
||||
fxt.Test_css_convert
|
||||
( "x {url(http://site/a.jpg)}"
|
||||
, "x {url(\"site/a.jpg\")}"
|
||||
, "site/a.jpg"
|
||||
);
|
||||
}
|
||||
@Test public void Base64() {
|
||||
fxt.Test_css_convert
|
||||
( "x {url(\"//site/a.jpg\")} y {url(\"data:image/png;base64,BASE64DATA;ABC=\")} z {}"
|
||||
, "x {url(\"site/a.jpg\")} y {url(\"data:image/png;base64,BASE64DATA;ABC=\")} z {}"
|
||||
, "site/a.jpg"
|
||||
);
|
||||
}
|
||||
@Test public void Exc_missing_quote() {
|
||||
fxt.Test_css_convert
|
||||
( "x {url(\"//site/a.jpg\")} y {url(\"//site/b.jpg} z {}"
|
||||
, "x {url(\"site/a.jpg\")} y {url(\"//site/b.jpg} z {}"
|
||||
, "site/a.jpg"
|
||||
);
|
||||
}
|
||||
@Test public void Exc_empty() {
|
||||
fxt.Test_css_convert
|
||||
( "x {url(\"//site/a.jpg\")} y {url(\"\"} z {}"
|
||||
, "x {url(\"site/a.jpg\")} y {url(\"\"} z {}"
|
||||
, "site/a.jpg"
|
||||
);
|
||||
}
|
||||
// @Test public void Exc_name_only() { // COMMENTED: not sure how to handle "b.jpg" (automatically add "current" path?); RESTORE: when example found
|
||||
// fxt.Test_css_convert
|
||||
// ( "x {url(\"//site/a.jpg\")} y {url(\"b.jpg\"} z {}"
|
||||
// , "x {url(\"site/a.jpg\")} y {url(\"b.jpg\"} z {}"
|
||||
// , "site/a.jpg"
|
||||
// );
|
||||
// }
|
||||
@Test public void Repeat() {// PURPOSE.fix: exact same item was being added literally
|
||||
fxt.Test_css_convert
|
||||
( "x {url(\"//site/a.jpg?a=b\")} y {url(\"//site/a.jpg?a=b\"}"
|
||||
, "x {url(\"site/a.jpg\")} y {url(\"site/a.jpg\"}"
|
||||
, "site/a.jpg"
|
||||
);
|
||||
}
|
||||
@Test public void Clean_basic() {fxt.Test_clean_img_url("//site/a.jpg" , "site/a.jpg");}
|
||||
@Test public void Clean_query() {fxt.Test_clean_img_url("//site/a.jpg?key=val" , "site/a.jpg");}
|
||||
@Test public void Clean_dir() {fxt.Test_clean_img_url("//site/a/b/c.jpg?key=val" , "site/a/b/c.jpg");}
|
||||
@Test public void Clean_exc_site_only() {fxt.Test_clean_img_url("//site" , null);}
|
||||
@Test public void Clean_exc_site_only_2() {fxt.Test_clean_img_url("//site/" , null);}
|
||||
@Test public void Import_url() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Io_mgr.Instance.SaveFilStr("mem/www/b.css", "imported_css");
|
||||
fxt.Test_css_convert
|
||||
( "x @import url(\"mem/www/b.css\") screen; z"
|
||||
, String_.Concat_lines_nl
|
||||
( "x "
|
||||
, "/*XOWA:mem/www/b.css*/"
|
||||
, "imported_css"
|
||||
, ""
|
||||
, " z"
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void Import_url_make() {
|
||||
fxt.Test_import_url("a.org/b" , "http:a.org/b"); // add "stylesheet_prefix"
|
||||
fxt.Test_import_url("http://a.org" , "http://a.org"); // unless it starts with http
|
||||
fxt.Test_import_url("https://a.org" , "https://a.org"); // unless starts with https EX:: handle @import(https://...); PAGE:tr.n:Main_Page; DATE:2014-06-04
|
||||
}
|
||||
@Test public void Import_url_relative() { // PURPOSE: if directory, add domain; "/a/b.css" -> "//domain/a/b.css"; DATE:2014-02-03
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Io_mgr.Instance.SaveFilStr("mem/en.wikipedia.org/www/b.css", "imported_css");
|
||||
fxt.Test_css_convert
|
||||
( "x @import url(\"/www/b.css\") screen; z" // starts with "/"
|
||||
, String_.Concat_lines_nl
|
||||
( "x "
|
||||
, "/*XOWA:mem/en.wikipedia.org/www/b.css*/"
|
||||
, "imported_css"
|
||||
, ""
|
||||
, " z"
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void Import_url_relative_skip() { // PURPOSE: if rel path, skip; "//site/a/b.css"; DATE:2014-02-03
|
||||
fxt.Downloader().Stylesheet_prefix_(Bry_.new_a7("mem")); // stylesheet prefix prefix defaults to ""; set to "mem", else test will try to retrieve "//url" which will fail
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Io_mgr.Instance.SaveFilStr("mem//en.wikipedia.org/a/b.css", "imported_css");
|
||||
fxt.Test_css_convert
|
||||
( "x @import url(\"//en.wikipedia.org/a/b.css\") screen; z" // starts with "//"
|
||||
, String_.Concat_lines_nl
|
||||
( "x "
|
||||
, "/*XOWA://en.wikipedia.org/a/b.css*/"
|
||||
, "imported_css"
|
||||
, ""
|
||||
, " z"
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void Import_url_space() { // PURPOSE: some css has spaces; replace with underlines else fails when downloaded; EX: https://it.wikivoyage.org/w/index.php?title=MediaWiki:Container e Infobox.css&action=raw&ctype=text/css; DATE:2015-03-08
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Io_mgr.Instance.SaveFilStr("mem/www/b_c.css", "imported_css");
|
||||
fxt.Test_css_convert
|
||||
( "x @import url(\"mem/www/b c.css\") screen; z"
|
||||
, String_.Concat_lines_nl
|
||||
( "x "
|
||||
, "/*XOWA:mem/www/b_c.css*/"
|
||||
, "imported_css"
|
||||
, ""
|
||||
, " z"
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void Wikisource_freedimg() { // PURPOSE: check that "wikimedia" is replaced for FreedImg hack; PAGE:en.s:Page:Notes_on_Osteology_of_Baptanodon._With_a_Description_of_a_New_Species.pdf/3 DATE:2014-09-06
|
||||
fxt.Downloader().Stylesheet_prefix_(Bry_.new_a7("mem")); // stylesheet prefix prefix defaults to ""; set to "mem", else test will try to retrieve "//url" which will fail
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Io_mgr.Instance.SaveFilStr("mem//en.wikisource.org/w/index.php?title=MediaWiki:Dynimg.css", ".freedImg img[src*=\"wikipedia\"], .freedImg img[src*=\"wikisource\"], .freedImg img[src*=\"score\"], .freedImg img[src*=\"math\"] {");
|
||||
fxt.Test_css_convert
|
||||
( "x @import url(\"//en.wikisource.org/w/index.php?title=MediaWiki:Dynimg.css\") screen; z" // starts with "//"
|
||||
, String_.Concat_lines_nl
|
||||
( "x "
|
||||
, "/*XOWA://en.wikisource.org/w/index.php?title=MediaWiki:Dynimg.css*/"
|
||||
, ".freedImg img[src*=\"wikipedia\"], .freedImg img[src*=\"wikisource\"], /*XOWA:handle file:// paths which will have /commons.wikimedia.org/ but not /wikipedia/ */ .freedImg img[src*=\"wikimedia\"], .freedImg img[src*=\"score\"], .freedImg img[src*=\"math\"] {"
|
||||
, ""
|
||||
, " z"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xoa_css_img_downloader_fxt {
|
||||
public Xoa_css_img_downloader Downloader() {return downloader;} private Xoa_css_img_downloader downloader;
|
||||
public void Clear() {
|
||||
downloader = new Xoa_css_img_downloader();
|
||||
downloader.Ctor(Gfo_usr_dlg_.Test(), new Xof_download_wkr_test(), Bry_.Empty);
|
||||
}
|
||||
public void Test_css_convert(String raw, String expd, String... expd_img_ary) {
|
||||
List_adp actl_img_list = List_adp_.New();
|
||||
byte[] actl_bry = downloader.Convert_to_local_urls(Bry_.new_a7("mem/en.wikipedia.org"), Bry_.new_u8(raw), actl_img_list);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl_bry));
|
||||
Tfds.Eq_ary_str(expd_img_ary, actl_img_list.To_str_ary());
|
||||
}
|
||||
public void Test_clean_img_url(String raw_str, String expd) {
|
||||
byte[] raw = Bry_.new_a7(raw_str);
|
||||
byte[] actl = downloader.Clean_img_url(raw, raw.length);
|
||||
Tfds.Eq(expd, actl == null ? null : String_.new_a7(actl));
|
||||
}
|
||||
public void Test_import_url(String raw, String expd) {
|
||||
byte[] actl = Xoa_css_img_downloader.Import_url_build(Bry_.new_a7("http:"), Bry_.new_a7("//en.wikipedia.org"), Bry_.new_u8(raw));
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
public class Xob_css_parser__import_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xob_css_parser__import_fxt fxt = new Xob_css_parser__import_fxt();
|
||||
@Test public void Basic() {fxt.Test_parse_import (" @import url(//site/a.png)" , " @import url('site/a.png')");}
|
||||
@Test public void Warn_eos() {fxt.Test_parse_warn (" @import" , " @import" , "EOS");}
|
||||
@Test public void Warn_missing() {fxt.Test_parse_warn (" @import ('//site/a.png')" , " @import" , "missing");} // no "url("
|
||||
@Test public void Warn_invalid() {fxt.Test_parse_warn (" @import url('//site')" , " @import url('//site')" , "invalid");} // invalid
|
||||
}
|
||||
class Xob_css_parser__import_fxt extends Xob_css_parser__url_fxt { private Xob_css_parser__import import_parser;
|
||||
@Override public void Clear() {
|
||||
super.Clear();
|
||||
this.import_parser = new Xob_css_parser__import(url_parser);
|
||||
}
|
||||
@Override protected void Exec_parse_hook() {
|
||||
this.cur_frag = import_parser.Parse(src_bry, src_bry.length, 0, 8); // 8=" @import".length
|
||||
}
|
||||
public void Test_parse_import(String src_str, String expd) {
|
||||
Exec_parse(src_str, Xob_css_tkn__base.Tid_import, expd);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
public class Xob_css_parser__url_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xob_css_parser__url_fxt fxt = new Xob_css_parser__url_fxt();
|
||||
@Test public void Quote_none() {fxt.Test_parse_url(" url(//site/A.png) b" , " url('site/A.png')");}
|
||||
@Test public void Quote_apos() {fxt.Test_parse_url(" url('//site/A.png') b" , " url('site/A.png')");}
|
||||
@Test public void Quote_quote() {fxt.Test_parse_url(" url(\"//site/A.png\") b" , " url(\"site/A.png\")");}
|
||||
@Test public void Base64() {fxt.Test_parse_base64(" url('data:image/png;base64,BASE64DATA;ABC=') b", " url('data:image/png;base64,BASE64DATA;ABC=')");}
|
||||
@Test public void Base64_dangling() {fxt.Test_parse_warn(" url('data:image/png;base64,BASE64DATA;ABC=' ", " url('data:image/png;base64,BASE64DATA;ABC='", "base64 dangling");}
|
||||
@Test public void Warn_eos() {fxt.Test_parse_warn(" url(" , " url(" , "EOS");}
|
||||
@Test public void Warn_dangling() {fxt.Test_parse_warn(" url(a" , " url(" , "dangling");}
|
||||
@Test public void Warn_empty() {fxt.Test_parse_warn(" url()" , " url(" , "empty");}
|
||||
@Test public void Warn_site() {fxt.Test_parse_warn(" url('//site')" , " url('//site')" , "invalid");}
|
||||
}
|
||||
class Xob_css_parser__url_fxt {
|
||||
protected Xob_css_parser__url url_parser; private final Bry_bfr bfr = Bry_bfr_.New_w_size(32);
|
||||
protected Xob_css_tkn__base cur_frag; protected byte[] src_bry;
|
||||
@gplx.Virtual public void Clear() {
|
||||
url_parser = new Xob_css_parser__url(Bry_.new_a7("site"));
|
||||
}
|
||||
protected void Exec_parse(String src_str, int expd_tid, String expd_str) {
|
||||
this.src_bry = Bry_.new_u8(src_str);
|
||||
this.Exec_parse_hook();
|
||||
cur_frag.Write(bfr, src_bry);
|
||||
String actl_str = bfr.To_str_and_clear();
|
||||
Tfds.Eq(expd_tid, cur_frag.Tid(), "wrong tid; expd={0}, actl={1}", expd_tid, cur_frag.Tid());
|
||||
Tfds.Eq(expd_str, actl_str);
|
||||
}
|
||||
@gplx.Virtual protected void Exec_parse_hook() {
|
||||
this.cur_frag = url_parser.Parse(src_bry, src_bry.length, 0, 5); // 5=" url(".length
|
||||
}
|
||||
public void Test_parse_url(String src_str, String expd) {
|
||||
Exec_parse(src_str, Xob_css_tkn__base.Tid_url, expd);
|
||||
}
|
||||
public void Test_parse_base64(String src_str, String expd) {
|
||||
Exec_parse(src_str, Xob_css_tkn__base.Tid_base64, expd);
|
||||
}
|
||||
public void Test_parse_warn(String src_str, String expd, String warn) {
|
||||
Exec_parse(src_str, Xob_css_tkn__base.Tid_warn, expd);
|
||||
Xob_css_tkn__warn sub_frag = (Xob_css_tkn__warn)cur_frag;
|
||||
Tfds.Eq(true, String_.Has(sub_frag.Fail_msg(), warn));
|
||||
}
|
||||
}
|
||||
61
400_xowa/src/gplx/xowa/bldrs/css/Xob_mirror_mgr_tst.java
Normal file
61
400_xowa/src/gplx/xowa/bldrs/css/Xob_mirror_mgr_tst.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.files.downloads.*;
|
||||
public class Xob_mirror_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xob_mirror_mgr_fxt fxt = new Xob_mirror_mgr_fxt();
|
||||
@Test public void Download_1() {
|
||||
fxt.Fsys().Init_fil("mem/http/enwiki/file/a.png");
|
||||
fxt.Fsys().Init_fil("mem/http/enwiki/wiki/Main_Page", "url('//enwiki/wiki/a.png')");
|
||||
// fxt.Test_css();
|
||||
// fxt.Fsys().Test_fil("url('//enwiki/wiki/a.png')", "url('enwiki/wiki/a.png')"); // remove "//"
|
||||
// fxt.Fsys().Test_fil("mem/fsys/enwiki/file/a.png");
|
||||
}
|
||||
}
|
||||
class Xob_mirror_mgr_fxt {
|
||||
// private Xob_mirror_mgr mirror_mgr;
|
||||
public Io_fsys_fxt Fsys() {return fsys;} private final Io_fsys_fxt fsys = new Io_fsys_fxt();
|
||||
public void Clear() {
|
||||
fsys.Clear();
|
||||
// mirror_mgr = new Xob_mirror_mgr(Gfo_usr_dlg_.Noop, new Xof_download_wkr_test(), Bry_.new_a7("mem/http/enwiki"), Bry_.new_a7("mem/http/enwiki/wiki/Main_Page"), Io_url_.new_dir_("mem/fsys"));
|
||||
}
|
||||
public void Test_css(String raw, String expd) {
|
||||
// byte[] raw_bry = Bry_.new_u8(raw);
|
||||
// mirror_mgr.Exec();
|
||||
}
|
||||
}
|
||||
class Io_fsys_fxt {
|
||||
public void Clear() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
}
|
||||
public void Init_fil(String url_str) {
|
||||
Io_url url = Io_url_.new_fil_(url_str);
|
||||
Init_fil(url, url.NameAndExt());
|
||||
}
|
||||
public void Init_fil(String url_str, String text) {Init_fil(Io_url_.new_fil_(url_str), text);}
|
||||
public void Init_fil(Io_url url, String text) {
|
||||
Io_mgr.Instance.SaveFilStr(url, text);
|
||||
}
|
||||
public void Test_fil(String url_str) {
|
||||
Io_url url = Io_url_.new_fil_(url_str);
|
||||
Test_fil(url, url.NameAndExt());
|
||||
}
|
||||
public void Test_fil(String url, String expd) {Test_fil(Io_url_.new_fil_(url), expd);}
|
||||
public void Test_fil(Io_url url, String expd) {
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(url));
|
||||
}
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/bldrs/css/Xob_url_fixer_tst.java
Normal file
40
400_xowa/src/gplx/xowa/bldrs/css/Xob_url_fixer_tst.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
public class Xob_url_fixer_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xob_url_fixer_fxt fxt = new Xob_url_fixer_fxt();
|
||||
@Test public void Slash2() {fxt.Test_fix("//site/a.png" , "site/a.png");}
|
||||
@Test public void Http() {fxt.Test_fix("http://site/a.png" , "site/a.png");}
|
||||
@Test public void Https() {fxt.Test_fix("https://site/a.png" , "site/a.png");}
|
||||
@Test public void Qarg() {fxt.Test_fix("//site/a.png?key=val" , "site/a.png");}
|
||||
@Test public void Qarg_dir() {fxt.Test_fix("//site/a/b/c.png?key=val" , "site/a/b/c.png");}
|
||||
@Test public void Root() {fxt.Test_fix("/a/b.png" , "site/a/b.png");} // EX:/static/images/project-logos/wikivoyage.png; DATE:2015-05-09
|
||||
@Test public void Rel_dot2() {fxt.Test_fix("//site/a/../b/c.png" , "site/b/c.png");} // DATE:2015-05-09
|
||||
@Test public void Rel_dot2_mult() {fxt.Test_fix("//site/a/../b/../c/d.png" , "site/c/d.png");} // DATE:2015-05-09
|
||||
@Test public void Rel_dot1() {fxt.Test_fix("//site/a/./b/c.png" , "site/a/b/c.png");} // DATE:2015-05-09
|
||||
@Test public void Site_only() {fxt.Test_fix("//site" , null);}
|
||||
}
|
||||
class Xob_url_fixer_fxt {
|
||||
public void Site_(String v) {site_bry = Bry_.new_u8(v);} private byte[] site_bry;
|
||||
public void Clear() {
|
||||
this.Site_("site");
|
||||
}
|
||||
public void Test_fix(String raw, String expd) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Tfds.Eq(expd, String_.new_u8(Xob_url_fixer.Fix(site_bry, raw_bry, raw_bry.length)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.filters.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.filters.*;
|
||||
import org.junit.*;
|
||||
public class Xob_ttl_filter_mgr_srl_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xob_ttl_filter_mgr_srl_fxt fxt = new Xob_ttl_filter_mgr_srl_fxt();
|
||||
@Test public void One() {fxt.Test_parse("a" , 1, "a");}
|
||||
@Test public void Two() {fxt.Test_parse("a\nb" , 2, "a", "b");}
|
||||
@Test public void Comment() {fxt.Test_parse("|x" , 0);}
|
||||
@Test public void Comment_many() {fxt.Test_parse("|x||" , 0);}
|
||||
@Test public void Blank() {fxt.Test_parse("\n" , 0);}
|
||||
@Test public void Mix() {
|
||||
fxt.Test_parse(String_.Concat_lines_nl_skip_last
|
||||
( "|comment 1"
|
||||
, "a"
|
||||
, ""
|
||||
, "|comment 2"
|
||||
, "b"
|
||||
)
|
||||
, 2, "a", "b")
|
||||
;}
|
||||
}
|
||||
class Xob_ttl_filter_mgr_srl_fxt {
|
||||
private final Xob_ttl_filter_mgr_srl mgr = new Xob_ttl_filter_mgr_srl();
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public void Clear() {
|
||||
hash.Clear();
|
||||
}
|
||||
public void Test_parse(String src, int expd_count, String... expd_itms) {
|
||||
mgr.Init(hash);
|
||||
mgr.Load_by_bry(Bry_.new_u8(src));
|
||||
Tfds.Eq(expd_count, hash.Count());
|
||||
int expd_len = expd_itms.length;
|
||||
for (int i = 0; i < expd_len; ++i) {
|
||||
String expd_itm = expd_itms[i];
|
||||
Tfds.Eq_true(hash.Has(Bry_.new_u8(expd_itm)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.filters.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.filters.*;
|
||||
import org.junit.*;
|
||||
public class Xob_ttl_filter_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xob_ttl_filter_mgr_fxt fxt = new Xob_ttl_filter_mgr_fxt();
|
||||
@Test public void One() {
|
||||
fxt.Init_load_exclude("A");
|
||||
fxt.Init_load_include("B");
|
||||
fxt.Test_match_exclude_y("A");
|
||||
fxt.Test_match_exclude_n("B", "C");
|
||||
fxt.Test_match_include_y("B");
|
||||
fxt.Test_match_include_n("A", "C");
|
||||
}
|
||||
}
|
||||
class Xob_ttl_filter_mgr_fxt {
|
||||
private final Xob_ttl_filter_mgr mgr = new Xob_ttl_filter_mgr();
|
||||
public void Clear() {
|
||||
mgr.Clear();
|
||||
}
|
||||
public void Init_load_exclude(String itm) {mgr.Load(Bool_.Y, Bry_.new_u8(itm));}
|
||||
public void Init_load_include(String itm) {mgr.Load(Bool_.N, Bry_.new_u8(itm));}
|
||||
public void Test_match_exclude_y(String... itms) {Test_match(Bool_.Y, Bool_.Y, itms);}
|
||||
public void Test_match_exclude_n(String... itms) {Test_match(Bool_.Y, Bool_.N, itms);}
|
||||
public void Test_match_include_y(String... itms) {Test_match(Bool_.N, Bool_.Y, itms);}
|
||||
public void Test_match_include_n(String... itms) {Test_match(Bool_.N, Bool_.N, itms);}
|
||||
private void Test_match(boolean exclude, boolean expd, String... itms) {
|
||||
for (String itm : itms) {
|
||||
byte[] itm_bry = Bry_.new_u8(itm);
|
||||
if (exclude)
|
||||
Tfds.Eq(expd, mgr.Match_exclude(itm_bry), itm);
|
||||
else
|
||||
Tfds.Eq(expd, mgr.Match_include(itm_bry), itm);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.filters.dansguardians; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.filters.*;
|
||||
import org.junit.*; import gplx.dbs.*;
|
||||
public class Dg_match_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Dg_match_mgr_fxt fxt = new Dg_match_mgr_fxt();
|
||||
@Test public void One() {
|
||||
fxt.Init_line(100, "a");
|
||||
fxt.Test_match_many_y("a", "ab", "ba", "abc");
|
||||
fxt.Test_match_many_n("b");
|
||||
}
|
||||
}
|
||||
class Dg_match_mgr_fxt {
|
||||
private Dg_match_mgr match_mgr;
|
||||
private final List_adp rule_list = List_adp_.New();
|
||||
public void Clear() {
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
Io_url root_dir = Io_url_.mem_dir_("mem/dg/");
|
||||
match_mgr = new Dg_match_mgr(root_dir.GenSubDir("words"), 1, 0, Bool_.Y, Bool_.Y, root_dir.GenSubDir("log"));
|
||||
rule_list.Clear();
|
||||
}
|
||||
public void Init_line(int score, String... words) {
|
||||
Dg_rule line = new Dg_rule(-1, -1, -1, Dg_rule.Tid_rule, Bry_.new_a7("key"), score, Dg_word.Ary_new_by_str_ary(words));
|
||||
rule_list.Add(line);
|
||||
}
|
||||
public void Test_match_many_y(String... words) {Test_match_many(Bool_.Y, words);}
|
||||
public void Test_match_many_n(String... words) {Test_match_many(Bool_.N, words);}
|
||||
public void Test_match_many(boolean expd, String... words) {
|
||||
int words_len = words.length;
|
||||
for (int i = 0; i < words_len; ++i)
|
||||
Test_match_one(expd, words[i]);
|
||||
}
|
||||
public void Test_match_one(boolean expd, String word_str) {
|
||||
match_mgr.Clear();
|
||||
int rule_list_len = rule_list.Count();
|
||||
for (int j = 0; j < rule_list_len; ++j) {
|
||||
Dg_rule rule = (Dg_rule)rule_list.Get_at(j);
|
||||
match_mgr.Init_by_rule(rule);
|
||||
}
|
||||
byte[] word_bry = Bry_.new_u8(word_str);
|
||||
Tfds.Eq(expd, match_mgr.Match(1, 101, 0, Bry_.Empty, Bry_.Empty, null, word_bry), (expd ? "pass:" : "fail:") + word_str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.filters.dansguardians; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.filters.*;
|
||||
import org.junit.*;
|
||||
public class Dg_parser_tst {
|
||||
@Before public void init() {fxt.Init();} private Dg_parser_fxt fxt = new Dg_parser_fxt();
|
||||
@Test public void One() {fxt.Test_parse_line("<a><123>", fxt.Make_line(123, "a"));}
|
||||
@Test public void Many() {fxt.Test_parse_line("<a>,<b>,<c><-123>", fxt.Make_line(-123, "a", "b", "c"));}
|
||||
@Test public void Score_0() {fxt.Test_parse_line("<a><0>", fxt.Make_line(Dg_rule.Score_banned, "a"));}
|
||||
@Test public void Noscore() {fxt.Test_parse_line("<a>", fxt.Make_line(Dg_rule.Score_banned, "a"));}
|
||||
@Test public void Noscore_2() {fxt.Test_parse_line("<a>,<b>", fxt.Make_line(Dg_rule.Score_banned, "a", "b"));}
|
||||
@Test public void Comment() {fxt.Test_parse_line("# comment", Dg_rule.Itm_comment);}
|
||||
@Test public void Blank() {fxt.Test_parse_line("", Dg_rule.Itm_blank);}
|
||||
@Test public void Invalid_line_bgn() {fxt.Test_parse_line(" <a><1>", Dg_rule.Itm_invalid);}
|
||||
@Test public void Dangling_word() {fxt.Test_parse_line("<a", Dg_rule.Itm_invalid);}
|
||||
@Test public void Dangling_score() {fxt.Test_parse_line("<a><12", fxt.Make_line(Dg_rule.Score_banned, "a"));}
|
||||
@Test public void Invalid_dlm() {fxt.Test_parse_line("<a> <1>", fxt.Make_line(Dg_rule.Score_banned, "a"));}
|
||||
@Test public void Invalid_dlm_2() {fxt.Test_parse_line("<a>,<b><c><2>", fxt.Make_line(Dg_rule.Score_banned, "a", "b"));}
|
||||
@Test public void Invalid_score() {fxt.Test_parse_line("<a><1a>", fxt.Make_line(Dg_rule.Score_banned, "a"));}
|
||||
// @Test public void Parse_dir() {
|
||||
// Dg_parser parser = new Dg_parser();
|
||||
// Gfo_usr_dlg_.I = Xoa_app_.New__usr_dlg__console();
|
||||
// parser.Parse_dir(Io_url_.new_dir_("C:\\xowa\\bin\\any\\xowa\\bldr\\filters\simple.wikipedia.org\\Dansguardian\\\\"));
|
||||
// }
|
||||
}
|
||||
class Dg_parser_fxt {
|
||||
private final Dg_parser parser = new Dg_parser(); private final Bry_bfr bfr = Bry_bfr_.Reset(32);
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(16);
|
||||
public void Init() {}
|
||||
public Dg_rule Make_line(int score, String... words) {return new Dg_rule(-1, -1, -1, Dg_rule.Tid_rule, null, score, Dg_word.Ary_new_by_str_ary(words));}
|
||||
public void Test_parse_line(String str, Dg_rule expd) {
|
||||
byte[] src = Bry_.new_u8(str);
|
||||
Dg_rule actl = parser.Parse_line("rel_path", 0, 0, src, 0, src.length);
|
||||
Tfds.Eq_str_lines(Xto_str(bfr, expd), Xto_str(bfr, actl));
|
||||
}
|
||||
private String Xto_str(Bry_bfr bfr, Dg_rule line) {
|
||||
bfr .Add_str_a7("score=").Add_int_variable(line.Score()).Add_byte_nl()
|
||||
.Add_str_a7("words=").Add_str_u8(String_.Concat_with_str(";", Dg_word.Ary_concat(line.Words(), tmp_bfr, Byte_ascii.Tick))).Add_byte_nl()
|
||||
;
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
public class Xoi_cmd_dumpfile_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoi_cmd_dumpfile_fxt fxt = new Xoi_cmd_dumpfile_fxt();
|
||||
@Test public void Bz2__unzip() {
|
||||
fxt .Exec_parse_msg("mem/en.wikipedia.org/fil.xml.bz2", "", "unzip")
|
||||
.Test_domain("en.wikipedia.org")
|
||||
.Test_vals("mem/en.wikipedia.org/fil.xml.bz2", "mem/en.wikipedia.org/fil.xml", true)
|
||||
;
|
||||
}
|
||||
@Test public void Bz2__unzip__assert_xml_ext() { // xml ext relies on removing ".bz2" from ".xml.bz2"; if just ".bz2" add an ".xml"
|
||||
fxt .Exec_parse_msg("mem/en.wikipedia.org/fil.bz2", "", "unzip")
|
||||
.Test_vals("mem/en.wikipedia.org/fil.bz2", "mem/en.wikipedia.org/fil.xml", true)
|
||||
;
|
||||
}
|
||||
@Test public void Bz2__direct() {
|
||||
fxt .Exec_parse_msg("mem/en.wikipedia.org/fil.bz2", "", "")
|
||||
.Test_vals("mem/en.wikipedia.org/fil.bz2", null, false)
|
||||
;
|
||||
}
|
||||
@Test public void Xml__unzip_n() {
|
||||
fxt .Exec_parse_msg("mem/en.wikipedia.org/fil.xml", "", "")
|
||||
.Test_vals(null, "mem/en.wikipedia.org/fil.xml", false)
|
||||
;
|
||||
}
|
||||
@Test public void Xml__unzip_y() {
|
||||
fxt .Exec_parse_msg("mem/en.wikipedia.org/fil.xml", "", "")
|
||||
.Test_vals(null, "mem/en.wikipedia.org/fil.xml", false)
|
||||
;
|
||||
}
|
||||
}
|
||||
class Xoi_cmd_dumpfile_fxt {
|
||||
public void Clear() {
|
||||
dumpfile.Clear();
|
||||
} private Xoi_cmd_dumpfile dumpfile = new Xoi_cmd_dumpfile();
|
||||
public Xoi_cmd_dumpfile_fxt Exec_parse_msg(String url, String domain, String args) {
|
||||
GfoMsg m = GfoMsg_.new_parse_("").Add("url", url).Add("domain", domain).Add("args", args);
|
||||
dumpfile.Parse_msg(m);
|
||||
return this;
|
||||
}
|
||||
public Xoi_cmd_dumpfile_fxt Test_vals(String expd_bz2, String expd_xml, boolean expd_unzip) {
|
||||
Eq_url(expd_bz2, dumpfile.Bz2_url());
|
||||
Eq_url(expd_xml, dumpfile.Xml_url());
|
||||
Tfds.Eq(expd_unzip, dumpfile.Bz2_unzip());
|
||||
return this;
|
||||
}
|
||||
public Xoi_cmd_dumpfile_fxt Test_domain(String expd_domain) {
|
||||
Tfds.Eq(expd_domain, String_.new_u8(dumpfile.Domain()));
|
||||
return this;
|
||||
}
|
||||
private void Eq_url(String expd, Io_url actl) {
|
||||
if (expd == null && actl == null) return;
|
||||
else if (expd != null && actl != null) {
|
||||
Tfds.Eq(expd, actl.Raw());
|
||||
}
|
||||
else if (expd == null) throw Err_.new_wo_type("actl should be null", "expd", expd);
|
||||
else if (actl == null) throw Err_.new_wo_type("actl should not be null", "expd", expd);
|
||||
}
|
||||
}
|
||||
128
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_wiki_tst.java
Normal file
128
400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_wiki_tst.java
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.consoles.*;
|
||||
import gplx.core.brys.args.*; import gplx.core.threads.*; import gplx.xowa.bldrs.setups.maints.*; import gplx.xowa.xtns.wbases.imports.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.bldrs.wms.*; import gplx.xowa.bldrs.wms.dumps.*;
|
||||
public class Xoi_cmd_wiki_tst {
|
||||
@Test public void Run() { // MAINT:2016-12-04
|
||||
// Bld_import_list(Xow_domain_regy.All);
|
||||
// Bld_cfg_files(Xow_domain_regy.All); // NOTE: remember to carry over the wikisource / page / index commands from the existing xowa_build_cfg.gfs; also, only run the xowa_build_cfg.gfs once; DATE:2013-10-15; last run: DATE:2014-09-09
|
||||
}
|
||||
public void Bld_import_list(String... ary) {
|
||||
int ary_len = ary.length;
|
||||
Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||
Wmf_latest_parser parser = new Wmf_latest_parser();
|
||||
Bfr_arg__time time_fmtr = new Bfr_arg__time();
|
||||
for (int i = 0; i < ary_len; i++)
|
||||
Bld_import_list_itm2(bfr, parser, time_fmtr, ary, i);
|
||||
Io_mgr.Instance.SaveFilStr("C:\\xowa\\user\\temp.txt", bfr.To_str());
|
||||
}
|
||||
private void Bld_import_list_itm2(Bry_bfr bfr, Wmf_latest_parser parser, Bfr_arg__time time_fmtr, String[] ary, int i) {
|
||||
String domain_str = ary[i];
|
||||
byte[] domain_bry = Bry_.new_a7(domain_str);
|
||||
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(domain_bry);
|
||||
byte[] wmf_key_bry = Bry_.Replace(Xow_abrv_wm_.To_abrv(domain_itm), Byte_ascii.Dash, Byte_ascii.Underline);
|
||||
String wmf_key = String_.new_u8(wmf_key_bry);
|
||||
String url = "https://dumps.wikimedia.org/" + wmf_key + "/latest";
|
||||
byte[] latest_html = null;
|
||||
for (int j = 0; j < 5; ++j) {
|
||||
latest_html = Io_mgr.Instance.DownloadFil_args("", Io_url_.Empty).Exec_as_bry(url);
|
||||
if (latest_html != null) break;
|
||||
Tfds.Dbg("fail|" + domain_str + "|" + url);
|
||||
if (j == 4) return;
|
||||
}
|
||||
parser.Parse(latest_html);
|
||||
Xowm_dump_file dump_file = new Xowm_dump_file(domain_str, "latest", Xowm_dump_type_.Str__pages_articles);
|
||||
dump_file.Server_url_(Xowm_dump_file_.Server_wmf_https);
|
||||
byte[] pages_articles_key = Bry_.new_a7(wmf_key + "-latest-pages-articles.xml.bz2");
|
||||
Wmf_latest_itm latest_itm = parser.Get_by(pages_articles_key);
|
||||
if (latest_itm == null) {Tfds.Dbg("missing|" + domain_str + "|" + url); return;} // NOTE: commonswiki missing entry for commonswiki-latest-pages-articles.xml.bz2 DATE:2016-05-01
|
||||
Tfds.Dbg("pass|" + domain_str + "|" + url);
|
||||
bfr.Add(domain_bry).Add_byte_pipe();
|
||||
bfr.Add_str_u8(dump_file.File_url()).Add_byte_pipe();
|
||||
bfr.Add(Xow_domain_tid_.Get_type_as_bry(domain_itm.Domain_type_id())).Add_byte_pipe();
|
||||
long src_size = latest_itm.Size();
|
||||
bfr.Add_long_variable(src_size).Add_byte_pipe();
|
||||
bfr.Add_str_a7(gplx.core.ios.Io_size_.To_str(src_size)).Add_byte_pipe();
|
||||
time_fmtr.Seconds_(Math_.Div_safe_as_long(src_size, 1000000)).Bfr_arg__add(bfr);
|
||||
bfr.Add_byte_pipe();
|
||||
bfr.Add_str_a7(latest_itm.Date().XtoStr_fmt_yyyy_MM_dd_HH_mm());
|
||||
bfr.Add_byte_pipe();
|
||||
bfr.Add_str_a7(dump_file.Dump_date());
|
||||
bfr.Add_byte_nl();
|
||||
}
|
||||
/*
|
||||
private void Bld_import_list_itm(Bry_bfr bfr, Xowm_dump_file dump_file, Bry_fmtr_arg_time time_fmtr, String[] ary, int i) {
|
||||
String itm = ary[i];
|
||||
dump_file.Ctor(itm, "latest", Xowm_dump_type_.Str__pages_articles);
|
||||
int count = 0;
|
||||
while (count++ < 1) {
|
||||
dump_file.Server_url_(Xowm_dump_file_.Server_wmf);
|
||||
if (dump_file.Connect()) break;
|
||||
Tfds.WriteText(String_.Format("retrying: {0} {1}\n", count, dump_file.File_modified()));
|
||||
Thread_adp_.Sleep(15000); // wait for connection to reset
|
||||
}
|
||||
if (count == 10) {
|
||||
Tfds.WriteText(String_.Format("failed: {0}\n", dump_file.File_url()));
|
||||
return;
|
||||
}
|
||||
else
|
||||
Tfds.WriteText(String_.Format("passed: {0}\n", itm));
|
||||
bfr.Add_str(itm).Add_byte_pipe();
|
||||
bfr.Add_str(dump_file.File_url()).Add_byte_pipe();
|
||||
bfr.Add(Xow_domain_tid_.Get_type_as_bry(dump_file.Wiki_type().Wiki_tid())).Add_byte_pipe();
|
||||
// Xol_lang_stub lang_itm = Xol_lang_stub_.Get_by_key(wiki_type.Lang_key());
|
||||
// if (lang_itm == null) lang_itm = Xol_lang_stub_.Get_by_key(Xol_lang_itm_.Key_en); // commons, species, meta, etc will have no lang
|
||||
// bfr.Add(lang_itm.Local_name()).Add_byte_pipe();
|
||||
// bfr.Add(lang_itm.Canonical_name()).Add_byte_pipe();
|
||||
long src_size = dump_file.File_len();
|
||||
bfr.Add_long_variable(src_size).Add_byte_pipe();
|
||||
bfr.Add_str(gplx.core.ios.Io_size_.To_str(src_size)).Add_byte_pipe();
|
||||
time_fmtr.Seconds_(Math_.Div_safe_as_long(src_size, 1000000)).XferAry(bfr, 0);
|
||||
bfr.Add_byte_pipe();
|
||||
bfr.Add_str(dump_file.File_modified().XtoStr_fmt_yyyy_MM_dd_HH_mm());
|
||||
bfr.Add_byte_pipe();
|
||||
// bfr.Add_str(String_.Concat_with_obj(",", (Object[])dump_file.Dump_available_dates()));
|
||||
// bfr.Add_byte_pipe();
|
||||
bfr.Add_str(dump_file.Dump_date());
|
||||
bfr.Add_byte_nl();
|
||||
Thread_adp_.Sleep(1000);
|
||||
}
|
||||
*/
|
||||
public void Bld_cfg_files(String... ary) {
|
||||
Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||
gplx.xowa.bldrs.wiki_cfgs.Xoi_wiki_props_api api = new gplx.xowa.bldrs.wiki_cfgs.Xoi_wiki_props_api();
|
||||
gplx.xowa.bldrs.wiki_cfgs.Xoi_wiki_props_wiki wiki = new gplx.xowa.bldrs.wiki_cfgs.Xoi_wiki_props_wiki();
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
String wiki_domain = ary[i];
|
||||
try {
|
||||
byte[] xml = api.Exec_api(api.Api_src(wiki_domain));
|
||||
wiki.Wiki_domain_(Bry_.new_a7(wiki_domain));
|
||||
api.Parse(wiki, String_.new_u8(xml));
|
||||
api.Build_cfg(bfr, wiki);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Console_adp__sys.Instance.Write_str_w_nl(Err_.Message_gplx_full(e));
|
||||
}
|
||||
}
|
||||
bfr.Add_str_a7("app.bldr.wiki_cfg_bldr.run;").Add_byte_nl();
|
||||
Io_mgr.Instance.SaveFilStr("C:\\user\\xowa_build_cfg.gfs", bfr.To_str());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
public class Xoi_mirror_parser_tst {
|
||||
@Test public void Basic() {
|
||||
Tst_parse(String_.Concat_lines_nl
|
||||
( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">"
|
||||
, "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">"
|
||||
, "<head>"
|
||||
, "<title>Index of /simplewiki/</title>"
|
||||
, "<link rel=\"stylesheet\" type=\"text/css\" href=\"/pub/misc/lighttpd-white-dir.css\" />"
|
||||
, "</head>"
|
||||
, "<body>"
|
||||
, "<h2>Index of /simplewiki/</h2>"
|
||||
, "<div class=\"list\">"
|
||||
, "<table summary=\"Directory Listing\" cellpadding=\"0\" cellspacing=\"0\">"
|
||||
, "<thead><tr><th class=\"n\">Name</th><th class=\"m\">Last Modified</th><th class=\"s\">Size</th><th class=\"t\">Type</th></tr></thead>"
|
||||
, "<tbody>"
|
||||
, "<tr><td class=\"n\"><a href=\"../\">Parent Directory</a>/</td><td class=\"m\"> </td><td class=\"s\">- </td><td class=\"t\">Directory</td></tr>"
|
||||
, "<tr><td class=\"n\"><a href=\"20120516/\">20120516</a>/</td><td class=\"m\">2012-May-17 01:04:39</td><td class=\"s\">- </td><td class=\"t\">Directory</td></tr>"
|
||||
, "<tr><td class=\"n\"><a href=\"20121220/\">20121220</a>/</td><td class=\"m\">2012-Dec-20 20:15:55</td><td class=\"s\">- </td><td class=\"t\">Directory</td></tr>"
|
||||
, "<tr><td class=\"n\"><a href=\"20130214/\">20130214</a>/</td><td class=\"m\">2013-Feb-14 06:28:41</td><td class=\"s\">- </td><td class=\"t\">Directory</td></tr>"
|
||||
, "<tr><td class=\"n\"><a href=\"latest/\">latest</a>/</td><td class=\"m\">2013-Feb-14 06:28:41</td><td class=\"s\">- </td><td class=\"t\">Directory</td></tr>"
|
||||
, "</tbody>"
|
||||
, "</table>"
|
||||
, "</div>"
|
||||
, "<div class=\"foot\">lighttpd</div>"
|
||||
, "</body>"
|
||||
, "</html>"
|
||||
), String_.Ary("20120516", "20121220", "20130214", "latest"));
|
||||
}
|
||||
@Test public void Find_last_lte() {
|
||||
Tst_find_last_lte(String_.Ary("20120516", "20121220", "20130214", "latest"), "20130101", "20121220");
|
||||
Tst_find_last_lte(String_.Ary("20120516", "20121220", "20130214", "latest"), "20120101", "");
|
||||
}
|
||||
private void Tst_parse(String raw, String[] expd) {
|
||||
Xoi_mirror_parser parser = new Xoi_mirror_parser();
|
||||
Tfds.Eq_ary_str(expd, parser.Parse(raw));
|
||||
}
|
||||
private void Tst_find_last_lte(String[] ary, String comp, String expd) {
|
||||
Tfds.Eq(expd, Xoi_mirror_parser.Find_last_lte(ary, comp));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.setups.addons; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.ios.*;
|
||||
public class Xoi_firefox_installer_tst {
|
||||
private Xoi_firefox_pref_fxt fxt = new Xoi_firefox_pref_fxt();
|
||||
@Test public void Pref_update() {
|
||||
fxt.Test_pref_update(String_.Concat_lines_nl
|
||||
( "pref(\"key_0\", \"val_0\"); // comment_0"
|
||||
, "pref(\"key_1\", \"val_1\"); // comment_1"
|
||||
, "pref(\"key_2\", \"val_2\"); // comment_2"
|
||||
)
|
||||
, "key_1", "val_1_updated"
|
||||
, String_.Concat_lines_nl
|
||||
( "pref(\"key_0\", \"val_0\"); // comment_0"
|
||||
, "pref(\"key_1\", \"val_1_updated\");"
|
||||
, "pref(\"key_2\", \"val_2\"); // comment_2"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xoi_firefox_pref_fxt {
|
||||
public void Test_pref_update(String src, String key, String val, String expd) {
|
||||
String actl = Xoi_firefox_installer.Pref_update(src, key, val);
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.setups.maints; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*;
|
||||
public class Wmf_dump_list_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} private Wmf_dump_list_parser_fxt fxt = new Wmf_dump_list_parser_fxt();
|
||||
@Test public void Parse() {
|
||||
fxt.Test_parse
|
||||
( "<li>2013-07-17 00:32:33 <a href=\"http://dumps.wikimedia.org/enwiki/20130708\">enwiki</a>: <span class=\"done\">Dump complete</span></li>"
|
||||
, fxt.itm("enwiki", "20130708", Wmf_dump_itm.Status_tid_complete, "Dump complete", "2013-07-17 00:32:33")
|
||||
);
|
||||
fxt.Test_parse(String_.Concat_lines_nl
|
||||
( "<li>2013-07-24 02:02:13 <a href=\"http://dumps.wikimedia.org/kawiki/20130724\">kawiki</a>: <span class=\"in-progress\">Dump in progress</span></li>"
|
||||
, "<ul><li class=\"in-progress\"><span class=\"updates\">2013-07-24 00:54:55</span> <span class=\"status\">in-progress</span> <span class=\"title\">All pages with complete page edit history (.bz2)</span><div class=\"progress\">2013-07-24 02:02:13: kawiki (ID 18587) 22046 pages (5.5|11140.9/sec all|curr), 869000 revs (215.2|505.3/sec all|curr), 99.9%|99.9% prefetched (all|curr), ETA 2013-07-24 04:09:41 [max 2514872]</div>"
|
||||
, "<ul><li class=\"file\">kawiki-20130724-pages-meta-history.xml.bz2 245.2 MB (written) </li></ul></li></ul>"
|
||||
)
|
||||
, fxt.itm("kawiki", "20130724", Wmf_dump_itm.Status_tid_working, "Dump in progress", "2013-07-24 02:02:13")
|
||||
);
|
||||
fxt.Test_parse
|
||||
( "<li>2013-07-17 00:32:33 <a href=\"http://dumps.wikimedia.org/enwiki/20130708\">enwiki</a>: <span class=\"done\">Error</span></li>"
|
||||
, fxt.itm("enwiki", "20130708", Wmf_dump_itm.Status_tid_error, "Error", "2013-07-17 00:32:33")
|
||||
);
|
||||
fxt.Test_parse
|
||||
( "<li>2013-11-28 06:08:56 <a href=\"zh_classicalwiki/20131128\">zh_classicalwiki</a>: <span class='done'>Dump complete</span></li>"
|
||||
, fxt.itm("zh-classicalwiki", "20131128", Wmf_dump_itm.Status_tid_complete, "Dump complete", "2013-11-28 06:08:56")
|
||||
);
|
||||
}
|
||||
// @Test public void Update() { // MAINT:QUARTERLY:2016-10-13; must run home/wiki/Dashboard/Wiki_maintenance and click "update dump status"
|
||||
// Hash_adp_bry excluded_domains = Hash_adp_bry.cs().Add_many_str
|
||||
// ( "advisory.wikipedia.org", "beta.wikiversity.org", "donate.wikipedia.org", "login.wikipedia.org"
|
||||
// , "nostalgia.wikipedia.org", "outreach.wikipedia.org", "quality.wikipedia.org", "sources.wikipedia.org"
|
||||
// , "strategy.wikipedia.org", "ten.wikipedia.org", "test2.wikipedia.org", "test.wikipedia.org"
|
||||
// , "usability.wikipedia.org", "vote.wikipedia.org"
|
||||
// , "bd.wikimedia.org", "dk.wikimedia.org", "mx.wikimedia.org", "nyc.wikimedia.org", "nz.wikimedia.org", "pa-us.wikimedia.org", "rs.wikimedia.org", "ua.wikimedia.org"
|
||||
// );
|
||||
// Wmf_dump_itm[] itms = new Wmf_dump_list_parser().Parse(Io_mgr.Instance.LoadFilBry("C:\\xowa\\bin\\any\\xowa\\xtns\\xowa\\maintenance\\backup-index.html"));
|
||||
// Array_.Sort(itms);
|
||||
// Bry_bfr sql_bfr = Bry_bfr_.New();
|
||||
// Bry_bfr bld_bfr = Bry_bfr_.New();
|
||||
// int itms_len = itms.length;
|
||||
// int counter = 1;
|
||||
// for (int i = 0; i < itms_len; i++) {
|
||||
// Wmf_dump_itm itm = itms[i];
|
||||
// byte[] abrv = itm.Wiki_abrv();
|
||||
// if (Bry_.Eq(abrv, Bry_.new_a7("testwikidatawiki"))) continue;
|
||||
// byte[] domain_bry = Xow_abrv_wm_.Parse_to_domain_bry(abrv);
|
||||
// if (domain_bry == null) continue; // not a standard WMF wiki; ignore
|
||||
// if (Bry_find_.Find_fwd(domain_bry, Bry_.new_a7("wikimania")) != Bry_find_.Not_found) continue;
|
||||
// if (excluded_domains.Has(domain_bry)) continue;
|
||||
// Xow_domain_itm domain_itm = Xow_domain_itm_.parse(domain_bry);
|
||||
// byte[] tid_name = Xto_display_name(Xow_domain_tid_.Get_type_as_bry(domain_itm.Domain_type_id()));
|
||||
// sql_bfr
|
||||
// .Add_byte(Byte_ascii.Paren_bgn)
|
||||
// .Add_int_variable(counter++)
|
||||
// .Add_byte(Byte_ascii.Comma)
|
||||
// .Add_int_variable(1)
|
||||
// .Add_byte(Byte_ascii.Comma)
|
||||
// .Add_byte(Byte_ascii.Apos)
|
||||
// .Add(domain_itm.Lang_orig_key())
|
||||
// .Add_byte(Byte_ascii.Apos)
|
||||
// .Add_byte(Byte_ascii.Comma)
|
||||
// .Add_byte(Byte_ascii.Apos)
|
||||
// .Add(tid_name)
|
||||
// .Add_byte(Byte_ascii.Apos)
|
||||
// .Add_byte(Byte_ascii.Paren_end)
|
||||
// .Add_byte(Byte_ascii.Comma)
|
||||
// .Add_str_u8("--" + String_.new_u8(abrv))
|
||||
// .Add_byte_nl()
|
||||
// ;
|
||||
// bld_bfr
|
||||
// .Add_byte(Byte_ascii.Comma)
|
||||
// .Add_byte(Byte_ascii.Space)
|
||||
// .Add_byte(Byte_ascii.Quote)
|
||||
// .Add(domain_bry)
|
||||
// .Add_byte(Byte_ascii.Quote)
|
||||
// .Add_byte_nl()
|
||||
// ;
|
||||
// }
|
||||
// Io_url temp = Io_url_.new_fil_("C:\\xowa\\user\\import_update.txt");
|
||||
// Io_mgr.Instance.SaveFilBfr(temp, sql_bfr);
|
||||
//// Io_mgr.Instance.AppendFilBfr(temp, bld_bfr);
|
||||
// }
|
||||
// private static byte[] Xto_display_name(byte[] v) {
|
||||
// if (Bry_.Eq(v, Xow_domain_tid_.Bry__wmforg)) return Bry_.new_a7("Wikimedia Foundation");
|
||||
// else if (Bry_.Eq(v, Xow_domain_tid_.Bry__species)) return Bry_.new_a7("Wikispecies");
|
||||
// else if (Bry_.Eq(v, Xow_domain_tid_.Bry__mediawiki)) return Bry_.new_a7("MediaWiki");
|
||||
// else return Bry_.Add(Byte_ascii.Case_upper(v[0]), Bry_.Mid(v, 1, v.length));
|
||||
// }
|
||||
}
|
||||
class Wmf_dump_list_parser_fxt {
|
||||
public void Clear() {}
|
||||
private Wmf_dump_list_parser parser = new Wmf_dump_list_parser();
|
||||
public String itm(String wiki_abrv, String dump_date, byte status_done, String status_msg, String status_time) {
|
||||
return String_.Concat_with_str("\n", wiki_abrv, dump_date
|
||||
, Byte_.To_str(status_done)
|
||||
, status_msg
|
||||
, status_time
|
||||
);
|
||||
}
|
||||
public void Test_parse(String raw, String... expd) {
|
||||
Wmf_dump_itm[] actl = parser.Parse(Bry_.new_a7(raw));
|
||||
Tfds.Eq_str_lines(String_.Concat_lines_nl(expd), String_.Concat_lines_nl(Xto_str(actl)));
|
||||
}
|
||||
public String[] Xto_str(Wmf_dump_itm[] ary) {
|
||||
int len = ary.length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv[i] = Xto_str(ary[i]);
|
||||
return rv;
|
||||
}
|
||||
public static String Xto_str(Wmf_dump_itm itm) {
|
||||
DateAdp status_time = itm.Status_time();
|
||||
String status_time_str = status_time == null ? "" : status_time.XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time);
|
||||
return String_.Concat_with_str("\n", String_.new_a7(itm.Wiki_abrv()), itm.Dump_date().XtoStr_fmt("yyyyMMdd")
|
||||
, Byte_.To_str(itm.Status_tid())
|
||||
, String_.new_a7(itm.Status_msg())
|
||||
, status_time_str
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.setups.maints; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
import org.junit.*; import gplx.core.ios.*;
|
||||
public class Wmf_latest_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} private Wmf_latest_parser_fxt fxt = new Wmf_latest_parser_fxt();
|
||||
@Test public void Parse() {
|
||||
fxt.Test_parse
|
||||
( "\n<a href=\"enwiki-latest-pages-articles.xml.bz2\">enwiki-latest-pages-articles.xml.bz2</a> 15-Jan-2015 05:43 11575640561\r\n"
|
||||
, fxt.itm("enwiki-latest-pages-articles.xml.bz2", "2015-01-15 05:43", "10.781 GB")
|
||||
);
|
||||
}
|
||||
// @Test public void Smoke() {
|
||||
// Wmf_latest_parser parser = new Wmf_latest_parser();
|
||||
// parser.Parse(Io_mgr.Instance.LoadFilBry("C:\\wmf_latest.html"));
|
||||
// Tfds.Dbg(String_.Concat_lines_nl(Wmf_latest_parser_fxt.Xto_str_ary(parser.To_ary())));
|
||||
// }
|
||||
}
|
||||
class Wmf_latest_parser_fxt {
|
||||
public void Clear() {}
|
||||
private Wmf_latest_parser parser = new Wmf_latest_parser();
|
||||
public Wmf_latest_itm itm(String name, String date, String size) {return new Wmf_latest_itm(Bry_.new_a7(name), DateAdp_.parse_iso8561(date), Io_size_.parse_or(size, 0));}
|
||||
public void Test_parse(String raw, Wmf_latest_itm... expd) {
|
||||
parser.Parse(Bry_.new_a7(raw));
|
||||
Wmf_latest_itm[] actl = parser.To_ary();
|
||||
Tfds.Eq_str_lines(String_.Concat_lines_nl(Xto_str_ary(expd)), String_.Concat_lines_nl(Xto_str_ary(actl)));
|
||||
}
|
||||
public static String[] Xto_str_ary(Wmf_latest_itm[] ary) {
|
||||
int len = ary.length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv[i] = Xto_str(ary[i]);
|
||||
return rv;
|
||||
}
|
||||
public static String Xto_str(Wmf_latest_itm itm) {
|
||||
return String_.Concat_with_str("\n", String_.new_a7(itm.Name()), itm.Date().XtoStr_fmt_iso_8561(), Io_size_.To_str(itm.Size()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.setups.upgrades; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_upgrade_mgr_tst {
|
||||
@Test public void Run() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
Io_url old_history_dir = app.Usere().Fsys_mgr().App_data_dir();
|
||||
Io_url new_history_dir = app.Usere().Fsys_mgr().App_data_dir().GenSubDir("history");
|
||||
Io_mgr.Instance.SaveFilStr(old_history_dir.GenSubFil("page_history.csv"), "test");
|
||||
Xoa_upgrade_mgr.Check(app);
|
||||
Tfds.Eq("test", Io_mgr.Instance.LoadFilStr(old_history_dir.GenSubFil("page_history.csv"))); // old file still exists
|
||||
Tfds.Eq("test", Io_mgr.Instance.LoadFilStr(new_history_dir.GenSubFil("page_history.csv"))); // new file exists
|
||||
Io_mgr.Instance.SaveFilStr(new_history_dir.GenSubFil("page_history.csv"), "test1"); // dirty file
|
||||
Xoa_upgrade_mgr.Check(app); // rerun
|
||||
Tfds.Eq("test1", Io_mgr.Instance.LoadFilStr(new_history_dir.GenSubFil("page_history.csv"))); // dirty file remains (not replaced by old file)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.sql_dumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.core.ios.*; import gplx.core.tests.*;
|
||||
public class Xosql_dump_parser__tst {
|
||||
private final Xosql_dump_parser__fxt fxt = new Xosql_dump_parser__fxt();
|
||||
private static final String table_def = "\n KEY \n) ENGINE; ";
|
||||
@Test public void One() {
|
||||
fxt.Init(String_.Ary("c1", "c2"), "c2").Test__parse(table_def + "INSERT INTO 'tbl_1' VALUES (1,2);", "2|");
|
||||
}
|
||||
@Test public void Many() {
|
||||
fxt.Init(String_.Ary("c1", "c2"), "c2").Test__parse(table_def + "INSERT INTO 'tbl_1' VALUES (1,2),(3,4),(5,6);", "2|\n4|\n6|");
|
||||
}
|
||||
@Test public void Quote_basic() {
|
||||
fxt.Init(String_.Ary("c1", "c2", "c3"), "c2", "c3").Test__parse(table_def + "INSERT INTO 'tbl_1' VALUES (1,'a','b');", "a|b|");
|
||||
}
|
||||
@Test public void Escape_backslash() {
|
||||
fxt.Init(String_.Ary("c1", "c2", "c3"), "c2", "c3").Test__parse(table_def + "INSERT INTO 'tbl_1' VALUES (1,'a\\\\b','c');", "a\\b|c|");
|
||||
}
|
||||
@Test public void Escape_quote() {
|
||||
fxt.Init(String_.Ary("c1", "c2", "c3"), "c2", "c3").Test__parse(table_def + "INSERT INTO 'tbl_1' VALUES (1,'a\"b','c');", "a\"b|c|");
|
||||
}
|
||||
@Test public void Fld_paren_end() {
|
||||
fxt.Init(String_.Ary("c1", "c2", "c3"), "c2", "c3").Test__parse(table_def + "INSERT INTO 'tbl_1' VALUES (1,'Психостимуляторы_(лекарственные_средства)','c');", "Психостимуляторы_(лекарственные_средства)|c|");
|
||||
}
|
||||
@Test public void Insert_multiple() {
|
||||
fxt.Init(String_.Ary("c1", "c2"), "c2").Test__parse(table_def + "INSERT INTO 'tbl_1' VALUES (1,2);INSERT INTO 'tbl_1' VALUES (3,4)", "2|\n4|");
|
||||
}
|
||||
}
|
||||
class Xosql_dump_parser__fxt {
|
||||
private Xosql_dump_parser parser;
|
||||
private Xosql_dump_cbk__test cbk;
|
||||
private String[] tbl_flds;
|
||||
public Xosql_dump_parser__fxt Init(String[] tbl_flds, String... cbk_flds) {
|
||||
this.tbl_flds = tbl_flds;
|
||||
this.cbk = new Xosql_dump_cbk__test();
|
||||
this.parser = new Xosql_dump_parser(cbk, cbk_flds);
|
||||
return this;
|
||||
}
|
||||
public void Test__parse(String raw_str, String expd) {
|
||||
Io_url src_fil = Io_url_.new_fil_("mem/test.sql");
|
||||
Io_mgr.Instance.SaveFilBry(src_fil, Make_dump(tbl_flds, raw_str));
|
||||
parser.Src_fil_(src_fil);
|
||||
parser.Parse(Gfo_usr_dlg_.Test());
|
||||
Gftest.Eq__str(expd, cbk.To_bry_and_clear());
|
||||
}
|
||||
private byte[] Make_dump(String[] tbl_flds, String insert) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
bfr.Add_str_a7("CREATE TABLE tbl_0 (");
|
||||
for (int i = 0; i < tbl_flds.length; ++i) {
|
||||
bfr.Add_byte_nl();
|
||||
bfr.Add_byte(Byte_ascii.Tick);
|
||||
bfr.Add_str_a7(tbl_flds[i]);
|
||||
bfr.Add_byte(Byte_ascii.Tick);
|
||||
bfr.Add_byte_comma();
|
||||
}
|
||||
bfr.Add_str_a7("\nUNIQUE KEY idx_0 (fld_0));\n");
|
||||
bfr.Add_str_u8(insert);
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
class Xosql_dump_cbk__test implements Xosql_dump_cbk {
|
||||
private int prv_idx = -1;
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public void Clear() {prv_idx = -1; bfr.Clear();}
|
||||
public void On_fld_done(int fld_idx, byte[] src, int val_bgn, int val_end) {
|
||||
if (fld_idx <= prv_idx) {
|
||||
if (prv_idx != -1) bfr.Add_byte_nl();
|
||||
}
|
||||
bfr.Add_mid(src, val_bgn, val_end).Add_byte_pipe();
|
||||
prv_idx = fld_idx;
|
||||
}
|
||||
public void On_row_done() {}
|
||||
public byte[] To_bry_and_clear() {return bfr.To_bry_and_clear();}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.sql_dumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xosql_tbl_parser__tst {
|
||||
private final Xosql_tbl_parser__fxt fxt = new Xosql_tbl_parser__fxt();
|
||||
@Test public void Unique_key() {
|
||||
fxt.Exec__parse(String_.Concat_lines_nl
|
||||
( "ignore"
|
||||
, "CREATE TABLE tbl_0 ("
|
||||
, " `fld_2` int,"
|
||||
, " `fld_1` int,"
|
||||
, " `fld_0` int,"
|
||||
, " UNIQUE KEY idx_0 (fld_2)"
|
||||
, ") ENGINE;"
|
||||
));
|
||||
fxt.Test__count(3);
|
||||
fxt.Test__get("fld_0", 2);
|
||||
fxt.Test__get("fld_1", 1);
|
||||
fxt.Test__get("fld_2", 0);
|
||||
fxt.Test__get("fld_3", -1);
|
||||
}
|
||||
@Test public void Primary_key() {
|
||||
fxt.Test__extract(String_.Concat_lines_nl
|
||||
( "ignore"
|
||||
, "CREATE TABLE tbl_0 ("
|
||||
, " `fld_0` int,"
|
||||
, " PRIMARY KEY idx_0 (fld_2)"
|
||||
, ") ENGINE;"
|
||||
), String_.Concat_lines_nl
|
||||
( " `fld_0` int,"
|
||||
));
|
||||
}
|
||||
@Test public void Key() {
|
||||
fxt.Test__extract(String_.Concat_lines_nl
|
||||
( "ignore"
|
||||
, "CREATE TABLE tbl_0 ("
|
||||
, " `fld_0` int,"
|
||||
, " KEY idx_0 (fld_2)"
|
||||
, ") ENGINE;"
|
||||
), String_.Concat_lines_nl
|
||||
( " `fld_0` int,"
|
||||
));
|
||||
}
|
||||
@Test public void Unique_key__key__primary_key() {
|
||||
fxt.Test__extract(String_.Concat_lines_nl
|
||||
( "ignore"
|
||||
, "CREATE TABLE tbl_0 ("
|
||||
, " `fld_0` int,"
|
||||
, " UNIQUE KEY idx_0 (fld_2),"
|
||||
, " KEY idx_0 (fld_2),"
|
||||
, " PRIMARY KEY idx_0 (fld_2),"
|
||||
, ") ENGINE;"
|
||||
), String_.Concat_lines_nl
|
||||
( " `fld_0` int,"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xosql_tbl_parser__fxt {
|
||||
private final Xosql_tbl_parser parser = new Xosql_tbl_parser();
|
||||
private Ordered_hash tbl_flds;
|
||||
public void Exec__parse(String v) {this.tbl_flds = parser.Parse(Bry_.new_a7(v));}
|
||||
public void Test__count(int expd) {Gftest.Eq__int(expd, tbl_flds.Len());}
|
||||
public void Test__get(String key, int expd) {
|
||||
Xosql_fld_itm actl_itm = (Xosql_fld_itm)tbl_flds.Get_by(Bry_.new_u8(key));
|
||||
Gftest.Eq__int(expd, actl_itm == null ? Bry_find_.Not_found : actl_itm.Idx());
|
||||
}
|
||||
public void Test__extract(String raw, String expd) {
|
||||
Gftest.Eq__ary__lines(expd, parser.Extract_flds(Bry_.new_u8(raw)), "extract");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.wiki_cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.core.strings.*;
|
||||
import gplx.langs.xmls.*;
|
||||
import gplx.xowa.addons.bldrs.app_cfgs.*;
|
||||
public class Xoi_wiki_props_api_tst {
|
||||
private Xoi_wiki_props_fxt fxt = new Xoi_wiki_props_fxt();
|
||||
@Before public void init() {} // private Xob_subpage_tst_fxt fxt = new] Xob_subpage_tst_fxt();
|
||||
@Test public void Parse() {
|
||||
fxt.Test_parse(String_.Concat_lines_nl
|
||||
( "<api>"
|
||||
, "<query>"
|
||||
, " <namespacealiases>"
|
||||
, " <ns id=\"4\" xml:space=\"preserve\">WP</ns>"
|
||||
, " <ns id=\"5\" xml:space=\"preserve\">WT</ns>"
|
||||
, " </namespacealiases>"
|
||||
, " <namespaces>"
|
||||
, " <ns id=\"0\" case=\"first-letter\" content=\"\" xml:space=\"preserve\"/>"
|
||||
, " <ns id=\"1\" case=\"first-letter\" subpages=\"\" canonical=\"Talk\" xml:space=\"preserve\">Talk</ns>"
|
||||
, " </namespaces>"
|
||||
, "</query>"
|
||||
, "</api>"
|
||||
), fxt.wiki_()
|
||||
.Alias_ary_(fxt.alias_(4, "WP"), fxt.alias_(5, "WT"))
|
||||
.Ns_ary_(fxt.ns_(0, false), fxt.ns_(1, true))
|
||||
);
|
||||
}
|
||||
// @Test public void Build() {
|
||||
// fxt.Test_build(fxt.wiki_("enwiki")
|
||||
// .Alias_ary_(fxt.alias_(4, "WP"), fxt.alias_(5, "WT"))
|
||||
// .Ns_ary_(fxt.ns_(0, false), fxt.ns_(1, true))
|
||||
// , "");
|
||||
// }
|
||||
// Tfds.Eq_str_lines(Query_ns(protocol, gplx.core.ios.IoEngine_.MemKey, wikis), String_.Concat_lines_nl
|
||||
// ( "app.bldr.wiki_cfg_bldr.get('en.wikipedia.org').new_cmd_('wiki.ns_mgr.aliases', 'ns_mgr.add_alias_bulk(\""
|
||||
// , "4|WP"
|
||||
// , "5|WT"
|
||||
// , "6|Image"
|
||||
// , "7|Image_talk"
|
||||
// , "\");');"
|
||||
// fxt.Test_parse(String_.Concat_lines_nl
|
||||
// ( "'wgNamespacesWithSubpages' => array"
|
||||
// , "( 'default' => array(2 => 1)"
|
||||
// , ", 'enwiki' => array(0 => 1)"
|
||||
// , ")"
|
||||
// ));
|
||||
}
|
||||
class Xoi_wiki_props_fxt {
|
||||
private Xoi_wiki_props_api api = new Xoi_wiki_props_api();
|
||||
private Bry_bfr bfr = Bry_bfr_.New();
|
||||
public Xoi_wiki_props_wiki wiki_() {return wiki_("domain_doesnt_matter");}
|
||||
public Xoi_wiki_props_wiki wiki_(String wiki_domain) {return new Xoi_wiki_props_wiki().Wiki_domain_(Bry_.new_a7(wiki_domain));}
|
||||
public Xoi_wiki_props_alias alias_(int id, String alias) {return new Xoi_wiki_props_alias().Init_by_ctor(id, alias);}
|
||||
public Xoi_wiki_props_ns ns_(int id, boolean subpages_enabled) {return new Xoi_wiki_props_ns().Init_by_ctor(id, subpages_enabled);}
|
||||
public void Test_parse(String xml, Xoi_wiki_props_wiki expd) {
|
||||
Xoi_wiki_props_wiki actl = new Xoi_wiki_props_wiki();
|
||||
api.Parse(actl, xml);
|
||||
Tfds.Eq_str_lines(Xto_str(expd), Xto_str(actl));
|
||||
}
|
||||
public void Test_build(Xoi_wiki_props_wiki wiki, String expd) {
|
||||
api.Build_cfg(bfr, wiki);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
private String Xto_str(Xoi_wiki_props_wiki v) {
|
||||
int len = v.Alias_ary().length;
|
||||
bfr.Add_str_a7("aliases").Add_byte_nl();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoi_wiki_props_alias alias = v.Alias_ary()[i];
|
||||
bfr.Add_int_variable(alias.Id()).Add_byte_pipe().Add_str_u8(alias.Alias()).Add_byte_nl();
|
||||
}
|
||||
bfr.Add_str_a7("ns").Add_byte_nl();
|
||||
len = v.Ns_ary().length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoi_wiki_props_ns ns = v.Ns_ary()[i];
|
||||
bfr.Add_int_variable(ns.Id()).Add_byte_pipe().Add_int_bool(ns.Subpages_enabled()).Add_byte_nl();
|
||||
}
|
||||
bfr.Add_byte_nl();
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
class Xob_subpage_tst_fxt {
|
||||
public Xob_subpage_tst_fxt Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
mgr = app.Bldr().Wiki_cfg_bldr();
|
||||
}
|
||||
mgr.Clear();
|
||||
hash.Clear();
|
||||
return this;
|
||||
} private Xoae_app app; Xob_wiki_cfg_bldr mgr; Ordered_hash hash = Ordered_hash_.New();
|
||||
private Xob_subpage_parser parser = new Xob_subpage_parser();
|
||||
public Xob_subpage_tst_fxt Init_cmd(String wiki, String key, String text) {
|
||||
// mgr.Itms_get_or_new(wiki).Itms_add(key, text);
|
||||
return this;
|
||||
}
|
||||
public Xob_subpage_tst_fxt Expd_txt(String wiki, String text) {
|
||||
// hash.Add(wiki, Keyval_.new_(wiki, text));
|
||||
return this;
|
||||
}
|
||||
private String_bldr sb = String_bldr_.new_();
|
||||
public void Test_parse(String s) {
|
||||
Xob_subpage_wiki[] actl = parser.Parse(Bry_.new_u8(s));
|
||||
Tfds.Eq_str_lines("", X_str_wikis(actl));
|
||||
}
|
||||
public String X_str_wikis(Xob_subpage_wiki[] ary) {
|
||||
X_str_wikis(sb, ary);
|
||||
return sb.To_str_and_clear();
|
||||
|
||||
}
|
||||
private void X_str_wikis(String_bldr sb, Xob_subpage_wiki[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xob_subpage_wiki wiki = ary[i];
|
||||
X_str_wiki(sb, wiki);
|
||||
}
|
||||
}
|
||||
private void X_str_wiki(String_bldr sb, Xob_subpage_wiki wiki) {
|
||||
sb.Add(wiki.Name()).Add_char_nl();
|
||||
int ns_len = wiki.Ns_list().Count();
|
||||
for (int i = 0; i < ns_len; i++) {
|
||||
Xob_subpage_ns ns = (Xob_subpage_ns)wiki.Ns_list().Get_at(i);
|
||||
sb.Add(ns.Id()).Add("=").Add(Bool_.To_str_lower(ns.Enabled())).Add_char_nl();
|
||||
}
|
||||
sb.Add_char_nl();
|
||||
}
|
||||
}
|
||||
41
400_xowa/src/gplx/xowa/bldrs/wkrs/Xob_io_utl__tst.java
Normal file
41
400_xowa/src/gplx/xowa/bldrs/wkrs/Xob_io_utl__tst.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xob_io_utl__tst {
|
||||
private final Xob_io_utl__fxt fxt = new Xob_io_utl__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__match(String_.Ary("a.txt", "b.txt", "c.txt"), "b", String_.Ary(".txt"), "b.txt");
|
||||
}
|
||||
@Test public void Include__ext() {// PURPOSE: handle calls like "a.sql", ".sql", ".gz"
|
||||
fxt.Test__match(String_.Ary("a.txt", "b.txt", "c.txt"), "b.txt", String_.Ary(".txt"), "b.txt");
|
||||
}
|
||||
@Test public void Dupe__pick_last() {
|
||||
fxt.Test__match(String_.Ary("b0.txt", "b1.txt", "b2.txt"), "b", String_.Ary(".txt"), "b2.txt");
|
||||
}
|
||||
@Test public void Ext() {
|
||||
fxt.Test__match(String_.Ary("b.txt", "b.png", "b.xml"), "b", String_.Ary(".xml", ".bz2"), "b.xml");
|
||||
}
|
||||
@Test public void Ext__dupes() {
|
||||
fxt.Test__match(String_.Ary("b.txt", "b.png", "b.xml"), "b", String_.Ary(".txt", ".xml"), "b.xml");
|
||||
}
|
||||
}
|
||||
class Xob_io_utl__fxt {
|
||||
public void Test__match(String[] path_ary, String name_pattern, String[] ext_ary, String expd) {
|
||||
Io_url actl = Xob_io_utl_.Find_nth_by_wildcard_or_null(Io_url_.Ary(path_ary), name_pattern, ext_ary);
|
||||
Gftest.Eq__str(expd, actl == null ? "<<NULL>>" : actl.Raw());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.wms.dump_pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xowmf_wiki_dump_dirs_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xowmf_wiki_dump_dirs_parser_fxt fxt = new Xowmf_wiki_dump_dirs_parser_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_parse("<a href=\"20141230/\">20141230/</a><a href=\"20150118/\">20150118/</a>", "20141230", "20150118");
|
||||
}
|
||||
@Test public void Example() { // http://dumps.wikimedia.org/jawiki/
|
||||
fxt.Test_parse(String_.Concat_lines_nl_skip_last
|
||||
( "<html>"
|
||||
, "<head><title>Index of /jawiki/</title></head>"
|
||||
, "<body bgcolor=\"white\">"
|
||||
, "<h1>Index of /jawiki/</h1><hr><pre><a href=\"../\">../</a>"
|
||||
, "<a href=\"20141122/\">20141122/</a> 25-Nov-2014 22:04 -"
|
||||
, "<a href=\"20141211/\">20141211/</a> 14-Dec-2014 09:25 -"
|
||||
, "<a href=\"20141230/\">20141230/</a> 02-Jan-2015 09:02 -"
|
||||
, "<a href=\"20150118/\">20150118/</a> 21-Jan-2015 04:39 -"
|
||||
, "<a href=\"20150221/\">20150221/</a> 24-Feb-2015 17:51 -"
|
||||
, "<a href=\"20150313/\">20150313/</a> 16-Mar-2015 14:37 -"
|
||||
, "<a href=\"20150402/\">20150402/</a> 05-Apr-2015 06:19 -"
|
||||
, "<a href=\"20150422/\">20150422/</a> 25-Apr-2015 13:52 -"
|
||||
, "<a href=\"20150512/\">20150512/</a> 15-May-2015 08:17 -"
|
||||
, "<a href=\"20150602/\">20150602/</a> 16-Jun-2015 01:34 -"
|
||||
, "<a href=\"20150703/\">20150703/</a> 08-Jul-2015 14:44 -"
|
||||
, "<a href=\"latest/\">latest/</a> 08-Jul-2015 14:44 -"
|
||||
, "</pre><hr></body>"
|
||||
, "</html>"
|
||||
)
|
||||
, "20141122"
|
||||
, "20141211"
|
||||
, "20141230"
|
||||
, "20150118"
|
||||
, "20150221"
|
||||
, "20150313"
|
||||
, "20150402"
|
||||
, "20150422"
|
||||
, "20150512"
|
||||
, "20150602"
|
||||
, "20150703"
|
||||
, "latest"
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xowmf_wiki_dump_dirs_parser_fxt {
|
||||
public void Clear() {}
|
||||
public void Test_parse(String src, String... expd_dates) {
|
||||
String[] actl_dates = Xowmf_wiki_dump_dirs_parser.Parse(Xow_domain_itm_.Bry__enwiki, Bry_.new_u8(src));
|
||||
Tfds.Eq_ary_str(expd_dates, actl_dates);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.wms.dumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
|
||||
import org.junit.*;
|
||||
public class Xowm_dump_file_tst {
|
||||
private final Xowm_dump_file_fxt fxt = new Xowm_dump_file_fxt();
|
||||
@Test public void Parse() {fxt.Test_parse("enwiki-20121201-pages-articles.xml.bz2", "en.wikipedia.org", "20121201", Xowm_dump_type_.Int__pages_articles);}
|
||||
@Test public void Bld_dump_dir_url() {
|
||||
fxt.Test_bld_dump_dir_url("simplewiki", "latest", "http://dumps.wikimedia.your.org/simplewiki/latest/");
|
||||
}
|
||||
@Test public void Bld_dump_file_name() {
|
||||
fxt.Test_bld_dump_file_name("simplewiki", "latest", Xowm_dump_type_.Str__pages_articles, "simplewiki-latest-pages-articles.xml.bz2");
|
||||
}
|
||||
}
|
||||
class Xowm_dump_file_fxt {
|
||||
public void Test_parse(String name, String domain, String date, int tid) {
|
||||
Xowm_dump_file dump_file = Xowm_dump_file_.parse(Bry_.new_u8(name));
|
||||
Tfds.Eq(domain , dump_file.Domain_itm().Domain_str());
|
||||
Tfds.Eq(date , dump_file.Dump_date());
|
||||
Tfds.Eq(tid , Xowm_dump_type_.parse_by_file(Bry_.new_u8(dump_file.Dump_type_str())));
|
||||
}
|
||||
public void Test_bld_dump_dir_url(String dump_file, String date, String expd) {
|
||||
byte[] actl = Xowm_dump_file_.Bld_dump_dir_url(Bry_.new_a7(Xowm_dump_file_.Server_your_org), Bry_.new_a7(dump_file), Bry_.new_a7(date));
|
||||
Tfds.Eq(expd, String_.new_a7(actl));
|
||||
}
|
||||
public void Test_bld_dump_file_name(String dump_file, String date, String dump_type, String expd) {
|
||||
byte[] actl = Xowm_dump_file_.Bld_dump_file_name(Bry_.new_a7(dump_file), Bry_.new_a7(date), Bry_.new_a7(dump_type), Xowm_dump_file_.Ext_xml_bz2);
|
||||
Tfds.Eq(expd, String_.new_a7(actl));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.wms.dumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
|
||||
import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.wikis.*;
|
||||
public class Xowm_dump_type__tst {
|
||||
private final Xowm_dump_type__fxt fxt = new Xowm_dump_type__fxt();
|
||||
@Test public void Parse() {
|
||||
fxt.Test_parse("pages-articles.xml" , Xowm_dump_type_.Int__pages_articles);
|
||||
fxt.Test_parse("pages-meta-current.xml" , Xowm_dump_type_.Int__pages_meta_current);
|
||||
}
|
||||
}
|
||||
class Xowm_dump_type__fxt {
|
||||
public void Test_parse(String raw_str, int expd) {Tfds.Eq_int(expd, Xowm_dump_type_.parse_by_file(Bry_.new_u8(raw_str)), "dump_type");}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.wms.revs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
|
||||
import org.junit.*; import gplx.langs.jsons.*; import gplx.core.net.*; import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xowm_rev_wkr__meta__wm_tst {
|
||||
private final Xowm_rev_wkr__meta__wm_fxt fxt = new Xowm_rev_wkr__meta__wm_fxt();
|
||||
@Before public void init() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();}
|
||||
@After public void term() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;}
|
||||
@Test public void Basic() {
|
||||
Wmapi_itm__pge[] expd = fxt.Make_pge_ary
|
||||
( fxt.Make_pge(Xow_ns_.Tid__main, "A", 1, 11, 100, "2015-01-01T01:01:01Z", "user1", "note1")
|
||||
, fxt.Make_pge(Xow_ns_.Tid__main, "B", 2, 22, 200, "2015-02-02T02:02:02Z", "user2", "note2")
|
||||
);
|
||||
fxt.Init_inet_upload(expd);
|
||||
fxt.Test_fetch(String_.Ary("A", "B"), expd); // test get both
|
||||
fxt.Init_inet_upload(expd);
|
||||
fxt.Test_fetch(String_.Ary("A") , expd[0]); // test get 1
|
||||
fxt.Init_inet_upload(expd);
|
||||
fxt.Test_fetch(String_.Ary("C"), fxt.Make_pge_empty(0, "C")); // test get none
|
||||
fxt.Init_inet_upload(expd);
|
||||
fxt.Test_fetch(String_.Ary("A", "B", "C"), expd[0], expd[1], fxt.Make_pge_empty(0, "C")); // test get too many
|
||||
}
|
||||
}
|
||||
class Xowm_rev_wkr__meta__wm_fxt {
|
||||
private final String domain_str = Xow_domain_itm_.Str__enwiki;
|
||||
private final Ordered_hash rev_hash = Ordered_hash_.New_bry();
|
||||
private final Xowm_rev_wkr__meta__wm meta_wkr = new Xowm_rev_wkr__meta__wm();
|
||||
private final Wmapi_itm_json_wtr json_wtr = new Wmapi_itm_json_wtr();
|
||||
public Xowm_rev_wkr__meta__wm_fxt() {
|
||||
meta_wkr.Inet_conn_(Gfo_inet_conn_.new_mem_pile());
|
||||
}
|
||||
public Wmapi_itm__pge[] Make_pge_ary(Wmapi_itm__pge... ary) {return ary;}
|
||||
public Wmapi_itm__pge Make_pge_empty(int page_ns, String page_ttl) {
|
||||
Wmapi_itm__pge rv = Make_pge(page_ns, page_ttl, 0, 0, 0, null, null, null);
|
||||
rv.Rvn_ary_(Wmapi_itm__rvn.Ary_empty);
|
||||
return rv;
|
||||
}
|
||||
public Wmapi_itm__pge Make_pge(int page_ns, String page_ttl, int page_id, int rev_id, int rev_len, String rev_time, String rev_user, String rev_note) {
|
||||
Wmapi_itm__pge rv = new Wmapi_itm__pge();
|
||||
rv.Init_id(page_id);
|
||||
rv.Init_ttl(page_ns, Bry_.new_u8(page_ttl));
|
||||
Wmapi_itm__rvn rvn = new Wmapi_itm__rvn();
|
||||
rv.Rvn_ary_(rvn);
|
||||
rvn.Init(rev_id, rev_len, Bry_.new_a7(rev_time), Bry_.new_a7(rev_user), Bry_.new_a7(rev_note));
|
||||
return rv;
|
||||
}
|
||||
public void Init_inet_upload(Wmapi_itm__pge... ary) {
|
||||
Gfo_inet_conn inet_conn = meta_wkr.Inet_conn();
|
||||
byte[] page = json_wtr.To_bry(ary);
|
||||
inet_conn.Clear();
|
||||
inet_conn.Upload_by_bytes(domain_str, page);
|
||||
}
|
||||
public void Test_fetch(String[] ttl_ary, Wmapi_itm__pge... expd) {
|
||||
Init_rev_hash(ttl_ary);
|
||||
meta_wkr.Fetch_meta(domain_str, rev_hash, 0, rev_hash.Count());
|
||||
Tfds.Eq_str_lines(String_.new_u8(json_wtr.To_bry(expd)), String_.new_u8(json_wtr.To_bry((Wmapi_itm__pge[])rev_hash.To_ary_and_clear(Wmapi_itm__pge.class))));
|
||||
}
|
||||
private void Init_rev_hash(String[] ttl_ary) {
|
||||
rev_hash.Clear();
|
||||
int len = ttl_ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String ttl_str = ttl_ary[i];
|
||||
byte[] ttl_bry = Bry_.new_u8(ttl_str);
|
||||
rev_hash.Add(ttl_bry, new Wmapi_itm__pge().Init_ttl(Xow_ns_.Tid__main, ttl_bry));
|
||||
}
|
||||
}
|
||||
}
|
||||
429
400_xowa/src/gplx/xowa/bldrs/wms/sites/Site_json_parser_tst.java
Normal file
429
400_xowa/src/gplx/xowa/bldrs/wms/sites/Site_json_parser_tst.java
Normal file
@@ -0,0 +1,429 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
|
||||
import org.junit.*; import gplx.langs.jsons.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Site_json_parser_tst {
|
||||
private final Site_json_parser_fxt fxt = new Site_json_parser_fxt();
|
||||
@Before public void init() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();}
|
||||
@After public void term() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;}
|
||||
@Test public void General() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'general':"
|
||||
, " { 'mainpage': 'Main Page'"
|
||||
, " , 'imagewhitelistenabled': ''"
|
||||
, " , 'timeoffset': 0"
|
||||
, " , 'thumblimits': "
|
||||
, " [ 120"
|
||||
, " , 150"
|
||||
, " ]"
|
||||
, " , 'imagelimits': "
|
||||
, " [ "
|
||||
, " { 'width': 320"
|
||||
, " , 'height': 240"
|
||||
, " }"
|
||||
, " , "
|
||||
, " { 'width': 640"
|
||||
, " , 'height': 480"
|
||||
, " }"
|
||||
, " ]"
|
||||
, " }"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_general(Keyval_.new_("mainpage", "Main Page"), Keyval_.new_("imagewhitelistenabled", ""), Keyval_.new_("timeoffset", "0"), Keyval_.new_("thumblimits", "120|150"), Keyval_.new_("imagelimits", "320=240|640=480"));
|
||||
}
|
||||
@Test public void Namespace() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'namespaces':"
|
||||
, " { '0':"
|
||||
, " { 'id': 0"
|
||||
, " , 'case': 'first-letter'"
|
||||
, " , 'content': ''"
|
||||
, " , '*': ''"
|
||||
, " }"
|
||||
, " , '2': "
|
||||
, " { 'id': 2"
|
||||
, " , 'case': 'first-letter'"
|
||||
, " , 'subpages': ''"
|
||||
, " , 'canonical': 'User'"
|
||||
, " , '*': 'User'"
|
||||
, " }"
|
||||
, " ,'4': "
|
||||
, " { 'id': 4"
|
||||
, " , 'case': 'first-letter'"
|
||||
, " , 'subpages': ''"
|
||||
, " , 'canonical': 'Project'"
|
||||
, " , '*': 'Wikipedia'"
|
||||
, " }"
|
||||
, " ,'2600': "
|
||||
, " { 'id': 2600"
|
||||
, " , 'case': 'case-sensitive'"
|
||||
, " , 'canonical': 'Topic'"
|
||||
, " , 'defaultcontentmodel': 'flow-board'"
|
||||
, " , '*': 'Topic'"
|
||||
, " }"
|
||||
, " }"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_namespace
|
||||
( fxt.Make_namespace(0 , Bool_.N, null , "" , Bool_.N, Bool_.Y, null)
|
||||
, fxt.Make_namespace(2 , Bool_.N, "User" , "User" , Bool_.Y, Bool_.N, null)
|
||||
, fxt.Make_namespace(4 , Bool_.N, "Project" , "Wikipedia" , Bool_.Y, Bool_.N, null)
|
||||
, fxt.Make_namespace(2600 , Bool_.Y, "Topic" , "Topic" , Bool_.N, Bool_.N, "flow-board")
|
||||
);
|
||||
}
|
||||
@Test public void Statistic() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'statistics':"
|
||||
, " { 'pages': 1"
|
||||
, " , 'articles': 2"
|
||||
, " , 'edits': 3"
|
||||
, " , 'images': 4"
|
||||
, " , 'users': 5"
|
||||
, " , 'activeusers': 6"
|
||||
, " , 'admins': 7"
|
||||
, " , 'jobs': 8"
|
||||
, " , 'queued-massmessages': 9"
|
||||
, " }"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_statistic
|
||||
( fxt.Make_statistic(1, 2, 3, 4, 5, 6, 7, 8, 9)
|
||||
);
|
||||
}
|
||||
@Test public void Interwikimap() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'interwikimap':"
|
||||
, " ["
|
||||
, " { 'prefix': 'aquariumwiki'"
|
||||
, " , 'url': 'http://www.theaquariumwiki.com/$1'"
|
||||
, " }"
|
||||
, " , { 'prefix': 'ar'"
|
||||
, " , 'local': ''"
|
||||
, " , 'extralanglink': ''"
|
||||
, " , 'linktext': 'More languages'"
|
||||
, " , 'sitename': 'Multilingual Wikisource'"
|
||||
, " , 'language': '\u0627\u0644\u0639\u0631\u0628\u064a\u0629'"
|
||||
, " , 'url': 'https://ar.wikipedia.org/wiki/$1'"
|
||||
, " , 'protorel': ''"
|
||||
, " }"
|
||||
, " ]"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_interwikimap
|
||||
( fxt.Make_interwikimap("aquariumwiki" , Bool_.N, Bool_.N, null , null , null , Bool_.N, "http://www.theaquariumwiki.com/$1" , Bool_.N)
|
||||
, fxt.Make_interwikimap("ar" , Bool_.Y, Bool_.Y, "More languages", "Multilingual Wikisource" , "العربية" , Bool_.N, "https://ar.wikipedia.org/wiki/$1" , Bool_.Y)
|
||||
);
|
||||
}
|
||||
@Test public void Namespacealias() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'namespacealiases':"
|
||||
, " [ "
|
||||
, " { 'id': 4"
|
||||
, " , '*': 'WP'"
|
||||
, " }"
|
||||
, " , "
|
||||
, " { 'id': 7"
|
||||
, " , '*': 'Image talk'"
|
||||
, " }"
|
||||
, " ]"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_namespacealias
|
||||
( fxt.Make_namespacealias(4 ,"WP")
|
||||
, fxt.Make_namespacealias(7 , "Image talk")
|
||||
);
|
||||
}
|
||||
@Test public void Specialpagealias() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'specialpagealiases':"
|
||||
, " [ "
|
||||
, " { 'realname': 'BrokenRedirects'"
|
||||
, " , 'aliases': "
|
||||
, " [ 'BrokenRedirects'"
|
||||
, " ]"
|
||||
, " }"
|
||||
, " , "
|
||||
, " { 'realname': 'Lonelypages'"
|
||||
, " , 'aliases': "
|
||||
, " [ 'LonelyPages'"
|
||||
, " , 'OrphanedPages'"
|
||||
, " ]"
|
||||
, " }"
|
||||
, " ]"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_specialpagealias
|
||||
( fxt.Make_specialpagealias("BrokenRedirects" , "BrokenRedirects")
|
||||
, fxt.Make_specialpagealias("Lonelypages" , "LonelyPages", "OrphanedPages")
|
||||
);
|
||||
}
|
||||
@Test public void Library() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'libraries':"
|
||||
, " [ "
|
||||
, " { 'name': 'cssjanus/cssjanus'"
|
||||
, " , 'version': '1.1.1'"
|
||||
, " }"
|
||||
, " , "
|
||||
, " { 'name': 'leafo/lessphp'"
|
||||
, " , 'version': '0.5.0'"
|
||||
, " }"
|
||||
, " ]"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_library
|
||||
( fxt.Make_library("cssjanus/cssjanus" , "1.1.1")
|
||||
, fxt.Make_library("leafo/lessphp" , "0.5.0")
|
||||
);
|
||||
}
|
||||
@Test public void Extension() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'extensions':"
|
||||
, " [ "
|
||||
, " { 'type': 'media'"
|
||||
, " , 'name': 'PagedTiffHandler'"
|
||||
, " , 'descriptionmsg': 'tiff-desc'"
|
||||
, " , 'author': '[http://www.hallowelt.biz HalloWelt! Medienwerkstatt GmbH], Sebastian Ulbricht, Daniel Lynge, Marc Reymann, Markus Glaser for Wikimedia Deutschland'"
|
||||
, " , 'url': 'https://www.mediawiki.org/wiki/Extension:PagedTiffHandler'"
|
||||
, " , 'vcs-system': 'git'"
|
||||
, " , 'vcs-version': 'b4a6c2077e3ea70cb0295b2282fe45d2e9ae06ba'"
|
||||
, " , 'vcs-url': 'https://git.wikimedia.org/tree/mediawiki%2Fextensions%2FPagedTiffHandler.git/b4a6c2077e3ea70cb0295b2282fe45d2e9ae06ba'"
|
||||
, " , 'vcs-date': '2015-03-27T16:44:25Z'"
|
||||
, " , 'license-name': 'GPL-2.0+'"
|
||||
, " , 'license': '/wiki/Special:Version/License/PagedTiffHandler'"
|
||||
, " }"
|
||||
, " , "
|
||||
, " { 'type': 'media'"
|
||||
, " , 'name': 'A'"
|
||||
, " , 'namemsg': 'A-name'"
|
||||
, " , 'description': 'desc'"
|
||||
, " , 'descriptionmsg': 'A-desc'"
|
||||
, " , 'author': 'B'"
|
||||
, " , 'url': 'C'"
|
||||
, " , 'version': '0.1.0'"
|
||||
, " , 'vcs-system': 'git'"
|
||||
, " , 'vcs-version': 'd'"
|
||||
, " , 'vcs-url': 'e'"
|
||||
, " , 'vcs-date': '2015-03-27T16:44:25Z'"
|
||||
, " , 'license-name': 'f'"
|
||||
, " , 'license': 'g'"
|
||||
, " }"
|
||||
, " ]"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_extension
|
||||
( fxt.Make_extension("media", "PagedTiffHandler", "", "", "tiff-desc", "[http://www.hallowelt.biz HalloWelt! Medienwerkstatt GmbH], Sebastian Ulbricht, Daniel Lynge, Marc Reymann, Markus Glaser for Wikimedia Deutschland", "https://www.mediawiki.org/wiki/Extension:PagedTiffHandler", null, "git", "b4a6c2077e3ea70cb0295b2282fe45d2e9ae06ba", "https://git.wikimedia.org/tree/mediawiki%2Fextensions%2FPagedTiffHandler.git/b4a6c2077e3ea70cb0295b2282fe45d2e9ae06ba", "2015-03-27T16:44:25Z", "GPL-2.0+", "/wiki/Special:Version/License/PagedTiffHandler", null)
|
||||
, fxt.Make_extension("media", "A", "A-name", "desc", "A-desc", "B", "C", "0.1.0", "git", "d", "e", "2015-03-27T16:44:25Z", "f", "g", null)
|
||||
);
|
||||
}
|
||||
@Test public void Skin() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'skins':"
|
||||
, " [ "
|
||||
, " { 'code': 'vector'"
|
||||
, " , 'default': ''"
|
||||
, " , '*': 'Vector'"
|
||||
, " }"
|
||||
, " , "
|
||||
, " { 'code': 'monobook'"
|
||||
, " , '*': 'MonoBook'"
|
||||
, " }"
|
||||
, " , "
|
||||
, " { 'code': 'fallback'"
|
||||
, " , 'unusable': ''"
|
||||
, " , '*': 'Fallback'"
|
||||
, " }"
|
||||
, " ]"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_skin
|
||||
( fxt.Make_skin("vector" , Bool_.Y, "Vector" , Bool_.N)
|
||||
, fxt.Make_skin("monobook" , Bool_.N, "MonoBook" , Bool_.N)
|
||||
, fxt.Make_skin("fallback" , Bool_.N, "Fallback" , Bool_.Y)
|
||||
);
|
||||
}
|
||||
@Test public void Magicword() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'magicwords':"
|
||||
, " [ "
|
||||
, " { 'name': 'expr'"
|
||||
, " , 'aliases': "
|
||||
, " [ 'expr'"
|
||||
, " ]"
|
||||
, " }"
|
||||
, " , "
|
||||
, " { 'name': 'currentmonth'"
|
||||
, " , 'aliases': "
|
||||
, " [ 'CURRENTMONTH'"
|
||||
, " , 'CURRENTMONTH2'"
|
||||
, " ]"
|
||||
, " , 'case-sensitive': ''"
|
||||
, " }"
|
||||
, " ]"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_magicword
|
||||
( fxt.Make_magicword("expr" , Bool_.N, "expr")
|
||||
, fxt.Make_magicword("currentmonth" , Bool_.Y, "CURRENTMONTH", "CURRENTMONTH2")
|
||||
);
|
||||
}
|
||||
@Test public void Functionhook() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'functionhooks':"
|
||||
, " [ 'ns'"
|
||||
, " , 'nse'"
|
||||
, " ]"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_functionhook("ns", "nse");
|
||||
}
|
||||
@Test public void Showhook() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'showhooks':"
|
||||
, " [ "
|
||||
, " { 'name': 'APIAfterExecute'"
|
||||
, " , 'subscribers': "
|
||||
, " [ 'ApiParseExtender::onAPIAfterExecute'"
|
||||
, " , 'ZeroBanner\\\\MccMncLogging::onAPIAfterExecute'"
|
||||
, " , 'XAnalytics::onAPIAfterExecute'"
|
||||
, " ]"
|
||||
, " }"
|
||||
, " , "
|
||||
, " { 'name': 'ParserLimitReport'"
|
||||
, " , 'subscribers': "
|
||||
, " { 'scribunto': 'ScribuntoHooks::reportLimits'"
|
||||
, " }"
|
||||
, " }"
|
||||
, " ]"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_showhook
|
||||
( fxt.Make_showhook("APIAfterExecute" , "", "ApiParseExtender::onAPIAfterExecute", "ZeroBanner\\MccMncLogging::onAPIAfterExecute", "XAnalytics::onAPIAfterExecute")
|
||||
, fxt.Make_showhook("ParserLimitReport" , "ScribuntoHooks::reportLimits")
|
||||
);
|
||||
}
|
||||
@Test public void Extensiontag() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'extensiontags':"
|
||||
, " [ '<pre>'"
|
||||
, " , '<nowiki>'"
|
||||
, " ]"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_extensiontag("<pre>", "<nowiki>");
|
||||
}
|
||||
@Test public void Protocol() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'protocols':"
|
||||
, " [ 'bitcoin:'"
|
||||
, " , 'ftp://'"
|
||||
, " ]"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_protocol("bitcoin:", "ftp://");
|
||||
}
|
||||
@Test public void Defaultoption() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'defaultoptions':"
|
||||
, " { 'globaluserpage': true"
|
||||
, " , 'cols': 80"
|
||||
, " , 'echo-email-format': 'html'"
|
||||
, " }"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_defaultoption(Keyval_.new_("globaluserpage", "true"), Keyval_.new_("cols", "80"), Keyval_.new_("echo-email-format", "html"));
|
||||
}
|
||||
@Test public void Language() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'languages':"
|
||||
, " [ "
|
||||
, " { 'code': 'aa'"
|
||||
, " , '*': 'Qaf\u00e1r af'"
|
||||
, " }"
|
||||
, " , "
|
||||
, " { 'code': 'ab'"
|
||||
, " , '*': '\u0410\u04a7\u0441\u0448\u04d9\u0430'"
|
||||
, " }"
|
||||
, " ]"
|
||||
, "}"
|
||||
));
|
||||
fxt.Test_language
|
||||
( fxt.Make_language("aa" , "Qafár af")
|
||||
, fxt.Make_language("ab" , "Аҧсшәа")
|
||||
);
|
||||
}
|
||||
// @Test public void Smoke() {
|
||||
// Io_url json_url = Tfds.RscDir.GenSubFil_nest("400_xowa", "site_meta__en.wikipedia.org.json");
|
||||
// byte[] src = Io_mgr.Instance.LoadFilBry(json_url);
|
||||
// Site_json_parser parser = new Site_json_parser();
|
||||
// Site_meta_itm meta_itm = new Site_meta_itm();
|
||||
// parser.Parse_root(meta_itm, "en.wikipedia.org", src);
|
||||
// gplx.dbs.Db_conn_bldr.Instance.Reg_default_sqlite();
|
||||
// Site_core_db core_db = new Site_core_db(Tfds.RscDir.GenSubFil_nest("400_xowa", "site_meta.sqlite3"));
|
||||
// core_db.Save(meta_itm, Bry_.new_a7("en.w"));
|
||||
// }
|
||||
}
|
||||
class Site_json_parser_fxt {
|
||||
private final Json_parser json_parser = new Json_parser();
|
||||
private final Site_json_parser site_meta_parser;
|
||||
private Site_meta_itm site_meta;
|
||||
public Site_json_parser_fxt() {
|
||||
this.site_meta_parser = new Site_json_parser(json_parser);
|
||||
}
|
||||
public void Exec_parse(String raw) {
|
||||
Json_doc jdoc = json_parser.Parse_by_apos(raw);
|
||||
site_meta = new Site_meta_itm();
|
||||
site_meta_parser.Parse_root(site_meta, "en.wikipedia.org", jdoc.Root_nde());
|
||||
}
|
||||
public Site_namespace_itm Make_namespace(int id, boolean case_tid_is_cs, String canonical, String localized, boolean subpages, boolean content, String defaultcontentmodel) {
|
||||
return new Site_namespace_itm(id, case_tid_is_cs ? Xow_ns_case_.Bry__all : Xow_ns_case_.Bry__1st, Bry_.new_u8_safe(canonical), Bry_.new_u8_safe(localized), subpages, content, Bry_.new_u8_safe(defaultcontentmodel));
|
||||
}
|
||||
public Site_statistic_itm Make_statistic(long pages, long articles, long edits, long images, long users, long activeusers, long admins, long jobs, long queued_massmessages) {return new Site_statistic_itm().Ctor(pages, articles, edits, images, users, activeusers, admins, jobs, queued_massmessages);}
|
||||
public Site_interwikimap_itm Make_interwikimap(String prefix, boolean local, boolean extralanglink, String linktext, String sitename, String language, boolean localinterwiki, String url, boolean protorel) {
|
||||
return new Site_interwikimap_itm(Bry_.new_u8_safe(prefix), local, extralanglink, Bry_.new_u8_safe(linktext), Bry_.new_u8_safe(sitename), Bry_.new_u8_safe(language), localinterwiki, Bry_.new_u8_safe(url), protorel);
|
||||
}
|
||||
public Site_namespacealias_itm Make_namespacealias(int id, String alias) {return new Site_namespacealias_itm(id, Bry_.new_u8_safe(alias));}
|
||||
public Site_specialpagealias_itm Make_specialpagealias(String realname, String... aliases) {return new Site_specialpagealias_itm(Bry_.new_u8_safe(realname), Bry_.Ary(aliases));}
|
||||
public Site_library_itm Make_library(String name, String version) {return new Site_library_itm(Bry_.new_u8_safe(name), Bry_.new_u8_safe(version));}
|
||||
public Site_extension_itm Make_extension
|
||||
( String type, String name, String namemsg, String description, String descriptionmsg, String author, String url, String version
|
||||
, String vcs_system, String vcs_version, String vcs_url, String vcs_date, String license_name, String license, String credits) {
|
||||
return new Site_extension_itm
|
||||
( Bry_.new_u8_safe(type), Bry_.new_u8_safe(name), Bry_.new_u8_safe(namemsg), Bry_.new_u8_safe(description), Bry_.new_u8_safe(descriptionmsg), Bry_.new_u8_safe(author), Bry_.new_u8_safe(url), Bry_.new_u8_safe(version)
|
||||
, Bry_.new_u8_safe(vcs_system), Bry_.new_u8_safe(vcs_version), Bry_.new_u8_safe(vcs_url), Bry_.new_u8_safe(vcs_date), Bry_.new_u8_safe(license_name), Bry_.new_u8_safe(license), Bry_.new_u8_safe(credits)
|
||||
);
|
||||
}
|
||||
public Site_skin_itm Make_skin(String code, boolean dflt, String name, boolean unusable) {return new Site_skin_itm(Bry_.new_u8_safe(code), dflt, Bry_.new_u8_safe(name), unusable);}
|
||||
public Site_magicword_itm Make_magicword(String name, boolean case_match, String... aliases) {return new Site_magicword_itm(Bry_.new_u8_safe(name), case_match, Bry_.Ary(aliases));}
|
||||
public Site_showhook_itm Make_showhook(String name, String scribunto, String... subscribers) {return new Site_showhook_itm(Bry_.new_u8_safe(name), Bry_.new_u8_safe(scribunto), Bry_.Ary(subscribers));}
|
||||
public Site_language_itm Make_language(String code, String name) {return new Site_language_itm(Bry_.new_u8_safe(code), Bry_.new_u8_safe(name));}
|
||||
public void Test_general(Keyval... expd) {Tfds.Eq_ary_str(expd, (Keyval[])site_meta.General_list().To_ary(Keyval.class));}
|
||||
public void Test_namespace(Site_namespace_itm... expd) {Tfds.Eq_ary_str(expd, (Site_namespace_itm[])site_meta.Namespace_list().To_ary(Site_namespace_itm.class));}
|
||||
public void Test_statistic(Site_statistic_itm expd) {Tfds.Eq_str_intf(expd, site_meta.Statistic_itm());}
|
||||
public void Test_interwikimap(Site_interwikimap_itm... expd) {Tfds.Eq_ary_str(expd, (Site_interwikimap_itm[])site_meta.Interwikimap_list().To_ary(Site_interwikimap_itm.class));}
|
||||
public void Test_namespacealias(Site_namespacealias_itm... expd) {Tfds.Eq_ary_str(expd, (Site_namespacealias_itm[])site_meta.Namespacealias_list().To_ary(Site_namespacealias_itm.class));}
|
||||
public void Test_specialpagealias(Site_specialpagealias_itm... expd) {Tfds.Eq_ary_str(expd, (Site_specialpagealias_itm[])site_meta.Specialpagealias_list().To_ary(Site_specialpagealias_itm.class));}
|
||||
public void Test_library(Site_library_itm... expd) {Tfds.Eq_ary_str(expd, (Site_library_itm[])site_meta.Library_list().To_ary(Site_library_itm.class));}
|
||||
public void Test_extension(Site_extension_itm... expd) {Tfds.Eq_ary_str(expd, (Site_extension_itm[])site_meta.Extension_list().To_ary(Site_extension_itm.class));}
|
||||
public void Test_skin(Site_skin_itm... expd) {Tfds.Eq_ary_str(expd, (Site_skin_itm[])site_meta.Skin_list().To_ary(Site_skin_itm.class));}
|
||||
public void Test_magicword(Site_magicword_itm... expd) {Tfds.Eq_ary_str(expd, (Site_magicword_itm[])site_meta.Magicword_list().To_ary(Site_magicword_itm.class));}
|
||||
public void Test_functionhook(String... expd) {Tfds.Eq_ary_str(expd, String_.Ary((byte[][])site_meta.Functionhook_list().To_ary(byte[].class)));}
|
||||
public void Test_showhook(Site_showhook_itm... expd) {Tfds.Eq_ary_str(expd, (Site_showhook_itm[])site_meta.Showhook_list().To_ary(Site_showhook_itm.class));}
|
||||
public void Test_extensiontag(String... expd) {Tfds.Eq_ary_str(expd, String_.Ary((byte[][])site_meta.Extensiontag_list().To_ary(byte[].class)));}
|
||||
public void Test_protocol(String... expd) {Tfds.Eq_ary_str(expd, String_.Ary((byte[][])site_meta.Protocol_list().To_ary(byte[].class)));}
|
||||
public void Test_defaultoption(Keyval... expd) {Tfds.Eq_ary_str(expd, (Keyval[])site_meta.Defaultoption_list().To_ary(Keyval.class));}
|
||||
public void Test_language(Site_language_itm... expd) {Tfds.Eq_ary_str(expd, (Site_language_itm[])site_meta.Language_list().To_ary(Site_language_itm.class));}
|
||||
}
|
||||
100
400_xowa/src/gplx/xowa/bldrs/xmls/Xob_xml_dumper_tst.java
Normal file
100
400_xowa/src/gplx/xowa/bldrs/xmls/Xob_xml_dumper_tst.java
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xob_xml_dumper_tst {
|
||||
private final Xob_xml_dumper_fxt fxt = new Xob_xml_dumper_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt.Test_page(fxt.Make_ary(fxt.Make_page(1, Xow_ns_.Tid__main, "A", "A_text")), String_.Concat_lines_nl_skip_last
|
||||
( "<mediawiki xmlns='http://www.mediawiki.org/xml/export-0.10/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.mediawiki.org/xml/export-0.10/ http://www.mediawiki.org/xml/export-0.10.xsd' version='0.10' xml:lang='en'>"
|
||||
, " <siteinfo>"
|
||||
, " <sitename>other</sitename>"
|
||||
, " <dbname></dbname>"
|
||||
, " <base>Main_Page</base>"
|
||||
, " <generator>XOWA 2.5.2.2</generator>"
|
||||
, " <case>first-letter</case>"
|
||||
, " </siteinfo>"
|
||||
, " <namespaces>"
|
||||
, " <namespace key='-2' case='first-letter'>Media</namespace>"
|
||||
, " <namespace key='-1' case='first-letter'>Special</namespace>"
|
||||
, " <namespace key='0' case='first-letter'></namespace>"
|
||||
, " <namespace key='1' case='first-letter'>Talk</namespace>"
|
||||
, " <namespace key='2' case='first-letter'>User</namespace>"
|
||||
, " <namespace key='3' case='first-letter'>User_talk</namespace>"
|
||||
, " <namespace key='4' case='first-letter'>Wikipedia</namespace>"
|
||||
, " <namespace key='5' case='first-letter'>Wikipedia_talk</namespace>"
|
||||
, " <namespace key='6' case='first-letter'>File</namespace>"
|
||||
, " <namespace key='7' case='first-letter'>File_talk</namespace>"
|
||||
, " <namespace key='8' case='first-letter'>MediaWiki</namespace>"
|
||||
, " <namespace key='9' case='first-letter'>MediaWiki_talk</namespace>"
|
||||
, " <namespace key='10' case='first-letter'>Template</namespace>"
|
||||
, " <namespace key='11' case='first-letter'>Template_talk</namespace>"
|
||||
, " <namespace key='12' case='first-letter'>Help</namespace>"
|
||||
, " <namespace key='13' case='first-letter'>Help_talk</namespace>"
|
||||
, " <namespace key='14' case='first-letter'>Category</namespace>"
|
||||
, " <namespace key='15' case='first-letter'>Category_talk</namespace>"
|
||||
, " <namespace key='100' case='first-letter'>Portal</namespace>"
|
||||
, " <namespace key='101' case='first-letter'>Portal_talk</namespace>"
|
||||
, " <namespace key='108' case='first-letter'>Book</namespace>"
|
||||
, " <namespace key='109' case='first-letter'>Book_talk</namespace>"
|
||||
, " <namespace key='828' case='first-letter'>Module</namespace>"
|
||||
, " <namespace key='829' case='first-letter'>Module_talk</namespace>"
|
||||
, " </namespaces>"
|
||||
, " <page>"
|
||||
, " <title>A</title>"
|
||||
, " <id>1</id>"
|
||||
, " <revision>"
|
||||
, " <id>-1</id>"
|
||||
, " <parent>-1</parent>"
|
||||
, " <timestamp>0001-01-01 00:00:00</timestamp>"
|
||||
, " <contributor>"
|
||||
, " <username></username>"
|
||||
, " <id>-1</id>"
|
||||
, " </contributor>"
|
||||
, " <comment></comment>"
|
||||
, " <model>wikitext</model>"
|
||||
, " <format>text/x-wiki</format>"
|
||||
, " <text xml:space='preserve'>A_text</text>"
|
||||
, " <sha1></sha1>"
|
||||
, " </revision>"
|
||||
, " </page>"
|
||||
, "</mediawiki>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xob_xml_dumper_fxt {
|
||||
private Xowe_wiki wiki;
|
||||
private final Xob_xml_dumper export_wtr = new Xob_xml_dumper();
|
||||
public void Clear() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
this.wiki = Xoa_app_fxt.Make__wiki__edit(app, "enwiki");
|
||||
}
|
||||
public Xowd_page_itm[] Make_ary(Xowd_page_itm... ary) {return ary;}
|
||||
public Xowd_page_itm Make_page(int id, int ns_id, String ttl_str, String text) {
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(ns_id, Bry_.new_u8(ttl_str));
|
||||
return new Xowd_page_itm().Id_(id).Ns_id_(ns_id).Ttl_(ttl).Text_(Bry_.new_u8(text));
|
||||
}
|
||||
public void Test_page(Xowd_page_itm[] ary, String expd) {
|
||||
export_wtr.Write_root_bgn(wiki.Ns_mgr(), wiki.Domain_itm(), "", String_.new_u8(wiki.Props().Main_page()), "first-letter", "XOWA 2.5.2.2");
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
export_wtr.Write_page(ary[i]);
|
||||
export_wtr.Write_root_end();
|
||||
String actl = export_wtr.Bld_str();
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
}
|
||||
146
400_xowa/src/gplx/xowa/bldrs/xmls/Xob_xml_parser_tst.java
Normal file
146
400_xowa/src/gplx/xowa/bldrs/xmls/Xob_xml_parser_tst.java
Normal file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.core.ios.*; import gplx.core.times.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xob_xml_parser_tst {
|
||||
@Before public void init() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
bldr = new Xob_bldr(app);
|
||||
} private Xow_ns_mgr ns_mgr = Xow_ns_mgr_.default_(gplx.xowa.langs.cases.Xol_case_mgr_.A7());
|
||||
@Test public void Basic_docs_1() {
|
||||
Xowd_page_itm doc = doc_(1, "a", "a a", Date_1);
|
||||
fil = page_bldr.Add(doc).XtoByteStreamRdr();
|
||||
tst_parse(fil, doc, 0);
|
||||
}
|
||||
@Test public void Basic_docs_2() {
|
||||
Xowd_page_itm doc1 = doc_(1, "a", "a a", Date_1);
|
||||
Xowd_page_itm doc2 = doc_(2, "b", "b b", Date_2);
|
||||
fil = page_bldr.Add_ary(doc1, doc2).XtoByteStreamRdr();
|
||||
int pos = tst_parse(fil, doc1, 0);
|
||||
tst_parse(fil, doc2, pos);
|
||||
}
|
||||
@Test public void Basic_space() {
|
||||
Xowd_page_itm doc1 = doc_(1, "a_b", "abc", Date_1);
|
||||
fil = page_bldr.Add_ary(doc1).Upd("a_b", "a b").XtoByteStreamRdr();
|
||||
tst_parse(fil, doc1, 0);
|
||||
}
|
||||
@Test public void Xml() {
|
||||
Xowd_page_itm doc = doc_(1, "a", ""a & b <> a | b"", Date_1);
|
||||
fil = page_bldr.Add(doc).XtoByteStreamRdr();
|
||||
tst_parse(fil, doc.Text_(Bry_.new_a7("\"a & b <> a | b\"")), 0);
|
||||
}
|
||||
@Test public void Tab() {
|
||||
Xowd_page_itm doc = doc_(1, "a", "a \t b", Date_1);
|
||||
fil = page_bldr.Add(doc).XtoByteStreamRdr();
|
||||
tst_parse(fil, doc.Text_(Bry_.new_a7("a 	 b")), 0);
|
||||
}
|
||||
@Test public void Tab_disable() {
|
||||
Xowd_page_itm doc = doc_(1, "a", "a \t b", Date_1);
|
||||
page_parser.Trie_tab_del_();
|
||||
fil = page_bldr.Add(doc).XtoByteStreamRdr();
|
||||
tst_parse(fil, doc.Text_(Bry_.new_a7("a \t b")), 0);
|
||||
}
|
||||
@Test public void Cr_nl() {
|
||||
Xowd_page_itm doc = doc_(1, "a", "a \r\n b", Date_1);
|
||||
fil = page_bldr.Add(doc).XtoByteStreamRdr();
|
||||
tst_parse(fil, doc.Text_(Bry_.new_a7("a \n b")), 0);
|
||||
}
|
||||
@Test public void Cr() {
|
||||
Xowd_page_itm doc = doc_(1, "a", "a \r b", Date_1);
|
||||
fil = page_bldr.Add(doc).XtoByteStreamRdr();
|
||||
tst_parse(fil, doc.Text_(Bry_.new_a7("a \n b")), 0);
|
||||
}
|
||||
@Test public void Text_long() {
|
||||
String s = String_.Repeat("a", 1024);
|
||||
Xowd_page_itm doc = doc_(1, "a", s, Date_1);
|
||||
page_parser.Tag_len_max_(32);
|
||||
fil = page_bldr.Add(doc).XtoByteStreamRdr(512);
|
||||
tst_parse(fil, doc, 0);
|
||||
}
|
||||
@Test public void Text_empty() {
|
||||
Xowd_page_itm doc = doc_(1, "a", "", Date_1);
|
||||
fil = page_bldr.Add(doc).Upd("<text></text>", "<text />").XtoByteStreamRdr();
|
||||
tst_parse(fil, doc, 0);
|
||||
}
|
||||
@Test public void Text_frag() {
|
||||
Xowd_page_itm doc = doc_(1, "a", "a", Date_1);
|
||||
fil = page_bldr.Add(doc).Upd("<text>a</text>", "<text xml:space=\"preserve\">a</text>").XtoByteStreamRdr();
|
||||
tst_parse(fil, doc, 0);
|
||||
}
|
||||
@Test public void Ns_file() {
|
||||
Xowd_page_itm doc = doc_(1, "File:a", "a", Date_1);
|
||||
Tfds.Eq(Xow_ns_.Tid__file, doc.Ns_id());
|
||||
Tfds.Eq("a", String_.new_u8(doc.Ttl_page_db()));
|
||||
}
|
||||
@Test public void Ns_main() {
|
||||
Xowd_page_itm doc = doc_(1, "a", "a", Date_1);
|
||||
Tfds.Eq(Xow_ns_.Tid__main, doc.Ns_id());
|
||||
Tfds.Eq("a", String_.new_u8(doc.Ttl_page_db()));
|
||||
}
|
||||
@Test public void Ns_main_book() {
|
||||
Xowd_page_itm doc = doc_(1, "Book", "a", Date_1);
|
||||
Tfds.Eq(Xow_ns_.Tid__main, doc.Ns_id());
|
||||
Tfds.Eq("Book", String_.new_u8(doc.Ttl_page_db()));
|
||||
}
|
||||
@Test public void XmlEntities() {
|
||||
Xowd_page_itm orig = doc_(1, "A&b", "a", Date_1);
|
||||
Xowd_page_itm actl = new Xowd_page_itm();
|
||||
fil = page_bldr.Add(orig).XtoByteStreamRdr();
|
||||
page_parser.Parse_page(actl, usr_dlg, fil, fil.Bfr(), 0, ns_mgr);
|
||||
Tfds.Eq("A&b", String_.new_u8(actl.Ttl_full_db()));
|
||||
}
|
||||
@Test public void Root() {
|
||||
Xowd_page_itm doc = doc_(1, "a", "a", Date_1);
|
||||
page_bldr.Bfr().Add_str_a7("<root>\n");
|
||||
page_bldr.Add(doc);
|
||||
page_bldr.Bfr().Add_str_a7("</root>");
|
||||
fil = page_bldr.XtoByteStreamRdr();
|
||||
tst_parse(fil, doc, 0);
|
||||
}
|
||||
private static final String Date_1 = "2012-01-01T01:01:01Z", Date_2 = "2012-02-02T02:02:02Z"; DateAdp_parser dateParser = DateAdp_parser.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
Xob_xml_page_bldr page_bldr = new Xob_xml_page_bldr(); Io_buffer_rdr fil; Xob_xml_parser page_parser = new Xob_xml_parser(); Xob_bldr bldr;
|
||||
Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Test();
|
||||
int tst_parse(Io_buffer_rdr fil, Xowd_page_itm expd, int cur_pos) {
|
||||
Xowd_page_itm actl = new Xowd_page_itm();
|
||||
int rv = page_parser.Parse_page(actl, usr_dlg, fil, fil.Bfr(), cur_pos, ns_mgr);
|
||||
Tfds.Eq(expd.Id(), actl.Id(), "id");
|
||||
Tfds.Eq(String_.new_u8(expd.Ttl_full_db()), String_.new_u8(actl.Ttl_full_db()), "title");
|
||||
Tfds.Eq(String_.new_u8(expd.Text()), String_.new_u8(actl.Text()), "text");
|
||||
Tfds.Eq_date(expd.Modified_on(), actl.Modified_on(), "timestamp");
|
||||
return rv;
|
||||
}
|
||||
Xowd_page_itm doc_(int id, String title, String text, String date) {
|
||||
Xowd_page_itm rv = new Xowd_page_itm().Id_(id).Ttl_(Bry_.new_a7(title), ns_mgr).Text_(Bry_.new_a7(text));
|
||||
int[] modified_on = new int[7];
|
||||
dateParser.Parse_iso8651_like(modified_on, date);
|
||||
rv.Modified_on_(DateAdp_.seg_(modified_on));
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Xob_xml_parser_fxt {
|
||||
// private final Xob_xml_parser page_parser = new Xob_xml_parser();
|
||||
// public void Test__parse(Io_buffer_rdr fil, Xowd_page_itm expd, int cur_pos) {
|
||||
// Xowd_page_itm actl = new Xowd_page_itm();
|
||||
// int rv = page_parser.Parse_page(actl, usr_dlg, fil, fil.Bfr(), cur_pos, ns_mgr);
|
||||
// Tfds.Eq(expd.Id(), actl.Id(), "id");
|
||||
// Tfds.Eq(String_.new_u8(expd.Ttl_full_db()), String_.new_u8(actl.Ttl_full_db()), "title");
|
||||
// Tfds.Eq(String_.new_u8(expd.Text()), String_.new_u8(actl.Text()), "text");
|
||||
// Tfds.Eq_date(expd.Modified_on(), actl.Modified_on(), "timestamp");
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user