modules/libjar/zipwriter/test/unit/test_bug419769_2.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:7cb21d614544
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 */
5
6 const DATA = "";
7 const FILENAME = "test.txt";
8 const CRC = 0x00000000;
9 const time = Date.now();
10
11 function testpass(source)
12 {
13 // Should exist.
14 do_check_true(source.hasEntry(FILENAME));
15
16 var entry = source.getEntry(FILENAME);
17 do_check_neq(entry, null);
18
19 do_check_false(entry.isDirectory);
20
21 // Should be stored
22 do_check_eq(entry.compression, ZIP_METHOD_DEFLATE);
23
24 // File size should match our data size.
25 do_check_eq(entry.realSize, DATA.length);
26
27 // Check that the CRC is accurate
28 do_check_eq(entry.CRC32, CRC);
29 }
30
31 function run_test()
32 {
33 zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
34
35 // Shouldn't be there to start with.
36 do_check_false(zipW.hasEntry(FILENAME));
37
38 do_check_false(zipW.inQueue);
39
40 var file = do_get_file(DATA_DIR + "emptyfile.txt");
41 zipW.addEntryFile(FILENAME, Ci.nsIZipWriter.COMPRESSION_BEST, file, false);
42
43 // Check that zip state is right at this stage.
44 testpass(zipW);
45 zipW.close();
46
47 // Check to see if we get the same results loading afresh.
48 zipW.open(tmpFile, PR_RDWR);
49 testpass(zipW);
50 zipW.close();
51
52 // Test the stored data with the zipreader
53 var zipR = new ZipReader(tmpFile);
54 testpass(zipR);
55 zipR.test(FILENAME);
56 var stream = Cc["@mozilla.org/scriptableinputstream;1"]
57 .createInstance(Ci.nsIScriptableInputStream);
58 stream.init(zipR.getInputStream(FILENAME));
59 var result = stream.read(DATA.length);
60 stream.close();
61 zipR.close();
62
63 do_check_eq(result, DATA);
64 }

mercurial