summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjin0.kim <jin0.kim@samsung.com>2017-05-16 19:56:40 +0830
committerjin0.kim <jin0.kim@samsung.com>2017-05-16 19:56:40 +0830
commit0b24d24733290fdddaa2add64ab1da1847655509 (patch)
tree50a45580f12ecd0a92e3bd9377d020ad48cced82
parent4bd0ac355ccc01a12ca52ee48c7bafcd8abb0e78 (diff)
downloadw3-home-0b24d24733290fdddaa2add64ab1da1847655509.tar.gz
w3-home-0b24d24733290fdddaa2add64ab1da1847655509.tar.bz2
w3-home-0b24d24733290fdddaa2add64ab1da1847655509.zip
upgrade test_case
Change-Id: Ic3514557ab6ae6ce6aed55330218c14153b9d90b
-rwxr-xr-xinc/common_conf.h5
-rwxr-xr-xtest/feature_test/group_feature_moments_show.c201
-rwxr-xr-xtest/unit/inc/unit.h11
-rwxr-xr-xtest/unit/inc/unit_assert.h14
-rwxr-xr-xtest/unit/inc/unit_group.h18
-rwxr-xr-xtest/unit/unit.c28
-rwxr-xr-x[-rw-r--r--]test/unit/unit_assert.c10
-rwxr-xr-xtest/unit/unit_group.c72
-rwxr-xr-xtest/unit/unit_test/unit_test_function_test/unit_test_group_function.c1
9 files changed, 214 insertions, 146 deletions
diff --git a/inc/common_conf.h b/inc/common_conf.h
index 147fb8e..d268d8c 100755
--- a/inc/common_conf.h
+++ b/inc/common_conf.h
@@ -19,6 +19,11 @@
#include <app.h>
+typedef struct __position_t {
+ int x;
+ int y;
+} position_t;
+
extern double _get_resolution_scale_h();
extern double _get_resolution_scale_w();
extern int _get_window_h();
diff --git a/test/feature_test/group_feature_moments_show.c b/test/feature_test/group_feature_moments_show.c
index 212a991..4334407 100755
--- a/test/feature_test/group_feature_moments_show.c
+++ b/test/feature_test/group_feature_moments_show.c
@@ -8,181 +8,114 @@
#include "moments/moments_view_conf.h"
#include "../test_function.h"
-
#include <Elementary.h>
#include <app.h>
-
-static void __case_touch_down_top(bool * is_passed);
-static void __case_touch_up(bool * is_passed);
-static void __case_check_bar_state_half(bool * is_passed);
-static void __case_check_bar_state_hide(bool * is_passed);
-static void __case_touch_down_somewhere(bool * is_passed);
-
static struct {
- int current_step;
- Ecore_Timer * group_timer;
unit_group_t * group;
- int current_case;
- void(*case_pool[TEST_CASE_MAX + 1])(bool * is_passed);
} s_info = {
- .current_step = 0,
- .group_timer = NULL,
.group = NULL,
- .current_case = 0,
- .case_pool = {
- __case_touch_down_top,
- __case_check_bar_state_half,
- __case_touch_up,
- __case_check_bar_state_hide,
- __case_touch_down_somewhere,
- __case_touch_down_top,
- __case_touch_up,
- __case_touch_down_top,
- __case_touch_up,
- __case_touch_down_top,
- __case_touch_up,
- __case_touch_down_top,
- __case_touch_up,
- NULL,
- },
};
-static Eina_Bool __group_timer_callback(void * data);
-
-static void __set_up(void) {}
-static void __tear_down(void) {}
-
-static int touch_x[10] = { 180, 101, 259, 180, 180, 0 };
-static int touch_y[10] = { 50, 50, 50, 89, 0, 0 };
-static void __case_touch_down_top(bool * is_passed)
+static void __set_up(void)
{
- main_s * info = main_get_info();
- TEST_ASSERT_TRUE(info != NULL);
- TEST_ASSERT_TRUE(info->layout != NULL);
-
- TEST_ASSERT_TRUE(moments_get_visible() == false);
-
- __t__layout_mouse_down(info->layout, touch_x[s_info.current_step], touch_y[s_info.current_step]);
-
- TEST_ASSERT_TRUE(moments_get_visible());
+ if (moments_get_visible()) {
+ moments_hide();
+ ecore_timer_add(0.6, s_info.group->set_up_complete, s_info.group);
+ return ;
+ }
- *is_passed = true;
+ s_info.group->set_up_complete(s_info.group);
}
-static void __case_touch_down_somewhere(bool * is_passed)
+static void __tear_down(void)
{
- main_s * info = main_get_info();
- TEST_ASSERT_TRUE(info != NULL);
- TEST_ASSERT_TRUE(info->layout != NULL);
-
- TEST_ASSERT_TRUE(moments_get_visible() == false);
-
- __t__layout_mouse_down(info->layout, 100, 50);
- TEST_ASSERT_TRUE(moments_get_visible() == false);
- __t__layout_mouse_up(info->layout, 100, 50);
+ if (moments_get_visible()) {
+ moments_hide();
+ ecore_timer_add(0.6, s_info.group->tear_down_complete, s_info.group);
+ return ;
+ }
- __t__layout_mouse_down(info->layout, 260, 50);
- TEST_ASSERT_TRUE(moments_get_visible() == false);
- __t__layout_mouse_up(info->layout, 260, 50);
+ s_info.group->tear_down_complete(s_info.group);
+}
- __t__layout_mouse_down(info->layout, 180, 90);
- TEST_ASSERT_TRUE(moments_get_visible() == false);
- __t__layout_mouse_up(info->layout, 180, 90);
+static Eina_Bool __check_bar_state_half(void * data)
+{
+ Evas_Object * layout = __t__get_moments_view_layout();
+ TEST_ASSERT_TRUE_UPGRADE(layout != NULL);
+ TEST_ASSERT_TRUE_UPGRADE(evas_object_visible_get(layout) == EINA_TRUE);
- __t__layout_mouse_down(info->layout, 0, 0);
- TEST_ASSERT_TRUE(moments_get_visible() == false);
- __t__layout_mouse_up(info->layout, 0, 0);
+ int x = 0, y = 0, w = 0, h = 0;
+ evas_object_geometry_get(layout, &x, &y, &w, &h);
- __t__layout_mouse_down(info->layout, 360, 360);
- TEST_ASSERT_TRUE(moments_get_visible() == false);
- __t__layout_mouse_up(info->layout, 360, 360);
+ TEST_ASSERT_EQUAL_INT_UPGRADE(0, x);
+ TEST_ASSERT_EQUAL_INT_UPGRADE((-WINDOW_H + MOMENTS_INIT_H), y);
+ TEST_ASSERT_EQUAL_INT_UPGRADE(WINDOW_W, w);
+ TEST_ASSERT_EQUAL_INT_UPGRADE(WINDOW_H, h);
- __t__layout_mouse_down(info->layout, 180, 180);
- TEST_ASSERT_TRUE(moments_get_visible() == false);
- __t__layout_mouse_up(info->layout, 180, 180);
+ TEST_CASE_DONE(s_info.group);
- *is_passed = true;
+ return ECORE_CALLBACK_CANCEL;
}
-
-static void __case_touch_up(bool * is_passed)
+static Eina_Bool __case_touch_valid_area(void * data)
{
- main_s * info = main_get_info();
- TEST_ASSERT_TRUE(info != NULL);
- TEST_ASSERT_TRUE(info->layout != NULL);
+ position_t *pos = (position_t *)data;
- TEST_ASSERT_TRUE(moments_get_visible());
+ main_s * info = main_get_info();
+ TEST_ASSERT_TRUE_UPGRADE(info != NULL);
+ TEST_ASSERT_TRUE_UPGRADE(info->layout != NULL);
- __t__layout_mouse_up(info->layout, touch_x[s_info.current_step], touch_y[s_info.current_step]);
+ TEST_ASSERT_TRUE_UPGRADE(moments_get_visible() == false);
- TEST_ASSERT_TRUE(moments_get_visible() == false);
+ __t__layout_mouse_down(info->layout, pos->x, pos->y);
+ TEST_ASSERT_TRUE_UPGRADE(moments_get_visible());
- s_info.current_step += 1;
+ ecore_timer_add(0.6, __check_bar_state_half, NULL);
- *is_passed = true;
+ return EINA_TRUE;
}
-static void __case_check_bar_state_half(bool * is_passed)
+static Eina_Bool __case_touch_invalid_area(void * data)
{
- Evas_Object * layout = __t__get_moments_view_layout();
- TEST_ASSERT_TRUE(layout != NULL);
- TEST_ASSERT_TRUE(evas_object_visible_get(layout) == EINA_TRUE);
+ position_t *pos = (position_t *)data;
- int x = 0, y = 0, w = 0, h = 0;
- evas_object_geometry_get(layout, &x, &y, &w, &h);
+ main_s * info = main_get_info();
+ TEST_ASSERT_TRUE_UPGRADE(info != NULL);
+ TEST_ASSERT_TRUE_UPGRADE(info->layout != NULL);
- TEST_ASSERT_EQUAL_INT(0, x);
- TEST_ASSERT_EQUAL_INT((-WINDOW_H + MOMENTS_INIT_H), y);
- TEST_ASSERT_EQUAL_INT(WINDOW_W, w);
- TEST_ASSERT_EQUAL_INT(WINDOW_H, h);
+ TEST_ASSERT_TRUE_UPGRADE(moments_get_visible() == false);
- *is_passed = true;
-}
+ __t__layout_mouse_down(info->layout, pos->x, pos->y);
+ TEST_ASSERT_TRUE_UPGRADE(moments_get_visible() == false);
-static void __case_check_bar_state_hide(bool *is_passed)
-{
- Evas_Object * layout = __t__get_moments_view_layout();
- TEST_ASSERT_TRUE(layout != NULL);
- TEST_ASSERT_TRUE(evas_object_visible_get(layout) == EINA_FALSE);
-
- int x = 0, y = 0, w = 0, h = 0;
- evas_object_geometry_get(layout, &x, &y, &w, &h);
+ TEST_CASE_DONE(s_info.group);
- TEST_ASSERT_EQUAL_INT(OUTSIDE_X, x);
- TEST_ASSERT_EQUAL_INT(OUTSIDE_Y, y);
- TEST_ASSERT_EQUAL_INT(WINDOW_W, w);
- TEST_ASSERT_EQUAL_INT(WINDOW_H, h);
-
- *is_passed = true;
+ return EINA_TRUE;
}
void group_feature_moments_show(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;
- s_info.group_timer = ecore_timer_add(0.6, __group_timer_callback, NULL);
-}
-
-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;
+ s_info.group->set_up = __set_up;
+ s_info.group->tear_down = __tear_down;
+
+ static position_t valid_pos[5] = { {180, 50}, {101, 50}, {259, 50}, {180, 89}, {180, 0} };
+ TEST_CASE_ADD(s_info.group, __case_touch_valid_area, &valid_pos[0]);
+ TEST_CASE_ADD(s_info.group, __case_touch_valid_area, &valid_pos[1]);
+ TEST_CASE_ADD(s_info.group, __case_touch_valid_area, &valid_pos[2]);
+ TEST_CASE_ADD(s_info.group, __case_touch_valid_area, &valid_pos[3]);
+ TEST_CASE_ADD(s_info.group, __case_touch_valid_area, &valid_pos[4]);
+
+ static position_t invalid_pos[6] = { {100, 50}, {260, 50}, {180, 90}, {0, 0}, {360, 360}, {180, 180} };
+ TEST_CASE_ADD(s_info.group, __case_touch_invalid_area, &invalid_pos[0]);
+ TEST_CASE_ADD(s_info.group, __case_touch_invalid_area, &invalid_pos[1]);
+ TEST_CASE_ADD(s_info.group, __case_touch_invalid_area, &invalid_pos[2]);
+ TEST_CASE_ADD(s_info.group, __case_touch_invalid_area, &invalid_pos[3]);
+ TEST_CASE_ADD(s_info.group, __case_touch_invalid_area, &invalid_pos[4]);
+ TEST_CASE_ADD(s_info.group, __case_touch_invalid_area, &invalid_pos[5]);
+
+ TEST_GROUP_RUN(s_info.group);
}
#endif
diff --git a/test/unit/inc/unit.h b/test/unit/inc/unit.h
index 31f7c23..489b88a 100755
--- a/test/unit/inc/unit.h
+++ b/test/unit/inc/unit.h
@@ -15,6 +15,11 @@
#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_CASE_DONE(group) unit_group_case_done(group)
+#define TEST_CASE_FAIL unit_case_fail
+
#define TEST_CASE(group, case_starter) { \
bool is_passed = false; \
__set_up(); \
@@ -24,14 +29,14 @@
else unit_result_fail((group)->result); \
}
-#define TEST_CASE_MAX 100
-#define GROUP_COUNT_MAX 200
-
void unit_init(void);
void unit_fini(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
#endif
diff --git a/test/unit/inc/unit_assert.h b/test/unit/inc/unit_assert.h
index e841210..ec04af7 100755
--- a/test/unit/inc/unit_assert.h
+++ b/test/unit/inc/unit_assert.h
@@ -12,12 +12,26 @@
return; \
} \
}
+#define TEST_ASSERT_TRUE_UPGRADE(value) { \
+ bool __ret = unit_assert_true((value), (__FUNCTION__), (__LINE__)); \
+ if (!__ret) { \
+ 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; \
} \
}
+#define TEST_ASSERT_EQUAL_INT_UPGRADE(expected_value, input_value) { \
+ bool __ret = unit_assert_equal_int((expected_value), (input_value), (__FUNCTION__), (__LINE__)); \
+ if (!__ret) { \
+ 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) { \
diff --git a/test/unit/inc/unit_group.h b/test/unit/inc/unit_group.h
index 5703fbf..b540925 100755
--- a/test/unit/inc/unit_group.h
+++ b/test/unit/inc/unit_group.h
@@ -6,18 +6,34 @@
#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);
} 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_fail(unit_group_t * group);
+
#endif
#endif
diff --git a/test/unit/unit.c b/test/unit/unit.c
index bfee4b0..f8e1f43 100755
--- a/test/unit/unit.c
+++ b/test/unit/unit.c
@@ -9,15 +9,17 @@
static struct {
+ unit_group_t * current_group;
unit_result_t * result;
- int current_group;
+ 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 = 0,
+ .current_group_idx = 0,
.group_count = 0,
.group_name = { "", },
.group_starter_pool = { NULL, },
@@ -57,6 +59,8 @@ void unit_fini(void)
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))
@@ -73,16 +77,26 @@ void unit_test_run(void(*test_complete_cb)(void))
__run_next_group();
}
+void unit_case_fail(void)
+{
+ 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] == NULL) {
+ if (s_info.group_starter_pool[s_info.current_group_idx] == NULL) {
if (s_info.test_complete_cb) s_info.test_complete_cb();
return;
}
- unit_group_t * group = unit_group_new(s_info.group_name[s_info.current_group], __group_finish);
- s_info.group_starter_pool[s_info.current_group](group);
+ 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)
@@ -93,7 +107,9 @@ static void __group_finish(unit_group_t * group)
unit_result_add(s_info.result, group->result);
- s_info.current_group += 1;
+ unit_group_del(group);
+
+ s_info.current_group_idx += 1;
__run_next_group();
}
diff --git a/test/unit/unit_assert.c b/test/unit/unit_assert.c
index d515a4c..63cb4dc 100644..100755
--- 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();
+ __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();
+ __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();
+ __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();
+ __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();
+ __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..c4306e2 100755
--- a/test/unit/unit_group.c
+++ b/test/unit/unit_group.c
@@ -6,13 +6,24 @@
#include <string.h>
#include <stdlib.h>
+static void __run_next_case(unit_group_t * group);
+static Eina_Bool __group_set_up_complete(void * data);
+ static Eina_Bool __group_tear_down_complete(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 = __group_set_up_complete;
+ group->tear_down = NULL;
+ group->tear_down_complete = __group_tear_down_complete;
+ group->current_case = 0;
+ group->case_count = 0;
+ group->case_starter_pool[0] = NULL;
+ group->case_data_pool[0] = NULL;
return group;
}
@@ -26,4 +37,63 @@ 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)
+{
+ __run_next_case(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();
+}
+
+static void __run_next_case(unit_group_t * group)
+{
+ if (group->case_starter_pool[group->current_case] == NULL) {
+ group->finish(group);
+
+ return;
+ }
+
+ group->set_up();
+}
+
+static Eina_Bool __group_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 __group_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;
+}
+
#endif
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..49314c2 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
@@ -27,7 +27,6 @@ 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);