Bug 683127 part 3 - Test for the Zip reader. r=tglek
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 11 Jan 2012 11:11:00 +0100
changeset 85483 ea78ef72f47fe254cd6beea23425417af9d83490
parent 85482 85c7cdc1a91601eaf43562b736bd65b768d64d14
child 85484 52edf42878930241de0331a601481eca9d410360
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstglek
bugs683127
milestone12.0a1
Bug 683127 part 3 - Test for the Zip reader. r=tglek
mozglue/Makefile.in
mozglue/tests/Makefile.in
mozglue/tests/TestZip.cpp
mozglue/tests/no_central_dir.zip
mozglue/tests/test.zip
--- a/mozglue/Makefile.in
+++ b/mozglue/Makefile.in
@@ -49,9 +49,11 @@ DIRS += linker
 endif
 
 ifeq (android,$(MOZ_WIDGET_TOOLKIT))
 DIRS += android
 endif
 
 DIRS += build
 
+TEST_DIRS = tests
+
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/mozglue/tests/Makefile.in
@@ -0,0 +1,33 @@
+# 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/.
+
+DEPTH		= ../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(DEPTH)/config/autoconf.mk
+
+ifdef MOZ_LINKER
+CPPSRCS = \
+  TestZip.cpp \
+  $(NULL)
+
+SIMPLE_PROGRAMS := $(CPPSRCS:.cpp=$(BIN_SUFFIX))
+NO_DIST_INSTALL = 1
+STL_FLAGS =
+
+LOCAL_INCLUDES += -I$(srcdir)/../linker
+# Only link against the linker, not mozglue
+MOZ_GLUE_PROGRAM_LDFLAGS =
+MOZ_GLUE_LDFLAGS =
+LIBS += $(call EXPAND_LIBNAME_PATH,linker,../linker)
+endif
+
+include $(topsrcdir)/config/rules.mk
+
+ifdef MOZ_LINKER
+check::
+	@$(EXIT_ON_ERROR) ./TestZip$(BIN_SUFFIX) $(srcdir)
+endif
new file mode 100644
--- /dev/null
+++ b/mozglue/tests/TestZip.cpp
@@ -0,0 +1,65 @@
+/* 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"
+
+/**
+ * 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.
+ */
+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.
+ */
+const char *no_central_dir_entries[] = {
+  "a", "b", "c", "d"
+};
+
+int main(int argc, char *argv[])
+{
+  if (argc != 2) {
+    fprintf(stderr, "TEST-FAIL | TestZip | Expecting the directory containing test Zips\n");
+    return 1;
+  }
+  chdir(argv[1]);
+  Zip::Stream s;
+  Zip z("test.zip");
+  for (size_t i = 0; i < sizeof(test_entries) / sizeof(*test_entries); i++) {
+    if (!z.GetStream(test_entries[i], &s)) {
+      fprintf(stderr, "TEST-UNEXPECTED-FAIL | TestZip | test.zip: Couldn't get entry \"%s\"\n", test_entries[i]);
+      return 1;
+    }
+  }
+  fprintf(stderr, "TEST-PASS | TestZip | test.zip could be accessed fully\n");
+
+  Zip z2("no_central_dir.zip");
+  for (size_t i = 0; i < sizeof(no_central_dir_entries)
+                         / sizeof(*no_central_dir_entries); i++) {
+    if (!z2.GetStream(no_central_dir_entries[i], &s)) {
+      fprintf(stderr, "TEST-UNEXPECTED-FAIL | TestZip | no_central_dir.zip: Couldn't get entry \"%s\"\n", no_central_dir_entries[i]);
+      return 1;
+    }
+  }
+  fprintf(stderr, "TEST-PASS | TestZip | no_central_dir.zip could be accessed in order\n");
+
+  return 0;
+}
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..df882220d19f3da6c90426f5c6d998cf4d4ffc20
GIT binary patch
literal 281
zc$^FHW@h1H0D*LmK700sukJDd*&xiwAj6Ot8p6rI>=g0B4}?oAxEUB(UNAE-fQdw|
z0I+5bpyFbnW{@GwPz=(X1lAl0)L4S4IVlOKo1G(FjfWYg2V|NE&@>K)GN5Unl%3zO
z0YzD$rX_<-O8}ZQ4bwDlKfh;83?KuMwFSWa=HcIG?-V+B0kYpxzy@lhzVHKKGy_w(
E08REbZU6uP
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..657835b0cac2fd84b1631590a4cf6b7181b78c60
GIT binary patch
literal 574
zc$^FHW@h1H0D+9qKKm7^Ms+MeHV88_$S|bk=ZA)HGB9t+f8lo=h)XND85mh!FauS9
z2%t1q0Nj8qpaCy8FJeJ9AStm3Y`_le1^}gz49Eo<@X)gQ45|TDU<3BzGN1~{fPA0<
z`&OJ=j%+|-X$9DTgV+rKN&^jGWRhdX6$%nyaYi6s(g<RK!-N$QCTNBs8-y7e$Obtw
zFhIhF6%sah48jZ*WP_T(233I#+Kb;H%+NtL=r98VB&=8=VTEB3D;on?BMXBHPzMW0
G7XtwIYIQXL