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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:d4821323f900
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 // XXX Must use a constant time here away from DST changes. See bug 402434.
10 const time = 1199145600000; // Jan 1st 2008
11
12 function testpass(source)
13 {
14 // Should exist.
15 do_check_true(source.hasEntry(FILENAME));
16
17 var entry = source.getEntry(FILENAME);
18 do_check_neq(entry, null);
19
20 do_check_false(entry.isDirectory);
21
22 // Should be stored
23 do_check_eq(entry.compression, ZIP_METHOD_DEFLATE);
24
25 do_check_eq(entry.lastModifiedTime / PR_USEC_PER_MSEC, time);
26
27 // File size should match our data size.
28 do_check_eq(entry.realSize, DATA.length);
29
30 // Check that the CRC is accurate
31 do_check_eq(entry.CRC32, CRC);
32 }
33
34 function run_test()
35 {
36 zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
37
38 // Shouldn't be there to start with.
39 do_check_false(zipW.hasEntry(FILENAME));
40
41 do_check_false(zipW.inQueue);
42
43 var stream = Cc["@mozilla.org/io/string-input-stream;1"]
44 .createInstance(Ci.nsIStringInputStream);
45 stream.setData(DATA, DATA.length);
46 zipW.addEntryStream(FILENAME, time * PR_USEC_PER_MSEC,
47 Ci.nsIZipWriter.COMPRESSION_BEST, stream, false);
48
49 // Check that zip state is right at this stage.
50 testpass(zipW);
51 zipW.close();
52
53 // Check to see if we get the same results loading afresh.
54 zipW.open(tmpFile, PR_RDWR);
55 testpass(zipW);
56 zipW.close();
57
58 // Test the stored data with the zipreader
59 var zipR = new ZipReader(tmpFile);
60 testpass(zipR);
61 zipR.test(FILENAME);
62 var stream = Cc["@mozilla.org/scriptableinputstream;1"]
63 .createInstance(Ci.nsIScriptableInputStream);
64 stream.init(zipR.getInputStream(FILENAME));
65 var result = stream.read(DATA.length);
66 stream.close();
67 zipR.close();
68
69 do_check_eq(result, DATA);
70 }

mercurial