-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#32 Merge branch 'master' into v1.6 (mainly the unit tests)
- Loading branch information
Showing
34 changed files
with
1,070 additions
and
802 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...lLibrary/app/src/androidTest/java/org/mewx/wenku8/global/api/NovelItemInfoUpdateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.mewx.wenku8.global.api; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class NovelItemInfoUpdateTest { | ||
|
||
@Test | ||
public void convertFromMeta() { | ||
final String META_XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + | ||
"<metadata>\n" + | ||
"<data name=\"Title\" aid=\"1306\"><![CDATA[向森之魔物献上花束(向森林的魔兽少女献花)]]></data>\n" + | ||
"<data name=\"Author\" value=\"小木君人\"/>\n" + | ||
"<data name=\"DayHitsCount\" value=\"26\"/>\n" + | ||
"<data name=\"TotalHitsCount\" value=\"43984\"/>\n" + | ||
"<data name=\"PushCount\" value=\"1735\"/>\n" + | ||
"<data name=\"FavCount\" value=\"848\"/>\n" + | ||
"<data name=\"PressId\" value=\"小学馆\" sid=\"10\"/>\n" + | ||
"<data name=\"BookStatus\" value=\"已完成\"/>\n" + | ||
"<data name=\"BookLength\" value=\"105985\"/>\n" + | ||
"<data name=\"LastUpdate\" value=\"2012-11-02\"/>\n" + | ||
"<data name=\"LatestSection\" cid=\"41897\"><![CDATA[第一卷 插图]]></data>\n" + | ||
"</metadata>"; | ||
NovelItemMeta meta = Wenku8Parser.parseNovelFullMeta(META_XML); | ||
assertNotNull(meta); | ||
|
||
NovelItemInfoUpdate info = NovelItemInfoUpdate.convertFromMeta(meta); | ||
assertEquals("向森之魔物献上花束(向森林的魔兽少女献花)", info.title); | ||
assertEquals(1306, info.aid); | ||
assertEquals("小木君人", info.author); | ||
assertEquals("已完成", info.status); | ||
assertEquals("2012-11-02", info.update); | ||
assertEquals("第一卷 插图", info.latest_chapter); | ||
} | ||
|
||
@Test | ||
public void parseNovelItemInfoUpdate() { | ||
final String XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + | ||
"<metadata>\n" + | ||
"<data name=\"Title\" aid=\"1305\"><![CDATA[绝对双刃absolute duo]]></data>\n" + | ||
"<data name=\"Author\" value=\"柊★巧\"/>\n" + | ||
"<data name=\"BookStatus\" value=\"连载中\"/>\n" + | ||
"<data name=\"LastUpdate\" value=\"2014-10-01\"/>\n" + | ||
"<data\n" + | ||
"name=\"IntroPreview\"><![CDATA[ 「焰牙」——那是藉由超化之后的精神力将自身灵...]]></data>\n" + | ||
"</metadata>"; | ||
NovelItemInfoUpdate info = NovelItemInfoUpdate.parse(XML); | ||
assertNotNull(info); | ||
|
||
assertEquals("绝对双刃absolute duo", info.title); | ||
assertEquals(1305, info.aid); | ||
assertEquals("柊★巧", info.author); | ||
assertEquals("连载中", info.status); | ||
assertEquals("2014-10-01", info.update); | ||
assertEquals("「焰牙」——那是藉由超化之后的精神力将自身灵...", info.intro_short); | ||
} | ||
|
||
@Test | ||
public void parseNovelItemInfoUpdateInvalid() { | ||
NovelItemInfoUpdate info = NovelItemInfoUpdate.parse("1234"); | ||
assertNull(info); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...rary/app/src/androidTest/java/org/mewx/wenku8/global/api/NovelListWithInfoParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.mewx.wenku8.global.api; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class NovelListWithInfoParserTest { | ||
private static final String XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + | ||
"<result>\n" + | ||
"<page num='166'/>\n" + | ||
"\n" + | ||
"<item aid='1034'>\n" + | ||
"<data name='Title'><![CDATA[恶魔高校DxD(High School DxD)]]></data>\n" + | ||
"<data name='TotalHitsCount' value='2316361'/>\n" + | ||
"<data name='PushCount' value='153422'/>\n" + | ||
"<data name='FavCount' value='14416'/>\n" + | ||
"<data name='Author' value='xxx1'/>\n" + | ||
"<data name='BookStatus' value='xxx2'/>\n" + | ||
"<data name='LastUpdate' value='xxx3'/>\n" + | ||
"<data name='IntroPreview' value='xxx4'/>\n" + | ||
"</item>\n" + | ||
"\n" + | ||
"<item aid='1035'>\n" + | ||
"<data name='Title'><![CDATA[High School DxD]]></data>\n" + | ||
"<data name='TotalHitsCount' value='1234'/>\n" + | ||
"<data name='PushCount' value='4567'/>\n" + | ||
"<data name='FavCount' value='789'/>\n" + | ||
"<data name='Author' value='yyy1'/>\n" + | ||
"<data name='BookStatus' value='yyy2'/>\n" + | ||
"<data name='LastUpdate' value='yyy3'/>\n" + | ||
"<data name='IntroPreview' value='yyy4'/>\n" + | ||
"</item>\n" + | ||
"\n" + | ||
"</result>"; | ||
|
||
@Test | ||
public void getNovelListWithInfoPageNumInvalid() { | ||
assertEquals(0, NovelListWithInfoParser.getNovelListWithInfoPageNum("1234")); | ||
} | ||
|
||
@Test | ||
public void getNovelListWithInfoPageNum() { | ||
assertEquals(166, NovelListWithInfoParser.getNovelListWithInfoPageNum(XML)); | ||
} | ||
|
||
|
||
@Test | ||
public void getNovelListWithInfoInvalid() { | ||
List<NovelListWithInfoParser.NovelListWithInfo> list = NovelListWithInfoParser.getNovelListWithInfo("1234"); | ||
assertTrue(list.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void getNovelListWithInfo() { | ||
List<NovelListWithInfoParser.NovelListWithInfo> list = NovelListWithInfoParser.getNovelListWithInfo(XML); | ||
assertEquals(2, list.size()); | ||
|
||
NovelListWithInfoParser.NovelListWithInfo info = list.get(0); | ||
assertEquals(1034, info.aid); | ||
assertEquals(14416, info.fav); | ||
assertEquals(2316361, info.hit); | ||
assertEquals(153422, info.push); | ||
assertEquals("恶魔高校DxD(High School DxD)", info.name); | ||
|
||
info = list.get(1); | ||
assertEquals(1035, info.aid); | ||
assertEquals(789, info.fav); | ||
assertEquals(1234, info.hit); | ||
assertEquals(4567, info.push); | ||
assertEquals("High School DxD", info.name); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...ibrary/app/src/androidTest/java/org/mewx/wenku8/global/api/OldNovelContentParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package org.mewx.wenku8.global.api; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.mewx.wenku8.global.api.OldNovelContentParser.NovelContentType.*; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class OldNovelContentParserTest { | ||
private static final String NOVEL_CONTENT = "line 1\r\n" + | ||
" <!--image-->http://bbbbb.com/pictures/1/1339/90903/107724.jpg<!--image--> \r\n" + | ||
" line 2 \r\n\r\n" + | ||
"<!--image-->http://bbbbb.com/pictures/1/1339/90903/107725.jpg<!--image-->\r\n" + | ||
"line 3\r\n"; | ||
|
||
private static final String NOVEL_CONTENt_BROKEN_IMAGE = "line 1\r\n" + | ||
" <!--image-->http://bbbbb.com/pictures/1/1339/90903/107724.jpg<!--image--> \r\n" + | ||
" line 2 \r\n\r\n" + | ||
" <!--image-->http://bbbbb.com/pictures/1/1339/90903/107725.jpg \r\n" + | ||
"line 3\r\n"; | ||
|
||
@Test | ||
public void parseNovelContent() { | ||
List<OldNovelContentParser.NovelContent> contents = OldNovelContentParser.parseNovelContent(NOVEL_CONTENT, null); | ||
assertEquals(5, contents.size()); | ||
|
||
OldNovelContentParser.NovelContent tempContent = contents.get(0); | ||
assertEquals(TEXT, tempContent.type); | ||
assertEquals("line 1", tempContent.content); | ||
|
||
tempContent = contents.get(1); | ||
assertEquals(IMAGE, tempContent.type); | ||
assertEquals("http://bbbbb.com/pictures/1/1339/90903/107724.jpg", tempContent.content); | ||
|
||
tempContent = contents.get(2); | ||
assertEquals(TEXT, tempContent.type); | ||
assertEquals("line 2", tempContent.content); | ||
|
||
tempContent = contents.get(3); | ||
assertEquals(IMAGE, tempContent.type); | ||
assertEquals("http://bbbbb.com/pictures/1/1339/90903/107725.jpg", tempContent.content); | ||
|
||
tempContent = contents.get(4); | ||
assertEquals(TEXT, tempContent.type); | ||
assertEquals("line 3", tempContent.content); | ||
} | ||
|
||
@Test | ||
public void parseNovelContentWithIncompleteImageTag() { | ||
List<OldNovelContentParser.NovelContent> contents = OldNovelContentParser.parseNovelContent(NOVEL_CONTENt_BROKEN_IMAGE, null); | ||
assertEquals(5, contents.size()); | ||
|
||
OldNovelContentParser.NovelContent tempContent = contents.get(0); | ||
assertEquals(TEXT, tempContent.type); | ||
assertEquals("line 1", tempContent.content); | ||
|
||
tempContent = contents.get(1); | ||
assertEquals(IMAGE, tempContent.type); | ||
assertEquals("http://bbbbb.com/pictures/1/1339/90903/107724.jpg", tempContent.content); | ||
|
||
tempContent = contents.get(2); | ||
assertEquals(TEXT, tempContent.type); | ||
assertEquals("line 2", tempContent.content); | ||
|
||
tempContent = contents.get(3); | ||
assertEquals(TEXT, tempContent.type); | ||
assertEquals("<!--image-->http://bbbbb.com/pictures/1/1339/90903/107725.jpg", tempContent.content); | ||
|
||
tempContent = contents.get(4); | ||
assertEquals(TEXT, tempContent.type); | ||
assertEquals("line 3", tempContent.content); | ||
} | ||
|
||
@Test | ||
public void novelContentParser_onlyImage() { | ||
List<OldNovelContentParser.NovelContent> contents = OldNovelContentParser.NovelContentParser_onlyImage(NOVEL_CONTENT); | ||
assertEquals(2, contents.size()); | ||
|
||
OldNovelContentParser.NovelContent tempContent = contents.get(0); | ||
assertEquals(IMAGE, tempContent.type); | ||
assertEquals("http://bbbbb.com/pictures/1/1339/90903/107724.jpg", tempContent.content); | ||
|
||
tempContent = contents.get(1); | ||
assertEquals(IMAGE, tempContent.type); | ||
assertEquals("http://bbbbb.com/pictures/1/1339/90903/107725.jpg", tempContent.content); | ||
} | ||
|
||
@Test | ||
public void novelContentParser_onlyImageBroken() { | ||
List<OldNovelContentParser.NovelContent> contents = OldNovelContentParser.NovelContentParser_onlyImage(NOVEL_CONTENt_BROKEN_IMAGE); | ||
assertEquals(1, contents.size()); | ||
|
||
OldNovelContentParser.NovelContent tempContent = contents.get(0); | ||
assertEquals(IMAGE, tempContent.type); | ||
assertEquals("http://bbbbb.com/pictures/1/1339/90903/107724.jpg", tempContent.content); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...d/LightNovelLibrary/app/src/androidTest/java/org/mewx/wenku8/global/api/UserInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.mewx.wenku8.global.api; | ||
|
||
import android.support.test.filters.SmallTest; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
@SmallTest | ||
public class UserInfoTest { | ||
private static final String USER_INFO_XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + | ||
"<metadata>\n" + | ||
"<item name=\"uname\"><![CDATA[apptest]]></item>\n" + | ||
"<item name=\"nickname\"><![CDATA[apptest nick]]></item>\n" + | ||
"<item name=\"score\">100</item>\n" + | ||
"<item name=\"experience\">10</item>\n" + | ||
"<item name=\"rank\"><![CDATA[新手上路]]></item>\n" + | ||
"</metadata>"; | ||
|
||
@Test | ||
public void parseUserInfo() { | ||
UserInfo ui = UserInfo.parseUserInfo(USER_INFO_XML); | ||
assertNotNull(ui); | ||
assertEquals("apptest", ui.username); | ||
assertEquals("apptest nick", ui.nickyname); | ||
assertEquals(10, ui.experience); | ||
assertEquals(100, ui.score); | ||
assertEquals("新手上路", ui.rank); | ||
} | ||
|
||
@Test | ||
public void parseInvalidUserInfo() { | ||
UserInfo ui = UserInfo.parseUserInfo("adfsdfasdfasdf"); | ||
assertNull(ui); | ||
} | ||
} |
Oops, something went wrong.