From d60f47d91ee4faeabc514c15c0d7b0abefa35e1a Mon Sep 17 00:00:00 2001 From: Yunjin Lee Date: Mon, 11 May 2020 17:52:20 +0900 Subject: [PATCH 01/16] Remove deprecated API - Remove 5.0 deprecated API and related local test cases Change-Id: I7e24ea3c41b45ada1358ac55508c3072c7f35728 Signed-off-by: Yunjin Lee --- packaging/privilege-info.spec | 10 ---- src/CMakeLists.txt | 2 +- src/include/privilege_information.h | 21 ------- src/privilege_information.c | 49 ---------------- test/CMakeLists.txt | 7 --- test/org.tizen.test-privilege-info.manifest | 6 -- test/org.tizen.test-privilege-info.xml | 12 ---- test/tc_privilege_info_app_privacy.c | 86 ----------------------------- 8 files changed, 1 insertion(+), 192 deletions(-) delete mode 100644 test/org.tizen.test-privilege-info.manifest delete mode 100644 test/org.tizen.test-privilege-info.xml delete mode 100644 test/tc_privilege_info_app_privacy.c diff --git a/packaging/privilege-info.spec b/packaging/privilege-info.spec index 6201068..ec1896c 100644 --- a/packaging/privilege-info.spec +++ b/packaging/privilege-info.spec @@ -13,9 +13,6 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(security-privilege-manager) -BuildRequires: pkgconfig(cynara-client) -BuildRequires: pkgconfig(cynara-session) -BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(capi-system-info) %if 0%{?gcov:1} @@ -105,10 +102,6 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj %post -n privilege-info -p /sbin/ldconfig %postun -n privilege-info -p /sbin/ldconfig -%post -n tc-privilege-info -tpk-backend -y org.tizen.test-privilege-info --preload -cyad -s -k MANIFESTS_GLOBAL -c User::Pkg::org.tizen.test-privilege-info -u '*' -p http://tizen.org/privilege/contact.read -t DENY - %files -n privilege-info %{_libdir}/libprivilege-info.so* %license LICENSE.Apache-2.0 @@ -119,9 +112,6 @@ cyad -s -k MANIFESTS_GLOBAL -c User::Pkg::org.tizen.test-privilege-info -u '*' - %{_libdir}/pkgconfig/privilege-info.pc %files -n tc-privilege-info -%manifest test/org.tizen.test-privilege-info.manifest -%{TZ_SYS_RO_APP}/org.tizen.test-privilege-info/bin/tc-privilege-info-app-privacy -%{TZ_SYS_RO_PACKAGES}/org.tizen.test-privilege-info.xml %{_bindir}/tc-privilege-info %if 0%{?gcov:1} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b0789ab..a0cf43c 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,7 +8,7 @@ SET(PRIV_INFO_SOURCES INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include) -SET(requires glib-2.0 dlog security-privilege-manager cynara-client cynara-session libsmack capi-system-info) +SET(requires glib-2.0 dlog security-privilege-manager capi-system-info) INCLUDE(FindPkgConfig) pkg_check_modules(${PACKAGE_NAME} REQUIRED ${requires}) FOREACH(flag ${${PACKAGE_NAME}_CFLAGS}) diff --git a/src/include/privilege_information.h b/src/include/privilege_information.h index 29e83f2..f1eb304 100755 --- a/src/include/privilege_information.h +++ b/src/include/privilege_information.h @@ -150,25 +150,6 @@ int privilege_info_get_privacy_display_name(const char *privilege, char **privac /** - * @deprecated Deprecated since 5.0. Use ppm_check_permission() instead. You can refer to @ref CAPI_PRIVACY_PRIVILEGE_MANAGER_MODULE. - * @brief Gets the status of the given privacy related privilege. - * @since_tizen 3.0 - * @remarks @a privilege must be privacy related, otherwise #PRVINFO_ERROR_INVALID_PARAMETER is returned. - * In case of errors, @a status is set to @c true. - * @param[in] privilege The privilege - * @param[out] status @c true if the privilege is on, - * and @c false if the privilege is off - * @return @c 0 on success, - * otherwise a negative error value - * @retval #PRVINFO_ERROR_NONE Successful - * @retval #PRVINFO_ERROR_INVALID_PARAMETER Invalid function parameter - * @retval #PRVINFO_ERROR_INTERNAL_ERROR Unknown error - * @retval #PRVINFO_ERROR_NOT_SUPPORTED Not supported - */ -int privilege_info_get_privacy_privilege_status(const char *privilege, bool *status) TIZEN_DEPRECATED_API; - - -/** * @brief The structure for privilege information. * @since_tizen 5.5 */ @@ -227,8 +208,6 @@ int privilege_info_get_privilege_info_list(const char* locale, GList* privilege_ int privilege_info_free_privilege_info_list(GList* privilege_info_list); - - /** * @} */ diff --git a/src/privilege_information.c b/src/privilege_information.c index 1c7687b..1f58050 100755 --- a/src/privilege_information.c +++ b/src/privilege_information.c @@ -18,8 +18,6 @@ #include #include #include -#include -#include #include #include #include @@ -27,9 +25,6 @@ #include #include -#include -#include - #include "privilege_information.h" #ifdef LOG_TAG @@ -52,8 +47,6 @@ } \ } while (0) -#define UIDMAXLEN 10 - #define TryReturn(condition, expr, returnValue, ...) \ if (!(condition)) { \ expr; \ @@ -234,48 +227,6 @@ int privilege_info_get_privacy_display_name(const char *privilege, char **privac } PI_API -int privilege_info_get_privacy_privilege_status(const char *privilege, bool *status) -{ - LOGW("DEPRECATION WARNING: privilege_info_get_privacy_privilege_status() is deprecated and will be removed from next release. Use ppm_check_permission() instead."); - CHECK_FEATURE_SUPPORTED(PRIVACY_FEATURE); - TryReturn(privilege != NULL, *status = true, PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL"); - TryReturn(privilege_db_manager_is('p', privilege) == 1, *status = true, PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege does not exist or is not a privacy related"); - - char* smack_label = NULL; - TryReturn(smack_new_label_from_self(&smack_label) != -1, *status = true, PRVINFO_ERROR_INTERNAL_ERROR, "[PRVINFO_ERROR_INTERNAL_ERROR] smack_new_label_from_self() failed."); - - cynara *cynara = NULL; - TryReturn(cynara_initialize(&cynara, NULL) == CYNARA_API_SUCCESS, *status = true; cynara = NULL; free(smack_label), PRVINFO_ERROR_INTERNAL_ERROR, "[PRVINFO_ERROR_INTERNAL_ERROR] cynara_initialize() failed."); - - char *session = NULL; - session = cynara_session_from_pid(getpid()); - TryReturn(session != NULL, *status = true; cynara_finish(cynara); free(smack_label), PRVINFO_ERROR_INTERNAL_ERROR, "[PRVINFO_ERROR_INTERNAL_ERROR] cynara_session_from_pid() failed"); - - char uid[UIDMAXLEN]; - int result = snprintf(uid, UIDMAXLEN, "%d", getuid()); - TryReturn(uid != NULL && result > 0, *status = true; free(session); cynara_finish(cynara); free(smack_label), PRVINFO_ERROR_INTERNAL_ERROR, "[PRVINFO_ERROR_INTERNAL_ERROR] snprintf() for uid failed."); - - result = cynara_simple_check(cynara, smack_label, session, uid, privilege); - int ret = PRVINFO_ERROR_NONE; - free(session); - cynara_finish(cynara); - - LOGD("result of cynara_check(cynara %s, session, %s, %s) result = %d", smack_label, uid, privilege, result); - free(smack_label); - if (result == CYNARA_API_ACCESS_DENIED) { - *status = false; - } else if (result == CYNARA_API_ACCESS_ALLOWED) { - *status = true; - } else { - *status = true; - LOGE("[PRVINFO_ERROR_INTERNAL_ERROR] cynara_check() failed. ret = %d", result); - ret = PRVINFO_ERROR_INTERNAL_ERROR; - } - - return ret; -} - -PI_API int privilege_info_get_privilege_info_list(const char* locale, GList* privilege_name_list, GList** privilege_info_list, privilege_consumer_return_code_e* return_result) { GList *l; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 18d6f42..8da99db 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,10 +3,8 @@ SET(PACKAGE_NAME tc-privilege-info) PROJECT(${PACKAGE_NAME}) SET(TC1_NAME tc-privilege-info) -SET(TC2_NAME tc-privilege-info-app-privacy) SET(TC1_SRCS ${PROJECT_SOURCE_DIR}/tc_privilege_info.c) -SET(TC2_SRCS ${PROJECT_SOURCE_DIR}/tc_privilege_info_app_privacy.c) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/include) @@ -21,11 +19,6 @@ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC -Wall -fvisibility=hidden -D_WITH_SYSTEM SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${PACKAGE_NAME_CFLAGS}") ADD_EXECUTABLE(${TC1_NAME} ${TC1_SRCS}) -ADD_EXECUTABLE(${TC2_NAME} ${TC2_SRCS}) TARGET_LINK_LIBRARIES(${TC1_NAME} "privilege-info") -TARGET_LINK_LIBRARIES(${TC2_NAME} "privilege-info") INSTALL(TARGETS ${TC1_NAME} DESTINATION /usr/bin) -INSTALL(TARGETS ${TC2_NAME} DESTINATION ${TZ_SYS_RO_APP}/org.tizen.test-privilege-info/bin/) -INSTALL(FILES ${CMAKE_SOURCE_DIR}/test/org.tizen.test-privilege-info.xml DESTINATION ${TZ_SYS_RO_PACKAGES}) - diff --git a/test/org.tizen.test-privilege-info.manifest b/test/org.tizen.test-privilege-info.manifest deleted file mode 100644 index ccea6a9..0000000 --- a/test/org.tizen.test-privilege-info.manifest +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/test/org.tizen.test-privilege-info.xml b/test/org.tizen.test-privilege-info.xml deleted file mode 100644 index c9d7ab2..0000000 --- a/test/org.tizen.test-privilege-info.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - http://tizen.org/privilege/account.read - http://tizen.org/privilege/contact.read - - - - diff --git a/test/tc_privilege_info_app_privacy.c b/test/tc_privilege_info_app_privacy.c deleted file mode 100644 index 6df037c..0000000 --- a/test/tc_privilege_info_app_privacy.c +++ /dev/null @@ -1,86 +0,0 @@ -#include -#include -#include -#include - -#ifdef LOG_TAG -#undef LOG_TAG -#define LOG_TAG "PRIVILEGE_INFO_TEST_APP" -#endif - - -static int fail_cnt = 0; -static int success_cnt = 0; - -static const char *__get_result_string(privilege_info_error_e ret) -{ - if (ret == PRVINFO_ERROR_NONE) - return "PRVINFO_ERROR_NONE"; - else if (ret == PRVINFO_ERROR_INVALID_PARAMETER) - return "PRVINFO_ERROR_INVALID_PARAMETER"; - else if (ret == PRVINFO_ERROR_INTERNAL_ERROR) - return "PRVINFO_ERROR_INTERNAL_ERROR"; - else if (ret == PRVINFO_ERROR_OUT_OF_MEMORY) - return "PRVINFO_ERROR_UNDECLARED_PRIVILEGE"; - else - return "FAIL"; -} - -static void __check_result(privilege_info_error_e expected_result, privilege_info_error_e result, bool expected_status, bool status) -{ - LOGD("expected result = %s, result = %s", __get_result_string(expected_result), __get_result_string(result)); - LOGD("expected status = %s, status = %s", expected_status ? "true" : "false", status ? "true" : "false"); - - if (expected_result != result) { - LOGD("test fail"); - fail_cnt++; - } else { - if (expected_status != status) { - LOGD("test fail"); - fail_cnt++; - } else { - LOGD("test success"); - success_cnt++; - } - } -} - -static void __test_privilege_info_get_privacy_privilege_status() -{ - int ret = PRVINFO_ERROR_NONE; - bool status; - - LOGD("-----------------------------------------------------------"); - LOGD("privilege : http://tizen.org/privilege/account.read"); - LOGD("expected result : PRVINFO_ERROR_NONE"); - ret = privilege_info_get_privacy_privilege_status("http://tizen.org/privilege/account.read", &status); - __check_result(PRVINFO_ERROR_NONE, ret, true, status); - LOGD("-----------------------------------------------------------"); - - LOGD("privilege : http://tizen.org/privilege/contact.read"); - LOGD("expected result : PRVINFO_ERROR_NONE"); - ret = privilege_info_get_privacy_privilege_status("http://tizen.org/privilege/contact.read", &status); - __check_result(PRVINFO_ERROR_NONE, ret, false, status); - LOGD("-----------------------------------------------------------"); - - LOGD("privilege : http://tizen.org/privilege/aaaaa"); - LOGD("expected result : PRVINFO_ERROR_INVALID_PARAMETER"); - ret = privilege_info_get_privacy_privilege_status("http://tizen.org/privilege/aaaaa", &status); - __check_result(PRVINFO_ERROR_INVALID_PARAMETER, ret, true, status); - LOGD("-----------------------------------------------------------"); - -} - -int main() -{ - LOGD("Test function : privilege_info_get_privacy_privilege_status"); - __test_privilege_info_get_privacy_privilege_status(); - - LOGD("===================================="); - LOGD("Test Complete"); - LOGD("success : %d, ", success_cnt); - LOGD("fail : %d", fail_cnt); - LOGD("===================================="); - - return 0; -} -- 2.7.4 From 2bf1262e0a34f35d525e1d5d956ee46ff59d7283 Mon Sep 17 00:00:00 2001 From: Yunjin Lee Date: Tue, 2 Jun 2020 16:40:46 +0900 Subject: [PATCH 02/16] Release version 0.0.5 - Remove deprecated API - Return error if there's no matched privilege - Added changes file Change-Id: I28a11e1bf7be5fbd1ff7cd8411e8b6c6336fdf9e Signed-off-by: Yunjin Lee --- packaging/privilege-info.changes | 48 ++++++++++++++++++++++++++++++++++++++++ packaging/privilege-info.spec | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 packaging/privilege-info.changes diff --git a/packaging/privilege-info.changes b/packaging/privilege-info.changes new file mode 100644 index 0000000..c9f6749 --- /dev/null +++ b/packaging/privilege-info.changes @@ -0,0 +1,48 @@ +Release version 0.0.5 +- Remove deprecated API +- Return error if there's no matched privilege + +Release version 0.0.4 +- Add null check before strdup() + +Release version 0.0.3 +- Fix build errors from toolchain upgrade (gcc6-> gcc9) +- Update API reference +- Update docs for wrong url +- Update doc +- Make gcov package when --define 'gcov ON' is given +- Add tizen-locale to requires +- Fix memory issue +- Add new API for getting privilege info as list + +Release version 0.0.2 +- Add privacy feature and deprecate redundant API + +Release version 0.0.1 +- Fix resource leak +- Adjust enum changes +- Merge "Fix not to launch privacy popup when getting privacy status" into tizen +- Fix not to launch privacy popup when getting privacy status +- Fix to use %license macro +- Update API reference +- Fix memory leak +- Update API documentation +- Merge "Remove rpmlint error and warning" into tizen +- Remove rpmlint error and warning +- Change test app process label on cyad command +- Add privacy related APIs +- Revise internal apis : Remove useless things +- Fix to handle invalid package type input parameter as an error +- Modify definition in header not to conflict +- Apply Tizen coding rule to headers +- Fix typo and add missing manifest to spec +- Apply "-Werror -Wall -Wextra" option +- Svace: Fix NO_RETURN_VALUE +- Revise dependency on privilege-manager +- Apply tizen coding rule +- Fix doxygen and apply secure coding +- Declare missing buildrequire to glib-2.0 +- Fix build macro for 64 bit +- Sync to latest code +- Initial empty repository + diff --git a/packaging/privilege-info.spec b/packaging/privilege-info.spec index ec1896c..84379a5 100644 --- a/packaging/privilege-info.spec +++ b/packaging/privilege-info.spec @@ -1,6 +1,6 @@ Name: privilege-info Summary: Privilege Information -Version: 0.0.4 +Version: 0.0.5 Release: 1 Group: Security/API License: Apache-2.0 -- 2.7.4 From 8b9417cb9ae3d90d0337ca5fe0e28714af03355d Mon Sep 17 00:00:00 2001 From: Yunjin Lee Date: Mon, 20 Jul 2020 13:31:19 +0900 Subject: [PATCH 03/16] Update API reference and doc - Update doc as suggested at https://review.tizen.org/gerrit/#/c/platform/core/security/privilege-info/+/230663/ Change-Id: Ic88b19163506c495812724e180442d32269c917e Signed-off-by: Yunjin Lee --- doc/privilege-info_doc.h | 2 +- src/include/privilege_information.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/privilege-info_doc.h b/doc/privilege-info_doc.h index d47d785..7848865 100755 --- a/doc/privilege-info_doc.h +++ b/doc/privilege-info_doc.h @@ -28,7 +28,7 @@ * @section CAPI_SECURITY_FRAMEWORK_PRIVILEGE_INFO_MODULE_OVERVIEW Overview * A library for reading privilege information of the given privilege and API issue version. * It provides the display name or description of privileges. - * If there's no matching privilege then it returns error. + * If there's no matching privilege then it returns an error. * * @section CAPI_SECURITY_FRAMEWORK_PRIVILEGE_INFO_MODULE_FEATURE Related Features * This API is related with the following features:\n diff --git a/src/include/privilege_information.h b/src/include/privilege_information.h index f1eb304..9006dbc 100755 --- a/src/include/privilege_information.h +++ b/src/include/privilege_information.h @@ -55,7 +55,7 @@ typedef enum { * @brief Gets the display name of the given privilege. * @since_tizen @if WEARABLE 2.3.1 @elseif MOBILE 2.3 @endif * @remarks @a display_name must be released using free(). - * @remarks Since 6.0, it will return #PRVINFO_ERROR_NO_MATCHING_PRIVILEGE if the given @a privilege not exist. + * @remarks Since 6.0, this function returns #PRVINFO_ERROR_NO_MATCHING_PRIVILEGE if the given @a privilege doesn't exist. * @param[in] api_version The API version of the application to get privilege information * @param[in] privilege The privilege * @param[out] display_name The display name of the privilege @@ -75,7 +75,7 @@ int privilege_info_get_display_name(const char *api_version, const char *privile * @since_tizen @if WEARABLE 2.3.1 @elseif MOBILE 2.3 @endif * @remarks @a display_name must be released using free(). * @remarks @a package_type must be one of followings: "PRVINFO_PACKAGE_TYPE_NATIVE", "PRVINFO_PACKAGE_TYPE_WEB" - * @remarks Since 6.0, it will return #PRVINFO_ERROR_NO_MATCHING_PRIVILEGE if the given @a privilege not exist. + * @remarks Since 6.0, this function returns #PRVINFO_ERROR_NO_MATCHING_PRIVILEGE if the given @a privilege doesn't exist. * @param[in] package_type The type of application package * @param[in] api_version The API version of the application to get privilege information * @param[in] privilege The privilege @@ -95,7 +95,7 @@ int privilege_info_get_display_name_by_pkgtype(const char *package_type, const c * @brief Gets the description of the given privilege. * @since_tizen @if WEARABLE 2.3.1 @elseif MOBILE 2.3 @endif * @remarks @a description must be released using free(). - * @remarks Since 6.0, it will return #PRVINFO_ERROR_NO_MATCHING_PRIVILEGE if the given @a privilege not exist. + * @remarks Since 6.0, this function returns #PRVINFO_ERROR_NO_MATCHING_PRIVILEGE if the given @a privilege doesn't exist. * @param[in] api_version The API version of the application to get privilege information * @param[in] privilege The privilege * @param[out] description The description of the privilege @@ -115,7 +115,7 @@ int privilege_info_get_description(const char *api_version, const char *privileg * @since_tizen @if WEARABLE 2.3.1 @elseif MOBILE 2.3 @endif * @remarks @a description must be released using free(). * @remarks @a package_type must be one of followings: "PRVINFO_PACKAGE_TYPE_NATIVE", "PRVINFO_PACKAGE_TYPE_WEB" - * @remarks Since 6.0, it will return #PRVINFO_ERROR_NO_MATCHING_PRIVILEGE if the given @a privilege not exist. + * @remarks Since 6.0, this function returns #PRVINFO_ERROR_NO_MATCHING_PRIVILEGE if the given @a privilege doesn't exist. * @param[in] package_type The type of application package * @param[in] api_version The API version of the application to get privilege information * @param[in] privilege The privilege -- 2.7.4 From 7b3b8734612574b97a40d65c8918b0a3f13dfb05 Mon Sep 17 00:00:00 2001 From: Yunjin Lee Date: Wed, 26 Aug 2020 17:33:55 +0900 Subject: [PATCH 04/16] Remove duplicated logics - Remove duplicated code with privilege-checker and call privilege-checker APIs Change-Id: Ic01498578c9932da4d546025313e7cd027a85c12 Signed-off-by: Yunjin Lee --- src/privilege_information.c | 322 +++++++------------------------------------- 1 file changed, 51 insertions(+), 271 deletions(-) diff --git a/src/privilege_information.c b/src/privilege_information.c index 1f58050..095bdc8 100755 --- a/src/privilege_information.c +++ b/src/privilege_information.c @@ -54,76 +54,52 @@ return returnValue; \ } +#define SAFE_FREE(var) { if (var) { free(var); var = NULL; } } + #ifndef PI_API #define PI_API __attribute__((visibility("default"))) #endif -int privilege_info_get_string_id(const char *package_type_string, int display, const char *api_version, const char *privilege, char **string_id) +static int __convert_package_type(const char* package_type_string) { - char* temp = NULL; - int ret; - privilege_manager_package_type_e package_type; - - if (package_type_string != NULL) - goto get_string_id_with_package_type; - - /* Check NATIVE */ - if (display) - ret = privilege_db_manager_get_privilege_display(PRVMGR_PACKAGE_TYPE_CORE, privilege, api_version, &temp); - else - ret = privilege_db_manager_get_privilege_description(PRVMGR_PACKAGE_TYPE_CORE, privilege, api_version, &temp); - - if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE && temp != NULL) - goto string_id_found; - else if (ret != PRIVILEGE_DB_MANAGER_ERR_NO_EXIST_RESULT) - goto err; + if (strcmp(package_type_string, "PRVINFO_PACKAGE_TYPE_WEB") == 0) + return PRVMGR_PACKAGE_TYPE_WRT; + if (strcmp(package_type_string, "PRVINFO_PACKAGE_TYPE_NATIVE") == 0) + return PRVMGR_PACKAGE_TYPE_CORE; - /* Check WEB */ + return PRVMGR_PACKAGE_TYPE_NONE; +} -get_string_id_with_package_type: - if (package_type_string == NULL || strcmp(package_type_string, "PRVINFO_PACKAGE_TYPE_WEB") == 0) - package_type = PRVMGR_PACKAGE_TYPE_WRT; - else if (strcmp(package_type_string, "PRVINFO_PACKAGE_TYPE_NATIVE") == 0) - package_type = PRVMGR_PACKAGE_TYPE_CORE; - else +static int __convert_return_value(int ret, const char* result) +{ + switch (ret) { + case PRVMGR_ERR_NONE: + if (result == NULL) + return PRVINFO_ERROR_NO_MATCHING_PRIVILEGE; + return PRVINFO_ERROR_NONE; + case PRVMGR_ERR_INVALID_PARAMETER: return PRVINFO_ERROR_INVALID_PARAMETER; - - if (display) - ret = privilege_db_manager_get_privilege_display(package_type, privilege, api_version, &temp); - else - ret = privilege_db_manager_get_privilege_description(package_type, privilege, api_version, &temp); - - if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE && temp != NULL) - goto string_id_found; - else - goto err; - -string_id_found: - *string_id = strdup(temp); - TryReturn(*string_id != NULL, free(temp), PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation is failed."); - free(temp); - return PRVINFO_ERROR_NONE; - -err: - *string_id = NULL; - if (temp != NULL) - free(temp); - if (ret == PRIVILEGE_DB_MANAGER_ERR_NO_EXIST_RESULT) + case PRVMGR_ERR_OUT_OF_MEMORY: + return PRVINFO_ERROR_OUT_OF_MEMORY; + case PRVMGR_ERR_NO_EXIST_PRIVILEGE: return PRVINFO_ERROR_NO_MATCHING_PRIVILEGE; - else + case PRVMGR_ERR_INTERNAL_ERROR: + default: return PRVINFO_ERROR_INTERNAL_ERROR; + } } -int privilege_info_get_string_by_string_id(const char *string_id, char **string) +static int __convert_result_code(int result) { - TryReturn(string_id != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] string_id is NULL"); - char* temp = NULL; - temp = dgettext("privilege", string_id); - - *string = strdup(temp); - TryReturn(*string != NULL, , PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] strdup of string failed."); - - return PRVINFO_ERROR_NONE; + switch (result) { + case PRIVILEGE_NOTI_INFO_RESULT_CODE_SUCCESS: + return PRIVILEGE_CONSUMER_RETURN_CODE_SUCCESS; + case PRIVILEGE_NOTI_INFO_RESULT_CODE_UNKNOWN_LOCALE_CODE: + return PRIVILEGE_CONSUMER_RETURN_CODE_UNKNOWN_LOCALE_CODE; + case PRIVILEGE_NOTI_INFO_RESULT_CODE_INVALID_PARAMETER: + default: + return PRIVILEGE_CONSUMER_RETURN_CODE_INVALID_PARAMETER; + } } PI_API @@ -132,16 +108,7 @@ int privilege_info_get_display_name(const char *api_version, const char *privile TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL"); TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL"); - int ret = 0; - char* string_id = NULL; - - ret = privilege_info_get_string_id(NULL, 1, api_version, privilege, &string_id); - - if (ret == PRVINFO_ERROR_NONE) - ret = privilege_info_get_string_by_string_id(string_id, display_name); - if (string_id != NULL) - free(string_id); - return ret; + return __convert_return_value(privilege_info_get_privilege_display_name(privilege, display_name), *display_name); } PI_API @@ -150,17 +117,7 @@ int privilege_info_get_description(const char *api_version, const char *privileg TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL"); TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL"); - int ret = 0; - char* string_id = NULL; - - ret = privilege_info_get_string_id(NULL, 0, api_version, privilege, &string_id); - - if (ret == PRVINFO_ERROR_NONE) - ret = privilege_info_get_string_by_string_id(string_id, description); - if (string_id != NULL) - free(string_id); - - return ret; + return __convert_return_value(privilege_info_get_privilege_description(privilege, description), *description); } PI_API @@ -170,18 +127,7 @@ int privilege_info_get_display_name_by_pkgtype(const char *package_type, const c TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL"); TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL"); - int ret = 0; - char* string_id = NULL; - - ret = privilege_info_get_string_id(package_type, 1, api_version, privilege, &string_id); - TryReturn(ret != PRVINFO_ERROR_INVALID_PARAMETER, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] invalid package_type : %s", package_type); - - if (ret == PRVINFO_ERROR_NONE) - ret = privilege_info_get_string_by_string_id(string_id, display_name); - if (string_id != NULL) - free(string_id); - - return ret; + return __convert_return_value(privilege_info_get_privilege_display_name_by_package_type(privilege, api_version, __convert_package_type(package_type), display_name), *display_name); } PI_API @@ -191,18 +137,7 @@ int privilege_info_get_description_by_pkgtype(const char *package_type, const ch TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL"); TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL"); - int ret = 0; - char* string_id = NULL; - - ret = privilege_info_get_string_id(package_type, 0, api_version, privilege, &string_id); - TryReturn(ret != PRVINFO_ERROR_INVALID_PARAMETER, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] invalid package_type : %s", package_type); - - if (ret == PRVINFO_ERROR_NONE) - ret = privilege_info_get_string_by_string_id(string_id, description); - if (string_id != NULL) - free(string_id); - - return ret; + return __convert_return_value(privilege_info_get_privilege_description_by_package_type(privilege, api_version, __convert_package_type(package_type), description), *description); } PI_API @@ -210,188 +145,33 @@ int privilege_info_get_privacy_display_name(const char *privilege, char **privac { CHECK_FEATURE_SUPPORTED(PRIVACY_FEATURE); TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL"); - TryReturn(privilege_db_manager_is('p', privilege) == 1, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege does not exist or is not a privacy related"); - - char* privacy_id = NULL; - char* privacy_display_string_id = NULL; + TryReturn(privilege_info_is_privacy(privilege) == 1, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege does not exist or is not a privacy related"); - TryReturn(privilege_db_manager_get_privacy_by_privilege(privilege, &privacy_id) == PRIVILEGE_DB_MANAGER_ERR_NONE && privacy_id != NULL, , PRVINFO_ERROR_INTERNAL_ERROR, "[PRVINFO_ERROR_INTERNAL_ERROR] privilege_db_manager_get_privacy_by_privilege failed"); + char* privacy_name = NULL; + TryReturn(privilege_info_get_privacy_by_privilege(privilege, &privacy_name) == PRVMGR_ERR_NONE && privacy_name != NULL, SAFE_FREE(privacy_name), PRVINFO_ERROR_INTERNAL_ERROR, "[PRVINFO_ERROR_INTERNAL_ERROR] privilege_info_get_privacy_by_privilege() failed. privilege = %s", privilege); - TryReturn(privilege_db_manager_get_privacy_display(privacy_id, &privacy_display_string_id) == PRIVILEGE_DB_MANAGER_ERR_NONE && privacy_display_string_id != NULL, free(privacy_id), PRVINFO_ERROR_INTERNAL_ERROR, "[PRVINFO_ERROR_INTERNAL_ERROR] privilege_db_manager_get_privacy_display failed"); + int ret = privilege_info_get_privacy_display(privacy_name, privacy_display_name); + SAFE_FREE(privacy_name); - TryReturn(privilege_info_get_string_by_string_id(privacy_display_string_id, privacy_display_name) == PRVINFO_ERROR_NONE && *privacy_display_name != NULL, free(privacy_id); free(privacy_display_string_id), PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed."); - - free(privacy_id); - free(privacy_display_string_id); - return PRVINFO_ERROR_NONE; + return __convert_return_value(ret, *privacy_display_name); } PI_API int privilege_info_get_privilege_info_list(const char* locale, GList* privilege_name_list, GList** privilege_info_list, privilege_consumer_return_code_e* return_result) { - GList *l; - GList *temp_privilege_info_list = NULL; - char* privilege_display = NULL; - char* privilege_description = NULL; - int is_invaild_parameter_count = 0; - int privilege_name_list_size = 0; - privilege_consumer_return_code_e consumer_return_code = PRIVILEGE_CONSUMER_RETURN_CODE_SUCCESS; - int ret = PRVINFO_ERROR_NONE; - - if (privilege_name_list == NULL) { - LOGE("[PRVINFO_ERROR_INVALID_PARAMETER] privilege_list is NULL"); - return PRVINFO_ERROR_INVALID_PARAMETER; - } - char *orig_locale = NULL; - char *result = (char *)setlocale(LC_ALL, NULL); - if (!result) { - LOGE("failed to get original locale. errno = %d", errno); - } else { - orig_locale = strdup(result); - TryReturn(orig_locale != NULL, , PRVINFO_ERROR_OUT_OF_MEMORY, "[PRVINFO_ERROR_OUT_OF_MEMORY] strdup of orig_locale failed"); - LOGD("orig_locale = %s", orig_locale); - } - result = (char *)setlocale(LC_ALL, locale); - if (result) { - LOGI("succeeded in setting locale = %s", result); - } else { - LOGE("failed to set locale. set locale to en_US.UTF8. errno = %d", errno); - setlocale(LC_ALL, "en_US.UTF8"); - - consumer_return_code = PRIVILEGE_CONSUMER_RETURN_CODE_UNKNOWN_LOCALE_CODE; - } - - for (l = privilege_name_list; l != NULL; l = l->next) { - char* privilege_name = (char*)l->data; - - LOGI("privilege_name = %s", privilege_name); - - ret = privilege_info_get_privilege_display_name(privilege_name, &privilege_display); - if (ret == PRVMGR_ERR_NONE) { - if (privilege_display != NULL) { - LOGI("display : %s", privilege_display); - } else { - privilege_display = strdup(""); - if (privilege_display == NULL) { - LOGE("[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed."); - ret = PRVINFO_ERROR_OUT_OF_MEMORY; - goto FINISH; - } - is_invaild_parameter_count++; - } - } else { - LOGE("failed to call privilege_info_get_privilege_display_name."); - ret = PRVINFO_ERROR_INTERNAL_ERROR; - goto FINISH; - } - - LOGI("privilege_display = %s", privilege_display); + TryReturn(privilege_name_list != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege_name_list is NULL."); - ret = privilege_info_get_privilege_description(privilege_name, &privilege_description); - if (ret == PRVMGR_ERR_NONE) { - if (privilege_description != NULL) { - LOGI("description : %s", privilege_description); - } else { - privilege_description = strdup(""); - if (privilege_description == NULL) { - LOGE("[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed."); - ret = PRVINFO_ERROR_OUT_OF_MEMORY; - goto FINISH; - } - } - } else { - LOGE("failed to call privilege_info_get_privilege_description."); - ret = PRVINFO_ERROR_INTERNAL_ERROR; - goto FINISH; - } + privilege_noti_info_result_e result; + int ret = privilege_info_get_privilege_noti_info_list(locale, privilege_name_list, privilege_info_list, &result); + *return_result = __convert_result_code(result); - LOGD("privilege_description = %s", privilege_description); - - privilege_info_s* privilege_info = (privilege_info_s*)malloc(sizeof(privilege_info_s)); - memset(privilege_info, 0, sizeof(privilege_info_s)); - - privilege_info->privilege_name = strdup(privilege_name); - if (privilege_info->privilege_name == NULL) { - LOGE("[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed."); - ret = PRVINFO_ERROR_OUT_OF_MEMORY; - free(privilege_info); - goto FINISH; - } - privilege_info->display_name = strdup(privilege_display); - if (privilege_info->display_name == NULL) { - LOGE("[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed."); - ret = PRVINFO_ERROR_OUT_OF_MEMORY; - free(privilege_info->privilege_name); - free(privilege_info); - goto FINISH; - } - privilege_info->description = strdup(privilege_description); - if (privilege_info->description == NULL) { - LOGE("[PRVINFO_ERROR_OUT_OF_MEMORY] Memory allocation failed."); - ret = PRVINFO_ERROR_OUT_OF_MEMORY; - free(privilege_info->privilege_name); - free(privilege_info->display_name); - free(privilege_info); - goto FINISH; - } - LOGI("privilege_info->privilege_name = %s", privilege_info->privilege_name); - LOGI("privilege_info->display_name = %s", privilege_info->display_name); - LOGI("privilege_info->description = %s", privilege_info->description); - - temp_privilege_info_list = g_list_append(temp_privilege_info_list, privilege_info); - - privilege_name_list_size++; - - if (privilege_display != NULL) { - free(privilege_display); - privilege_display = NULL; - } - - if (privilege_description != NULL) { - free(privilege_description); - privilege_description = NULL; - } - } - - if (is_invaild_parameter_count == privilege_name_list_size) - consumer_return_code = PRIVILEGE_CONSUMER_RETURN_CODE_INVALID_PARAMETER; - -FINISH: - - *privilege_info_list = temp_privilege_info_list; - *return_result = consumer_return_code; - - if (privilege_display != NULL) { - free(privilege_display); - privilege_display = NULL; - } - - if (privilege_description != NULL) { - free(privilege_description); - privilege_description = NULL; - } - if (orig_locale != NULL) { - setlocale(LC_ALL, orig_locale); - free(orig_locale); - orig_locale = NULL; - } - - return ret; + return __convert_return_value(ret, ""); } PI_API int privilege_info_free_privilege_info_list(GList* privilege_info_list) { - if (privilege_info_list == NULL) - return PRVINFO_ERROR_INVALID_PARAMETER; - - GList* l = NULL; - for (l = privilege_info_list; l != NULL; l = l->next) { - privilege_info_s* privilege_info = (privilege_info_s*)l->data; - free(privilege_info->privilege_name); - free(privilege_info->display_name); - free(privilege_info->description); - } - g_list_free(privilege_info_list); - return PRVINFO_ERROR_NONE; + return __convert_return_value(privilege_info_free_privilege_noti_info_list(privilege_info_list), ""); } + + -- 2.7.4 From 4c8d7b0187785c9798faeab16b9b7b0a83899959 Mon Sep 17 00:00:00 2001 From: Yunjin Lee Date: Thu, 3 Sep 2020 17:31:57 +0900 Subject: [PATCH 05/16] Release version 0.0.6 - Remove duplicated logics - Update API reference and doc Change-Id: Ie36c805c57c3c130534ae7c31b6983ce9c19e96c Signed-off-by: Yunjin Lee --- packaging/privilege-info.changes | 4 ++++ packaging/privilege-info.spec | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packaging/privilege-info.changes b/packaging/privilege-info.changes index c9f6749..85fcf2e 100644 --- a/packaging/privilege-info.changes +++ b/packaging/privilege-info.changes @@ -1,3 +1,7 @@ +Release version 0.0.6 +- Remove duplicated logics +- Update API reference and doc + Release version 0.0.5 - Remove deprecated API - Return error if there's no matched privilege diff --git a/packaging/privilege-info.spec b/packaging/privilege-info.spec index 84379a5..a45e337 100644 --- a/packaging/privilege-info.spec +++ b/packaging/privilege-info.spec @@ -1,6 +1,6 @@ Name: privilege-info Summary: Privilege Information -Version: 0.0.5 +Version: 0.0.6 Release: 1 Group: Security/API License: Apache-2.0 -- 2.7.4 From 7947c5452ed817dd85375d9565e118e0c872fb1d Mon Sep 17 00:00:00 2001 From: Yunjin Lee Date: Wed, 9 Sep 2020 19:28:49 +0900 Subject: [PATCH 06/16] Change privacy privilege check - Use privilege_info_has_privacy_attr() instead of privilege_info_is_privacy() to see if the given privilege is privacy related or not regardless of the askuser enabled or not. Change-Id: I34d3652c21fe52f18e048b39dfa73667e2841d38 Signed-off-by: Yunjin Lee --- src/privilege_information.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/privilege_information.c b/src/privilege_information.c index 095bdc8..6de2c21 100755 --- a/src/privilege_information.c +++ b/src/privilege_information.c @@ -145,7 +145,7 @@ int privilege_info_get_privacy_display_name(const char *privilege, char **privac { CHECK_FEATURE_SUPPORTED(PRIVACY_FEATURE); TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL"); - TryReturn(privilege_info_is_privacy(privilege) == 1, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege does not exist or is not a privacy related"); + TryReturn(privilege_info_has_privacy_attr(privilege) == 1, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege %s does not exist or does not have privacy attribute", privilege); char* privacy_name = NULL; TryReturn(privilege_info_get_privacy_by_privilege(privilege, &privacy_name) == PRVMGR_ERR_NONE && privacy_name != NULL, SAFE_FREE(privacy_name), PRVINFO_ERROR_INTERNAL_ERROR, "[PRVINFO_ERROR_INTERNAL_ERROR] privilege_info_get_privacy_by_privilege() failed. privilege = %s", privilege); -- 2.7.4 From 157829b74c6073be2dc27f6927a80ac081968c88 Mon Sep 17 00:00:00 2001 From: Yunjin Lee Date: Fri, 11 Sep 2020 10:49:51 +0900 Subject: [PATCH 07/16] Release version 0.0.6 (modified) - Due to the testhub environment, change privacy privilege check method - Remove duplicated logics - Update API reference and doc Change-Id: Ib2769f5ce91a500d07e1f7fd413619a8254bbe2b Signed-off-by: Yunjin Lee --- packaging/privilege-info.changes | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/privilege-info.changes b/packaging/privilege-info.changes index 85fcf2e..5ea38ff 100644 --- a/packaging/privilege-info.changes +++ b/packaging/privilege-info.changes @@ -1,4 +1,5 @@ Release version 0.0.6 +- Change privacy privilege check - Remove duplicated logics - Update API reference and doc -- 2.7.4 From 5d869680b75442b0d2c256124b199c349cd440e6 Mon Sep 17 00:00:00 2001 From: Yunjin Lee Date: Mon, 21 Sep 2020 11:36:04 +0900 Subject: [PATCH 08/16] Check after getting return - When calling __convert_return_value(), pass return value and derived out value after getting return cleary. On some target, in this case emulator image, it fails to reference passed out param pointer, hence separate them to be safe. Change-Id: I7ffb4f9dd06be466485952800a280c5fd6973254 Signed-off-by: Yunjin Lee --- src/privilege_information.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/privilege_information.c b/src/privilege_information.c index 6de2c21..6d7e2e7 100755 --- a/src/privilege_information.c +++ b/src/privilege_information.c @@ -108,7 +108,9 @@ int privilege_info_get_display_name(const char *api_version, const char *privile TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL"); TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL"); - return __convert_return_value(privilege_info_get_privilege_display_name(privilege, display_name), *display_name); + int ret = privilege_info_get_privilege_display_name(privilege, display_name); + + return __convert_return_value(ret, *display_name); } PI_API @@ -117,7 +119,9 @@ int privilege_info_get_description(const char *api_version, const char *privileg TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL"); TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL"); - return __convert_return_value(privilege_info_get_privilege_description(privilege, description), *description); + int ret = privilege_info_get_privilege_description(privilege, description); + + return __convert_return_value(ret, *description); } PI_API @@ -127,7 +131,9 @@ int privilege_info_get_display_name_by_pkgtype(const char *package_type, const c TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL"); TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL"); - return __convert_return_value(privilege_info_get_privilege_display_name_by_package_type(privilege, api_version, __convert_package_type(package_type), display_name), *display_name); + int ret = privilege_info_get_privilege_display_name_by_package_type(privilege, api_version, __convert_package_type(package_type), display_name); + + return __convert_return_value(ret, *display_name); } PI_API @@ -137,7 +143,9 @@ int privilege_info_get_description_by_pkgtype(const char *package_type, const ch TryReturn(api_version != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] api_version is NULL"); TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL"); - return __convert_return_value(privilege_info_get_privilege_description_by_package_type(privilege, api_version, __convert_package_type(package_type), description), *description); + int ret = privilege_info_get_privilege_description_by_package_type(privilege, api_version, __convert_package_type(package_type), description); + + return __convert_return_value(ret, *description); } PI_API -- 2.7.4 From 282b7b05fdcb656aa82e590ef9fb6d1f556aadcf Mon Sep 17 00:00:00 2001 From: Yunjin Lee Date: Mon, 21 Sep 2020 11:44:37 +0900 Subject: [PATCH 09/16] Release version 0.0.7 - Check after getting return Change-Id: Ifbb1cc7bdbd661642e1945276ecbb32b4dc7da64 Signed-off-by: Yunjin Lee --- packaging/privilege-info.changes | 3 +++ packaging/privilege-info.spec | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packaging/privilege-info.changes b/packaging/privilege-info.changes index 5ea38ff..2b479eb 100644 --- a/packaging/privilege-info.changes +++ b/packaging/privilege-info.changes @@ -1,3 +1,6 @@ +Release version 0.0.7 +- Check after getting return + Release version 0.0.6 - Change privacy privilege check - Remove duplicated logics diff --git a/packaging/privilege-info.spec b/packaging/privilege-info.spec index a45e337..f4c306e 100644 --- a/packaging/privilege-info.spec +++ b/packaging/privilege-info.spec @@ -1,6 +1,6 @@ Name: privilege-info Summary: Privilege Information -Version: 0.0.6 +Version: 0.0.7 Release: 1 Group: Security/API License: Apache-2.0 -- 2.7.4 From b3cd1f9fb5007f3f9ec65abac0ec3ce0b4a5e993 Mon Sep 17 00:00:00 2001 From: Yunjin Lee Date: Thu, 17 Dec 2020 10:22:17 +0900 Subject: [PATCH 10/16] remove hyperlink from feature name of doc Change-Id: I7072256239f49a3034453445d1fabb6303ff27a4 Signed-off-by: Yunjin Lee --- doc/privilege-info_doc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/privilege-info_doc.h b/doc/privilege-info_doc.h index 7848865..5b0e618 100755 --- a/doc/privilege-info_doc.h +++ b/doc/privilege-info_doc.h @@ -32,7 +32,7 @@ * * @section CAPI_SECURITY_FRAMEWORK_PRIVILEGE_INFO_MODULE_FEATURE Related Features * This API is related with the following features:\n - * - http://tizen.org/feature/security.privacy_privilege\n + * - %http://tizen.org/feature/security.privacy_privilege\n * It is recommended to design feature related codes in your application for reliability.\n * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n -- 2.7.4 From a4a014b3e33388e125c7376be295c335e051f69f Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Tue, 12 Jan 2021 16:38:06 +0100 Subject: [PATCH 11/16] Fix source files access rights Change-Id: I3f8f77e83e656c4f00645ca071807317b90248f8 --- CMakeLists.txt | 0 doc/privilege-info_doc.h | 0 privilege-info.pc.in | 0 src/CMakeLists.txt | 0 src/include/privilege_information.h | 0 src/privilege_information.c | 0 test/CMakeLists.txt | 0 test/tc_privilege_info.c | 0 8 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 CMakeLists.txt mode change 100755 => 100644 doc/privilege-info_doc.h mode change 100755 => 100644 privilege-info.pc.in mode change 100755 => 100644 src/CMakeLists.txt mode change 100755 => 100644 src/include/privilege_information.h mode change 100755 => 100644 src/privilege_information.c mode change 100755 => 100644 test/CMakeLists.txt mode change 100755 => 100644 test/tc_privilege_info.c diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/doc/privilege-info_doc.h b/doc/privilege-info_doc.h old mode 100755 new mode 100644 diff --git a/privilege-info.pc.in b/privilege-info.pc.in old mode 100755 new mode 100644 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/src/include/privilege_information.h b/src/include/privilege_information.h old mode 100755 new mode 100644 diff --git a/src/privilege_information.c b/src/privilege_information.c old mode 100755 new mode 100644 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/test/tc_privilege_info.c b/test/tc_privilege_info.c old mode 100755 new mode 100644 -- 2.7.4 From af0671e6734470169f57f0f2b21e1a9331e9b7fe Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Wed, 13 Jan 2021 12:21:37 +0100 Subject: [PATCH 12/16] Cleanup cmake/spec infrastructure Change-Id: I17436b498832c39c19393d752c2d79ee81bbaa72 --- CMakeLists.txt | 37 ++++++++++++------- packaging/privilege-info.spec | 85 ++++++++----------------------------------- privilege-info.pc.in | 23 +++++------- src/CMakeLists.txt | 66 ++++++++++----------------------- test/CMakeLists.txt | 27 ++------------ 5 files changed, 74 insertions(+), 164 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ed70da..c8b66fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,22 +1,33 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +CMAKE_MINIMUM_REQUIRED(VERSION 3.0) +PROJECT(privilege-info VERSION 0.0.7 LANGUAGES C) -SET(CMAKE_VERBOSE_MAKEFILE OFF) +INCLUDE(GNUInstallDirs) +INCLUDE(FindPkgConfig) -IF("${USE_AUTOSTART}" STREQUAL "1") - ADD_DEFINITIONS("-DUSE_AUTOSTART") -ENDIF() +IF(NOT CMAKE_BUILD_TYPE) + SET(CMAKE_BUILD_TYPE "RELEASE") +ENDIF(NOT CMAKE_BUILD_TYPE) -ADD_DEFINITIONS("-DCLIENT_IPC_THREAD") -ADD_DEFINITIONS("-DUSE_IPC_EPOLL") +SET(CMAKE_C_FLAGS_DEBUG "-std=c11 -O0 -ggdb -Wp,-U_FORTIFY_SOURCE") +SET(CMAKE_C_FLAGS_RELEASE "-std=c11 -O2 -DNDEBUG") -ADD_DEFINITIONS("-Werror -Wall -Wextra") +ADD_DEFINITIONS("-Werror") +ADD_DEFINITIONS("-Wall") +ADD_DEFINITIONS("-Wextra") -STRING(REGEX MATCH "([^.]*)" API_VERSION "${VERSION}") -ADD_DEFINITIONS("-DAPI_VERSION=\"$(API_VERSION)\"") +SET(CMAKE_POSITION_INDEPENDENT_CODE "True") +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") -CONFIGURE_FILE(privilege-info.pc.in privilege-info.pc @ONLY) +PKG_CHECK_MODULES(PRIVILEGE_INFO_DEPS REQUIRED + glib-2.0 + dlog + security-privilege-manager + capi-base-common + capi-system-info) + +INCLUDE_DIRECTORIES(SYSTEM ${PRIVILEGE_INFO_DEPS_INCLUDE_DIRS}) +LINK_DIRECTORIES(${PRIVILEGE_INFO_DEPS_LIBRARY_DIRS}) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/include) -MESSAGE("build privilege-info") ADD_SUBDIRECTORY(src) -MESSAGE("build tc-privilege-info") ADD_SUBDIRECTORY(test) diff --git a/packaging/privilege-info.spec b/packaging/privilege-info.spec index f4c306e..5a1cdea 100644 --- a/packaging/privilege-info.spec +++ b/packaging/privilege-info.spec @@ -1,3 +1,5 @@ +%{!?build_type:%global build_type RELEASE} + Name: privilege-info Summary: Privilege Information Version: 0.0.7 @@ -8,17 +10,13 @@ Source0: %{name}-%{version}.tar.gz Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig + BuildRequires: cmake BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(capi-base-common) -BuildRequires: pkgconfig(security-privilege-manager) -BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(capi-system-info) -%if 0%{?gcov:1} -BuildRequires: lcov -%endif -Requires: tizen-locale +BuildRequires: pkgconfig(security-privilege-manager) %description Provides Privilege Information(Privilege Info) API @@ -29,96 +27,45 @@ Group: Security/Development Requires: %{name} = %{version}-%{release} %description -n privilege-info-devel -The Privilege Info API provides functions to get privilege information (DEV) +The Privilege Info API provides functions to get privilege information (Development) -%package -n tc-privilege-info +%package -n privilege-info-tests Summary: Privilege Info TC Group: Security/Testing Requires: %{name} = %{version}-%{release} -%description -n tc-privilege-info +%description -n privilege-info-tests Privilege Info API Internal Test -%if 0%{?gcov:1} -%package gcov -Summary: Privilege Info(gcov) -Group: Security/Testing -%description gcov -New Privilege Info gcov objects -%endif - - %prep %setup -q %build - -export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE" -export CXXFLAGS="$CXXFLAGS -DTIZEN_ENGINEER_MODE" -export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE" - -%if 0%{?gcov:1} -export CFLAGS+=" -fprofile-arcs -ftest-coverage" -export CXXFLAGS+=" -fprofile-arcs -ftest-coverage" -export FFLAGS+=" -fprofile-arcs -ftest-coverage" -export LDFLAGS+=" -lgcov" -%endif - -echo cmake . -DPREFIX=%{_prefix} \ - -DLIBDIR=%{_libdir} \ - -DINCLUDEDIR=%{_includedir} \ - -DCMAKE_BUILD_TYPE=%{build_type} \ - -DVERSION=%{version} \ - -DTZ_SYS_RO_PACKAGES=%TZ_SYS_RO_PACKAGES \ - -DTZ_SYS_RO_APP=%TZ_SYS_RO_APP \ - -DBUILD_GCOV={?gcov:1}%{!?gcov:0} - -cmake . -DPREFIX=%{_prefix} \ - -DLIBDIR=%{_libdir} \ - -DINCLUDEDIR=%{_includedir} \ - -DCMAKE_BUILD_TYPE=%{build_type} \ - -DVERSION=%{version} \ - -DTZ_SYS_RO_PACKAGES=%TZ_SYS_RO_PACKAGES \ - -DTZ_SYS_RO_APP=%TZ_SYS_RO_APP \ - -DBUILD_GCOV={?gcov:1}%{!?gcov:0} +%cmake . -DCMAKE_BUILD_TYPE=%{build_type} make %{?jobs:-j%jobs} -%if 0%{?gcov:1} -mkdir -p gcov-obj -find . \( -name '*.gcno' ! -name 'tc_*' \) -exec cp '{}' gcov-obj ';' -%endif - %install rm -rf %{buildroot} - %make_install -%if 0%{?gcov:1} -mkdir -p %{buildroot}%{_datadir}/gcov/obj -install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj -%endif +%clean +rm -rf %{buildroot} %post -n privilege-info -p /sbin/ldconfig %postun -n privilege-info -p /sbin/ldconfig %files -n privilege-info -%{_libdir}/libprivilege-info.so* %license LICENSE.Apache-2.0 %manifest packaging/privilege-info.manifest +%{_libdir}/libprivilege-info.so.* %files -n privilege-info-devel +%manifest packaging/privilege-info.manifest +%{_libdir}/libprivilege-info.so %{_includedir}/privilege_information.h %{_libdir}/pkgconfig/privilege-info.pc -%files -n tc-privilege-info -%{_bindir}/tc-privilege-info - -%if 0%{?gcov:1} -%files gcov -%{_datadir}/gcov/obj/* -%endif - -%clean -rm -rf %{buildroot} - +%files -n privilege-info-tests +%manifest packaging/privilege-info.manifest +%{_bindir}/privilege-info-tests diff --git a/privilege-info.pc.in b/privilege-info.pc.in index 050d8ad..6a257c0 100644 --- a/privilege-info.pc.in +++ b/privilege-info.pc.in @@ -1,14 +1,11 @@ -# Package Information for pkg-config - -prefix=@PREFIX@ -exec_prefix=/usr -libdir=@LIBDIR@ -includedir=@INCLUDEDIR@ - -Name: @PC_NAME@ -Description: @PACKAGE_DESCRIPTION@ -Version: @VERSION@ -Requires: @PC_REQUIRED@ -Libs: -L${libdir} @PC_LDFLAGS@ -Cflags: -I${includedir} @PC_CFLAGS@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@LIB_INSTALL_DIR@ +includedir=@INCLUDE_INSTALL_DIR@ +Name: privilege-info +Description: Provides Privilege Information(Privilege Info) API +Version: @PROJECT_VERSION@ +Requires: glib-2.0 +Libs: -L${libdir} -lprivilege-info +Cflags: -I${includedir} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a0cf43c..f0bd2ae 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,46 +1,20 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(PACKAGE_NAME privilege-info) -PROJECT(${PACKAGE_NAME}) - -SET(PRIV_INFO_SOURCES - ${PROJECT_SOURCE_DIR}/privilege_information.c -) - -INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include) - -SET(requires glib-2.0 dlog security-privilege-manager capi-system-info) -INCLUDE(FindPkgConfig) -pkg_check_modules(${PACKAGE_NAME} REQUIRED ${requires}) -FOREACH(flag ${${PACKAGE_NAME}_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -# Compiler flags -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC -fvisibility=hidden -D_WITH_SYSTEMD_") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${PACKAGE_NAME_CFLAGS}") - -######################################################## -# For libprivilege-info libraries(.so) -######################################################## - -SET(TARGET_PRIV_INFO_LIB "privilege-info") -SET(SO_VERSION 1) -SET(VERSION "${SO_VERSION}.0.0") - -ADD_LIBRARY(${TARGET_PRIV_INFO_LIB} SHARED ${PRIV_INFO_SOURCES}) - -SET_TARGET_PROPERTIES(${TARGET_PRIV_INFO_LIB} PROPERTIES - SOVERSION ${SO_VERSION} - VERSION ${VERSION} -) - -TARGET_LINK_LIBRARIES(${TARGET_PRIV_INFO_LIB} ${${PACKAGE_NAME}_LDFLAGS}) - -####################################################### - -INSTALL(TARGETS ${PACKAGE_NAME} DESTINATION ${LIBDIR}) -INSTALL(FILES ${PROJECT_SOURCE_DIR}/include/privilege_information.h DESTINATION ${INCLUDEDIR}) - -SET(PC_LDFLAGS -l${PACKAGE_NAME}) -CONFIGURE_FILE(../${PACKAGE_NAME}.pc.in ${PACKAGE_NAME}.pc @ONLY) -INSTALL(FILES ${PACKAGE_NAME}.pc DESTINATION ${LIBDIR}/pkgconfig) +SET(TARGET_LIB "privilege-info") +ADD_LIBRARY(${TARGET_LIB} SHARED privilege_information.c) +TARGET_LINK_LIBRARIES(${TARGET_LIB} ${PRIVILEGE_INFO_DEPS_LIBRARIES}) + +SET_TARGET_PROPERTIES(${TARGET_LIB} + PROPERTIES + VERSION "1.0.0" + SOVERSION 1 + C_VISIBILITY_PRESET hidden) + +INSTALL(TARGETS ${TARGET_LIB} LIBRARY) + +INSTALL(FILES + ${CMAKE_SOURCE_DIR}/src/include/privilege_information.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +CONFIGURE_FILE(../privilege-info.pc.in privilege-info.pc @ONLY) +INSTALL(FILES + ${CMAKE_CURRENT_BINARY_DIR}/privilege-info.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8da99db..a402a1b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,24 +1,5 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(PACKAGE_NAME tc-privilege-info) -PROJECT(${PACKAGE_NAME}) +SET(TARGET_TESTS "privilege-info-tests") +ADD_EXECUTABLE(${TARGET_TESTS} tc_privilege_info.c ../src/privilege_information.c) +TARGET_LINK_LIBRARIES(${TARGET_TESTS} ${PRIVILEGE_INFO_DEPS_LIBRARIES}) -SET(TC1_NAME tc-privilege-info) - -SET(TC1_SRCS ${PROJECT_SOURCE_DIR}/tc_privilege_info.c) - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/include) - -SET(requires glib-2.0 dlog) -INCLUDE(FindPkgConfig) -pkg_check_modules(${PACKAGE_NAME} REQUIRED ${requires}) -FOREACH(flag ${${PACKAGE_NAME}_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC -Wall -fvisibility=hidden -D_WITH_SYSTEMD_") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${PACKAGE_NAME_CFLAGS}") - -ADD_EXECUTABLE(${TC1_NAME} ${TC1_SRCS}) -TARGET_LINK_LIBRARIES(${TC1_NAME} "privilege-info") - -INSTALL(TARGETS ${TC1_NAME} DESTINATION /usr/bin) +INSTALL(TARGETS ${TARGET_TESTS} RUNTIME) -- 2.7.4 From 5c8d5b5d7f31e30efa3fe66bad0da011bd46de32 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Wed, 13 Jan 2021 14:07:34 +0100 Subject: [PATCH 13/16] Automate code coverage measurement To gather unit tests coverage report: - use COVERAGE build_type, - install privilege-info-coverage rpm, - run privilege-info-coverage.sh script. Change-Id: I21d6c63ffba6a61646d80facedfe5bdf3c27d797 --- CMakeLists.txt | 9 +++++++++ packaging/privilege-info.spec | 32 ++++++++++++++++++++++++++++++- test/CMakeLists.txt | 23 ++++++++++++++++++++++ test/privilege-info-coverage.sh.in | 39 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 test/privilege-info-coverage.sh.in diff --git a/CMakeLists.txt b/CMakeLists.txt index c8b66fa..0e024a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,8 +8,17 @@ IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "RELEASE") ENDIF(NOT CMAKE_BUILD_TYPE) +IF(NOT DEFINED COVERAGE_DIR) + SET(COVERAGE_DIR + "${SHARE_INSTALL_PREFIX}/${PROJECT_NAME}-coverage" + CACHE PATH + "Read-only coverage data directory") +ENDIF(NOT DEFINED COVERAGE_DIR) +ADD_DEFINITIONS("-DCOVERAGE_DIR=\"${COVERAGE_DIR}\"") + SET(CMAKE_C_FLAGS_DEBUG "-std=c11 -O0 -ggdb -Wp,-U_FORTIFY_SOURCE") SET(CMAKE_C_FLAGS_RELEASE "-std=c11 -O2 -DNDEBUG") +SET(CMAKE_C_FLAGS_COVERAGE "-std=c11 -O0 -ggdb --coverage -Wp,-U_FORTIFY_SOURCE") ADD_DEFINITIONS("-Werror") ADD_DEFINITIONS("-Wall") diff --git a/packaging/privilege-info.spec b/packaging/privilege-info.spec index 5a1cdea..29b8410 100644 --- a/packaging/privilege-info.spec +++ b/packaging/privilege-info.spec @@ -17,6 +17,9 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(security-privilege-manager) +%if "%{build_type}" == "COVERAGE" +BuildRequires: lcov +%endif %description Provides Privilege Information(Privilege Info) API @@ -37,11 +40,29 @@ Requires: %{name} = %{version}-%{release} %description -n privilege-info-tests Privilege Info API Internal Test +%if "%{build_type}" == "COVERAGE" + +%package -n privilege-info-coverage +Summary: Privilege Info code coverage data +Group: Security/Testing +Requires: privilege-info-tests = %{version}-%{release} +Requires: privilege-info-debugsource = %{version}-%{release} +Requires: lcov +Requires: gcc + +%description -n privilege-info-coverage +Privilege Info code coverage data + +%endif + %prep %setup -q %build -%cmake . -DCMAKE_BUILD_TYPE=%{build_type} + +%global coverage_dir %{_datadir}/privilege-info-coverage + +%cmake . -DCMAKE_BUILD_TYPE=%{build_type} -DCOVERAGE_DIR=%{coverage_dir} make %{?jobs:-j%jobs} @@ -69,3 +90,12 @@ rm -rf %{buildroot} %files -n privilege-info-tests %manifest packaging/privilege-info.manifest %{_bindir}/privilege-info-tests + +%if "%{build_type}" == "COVERAGE" + +%files -n privilege-info-coverage +%manifest packaging/privilege-info.manifest +%{_bindir}/privilege-info-coverage.sh +%coverage_dir + +%endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a402a1b..74ccad7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,4 +2,27 @@ SET(TARGET_TESTS "privilege-info-tests") ADD_EXECUTABLE(${TARGET_TESTS} tc_privilege_info.c ../src/privilege_information.c) TARGET_LINK_LIBRARIES(${TARGET_TESTS} ${PRIVILEGE_INFO_DEPS_LIBRARIES}) +IF (CMAKE_BUILD_TYPE MATCHES "COVERAGE") + + # coverage data + SET(COVERAGE_BUILD_DIR + ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TARGET_TESTS}.dir/ + ) + + # install gcno files + INSTALL( + DIRECTORY ${COVERAGE_BUILD_DIR}/ + DESTINATION ${COVERAGE_DIR} + FILES_MATCHING PATTERN "*.gcno" + ) + + # install code coverage automation script + CONFIGURE_FILE(privilege-info-coverage.sh.in privilege-info-coverage.sh @ONLY) + INSTALL( + PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/privilege-info-coverage.sh + DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + +ENDIF (CMAKE_BUILD_TYPE MATCHES "COVERAGE") + INSTALL(TARGETS ${TARGET_TESTS} RUNTIME) diff --git a/test/privilege-info-coverage.sh.in b/test/privilege-info-coverage.sh.in new file mode 100644 index 0000000..42caa34 --- /dev/null +++ b/test/privilege-info-coverage.sh.in @@ -0,0 +1,39 @@ +#!/bin/bash + +set -exuo pipefail + +REPORT="@PROJECT_NAME@-coverage.info" +STDERR="@PROJECT_NAME@-coverage.stderr" +HTML_DIR="@PROJECT_NAME@-coverage" + +SRCS_DIR="/usr/src/debug/@PROJECT_NAME@-@PROJECT_VERSION@" + +# create dir for the report +mkdir $HTML_DIR + +# remove old gcda files +find / -iname "*.gcda" -exec rm {} \; + +# launch unit tests +privilege-info-tests + +# copy source files +cp -rp $SRCS_DIR/* "@CMAKE_BINARY_DIR@" + +# copy gcda files +cp -r "@COVERAGE_BUILD_DIR@"/* "@COVERAGE_DIR@" + +# prepare report +rm -f $STDERR +lcov --no-external -c -d "@COVERAGE_DIR@" -b "@CMAKE_BINARY_DIR@" -o $REPORT 2>$STDERR +lcov -r $REPORT "@CMAKE_BINARY_DIR@/test/*" -o $REPORT + +# check warnings +if [ -s $STDERR ] +then + echo "Warnings detected (see $STDERR). Aborting." + exit 1 +fi + +# html +genhtml $REPORT --output-directory $HTML_DIR/ -- 2.7.4 From a5c4d9a989ab8e736e752fc36955de8f5361e591 Mon Sep 17 00:00:00 2001 From: Tomasz Swierczek Date: Wed, 3 Mar 2021 14:46:59 +0100 Subject: [PATCH 14/16] Fix coverage generation in rpm 4.14.1 Debug source package directories now have different names. Change-Id: I9d6381c56de855d895a6f9d2b1858768657e0e17 --- test/privilege-info-coverage.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/privilege-info-coverage.sh.in b/test/privilege-info-coverage.sh.in index 42caa34..26eaf5c 100644 --- a/test/privilege-info-coverage.sh.in +++ b/test/privilege-info-coverage.sh.in @@ -18,7 +18,7 @@ find / -iname "*.gcda" -exec rm {} \; privilege-info-tests # copy source files -cp -rp $SRCS_DIR/* "@CMAKE_BINARY_DIR@" +cp -rp $SRCS_DIR*/* "@CMAKE_BINARY_DIR@" # copy gcda files cp -r "@COVERAGE_BUILD_DIR@"/* "@COVERAGE_DIR@" -- 2.7.4 From 55a4529b8346ae342b20909322ff4b688ef25ea7 Mon Sep 17 00:00:00 2001 From: Tomasz Swierczek Date: Wed, 19 May 2021 11:03:43 +0200 Subject: [PATCH 15/16] Add license to test file Change-Id: Ifa4ee896b2ea4af0f569f9bac0181607c4bfecf4 --- test/tc_privilege_info.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/tc_privilege_info.c b/test/tc_privilege_info.c index c4f992b..1bf7081 100644 --- a/test/tc_privilege_info.c +++ b/test/tc_privilege_info.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include #include #include -- 2.7.4 From 81a6bd6fea389b2fae596b57f20e88069564bcfa Mon Sep 17 00:00:00 2001 From: Tomasz Swierczek Date: Wed, 19 May 2021 11:15:40 +0200 Subject: [PATCH 16/16] Categorize tests into positive and negative This commit also changes output of unit test binary so its easier to parse by automatic tools. Change-Id: Ia1375d06f0245f7ea9426328a860924d3c2e8682 --- test/tc_privilege_info.c | 388 ++++++++++++++++++++++++++--------------------- 1 file changed, 211 insertions(+), 177 deletions(-) diff --git a/test/tc_privilege_info.c b/test/tc_privilege_info.c index 1bf7081..1ce7d77 100644 --- a/test/tc_privilege_info.c +++ b/test/tc_privilege_info.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2021 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -37,11 +37,6 @@ static void __change_color_to_green() printf("%c[%d;%dm", 0x1B, BRIGHTNESS, GREEN); } -static void __change_color_to_yellow() -{ - printf("%c[%d;%dm", 0x1B, BRIGHTNESS, YELLOW); -} - static void __change_color_to_origin() { printf("%c[%dm", 0x1B, 0); @@ -67,39 +62,37 @@ static const char* __get_result_string(privilege_info_error_e ret) static void __check_get_privilege_display_name_result(privilege_info_error_e expected_result, privilege_info_error_e result, const char* display_name) { - printf("expected : %s\n result : %s\n", __get_result_string(expected_result), __get_result_string(result)); + printf("--- expected : %s\n result : %s\n", __get_result_string(expected_result), __get_result_string(result)); if (expected_result != result) { - printf("not matched\n"); __change_color_to_red(); - printf("test fail\n"); + printf("TEST RESULT: FAILED\n"); fail_cnt++; } else { - printf("matched\n"); if (result == PRVINFO_ERROR_NONE) { if (display_name == NULL) { - printf("display_name must not be NULL\n"); + printf("--- display_name must not be NULL\n"); __change_color_to_red(); - printf("test fail\n"); + printf("TEST RESULT: FAILED\n"); fail_cnt++; __change_color_to_origin(); return; } else { - printf("display_name = %s\n", display_name); + printf("--- display_name = %s\n", display_name); } } else if (result == PRVINFO_ERROR_NO_MATCHING_PRIVILEGE) { if (display_name != NULL) { - printf("display_name = %s\n", display_name); - printf("display_name must be NULL\n"); + printf("--- display_name = %s\n", display_name); + printf("--- display_name must be NULL\n"); __change_color_to_red(); - printf("test fail\n"); + printf("TEST RESULT: FAILED\n"); fail_cnt++; __change_color_to_origin(); return; } } __change_color_to_green(); - printf("test success\n"); + printf("TEST RESULT: SUCCESS\n"); success_cnt++; } __change_color_to_origin(); @@ -108,32 +101,30 @@ static void __check_get_privilege_display_name_result(privilege_info_error_e exp static void __check_get_privilege_description_result(privilege_info_error_e expected_result, privilege_info_error_e result, const char* description) { - printf("expected : %s\n result : %s\n", __get_result_string(expected_result), __get_result_string(result)); + printf("--- expected : %s\n result : %s\n", __get_result_string(expected_result), __get_result_string(result)); if (expected_result != result) { - printf("not matched\n"); __change_color_to_red(); - printf("test fail\n"); + printf("TEST RESULT: FAILED\n"); fail_cnt++; } else { - printf("matched\n"); if (result == PRVINFO_ERROR_NONE) { if (description == NULL) { - printf("description must not be NULL\n"); + printf("--- description must not be NULL\n"); __change_color_to_red(); - printf("test fail\n"); + printf("TEST RESULT: FAILED\n"); fail_cnt++; __change_color_to_origin(); return; } else { - printf("description = %s\n", description); + printf("--- description = %s\n", description); } } else if (result == PRVINFO_ERROR_NO_MATCHING_PRIVILEGE) { if (description != NULL) { - printf("description = %s\n", description); - printf("description must be NULL\n"); + printf("--- description = %s\n", description); + printf("--- description must be NULL\n"); __change_color_to_red(); - printf("test fail\n"); + printf("TEST RESULT: FAILED\n"); fail_cnt++; __change_color_to_origin(); return; @@ -141,7 +132,7 @@ static void __check_get_privilege_description_result(privilege_info_error_e expe } __change_color_to_green(); - printf("test success\n"); + printf("TEST RESULT: SUCCESS\n"); success_cnt++; } __change_color_to_origin(); @@ -149,40 +140,39 @@ static void __check_get_privilege_description_result(privilege_info_error_e expe static void __check_get_privacy_display_name_result(privilege_info_error_e expected_result, privilege_info_error_e result, const char* privacy_display) { - printf("expected : %s\n result : %s\n", __get_result_string(expected_result), __get_result_string(result)); + printf("--- expected : %s\n result : %s\n", __get_result_string(expected_result), __get_result_string(result)); if (expected_result != result) { - printf("not matched\n"); __change_color_to_red(); - printf("test fail\n"); + printf("TEST RESULT: FAILED\n"); fail_cnt++; } else { - printf("matched\n"); if (privacy_display != NULL) - printf("privacy_display_name = %s\n", privacy_display); + printf("--- privacy_display_name = %s\n", privacy_display); else - printf("privacy_display_name is NULL.\n"); + printf("--- privacy_display_name is NULL.\n"); __change_color_to_green(); - printf("test success\n"); + printf("TEST RESULT: SUCCESS\n"); success_cnt++; } __change_color_to_origin(); } -static void __test_privilege_info_get_display_name() +static void __test_positive_privilege_info_get_display_name() { int ret; char* display_name = NULL; - printf("-----------------------------------------------------------\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/window.priority.set\n"); + printf("TEST NAME: %s #1\n",__func__); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/window.priority.set\n"); ret = privilege_info_get_display_name("2.3", "http://tizen.org/privilege/window.priority.set", &display_name); __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name); printf("-----------------------------------------------------------\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/mediacapture\n"); + printf("TEST NAME: %s #2\n",__func__); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/mediacapture\n"); if (display_name != NULL) { free(display_name); display_name = NULL; @@ -190,10 +180,18 @@ static void __test_privilege_info_get_display_name() ret = privilege_info_get_display_name("2.3", "http://tizen.org/privilege/mediacapture", &display_name); __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name); - printf("-----------------------------------------------------------\n"); - printf("Not existing privilege\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/RRRRRRRRRR\n"); + free(display_name); +} + +static void __test_negative_privilege_info_get_display_name() +{ + int ret; + char * display_name = NULL; + + printf("TEST NAME: %s #1\n",__func__); + printf("--- Not existing privilege\n"); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/RRRRRRRRRR\n"); if (display_name != NULL) { free(display_name); display_name = NULL; @@ -201,10 +199,10 @@ static void __test_privilege_info_get_display_name() ret = privilege_info_get_display_name("2.3", "http://tizen.org/privilege/RRRRRRRRRR", &display_name); __check_get_privilege_display_name_result(PRVINFO_ERROR_NO_MATCHING_PRIVILEGE, ret, display_name); - printf("-----------------------------------------------------------\n"); - printf("Invalid parameter\n"); - printf("api_version : NULL\n"); - printf("privilege : http://tizen.org/privilege/window.priority.set\n"); + printf("TEST NAME: %s #2\n",__func__); + printf("--- Invalid parameter\n"); + printf("--- api_version : NULL\n"); + printf("--- privilege : http://tizen.org/privilege/window.priority.set\n"); if (display_name != NULL) { free(display_name); display_name = NULL; @@ -215,22 +213,22 @@ static void __test_privilege_info_get_display_name() free(display_name); } -static void __test_privilege_info_get_display_name_by_pkgtype() +static void __test_positive_privilege_info_get_display_name_by_pkgtype() { int ret; char* display_name = NULL; - printf("-----------------------------------------------------------\n"); - printf("pkgtype : PRVINFO_PACKAGE_TYPE_NATIVE\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/window.priority.set\n"); + printf("TEST NAME: %s #1\n",__func__); + printf("--- pkgtype : PRVINFO_PACKAGE_TYPE_NATIVE\n"); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/window.priority.set\n"); ret = privilege_info_get_display_name_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", "http://tizen.org/privilege/window.priority.set", &display_name); __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name); - printf("-----------------------------------------------------------\n"); - printf("pkgtype : PRVINFO_PACKAGE_TYPE_WEB\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/mediacapture\n"); + printf("TEST NAME: %s #2\n",__func__); + printf("--- pkgtype : PRVINFO_PACKAGE_TYPE_WEB\n"); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/mediacapture\n"); if (display_name != NULL) { free(display_name); display_name = NULL; @@ -238,11 +236,19 @@ static void __test_privilege_info_get_display_name_by_pkgtype() ret = privilege_info_get_display_name_by_pkgtype("PRVINFO_PACKAGE_TYPE_WEB", "2.3", "http://tizen.org/privilege/mediacapture", &display_name); __check_get_privilege_display_name_result(PRVINFO_ERROR_NONE, ret, display_name); - printf("-----------------------------------------------------------\n"); - printf("Mismatched package type: write WEB as NATIVE\n"); - printf("pkgtype : PRVINFO_PACKAGE_TYPE_NATIVE\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/mediacapture\n"); + free(display_name); +} + +static void __test_negative_privilege_info_get_display_name_by_pkgtype() +{ + int ret; + char* display_name = NULL; + + printf("TEST NAME: %s #1\n",__func__); + printf("--- Mismatched package type: write WEB as NATIVE\n"); + printf("--- pkgtype : PRVINFO_PACKAGE_TYPE_NATIVE\n"); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/mediacapture\n"); if (display_name != NULL) { free(display_name); display_name = NULL; @@ -250,11 +256,10 @@ static void __test_privilege_info_get_display_name_by_pkgtype() ret = privilege_info_get_display_name_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", "http://tizen.org/privilege/mediacapture", &display_name); __check_get_privilege_display_name_result(PRVINFO_ERROR_NO_MATCHING_PRIVILEGE, ret, display_name); - - printf("-----------------------------------------------------------\n"); - printf("Not existing privilege\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/RRRRRRRRRR\n"); + printf("TEST NAME: %s #2\n",__func__); + printf("--- Not existing privilege\n"); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/RRRRRRRRRR\n"); if (display_name != NULL) { free(display_name); display_name = NULL; @@ -262,10 +267,10 @@ static void __test_privilege_info_get_display_name_by_pkgtype() ret = privilege_info_get_display_name_by_pkgtype("PRVINFO_PACKAGE_TYPE_WEB", "2.3", "http://tizen.org/privilege/RRRRRRRRRR", &display_name); __check_get_privilege_display_name_result(PRVINFO_ERROR_NO_MATCHING_PRIVILEGE, ret, display_name); - printf("-----------------------------------------------------------\n"); - printf("Invalid parameter\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/mediacapture\n"); + printf("TEST NAME: %s #3\n",__func__); + printf("--- Invalid parameter\n"); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/mediacapture\n"); if (display_name != NULL) { free(display_name); display_name = NULL; @@ -276,20 +281,21 @@ static void __test_privilege_info_get_display_name_by_pkgtype() free(display_name); } -static void __test_privilege_info_get_description() + +static void __test_positive_privilege_info_get_description() { int ret; char* description = NULL; - printf("-----------------------------------------------------------\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/window.priority.set\n"); + printf("TEST NAME: %s #1\n",__func__); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/window.priority.set\n"); ret = privilege_info_get_description("2.3", "http://tizen.org/privilege/window.priority.set", &description); __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description); - printf("-----------------------------------------------------------\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/mediacapture\n"); + printf("TEST NAME: %s #2\n",__func__); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/mediacapture\n"); if (description != NULL) { free(description); description = NULL; @@ -297,10 +303,18 @@ static void __test_privilege_info_get_description() ret = privilege_info_get_description("2.3", "http://tizen.org/privilege/mediacapture", &description); __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description); - printf("-----------------------------------------------------------\n"); - printf("Not existing privilege\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/RRRRRRRRRR\n"); + free(description); +} + +static void __test_negative_privilege_info_get_description() +{ + int ret; + char* description = NULL; + + printf("TEST NAME: %s #1\n",__func__); + printf("--- Not existing privilege\n"); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/RRRRRRRRRR\n"); if (description != NULL) { free(description); description = NULL; @@ -308,10 +322,10 @@ static void __test_privilege_info_get_description() ret = privilege_info_get_description("2.3", "http://tizen.org/privilege/RRRRRRRRRR", &description); __check_get_privilege_description_result(PRVINFO_ERROR_NO_MATCHING_PRIVILEGE, ret, description); - printf("-----------------------------------------------------------\n"); - printf("Invalid parameter\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/mediacapture\n"); + printf("TEST NAME: %s #2\n",__func__); + printf("--- Invalid parameter\n"); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/mediacapture\n"); if (description != NULL) { free(description); description = NULL; @@ -322,20 +336,20 @@ static void __test_privilege_info_get_description() free(description); } -static void __test_privilege_info_get_description_by_pkgtype() +static void __test_positive_privilege_info_get_description_by_pkgtype() { int ret; char* description = NULL; - printf("-----------------------------------------------------------\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/window.priority.set\n"); + printf("TEST NAME: %s #1\n",__func__); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/window.priority.set\n"); ret = privilege_info_get_description_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", "http://tizen.org/privilege/window.priority.set", &description); __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description); - printf("-----------------------------------------------------------\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/mediacapture\n"); + printf("TEST NAME: %s #2\n",__func__); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/mediacapture\n"); if (description != NULL) { free(description); description = NULL; @@ -343,11 +357,19 @@ static void __test_privilege_info_get_description_by_pkgtype() ret = privilege_info_get_description_by_pkgtype("PRVINFO_PACKAGE_TYPE_WEB", "2.3", "http://tizen.org/privilege/mediacapture", &description); __check_get_privilege_description_result(PRVINFO_ERROR_NONE, ret, description); - printf("-----------------------------------------------------------\n"); - printf("Mismatched package type: write WEB as NATIVE\n"); - printf("pkgtype : PRVINFO_PACKAGE_TYPE_NATIVE\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/mediacapture\n"); + free(description); +} + +static void __test_negative_privilege_info_get_description_by_pkgtype() +{ + int ret; + char* description = NULL; + + printf("TEST NAME: %s #1\n",__func__); + printf("--- Mismatched package type: write WEB as NATIVE\n"); + printf("--- pkgtype : PRVINFO_PACKAGE_TYPE_NATIVE\n"); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/mediacapture\n"); if (description != NULL) { free(description); description = NULL; @@ -355,10 +377,10 @@ static void __test_privilege_info_get_description_by_pkgtype() ret = privilege_info_get_description_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", "http://tizen.org/privilege/mediacapture", &description); __check_get_privilege_description_result(PRVINFO_ERROR_NO_MATCHING_PRIVILEGE, ret, description); - printf("-----------------------------------------------------------\n"); - printf("Not existing privilege\n"); - printf("api_version : 2.3\n"); - printf("privilege : http://tizen.org/privilege/RRRRRRRRRR\n"); + printf("TEST NAME: %s #2\n",__func__); + printf("--- Not existing privilege\n"); + printf("--- api_version : 2.3\n"); + printf("--- privilege : http://tizen.org/privilege/RRRRRRRRRR\n"); if (description != NULL) { free(description); description = NULL; @@ -366,10 +388,10 @@ static void __test_privilege_info_get_description_by_pkgtype() ret = privilege_info_get_description_by_pkgtype("PRVINFO_PACKAGE_TYPE_NATIVE", "2.3", "http://tizen.org/privilege/RRRRRRRRRR", &description); __check_get_privilege_description_result(PRVINFO_ERROR_NO_MATCHING_PRIVILEGE, ret, description); - printf("-----------------------------------------------------------\n"); - printf("Invalid parameter\n"); - printf("api_version : 2.3\n"); - printf("privilege : NULL\n"); + printf("TEST NAME: %s #3\n",__func__); + printf("--- Invalid parameter\n"); + printf("--- api_version : 2.3\n"); + printf("--- privilege : NULL\n"); if (description != NULL) { free(description); description = NULL; @@ -380,14 +402,28 @@ static void __test_privilege_info_get_description_by_pkgtype() free(description); } -static void __test_privilege_info_get_privacy_display_name() +static void __test_positive_privilege_info_get_privacy_display_name() { int ret; char* privacy_display_name = NULL; - printf("-----------------------------------------------------------\n"); - printf("Invalid parameter\n"); - printf("no input privilege\n"); + printf("TEST NAME: %s #1\n",__func__); + printf("--- Privacy related privilege\n"); + printf("--- privilege: http://tizen.org/privilege/account.read\n"); + ret = privilege_info_get_privacy_display_name("http://tizen.org/privilege/account.read", &privacy_display_name); + __check_get_privacy_display_name_result(PRVINFO_ERROR_NONE, ret, privacy_display_name); + + free(privacy_display_name); +} + +static void __test_negative_privilege_info_get_privacy_display_name() +{ + int ret; + char* privacy_display_name = NULL; + + printf("TEST NAME: %s #1\n",__func__); + printf("--- Invalid parameter\n"); + printf("--- no input privilege\n"); ret = privilege_info_get_privacy_display_name(NULL, &privacy_display_name); __check_get_privacy_display_name_result(PRVINFO_ERROR_INVALID_PARAMETER, ret, privacy_display_name); @@ -396,9 +432,9 @@ static void __test_privilege_info_get_privacy_display_name() privacy_display_name = NULL; } - printf("-----------------------------------------------------------\n"); - printf("Not a privacy related privilege\n"); - printf("privilege: http://tizen.org/privilege/internet\n"); + printf("TEST NAME: %s #2\n",__func__); + printf("--- Not a privacy related privilege\n"); + printf("--- privilege: http://tizen.org/privilege/internet\n"); ret = privilege_info_get_privacy_display_name("http://tizen.org/privilege/internet", &privacy_display_name); __check_get_privacy_display_name_result(PRVINFO_ERROR_INVALID_PARAMETER, ret, privacy_display_name); @@ -407,9 +443,9 @@ static void __test_privilege_info_get_privacy_display_name() privacy_display_name = NULL; } - printf("-----------------------------------------------------------\n"); - printf("Not existing privilege\n"); - printf("privilege: http://tizen.org/privilege/wrong.privilege.name\n"); + printf("TEST NAME: %s #3\n",__func__); + printf("--- Not existing privilege\n"); + printf("--- privilege: http://tizen.org/privilege/wrong.privilege.name\n"); ret = privilege_info_get_privacy_display_name("http://tizen.org/privilege/wrong.privilege.name", &privacy_display_name); __check_get_privacy_display_name_result(PRVINFO_ERROR_INVALID_PARAMETER, ret, privacy_display_name); @@ -418,38 +454,34 @@ static void __test_privilege_info_get_privacy_display_name() privacy_display_name = NULL; } - printf("-----------------------------------------------------------\n"); - printf("Privacy related privilege\n"); - printf("privilege: http://tizen.org/privilege/account.read\n"); - ret = privilege_info_get_privacy_display_name("http://tizen.org/privilege/account.read", &privacy_display_name); - __check_get_privacy_display_name_result(PRVINFO_ERROR_NONE, ret, privacy_display_name); - free(privacy_display_name); } static void __check_privilege_info_get_privilege_info(privilege_info_error_e expected_result, privilege_info_error_e result, GList* privilege_info_list, int return_result) { - printf("expected : %s\n result : %s\n", __get_result_string(expected_result), __get_result_string(result)); + printf("--- expected : %s\n result : %s\n", __get_result_string(expected_result), __get_result_string(result)); if (expected_result != result) { - __change_color_to_yellow(); - printf("not matched\n"); + __change_color_to_red(); + printf("TEST RESULT: FAILED\n"); + fail_cnt++; __change_color_to_origin(); } else { __change_color_to_green(); - printf("matched\n"); + printf("TEST RESULT: SUCCESS\n"); + success_cnt++; __change_color_to_origin(); } - printf("return_result = %d\n", return_result); + printf("--- return_result = %d\n", return_result); GList* l; if (result == PRVINFO_ERROR_NONE) { for (l = privilege_info_list; l != NULL; l = l->next) { privilege_info_s* privilege_info = (privilege_info_s*)l->data; - printf("privilege_info->privilege_name = %s\n", privilege_info->privilege_name); - printf("privilege_info->display_name = %s\n", privilege_info->display_name); - printf("privilege_info->description = %s\n", privilege_info->description); + printf("--- privilege_info->privilege_name = %s\n", privilege_info->privilege_name); + printf("--- privilege_info->display_name = %s\n", privilege_info->display_name); + printf("--- privilege_info->description = %s\n", privilege_info->description); printf("\n"); } } @@ -457,18 +489,18 @@ static void __check_privilege_info_get_privilege_info(privilege_info_error_e exp printf("\n"); } -static void __test_privilege_info_get_privilege_info_list() +static void __test_positive_privilege_info_get_privilege_info_list() { GList* privilege_name_list = NULL; GList* privilege_info_list = NULL; privilege_consumer_return_code_e return_result; int ret; - printf("case : SUCCESS\n"); - printf("locale : ko_KR.UTF8\n"); - printf("privilege name : http://tizen.org/privilege/call\n"); - printf("privilege name : http://tizen.org/privilege/content.read\n"); - printf("privilege name : http://tizen.org/privilege/filesystem.read\n"); + printf("TEST NAME: %s #1\n",__func__); + printf("--- locale : ko_KR.UTF8\n"); + printf("--- privilege name : http://tizen.org/privilege/call\n"); + printf("--- privilege name : http://tizen.org/privilege/content.read\n"); + printf("--- privilege name : http://tizen.org/privilege/filesystem.read\n"); privilege_name_list = g_list_append(privilege_name_list, "http://tizen.org/privilege/call"); privilege_name_list = g_list_append(privilege_name_list, "http://tizen.org/privilege/content.read"); privilege_name_list = g_list_append(privilege_name_list, "http://tizen.org/privilege/filesystem.read"); @@ -481,11 +513,11 @@ static void __test_privilege_info_get_privilege_info_list() privilege_info_list = NULL; printf("-----------------------------------------------------------\n"); - printf("case : SUCCESS2\n"); - printf("locale : ko_KR.UTF8\n"); - printf("privilege name : http://tizen.org/privilege/call\n"); - printf("privilege name : http://tizen.org/privilege/systemsettings.admin\n"); - printf("privilege name : http://tizen.org/privilege/bookmark.admin\n"); + printf("TEST NAME: %s #2\n",__func__); + printf("--- locale : ko_KR.UTF8\n"); + printf("--- privilege name : http://tizen.org/privilege/call\n"); + printf("--- privilege name : http://tizen.org/privilege/systemsettings.admin\n"); + printf("--- privilege name : http://tizen.org/privilege/bookmark.admin\n"); privilege_name_list = g_list_append(privilege_name_list, "http://tizen.org/privilege/call"); privilege_name_list = g_list_append(privilege_name_list, "http://tizen.org/privilege/systemsettings.admin"); privilege_name_list = g_list_append(privilege_name_list, "http://tizen.org/privilege/bookmark.admin"); @@ -498,11 +530,11 @@ static void __test_privilege_info_get_privilege_info_list() privilege_info_list = NULL; printf("-----------------------------------------------------------\n"); - printf("case : SUCCESS3\n"); - printf("locale : ko_KR.UTF8\n"); - printf("privilege name : http://tizen.org/privilege/call\n"); - printf("privilege name : http://tizen.org/privilege/alarm.xxxx\n"); - printf("privilege name : http://tizen.org/privilege/account.xxx\n"); + printf("TEST NAME: %s #3\n",__func__); + printf("--- locale : ko_KR.UTF8\n"); + printf("--- privilege name : http://tizen.org/privilege/call\n"); + printf("--- privilege name : http://tizen.org/privilege/alarm.xxxx\n"); + printf("--- privilege name : http://tizen.org/privilege/account.xxx\n"); privilege_name_list = g_list_append(privilege_name_list, "http://tizen.org/privilege/call"); privilege_name_list = g_list_append(privilege_name_list, "http://tizen.org/privilege/alarm.xxxx"); privilege_name_list = g_list_append(privilege_name_list, "http://tizen.org/privilege/account.xxx"); @@ -514,12 +546,21 @@ static void __test_privilege_info_get_privilege_info_list() privilege_info_free_privilege_info_list(privilege_info_list); privilege_info_list = NULL; printf("-----------------------------------------------------------\n"); +} - printf("case : UNKNOWN_LOCAL_CODE\n"); - printf("locale : xx_XX.UTF8\n"); - printf("privilege name : http://tizen.org/privilege/call\n"); - printf("privilege name : http://tizen.org/privilege/content.read\n"); - printf("privilege name : http://tizen.org/privilege/filesystem.read\n"); +static void __test_negative_privilege_info_get_privilege_info_list() +{ + GList* privilege_name_list = NULL; + GList* privilege_info_list = NULL; + privilege_consumer_return_code_e return_result; + int ret; + + printf("TEST NAME: %s #1\n",__func__); + printf("--- UNKNOWN_LOCAL_CODE\n"); + printf("--- locale : xx_XX.UTF8\n"); + printf("--- privilege name : http://tizen.org/privilege/call\n"); + printf("--- privilege name : http://tizen.org/privilege/content.read\n"); + printf("--- privilege name : http://tizen.org/privilege/filesystem.read\n"); privilege_name_list = g_list_append(privilege_name_list, "http://tizen.org/privilege/call"); privilege_name_list = g_list_append(privilege_name_list, "http://tizen.org/privilege/content.read"); privilege_name_list = g_list_append(privilege_name_list, "http://tizen.org/privilege/filesystem.read"); @@ -530,13 +571,13 @@ static void __test_privilege_info_get_privilege_info_list() privilege_name_list = NULL; privilege_info_free_privilege_info_list(privilege_info_list); privilege_info_list = NULL; - printf("-----------------------------------------------------------\n"); - printf("case : INVAILD_PARAMETER\n"); - printf("locale : ko_KR.UTF8\n"); - printf("privilege name : http://tizen.org/privilege/xxxx\n"); - printf("privilege name : http://tizen.org/privilege/alarm.xxxx\n"); - printf("privilege name : http://tizen.org/privilege/account.xxx\n"); + printf("TEST NAME: %s #2\n",__func__); + printf("--- INVAILD_PARAMETER\n"); + printf("--- locale : ko_KR.UTF8\n"); + printf("--- privilege name : http://tizen.org/privilege/xxxx\n"); + printf("--- privilege name : http://tizen.org/privilege/alarm.xxxx\n"); + printf("--- privilege name : http://tizen.org/privilege/account.xxx\n"); privilege_name_list = g_list_append(privilege_name_list, "http://tizen.org/privilege/xxxx"); privilege_name_list = g_list_append(privilege_name_list, "http://tizen.org/privilege/alarm.xxxx"); privilege_name_list = g_list_append(privilege_name_list, "http://tizen.org/privilege/account.xxx"); @@ -548,40 +589,33 @@ static void __test_privilege_info_get_privilege_info_list() privilege_info_free_privilege_info_list(privilege_info_list); privilege_info_list = NULL; printf("-----------------------------------------------------------\n"); - } int main() { - __change_color_to_yellow(); - printf("Test function : privilege_info_get_display_name\n"); __change_color_to_origin(); - __test_privilege_info_get_display_name(); + __test_positive_privilege_info_get_display_name(); + __test_negative_privilege_info_get_display_name(); - __change_color_to_yellow(); - printf("Test function : privilege_info_get_display_name_by_pkgtype\n"); __change_color_to_origin(); - __test_privilege_info_get_display_name_by_pkgtype(); + __test_positive_privilege_info_get_display_name_by_pkgtype(); + __test_negative_privilege_info_get_display_name_by_pkgtype(); - __change_color_to_yellow(); - printf("Test function : privilege_info_get_description\n"); __change_color_to_origin(); - __test_privilege_info_get_description(); + __test_positive_privilege_info_get_description(); + __test_negative_privilege_info_get_description(); - __change_color_to_yellow(); - printf("Test function : privilege_info_get_description_by_pkgtype\n"); __change_color_to_origin(); - __test_privilege_info_get_description_by_pkgtype(); + __test_positive_privilege_info_get_description_by_pkgtype(); + __test_negative_privilege_info_get_description_by_pkgtype(); - __change_color_to_yellow(); - printf("Test function : privilege_info_get_privacy_display_name\n"); __change_color_to_origin(); - __test_privilege_info_get_privacy_display_name(); + __test_positive_privilege_info_get_privacy_display_name(); + __test_negative_privilege_info_get_privacy_display_name(); - __change_color_to_yellow(); - printf("Test function : privilege_info_get_privilege_info_list\n"); __change_color_to_origin(); - __test_privilege_info_get_privilege_info_list(); + __test_positive_privilege_info_get_privilege_info_list(); + __test_negative_privilege_info_get_privilege_info_list(); __change_color_to_green(); printf("Test Complete\n"); -- 2.7.4