PageRenderTime 26ms CodeModel.GetById 17ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://github.com/zpao/v8monkey
JavaScript | 97 lines | 37 code | 15 blank | 45 comment | 0 complexity | f0d77cc32b17f4c1b6446de0e2b830ee MD5 | raw file
 1/* ***** BEGIN LICENSE BLOCK *****
 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 3 *
 4 * The contents of this file are subject to the Mozilla Public License Version
 5 * 1.1 (the "License"); you may not use this file except in compliance with
 6 * the License. You may obtain a copy of the License at
 7 * http://www.mozilla.org/MPL/
 8 *
 9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is Zip Writer Component.
15 *
16 * The Initial Developer of the Original Code is
17 * Dave Townsend <dtownsend@oxymoronical.com>.
18 *
19 * Portions created by the Initial Developer are Copyright (C) 2008
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK *****
37 */
38
39const DATA = "";
40const FILENAME = "test.txt";
41const CRC = 0x00000000;
42const time = Date.now();
43
44function testpass(source)
45{
46  // Should exist.
47  do_check_true(source.hasEntry(FILENAME));
48
49  var entry = source.getEntry(FILENAME);
50  do_check_neq(entry, null);
51
52  do_check_false(entry.isDirectory);
53
54  // Should be stored
55  do_check_eq(entry.compression, ZIP_METHOD_DEFLATE);
56
57  // File size should match our data size.
58  do_check_eq(entry.realSize, DATA.length);
59
60  // Check that the CRC is accurate
61  do_check_eq(entry.CRC32, CRC);
62}
63
64function run_test()
65{
66  zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
67
68  // Shouldn't be there to start with.
69  do_check_false(zipW.hasEntry(FILENAME));
70
71  do_check_false(zipW.inQueue);
72
73  var file = do_get_file(DATA_DIR + "emptyfile.txt");
74  zipW.addEntryFile(FILENAME, Ci.nsIZipWriter.COMPRESSION_BEST, file, false);
75
76  // Check that zip state is right at this stage.
77  testpass(zipW);
78  zipW.close();
79
80  // Check to see if we get the same results loading afresh.
81  zipW.open(tmpFile, PR_RDWR);
82  testpass(zipW);
83  zipW.close();
84
85  // Test the stored data with the zipreader
86  var zipR = new ZipReader(tmpFile);
87  testpass(zipR);
88  zipR.test(FILENAME);
89  var stream = Cc["@mozilla.org/scriptableinputstream;1"]
90                .createInstance(Ci.nsIScriptableInputStream);
91  stream.init(zipR.getInputStream(FILENAME));
92  var result = stream.read(DATA.length);
93  stream.close();
94  zipR.close();
95
96  do_check_eq(result, DATA);
97}