Remove ecore_x for pure Wayland build.
[platform/core/api/nfc.git] / TC / testcase / utc_network_nfc_ndef_message.c
1 /*
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <tet_api.h>
18 #include <nfc.h>
19
20 enum
21 {
22         POSITIVE_TC_IDX = 0x01,
23         NEGATIVE_TC_IDX,
24 };
25
26 static void startup(void);
27 static void cleanup(void);
28
29 void (*tet_startup)(void) = startup;
30 void (*tet_cleanup)(void) = cleanup;
31
32 static void utc_nfc_ndef_message_create_p(void);
33 static void utc_nfc_ndef_message_create_n(void);
34 static void utc_nfc_ndef_message_create_from_rawdata_p(void);
35 static void utc_nfc_ndef_message_create_from_rawdata_n(void);
36 static void utc_nfc_ndef_message_destroy_p(void);
37 static void utc_nfc_ndef_message_destroy_n(void);
38 static void utc_nfc_ndef_message_get_record_count_p(void);
39 static void utc_nfc_ndef_message_get_record_count_n(void);
40 static void utc_nfc_ndef_message_get_rawdata_p(void);
41 static void utc_nfc_ndef_message_get_rawdata_n(void);
42 static void utc_nfc_ndef_message_append_record_p(void);
43 static void utc_nfc_ndef_message_append_record_n(void);
44 static void utc_nfc_ndef_message_insert_record_p(void);
45 static void utc_nfc_ndef_message_insert_record_n(void);
46 static void utc_nfc_ndef_message_remove_record_p(void);
47 static void utc_nfc_ndef_message_remove_record_n(void);
48 static void utc_nfc_ndef_message_get_record_p(void);
49 static void utc_nfc_ndef_message_get_record_n(void);
50
51 struct tet_testlist tet_testlist[] =
52 {
53         { utc_nfc_ndef_message_create_p, POSITIVE_TC_IDX },
54         { utc_nfc_ndef_message_create_n, NEGATIVE_TC_IDX },
55         { utc_nfc_ndef_message_create_from_rawdata_p, POSITIVE_TC_IDX },
56         { utc_nfc_ndef_message_create_from_rawdata_n, NEGATIVE_TC_IDX },
57         { utc_nfc_ndef_message_destroy_p, POSITIVE_TC_IDX },
58         { utc_nfc_ndef_message_destroy_n, NEGATIVE_TC_IDX },
59         { utc_nfc_ndef_message_get_record_count_p, POSITIVE_TC_IDX },
60         { utc_nfc_ndef_message_get_record_count_n, NEGATIVE_TC_IDX },
61         { utc_nfc_ndef_message_get_rawdata_p, POSITIVE_TC_IDX },
62         { utc_nfc_ndef_message_get_rawdata_n, NEGATIVE_TC_IDX },
63         { utc_nfc_ndef_message_append_record_p, POSITIVE_TC_IDX },
64         { utc_nfc_ndef_message_append_record_n, NEGATIVE_TC_IDX },
65         { utc_nfc_ndef_message_insert_record_p, POSITIVE_TC_IDX },
66         { utc_nfc_ndef_message_insert_record_n, NEGATIVE_TC_IDX },
67         { utc_nfc_ndef_message_remove_record_p, POSITIVE_TC_IDX },
68         { utc_nfc_ndef_message_remove_record_n, NEGATIVE_TC_IDX },
69         { utc_nfc_ndef_message_get_record_p, POSITIVE_TC_IDX },
70         { utc_nfc_ndef_message_get_record_n, NEGATIVE_TC_IDX },
71
72         { NULL, 0 },
73 };
74
75 //this method is called only once in start
76 static void startup(void)
77 {
78         /* start of TC */
79 }
80
81 static void cleanup(void)
82 {
83         /* end of TC */
84 }
85
86 static void utc_nfc_ndef_message_create_p(void)
87 {
88         int ret;
89         nfc_ndef_message_h message;
90
91         ret = nfc_ndef_message_create(&message);
92         nfc_ndef_message_destroy(message);
93
94         dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_create is failed");
95 }
96
97 static void utc_nfc_ndef_message_create_n(void)
98 {
99         int ret;
100
101         ret = nfc_ndef_message_create(NULL);
102
103         dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_create not allow null");
104 }
105
106 static void utc_nfc_ndef_message_create_from_rawdata_p(void)
107 {
108         int ret;
109         unsigned char *buffer;
110         uint32_t int size;
111         nfc_ndef_message_h message;
112         nfc_ndef_message_h message2;
113         nfc_ndef_record_h record1;
114
115         ret = nfc_ndef_message_create(&message);
116         nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8);
117         nfc_ndef_message_append_record(message, record1);
118         nfc_ndef_message_get_rawdata(message, &buffer, &size);
119         ret = nfc_ndef_message_create_from_rawdata(&message2, buffer, size);
120
121         nfc_ndef_message_destroy(message2);
122         nfc_ndef_message_destroy(message);
123         free(buffer);
124
125         dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_create_from_rawdata is failed");
126 }
127
128 static void utc_nfc_ndef_message_create_from_rawdata_n(void)
129 {
130         int ret;
131
132         ret = nfc_ndef_message_create_from_rawdata(NULL, NULL, 0);
133
134         dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_create_from_rawdata not allow null");
135 }
136
137 static void utc_nfc_ndef_message_destroy_p(void)
138 {
139         int ret;
140         nfc_ndef_message_h message;
141
142         ret = nfc_ndef_message_create(&message);
143         ret = nfc_ndef_message_destroy(message);
144
145         dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_destroy is failed");
146 }
147
148 static void utc_nfc_ndef_message_destroy_n(void)
149 {
150         int ret;
151
152         ret = nfc_ndef_message_destroy(NULL);
153
154         dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_destroy not allow null");
155 }
156
157 static void utc_nfc_ndef_message_get_record_count_p(void)
158 {
159         int ret;
160         int count;
161         nfc_ndef_message_h message;
162         nfc_ndef_record_h record1;
163
164         ret = nfc_ndef_message_create(&message);
165         nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8);
166         nfc_ndef_message_append_record(message, record1);
167         ret = nfc_ndef_message_get_record_count(message, &count);
168         nfc_ndef_message_destroy(message);
169
170         dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_get_record_count is failed");
171 }
172
173 static void utc_nfc_ndef_message_get_record_count_n(void)
174 {
175         int ret;
176
177         ret = nfc_ndef_message_get_record_count(NULL, NULL);
178
179         dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_get_record_count not allow null");
180 }
181
182 static void utc_nfc_ndef_message_get_rawdata_p(void)
183 {
184         int ret;
185         unsigned char *buffer;
186         uint32_t size;
187         nfc_ndef_message_h message;
188         nfc_ndef_record_h record1;
189
190         ret = nfc_ndef_message_create(&message);
191         nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8);
192         nfc_ndef_message_append_record(message, record1);
193         ret = nfc_ndef_message_get_rawdata(message, &buffer, &size);
194         nfc_ndef_message_destroy(message);
195         free(buffer);
196
197         dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_get_rawdata is failed");
198 }
199
200 static void utc_nfc_ndef_message_get_rawdata_n(void)
201 {
202         int ret;
203
204         ret = nfc_ndef_message_get_rawdata(NULL, NULL, NULL);
205
206         dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_get_rawdata not allow null");
207 }
208
209 static void utc_nfc_ndef_message_append_record_p(void)
210 {
211         int ret;
212         nfc_ndef_message_h message;
213         nfc_ndef_record_h record1;
214
215         ret = nfc_ndef_message_create(&message);
216         nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8);
217         ret = nfc_ndef_message_append_record(message, record1);
218         nfc_ndef_message_destroy(message);
219
220         dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_append_record is failed");
221 }
222
223 static void utc_nfc_ndef_message_append_record_n(void)
224 {
225         int ret;
226
227         ret = nfc_ndef_message_append_record(NULL, NULL);
228
229         dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_append_record not allow null");
230 }
231
232 static void utc_nfc_ndef_message_insert_record_p(void)
233 {
234         int ret;
235         nfc_ndef_message_h message;
236         nfc_ndef_record_h record1;
237
238         ret = nfc_ndef_message_create(&message);
239         nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8);
240         ret = nfc_ndef_message_insert_record(message, 0, record1);
241         nfc_ndef_message_destroy(message);
242
243         dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_insert_record is failed");
244 }
245
246 static void utc_nfc_ndef_message_insert_record_n(void)
247 {
248         int ret;
249
250         ret = nfc_ndef_message_insert_record(NULL, 0, NULL);
251
252         dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_insert_record not allow null");
253 }
254
255 static void utc_nfc_ndef_message_remove_record_p(void)
256 {
257         int ret;
258         nfc_ndef_message_h message;
259         nfc_ndef_record_h record1;
260
261         ret = nfc_ndef_message_create(&message);
262         nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8);
263         ret = nfc_ndef_message_insert_record(message, 0, record1);
264         ret = nfc_ndef_message_remove_record(message, 0);
265         nfc_ndef_message_destroy(message);
266
267         dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_remove_record is failed");
268 }
269
270 static void utc_nfc_ndef_message_remove_record_n(void)
271 {
272         int ret;
273
274         ret = nfc_ndef_message_remove_record(NULL, 0);
275
276         dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_remove_record not allow null");
277 }
278
279 static void utc_nfc_ndef_message_get_record_p(void)
280 {
281         int ret;
282         nfc_ndef_message_h message;
283         nfc_ndef_record_h record1, record2;
284
285         ret = nfc_ndef_message_create(&message);
286         nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8);
287         ret = nfc_ndef_message_insert_record(message, 0, record1);
288         ret = nfc_ndef_message_get_record(message, 0, &record2);
289         nfc_ndef_message_destroy(message);
290
291         dts_check_eq(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_get_record is failed");
292 }
293
294 static void utc_nfc_ndef_message_get_record_n(void)
295 {
296         int ret;
297
298         ret = nfc_ndef_message_get_record(NULL, 0, NULL);
299
300         dts_check_ne(__func__, ret, NFC_ERROR_NONE, "nfc_ndef_message_get_record not allow null");
301 }