diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /mozglue/linker/tests | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mozglue/linker/tests')
-rw-r--r-- | mozglue/linker/tests/TestZip.cpp | 61 | ||||
-rw-r--r-- | mozglue/linker/tests/TestZipData.S | 17 | ||||
-rw-r--r-- | mozglue/linker/tests/moz.build | 20 | ||||
-rw-r--r-- | mozglue/linker/tests/no_central_dir.zip | bin | 0 -> 281 bytes | |||
-rw-r--r-- | mozglue/linker/tests/test.zip | bin | 0 -> 574 bytes |
5 files changed, 98 insertions, 0 deletions
diff --git a/mozglue/linker/tests/TestZip.cpp b/mozglue/linker/tests/TestZip.cpp new file mode 100644 index 0000000000..a2d2b10bdd --- /dev/null +++ b/mozglue/linker/tests/TestZip.cpp @@ -0,0 +1,61 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include <cstdio> +#include <unistd.h> +#include "Zip.h" +#include "mozilla/RefPtr.h" + +#include "gtest/gtest.h" + +Logging Logging::Singleton; + +/** + * test.zip is a basic test zip file with a central directory. It contains + * four entries, in the following order: + * "foo", "bar", "baz", "qux". + * The entries are going to be read out of order. + */ +extern const unsigned char TEST_ZIP[]; +extern const unsigned int TEST_ZIP_SIZE; +const char* test_entries[] = {"baz", "foo", "bar", "qux"}; + +/** + * no_central_dir.zip is a hand crafted test zip with no central directory + * entries. The Zip reader is expected to be able to traverse these entries + * if requested in order, without reading a central directory + * - First entry is a file "a", STOREd. + * - Second entry is a file "b", STOREd, using a data descriptor. CRC is + * unknown, but compressed and uncompressed sizes are known in the local + * file header. + * - Third entry is a file "c", DEFLATEd, using a data descriptor. CRC, + * compressed and uncompressed sizes are known in the local file header. + * This is the kind of entry that can be found in a zip that went through + * zipalign if it had a data descriptor originally. + * - Fourth entry is a file "d", STOREd. + */ +extern const unsigned char NO_CENTRAL_DIR_ZIP[]; +extern const unsigned int NO_CENTRAL_DIR_ZIP_SIZE; +const char* no_central_dir_entries[] = {"a", "b", "c", "d"}; + +TEST(Zip, TestZip) +{ + Zip::Stream s; + RefPtr<Zip> z = Zip::Create((void*)TEST_ZIP, TEST_ZIP_SIZE); + for (auto& entry : test_entries) { + ASSERT_TRUE(z->GetStream(entry, &s)) + << "Could not get entry \"" << entry << "\""; + } +} + +TEST(Zip, NoCentralDir) +{ + Zip::Stream s; + RefPtr<Zip> z = + Zip::Create((void*)NO_CENTRAL_DIR_ZIP, NO_CENTRAL_DIR_ZIP_SIZE); + for (auto& entry : no_central_dir_entries) { + ASSERT_TRUE(z->GetStream(entry, &s)) + << "Could not get entry \"" << entry << "\""; + } +} diff --git a/mozglue/linker/tests/TestZipData.S b/mozglue/linker/tests/TestZipData.S new file mode 100644 index 0000000000..5fbb825451 --- /dev/null +++ b/mozglue/linker/tests/TestZipData.S @@ -0,0 +1,17 @@ +.macro zip_data name, path + .global \name + .data + .balign 16 + \name: + .incbin "\path" + .L\name\()_END: + .size \name, .L\name\()_END-\name + .global \name\()_SIZE + .data + .balign 4 + \name\()_SIZE: + .int .L\name\()_END-\name +.endm + +zip_data TEST_ZIP, "test.zip" +zip_data NO_CENTRAL_DIR_ZIP, "no_central_dir.zip" diff --git a/mozglue/linker/tests/moz.build b/mozglue/linker/tests/moz.build new file mode 100644 index 0000000000..4ecc93b190 --- /dev/null +++ b/mozglue/linker/tests/moz.build @@ -0,0 +1,20 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +FINAL_LIBRARY = "xul-gtest" + +UNIFIED_SOURCES += [ + "../Zip.cpp", + "TestZip.cpp", +] + +SOURCES += [ + "TestZipData.S", +] + +LOCAL_INCLUDES += [".."] + +ASFLAGS += ["-I", SRCDIR] diff --git a/mozglue/linker/tests/no_central_dir.zip b/mozglue/linker/tests/no_central_dir.zip Binary files differnew file mode 100644 index 0000000000..df882220d1 --- /dev/null +++ b/mozglue/linker/tests/no_central_dir.zip diff --git a/mozglue/linker/tests/test.zip b/mozglue/linker/tests/test.zip Binary files differnew file mode 100644 index 0000000000..657835b0ca --- /dev/null +++ b/mozglue/linker/tests/test.zip |