mozglue/tests/TestZip.cpp

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.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include <cstdio>
michael@0 6 #include <unistd.h>
michael@0 7 #include "Zip.h"
michael@0 8 #include "mozilla/RefPtr.h"
michael@0 9
michael@0 10 extern "C" void report_mapping() { }
michael@0 11
michael@0 12 /**
michael@0 13 * test.zip is a basic test zip file with a central directory. It contains
michael@0 14 * four entries, in the following order:
michael@0 15 * "foo", "bar", "baz", "qux".
michael@0 16 * The entries are going to be read out of order.
michael@0 17 */
michael@0 18 const char *test_entries[] = {
michael@0 19 "baz", "foo", "bar", "qux"
michael@0 20 };
michael@0 21
michael@0 22 /**
michael@0 23 * no_central_dir.zip is a hand crafted test zip with no central directory
michael@0 24 * entries. The Zip reader is expected to be able to traverse these entries
michael@0 25 * if requested in order, without reading a central directory
michael@0 26 * - First entry is a file "a", STOREd.
michael@0 27 * - Second entry is a file "b", STOREd, using a data descriptor. CRC is
michael@0 28 * unknown, but compressed and uncompressed sizes are known in the local
michael@0 29 * file header.
michael@0 30 * - Third entry is a file "c", DEFLATEd, using a data descriptor. CRC,
michael@0 31 * compressed and uncompressed sizes are known in the local file header.
michael@0 32 * This is the kind of entry that can be found in a zip that went through
michael@0 33 * zipalign if it had a data descriptor originally.
michael@0 34 * - Fourth entry is a file "d", STOREd.
michael@0 35 */
michael@0 36 const char *no_central_dir_entries[] = {
michael@0 37 "a", "b", "c", "d"
michael@0 38 };
michael@0 39
michael@0 40 int main(int argc, char *argv[])
michael@0 41 {
michael@0 42 if (argc != 2) {
michael@0 43 fprintf(stderr, "TEST-FAIL | TestZip | Expecting the directory containing test Zips\n");
michael@0 44 return 1;
michael@0 45 }
michael@0 46 chdir(argv[1]);
michael@0 47 Zip::Stream s;
michael@0 48 mozilla::RefPtr<Zip> z = ZipCollection::GetZip("test.zip");
michael@0 49 for (size_t i = 0; i < sizeof(test_entries) / sizeof(*test_entries); i++) {
michael@0 50 if (!z->GetStream(test_entries[i], &s)) {
michael@0 51 fprintf(stderr, "TEST-UNEXPECTED-FAIL | TestZip | test.zip: Couldn't get entry \"%s\"\n", test_entries[i]);
michael@0 52 return 1;
michael@0 53 }
michael@0 54 }
michael@0 55 fprintf(stderr, "TEST-PASS | TestZip | test.zip could be accessed fully\n");
michael@0 56
michael@0 57 z = ZipCollection::GetZip("no_central_dir.zip");
michael@0 58 for (size_t i = 0; i < sizeof(no_central_dir_entries)
michael@0 59 / sizeof(*no_central_dir_entries); i++) {
michael@0 60 if (!z->GetStream(no_central_dir_entries[i], &s)) {
michael@0 61 fprintf(stderr, "TEST-UNEXPECTED-FAIL | TestZip | no_central_dir.zip: Couldn't get entry \"%s\"\n", no_central_dir_entries[i]);
michael@0 62 return 1;
michael@0 63 }
michael@0 64 }
michael@0 65 fprintf(stderr, "TEST-PASS | TestZip | no_central_dir.zip could be accessed in order\n");
michael@0 66
michael@0 67 return 0;
michael@0 68 }

mercurial