Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */ 2 : 3 : #include "alloc-util.h" 4 : #include "static-destruct.h" 5 : #include "tests.h" 6 : 7 : static int foo = 0; 8 : static int bar = 0; 9 : static int baz = 0; 10 : static char* memory = NULL; 11 : 12 6 : static void test_destroy(int *b) { 13 6 : (*b)++; 14 6 : } 15 : 16 1 : STATIC_DESTRUCTOR_REGISTER(foo, test_destroy); 17 1 : STATIC_DESTRUCTOR_REGISTER(bar, test_destroy); 18 1 : STATIC_DESTRUCTOR_REGISTER(bar, test_destroy); 19 1 : STATIC_DESTRUCTOR_REGISTER(baz, test_destroy); 20 1 : STATIC_DESTRUCTOR_REGISTER(baz, test_destroy); 21 1 : STATIC_DESTRUCTOR_REGISTER(baz, test_destroy); 22 1 : STATIC_DESTRUCTOR_REGISTER(memory, freep); 23 : 24 1 : int main(int argc, char *argv[]) { 25 1 : test_setup_logging(LOG_INFO); 26 : 27 1 : assert_se(memory = strdup("hallo")); 28 : 29 1 : assert_se(foo == 0 && bar == 0 && baz == 0); 30 1 : static_destruct(); 31 1 : assert_se(foo == 1 && bar == 2 && baz == 3); 32 : 33 1 : return EXIT_SUCCESS; 34 : }