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

Wikibase: Add basic support for getSetting

This commit is contained in:
gnosygnu
2018-07-01 07:15:13 -04:00
parent 341d2e13a4
commit 10c39e4c76
936 changed files with 275 additions and 70506 deletions

View File

@@ -1,48 +0,0 @@
/*
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.files; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*;
import gplx.xowa.files.origs.*; import gplx.xowa.files.repos.*;
public class Xof_file_fxt {
private final Xowe_wiki wiki;
Xof_file_fxt(Xowe_wiki wiki) {
this.wiki = wiki;
Io_mgr.Instance.InitEngine_mem();
Db_conn_bldr.Instance.Reg_default_mem();
wiki.File_mgr().Version_2_y_();
}
public static Xof_file_fxt new_(Xowe_wiki wiki) {return new Xof_file_fxt(wiki);}
public static Xof_file_fxt new_all(Xowe_wiki wiki) {return new Xof_file_fxt(wiki).Init_repos().Init_cache().Init_orig();}
public Xof_file_fxt Init_repos() {
Xow_repo_mgr_.Assert_repos(wiki.Appe(), wiki);
return this;
}
public Xof_file_fxt Init_cache() {
wiki.App().User().User_db_mgr().Init_by_app(Bool_.N, wiki.App().Fsys_mgr().Root_dir().GenSubFil_nest("user", "xowa.user.anonymous.sqlite3"));
return this;
}
public Xof_file_fxt Init_orig() {
Db_conn conn = Db_conn_bldr.Instance.Get_or_new(Io_url_.mem_fil_("mem/xowa/wiki/" + wiki.Domain_str() + "/orig.xowa")).Conn();
Xof_orig_tbl orig_tbl = new Xof_orig_tbl(conn, Bool_.Y);
orig_tbl.Create_tbl();
wiki.File_mgr().Orig_mgr().Init_by_wiki(wiki, Xof_fsdb_mode.New__v2__gui(), new Xof_orig_tbl[] {orig_tbl}, Xof_url_bldr.new_v2());
return this;
}
public void Exec_orig_add(boolean repo_is_commons, String orig_ttl, int orig_ext_id, int orig_w, int orig_h, String orig_redirect) {
byte repo_tid = repo_is_commons ? Xof_repo_tid_.Tid__remote : Xof_repo_tid_.Tid__local;
wiki.File_mgr().Orig_mgr().Insert(repo_tid, Bry_.new_u8(orig_ttl), orig_ext_id, orig_w, orig_h, Bry_.new_u8(orig_redirect));
}
}

View File

@@ -1,31 +0,0 @@
/*
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.files; import gplx.*; import gplx.xowa.*;
import org.junit.*;
public class Xof_file_wkr__tst {
private final Xof_file_wkr___fxt fxt = new Xof_file_wkr___fxt();
@Test public void Ttl_standardize() {
fxt.Test__ttl_standardize("Abc.png" , "Abc.png"); // basic
fxt.Test__ttl_standardize("A b.png" , "A_b.png"); // spaces -> unders
fxt.Test__ttl_standardize("A b c.png" , "A_b_c.png"); // spaces -> unders; multiple
fxt.Test__ttl_standardize("abc.png" , "Abc.png"); // ucase 1st
}
}
class Xof_file_wkr___fxt {
public void Test__ttl_standardize(String src_str, String expd) {
Tfds.Eq_bry(Bry_.new_u8(expd), Xof_file_wkr_.Ttl_standardize(Bry_.new_u8(src_str)));
}
}

View File

@@ -1,79 +0,0 @@
/*
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.files; import gplx.*; import gplx.xowa.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.files.repos.*;
import gplx.xowa.parsers.lnkis.*;
public class Xof_fsdb_itm_fxt {
private byte[] wiki_abrv;
private byte[] lnki_ttl;
private byte lnki_type;
private double lnki_upright;
private int lnki_w;
private int lnki_h;
private double lnki_time;
private int lnki_page;
private byte orig_repo_id;
private byte[] orig_repo_name;
private byte[] orig_ttl;
private Xof_ext orig_ext;
private int orig_w;
private int orig_h;
private byte[] orig_redirect;
public Xof_fsdb_itm_fxt() {this.Clear();}
public void Clear() {
this.wiki_abrv = lnki_ttl = null;
this.lnki_type = Xop_lnki_type.Id_null;
this.lnki_upright = Xof_img_size.Upright_null;
this.lnki_w = this.lnki_h = this.orig_w = this.orig_h = Xof_img_size.Size__neg1;
this.lnki_h = Xof_img_size.Size__neg1;
this.lnki_time = Xof_lnki_time.Null;
this.lnki_page = Xof_lnki_page.Null;
this.orig_repo_id = Xof_repo_tid_.Tid__null;
this.orig_repo_name = orig_ttl = orig_redirect = null;
this.orig_ext = null;
}
public Xof_fsdb_itm_fxt Lnki__en_w(String lnki_ttl_str) {
this.wiki_abrv = Abrv__en_w;
this.lnki_ttl = Bry_.new_u8(lnki_ttl_str);
return this;
}
public Xof_fsdb_itm_fxt Orig__commons__lnki() {
this.orig_repo_name = Xow_domain_itm_.Bry__commons;
this.orig_repo_id = Xof_repo_tid_.Tid__remote;
this.orig_ttl = lnki_ttl;
this.orig_ext = Xof_ext_.new_by_ttl_(orig_ttl);
this.orig_w = 880;
this.orig_w = 440;
return this;
}
public Xof_fsdb_itm_fxt Orig__enwiki__lnki() {
this.orig_repo_name = Xow_domain_itm_.Bry__enwiki;
this.orig_repo_id = Xof_repo_tid_.Tid__local;
this.orig_ttl = lnki_ttl;
this.orig_ext = Xof_ext_.new_by_ttl_(orig_ttl);
this.orig_w = 880;
this.orig_w = 440;
return this;
}
public Xof_fsdb_itm Make() {
Xof_fsdb_itm rv = new Xof_fsdb_itm();
rv.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, wiki_abrv, lnki_ttl, lnki_type, lnki_upright, lnki_w, lnki_h, lnki_time, lnki_page, Xof_patch_upright_tid_.Tid_all);
rv.Init_at_orig(orig_repo_id, orig_repo_name, orig_ttl, orig_ext, orig_w, orig_h, orig_redirect);
return rv;
}
private final static byte[] Abrv__en_w = Bry_.new_a7("en.w");
}

View File

@@ -1,105 +0,0 @@
/*
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.files; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.core.bits.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
public class Xof_img_size_tst {
private final Xof_img_size_fxt fxt = new Xof_img_size_fxt();
@Before public void init() {
fxt.Reset();
fxt.Orig_(400, 200);
}
@Test public void Lnki_lt_orig_null() {fxt.Lnki_type_(Xop_lnki_type.Id_null) .Lnki_(200, 100).Test_html(200, 100, Bool_.N);} // [[File:A.png|200px]] -> 200,100; File_is_orig = n
@Test public void Lnki_lt_orig_thumb() {fxt.Lnki_type_(Xop_lnki_type.Id_thumb) .Lnki_(200, 100).Test_html(200, 100, Bool_.N);} // [[File:A.png|thumb|200px]] -> 200,100; File_is_orig = n
@Test public void Lnki_lt_orig_frameless() {fxt.Lnki_type_(Xop_lnki_type.Id_frameless) .Lnki_(200, 100).Test_html(200, 100, Bool_.N);} // [[File:A.png|frameless|200px]] -> 200,100; File_is_orig = n
@Test public void Lnki_lt_orig_frame() {fxt.Lnki_type_(Xop_lnki_type.Id_frame) .Lnki_(200, -1).Test_html(400, 200, Bool_.Y);} // [[File:A.png|frame|200px]] -> 400,200; File_is_orig = y; frame always ignores parameters and returns orig
@Test public void Lnki_gt_orig_null() {fxt.Lnki_type_(Xop_lnki_type.Id_null) .Lnki_(800, 400).Test_html(800, 400, Bool_.Y);} // [[File:A.png|800px]] -> 800,400; File_is_orig = n
@Test public void Lnki_gt_orig_thumb() {fxt.Lnki_type_(Xop_lnki_type.Id_thumb) .Lnki_(800, 400).Test_html(400, 200, Bool_.Y);} // [[File:A.png|thumb|800px]] -> 400,200; File_is_orig = n
@Test public void Lnki_gt_orig_frameless() {fxt.Lnki_type_(Xop_lnki_type.Id_frameless) .Lnki_(800, 400).Test_html(400, 200, Bool_.Y);} // [[File:A.png|frameless|800px]] -> 400,200; File_is_orig = n
@Test public void Lnki_gt_orig_frame() {fxt.Lnki_type_(Xop_lnki_type.Id_frame) .Lnki_(800, -1).Test_html(400, 200, Bool_.Y);} // [[File:A.png|frame|800px]] -> 400,200; File_is_orig = y; frame always ignores parameters and returns orig
@Test public void Lnki_eq_orig_null() {fxt.Lnki_type_(Xop_lnki_type.Id_null) .Lnki_(400, 200).Test_html(400, 200, Bool_.Y);} // make sure File_is_orig = y
@Test public void Lnki_gt_orig_null_svg() {fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_type_(Xop_lnki_type.Id_null) .Lnki_(800, 400).Test_html(800, 400, Bool_.N);} // [[File:A.svg|800px]] -> 800,400; File_is_orig = n
@Test public void Lnki_gt_orig_thumb_svg() {fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_type_(Xop_lnki_type.Id_thumb) .Lnki_(800, 400).Test_html(800, 400, Bool_.N);} // [[File:A.svg|thumb|800px]] -> 800,400; File_is_orig = n
@Test public void Lnki_gt_orig_frameless_svg(){fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_type_(Xop_lnki_type.Id_frameless) .Lnki_(800, 400).Test_html(800, 400, Bool_.N);} // [[File:A.svg|frameless|800px]] -> 800,400; File_is_orig = n
@Test public void Lnki_gt_orig_frame_svg() {fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_type_(Xop_lnki_type.Id_frame) .Lnki_(800, -1).Test_html(400, 200, Bool_.N);} // [[File:A.svg|frame|800px]] -> 400,200; File_is_orig = n; frame always ignores parameters and returns orig
@Test public void Width_missing() {fxt.Lnki_( -1, 100).Test_html(200, 100);} // calc width based on height and orig
@Test public void Height_missing() {fxt.Lnki_(200, -1).Test_html(200, 100);}
@Test public void Orig_missing() {fxt.Lnki_(400, 200).Orig_( -1, -1).Test_html(400, 200);} // no orig_size; use lnki_w and lnki_h
@Test public void Lnki_missing() {fxt.Lnki_( -1, -1).Test_html(220, 110);} // w=thumbnail default; h=calc from orig
@Test public void Lnki_missing_frameless() {fxt.Lnki_( -1, -1).Lnki_type_(Xop_lnki_type.Id_frameless) .Test_html(220, 110, Bool_.N);} // default to thumb width
@Test public void Lnki_missing_null() {fxt.Lnki_( -1, -1).Lnki_type_(Xop_lnki_type.Id_null) .Test_html(400, 200, Bool_.Y);} // default to orig width
@Test public void Lnki_missing__orig_missing(){fxt.Lnki_( -1, -1).Orig_( -1, -1).Test_html(220, -1);} // no lnki or orig size; default to 220 with unknown height
@Test public void Prefer_height_over_width() {fxt.Lnki_(200, 100).Test_html(200, 100);} // prefer height; if width were preferred, size would be 200,134
@Test public void Upright() {fxt.Lnki_upright_(1).Lnki_(-1, -1).Orig_(440, 400).Test_html(220, 200);}
@Test public void Upright_w_thumb() {fxt.Lnki_type_(Xop_lnki_type.Id_thumb).Lnki_upright_(2).Lnki_(-1, -1).Orig_(1500, 1125).Test_html(440, 330);}
@Test public void Upright_ignored_by_w() {fxt.Lnki_type_(Xop_lnki_type.Id_thumb).Lnki_upright_(3.2).Lnki_(900, -1).Orig_(4653, 854).Test_html(900, 165);}// PAGE: fr.w:Bogota; DATE:2014-05-22
@Test public void Explicit_ratio_large() {fxt.Lnki_(120, 40).Test_html( 80, 40);} // see NOTE_2: lnki_ratio > orig_ratio
@Test public void Explicit_ratio_small() {fxt.Lnki_(120, 80).Test_html(120, 60);} // see NOTE_2: lnki_ratio > orig_ratio
@Test public void Lnki_gt_orig_null_svg_example() { // EX:[[File:Crystal Clear app kedit.svg|50x40px]]
fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_type_(Xop_lnki_type.Id_null).Lnki_( 50, 40).Orig_( 40, 40).Test_html( 40, 40);
}
@Test public void Prefer_height_over_width_example() {// EX:[[File:Firma B.Ohiggins.svg|128x80px|alt=|Bernardo O'Higgins's signature]]
fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_type_(Xop_lnki_type.Id_null).Lnki_(128, 80).Orig_(720, 194).Test_html(128, 34);
}
@Test public void Lnki_gt_orig_thumb_example() {// EX:[[File:Adhanema Lasva.jpg|thumb|300px|The Firman given to the Bosnian Franciscans]]
fxt.Lnki_type_(Xop_lnki_type.Id_thumb).Lnki_(300, -1).Orig_(149, 408).Test_html(149, 408, Bool_.Y);
}
@Test public void Upright_and_null_width_fails() {// PURPOSE: if width = -1, but upright is specified, ignore upright (was calculating 0 for width); DATE:2013-11-23
fxt.Lnki_type_(Xop_lnki_type.Id_null).Lnki_(-1, 110).Orig_(440, 220).Lnki_upright_(.50f).Test_html(220, 110, Bool_.N);
}
@Test public void Svg_null_width() { // PURPOSE: if svg and only height is specified, default width to 2048 (and recalc); DATE: 2013-11-26
fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_(-1, 40).Orig_(1, 1).Test_html(40, 40, Bool_.N); // NOTE: used to be 1,1
}
@Test public void Svg_max_width() { // PURPOSE: large width causes int overflow; vi.w:Danh_sách_quốc_kỳ DATE:2014-04-26
fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_(Int_.Max_value, 90).Orig_(900, 600).Test_html(135, 90, Bool_.N); // NOTE: used to be Int_.Max_value,90
}
@Test public void Pdf_none_defaults_to_thumb() { // PURPOSE: if no width is specified, pdf uses thumb width default, not orig width); DATE: 2013-11-27
fxt.Lnki_type_(Xop_lnki_type.Id_none).Lnki_ext_(Xof_ext_.Id_pdf).Lnki_(-1, -1).Orig_(440, 220).Test_html(220, 110, Bool_.N); // NOTE: used to be 1,1
}
@Test public void Frame() { // PURPOSE: frame incorrectly defaulted to file_is_orig; [[File:MESSENGER.jpg|200x200px|framed]]; DATE:2013-12-22
fxt.Lnki_type_(Xop_lnki_type.Id_frame).Lnki_ext_(Xof_ext_.Id_png).Lnki_(200, 200).Orig_(2038, 1529).Test_html(200, 150, Bool_.N);
}
@Test public void Frame_and_thumb(){ // PURPOSE: frame and thumb should be treated as frame; Enm.Has(val, Id_frame) vs val == Id_frame; PAGE:en.w:History_of_Western_Civilization; DATE:2015-04-16
fxt.Lnki_type_(Bitmask_.Add_byte(Xop_lnki_type.Id_frame, Xop_lnki_type.Id_thumb)).Lnki_(200, -1).Test_html(400, 200, Bool_.Y); // mut return same as Lnki_lt_orig_frame above
}
@Test public void Video__use_orig_w(){ // PURPOSE: video should use orig_w; DATE:2015-08-07
fxt.Lnki_type_(Xop_lnki_type.Id_none).Lnki_ext_(Xof_ext_.Id_ogv).Lnki_(-1, -1).Orig_(500, 250).Test_html(500, 250, Bool_.N);
}
@Test public void Video__use_thumb(){ // PURPOSE: video should use thumb_w, not orig_w; PAGE:en.w:Edward_Snowden DATE:2015-08-17
fxt.Lnki_type_(Xop_lnki_type.Id_thumb).Lnki_ext_(Xof_ext_.Id_ogv).Lnki_(-1, -1).Orig_(440, 220).Test_html(220, 110, Bool_.N);
}
}
class Xof_img_size_fxt {
private Xof_img_size img_size = new Xof_img_size();
public Xof_img_size_fxt Reset() {
lnki_type = Xop_lnki_type.Id_thumb;
lnki_ext = Xof_ext_.Id_jpg;
lnki_upright = Xof_img_size.Upright_null;
orig_w = orig_h = lnki_w = lnki_h = Xof_img_size.Null;
return this;
}
public Xof_img_size_fxt Lnki_type_(byte v) {lnki_type = v; return this;} private byte lnki_type;
public Xof_img_size_fxt Lnki_ext_(int v) {lnki_ext = v; return this;} private int lnki_ext;
public Xof_img_size_fxt Lnki_upright_(double v) {lnki_upright = v; return this;} private double lnki_upright;
public Xof_img_size_fxt Orig_(int w, int h) {orig_w = w; orig_h = h; return this;} private int orig_w, orig_h;
public Xof_img_size_fxt Lnki_(int w, int h) {lnki_w = w; lnki_h = h; return this;} private int lnki_w, lnki_h;
public void Test_html(int expd_w, int expd_h) {Test_html(expd_w, expd_h, false);}
public void Test_html(int expd_html_w, int expd_html_h, boolean expd_file_is_orig) {
img_size.Html_size_calc(Xof_exec_tid.Tid_wiki_page, lnki_w, lnki_h, lnki_type, Xof_patch_upright_tid_.Tid_all, lnki_upright, lnki_ext, orig_w, orig_h, Xof_img_size.Thumb_width_img);
Tfds.Eq(expd_html_w, img_size.Html_w(), "html_w");
Tfds.Eq(expd_html_h, img_size.Html_h(), "html_h");
Tfds.Eq(expd_file_is_orig, img_size.File_is_orig(), "file_is_orig");
}
}

View File

@@ -1,65 +0,0 @@
/*
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.files; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.imgs.*;
public class Xof_url_bldr__tst {
private Xof_url_bldr__fxt fxt = new Xof_url_bldr__fxt();
@Before public void init() {fxt.Clear().Dir_spr_http_();}
@Test public void Ogv() {fxt.Root_("http://test/").Md5_("d0").Ttl_("A.ogv").W_(220).Expd_src_("http://test/thumb/d/d0/A.ogv/220px--A.ogv.jpg").Test();}
@Test public void Ogv__seek() {fxt.Root_("http://test/").Md5_("d0").Ttl_("A.ogv").W_(220).Expd_src_("http://test/thumb/d/d0/A.ogv/220px-seek%3D5-A.ogv.jpg").Seek_(5).Test();}
@Test public void Ogv__no_w() {fxt.Root_("http://test/").Md5_("d0").Ttl_("A.ogv").W_( -1).Expd_src_("http://test/thumb/d/d0/A.ogv/-1px--A.ogv.jpg").Test();} // TODO_OLD: use orig_w, not -1
@Test public void Xcf() {fxt.Root_("http://test/").Md5_("44").Ttl_("A.xcf").W_(220).Expd_src_("http://test/thumb/4/44/A.xcf/220px-A.xcf.png").Test();}
@Test public void Bmp() {fxt.Root_("http://test/").Md5_("70").Ttl_("A.bmp").W_(220).Expd_src_("http://test/thumb/7/70/A.bmp/220px-A.bmp.png").Test();}
@Test public void Pdf() {fxt.Root_("http://test/").Md5_("ef").Ttl_("A.pdf").W_(220).Expd_src_("http://test/thumb/e/ef/A.pdf/page1-220px-A.pdf.jpg").Test();}
@Test public void Pdf__page_2() {fxt.Root_("http://test/").Md5_("ef").Ttl_("A.pdf").W_(220).Expd_src_("http://test/thumb/e/ef/A.pdf/page2-220px-A.pdf.jpg").Page_(2).Test();}
@Test public void Long() {
String filename = String_.Repeat("A", 200) + ".png";
fxt.Root_("http://test/").Md5_("14").Ttl_(filename).W_(220)
.Expd_src_("http://test/thumb/1/14/" + filename + "/220px-thumbnail.png")
.Test()
;
}
@Test public void Math__http() {fxt.Repo_tid_(Xof_repo_tid_.Tid__math).Fsys_is_wnt_(Bool_.N).Root_("http://test/").Ttl_("random_md5.svg").Expd_src_("http://test/random_md5").Test();} // NOTE: strip ".svg" if online
@Test public void Math__file() {fxt.Repo_tid_(Xof_repo_tid_.Tid__math).Fsys_is_wnt_(Bool_.Y).Root_("file://xowa/").Ttl_("random_md5.svg").Expd_src_("file://xowa/random_md5.svg").Test();} // NOTE: keep ".svg" if online
}
class Xof_url_bldr__fxt {
private final Xof_url_bldr url_bldr = new Xof_url_bldr();
public Xof_url_bldr__fxt Clear() {
dir_spr = Byte_.Zero; ext = null; root = md5 = ttl = expd_src = null;
seek = Xof_lnki_time.Null;
page = Xof_lnki_page.Null;
w = Xof_img_size.Null;
return this;
}
public Xof_url_bldr__fxt Dir_spr_http_() {return Dir_spr_(Byte_ascii.Slash);}
public Xof_url_bldr__fxt Dir_spr_fsys_wnt_() {return Dir_spr_(Byte_ascii.Backslash);}
public Xof_url_bldr__fxt Dir_spr_(byte v) {dir_spr = v; return this;} private byte dir_spr;
public Xof_url_bldr__fxt Root_(String v) {root = v; return this;} private String root;
public Xof_url_bldr__fxt Md5_(String v) {md5 = v; return this;} private String md5;
public Xof_url_bldr__fxt Ttl_(String v) {ttl = v; ext = Xof_ext_.new_by_ttl_(Bry_.new_u8(v)); return this;} private String ttl; Xof_ext ext;
public Xof_url_bldr__fxt W_(int v) {this.w = v; return this;} private int w;
public Xof_url_bldr__fxt Page_(int v) {page = v; return this;} private int page = Xof_lnki_page.Null;
public Xof_url_bldr__fxt Seek_(int v) {seek = v; return this;} private double seek = Xof_lnki_time.Null;
public Xof_url_bldr__fxt Repo_tid_(byte v) {repo_tid = v; return this;} private byte repo_tid = Xof_repo_tid_.Tid__null;
public Xof_url_bldr__fxt Fsys_is_wnt_(boolean v) {fsys_is_wnt = v; return this;} private boolean fsys_is_wnt;
public Xof_url_bldr__fxt Expd_src_(String v) {expd_src = v; return this;} private String expd_src;
public Xof_url_bldr__fxt Test() {
url_bldr.Init_by_repo(repo_tid, Bry_.new_u8(root), fsys_is_wnt, dir_spr, Bool_.Y, Bool_.N, 2);
url_bldr.Init_by_itm (Xof_img_mode_.Tid__thumb, Bry_.new_u8(ttl), Bry_.new_u8_safe(md5), ext, w, seek, page);
Tfds.Eq(expd_src, url_bldr.Xto_str());
return this;
}
}

View File

@@ -1,63 +0,0 @@
/*
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.files; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.core.primitives.*; import gplx.gfui.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
public class Xof_xfer_itm_tst {
@Before public void init() {fxt.ini();} Xof_xfer_itm_fxt fxt = new Xof_xfer_itm_fxt();
@Test public void Box() {tst_Calc_view("40,50" , "40,40" , "40,40");} // EX:[[File:Crystal Clear app kedit.svg|50x40px]]
@Test public void Long_w() {tst_Calc_view("128,80" , "720,194" , "128,34");} // EX:[[File:Firma B.Ohiggins.svg|128x80px|alt=|Bernardo O'Higgins's signature]]
@Test public void Long_h() {tst_Calc_view("300,-1" , "149,408" , "149,408");} // EX:[[File:Adhanema Lasva.jpg|thumb|300px|The Firman given to the Bosnian Franciscans]]
@Test public void Width_too_long() {tst_Calc_view("100,-1" , "40,40" , "40,40");} // limit to height;
@Test public void Width_missing() {tst_Calc_view("-1,20" , "80,40" , "40,20");} // calc width based on height and file_size
@Test public void Prefer_height_over_width() {tst_Calc_view("60,20" , "120,60" , "40,20");} // prefer height; if width was preferred, size would be 60,30
@Test public void Height_missing() {tst_Calc_view("50,-1" , "100,200" , "50,100");}
@Test public void Explicit_ratio_large() {tst_Calc_view("120,40" , "200,100" , "80,40");} // see NOTE_1:view ratio > file ratio
@Test public void Explicit_ratio_small() {tst_Calc_view("120,80" , "200,100" , "120,60");} // see NOTE_1:view ratio > file ratio
private void tst_Calc_view(String lnki_str, String file_str, String expd_str) {
Int_2_ref rv = new Int_2_ref();
Int_2_val lnki = Int_2_val.parse(lnki_str);
Int_2_val file = Int_2_val.parse(file_str);
Int_2_val expd = Int_2_val.parse(expd_str);
Xof_xfer_itm_.Calc_view(rv, Xop_lnki_type.Id_thumb, lnki.Val_0(), lnki.Val_1(), file.Val_0(), file.Val_1(), true);
Tfds.Eq(expd.Val_0(), rv.Val_0());
Tfds.Eq(expd.Val_1(), rv.Val_1());
}
@Test public void Thumb_lnkY() {fxt.Lnki_(300, 200).tst(300, 200);} // size provided; use
@Test public void Thumb_lnkN() {fxt.Lnki_( -1, -1).tst(220, -1);} // w=thumbnail default
@Test public void Thumb_lnkN_sqlY() {fxt.Lnki_( -1, -1).File_(220, 200).tst(220, 200);} // w=thumbnail default; h=calc from sql
@Test public void Thumb_lnkN_sqlY_adjH() {fxt.Lnki_( -1, -1).File_(440, 500).tst(220, 250);} // w=thumbnail default; h=calc from sql
@Test public void Thumb_lnkW_sqlY() {fxt.Lnki_(200, -1).File_(400, 500).tst(200, 250);} // w=lnki; h=calc from sql
@Test public void Thumb_lnkH_sqlY() {fxt.Lnki_( -1, 250).File_(400, 500).tst(200, 250);} // w=calc from sql
@Test public void Thumb_lnkW_sqlY_W_too_large() {fxt.Lnki_(600, 750).File_(400, 500).tst(400, 500);} // w/h: truncate to file
@Test public void Thumb_w_is_wrong() {fxt.Lnki_( 20, 20).File_( 80, 100).tst( 16, 20);}
@Test public void Thumb_w_is_wrong_2() {fxt.Lnki_( 65, 50).File_(160, 160).tst( 50, 50);}
@Test public void Thumb_size_is_wrong() {fxt.Lnki_(128, 80).File_(720, 194).tst(128, 34);}
}
class Xof_xfer_itm_fxt {
public Xof_xfer_itm_fxt ini() {lnki_img_type = Xop_lnki_type.Id_thumb; lnki_upright = -1; file_w = file_h = lnki_w = lnki_h = -1; return this;}
public Xof_xfer_itm_fxt Lnki_img_type_(byte v) {lnki_img_type = v; return this;} private byte lnki_img_type;
public Xof_xfer_itm_fxt Lnki_upright_(double v) {lnki_upright = v; return this;} double lnki_upright;
public Xof_xfer_itm_fxt File_(int w, int h) {file_w = w; file_h = h; return this;} private int file_w, file_h;
public Xof_xfer_itm_fxt Lnki_(int w, int h) {lnki_w = w; lnki_h = h; return this;} private int lnki_w, lnki_h;
public Xof_xfer_itm_fxt tst(int expd_w, int expd_h) {
boolean wmf_thumbable = Xof_xfer_itm_.Lnki_thumbable_calc(lnki_img_type, lnki_w, lnki_h);
Int_2_ref calc_size = new Int_2_ref();
Xof_xfer_itm_.Calc_xfer_size(calc_size, Xop_lnki_type.Id_thumb, Xof_img_size.Thumb_width_img, file_w, file_h, lnki_w, lnki_h, wmf_thumbable, lnki_upright);
Tfds.Eq(expd_w, calc_size.Val_0());
Tfds.Eq(expd_h, calc_size.Val_1());
return this;
}
}

View File

@@ -1,184 +0,0 @@
/*
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.files; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.core.primitives.*; import gplx.dbs.*;
import gplx.xowa.files.fsdb.*; import gplx.xowa.files.caches.*; import gplx.xowa.parsers.lnkis.*;
import gplx.xowa.apps.*; import gplx.xowa.wikis.*; import gplx.xowa.files.origs.*;
public class Xofv_file_mgr_tst {
// @Before public void init() {fxt.Clear();} private final Xofv_file_mgr_fxt fxt = new Xofv_file_mgr_fxt();
@After public void term() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;}
@Test public void Stub() {}
// @Test public void Thumb() {
// fxt .Init_orig_add(fxt.Mkr_orig().Init_comm("A.png", 440, 400))
// .Init_fsdb_add(fxt.Mkr_fsdb().Init_comm_thum("A.png", 220, 200))
// .Init_xfer_add(fxt.Mkr_xfer().Init_thumb(0, "A.png", 220, 200))
// .Exec_process_lnki()
// .Test_html_get(fxt.Mkr_html().Init(0, "file:///mem/xowa/file/comm/thumb/7/0/A.png/220px.png", 220, 200))
// .Test_fsys_get("mem/xowa/file/comm/thumb/7/0/A.png/220px.png")
// .Test_fsdb_download(1);
// ;
// }
// @Test public void Orig() {
// fxt .Init_orig_add(fxt.Mkr_orig().Init_comm("A.png", 440, 400))
// .Init_fsdb_add(fxt.Mkr_fsdb().Init_comm_orig("A.png", 440, 400))
// .Init_xfer_add(fxt.Mkr_xfer().Init_none(0, "A.png"))
// .Exec_process_lnki()
// .Test_html_get(fxt.Mkr_html().Init(0, "file:///mem/xowa/file/comm/orig/7/0/A.png", 440, 400))
// .Test_fsys_get("mem/xowa/file/comm/orig/7/0/A.png")
// .Test_fsdb_download(1);
// ;
// }
// @Test public void Img_size() { // PURPOSE: test integration of Xof_img_size
// fxt .Init_orig_add(fxt.Mkr_orig().Init_comm("A.png", 440, 400))
// .Init_fsdb_add(fxt.Mkr_fsdb().Init_comm_thum("A.png", 110, 100))
// .Init_xfer_add(fxt.Mkr_xfer().Init_thumb(0, "A.png", Xof_img_size.Null, Xof_img_size.Null).Upright_(.5f))
// .Exec_process_lnki()
// .Test_html_get(fxt.Mkr_html().Init(0, "file:///mem/xowa/file/comm/thumb/7/0/A.png/110px.png", 110, 100))
// .Test_fsys_get("mem/xowa/file/comm/thumb/7/0/A.png/110px.png")
// .Test_fsdb_download(1);
// ;
// }
// @Test public void Orig_mgr() { // PURPOSE: test integration of Orig_mgr
// fxt .Init_orig_add(fxt.Mkr_orig().Init_comm_redirect("B.jpg", "A.png", 440, 400)) // B.jpg redirects to A.png
// .Init_fsdb_add(fxt.Mkr_fsdb().Init_comm_thum("A.png", 220, 200))
// .Init_xfer_add(fxt.Mkr_xfer().Init_thumb(0, "B.jpg", 220, 200))
// .Exec_process_lnki()
// .Test_html_get(fxt.Mkr_html().Init(0, "file:///mem/xowa/file/comm/thumb/7/0/A.png/220px.png", 220, 200))
// .Test_fsys_get("mem/xowa/file/comm/thumb/7/0/A.png/220px.png")
// .Test_fsdb_download(1);
// ;
// }
// @Test public void Cache_exists() {
// fxt .Init_orig_add(fxt.Mkr_orig().Init_comm("A.png", 440, 400))
// .Init_fsdb_add(fxt.Mkr_fsdb().Init_comm_thum("A.png", 220, 200))
// .Init_xfer_add(fxt.Mkr_xfer().Init_thumb(0, "A.png", 220, 200))
// .Init_cache_add(fxt.Mkr_cache().Init("comm", "A.png", Bool_.N, 220)) // add to cache
// .Init_fsys_add("mem/xowa/file/comm/thumb/7/0/A.png/220px.png") // copy file to fsys
// .Exec_process_lnki()
// .Test_fsdb_download(0) // skip download
// ;
// }
// @Test public void Cache_absent() {
// fxt .Init_orig_add(fxt.Mkr_orig().Init_comm("A.png", 440, 400))
// .Init_fsdb_add(fxt.Mkr_fsdb().Init_comm_thum("A.png", 220, 200))
// .Init_xfer_add(fxt.Mkr_xfer().Init_thumb(0, "A.png", 220, 200))
// .Init_cache_add(fxt.Mkr_cache().Init("commons", "A.png", Bool_.N, 220)) // add to cache
// .Exec_process_lnki()
// .Test_fsdb_download(1) // do download
// ;
// }
}
// class Xofv_file_mgr_fxt {
// private Xofv_file_mgr file_mgr;
// public Xof_xfer_mkr Mkr_xfer() {return mkr_xfer;} private final Xof_xfer_mkr mkr_xfer = new Xof_xfer_mkr();
// public Xof_orig_itm_mkr Mkr_orig() {return mkr_orig;} private final Xof_orig_itm_mkr mkr_orig = new Xof_orig_itm_mkr();
// public Xof_fsdb_mkr Mkr_fsdb() {return mkr_fsdb;} private final Xof_fsdb_mkr mkr_fsdb = new Xof_fsdb_mkr();
// public Xou_cache_itm_mkr Mkr_cache() {return mkr_cache;} private final Xou_cache_itm_mkr mkr_cache = new Xou_cache_itm_mkr();
// public void Clear() {
// file_mgr = new Xofv_file_mgr(Bry_.Empty);
// Clear_repos();
// }
// private void Clear_repos() {
// Xofv_repo_mgr repo_mgr = file_mgr.Repo_mgr();
// Io_url root_dir = Io_url_.mem_dir_("mem/xowa/file/");
// Xofv_repo_itm repo_comm = Xofv_repo_itm.new_trg_fsys(Xofv_repo_itm.Tid_val_comm, Bry_.new_a7("comm"), root_dir.GenSubDir("comm"));
// Xofv_repo_itm repo_wiki = Xofv_repo_itm.new_trg_fsys(Xofv_repo_itm.Tid_val_wiki, Bry_.new_a7("wiki"), root_dir.GenSubDir("wiki"));
// repo_mgr.Add(repo_comm).Add(repo_wiki);
// mkr_orig.Setup_repos(repo_comm, repo_wiki);
// mkr_fsdb.Setup_repos(Bry_.new_a7("comm"), Bry_.new_a7("wiki"));
// }
// public Xofv_file_mgr_fxt Init_xfer_add(Xof_xfer_mkr mkr) {file_mgr.Reg(mkr.Make()); return this;}
// public Xofv_file_mgr_fxt Init_cache_add(Xou_cache_itm_mkr mkr) {mkr.Make(file_mgr.Cache_mgr()); return this;}
// public Xofv_file_mgr_fxt Init_fsys_add(String s) {Io_mgr.Instance.SaveFilStr(s, ""); return this;}
// public Xofv_file_mgr_fxt Exec_process_lnki() {file_mgr.Process_lnki(); return this;}
// public Xofv_file_mgr_fxt Test_fsys_get(String path) {
// Tfds.Eq_true(Io_mgr.Instance.ExistsFil(Io_url_.mem_fil_(path)), "fsys: " + path);
// return this;
// }
// }
class Xof_orig_itm_mkr {
private byte[] ttl_bry; private int ext, orig_w, orig_h; private Xofv_repo_itm repo;
private byte[] redirect_bry;
private Xofv_repo_itm repo_comm, repo_wiki;
public Xof_orig_itm_mkr() {this.Reset();}
private void Reset() {
redirect_bry = Bry_.Empty;
}
public void Setup_repos(Xofv_repo_itm repo_comm, Xofv_repo_itm repo_wiki) {this.repo_comm = repo_comm; this.repo_wiki = repo_wiki;}
public Xof_orig_itm_mkr Init_comm_redirect(String src, String trg, int orig_w, int orig_h) {return Init(Bool_.Y, src, trg, orig_w, orig_h);}
public Xof_orig_itm_mkr Init_comm(String ttl_str, int orig_w, int orig_h) {return Init(Bool_.Y, ttl_str, null, orig_w, orig_h);}
public Xof_orig_itm_mkr Init_wiki(String ttl_str, int orig_w, int orig_h) {return Init(Bool_.N, ttl_str, null, orig_w, orig_h);}
private Xof_orig_itm_mkr Init(boolean repo_is_comm, String ttl_str, String redirect_str, int orig_w, int orig_h) {
repo = repo_is_comm ? repo_comm : repo_wiki;
this.ttl_bry = Bry_.new_u8(ttl_str); this.orig_w = orig_w; this.orig_h = orig_h;
this.redirect_bry = redirect_str == null ? Bry_.Empty : Bry_.new_u8(redirect_str);
this.ext = Xof_ext_.new_by_ttl_(ttl_bry).Id();
return this;
}
public void Make(Xof_orig_wkr wkr) {
wkr.Add_orig(repo.Tid(), ttl_bry, ext, orig_w, orig_h, redirect_bry);
this.Reset();
}
}
class Xof_fsdb_mkr {
private byte[] repo_comm, repo_wiki, repo;
private byte[] ttl_bry; private byte lnki_type; private int file_w, file_h;
private double upright, time; private int page;
public Xof_fsdb_mkr() {this.Reset();}
public void Setup_repos(byte[] repo_comm, byte[] repo_wiki) {this.repo_comm = repo_comm; this.repo_wiki = repo_wiki;}
private void Reset() {
upright = Xop_lnki_tkn.Upright_null;
time = Xof_lnki_time.Null;
page = Xof_lnki_page.Null;
}
public Xof_fsdb_mkr Init_comm_thum(String ttl_str, int file_w, int file_h) {return Init(Bool_.Y, Bool_.N, ttl_str, file_w, file_h);}
public Xof_fsdb_mkr Init_comm_orig(String ttl_str, int file_w, int file_h) {return Init(Bool_.Y, Bool_.Y, ttl_str, file_w, file_h);}
public Xof_fsdb_mkr Init(boolean repo_is_commons, boolean file_is_orig, String ttl_str, int file_w, int file_h) {
this.lnki_type = file_is_orig ? Xop_lnki_type.Id_none : Xop_lnki_type.Id_thumb;
this.repo = repo_is_commons ? repo_comm : repo_wiki;
this.ttl_bry = Bry_.new_u8(ttl_str);
this.file_w = file_w; this.file_h = file_h;
return this;
}
public Xof_fsdb_itm Make() {
Xof_fsdb_itm rv = new Xof_fsdb_itm();
rv.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, Bry_.new_a7("en.w"), ttl_bry, lnki_type, upright, file_w, file_h, time, page, Xof_patch_upright_tid_.Tid_all);
rv.Orig_repo_name_(repo);
this.Reset();
return rv;
}
}
class Xou_cache_itm_mkr {
// private byte[] dir; private byte[] ttl; private boolean is_orig; private int w, h; private double time; private int page; private long size;
public Xou_cache_itm_mkr() {this.Reset();}
private void Reset() {
// this.time = Xof_lnki_time.Null;
// this.page = Xof_lnki_page.Null;
// this.h = 200;
// this.size = 1;
}
public Xou_cache_itm_mkr Init(String dir_str, String ttl_str, boolean is_orig, int w) {
// this.dir = Bry_.new_u8(dir_str);
// this.ttl = Bry_.new_u8(ttl_str);
// this.is_orig = is_orig;
// this.w = w;
return this;
}
public void Make(Xof_cache_mgr cache_mgr) {
// cache_mgr.Fil__make(dir, ttl, is_orig, w, h, time, page, size);
this.Reset();
}
}

View File

@@ -1,65 +0,0 @@
/*
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.files.bins; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import org.junit.*; import gplx.core.ios.*; import gplx.core.ios.streams.*; import gplx.xowa.files.repos.*;
public class Xof_bin_wkr__http_wmf__tst {
private final Xof_bin_wkr__http_wmf__fxt fxt = new Xof_bin_wkr__http_wmf__fxt();
@Before public void init() {fxt.Clear();}
@Test public void Basic() {
fxt.Init__Http("mem/http/commons.wikimedia.org/thumb/7/70/A.png/220px-A.png", "test_data");
fxt.Exec__Get_as_rdr(fxt.Fsdb_itm_mkr().Lnki__en_w("A.png").Orig__commons__lnki(), Bool_.Y, 220);
fxt.Test__Get_as_rdr__rdr("test_data");
}
@Test public void Enwiki_fails__fallback_to_commons() {
fxt.Init__Http("mem/http/commons.wikimedia.org/thumb/7/70/A.png/220px-A.png", "test_data"); // put file in commons
Xof_fsdb_itm fsdb_itm = fxt.Fsdb_itm_mkr().Lnki__en_w("A.png").Orig__enwiki__lnki().Make();
fxt.Exec__Get_as_rdr(fsdb_itm, Bool_.Y, 220); // look in enwiki
fxt.Test__Get_as_rdr__rdr("test_data"); // test that enwiki tries commons again
Tfds.Eq_str("commons.wikimedia.org", fsdb_itm.Orig_repo_name(), "repo_name"); // test that it's now commons
Tfds.Eq_byte(Xof_repo_tid_.Tid__remote, fsdb_itm.Orig_repo_id(), "repo_tid"); // test that it's now commons
}
@Test public void Long_filename_becomes_thumbnail() {
String filename = String_.Repeat("A", 200) + ".png";
fxt.Init__Http("mem/http/commons.wikimedia.org/thumb/1/14/" + filename + "/220px-thumbnail.png", "test_data"); // add file as "thumbnail.png"
Xof_fsdb_itm fsdb_itm = fxt.Fsdb_itm_mkr().Lnki__en_w(filename).Orig__enwiki__lnki().Make();
fxt.Exec__Get_as_rdr(fsdb_itm, Bool_.Y, 220); // look in enwiki
fxt.Test__Get_as_rdr__rdr("test_data"); // test that file is there
}
}
class Xof_bin_wkr__http_wmf__fxt {
private final Xof_bin_wkr__http_wmf wkr;
private final Io_download_mgr__memory download_mgr;
private Io_stream_rdr get_as_rdr__rdr;
public Xof_fsdb_itm_fxt Fsdb_itm_mkr() {return fsdb_itm_mkr;} private final Xof_fsdb_itm_fxt fsdb_itm_mkr = new Xof_fsdb_itm_fxt();
public Xof_bin_wkr__http_wmf__fxt() {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app);
Xoa_app_fxt.repo2_(app, wiki);
this.download_mgr = Io_download_mgr_.new_memory();
this.wkr = Xof_bin_wkr__http_wmf.new_(wiki, download_mgr);
}
public void Clear() {
download_mgr.Clear();
}
public void Init__Http(String url, String data) {download_mgr.Upload_data(url, Bry_.new_u8(data));}
public void Exec__Get_as_rdr(Xof_fsdb_itm_fxt fsdb_itm_mkr, boolean is_thumb, int w) {Exec__Get_as_rdr(fsdb_itm_mkr.Make(), is_thumb, w);}
public void Exec__Get_as_rdr(Xof_fsdb_itm fsdb_itm , boolean is_thumb, int w) {
this.get_as_rdr__rdr = wkr.Get_as_rdr(fsdb_itm, is_thumb, w);
}
public void Test__Get_as_rdr__rdr(String expd) {
Tfds.Eq_str(expd, Io_stream_rdr_.Load_all_as_str(get_as_rdr__rdr), "rdr_contents");
}
}

View File

@@ -1,70 +0,0 @@
/*
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.files.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import org.junit.*; import gplx.dbs.*;
public class Xof_cache_mgr_tst {
// @Before public void init() {fxt.Reset();} private Xof_cache_mgr_fxt fxt = new Xof_cache_mgr_fxt();
@Test public void Basic() {
// Xou_cache_itm itm = fxt.Bldr_itm("A.png").Make();
// fxt.Test_get_n(itm);
// fxt.Exec_update(itm);
// fxt.Test_get_y(itm);
// fxt.Test_viewed_data(1, 123);
// fxt.Exec_update(itm);
// fxt.Test_viewed_data(2, 124);
// fxt.Exec_db_save(itm);
// fxt.Test_db_itms(itm);
}
}
// class Xof_cache_mgr_fxt {
// public Xof_cache_mgr_fxt Reset() {
// return this;
// }
// }
// class Xof_cache_itm_mkr {
//// private byte[] dir; private byte[] ttl; private boolean is_orig; private int w, h; private double time; private int page; private long size;
// private byte db_state;
// private int lnki_site; private byte[] lnki_ttl; private int lnki_type; private double lnki_upright; private int lnki_w; private int lnki_h; private double lnki_time; private int lnki_page;
// private int orig_wiki; private byte[] orig_ttl; private int orig_ext; private int file_w; private int file_h; private double file_time; private int file_page;
// private long temp_file_size; private int temp_view_count; private long temp_view_date; private int temp_w;
// private Bry_bfr key_bfr = Bry_bfr_.New();
// public Xof_cache_itm_mkr() {this.Reset();}
// private void Reset() {
// db_state = Db_cmd_mode.Tid_ignore;
// lnki_site = orig_wiki = -1;
// lnki_ttl = orig_ttl = null;
// lnki_type = Byte_.Max_value_127;
// lnki_upright = Xof_img_size.Upright_null;
// lnki_w = lnki_h = file_w = file_h = temp_w = Xof_img_size.Size_null;
// lnki_time = file_time = Xof_lnki_time.Null;
// lnki_page = file_page = Xof_lnki_page.Null;
// orig_ext = Xof_ext_.Id_unknown;
// temp_file_size = -1;
// temp_view_count = -1;
// temp_view_date = -1;
// }
// public Xof_cache_itm_mkr Init(String dir_str, String ttl_str, boolean is_orig, int w) {
//// this.dir = Bry_.new_u8(dir_str);
//// this.ttl = Bry_.new_u8(ttl_str);
//// this.is_orig = is_orig;
//// this.w = w;
// return this;
// }
// public Xou_cache_itm Make() {
// return new Xou_cache_itm(key_bfr, db_state, lnki_site, lnki_ttl, lnki_type, lnki_upright, lnki_w, lnki_h, file_w, file_h, );
// this.Reset();
// }
// }

View File

@@ -1,112 +0,0 @@
/*
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.files.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import org.junit.*; import gplx.dbs.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.files.repos.*;
public class Xou_cache_mgr_tst {
@Before public void init() {fxt.Clear();} private final Xou_cache_mgr_fxt fxt = new Xou_cache_mgr_fxt();
@Test public void Update() {
Xof_fsdb_itm itm_1 = fxt.Make_itm("en.w", "1.png", 2);
fxt.Exec_update(itm_1);
fxt.Test_get(itm_1, 1, 0);
}
@Test public void Update_mult() {
Xof_fsdb_itm itm_1 = fxt.Make_itm("en.w", "1.png", 2);
fxt.Exec_update(itm_1, itm_1, itm_1);
fxt.Test_get(itm_1, 3, 2);
}
@Test public void Reload() {
Xof_fsdb_itm itm_1 = fxt.Make_itm("en.w", "1.png", 2);
fxt.Exec_update(itm_1, itm_1, itm_1);
fxt.Test_get(itm_1, 3, 2);
fxt.Exec_save_and_clear();
fxt.Test_get(itm_1, 3, 2);
}
@Test public void Reduce() {
fxt.Init_delete(3, 5);
Xof_fsdb_itm itm_1 = fxt.Make_itm("en.w", "1.png", 2);
Xof_fsdb_itm itm_2 = fxt.Make_itm("en.w", "2.png", 2);
Xof_fsdb_itm itm_3 = fxt.Make_itm("en.w", "3.png", 2);
fxt.Exec_update(itm_1, itm_2, itm_3);
fxt.Exec_reduce();
fxt.Test_get_y(itm_3);
fxt.Test_get_n(itm_1, itm_2);
}
@Test public void Reduce_same() {
fxt.Init_delete(3, 5);
Xof_fsdb_itm itm_1 = fxt.Make_itm("en.w", "1.png", 2);
Xof_fsdb_itm itm_2 = fxt.Make_itm("fr.w", "1.png", 2);
Xof_fsdb_itm itm_3 = fxt.Make_itm("en.w", "2.png", 2);
fxt.Exec_update(itm_3, itm_2, itm_1);
fxt.Exec_reduce();
fxt.Test_get_y(itm_3);
fxt.Test_get_n(itm_1, itm_2);
}
}
class Xou_cache_mgr_fxt {
private Xou_cache_mgr mgr;
private long cache_min;
public void Clear() {
Datetime_now.Manual_(DateAdp_.new_(1970, 1, 1, 0, 0, 0, 0));
Io_mgr.Instance.InitEngine_mem();
Db_conn_bldr.Instance.Reg_default_mem();
Xoae_app app = Xoa_app_fxt.Make__app__edit();
app.User().User_db_mgr().Init_by_app(Bool_.N, app.Fsys_mgr().Root_dir().GenSubFil_nest("user", "xowa.user.anonymous.sqlite3"));
Xoa_app_fxt.repo_(app, Xoa_app_fxt.Make__wiki__edit(app, "en.wikipedia.org"));
Xoa_app_fxt.repo_(app, Xoa_app_fxt.Make__wiki__edit(app, "fr.wikipedia.org"));
this.mgr = new Xou_cache_mgr(app.Wiki_mgr(), app.Fsys_mgr().File_dir(), app.User().User_db_mgr().Db_file());
}
public void Init_delete(long min, long max) {
cache_min = min;
mgr.Fsys_size_(min, max);
}
public Xof_fsdb_itm Make_itm(String wiki, String file, int size) {
Xof_fsdb_itm rv = new Xof_fsdb_itm();
byte[] wiki_domain = Bry_.new_a7(wiki);
byte[] file_ttl = Bry_.new_a7(file);
rv.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, wiki_domain, file_ttl, Byte_.Zero, 1, 1, 1 ,1, 1, 1);
rv.Init_at_orig(Xof_repo_tid_.Tid__local, wiki_domain, file_ttl, Xof_ext_.new_by_id_(Xof_ext_.Id_png), 120, 120, Bry_.Empty);
rv.File_size_(size);
return rv;
}
public void Exec_update(Xof_fsdb_itm... ary) {
for (Xof_fsdb_itm itm : ary)
mgr.Update(itm);
}
public void Exec_save_and_clear() {
mgr.Db_save();
mgr.Clear();
}
public void Exec_reduce() {
mgr.Reduce(cache_min);
}
public void Test_get(Xof_fsdb_itm fsdb, int expd_view_count, long expd_view_date) {
Xou_cache_itm cache = mgr.Get_or_null(fsdb);
Tfds.Eq(expd_view_count, cache.View_count(), "count");
Tfds.Eq(expd_view_date , (cache.View_date() / 60) - 1, "time"); // Tfds.Now increments by 60 seconds; also -1 b/c Gfo_log now calls Datetime_now.Get once
}
public void Test_get_n(Xof_fsdb_itm... ary) {
for (Xof_fsdb_itm itm : ary) {
Xou_cache_itm cache = mgr.Get_or_null(itm);
Tfds.Eq_null(cache, String_.new_u8(itm.Lnki_ttl()));
}
}
public void Test_get_y(Xof_fsdb_itm... ary) {
for (Xof_fsdb_itm itm : ary) {
Xou_cache_itm cache = mgr.Get_or_null(itm);
Tfds.Eq_nullNot(cache, String_.new_u8(itm.Lnki_ttl()));
}
}
}

View File

@@ -1,59 +0,0 @@
/*
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.files.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import org.junit.*; import gplx.dbs.*;
public class Xou_cache_tbl_tst {
@Before public void init() {fxt.Clear();} private final Xou_cache_tbl_fxt fxt = new Xou_cache_tbl_fxt();
@Test public void Orig_ttl__same() {fxt.Test_save_orig_ttl("A.png", "A.png", "");}
@Test public void Orig_ttl__redirect() {fxt.Test_save_orig_ttl("A.png", "B.png", "B.png");}
}
class Xou_cache_tbl_fxt {
private final Bry_bfr lnki_key_bfr = Bry_bfr_.New_w_size(255);
private Xou_cache_tbl tbl;
public void Clear() {
Io_mgr.Instance.InitEngine_mem();
Db_conn_bldr.Instance.Reg_default_mem();
Db_conn_bldr_data conn_data = Db_conn_bldr.Instance.Get_or_new(Io_url_.mem_fil_("mem/test.xowa"));
this.tbl = new Xou_cache_tbl(conn_data.Conn());
tbl.Create_tbl();
}
public Xou_cache_itm Make_itm(String lnki_wiki_abrv_xo, String lnki_ttl, int lnki_type, double lnki_upright, int lnki_w, int lnki_h, double lnki_time, int lnki_page, int user_thumb_w
, int orig_repo_id, String orig_ttl, int orig_ext_id, int orig_w, int orig_h
, int html_w, int html_h, double html_time, int html_page
, boolean file_is_orig, int file_w, double file_time, int file_page, long file_size
, int view_count, long view_date) {
return new Xou_cache_itm(lnki_key_bfr, Db_cmd_mode.Tid_create
, Bry_.new_u8(lnki_wiki_abrv_xo), Bry_.new_u8(lnki_ttl), lnki_type, lnki_upright, lnki_w, lnki_h, lnki_time, lnki_page, user_thumb_w
, orig_repo_id, Bry_.new_u8(orig_ttl), orig_ext_id, orig_w, orig_h
, html_w, html_h, html_time, html_page
, file_is_orig, file_w, file_time, file_page, file_size
, view_count, view_date
);
}
public Xou_cache_itm Exec_select_one(String lnki_wiki_abrv_xo, String lnki_ttl, int lnki_type, double lnki_upright, int lnki_w, int lnki_h, double lnki_time, int lnki_page, int user_thumb_w) {
return tbl.Select_one(Bry_.new_u8(lnki_wiki_abrv_xo), Bry_.new_u8(lnki_ttl), 1, 1, 1, 1, 1, 1, 1);
}
public void Test_save_orig_ttl(String lnki_ttl, String orig_ttl, String expd_orig_ttl) {
Xou_cache_itm itm = Make_itm("en.w", lnki_ttl, 1, 1, 1, 1, 1, 1, 1, 1, orig_ttl, 1, 1, 1, 1, 1, 1, 1, Bool_.Y, 1, 1, 1, 1, 1, 1);
tbl.Db_save(itm);
Db_rdr rdr = tbl.Select_all_for_test();
try {
Tfds.Eq_true(rdr.Move_next());
Tfds.Eq(expd_orig_ttl, rdr.Read_str(tbl.Fld_orig_ttl()));
}
finally {rdr.Rls();}
}
}

View File

@@ -1,30 +0,0 @@
/*
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.files.cnvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.core.primitives.*;
import gplx.gfui.*; import gplx.gfui.imgs.*;
import gplx.xowa.files.cnvs.*;
public class Xof_img_wkr_resize_img_mok implements Xof_img_wkr_resize_img {
public boolean Resize_exec(Io_url src, Io_url trg, int trg_w, int trg_h, int ext_id, String_obj_ref rslt_val) {
SizeAdp src_size = ImageAdp_.txt_fil_(src).Size();
int src_w = src_size.Width(), src_h = src_size.Height();
if (trg_w < 1) throw Err_.new_wo_type("trg_w must be > 0", "trg_w", trg_w);
if (trg_h < 1) trg_h = Xof_xfer_itm_.Scale_h(src_w, src_h, trg_w);
Io_mgr.Instance.SaveFilStr(trg, SizeAdp_.new_(trg_w, trg_h).To_str());
return true;
}
public static final Xof_img_wkr_resize_img_mok Instance = new Xof_img_wkr_resize_img_mok(); Xof_img_wkr_resize_img_mok() {}
}

View File

@@ -1,82 +0,0 @@
/*
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.files.fsdb.fs_roots; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.files.imgs.*;
import gplx.fsdb.meta.*;
public class Fs_root_wkr_tst {
@Before public void init() {fxt.Reset();} private Fs_root_wkr_fxt fxt = new Fs_root_wkr_fxt();
@Test public void Basic() {
fxt.Init_fs("mem/dir/7/70/A.png", 200, 100);
fxt.Test_get("A.png", fxt.itm_().Url_("mem/dir/7/70/A.png").Size_(200, 100));
fxt.Test_db("A.png", fxt.itm_().Init(1, "mem/dir/7/70/A.png", 200, 100));
}
@Test public void Recurse() {
fxt.Init_fs("mem/dir/A/A1.png", 200, 100);
fxt.Test_get("A1.png", fxt.itm_().Url_("mem/dir/A/A1.png").Size_(200, 100));
}
}
class Fs_root_wkr_fxt {
private Fs_root_wkr root_dir = new Fs_root_wkr();
private Io_url url;
public void Reset() {
Db_conn_bldr.Instance.Reg_default_mem();
Io_mgr.Instance.InitEngine_mem();
url = Io_url_.mem_dir_("mem/dir/");
root_dir = new Fs_root_wkr();
Xof_img_wkr_query_img_size img_size_wkr = new Xof_img_wkr_query_img_size_test();
root_dir.Init(img_size_wkr, url);
}
public Orig_fil_mok itm_() {return new Orig_fil_mok();}
public void Init_fs(String url, int w, int h) {Save_img(url, w, h);}
public void Test_get(String name, Orig_fil_mok expd) {
Orig_fil_row actl = root_dir.Get_by_ttl(Bry_.new_u8(name));
expd.Test(actl);
}
public void Test_db(String ttl, Orig_fil_mok expd) {
Orig_fil_row actl = root_dir.Orig_tbl().Select_itm_or_null(url, Bry_.new_u8(ttl));
expd.Test(actl);
}
public static void Save_img(String url, int w, int h) {
gplx.gfui.SizeAdp img_size = gplx.gfui.SizeAdp_.new_(w, h);
Io_mgr.Instance.SaveFilStr(url, img_size.To_str());
}
}
class Orig_fil_mok {
private int uid = -1;
private int ext_id = -1;
private String name = null;
private int w = -1;
private int h = -1;
public Orig_fil_mok Url_(String v) {url = v; return this;} private String url = null;
public Orig_fil_mok Size_(int w, int h) {this.w = w; this.h = h; return this;}
public Orig_fil_mok Init(int uid, String url, int w, int h) {
this.uid = uid;
this.url = url; this.w = w; this.h = h;
this.name = Io_url_.new_any_(url).NameAndExt();
this.ext_id = Xof_ext_.new_by_ttl_(Bry_.new_u8(name)).Id();
return this;
}
public void Test(Orig_fil_row actl) {
if (actl == null) Tfds.Fail("actl itm is null");
if (w != -1) Tfds.Eq(w, actl.W());
if (h != -1) Tfds.Eq(h, actl.H());
if (url != null) Tfds.Eq(url, actl.Url().Raw());
if (uid != -1) Tfds.Eq(uid, actl.Uid());
if (ext_id != -1) Tfds.Eq(uid, actl.Ext_id());
if (name != null) Tfds.Eq(name, String_.new_u8(actl.Name()));
}
}

View File

@@ -1,31 +0,0 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__bmp_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Make_orig() {
fxt.Init__orig_w_fsdb__commons_orig("A.bmp", 440, 400);
fxt.Exec_get(Xof_exec_arg.new_orig("A.bmp").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/7/0/A.bmp/440px.png", "440,400");
}
@Test public void Make_thumb() {
fxt.Init__orig_w_fsdb__commons_orig("A.bmp", 440, 400);
fxt.Exec_get(Xof_exec_arg.new_thumb("A.bmp").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/7/0/A.bmp/220px.png", "220,200");
}
}

View File

@@ -1,33 +0,0 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__flac_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Orig_page() { // .flac is on page [[File:A.flac]]
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.flac"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.flac"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.flac").Rslt_orig_exists_y().Rslt_file_exists_n()); // check orig (since orig may redirect) but do not get file; (since file is not "viewable" immediately); DATE:2015-02-15
fxt.Test_fsys_exists_n("mem/root/common/orig/8/b/A.flac");
}
@Test public void Orig_app() { // .flac is clicked; get file
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.flac"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.flac"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.flac").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_orig_exists_y().Rslt_file_exists_y());
fxt.Test_fsys_exists_y("mem/root/common/orig/8/b/A.flac");
}
}

View File

@@ -1,33 +0,0 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__oga_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Orig_page() { // .oga is on page [[File:A.oga]]; check orig (since orig may redirect) but do not get file; (since file is not "viewable" immediately)
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.oga"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.oga"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.oga").Rslt_orig_exists_y().Rslt_file_exists_n());
fxt.Test_fsys_exists_n("mem/root/common/orig/4/f/A.oga");
}
@Test public void Orig_app() { // .oga is clicked; get file
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.oga"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.oga"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.oga").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_orig_exists_y().Rslt_file_exists_y());
fxt.Test_fsys_exists_y("mem/root/common/orig/4/f/A.oga");
}
}

View File

@@ -1,35 +0,0 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
import gplx.xowa.files.bins.*;
public class Xof_file_ext__ogg_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
// @Test public void Video() { // disabled; .ogg will never be video; DATE:2014-02-02
// fxt.Init_orig_db(Xof_orig_arg.new_comm("A.ogg", 440, 400));
// fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.ogg", 440, 400)); // create a thumb at 440,400 (needed for preview of video)
// fxt.Exec_get(Xof_exec_arg.new_orig("A.ogg").Rslt_orig_missing().Rslt_fsdb_xowa().Rslt_conv_n());
// fxt.Test_fsys("mem/root/common/thumb/4/2/A.ogg/440px.jpg", "440,400");
// Xof_fsdb_itm itm = fxt.Test_regy_pass("A.ogg");
// fxt.Test_itm_ext(itm, Xof_ext_.Id_ogv);// chk that file is now ogv
// }
@Test public void Audio() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.ogg", 0, 0)); // audio has no size
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.ogg", 440, 400)); // create a thumb but it should never be used
fxt.Exec_get(Xof_exec_arg.new_orig("A.ogg").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_orig_exists_y().Rslt_file_exists_n().Rslt_file_resized_n());
}
}

View File

@@ -1,34 +0,0 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__ogv_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Copy_orig() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.ogv", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.ogv", 440, 400));
fxt.Exec_get(Xof_exec_arg.new_orig("A.ogv").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_n());
fxt.Test_fsys("mem/root/common/thumb/d/0/A.ogv/440px.jpg", "440,400");
}
@Test public void Copy_orig_w_thumbtime() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.ogv", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.ogv", 440, 400, 10));
fxt.Exec_get(Xof_exec_arg.new_orig("A.ogv").Lnki_time_(10).Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_n());
fxt.Test_fsys("mem/root/common/thumb/d/0/A.ogv/440px-10.jpg", "440,400");
// fxt.Exec_get(Xof_exec_arg.new_thumb("A.png", Xop_lnki_tkn.Width_null, 130)); DELETE: not needed; tests if new A.png can be resized from existing; DATE:2015-03-03
}
}

View File

@@ -1,27 +0,0 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__pdf_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Copy_thumb() {// PURPOSE: download pdf thumb only; [[File:Physical world.pdf|thumb]]
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.pdf", 2200, 1700));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.pdf", 220, 170));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.pdf", 220));
fxt.Test_fsys("mem/root/common/thumb/e/f/A.pdf/220px.jpg", "220,170");
}
}

View File

@@ -1,61 +0,0 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*; import gplx.xowa.parsers.lnkis.*;
public class Xof_file_ext__png_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Copy_thumb() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.png"));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.png").Rslt_orig_exists_y().Rslt_file_exists_y());
fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/220px.png", "220,200");
}
@Test public void Copy_orig() {
fxt.Init__orig_w_fsdb__commons_orig("A.png", 440, 400);
fxt.Exec_get(Xof_exec_arg.new_orig("A.png").Rslt_orig_exists_y().Rslt_file_exists_y());
fxt.Test_fsys("mem/root/common/orig/7/0/A.png", "440,400");
}
@Test public void Copy_orig_w_width() { // PURPOSE: if not thumb, but width is specified; do not download orig and convert; EX: [[File:The Earth seen from Apollo 17.jpg|250px]]
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.png", 220, 200));
fxt.Exec_get(Xof_exec_arg.new_("A.png", Xop_lnki_type.Id_null, 220, Xop_lnki_tkn.Height_null).Rslt_orig_exists_y().Rslt_file_exists_y());
fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/220px.png", "220,200");
}
@Test public void Make_thumb() {
fxt.Init__orig_w_fsdb__commons_orig("A.png", 440, 400);
fxt.Exec_get(Xof_exec_arg.new_thumb("A.png").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/220px.png", "220,200");
}
@Test public void Height_only() { // PURPOSE.fix: height only was still using old infer-size code; EX:w:[[File:Upper and Middle Manhattan.jpg|x120px]]; DATE:2012-12-27
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 12591, 1847));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.png", 887, 130));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.png", Xop_lnki_tkn.Width_null, 130));
fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/887px.png", "887,130");
}
@Test public void Width_only_height_ignored() {// PURPOSE.fix: if height is not specified, do not recalc; needed when true scaled height is 150x151 but WM has 150x158; defect would discard 150x158; EX:[[File:Tokage_2011-07-15.jpg|150px]] simple.wikipedia.org/wiki/2011_Pacific_typhoon_season; DATE:2013-06-03
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 4884, 4932));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.png", 150, 150));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.png", 150, Xop_lnki_tkn.Height_null));
fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/150px.png", "150,150");
}
@Test public void Upright() { // PURPOSE.fix: upright not working; EX: w:Beethoven; [[File:Rudolf-habsburg-olmuetz.jpg|thumb|upright|]]
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 1378, 1829));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.png", 170, 226));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.png", Xop_lnki_tkn.Width_null, Xop_lnki_tkn.Height_null).Lnki_upright_(Xof_img_size.Upright_default_marker));
fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/170px.png", "170,226");
}
}

View File

@@ -1,38 +0,0 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__svg_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Make_orig() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.svg", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.svg", 440, 400));
fxt.Exec_get(Xof_exec_arg.new_orig("A.svg").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/7/5/A.svg/440px.png", "440,400");
}
@Test public void Make_thumb() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.svg", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.svg", 440, 400));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.svg").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/7/5/A.svg/220px.png", "220,200");
}
@Test public void Thumb_can_be_bigger_than_orig() {// PURPOSE: svg thumbs allowed to exceed orig in size; EX: w:Portal:Music; [[File:Treble a.svg|left|160px]]
fxt.Init__orig_w_fsdb__commons_orig("A.svg", 110, 100); // create orig of 110,100
fxt.Exec_get(Xof_exec_arg.new_thumb("A.svg", 330).Rslt_file_exists_y()); // get 330
fxt.Test_fsys("mem/root/common/thumb/7/5/A.svg/330px.png", "330,300");
}
}

View File

@@ -1,33 +0,0 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__unknown_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Orig_page() { // .bin is on page [[File:A.bin]]; check orig (since orig may redirect) but do not get file; (since file is not "viewable" immediately); DATE:2014-08-17
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.bin"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.bin"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.bin").Rslt_orig_exists_y().Rslt_file_exists_n());
fxt.Test_fsys_exists_n("mem/root/common/orig/f/b/A.bin");
}
@Test public void Orig_app() { // .bin is clicked; get file
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.bin"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.bin"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.bin").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_orig_exists_y().Rslt_file_exists_y());
fxt.Test_fsys_exists_y("mem/root/common/orig/f/b/A.bin");
}
}

View File

@@ -1,34 +0,0 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
import gplx.xowa.files.bins.*;
public class Xof_file_ext__wav_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Orig_page() { // .wav is on page [[File:A.wav]]; check orig (since orig may redirect) but do not get file; (since file is not "viewable" immediately); DATE:2014-08-17
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.wav"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.wav"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.wav").Rslt_orig_exists_y().Rslt_file_exists_n());
fxt.Test_fsys_exists_n("mem/root/common/orig/c/3/A.wav");
}
@Test public void Orig_app() { // .wav is clicked; get file
fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.wav"));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.wav"));
fxt.Exec_get(Xof_exec_arg.new_orig("A.wav").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_orig_exists_y().Rslt_file_exists_y());
fxt.Test_fsys_exists_y("mem/root/common/orig/c/3/A.wav");
}
}

View File

@@ -1,33 +0,0 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_ext__xcf_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Make_orig() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.xcf", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.xcf", 440, 400));
fxt.Exec_get(Xof_exec_arg.new_orig("A.xcf").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/4/4/A.xcf/440px.png", "440,400");
}
@Test public void Make_thumb() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.xcf", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.xcf", 440, 400));
fxt.Exec_get(Xof_exec_arg.new_thumb("A.xcf").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/common/thumb/4/4/A.xcf/220px.png", "220,200");
}
}

View File

@@ -1,190 +0,0 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import gplx.core.envs.*;
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.dbs.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.cnvs.*; import gplx.xowa.files.exts.*; import gplx.xowa.guis.cbks.js.*;
import gplx.fsdb.data.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.files.repos.*; import gplx.xowa.wikis.data.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.parsers.lnkis.*;
class Xof_file_fxt {
private Xoae_app app; private Xof_fsdb_mgr__sql fsdb_mgr; private Xowe_wiki wiki; private Xof_orig_mgr orig_mgr;
private final Fsd_thm_itm tmp_thm = Fsd_thm_itm.new_();
public void Rls() {}
public void Reset() {
Io_mgr.Instance.InitEngine_mem(); // NOTE: files are downloaded to mem_engine, regardless of Db being mem or sqlite; always reset
Io_url root_url = Xoa_test_.Url_root();
Xoa_test_.Db_init(root_url);
app = Xoa_app_fxt.Make__app__edit(Op_sys.Cur().Os_name(), root_url);
wiki = Xoa_app_fxt.Make__wiki__edit(app);
wiki.File__fsdb_mode().Tid__v2__bld__y_();
this.fsdb_mgr = (Xof_fsdb_mgr__sql)wiki.File_mgr().Fsdb_mgr();
this.orig_mgr = wiki.File__orig_mgr();
Xof_repo_fxt.Repos_init(app.File_mgr(), true, wiki);
Xowe_wiki_.Create(wiki, 1, "dump.xml");
Xow_db_file text_db = wiki.Data__core_mgr().Dbs__make_by_tid(Xow_db_file_.Tid__text); text_db.Tbl__text().Create_tbl();
Fsdb_db_mgr__v2 fsdb_core = Fsdb_db_mgr__v2_bldr.Get_or_make(wiki, Bool_.Y);
fsdb_mgr.Mnt_mgr().Ctor_by_load(fsdb_core);
fsdb_mgr.Mnt_mgr().Mnts__get_main().Bin_mgr().Dbs__make("temp.xowa");
wiki.File_mgr().Init_file_mgr_by_load(wiki);
fsdb_mgr.Bin_mgr().Wkrs__del(Xof_bin_wkr_.Key_http_wmf); // never use http_wmf wkr for these tests
Xof_bin_wkr__fsdb_sql bin_wkr_fsdb = (Xof_bin_wkr__fsdb_sql)fsdb_mgr.Bin_mgr().Wkrs__get_or_null(Xof_bin_wkr_.Key_fsdb_wiki);
fsdb_mgr.Bin_mgr().Resizer_(Xof_img_wkr_resize_img_mok.Instance);
bin_wkr_fsdb.Resize_allowed_(true);
}
public void Init__orig_w_fsdb__commons_orig(String ttl, int w, int h) {
this.Init_fsdb_db(Xof_fsdb_arg.new_comm(Bool_.N, ttl, w, h));
this.Init_orig_db(Xof_orig_arg.new_comm(ttl, w, h));
}
public void Init_orig_db(Xof_orig_arg arg) {
orig_mgr.Insert(arg.Repo(), arg.Page(), Xof_ext_.new_by_ttl_(arg.Page()).Id(), arg.W(), arg.H(), arg.Redirect());
}
public void Init_fsdb_db(Xof_fsdb_arg arg) {
Fsm_mnt_itm mnt_itm = fsdb_mgr.Mnt_mgr().Mnts__get_main();
Fsm_atr_fil atr_fil = mnt_itm.Atr_mgr().Db__core();
Fsm_bin_fil bin_fil = mnt_itm.Bin_mgr().Dbs__get_nth();
if (arg.Is_thumb())
mnt_itm.Insert_thm(tmp_thm, atr_fil, bin_fil, arg.Wiki(), arg.Ttl(), arg.Ext(), arg.W(), arg.H(), arg.Time(), arg.Page(), arg.Bin().length, gplx.core.ios.streams.Io_stream_rdr_.New__mem(arg.Bin()));
else
mnt_itm.Insert_img(atr_fil, bin_fil, arg.Wiki(), arg.Ttl(), arg.Ext(), arg.W(), arg.H(), arg.Bin().length, gplx.core.ios.streams.Io_stream_rdr_.New__mem(arg.Bin()));
}
public void Exec_get(Xof_exec_arg arg) {
byte[] ttl_bry = arg.Ttl();
Xof_fsdb_itm itm = new Xof_fsdb_itm();
itm.Init_at_lnki(arg.Exec_tid(), wiki.Domain_itm().Abrv_xo(), ttl_bry, arg.Lnki_type(), arg.Lnki_upright(), arg.Lnki_w(), arg.Lnki_h(), arg.Lnki_time(), Xof_lnki_page.Null, Xof_patch_upright_tid_.Tid_all);
List_adp itms_list = List_adp_.New(); itms_list.Add(itm);
orig_mgr.Find_by_list(Ordered_hash_.New_bry(), itms_list, Xof_exec_tid.Tid_wiki_page);
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Xow_ns_.Tid__main, ttl_bry);
Xoae_page page = Xoae_page.New(wiki, ttl);
fsdb_mgr.Fsdb_search_by_list(itms_list, wiki, page, Xog_js_wkr_.Noop);
if (arg.Rslt_orig_exists() != Bool_.__byte) Tfds.Eq(arg.Rslt_orig_exists() == Bool_.Y_byte, itm.Orig_exists(), "orig_exists");
if (arg.Rslt_file_exists() != Bool_.__byte) Tfds.Eq(arg.Rslt_file_exists() == Bool_.Y_byte, itm.File_exists(), "file_exists");
if (arg.Rslt_file_resized() != Bool_.__byte) Tfds.Eq(arg.Rslt_file_resized() == Bool_.Y_byte, itm.File_resized(), "file_resize");
}
public void Test_fsys_exists_y(String url) {Test_fsys_exists(url, Bool_.Y);}
public void Test_fsys_exists_n(String url) {Test_fsys_exists(url, Bool_.N);}
public void Test_fsys_exists(String url, boolean expd) {Tfds.Eq(expd, Io_mgr.Instance.ExistsFil(Io_url_.new_any_(url)));}
public void Test_fsys(String url, String expd_bin) {Tfds.Eq(expd_bin, Io_mgr.Instance.LoadFilStr(url));}
}
class Xof_repo_fxt {
public static void Repos_init(Xof_file_mgr file_mgr, boolean src_repo_is_wmf, Xowe_wiki wiki) {
byte[] src_commons = Bry_.new_a7("src_commons");
byte[] src_en_wiki = Bry_.new_a7("src_en_wiki");
byte[] trg_commons = Bry_.new_a7("trg_commons");
byte[] trg_en_wiki = Bry_.new_a7("trg_en_wiki");
Ini_repo_add(file_mgr, src_commons, "mem/src/commons.wikimedia.org/", Xow_domain_itm_.Str__commons, false);
Ini_repo_add(file_mgr, src_en_wiki, "mem/src/en.wikipedia.org/" , Xow_domain_itm_.Str__enwiki, false);
Ini_repo_add(file_mgr, trg_commons, "mem/root/common/", Xow_domain_itm_.Str__commons, true).Primary_(true);
Ini_repo_add(file_mgr, trg_en_wiki, "mem/root/enwiki/", Xow_domain_itm_.Str__enwiki, true).Primary_(true);
Xowe_repo_mgr wiki_repo_mgr = wiki.File_mgr().Repo_mgr();
Xof_repo_pair pair = null;
pair = wiki_repo_mgr.Add_repo(src_commons, trg_commons);
pair.Src().Fsys_is_wnt_(true).Wmf_fsys_(src_repo_is_wmf).Tarball_(!src_repo_is_wmf);
pair.Trg().Fsys_is_wnt_(true);
pair = wiki_repo_mgr.Add_repo(src_en_wiki, trg_en_wiki);
pair.Src().Fsys_is_wnt_(true).Wmf_fsys_(src_repo_is_wmf);
pair.Trg().Fsys_is_wnt_(true);
}
private static Xof_repo_itm Ini_repo_add(Xof_file_mgr file_mgr, byte[] key, String root, String wiki, boolean trg) {
return file_mgr.Repo_mgr().Set(String_.new_u8(key), root, wiki).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
}
}
class Xof_orig_arg {
Xof_orig_arg(byte repo, byte[] page, int w, int h, byte[] redirect) {this.repo = repo; this.page = page; this.w = w; this.h = h; this.redirect = redirect;}
public byte Repo() {return repo;} private final byte repo;
public byte[] Page() {return page;} private final byte[] page;
public int W() {return w;} private final int w;
public int H() {return h;} private final int h;
public byte[] Redirect() {return redirect;} private final byte[] redirect;
public static Xof_orig_arg new_comm_file(String page) {return new_(Bool_.Y, page, Xof_img_size.Size_null, Xof_img_size.Size_null);}
public static Xof_orig_arg new_comm(String page, int w, int h) {return new_(Bool_.Y, page, w, h);}
public static Xof_orig_arg new_wiki(String page, int w, int h) {return new_(Bool_.N, page, w, h);}
public static Xof_orig_arg new_wiki_redirect(String src, String trg) {return new_(Bool_.N, src, 440, 400, trg);}
public static Xof_orig_arg new_comm_redirect(String src, String trg) {return new_(Bool_.Y, src, 440, 400, trg);}
private static Xof_orig_arg new_(boolean repo_is_commons, String page, int w, int h) {return new_(repo_is_commons, page, w, h, null);}
public static Xof_orig_arg new_(boolean repo_is_commons, String page, int w, int h, String redirect_str) {
byte repo = repo_is_commons ? Xof_repo_tid_.Tid__remote : Xof_repo_tid_.Tid__local;
byte[] redirect = redirect_str == null ? Bry_.Empty : Bry_.new_u8(redirect_str);
return new Xof_orig_arg(repo, Bry_.new_u8(page), w, h, redirect);
}
}
class Xof_fsdb_arg {
Xof_fsdb_arg(byte[] wiki, byte[] ttl, boolean is_thumb, int ext, int w, int h, int time, byte[] bin) {
this.wiki = wiki; this.ttl = ttl; this.is_thumb = is_thumb; this.w = w; this.h = h; this.time = time; this.ext = ext; this.bin = bin;
}
public byte[] Wiki() {return wiki;} private final byte[] wiki;
public byte[] Ttl() {return ttl;} private final byte[] ttl;
public int Ext() {return ext;} private final int ext;
public boolean Is_thumb() {return is_thumb;} private final boolean is_thumb;
public int W() {return w;} private final int w;
public int H() {return h;} private final int h;
public double Time() {return time;} private final double time;
public int Page() {return page;} private final int page = Xof_lnki_page.Null;
public byte[] Bin() {return bin;} private final byte[] bin;
public DateAdp Modified() {return modified;} private final DateAdp modified = Fsd_thm_tbl.Modified_null;
public String Hash() {return hash;} private final String hash = Fsd_thm_tbl.Hash_null;
public static Xof_fsdb_arg new_comm_file(String ttl) {return new_(Xow_domain_itm_.Bry__commons, Bool_.N, ttl, Xof_img_size.Null, Xof_img_size.Null, Xof_lnki_time.Null_as_int);}
public static Xof_fsdb_arg new_comm_thumb(String ttl) {return new_(Xow_domain_itm_.Bry__commons, Bool_.Y, ttl, W_default, H_default, Xof_lnki_time.Null_as_int);}
public static Xof_fsdb_arg new_comm_thumb(String ttl, int w, int h) {return new_(Xow_domain_itm_.Bry__commons, Bool_.Y, ttl, w, h, Xof_lnki_time.Null_as_int);}
public static Xof_fsdb_arg new_comm_thumb(String ttl, int w, int h, int s) {return new_(Xow_domain_itm_.Bry__commons, Bool_.Y, ttl, w, h, s);}
public static Xof_fsdb_arg new_comm_orig(String ttl, int w, int h) {return new_(Xow_domain_itm_.Bry__commons, Bool_.N, ttl, w, h, Xof_lnki_time.Null_as_int);}
public static Xof_fsdb_arg new_comm(boolean thumb, String ttl, int w, int h) {return new_(Xow_domain_itm_.Bry__commons, thumb, ttl, w, h, Xof_lnki_time.Null_as_int);}
public static Xof_fsdb_arg new_wiki_thumb(String ttl, int w, int h) {return new_(Xow_domain_itm_.Bry__enwiki, Bool_.Y, ttl, w, h, Xof_lnki_time.Null_as_int);}
public static Xof_fsdb_arg new_wiki_orig(String ttl, int w, int h) {return new_(Xow_domain_itm_.Bry__enwiki, Bool_.N, ttl, w, h, Xof_lnki_time.Null_as_int);}
public static Xof_fsdb_arg new_(byte[] wiki, boolean is_thumb, String ttl_str, int w, int h, int time) {
byte[] ttl = Bry_.new_u8(ttl_str);
int ext = Xof_ext_.new_by_ttl_(ttl).Id();
String bin_str = ext == Xof_ext_.Id_svg ? file_svg_(w, h) : file_img_(w, h);
byte[] bin = Bry_.new_a7(bin_str);
return new Xof_fsdb_arg(wiki, ttl, is_thumb, ext, w, h, time, bin);
}
private static final int W_default = 220, H_default = 200;
private static String file_img_(int w, int h) {return String_.Format("{0},{1}", w, h);}
private static String file_svg_(int w, int h) {return String_.Format("<svg width=\"{0}\" height=\"{1}\" />", w, h);}
}
class Xof_exec_arg {
public byte[] Ttl() {return ttl;} private byte[] ttl;
public byte Lnki_type() {return lnki_type;} private byte lnki_type = Xop_lnki_type.Id_thumb;
public int Lnki_w() {return lnki_w;} private int lnki_w;
public int Lnki_h() {return lnki_h;} private int lnki_h = Xop_lnki_tkn.Height_null;
public double Lnki_upright() {return lnki_upright;} public Xof_exec_arg Lnki_upright_(double v) {lnki_upright = v; return this;} private double lnki_upright = Xop_lnki_tkn.Upright_null;
public int Lnki_time() {return lnki_time;} public Xof_exec_arg Lnki_time_(int v) {lnki_time = v; return this;} private int lnki_time = Xof_lnki_time.Null_as_int;
public int Lnki_page() {return lnki_page;} public Xof_exec_arg Lnki_page_(int v) {lnki_page = v; return this;} private int lnki_page = Xof_lnki_page.Null;
public int Exec_tid() {return exec_tid;} public Xof_exec_arg Exec_tid_(int v) {exec_tid = v; return this;} private int exec_tid = Xof_exec_tid.Tid_wiki_page;
public byte Rslt_orig_exists() {return rslt_orig_exists;} private byte rslt_orig_exists = Bool_.__byte;
public byte Rslt_file_exists() {return rslt_file_exists;} private byte rslt_file_exists = Bool_.__byte;
public byte Rslt_file_resized() {return rslt_file_resized;} private byte rslt_file_resized = Bool_.__byte;
public boolean Lnki_type_is_thumb() {return Xop_lnki_type.Id_defaults_to_thumb(lnki_type);}
public Xof_exec_arg Rslt_orig_exists_n() {rslt_orig_exists = Bool_.N_byte; return this;}
public Xof_exec_arg Rslt_orig_exists_y() {rslt_orig_exists = Bool_.Y_byte; return this;}
public Xof_exec_arg Rslt_file_exists_n() {rslt_file_exists = Bool_.N_byte; return this;}
public Xof_exec_arg Rslt_file_exists_y() {rslt_file_exists = Bool_.Y_byte; return this;}
public Xof_exec_arg Rslt_file_resized_n() {rslt_file_resized = Bool_.N_byte; return this;}
public Xof_exec_arg Rslt_file_resized_y() {rslt_file_resized = Bool_.Y_byte; return this;}
public static Xof_exec_arg new_thumb(String ttl) {return new_(ttl, Xop_lnki_type.Id_thumb, 220, Xop_lnki_tkn.Height_null);}
public static Xof_exec_arg new_thumb(String ttl, int w) {return new_(ttl, Xop_lnki_type.Id_thumb, w, Xop_lnki_tkn.Height_null);}
public static Xof_exec_arg new_thumb(String ttl, int w, int h) {return new_(ttl, Xop_lnki_type.Id_thumb, w, h);}
public static Xof_exec_arg new_orig(String ttl) {return new_(ttl, Xop_lnki_type.Id_null, Xop_lnki_tkn.Width_null, Xop_lnki_tkn.Height_null);}
public static Xof_exec_arg new_(String ttl, byte type, int w, int h) {
Xof_exec_arg rv = new Xof_exec_arg();
rv.ttl = Bry_.new_u8(ttl);
rv.lnki_type = type;
rv.lnki_w = w;
rv.lnki_h = h;
return rv;
}
}

View File

@@ -1,64 +0,0 @@
/*
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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
public class Xof_file_redirect_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}
@Test public void Same_wiki_orig_copy() {
fxt.Init_orig_db(Xof_orig_arg.new_wiki("A.png", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_wiki_orig("A.png", 440, 400));
fxt.Init_orig_db(Xof_orig_arg.new_wiki_redirect("B.png", "A.png"));
fxt.Exec_get(Xof_exec_arg.new_orig("B.png").Rslt_file_exists_y());
fxt.Test_fsys("mem/root/enwiki/orig/7/0/A.png", "440,400");
}
@Test public void Same_wiki_thumb_copy() {
fxt.Init_orig_db(Xof_orig_arg.new_wiki("A.png", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_wiki_thumb("A.png", 220, 200));
fxt.Init_orig_db(Xof_orig_arg.new_wiki_redirect("B.png", "A.png"));
fxt.Exec_get(Xof_exec_arg.new_thumb("B.png", 220).Rslt_file_exists_y());
fxt.Test_fsys("mem/root/enwiki/thumb/7/0/A.png/220px.png", "220,200");
}
@Test public void Same_wiki_thumb_make() {
fxt.Init_orig_db(Xof_orig_arg.new_wiki("A.png", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_wiki_orig("A.png", 440, 400));
fxt.Init_orig_db(Xof_orig_arg.new_wiki_redirect("B.png", "A.png"));
fxt.Exec_get(Xof_exec_arg.new_thumb("B.png", 220).Rslt_file_exists_y().Rslt_file_resized_y());
fxt.Test_fsys("mem/root/enwiki/thumb/7/0/A.png/220px.png", "220,200");
}
@Test public void Diff_wiki_orig_copy() {
fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 440, 400));
fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.png", 440, 400));
fxt.Init_orig_db(Xof_orig_arg.new_comm_redirect("B.png", "A.png"));
fxt.Exec_get(Xof_exec_arg.new_orig("B.png").Rslt_file_exists_y());
fxt.Test_fsys("mem/root/common/orig/7/0/A.png", "440,400");
}
// @Test public void Cross_wiki() {
// fxt.Init__orig_w_fsdb__commons_orig("A.png", 440, 400);
// fxt.Init_orig_db(Xof_orig_arg.new_wiki_redirect("B.png", "A.png"));
// fxt.Exec_get(Xof_exec_arg.new_orig("B.png").Rslt_fsdb_xowa());
// fxt.Test_fsys("mem/root/common/orig/7/0/A.png", "440,400");
// fxt .ini_page_create_en_wiki_redirect ("File:B.png", "File:A.png");
// fxt .ini_page_create_commons ("File:A.png");
// fxt .Lnki_orig_("B.png")
// .Src( fxt.img_("mem/src/commons.wikimedia.org/7/70/A.png", 900, 800))
// .Trg( fxt.img_("mem/trg/commons.wikimedia.org/raw/7/0/A.png", 900, 800)
// , fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/5/57.csv" , "B.png|y|A.png|1?900,800|")
// );
// fxt.tst();
// }
}

View File

@@ -1,74 +0,0 @@
/*
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.files.origs; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import org.junit.*;
import gplx.dbs.*; import gplx.xowa.*;
import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import gplx.xowa.parsers.lnkis.*;
public class Xof_orig_tbl_tst {
@Before public void init() {fxt.Clear();} private Xof_orig_tbl_fxt fxt = new Xof_orig_tbl_fxt();
@Test public void Select_in() {
Xof_orig_itm itm_1 = fxt.Exec_insert("A.png", 220, 330);
fxt.Exec_insert("B.png", 220, 330);
Xof_orig_itm itm_3 = fxt.Exec_insert("C.png", 220, 330);
fxt.Test_select_in(String_.Ary("A.png", "C.png"), itm_1, itm_3);
}
}
class Xof_orig_tbl_fxt {
private Xof_orig_tbl tbl;
public void Clear() {
Io_url test_url = Io_url_.mem_fil_("mem/file/en.wikipedia.org/file/orig_regy");
Db_conn_bldr.Instance.Reg_default_mem();
Db_conn conn = Db_conn_bldr.Instance.New(test_url);
tbl = new Xof_orig_tbl(conn, Bool_.Y);
tbl.Create_tbl();
}
public Xof_orig_itm Exec_insert(String ttl, int w, int h) {
byte[] ttl_bry = Bry_.new_u8(ttl);
Xof_orig_itm rv = new Xof_orig_itm(Xof_orig_itm.Repo_comm, ttl_bry, Xof_ext_.new_by_ttl_(ttl_bry).Id(), w, h, Bry_.Empty);
tbl.Insert(rv.Repo(), rv.Ttl(), rv.Ext_id(), rv.W(), rv.H(), rv.Redirect());
return rv;
}
public void Test_select_in(String[] itms, Xof_orig_itm... expd) {
Ordered_hash rv = Ordered_hash_.New();
List_adp list = List_adp_.New();
int itms_len = itms.length;
for (int i = 0; i < itms_len; ++i) {
String itm = itms[i];
Xof_fsdb_itm fsdb_itm = new Xof_fsdb_itm();
fsdb_itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, Bry_.new_a7("en.w"), Bry_.new_u8(itm), Xop_lnki_type.Id_none, Xof_img_size.Upright_null, Xof_img_size.Null, Xof_img_size.Null, Xof_lnki_time.Null, Xof_lnki_page.Null, Xof_patch_upright_tid_.Tid_all);
list.Add(fsdb_itm);
}
tbl.Select_by_list(rv, list);
Tfds.Eq_str_lines(To_str_ary(expd), To_str_ary((Xof_orig_itm[])rv.To_ary(Xof_orig_itm.class)));
}
private static String To_str_ary(Xof_orig_itm... ary) {
Bry_bfr bfr = Bry_bfr_.Reset(255);
int len = ary.length;
for (int i = 0; i < len; ++i) {
Xof_orig_itm itm = ary[i];
bfr .Add_byte(itm.Repo()).Add_byte_pipe()
.Add(itm.Ttl()).Add_byte_pipe()
.Add_int_variable(itm.Ext_id()).Add_byte_pipe()
.Add_int_variable(itm.W()).Add_byte_pipe()
.Add_int_variable(itm.H()).Add_byte_pipe()
.Add(itm.Redirect()).Add_byte_pipe()
;
bfr.Add_byte_nl();
}
return bfr.To_str_and_clear();
}
}

View File

@@ -1,56 +0,0 @@
/*
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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import org.junit.*; import gplx.core.tests.*;
import gplx.core.envs.*;
import gplx.xowa.apps.fsys.*;
import gplx.xowa.files.exts.*;
public class Xof_repo_itm__tst {
private final Xof_repo_itm__fxt fxt = new Xof_repo_itm__fxt();
@Test public void Gen_name_trg__long() {
// make a windows repo with a long directory name
Xof_repo_itm repo = fxt.Make__repo(Op_sys.Wnt.Os_name(), "C:\\xowa0123456789", "commons.wikimedia.org");
// mark it as wnt repo and reduce max ttl_len from 160 to 99 for shorter test vars
repo.Fsys_is_wnt_(true).Url_max_len_(99);
// short: full name
fxt.Test__gen_name_trg(repo, "A.png", "A.png");
// long: truncated_ttl + md5
fxt.Test__gen_name_trg(repo, "0123456789012345678901234567890123456789.png", "0123456789_965d037bf686058361510201be299ed4.png");
// extremely long; md5 only
repo.Root_str_("C:\\xowa012345678901234567890123456789");
fxt.Test__gen_name_trg(repo, "0123456789012345678901234567890123456789.png", "965d037bf686058361510201be299ed4.png");
}
}
class Xof_repo_itm__fxt {
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
public Xof_repo_itm Make__repo(String plat_name, String root_dir_str, String wiki_domain) {
String key = "test_repo";
Io_url root_dir = Io_url_.new_dir_(root_dir_str);
Xoa_fsys_mgr fsys_mgr = Xoa_fsys_mgr.New_by_plat(plat_name, root_dir);
Xof_repo_itm repo = new Xof_repo_itm(Bry_.new_u8(key), fsys_mgr, new Xof_rule_mgr(), Bry_.new_u8(wiki_domain));
repo.Root_str_(root_dir.Raw());
return repo;
}
public void Test__gen_name_trg(Xof_repo_itm repo, String ttl_str, String expd) {
byte[] ttl_bry = Bry_.new_u8(ttl_str);
byte[] md5 = Xof_file_wkr_.Md5(ttl_bry);
Gftest.Eq__str(expd, repo.Gen_name_trg(tmp_bfr, ttl_bry, md5, Xof_ext_.new_by_ttl_(ttl_bry)));
}
}

View File

@@ -1,113 +0,0 @@
/*
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.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.core.ios.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.files.cnvs.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.imgs.*;
import gplx.xowa.apps.wms.apis.*; import gplx.xowa.apps.wms.apis.origs.*;
public class Xof_xfer_queue_base_fxt {
public Xoapi_orig_mok Api_size() {return api_size;} private Xoapi_orig_mok api_size = Xoapi_orig_mok.Instance;
public Xof_repo_itm Src_commons_repo() {return src_commons_repo;} private Xof_repo_itm src_commons_repo;
public Xof_repo_itm Src_en_wiki_repo() {return src_en_wiki_repo;} private Xof_repo_itm src_en_wiki_repo;
@gplx.Virtual public void Clear(boolean src_repo_is_wmf) {
Io_mgr.Instance.InitEngine_mem();
if (app == null) {
app = Xoa_app_fxt.Make__app__edit();
en_wiki = Xoa_app_fxt.Make__wiki__edit(app, Xow_domain_itm_.Str__enwiki);
commons = Xoa_app_fxt.Make__wiki__edit(app, Xow_domain_itm_.Str__commons);
app.Wiki_mgr().Add(commons);
app.Wiki_mgr().Add(en_wiki);
Xof_file_mgr file_mgr = app.File_mgr();
file_mgr.Img_mgr().Wkr_resize_img_(Xof_img_wkr_resize_img_mok.Instance);
file_mgr.Img_mgr().Wkr_query_img_size_(new Xof_img_wkr_query_img_size_test());
app.Wmf_mgr().Api_mgr().Api_orig_(api_size);
byte[] src_commons = Bry_.new_a7("src_commons");
byte[] src_en_wiki = Bry_.new_a7("src_en_wiki");
byte[] trg_commons = Bry_.new_a7("trg_commons");
byte[] trg_en_wiki = Bry_.new_a7("trg_en_wiki");
src_commons_repo = Ini_repo_add(file_mgr, src_commons, "mem/src/commons.wikimedia.org/", Xow_domain_itm_.Str__commons, false);
src_en_wiki_repo = Ini_repo_add(file_mgr, src_en_wiki, "mem/src/en.wikipedia.org/" , Xow_domain_itm_.Str__enwiki, false);
Ini_repo_add(file_mgr, trg_commons, "mem/trg/commons.wikimedia.org/", Xow_domain_itm_.Str__commons, true).Primary_(true);
Ini_repo_add(file_mgr, trg_en_wiki, "mem/trg/en.wikipedia.org/" , Xow_domain_itm_.Str__enwiki, true).Primary_(true);
Xowe_repo_mgr wiki_repo_mgr = en_wiki.File_mgr().Repo_mgr();
Xof_repo_pair pair = null;
pair = wiki_repo_mgr.Add_repo(src_commons, trg_commons);
pair.Src().Fsys_is_wnt_(true).Wmf_fsys_(src_repo_is_wmf).Tarball_(!src_repo_is_wmf);
pair.Trg().Fsys_is_wnt_(true);
pair = wiki_repo_mgr.Add_repo(src_en_wiki, trg_en_wiki);
pair.Src().Fsys_is_wnt_(true).Wmf_fsys_(src_repo_is_wmf);
pair.Trg().Fsys_is_wnt_(true);
}
en_wiki.Clear_for_tests();
commons.Clear_for_tests();
src_fils = trg_fils = Io_fil.Ary_empty;
html_view_str = null;
html_w = html_h = -1;
}
public Xoae_app App() {return app;} private Xoae_app app;
public Xowe_wiki En_wiki() {return en_wiki;} private Xowe_wiki en_wiki;
public Xowe_wiki Commons() {return commons;} private Xowe_wiki commons;
public void ini_page_create_commons(String ttl) {Init_page_create(commons, ttl, "");}
public void ini_page_create_commons_redirect(String ttl, String redirect) {Init_page_create(commons, ttl, "#REDIRECT [[" + redirect + "]]");}
public void ini_page_create_en_wiki(String ttl) {Init_page_create(en_wiki, ttl, "");}
public void ini_page_create_en_wiki_redirect(String ttl, String redirect) {Init_page_create(en_wiki, ttl, "#REDIRECT [[" + redirect + "]]");}
public void Init_page_create(Xowe_wiki wiki, String ttl, String txt) {
Xoa_ttl page_ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl));
byte[] page_raw = Bry_.new_u8(txt);
wiki.Db_mgr().Save_mgr().Data_create(wiki, page_ttl, page_raw);
}
Xof_repo_itm Ini_repo_add(Xof_file_mgr file_mgr, byte[] key, String root, String wiki, boolean trg) {
Xof_repo_itm repo = file_mgr.Repo_mgr().Set(String_.new_u8(key), root, wiki).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
if (trg) {
byte[][] ary = repo.Mode_names();
ary[0] = Bry_.new_a7("raw");
ary[1] = Bry_.new_a7("fit");
}
return repo;
}
public Xof_xfer_queue_base_fxt Src_base(Io_fil... v) {src_fils = v; return this;} Io_fil[] src_fils = Io_fil.Ary_empty;
public Xof_xfer_queue_base_fxt Trg_base(Io_fil... v) {trg_fils = v; return this;} Io_fil[] trg_fils = Io_fil.Ary_empty;
public String Html_view_src() {return html_view_str;} protected Xof_xfer_queue_base_fxt Html_src_base_(String v) {html_view_str = v; return this;} private String html_view_str;
public int Html_w() {return html_w;} public Xof_xfer_queue_base_fxt Html_w_(int v) {html_w = v; return this;} private int html_w = -1;
public int Html_h() {return html_h;} public Xof_xfer_queue_base_fxt Html_h_(int v) {html_h = v; return this;} private int html_h = -1;
public void ini_src_fils() {
if (src_fils != null) {
for (int i = 0; i < src_fils.length; i++) {
Io_fil src_fil = src_fils[i];
Io_mgr.Instance.SaveFilStr(src_fil.Url(), src_fil.Data());
}
}
}
public void tst_trg_fils() {
for (int i = 0; i < trg_fils.length; i++) {
Io_fil trg_fil = trg_fils[i];
String data = Io_mgr.Instance.LoadFilStr(trg_fil.Url());
Tfds.Eq_str_lines(trg_fil.Data(), data, trg_fil.Url().Raw());
}
}
public void save_(Io_fil v) {Io_mgr.Instance.SaveFilStr(v.Url(), v.Data());}
public Io_fil reg_(String url, String... v) {return new Io_fil(Io_url_.mem_fil_(url), String_.Concat_lines_nl(v));}
public Io_fil img_(String url_str, int w, int h) {return file_(url_str, file_img(w, h));}
public Io_fil svg_(String url_str, int w, int h) {return file_(url_str, file_svg(w, h));}
public Io_fil ogg_(String url_str) {return file_(url_str, "");}
public void fil_absent(String url) {Tfds.Eq_false(Io_mgr.Instance.ExistsFil(Io_url_.mem_fil_(url)), "fil should not exist: {0}", url);}
Io_fil file_(String url_str, String data) {return new Io_fil(Io_url_.mem_fil_(url_str), data);}
String file_img(int w, int h) {return String_.Format("{0},{1}", w, h);}
String file_svg(int w, int h) {return String_.Format("<svg width=\"{0}\" height=\"{1}\" />", w, h);}
}

View File

@@ -1,132 +0,0 @@
/*
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.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import org.junit.*;
import gplx.core.ios.*; import gplx.gfui.*; import gplx.xowa.files.*;
public class Xof_xfer_queue_html_basic_tst {
Xof_xfer_queue_html_fxt fxt = new Xof_xfer_queue_html_fxt();
@Before public void init() {fxt.Clear(true);}
@Test public void Main_orig() {
fxt .ini_page_create_en_wiki("File:A.png");
fxt .Lnki_orig_("A.png")
.Src( fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 900, 800))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/raw/7/0/A.png", 900, 800)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|y||1?900,800|")
);
fxt.tst();
}
@Test public void Main_thumb_download() {
fxt .ini_page_create_en_wiki("File:A.png");
fxt .Lnki_thumb_("A.png", 90)
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/90px-A.png", 90, 80))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/90px.png", 90, 80)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|y||2?0,0|1?90,80")
);
fxt.tst();
}
@Test public void Main_thumb_convert() {
fxt .ini_page_create_en_wiki("File:A.png");
fxt .Lnki_thumb_("A.png", 90)
.Src( fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 900, 800))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/raw/7/0/A.png", 900, 800)
, fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/90px.png", 90, 80)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|y||1?900,800|1?90,80")
);
fxt.tst();
}
@Test public void Ptr_orig() {
fxt .ini_page_create_en_wiki ("File:A.png");
fxt .ini_page_create_en_wiki_redirect ("File:B.png", "File:A.png");
fxt .Lnki_orig_("B.png")
.Src( fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 900, 800))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/raw/7/0/A.png", 900, 800)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/5/57.csv", "B.png|y|A.png|1?900,800|")
);
fxt.tst();
fxt .Lnki_orig_("B.png")
.Html_src_("file:///mem/trg/en.wikipedia.org/raw/7/0/A.png")
.tst();
}
@Test public void Ptr_thumb_download() {
fxt .ini_page_create_en_wiki ("File:A.png");
fxt .ini_page_create_en_wiki_redirect ("File:B.png", "File:A.png");
fxt .Lnki_thumb_("B.png", 90)
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/90px-A.png", 90, 80))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/90px.png", 90, 80)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/5/57.csv", "B.png|y|A.png|2?0,0|1?90,80")
);
fxt.tst();
}
@Test public void Ptr_thumb_convert() {
fxt .ini_page_create_en_wiki ("File:A.png");
fxt .ini_page_create_en_wiki_redirect ("File:B.png", "File:A.png");
fxt .Lnki_thumb_("B.png", 90)
.Src( fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 900, 800))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/raw/7/0/A.png", 900, 800)
, fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/90px.png", 90, 80)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/5/57.csv", "B.png|y|A.png|1?900,800|1?90,80")
);
fxt.tst();
}
@Test public void Vrtl_orig() {
fxt .ini_page_create_commons ("File:A.png");
fxt .Lnki_orig_("A.png")
.Src( fxt.img_("mem/src/commons.wikimedia.org/7/70/A.png", 900, 800))
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/raw/7/0/A.png", 900, 800)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|0||1?900,800|")
);
fxt.tst();
}
@Test public void Vrtl_thumb_download() {
fxt .ini_page_create_commons ("File:A.png");
fxt .Lnki_thumb_("A.png", 90)
.Src( fxt.img_("mem/src/commons.wikimedia.org/thumb/7/70/A.png/90px-A.png", 90, 80))
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/fit/7/0/A.png/90px.png", 90, 80)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|0||2?0,0|1?90,80")
);
fxt.tst();
}
@Test public void Vrtl_thumb_convert() {
fxt .ini_page_create_commons ("File:A.png");
fxt .Lnki_thumb_("A.png", 90)
.Src( fxt.img_("mem/src/commons.wikimedia.org/7/70/A.png", 900, 800))
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/raw/7/0/A.png", 900, 800)
, fxt.img_("mem/trg/commons.wikimedia.org/fit/7/0/A.png/90px.png", 90, 80)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|0||1?900,800|1?90,80")
);
fxt.tst();
}
@Test public void Vrtl_ptr_orig() {
fxt .ini_page_create_commons_redirect ("File:B.png", "File:A.png");
fxt .ini_page_create_commons ("File:A.png");
fxt .Lnki_orig_("B.png")
.Src( fxt.img_("mem/src/commons.wikimedia.org/7/70/A.png", 900, 800))
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/raw/7/0/A.png", 900, 800)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/5/57.csv" , "B.png|0|A.png|1?900,800|")
);
fxt.tst();
}
@Test public void Ptr_vrtl_orig() {
fxt .ini_page_create_en_wiki_redirect ("File:B.png", "File:A.png");
fxt .ini_page_create_commons ("File:A.png");
fxt .Lnki_orig_("B.png")
.Src( fxt.img_("mem/src/commons.wikimedia.org/7/70/A.png", 900, 800))
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/raw/7/0/A.png", 900, 800)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/5/57.csv" , "B.png|y|A.png|1?900,800|")
);
fxt.tst();
}
}

View File

@@ -1,288 +0,0 @@
/*
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.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import org.junit.*;
import gplx.xowa.files.*; import gplx.xowa.files.imgs.*;
public class Xof_xfer_queue_html_cases_tst {
Xof_xfer_queue_html_fxt fxt = new Xof_xfer_queue_html_fxt();
@Before public void init() {
fxt.Clear(true);
}
@Test public void Png_missing() {
fxt .Lnki_orig_("A.png")
.Trg( fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|z||0?0,0|")
);
fxt.tst();
}
@Test public void Png_missing_2() { // PURPOSE: orig is missing; do not download again; NOTE: simulating "do not download again" check by putting in thumb and making sure it doesn't get downloaded
fxt.save_(fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|z||0?0,0|")); // save reg file and mark file as missing
fxt .Lnki_thumb_("A.png", 90)
.Src( fxt.img_("mem/src/commons.wikimedia.org/thumb/7/70/A.png/90px-A.png", 90, 80))
.Trg( fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|z||0?0,0|") // NOTE: 90,80 should not show up
);
fxt.tst();
}
@Test public void Png_encode() { // PURPOSE: make sure \s is converted to _; also ' should not be encoded on trg; done
fxt .ini_page_create_commons ("File:A'b c.png");
fxt .Lnki_orig_("A'b c.png")
.Src( fxt.img_("mem/src/commons.wikimedia.org/9/9c/A%27b_c.png", 90, 80))
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/raw/9/c/A'b_c.png", 90, 80)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/9/9c.csv", "A'b_c.png|0||1?90,80|")
);
fxt.tst();
}
@Test public void Ogg_vid_thumb() {
fxt .ini_page_create_commons ("File:A.ogg");
fxt .Lnki_orig_("A.ogg")
.Src( fxt.img_("mem/src/commons.wikimedia.org/thumb/4/42/A.ogg/-1px--A.ogg.jpg", 300, 40))
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/fit/4/2/A.ogg/300px.jpg", 300, 40)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/4/42.csv", "A.ogg|0||0?0,0|1?300,40")
);
fxt.tst();
}
@Test public void Ogg_vid_missing_thumb() {
fxt .Lnki_orig_("A.ogg")
.Src( )
.Trg( fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/4/42.csv", "A.ogg|z||0?0,0|0?0,0") // NOTE: mark thumb not found (since xfer_mgr checked all repos)
);
fxt.tst();
}
@Test public void Aud_do_not_download() {
fxt.save_(fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/4/42.csv", "A.ogg|z||2?0,0|0?0,0")); // save reg file and mark file as aud
fxt .Lnki_orig_("A.ogg")
.Src( fxt.img_("mem/src/commons.wikimedia.org/thumb/4/42/A.ogg/mid-A.ogg.jpg", 300, 40) // simulate thumb (make sure test does not download)
)
.Trg( fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/4/42.csv", "A.ogg|z||2?0,0|0?0,0") // 300,40 should not show up
);
fxt.tst();
}
@Test public void Img_thumb_djvu() {// PURPOSE: exact djvu thumbs are not on server; always seems to retrieve 1 off;
fxt .ini_page_create_commons ("File:A.djvu");
fxt .App().File_mgr().Img_mgr().Wkr_convert_djvu_to_tiff_(Xof_img_wkr_convert_djvu_to_tiff_.new_mok(199, 299));
fxt .Lnki_thumb_("A.djvu", 200)
.Src( fxt.img_("mem/src/commons.wikimedia.org/7/76/A.djvu", 1990, 2990)
)
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/fit/7/6/A.djvu/199px.jpg", 199, 299)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/76.csv", "A.djvu|0||1?0,0|1?199,299")
);
fxt.tst();
fxt .Lnki_thumb_("A.djvu", 200)
.Html_src_("file:///mem/trg/commons.wikimedia.org/fit/7/6/A.djvu/199px.jpg")
.Html_size_(200, 301)
.tst();
}
@Test public void Img_thumb_pdf() {// PURPOSE: download pdf thumb only; [[File:Physical world.pdf|thumb]]
fxt .ini_page_create_commons ("File:A.pdf");
fxt .Lnki_thumb_("A.pdf", 220)
.Src( fxt.img_("mem/src/commons.wikimedia.org/e/ef/A.pdf", 2200, 1700)
, fxt.img_("mem/src/commons.wikimedia.org/thumb/e/ef/A.pdf/page1-220px-A.pdf.jpg", 220, 170)
)
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/fit/e/f/A.pdf/220px.jpg", 220, 170)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/e/ef.csv", "A.pdf|0||2?0,0|1?220,170")
);
fxt.tst();
fxt .Lnki_thumb_("A.pdf", 220)
.Html_src_("file:///mem/trg/commons.wikimedia.org/fit/e/f/A.pdf/220px.jpg")
.Html_size_(220, 170)
.tst();
}
@Test public void Img_missing_wiki_0() { // PURPOSE.outlier: page is in wiki_1 but file is actually in wiki_0; download from wiki_0; occurs when working with old commons/en.wikipedia.org against current wmf servers; EX: Mars Science Laboratory and File:Curiosity wheel pattern morse code.png; Curiosity rover
fxt .ini_page_create_en_wiki ("File:A.png"); // page is in en_wiki
fxt .Lnki_orig_("A.png")
.Src( fxt.img_("mem/src/commons.wikimedia.org/7/70/A.png", 900, 800)) // file is in commons
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/raw/7/0/A.png", 900, 800)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|y||1?900,800|")
);
fxt.tst();
}
// @Test public void Img_missing_wiki_1() { // PURPOSE.outlier: page is in wiki_0 and in wiki_1; file is in wiki_1; EX:[[Image:Alcott-L.jpg|thumb|right|Louisa May Alcott]]
// fxt .ini_page_create_commons ("File:A.png"); // page is in commons also
// fxt .ini_page_create_en_wiki ("File:A.png"); // page is in en_wiki
// fxt .Lnki_thumb_("A.png", 220)
// .Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/220px-A.png", 220, 110)) // file is in en_wiki
// .Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/220px.png", 220, 110) // download en_wiki
// , fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "2|A.png|y||2?0,0|1?220,110")
// );
// fxt.tst();
// }
@Test public void Do_not_download_orig_0() {// PURPOSE: do not download orig if size can be inferred from thumb; EX: [[File:Vanadium etched.jpg|350x250px|Vanadium]]
fxt .ini_page_create_en_wiki ("File:A.png");
fxt .Lnki_thumb_("A.png", 350, 250) // requesting w=350 and h=250; note that h trumps w
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/350px-A.png", 350, 309) // w=350 exists, but should not be used
, fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/283px-A.png", 283, 250) // h=250 exists, and should be used
, fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 3808, 3364) // orig image exists, and should not be downloaded
)
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/283px.png" , 283, 250)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|y||2?0,0|1?283,250") // note that orig does not exist
);
fxt.tst();
fxt.fil_absent( "mem/trg/en.wikipedia.org/raw/7/0/A.png");
fxt .Lnki_thumb_("A.png", 350, 250)
.Html_src_("file:///mem/trg/en.wikipedia.org/fit/7/0/A.png/283px.png")
.tst();
}
@Test public void Do_not_download_orig_1() {// PURPOSE: allow variance of 1 for thumbs (rounding errors); EX:<gallery>Image:President Woodrow Wilson portrait December 2 1912.jpg|US President Woodrow Wilson</gallery>
fxt .ini_page_create_en_wiki ("File:A.png");
fxt .Lnki_thumb_("A.png", 120, 120) // requesting 120,120 (gallery default); note that h trumps w
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/120px-A.png", 120, 146) // w=120 exists, but should not be used
, fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/99px-A.png", 99, 121) // true width should be w=98, but b/c of rounding off of large 2976, getting 99 instead
, fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 2976, 3623) // orig image exists, and should not be downloaded
)
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/99px.png" , 99, 121)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|y||2?0,0|1?99,121") // note that orig does not exist
);
fxt.tst();
fxt.fil_absent( "mem/trg/en.wikipedia.org/raw/7/0/A.png");
fxt .Lnki_thumb_("A.png", 120, 120) // note that 120 is requested
.Html_src_("file:///mem/trg/en.wikipedia.org/fit/7/0/A.png/99px.png") // note that image used is 99
.Html_size_(98, 120) // note that view width is 98
.tst();
}
@Test public void Do_not_download_orig_3() {// PURPOSE.defect: account for multiple thumbs; EX: <gallery heights="380" widths="454">File:Rembrandt van Rijn-De Nachtwacht-1642.jpg|1642.</gallery>
fxt .ini_page_create_en_wiki ("File:A.png");
fxt .Lnki_thumb_("A.png", 454, 380) // standard request
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/454px-A.png", 454, 380)
, fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 3344, 2796)
)
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/454px.png" , 454, 380)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|y||2?0,0|1?454,380") // note that orig does not exist
);
fxt.tst();
fxt.fil_absent( "mem/trg/en.wikipedia.org/raw/7/0/A.png");
fxt .Lnki_thumb_("A.png", 718, 600) // this is the defect; 718 was not being brought down; instead 454 was being reused
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/718px-A.png", 718, 600)
, fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 3344, 2796)
)
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/718px.png" , 718, 600)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|y||2?0,0|1?454,380;1?718,600") // note that orig does not exist
)
.tst();
}
@Test public void Do_not_download_orig_height() {// PURPOSE: handles links with only height specified; EX: [[File:Fresh_Pesto.jpeg|x210px|center]]
fxt .ini_page_create_en_wiki ("File:A.png");
fxt .Lnki_thumb_("A.png", -1, 210) // height-only request
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/291px-A.png", 291, 210)
, fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/220px-A.png", 220, 159)
, fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 2910, 2100)
)
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/291px.png" , 291, 210)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|y||2?0,0|1?220,159;1?291,210") // note that orig does not exist
);
fxt.tst();
fxt .Lnki_thumb_("A.png", -1, 210)
.Html_src_("file:///mem/trg/en.wikipedia.org/fit/7/0/A.png/291px.png")
.Html_size_(291, 210)
.tst();
}
@Test public void Upright_size_incorrect() {// PURPOSE.fix: incorrect image size being brought down; EX: w:ASCII; [[Image:ASCII Code Chart.svg|thumb|right|upright=1.6]]; 264, but should be 350
fxt .ini_page_create_en_wiki ("File:A.png");
fxt .Lnki_("A.png", true, -1, -1, 1.6, Xof_lnki_time.Null_as_int) // upright
.Src( fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 830, 328)
, fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/350px-A.png", 350, 138)
)
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/350px.png" , 350, 138)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|y||2?0,0|1?350,138")
);
fxt.tst();
}
@Test public void Width_height_retrieves_wrong_size() {// PURPOSE.fix: EX: c:Yellowstone Park; [[Image:YellowstoneLake.jpg|Yellowstone Lake|120x120px|thumb]];
fxt .ini_page_create_en_wiki ("File:A.png");
fxt .Lnki_thumb_("A.png", 120, 120)
.Src( fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 1756, 1204)
, fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/120px-A.png", 119, 82) // NOTE: wmf has 119px width, even though 120px file_name
)
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/119px.png" , 119, 82)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|y||2?0,0|1?119,82")
);
fxt.tst();
fxt .Lnki_thumb_("A.png", 120, 120)
.Html_src_("file:///mem/trg/en.wikipedia.org/fit/7/0/A.png/119px.png")
.Html_size_(120, 83)
.tst();
}
@Test public void Svg_thumb_can_be_bigger_than_orig__convert() {// PURPOSE: svg thumbs allowed to exceed orig in size; EX: w:Portal:Music; [[File:Treble a.svg|left|160px]]
fxt .ini_page_create_en_wiki ("File:A.svg");
fxt .Lnki_thumb_("A.svg", 220) // thumb = 220
.Src( fxt.svg_("mem/src/en.wikipedia.org/7/75/A.svg", 110, 100) // orig = 110
)
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/5/A.svg/220px.png" , 220, 200) // thumb = 220; not limited to 110
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/75.csv" , "A.svg|y||1?110,100|1?220,200")
)
.tst(
);
fxt .Lnki_thumb_("A.svg", 220)
.Html_src_("file:///mem/trg/en.wikipedia.org/fit/7/5/A.svg/220px.png")
.Html_size_(220, 200)
.tst();
}
@Test public void Ogv_width_seek_again_should_dirty() { // PURPOSE: outlier case wherein (a) downloading thumb then (b) downloading thumb seek; (b) does not dirty file since (a) exists; PAGE:en.w:Wikipedia
fxt.Src_en_wiki_repo().Ext_rules().Get_or_new(Xof_ext_.Bry_ogv).View_max_(0);
Io_mgr.Instance.SaveFilStr("mem/xowa/file/#meta/en.wikipedia.org/d/d0.csv", "A.ogv|0||2?0,0|1?300,40\n"); // simulate (a)
fxt .Lnki_("A.ogv", true, -1, -1, -1, 5)
.Src( fxt.img_("mem/src/commons.wikimedia.org/thumb/d/d0/A.ogv/-1px-seek%3D5-A.ogv.jpg", 300, 40)
)
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/fit/d/0/A.ogv/300px@5.jpg", 300, 40)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/d/d0.csv", "A.ogv|0||2?0,0|1?300,40@5")
)
.tst();
fxt.Src_en_wiki_repo().Ext_rules().Get_or_new(Xof_ext_.Bry_ogv).View_max_(-1);
}
@Test public void Webm() {
fxt .ini_page_create_commons ("File:A.webm");
fxt .Lnki_thumb_("A.webm", 220)
.Src( fxt.ogg_("mem/src/commons.wikimedia.org/3/34/A.webm")
, fxt.img_("mem/src/commons.wikimedia.org/thumb/3/34/A.webm/220px--A.webm.jpg", 300, 40)
)
.Trg( fxt.ogg_("mem/trg/commons.wikimedia.org/raw/3/4/A.webm")
, fxt.img_("mem/trg/commons.wikimedia.org/fit/3/4/A.webm/300px.jpg", 300, 40)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/3/34.csv", "A.webm|0||1?0,0|1?300,40")
)
.tst();
}
@Test public void Ogv_thumb() {// d00d1d5019e37cc219a91a2f8ad47bfe
fxt .ini_page_create_commons ("File:A.ogv");
fxt .Lnki_orig_("A.ogv")
.Src( fxt.img_("mem/src/commons.wikimedia.org/thumb/d/d0/A.ogv/-1px--A.ogv.jpg", 300, 40))
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/fit/d/0/A.ogv/300px.jpg", 300, 40)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/d/d0.csv", "A.ogv|0||0?0,0|1?300,40")
)
.tst();
fxt .Lnki_orig_("A.ogv")
.Html_src_("file:///mem/trg/commons.wikimedia.org/fit/d/0/A.ogv/300px.jpg")
.Html_size_(300, 40)
.tst();
}
@Test public void Thumbtime_ignored_if_non_media() { // PURPOSE: ignore thumbtime if not media; PAGE:en.w:Moon; EX:[[File:A.png|thumbtime=0.02]] DATE:2014-07-22
fxt .ini_page_create_en_wiki("File:A.png");
fxt .Lnki_("A.png", true, 90, Xof_img_size.Size__neg1, Xof_img_size.Size__neg1, 2) // thumbtime of 2 specified; will be ignored below
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/90px-A.png", 90, 80))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/90px.png", 90, 80)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|y||2?0,0|1?90,80")
);
fxt.tst();
}
// @Test public void Ogg_full_skip() { // DISABLED: 2012-12-03; not sure about logic
// fxt .ini_page_create_commons ("File:A.ogg");
// fxt .En_wiki().File_mgr().Repo_mgr().Repos_get_at(0).Src().Ext_rules().Get_or_new(Xof_ext_.Bry_ogg).View_max_(0); // set ogg to do not download
// fxt .Lnki_orig_("A.ogg")
// .Src( fxt.ogg_("mem/src/commons.wikimedia.org/4/2/A.ogg"))
// .Trg( fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/4/42.csv", "2|A.ogg|0|2?0,0|")
// );
// fxt.tst();
// fxt .En_wiki().File_mgr().Repo_mgr().Repos_get_at(0).Src().Ext_rules().Get_or_new(Xof_ext_.Bry_ogg).View_max_(1000); // undo above
// }
}

View File

@@ -1,60 +0,0 @@
/*
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.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.core.primitives.*; import gplx.dbs.*;
import gplx.core.ios.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.files.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*;
public class Xof_xfer_queue_html_fxt extends Xof_xfer_queue_base_fxt {
private final Xof_xfer_queue queue = new Xof_xfer_queue();
@Override public void Clear(boolean src_repo_is_wmf) {
Db_conn_bldr.Instance.Reg_default_mem();
super.Clear(src_repo_is_wmf);
this.Api_size().Clear();
}
public Xof_xfer_queue_html_fxt Lnki_orig_ (String lnki_ttl) {return Lnki_(lnki_ttl, Bool_.N, Xof_img_size.Size__neg1, Xof_img_size.Size__neg1, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int);}
public Xof_xfer_queue_html_fxt Lnki_thumb_(String lnki_ttl, int lnki_w) {return Lnki_(lnki_ttl, Bool_.Y, lnki_w, Xof_img_size.Size__neg1, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int);}
public Xof_xfer_queue_html_fxt Lnki_thumb_(String lnki_ttl, int lnki_w, int lnki_h) {return Lnki_(lnki_ttl, Bool_.Y, lnki_w, lnki_h, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int);}
public Xof_xfer_queue_html_fxt Lnki_(String lnki_ttl, boolean thumb, int lnki_w, int lnki_h, double upright, int seek_time) { // NOTE: only one xfer_itm; supports one Lnki_ per test only
Xowe_wiki wiki = this.En_wiki();
Xop_ctx ctx = wiki.Parser_mgr().Ctx();
xfer_itm = wiki.Html_mgr().Html_wtr().Lnki_wtr().File_wtr().Lnki_eval(Xof_exec_tid.Tid_wiki_page, ctx, ctx.Page(), queue, Bry_.new_u8(lnki_ttl), thumb ? Xop_lnki_type.Id_thumb : Xop_lnki_type.Id_null, upright, lnki_w, lnki_h, Xof_lnki_time.X_int(seek_time), Xof_lnki_page.Null, false);
return this;
}
public Xof_file_itm Xfer_itm() {return xfer_itm;} private Xof_file_itm xfer_itm;
public Xof_xfer_queue_html_fxt Src(Io_fil... v) {return (Xof_xfer_queue_html_fxt)Src_base(v);}
public Xof_xfer_queue_html_fxt Trg(Io_fil... v) {return (Xof_xfer_queue_html_fxt)Trg_base(v);}
public Xof_xfer_queue_html_fxt Html_src_(String v) {return (Xof_xfer_queue_html_fxt)Html_src_base_(v);}
public Xof_xfer_queue_html_fxt Html_size_(int w, int h) {this.Html_w_(w); this.Html_h_(h); return this;}
public Xof_xfer_queue_html_fxt Html_orig_src_(String v) {html_orig_src = v; return this;} private String html_orig_src;
public Xof_xfer_queue_html_fxt ini_page_api(String wiki_str, String ttl_str, String redirect_str, int orig_w, int orig_h) {return ini_page_api(wiki_str, ttl_str, redirect_str, orig_w, orig_h, true);}
public Xof_xfer_queue_html_fxt ini_page_api(String wiki_str, String ttl_str, String redirect_str, int orig_w, int orig_h, boolean pass) {
String wiki_key = String_.Eq(wiki_str, "commons") ? Xow_domain_itm_.Str__commons : Xow_domain_itm_.Str__enwiki;
this.Api_size().Ini(wiki_key, ttl_str, redirect_str, orig_w, orig_h, pass);
return this;
}
@gplx.Virtual public void tst() {
Xowe_wiki wiki = this.En_wiki();
ini_src_fils();
wiki.File_mgr().Cfg_download().Enabled_(true);
queue.Exec(wiki, Xoae_page.New(wiki, wiki.Ttl_parse(Bry_.new_a7("A"))));
tst_trg_fils();
if (this.html_orig_src != null) Tfds.Eq(this.html_orig_src , xfer_itm.Html_orig_url().To_http_file_str());
if (this.Html_view_src() != null) Tfds.Eq(this.Html_view_src(), xfer_itm.Html_view_url().To_http_file_str());
if (this.Html_w() != -1) Tfds.Eq(this.Html_w(), xfer_itm.Html_w());
if (this.Html_h() != -1) Tfds.Eq(this.Html_h(), xfer_itm.Html_h());
queue.Clear();
}
}

View File

@@ -1,28 +0,0 @@
/*
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.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
public class Xof_xfer_queue_html_offline_tst {
Xof_xfer_queue_html_fxt fxt = new Xof_xfer_queue_html_fxt();
@Before public void init() {fxt.Clear(true); fxt.Src_commons_repo().Tarball_(true); fxt.Src_en_wiki_repo().Tarball_(true);}
@Test public void Missing() { // PURPOSE.fix: missing image was not being marked as missing; DATE:20121227
fxt .Lnki_("A.png", true, 220, -1, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int)
.Src()
.Trg( fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|x||0?0,0|")
)
.tst();
}
}

View File

@@ -1,171 +0,0 @@
/*
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.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import org.junit.*; import gplx.xowa.parsers.lnkis.*;
public class Xof_xfer_queue_html_wmf_api_tst {
private final Xof_xfer_queue_html_fxt fxt = new Xof_xfer_queue_html_fxt();
@Before public void init() {
gplx.core.ios.IoEngine_system.Web_access_enabled = true; // NOTE: must set to true, else Wmf_api calls below will always return false
fxt.Clear(true); fxt.Src_commons_repo().Wmf_api_(true); fxt.Src_en_wiki_repo().Wmf_api_(true);
}
@Test public void Thumb() {
fxt .ini_page_api("en_wiki", "A.png", "", 2200, 2000);
fxt .Lnki_thumb_("A.png", 220)
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/220px-A.png", 220, 200))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/220px.png", 220, 200)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|y||2?2200,2000|1?220,200")
)
.tst();
}
@Test public void Redirect() {
fxt .ini_page_api("en_wiki", "B.png", "A.png", 2200, 2000);
fxt .Lnki_thumb_("B.png", 220)
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/220px-A.png", 220, 200))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/220px.png", 220, 200)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/5/57.csv", "B.png|y|A.png|2?2200,2000|1?220,200")
)
.tst();
}
@Test public void Svg_thumb_can_be_bigger_than_orig__download() {// PURPOSE: svg thumbs allowed to exceed orig in size; EX: w:Portal:Music; [[File:Treble a.svg|left|160px]]
fxt .ini_page_api("en_wiki", "A.svg", "", 110, 100); // put orig of 110,100 on server
fxt .Lnki_thumb_("A.svg", 220) // request 220
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/75/A.svg/220px-A.svg.png", 220, 200) // thumb = 220
)
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/5/A.svg/220px.png" , 220, 200) // thumb = 220
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/75.csv" , "A.svg|y||2?110,100|1?220,200")
)
.tst();
fxt .Lnki_thumb_("A.svg", 220)
.Html_src_("file:///mem/trg/en.wikipedia.org/fit/7/5/A.svg/220px.png")
.Html_size_(220, 200)
.tst();
}
@Test public void Pdf() {// PURPOSE: main page always assumes size of 800x600; if actual size does not scale to 800x600, don't redownload; [[File:Physical world.pdf|thumb]]
fxt.ini_page_api("en_wiki", "A.pdf", "", 6600, 5100);
fxt .ini_page_create_commons ("File:A.pdf");
fxt .Lnki_thumb_("A.pdf", 800, 600)
.Src( fxt.img_("mem/src/en.wikipedia.org/e/ef/A.pdf", 6600, 5100)
, fxt.img_("mem/src/en.wikipedia.org/thumb/e/ef/A.pdf/page1-777px-A.pdf.jpg", 777, 600)
)
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/e/f/A.pdf/777px.jpg", 777, 600)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/e/ef.csv", "A.pdf|y||2?6600,5100|1?777,600")
)
.tst();
fxt .Lnki_thumb_("A.pdf", 800, 600)
.Html_src_("file:///mem/trg/en.wikipedia.org/fit/e/f/A.pdf/777px.jpg")
.Html_size_(777, 600)
.tst();
}
@Test public void Upright_defect() { // PURPOSE.fix: upright not working; PAGE:en.w:Beethoven; [[File:Rudolf-habsburg-olmuetz.jpg|thumb|upright|]]; changed upright to = Upright_default; DATE:2014-05-23
fxt .ini_page_api("en_wiki", "A.png", "", 1378, 1829);
fxt .Lnki_("A.png", true, -1, -1, Xof_img_size.Upright_default_marker, Xof_lnki_time.Null_as_int)
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/170px-A.png", 170, 226))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/170px.png", 170, 226)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|y||2?1378,1829|1?170,226")
)
.tst();
}
@Test public void Height_only() { // PURPOSE.fix: height only was still using old infer-size code; EX:w:[[File:Upper and Middle Manhattan.jpg|x120px]]; DATE:2012-12-27
fxt .ini_page_api("en_wiki", "A.png", "", 12591, 1847);
fxt .Lnki_("A.png", false, -1, 130, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int)
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/887px-A.png", 887, 130))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/887px.png", 887, 130)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|y||2?12591,1847|1?887,130")
)
.tst();
}
@Test public void Width_only_height_ignored() {// PURPOSE.fix: if height is not specified, do not recalc; needed when true scaled height is 150x151 but WM has 150x158; defect would discard 150x158; EX:[[File:Tokage_2011-07-15.jpg|150px]] simple.wikipedia.org/wiki/2011_Pacific_typhoon_season; DATE:2013-06-03
fxt .ini_page_api("en_wiki", "A.png", "", 4884, 4932);
fxt .Lnki_("A.png", true, 150, -1, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int)
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/150px-A.png", 150, 158))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/150px.png", 150, 158)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|y||2?4884,4932|1?150,158")
)
.tst();
}
@Test public void Missing_was_not_being_marked() { // PURPOSE.fix: missing image was not showing up as repo=x in meta; DATE:2013-01-10
fxt .Lnki_("A.png", false, -1, 130, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int)
.Src()
.Trg( fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|x||0?0,0|")
)
.tst();
}
@Test public void Missing_was_not_redownloaded() { // PURPOSE.fix: missing image was not being redownloaded; DATE:2013-01-26
fxt.save_(fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|x||0?0,0|")); // mark file as missing
fxt .ini_page_api("en_wiki", "A.png", "", 220, 200);
fxt.En_wiki().File_mgr().Cfg_download().Redownload_(Xof_cfg_download.Redownload_missing); // redownload for missing
fxt .Lnki_orig_("A.png")
.Src( fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 220, 200))
.Trg( fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|x||1?220,200|")// check that file shows up
)
.tst();
fxt.En_wiki().File_mgr().Cfg_download().Redownload_(Xof_cfg_download.Redownload_none); // redownload back to none (for other tests)
}
@Test public void Error_should_not_abort() { // PURPOSE: API sometimes returns xml but no <iinfo> node; try to download anyway
fxt .ini_page_api("commons", "A.png", "", 2200, 2000, false);
fxt .Lnki_thumb_("A.png", 220)
.Src( fxt.img_("mem/src/commons.wikimedia.org/thumb/7/70/A.png/220px-A.png", 220, 200))
.Trg( fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|0||0?0,0|1?220,200")
)
.tst();
}
@Test public void Tilde() {
fxt .ini_page_api("en_wiki", "A~.png", "", 2200, 2000);
fxt .Lnki_thumb_("A~.png", 220)
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/a/a5/A%7E.png/220px-A%7E.png", 220, 200))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/a/5/A~.png/220px.png", 220, 200)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/a/a5.csv", "A~~.png|y||2?2200,2000|1?220,200") // NOTE: tildes are doubled in meta file
)
.tst();
}
@Test public void Missing_from_1st_repo() { // PURPOSE: WMF now requires that API goes to image's actual repo (used to accept http://en.wikipedia.org and return back http://commons.wikimedia.org) DATE:2013-03-11
fxt .ini_page_api("commons", "A.png", "B.png", 2200, 2000); // put the redirect in commons wiki
fxt .Lnki_thumb_("A.png", 220)
.Src( fxt.img_("mem/src/commons.wikimedia.org/thumb/5/57/B.png/220px-B.png", 220, 200))
.Trg( fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|0|B.png|2?2200,2000|1?220,200")
)
.tst();
}
@Test public void Ogg_audio() { // PURPOSE: ogg is audio; (a) do not download thumb; (b) get from correct wiki; DATE:2013-08-03
fxt .ini_page_create_commons("File:A.ogg");
fxt .ini_page_api("commons", "A.ogg", "", 0, 0);
fxt .Lnki_("A.ogg", false, -1, -1, 1, Xof_lnki_time.Null_as_int)
.Src( fxt.img_("mem/src/commons.wikimedia.org/4/42/A.ogg", 0, 0))
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/raw/4/2/A.ogg", 0, 0)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/4/42.csv" , "A.ogg|0||1?0,0|0?0,0")
)
.tst();
}
@Test public void Height_should_precede_width() {// PURPOSE: height should precede width; EX: <gallery>David_Self_Portrait.jpg</gallery>; c:Jacques-Louis David
fxt.save_(fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|z||2?0,0|1?86,121;1?120,168"));
fxt .Lnki_thumb_("A.png", 120, 120)
.Html_src_("file:///mem/trg/en.wikipedia.org/fit/7/0/A.png/86px.png")
.Html_size_(85, 120)
.tst();
}
@Test public void Imap() { // PURPOSE: check that imap downloads orig, even when thumb is requested; DATE:2014-08-08
fxt .ini_page_create_commons("File:A.png");
fxt .ini_page_api("commons", "A.png", "", 180, 160);
fxt .Lnki_("A.png", true, 90, Xof_img_size.Size__neg1, Xof_img_size.Size__neg1, Xof_lnki_time.Null_as_int); // thumbtime of 2 specified; will be ignored below
fxt .Xfer_itm().Html_elem_tid_(Xof_html_elem.Tid_imap);
fxt .Src( fxt.img_("mem/src/commons.wikimedia.org/thumb/7/70/A.png/90px-A.png", 90, 80))
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/fit/7/0/A.png/90px.png", 90, 80)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|0||2?180,160|1?90,80") // check that orig has 180,160, not 0,0
);
fxt.tst();
}
}