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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/modules/libjar/zipwriter/test/unit/test_sync.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,57 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 + */
     1.8 +
     1.9 +// Values taken from using zipinfo to list the test.zip contents
    1.10 +var TESTS = [
    1.11 +  {
    1.12 +    name: "test.txt",
    1.13 +    size: 232,
    1.14 +    crc: 0x0373ac26
    1.15 +  },
    1.16 +  {
    1.17 +    name: "test.png",
    1.18 +    size: 3402,
    1.19 +    crc: 0x504a5c30
    1.20 +  }
    1.21 +];
    1.22 +
    1.23 +function run_test()
    1.24 +{
    1.25 +  zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
    1.26 +
    1.27 +  var size = 0;
    1.28 +  for (var i = 0; i < TESTS.length; i++) {
    1.29 +    var source = do_get_file(DATA_DIR + TESTS[i].name);
    1.30 +    zipW.addEntryFile(TESTS[i].name, Ci.nsIZipWriter.COMPRESSION_NONE, source,
    1.31 +                      false);
    1.32 +    size += ZIP_FILE_HEADER_SIZE + ZIP_CDS_HEADER_SIZE +
    1.33 +            (ZIP_EXTENDED_TIMESTAMP_SIZE * 2) +
    1.34 +            (TESTS[i].name.length*2) + TESTS[i].size;
    1.35 +  }
    1.36 +
    1.37 +  zipW.close();
    1.38 +  size += ZIP_EOCDR_HEADER_SIZE;
    1.39 +
    1.40 +  do_check_eq(size, tmpFile.fileSize);
    1.41 +
    1.42 +  // Test the stored data with the zipreader
    1.43 +  var zipR = new ZipReader(tmpFile);
    1.44 +
    1.45 +  for (var i = 0; i < TESTS.length; i++) {
    1.46 +    var source = do_get_file(DATA_DIR + TESTS[i].name);
    1.47 +    do_check_true(zipR.hasEntry(TESTS[i].name));
    1.48 +
    1.49 +    var entry = zipR.getEntry(TESTS[i].name);
    1.50 +    do_check_eq(entry.realSize, TESTS[i].size);
    1.51 +    do_check_eq(entry.size, TESTS[i].size);
    1.52 +    do_check_eq(entry.CRC32, TESTS[i].crc);
    1.53 +    do_check_eq(Math.floor(entry.lastModifiedTime / PR_USEC_PER_SEC),
    1.54 +                Math.floor(source.lastModifiedTime / PR_MSEC_PER_SEC));
    1.55 +
    1.56 +    zipR.test(TESTS[i].name);
    1.57 +  }
    1.58 +
    1.59 +  zipR.close();
    1.60 +}

mercurial