From 1fac7349a9900b61e28749a09efd531821aa8fd4 Mon Sep 17 00:00:00 2001 From: YoungHun Cho Date: Mon, 5 Jun 2017 17:07:12 +0900 Subject: [PATCH] upgrade test_unit Change-Id: Iaba268f1c49461007f0649c9b7747f37720701c0 --- test/feature_test/feature_test.c | 56 +++--- test/feature_test/feature_test.h | 17 ++ test/feature_test/group_feature_on_off_animation.c | 215 +++++++++------------ test/function_test/function_test.c | 53 ++--- test/function_test/function_test.h | 17 ++ test/function_test/group_function_animation.c | 92 +++++---- test/test_main.c | 18 +- test/unit/inc/unit.h | 33 +++- test/unit/inc/unit_assert.h | 18 +- test/unit/inc/unit_group.h | 24 ++- test/unit/unit.c | 64 +++++- test/unit/unit_assert.c | 10 + test/unit/unit_group.c | 108 ++++++++++- test/unit/unit_log_buf.c | 2 + test/unit/unit_test/inc/unit_test_common.h | 23 --- .../unit_test_append_log/unit_test_append_log.h | 6 +- .../unit_test_assert_test/unit_test_assert.c | 115 +++++------ .../unit_test_assert_test/unit_test_assert.h | 8 +- .../unit_test_function_test/unit_test_function.h | 8 +- .../unit_test_group_function.c | 15 +- .../unit_test_log_buf_function.c | 22 +-- .../unit_test_unit_function.c | 30 ++- .../unit_test_group_test/unit_test_group.c | 74 +------ .../unit_test_group_test/unit_test_group.h | 7 +- .../unit_test_group_test/unit_test_group_result.c | 133 +++++++++---- test/unit/unit_test/unit_test_main.c | 3 +- 26 files changed, 685 insertions(+), 486 deletions(-) mode change 100644 => 100755 test/unit/unit_assert.c delete mode 100755 test/unit/unit_test/inc/unit_test_common.h diff --git a/test/feature_test/feature_test.c b/test/feature_test/feature_test.c index a2ecbeb..daa0552 100755 --- a/test/feature_test/feature_test.c +++ b/test/feature_test/feature_test.c @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + #include "test.h" #if TEST_MODE @@ -5,49 +22,20 @@ #include -static void __complete_group_cb(void); -static void __run_next_group(void); - -static struct { - int current_group; - char group_name[GROUP_COUNT_MAX + 1][128]; - void(*group_starter_pool[GROUP_COUNT_MAX + 1])(unit_group_t * group); -} s_info = { - .current_group = 0, - .group_name = { - "group_feature_on_off_animation", - "" - }, - .group_starter_pool = { - group_feature_on_off_animation, - NULL, - }, -}; - -static void __complete_group_cb(void) -{ - s_info.current_group += 1; - - __run_next_group(); -} - -static void __run_next_group(void) +static void __test_complete_cb(void) { - if (s_info.group_starter_pool[s_info.current_group] == NULL) { - elm_exit(); - return ; - } + unit_fini(); - TEST_GROUP(s_info.group_name[s_info.current_group], s_info.group_starter_pool[s_info.current_group], __complete_group_cb); + elm_exit(); } void feature_test(void) { unit_clear_log(); - s_info.current_group = 0; + TEST_GROUP_ADD("group_feature_on_off_animation", group_feature_on_off_animation); - __run_next_group(); + TEST_RUN(__test_complete_cb); } #endif diff --git a/test/feature_test/feature_test.h b/test/feature_test/feature_test.h index 6d5e412..692cc87 100755 --- a/test/feature_test/feature_test.h +++ b/test/feature_test/feature_test.h @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + #ifndef __FEATURE_TEST__ #define __FEATURE_TEST__ diff --git a/test/feature_test/group_feature_on_off_animation.c b/test/feature_test/group_feature_on_off_animation.c index 8e948c6..5f200fd 100755 --- a/test/feature_test/group_feature_on_off_animation.c +++ b/test/feature_test/group_feature_on_off_animation.c @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + #include "test.h" #if TEST_MODE @@ -8,88 +25,34 @@ #include #include -extern Evas_Object *__t__get_window(void); -extern Evas_Object *__t__get_layout(void); -extern Evas_Object *__t__get_display_block(void); - -static void __case_start_on_animation(bool * is_passed); -static void __case_start_off_animation(bool * is_passed); -static void __case_check_animation(bool * is_passed); -static void __case_check_finish_on_animation(bool * is_passed); -static void __case_check_finish_off_animation(bool * is_passed); - static struct { - int on_off; + int animation_type; bool is_exit; - int current_step; - int step_max; - Ecore_Timer * group_timer; unit_group_t * group; - int current_case; - void(*case_pool[CASE_COUNT_MAX + 1])(bool * is_passed); } s_info = { - .on_off = 0, + .animation_type = 0, .is_exit = false, - .current_step = 0, - .group_timer = NULL, .group = NULL, - .current_case = 0, - .case_pool = { - __case_start_on_animation, - __case_check_animation, /* x 8 */ - __case_check_finish_on_animation, - __case_start_off_animation, - __case_check_animation, /* x 3 */ - __case_check_finish_off_animation, - NULL, - }, }; -static Eina_Bool __group_timer_callback(void * data); - -static void __set_up(void) {} -static void __tear_down(void) {} - static void test_elm_exit(void) { s_info.is_exit = true; } -static void __case_start_on_animation(bool * is_passed) +static void __set_up(void) { - int is_finished = -1; - - vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 0); - - vconf_get_int(VCONFKEY_BOOT_ANIMATION_FINISHED, &is_finished); - TEST_ASSERT_EQUAL_INT(0, is_finished); - - boot_exit = test_elm_exit; s_info.is_exit = false; + boot_exit = test_elm_exit; + vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 0); - init_animation(TYPE_ON); - - s_info.current_step = 1; - s_info.on_off = 1; - - *is_passed = true; + ecore_timer_add(0.1, s_info.group->set_up_complete, s_info.group); } -static void __case_start_off_animation(bool * is_passed) +static void __tear_down(void) { - int is_finished = -1; - - vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 0); - - vconf_get_int(VCONFKEY_BOOT_ANIMATION_FINISHED, &is_finished); - TEST_ASSERT_EQUAL_INT(0, is_finished); - - init_animation(TYPE_OFF); - - s_info.current_step = 1; - s_info.on_off = 2; - - *is_passed = true; + boot_exit = elm_exit; + s_info.group->tear_down_complete(s_info.group); } static int __get_step_max(int w, int h) @@ -99,19 +62,19 @@ static int __get_step_max(int w, int h) } else if (w == 360 && h == 480) { return 3; } else if (w == 480 && h == 800) { - if (s_info.on_off == TYPE_ON) { + if (s_info.animation_type == TYPE_ON) { return 4; } else { return 3; } } else if (w == 720 && h == 1280) { - if (s_info.on_off == TYPE_ON) { + if (s_info.animation_type == TYPE_ON) { return 7; } else { return 3; } } else { - if (s_info.on_off == TYPE_ON) { + if (s_info.animation_type == TYPE_ON) { return 7; } else { return 3; @@ -119,7 +82,44 @@ static int __get_step_max(int w, int h) } } -static void __case_check_animation(bool * is_passed) +static unit_case_func_t __continue_check_finish_on_animation(void *data) +{ + int is_finished = -1; + + vconf_get_int(VCONFKEY_BOOT_ANIMATION_FINISHED, &is_finished); + TEST_ASSERT_EQUAL_INT(1, is_finished); + + TEST_ASSERT_TRUE(s_info.is_exit == true); + + TEST_CASE_DONE(s_info.group); +} + +extern Evas_Object *__t__get_window(void); +extern Evas_Object *__t__get_display_block(void); +static unit_case_func_t __continue_check_finish_off_animation(void *data) +{ + int rx, ry, rw, rh; + int screen_w, screen_h; + + Evas_Object *window = __t__get_window(); + TEST_ASSERT_TRUE(window != NULL); + elm_win_screen_size_get(window, NULL, NULL, &screen_w, &screen_h); + + Evas_Object *display_block = __t__get_display_block(); + TEST_ASSERT_TRUE(display_block != NULL); + + evas_object_geometry_get(display_block, &rx, &ry, &rw, &rh); + TEST_ASSERT_EQUAL_INT(0, rx); + TEST_ASSERT_EQUAL_INT(0, ry); + TEST_ASSERT_EQUAL_INT(screen_w, rw); + TEST_ASSERT_EQUAL_INT(screen_h, rh); + TEST_ASSERT_TRUE(evas_object_visible_get(display_block)); + + TEST_CASE_DONE(s_info.group); +} + +extern Evas_Object *__t__get_layout(void); +static unit_case_func_t __continue_check_animation_layout(void *data) { int rx, ry, rw, rh; int screen_w, screen_h; @@ -147,82 +147,49 @@ static void __case_check_animation(bool * is_passed) const char *file_name = NULL; elm_layout_file_get(layout, &file_name, NULL); - TEST_ASSERT_EQUAL_STRING(get_layout_file_name(s_info.on_off, screen_w, screen_h), file_name); + char * expected_file_name = get_layout_file_name(s_info.animation_type, screen_w, screen_h); + TEST_ASSERT_EQUAL_STRING(expected_file_name, file_name); + free(expected_file_name); - if (s_info.current_step < __get_step_max(screen_w, screen_h)) { - s_info.current_case -= 1; + int current_step = (int)data; + if (current_step < __get_step_max(screen_w, screen_h)) { + TEST_CASE_CONTINUE(0.8, __continue_check_animation_layout, (void*)(current_step + 1)); } - s_info.current_step += 1; + if (s_info.animation_type == TYPE_ON) + TEST_CASE_CONTINUE(0.8, __continue_check_finish_on_animation, NULL); - *is_passed = true; + TEST_CASE_CONTINUE(0.8, __continue_check_finish_off_animation, NULL); } -static void __case_check_finish_on_animation(bool * is_passed) +static unit_case_func_t __case_check_animation(void *data) { int is_finished = -1; vconf_get_int(VCONFKEY_BOOT_ANIMATION_FINISHED, &is_finished); - TEST_ASSERT_TRUE(is_finished == 1); + TEST_ASSERT_EQUAL_INT(0, is_finished); - TEST_ASSERT_TRUE(s_info.is_exit == true); + boot_exit = test_elm_exit; s_info.is_exit = false; - s_info.on_off = 0; - - *is_passed = true; -} - -static void __case_check_finish_off_animation(bool * is_passed) -{ - int rx, ry, rw, rh; - int screen_w, screen_h; - Evas_Object *window = __t__get_window(); - TEST_ASSERT_TRUE(window != NULL); - elm_win_screen_size_get(window, NULL, NULL, &screen_w, &screen_h); + s_info.animation_type = (int)data; + init_animation(s_info.animation_type); - Evas_Object *display_block = __t__get_display_block(); - TEST_ASSERT_TRUE(display_block != NULL); - - evas_object_geometry_get(display_block, &rx, &ry, &rw, &rh); - TEST_ASSERT_EQUAL_INT(0, rx); - TEST_ASSERT_EQUAL_INT(0, ry); - TEST_ASSERT_EQUAL_INT(screen_w, rw); - TEST_ASSERT_EQUAL_INT(screen_h, rh); - TEST_ASSERT_TRUE(evas_object_visible_get(display_block)); - - s_info.on_off = 0; - - *is_passed = true; -} - -static Eina_Bool __group_timer_callback(void * data) -{ - if (s_info.case_pool[s_info.current_case] == NULL) { - s_info.group->finish(s_info.group); - - s_info.group_timer = NULL; - return ECORE_CALLBACK_CANCEL; - } - - TEST_CASE(s_info.group, s_info.case_pool[s_info.current_case]); - s_info.current_case += 1; - - return ECORE_CALLBACK_RENEW; + /* 0.8 because boot-animation take 6 sec, we should not use divisor */ + TEST_CASE_CONTINUE(0.8, __continue_check_animation_layout, (void*)1); } void group_feature_on_off_animation(unit_group_t * group) { - if (s_info.group_timer) { - ecore_timer_del(s_info.group_timer); - s_info.group_timer = NULL; - } - - s_info.current_step = 0; - s_info.current_case = 0; s_info.group = group; - /* 0.8 because boot-animation take 6 sec, we should not use divisor */ - s_info.group_timer = ecore_timer_add(0.8, __group_timer_callback, NULL); + s_info.group->set_up = __set_up; + s_info.group->tear_down = __tear_down; + + TEST_CASE_ADD(s_info.group, __case_check_animation, (void*)TYPE_ON); + TEST_CASE_ADD(s_info.group, __case_check_animation, (void*)TYPE_OFF); + + TEST_GROUP_RUN(s_info.group); } #endif + diff --git a/test/function_test/function_test.c b/test/function_test/function_test.c index 26fce35..8a50f07 100755 --- a/test/function_test/function_test.c +++ b/test/function_test/function_test.c @@ -1,47 +1,36 @@ +/* + * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + #include "test.h" #if TEST_MODE #include "function_test.h" -static struct { - int current_group; - char group_name[GROUP_COUNT_MAX + 1][128]; - void(*group_starter_pool[GROUP_COUNT_MAX + 1])(unit_group_t * group); -} s_info = { - .current_group = 0, - .group_name = { - "group_function_create_animation", - "" - }, - .group_starter_pool = { - group_function_create_animation, - NULL, - }, -}; - -static void __complete_group_cb(void); -static void __run_next_group(void); - -static void __complete_group_cb(void) -{ - s_info.current_group += 1; - - __run_next_group(); -} - -static void __run_next_group(void) +static void __test_complete_cb(void) { - if (s_info.group_starter_pool[s_info.current_group]) { - TEST_GROUP(s_info.group_name[s_info.current_group], s_info.group_starter_pool[s_info.current_group], __complete_group_cb); - } } void function_test(void) { unit_clear_log(); - s_info.current_group = 0; - __run_next_group(); + TEST_GROUP_ADD("group_function_create_animation", group_function_create_animation); + + TEST_RUN(__test_complete_cb); } #endif diff --git a/test/function_test/function_test.h b/test/function_test/function_test.h index 3712da6..eeb8d57 100755 --- a/test/function_test/function_test.h +++ b/test/function_test/function_test.h @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + #ifndef __FUNCTION_TEST__ #define __FUNCTION_TEST__ diff --git a/test/function_test/group_function_animation.c b/test/function_test/group_function_animation.c index 3dde346..0c2e61b 100755 --- a/test/function_test/group_function_animation.c +++ b/test/function_test/group_function_animation.c @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + #include "test.h" #if TEST_MODE @@ -7,55 +24,59 @@ #include -#define LAYOUT "/usr/share/edje/720x1280_PowerOn.edj" -#define LAYOUT_W 720 -#define LAYOUT_H 1280 #define TYPE_POWER_ON 1 #define TYPE_POWER_OFF 2 -extern int __t__check_on_off_type(void *user_data); -static void __case_get_layout_file_name(bool * is_passed); - static struct { Evas_Object *win; Evas_Object *layout; + struct args args; + unit_group_t * group; } s_info = { .win = NULL, .layout = NULL, + .args = { 2, NULL }, + .group = NULL, }; static void __set_up(void) { + unit_clear_log(); + s_info.win = create_window(); + s_info.args.argv = (char **)malloc(4 * 2); + s_info.group->set_up_complete(s_info.group); } + static void __tear_down(void) { + unit_clear_log(); + if (s_info.layout) evas_object_del(s_info.layout); if (s_info.win) evas_object_del(s_info.win); s_info.layout = NULL; s_info.win = NULL; + free(s_info.args.argv); + s_info.args.argv = NULL; + + s_info.group->tear_down_complete(s_info.group); } -static void __case_check_on_off_type(bool * is_passed) +extern int __t__check_on_off_type(void *user_data); +static unit_case_func_t __case_check_on_off_type(void * data) { - struct args args; - args.argc = 2; - args.argv = (char **)malloc(4 * 2); - - args.argv[0] = "/usr/bin/boot-animation"; - args.argv[1] = "--start"; - TEST_ASSERT_EQUAL_INT(TYPE_POWER_ON, __t__check_on_off_type(&args)); + s_info.args.argv[0] = "/usr/bin/boot-animation"; + s_info.args.argv[1] = "--start"; + TEST_ASSERT_EQUAL_INT(TYPE_POWER_ON, __t__check_on_off_type(&s_info.args)); - args.argv[1] = "--off"; - TEST_ASSERT_EQUAL_INT(TYPE_POWER_OFF, __t__check_on_off_type(&args)); + s_info.args.argv[1] = "--off"; + TEST_ASSERT_EQUAL_INT(TYPE_POWER_OFF, __t__check_on_off_type(&s_info.args)); - free(args.argv); - - *is_passed = true; + TEST_CASE_DONE(s_info.group); } -static void __case_create_win(bool * is_passed) +static unit_case_func_t __case_create_win(void * data) { TEST_ASSERT_TRUE(s_info.win != NULL); @@ -66,10 +87,10 @@ static void __case_create_win(bool * is_passed) TEST_ASSERT_EQUAL_INT(elm_win_indicator_mode_get(s_info.win), ELM_WIN_INDICATOR_HIDE); TEST_ASSERT_TRUE(evas_object_visible_get(s_info.win)); - *is_passed = true; + TEST_CASE_DONE(s_info.group); } -static void __case_create_layout(bool * is_passed) +static unit_case_func_t __case_create_layout(void * data) { TEST_ASSERT_TRUE(s_info.win != NULL); @@ -120,10 +141,10 @@ static void __case_create_layout(bool * is_passed) TEST_ASSERT_TRUE(layout == NULL); evas_object_del(layout); - *is_passed = true; + TEST_CASE_DONE(s_info.group); } -static void __case_get_layout_file_name(bool * is_passed) +static unit_case_func_t __case_get_layout_file_name(void * data) { char * file_name = get_layout_file_name(0, 720, 1280); TEST_ASSERT_EQUAL_STRING("/usr/share/edje/720x1280_PowerOn.edj", file_name); @@ -157,10 +178,10 @@ static void __case_get_layout_file_name(bool * is_passed) TEST_ASSERT_EQUAL_STRING("/usr/share/edje/480x800_PowerOn.edj", file_name); free(file_name); - *is_passed = true; + TEST_CASE_DONE(s_info.group); } -static void __case_is_layout_file_exist(bool * is_passed) +static unit_case_func_t __case_is_layout_file_exist(void * data) { char *file_name = "/usr/share/edje/480x800_PowerOn.edj"; TEST_ASSERT_TRUE(is_layout_file_exist(file_name)); @@ -183,18 +204,23 @@ static void __case_is_layout_file_exist(bool * is_passed) file_name = "/usr/share/720x1280_PowerOn.edj"; TEST_ASSERT_TRUE(is_layout_file_exist(file_name) == EINA_FALSE); - *is_passed = true; + TEST_CASE_DONE(s_info.group); } void group_function_create_animation(unit_group_t * group) { - TEST_CASE(group, __case_check_on_off_type); - TEST_CASE(group, __case_create_win); - TEST_CASE(group, __case_get_layout_file_name); - TEST_CASE(group, __case_is_layout_file_exist); - TEST_CASE(group, __case_create_layout); + s_info.group = group; + s_info.group->set_up = __set_up; + s_info.group->tear_down = __tear_down; + + TEST_CASE_ADD(group, __case_check_on_off_type, NULL); + TEST_CASE_ADD(group, __case_create_win, NULL); + TEST_CASE_ADD(group, __case_get_layout_file_name, NULL); + TEST_CASE_ADD(group, __case_is_layout_file_exist, NULL); + TEST_CASE_ADD(group, __case_create_layout, NULL); - group->finish(group); + TEST_GROUP_RUN(s_info.group); } #endif + diff --git a/test/test_main.c b/test/test_main.c index c0d1d99..b1f4bcf 100755 --- a/test/test_main.c +++ b/test/test_main.c @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + #include "../inc/test.h" #if (TEST_MODE == TEST_APP) @@ -22,7 +39,6 @@ int main(int argc, char *argv[]) elm_run(); - unit_fini(); return 0; } diff --git a/test/unit/inc/unit.h b/test/unit/inc/unit.h index b79a9a9..b1f1a85 100755 --- a/test/unit/inc/unit.h +++ b/test/unit/inc/unit.h @@ -12,22 +12,37 @@ #include -#define GROUP_COUNT_MAX 100 -#define CASE_COUNT_MAX 100 - -#define TEST_GROUP(group_name, group_starter, group_complete_cb) unit_add_group(group_name, group_starter, group_complete_cb) -#define TEST_CASE(group, case_starter) { \ +#define TEST_GROUP_ADD(__group_name, __group_starter) unit_add_group(__group_name, __group_starter) +#define TEST_RUN(__func) unit_test_run(__func) + +#define TEST_CASE_ADD(__group, __case_starter, __data) unit_group_add_case(__group, __case_starter, __data) +#define TEST_GROUP_RUN(__group) unit_group_run(__group) +#define TEST_GROUP_SET_UP(__group, __group_set_up) { (__group)->group_set_up = __group_set_up; } +#define TEST_GROUP_TEAR_DOWN(__group, __group_tear_down) { (__group)->group_tear_down = __group_tear_down; } +#define TEST_GROUP_SET_UP_DONE(__delay_sec, __group) { unit_group_set_up_done(__delay_sec, __group); return ; } +#define TEST_GROUP_TEAR_DOWN_DONE(__delay_sec, __group) { unit_group_tear_down_done(__delay_sec, __group); return ; } + +#define TEST_CASE_CONTINUE(__sec, __next_func, __data) { ecore_timer_add(__sec, __next_func, __data); return ECORE_CALLBACK_CANCEL; } +#define TEST_CASE_DONE(__group) { unit_group_case_done(__group); return ECORE_CALLBACK_CANCEL; } +#define TEST_CASE_FAIL unit_case_fail +#define unit_case_func_t Eina_Bool + +#define TEST_CASE(__group, __case_starter) { \ bool is_passed = false; \ __set_up(); \ - case_starter(&is_passed); \ + __case_starter(&is_passed); \ __tear_down(); \ - if (is_passed) unit_result_pass((group)->result); \ - else unit_result_fail((group)->result); \ + if (is_passed) unit_result_pass((__group)->result); \ + else unit_result_fail((__group)->result); \ } void unit_init(void); void unit_fini(void); -void unit_add_group(const char * group_name, void(*group_starter)(unit_group_t * group), void(*group_complete_cb)(void)); +void unit_add_group(const char * group_name, void(*group_starter)(unit_group_t * group)); +void unit_test_run(void(*test_complete_cb)(void)); + +void unit_case_fail(void); +unit_group_t * unit_get_current_group(void); #endif diff --git a/test/unit/inc/unit_assert.h b/test/unit/inc/unit_assert.h index e841210..f2e4844 100755 --- a/test/unit/inc/unit_assert.h +++ b/test/unit/inc/unit_assert.h @@ -9,37 +9,43 @@ #define TEST_ASSERT_TRUE(value) { \ bool __ret = unit_assert_true((value), (__FUNCTION__), (__LINE__)); \ if (!__ret) { \ - return; \ + TEST_CASE_FAIL(); \ + return EINA_FALSE; \ } \ } #define TEST_ASSERT_EQUAL_INT(expected_value, input_value) { \ bool __ret = unit_assert_equal_int((expected_value), (input_value), (__FUNCTION__), (__LINE__)); \ if (!__ret) { \ - return; \ + TEST_CASE_FAIL(); \ + return EINA_FALSE; \ } \ } #define TEST_ASSERT_EQUAL_DOUBLE(expected_value, input_value) { \ bool __ret = unit_assert_equal_double((expected_value), (input_value), (__FUNCTION__), (__LINE__)); \ if (!__ret) { \ - return; \ + TEST_CASE_FAIL(); \ + return EINA_FALSE; \ } \ } #define TEST_ASSERT_EQUAL_STRING(expected_value, input_value) { \ bool __ret = unit_assert_equal_string((expected_value), (input_value), (__FUNCTION__), (__LINE__)); \ if (!__ret) { \ - return; \ + TEST_CASE_FAIL(); \ + return EINA_FALSE; \ } \ } #define TEST_ASSERT_EQUAL_OBJECT(expected_value, input_value, compare_func) { \ bool __ret = unit_assert_equal_object((expected_value), (input_value), (compare_func), (__FUNCTION__), (__LINE__)); \ if (!__ret) { \ - return; \ + TEST_CASE_FAIL(); \ + return EINA_FALSE; \ } \ } #define TEST_ASSERT_EQUAL_LOG(input_value) { \ bool __ret = unit_equal_log((input_value), (__FUNCTION__), (__LINE__)); \ if (!__ret) { \ - return; \ + TEST_CASE_FAIL(); \ + return EINA_FALSE; \ } \ } diff --git a/test/unit/inc/unit_group.h b/test/unit/inc/unit_group.h index 5703fbf..9741b47 100755 --- a/test/unit/inc/unit_group.h +++ b/test/unit/inc/unit_group.h @@ -6,18 +6,40 @@ #include "unit_result.h" +#include #include +#define TEST_CASE_MAX 100 +#define GROUP_COUNT_MAX 200 + typedef struct __unit_group_t { char * name; unit_result_t * result; + Eina_Bool(*case_starter_pool[TEST_CASE_MAX + 1])(void * data); + void *case_data_pool[TEST_CASE_MAX + 1]; + int current_case; + int case_count; void(*finish)(struct __unit_group_t * group); - void(*group_complete_cb)(void); + void(*set_up)(void); + Eina_Bool(*set_up_complete)(void * data); + void(*tear_down)(void); + Eina_Bool(*tear_down_complete)(void * data); + void(*group_set_up)(void); + void(*group_tear_down)(void); } unit_group_t; unit_group_t * unit_group_new(const char * name, void(*finish)(unit_group_t * group)); void unit_group_del(unit_group_t * group); +void unit_group_add_case(unit_group_t * group, Eina_Bool(*case_starter)(void * data), void * data); + +void unit_group_run(unit_group_t * group); +void unit_group_case_done(unit_group_t * group); +void unit_group_case_fail(unit_group_t * group); + +void unit_group_set_up_done(double delay_sec, unit_group_t * group); +void unit_group_tear_down_done(double delay_sec, unit_group_t * group); + #endif #endif diff --git a/test/unit/unit.c b/test/unit/unit.c index 83a238c..a4f248c 100755 --- a/test/unit/unit.c +++ b/test/unit/unit.c @@ -9,11 +9,24 @@ static struct { + unit_group_t * current_group; unit_result_t * result; + int current_group_idx; + int group_count; + char *group_name[GROUP_COUNT_MAX + 1]; + void(*group_starter_pool[GROUP_COUNT_MAX + 1])(unit_group_t * group); + void(*test_complete_cb)(void); } s_info = { + .current_group = NULL, .result = NULL, + .current_group_idx = 0, + .group_count = 0, + .group_name = { "", }, + .group_starter_pool = { NULL, }, + .test_complete_cb = NULL, }; +static void __run_next_group(void); static void __group_finish(unit_group_t * group); void unit_init(void) @@ -38,15 +51,52 @@ void unit_fini(void) __T("%s", s_info.result->failed ? "FAIL" : "OK"); __T("----------------------------------------------------------------------------"); + int i; + for (i = 0; i < s_info.group_count; i++) { + free(s_info.group_name[i]); + s_info.group_name[i] = NULL; + } + unit_result_del(s_info.result); s_info.result = NULL; + + s_info.current_group = NULL; +} + +void unit_add_group(const char * group_name, void(*group_starter)(unit_group_t * group)) +{ + s_info.group_name[s_info.group_count] = strdup(group_name); + s_info.group_starter_pool[s_info.group_count] = group_starter; + s_info.group_count += 1; } -void unit_add_group(const char * group_name, void(*group_starter)(unit_group_t * group), void(*group_complete_cb)(void)) +void unit_test_run(void(*test_complete_cb)(void)) { - unit_group_t * group = unit_group_new(group_name, __group_finish); - group->group_complete_cb = group_complete_cb; - group_starter(group); + s_info.test_complete_cb = test_complete_cb; + + __run_next_group(); +} + +void unit_case_fail(void) +{ + if (s_info.current_group) unit_group_case_fail(s_info.current_group); +} + +unit_group_t * unit_get_current_group(void) +{ + return s_info.current_group; +} + +static void __run_next_group(void) +{ + if (s_info.group_starter_pool[s_info.current_group_idx] == NULL) { + if (s_info.test_complete_cb) s_info.test_complete_cb(); + + return; + } + + s_info.current_group = unit_group_new(s_info.group_name[s_info.current_group_idx], __group_finish); + s_info.group_starter_pool[s_info.current_group_idx](s_info.current_group); } static void __group_finish(unit_group_t * group) @@ -56,7 +106,11 @@ static void __group_finish(unit_group_t * group) group->result->ran_case, group->result->passed, group->result->failed); unit_result_add(s_info.result, group->result); - group->group_complete_cb(); + + unit_group_del(group); + + s_info.current_group_idx += 1; + __run_next_group(); } #if (TEST_MODE == TEST_UNIT) diff --git a/test/unit/unit_assert.c b/test/unit/unit_assert.c old mode 100644 new mode 100755 index d515a4c..7747a1f --- a/test/unit/unit_assert.c +++ b/test/unit/unit_assert.c @@ -9,6 +9,8 @@ bool unit_assert_true(const int value, const char * func, const int line) { if (value == 0) { + unit_group_t * group = unit_get_current_group(); + if (group) __T("[%d of %s]", group->current_case, group->name); __T("%s (%d) FAIL", func, line); return false; } @@ -19,6 +21,8 @@ bool unit_assert_true(const int value, const char * func, const int line) bool unit_assert_equal_int(const int expected_value, const int input_value, const char * func, const int line) { if (expected_value != input_value) { + unit_group_t * group = unit_get_current_group(); + if (group) __T("[%d of %s]", group->current_case, group->name); __T("%s (%d) FAIL, Expected %d was %d", func, line, expected_value, input_value); return false; } @@ -29,6 +33,8 @@ bool unit_assert_equal_int(const int expected_value, const int input_value, cons bool unit_assert_equal_double(const double expected_value, const double input_value, const char * func, const int line) { if (fabs(expected_value - input_value) >= 1e-10) { + unit_group_t * group = unit_get_current_group(); + if (group) __T("[%d of %s]", group->current_case, group->name); __T("%s (%d) FAIL, Expected %.10lf was %.10lf", func, line, expected_value, input_value); return false; } @@ -39,6 +45,8 @@ bool unit_assert_equal_double(const double expected_value, const double input_va bool unit_assert_equal_string(const char * expected_value, const char * input_value, const char * func, const int line) { if (strcmp(expected_value, input_value)) { + unit_group_t * group = unit_get_current_group(); + if (group) __T("[%d of %s]", group->current_case, group->name); __T("%s (%d) FAIL, Expected %s was %s", func, line, expected_value, input_value); return false; } @@ -51,6 +59,8 @@ bool unit_assert_equal_object(const void * expected_value, const void * input_va const char * func, const int line) { if (!compare_func(expected_value, input_value)) { + unit_group_t * group = unit_get_current_group(); + if (group) __T("[%d of %s]", group->current_case, group->name); __T("%s (%d) FAIL, Objects are not equal", func, line); return false; } diff --git a/test/unit/unit_group.c b/test/unit/unit_group.c index 6f6ef5f..1053009 100755 --- a/test/unit/unit_group.c +++ b/test/unit/unit_group.c @@ -6,13 +6,29 @@ #include #include +static void __run_next_case(unit_group_t * group); +static Eina_Bool __case_set_up_complete(void * data); +static Eina_Bool __case_tear_down_complete(void * data); +static Eina_Bool __group_set_up_done(void * data); +static Eina_Bool __group_tear_down_done(void * data); + + unit_group_t * unit_group_new(const char * name, void(*finish)(unit_group_t * group)) { unit_group_t * group = (unit_group_t *)malloc(sizeof(unit_group_t)); group->name = strdup(name); group->result = unit_result_new(); group->finish = finish; - group->group_complete_cb = NULL; + group->set_up = NULL; + group->set_up_complete = __case_set_up_complete; + group->tear_down = NULL; + group->tear_down_complete = __case_tear_down_complete; + group->current_case = 0; + group->case_count = 0; + group->case_starter_pool[0] = NULL; + group->case_data_pool[0] = NULL; + group->group_set_up = NULL; + group->group_tear_down = NULL; return group; } @@ -26,4 +42,94 @@ void unit_group_del(unit_group_t * group) free(group); } +void unit_group_add_case(unit_group_t * group, Eina_Bool(*case_starter)(void * data), void * data) +{ + group->case_starter_pool[group->case_count] = case_starter; + group->case_data_pool[group->case_count] = data; + group->case_count += 1; + + group->case_starter_pool[group->case_count] = NULL; + group->case_data_pool[group->case_count] = NULL; +} + +void unit_group_run(unit_group_t * group) +{ + group->group_set_up ? group->group_set_up() : __group_set_up_done(group); +} + +void unit_group_case_fail(unit_group_t * group) +{ + unit_result_fail((group)->result); + + group->tear_down(); +} + +void unit_group_case_done(unit_group_t * group) +{ + unit_result_pass((group)->result); + + group->tear_down(); +} + +void unit_group_set_up_done(double delay_sec, unit_group_t * group) +{ + if (delay_sec == 0.0) + __group_set_up_done(group); + else + ecore_timer_add(delay_sec, __group_set_up_done, group); +} + +void unit_group_tear_down_done(double delay_sec, unit_group_t * group) +{ + if (delay_sec == 0.0) + __group_tear_down_done(group); + else + ecore_timer_add(delay_sec, __group_tear_down_done, group); +} + +static void __run_next_case(unit_group_t * group) +{ + if (group->case_starter_pool[group->current_case] == NULL) { + group->group_tear_down ? group->group_tear_down() : __group_tear_down_done(group); + + return; + } + + group->set_up(); +} + +static Eina_Bool __case_set_up_complete(void * data) +{ + unit_group_t * group = (unit_group_t *)data; + + group->case_starter_pool[group->current_case](group->case_data_pool[group->current_case]); + + return ECORE_CALLBACK_CANCEL; +} + +static Eina_Bool __case_tear_down_complete(void * data) +{ + unit_group_t * group = (unit_group_t *)data; + + group->current_case += 1; + __run_next_case(group); + + return ECORE_CALLBACK_CANCEL; +} + +static Eina_Bool __group_set_up_done(void * data) +{ + __run_next_case((unit_group_t *)data); + + return ECORE_CALLBACK_CANCEL; +} + +static Eina_Bool __group_tear_down_done(void * data) +{ + unit_group_t * group = (unit_group_t *)data; + group->finish(group); + + return ECORE_CALLBACK_CANCEL; +} + #endif diff --git a/test/unit/unit_log_buf.c b/test/unit/unit_log_buf.c index 8138f88..a6a34cf 100755 --- a/test/unit/unit_log_buf.c +++ b/test/unit/unit_log_buf.c @@ -41,6 +41,8 @@ void unit_clear_log(void) bool unit_equal_log(const char * input_value, const char * func, const int line) { if (strcmp(s_info.log_buf, input_value)) { + unit_group_t * group = unit_get_current_group(); + if (group) __T("[%d of %s]", group->current_case, group->name); __T("%s (%d) FAIL, Expected %s was %s", func, line, input_value, s_info.log_buf); return false; } diff --git a/test/unit/unit_test/inc/unit_test_common.h b/test/unit/unit_test/inc/unit_test_common.h deleted file mode 100755 index 9bd86ea..0000000 --- a/test/unit/unit_test/inc/unit_test_common.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __TEST_TEST_RUN_H__ -#define __TEST_TEST_RUN_H__ - -#include "../../../../inc/test.h" -#if (TEST_MODE == TEST_UNIT) -#include "../../../../inc/app_log.h" -#include "../../inc/unit.h" - -#include -#include - -#define __unit_test_run(before, after, func, fail_log) { \ - s_info.log = (before); \ - (func)(); \ - if (s_info.log != (after)) { \ - __TU(fail_log); \ - return ; \ - } \ - } - -#endif - -#endif diff --git a/test/unit/unit_test/unit_test_append_log/unit_test_append_log.h b/test/unit/unit_test/unit_test_append_log/unit_test_append_log.h index aefcad4..2ee1bf8 100755 --- a/test/unit/unit_test/unit_test_append_log/unit_test_append_log.h +++ b/test/unit/unit_test/unit_test_append_log/unit_test_append_log.h @@ -3,7 +3,11 @@ #include "../../../../inc/test.h" #if (TEST_MODE == TEST_UNIT) -#include "../inc/unit_test_common.h" +#include "../../../../inc/app_log.h" +#include "../../inc/unit.h" + +#include +#include void unit_test_log_append_unit_init(char * buf); void unit_test_log_append_unit_fini(char * buf, unit_result_t * result); diff --git a/test/unit/unit_test/unit_test_assert_test/unit_test_assert.c b/test/unit/unit_test/unit_test_assert_test/unit_test_assert.c index 2d8b0c7..cf5b35b 100755 --- a/test/unit/unit_test/unit_test_assert_test/unit_test_assert.c +++ b/test/unit/unit_test/unit_test_assert_test/unit_test_assert.c @@ -3,16 +3,11 @@ #include "unit_test_assert.h" +#include #include #include #include -static struct __assert_s { - int log; -} s_info = { - .log = 0, -}; - typedef struct __object_t { int a; double b; @@ -23,85 +18,90 @@ typedef struct __object_t { extern char * __t__get_unit_log_buf(void); -static void __unit_test_assert_bool_ok(void); -static void __unit_test_assert_bool_fail(void); -static void __unit_test_assert_int_ok(void); -static void __unit_test_assert_int_fail(void); -static void __unit_test_assert_double_ok(void); -static void __unit_test_assert_double_fail(void); -static void __unit_test_assert_string_ok(void); -static void __unit_test_assert_string_fail(void); -static void __unit_test_assert_object_ok(void); -static void __unit_test_assert_object_fail(void); -static void __unit_test_assert_log_ok(void); -static void __unit_test_assert_log_fail(void); +static Eina_Bool __unit_test_assert_bool_ok(void); +static Eina_Bool __unit_test_assert_bool_fail(void); +static Eina_Bool __unit_test_assert_int_ok(void); +static Eina_Bool __unit_test_assert_int_fail(void); +static Eina_Bool __unit_test_assert_double_ok(void); +static Eina_Bool __unit_test_assert_double_fail(void); +static Eina_Bool __unit_test_assert_string_ok(void); +static Eina_Bool __unit_test_assert_string_fail(void); +static Eina_Bool __unit_test_assert_object_ok(void); +static Eina_Bool __unit_test_assert_object_fail(void); +static Eina_Bool __unit_test_assert_log_ok(void); +static Eina_Bool __unit_test_assert_log_fail(void); static bool __object_equal(const void * object1, const void * object2); void unit_test_assert(void) { - __unit_test_run_assert(0, 1, __unit_test_assert_int_ok); - __unit_test_run_assert(987654321, 987654321, __unit_test_assert_int_fail); - __unit_test_run_assert(0, 1, __unit_test_assert_bool_ok); - __unit_test_run_assert(987654321, 987654321, __unit_test_assert_bool_fail); - __unit_test_run_assert(0, 1, __unit_test_assert_double_ok); - __unit_test_run_assert(987654321, 987654321, __unit_test_assert_double_fail); - __unit_test_run_assert(0, 1, __unit_test_assert_string_ok); - __unit_test_run_assert(987654321, 987654321, __unit_test_assert_string_fail); - __unit_test_run_assert(0, 1, __unit_test_assert_object_ok); - __unit_test_run_assert(987654321, 987654321, __unit_test_assert_object_fail); - __unit_test_run_assert(0, 1, __unit_test_assert_log_ok); - __unit_test_run_assert(987654321, 987654321, __unit_test_assert_log_fail); + __unit_test_run_assert(__unit_test_assert_int_ok() == EINA_TRUE); + __unit_test_run_assert(__unit_test_assert_int_fail() == EINA_FALSE); + __unit_test_run_assert(__unit_test_assert_bool_ok() == EINA_TRUE); + __unit_test_run_assert(__unit_test_assert_bool_fail() == EINA_FALSE); + __unit_test_run_assert(__unit_test_assert_double_ok() == EINA_TRUE); + __unit_test_run_assert(__unit_test_assert_double_fail() == EINA_FALSE); + __unit_test_run_assert(__unit_test_assert_string_ok() == EINA_TRUE); + __unit_test_run_assert(__unit_test_assert_string_fail() == EINA_FALSE); + __unit_test_run_assert(__unit_test_assert_object_ok() == EINA_TRUE); + __unit_test_run_assert(__unit_test_assert_object_fail() == EINA_FALSE); + __unit_test_run_assert(__unit_test_assert_log_ok() == EINA_TRUE); + __unit_test_run_assert(__unit_test_assert_log_fail() == EINA_FALSE); } -static void __unit_test_assert_bool_ok(void) +static Eina_Bool __unit_test_assert_bool_ok(void) { TEST_ASSERT_TRUE(1); TEST_ASSERT_TRUE(-1); TEST_ASSERT_TRUE(987654321); - s_info.log = 1; + + return EINA_TRUE; } -static void __unit_test_assert_bool_fail(void) +static Eina_Bool __unit_test_assert_bool_fail(void) { TEST_ASSERT_TRUE(0); - s_info.log = 0; + + return EINA_TRUE; } -static void __unit_test_assert_int_ok(void) +static Eina_Bool __unit_test_assert_int_ok(void) { TEST_ASSERT_EQUAL_INT(1, 1); TEST_ASSERT_EQUAL_INT(-1, -1); TEST_ASSERT_EQUAL_INT(987654321, 987654321); - s_info.log = 1; + + return EINA_TRUE; } -static void __unit_test_assert_int_fail(void) +static Eina_Bool __unit_test_assert_int_fail(void) { TEST_ASSERT_EQUAL_INT(100, 100); TEST_ASSERT_EQUAL_INT(1, 2); - s_info.log = 0; TEST_ASSERT_EQUAL_INT(-1, -1); - s_info.log = 1; + + return EINA_TRUE; } -static void __unit_test_assert_double_ok(void) +static Eina_Bool __unit_test_assert_double_ok(void) { TEST_ASSERT_EQUAL_DOUBLE(1.0, 1.0); TEST_ASSERT_EQUAL_DOUBLE(0.1, 0.1); TEST_ASSERT_EQUAL_DOUBLE(0.000001, 0.000001); TEST_ASSERT_EQUAL_DOUBLE(0.00000000001, 0.00000000002); - s_info.log = 1; + + return EINA_TRUE; } -static void __unit_test_assert_double_fail(void) +static Eina_Bool __unit_test_assert_double_fail(void) { TEST_ASSERT_EQUAL_DOUBLE(0.00000000001, 0.00000000002); TEST_ASSERT_EQUAL_DOUBLE(0.0000000001, 0.0000000002); - s_info.log = 1; + + return EINA_TRUE; } -static void __unit_test_assert_string_ok(void) +static Eina_Bool __unit_test_assert_string_ok(void) { TEST_ASSERT_EQUAL_STRING("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); TEST_ASSERT_EQUAL_STRING("abcdefg", "abcdefg"); @@ -112,20 +112,22 @@ static void __unit_test_assert_string_ok(void) char str3[] = "abcdefghijklmnopqrstuvwxyz"; char str4[] = "aabcdefghijklmnopqrstuvwxyz"; TEST_ASSERT_EQUAL_STRING(str3, str4+1); - s_info.log = 1; + + return EINA_TRUE; } -static void __unit_test_assert_string_fail(void) +static Eina_Bool __unit_test_assert_string_fail(void) { TEST_ASSERT_EQUAL_STRING("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); char str1[] = "abcdefghijklmnopqrstuvwxyz"; char str2[] = "abcdefghijklmnopqrstuvwxyz"; TEST_ASSERT_EQUAL_STRING(str1, str2 + 1); - s_info.log = 1; + + return EINA_TRUE; } -static void __unit_test_assert_object_ok(void) +static Eina_Bool __unit_test_assert_object_ok(void) { object_t a = { 0, 0, 0, 0, 0 }; object_t b = { 0, 0, 0, 0, 0 }; @@ -157,10 +159,11 @@ static void __unit_test_assert_object_ok(void) free(p_a); free(p_b); - s_info.log = 1; + + return EINA_TRUE; } -static void __unit_test_assert_object_fail(void) +static Eina_Bool __unit_test_assert_object_fail(void) { object_t a = { 0, 0, 0, 0, 0 }; object_t b = { 0, 0, 0, 0, 0 }; @@ -175,10 +178,10 @@ static void __unit_test_assert_object_fail(void) b.func_a = __unit_test_assert_object_ok; TEST_ASSERT_EQUAL_OBJECT(&a, &b, __object_equal); - s_info.log = 1; + return EINA_TRUE; } -static void __unit_test_assert_log_ok(void) +static Eina_Bool __unit_test_assert_log_ok(void) { char * buf = __t__get_unit_log_buf(); strcpy(buf, ""); @@ -191,10 +194,10 @@ static void __unit_test_assert_log_ok(void) __T("%d %.2lf ok", 99, 0.01); TEST_ASSERT_EQUAL_LOG("assert\nlog\n99 0.01 ok\n"); - s_info.log = 1; + return EINA_TRUE; } -static void __unit_test_assert_log_fail(void) +static Eina_Bool __unit_test_assert_log_fail(void) { char * buf = __t__get_unit_log_buf(); strcpy(buf, ""); @@ -203,9 +206,9 @@ static void __unit_test_assert_log_fail(void) __T("assert"); __T("%s", "log"); __T("%d %.2lf ok", 99, 0.01); - TEST_ASSERT_EQUAL_LOG("assert\nlog\n99 0.01 ok"); + TEST_ASSERT_EQUAL_LOG("assert\nlog\n99 0.01 no\n"); - s_info.log = 1; + return EINA_TRUE; } static bool __object_equal(const void * object1, const void * object2) diff --git a/test/unit/unit_test/unit_test_assert_test/unit_test_assert.h b/test/unit/unit_test/unit_test_assert_test/unit_test_assert.h index 1031a34..90d6ae7 100755 --- a/test/unit/unit_test/unit_test_assert_test/unit_test_assert.h +++ b/test/unit/unit_test/unit_test_assert_test/unit_test_assert.h @@ -3,9 +3,13 @@ #include "../../../../inc/test.h" #if (TEST_MODE == TEST_UNIT) -#include "../inc/unit_test_common.h" +#include "../../../../inc/app_log.h" +#include "../../inc/unit.h" -#define __unit_test_run_assert(before, after, func) __unit_test_run(before, after, func, "!!!!!ASSERT MACRO TEST FAIL!!!!!") +#include +#include + +#define __unit_test_run_assert(result) { if ((result) == false) __TU("!!!!!ASSERT MACRO TEST FAIL!!!!!"); } void unit_test_assert(void); diff --git a/test/unit/unit_test/unit_test_function_test/unit_test_function.h b/test/unit/unit_test/unit_test_function_test/unit_test_function.h index 889cf67..2566981 100755 --- a/test/unit/unit_test/unit_test_function_test/unit_test_function.h +++ b/test/unit/unit_test/unit_test_function_test/unit_test_function.h @@ -3,9 +3,13 @@ #include "../../../../inc/test.h" #if (TEST_MODE == TEST_UNIT) +#include "../../../../inc/app_log.h" +#include "../../inc/unit.h" -#include "../inc/unit_test_common.h" -#define __unit_test_run_function(before, after, func) __unit_test_run(before, after, func, "##########FUNCTION TEST FAIL##########") +#include +#include + +#define __unit_test_run_function(result) { if ((result) == false) __TU("##########FUNCTION TEST FAIL##########"); } void unit_test_function(void); void unit_test_unit_function(void); diff --git a/test/unit/unit_test/unit_test_function_test/unit_test_group_function.c b/test/unit/unit_test/unit_test_function_test/unit_test_group_function.c index 3601753..d6abead 100755 --- a/test/unit/unit_test/unit_test_function_test/unit_test_group_function.c +++ b/test/unit/unit_test/unit_test_function_test/unit_test_group_function.c @@ -3,22 +3,16 @@ #include "unit_test_function.h" -static struct { - int log; -} s_info = { - .log = 0, -}; - -static void __unit_test_group_new(void); +static Eina_Bool __unit_test_group_new(void); void unit_test_group_function(void) { - __unit_test_run_function(0, 1, __unit_test_group_new); + __unit_test_run_function(__unit_test_group_new() == EINA_TRUE); } static void __group_finish(unit_group_t * group) {} -static void __unit_test_group_new(void) +static Eina_Bool __unit_test_group_new(void) { unit_group_t * group = unit_group_new("group_1", __group_finish); TEST_ASSERT_TRUE(group != NULL); @@ -27,11 +21,10 @@ static void __unit_test_group_new(void) TEST_ASSERT_EQUAL_INT(0, group->result->passed); TEST_ASSERT_EQUAL_INT(0, group->result->failed); TEST_ASSERT_TRUE(group->finish != NULL) - TEST_ASSERT_TRUE(group->group_complete_cb == NULL) unit_group_del(group); - s_info.log = 1; + return EINA_TRUE; } #endif diff --git a/test/unit/unit_test/unit_test_function_test/unit_test_log_buf_function.c b/test/unit/unit_test/unit_test_function_test/unit_test_log_buf_function.c index 5c43231..3cceaca 100755 --- a/test/unit/unit_test/unit_test_function_test/unit_test_log_buf_function.c +++ b/test/unit/unit_test/unit_test_function_test/unit_test_log_buf_function.c @@ -5,22 +5,16 @@ extern char * __t__get_unit_log_buf(void); -static struct { - int log; -} s_info = { - .log = 0, -}; - -static void __unit_test_write_log(void); -static void __unit_test_clear_log(void); +static Eina_Bool __unit_test_write_log(void); +static Eina_Bool __unit_test_clear_log(void); void unit_test_log_buf_function(void) { - __unit_test_run_function(0, 1, __unit_test_write_log); - __unit_test_run_function(0, 1, __unit_test_clear_log); + __unit_test_run_function( __unit_test_write_log() == EINA_TRUE); + __unit_test_run_function(__unit_test_clear_log() == EINA_TRUE); } -static void __unit_test_write_log(void) +static Eina_Bool __unit_test_write_log(void) { char * buf = __t__get_unit_log_buf(); strcpy(buf, ""); @@ -31,10 +25,10 @@ static void __unit_test_write_log(void) TEST_ASSERT_EQUAL_STRING(buf, "write\nlog\n"); - s_info.log = 1; + return EINA_TRUE; } -static void __unit_test_clear_log(void) +static Eina_Bool __unit_test_clear_log(void) { char * buf = __t__get_unit_log_buf(); strcpy(buf, "clear"); @@ -44,7 +38,7 @@ static void __unit_test_clear_log(void) TEST_ASSERT_EQUAL_STRING(buf, ""); - s_info.log = 1; + return EINA_TRUE; } #endif diff --git a/test/unit/unit_test/unit_test_function_test/unit_test_unit_function.c b/test/unit/unit_test/unit_test_function_test/unit_test_unit_function.c index 3c635fd..a44ead2 100755 --- a/test/unit/unit_test/unit_test_function_test/unit_test_unit_function.c +++ b/test/unit/unit_test/unit_test_function_test/unit_test_unit_function.c @@ -6,24 +6,18 @@ extern unit_result_t * __t__get_unit_result(void); -static struct { - int log; -} s_info = { - .log = 0, -}; - -static void __unit_test_uint_result(void); -static void __unit_test_unit_init(void); -static void __unit_test_unit_fini(void); +static Eina_Bool __unit_test_uint_result(void); +static Eina_Bool __unit_test_unit_init(void); +static Eina_Bool __unit_test_unit_fini(void); void unit_test_unit_function(void) { - __unit_test_run_function(0, 1, __unit_test_uint_result); - __unit_test_run_function(0, 1, __unit_test_unit_init); - __unit_test_run_function(0, 1, __unit_test_unit_fini); + __unit_test_run_function(__unit_test_uint_result() == EINA_TRUE); + __unit_test_run_function(__unit_test_unit_init() == EINA_TRUE); + __unit_test_run_function(__unit_test_unit_fini() == EINA_TRUE); } -static void __unit_test_uint_result(void) +static Eina_Bool __unit_test_uint_result(void) { unit_result_t * result = unit_result_new(); @@ -66,10 +60,10 @@ static void __unit_test_uint_result(void) unit_result_del(result2); unit_result_del(result); - s_info.log = 1; + return EINA_TRUE; } -static void __unit_test_unit_init(void) +static Eina_Bool __unit_test_unit_init(void) { unit_clear_log(); @@ -93,10 +87,10 @@ static void __unit_test_unit_init(void) unit_test_log_append_unit_init(buf); TEST_ASSERT_EQUAL_LOG(buf); - s_info.log = 1; + return EINA_TRUE; } -static void __unit_test_unit_fini(void) +static Eina_Bool __unit_test_unit_fini(void) { unit_init(); unit_clear_log(); @@ -128,7 +122,7 @@ static void __unit_test_unit_fini(void) TEST_ASSERT_EQUAL_LOG(buf); - s_info.log = 1; + return EINA_TRUE; } #endif diff --git a/test/unit/unit_test/unit_test_group_test/unit_test_group.c b/test/unit/unit_test/unit_test_group_test/unit_test_group.c index 186a7d5..04c3229 100755 --- a/test/unit/unit_test/unit_test_group_test/unit_test_group.c +++ b/test/unit/unit_test/unit_test_group_test/unit_test_group.c @@ -5,80 +5,20 @@ #include -static struct { - int log; - int current_group; - char group_name[3][128]; - void(*group_starter_pool[3])(unit_group_t * group); -} s_info = { - .log = 0, - .current_group = 0, - .group_name = { - "unit_test_group_pass", - "unit_test_group_fail", - "", - }, - .group_starter_pool = { - unit_test_group_pass, - unit_test_group_fail, - NULL, - }, -}; - -extern unit_result_t * __t__get_unit_result(void); - -static void __unit_test_pass_group(void); -static void __unit_test_fail_group(void); -static void __run_next_group(void); -static void __complete_group_cb(void); - -void unit_test_group(void) +static void __complete_cb(void) { - s_info.current_group = 0; - __run_next_group(); + ui_app_exit(); } -static void __run_next_group(void) +void unit_test_group(void) { - if (s_info.current_group >= 2) { - return ; - } - unit_init(); - TEST_GROUP(s_info.group_name[s_info.current_group], s_info.group_starter_pool[s_info.current_group], __complete_group_cb); -} - -static void __complete_group_cb(void) -{ - if (s_info.current_group == 0) { - __unit_test_run_group(0, 1, __unit_test_pass_group); - } else if (s_info.current_group == 1) { - __unit_test_run_group(0, 1, __unit_test_fail_group); - } + unit_clear_log(); - s_info.current_group += 1; - - __run_next_group(); -} - -static void __unit_test_pass_group(void) -{ - unit_result_t * result = __t__get_unit_result(); - TEST_ASSERT_EQUAL_INT(3, result->passed); - TEST_ASSERT_EQUAL_INT(0, result->failed); - TEST_ASSERT_EQUAL_INT(3, result->ran_case); - - s_info.log = 1; -} - -static void __unit_test_fail_group(void) -{ - unit_result_t * result = __t__get_unit_result(); - TEST_ASSERT_EQUAL_INT(2, result->passed); - TEST_ASSERT_EQUAL_INT(1, result->failed); - TEST_ASSERT_EQUAL_INT(3, result->ran_case); + TEST_GROUP_ADD("unit_test_group_pass", unit_test_group_pass); + TEST_GROUP_ADD("unit_test_group_fail", unit_test_group_fail); - s_info.log = 1; + TEST_RUN(__complete_cb); } #endif diff --git a/test/unit/unit_test/unit_test_group_test/unit_test_group.h b/test/unit/unit_test/unit_test_group_test/unit_test_group.h index 7c23c3f..3fc4c82 100755 --- a/test/unit/unit_test/unit_test_group_test/unit_test_group.h +++ b/test/unit/unit_test/unit_test_group_test/unit_test_group.h @@ -3,9 +3,12 @@ #include "../../../../inc/test.h" #if (TEST_MODE == TEST_UNIT) +#define __unit_test_run_group(result) { if ((result) == false) __TU("!!!!!GROUP TEST FAIL!!!!!"); } +#include "../../../../inc/app_log.h" +#include "../../inc/unit.h" -#include "../inc/unit_test_common.h" -#define __unit_test_run_group(before, after, func) __unit_test_run(before, after, func, "!!!!!GROUP TEST FAIL!!!!!") +#include +#include void unit_test_group(void); void unit_test_group_pass(unit_group_t * group); diff --git a/test/unit/unit_test/unit_test_group_test/unit_test_group_result.c b/test/unit/unit_test/unit_test_group_test/unit_test_group_result.c index 8c0bffc..25a046a 100755 --- a/test/unit/unit_test/unit_test_group_test/unit_test_group_result.c +++ b/test/unit/unit_test/unit_test_group_test/unit_test_group_result.c @@ -4,77 +4,126 @@ #include "unit_test_group.h" static struct { - int log; + unit_group_t * group; } s_info = { - .log = 0, + .group = NULL, }; static void __set_up(void) { - s_info.log = 99; + __T("case __set_up"); + + s_info.group->set_up_complete(s_info.group); } static void __tear_down(void) { - TEST_ASSERT_EQUAL_INT(88, s_info.log); + __T("case __tear_down"); - s_info.log = 66; + s_info.group->tear_down_complete(s_info.group); } -static void __pass_case(bool * is_passed) +static unit_case_func_t __pass_case(void * data) { - TEST_ASSERT_EQUAL_INT(99, s_info.log); - s_info.log = 88; + TEST_ASSERT_EQUAL_INT(99, 99); + TEST_ASSERT_TRUE(true); + + __T("pass case : %d", (int)data); + + TEST_CASE_DONE(s_info.group); +} +static unit_case_func_t __continue_pass(void * data); +static unit_case_func_t __pass_continue_case(void * data) +{ + TEST_ASSERT_EQUAL_INT(99, 99); TEST_ASSERT_TRUE(true); - *is_passed = true; + __T("pass continue case : %d", (int)data); + + TEST_CASE_CONTINUE(0.1, __continue_pass, data); } -static void __fail_case(bool * is_passed) +static unit_case_func_t __continue_pass(void * data) { - TEST_ASSERT_EQUAL_INT(99, s_info.log); - s_info.log = 88; + TEST_ASSERT_EQUAL_INT(99, 99); + TEST_ASSERT_TRUE(true); + + __T("continue : %d", (int)data); + TEST_CASE_DONE(s_info.group); +} + +void unit_test_group_pass(unit_group_t * group) +{ + s_info.group = group; + s_info.group->set_up = __set_up; + s_info.group->tear_down = __tear_down; + + TEST_CASE_ADD(s_info.group, __pass_case, (void *)1); + TEST_CASE_ADD(s_info.group, __pass_case, (void *)2); + TEST_CASE_ADD(s_info.group, __pass_continue_case, (void *)3); + + TEST_GROUP_RUN(s_info.group); +} + +static void __group_set_up(void *data) +{ + __T("__group_set_up"); + TEST_GROUP_SET_UP_DONE(0.1, s_info.group); +} + +static void __group_tear_down(void *data) +{ + __T("__group_tear_down"); + TEST_GROUP_TEAR_DOWN_DONE(0.1, s_info.group); +} + +static unit_case_func_t __fail_case(void * data) +{ + TEST_ASSERT_EQUAL_INT(99, 99); + __T("fail case : %d", (int)data); TEST_ASSERT_TRUE(false); - *is_passed = true; + __T("fail case done"); + + TEST_CASE_DONE(s_info.group); } -void unit_test_group_pass(unit_group_t * group) +static unit_case_func_t __continue_fail(void * data); +static unit_case_func_t __fail_continue_case(void * data) +{ + TEST_ASSERT_EQUAL_INT(99, 99); + __T("fail continue case : %d", (int)data); + + TEST_CASE_CONTINUE(0.1, __continue_fail, data); +} + +static unit_case_func_t __continue_fail(void * data) { - s_info.log = 0; - TEST_ASSERT_TRUE(group != NULL); - TEST_ASSERT_EQUAL_INT(0, group->result->ran_case); - TEST_ASSERT_EQUAL_INT(0, group->result->passed); - TEST_ASSERT_EQUAL_INT(0, group->result->failed); - - TEST_CASE(group, __pass_case); - TEST_ASSERT_EQUAL_INT(66, s_info.log); - TEST_CASE(group, __pass_case); - TEST_ASSERT_EQUAL_INT(66, s_info.log); - TEST_CASE(group, __pass_case); - TEST_ASSERT_EQUAL_INT(66, s_info.log); - - group->finish(group); + TEST_ASSERT_EQUAL_INT(99, 99); + + __T("continue : %d", (int)data); + + TEST_ASSERT_TRUE(false); + + __T("continue done"); + + TEST_CASE_DONE(s_info.group); } void unit_test_group_fail(unit_group_t * group) { - s_info.log = 0; - TEST_ASSERT_TRUE(group != NULL); - TEST_ASSERT_EQUAL_INT(0, group->result->ran_case); - TEST_ASSERT_EQUAL_INT(0, group->result->passed); - TEST_ASSERT_EQUAL_INT(0, group->result->failed); - - TEST_CASE(group, __pass_case); - TEST_ASSERT_EQUAL_INT(66, s_info.log); - TEST_CASE(group, __pass_case); - TEST_ASSERT_EQUAL_INT(66, s_info.log); - TEST_CASE(group, __fail_case); - TEST_ASSERT_EQUAL_INT(66, s_info.log); - - group->finish(group); + s_info.group = group; + s_info.group->set_up = __set_up; + s_info.group->tear_down = __tear_down; + + TEST_GROUP_SET_UP(s_info.group, __group_set_up); + TEST_GROUP_TEAR_DOWN(s_info.group, __group_tear_down); + TEST_CASE_ADD(s_info.group, __fail_case, (void *)1); + TEST_CASE_ADD(s_info.group, __fail_continue_case, (void *)2); + + TEST_GROUP_RUN(s_info.group); } #endif diff --git a/test/unit/unit_test/unit_test_main.c b/test/unit/unit_test/unit_test_main.c index fb51f03..46b1d58 100755 --- a/test/unit/unit_test/unit_test_main.c +++ b/test/unit/unit_test/unit_test_main.c @@ -6,7 +6,6 @@ #include "unit_test_function_test/unit_test_function.h" #include "unit_test_group_test/unit_test_group.h" -#include #include static bool __create(void * data) @@ -15,7 +14,7 @@ static bool __create(void * data) unit_test_function(); unit_test_group(); - return false; + return true; } static void __app_control(app_control_h app_control_handle, void * data) -- 2.7.4