|
Packit Service |
1d0348 |
$FreeBSD: src/lib/libarchive/test/README,v 1.3 2008/01/01 22:28:04 kientzle Exp $
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
This is the test harness for libarchive.
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
It compiles into a single program "libarchive_test" that is intended
|
|
Packit Service |
1d0348 |
to exercise as much of the library as possible. It is, of course,
|
|
Packit Service |
1d0348 |
very much a work in progress.
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
Each test is a function named test_foo in a file named test_foo.c.
|
|
Packit Service |
1d0348 |
Note that the file name is the same as the function name.
|
|
Packit Service |
1d0348 |
Each file must start with this line:
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
#include "test.h"
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
The test function must be declared with a line of this form
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
DEFINE_TEST(test_foo)
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
Nothing else should appear on that line.
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
When you add a test, please update the top-level Makefile.am and the
|
|
Packit Service |
1d0348 |
CMakeLists.txt in this directory to add your file to the list of
|
|
Packit Service |
1d0348 |
tests. The Makefile and main.c use various macro trickery to
|
|
Packit Service |
1d0348 |
automatically collect a list of test functions to be invoked.
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
Each test function can rely on the following:
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
* The current directory will be a freshly-created empty directory
|
|
Packit Service |
1d0348 |
suitable for that test. (The top-level main() creates a
|
|
Packit Service |
1d0348 |
directory for each separate test and chdir()s to that directory
|
|
Packit Service |
1d0348 |
before running the test.)
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
* The test function should use assert(), assertA() and similar macros
|
|
Packit Service |
1d0348 |
defined in test.h. If you need to add new macros of this form, feel
|
|
Packit Service |
1d0348 |
free to do so. The current macro set includes assertEqualInt() and
|
|
Packit Service |
1d0348 |
assertEqualString() that print out additional detail about their
|
|
Packit Service |
1d0348 |
arguments if the assertion does fail. 'A' versions also accept
|
|
Packit Service |
1d0348 |
a struct archive * and display any error message from there on
|
|
Packit Service |
1d0348 |
failure.
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
* You are encouraged to document each assertion with a failure() call
|
|
Packit Service |
1d0348 |
just before the assert. The failure() function is a printf-like
|
|
Packit Service |
1d0348 |
function whose text is displayed only if the assertion fails. It
|
|
Packit Service |
1d0348 |
can be used to display additional information relevant to the failure:
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
failure("The data read from file %s did not match the data written to that file.", filename);
|
|
Packit Service |
1d0348 |
assert(strcmp(buff1, buff2) == 0);
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
* Tests are encouraged to be economical with their memory and disk usage,
|
|
Packit Service |
1d0348 |
though this is not essential. The test is occasionally run under
|
|
Packit Service |
1d0348 |
a memory debugger to try to locate memory leaks in the library;
|
|
Packit Service |
1d0348 |
as a result, tests should be careful to release any memory they
|
|
Packit Service |
1d0348 |
allocate.
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
* Disable tests on specific platforms as necessary. Please avoid
|
|
Packit Service |
1d0348 |
using config.h to adjust feature requirements, as I want the tests
|
|
Packit Service |
1d0348 |
to also serve as a check on the configure process. The following
|
|
Packit Service |
1d0348 |
form is usually more appropriate:
|
|
Packit Service |
1d0348 |
|
|
Packit Service |
1d0348 |
#if !defined(__PLATFORM) && !defined(__Platform2__)
|
|
Packit Service |
1d0348 |
assert(xxxx)
|
|
Packit Service |
1d0348 |
#endif
|
|
Packit Service |
1d0348 |
|