apply FSL(Flora Software License)
[framework/connectivity/nfc-manager.git] / TC / testcase / utc_net_nfc_client_ndef_message.c
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
4   * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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 <stdint.h>
19
20 #include "net_nfc_ndef_message.h"
21 #include "net_nfc_util_private.h"
22 #include "net_nfc.h" // to use net_nfc_data
23
24
25 enum {
26         POSITIVE_TC_IDX = 0x01,
27         NEGATIVE_TC_IDX,
28 };
29 static void startup(void);
30 static void cleanup(void);
31
32 void (*tet_startup)(void) = startup;
33 void (*tet_cleanup)(void) = cleanup;
34
35 static void utc_net_nfc_create_ndef_message_p(void);
36 static void utc_net_nfc_create_ndef_message_n(void);
37 static void utc_net_nfc_create_rawdata_from_ndef_message_p(void);
38 static void utc_net_nfc_create_rawdata_from_ndef_message_n(void);
39 static void utc_net_nfc_create_ndef_message_from_rawdata_p(void);
40 static void utc_net_nfc_create_ndef_message_from_rawdata_n(void);
41 static void utc_net_nfc_get_ndef_message_byte_length_p(void);
42 static void utc_net_nfc_get_ndef_message_byte_length_n(void);
43 static void utc_net_nfc_append_record_to_ndef_message_p(void);
44 static void utc_net_nfc_append_record_to_ndef_message_n(void);
45 static void utc_net_nfc_free_ndef_message_p(void);
46 static void utc_net_nfc_free_ndef_message_n(void);
47 static void utc_net_nfc_get_ndef_message_record_count_p(void);
48 static void utc_net_nfc_get_ndef_message_record_count_n(void);
49
50
51
52
53 struct tet_testlist tet_testlist[] = {
54         { utc_net_nfc_create_ndef_message_p , POSITIVE_TC_IDX },
55         { utc_net_nfc_create_ndef_message_n , NEGATIVE_TC_IDX },
56         { utc_net_nfc_create_rawdata_from_ndef_message_p, POSITIVE_TC_IDX },
57         { utc_net_nfc_create_rawdata_from_ndef_message_n , NEGATIVE_TC_IDX},
58         { utc_net_nfc_create_ndef_message_from_rawdata_p, 1},
59         { utc_net_nfc_create_ndef_message_from_rawdata_n, 2 },
60         { utc_net_nfc_get_ndef_message_byte_length_p, 1},
61         { utc_net_nfc_get_ndef_message_byte_length_n, 2},
62         { utc_net_nfc_append_record_to_ndef_message_p, 1},
63         { utc_net_nfc_append_record_to_ndef_message_n, 2},
64         { utc_net_nfc_free_ndef_message_p, 1},
65         { utc_net_nfc_free_ndef_message_n, 2},
66         { utc_net_nfc_get_ndef_message_record_count_p, 1},
67         { utc_net_nfc_get_ndef_message_record_count_n, 2},
68         { NULL, 0 },
69 };
70
71 //this method is called only once in start
72 static void startup(void)
73 {
74         /* start of TC */
75 }
76
77 static void cleanup(void)
78 {
79         /* end of TC */
80 }
81 static void utc_net_nfc_create_ndef_message_p(void)
82 {
83         int ret ;
84         ndef_message_h message;
85
86         ret = net_nfc_create_ndef_message(&message);
87         net_nfc_free_ndef_message(message);
88
89         dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_ndef_message is failed");
90 }
91
92 static void utc_net_nfc_create_ndef_message_n(void)
93 {
94         int ret=0;
95
96         ret = net_nfc_create_ndef_message( NULL);
97
98         dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_ndef_message not allow null");
99 }
100
101 static void utc_net_nfc_create_rawdata_from_ndef_message_p(void)
102 {
103         int ret ;
104         char url[] = "samsung.com";
105         ndef_record_h record = NULL;
106         ndef_message_h msg = NULL;
107         data_h rawdata = NULL;
108
109         net_nfc_create_uri_type_record(&record, url, NET_NFC_SCHEMA_HTTPS_WWW);
110
111         net_nfc_create_ndef_message(&msg);
112
113         net_nfc_append_record_to_ndef_message(msg, record);
114
115         ret = net_nfc_create_rawdata_from_ndef_message (msg, &rawdata);
116
117         dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_rawdata_from_ndef_message is failed");
118 }
119
120 static void utc_net_nfc_create_rawdata_from_ndef_message_n(void)
121 {
122         int ret ;
123
124         ret = net_nfc_create_rawdata_from_ndef_message (NULL, NULL);
125
126         dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_create_rawdata_from_ndef_message not allow null");
127 }
128
129 static void utc_net_nfc_create_ndef_message_from_rawdata_p(void)
130 {
131         int ret ;
132         uint8_t url[] = "samsung.com";
133         ndef_message_s* msg = NULL;
134         data_s* rawdata = NULL;
135
136         rawdata = calloc(1, sizeof(data_s));
137         msg = calloc(1, sizeof(ndef_message_s));
138
139         rawdata->buffer = url;
140         rawdata->length = 11;
141
142         ret = net_nfc_create_ndef_message_from_rawdata ((ndef_message_h*)msg, (data_h)rawdata);
143
144         net_nfc_free_ndef_message((ndef_message_h)msg);
145
146         dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_create_ndef_message_from_rawdata is failed");
147 }
148
149 static void utc_net_nfc_create_ndef_message_from_rawdata_n(void)
150 {
151         int ret ;
152
153         ret = net_nfc_create_ndef_message_from_rawdata (NULL, NULL);
154
155         dts_check_ne(__func__, ret, NET_NFC_OK,"net_nfc_create_ndef_message_from_rawdata not allow null");
156 }
157
158 static void utc_net_nfc_get_ndef_message_byte_length_p(void)
159 {
160         int ret ;
161         char url[] = "samsung.com";
162         ndef_record_h record = NULL;
163         ndef_message_h msg = NULL;
164         int length = 0;
165
166         net_nfc_create_uri_type_record(&record, url, NET_NFC_SCHEMA_HTTPS_WWW);
167
168         net_nfc_create_ndef_message(&msg);
169
170         net_nfc_append_record_to_ndef_message(msg, record);
171
172         ret = net_nfc_get_ndef_message_byte_length( msg , &length);
173
174         dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_ndef_message_byte_length is failed");
175 }
176
177 static void utc_net_nfc_get_ndef_message_byte_length_n(void)
178 {
179         int ret ;
180
181         ret = net_nfc_get_ndef_message_byte_length (NULL, NULL);
182
183         dts_check_ne(__func__, ret, NET_NFC_OK,"net_nfc_get_ndef_message_byte_length not allow null");
184 }
185
186 static void utc_net_nfc_append_record_to_ndef_message_p(void)
187 {
188         int ret ;
189         char url[] = "samsung.com";
190         ndef_record_h record = NULL;
191         ndef_message_h msg = NULL;
192
193         net_nfc_create_uri_type_record(&record, url, NET_NFC_SCHEMA_HTTPS_WWW);
194
195         net_nfc_create_ndef_message(&msg);
196
197         ret = net_nfc_append_record_to_ndef_message(msg, record);
198
199         dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_append_record_to_ndef_message is failed");
200 }
201
202 static void utc_net_nfc_append_record_to_ndef_message_n(void)
203 {
204         int ret ;
205
206         ret = net_nfc_append_record_to_ndef_message (NULL, NULL);
207
208         dts_check_ne(__func__, ret, NET_NFC_OK,"net_nfc_append_record_to_ndef_message not allow null");
209 }
210
211 static void utc_net_nfc_free_ndef_message_p(void)
212 {
213         int ret ;
214         ndef_message_h message;
215
216         net_nfc_create_ndef_message(&message);
217         ret = net_nfc_free_ndef_message(message);
218
219         dts_check_eq(__func__, ret, NET_NFC_OK, "utc_net_nfc_free_ndef_message_n is failed");
220 }
221
222 static void utc_net_nfc_free_ndef_message_n(void)
223 {
224         int ret=0;
225
226         ret = net_nfc_free_ndef_message( NULL);
227
228         dts_check_ne(__func__, ret, NET_NFC_OK, "utc_net_nfc_free_ndef_message_n not allow null");
229 }
230
231 static void utc_net_nfc_get_ndef_message_record_count_p(void)
232 {
233         int ret ;
234         char url[] = "samsung.com";
235         ndef_record_h record = NULL;
236         ndef_message_h msg = NULL;
237         int count = 0;
238
239         net_nfc_create_uri_type_record(&record, url, NET_NFC_SCHEMA_HTTPS_WWW);
240
241         net_nfc_create_ndef_message(&msg);
242
243         net_nfc_append_record_to_ndef_message(msg, record);
244
245         ret = net_nfc_get_ndef_message_record_count( msg , &count );
246
247         dts_check_eq(__func__, ret, NET_NFC_OK, "net_nfc_get_ndef_message_record_count is failed");
248 }
249
250 static void utc_net_nfc_get_ndef_message_record_count_n(void)
251 {
252         int ret=0;
253
254         ret = net_nfc_get_ndef_message_record_count( NULL , NULL);
255
256         dts_check_ne(__func__, ret, NET_NFC_OK, "net_nfc_get_ndef_message_record_count not allow null");
257 }