blob: 0f6d7ca8b82a8959bec4be0838ba5cd39a6be018 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#include "delivery.h"
#include "testing.h"
static struct Test *mock_test(const int ident) {
struct Test *test = test_init();
if (asprintf(&test->name, "test_%d", ident) < 0) {
return NULL;
}
return test;
}
void test_tests() {
const int initial = TEST_NUM_ALLOC_INITIAL;
const int balloon = initial * 10;
struct Tests *tests = tests_init(initial);
STASIS_ASSERT_FATAL(tests != NULL, "tests structure allocation failed");
STASIS_ASSERT(tests->num_alloc == (size_t) initial, "incorrect number of records initialized");
STASIS_ASSERT(tests->num_used == 0, "incorrect number of records used");
for (int i = 0; i < balloon; i++) {
struct Test *test = mock_test(i);
if (!test) {
SYSERROR("unable to allocate memory for test %d", i);
return;
}
tests_add(tests, test);
}
size_t errors = 0;
for (int i = 0; i < initial * 10; i++) {
struct Test *test = tests->test[i];
if (!test) {
errors++;
continue;
}
if (!test->name) {
errors++;
}
}
STASIS_ASSERT(errors == 0, "no errors should be detected in test->name member");
tests_free(&tests);
}
int main(int argc, char *argv[]) {
STASIS_TEST_BEGIN_MAIN();
STASIS_TEST_FUNC *tests[] = {
test_tests,
};
STASIS_TEST_RUN(tests);
STASIS_TEST_END_MAIN();
}
|