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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4 */
michael@0 5
michael@0 6 // Values taken from using zipinfo to list the test.zip contents
michael@0 7 var TESTS = [
michael@0 8 {
michael@0 9 name: "test.txt",
michael@0 10 size: 232,
michael@0 11 crc: 0x0373ac26
michael@0 12 },
michael@0 13 {
michael@0 14 name: "test.png",
michael@0 15 size: 3402,
michael@0 16 crc: 0x504a5c30
michael@0 17 }
michael@0 18 ];
michael@0 19
michael@0 20 function run_test()
michael@0 21 {
michael@0 22 zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
michael@0 23
michael@0 24 var size = 0;
michael@0 25 for (var i = 0; i < TESTS.length; i++) {
michael@0 26 var source = do_get_file(DATA_DIR + TESTS[i].name);
michael@0 27 zipW.addEntryFile(TESTS[i].name, Ci.nsIZipWriter.COMPRESSION_NONE, source,
michael@0 28 false);
michael@0 29 size += ZIP_FILE_HEADER_SIZE + ZIP_CDS_HEADER_SIZE +
michael@0 30 (ZIP_EXTENDED_TIMESTAMP_SIZE * 2) +
michael@0 31 (TESTS[i].name.length*2) + TESTS[i].size;
michael@0 32 }
michael@0 33
michael@0 34 zipW.close();
michael@0 35 size += ZIP_EOCDR_HEADER_SIZE;
michael@0 36
michael@0 37 do_check_eq(size, tmpFile.fileSize);
michael@0 38
michael@0 39 // Test the stored data with the zipreader
michael@0 40 var zipR = new ZipReader(tmpFile);
michael@0 41
michael@0 42 for (var i = 0; i < TESTS.length; i++) {
michael@0 43 var source = do_get_file(DATA_DIR + TESTS[i].name);
michael@0 44 do_check_true(zipR.hasEntry(TESTS[i].name));
michael@0 45
michael@0 46 var entry = zipR.getEntry(TESTS[i].name);
michael@0 47 do_check_eq(entry.realSize, TESTS[i].size);
michael@0 48 do_check_eq(entry.size, TESTS[i].size);
michael@0 49 do_check_eq(entry.CRC32, TESTS[i].crc);
michael@0 50 do_check_eq(Math.floor(entry.lastModifiedTime / PR_USEC_PER_SEC),
michael@0 51 Math.floor(source.lastModifiedTime / PR_MSEC_PER_SEC));
michael@0 52
michael@0 53 zipR.test(TESTS[i].name);
michael@0 54 }
michael@0 55
michael@0 56 zipR.close();
michael@0 57 }

mercurial