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")
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})
ZonePolicy zone = client.createPolicyInterface<ZonePolicy>();
int result = zone.getZoneState(name);
- if (result <0) {
+ if (result == 0) {
return DPM_ERROR_NO_DATA;
}
ZonePolicy zone = client.createPolicyInterface<ZonePolicy>();
std::vector<std::string> 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;
restriction.c
security.c
wifi.c
+ zone.c
)
ADD_EXECUTABLE(${API_TEST_TARGET} ${API_TEST_SOURCES})
#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);
}
#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)
ZoneManager zone = client.createPolicyInterface<ZoneManager>();
int result = zone.getZoneState(name);
- if (result <0) {
+ if (result == 0) {
return ZONE_ERROR_NO_DATA;
}
return ZONE_ERROR_NONE;
}
-typedef runtime::Array<std::string> 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<ZoneManager>();
-
- return reinterpret_cast<zone_iterator_h>(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<zone_iterator*>(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<zone_iterator*>(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)
{
std::vector<std::string> list = zone.getZoneList(state);
for (std::vector<std::string>::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;
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