From: Andres Mejia Date: Wed, 19 Sep 2012 18:17:54 +0000 (-0400) Subject: Seperate get_test_set() function out into a utility source file used by all test... X-Git-Tag: v3.1.0~55^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa95a749a03cc7a8cc13401999a2de2a17d137fd;p=thirdparty%2Flibarchive.git Seperate get_test_set() function out into a utility source file used by all test programs. --- diff --git a/.gitignore b/.gitignore index 76c798c10..624d0e850 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Makefile.am b/Makefile.am index 93413b2e7..da04e44c7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/cpio/test/CMakeLists.txt b/cpio/test/CMakeLists.txt index bbb70be78..662316425 100644 --- a/cpio/test/CMakeLists.txt +++ b/cpio/test/CMakeLists.txt @@ -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 diff --git a/cpio/test/main.c b/cpio/test/main.c index e190123d5..a016bcc1b 100644 --- a/cpio/test/main.c +++ b/cpio/test/main.c @@ -24,6 +24,7 @@ */ #include "test.h" +#include "test_utils.h" #ifdef HAVE_SYS_IOCTL_H #include #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/libarchive/test/CMakeLists.txt b/libarchive/test/CMakeLists.txt index ee8852d58..0ae41ae63 100644 --- a/libarchive/test/CMakeLists.txt +++ b/libarchive/test/CMakeLists.txt @@ -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 diff --git a/libarchive/test/main.c b/libarchive/test/main.c index 214bbf0ed..db160ddb1 100644 --- a/libarchive/test/main.c +++ b/libarchive/test/main.c @@ -24,6 +24,7 @@ */ #include "test.h" +#include "test_utils.h" #ifdef HAVE_SYS_IOCTL_H #include #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); diff --git a/tar/test/CMakeLists.txt b/tar/test/CMakeLists.txt index 5c0c44370..9cdb68b7f 100644 --- a/tar/test/CMakeLists.txt +++ b/tar/test/CMakeLists.txt @@ -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 diff --git a/tar/test/main.c b/tar/test/main.c index d026203cc..d9f12c1eb 100644 --- a/tar/test/main.c +++ b/tar/test/main.c @@ -24,6 +24,7 @@ */ #include "test.h" +#include "test_utils.h" #ifdef HAVE_SYS_IOCTL_H #include #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 index 000000000..e8ae5ff74 --- /dev/null +++ b/test_utils/test_utils.c @@ -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 +#include + +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 index 000000000..164c528fc --- /dev/null +++ b/test_utils/test_utils.h @@ -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 */