/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. const DATA = "";
  39. const FILENAME = "test.txt";
  40. const CRC = 0x00000000;
  41. const time = Date.now();
  42. function testpass(source)
  43. {
  44. // Should exist.
  45. do_check_true(source.hasEntry(FILENAME));
  46. var entry = source.getEntry(FILENAME);
  47. do_check_neq(entry, null);
  48. do_check_false(entry.isDirectory);
  49. // Should be stored
  50. do_check_eq(entry.compression, ZIP_METHOD_DEFLATE);
  51. // File size should match our data size.
  52. do_check_eq(entry.realSize, DATA.length);
  53. // Check that the CRC is accurate
  54. do_check_eq(entry.CRC32, CRC);
  55. }
  56. function run_test()
  57. {
  58. zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
  59. // Shouldn't be there to start with.
  60. do_check_false(zipW.hasEntry(FILENAME));
  61. do_check_false(zipW.inQueue);
  62. var file = do_get_file(DATA_DIR + "emptyfile.txt");
  63. zipW.addEntryFile(FILENAME, Ci.nsIZipWriter.COMPRESSION_BEST, file, false);
  64. // Check that zip state is right at this stage.
  65. testpass(zipW);
  66. zipW.close();
  67. // Check to see if we get the same results loading afresh.
  68. zipW.open(tmpFile, PR_RDWR);
  69. testpass(zipW);
  70. zipW.close();
  71. // Test the stored data with the zipreader
  72. var zipR = new ZipReader(tmpFile);
  73. testpass(zipR);
  74. zipR.test(FILENAME);
  75. var stream = Cc["@mozilla.org/scriptableinputstream;1"]
  76. .createInstance(Ci.nsIScriptableInputStream);
  77. stream.init(zipR.getInputStream(FILENAME));
  78. var result = stream.read(DATA.length);
  79. stream.close();
  80. zipR.close();
  81. do_check_eq(result, DATA);
  82. }