Tizen 2.0 Release
[framework/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         POSITIVE_TC_IDX = 0x01,
22         NEGATIVE_TC_IDX,
23 };
24
25 #define MY_ASSERT( fun , test , msg ) \
26 {\
27         if( !test ) \
28                 dts_fail(fun , msg ); \
29 }
30
31
32 static void startup(void);
33 static void cleanup(void);
34
35 void (*tet_startup)(void) = startup;
36 void (*tet_cleanup)(void) = cleanup;
37
38 static void utc_nfc_ndef_message_create_p(void);
39 static void utc_nfc_ndef_message_create_n(void);
40 static void utc_nfc_ndef_message_create_from_rawdata_p(void);
41 static void utc_nfc_ndef_message_create_from_rawdata_n(void);
42 static void utc_nfc_ndef_message_destroy_p(void);
43 static void utc_nfc_ndef_message_destroy_n(void);
44 static void utc_nfc_ndef_message_get_record_count_p(void);
45 static void utc_nfc_ndef_message_get_record_count_n(void);
46 static void utc_nfc_ndef_message_get_rawdata_p(void);
47 static void utc_nfc_ndef_message_get_rawdata_n(void);
48 static void utc_nfc_ndef_message_append_record_p(void);
49 static void utc_nfc_ndef_message_append_record_n(void);
50 static void utc_nfc_ndef_message_insert_record_p(void);
51 static void utc_nfc_ndef_message_insert_record_n(void);
52 static void utc_nfc_ndef_message_remove_record_p(void);
53 static void utc_nfc_ndef_message_remove_record_n(void);
54 static void utc_nfc_ndef_message_get_record_p(void);
55 static void utc_nfc_ndef_message_get_record_n(void);
56
57
58 struct tet_testlist tet_testlist[] = {
59         { utc_nfc_ndef_message_create_p , POSITIVE_TC_IDX },
60         { utc_nfc_ndef_message_create_n , NEGATIVE_TC_IDX },
61         { utc_nfc_ndef_message_create_from_rawdata_p , POSITIVE_TC_IDX },
62         { utc_nfc_ndef_message_create_from_rawdata_n , NEGATIVE_TC_IDX },
63         { utc_nfc_ndef_message_destroy_p , POSITIVE_TC_IDX },
64         { utc_nfc_ndef_message_destroy_n , NEGATIVE_TC_IDX },
65         { utc_nfc_ndef_message_get_record_count_p , POSITIVE_TC_IDX },
66         { utc_nfc_ndef_message_get_record_count_n , NEGATIVE_TC_IDX },
67         { utc_nfc_ndef_message_get_rawdata_p , POSITIVE_TC_IDX },
68         { utc_nfc_ndef_message_get_rawdata_n , NEGATIVE_TC_IDX },
69         { utc_nfc_ndef_message_append_record_p , POSITIVE_TC_IDX },
70         { utc_nfc_ndef_message_append_record_n , NEGATIVE_TC_IDX },
71         { utc_nfc_ndef_message_insert_record_p , POSITIVE_TC_IDX },
72         { utc_nfc_ndef_message_insert_record_n , NEGATIVE_TC_IDX },
73         { utc_nfc_ndef_message_remove_record_p , POSITIVE_TC_IDX },
74         { utc_nfc_ndef_message_remove_record_n , NEGATIVE_TC_IDX },
75         { utc_nfc_ndef_message_get_record_p , POSITIVE_TC_IDX },
76         { utc_nfc_ndef_message_get_record_n , NEGATIVE_TC_IDX },
77
78         { NULL, 0 },
79 };
80
81 //this method is called only once in start
82 static void startup(void)
83 {
84         /* start of TC */
85 }
86
87 static void cleanup(void)
88 {
89         /* end of TC */
90 }
91
92
93 static void utc_nfc_ndef_message_create_p(void)
94 {
95         int ret ;
96         nfc_ndef_message_h message;
97         ret = nfc_ndef_message_create(&message);
98         MY_ASSERT(__func__ , ret == NFC_ERROR_NONE , "FAIL");
99         nfc_ndef_message_destroy(message);
100         dts_pass(__func__, "PASS");
101 }
102 static void utc_nfc_ndef_message_create_n(void)
103 {
104         int ret ;
105         ret = nfc_ndef_message_create(NULL);
106         MY_ASSERT(__func__,  ret != NFC_ERROR_NONE , "FAIL");
107         dts_pass(__func__, "PASS");
108 }
109 static void utc_nfc_ndef_message_create_from_rawdata_p(void)
110 {
111         int ret ;
112         unsigned char *buffer;
113         int size;
114         nfc_ndef_message_h message;
115         nfc_ndef_message_h message2;
116         nfc_ndef_record_h record1;
117         ret = nfc_ndef_message_create(&message);
118         nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8);
119         nfc_ndef_message_append_record(message, record1);
120         nfc_ndef_message_get_rawdata(message, &buffer, &size);
121         ret = nfc_ndef_message_create_from_rawdata(&message2, buffer,size);
122
123         MY_ASSERT(__func__ , ret == NFC_ERROR_NONE , "FAIL");
124         nfc_ndef_message_destroy(message2);
125         nfc_ndef_message_destroy(message);
126         free(buffer);
127         dts_pass(__func__, "PASS");
128
129 }
130 static void utc_nfc_ndef_message_create_from_rawdata_n(void)
131 {
132         int ret ;
133         ret = nfc_ndef_message_create_from_rawdata(NULL, NULL, 0);
134         MY_ASSERT(__func__,  ret != NFC_ERROR_NONE , "FAIL");
135         dts_pass(__func__, "PASS");
136 }
137 static void utc_nfc_ndef_message_destroy_p(void)
138 {
139         int ret ;
140         nfc_ndef_message_h message;
141         ret = nfc_ndef_message_create(&message);
142         ret = nfc_ndef_message_destroy(message);
143         MY_ASSERT(__func__ , ret == NFC_ERROR_NONE , "FAIL");
144         dts_pass(__func__, "PASS");
145
146 }
147 static void utc_nfc_ndef_message_destroy_n(void)
148 {
149         int ret ;
150         ret = nfc_ndef_message_destroy(NULL);
151         MY_ASSERT(__func__,  ret != NFC_ERROR_NONE , "FAIL");
152         dts_pass(__func__, "PASS");
153 }
154 static void utc_nfc_ndef_message_get_record_count_p(void)
155 {
156         int ret ;
157         int count;
158         nfc_ndef_message_h message;
159         nfc_ndef_record_h record1;
160         ret = nfc_ndef_message_create(&message);
161         nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8);
162         nfc_ndef_message_append_record(message, record1);
163         ret = nfc_ndef_message_get_record_count(message, &count);
164
165         MY_ASSERT(__func__ , ret == NFC_ERROR_NONE , "FAIL");
166         nfc_ndef_message_destroy(message);
167         dts_pass(__func__, "PASS");
168
169 }
170 static void utc_nfc_ndef_message_get_record_count_n(void)
171 {
172         int ret ;
173         ret = nfc_ndef_message_get_record_count(NULL, NULL);
174         MY_ASSERT(__func__,  ret != NFC_ERROR_NONE , "FAIL");
175         dts_pass(__func__, "PASS");
176 }
177 static void utc_nfc_ndef_message_get_rawdata_p(void)
178 {
179         int ret ;
180         unsigned char *buffer;
181         int size;
182         nfc_ndef_message_h message;
183         nfc_ndef_record_h record1;
184         ret = nfc_ndef_message_create(&message);
185         nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8);
186         nfc_ndef_message_append_record(message, record1);
187         ret= nfc_ndef_message_get_rawdata(message, &buffer, &size);
188
189         MY_ASSERT(__func__ , ret == NFC_ERROR_NONE , "FAIL");
190         nfc_ndef_message_destroy(message);
191         free(buffer);
192         dts_pass(__func__, "PASS");
193
194 }
195 static void utc_nfc_ndef_message_get_rawdata_n(void)
196 {
197         int ret ;
198         ret = nfc_ndef_message_get_rawdata(NULL, NULL, NULL);
199         MY_ASSERT(__func__,  ret != NFC_ERROR_NONE , "FAIL");
200         dts_pass(__func__, "PASS");
201 }
202 static void utc_nfc_ndef_message_append_record_p(void)
203 {
204         int ret ;
205         nfc_ndef_message_h message;
206         nfc_ndef_record_h record1;
207         ret = nfc_ndef_message_create(&message);
208         nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8);
209         ret = nfc_ndef_message_append_record(message, record1);
210         MY_ASSERT(__func__ , ret == NFC_ERROR_NONE , "FAIL");
211         nfc_ndef_message_destroy(message);
212         dts_pass(__func__, "PASS");
213 }
214 static void utc_nfc_ndef_message_append_record_n(void)
215 {
216         int ret ;
217         ret = nfc_ndef_message_append_record(NULL, NULL);
218         MY_ASSERT(__func__,  ret != NFC_ERROR_NONE , "FAIL");
219         dts_pass(__func__, "PASS");
220 }
221 static void utc_nfc_ndef_message_insert_record_p(void)
222 {
223         int ret ;
224         nfc_ndef_message_h message;
225         nfc_ndef_record_h record1;
226         ret = nfc_ndef_message_create(&message);
227         nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8);
228         ret = nfc_ndef_message_insert_record(message,0, record1);
229         MY_ASSERT(__func__ , ret == NFC_ERROR_NONE , "FAIL");
230         nfc_ndef_message_destroy(message);
231         dts_pass(__func__, "PASS");
232 }
233 static void utc_nfc_ndef_message_insert_record_n(void)
234 {
235         int ret ;
236         ret = nfc_ndef_message_insert_record(NULL, 0 , NULL);
237         MY_ASSERT(__func__,  ret != NFC_ERROR_NONE , "FAIL");
238         dts_pass(__func__, "PASS");
239 }
240 static void utc_nfc_ndef_message_remove_record_p(void)
241 {
242         int ret ;
243         nfc_ndef_message_h message;
244         nfc_ndef_record_h record1;
245         ret = nfc_ndef_message_create(&message);
246         nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8);
247         ret = nfc_ndef_message_insert_record(message,0, record1);
248         ret = nfc_ndef_message_remove_record(message, 0);
249         MY_ASSERT(__func__ , ret == NFC_ERROR_NONE , "FAIL");
250         nfc_ndef_message_destroy(message);
251         dts_pass(__func__, "PASS");
252
253 }
254 static void utc_nfc_ndef_message_remove_record_n(void)
255 {
256         int ret ;
257         ret = nfc_ndef_message_remove_record(NULL, 0);
258         MY_ASSERT(__func__,  ret != NFC_ERROR_NONE , "FAIL");
259         dts_pass(__func__, "PASS");
260 }
261 static void utc_nfc_ndef_message_get_record_p(void)
262 {
263         int ret ;
264         nfc_ndef_message_h message;
265         nfc_ndef_record_h record1, record2;
266         ret = nfc_ndef_message_create(&message);
267         nfc_ndef_record_create_text(&record1, "test", "en-US", NFC_ENCODE_UTF_8);
268         ret = nfc_ndef_message_insert_record(message,0, record1);
269         ret = nfc_ndef_message_get_record(message, 0, &record2);
270         MY_ASSERT(__func__ , ret == NFC_ERROR_NONE , "FAIL");
271         nfc_ndef_message_destroy(message);
272         dts_pass(__func__, "PASS");
273
274 }
275 static void utc_nfc_ndef_message_get_record_n(void)
276 {
277         int ret ;
278         ret = nfc_ndef_message_get_record(NULL, 0 , NULL);
279         MY_ASSERT(__func__,  ret != NFC_ERROR_NONE , "FAIL");
280         dts_pass(__func__, "PASS");
281 }
282