diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2013-10-27 15:54:53 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2013-10-27 16:04:25 +0100 |
commit | 5c8a0fb3a07912aad0121b948092cb108a958ec9 (patch) | |
tree | def9d96b4b0694adf6f2724522aa898ea5c42d09 /example | |
parent | fc5f1448acafd56630c23ce978d835982c00f40c (diff) | |
download | cmocka-5c8a0fb3a07912aad0121b948092cb108a958ec9.tar.gz cmocka-5c8a0fb3a07912aad0121b948092cb108a958ec9.tar.xz cmocka-5c8a0fb3a07912aad0121b948092cb108a958ec9.zip |
include: Fix unit_test_teardown macro.
Diffstat (limited to 'example')
-rw-r--r-- | example/CMakeLists.txt | 5 | ||||
-rw-r--r-- | example/fixture_test.c | 37 |
2 files changed, 42 insertions, 0 deletions
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 12d1397..c2d3423 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -15,6 +15,11 @@ set_source_files_properties( PROPERTIES COMPILE_FLAGS -DUNIT_TESTING=1) +add_executable(fixture_test fixture_test.c) +target_link_libraries(fixture_test ${CMOCKA_SHARED_LIBRARY}) + +add_test(fixture_test ${CMAKE_CURRENT_BINARY_DIR}/fixture_test) + add_executable(calculator_test calculator.c calculator_test.c) target_link_libraries(calculator_test ${CMOCKA_SHARED_LIBRARY}) diff --git a/example/fixture_test.c b/example/fixture_test.c new file mode 100644 index 0000000..757394a --- /dev/null +++ b/example/fixture_test.c @@ -0,0 +1,37 @@ +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> + +#include <stdlib.h> + +static void setup_only(void **state) +{ + *state = malloc(1); +} + +static void teardown_only(void **state) +{ + free(*state); +} + +static void malloc_setup_test(void **state) +{ + assert_non_null(*state); + free(*state); +} + +static void malloc_teardown_test(void **state) +{ + *state = malloc(1); + assert_non_null(*state); +} + +int main(void) { + const UnitTest tests[] = { + unit_test_setup(malloc_setup_test, setup_only), + unit_test_teardown(malloc_teardown_test, teardown_only), + }; + + return run_tests(tests); +} |