Fix resource leak
[platform/core/security/privilege-info.git] / test / tc_privilege_info_app_privacy.c
1 #include <stdio.h>
2 #include <dlog.h>
3 #include <stdbool.h>
4 #include <privilege_information.h>
5
6 #ifdef LOG_TAG
7 #undef LOG_TAG
8 #define LOG_TAG "PRIVILEGE_INFO_TEST_APP"
9 #endif
10
11
12 static int fail_cnt = 0;
13 static int success_cnt = 0;
14
15 static const char *__get_result_string(privilege_info_error_e ret)
16 {
17         if (ret == PRVINFO_ERROR_NONE)
18                 return "PRVINFO_ERROR_NONE";
19         else if (ret == PRVINFO_ERROR_INVALID_PARAMETER)
20                 return "PRVINFO_ERROR_INVALID_PARAMETER";
21         else if (ret == PRVINFO_ERROR_INTERNAL_ERROR)
22                 return "PRVINFO_ERROR_INTERNAL_ERROR";
23         else if (ret == PRVINFO_ERROR_OUT_OF_MEMORY)
24                 return "PRVINFO_ERROR_UNDECLARED_PRIVILEGE";
25         else
26                 return "FAIL";
27 }
28
29 static void __check_result(privilege_info_error_e expected_result, privilege_info_error_e result, bool expected_status, bool status)
30 {
31         LOGD("expected result = %s, result = %s", __get_result_string(expected_result), __get_result_string(result));
32         LOGD("expected status = %s, status = %s", expected_status ? "true" : "false", status ? "true" : "false");
33
34         if (expected_result != result) {
35                 LOGD("test fail");
36                 fail_cnt++;
37         } else {
38                 if (expected_status != status) {
39                         LOGD("test fail");
40                         fail_cnt++;
41                 } else {
42                         LOGD("test success");
43                         success_cnt++;
44                 }
45         }
46 }
47
48 static void __test_privilege_info_get_privacy_privilege_status()
49 {
50         int ret = PRVINFO_ERROR_NONE;
51         bool status;
52
53         LOGD("-----------------------------------------------------------");
54         LOGD("privilege : http://tizen.org/privilege/account.read");
55         LOGD("expected result : PRVINFO_ERROR_NONE");
56         ret = privilege_info_get_privacy_privilege_status("http://tizen.org/privilege/account.read", &status);
57         __check_result(PRVINFO_ERROR_NONE, ret, true, status);
58         LOGD("-----------------------------------------------------------");
59
60         LOGD("privilege : http://tizen.org/privilege/contact.read");
61         LOGD("expected result : PRVINFO_ERROR_NONE");
62         ret = privilege_info_get_privacy_privilege_status("http://tizen.org/privilege/contact.read", &status);
63         __check_result(PRVINFO_ERROR_NONE, ret, false, status);
64         LOGD("-----------------------------------------------------------");
65
66         LOGD("privilege : http://tizen.org/privilege/aaaaa");
67         LOGD("expected result : PRVINFO_ERROR_INVALID_PARAMETER");
68         ret = privilege_info_get_privacy_privilege_status("http://tizen.org/privilege/aaaaa", &status);
69         __check_result(PRVINFO_ERROR_INVALID_PARAMETER, ret, true, status);
70         LOGD("-----------------------------------------------------------");
71
72 }
73
74 int main()
75 {
76         LOGD("Test function : privilege_info_get_privacy_privilege_status");
77         __test_privilege_info_get_privacy_privilege_status();
78
79         LOGD("====================================");
80         LOGD("Test Complete");
81         LOGD("success : %d, ", success_cnt);
82         LOGD("fail : %d", fail_cnt);
83         LOGD("====================================");
84
85         return 0;
86 }