]>
git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libstrongswan/utils/test.c
2 * Copyright (C) 2013 Tobias Brunner
4 * Copyright (C) secunet Security Networks AG
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * A collection of testable functions
24 static hashtable_t
*functions
= NULL
;
27 bool test_runner_available
__attribute__((weak
));
31 * Check if we have libtest linkage and need testable functions
33 static bool has_libtest_linkage()
36 return dlsym(RTLD_DEFAULT
, "test_runner_available");
38 return test_runner_available
;
43 * Described in header.
45 void testable_function_register(char *name
, void *fn
)
49 if (lib
&& lib
->leak_detective
)
51 old
= lib
->leak_detective
->set_state(lib
->leak_detective
, FALSE
);
54 if (has_libtest_linkage())
59 functions
= hashtable_create(hashtable_hash_str
,
60 hashtable_equals_str
, 8);
64 functions
->put(functions
, name
, fn
);
68 functions
->remove(functions
, name
);
69 if (functions
->get_count(functions
) == 0)
71 functions
->destroy(functions
);
77 if (lib
&& lib
->leak_detective
)
79 lib
->leak_detective
->set_state(lib
->leak_detective
, old
);
84 * Described in header.
86 void* testable_function_get(char *name
)
90 return functions
->get(functions
, name
);