]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Consistify the test harnesses and ensure that config.h gets
authorTim Kientzle <kientzle@gmail.com>
Thu, 5 Jun 2008 22:38:03 +0000 (18:38 -0400)
committerTim Kientzle <kientzle@gmail.com>
Thu, 5 Jun 2008 22:38:03 +0000 (18:38 -0400)
included before other headers.

SVN-Revision: 106

cpio/test/main.c
cpio/test/test.h
libarchive/test/main.c
libarchive/test/test.h
tar/test/main.c
tar/test/test.h

index c88dd2ac341cf215912ff33c27d800d1ec19e323..ecf343cde39042a7d41371906196e7264d0972ee 100644 (file)
  * Various utility routines useful for test programs.
  * Each test program is linked against this file.
  */
+#include "test.h"
+
 #include <errno.h>
 #include <locale.h>
 #include <stdarg.h>
 #include <time.h>
 
-#include "test.h"
-
 /*
  * This same file is used pretty much verbatim for all test harnesses.
  *
@@ -541,6 +541,48 @@ test_assert_equal_file(const char *f1, const char *f2pattern, ...)
        return (0);
 }
 
+int
+test_assert_file_exists(const char *fpattern, ...)
+{
+       char f[1024];
+       va_list ap;
+
+       va_start(ap, fpattern);
+       vsprintf(f, fpattern, ap);
+       va_end(ap);
+
+       if (!access(f, F_OK))
+               return (1);
+       if (!previous_failures(test_filename, test_line)) {
+               fprintf(stderr, "%s:%d: File doesn't exist\n",
+                   test_filename, test_line);
+               fprintf(stderr, "  file=\"%s\"\n", f);
+               report_failure(test_extra);
+       }
+       return (0);
+}
+
+int
+test_assert_file_not_exists(const char *fpattern, ...)
+{
+       char f[1024];
+       va_list ap;
+
+       va_start(ap, fpattern);
+       vsprintf(f, fpattern, ap);
+       va_end(ap);
+
+       if (access(f, F_OK))
+               return (1);
+       if (!previous_failures(test_filename, test_line)) {
+               fprintf(stderr, "%s:%d: File exists and shouldn't\n",
+                   test_filename, test_line);
+               fprintf(stderr, "  file=\"%s\"\n", f);
+               report_failure(test_extra);
+       }
+       return (0);
+}
+
 /* assertFileContents() asserts the contents of a file. */
 int
 test_assert_file_contents(const void *buff, int s, const char *fpattern, ...)
