| 1 |
elly/angband unit tests |
| 2 |
|
| 3 |
This directory contains the unit tests for the Angband engine. As we refactor |
| 4 |
the engine to be more modular, the number of tests will grow. A unit test is a C |
| 5 |
program which links against angband.o and tests the desired functions. To make |
| 6 |
writing these tests easier, there is a header file (at /src/tests/unit-test.h) |
| 7 |
which defines a particular main function which runs a set of specified tests in |
| 8 |
sequence. |
| 9 |
|
| 10 |
Using unit-test.h: |
| 11 |
To use this test template, your test needs to supply four things: |
| 12 |
static struct test tests[]: |
| 13 |
A list of all the tests to run, terminated by a test with a |
| 14 |
null name. |
| 15 |
static int setup(void **data): |
| 16 |
A function to set up this suite of tests; may do something like |
| 17 |
preallocate file handles and such. The `data` argument points to |
| 18 |
a pointer which is supplied to all unit test functions and the |
| 19 |
teardown function. |
| 20 |
static int teardown(void *data): |
| 21 |
Clean up after the test; close file handles, etc. |
| 22 |
static const char *suite_name: |
| 23 |
The test suite name. |
| 24 |
For examples, see the /src/tests/trivial. |
| 25 |
|
| 26 |
Using unit-test-data.h: |
| 27 |
Since we're testing a game engine, many times we will need dummy races, classes, |
| 28 |
etc to pass in to functions we'd like to test. Creating these is time-consuming |
| 29 |
since some of the structures involved are fairly large; unit-test-data.h defines |
| 30 |
test objects of most types to ease this pain. |