2 #include <privilege_information.h>
10 static int fail_cnt = 0;
11 static int success_cnt = 0;
13 static void __change_color_to_red()
15 printf("%c[%d;%dm", 0x1B, BRIGHTNESS, RED);
18 static void __change_color_to_green()
20 printf("%c[%d;%dm", 0x1B, BRIGHTNESS, GREEN);
23 static void __change_color_to_yellow()
25 printf("%c[%d;%dm", 0x1B, BRIGHTNESS, YELLOW);
28 static void __change_color_to_origin()
30 printf("%c[%dm", 0x1B, 0);
33 static const char* __get_result_string(privilege_info_error_e ret)
35 if (ret == PRVINFO_ERROR_NONE)
36 return "PRVINFO_ERROR_NONE";
37 else if (ret == PRVINFO_ERROR_INVALID_PARAMETER)
38 return "PRVINFO_ERROR_INVALID_PARAMETER";
39 else if (ret == PRVINFO_ERROR_OUT_OF_MEMORY)
40 return "PRVINFO_ERROR_OUT_OF_MEMORY";
41 else if (ret == PRVINFO_ERROR_INTERNAL_ERROR)
42 return "PRVINFO_ERROR_INTERNAL_ERROR";
44 return "PRVINFO_ERROR_NO_MATCHED_ERROR_MESSAGE";
47 static void __check_get_privilege_display_name_result(privilege_info_error_e expected_result, privilege_info_error_e result, const char* display_name)
49 printf("expected result = %s, result = %s\n", __get_result_string(expected_result), __get_result_string(result));
51 if (expected_result != result) {
52 printf("not matched\n");
53 __change_color_to_red();
54 printf("test fail\n");
58 if (result == PRVINFO_ERROR_NONE) {
59 if (display_name == NULL) {
60 printf("display_name must not be NULL\n");
61 __change_color_to_red();
62 printf("test fail\n");
64 __change_color_to_origin();
67 printf("display_name = %s\n", display_name);
70 if (display_name != NULL) {
71 printf("display_name = %s\n", display_name);
72 printf("display_name must be NULL\n");
73 __change_color_to_red();
74 printf("test fail\n");
76 __change_color_to_origin();
80 __change_color_to_green();
81 printf("test success\n");
84 __change_color_to_origin();
88 static void __check_get_privilege_description_result(privilege_info_error_e expected_result, privilege_info_error_e result, const char* description)
90 printf("expected result = %s, result = %s\n", __get_result_string(expected_result), __get_result_string(result));
92 if (expected_result != result) {
93 printf("not matched\n");
94 __change_color_to_red();
95 printf("test fail\n");
99 if (result == PRVINFO_ERROR_NONE) {
100 if (description == NULL) {
101 printf("description must not be NULL\n");
102 __change_color_to_red();
103 printf("test fail\n");
105 __change_color_to_origin();
108 printf("description = %s\n", description);
111 if (description != NULL) {
112 printf("description = %s\n", description);
113 printf("description must be NULL\n");
114 __change_color_to_red();
115 printf("test fail\n");
117 __change_color_to_origin();
122 __change_color_to_green();
123 printf("test success\n");
126 __change_color_to_origin();
129 static void __test_privilege_info_get_display_name()
132 char* display_name = NULL;
134 printf("-----------------------------------------------------------\n");
135 printf("api_version : 2.3\n");
136 printf("privilege : http://tizen.org/privilege/window.priority.set\n");
137 printf("expected result : PRVINFO_ERROR_NONE\n");
138 ret = privilege_info_get_display_name("2.3", "http://tizen.org/privilege/window.priority.set", &display_name);
139 __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name);
141 printf("-----------------------------------------------------------\n");
142 printf("api_version : 2.3\n");
143 printf("privilege : http://tizen.org/privilege/mediacapture\n");
144 printf("expected result : PRVINFO_ERROR_NONE\n");
145 if (display_name != NULL) {
149 ret = privilege_info_get_display_name("2.3", "http://tizen.org/privilege/mediacapture", &display_name);
150 __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name);
152 printf("-----------------------------------------------------------\n");
153 printf("Not existing privilege\n");
154 printf("api_version : 2.3\n");
155 printf("privilege : http://tizen.org/privilege/RRRRRRRRRR\n");
156 printf("expected result : PRVINFO_ERROR_NONE\n");
157 if (display_name != NULL) {
161 ret = privilege_info_get_display_name("2.3", "http://tizen.org/privilege/RRRRRRRRRR", &display_name);
162 __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name);
164 printf("-----------------------------------------------------------\n");
165 printf("Invalid parameter\n");
166 printf("api_version : NULL\n");
167 printf("privilege : http://tizen.org/privilege/window.priority.set\n");
168 printf("expected result : PRVINFO_ERROR_NONE\n");
169 if (display_name != NULL) {
173 ret = privilege_info_get_display_name(NULL, "http://tizen.org/privilege/window, priority.set", &display_name);
174 __check_get_privilege_display_name_result(PRVINFO_ERROR_INVALID_PARAMETER, ret, display_name);
178 static void __test_privilege_info_get_display_name_by_pkgtype()
181 char* display_name = NULL;
183 printf("-----------------------------------------------------------\n");
184 printf("pkgtype : PRVINFO_PACKAGE_TYPE_NATIVE\n");
185 printf("api_version : 2.3\n");
186 printf("privilege : http://tizen.org/privilege/window.priority.set\n");
187 printf("expected result : PRVINFO_ERROR_NONE\n");
188 ret = privilege_info_get_display_name_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", "http://tizen.org/privilege/window.priority.set", &display_name);
189 __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name);
191 printf("-----------------------------------------------------------\n");
192 printf("pkgtype : PRVINFO_PACKAGE_TYPE_WEB\n");
193 printf("api_version : 2.3\n");
194 printf("privilege : http://tizen.org/privilege/mediacapture\n");
195 printf("expected result : PRVINFO_ERROR_NONE\n");
196 if (display_name != NULL) {
200 ret = privilege_info_get_display_name_by_pkgtype("PRVINFO_PACKAGE_TYPE_WEB", "2.3", "http://tizen.org/privilege/mediacapture", &display_name);
201 __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name);
203 printf("-----------------------------------------------------------\n");
204 printf("Mismatched package type: write WEB as NATIVE\n");
205 printf("pkgtype : PRVINFO_PACKAGE_TYPE_NATIVE\n");
206 printf("api_version : 2.3\n");
207 printf("privilege : http://tizen.org/privilege/mediacapture\n");
208 printf("expected result : PRVINFO_ERROR_NONE\n");
209 if (display_name != NULL) {
213 ret = privilege_info_get_display_name_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", "http://tizen.org/privilege/mediacapture", &display_name);
214 __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name);
217 printf("-----------------------------------------------------------\n");
218 printf("Not existing privilege\n");
219 printf("api_version : 2.3\n");
220 printf("privilege : http://tizen.org/privilege/RRRRRRRRRR\n");
221 printf("expected result : PRVINFO_ERROR_NONE\n");
222 if (display_name != NULL) {
226 ret = privilege_info_get_display_name_by_pkgtype("PRVINFO_PACKAGE_TYPE_WEB", "2.3", "http://tizen.org/privilege/RRRRRRRRRR", &display_name);
227 __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name);
229 printf("-----------------------------------------------------------\n");
230 printf("Invalid parameter\n");
231 printf("api_version : 2.3\n");
232 printf("privilege : http://tizen.org/privilege/mediacapture\n");
233 printf("expected result : PRVINFO_ERROR_NONE\n");
234 if (display_name != NULL) {
238 ret = privilege_info_get_display_name_by_pkgtype(NULL, "2.3", "http://tizen.org/privilege/mediacapture", &display_name);
239 __check_get_privilege_display_name_result(PRVINFO_ERROR_INVALID_PARAMETER, ret, display_name);
244 static void __test_privilege_info_get_description()
247 char* description = NULL;
249 printf("-----------------------------------------------------------\n");
250 printf("api_version : 2.3\n");
251 printf("privilege : http://tizen.org/privilege/window.priority.set\n");
252 printf("expected result : PRVINFO_ERROR_NONE\n");
253 ret = privilege_info_get_description("2.3", "http://tizen.org/privilege/window.priority.set", &description);
254 __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description);
256 printf("-----------------------------------------------------------\n");
257 printf("api_version : 2.3\n");
258 printf("privilege : http://tizen.org/privilege/mediacapture\n");
259 printf("expected result : PRVINFO_ERROR_NONE\n");
260 if (description != NULL) {
264 ret = privilege_info_get_description("2.3", "http://tizen.org/privilege/mediacapture", &description);
265 __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description);
267 printf("-----------------------------------------------------------\n");
268 printf("Not existing privilege\n");
269 printf("api_version : 2.3\n");
270 printf("privilege : http://tizen.org/privilege/RRRRRRRRRR\n");
271 printf("expected result : PRVINFO_ERROR_NONE\n");
272 if (description != NULL) {
276 ret = privilege_info_get_description("2.3", "http://tizen.org/privilege/RRRRRRRRRR", &description);
277 __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description);
279 printf("-----------------------------------------------------------\n");
280 printf("Invalid parameter\n");
281 printf("api_version : 2.3\n");
282 printf("privilege : http://tizen.org/privilege/mediacapture\n");
283 printf("expected result : PRVINFO_ERROR_NONE\n");
284 if (description != NULL) {
288 ret = privilege_info_get_description(NULL, "http://tizen.org/privilege/mediacapture", &description);
289 __check_get_privilege_description_result(PRVINFO_ERROR_INVALID_PARAMETER, ret, description);
294 static void __test_privilege_info_get_description_by_pkgtype()
297 char* description = NULL;
299 printf("-----------------------------------------------------------\n");
300 printf("api_version : 2.3\n");
301 printf("privilege : http://tizen.org/privilege/window.priority.set\n");
302 printf("expected result : PRVINFO_ERROR_NONE\n");
303 ret = privilege_info_get_description_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", "http://tizen.org/privilege/window.priority.set", &description);
304 __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description);
306 printf("-----------------------------------------------------------\n");
307 printf("api_version : 2.3\n");
308 printf("privilege : http://tizen.org/privilege/mediacapture\n");
309 printf("expected result : PRVINFO_ERROR_NONE\n");
310 if (description != NULL) {
314 ret = privilege_info_get_description_by_pkgtype("PRVINFO_PACKAGE_TYPE_WEB", "2.3", "http://tizen.org/privilege/mediacapture", &description);
315 __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description);
317 printf("-----------------------------------------------------------\n");
318 printf("Mismatched package type: write WEB as NATIVE\n");
319 printf("pkgtype : PRVINFO_PACKAGE_TYPE_NATIVE\n");
320 printf("api_version : 2.3\n");
321 printf("privilege : http://tizen.org/privilege/mediacapture\n");
322 printf("expected result : PRVINFO_ERROR_NONE\n");
323 if (description != NULL) {
327 ret = privilege_info_get_description_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", "http://tizen.org/privilege/mediacapture", &description);
328 __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description);
330 printf("-----------------------------------------------------------\n");
331 printf("Not existing privilege\n");
332 printf("api_version : 2.3\n");
333 printf("privilege : http://tizen.org/privilege/RRRRRRRRRR\n");
334 printf("expected result : PRVINFO_ERROR_NONE\n");
335 if (description != NULL) {
339 ret = privilege_info_get_description_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", "http://tizen.org/privilege/RRRRRRRRRR", &description);
340 __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description);
342 printf("-----------------------------------------------------------\n");
343 printf("Invalid parameter\n");
344 printf("api_version : 2.3\n");
345 printf("privilege : NULL\n");
346 printf("expected result : PRVINFO_ERROR_INVALID_PARAMETER\n");
347 if (description != NULL) {
351 ret = privilege_info_get_description_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", NULL, &description);
352 __check_get_privilege_description_result(PRVINFO_ERROR_INVALID_PARAMETER, ret, description);
359 __change_color_to_yellow();
360 printf("Test function : privilege_info_get_display_name\n");
361 __change_color_to_origin();
362 __test_privilege_info_get_display_name();
364 __change_color_to_yellow();
365 printf("Test function : privilege_info_get_display_name_by_pkgtype\n");
366 __change_color_to_origin();
367 __test_privilege_info_get_display_name_by_pkgtype();
369 __change_color_to_yellow();
370 printf("Test function : privilege_info_get_description\n");
371 __change_color_to_origin();
372 __test_privilege_info_get_description();
374 __change_color_to_yellow();
375 printf("Test function : privilege_info_get_description_by_pkgtype\n");
376 __change_color_to_origin();
377 __test_privilege_info_get_description_by_pkgtype();
379 __change_color_to_green();
380 printf("Test Complete\n");
381 printf("success : %d, ", success_cnt);
382 __change_color_to_red();
383 printf("fail : %d\n", fail_cnt);
384 __change_color_to_origin();