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})
--- /dev/null
+#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);
+}
/** 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)