From 38c7ebd2b4e333dd4c96c2140a81833090a70c2a Mon Sep 17 00:00:00 2001 From: Sungbae Yoo Date: Mon, 4 Jul 2016 15:33:25 +0900 Subject: [PATCH] Add Zone API test cases Signed-off-by: Sungbae Yoo Change-Id: I35085203dcc191f33ccf3569b9df84ac457b5047 --- CMakeLists.txt | 5 +-- libs/dpm/zone.cpp | 5 ++- tests/api/CMakeLists.txt | 1 + tests/api/zone.c | 91 +++++++++++++++++++++++++++++++++++----------- tests/integration/zone.cpp | 2 +- zone/libs/zone/zone.cpp | 41 ++------------------- zone/libs/zone/zone.h | 72 +----------------------------------- 7 files changed, 81 insertions(+), 136 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 05ed5a6..d82ebbe 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,9 +32,9 @@ SET(DPM_COMMON ${PROJECT_SOURCE_DIR}/common) SET(DPM_POLICY ${PROJECT_SOURCE_DIR}/policy) SET(DPM_LIBS ${PROJECT_SOURCE_DIR}/libs) SET(DPM_SERVER ${PROJECT_SOURCE_DIR}/server) -SET(DPM_TESTS ${PROJECT_SOURCE_DIR}/tests) SET(DPM_TOOLS ${PROJECT_SOURCE_DIR}/tools) SET(DPM_ZONE ${PROJECT_SOURCE_DIR}/zone) +SET(DPM_TESTS ${PROJECT_SOURCE_DIR}/tests) IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7) SET(CXX_STD "c++0x") @@ -89,9 +89,8 @@ ADD_DEFINITIONS(-DUG_WAYLAND) ADD_SUBDIRECTORY(${DPM_COMMON}) ADD_SUBDIRECTORY(${DPM_SERVER}) ADD_SUBDIRECTORY(${DPM_LIBS}) -ADD_SUBDIRECTORY(${DPM_TESTS}) ADD_SUBDIRECTORY(${DPM_TOOLS}) - IF("${TIZEN_PROFILE_NAME}" STREQUAL "mobile") ADD_SUBDIRECTORY(${DPM_ZONE}) ENDIF() +ADD_SUBDIRECTORY(${DPM_TESTS}) diff --git a/libs/dpm/zone.cpp b/libs/dpm/zone.cpp index 6e02e5f..6e76ade 100755 --- a/libs/dpm/zone.cpp +++ b/libs/dpm/zone.cpp @@ -53,7 +53,7 @@ EXPORT_API int dpm_zone_get_state(device_policy_manager_h handle, const char* na ZonePolicy zone = client.createPolicyInterface(); int result = zone.getZoneState(name); - if (result <0) { + if (result == 0) { return DPM_ERROR_NO_DATA; } @@ -71,7 +71,8 @@ EXPORT_API int dpm_zone_foreach_name(device_policy_manager_h handle, dpm_zone_st ZonePolicy zone = client.createPolicyInterface(); std::vector list = zone.getZoneList(state); for (const std::string& name : list) { - callback(name.c_str(), user_data); + if (!callback(name.c_str(), user_data)) + break; } return DPM_ERROR_NONE; diff --git a/tests/api/CMakeLists.txt b/tests/api/CMakeLists.txt index 6311b7a..ceb375b 100644 --- a/tests/api/CMakeLists.txt +++ b/tests/api/CMakeLists.txt @@ -26,6 +26,7 @@ SET(API_TEST_SOURCES main.c restriction.c security.c wifi.c + zone.c ) ADD_EXECUTABLE(${API_TEST_TARGET} ${API_TEST_SOURCES}) diff --git a/tests/api/zone.c b/tests/api/zone.c index 761b8f1..edef35f 100644 --- a/tests/api/zone.c +++ b/tests/api/zone.c @@ -21,58 +21,105 @@ #include "testbench.h" #define TEST_ZONE_ID "zone1" -#define TEST_SETUP_WIZARD_PKG_ID "org.tizen.zone-setup-wizard" +#define TEST_SETUP_WIZARD_PKG_ID "org.tizen.krate-setup-wizard" + +#define OWNER_ZONE_ID "owner" static int zone_create(struct testcase* tc) { - int ret; - dpm_context_h context; - dpm_zone_policy_h policy; - dpm_zone_state_e state; + int ret = TEST_SUCCESSED; + device_policy_manager_h handle; - context = dpm_context_create(); - if (context == NULL) { + handle = dpm_manager_create(); + if (handle == NULL) { printf("Failed to create client context\n"); return TEST_FAILED; } - policy = dpm_context_acquire_zone_policy(context); - if (policy == NULL) { - printf("Failed to get zone policy"); - dpm_context_destroy(context); + if (dpm_zone_create(handle, TEST_ZONE_ID, TEST_SETUP_WIZARD_PKG_ID) != DPM_ERROR_NONE) { + ret = TEST_FAILED; + goto out; + } + +out: + dpm_manager_destroy(handle); + + return ret; +} + +static int zone_get_state(struct testcase* tc) +{ + int ret = TEST_SUCCESSED; + device_policy_manager_h handle; + dpm_zone_state_e state; + + handle = dpm_manager_create(); + if (handle == NULL) { + printf("Failed to create client context\n"); return TEST_FAILED; } - ret = TEST_SUCCESSED; - if (dpm_zone_create(policy, TEST_ZONE_ID, TEST_SETUP_WIZARD_PKG_ID) != DPM_ERROR_NONE) { + if (dpm_zone_get_state(handle, OWNER_ZONE_ID, &state) != DPM_ERROR_NONE) { ret = TEST_FAILED; goto out; } - if (dpm_zone_get_state(policy, TEST_ZONE_ID, &state) != DPM_ERROR_NONE) { + if (state == 0) { ret = TEST_FAILED; - goto remove; } -remove: - if (dpm_zone_destroy(policy, TEST_ZONE_ID) == DPM_ERROR_NONE) { +out: + dpm_manager_destroy(handle); + + return ret; +} + +static bool get_list_cb(const char* name, void* result) +{ + *((int*)result) = TEST_SUCCESSED; + return true; +} + +static int zone_get_list(struct testcase* tc) +{ + int ret = TEST_SUCCESSED; + device_policy_manager_h handle; + + handle = dpm_manager_create(); + if (handle == NULL) { + printf("Failed to create client context\n"); + return TEST_FAILED; + } + + if (dpm_zone_foreach_name(handle, DPM_ZONE_STATE_ALL, get_list_cb, &ret) != DPM_ERROR_NONE) { ret = TEST_FAILED; goto out; } out: - dpm_context_release_zone_policy(context, policy); - dpm_context_destroy(context); + dpm_manager_destroy(handle); return ret; } -struct testcase zone_testcase_lifecycle = { - .description = "dpm_zone", +struct testcase dpm_zone_testcase_lifecycle = { + .description = "dpm_zone_lifecycle", .handler = zone_create }; +struct testcase dpm_zone_testcase_state = { + .description = "dpm_zone_state", + .handler = zone_get_state +}; + +struct testcase dpm_zone_testcase_list = { + .description = "dpm_zone_list", + .handler = zone_get_list +}; + void TESTCASE_CONSTRUCTOR zone_policy_build_testcase(void) { - testbench_populate_testcase(&zone_testcase_lifecycle); + testbench_populate_testcase(&dpm_zone_testcase_lifecycle); + testbench_populate_testcase(&dpm_zone_testcase_state); + testbench_populate_testcase(&dpm_zone_testcase_list); } diff --git a/tests/integration/zone.cpp b/tests/integration/zone.cpp index 05861d2..e764ea7 100644 --- a/tests/integration/zone.cpp +++ b/tests/integration/zone.cpp @@ -22,7 +22,7 @@ #include "audit/logger.h" #include "testbench/testbench.h" -const std::string testSetupWizardAppid = "org.tizen.zone-setup-wizard"; +const std::string testSetupWizardAppid = "org.tizen.krate-setup-wizard"; const std::string testZonePolicyName = "zone1"; TESTCASE(ZonePolicyCreateTest) diff --git a/zone/libs/zone/zone.cpp b/zone/libs/zone/zone.cpp index 2342f5e..bce2286 100644 --- a/zone/libs/zone/zone.cpp +++ b/zone/libs/zone/zone.cpp @@ -116,7 +116,7 @@ int zone_manager_get_zone_state(zone_manager_h handle, const char* name, zone_st ZoneManager zone = client.createPolicyInterface(); int result = zone.getZoneState(name); - if (result <0) { + if (result == 0) { return ZONE_ERROR_NO_DATA; } @@ -124,42 +124,6 @@ int zone_manager_get_zone_state(zone_manager_h handle, const char* name, zone_st return ZONE_ERROR_NONE; } -typedef runtime::Array zone_iterator; - -zone_iterator_h zone_manager_create_zone_iterator(zone_manager_h handle, zone_state_e state) -{ - RET_ON_FAILURE(handle, NULL); - - DevicePolicyContext &client = GetDevicePolicyContext(handle); - ZoneManager zone = client.createPolicyInterface(); - - return reinterpret_cast(new zone_iterator(zone.getZoneList(state))); -} - -int zone_iterator_next(zone_iterator_h iter, const char** result) -{ - RET_ON_FAILURE(iter, ZONE_ERROR_INVALID_PARAMETER); - RET_ON_FAILURE(result, ZONE_ERROR_INVALID_PARAMETER); - - zone_iterator* it = reinterpret_cast(iter); - - if (it->isEnd()) - *result = NULL; - else - *result = it->next()->c_str(); - - return ZONE_ERROR_NONE; -} - -int zone_iterator_destroy(zone_iterator_h iter) -{ - RET_ON_FAILURE(iter, ZONE_ERROR_INVALID_PARAMETER); - - delete reinterpret_cast(iter); - - return ZONE_ERROR_NONE; -} - int zone_manager_foreach_name(zone_manager_h handle, zone_state_e state, zone_manager_foreach_cb callback, void* user_data) { @@ -171,7 +135,8 @@ int zone_manager_foreach_name(zone_manager_h handle, zone_state_e state, std::vector list = zone.getZoneList(state); for (std::vector::iterator it = list.begin(); it != list.end(); it++) { - callback((*it).c_str(), user_data); + if (!callback((*it).c_str(), user_data)) + break; } return ZONE_ERROR_NONE; diff --git a/zone/libs/zone/zone.h b/zone/libs/zone/zone.h index 2ae3c33..3e3e2bb 100644 --- a/zone/libs/zone/zone.h +++ b/zone/libs/zone/zone.h @@ -240,82 +240,14 @@ typedef enum { ZONE_API int zone_manager_get_zone_state(zone_manager_h handle, const char* name, zone_state_e* state); /** - * @brief The zone list iterator handle - * @since_tizen 3.0 - * @see zone_manager_create_zone_terator() - * @see zone_iterator_next() - * @see zone_iterator_destroy() - */ -typedef void* zone_iterator_h; - -/** - * @brief Creates a zone list iterator. - * @details The zone list iterator can be used to get all defined zones. - * @since_tizen 3.0 - * @param[in] handle The zone policy handle - * @param[in] state a combination of the zone state to look - * @return A zone list iterator on success, otherwise - * null value - * @remark The specific error code can be obtained by using the - * get_last_result() method. Error codes are described in - * exception section. - * @exception #ZONE_ERROR_NONE No error - * @exception #ZONE_ERROR_OUT_OF_MEMORY Out of memory - * @exception #ZONE_ERROR_INVALID_PARAMETER Invalid parameter - * @exception #ZONE_ERROR_TIMED_OUT Time out - * @pre The handle must be created by zone_manager_create(). - * @see zone_manager_create() - * @see zone_manager_destroy() - * @see zone_manager_create_zone() - * @see zone_manager_destroy_zone() - * @see zone_iterator_next() - * @see zone_interator_destroy() - * @see get_last_result() - */ -ZONE_API zone_iterator_h zone_manager_create_zone_iterator(zone_manager_h handle, zone_state_e state); - -/** - * @brief Fetches a zone name and forwards the iterator. - * @details This API returns zone name indicated by the iterator, and then - * the iterator is moved to the next position. If the iterator reaches - * the end of the list, null value will be returned. - * @since_tizen 3.0 - * @param[in] iter The iterator to be controlled - * @param[out] zone_name The zone name got from the iterator - * @return #ZONE_ERROR_NONE on success, otherwise a negative value - * @retval #ZONE_ERROR_NONE Successful - * @retval #ZONE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #ZONE_ERROR_TIMED_OUT Time out - * @pre The iter must be created by zone_manager_create_iterator(). - * @see zone_manager_create_zone_iterator() - * @see zone_interator_destroy() - */ -ZONE_API int zone_iterator_next(zone_iterator_h iter, const char** zone_name); - -/** - * @brief Frees the zone iterator. - * @details This API frees the zone iterator. This API must be called - * if the iterator no longer used. - * @since_tizen 3.0 - * @param[in] iter The iterator to be removed - * @return #ZONE_ERROR_NONE on success, otherwise a negative value - * @retval #ZONE_ERROR_NONE Successful - * @retval #ZONE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #ZONE_ERROR_TIMED_OUT Time out - * @pre The iter must be created by zone_manager_create_iterator() - * @see zone_manager_create_zone_iterator() - * @see zone_iterator_next() - */ -ZONE_API int zone_iterator_destroy(zone_iterator_h iter); - -/** * @brief Called to get all the name of created zones. * @since_tizen 3.0 * @param[in] name The zone name * @param[in] user_data The user data passed from zone_manager_foreach_name + * @return true to continue with the next iteration of the loop, otherwise false to break out out the loop * @see zone_manager_foreach_name() */ -typedef void(*zone_manager_foreach_cb)(const char* name, void* user_data); +typedef bool(*zone_manager_foreach_cb)(const char* name, void* user_data); /** * @brief Retrieves all the name of created zones -- 2.7.4