]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Seperate get_test_set() function out into a utility source file used by all test...
authorAndres Mejia <amejia004@gmail.com>
Wed, 19 Sep 2012 18:17:54 +0000 (14:17 -0400)
committerAndres Mejia <amejia004@gmail.com>
Wed, 19 Sep 2012 18:17:54 +0000 (14:17 -0400)
.gitignore
Makefile.am
cpio/test/CMakeLists.txt
cpio/test/main.c
libarchive/test/CMakeLists.txt
libarchive/test/main.c
tar/test/CMakeLists.txt
tar/test/main.c
test_utils/test_utils.c [new file with mode: 0644]
test_utils/test_utils.h [new file with mode: 0644]

index 76c798c102f1fea26c2cdf74a08866c180d53137..624d0e85036ef303e37259bdc231457ebd463578 100644 (file)
@@ -61,6 +61,8 @@ libarchive/CMakeFiles/
 libarchive/test/CMakeFiles/
 tar/CMakeFiles/
 tar/test/CMakeFiles/
+test_utils/.deps/
+test_utils/.dirstamp
 
 doc/html/*.html
 doc/man/*.1
index 93413b2e7f3c706667ee07ba6bea6f8bf58a97ab..da04e44c7eb04baae27753b74d41a66690137a59 100644 (file)
@@ -248,6 +248,10 @@ libarchive_EXTRA_DIST=                     \
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = build/pkgconfig/libarchive.pc
 
+# Sources needed by all test programs
+test_utils_SOURCES= \
+       test_utils/test_utils.c
+
 #
 #
 # libarchive_test program
@@ -255,6 +259,7 @@ pkgconfig_DATA = build/pkgconfig/libarchive.pc
 #
 libarchive_test_SOURCES=                                       \
        $(libarchive_la_SOURCES)                                \
+       $(test_utils_SOURCES)                                   \
        libarchive/test/main.c                                  \
        libarchive/test/read_open_memory.c                      \
        libarchive/test/test.h                                  \
@@ -436,7 +441,7 @@ libarchive_test_SOURCES=                                    \
        libarchive/test/test_write_zip_set_compression_store.c  \
        libarchive/test/test_zip_filename_encoding.c
 
-libarchive_test_CPPFLAGS= -I$(top_srcdir)/libarchive -I$(top_builddir)/libarchive/test -DLIBARCHIVE_STATIC $(PLATFORMCPPFLAGS)
+libarchive_test_CPPFLAGS= -I$(top_srcdir)/libarchive -I$(top_srcdir)/test_utils -I$(top_builddir)/libarchive/test -DLIBARCHIVE_STATIC $(PLATFORMCPPFLAGS)
 libarchive_test_LDADD= $(LTLIBICONV)
 
 # The "list.h" file just lists all of the tests defined in all of the sources.
@@ -670,6 +675,7 @@ endif
 #
 
 bsdtar_test_SOURCES=                                           \
+       $(test_utils_SOURCES)                                   \
        tar/test/main.c                                         \
        tar/test/test.h                                         \
        tar/test/test_0.c                                       \
@@ -707,6 +713,7 @@ bsdtar_test_SOURCES=                                                \
 
 bsdtar_test_CPPFLAGS=\
        -I$(top_srcdir)/libarchive -I$(top_srcdir)/libarchive_fe \
+       -I$(top_srcdir)/test_utils \
        -I$(top_srcdir)/tar -I$(top_builddir)/tar/test \
        $(PLATFORMCPPFLAGS)
 
@@ -787,6 +794,7 @@ endif
 #
 
 bsdcpio_test_SOURCES=                                          \
+       $(test_utils_SOURCES)                                   \
        cpio/cmdline.c                                          \
        cpio/test/main.c                                        \
        cpio/test/test.h                                        \
@@ -820,6 +828,7 @@ bsdcpio_test_SOURCES=                                               \
 
 bsdcpio_test_CPPFLAGS= \
        -I$(top_srcdir)/libarchive -I$(top_srcdir)/libarchive_fe \
+       -I$(top_srcdir)/test_utils \
        -I$(top_srcdir)/cpio -I$(top_builddir)/cpio/test \
        $(PLATFORMCPPFLAGS)
 bsdcpio_test_LDADD=libarchive_fe.la
index bbb70be7830ff652b0cec148a9e34875642041eb..662316425d938956f34e4880c6b7da6e08b4a05a 100644 (file)
@@ -7,6 +7,7 @@ IF(ENABLE_CPIO AND ENABLE_TEST)
   SET(bsdcpio_test_SOURCES
     ../cmdline.c
     ../../libarchive_fe/err.c
+    ../../test_utils/test_utils.c
     main.c
     test.h
     test_0.c
@@ -66,6 +67,7 @@ IF(ENABLE_CPIO AND ENABLE_TEST)
 
   INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/list.h)
   INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
+  INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/test_utils)
 
   # Experimental new test handling
   ADD_CUSTOM_TARGET(run_bsdcpio_test
index e190123d5c83e78a5c418e65cd34850c97dc6e0a..a016bcc1b07d42ffd976bfeb697812764e2e6bbd 100644 (file)
@@ -24,6 +24,7 @@
  */
 
 #include "test.h"
