#include <privilege_db_manager.h>
#include <tc-common.h>
+void __check_result_code_and_list(
+ GList *expected_list,
+ GList *achieved_list,
+ int expected_result,
+ int achieved_result,
+ bool is_single_data_at_node,
+ char type)
+{
+ bool isFalse = __check_the_return_code(type, expected_result, achieved_result);
+
+ if (isFalse)
+ return;
+
+ GList *l = expected_list;
+ GList *l1 = achieved_list;
+
+ if (g_list_length(expected_list) != g_list_length(achieved_list)) {
+ printf("EXPECTED LIST LENGTH DONT MATCH ACHIEVED LIST LENGTH\n");
+ fail_cnt++;
+ success_cnt--;
+ return;
+ }
+
+ while (l != NULL && l1 != NULL) {
+
+ printf("--- Check content: \n");
+
+ if (is_single_data_at_node) {
+ printf("\texpected data: %s\n\tactual data: %s\n", (char*)l->data, (char*)l1->data);
+
+ if (strcmp((char*)l->data, (char*)l1->data)) {
+ printf("---> INVALID\n");
+ fail_cnt++;
+ success_cnt--;
+ return;
+ }
+ } else {
+ privilege_privacy_info_s *p = l->data;
+ privilege_privacy_info_s *p1 = l1->data;
+
+ printf("\texpected privilege name: %s\n\tactual privilege name: %s\n", p->privilege_name, p1->privilege_name);
+ printf("\texpected privacy name: %s\n\tactual privacy name: %s\n", p->privacy_name, p1->privacy_name);
+
+ if (strcmp(p->privilege_name, p1->privilege_name) || strcmp(p->privacy_name, p1->privacy_name)) {
+ printf("---> INVALID\n");
+ fail_cnt++;
+ success_cnt--;
+ return;
+ }
+ }
+
+ printf("---> VALID\n");
+ l = l->next;
+ l1 = l1->next;
+ }
+}
+
static void __free_privilege_list(GList * privilege_list)
{
GList *l = NULL;
}
}
-
void __test_privilege_db_manager_get_privilege_level_info_list()
{
GList *privilege_list = NULL;
void __test_privilege_db_manager_set_package_privacy_privilege_info()
{
- __print_line();
-
- int ret = PRIVILEGE_DB_MANAGER_ERR_NONE;
GList* privilege_list = NULL;
privilege_privacy_info_s p;
char *pkgid = "attach-panel-camera";
char *api_version = "5.5";
- printf("uid = %d\npkgid = %s\napi_version = %s\nprivilege_privacy {privilege_name = %s privacy_name = %s}\n",
- uid, pkgid, api_version, p.privilege_name, p.privacy_name);
-
- ret = privilege_db_manager_set_package_privacy_privilege_info(uid, pkgid, api_version, privilege_list);
-
- printf("- EXPECTED RESULT : %d\n", PRIVILEGE_DB_MANAGER_ERR_NONE);
- printf("- ACHIEVED RESULT : %d\n", ret);
-
- if(ret == PRIVILEGE_DB_MANAGER_ERR_NONE){
- printf("match\n");
- success_cnt++;
- printf_green("success\n");
- }else{
- printf("don't match\n");
- fail_cnt++;
- printf_red("fail\n");
- }
-
- __print_line();
-
- privilege_list = NULL;
-
- p.privilege_name = "http://tizen.org/privilege/externalstorage";
- p.privacy_name = "http://tizen.org/privacy/storage";
- privilege_list = g_list_append(privilege_list, &p);
-
- uid = 5001;
- pkgid = "cert-svc-ui";
- api_version = "3.0";
+ __tcinfo(goal, POS_TC_PREFIX "set package privacy privilege info");
printf("uid = %d\npkgid = %s\napi_version = %s\nprivilege_privacy {privilege_name = %s privacy_name = %s}\n",
- uid, pkgid, api_version, p.privilege_name, p.privacy_name);
+ uid, pkgid, api_version, p.privilege_name, p.privacy_name);
- ret = privilege_db_manager_set_package_privacy_privilege_info(uid, pkgid, api_version, privilege_list);
+ int ret = privilege_db_manager_set_package_privacy_privilege_info(uid, pkgid, api_version, privilege_list);
- printf("- EXPECTED RESULT : %d\n", PRIVILEGE_DB_MANAGER_ERR_NONE);
- printf("- ACHIEVED RESULT : %d\n", ret);
+ __check_the_return_code('d', PRIVILEGE_DB_MANAGER_ERR_NONE, ret);
- if(ret == PRIVILEGE_DB_MANAGER_ERR_NONE){
- printf("match\n");
- success_cnt++;
- printf_green("success\n");
- }else{
- printf("don't match");
- fail_cnt++;
- printf_red("fail\n");
- }
privilege_list = NULL;
}
{
__print_line();
- int ret = PRIVILEGE_DB_MANAGER_ERR_NONE;
-
uid_t uid = 5001;
char *pkgid = "attach-panel-camera";
+ __tcinfo(goal, POS_TC_PREFIX "unset package privacy privilege info");
printf("uid = %d\npkgid = %s\n", uid, pkgid);
- ret = privilege_db_manager_unset_package_privilege_info(uid, pkgid);
-
- printf("- EXPECTED RESULT : %d\n", PRIVILEGE_DB_MANAGER_ERR_NONE);
- printf("- ACHIEVED RESULT : %d\n", ret);
-
- if(ret == PRIVILEGE_DB_MANAGER_ERR_NONE){
- printf("match\n");
- success_cnt++;
- printf_green("success\n");
- }else{
- printf("don't match");
- fail_cnt++;
- printf_red("fail\n");
- }
-
- __print_line();
-
- uid = 5001;
- pkgid = "jadjasffjf";
-
- printf("uid = %d\npkgid = %s\n", uid, pkgid);
-
- ret = privilege_db_manager_unset_package_privilege_info(uid, pkgid);
-
- printf("- EXPECTED RESULT : %d\n", PRIVILEGE_DB_MANAGER_ERR_NONE);
- printf("- ACHIEVED RESULT : %d\n", ret);
+ int ret = privilege_db_manager_unset_package_privilege_info(uid, pkgid);
- if(ret == PRIVILEGE_DB_MANAGER_ERR_NONE){
- printf("match\n");
- success_cnt++;
- printf_green("success\n");
- }else{
- printf("don't match");
- fail_cnt++;
- printf_red("fail\n");
- }
+ __check_the_return_code('d', PRIVILEGE_DB_MANAGER_ERR_NONE, ret);
}
void __test_privilege_db_manager_is_privacy_requestable()
{
__print_line();
- int expected_ret = PRIVILEGE_DB_MANAGER_ERR_NONE;
bool expected_is_privacy_requestable = false;
bool is_privacy_requestable;
+ privilege_privacy_info_s p;
uid_t uid = 5001;
char *pkgid = "cert-svc-ui";
+ char *api_version = "3.0";
char *privilege = "http://tizen.org/privilege/externalstorage";
privilege_manager_package_type_e prvmgr_package_type_e = PRVMGR_PACKAGE_TYPE_CORE;
- printf("uid = %d\npkgid = %s\nprivilege = %s\nprvmgr_package_type_e %d\n",
- uid, pkgid, privilege, prvmgr_package_type_e);
+ p.privilege_name = privilege;
+ p.privacy_name = "http://tizen.org/privacy/storage";
+ privilege_list = g_list_append(privilege_list, &p);
- printf("- EXPECTED RESULT:\nexpected_ret = %d\nexpected_is_privacy_requestable = %d\n",
- expected_ret, expected_is_privacy_requestable);
+ privilege_db_manager_set_package_privacy_privilege_info(uid, pkgid, api_version, privilege_list);
- int ret = privilege_db_manager_is_privacy_requestable(uid, pkgid, privilege,
- prvmgr_package_type_e, &is_privacy_requestable);
+ __tcinfo(goal, NEG_TC_PREFIX "privacy requestable is false");
- printf("- ACHIEVED RESULT:\nret = %d\nis_privacy_requestable = %d\n",
- ret, is_privacy_requestable);
+ printf("uid = %d\npkgid = %s\nprivilege = %s\nprvmgr package type e = %d\n",
+ uid, pkgid, privilege, prvmgr_package_type_e);
- if(ret == expected_ret && is_privacy_requestable == expected_is_privacy_requestable){
- printf("match\n");
- success_cnt++;
- printf_green("success\n");
- }else{
- printf("don't match");
- fail_cnt++;
- printf_red("fail\n");
+ int ret = privilege_db_manager_is_privacy_requestable(
+ uid,
+ pkgid,
+ privilege,
+ prvmgr_package_type_e,
+ &is_privacy_requestable);
+
+ bool isDiff = __check_the_return_code('d', PRIVILEGE_DB_MANAGER_ERR_NONE, ret);
+
+ if (!isDiff) {
+ printf("EXPECTED REQUESTABLE: %d, RETURNED REQUESTABLE : %d\n",
+ expected_is_privacy_requestable, is_privacy_requestable);
+
+ if (expected_is_privacy_requestable == is_privacy_requestable) {
+ printf_green("RESULT MATCH\n");
+ } else {
+ printf_red("RESULT DONT MATCH\n");
+ fail_cnt++;
+ success_cnt--;
+ }
}
+
+ privilege_list = NULL;
}
void __test_privilege_db_manager_get_all_privacy_package_list()
GList *expected_package_list = NULL;
uid_t uid = 5001;
- int expected_ret = PRIVILEGE_DB_MANAGER_ERR_NONE;
- char *pkgname = NULL;
+ char *pkg0 = "cert-svc-ui";
+ char *pkg1 = "org.test.nativeapp_3";
- pkgname = "cert-svc-ui";
- expected_package_list = g_list_append(expected_package_list, pkgname);
+ expected_package_list = g_list_append(expected_package_list, pkg0);
+ expected_package_list = g_list_append(expected_package_list, pkg1);
- printf("uid = %d\n", uid);
+ __tcinfo(goal, POS_TC_PREFIX "get all privacy package list");
- printf("- EXPECTED RESULT:\nexpected_ret = %d\n", expected_ret);
- printf("package_list :\n");
- __print_glist(expected_package_list);
+ printf("uid = %d\n", uid);
int ret = privilege_db_manager_get_all_privacy_package_list(uid, &package_list);
- printf("- ACHIEVED RESULT:\nret = %d\n", ret);
- printf("package_list :\n");
- __print_glist(package_list);
-
- bool success = true;
- if(ret != expected_ret){
- success = false;
- }
-
- GList *l = package_list;
- GList *l1 = expected_package_list;
-
- while (l != NULL && l1 != NULL && success)
- {
- if(strcmp((char*)l->data, (char*)l1->data)){
- printf("don't match\n");
- success = false;
- break;
- }
- l = l->next;
- l1 = l1->next;
- }
+ __check_result_code_and_list(expected_package_list, package_list, PRIVILEGE_DB_MANAGER_ERR_NONE, ret, true, 'd');
- if(success){
- printf("match\n");
- success_cnt++;
- printf_green("success\n");
- }else{
- printf("don't match\n");
- fail_cnt++;
- printf_red("fail\n");
- }
g_list_free_full(package_list, free);
}
GList *expected_privacy_list = NULL;
uid_t uid = 5001;
- char *expected_ret = __get_result_string('d', PRIVILEGE_DB_MANAGER_ERR_NONE);
-
char *pkgid = "cert-svc-ui";
char *privacy_name = "http://tizen.org/privacy/storage";
expected_privacy_list = g_list_append(expected_privacy_list, privacy_name);
- printf("uid = %d\npkgid = %s\n", uid, pkgid);
+ __tcinfo(goal, POS_TC_PREFIX "get all privacy list by pkgid");
- printf("- EXPECTED RESULT:\nexpected_ret = %s\n", expected_ret);
- printf("privacy_list :\n");
- __print_glist(expected_privacy_list);
+ printf("uid = %d\npkgid = %s\n", uid, pkgid);
int ret = privilege_db_manager_get_privacy_list_by_pkgid(uid, pkgid, &privacy_list);
- char *str_ret = __get_result_string('d', ret);
- printf("- ACHIEVED RESULT:\nret = %s\n", str_ret);
- printf("privacy_list :\n");
- __print_glist(privacy_list);
-
- bool success = true;
- if(strcmp(expected_ret, str_ret)){
- success = false;
- }
-
- if(g_list_length(expected_privacy_list) != g_list_length(privacy_list) && success){
- success = false;
- }
-
- GList *l = privacy_list;
- GList *l1 = expected_privacy_list;
-
- while (l != NULL && l1 != NULL && success)
- {
- if(strcmp((char*)l->data, (char*)l1->data)){
- printf("don't match\n");
- success = false;
- break;
- }
- l = l->next;
- l1 = l1->next;
- }
+ __check_result_code_and_list(expected_privacy_list, privacy_list, PRIVILEGE_DB_MANAGER_ERR_NONE, ret, true , 'd');
- if(success){
- printf("match\n");
- success_cnt++;
- printf_green("success\n");
- }else{
- printf("don't match\n");
- fail_cnt++;
- printf_red("fail\n");
- }
privilege_db_manager_list_free(privacy_list);
}
char *pkgid = "cert-svc-ui";
expected_package_list = g_list_append(expected_package_list, pkgid);
- char *expected_ret = __get_result_string('d', PRIVILEGE_DB_MANAGER_ERR_NONE);
+ __tcinfo(goal, POS_TC_PREFIX "get package list by privacy");
printf("uid = %d\nprivacy = %s\n", uid, privacy);
- printf("- EXPECTED RESULT:\nexpected_ret = %s\n", expected_ret);
- printf("package_list :\n");
- __print_glist(expected_package_list);
-
int ret = privilege_db_manager_get_package_list_by_privacy(uid, privacy, &package_list);
- char *str_ret = __get_result_string('d', ret);
- printf("- ACHIEVED RESULT:\nret = %s\n", str_ret);
- printf("package_list :\n");
- __print_glist(package_list);
-
- bool success = true;
- if(strcmp(expected_ret, str_ret)){
- success = false;
- }
-
- if(g_list_length(expected_package_list) != g_list_length(package_list) && success){
- success = false;
- }
-
- GList *l = expected_package_list;
- GList *l1 = package_list;
- while (l != NULL && l1 != NULL && success)
- {
- if(strcmp((char*)l->data, (char*)l1->data)){
- success = false;
- break;
- }
- l = l->next;
- l1 = l1->next;
- }
+ __check_result_code_and_list(expected_package_list, package_list, PRIVILEGE_DB_MANAGER_ERR_NONE, ret, true, 'd');
- if(success){
- printf("match\n");
- success_cnt++;
- printf_green("success\n");
- }else{
- fail_cnt++;
- printf_red("fail\n");
- }
privilege_db_manager_list_free(package_list);
}
return PRVMGR_ERR_NO_DATA;
}
-void __check_the_return_code(int expected_result, int ret)
-{
- if (expected_result != ret) {
- printf_red("TEST RESULT: FAILED\n");
- fail_cnt++;
- } else {
- printf_green("TEST RESULT: SUCCESS\n");
- success_cnt++;
- }
- printf("EXPECTED: %s, RETURNED : %s\n",
- __get_result_string('m', expected_result),
- __get_result_string('m', ret));
- __print_line();
-}
-
void __test_privilege_info_foreach_privilege_group_list_by_pkgid()
{
GList* group_list_user_data = NULL;
__check_privilege_info_foreach_list_callback,
group_list_user_data);
- __check_the_return_code(expected_result, ret);
+ __check_the_return_code('m', expected_result, ret);
gfree(group_list_user_data);
}
char *privilege_group_1 = "http://tizen.org/privilege/group/group0";
char *privilege_group_2 = "http://tizen.org/privilege/group/group4";
+ __tcinfo(goal, POS_TC_PREFIX "foreach privilege group list by pkgid and uid");
+
printf("pkgid : %s\n", pkgid);
printf("privilege group : %s\n", privilege_group_1);
printf("privilege group : %s\n", privilege_group_2);
__check_privilege_info_foreach_list_callback,
group_list_user_data);
- __check_the_return_code(expected_result, ret);
+ __check_the_return_code('m', expected_result, ret);
gfree(group_list_user_data);
}
char *privilege_group = "http://tizen.org/privilege/group/group0";
char *privilege = "http://tizen.org/privilege/camera";
+ __tcinfo(goal, POS_TC_PREFIX "foreach privilege list by pkgid and privilege group");
+
printf("pkgid : %s\n", pkgid);
printf("privilege_group : %s\n", privilege_group);
printf("privilege : %s\n", privilege);
__check_privilege_info_foreach_list_callback,
privilege_list);
- __check_the_return_code(expected_result, ret);
+ __check_the_return_code('m', expected_result, ret);
gfree(privilege_list);
privilege = "http://tizen.org/privilege/audiorecorder";
+ __tcinfo(goal, POS_TC_PREFIX "foreach privilege list by pkgid and privilege group");
+
printf("pkgid : %s\n", pkgid);
printf("privilege_group : %s\n", privilege_group);
printf("privilege : %s\n", privilege);
__check_privilege_info_foreach_list_callback,
privilege_list);
- __check_the_return_code(expected_result, ret);
+ __check_the_return_code('m', expected_result, ret);
gfree(privilege_list);
}
char *privilege_group = "http://tizen.org/privilege/group/group0";
char *privilege = "http://tizen.org/privilege/camera";
+ __tcinfo(goal, POS_TC_PREFIX "foreach privilege list by pkgid and privilege group and uid");
+
printf("pkgid : %s\n", pkgid);
printf("privilege_group : %s\n", privilege_group);
printf("privilege : %s\n", privilege);
__check_privilege_info_foreach_list_callback,
privilege_list);
- __check_the_return_code(expected_result, ret);
+ __check_the_return_code('m', expected_result, ret);
gfree(privilege_list);
privilege = "http://tizen.org/privilege/d2d.datasharing";
+ __tcinfo(goal, POS_TC_PREFIX "foreach privilege list by pkgid and privilege group and uid");
+
printf("pkgid : %s\n", pkgid);
printf("privilege_group : %s\n", privilege_group);
printf("privilege : %s\n", privilege);
__check_privilege_info_foreach_list_callback,
privilege_list);
- __check_the_return_code(expected_result, ret);
+ __check_the_return_code('m', expected_result, ret);
gfree(privilege_list);
}