summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-12-23 19:06:11 +0100
committerAndreas Schneider <asn@cryptomilk.org>2014-04-11 15:09:05 +0200
commit01898b8bada0f96adfec6f47a4e888845cab172d (patch)
treeb855e7c16c94ef1c82d402caddfbf600c50ab806 /tests
parenta046988ac4135ec63f6b19172cdcdae7ef123869 (diff)
downloadcmocka-01898b8bada0f96adfec6f47a4e888845cab172d.tar.gz
cmocka-01898b8bada0f96adfec6f47a4e888845cab172d.tar.bz2
cmocka-01898b8bada0f96adfec6f47a4e888845cab172d.zip
tests: Add test_group_fixtures.
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/test_group_fixtures.c48
2 files changed, 49 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 8287b61..9c00846 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -8,6 +8,7 @@ include_directories(
set(CMOCKA_TESTS
test_fixtures
+ test_group_fixtures
test_assert_macros
test_assert_macros_fail
test_exception_handler
diff --git a/tests/test_group_fixtures.c b/tests/test_group_fixtures.c
new file mode 100644
index 0000000..6f49e24
--- /dev/null
+++ b/tests/test_group_fixtures.c
@@ -0,0 +1,48 @@
+/* Use the unit test allocators */
+#define UNIT_TESTING 1
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+static void group_setup(void **state)
+{
+ int *answer = malloc(sizeof(int));
+ assert_non_null(answer);
+ *answer = 42;
+
+ *state = answer;
+}
+
+static void group_teardown(void **state)
+{
+ int *answer = (int *)*state;
+
+ free(answer);
+}
+
+static void test_value_equal(void **state)
+{
+ int a = *((int *)*state);
+
+ assert_int_equal(a, 42);
+}
+
+static void test_value_range(void **state)
+{
+ int a = *((int *)*state);
+
+ assert_in_range(a, 0, 100);
+}
+
+int main(void) {
+ const UnitTest tests[] = {
+ group_test_setup(group_setup),
+ unit_test(test_value_equal),
+ unit_test(test_value_range),
+ group_test_teardown(group_teardown),
+ };
+
+ return run_group_tests(tests);
+}