Initialize Tizen 2.3
[framework/uifw/elementary.git] / mobile / TC / elm_ts / index / utc_UIFW_elm_index_item_data_get_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_data_get_func_01(void);
40 static void utc_UIFW_elm_index_item_data_get_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_data_get_func_01, POSITIVE_TC_IDX },
49         { utc_UIFW_elm_index_item_data_get_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(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  * @brief Positive test case of elm_index_item_data_get()
83  */
84 static void utc_UIFW_elm_index_item_data_get_func_01(void)
85 {
86         Evas_Object *idx = NULL;
87         Elm_Object_Item *it = NULL;
88         Elm_Object_Item *it_gl = NULL;
89         Elm_Object_Item *item = NULL;
90         Evas_Object *gl = NULL;
91         void *d = NULL;
92         int i = 0, j = 0;
93
94         gl = elm_genlist_add(main_win);
95         idx= elm_index_add(main_win);
96         evas_object_show(gl);
97         evas_object_show(idx);
98         itci.item_style     = "default";
99         itci.func.label_get = gli_label_get;
100         itci.func.icon_get  = NULL;
101         itci.func.state_get = NULL;
102         itci.func.del       = NULL;
103         for (i = 0; i < 40; i++) {
104                 it = elm_genlist_item_append(gl, &itci,(void *)j, NULL, ELM_GENLIST_ITEM_NONE, NULL,NULL);
105                 if ((j & 0xf) == 0) {
106                         char buf[32];
107                         snprintf(buf, sizeof(buf), "%c", 'A' + ((j >> 4) & 0xf));
108                         elm_index_item_append(idx, buf, it);
109                 }
110                 j += 2;
111                 if(i==0)
112                 it_gl=it;
113         }
114         elm_index_item_go(idx, 0);
115         item = elm_index_item_find(idx,it_gl);
116         d =  (void*)elm_index_item_data_get(item);
117         if(!item) {
118                 tet_infoline("elm_index_item_data_get() failed in positive test case");
119                 tet_result(TET_FAIL);
120                 return;
121         }
122         tet_result(TET_PASS);
123 }
124
125 /**
126  * @brief Negative test case of ug_init elm_index_item_data_get()
127  */
128 static void utc_UIFW_elm_index_item_data_get_func_02(void)
129 {
130         Evas_Object *idx = NULL;
131         Elm_Object_Item *it = NULL;
132         Elm_Object_Item *it_gl = NULL;
133         Elm_Object_Item *item = NULL;
134         Evas_Object *gl = NULL;
135         void *d = NULL;
136         int i = 0, j = 0;
137
138         gl = elm_genlist_add(main_win);
139         idx= elm_index_add(main_win);
140         evas_object_show(gl);
141         evas_object_show(idx);
142         itci.item_style     = "default";
143         itci.func.label_get = gli_label_get;
144         itci.func.icon_get  = NULL;
145         itci.func.state_get = NULL;
146         itci.func.del       = NULL;
147         for (i = 0; i < 40; i++) {
148                 it = elm_genlist_item_append(gl, &itci,(void *)j, NULL, ELM_GENLIST_ITEM_NONE, NULL,NULL);
149                 if ((j & 0xf) == 0) {
150                         char buf[32];
151                         snprintf(buf, sizeof(buf), "%c", 'A' + ((j >> 4) & 0xf));
152                         elm_index_item_append(idx, buf, it);
153                 }
154                 j += 2;
155                 if(i==0) it_gl=it;
156         }
157         elm_index_item_go(idx, 0);
158         item = elm_index_item_find(NULL,it_gl);
159         d = (void *) elm_index_item_data_get(NULL);
160         if(d) {
161                 tet_infoline("elm_index_item_data_get() with argument as NULL failed in negative test case");
162                 tet_result(TET_FAIL);
163                 return;
164         }
165         tet_result(TET_PASS);
166 }