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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:a5fd6237e762
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 = "ZIP WRITER TEST DATA";
7 const FILENAME = "test.txt";
8 const CRC = 0xe6164331;
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 run_test()
13 {
14 zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
15
16 // Shouldn't be there to start with.
17 do_check_false(zipW.hasEntry(FILENAME));
18
19 do_check_false(zipW.inQueue);
20
21 var stream = Cc["@mozilla.org/io/string-input-stream;1"]
22 .createInstance(Ci.nsIStringInputStream);
23 stream.setData(DATA, DATA.length);
24 zipW.addEntryStream(FILENAME, time * PR_USEC_PER_MSEC,
25 Ci.nsIZipWriter.COMPRESSION_BEST, stream, false);
26
27 var entry = zipW.getEntry(FILENAME);
28
29 do_check_true(entry != null);
30
31 // Check entry seems right.
32 do_check_eq(entry.compression, ZIP_METHOD_DEFLATE);
33 do_check_eq(entry.CRC32, CRC);
34 do_check_eq(entry.realSize, DATA.length);
35 do_check_eq(entry.lastModifiedTime / PR_USEC_PER_MSEC, time);
36
37 zipW.close();
38
39 // Test the stored data with the zipreader
40 var zipR = new ZipReader(tmpFile);
41 do_check_true(zipR.hasEntry(FILENAME));
42
43 zipR.test(FILENAME);
44
45 var stream = Cc["@mozilla.org/scriptableinputstream;1"]
46 .createInstance(Ci.nsIScriptableInputStream);
47 stream.init(zipR.getInputStream(FILENAME));
48 var result = stream.read(DATA.length);
49 stream.close();
50 zipR.close();
51
52 do_check_eq(result, DATA);
53 }

mercurial