include: Fix unit_test_teardown macro.
authorAndreas Schneider <asn@cryptomilk.org>
Sun, 27 Oct 2013 14:54:53 +0000 (15:54 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Sun, 27 Oct 2013 15:04:25 +0000 (16:04 +0100)
example/CMakeLists.txt
example/fixture_test.c [new file with mode: 0644]
include/cmocka.h

index 12d1397968701a9f94d09ec4e3c8910786bb9de2..c2d34239afea517b9a5520dc559c30389902c9be 100644 (file)
@@ -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 (file)
index 0000000..757394a
--- /dev/null
@@ -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);
+}
index 9cd37eaba7ccdaf66a69327dec30e1547a2ef6e0..45d80a3b4d286f0c59c1ebcfa7b62965d6e4667a 100644 (file)
@@ -1312,7 +1312,6 @@ int run_test(#function);
 
 /** Initializes a UnitTest structure with a teardown function. */
 #define unit_test_teardown(test, teardown) \
-    _unit_test_setup(test, setup), \
     unit_test(test), \
     _unit_test_teardown(test, teardown)