+/*
+ * 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 <Elementary.h>
-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
+/*
+ * 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__
+/*
+ * 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 <Elementary.h>
#include <vconf.h>
-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)
} 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;
}
}
-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;
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
+
+/*
+ * 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
+/*
+ * 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__
+/*
+ * 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 <Elementary.h>
-#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);
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);
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);
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));
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
+
+/*
+ * 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)
elm_run();
- unit_fini();
return 0;
}
#include <app.h>
-#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
#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; \
} \
}
#include "unit_result.h"
+#include <Elementary.h>
#include <app.h>
+#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
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)
__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)
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)
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;
}
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;
}
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;
}
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;
}
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;
}
#include <string.h>
#include <stdlib.h>
+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;
}
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
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;
}
+++ /dev/null
-#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 <app.h>
-#include <string.h>
-
-#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
#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 <app.h>
+#include <string.h>
void unit_test_log_append_unit_init(char * buf);
void unit_test_log_append_unit_fini(char * buf, unit_result_t * result);
#include "unit_test_assert.h"
+#include <app.h>
#include <math.h>
#include <stdlib.h>
#include <memory.h>
-static struct __assert_s {
- int log;
-} s_info = {
- .log = 0,
-};
-
typedef struct __object_t {
int a;
double b;
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");
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 };
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 };
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, "");
__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, "");
__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)
#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 <app.h>
+#include <string.h>
+
+#define __unit_test_run_assert(result) { if ((result) == false) __TU("!!!!!ASSERT MACRO TEST FAIL!!!!!"); }
void unit_test_assert(void);
#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 <app.h>
+#include <string.h>
+
+#define __unit_test_run_function(result) { if ((result) == false) __TU("##########FUNCTION TEST FAIL##########"); }
void unit_test_function(void);
void unit_test_unit_function(void);
#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);
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
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, "");
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");
TEST_ASSERT_EQUAL_STRING(buf, "");
- s_info.log = 1;
+ return EINA_TRUE;
}
#endif
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();
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();
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();
TEST_ASSERT_EQUAL_LOG(buf);
- s_info.log = 1;
+ return EINA_TRUE;
}
#endif
#include <efl_extension.h>
-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
#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 <app.h>
+#include <string.h>
void unit_test_group(void);
void unit_test_group_pass(unit_group_t * group);
#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
#include "unit_test_function_test/unit_test_function.h"
#include "unit_test_group_test/unit_test_group.h"
-#include <app.h>
#include <Elementary.h>
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)