modules/libjar/zipwriter/test/unit/test_deflatedata.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_deflatedata.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,53 @@
     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 +const DATA = "ZIP WRITER TEST DATA";
    1.10 +const FILENAME = "test.txt";
    1.11 +const CRC = 0xe6164331;
    1.12 +// XXX Must use a constant time here away from DST changes. See bug 402434.
    1.13 +const time = 1199145600000; // Jan 1st 2008
    1.14 +
    1.15 +function run_test()
    1.16 +{
    1.17 +  zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
    1.18 +
    1.19 +  // Shouldn't be there to start with.
    1.20 +  do_check_false(zipW.hasEntry(FILENAME));
    1.21 +
    1.22 +  do_check_false(zipW.inQueue);
    1.23 +
    1.24 +  var stream = Cc["@mozilla.org/io/string-input-stream;1"]
    1.25 +                .createInstance(Ci.nsIStringInputStream);
    1.26 +  stream.setData(DATA, DATA.length);
    1.27 +  zipW.addEntryStream(FILENAME, time * PR_USEC_PER_MSEC,
    1.28 +                      Ci.nsIZipWriter.COMPRESSION_BEST, stream, false);
    1.29 +
    1.30 +  var entry = zipW.getEntry(FILENAME);
    1.31 +
    1.32 +  do_check_true(entry != null);
    1.33 +
    1.34 +  // Check entry seems right.
    1.35 +  do_check_eq(entry.compression, ZIP_METHOD_DEFLATE);
    1.36 +  do_check_eq(entry.CRC32, CRC);
    1.37 +  do_check_eq(entry.realSize, DATA.length);
    1.38 +  do_check_eq(entry.lastModifiedTime / PR_USEC_PER_MSEC, time);
    1.39 +
    1.40 +  zipW.close();
    1.41 +
    1.42 +  // Test the stored data with the zipreader
    1.43 +  var zipR = new ZipReader(tmpFile);
    1.44 +  do_check_true(zipR.hasEntry(FILENAME));
    1.45 +
    1.46 +  zipR.test(FILENAME);
    1.47 +
    1.48 +  var stream = Cc["@mozilla.org/scriptableinputstream;1"]
    1.49 +                .createInstance(Ci.nsIScriptableInputStream);
    1.50 +  stream.init(zipR.getInputStream(FILENAME));
    1.51 +  var result = stream.read(DATA.length);
    1.52 +  stream.close();
    1.53 +  zipR.close();
    1.54 +
    1.55 +  do_check_eq(result, DATA);
    1.56 +}

mercurial