diff options
author | Tim Kientzle <kientzle@FreeBSD.org> | 2008-02-19 05:52:30 +0000 |
---|---|---|
committer | Tim Kientzle <kientzle@FreeBSD.org> | 2008-02-19 05:52:30 +0000 |
commit | 4d9cfd1eb7deefc964d2778ec9e2b5d3ccda4df1 (patch) | |
tree | 70cac778552241f38b1a3107f0b158ec3af5449d /lib | |
parent | 5c5430972aeddea4eb97a8f8b76f58e011cb0585 (diff) | |
download | src-4d9cfd1eb7deefc964d2778ec9e2b5d3ccda4df1.tar.gz src-4d9cfd1eb7deefc964d2778ec9e2b5d3ccda4df1.zip |
The test_assert() function that backs my custom assert() macro
now returns a value, which supports such convenient
constructs as:
if (assert(NULL != foo())) {
}
Also be careful to setlocale("C") for each new test to
avoid locale pollution.
Also a couple of minor portability enhancements.
Notes
Notes:
svn path=/head/; revision=176401
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libarchive/test/main.c | 14 | ||||
-rw-r--r-- | lib/libarchive/test/test.h | 7 |
2 files changed, 12 insertions, 9 deletions
diff --git a/lib/libarchive/test/main.c b/lib/libarchive/test/main.c index ffe81cf30a51..a7289ec236ef 100644 --- a/lib/libarchive/test/main.c +++ b/lib/libarchive/test/main.c @@ -34,11 +34,8 @@ */ #define PROGRAM "LIBARCHIVE" -/* - * Various utility routines useful for test programs. - * Each test program is linked against this file. - */ #include <errno.h> +#include <locale.h> #include <stdarg.h> #include <time.h> @@ -226,20 +223,21 @@ failure(const char *fmt, ...) } /* Generic assert() just displays the failed condition. */ -void +int test_assert(const char *file, int line, int value, const char *condition, void *extra) { ++assertions; if (value) { msg[0] = '\0'; - return; + return (value); } failures ++; if (previous_failures(file, line)) - return; + return (value); fprintf(stderr, "%s:%d: Assertion failed\n", file, line); fprintf(stderr, " Condition: %s\n", condition); report_failure(extra); + return (value); } /* assertEqualInt() displays the values of the two integers. */ @@ -553,6 +551,8 @@ static int test_run(int i, const char *tmpdir) tests[i].name); exit(1); } + /* Explicitly reset the locale before each test. */ + setlocale(LC_ALL, "C"); /* Run the actual test. */ (*tests[i].func)(); /* Summarize the results of this test. */ diff --git a/lib/libarchive/test/test.h b/lib/libarchive/test/test.h index 3ec41eba7236..07de016f3219 100644 --- a/lib/libarchive/test/test.h +++ b/lib/libarchive/test/test.h @@ -31,8 +31,9 @@ * 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 +#endif #include <errno.h> #include <fcntl.h> @@ -40,7 +41,9 @@ #include <stdlib.h> #include <string.h> #include <sys/stat.h> +#ifndef _WIN32 #include <unistd.h> +#endif #include <wchar.h> #ifdef USE_DMALLOC @@ -112,7 +115,7 @@ void failure(const char *fmt, ...); void test_setup(const char *, int); void test_skipping(const char *fmt, ...); -void test_assert(const char *, int, int, const char *, void *); +int test_assert(const char *, int, int, const char *, void *); void test_assert_empty_file(const char *, ...); void test_assert_equal_file(const char *, const char *, ...); void test_assert_equal_int(const char *, int, int, const char *, int, const char *, void *); |