+#include "test_utils.h"
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
@@ -2124,7 +2125,7 @@ is_LargeInode(const char *file)
 /* Use "list.h" to create a list of all tests (functions and names). */
 #undef DEFINE_TEST
 #define        DEFINE_TEST(n) { n, #n, 0 },
-struct { void (*func)(void); const char *name; int failures; } tests[] = {
+struct test_list_t tests[] = {
        #include "list.h"
 };
 
@@ -2377,65 +2378,6 @@ success:
        return strdup(buff);
 }
 
-static int
-get_test_set(int *test_set, int limit, const char *test)
-{
-       int start, end;
-       int idx = 0;
-
-       if (test == NULL) {
-               /* Default: Run all tests. */
-               for (;idx < limit; idx++)
-                       test_set[idx] = idx;
-               return (limit);
-       }
-       if (*test >= '0' && *test <= '9') {
-               const char *vp = test;
-               start = 0;
-               while (*vp >= '0' && *vp <= '9') {
-                       start *= 10;
-                       start += *vp - '0';
-                       ++vp;
-               }
-               if (*vp == '\0') {
-                       end = start;
-               } else if (*vp == '-') {
-                       ++vp;
-                       if (*vp == '\0') {
-                               end = limit - 1;
-                       } else {
-                               end = 0;
-                               while (*vp >= '0' && *vp <= '9') {
-                                       end *= 10;
-                                       end += *vp - '0';
-                                       ++vp;
-                               }
-                       }
-               } else
-                       return (-1);
-               if (start < 0 || end >= limit || start > end)
-                       return (-1);
-               while (start <= end)
-                       test_set[idx++] = start++;
-       } else {
-               size_t len = strlen(test);
-               for (start = 0; start < limit; ++start) {
-                       const char *name = tests[start].name;
-                       const char *p;
-
-                       while ((p = strchr(name, test[0])) != NULL) {
-                               if (strncmp(p, test, len) == 0) {
-                                       test_set[idx++] = start;
-                                       break;
-                               } else
-                                       name = p + 1;
-                       }
-
-               }
-       }
-       return ((idx == 0)?-1:idx);
-}
-
 int
 main(int argc, char **argv)
 {
@@ -2720,7 +2662,7 @@ main(int argc, char **argv)
                do {
                        int test_num;
 
-                       test_num = get_test_set(test_set, limit, *argv);
+                       test_num = get_test_set(test_set, limit, *argv, tests);
                        if (test_num < 0) {
                                printf("*** INVALID Test %s\n", *argv);
                                free(refdir_alloc);
index ee8852d58b7d43a4bd9ea3b35e0ad16d4f5c01c6..0ae41ae637351d420af3228153ae4f52c5afc588 100644 (file)
@@ -5,6 +5,7 @@
 ############################################
 IF(ENABLE_TEST)
   SET(libarchive_test_SOURCES
+    ../../test_utils/test_utils.c
    main.c
     read_open_memory.c
     test.h
@@ -216,6 +217,7 @@ IF(ENABLE_TEST)
 
   INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/list.h)
   INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
+  INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/test_utils)
 
   # Experimental new test handling
   ADD_CUSTOM_TARGET(run_libarchive_test
index 214bbf0ed242305539fff95184543768b3928002..db160ddb19c0767cbb9fec8772c902cc0eb75c76 100644 (file)
@@ -24,6 +24,7 @@
  */
 
 #include "test.h"
+#include "test_utils.h"
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
@@ -2142,7 +2143,7 @@ extract_reference_files(const char **names)
 /* Use "list.h" to create a list of all tests (functions and names). */
 #undef DEFINE_TEST
 #define        DEFINE_TEST(n) { n, #n, 0 },
-struct { void (*func)(void); const char *name; int failures; } tests[] = {
+struct test_list_t tests[] = {
        #include "list.h"
 };
 
@@ -2395,65 +2396,6 @@ success:
        return strdup(buff);
 }
 
-static int
-get_test_set(int *test_set, int limit, const char *test)
-{
-       int start, end;
-       int idx = 0;
-
-       if (test == NULL) {
-               /* Default: Run all tests. */
-               for (;idx < limit; idx++)
-                       test_set[idx] = idx;
-               return (limit);
-       }
-       if (*test >= '0' && *test <= '9') {
-               const char *vp = test;
-               start = 0;
-               while (*vp >= '0' && *vp <= '9') {
-                       start *= 10;
-                       start += *vp - '0';
-                       ++vp;
-               }
-               if (*vp == '\0') {
-                       end = start;
-               } else if (*vp == '-') {
-                       ++vp;
-                       if (*vp == '\0') {
-                               end = limit - 1;
-                       } else {
-                               end = 0;
-                               while (*vp >= '0' && *vp <= '9') {
-                                       end *= 10;
-                                       end += *vp - '0';
-                                       ++vp;
-                               }
-                       }
-               } else
-                       return (-1);
-               if (start < 0 || end >= limit || start > end)
-                       return (-1);
-               while (start <= end)
-                       test_set[idx++] = start++;
-       } else {
-               size_t len = strlen(test);
-               for (start = 0; start < limit; ++start) {
-                       const char *name = tests[start].name;
-                       const char *p;
-
-                       while ((p = strchr(name, test[0])) != NULL) {
-                               if (strncmp(p, test, len) == 0) {
-                                       test_set[idx++] = start;
-                                       break;
-                               } else
-                                       name = p + 1;
-                       }
-
-               }
-       }
-       return ((idx == 0)?-1:idx);
-}
-
 int
 main(int argc, char **argv)
 {
@@ -2738,7 +2680,7 @@ main(int argc, char **argv)
                do {
                        int test_num;
 
-                       test_num = get_test_set(test_set, limit, *argv);
+                       test_num = get_test_set(test_set, limit, *argv, tests);
                        if (test_num < 0) {
                                printf("*** INVALID Test %s\n", *argv);
                                free(refdir_alloc);
index 5c0c44370c20e1c2ef3337ea5c4a73444270f3eb..9cdb68b7fa7420f5fe39223fb81ad43a9c4ecd39 100644 (file)
@@ -5,6 +5,7 @@
 ############################################
 IF(ENABLE_TAR AND ENABLE_TEST)
   SET(bsdtar_test_SOURCES
+    ../../test_utils/test_utils.c
     main.c
     test.h
     test_0.c
@@ -69,6 +70,7 @@ IF(ENABLE_TAR AND ENABLE_TEST)
 
   INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/list.h)
   INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
+  INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/test_utils)
 
   # Experimental new test handling
   ADD_CUSTOM_TARGET(run_bsdtar_test
index d026203ccee5fec0ebdb71b905692d4207c53661..d9f12c1ebb9e2a1485f33fab2fcfc1a262eda773 100644 (file)
@@ -24,6 +24,7 @@
  */
 
 #include "test.h"
+#include "test_utils.h"
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
@@ -2124,7 +2125,7 @@ is_LargeInode(const char *file)
 /* Use "list.h" to create a list of all tests (functions and names). */
 #undef DEFINE_TEST
 #define        DEFINE_TEST(n) { n, #n, 0 },
-struct { void (*func)(void); const char *name; int failures; } tests[] = {
+struct test_list_t tests[] = {
        #include "list.h"
 };
 
@@ -2377,65 +2378,6 @@ success:
        return strdup(buff);
 }
 
-static int
-get_test_set(int *test_set, int limit, const char *test)
-{
-       int start, end;
-       int idx = 0;
-
-       if (test == NULL) {
-               /* Default: Run all tests. */
-               for (;idx < limit; idx++)
-                       test_set[idx] = idx;
-               return (limit);
-       }
-       if (*test >= '0' && *test <= '9') {
-               const char *vp = test;
-               start = 0;
-               while (*vp >= '0' && *vp <= '9') {
-                       start *= 10;
-                       start += *vp - '0';
-                       ++vp;
-               }
-               if (*vp == '\0') {
-                       end = start;
-               } else if (*vp == '-') {
-                       ++vp;
-                       if (*vp == '\0') {
-                               end = limit - 1;
-                       } else {
-                               end = 0;
-                               while (*vp >= '0' && *vp <= '9') {
-                                       end *= 10;
-                                       end += *vp - '0';
-                                       ++vp;
-                               }
-                       }
-               } else
-                       return (-1);
-               if (start < 0 || end >= limit || start > end)
-                       return (-1);
-               while (start <= end)
-                       test_set[idx++] = start++;
-       } else {
-               size_t len = strlen(test);
-               for (start = 0; start < limit; ++start) {
-                       const char *name = tests[start].name;
-                       const char *p;
-
-                       while ((p = strchr(name, test[0])) != NULL) {
-                               if (strncmp(p, test, len) == 0) {
-                                       test_set[idx++] = start;
-                                       break;
-                               } else
-                                       name = p + 1;
-                       }
-
-               }
-       }
-       return ((idx == 0)?-1:idx);
-}
-
 int
 main(int argc, char **argv)
 {
@@ -2720,7 +2662,7 @@ main(int argc, char **argv)
                do {
                        int test_num;
 
-                       test_num = get_test_set(test_set, limit, *argv);
+                       test_num = get_test_set(test_set, limit, *argv, tests);
                        if (test_num < 0) {
                                printf("*** INVALID Test %s\n", *argv);
                                free(refdir_alloc);
diff --git a/test_utils/test_utils.c b/test_utils/test_utils.c
new file mode 100644 (file)
index 0000000..e8ae5ff
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2003-2012 Tim Kientzle
+ * Copyright (c) 2012 Andres Mejia
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test_utils.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+int get_test_set(int *test_set, int limit, const char *test,
+       struct test_list_t *tests)
+{
+       int start, end;
+       int idx = 0;
+
+       if (test == NULL) {
+               /* Default: Run all tests. */
+               for (;idx < limit; idx++)
+                       test_set[idx] = idx;
+               return (limit);
+       }
+       if (*test >= '0' && *test <= '9') {
+               const char *vp = test;
+               start = 0;
+               while (*vp >= '0' && *vp <= '9') {
+                       start *= 10;
+                       start += *vp - '0';
+                       ++vp;
+               }
+               if (*vp == '\0') {
+                       end = start;
+               } else if (*vp == '-') {
+                       ++vp;
+                       if (*vp == '\0') {
+                               end = limit - 1;
+                       } else {
+                               end = 0;
+                               while (*vp >= '0' && *vp <= '9') {
+                                       end *= 10;
+                                       end += *vp - '0';
+                                       ++vp;
+                               }
+                       }
+               } else
+                       return (-1);
+               if (start < 0 || end >= limit || start > end)
+                       return (-1);
+               while (start <= end)
+                       test_set[idx++] = start++;
+       } else {
+               size_t len = strlen(test);
+               for (start = 0; start < limit; ++start) {
+                       const char *name = tests[start].name;
+                       const char *p;
+
+                       while ((p = strchr(name, test[0])) != NULL) {
+                               if (strncmp(p, test, len) == 0) {
+                                       test_set[idx++] = start;
+                                       break;
+                               } else
+                                       name = p + 1;
+                       }
+
+               }
+       }
+       return ((idx == 0)?-1:idx);
+}
diff --git a/test_utils/test_utils.h b/test_utils/test_utils.h
new file mode 100644 (file)
index 0000000..164c528
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2003-2012 Tim Kientzle
+ * Copyright (c) 2012 Andres Mejia
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TEST_UTILS_H
+#define TEST_UTILS_H
+
+struct test_list_t
+{
+  void (*func)(void);
+  const char *name;
+  int failures;
+};
+
+int get_test_set(int *, int, const char *, struct test_list_t *);
+
+#endif /* TEST_UTILS_H */