[Refactoring] Removed trailing whitespaces.
[framework/uifw/elementary.git] / TC / elm_ts / index / utc_UIFW_elm_index_item_sorted_insert_func.c
1 #include <tet_api.h>
2 #include <Elementary.h>
3
4 // Definitions
5 // For checking the result of the positive test case.
6 #define TET_CHECK_PASS(x1, y...) \
7 { \
8         Evas_Object *err = y; \
9         if (err == (x1)) \
10                 { \
11                         tet_printf("[TET_CHECK_PASS]:: %s[%d] : Test has failed..", __FILE__,__LINE__); \
12                         tet_result(TET_FAIL); \
13                         return; \
14                 } \
15 }
16
17 // For checking the result of the negative test case.
18 #define TET_CHECK_FAIL(x1, y...) \
19 { \
20         Evas_Object *err = y; \
21         if (err != (x1)) \
22                 { \
23                         tet_printf("[TET_CHECK_FAIL]:: %s[%d] : Test has failed..", __FILE__,__LINE__); \
24                         tet_result(TET_FAIL); \
25                         return; \
26                 } \
27 }
28
29
30 Evas_Object *main_win;
31 static Elm_Genlist_Item_Class itci;
32
33 static void startup(void);
34 static void cleanup(void);
35
36 void (*tet_startup)(void) = startup;
37 void (*tet_cleanup)(void) = cleanup;
38
39 static void utc_UIFW_elm_index_item_sorted_insert_func_01(void);
40 static void utc_UIFW_elm_index_item_sorted_insert_func_02(void);
41
42 enum {
43         POSITIVE_TC_IDX = 0x01,
44         NEGATIVE_TC_IDX,
45 };
46
47 struct tet_testlist tet_testlist[] = {
48         { utc_UIFW_elm_index_item_sorted_insert_func_01, POSITIVE_TC_IDX },
49         { utc_UIFW_elm_index_item_sorted_insert_func_02, NEGATIVE_TC_IDX },
50         { NULL, 0 }
51 };
52
53 static void startup(void)
54 {
55         tet_infoline("[[ TET_MSG ]]:: ============ Startup ============ ");
56         elm_init(0, NULL);
57         main_win = elm_win_add(NULL, "main", ELM_WIN_BASIC);
58         evas_object_show(main_win);
59 }
60
61 static void cleanup(void)
62 {
63         if ( NULL != main_win ) {
64                 evas_object_del(main_win);
65                 main_win = NULL;
66         }
67         elm_shutdown();
68         tet_infoline("[[ TET_MSG ]]:: ============ Cleanup ============ ");
69 }
70
71 char *gli_label_get(const void *data, Evas_Object *obj, const char *part)
72 {
73    char buf[256];
74    int j = (int)data;
75    snprintf(buf, sizeof(buf), "%c%c",
76             'A' + ((j >> 4) & 0xf),
77             'a' + ((j     ) & 0xf)
78             );
79    return strdup(buf);
80 }
81
82 int
83 test_index2_cmp(const void *data1, const void *data2)
84 {
85    const char *label1, *label2;
86    const Elm_List_Item *it1 = data1;
87    const Elm_List_Item *it2 = data2;
88
89    label1 = elm_list_item_label_get(it1);
90    label2 = elm_list_item_label_get(it2);
91
92    return strcasecmp(label1, label2);
93 }
94
95 int
96 test_index2_icmp(const void *data1, const void *data2)
97 {
98    const char *label1, *label2;
99    const Elm_Index_Item *it1 = data1;
100    const Elm_Index_Item *it2 = data2;
101
102    label1 = elm_index_item_letter_get(it1);
103    label2 = elm_index_item_letter_get(it2);
104
105    return strcasecmp(label1, label2);
106 }
107 /**
108  * @brief Positive test case of elm_index_item_sorted_insert()
109  */
110 static void utc_UIFW_elm_index_item_sorted_insert_func_01(void)
111 {
112         Evas_Object *idx = NULL;
113         Elm_Genlist_Item *it = NULL, *it_gl=NULL;
114         Evas_Object *gl = NULL;
115         Elm_Index_Item *it_idx = NULL;
116         int i = 0, j = 0;
117
118         const char  *letter = NULL;
119         gl = elm_genlist_add(main_win);
120         idx= elm_index_add(main_win);
121         evas_object_show(gl);
122         evas_object_show(idx);
123         itci.item_style     = "default";
124         itci.func.label_get = gli_label_get;
125         itci.func.icon_get  = NULL;
126         itci.func.state_get = NULL;
127         itci.func.del       = NULL;
128         for (i = 0; i <=40; i++) {
129                 it = elm_genlist_item_append(gl, &itci,(void *)j, NULL, ELM_GENLIST_ITEM_NONE, NULL,NULL);
130                 if ((j & 0xf) == 0) {
131                         char buf[32];
132                         snprintf(buf, sizeof(buf), "%c", 'A' + ((j >> 3) & 0xf));
133                         elm_index_item_append(idx, buf, it);
134                 }
135                 if(i==0) it_gl=it;
136                 j += 2;
137         }
138         it = elm_genlist_item_append(gl, &itci,(void *)j, NULL, ELM_GENLIST_ITEM_NONE, NULL,NULL);
139         char buf[32];
140         snprintf(buf, sizeof(buf), "%c", 'A' + ((j >> 3) & 0xf));
141
142         elm_index_item_sorted_insert(idx, buf, it, test_index2_icmp, test_index2_cmp);
143         elm_index_item_go(idx, 0);
144         it_idx = elm_index_item_find(idx,(void*)it_gl);
145         letter = elm_index_item_letter_get(it_idx);
146         if((strcmp(letter,"A")&&(strcmp(buf,"K")))) {
147                 tet_infoline("elm_index_item_sorted_insert() with argument as NULL failed in positive test case");
148                 tet_result(TET_FAIL);
149                 return;
150         }
151         tet_result(TET_PASS);
152 }
153
154 /**
155  * @brief Negative test case of ug_init elm_index_item_sorted_insert()
156  */
157 static void utc_UIFW_elm_index_item_sorted_insert_func_02(void)
158 {
159         Evas_Object *idx = NULL;
160         Elm_Genlist_Item *it = NULL, *it_gl=NULL;
161         Evas_Object *gl = NULL;
162         Elm_Index_Item *it_idx = NULL;
163         int i = 0, j = 0;
164
165         gl = elm_genlist_add(main_win);
166         idx= elm_index_add(main_win);
167         evas_object_show(gl);
168         evas_object_show(idx);
169         itci.item_style     = "default";
170         itci.func.label_get = gli_label_get;
171         itci.func.icon_get  = NULL;
172         itci.func.state_get = NULL;
173         itci.func.del       = NULL;
174         for (i = 0; i <=40; i++) {
175                 it = elm_genlist_item_append(gl, &itci,(void *)j, NULL, ELM_GENLIST_ITEM_NONE, NULL,NULL);
176                 if ((j & 0xf) == 0) {
177                         char buf[32];
178                         snprintf(buf, sizeof(buf), "%c", 'A' + ((j >> 3) & 0xf));
179                         elm_index_item_append(idx, buf, it);
180                 }
181                 if(i==0) it_gl=it;
182                 j += 2;
183         }
184         it = elm_genlist_item_append(gl, &itci,(void *)j, NULL, ELM_GENLIST_ITEM_NONE, NULL,NULL);
185         char buf[32];
186         snprintf(buf, sizeof(buf), "%c", 'A' + ((j >> 3) & 0xf));
187         elm_index_item_sorted_insert(NULL, buf, it, NULL,NULL);
188         elm_index_item_go(idx, 0);
189         it_idx = elm_index_item_find(idx,(void*)it);
190         if(it_idx) {
191                 tet_infoline("elm_index_item_sorted_insert() failed in negative test case");
192                 tet_result(TET_FAIL);
193                 return;
194         }
195         tet_result(TET_PASS);
196 }