Add test case privilege_db_manager_get_privacy_id_by_privilege for privilege_db_manag... 64/315364/2
authortranthanhtung2001 <tran.tung@samsung.com>
Tue, 21 Nov 2023 22:07:15 +0000 (05:07 +0700)
committertranthanhtung2001 <tran.tung@samsung.com>
Tue, 21 Nov 2023 22:13:33 +0000 (05:13 +0700)
Change-Id: I2b163c33250352919efd8d8db9eedbd909de21ba
Signed-off-by: tranthanhtung2001 <tran.tung@samsung.com>
test/privilege-checker.c
test/tc-privilege-db-manager.c

index e5be79e..a8c3270 100644 (file)
@@ -33,6 +33,7 @@ extern void __test_privilege_db_manager_get_mapped_privilege_list();
 extern void __test_privilege_db_manager_get_privilege_display();
 extern void __test_privilege_db_manager_get_privilege_description();
 extern void __test_privilege_db_manager_get_privacy_by_privilege();
+extern void __test_privilege_db_manager_get_privacy_id_by_privilege();
 extern void __test_privilege_db_manager_is_privacy_white_list();
 extern void __test_privilege_db_manager_get_privacy_id();
 extern void __test_privilege_db_manager_is_user_settable();
@@ -157,9 +158,12 @@ int main()
        __tcinfo(function, "privilege_db_manager_get_privilege_description");
        __test_privilege_db_manager_get_privilege_description();
 
-       __tcinfo(function, "privilege_db_manager_get_privacy_id_by_privilege, privilege_db_manager_get_privacy_by_privilege");
+       __tcinfo(function, "privilege_db_manager_get_privacy_by_privilege");
        __test_privilege_db_manager_get_privacy_by_privilege();
 
+       __tcinfo(function, "privilege_db_manager_get_privacy_id_by_privilege");
+       __test_privilege_db_manager_get_privacy_id_by_privilege();
+
        __tcinfo(function, "privilege_db_manager_is_privacy_white_list");
        __test_privilege_db_manager_is_privacy_white_list();
 
index 5370a81..2434638 100644 (file)
@@ -37,6 +37,32 @@ static bool __check_result_code_and_string(char type, int expected_result, int a
        return ret;
 }
 
+static bool __check_result_code_and_integer(
+       char type,
+       int expected_result,
+       int achieved_result,
+       int expected_ret,
+       int achieved_ret)
+{
+       bool isFalse = __check_the_return_code(type, expected_result, achieved_result);
+
+       if (isFalse)
+               return false;
+
+       printf("\texpected data: %d\n\tactual data: %d\n", expected_ret, achieved_ret);
+
+       if (expected_ret == achieved_ret) {
+               printf("---> VALID\n");
+               return true;
+       } else {
+               printf("---> INVALID\n");
+               printf_red("TEST RESULT: FAILED\n");
+               fail_cnt++;
+               success_cnt--;
+               return false;
+       }
+}
+
 void __check_result_code_and_list(
        GList *expected_list,
        GList *achieved_list,
@@ -471,6 +497,35 @@ void __test_privilege_db_manager_get_privacy_by_privilege()
        privacy_name = NULL;
 }
 
+void __test_privilege_db_manager_get_privacy_id_by_privilege()
+{
+       __print_line();
+
+       int privacy_id;
+       int expected_privacy_id;
+       char *privilege = "http://tizen.org/privilege/account.read";
+
+       __tcinfo(goal, POS_TC_PREFIX "get privacy id by privilege");
+
+       expected_privacy_id = 0;
+       printf("privilege: %s\n", privilege);
+
+       int ret = privilege_db_manager_get_privacy_id_by_privilege(privilege, &privacy_id);
+       __check_result_code_and_integer('d', PRIVILEGE_DB_MANAGER_ERR_NONE, ret, expected_privacy_id, privacy_id);
+
+       __tcinfo(goal, NEG_TC_PREFIX "get privacy id by privilege with privilege parameter does not exist");
+
+       privilege = "http://tizen.org/privilege/fakeData";
+       expected_privacy_id = 99999;
+       privacy_id = 99999;
+
+       printf("privilege: %s\n", privilege);
+
+       ret = privilege_db_manager_get_privacy_id_by_privilege(privilege, &privacy_id);
+       __check_result_code_and_integer('d', PRIVILEGE_DB_MANAGER_ERR_NO_EXIST_RESULT, ret, expected_privacy_id, privacy_id);
+
+}
+
 void __test_privilege_db_manager_is_privacy_white_list()
 {
        int ret = 0;