blob: cb518ea3623bbb5700e276f29f6c06fb0f986db6 (
plain)
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
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "alloc-util.h"
#include "static-destruct.h"
#include "tests.h"
static int foo = 0;
static int bar = 0;
static int baz = 0;
static char* memory = NULL;
static void test_destroy(int *b) {
(*b)++;
}
STATIC_DESTRUCTOR_REGISTER(foo, test_destroy);
STATIC_DESTRUCTOR_REGISTER(bar, test_destroy);
STATIC_DESTRUCTOR_REGISTER(bar, test_destroy);
STATIC_DESTRUCTOR_REGISTER(baz, test_destroy);
STATIC_DESTRUCTOR_REGISTER(baz, test_destroy);
STATIC_DESTRUCTOR_REGISTER(baz, test_destroy);
STATIC_DESTRUCTOR_REGISTER(memory, freep);
TEST(static_destruct) {
assert_se(memory = strdup("hallo"));
assert_se(foo == 0 && bar == 0 && baz == 0);
static_destruct();
assert_se(foo == 1 && bar == 2 && baz == 3);
assert_se(memory == NULL);
}
DEFINE_TEST_MAIN(LOG_INFO);
|