@@ -44,32 +44,38 @@ private static String getTextFileContent(String path)
4444 return new String (getFileContent (path ));
4545 }
4646
47- @ Test
48- public void testArchive ()
49- throws JNIKiwixException , IOException , ZimFileFormatException {
50- Archive archive = new Archive ("small.zim" );
47+ private void testArchive (Archive archive )
48+ throws IOException {
5149 // test the zim file main page title
5250 assertEquals ("Test ZIM file" , archive .getMainEntry ().getTitle ());
5351 // test zim file size
5452 assertEquals (4070 , archive .getFilesize ()); // The file size is in KiB
5553 // test zim file main url
5654 assertEquals ("A/main.html" , archive .getMainEntry ().getPath ());
5755 // test zim file content
58- String s = getTextFileContent ("small_zimfile_data/main.html" );
59- String c = archive .getEntryByPath ("A/main.html" ).getItem (true ).getData ().getData ();
60- assertEquals ( s , c );
56+ byte [] mainData = getFileContent ("small_zimfile_data/main.html" );
57+ byte [] inZimMainData = archive .getEntryByPath ("A/main.html" ).getItem (true ).getData ().getData ();
58+ assert ( Arrays . equals ( mainData , inZimMainData ) );
6159
6260 // test zim file icon
63- byte [] faviconData = getFileContent ("small_zimfile_data/favicon.png" );
6461 assertEquals (true , archive .hasIllustration (48 ));
62+ byte [] faviconData = getFileContent ("small_zimfile_data/favicon.png" );
6563 Item item = archive .getIllustrationItem (48 );
6664 assertEquals (faviconData .length , item .getSize ());
65+ assert (Arrays .equals (faviconData , item .getData ().getData ()));
6766
68- DirectAccessInfo dai = archive .getEntryByPath ("I/favicon.png" ).getItem (true ).getDirectAccessInformation ();
67+ // Checking direct access information
68+ DirectAccessInfo dai = item .getDirectAccessInformation ();
6969 assertNotEquals ("" , dai .filename );
70- c = new String (getFileContentPartial (dai .filename , (int ) dai .offset , faviconData .length ));
71- assertEquals (new String (faviconData ), c );
70+ byte [] readData = getFileContentPartial (dai .filename , (int ) dai .offset , (int ) item .getSize ());
71+ assert (Arrays .equals (faviconData , readData ));
72+ }
7273
74+ @ Test
75+ public void testArchiveDirect ()
76+ throws JNIKiwixException , IOException , ZimFileFormatException {
77+ Archive archive = new Archive ("small.zim" );
78+ testArchive (archive );
7379 archive .dispose ();
7480
7581 // test reader with invalid zim file
@@ -87,28 +93,7 @@ public void testArchiveByFd()
8793 throws JNIKiwixException , IOException , ZimFileFormatException {
8894 FileInputStream fis = new FileInputStream ("small.zim" );
8995 Archive archive = new Archive (fis .getFD ());
90- // test the zim file main page title
91- assertEquals ("Test ZIM file" , archive .getMainEntry ().getTitle ());
92- // test zim file size
93- assertEquals (4070 , archive .getFilesize ()); // The file size is in KiB
94- // test zim file main url
95- assertEquals ("A/main.html" , archive .getMainEntry ().getPath ());
96- // test zim file content
97- String s = getTextFileContent ("small_zimfile_data/main.html" );
98- String c = archive .getEntryByPath ("A/main.html" ).getItem (true ).getData ().getData ();
99- assertEquals (s , c );
100-
101- // test zim file icon
102- byte [] faviconData = getFileContent ("small_zimfile_data/favicon.png" );
103- assertEquals (true , archive .hasIllustration (48 ));
104- Item item = archive .getIllustrationItem (48 );
105- assertEquals (faviconData .length , item .getSize ());
106-
107- DirectAccessInfo dai = archive .getEntryByPath ("I/favicon.png" ).getItem (true ).getDirectAccessInformation ();
108- assertNotEquals ("" , dai .filename );
109- c = new String (getFileContentPartial (dai .filename , (int ) dai .offset , faviconData .length ));
110- assertEquals (new String (faviconData ), c );
111-
96+ testArchive (archive );
11297 archive .dispose ();
11398 }
11499
@@ -118,29 +103,7 @@ public void testArchiveWithAnEmbeddedArchive()
118103 File plainArchive = new File ("small.zim" );
119104 FileInputStream fis = new FileInputStream ("small.zim.embedded" );
120105 Archive archive = new Archive (fis .getFD (), 8 , plainArchive .length ());
121- // test the zim file main page title
122- assertEquals ("Test ZIM file" , archive .getMainEntry ().getTitle ());
123- // test zim file size
124- assertEquals (4070 , archive .getFilesize ()); // The file size is in KiB
125- // test zim file main url
126- assertEquals ("A/main.html" , archive .getMainEntry ().getPath ());
127- // test zim file content
128- String s = getTextFileContent ("small_zimfile_data/main.html" );
129- String c = archive .getEntryByPath ("A/main.html" ).getItem (true ).getData ().getData ();
130- assertEquals (s , c );
131-
132- // test zim file icon
133- byte [] faviconData = getFileContent ("small_zimfile_data/favicon.png" );
134- assertEquals (true , archive .hasIllustration (48 ));
135- Item item = archive .getIllustrationItem (48 );
136- assertEquals (faviconData .length , item .getSize ());
137- assertEquals (new String (faviconData ), item .getData ().getData ());
138-
139- DirectAccessInfo dai = archive .getEntryByPath ("I/favicon.png" ).getItem (true ).getDirectAccessInformation ();
140- assertNotEquals ("" , dai .filename );
141- c = new String (getFileContentPartial (dai .filename , (int ) dai .offset , faviconData .length ));
142- assertEquals (new String (faviconData ), c );
143-
106+ testArchive (archive );
144107 archive .dispose ();
145108 }
146109
0 commit comments