modules/libjar/zipwriter/test/unit/test_deflatedata.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.

     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  */
     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
    12 function run_test()
    13 {
    14   zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
    16   // Shouldn't be there to start with.
    17   do_check_false(zipW.hasEntry(FILENAME));
    19   do_check_false(zipW.inQueue);
    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);
    27   var entry = zipW.getEntry(FILENAME);
    29   do_check_true(entry != null);
    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);
    37   zipW.close();
    39   // Test the stored data with the zipreader
    40   var zipR = new ZipReader(tmpFile);
    41   do_check_true(zipR.hasEntry(FILENAME));
    43   zipR.test(FILENAME);
    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();
    52   do_check_eq(result, DATA);
    53 }

mercurial