@@ -670,6 +712,7 @@ static int test_run(int i, const char *tmpdir)
 {
        int failures_before = failures;
 
+       fflush(stdout);
        if (!quiet_flag)
                printf("%d: %s\n", i, tests[i].name);
        /*
index 06e6d903fc8b9b36f7414312a27362f223c7378b..39a98376f3306d0360a2c40295e14a59a3c94157 100644 (file)
  * The goal of this file (and the matching test.c) is to
  * simplify the very repetitive test-*.c test programs.
  */
-#ifndef _FILE_OFFSET_BITS
-#define _FILE_OFFSET_BITS 64
+#if defined(HAVE_CONFIG_H)
+/* Most POSIX platforms use the 'configure' script to build config.h */
+#include "../../config.h"
+#elif defined(__FreeBSD__)
+/* Building as part of FreeBSD system requires a pre-built config.h. */
+#include "../config_freebsd.h"
+#elif defined(_WIN32)
+/* Win32 can't run the 'configure' script. */
+#include "../config_windows.h"
+#else
+/* Warn if the library hasn't been (automatically or manually) configured. */
+#error Oops: No config.h and no pre-built configuration in test.h.
 #endif
 
 #include <dirent.h>
 #include <dmalloc.h>
 #endif
 
-#if defined(HAVE_CONFIG_H)
-/* Most POSIX platforms use the 'configure' script to build config.h */
-#include "../../config.h"
-#elif defined(__FreeBSD__)
-/* Building as part of FreeBSD system requires a pre-built config.h. */
-#include "../config_freebsd.h"
-#elif defined(_WIN32)
-/* Win32 can't run the 'configure' script. */
-#include "../config_windows.h"
-#else
-/* Warn if the library hasn't been (automatically or manually) configured. */
-#error Oops: No config.h and no pre-built configuration in test.h.
-#endif
-
 /* No non-FreeBSD platform will have __FBSDID, so just define it here. */
 #ifdef __FreeBSD__
 #include <sys/cdefs.h>  /* For __FBSDID */
 /* Assert that a file is empty; supports printf-style arguments. */
 #define assertEmptyFile                \
   test_setup(__FILE__, __LINE__);test_assert_empty_file
+/* Assert that a file exists; supports printf-style arguments. */
+#define assertFileExists               \
+  test_setup(__FILE__, __LINE__);test_assert_file_exists
+/* Assert that a file exists; supports printf-style arguments. */
+#define assertFileNotExists            \
+  test_setup(__FILE__, __LINE__);test_assert_file_not_exists
 /* Assert that file contents match a string; supports printf-style arguments. */
 #define assertFileContents             \
   test_setup(__FILE__, __LINE__);test_assert_file_contents
@@ -127,6 +129,8 @@ int test_assert_equal_string(const char *, int, const char *v1, const char *, co
 int test_assert_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *);
 int test_assert_equal_mem(const char *, int, const char *, const char *, const char *, const char *, size_t, const char *, void *);
 int test_assert_file_contents(const void *, int, const char *, ...);
+int test_assert_file_exists(const char *, ...);
+int test_assert_file_not_exists(const char *, ...);
 
 /* Like sprintf, then system() */
 int systemf(const char * fmt, ...);
@@ -144,4 +148,3 @@ void extract_reference_file(const char *);
 
 /* Pathname of exe to be tested. */
 char *testprog;
-
index 95431aa267a4852126c988ba239110bd5339e087..da8ea821b4d32aa407cef5c8b8b0a0ee8fbb3894 100644 (file)
  * Various utility routines useful for test programs.
  * Each test program is linked against this file.
  */
+#include "test.h"
+
 #include <errno.h>
 #include <locale.h>
 #include <stdarg.h>
 #include <time.h>
 
-#include "test.h"
-
 /*
  * This same file is used pretty much verbatim for all test harnesses.
  *
@@ -540,6 +540,48 @@ test_assert_equal_file(const char *f1, const char *f2pattern, ...)
        return (0);
 }
 
+int
+test_assert_file_exists(const char *fpattern, ...)
+{
+       char f[1024];
+       va_list ap;
+
+       va_start(ap, fpattern);
+       vsprintf(f, fpattern, ap);
+       va_end(ap);
+
+       if (!access(f, F_OK))
+               return (1);
+       if (!previous_failures(test_filename, test_line)) {
+               fprintf(stderr, "%s:%d: File doesn't exist\n",
+                   test_filename, test_line);
+               fprintf(stderr, "  file=\"%s\"\n", f);
+               report_failure(test_extra);
+       }
+       return (0);
+}
+
+int
+test_assert_file_not_exists(const char *fpattern, ...)
+{
+       char f[1024];
+       va_list ap;
+
+       va_start(ap, fpattern);
+       vsprintf(f, fpattern, ap);
+       va_end(ap);
+
+       if (access(f, F_OK))
+               return (1);
+       if (!previous_failures(test_filename, test_line)) {
+               fprintf(stderr, "%s:%d: File exists and shouldn't\n",
+                   test_filename, test_line);
+               fprintf(stderr, "  file=\"%s\"\n", f);
+               report_failure(test_extra);
+       }
+       return (0);
+}
+
 /* assertFileContents() asserts the contents of a file. */
 int
 test_assert_file_contents(const void *buff, int s, const char *fpattern, ...)
@@ -669,6 +711,7 @@ static int test_run(int i, const char *tmpdir)
 {
        int failures_before = failures;
 
+       fflush(stdout);
        if (!quiet_flag)
                printf("%d: %s\n", i, tests[i].name);
        /*
index dcb190ff3fe7bf828c2995dab7c7066d37b0f00c..30efce80bc7d7500bc09ebcd36fd7e0bfbbf5ba1 100644 (file)
  * The goal of this file (and the matching test.c) is to
  * simplify the very repetitive test-*.c test programs.
  */
-#ifndef _FILE_OFFSET_BITS
-#define _FILE_OFFSET_BITS 64
+#if defined(HAVE_CONFIG_H)
+/* Most POSIX platforms use the 'configure' script to build config.h */
+#include "../../config.h"
+#elif defined(__FreeBSD__)
+/* Building as part of FreeBSD system requires a pre-built config.h. */
+#include "../config_freebsd.h"
+#elif defined(_WIN32)
+/* Win32 can't run the 'configure' script. */
+#include "../config_windows.h"
+#else
+/* Warn if the library hasn't been (automatically or manually) configured. */
+#error Oops: No config.h and no pre-built configuration in test.h.
 #endif
 
 #include <dirent.h>
 #include <dmalloc.h>
 #endif
 
-#if defined(HAVE_CONFIG_H)
-/* Most POSIX platforms use the 'configure' script to build config.h */
-#include "../../config.h"
-#elif defined(__FreeBSD__)
-/* Building as part of FreeBSD system requires a pre-built config.h. */
-#include "../config_freebsd.h"
-#elif defined(_WIN32)
-/* Win32 can't run the 'configure' script. */
-#include "../config_windows.h"
-#else
-/* Warn if the library hasn't been (automatically or manually) configured. */
-#error Oops: No config.h and no pre-built configuration in test.h.
-#endif
-
 /* No non-FreeBSD platform will have __FBSDID, so just define it here. */
 #ifdef __FreeBSD__
 #include <sys/cdefs.h>  /* For __FBSDID */
 /* Assert that a file is empty; supports printf-style arguments. */
 #define assertEmptyFile                \
   test_setup(__FILE__, __LINE__);test_assert_empty_file
+/* Assert that a file exists; supports printf-style arguments. */
+#define assertFileExists               \
+  test_setup(__FILE__, __LINE__);test_assert_file_exists
+/* Assert that a file exists; supports printf-style arguments. */
+#define assertFileNotExists            \
+  test_setup(__FILE__, __LINE__);test_assert_file_not_exists
+/* Assert that file contents match a string; supports printf-style arguments. */
+#define assertFileContents             \
+  test_setup(__FILE__, __LINE__);test_assert_file_contents
 
 /*
  * This would be simple with C99 variadic macros, but I don't want to
@@ -124,6 +129,8 @@ int test_assert_equal_string(const char *, int, const char *v1, const char *, co
 int test_assert_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *);
 int test_assert_equal_mem(const char *, int, const char *, const char *, const char *, const char *, size_t, const char *, void *);
 int test_assert_file_contents(const void *, int, const char *, ...);
+int test_assert_file_exists(const char *, ...);
+int test_assert_file_not_exists(const char *, ...);
 
 /* Like sprintf, then system() */
 int systemf(const char * fmt, ...);
index 0d4fcd3ffb27f2d368396cea000986d21bb1dc21..281a0c69fb072c56b55377dd98c29d6f07ae8bb0 100644 (file)
  * Various utility routines useful for test programs.
  * Each test program is linked against this file.
  */
+#include "test.h"
+
 #include <errno.h>
 #include <locale.h>
 #include <stdarg.h>
 #include <time.h>
 
-#include "test.h"
-
 /*
  * This same file is used pretty much verbatim for all test harnesses.
  *
@@ -712,6 +712,7 @@ static int test_run(int i, const char *tmpdir)
 {
        int failures_before = failures;
 
+       fflush(stdout);
        if (!quiet_flag)
                printf("%d: %s\n", i, tests[i].name);
        /*
index 9bc1ae8a3450ecebdd67b9e5f73a39a6f74db9d0..6feac22b6099b2de3e15af62777ad9d6f05902cc 100644 (file)
  * The goal of this file (and the matching test.c) is to
  * simplify the very repetitive test-*.c test programs.
  */
-#ifndef _FILE_OFFSET_BITS
-#define _FILE_OFFSET_BITS 64
+#if defined(HAVE_CONFIG_H)
+/* Most POSIX platforms use the 'configure' script to build config.h */
+#include "../../config.h"
+#elif defined(__FreeBSD__)
+/* Building as part of FreeBSD system requires a pre-built config.h. */
+#include "../config_freebsd.h"
+#elif defined(_WIN32)
+/* Win32 can't run the 'configure' script. */
+#include "../config_windows.h"
+#else
+/* Warn if the library hasn't been (automatically or manually) configured. */
+#error Oops: No config.h and no pre-built configuration in test.h.
 #endif
 
 #include <dirent.h>
 #include <dmalloc.h>
 #endif
 
-#if defined(HAVE_CONFIG_H)
-/* Most POSIX platforms use the 'configure' script to build config.h */
-#include "../../config.h"
-#elif defined(__FreeBSD__)
-/* Building as part of FreeBSD system requires a pre-built config.h. */
-#include "../config_freebsd.h"
-#elif defined(_WIN32)
-/* Win32 can't run the 'configure' script. */
-#include "../config_windows.h"
-#else
-/* Warn if the library hasn't been (automatically or manually) configured. */
-#error Oops: No config.h and no pre-built configuration in test.h.
-#endif
-
 /* No non-FreeBSD platform will have __FBSDID, so just define it here. */
 #ifdef __FreeBSD__
 #include <sys/cdefs.h>  /* For __FBSDID */
 /* Assert that a file exists; supports printf-style arguments. */
 #define assertFileNotExists            \
   test_setup(__FILE__, __LINE__);test_assert_file_not_exists
+/* Assert that file contents match a string; supports printf-style arguments. */
+#define assertFileContents             \
+  test_setup(__FILE__, __LINE__);test_assert_file_contents
 
 /*
  * This would be simple with C99 variadic macros, but I don't want to