michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #include "Zip.h" michael@0: #include "mozilla/RefPtr.h" michael@0: michael@0: extern "C" void report_mapping() { } michael@0: michael@0: /** michael@0: * test.zip is a basic test zip file with a central directory. It contains michael@0: * four entries, in the following order: michael@0: * "foo", "bar", "baz", "qux". michael@0: * The entries are going to be read out of order. michael@0: */ michael@0: const char *test_entries[] = { michael@0: "baz", "foo", "bar", "qux" michael@0: }; michael@0: michael@0: /** michael@0: * no_central_dir.zip is a hand crafted test zip with no central directory michael@0: * entries. The Zip reader is expected to be able to traverse these entries michael@0: * if requested in order, without reading a central directory michael@0: * - First entry is a file "a", STOREd. michael@0: * - Second entry is a file "b", STOREd, using a data descriptor. CRC is michael@0: * unknown, but compressed and uncompressed sizes are known in the local michael@0: * file header. michael@0: * - Third entry is a file "c", DEFLATEd, using a data descriptor. CRC, michael@0: * compressed and uncompressed sizes are known in the local file header. michael@0: * This is the kind of entry that can be found in a zip that went through michael@0: * zipalign if it had a data descriptor originally. michael@0: * - Fourth entry is a file "d", STOREd. michael@0: */ michael@0: const char *no_central_dir_entries[] = { michael@0: "a", "b", "c", "d" michael@0: }; michael@0: michael@0: int main(int argc, char *argv[]) michael@0: { michael@0: if (argc != 2) { michael@0: fprintf(stderr, "TEST-FAIL | TestZip | Expecting the directory containing test Zips\n"); michael@0: return 1; michael@0: } michael@0: chdir(argv[1]); michael@0: Zip::Stream s; michael@0: mozilla::RefPtr z = ZipCollection::GetZip("test.zip"); michael@0: for (size_t i = 0; i < sizeof(test_entries) / sizeof(*test_entries); i++) { michael@0: if (!z->GetStream(test_entries[i], &s)) { michael@0: fprintf(stderr, "TEST-UNEXPECTED-FAIL | TestZip | test.zip: Couldn't get entry \"%s\"\n", test_entries[i]); michael@0: return 1; michael@0: } michael@0: } michael@0: fprintf(stderr, "TEST-PASS | TestZip | test.zip could be accessed fully\n"); michael@0: michael@0: z = ZipCollection::GetZip("no_central_dir.zip"); michael@0: for (size_t i = 0; i < sizeof(no_central_dir_entries) michael@0: / sizeof(*no_central_dir_entries); i++) { michael@0: if (!z->GetStream(no_central_dir_entries[i], &s)) { michael@0: fprintf(stderr, "TEST-UNEXPECTED-FAIL | TestZip | no_central_dir.zip: Couldn't get entry \"%s\"\n", no_central_dir_entries[i]); michael@0: return 1; michael@0: } michael@0: } michael@0: fprintf(stderr, "TEST-PASS | TestZip | no_central_dir.zip could be accessed in order\n"); michael@0: michael@0: return 0; michael@0: }