From b750101eb236130cf056c675997decbac904cc49 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 17:35:18 +0200 Subject: Adding upstream version 252.22. Signed-off-by: Daniel Baumann --- src/test/test-static-destruct.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/test-static-destruct.c (limited to 'src/test/test-static-destruct.c') diff --git a/src/test/test-static-destruct.c b/src/test/test-static-destruct.c new file mode 100644 index 0000000..cb518ea --- /dev/null +++ b/src/test/test-static-destruct.c @@ -0,0 +1,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); -- cgit v1.2.3