mozglue/tests/TestZip.cpp

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial