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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:52168bf65459
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 // Values taken from using zipinfo to list the test.zip contents
7 var TESTS = [
8 {
9 name: "test.txt",
10 size: 232,
11 crc: 0x0373ac26
12 },
13 {
14 name: "test.png",
15 size: 3402,
16 crc: 0x504a5c30
17 }
18 ];
19
20 function run_test()
21 {
22 zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
23
24 var size = 0;
25 for (var i = 0; i < TESTS.length; i++) {
26 var source = do_get_file(DATA_DIR + TESTS[i].name);
27 zipW.addEntryFile(TESTS[i].name, Ci.nsIZipWriter.COMPRESSION_NONE, source,
28 false);
29 size += ZIP_FILE_HEADER_SIZE + ZIP_CDS_HEADER_SIZE +
30 (ZIP_EXTENDED_TIMESTAMP_SIZE * 2) +
31 (TESTS[i].name.length*2) + TESTS[i].size;
32 }
33
34 zipW.close();
35 size += ZIP_EOCDR_HEADER_SIZE;
36
37 do_check_eq(size, tmpFile.fileSize);
38
39 // Test the stored data with the zipreader
40 var zipR = new ZipReader(tmpFile);
41
42 for (var i = 0; i < TESTS.length; i++) {
43 var source = do_get_file(DATA_DIR + TESTS[i].name);
44 do_check_true(zipR.hasEntry(TESTS[i].name));
45
46 var entry = zipR.getEntry(TESTS[i].name);
47 do_check_eq(entry.realSize, TESTS[i].size);
48 do_check_eq(entry.size, TESTS[i].size);
49 do_check_eq(entry.CRC32, TESTS[i].crc);
50 do_check_eq(Math.floor(entry.lastModifiedTime / PR_USEC_PER_SEC),
51 Math.floor(source.lastModifiedTime / PR_MSEC_PER_SEC));
52
53 zipR.test(TESTS[i].name);
54 }
55
56 zipR.close();
57 }

mercurial