[waffle] [PATCH 18/29] core: convert unittests to new cmocka API
Emil Velikov
emil.l.velikov at gmail.com
Wed Jan 6 13:27:44 PST 2016
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
src/waffle/core/wcore_attrib_list_unittest.c | 40 +++++++++++++--------------
src/waffle/core/wcore_config_attrs_unittest.c | 18 ++++++++----
src/waffle/core/wcore_error_unittest.c | 26 ++++++++---------
3 files changed, 45 insertions(+), 39 deletions(-)
diff --git a/src/waffle/core/wcore_attrib_list_unittest.c b/src/waffle/core/wcore_attrib_list_unittest.c
index 2eb95f2..727c721 100644
--- a/src/waffle/core/wcore_attrib_list_unittest.c
+++ b/src/waffle/core/wcore_attrib_list_unittest.c
@@ -228,26 +228,26 @@ test_wcore_attrib_list32_update_missing_key(void **state) {
int
main(void) {
- const UnitTest tests[] = {
- unit_test(test_wcore_attrib_list32_get_null),
- unit_test(test_wcore_attrib_list32_get_empty),
- unit_test(test_wcore_attrib_list32_get_missing_value),
- unit_test(test_wcore_attrib_list32_get_trailing_items),
- unit_test(test_wcore_attrib_list32_get_value_not_modified_if_not_found),
- unit_test(test_wcore_attrib_list32_get_key_is_first),
- unit_test(test_wcore_attrib_list32_get_key_is_last),
- unit_test(test_wcore_attrib_list32_length_null),
- unit_test(test_wcore_attrib_list32_length_is_0),
- unit_test(test_wcore_attrib_list32_length_is_1),
- unit_test(test_wcore_attrib_list32_length_is_2),
- unit_test(test_wcore_attrib_list32_length_is_37),
- unit_test(test_wcore_attrib_list32_length_trailing_items),
- unit_test(test_wcore_attrib_list32_update_null),
- unit_test(test_wcore_attrib_list32_update_empty_list),
- unit_test(test_wcore_attrib_list32_update_at_0),
- unit_test(test_wcore_attrib_list32_update_at_1),
- unit_test(test_wcore_attrib_list32_update_missing_key),
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test(test_wcore_attrib_list32_get_null),
+ cmocka_unit_test(test_wcore_attrib_list32_get_empty),
+ cmocka_unit_test(test_wcore_attrib_list32_get_missing_value),
+ cmocka_unit_test(test_wcore_attrib_list32_get_trailing_items),
+ cmocka_unit_test(test_wcore_attrib_list32_get_value_not_modified_if_not_found),
+ cmocka_unit_test(test_wcore_attrib_list32_get_key_is_first),
+ cmocka_unit_test(test_wcore_attrib_list32_get_key_is_last),
+ cmocka_unit_test(test_wcore_attrib_list32_length_null),
+ cmocka_unit_test(test_wcore_attrib_list32_length_is_0),
+ cmocka_unit_test(test_wcore_attrib_list32_length_is_1),
+ cmocka_unit_test(test_wcore_attrib_list32_length_is_2),
+ cmocka_unit_test(test_wcore_attrib_list32_length_is_37),
+ cmocka_unit_test(test_wcore_attrib_list32_length_trailing_items),
+ cmocka_unit_test(test_wcore_attrib_list32_update_null),
+ cmocka_unit_test(test_wcore_attrib_list32_update_empty_list),
+ cmocka_unit_test(test_wcore_attrib_list32_update_at_0),
+ cmocka_unit_test(test_wcore_attrib_list32_update_at_1),
+ cmocka_unit_test(test_wcore_attrib_list32_update_missing_key),
};
- return run_tests(tests);
+ return cmocka_run_group_tests(tests, NULL, NULL);
}
diff --git a/src/waffle/core/wcore_config_attrs_unittest.c b/src/waffle/core/wcore_config_attrs_unittest.c
index 501e30f..e6a2af0 100644
--- a/src/waffle/core/wcore_config_attrs_unittest.c
+++ b/src/waffle/core/wcore_config_attrs_unittest.c
@@ -40,7 +40,7 @@ struct test_state_wcore_config_attrs {
struct wcore_config_attrs expect_attrs;
};
-static void
+static int
setup(void **state) {
static const struct wcore_config_attrs default_attrs = {
// There is no default context api, so arbitrarily choose OpenGL. The
@@ -73,18 +73,24 @@ setup(void **state) {
wcore_error_reset();
- *state = ts = calloc(1, sizeof(*ts));
+ ts = calloc(1, sizeof(*ts));
+ if (!ts)
+ return -1;
+
+ *state = ts;
// Fill actual_attrs with canaries.
memset(&ts->actual_attrs, 0x99, sizeof(ts->actual_attrs));
// Set expect_attrs to defaults.
memcpy(&ts->expect_attrs, &default_attrs, sizeof(ts->expect_attrs));
+ return 0;
}
-static void
+static int
teardown(void **state) {
free(*state);
+ return 0;
}
static void
@@ -1145,8 +1151,8 @@ test_wcore_config_attrs_debug_gles3(void **state) {
int
main(void) {
- const UnitTest tests[] = {
- #define unit_test_make(name) unit_test_setup_teardown(name, setup, teardown)
+ const struct CMUnitTest tests[] = {
+ #define unit_test_make(name) cmocka_unit_test_setup_teardown(name, setup, teardown)
unit_test_make(test_wcore_config_attrs_null_attrib_list),
unit_test_make(test_wcore_config_attrs_empty_attrib_list),
@@ -1213,5 +1219,5 @@ main(void) {
#undef unit_test_make
};
- return run_tests(tests);
+ return cmocka_run_group_tests(tests, NULL, NULL);
}
diff --git a/src/waffle/core/wcore_error_unittest.c b/src/waffle/core/wcore_error_unittest.c
index 0ac667b..8f0d8df 100644
--- a/src/waffle/core/wcore_error_unittest.c
+++ b/src/waffle/core/wcore_error_unittest.c
@@ -227,19 +227,19 @@ test_wcore_error_thread_local(void **state) {
int
main(void) {
- const UnitTest tests[] = {
- unit_test(test_wcore_error_code_unknown_error),
- unit_test(test_wcore_error_code_bad_attribute),
- unit_test(test_wcore_error_code_unknown_error),
- unit_test(test_wcore_error_with_message),
- unit_test(test_wcore_error_internal_error),
- unit_test(test_wcore_error_first_call_without_message_wins),
- unit_test(test_wcore_error_first_call_with_message_wins),
- unit_test(test_wcore_error_disable_then_error),
- unit_test(test_wcore_error_disable_then_errorf),
- unit_test(test_wcore_error_disable_then_error_internal),
- unit_test(test_wcore_error_thread_local),
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test(test_wcore_error_code_unknown_error),
+ cmocka_unit_test(test_wcore_error_code_bad_attribute),
+ cmocka_unit_test(test_wcore_error_code_unknown_error),
+ cmocka_unit_test(test_wcore_error_with_message),
+ cmocka_unit_test(test_wcore_error_internal_error),
+ cmocka_unit_test(test_wcore_error_first_call_without_message_wins),
+ cmocka_unit_test(test_wcore_error_first_call_with_message_wins),
+ cmocka_unit_test(test_wcore_error_disable_then_error),
+ cmocka_unit_test(test_wcore_error_disable_then_errorf),
+ cmocka_unit_test(test_wcore_error_disable_then_error_internal),
+ cmocka_unit_test(test_wcore_error_thread_local),
};
- return run_tests(tests);
+ return cmocka_run_group_tests(tests, NULL, NULL);
}
--
2.6.2
More information about the waffle
mailing list