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";
45 static void __check_get_privilege_display_name_result(privilege_info_error_e expected_result, privilege_info_error_e result, const char* display_name)
47 printf("expected result = %s, result = %s\n", __get_result_string(expected_result), __get_result_string(result));
49 if (expected_result != result) {
50 printf("not matched\n");
51 __change_color_to_red();
52 printf("test fail\n");
56 if (result == PRVINFO_ERROR_NONE) {
57 if (display_name == NULL) {
58 printf("display_name must not be NULL\n");
59 __change_color_to_red();
60 printf("test fail\n");
62 __change_color_to_origin();
65 printf("display_name = %s\n", display_name);
68 if (display_name != NULL) {
69 printf("display_name = %s\n", display_name);
70 printf("display_name must be NULL\n");
71 __change_color_to_red();
72 printf("test fail\n");
74 __change_color_to_origin();
78 __change_color_to_green();
79 printf("test success\n");
82 __change_color_to_origin();
86 static void __check_get_privilege_description_result(privilege_info_error_e expected_result, privilege_info_error_e result, const char* description)
88 printf("expected result = %s, result = %s\n", __get_result_string(expected_result), __get_result_string(result));
90 if (expected_result != result) {
91 printf("not matched\n");
92 __change_color_to_red();
93 printf("test fail\n");
97 if (result == PRVINFO_ERROR_NONE) {
98 if (description == NULL) {
99 printf("description must not be NULL\n");
100 __change_color_to_red();
101 printf("test fail\n");
103 __change_color_to_origin();
106 printf("description = %s\n", description);
109 if (description != NULL) {
110 printf("description = %s\n", description);
111 printf("description must be NULL\n");
112 __change_color_to_red();
113 printf("test fail\n");
115 __change_color_to_origin();
120 __change_color_to_green();
121 printf("test success\n");
124 __change_color_to_origin();
127 static void __test_privilege_info_get_display_name()
130 char* display_name = NULL;
132 printf("-----------------------------------------------------------\n");
133 printf("api_version : 2.3\n");
134 printf("privilege : http://tizen.org/privilege/window.priority.set\n");
135 printf("expected result : PRVINFO_ERROR_NONE\n");
136 ret = privilege_info_get_display_name("2.3", "http://tizen.org/privilege/window.priority.set", &display_name);
137 __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name);
139 printf("-----------------------------------------------------------\n");
140 printf("api_version : 2.3\n");
141 printf("privilege : http://tizen.org/privilege/mediacapture\n");
142 printf("expected result : PRVINFO_ERROR_NONE\n");
143 if (display_name != NULL) {
147 ret = privilege_info_get_display_name("2.3", "http://tizen.org/privilege/mediacapture", &display_name);
148 __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name);
150 printf("-----------------------------------------------------------\n");
151 printf("Not existing privilege\n");
152 printf("api_version : 2.3\n");
153 printf("privilege : http://tizen.org/privilege/RRRRRRRRRR\n");
154 printf("expected result : PRVINFO_ERROR_NONE\n");
155 if (display_name != NULL) {
159 ret = privilege_info_get_display_name("2.3", "http://tizen.org/privilege/RRRRRRRRRR", &display_name);
160 __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name);
162 printf("-----------------------------------------------------------\n");
163 printf("Invalid parameter\n");
164 printf("api_version : NULL\n");
165 printf("privilege : http://tizen.org/privilege/window.priority.set\n");
166 printf("expected result : PRVINFO_ERROR_NONE\n");
167 if (display_name != NULL) {
171 ret = privilege_info_get_display_name(NULL, "http://tizen.org/privilege/window, priority.set", &display_name);
172 __check_get_privilege_display_name_result(PRVINFO_ERROR_INVALID_PARAMETER, ret, display_name);
176 static void __test_privilege_info_get_display_name_by_pkgtype()
179 char* display_name = NULL;
181 printf("-----------------------------------------------------------\n");
182 printf("pkgtype : PRVINFO_PACKAGE_TYPE_NATIVE\n");
183 printf("api_version : 2.3\n");
184 printf("privilege : http://tizen.org/privilege/window.priority.set\n");
185 printf("expected result : PRVINFO_ERROR_NONE\n");
186 ret = privilege_info_get_display_name_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", "http://tizen.org/privilege/window.priority.set", &display_name);
187 __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name);
189 printf("-----------------------------------------------------------\n");
190 printf("pkgtype : PRVINFO_PACKAGE_TYPE_WEB\n");
191 printf("api_version : 2.3\n");
192 printf("privilege : http://tizen.org/privilege/mediacapture\n");
193 printf("expected result : PRVINFO_ERROR_NONE\n");
194 if (display_name != NULL) {
198 ret = privilege_info_get_display_name_by_pkgtype("PRVINFO_PACKAGE_TYPE_WEB", "2.3", "http://tizen.org/privilege/mediacapture", &display_name);
199 __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name);
201 printf("-----------------------------------------------------------\n");
202 printf("Mismatched package type: write WEB as NATIVE\n");
203 printf("pkgtype : PRVINFO_PACKAGE_TYPE_NATIVE\n");
204 printf("api_version : 2.3\n");
205 printf("privilege : http://tizen.org/privilege/mediacapture\n");
206 printf("expected result : PRVINFO_ERROR_NONE\n");
207 if (display_name != NULL) {
211 ret = privilege_info_get_display_name_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", "http://tizen.org/privilege/mediacapture", &display_name);
212 __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name);
215 printf("-----------------------------------------------------------\n");
216 printf("Not existing privilege\n");
217 printf("api_version : 2.3\n");
218 printf("privilege : http://tizen.org/privilege/RRRRRRRRRR\n");
219 printf("expected result : PRVINFO_ERROR_NONE\n");
220 if (display_name != NULL) {
224 ret = privilege_info_get_display_name_by_pkgtype("PRVINFO_PACKAGE_TYPE_WEB", "2.3", "http://tizen.org/privilege/RRRRRRRRRR", &display_name);
225 __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name);
227 printf("-----------------------------------------------------------\n");
228 printf("Invalid parameter\n");
229 printf("api_version : 2.3\n");
230 printf("privilege : http://tizen.org/privilege/mediacapture\n");
231 printf("expected result : PRVINFO_ERROR_NONE\n");
232 if (display_name != NULL) {
236 ret = privilege_info_get_display_name_by_pkgtype(NULL, "2.3", "http://tizen.org/privilege/mediacapture", &display_name);
237 __check_get_privilege_display_name_result(PRVINFO_ERROR_INVALID_PARAMETER, ret, display_name);
242 static void __test_privilege_info_get_description()
245 char* description = NULL;
247 printf("-----------------------------------------------------------\n");
248 printf("api_version : 2.3\n");
249 printf("privilege : http://tizen.org/privilege/window.priority.set\n");
250 printf("expected result : PRVINFO_ERROR_NONE\n");
251 ret = privilege_info_get_description("2.3", "http://tizen.org/privilege/window.priority.set", &description);
252 __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description);
254 printf("-----------------------------------------------------------\n");
255 printf("api_version : 2.3\n");
256 printf("privilege : http://tizen.org/privilege/mediacapture\n");
257 printf("expected result : PRVINFO_ERROR_NONE\n");
258 if (description != NULL) {
262 ret = privilege_info_get_description("2.3", "http://tizen.org/privilege/mediacapture", &description);
263 __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description);
265 printf("-----------------------------------------------------------\n");
266 printf("Not existing privilege\n");
267 printf("api_version : 2.3\n");
268 printf("privilege : http://tizen.org/privilege/RRRRRRRRRR\n");
269 printf("expected result : PRVINFO_ERROR_NONE\n");
270 if (description != NULL) {
274 ret = privilege_info_get_description("2.3", "http://tizen.org/privilege/RRRRRRRRRR", &description);
275 __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description);
277 printf("-----------------------------------------------------------\n");
278 printf("Invalid parameter\n");
279 printf("api_version : 2.3\n");
280 printf("privilege : http://tizen.org/privilege/mediacapture\n");
281 printf("expected result : PRVINFO_ERROR_NONE\n");
282 if (description != NULL) {
286 ret = privilege_info_get_description(NULL, "http://tizen.org/privilege/mediacapture", &description);
287 __check_get_privilege_description_result(PRVINFO_ERROR_INVALID_PARAMETER, ret, description);
292 static void __test_privilege_info_get_description_by_pkgtype()
295 char* description = NULL;
297 printf("-----------------------------------------------------------\n");
298 printf("api_version : 2.3\n");
299 printf("privilege : http://tizen.org/privilege/window.priority.set\n");
300 printf("expected result : PRVINFO_ERROR_NONE\n");
301 ret = privilege_info_get_description_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", "http://tizen.org/privilege/window.priority.set", &description);
302 __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description);
304 printf("-----------------------------------------------------------\n");
305 printf("api_version : 2.3\n");
306 printf("privilege : http://tizen.org/privilege/mediacapture\n");
307 printf("expected result : PRVINFO_ERROR_NONE\n");
308 if (description != NULL) {
312 ret = privilege_info_get_description_by_pkgtype("PRVINFO_PACKAGE_TYPE_WEB", "2.3", "http://tizen.org/privilege/mediacapture", &description);
313 __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description);
315 printf("-----------------------------------------------------------\n");
316 printf("Mismatched package type: write WEB as NATIVE\n");
317 printf("pkgtype : PRVINFO_PACKAGE_TYPE_NATIVE\n");
318 printf("api_version : 2.3\n");
319 printf("privilege : http://tizen.org/privilege/mediacapture\n");
320 printf("expected result : PRVINFO_ERROR_NONE\n");
321 if (description != NULL) {
325 ret = privilege_info_get_description_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", "http://tizen.org/privilege/mediacapture", &description);
326 __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description);
328 printf("-----------------------------------------------------------\n");
329 printf("Not existing privilege\n");
330 printf("api_version : 2.3\n");
331 printf("privilege : http://tizen.org/privilege/RRRRRRRRRR\n");
332 printf("expected result : PRVINFO_ERROR_NONE\n");
333 if (description != NULL) {
337 ret = privilege_info_get_description_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", "http://tizen.org/privilege/RRRRRRRRRR", &description);
338 __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description);
340 printf("-----------------------------------------------------------\n");
341 printf("Invalid parameter\n");
342 printf("api_version : 2.3\n");
343 printf("privilege : NULL\n");
344 printf("expected result : PRVINFO_ERROR_INVALID_PARAMETER\n");
345 if (description != NULL) {
349 ret = privilege_info_get_description_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", NULL, &description);
350 __check_get_privilege_description_result(PRVINFO_ERROR_INVALID_PARAMETER, ret, description);
357 __change_color_to_yellow();
358 printf("Test function : privilege_info_get_display_name\n");
359 __change_color_to_origin();
360 __test_privilege_info_get_display_name();
362 __change_color_to_yellow();
363 printf("Test function : privilege_info_get_display_name_by_pkgtype\n");
364 __change_color_to_origin();
365 __test_privilege_info_get_display_name_by_pkgtype();
367 __change_color_to_yellow();
368 printf("Test function : privilege_info_get_description\n");
369 __change_color_to_origin();
370 __test_privilege_info_get_description();
372 __change_color_to_yellow();
373 printf("Test function : privilege_info_get_description_by_pkgtype\n");
374 __change_color_to_origin();
375 __test_privilege_info_get_description_by_pkgtype();
377 __change_color_to_green();
378 printf("Test Complete\n");
379 printf("success : %d, ", success_cnt);
380 __change_color_to_red();
381 printf("fail : %d\n", fail_cnt);
382 __change_color_to_origin();