revise file names for readability
authorYoungjae Shin <yj99.shin@samsung.com>
Mon, 11 May 2020 05:18:32 +0000 (14:18 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Mon, 11 May 2020 09:21:08 +0000 (18:21 +0900)
41 files changed:
CMakeLists.txt
client/mdsc.c
client/mdsc_add_remove.c [new file with mode: 0644]
client/mdsc_apply.c [new file with mode: 0644]
client/mdsc_apply_mode.c [deleted file]
client/mdsc_insert_del_mode.c [deleted file]
client/mdsc_noti_mode.c [deleted file]
client/mdsc_noti_mode.h [deleted file]
client/mdsc_subscribe.c [new file with mode: 0644]
client/mdsc_subscribe.h [new file with mode: 0644]
client/mdsc_undo.c [new file with mode: 0644]
client/mdsc_undo_mode.c [deleted file]
packaging/modes.spec
tests/CMakeLists.txt [new file with mode: 0644]
tests/modes-gtest-run.sh [new file with mode: 0644]
tests/modes_mode_test.c [new file with mode: 0644]
tests/modes_test_async.cpp [new file with mode: 0644]
tests/modes_test_client.cpp [new file with mode: 0644]
tests/modes_test_conflict.cpp [new file with mode: 0644]
tests/modes_test_generator.cpp [new file with mode: 0644]
tests/modes_test_main.cpp [new file with mode: 0644]
tests/modes_test_modemgr.cpp [new file with mode: 0644]
tests/modes_test_noti.cpp [new file with mode: 0644]
tests/modes_test_parser.cpp [new file with mode: 0644]
tests/modes_test_plugin.cpp [new file with mode: 0644]
tests/modes_test_policy.cpp [new file with mode: 0644]
tests/modes_test_rulemgr.cpp [new file with mode: 0644]
unittest/CMakeLists.txt [deleted file]
unittest/modes-gtest-run.sh [deleted file]
unittest/modes_mode_test.c [deleted file]
unittest/modes_test_async.cpp [deleted file]
unittest/modes_test_client.cpp [deleted file]
unittest/modes_test_conflict.cpp [deleted file]
unittest/modes_test_generator.cpp [deleted file]
unittest/modes_test_main.cpp [deleted file]
unittest/modes_test_modemgr.cpp [deleted file]
unittest/modes_test_noti.cpp [deleted file]
unittest/modes_test_parser.cpp [deleted file]
unittest/modes_test_plugin.cpp [deleted file]
unittest/modes_test_policy.cpp [deleted file]
unittest/modes_test_rulemgr.cpp [deleted file]

index ee00e4c514f5a9dcef3d578c5a54351584bba11f..9aa1f35194f24c2242ecc950c8d6e1e85fdb4bfd 100644 (file)
@@ -32,4 +32,4 @@ ADD_SUBDIRECTORY(common)
 ADD_SUBDIRECTORY(client)
 ADD_SUBDIRECTORY(supervisor)
 ADD_SUBDIRECTORY(plugin)
-ADD_SUBDIRECTORY(unittest)
+ADD_SUBDIRECTORY(tests)
index fba12f83b38dd76d651626eac1476c1bb766de02..a6cee7bd89bd047ee22ca5b26a1c6d293516fc27 100644 (file)
@@ -20,7 +20,7 @@
 #include "mdsc.h"
 #include "common/dbus.h"
 #include "common/dbus_def.h"
-#include "mdsc_noti_mode.h"
+#include "mdsc_subscribe.h"
 
 API modes_h modes_connect()
 {
@@ -56,7 +56,7 @@ API void modes_disconnect(modes_h handle)
 {
        RET_IF(NULL == handle);
 
-       mdsc_noti_terminate(handle);
+       mdsc_subscription_disconnect(handle);
        pthread_mutex_destroy(&handle->noti_mutex);
        g_object_unref(handle->conn);
        handle->conn = NULL;
diff --git a/client/mdsc_add_remove.c b/client/mdsc_add_remove.c
new file mode 100644 (file)
index 0000000..b2cdfb1
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * Copyright (c) 2019-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 "modes.h"
+
+#include <stdlib.h>
+#include <glib.h>
+#include "mdsc.h"
+#include "common/dbus.h"
+#include "common/dbus_def.h"
+
+struct mds_action_handle {
+       char *id;
+       char *rule;
+       char *value;
+};
+
+struct mds_mode_handle {
+       char *name;
+       modes_type_mode_e type;
+       bool hidden;
+       GList *action_list;
+};
+
+static int _mdsc_dbus_add_mode_sync(mdsDbus *mdsc_dbus, GVariant *mode_data)
+{
+       int result = MODES_ERROR_NONE;
+       gboolean ret;
+       GError *error = NULL;
+
+       RETV_IF(NULL == mode_data, MODES_ERROR_INVALID_PARAMETER);
+
+       ret = mds_dbus_call_add_mode_sync(mdsc_dbus, mode_data, &result, NULL, &error);
+       if (FALSE == ret) {
+               ERR("mds_dbus_call_add_mode_sync() Fail(%s)", error ? error->message : "unknown");
+               g_error_free(error);
+               return MODES_ERROR_SYSTEM;
+       }
+
+       return result;
+}
+
+static int _mdsc_dbus_remove_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
+{
+       int result = MODES_ERROR_NONE;
+       gboolean ret;
+       GError *error = NULL;
+
+       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+
+       ret = mds_dbus_call_remove_mode_sync(mdsc_dbus, mode, &result, NULL, &error);
+       if (FALSE == ret) {
+               ERR("mds_dbus_call_remove_mode_sync() Fail(%s)", error ? error->message : "unknown");
+               g_error_free(error);
+               return MODES_ERROR_SYSTEM;
+       }
+
+       return result;
+}
+
+static void _mdsc_free_action(gpointer data)
+{
+       RET_IF(NULL == data);
+
+       struct mds_action_handle *action_data = data;
+
+       free(action_data->id);
+       free(action_data->rule);
+       free(action_data->value);
+       free(action_data);
+}
+
+static GVariant* _mdsc_create_mode_data(modes_mode_h mode)
+{
+       RETV_IF(NULL == mode, NULL);
+
+       GVariantBuilder *action_builder = g_variant_builder_new(G_VARIANT_TYPE(MODES_DBUS_ACTION_LIST_SIG));
+       GList *it = g_list_first(mode->action_list);
+
+       while (NULL != it) {
+               struct mds_action_handle *action_data = (struct mds_action_handle *)it->data;
+               g_variant_builder_add(action_builder, MODES_DBUS_ACTION_SIG, MODES_DBUS_SAFE_STR(action_data->id),
+                       MODES_DBUS_SAFE_STR(action_data->rule), MODES_DBUS_SAFE_STR(action_data->value));
+               it = g_list_next(it);
+       }
+
+       GVariant *action = g_variant_new(MODES_DBUS_ACTION_LIST_SIG, action_builder);
+       GVariant *mode_data = g_variant_new(MODES_DBUS_MODE_SIG, mode->name, mode->type, mode->hidden, action);
+       g_variant_builder_unref(action_builder);
+
+       return mode_data;
+}
+
+API modes_mode_h modes_create_mode(const char *name, modes_type_mode_e type)
+{
+       struct mds_mode_handle *mode;
+
+       RETV_IF(NULL == name, NULL);
+
+       mode = malloc(sizeof(struct mds_mode_handle));
+       RETV_IF(NULL == mode, NULL);
+
+       mode->name = strdup(name);
+       mode->type = type;
+       mode->hidden = false;
+       mode->action_list = NULL;
+
+       return mode;
+}
+
+API int modes_set_hidden(modes_mode_h mode, bool hidden)
+{
+       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+
+       mode->hidden = hidden;
+
+       return MODES_ERROR_NONE;
+}
+
+API modes_action_h modes_create_action(const char *name, const char *value)
+{
+       struct mds_action_handle *action;
+
+       RETV_IF(NULL == name, NULL);
+       RETV_IF(NULL == value, NULL);
+
+       action = malloc(sizeof(struct mds_action_handle));
+       RETV_IF(NULL == action, NULL);
+
+       action->rule = strdup(name);
+       action->value = strdup(value);
+       action->id = NULL;
+
+       return action;
+}
+
+API int modes_mode_add_action(modes_mode_h mode, modes_action_h action)
+{
+       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == action, MODES_ERROR_INVALID_PARAMETER);
+
+       mode->action_list = g_list_append(mode->action_list, action);
+
+       return MODES_ERROR_NONE;
+}
+
+API int modes_add_mode(modes_h handle, modes_mode_h mode)
+{
+       int ret;
+
+       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+
+       GVariant *mode_data = _mdsc_create_mode_data(mode);
+       RETV_IF(NULL == mode_data, MODES_ERROR_INVALID_PARAMETER);
+
+       ret = _mdsc_dbus_add_mode_sync(handle->conn, mode_data);
+       if (MODES_ERROR_NONE != ret) {
+               ERR("_mdsc_dbus_add_mode_sync() Fail(%d)", ret);
+               return ret;
+       }
+
+       return MODES_ERROR_NONE;
+}
+
+API int modes_remove_mode(modes_h handle, const char *name)
+{
+       int ret;
+       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == name, MODES_ERROR_INVALID_PARAMETER);
+
+       ret = _mdsc_dbus_remove_mode_sync(handle->conn, name);
+       if (MODES_ERROR_NONE != ret) {
+               ERR("_mdsc_dbus_remove_mode_sync() Fail(%d)", ret);
+               return ret;
+       }
+
+       return MODES_ERROR_NONE;
+}
+
+API void modes_destroy_mode(modes_mode_h mode)
+{
+       RET_IF(NULL == mode);
+
+       free(mode->name);
+
+       g_list_free_full(mode->action_list, _mdsc_free_action);
+
+       free(mode);
+}
+
diff --git a/client/mdsc_apply.c b/client/mdsc_apply.c
new file mode 100644 (file)
index 0000000..2dda682
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2019-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 "modes.h"
+
+#include <glib.h>
+#include "mdsc.h"
+#include "common/dbus.h"
+
+static int _mdsc_dbus_apply_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
+{
+       int result = MODES_ERROR_NONE;
+       gboolean ret;
+       GError *error = NULL;
+
+       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+
+       ret = mds_dbus_call_apply_mode_sync(mdsc_dbus, mode, &result, NULL, &error);
+       if (FALSE == ret) {
+               ERR("mds_dbus_call_apply_mode_sync() Fail(%s)", error ? error->message : "unknown");
+               g_error_free(error);
+               return MODES_ERROR_SYSTEM;
+       }
+
+       return result;
+}
+
+API int modes_apply_mode(modes_h handle, const char *name)
+{
+       int ret;
+       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == name, MODES_ERROR_INVALID_PARAMETER);
+
+       ret = _mdsc_dbus_apply_mode_sync(handle->conn, name);
+       if (MODES_ERROR_NONE != ret) {
+               ERR("_mdsc_bus_client_change_mode_sync() Fail(%d)", ret);
+               return ret;
+       }
+
+       return MODES_ERROR_NONE;
+}
diff --git a/client/mdsc_apply_mode.c b/client/mdsc_apply_mode.c
deleted file mode 100644 (file)
index 2dda682..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2019-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 "modes.h"
-
-#include <glib.h>
-#include "mdsc.h"
-#include "common/dbus.h"
-
-static int _mdsc_dbus_apply_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
-{
-       int result = MODES_ERROR_NONE;
-       gboolean ret;
-       GError *error = NULL;
-
-       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
-
-       ret = mds_dbus_call_apply_mode_sync(mdsc_dbus, mode, &result, NULL, &error);
-       if (FALSE == ret) {
-               ERR("mds_dbus_call_apply_mode_sync() Fail(%s)", error ? error->message : "unknown");
-               g_error_free(error);
-               return MODES_ERROR_SYSTEM;
-       }
-
-       return result;
-}
-
-API int modes_apply_mode(modes_h handle, const char *name)
-{
-       int ret;
-       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == name, MODES_ERROR_INVALID_PARAMETER);
-
-       ret = _mdsc_dbus_apply_mode_sync(handle->conn, name);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("_mdsc_bus_client_change_mode_sync() Fail(%d)", ret);
-               return ret;
-       }
-
-       return MODES_ERROR_NONE;
-}
diff --git a/client/mdsc_insert_del_mode.c b/client/mdsc_insert_del_mode.c
deleted file mode 100644 (file)
index b2cdfb1..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Copyright (c) 2019-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 "modes.h"
-
-#include <stdlib.h>
-#include <glib.h>
-#include "mdsc.h"
-#include "common/dbus.h"
-#include "common/dbus_def.h"
-
-struct mds_action_handle {
-       char *id;
-       char *rule;
-       char *value;
-};
-
-struct mds_mode_handle {
-       char *name;
-       modes_type_mode_e type;
-       bool hidden;
-       GList *action_list;
-};
-
-static int _mdsc_dbus_add_mode_sync(mdsDbus *mdsc_dbus, GVariant *mode_data)
-{
-       int result = MODES_ERROR_NONE;
-       gboolean ret;
-       GError *error = NULL;
-
-       RETV_IF(NULL == mode_data, MODES_ERROR_INVALID_PARAMETER);
-
-       ret = mds_dbus_call_add_mode_sync(mdsc_dbus, mode_data, &result, NULL, &error);
-       if (FALSE == ret) {
-               ERR("mds_dbus_call_add_mode_sync() Fail(%s)", error ? error->message : "unknown");
-               g_error_free(error);
-               return MODES_ERROR_SYSTEM;
-       }
-
-       return result;
-}
-
-static int _mdsc_dbus_remove_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
-{
-       int result = MODES_ERROR_NONE;
-       gboolean ret;
-       GError *error = NULL;
-
-       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
-
-       ret = mds_dbus_call_remove_mode_sync(mdsc_dbus, mode, &result, NULL, &error);
-       if (FALSE == ret) {
-               ERR("mds_dbus_call_remove_mode_sync() Fail(%s)", error ? error->message : "unknown");
-               g_error_free(error);
-               return MODES_ERROR_SYSTEM;
-       }
-
-       return result;
-}
-
-static void _mdsc_free_action(gpointer data)
-{
-       RET_IF(NULL == data);
-
-       struct mds_action_handle *action_data = data;
-
-       free(action_data->id);
-       free(action_data->rule);
-       free(action_data->value);
-       free(action_data);
-}
-
-static GVariant* _mdsc_create_mode_data(modes_mode_h mode)
-{
-       RETV_IF(NULL == mode, NULL);
-
-       GVariantBuilder *action_builder = g_variant_builder_new(G_VARIANT_TYPE(MODES_DBUS_ACTION_LIST_SIG));
-       GList *it = g_list_first(mode->action_list);
-
-       while (NULL != it) {
-               struct mds_action_handle *action_data = (struct mds_action_handle *)it->data;
-               g_variant_builder_add(action_builder, MODES_DBUS_ACTION_SIG, MODES_DBUS_SAFE_STR(action_data->id),
-                       MODES_DBUS_SAFE_STR(action_data->rule), MODES_DBUS_SAFE_STR(action_data->value));
-               it = g_list_next(it);
-       }
-
-       GVariant *action = g_variant_new(MODES_DBUS_ACTION_LIST_SIG, action_builder);
-       GVariant *mode_data = g_variant_new(MODES_DBUS_MODE_SIG, mode->name, mode->type, mode->hidden, action);
-       g_variant_builder_unref(action_builder);
-
-       return mode_data;
-}
-
-API modes_mode_h modes_create_mode(const char *name, modes_type_mode_e type)
-{
-       struct mds_mode_handle *mode;
-
-       RETV_IF(NULL == name, NULL);
-
-       mode = malloc(sizeof(struct mds_mode_handle));
-       RETV_IF(NULL == mode, NULL);
-
-       mode->name = strdup(name);
-       mode->type = type;
-       mode->hidden = false;
-       mode->action_list = NULL;
-
-       return mode;
-}
-
-API int modes_set_hidden(modes_mode_h mode, bool hidden)
-{
-       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
-
-       mode->hidden = hidden;
-
-       return MODES_ERROR_NONE;
-}
-
-API modes_action_h modes_create_action(const char *name, const char *value)
-{
-       struct mds_action_handle *action;
-
-       RETV_IF(NULL == name, NULL);
-       RETV_IF(NULL == value, NULL);
-
-       action = malloc(sizeof(struct mds_action_handle));
-       RETV_IF(NULL == action, NULL);
-
-       action->rule = strdup(name);
-       action->value = strdup(value);
-       action->id = NULL;
-
-       return action;
-}
-
-API int modes_mode_add_action(modes_mode_h mode, modes_action_h action)
-{
-       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == action, MODES_ERROR_INVALID_PARAMETER);
-
-       mode->action_list = g_list_append(mode->action_list, action);
-
-       return MODES_ERROR_NONE;
-}
-
-API int modes_add_mode(modes_h handle, modes_mode_h mode)
-{
-       int ret;
-
-       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
-
-       GVariant *mode_data = _mdsc_create_mode_data(mode);
-       RETV_IF(NULL == mode_data, MODES_ERROR_INVALID_PARAMETER);
-
-       ret = _mdsc_dbus_add_mode_sync(handle->conn, mode_data);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("_mdsc_dbus_add_mode_sync() Fail(%d)", ret);
-               return ret;
-       }
-
-       return MODES_ERROR_NONE;
-}
-
-API int modes_remove_mode(modes_h handle, const char *name)
-{
-       int ret;
-       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == name, MODES_ERROR_INVALID_PARAMETER);
-
-       ret = _mdsc_dbus_remove_mode_sync(handle->conn, name);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("_mdsc_dbus_remove_mode_sync() Fail(%d)", ret);
-               return ret;
-       }
-
-       return MODES_ERROR_NONE;
-}
-
-API void modes_destroy_mode(modes_mode_h mode)
-{
-       RET_IF(NULL == mode);
-
-       free(mode->name);
-
-       g_list_free_full(mode->action_list, _mdsc_free_action);
-
-       free(mode);
-}
-
diff --git a/client/mdsc_noti_mode.c b/client/mdsc_noti_mode.c
deleted file mode 100644 (file)
index 0e36160..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (c) 2019-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 "modes.h"
-
-#include <stdlib.h>
-#include <glib.h>
-#include "mdsc.h"
-#include "common/dbus.h"
-
-struct mds_noti_data {
-       modes_noti_fn cb;
-       void *user_data;
-};
-
-static void _mutex_lock(pthread_mutex_t *mutex)
-{
-       int ret = pthread_mutex_lock(mutex);
-       if (0 != ret)
-               ERR("pthread_mutex_lock() Fail(%d)", errno);
-}
-
-static void _mutex_unlock(pthread_mutex_t *mutex)
-{
-       int ret = pthread_mutex_unlock(mutex);
-       if (0 != ret)
-               ERR("pthread_mutex_unlock() Fail(%d)", errno);
-}
-
-static void _on_changed_mode(mdsDbus *mdsc_dbus, const char *mode, int state, gpointer user_data)
-{
-       int i;
-       GList *it;
-       modes_h handle = user_data;
-
-       RET_IF(NULL == handle);
-
-       _mutex_lock(&handle->noti_mutex);
-       int length = g_list_length(handle->noti_cb_list);
-       struct mds_noti_data cb_list[length];
-
-       for (i = 0, it = handle->noti_cb_list; it != NULL; it = g_list_next(it), i++) {
-               modes_noti_ID data = it->data;
-               if (data) {
-                       cb_list[i].cb = data->cb;
-                       cb_list[i].user_data = data->user_data;
-               }
-       }
-       _mutex_unlock(&handle->noti_mutex);
-
-       length = i;
-       for (i = 0; i < length; i++) {
-               if (cb_list[i].cb)
-                       cb_list[i].cb(mode, state, cb_list[i].user_data);
-       }
-}
-
-API modes_noti_ID modes_subscribe_mode_changes(modes_h handle, modes_noti_fn cb, void *user_data)
-{
-       RETV_IF(NULL == handle, NULL);
-       RETV_IF(NULL == handle->conn, NULL);
-
-       modes_noti_ID data = malloc(sizeof(struct mds_noti_data));
-       if (NULL == data) {
-               ERR("malloc() Fail(%d)", errno);
-               return NULL;
-       }
-
-       data->cb = cb;
-       data->user_data = user_data;
-
-       if (NULL == handle->noti_cb_list)
-               handle->noti_dbus_ID = g_signal_connect(handle->conn,
-                       "changed-mode",
-                       G_CALLBACK(_on_changed_mode),
-                       handle);
-
-       _mutex_lock(&handle->noti_mutex);
-       handle->noti_cb_list = g_list_append(handle->noti_cb_list, data);
-       _mutex_unlock(&handle->noti_mutex);
-
-       return data;
-}
-
-API void modes_unsubscribe_mode_changes(modes_h handle, modes_noti_ID id)
-{
-       RET_IF(NULL == handle);
-       RET_IF(NULL == handle->conn);
-
-       _mutex_lock(&handle->noti_mutex);
-       handle->noti_cb_list = g_list_remove(handle->noti_cb_list, id);
-       free(id);
-       if (NULL == handle->noti_cb_list) {
-               g_signal_handler_disconnect(handle->conn, handle->noti_dbus_ID);
-               handle->noti_dbus_ID = 0;
-       }
-       _mutex_unlock(&handle->noti_mutex);
-}
-
-void mdsc_noti_terminate(modes_h handle)
-{
-       RET_IF(NULL == handle);
-
-       _mutex_lock(&handle->noti_mutex);
-       if (handle->noti_cb_list) {
-               g_list_free_full(handle->noti_cb_list, free);
-               handle->noti_cb_list = NULL;
-               g_signal_handler_disconnect(handle->conn, handle->noti_dbus_ID);
-               handle->noti_dbus_ID = 0;
-       }
-       _mutex_unlock(&handle->noti_mutex);
-}
diff --git a/client/mdsc_noti_mode.h b/client/mdsc_noti_mode.h
deleted file mode 100644 (file)
index 6e53cbf..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (c) 2019-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.
- */
-#pragma once
-
-#include "modes.h"
-
-void mdsc_noti_terminate(modes_h handle);
diff --git a/client/mdsc_subscribe.c b/client/mdsc_subscribe.c
new file mode 100644 (file)
index 0000000..290369f
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2019-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 "modes.h"
+#include "mdsc_subscribe.h"
+
+#include <stdlib.h>
+#include <glib.h>
+#include "mdsc.h"
+#include "common/dbus.h"
+
+struct mds_noti_data {
+       modes_noti_fn cb;
+       void *user_data;
+};
+
+static void _mutex_lock(pthread_mutex_t *mutex)
+{
+       int ret = pthread_mutex_lock(mutex);
+       if (0 != ret)
+               ERR("pthread_mutex_lock() Fail(%d)", errno);
+}
+
+static void _mutex_unlock(pthread_mutex_t *mutex)
+{
+       int ret = pthread_mutex_unlock(mutex);
+       if (0 != ret)
+               ERR("pthread_mutex_unlock() Fail(%d)", errno);
+}
+
+static void _on_changed_mode(mdsDbus *mdsc_dbus, const char *mode, int state, gpointer user_data)
+{
+       int i;
+       GList *it;
+       modes_h handle = user_data;
+
+       RET_IF(NULL == handle);
+
+       _mutex_lock(&handle->noti_mutex);
+       int length = g_list_length(handle->noti_cb_list);
+       struct mds_noti_data cb_list[length];
+
+       for (i = 0, it = handle->noti_cb_list; it != NULL; it = g_list_next(it), i++) {
+               modes_noti_ID data = it->data;
+               if (data) {
+                       cb_list[i].cb = data->cb;
+                       cb_list[i].user_data = data->user_data;
+               }
+       }
+       _mutex_unlock(&handle->noti_mutex);
+
+       length = i;
+       for (i = 0; i < length; i++) {
+               if (cb_list[i].cb)
+                       cb_list[i].cb(mode, state, cb_list[i].user_data);
+       }
+}
+
+API modes_noti_ID modes_subscribe_mode_changes(modes_h handle, modes_noti_fn cb, void *user_data)
+{
+       RETV_IF(NULL == handle, NULL);
+       RETV_IF(NULL == handle->conn, NULL);
+
+       modes_noti_ID data = malloc(sizeof(struct mds_noti_data));
+       if (NULL == data) {
+               ERR("malloc() Fail(%d)", errno);
+               return NULL;
+       }
+
+       data->cb = cb;
+       data->user_data = user_data;
+
+       if (NULL == handle->noti_cb_list)
+               handle->noti_dbus_ID = g_signal_connect(handle->conn,
+                       "changed-mode",
+                       G_CALLBACK(_on_changed_mode),
+                       handle);
+
+       _mutex_lock(&handle->noti_mutex);
+       handle->noti_cb_list = g_list_append(handle->noti_cb_list, data);
+       _mutex_unlock(&handle->noti_mutex);
+
+       return data;
+}
+
+API void modes_unsubscribe_mode_changes(modes_h handle, modes_noti_ID id)
+{
+       RET_IF(NULL == handle);
+       RET_IF(NULL == handle->conn);
+
+       _mutex_lock(&handle->noti_mutex);
+       handle->noti_cb_list = g_list_remove(handle->noti_cb_list, id);
+       free(id);
+       if (NULL == handle->noti_cb_list) {
+               g_signal_handler_disconnect(handle->conn, handle->noti_dbus_ID);
+               handle->noti_dbus_ID = 0;
+       }
+       _mutex_unlock(&handle->noti_mutex);
+}
+
+void mdsc_subscription_disconnect(modes_h handle)
+{
+       RET_IF(NULL == handle);
+
+       _mutex_lock(&handle->noti_mutex);
+       if (handle->noti_cb_list) {
+               g_list_free_full(handle->noti_cb_list, free);
+               handle->noti_cb_list = NULL;
+               g_signal_handler_disconnect(handle->conn, handle->noti_dbus_ID);
+               handle->noti_dbus_ID = 0;
+       }
+       _mutex_unlock(&handle->noti_mutex);
+}
diff --git a/client/mdsc_subscribe.h b/client/mdsc_subscribe.h
new file mode 100644 (file)
index 0000000..ad59720
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2019-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.
+ */
+#pragma once
+
+#include "modes.h"
+
+void mdsc_subscription_disconnect(modes_h handle);
diff --git a/client/mdsc_undo.c b/client/mdsc_undo.c
new file mode 100644 (file)
index 0000000..b5dd774
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2019-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 "modes.h"
+
+#include <glib.h>
+#include "mdsc.h"
+#include "common/dbus.h"
+
+static int _mdsc_dbus_undo_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
+{
+       gboolean ret;
+       GError *error = NULL;
+       int result = MODES_ERROR_NONE;
+
+       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+
+       ret = mds_dbus_call_undo_mode_sync(mdsc_dbus, mode, &result, NULL, &error);
+       if (FALSE == ret) {
+               ERR("mds_dbus_call_undo_mode_sync() Fail(%s)", error ? error->message : "unknown");
+               g_error_free(error);
+               return MODES_ERROR_SYSTEM;
+       }
+
+       return result;
+}
+
+API int modes_undo_mode(modes_h handle, const char *name)
+{
+       int ret;
+
+       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == name, MODES_ERROR_INVALID_PARAMETER);
+
+       ret = _mdsc_dbus_undo_mode_sync(handle->conn, name);
+       if (MODES_ERROR_NONE != ret) {
+               ERR("_mdsc_bus_client_change_mode_sync() Fail(%d)", ret);
+               return ret;
+       }
+
+       return MODES_ERROR_NONE;
+}
diff --git a/client/mdsc_undo_mode.c b/client/mdsc_undo_mode.c
deleted file mode 100644 (file)
index b5dd774..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2019-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 "modes.h"
-
-#include <glib.h>
-#include "mdsc.h"
-#include "common/dbus.h"
-
-static int _mdsc_dbus_undo_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
-{
-       gboolean ret;
-       GError *error = NULL;
-       int result = MODES_ERROR_NONE;
-
-       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
-
-       ret = mds_dbus_call_undo_mode_sync(mdsc_dbus, mode, &result, NULL, &error);
-       if (FALSE == ret) {
-               ERR("mds_dbus_call_undo_mode_sync() Fail(%s)", error ? error->message : "unknown");
-               g_error_free(error);
-               return MODES_ERROR_SYSTEM;
-       }
-
-       return result;
-}
-
-API int modes_undo_mode(modes_h handle, const char *name)
-{
-       int ret;
-
-       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == name, MODES_ERROR_INVALID_PARAMETER);
-
-       ret = _mdsc_dbus_undo_mode_sync(handle->conn, name);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("_mdsc_bus_client_change_mode_sync() Fail(%d)", ret);
-               return ret;
-       }
-
-       return MODES_ERROR_NONE;
-}
index 1e791429050fce4b990201e5f739493b148dd2bd..c46c4f811e0e36af1790c25a2a09f9b530e45bc6 100644 (file)
@@ -115,7 +115,7 @@ install -d -m 755 %{buildroot}%{modes_rw_dir}/undo-info
 install -m 0644 example/mode/*Ex*_mode.xml %{buildroot}%{modes_ro_dir}/mode/
 install -m 0644 example/mode/*Err*_mode.xml %{buildroot}%{modes_test_dir}/
 install -m 0644 example/rule/*Err*_rule.xml %{buildroot}%{modes_test_dir}/
-install -m 0755 unittest/modes-gtest-run.sh %{buildroot}%{modes_test_dir}/
+install -m 0755 tests/modes-gtest-run.sh %{buildroot}%{modes_test_dir}/
 
 %install_service multi-user.target.wants %{name}.path
 
@@ -129,7 +129,7 @@ tar xf %{name}-gcov.tar -C %{buildroot}%{_datadir}/gcov/obj
 xmllint --noout --schema schema/tizen_mode.xsd example/mode/tizen_*_mode.xml
 xmllint --noout --schema schema/tizen_action_rule.xsd plugin/tizen_test_rule.xml
 xmllint --noout --schema schema/tizen_action_rule.xsd example/rule/tizen_*_rule.xml
-bash ./unittest/modes-gtest-run.sh %{buildroot}%{modes_ro_dir} %{buildroot}%{modes_test_dir} Building
+bash ./tests/modes-gtest-run.sh %{buildroot}%{modes_ro_dir} %{buildroot}%{modes_test_dir} Building
 
 %post
 /sbin/ldconfig
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..5151dc0
--- /dev/null
@@ -0,0 +1,174 @@
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
+ADD_DEFINITIONS("-DMDS_TEST")
+
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/common/dbus.c
+    PROPERTIES GENERATED TRUE)
+
+pkg_check_modules(gtest_pkgs REQUIRED dlog glib-2.0 gio-2.0 gio-unix-2.0 libxml-2.0 gmock cynara-client cynara-creds-gdbus cynara-session)
+INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS})
+
+SET(SUPERVISOR_DIR "${CMAKE_SOURCE_DIR}/supervisor/" )
+FILE(GLOB SRC "modes_test_main.cpp")
+#=======================================================================================#
+SET(GTEST_NOTI "modes-gtest-noti")
+SET(GTEST_NOTI_SRCS modes_test_noti.cpp)
+ADD_EXECUTABLE(${GTEST_NOTI} ${SRC} ${GTEST_NOTI_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_NOTI} ${CLIENT} ${gtest_pkgs_LIBRARIES})
+INSTALL(TARGETS ${GTEST_NOTI} DESTINATION ${TEST_INSTALL_DIR})
+#=======================================================================================#
+SET(GTEST_CLIENT "modes-gtest-client")
+SET(GTEST_CLIENT_SRCS modes_test_client.cpp)
+ADD_EXECUTABLE(${GTEST_CLIENT} ${SRC} ${GTEST_CLIENT_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_CLIENT} ${CLIENT} ${gtest_pkgs_LIBRARIES})
+INSTALL(TARGETS ${GTEST_CLIENT} DESTINATION ${TEST_INSTALL_DIR})
+#=======================================================================================#
+SET(GTEST_CLIENT "modes-gtest-async")
+SET(GTEST_CLIENT_SRCS modes_test_async.cpp)
+ADD_EXECUTABLE(${GTEST_CLIENT} ${SRC} ${GTEST_CLIENT_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_CLIENT} ${CLIENT} ${gtest_pkgs_LIBRARIES})
+INSTALL(TARGETS ${GTEST_CLIENT} DESTINATION ${TEST_INSTALL_DIR})
+#=======================================================================================#
+SET(TEST_APPLY_MODE "modes-mode-test")
+SET(TEST_APPLY_MODE_SRC modes_mode_test.c)
+ADD_EXECUTABLE(${TEST_APPLY_MODE} ${TEST_APPLY_MODE_SRC})
+TARGET_LINK_LIBRARIES(${TEST_APPLY_MODE} ${CLIENT})
+INSTALL(TARGETS ${TEST_APPLY_MODE} DESTINATION ${TEST_INSTALL_DIR})
+#=======================================================================================#
+SET(GTEST_MODEMGR "modes-gtest-modemgr")
+FILE(GLOB GTEST_MODEMGR_SRCS
+               ${SUPERVISOR_DIR}/ModesXMLTag.cpp
+               ${SUPERVISOR_DIR}/XMLParser.cpp
+               ${SUPERVISOR_DIR}/XMLGenerator.cpp
+               ${SUPERVISOR_DIR}/ModeManager.cpp
+               ${SUPERVISOR_DIR}/ConflictManager.cpp
+               ${SUPERVISOR_DIR}/ModeCareTaker.cpp
+               ${SUPERVISOR_DIR}/EssentialHandler.cpp
+               ${SUPERVISOR_DIR}/ModeXMLParser.cpp
+               ${SUPERVISOR_DIR}/UndoInfoParser.cpp
+               ${SUPERVISOR_DIR}/Action.cpp
+               ${SUPERVISOR_DIR}/ActionRule.cpp
+               ${SUPERVISOR_DIR}/RuleManager.cpp
+               ${SUPERVISOR_DIR}/PluginMapper.cpp
+               ${SUPERVISOR_DIR}/ClientPrivilege.cpp
+               ${SUPERVISOR_DIR}/Mode.cpp
+               ${SUPERVISOR_DIR}/ModesEx.cpp
+               ${SUPERVISOR_DIR}/ValueChecker.cpp
+               modes_test_modemgr.cpp
+       )
+ADD_EXECUTABLE(${GTEST_MODEMGR} ${SRC} ${GTEST_MODEMGR_SRCS})
+ADD_DEPENDENCIES(${GTEST_MODEMGR} GENERATED_DBUS_CODE)
+TARGET_LINK_LIBRARIES(${GTEST_MODEMGR} ${gtest_pkgs_LIBRARIES} dl)
+INSTALL(TARGETS ${GTEST_MODEMGR} DESTINATION ${TEST_INSTALL_DIR})
+
+#=======================================================================================#
+SET(GTEST_PLUGIN "modes-gtest-plugin")
+FILE(GLOB GTEST_PLUGIN_SRCS
+               ${SUPERVISOR_DIR}/PluginMapper.cpp
+               ${SUPERVISOR_DIR}/ModesEx.cpp
+               modes_test_plugin.cpp
+       )
+ADD_EXECUTABLE(${GTEST_PLUGIN} ${SRC} ${GTEST_PLUGIN_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_PLUGIN} ${gtest_pkgs_LIBRARIES} dl)
+INSTALL(TARGETS ${GTEST_PLUGIN} DESTINATION ${TEST_INSTALL_DIR})
+
+#=======================================================================================#
+SET(GTEST_PARSER "modes-gtest-parser")
+FILE(GLOB GTEST_PARSER_SRCS
+               ${SUPERVISOR_DIR}/XMLParser.cpp
+               ${SUPERVISOR_DIR}/ClientPrivilege.cpp
+               ${SUPERVISOR_DIR}/Action.cpp
+               ${SUPERVISOR_DIR}/ActionRule.cpp
+               ${SUPERVISOR_DIR}/RuleManager.cpp
+               ${SUPERVISOR_DIR}/PluginMapper.cpp
+               ${SUPERVISOR_DIR}/ModeXMLParser.cpp
+               ${SUPERVISOR_DIR}/ModesEx.cpp
+               ${SUPERVISOR_DIR}/Mode.cpp
+               ${SUPERVISOR_DIR}/ModesXMLTag.cpp
+               ${SUPERVISOR_DIR}/ValueChecker.cpp
+               modes_test_parser.cpp
+       )
+ADD_EXECUTABLE(${GTEST_PARSER} ${SRC} ${GTEST_PARSER_SRCS})
+ADD_DEPENDENCIES(${GTEST_PARSER} GENERATED_DBUS_CODE)
+TARGET_LINK_LIBRARIES(${GTEST_PARSER} ${gtest_pkgs_LIBRARIES} dl)
+INSTALL(TARGETS ${GTEST_PARSER} DESTINATION ${TEST_INSTALL_DIR})
+#=======================================================================================#
+SET(GTEST_GENERATOR "modes-gtest-generator")
+FILE(GLOB GTEST_GENERATOR_SRCS
+               ${SUPERVISOR_DIR}/XMLGenerator.cpp
+               ${SUPERVISOR_DIR}/ModesXMLTag.cpp
+               ${SUPERVISOR_DIR}/ModeXMLParser.cpp
+               ${SUPERVISOR_DIR}/XMLParser.cpp
+               ${SUPERVISOR_DIR}/Mode.cpp
+               ${SUPERVISOR_DIR}/Action.cpp
+               ${SUPERVISOR_DIR}/ModesEx.cpp
+               ${SUPERVISOR_DIR}/ClientPrivilege.cpp
+               ${SUPERVISOR_DIR}/RuleManager.cpp
+               ${SUPERVISOR_DIR}/PluginMapper.cpp
+               ${SUPERVISOR_DIR}/ActionRule.cpp
+               ${SUPERVISOR_DIR}/ValueChecker.cpp
+               "modes_test_generator.cpp"
+       )
+ADD_EXECUTABLE(${GTEST_GENERATOR} ${SRC} ${GTEST_GENERATOR_SRCS})
+ADD_DEPENDENCIES(${GTEST_GENERATOR} GENERATED_DBUS_CODE)
+TARGET_LINK_LIBRARIES(${GTEST_GENERATOR} ${gtest_pkgs_LIBRARIES} dl)
+INSTALL(TARGETS ${GTEST_GENERATOR} DESTINATION ${TEST_INSTALL_DIR})
+
+#=======================================================================================#
+SET(GTEST_CONFLICT "modes-gtest-conflict")
+FILE(GLOB GTEST_CONFLICT_SRCS
+               ${SUPERVISOR_DIR}/ConflictManager.cpp
+               ${SUPERVISOR_DIR}/Mode.cpp
+               ${SUPERVISOR_DIR}/ModeCareTaker.cpp
+               ${SUPERVISOR_DIR}/EssentialHandler.cpp
+               ${SUPERVISOR_DIR}/ModeManager.cpp
+               ${SUPERVISOR_DIR}/UndoInfoParser.cpp
+               ${SUPERVISOR_DIR}/XMLGenerator.cpp
+               ${SUPERVISOR_DIR}/Action.cpp
+               ${SUPERVISOR_DIR}/ModeXMLParser.cpp
+               ${SUPERVISOR_DIR}/XMLParser.cpp
+               ${SUPERVISOR_DIR}/ModesEx.cpp
+               ${SUPERVISOR_DIR}/ClientPrivilege.cpp
+               ${SUPERVISOR_DIR}/ModesXMLTag.cpp
+               ${SUPERVISOR_DIR}/RuleManager.cpp
+               ${SUPERVISOR_DIR}/PluginMapper.cpp
+               ${SUPERVISOR_DIR}/ActionRule.cpp
+               ${SUPERVISOR_DIR}/ValueChecker.cpp
+               modes_test_conflict.cpp
+       )
+ADD_EXECUTABLE(${GTEST_CONFLICT} ${SRC} ${GTEST_CONFLICT_SRCS})
+ADD_DEPENDENCIES(${GTEST_CONFLICT} GENERATED_DBUS_CODE)
+TARGET_LINK_LIBRARIES(${GTEST_CONFLICT} ${gtest_pkgs_LIBRARIES} dl)
+INSTALL(TARGETS ${GTEST_CONFLICT} DESTINATION ${TEST_INSTALL_DIR})
+#=======================================================================================#
+SET(GTEST_RULEMGR "modes-gtest-rulemgr")
+FILE(GLOB GTEST_RULE_SRCS
+               ${SUPERVISOR_DIR}/RuleManager.cpp
+               ${SUPERVISOR_DIR}/PluginMapper.cpp
+               ${SUPERVISOR_DIR}/XMLParser.cpp
+               ${SUPERVISOR_DIR}/ActionRule.cpp
+               ${SUPERVISOR_DIR}/ModesEx.cpp
+               ${SUPERVISOR_DIR}/Mode.cpp
+               ${SUPERVISOR_DIR}/ClientPrivilege.cpp
+               ${SUPERVISOR_DIR}/Action.cpp
+               ${SUPERVISOR_DIR}/ValueChecker.cpp
+               modes_test_rulemgr.cpp
+       )
+ADD_EXECUTABLE(${GTEST_RULEMGR} ${SRC} ${GTEST_RULE_SRCS})
+ADD_DEPENDENCIES(${GTEST_RULEMGR} GENERATED_DBUS_CODE)
+TARGET_LINK_LIBRARIES(${GTEST_RULEMGR} ${gtest_pkgs_LIBRARIES} dl)
+INSTALL(TARGETS ${GTEST_RULEMGR} DESTINATION ${TEST_INSTALL_DIR})
+#=======================================================================================#
+SET(GTEST_POLICY "modes-gtest-policy")
+FILE(GLOB GTEST_POLICY_SRCS
+               ${SUPERVISOR_DIR}/ModesEx.cpp
+               ${SUPERVISOR_DIR}/Action.cpp
+               ${SUPERVISOR_DIR}/ValueChecker.cpp
+               ${CMAKE_SOURCE_DIR}/plugin/*.cpp
+               modes_test_policy.cpp
+       )
+ADD_EXECUTABLE(${GTEST_POLICY} ${SRC} ${GTEST_POLICY_SRCS})
+ADD_DEPENDENCIES(${GTEST_POLICY} GENERATED_DBUS_CODE)
+TARGET_LINK_LIBRARIES(${GTEST_POLICY} ${gtest_pkgs_LIBRARIES})
+INSTALL(TARGETS ${GTEST_POLICY} DESTINATION ${TEST_INSTALL_DIR})
diff --git a/tests/modes-gtest-run.sh b/tests/modes-gtest-run.sh
new file mode 100644 (file)
index 0000000..540d09a
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/bash
+
+# fails when set -e is in force
+set -e
+
+if [ $# -lt 2 ]
+then
+       echo "Usage) $0 DATA_DIR WORKING_DIR [Building]"
+       exit 1
+fi
+
+IsBUILDING="no"
+if [ $# -gt 2 ]
+then
+       IsBUILDING=$3
+fi
+
+DATA_DIR=$1
+WORKING_DIR=$2
+#CUR_DIR=$PWD
+
+pushd $WORKING_DIR
+
+cp $DATA_DIR/mode/*_mode.xml ./
+cp $DATA_DIR/rule/*_rule.xml ./
+mkdir -p ./extra
+sed s/ex1/ex3/g ./tizen_normalEx1_mode.xml > ./extra/tizen_normalEx3_mode.xml
+sed s/ex1/ex4/g ./tizen_normalEx1_mode.xml > ./extra/tizen_normalEx4_mode.xml
+cp $DATA_DIR/schema/*.xsd ./
+
+if [ "$IsBUILDING" == "no" ]
+then # on Target
+       ./modes-gtest-client
+       ./modes-gtest-noti
+       ./modes-gtest-async
+fi
+
+./modes-gtest-rulemgr
+./modes-gtest-modemgr
+./modes-gtest-parser
+./modes-gtest-generator
+./modes-gtest-conflict
+./modes-gtest-plugin
+./modes-gtest-policy
+
+rm -rf *.xsd extra
+
+popd
diff --git a/tests/modes_mode_test.c b/tests/modes_mode_test.c
new file mode 100644 (file)
index 0000000..2593111
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2019-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 <glib.h>
+#include <modes.h>
+
+#ifndef MDS_STDOUT
+#define MDS_STDOUT
+#endif
+#include "common/log.h"
+
+static GMainLoop *_modes_loop;
+static modes_h _handle;
+
+#define PERR(fmt, arg...) printf("\033[31m %d:" fmt "\n \033[0m", __LINE__, ##arg)
+
+static gboolean apply_idler(gpointer data)
+{
+       int ret = modes_apply_mode(_handle, data);
+       if (MODES_ERROR_NONE != ret)
+               PERR("modes_apply_mode() Fail(%d)", ret);
+
+       g_main_loop_quit(_modes_loop);
+       return G_SOURCE_REMOVE;
+}
+
+static gboolean can_apply_idler(gpointer data)
+{
+       int ret = modes_can_apply(_handle, data);
+       if (MODES_ERROR_NONE != ret)
+               PERR("modes_can_apply() Fail(%d)", ret);
+
+       g_main_loop_quit(_modes_loop);
+       return G_SOURCE_REMOVE;
+}
+
+static gboolean undo_idler(gpointer data)
+{
+       int ret = modes_undo_mode(_handle, data);
+       if (MODES_ERROR_NONE != ret)
+               PERR("modes_undo_mode() Fail(%d)", ret);
+
+       g_main_loop_quit(_modes_loop);
+       return G_SOURCE_REMOVE;
+}
+
+static void print_usage(const char *exec_name)
+{
+       printf("Usage)\n");
+       printf("\t%s can_apply ModeName\n", exec_name);
+       printf("\t%s apply ModeName\n", exec_name);
+       printf("\t%s undo ModeName\n", exec_name);
+}
+
+int main(int argc, char **argv)
+{
+       if (3 != argc) {
+               print_usage(argv[0]);
+               return -1;
+       }
+       _handle = modes_connect();
+       _modes_loop = g_main_loop_new(NULL, FALSE);
+       if (0 == strcasecmp(argv[1], "apply")) {
+               g_idle_add(apply_idler, argv[2]);
+       } else if (0 == strcasecmp(argv[1], "can_apply")) {
+               g_idle_add(can_apply_idler, argv[2]);
+       } else if (0 == strcasecmp(argv[1], "undo")) {
+               g_idle_add(undo_idler, argv[2]);
+       } else {
+               PERR("Invalid option(%s)", argv[1]);
+               print_usage(argv[0]);
+       }
+
+       g_main_loop_run(_modes_loop);
+       g_main_loop_unref(_modes_loop);
+
+       modes_disconnect(_handle);
+       _handle = NULL;
+       return 0;
+}
diff --git a/tests/modes_test_async.cpp b/tests/modes_test_async.cpp
new file mode 100644 (file)
index 0000000..7a591b5
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2019-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 <glib.h>
+#include <gtest/gtest.h>
+#include <modes.h>
+
+class AsyncTest : public ::testing::Test {
+protected:
+       void SetUp() override
+       {
+               loop = g_main_loop_new(NULL, FALSE);
+               handle = modes_connect();
+       }
+
+       void TearDown() override
+       {
+               g_main_loop_unref(loop);
+               loop = NULL;
+               modes_disconnect(handle);
+               handle = NULL;
+       }
+
+       static gboolean ModeIdler(gpointer data)
+       {
+               int ret;
+               ret = modes_apply_mode(handle, (char*)data);
+               EXPECT_EQ(MODES_ERROR_NONE, ret);
+               sleep(1);
+               ret = modes_undo_mode(handle, (char*)data);
+               EXPECT_EQ(MODES_ERROR_NONE, ret);
+
+               g_main_loop_quit(loop);
+               return G_SOURCE_REMOVE;
+       }
+
+       static gboolean failIdler(gpointer data)
+       {
+               int ret;
+               ret = modes_apply_mode(handle, (char*)data);
+               EXPECT_EQ(MODES_ERROR_SYSTEM, ret);
+               sleep(1);
+               ret = modes_undo_mode(handle, (char*)data);
+               EXPECT_EQ(MODES_ERROR_NO_DATA, ret);
+
+               g_main_loop_quit(loop);
+               return G_SOURCE_REMOVE;
+       }
+       static modes_h handle;
+       static GMainLoop *loop;
+};
+
+modes_h AsyncTest::handle = NULL;
+GMainLoop *AsyncTest::loop = NULL;
+
+TEST_F(AsyncTest, normalAsync)
+{
+       const char *modeName = "asyncEx1";
+       modes_undo_mode(handle, modeName);
+       g_idle_add(ModeIdler, (gpointer)modeName);
+       g_main_loop_run(loop);
+}
+
+TEST_F(AsyncTest, oneshotAsync)
+{
+       const char *modeName = "asyncEx2";
+       int ret = modes_apply_mode(handle, modeName);
+       EXPECT_EQ(MODES_ERROR_NONE, ret);
+}
+
+TEST_F(AsyncTest, normalAsyncFail)
+{
+       const char *modeName = "asyncFail1";
+       modes_undo_mode(handle, modeName);
+       g_idle_add(failIdler, (gpointer)modeName);
+       g_main_loop_run(loop);
+}
+
+TEST_F(AsyncTest, oneshotAsyncFail)
+{
+       const char *modeName = "asyncFail2";
+       g_idle_add(failIdler, (gpointer)modeName);
+       g_main_loop_run(loop);
+}
diff --git a/tests/modes_test_client.cpp b/tests/modes_test_client.cpp
new file mode 100644 (file)
index 0000000..23acfa4
--- /dev/null
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2019-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 <iostream>
+#include <glib.h>
+#include <gtest/gtest.h>
+#include <modes.h>
+#include "common/definitions.h"
+
+class ClientTest : public ::testing::Test {
+protected:
+       void SetUp() override
+       {
+               handle = modes_connect();
+               loop = g_main_loop_new(NULL, FALSE);
+       }
+
+       void TearDown() override
+       {
+               g_main_loop_unref(loop);
+               loop = NULL;
+               modes_disconnect(handle);
+               handle = NULL;
+       }
+
+       static gboolean applyModeIdler(gpointer data)
+       {
+               result = modes_apply_mode(handle, (char*)data);
+
+               g_main_loop_quit(loop);
+               return G_SOURCE_REMOVE;
+       }
+
+       static gboolean undoModeIdler(gpointer data)
+       {
+               result = modes_apply_mode(handle, (char*)data);
+               EXPECT_EQ(MODES_ERROR_NONE, result);
+               sleep(1);
+               result = modes_undo_mode(handle, (char*)data);
+
+               g_main_loop_quit(loop);
+               return G_SOURCE_REMOVE;
+       }
+
+       static void addModeTest(gpointer data)
+       {
+               modes_mode_h created_mode = modes_create_mode((char*)data, MODES_TYPE_MODE_NORMAL);
+               modes_action_h action_handle[2];
+               action_handle[0] = modes_create_action("test.printBool", "on");
+               action_handle[1] = modes_create_action("test.printBool", "off");
+
+               for (int i = 0; i < 2; i++) {
+                       result = modes_mode_add_action(created_mode, action_handle[i]);
+                       EXPECT_EQ(MODES_ERROR_NONE, result);
+               }
+
+               result = modes_set_hidden(created_mode, true);
+               EXPECT_EQ(MODES_ERROR_NONE, result);
+
+               result = modes_add_mode(handle, created_mode);
+               modes_destroy_mode(created_mode);
+               EXPECT_EQ(MODES_ERROR_NONE, result);
+
+               result = modes_apply_mode(handle, (char*)data);
+               EXPECT_EQ(MODES_ERROR_NONE, result);
+       }
+
+       static gboolean addModeIdler(gpointer data)
+       {
+               addModeTest(data);
+               modes_undo_mode(handle, (char*)data);
+               modes_remove_mode(handle, (char*)data);
+               g_main_loop_quit(loop);
+
+               return G_SOURCE_REMOVE;
+       }
+
+       static gboolean removeModeIdler(gpointer data)
+       {
+               addModeTest(data);
+
+               result = modes_remove_mode(handle, (char*)data);
+               EXPECT_EQ(MODES_ERROR_CONFLICT, result);
+
+               modes_undo_mode(handle, (char*)data);
+               result = modes_remove_mode(handle, (char*)data);
+               EXPECT_EQ(MODES_ERROR_NONE, result);
+
+               g_main_loop_quit(loop);
+               return G_SOURCE_REMOVE;
+       }
+
+       static modes_h handle;
+       static int result;
+       static GMainLoop *loop;
+};
+
+modes_h ClientTest::handle = NULL;
+int ClientTest::result = 0;
+GMainLoop *ClientTest::loop = NULL;
+
+TEST_F(ClientTest, applyModeP)
+{
+       modes_undo_mode(handle, "ex1");
+       g_idle_add(applyModeIdler, (gpointer)"ex1");
+       g_main_loop_run(loop);
+       EXPECT_EQ(MODES_ERROR_NONE, result);
+}
+
+TEST_F(ClientTest, applyModeN)
+{
+       g_idle_add(applyModeIdler, (gpointer)"non_ex2");
+       g_main_loop_run(loop);
+       EXPECT_EQ(MODES_ERROR_NO_DATA, result);
+}
+
+TEST_F(ClientTest, canApplyModeP)
+{
+       modes_undo_mode(handle, "ex1");
+       int ret = modes_can_apply(handle, "ex1");
+       EXPECT_EQ(MODES_ERROR_NONE, ret);
+}
+
+TEST_F(ClientTest, canApplyModeN)
+{
+       int ret = modes_can_apply(handle, "ex4");
+       EXPECT_EQ(MODES_ERROR_NO_DATA, ret);
+}
+
+TEST_F(ClientTest, addMode)
+{
+       g_idle_add(addModeIdler, (gpointer)"created");
+       g_main_loop_run(loop);
+       EXPECT_EQ(MODES_ERROR_NONE, result);
+}
+
+TEST_F(ClientTest, removeMode)
+{
+       g_idle_add(removeModeIdler, (gpointer)"deltest");
+       g_main_loop_run(loop);
+       EXPECT_EQ(MODES_ERROR_NONE, result);
+
+       int ret = modes_remove_mode(handle, "deltestN");
+       EXPECT_EQ(MODES_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(ClientTest, undoModeEx1)
+{
+       modes_undo_mode(handle, "ex1");
+       g_idle_add(undoModeIdler, (gpointer)"ex1");
+       g_main_loop_run(loop);
+       EXPECT_EQ(MODES_ERROR_NONE, result);
+}
+
+TEST_F(ClientTest, undoModeEx2)
+{
+       modes_undo_mode(handle, "ex2");
+       g_idle_add(undoModeIdler, (gpointer)"ex2");
+       g_main_loop_run(loop);
+       EXPECT_EQ(MODES_ERROR_NONE, result);
+}
+
+TEST_F(ClientTest, getModes)
+{
+       const char* const typeList[2] = {
+               "MODES_TYPE_MODE_NORMAL",
+               "MODES_TYPE_MODE_ONESHOT"
+       };
+
+       GList *list, *cur;
+       int ret = modes_get_modes(handle, &list);
+       EXPECT_EQ(MODES_ERROR_NONE, ret);
+
+       for (cur = g_list_first(list); cur; cur = g_list_next(cur)) {
+               EXPECT_NE(nullptr, cur->data);
+
+               const char *name = modes_get_mode_name((mode_list_data_h)cur->data);
+               EXPECT_NE(nullptr, name);
+
+               int type = modes_get_mode_type((mode_list_data_h)cur->data);
+               EXPECT_NE(MODES_ERROR_INVALID_PARAMETER, type);
+
+               int state = modes_get_mode_state((mode_list_data_h)cur->data);
+               EXPECT_NE(MODES_ERROR_INVALID_PARAMETER, state);
+
+               std::cout << name << " " << typeList[type] << "(" << type << ") :state(" << state << ")" << std::endl;
+       }
+       modes_free_modes(list);
+}
diff --git a/tests/modes_test_conflict.cpp b/tests/modes_test_conflict.cpp
new file mode 100644 (file)
index 0000000..29cb270
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2019-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 <gtest/gtest.h>
+#include "common/definitions.h"
+#include "supervisor/ModeXMLParser.h"
+#include "supervisor/ModeCareTaker.h"
+
+MODES_NAMESPACE_USE;
+
+MODES_NAMESPACE_BEGIN
+class ConflictTest : public ::testing::Test {
+public:
+       ConflictTest();
+protected:
+       void SetUp() override
+       {
+               ModeXMLParser modeparser("tizen_conflictErrBase_mode.xml", ruleMgr);
+               careTaker.pushMode(modeparser.getMode());
+       }
+
+       void TearDown() override
+       {
+               Mode mode;
+               careTaker.popMode("conflict1", mode);
+       }
+
+       bool checkConflictAction(const Mode &mode)
+       {
+               return careTaker.checkConflictAction(mode);
+       }
+
+       RuleManager ruleMgr;
+       ModeCareTaker careTaker;
+};
+MODES_NAMESPACE_END
+
+
+ConflictTest::ConflictTest()
+       : ruleMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR), careTaker(".")
+{
+       ruleMgr.start();
+}
+
+
+TEST_F(ConflictTest, isSavedMode)
+{
+       ModeXMLParser modeparser("tizen_conflictErrBase_mode.xml", ruleMgr);
+       Mode mode = modeparser.getMode();
+       EXPECT_TRUE(careTaker.isSavedMode(mode.getName()));
+}
+
+TEST_F(ConflictTest, checkConflictAction)
+{
+       ModeXMLParser modeparser("tizen_conflictErr_mode.xml", ruleMgr);
+
+       Mode mode = modeparser.getMode();
+       EXPECT_TRUE(checkConflictAction(mode));
+}
+
+TEST_F(ConflictTest, isConflict)
+{
+       ModeXMLParser modeparser("tizen_conflictErr_mode.xml", ruleMgr);
+       EXPECT_TRUE(careTaker.isConflict(modeparser.getMode()));
+}
diff --git a/tests/modes_test_generator.cpp b/tests/modes_test_generator.cpp
new file mode 100644 (file)
index 0000000..99cf52e
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2019-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 <memory.h>
+#include <iostream>
+#include <gtest/gtest.h>
+#include "supervisor/Mode.h"
+#include "supervisor/ModesEx.h"
+#include "supervisor/RuleManager.h"
+#include "supervisor/XMLGenerator.h"
+#include "supervisor/ModeXMLParser.h"
+
+using namespace std;
+MODES_NAMESPACE_USE;
+
+MODES_NAMESPACE_BEGIN
+class GeneratorTest {
+public:
+       GeneratorTest();
+       RuleManager ruleMgr;
+};
+MODES_NAMESPACE_END
+
+GeneratorTest::GeneratorTest()
+       : ruleMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR)
+{
+       ruleMgr.start();
+}
+
+TEST(XMLGenerator, makeModeXML)
+{
+       GeneratorTest broker;
+
+       ModeXMLParser modeParser("tizen_normalEx1_mode.xml", broker.ruleMgr);
+       Mode mode = modeParser.getMode();
+
+       try {
+               XMLGenerator xmlGenerator;
+               xmlGenerator.makeModeXML("tizen_generatedEx1_mode.xml", mode);
+       } catch (ModesEx &e) {
+               ERR("XMLGenerator(tizen_generatedEx1_mode.xml) Fail(%s)", e.what());
+               FAIL();
+       }
+
+       ModeXMLParser genModeParser("tizen_generatedEx1_mode.xml", broker.ruleMgr);
+       Mode genMode = genModeParser.getMode();
+
+       EXPECT_EQ("ex1", genMode.getName());
+       std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
+       EXPECT_FALSE(actionList.empty());
+
+       for (std::list<std::shared_ptr<Action>>::iterator it = actionList.begin(); it != actionList.end(); ++it) {
+               cout << "* Action : " << (*it)->getRuleName() << endl;
+               cout << "\t\t- Restrict : " << (*it)->getRestrict() << endl;
+               cout << "\t\t- Content : " << (*it)->getStringOfValue() << endl;
+       }
+}
+
+TEST(XMLGenerator, exFileName)
+{
+       GeneratorTest broker;
+
+       ModeXMLParser modeParser("tizen_normalEx1_mode.xml", broker.ruleMgr);
+       Mode mode = modeParser.getMode();
+
+       EXPECT_THROW({
+               XMLGenerator xmlGenerator;
+               xmlGenerator.makeModeXML("", mode);
+       }, ModesEx);
+}
diff --git a/tests/modes_test_main.cpp b/tests/modes_test_main.cpp
new file mode 100644 (file)
index 0000000..e7484bd
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2019-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 <gtest/gtest.h>
+
+int main(int argc, char **argv) {
+       testing::InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
+}
diff --git a/tests/modes_test_modemgr.cpp b/tests/modes_test_modemgr.cpp
new file mode 100644 (file)
index 0000000..f7aaa2e
--- /dev/null
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2019-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 <iostream>
+#include <exception>
+#include <gtest/gtest.h>
+#include "supervisor/ModeManager.h"
+
+using namespace std;
+MODES_NAMESPACE_USE;
+
+MODES_NAMESPACE_BEGIN
+class ModeManagerTest {
+public:
+       ModeManagerTest();
+       RuleManager rMgr;
+       ModeManager mdMgr;
+
+       set<string> getDirectories();
+       bool emptyModeMap();
+       void printModeMap();
+};
+MODES_NAMESPACE_END
+
+ModeManagerTest::ModeManagerTest()
+       : rMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR),
+       mdMgr(set<string>(), "./" MODES_MODE_DEFAULT_XSD_FILE, rMgr)
+{
+       rMgr.start();
+       mdMgr.modeDirList.insert(".");
+       mdMgr.init();
+}
+
+set<string>  ModeManagerTest::getDirectories()
+{
+       return mdMgr.modeDirList;
+}
+
+bool ModeManagerTest::emptyModeMap()
+{
+       return mdMgr.modeMap.empty();
+}
+
+void ModeManagerTest::printModeMap()
+{
+       static const char* const mode_type[3] = {
+               "MODE_NORMAL",
+               "MODE_ONESHOT",
+               "MODE_EXCLUSIVE" };
+
+       if (!mdMgr.modeMap.empty()) {
+               cout << "| "; cout.width(15); cout << "Mode Name" << " | " << "ModeXML file Path" << "| type      | hidden" << endl;
+
+               for (auto it = mdMgr.modeMap.begin(); it != mdMgr.modeMap.end(); it++) {
+                       cout << "| ";  cout.width(15); cout << it->first.c_str() << " | " << std::get<0>(it->second).c_str() << " | ";
+                       cout << mode_type[std::get<1>(it->second)];
+                       if (std::get<2>(it->second))
+                               cout << "hidden";
+                       else
+                               cout << "Not hidden";
+                       cout << endl;
+               }
+       }
+}
+
+TEST(ModeManager, setOptions)
+{
+       ModeManagerTest mdMgrTest;
+
+       EXPECT_FALSE(mdMgrTest.emptyModeMap()) << "Mode Map is empty!" << endl;
+
+       mdMgrTest.printModeMap();
+}
+
+TEST(ModeManager, addModeDirectory)
+{
+       ModeManagerTest mdMgrTest;
+
+       string dir_extra = "./extra";
+       try {
+               mdMgrTest.mdMgr.addModeDirectory(dir_extra);
+       }
+       catch (exception &e) {
+               ADD_FAILURE() << "Fail to append : " << e.what() << endl;
+               return;
+       }
+
+       EXPECT_FALSE(mdMgrTest.emptyModeMap()) << "Mode Map is empty!" << endl;
+
+       mdMgrTest.printModeMap();
+}
+
+TEST(ModeManager, addModeDirectory_withwrongdir)
+{
+       ModeManagerTest mdMgrTest;
+
+       string dir_wrong = "./dir_wrong";
+       try {
+               mdMgrTest.mdMgr.addModeDirectory(dir_wrong);
+       }
+       catch (exception &e) {
+               cout << "Fail to append : " << e.what() << endl;
+               return;
+       }
+
+       ADD_FAILURE() << "addModeDirectory() did not detect a wrong directory!" << endl;
+}
+
+TEST(ModeManager, addModeDirectory_withappendeddir)
+{
+       ModeManagerTest mdMgrTest;
+
+       string dir_extra = "./extra";
+       try {
+               mdMgrTest.mdMgr.addModeDirectory(dir_extra);
+       }
+       catch (exception &e) {
+               cout << "Fail to append : " << e.what() << endl;
+               ADD_FAILURE();
+               return;
+       }
+       EXPECT_FALSE(mdMgrTest.emptyModeMap()) << "Mode Map is empty!" << endl;
+       mdMgrTest.printModeMap();
+
+       string dir_appended = dir_extra;
+       try {
+               mdMgrTest.mdMgr.addModeDirectory(dir_appended);
+       }
+       catch (exception &e) {
+               cout << "Fail to append : " << e.what() << endl;
+               return;
+       }
+
+       ADD_FAILURE() << "addModeDirectory() did not detect a directory that is already attached!" << endl;
+}
diff --git a/tests/modes_test_noti.cpp b/tests/modes_test_noti.cpp
new file mode 100644 (file)
index 0000000..9145c84
--- /dev/null
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 2019-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 <glib.h>
+#include <gtest/gtest.h>
+#include <modes.h>
+
+class ClientNotiTest : public ::testing::Test {
+protected:
+       void SetUp() override
+       {
+               handle = modes_connect();
+               loop = g_main_loop_new(NULL, FALSE);
+       }
+
+       void TearDown() override
+       {
+               g_main_loop_unref(loop);
+               loop = NULL;
+               modes_disconnect(handle);
+               handle = NULL;
+       }
+
+       static gboolean undoTimeout(gpointer data)
+       {
+               expectedState = 0;
+               int ret = modes_undo_mode(handle, (const char*)data);
+               EXPECT_EQ(MODES_ERROR_NONE, ret);
+
+               return G_SOURCE_REMOVE;
+       }
+
+       static int notiFunc(const char *modeName, int state, void *user_data)
+       {
+               char *requestMode = (char*)user_data;
+
+               std::cout << "notiFunc Changed Mode : " << modeName << std::endl;
+               EXPECT_EQ(requestMode, std::string(modeName));
+               std::cout << "state : " << state << std::endl;
+               EXPECT_EQ(expectedState, state);
+
+               if (0 == expectedState)
+                       g_main_loop_quit(loop);
+               return MODES_ERROR_NONE;
+       }
+
+       static int changeFn(const char *modeName, int state, void *user_data)
+       {
+               char *requestMode = (char*)user_data;
+
+               std::cout << "changeFn Changed Mode : " << modeName << std::endl;
+               EXPECT_EQ(requestMode, std::string(modeName));
+               std::cout << "state : " << state << std::endl;
+
+               if (0 == state)
+                       g_main_loop_quit(loop);
+
+               return MODES_ERROR_NONE;
+       }
+
+       static int notiMultiFunc1(const char *modeName, int state, void *user_data)
+       {
+               std::cout << "notiMultiFunc1 Changed Mode : " << modeName << std::endl;
+               std::cout << "state : " << state << std::endl;
+
+               calledbit1 |= 0x1 << state;
+
+               return MODES_ERROR_NONE;
+       }
+
+       static int notiMultiFunc2(const char *modeName, int state, void *user_data)
+       {
+               std::cout << "notiMultiFunc2 Changed Mode : " << modeName << std::endl;
+               std::cout << "state : " << state << std::endl;
+
+               calledbit2 |= 0x1 << state;
+
+               return MODES_ERROR_NONE;
+       }
+
+       static int notiMultiFunc3(const char *modeName, int state, void *user_data)
+       {
+               std::cout << "notiMultiFunc3 Changed Mode : " << modeName << std::endl;
+               std::cout << "state : " << state << std::endl;
+
+               EXPECT_TRUE(NULL == user_data || notiTestMode == user_data);
+
+               if (NULL == user_data)
+                       calledbit3 |= 0x1 << state;
+               if (notiTestMode == user_data)
+                       calledbit4 |= 0x1 << state;
+
+               if (0x3 == calledbit3 && 0x3 == calledbit4)
+                       g_main_loop_quit(loop);
+
+               return MODES_ERROR_NONE;
+       }
+
+
+       static modes_h handle;
+       static int expectedState;
+       static GMainLoop *loop;
+       static unsigned char calledbit1;
+       static unsigned char calledbit2;
+       static unsigned char calledbit3;
+       static unsigned char calledbit4;
+       static const char *notiTestMode;
+};
+
+modes_h ClientNotiTest::handle = NULL;
+int ClientNotiTest::expectedState = 1;
+unsigned char ClientNotiTest::calledbit1 = 0;
+unsigned char ClientNotiTest::calledbit2 = 0;
+unsigned char ClientNotiTest::calledbit3 = 0;
+unsigned char ClientNotiTest::calledbit4 = 0;
+GMainLoop *ClientNotiTest::loop = NULL;
+const char *ClientNotiTest::notiTestMode = "ex2";
+
+TEST_F(ClientNotiTest, subscribeCB)
+{
+       const char *testMode = "ex2";
+       modes_noti_ID id = modes_subscribe_mode_changes(handle, notiFunc, (void*)testMode);
+       EXPECT_NE(nullptr , id);
+
+       ClientNotiTest::expectedState = 1;
+       int ret = modes_apply_mode(handle, testMode);
+       EXPECT_EQ(MODES_ERROR_NONE, ret);
+
+       g_timeout_add_seconds(1, undoTimeout, (void*)testMode);
+
+       g_main_loop_run(loop);
+
+       modes_unsubscribe_mode_changes(handle, id);
+}
+TEST_F(ClientNotiTest, subscribeMultiCb)
+{
+       calledbit1 = 0;
+       calledbit2 = 0;
+       calledbit3 = 0;
+
+       modes_noti_ID id1 = modes_subscribe_mode_changes(handle, notiMultiFunc1, NULL);
+       EXPECT_NE(nullptr, id1);
+
+       modes_noti_ID id2 = modes_subscribe_mode_changes(handle, notiMultiFunc2, NULL);
+       EXPECT_NE(nullptr, id2);
+
+       modes_noti_ID id3 = modes_subscribe_mode_changes(handle, notiMultiFunc3, (void*)notiTestMode);
+       EXPECT_NE(nullptr, id3);
+
+       modes_noti_ID id4 = modes_subscribe_mode_changes(handle, notiMultiFunc3, NULL);
+       EXPECT_NE(nullptr, id4);
+
+       int ret = modes_apply_mode(handle, notiTestMode);
+       EXPECT_EQ(MODES_ERROR_NONE, ret);
+
+       g_timeout_add_seconds(1, undoTimeout, (void*)notiTestMode);
+       g_main_loop_run(loop);
+
+       modes_unsubscribe_mode_changes(handle, id1);
+       modes_unsubscribe_mode_changes(handle, id2);
+       modes_unsubscribe_mode_changes(handle, id3);
+       modes_unsubscribe_mode_changes(handle, id4);
+
+       EXPECT_EQ(calledbit1, 1 << 0 | 1 << 1);
+       EXPECT_EQ(calledbit2, 1 << 0 | 1 << 1);
+       EXPECT_EQ(calledbit3, 1 << 0 | 1 << 1);
+       EXPECT_EQ(calledbit4, 1 << 0 | 1 << 1);
+}
+
+TEST_F(ClientNotiTest, essentialAction)
+{
+       const char *testMode = "essential_ex";
+       modes_noti_ID id = modes_subscribe_mode_changes(handle, changeFn, (void*)testMode);
+       EXPECT_NE(nullptr, id);
+
+       int ret = modes_apply_mode(handle, testMode);
+       EXPECT_EQ(MODES_ERROR_NONE, ret);
+
+       g_main_loop_run(loop);
+
+       modes_unsubscribe_mode_changes(handle, id);
+}
diff --git a/tests/modes_test_parser.cpp b/tests/modes_test_parser.cpp
new file mode 100644 (file)
index 0000000..8a5d110
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2019-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 <iostream>
+#include <memory>
+#include <gtest/gtest.h>
+#include "supervisor/Mode.h"
+#include "supervisor/ModesEx.h"
+#include "supervisor/RuleManager.h"
+#include "supervisor/ModeXMLParser.h"
+
+using namespace std;
+MODES_NAMESPACE_USE;
+
+MODES_NAMESPACE_BEGIN
+class ParserTest : public ::testing::Test {
+public:
+       ParserTest();
+
+       void parserTest(const string &fileName);
+       list<shared_ptr<Action>> getActionList(Mode& m);
+
+protected:
+       void SetUp() override
+       {
+       }
+
+       void TearDown() override
+       {
+       }
+
+       RuleManager ruleMgr;
+};
+MODES_NAMESPACE_END
+
+ParserTest::ParserTest()
+       : ruleMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR)
+{
+       ruleMgr.start();
+}
+
+list<shared_ptr<Action>> ParserTest::getActionList(Mode& m)
+{
+       return m.actionList;
+}
+
+TEST_F(ParserTest, modeGetName)
+{
+       ModeXMLParser modeparser("tizen_normalEx2_mode.xml", ruleMgr);
+       Mode mode = modeparser.getMode();
+       EXPECT_EQ("ex2", mode.getName());
+}
+
+TEST_F(ParserTest, isHiddenTrue)
+{
+       ModeXMLParser modeparser("tizen_normalEx2_mode.xml", ruleMgr);
+       Mode mode = modeparser.getMode();
+       EXPECT_EQ(true, mode.isHidden());
+}
+
+TEST_F(ParserTest, isHiddenFalse)
+{
+       ModeXMLParser modeparser("tizen_normalEx1_mode.xml", ruleMgr);
+       Mode mode = modeparser.getMode();
+       EXPECT_EQ(false, mode.isHidden());
+}
+
+TEST_F(ParserTest, getModeType)
+{
+       ModeXMLParser modeparser("tizen_normalEx1_mode.xml", ruleMgr);
+       Mode mode = modeparser.getMode();
+       EXPECT_EQ(Mode::MODE_NORMAL, mode.getModeType());
+}
+
+TEST_F(ParserTest, printAction)
+{
+       ModeXMLParser modeparser("tizen_normalEx1_mode.xml", ruleMgr);
+       Mode mode = modeparser.getMode();
+
+       list<std::shared_ptr<Action>> actionList = getActionList(mode);
+       EXPECT_FALSE(actionList.empty());
+
+       for (list<std::shared_ptr<Action>>::iterator it = actionList.begin(); it != actionList.end(); ++it) {
+               cout << "* Action : " << (*it)->getRuleName() << endl;
+               cout << "\t\t- Restrict : " << (*it)->getRestrict() << endl;
+               //cout << "\t\t- Content : " << (*it)->getValue() << endl;
+       }
+}
+
+TEST_F(ParserTest, invalidActionValue)
+{
+       ModeXMLParser modeparser1("tizen_invalidValErr1_mode.xml", ruleMgr);
+       EXPECT_THROW(modeparser1.getMode(), ModesEx);
+
+       ModeXMLParser modeparser2("tizen_invalidValErr2_mode.xml", ruleMgr);
+       EXPECT_THROW(modeparser2.getMode(), ModesEx);
+}
+
+TEST_F(ParserTest, validateAsyncStopOnErr)
+{
+       ModeXMLParser modeparser("tizen_asyncValidErr_mode.xml", ruleMgr);
+
+       EXPECT_THROW(modeparser.getMode(), ModesEx);
+}
+
+TEST_F(ParserTest, printError)
+{
+       EXPECT_NO_THROW(
+               std::cout << "MODES_ERROR_NONE " << MODES_ERROR_NONE << std::endl;
+       std::cout << "MODES_ERROR_ALREADY " << MODES_ERROR_ALREADY << std::endl;
+       std::cout << "MODES_ERROR_NO_DATA " << MODES_ERROR_NO_DATA << std::endl;
+       std::cout << "MODES_ERROR_TIMEOUT " << MODES_ERROR_TIMEOUT << std::endl;
+       std::cout << "MODES_ERROR_IO_ERROR " << MODES_ERROR_IO_ERROR << std::endl;
+       std::cout << "MODES_ERROR_NOT_SUPPORTED " << MODES_ERROR_NOT_SUPPORTED << std::endl;
+       std::cout << "MODES_ERROR_OUT_OF_MEMORY " << MODES_ERROR_OUT_OF_MEMORY << std::endl;
+       std::cout << "MODES_ERROR_PERMISSION_DENIED " << MODES_ERROR_PERMISSION_DENIED << std::endl;
+       std::cout << "MODES_ERROR_INVALID_PARAMETER " << MODES_ERROR_INVALID_PARAMETER << std::endl;
+       std::cout << "MODES_ERROR_SYSTEM " << MODES_ERROR_SYSTEM << std::endl;
+       std::cout << "MODES_ERROR_CONFLICT " << MODES_ERROR_CONFLICT << std::endl;
+       );
+}
diff --git a/tests/modes_test_plugin.cpp b/tests/modes_test_plugin.cpp
new file mode 100644 (file)
index 0000000..fe146b7
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2019-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 <iostream>
+#include <gtest/gtest.h>
+#include "supervisor/PluginMapper.h"
+#include "supervisor/ModesEx.h"
+
+using namespace std;
+
+MODES_NAMESPACE_BEGIN
+class TestPluginBroker {
+public:
+       TestPluginBroker();
+
+       bool emptyPluginMap();
+       string getpluginDir();
+
+       PluginMapper piMapper;
+};
+MODES_NAMESPACE_END
+
+MODES_NAMESPACE_USE;
+
+TestPluginBroker::TestPluginBroker()
+       : piMapper("../../.." MODES_PLUGIN_DEFAULT_DIR)
+{
+}
+
+bool TestPluginBroker::emptyPluginMap()
+{
+       return piMapper.pluginMap.empty();
+}
+
+string TestPluginBroker::getpluginDir()
+{
+       return piMapper.pluginDir;
+}
+
+TEST(PluginMapper, readLibraryList)
+{
+       TestPluginBroker broker;
+
+       EXPECT_NO_THROW(broker.piMapper.loadPlugins());
+       EXPECT_FALSE(broker.emptyPluginMap());
+
+       list<string> pluginList = broker.piMapper.getPluginList();
+       if (pluginList.empty()) {
+               FAIL() << "getPluginList() Fail:This should never be reached";
+       } else {
+               for (auto it = pluginList.begin(); it != pluginList.end(); ++it)
+                       printf("plugin library : %s\n", it->c_str());
+       }
+}
+
+TEST(PluginMapper, unloadClassMap)
+{
+       TestPluginBroker broker;
+
+       int ret = broker.piMapper.unloadPlugins();
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+       EXPECT_TRUE(broker.emptyPluginMap());
+}
+
+TEST(PluginMapper, getPluginTest)
+{
+       int ret;
+       TestPluginBroker broker;
+
+       EXPECT_NO_THROW(broker.piMapper.loadPlugins());
+       EXPECT_FALSE(broker.emptyPluginMap());
+
+       Plugin *plugin = broker.piMapper.getPlugin("test");
+       ASSERT_TRUE(plugin);
+
+       PluginAction *piAction = plugin->newAction("printInt");
+       ret = piAction->set(0);
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+
+       ret = piAction->set(false);
+       EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
+       plugin->deleteAction(piAction);
+
+       piAction = plugin->newAction("printFloat");
+       ret = piAction->set(1.234);
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+       plugin->deleteAction(piAction);
+
+       piAction = plugin->newAction("printBool");
+       ret = piAction->set(false);
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+
+       ret = piAction->set(3);
+       EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
+       plugin->deleteAction(piAction);
+
+       piAction = plugin->newAction("printString");
+       ret = piAction->set(string("String value"));
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+       plugin->deleteAction(piAction);
+
+       piAction = plugin->newAction("alwaySameValue");
+       bool same = piAction->IsCurrentValue(string("String value"));
+       EXPECT_EQ(same, true);
+       ret = piAction->set(string("String value"));
+       EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
+       plugin->deleteAction(piAction);
+
+       ret = broker.piMapper.unloadPlugins();
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+       EXPECT_TRUE(broker.emptyPluginMap());
+}
diff --git a/tests/modes_test_policy.cpp b/tests/modes_test_policy.cpp
new file mode 100644 (file)
index 0000000..fa6c190
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2019-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 <functional>
+#include <gtest/gtest.h>
+#include "Plugin.h"
+#include "supervisor/ModesEx.h"
+#include "supervisor/TAction.h"
+
+using namespace std;
+MODES_NAMESPACE_USE;
+
+extern "C" Plugin* objectCreate(void);
+extern "C" void objectDelete(Plugin *plugin);
+
+MODES_NAMESPACE_BEGIN
+class PolicyTest : public ::testing::Test {
+protected:
+       void SetUp() override
+       {
+               plugin = objectCreate();
+       }
+
+       void TearDown() override
+       {
+               objectDelete(plugin);
+       }
+
+       bool isSubscribed(Action *action)
+       {
+               return !(action->isIgnored());
+       }
+
+       Plugin *plugin;
+};
+MODES_NAMESPACE_END
+
+TEST_F(PolicyTest, OnlyOneSubscribe)
+{
+       int ret;
+       string ruleName = "test.printInt";
+
+       int pos = ruleName.find_first_of(".");
+       std::string actionKey = ruleName.substr(pos + 1);
+       std::shared_ptr<PluginAction> piAction1(plugin->newAction(actionKey),
+               std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
+
+       Action *action1 = nullptr;
+       ASSERT_NO_THROW(action1 = new TAction<int>(ruleName, piAction1));
+
+       ret = action1->setValue("4");
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+       ret = action1->apply();
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+       EXPECT_EQ(isSubscribed(action1), true);
+
+       std::shared_ptr<PluginAction> piAction2(plugin->newAction(actionKey),
+               std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
+       Action *action2 = nullptr;
+       ASSERT_NO_THROW(action2 = new TAction<int>(ruleName, piAction2));
+
+       ret = action2->setValue("2");
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+       ret = action2->apply();
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+       EXPECT_EQ(isSubscribed(action2), true);
+       EXPECT_EQ(isSubscribed(action1), false);
+}
+
+TEST_F(PolicyTest, ignoreSameValue)
+{
+       int ret;
+       string ruleName = "test.printInt";
+
+       int pos = ruleName.find_first_of(".");
+       std::string actionKey = ruleName.substr(pos + 1);
+       std::shared_ptr<PluginAction> piAction1(plugin->newAction(actionKey),
+               std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
+
+       Action *action1 = nullptr;
+       ASSERT_NO_THROW(action1 = new TAction<int>(ruleName, piAction1));
+
+       ret = action1->setValue("4");
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+       ret = action1->apply();
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+       EXPECT_EQ(isSubscribed(action1), true);
+
+       std::shared_ptr<PluginAction> piAction2(plugin->newAction(actionKey),
+               std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
+       Action *action2 = nullptr;
+       ASSERT_NO_THROW(action2 = new TAction<int>(ruleName, piAction2));
+
+       ret = action2->setValue("4");
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+       ret = action2->apply();
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+       EXPECT_EQ(isSubscribed(action2), false);
+       EXPECT_EQ(isSubscribed(action1), true);
+}
+
+TEST_F(PolicyTest, oneShotNoSubscribe)
+{
+       int ret;
+       string ruleName = "test.printInt";
+
+       int pos = ruleName.find_first_of(".");
+       std::string actionKey = ruleName.substr(pos + 1);
+       std::shared_ptr<PluginAction> piAction1(plugin->newAction(actionKey),
+               std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
+
+       Action *action1 = nullptr;
+       ASSERT_NO_THROW(action1 = new TAction<int>(ruleName, piAction1));
+
+       ret = action1->setValue("4");
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+       ret = action1->applyOneShot();
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+       EXPECT_EQ(isSubscribed(action1), false);
+}
diff --git a/tests/modes_test_rulemgr.cpp b/tests/modes_test_rulemgr.cpp
new file mode 100644 (file)
index 0000000..dff8805
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2019-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 <gtest/gtest.h>
+#include "supervisor/ModesEx.h"
+#include "supervisor/RuleManager.h"
+
+using namespace std;
+
+MODES_NAMESPACE_BEGIN
+class RuleManagerTest {
+public:
+       RuleManagerTest();
+
+       RuleManager rMgr;
+       void parseActionRule(const string &xmlFile)
+       {
+               rMgr.parseActionRule(xmlFile);
+       }
+       bool emptyRuleMap()
+       {
+               return rMgr.ruleMap.empty();
+       }
+};
+MODES_NAMESPACE_END
+
+MODES_NAMESPACE_USE;
+
+RuleManagerTest::RuleManagerTest()
+       : rMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR)
+{
+       rMgr.piMapper.loadPlugins();
+}
+
+TEST(RuleManagerTest, makeRuleMapP)
+{
+       RuleManagerTest testBroker;
+       EXPECT_NO_THROW(testBroker.rMgr.start());
+}
+
+TEST(RuleManagerTest, parseActionRuleP)
+{
+       RuleManagerTest testBroker;
+       EXPECT_NO_THROW(testBroker.parseActionRule("./tizen_test_rule.xml"));
+}
+
+TEST(RuleManagerTest, DuplicatedRule)
+{
+       RuleManagerTest testBroker;
+       EXPECT_THROW(testBroker.parseActionRule("./tizen_uniqueRuleErr_rule.xml"), ModesEx);
+}
+
+TEST(RuleManagerTest, InvalidValue)
+{
+       RuleManagerTest testBroker;
+       EXPECT_THROW(testBroker.parseActionRule("./tizen_uniqueRuleErr_rule.xml"), ModesEx);
+}
+
+// If there are any errors in a file, the file will be ignored.
+TEST(RuleManagerTest, CheckAtomicity)
+{
+       RuleManagerTest testBroker;
+       EXPECT_THROW(testBroker.parseActionRule("./tizen_aliasValueErr.xml"), ModesEx);
+       EXPECT_TRUE(testBroker.emptyRuleMap());
+}
+
+TEST(RuleManagerTest, UnknownPlugin1)
+{
+       RuleManagerTest testBroker;
+       EXPECT_THROW(testBroker.parseActionRule("./tizen_pluginErr1_rule.xml"), ModesEx);
+}
+
+TEST(RuleManagerTest, UnknownPlugin2)
+{
+       RuleManagerTest testBroker;
+       EXPECT_THROW(testBroker.parseActionRule("./tizen_pluginErr2_rule.xml"), ModesEx);
+}
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
deleted file mode 100644 (file)
index 5151dc0..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
-ADD_DEFINITIONS("-DMDS_TEST")
-
-SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/common/dbus.c
-    PROPERTIES GENERATED TRUE)
-
-pkg_check_modules(gtest_pkgs REQUIRED dlog glib-2.0 gio-2.0 gio-unix-2.0 libxml-2.0 gmock cynara-client cynara-creds-gdbus cynara-session)
-INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS})
-LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS})
-
-SET(SUPERVISOR_DIR "${CMAKE_SOURCE_DIR}/supervisor/" )
-FILE(GLOB SRC "modes_test_main.cpp")
-#=======================================================================================#
-SET(GTEST_NOTI "modes-gtest-noti")
-SET(GTEST_NOTI_SRCS modes_test_noti.cpp)
-ADD_EXECUTABLE(${GTEST_NOTI} ${SRC} ${GTEST_NOTI_SRCS})
-TARGET_LINK_LIBRARIES(${GTEST_NOTI} ${CLIENT} ${gtest_pkgs_LIBRARIES})
-INSTALL(TARGETS ${GTEST_NOTI} DESTINATION ${TEST_INSTALL_DIR})
-#=======================================================================================#
-SET(GTEST_CLIENT "modes-gtest-client")
-SET(GTEST_CLIENT_SRCS modes_test_client.cpp)
-ADD_EXECUTABLE(${GTEST_CLIENT} ${SRC} ${GTEST_CLIENT_SRCS})
-TARGET_LINK_LIBRARIES(${GTEST_CLIENT} ${CLIENT} ${gtest_pkgs_LIBRARIES})
-INSTALL(TARGETS ${GTEST_CLIENT} DESTINATION ${TEST_INSTALL_DIR})
-#=======================================================================================#
-SET(GTEST_CLIENT "modes-gtest-async")
-SET(GTEST_CLIENT_SRCS modes_test_async.cpp)
-ADD_EXECUTABLE(${GTEST_CLIENT} ${SRC} ${GTEST_CLIENT_SRCS})
-TARGET_LINK_LIBRARIES(${GTEST_CLIENT} ${CLIENT} ${gtest_pkgs_LIBRARIES})
-INSTALL(TARGETS ${GTEST_CLIENT} DESTINATION ${TEST_INSTALL_DIR})
-#=======================================================================================#
-SET(TEST_APPLY_MODE "modes-mode-test")
-SET(TEST_APPLY_MODE_SRC modes_mode_test.c)
-ADD_EXECUTABLE(${TEST_APPLY_MODE} ${TEST_APPLY_MODE_SRC})
-TARGET_LINK_LIBRARIES(${TEST_APPLY_MODE} ${CLIENT})
-INSTALL(TARGETS ${TEST_APPLY_MODE} DESTINATION ${TEST_INSTALL_DIR})
-#=======================================================================================#
-SET(GTEST_MODEMGR "modes-gtest-modemgr")
-FILE(GLOB GTEST_MODEMGR_SRCS
-               ${SUPERVISOR_DIR}/ModesXMLTag.cpp
-               ${SUPERVISOR_DIR}/XMLParser.cpp
-               ${SUPERVISOR_DIR}/XMLGenerator.cpp
-               ${SUPERVISOR_DIR}/ModeManager.cpp
-               ${SUPERVISOR_DIR}/ConflictManager.cpp
-               ${SUPERVISOR_DIR}/ModeCareTaker.cpp
-               ${SUPERVISOR_DIR}/EssentialHandler.cpp
-               ${SUPERVISOR_DIR}/ModeXMLParser.cpp
-               ${SUPERVISOR_DIR}/UndoInfoParser.cpp
-               ${SUPERVISOR_DIR}/Action.cpp
-               ${SUPERVISOR_DIR}/ActionRule.cpp
-               ${SUPERVISOR_DIR}/RuleManager.cpp
-               ${SUPERVISOR_DIR}/PluginMapper.cpp
-               ${SUPERVISOR_DIR}/ClientPrivilege.cpp
-               ${SUPERVISOR_DIR}/Mode.cpp
-               ${SUPERVISOR_DIR}/ModesEx.cpp
-               ${SUPERVISOR_DIR}/ValueChecker.cpp
-               modes_test_modemgr.cpp
-       )
-ADD_EXECUTABLE(${GTEST_MODEMGR} ${SRC} ${GTEST_MODEMGR_SRCS})
-ADD_DEPENDENCIES(${GTEST_MODEMGR} GENERATED_DBUS_CODE)
-TARGET_LINK_LIBRARIES(${GTEST_MODEMGR} ${gtest_pkgs_LIBRARIES} dl)
-INSTALL(TARGETS ${GTEST_MODEMGR} DESTINATION ${TEST_INSTALL_DIR})
-
-#=======================================================================================#
-SET(GTEST_PLUGIN "modes-gtest-plugin")
-FILE(GLOB GTEST_PLUGIN_SRCS
-               ${SUPERVISOR_DIR}/PluginMapper.cpp
-               ${SUPERVISOR_DIR}/ModesEx.cpp
-               modes_test_plugin.cpp
-       )
-ADD_EXECUTABLE(${GTEST_PLUGIN} ${SRC} ${GTEST_PLUGIN_SRCS})
-TARGET_LINK_LIBRARIES(${GTEST_PLUGIN} ${gtest_pkgs_LIBRARIES} dl)
-INSTALL(TARGETS ${GTEST_PLUGIN} DESTINATION ${TEST_INSTALL_DIR})
-
-#=======================================================================================#
-SET(GTEST_PARSER "modes-gtest-parser")
-FILE(GLOB GTEST_PARSER_SRCS
-               ${SUPERVISOR_DIR}/XMLParser.cpp
-               ${SUPERVISOR_DIR}/ClientPrivilege.cpp
-               ${SUPERVISOR_DIR}/Action.cpp
-               ${SUPERVISOR_DIR}/ActionRule.cpp
-               ${SUPERVISOR_DIR}/RuleManager.cpp
-               ${SUPERVISOR_DIR}/PluginMapper.cpp
-               ${SUPERVISOR_DIR}/ModeXMLParser.cpp
-               ${SUPERVISOR_DIR}/ModesEx.cpp
-               ${SUPERVISOR_DIR}/Mode.cpp
-               ${SUPERVISOR_DIR}/ModesXMLTag.cpp
-               ${SUPERVISOR_DIR}/ValueChecker.cpp
-               modes_test_parser.cpp
-       )
-ADD_EXECUTABLE(${GTEST_PARSER} ${SRC} ${GTEST_PARSER_SRCS})
-ADD_DEPENDENCIES(${GTEST_PARSER} GENERATED_DBUS_CODE)
-TARGET_LINK_LIBRARIES(${GTEST_PARSER} ${gtest_pkgs_LIBRARIES} dl)
-INSTALL(TARGETS ${GTEST_PARSER} DESTINATION ${TEST_INSTALL_DIR})
-#=======================================================================================#
-SET(GTEST_GENERATOR "modes-gtest-generator")
-FILE(GLOB GTEST_GENERATOR_SRCS
-               ${SUPERVISOR_DIR}/XMLGenerator.cpp
-               ${SUPERVISOR_DIR}/ModesXMLTag.cpp
-               ${SUPERVISOR_DIR}/ModeXMLParser.cpp
-               ${SUPERVISOR_DIR}/XMLParser.cpp
-               ${SUPERVISOR_DIR}/Mode.cpp
-               ${SUPERVISOR_DIR}/Action.cpp
-               ${SUPERVISOR_DIR}/ModesEx.cpp
-               ${SUPERVISOR_DIR}/ClientPrivilege.cpp
-               ${SUPERVISOR_DIR}/RuleManager.cpp
-               ${SUPERVISOR_DIR}/PluginMapper.cpp
-               ${SUPERVISOR_DIR}/ActionRule.cpp
-               ${SUPERVISOR_DIR}/ValueChecker.cpp
-               "modes_test_generator.cpp"
-       )
-ADD_EXECUTABLE(${GTEST_GENERATOR} ${SRC} ${GTEST_GENERATOR_SRCS})
-ADD_DEPENDENCIES(${GTEST_GENERATOR} GENERATED_DBUS_CODE)
-TARGET_LINK_LIBRARIES(${GTEST_GENERATOR} ${gtest_pkgs_LIBRARIES} dl)
-INSTALL(TARGETS ${GTEST_GENERATOR} DESTINATION ${TEST_INSTALL_DIR})
-
-#=======================================================================================#
-SET(GTEST_CONFLICT "modes-gtest-conflict")
-FILE(GLOB GTEST_CONFLICT_SRCS
-               ${SUPERVISOR_DIR}/ConflictManager.cpp
-               ${SUPERVISOR_DIR}/Mode.cpp
-               ${SUPERVISOR_DIR}/ModeCareTaker.cpp
-               ${SUPERVISOR_DIR}/EssentialHandler.cpp
-               ${SUPERVISOR_DIR}/ModeManager.cpp
-               ${SUPERVISOR_DIR}/UndoInfoParser.cpp
-               ${SUPERVISOR_DIR}/XMLGenerator.cpp
-               ${SUPERVISOR_DIR}/Action.cpp
-               ${SUPERVISOR_DIR}/ModeXMLParser.cpp
-               ${SUPERVISOR_DIR}/XMLParser.cpp
-               ${SUPERVISOR_DIR}/ModesEx.cpp
-               ${SUPERVISOR_DIR}/ClientPrivilege.cpp
-               ${SUPERVISOR_DIR}/ModesXMLTag.cpp
-               ${SUPERVISOR_DIR}/RuleManager.cpp
-               ${SUPERVISOR_DIR}/PluginMapper.cpp
-               ${SUPERVISOR_DIR}/ActionRule.cpp
-               ${SUPERVISOR_DIR}/ValueChecker.cpp
-               modes_test_conflict.cpp
-       )
-ADD_EXECUTABLE(${GTEST_CONFLICT} ${SRC} ${GTEST_CONFLICT_SRCS})
-ADD_DEPENDENCIES(${GTEST_CONFLICT} GENERATED_DBUS_CODE)
-TARGET_LINK_LIBRARIES(${GTEST_CONFLICT} ${gtest_pkgs_LIBRARIES} dl)
-INSTALL(TARGETS ${GTEST_CONFLICT} DESTINATION ${TEST_INSTALL_DIR})
-#=======================================================================================#
-SET(GTEST_RULEMGR "modes-gtest-rulemgr")
-FILE(GLOB GTEST_RULE_SRCS
-               ${SUPERVISOR_DIR}/RuleManager.cpp
-               ${SUPERVISOR_DIR}/PluginMapper.cpp
-               ${SUPERVISOR_DIR}/XMLParser.cpp
-               ${SUPERVISOR_DIR}/ActionRule.cpp
-               ${SUPERVISOR_DIR}/ModesEx.cpp
-               ${SUPERVISOR_DIR}/Mode.cpp
-               ${SUPERVISOR_DIR}/ClientPrivilege.cpp
-               ${SUPERVISOR_DIR}/Action.cpp
-               ${SUPERVISOR_DIR}/ValueChecker.cpp
-               modes_test_rulemgr.cpp
-       )
-ADD_EXECUTABLE(${GTEST_RULEMGR} ${SRC} ${GTEST_RULE_SRCS})
-ADD_DEPENDENCIES(${GTEST_RULEMGR} GENERATED_DBUS_CODE)
-TARGET_LINK_LIBRARIES(${GTEST_RULEMGR} ${gtest_pkgs_LIBRARIES} dl)
-INSTALL(TARGETS ${GTEST_RULEMGR} DESTINATION ${TEST_INSTALL_DIR})
-#=======================================================================================#
-SET(GTEST_POLICY "modes-gtest-policy")
-FILE(GLOB GTEST_POLICY_SRCS
-               ${SUPERVISOR_DIR}/ModesEx.cpp
-               ${SUPERVISOR_DIR}/Action.cpp
-               ${SUPERVISOR_DIR}/ValueChecker.cpp
-               ${CMAKE_SOURCE_DIR}/plugin/*.cpp
-               modes_test_policy.cpp
-       )
-ADD_EXECUTABLE(${GTEST_POLICY} ${SRC} ${GTEST_POLICY_SRCS})
-ADD_DEPENDENCIES(${GTEST_POLICY} GENERATED_DBUS_CODE)
-TARGET_LINK_LIBRARIES(${GTEST_POLICY} ${gtest_pkgs_LIBRARIES})
-INSTALL(TARGETS ${GTEST_POLICY} DESTINATION ${TEST_INSTALL_DIR})
diff --git a/unittest/modes-gtest-run.sh b/unittest/modes-gtest-run.sh
deleted file mode 100755 (executable)
index 540d09a..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/bash
-
-# fails when set -e is in force
-set -e
-
-if [ $# -lt 2 ]
-then
-       echo "Usage) $0 DATA_DIR WORKING_DIR [Building]"
-       exit 1
-fi
-
-IsBUILDING="no"
-if [ $# -gt 2 ]
-then
-       IsBUILDING=$3
-fi
-
-DATA_DIR=$1
-WORKING_DIR=$2
-#CUR_DIR=$PWD
-
-pushd $WORKING_DIR
-
-cp $DATA_DIR/mode/*_mode.xml ./
-cp $DATA_DIR/rule/*_rule.xml ./
-mkdir -p ./extra
-sed s/ex1/ex3/g ./tizen_normalEx1_mode.xml > ./extra/tizen_normalEx3_mode.xml
-sed s/ex1/ex4/g ./tizen_normalEx1_mode.xml > ./extra/tizen_normalEx4_mode.xml
-cp $DATA_DIR/schema/*.xsd ./
-
-if [ "$IsBUILDING" == "no" ]
-then # on Target
-       ./modes-gtest-client
-       ./modes-gtest-noti
-       ./modes-gtest-async
-fi
-
-./modes-gtest-rulemgr
-./modes-gtest-modemgr
-./modes-gtest-parser
-./modes-gtest-generator
-./modes-gtest-conflict
-./modes-gtest-plugin
-./modes-gtest-policy
-
-rm -rf *.xsd extra
-
-popd
diff --git a/unittest/modes_mode_test.c b/unittest/modes_mode_test.c
deleted file mode 100644 (file)
index 2593111..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2019-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 <glib.h>
-#include <modes.h>
-
-#ifndef MDS_STDOUT
-#define MDS_STDOUT
-#endif
-#include "common/log.h"
-
-static GMainLoop *_modes_loop;
-static modes_h _handle;
-
-#define PERR(fmt, arg...) printf("\033[31m %d:" fmt "\n \033[0m", __LINE__, ##arg)
-
-static gboolean apply_idler(gpointer data)
-{
-       int ret = modes_apply_mode(_handle, data);
-       if (MODES_ERROR_NONE != ret)
-               PERR("modes_apply_mode() Fail(%d)", ret);
-
-       g_main_loop_quit(_modes_loop);
-       return G_SOURCE_REMOVE;
-}
-
-static gboolean can_apply_idler(gpointer data)
-{
-       int ret = modes_can_apply(_handle, data);
-       if (MODES_ERROR_NONE != ret)
-               PERR("modes_can_apply() Fail(%d)", ret);
-
-       g_main_loop_quit(_modes_loop);
-       return G_SOURCE_REMOVE;
-}
-
-static gboolean undo_idler(gpointer data)
-{
-       int ret = modes_undo_mode(_handle, data);
-       if (MODES_ERROR_NONE != ret)
-               PERR("modes_undo_mode() Fail(%d)", ret);
-
-       g_main_loop_quit(_modes_loop);
-       return G_SOURCE_REMOVE;
-}
-
-static void print_usage(const char *exec_name)
-{
-       printf("Usage)\n");
-       printf("\t%s can_apply ModeName\n", exec_name);
-       printf("\t%s apply ModeName\n", exec_name);
-       printf("\t%s undo ModeName\n", exec_name);
-}
-
-int main(int argc, char **argv)
-{
-       if (3 != argc) {
-               print_usage(argv[0]);
-               return -1;
-       }
-       _handle = modes_connect();
-       _modes_loop = g_main_loop_new(NULL, FALSE);
-       if (0 == strcasecmp(argv[1], "apply")) {
-               g_idle_add(apply_idler, argv[2]);
-       } else if (0 == strcasecmp(argv[1], "can_apply")) {
-               g_idle_add(can_apply_idler, argv[2]);
-       } else if (0 == strcasecmp(argv[1], "undo")) {
-               g_idle_add(undo_idler, argv[2]);
-       } else {
-               PERR("Invalid option(%s)", argv[1]);
-               print_usage(argv[0]);
-       }
-
-       g_main_loop_run(_modes_loop);
-       g_main_loop_unref(_modes_loop);
-
-       modes_disconnect(_handle);
-       _handle = NULL;
-       return 0;
-}
diff --git a/unittest/modes_test_async.cpp b/unittest/modes_test_async.cpp
deleted file mode 100644 (file)
index 7a591b5..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (c) 2019-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 <glib.h>
-#include <gtest/gtest.h>
-#include <modes.h>
-
-class AsyncTest : public ::testing::Test {
-protected:
-       void SetUp() override
-       {
-               loop = g_main_loop_new(NULL, FALSE);
-               handle = modes_connect();
-       }
-
-       void TearDown() override
-       {
-               g_main_loop_unref(loop);
-               loop = NULL;
-               modes_disconnect(handle);
-               handle = NULL;
-       }
-
-       static gboolean ModeIdler(gpointer data)
-       {
-               int ret;
-               ret = modes_apply_mode(handle, (char*)data);
-               EXPECT_EQ(MODES_ERROR_NONE, ret);
-               sleep(1);
-               ret = modes_undo_mode(handle, (char*)data);
-               EXPECT_EQ(MODES_ERROR_NONE, ret);
-
-               g_main_loop_quit(loop);
-               return G_SOURCE_REMOVE;
-       }
-
-       static gboolean failIdler(gpointer data)
-       {
-               int ret;
-               ret = modes_apply_mode(handle, (char*)data);
-               EXPECT_EQ(MODES_ERROR_SYSTEM, ret);
-               sleep(1);
-               ret = modes_undo_mode(handle, (char*)data);
-               EXPECT_EQ(MODES_ERROR_NO_DATA, ret);
-
-               g_main_loop_quit(loop);
-               return G_SOURCE_REMOVE;
-       }
-       static modes_h handle;
-       static GMainLoop *loop;
-};
-
-modes_h AsyncTest::handle = NULL;
-GMainLoop *AsyncTest::loop = NULL;
-
-TEST_F(AsyncTest, normalAsync)
-{
-       const char *modeName = "asyncEx1";
-       modes_undo_mode(handle, modeName);
-       g_idle_add(ModeIdler, (gpointer)modeName);
-       g_main_loop_run(loop);
-}
-
-TEST_F(AsyncTest, oneshotAsync)
-{
-       const char *modeName = "asyncEx2";
-       int ret = modes_apply_mode(handle, modeName);
-       EXPECT_EQ(MODES_ERROR_NONE, ret);
-}
-
-TEST_F(AsyncTest, normalAsyncFail)
-{
-       const char *modeName = "asyncFail1";
-       modes_undo_mode(handle, modeName);
-       g_idle_add(failIdler, (gpointer)modeName);
-       g_main_loop_run(loop);
-}
-
-TEST_F(AsyncTest, oneshotAsyncFail)
-{
-       const char *modeName = "asyncFail2";
-       g_idle_add(failIdler, (gpointer)modeName);
-       g_main_loop_run(loop);
-}
diff --git a/unittest/modes_test_client.cpp b/unittest/modes_test_client.cpp
deleted file mode 100644 (file)
index 23acfa4..0000000
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Copyright (c) 2019-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 <iostream>
-#include <glib.h>
-#include <gtest/gtest.h>
-#include <modes.h>
-#include "common/definitions.h"
-
-class ClientTest : public ::testing::Test {
-protected:
-       void SetUp() override
-       {
-               handle = modes_connect();
-               loop = g_main_loop_new(NULL, FALSE);
-       }
-
-       void TearDown() override
-       {
-               g_main_loop_unref(loop);
-               loop = NULL;
-               modes_disconnect(handle);
-               handle = NULL;
-       }
-
-       static gboolean applyModeIdler(gpointer data)
-       {
-               result = modes_apply_mode(handle, (char*)data);
-
-               g_main_loop_quit(loop);
-               return G_SOURCE_REMOVE;
-       }
-
-       static gboolean undoModeIdler(gpointer data)
-       {
-               result = modes_apply_mode(handle, (char*)data);
-               EXPECT_EQ(MODES_ERROR_NONE, result);
-               sleep(1);
-               result = modes_undo_mode(handle, (char*)data);
-
-               g_main_loop_quit(loop);
-               return G_SOURCE_REMOVE;
-       }
-
-       static void addModeTest(gpointer data)
-       {
-               modes_mode_h created_mode = modes_create_mode((char*)data, MODES_TYPE_MODE_NORMAL);
-               modes_action_h action_handle[2];
-               action_handle[0] = modes_create_action("test.printBool", "on");
-               action_handle[1] = modes_create_action("test.printBool", "off");
-
-               for (int i = 0; i < 2; i++) {
-                       result = modes_mode_add_action(created_mode, action_handle[i]);
-                       EXPECT_EQ(MODES_ERROR_NONE, result);
-               }
-
-               result = modes_set_hidden(created_mode, true);
-               EXPECT_EQ(MODES_ERROR_NONE, result);
-
-               result = modes_add_mode(handle, created_mode);
-               modes_destroy_mode(created_mode);
-               EXPECT_EQ(MODES_ERROR_NONE, result);
-
-               result = modes_apply_mode(handle, (char*)data);
-               EXPECT_EQ(MODES_ERROR_NONE, result);
-       }
-
-       static gboolean addModeIdler(gpointer data)
-       {
-               addModeTest(data);
-               modes_undo_mode(handle, (char*)data);
-               modes_remove_mode(handle, (char*)data);
-               g_main_loop_quit(loop);
-
-               return G_SOURCE_REMOVE;
-       }
-
-       static gboolean removeModeIdler(gpointer data)
-       {
-               addModeTest(data);
-
-               result = modes_remove_mode(handle, (char*)data);
-               EXPECT_EQ(MODES_ERROR_CONFLICT, result);
-
-               modes_undo_mode(handle, (char*)data);
-               result = modes_remove_mode(handle, (char*)data);
-               EXPECT_EQ(MODES_ERROR_NONE, result);
-
-               g_main_loop_quit(loop);
-               return G_SOURCE_REMOVE;
-       }
-
-       static modes_h handle;
-       static int result;
-       static GMainLoop *loop;
-};
-
-modes_h ClientTest::handle = NULL;
-int ClientTest::result = 0;
-GMainLoop *ClientTest::loop = NULL;
-
-TEST_F(ClientTest, applyModeP)
-{
-       modes_undo_mode(handle, "ex1");
-       g_idle_add(applyModeIdler, (gpointer)"ex1");
-       g_main_loop_run(loop);
-       EXPECT_EQ(MODES_ERROR_NONE, result);
-}
-
-TEST_F(ClientTest, applyModeN)
-{
-       g_idle_add(applyModeIdler, (gpointer)"non_ex2");
-       g_main_loop_run(loop);
-       EXPECT_EQ(MODES_ERROR_NO_DATA, result);
-}
-
-TEST_F(ClientTest, canApplyModeP)
-{
-       modes_undo_mode(handle, "ex1");
-       int ret = modes_can_apply(handle, "ex1");
-       EXPECT_EQ(MODES_ERROR_NONE, ret);
-}
-
-TEST_F(ClientTest, canApplyModeN)
-{
-       int ret = modes_can_apply(handle, "ex4");
-       EXPECT_EQ(MODES_ERROR_NO_DATA, ret);
-}
-
-TEST_F(ClientTest, addMode)
-{
-       g_idle_add(addModeIdler, (gpointer)"created");
-       g_main_loop_run(loop);
-       EXPECT_EQ(MODES_ERROR_NONE, result);
-}
-
-TEST_F(ClientTest, removeMode)
-{
-       g_idle_add(removeModeIdler, (gpointer)"deltest");
-       g_main_loop_run(loop);
-       EXPECT_EQ(MODES_ERROR_NONE, result);
-
-       int ret = modes_remove_mode(handle, "deltestN");
-       EXPECT_EQ(MODES_ERROR_INVALID_PARAMETER, ret);
-}
-
-TEST_F(ClientTest, undoModeEx1)
-{
-       modes_undo_mode(handle, "ex1");
-       g_idle_add(undoModeIdler, (gpointer)"ex1");
-       g_main_loop_run(loop);
-       EXPECT_EQ(MODES_ERROR_NONE, result);
-}
-
-TEST_F(ClientTest, undoModeEx2)
-{
-       modes_undo_mode(handle, "ex2");
-       g_idle_add(undoModeIdler, (gpointer)"ex2");
-       g_main_loop_run(loop);
-       EXPECT_EQ(MODES_ERROR_NONE, result);
-}
-
-TEST_F(ClientTest, getModes)
-{
-       const char* const typeList[2] = {
-               "MODES_TYPE_MODE_NORMAL",
-               "MODES_TYPE_MODE_ONESHOT"
-       };
-
-       GList *list, *cur;
-       int ret = modes_get_modes(handle, &list);
-       EXPECT_EQ(MODES_ERROR_NONE, ret);
-
-       for (cur = g_list_first(list); cur; cur = g_list_next(cur)) {
-               EXPECT_NE(nullptr, cur->data);
-
-               const char *name = modes_get_mode_name((mode_list_data_h)cur->data);
-               EXPECT_NE(nullptr, name);
-
-               int type = modes_get_mode_type((mode_list_data_h)cur->data);
-               EXPECT_NE(MODES_ERROR_INVALID_PARAMETER, type);
-
-               int state = modes_get_mode_state((mode_list_data_h)cur->data);
-               EXPECT_NE(MODES_ERROR_INVALID_PARAMETER, state);
-
-               std::cout << name << " " << typeList[type] << "(" << type << ") :state(" << state << ")" << std::endl;
-       }
-       modes_free_modes(list);
-}
diff --git a/unittest/modes_test_conflict.cpp b/unittest/modes_test_conflict.cpp
deleted file mode 100644 (file)
index 29cb270..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2019-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 <gtest/gtest.h>
-#include "common/definitions.h"
-#include "supervisor/ModeXMLParser.h"
-#include "supervisor/ModeCareTaker.h"
-
-MODES_NAMESPACE_USE;
-
-MODES_NAMESPACE_BEGIN
-class ConflictTest : public ::testing::Test {
-public:
-       ConflictTest();
-protected:
-       void SetUp() override
-       {
-               ModeXMLParser modeparser("tizen_conflictErrBase_mode.xml", ruleMgr);
-               careTaker.pushMode(modeparser.getMode());
-       }
-
-       void TearDown() override
-       {
-               Mode mode;
-               careTaker.popMode("conflict1", mode);
-       }
-
-       bool checkConflictAction(const Mode &mode)
-       {
-               return careTaker.checkConflictAction(mode);
-       }
-
-       RuleManager ruleMgr;
-       ModeCareTaker careTaker;
-};
-MODES_NAMESPACE_END
-
-
-ConflictTest::ConflictTest()
-       : ruleMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR), careTaker(".")
-{
-       ruleMgr.start();
-}
-
-
-TEST_F(ConflictTest, isSavedMode)
-{
-       ModeXMLParser modeparser("tizen_conflictErrBase_mode.xml", ruleMgr);
-       Mode mode = modeparser.getMode();
-       EXPECT_TRUE(careTaker.isSavedMode(mode.getName()));
-}
-
-TEST_F(ConflictTest, checkConflictAction)
-{
-       ModeXMLParser modeparser("tizen_conflictErr_mode.xml", ruleMgr);
-
-       Mode mode = modeparser.getMode();
-       EXPECT_TRUE(checkConflictAction(mode));
-}
-
-TEST_F(ConflictTest, isConflict)
-{
-       ModeXMLParser modeparser("tizen_conflictErr_mode.xml", ruleMgr);
-       EXPECT_TRUE(careTaker.isConflict(modeparser.getMode()));
-}
diff --git a/unittest/modes_test_generator.cpp b/unittest/modes_test_generator.cpp
deleted file mode 100644 (file)
index 99cf52e..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2019-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 <memory.h>
-#include <iostream>
-#include <gtest/gtest.h>
-#include "supervisor/Mode.h"
-#include "supervisor/ModesEx.h"
-#include "supervisor/RuleManager.h"
-#include "supervisor/XMLGenerator.h"
-#include "supervisor/ModeXMLParser.h"
-
-using namespace std;
-MODES_NAMESPACE_USE;
-
-MODES_NAMESPACE_BEGIN
-class GeneratorTest {
-public:
-       GeneratorTest();
-       RuleManager ruleMgr;
-};
-MODES_NAMESPACE_END
-
-GeneratorTest::GeneratorTest()
-       : ruleMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR)
-{
-       ruleMgr.start();
-}
-
-TEST(XMLGenerator, makeModeXML)
-{
-       GeneratorTest broker;
-
-       ModeXMLParser modeParser("tizen_normalEx1_mode.xml", broker.ruleMgr);
-       Mode mode = modeParser.getMode();
-
-       try {
-               XMLGenerator xmlGenerator;
-               xmlGenerator.makeModeXML("tizen_generatedEx1_mode.xml", mode);
-       } catch (ModesEx &e) {
-               ERR("XMLGenerator(tizen_generatedEx1_mode.xml) Fail(%s)", e.what());
-               FAIL();
-       }
-
-       ModeXMLParser genModeParser("tizen_generatedEx1_mode.xml", broker.ruleMgr);
-       Mode genMode = genModeParser.getMode();
-
-       EXPECT_EQ("ex1", genMode.getName());
-       std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
-       EXPECT_FALSE(actionList.empty());
-
-       for (std::list<std::shared_ptr<Action>>::iterator it = actionList.begin(); it != actionList.end(); ++it) {
-               cout << "* Action : " << (*it)->getRuleName() << endl;
-               cout << "\t\t- Restrict : " << (*it)->getRestrict() << endl;
-               cout << "\t\t- Content : " << (*it)->getStringOfValue() << endl;
-       }
-}
-
-TEST(XMLGenerator, exFileName)
-{
-       GeneratorTest broker;
-
-       ModeXMLParser modeParser("tizen_normalEx1_mode.xml", broker.ruleMgr);
-       Mode mode = modeParser.getMode();
-
-       EXPECT_THROW({
-               XMLGenerator xmlGenerator;
-               xmlGenerator.makeModeXML("", mode);
-       }, ModesEx);
-}
diff --git a/unittest/modes_test_main.cpp b/unittest/modes_test_main.cpp
deleted file mode 100644 (file)
index e7484bd..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2019-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 <gtest/gtest.h>
-
-int main(int argc, char **argv) {
-       testing::InitGoogleTest(&argc, argv);
-       return RUN_ALL_TESTS();
-}
diff --git a/unittest/modes_test_modemgr.cpp b/unittest/modes_test_modemgr.cpp
deleted file mode 100644 (file)
index f7aaa2e..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright (c) 2019-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 <iostream>
-#include <exception>
-#include <gtest/gtest.h>
-#include "supervisor/ModeManager.h"
-
-using namespace std;
-MODES_NAMESPACE_USE;
-
-MODES_NAMESPACE_BEGIN
-class ModeManagerTest {
-public:
-       ModeManagerTest();
-       RuleManager rMgr;
-       ModeManager mdMgr;
-
-       set<string> getDirectories();
-       bool emptyModeMap();
-       void printModeMap();
-};
-MODES_NAMESPACE_END
-
-ModeManagerTest::ModeManagerTest()
-       : rMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR),
-       mdMgr(set<string>(), "./" MODES_MODE_DEFAULT_XSD_FILE, rMgr)
-{
-       rMgr.start();
-       mdMgr.modeDirList.insert(".");
-       mdMgr.init();
-}
-
-set<string>  ModeManagerTest::getDirectories()
-{
-       return mdMgr.modeDirList;
-}
-
-bool ModeManagerTest::emptyModeMap()
-{
-       return mdMgr.modeMap.empty();
-}
-
-void ModeManagerTest::printModeMap()
-{
-       static const char* const mode_type[3] = {
-               "MODE_NORMAL",
-               "MODE_ONESHOT",
-               "MODE_EXCLUSIVE" };
-
-       if (!mdMgr.modeMap.empty()) {
-               cout << "| "; cout.width(15); cout << "Mode Name" << " | " << "ModeXML file Path" << "| type      | hidden" << endl;
-
-               for (auto it = mdMgr.modeMap.begin(); it != mdMgr.modeMap.end(); it++) {
-                       cout << "| ";  cout.width(15); cout << it->first.c_str() << " | " << std::get<0>(it->second).c_str() << " | ";
-                       cout << mode_type[std::get<1>(it->second)];
-                       if (std::get<2>(it->second))
-                               cout << "hidden";
-                       else
-                               cout << "Not hidden";
-                       cout << endl;
-               }
-       }
-}
-
-TEST(ModeManager, setOptions)
-{
-       ModeManagerTest mdMgrTest;
-
-       EXPECT_FALSE(mdMgrTest.emptyModeMap()) << "Mode Map is empty!" << endl;
-
-       mdMgrTest.printModeMap();
-}
-
-TEST(ModeManager, addModeDirectory)
-{
-       ModeManagerTest mdMgrTest;
-
-       string dir_extra = "./extra";
-       try {
-               mdMgrTest.mdMgr.addModeDirectory(dir_extra);
-       }
-       catch (exception &e) {
-               ADD_FAILURE() << "Fail to append : " << e.what() << endl;
-               return;
-       }
-
-       EXPECT_FALSE(mdMgrTest.emptyModeMap()) << "Mode Map is empty!" << endl;
-
-       mdMgrTest.printModeMap();
-}
-
-TEST(ModeManager, addModeDirectory_withwrongdir)
-{
-       ModeManagerTest mdMgrTest;
-
-       string dir_wrong = "./dir_wrong";
-       try {
-               mdMgrTest.mdMgr.addModeDirectory(dir_wrong);
-       }
-       catch (exception &e) {
-               cout << "Fail to append : " << e.what() << endl;
-               return;
-       }
-
-       ADD_FAILURE() << "addModeDirectory() did not detect a wrong directory!" << endl;
-}
-
-TEST(ModeManager, addModeDirectory_withappendeddir)
-{
-       ModeManagerTest mdMgrTest;
-
-       string dir_extra = "./extra";
-       try {
-               mdMgrTest.mdMgr.addModeDirectory(dir_extra);
-       }
-       catch (exception &e) {
-               cout << "Fail to append : " << e.what() << endl;
-               ADD_FAILURE();
-               return;
-       }
-       EXPECT_FALSE(mdMgrTest.emptyModeMap()) << "Mode Map is empty!" << endl;
-       mdMgrTest.printModeMap();
-
-       string dir_appended = dir_extra;
-       try {
-               mdMgrTest.mdMgr.addModeDirectory(dir_appended);
-       }
-       catch (exception &e) {
-               cout << "Fail to append : " << e.what() << endl;
-               return;
-       }
-
-       ADD_FAILURE() << "addModeDirectory() did not detect a directory that is already attached!" << endl;
-}
diff --git a/unittest/modes_test_noti.cpp b/unittest/modes_test_noti.cpp
deleted file mode 100644 (file)
index 9145c84..0000000
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright (c) 2019-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 <glib.h>
-#include <gtest/gtest.h>
-#include <modes.h>
-
-class ClientNotiTest : public ::testing::Test {
-protected:
-       void SetUp() override
-       {
-               handle = modes_connect();
-               loop = g_main_loop_new(NULL, FALSE);
-       }
-
-       void TearDown() override
-       {
-               g_main_loop_unref(loop);
-               loop = NULL;
-               modes_disconnect(handle);
-               handle = NULL;
-       }
-
-       static gboolean undoTimeout(gpointer data)
-       {
-               expectedState = 0;
-               int ret = modes_undo_mode(handle, (const char*)data);
-               EXPECT_EQ(MODES_ERROR_NONE, ret);
-
-               return G_SOURCE_REMOVE;
-       }
-
-       static int notiFunc(const char *modeName, int state, void *user_data)
-       {
-               char *requestMode = (char*)user_data;
-
-               std::cout << "notiFunc Changed Mode : " << modeName << std::endl;
-               EXPECT_EQ(requestMode, std::string(modeName));
-               std::cout << "state : " << state << std::endl;
-               EXPECT_EQ(expectedState, state);
-
-               if (0 == expectedState)
-                       g_main_loop_quit(loop);
-               return MODES_ERROR_NONE;
-       }
-
-       static int changeFn(const char *modeName, int state, void *user_data)
-       {
-               char *requestMode = (char*)user_data;
-
-               std::cout << "changeFn Changed Mode : " << modeName << std::endl;
-               EXPECT_EQ(requestMode, std::string(modeName));
-               std::cout << "state : " << state << std::endl;
-
-               if (0 == state)
-                       g_main_loop_quit(loop);
-
-               return MODES_ERROR_NONE;
-       }
-
-       static int notiMultiFunc1(const char *modeName, int state, void *user_data)
-       {
-               std::cout << "notiMultiFunc1 Changed Mode : " << modeName << std::endl;
-               std::cout << "state : " << state << std::endl;
-
-               calledbit1 |= 0x1 << state;
-
-               return MODES_ERROR_NONE;
-       }
-
-       static int notiMultiFunc2(const char *modeName, int state, void *user_data)
-       {
-               std::cout << "notiMultiFunc2 Changed Mode : " << modeName << std::endl;
-               std::cout << "state : " << state << std::endl;
-
-               calledbit2 |= 0x1 << state;
-
-               return MODES_ERROR_NONE;
-       }
-
-       static int notiMultiFunc3(const char *modeName, int state, void *user_data)
-       {
-               std::cout << "notiMultiFunc3 Changed Mode : " << modeName << std::endl;
-               std::cout << "state : " << state << std::endl;
-
-               EXPECT_TRUE(NULL == user_data || notiTestMode == user_data);
-
-               if (NULL == user_data)
-                       calledbit3 |= 0x1 << state;
-               if (notiTestMode == user_data)
-                       calledbit4 |= 0x1 << state;
-
-               if (0x3 == calledbit3 && 0x3 == calledbit4)
-                       g_main_loop_quit(loop);
-
-               return MODES_ERROR_NONE;
-       }
-
-
-       static modes_h handle;
-       static int expectedState;
-       static GMainLoop *loop;
-       static unsigned char calledbit1;
-       static unsigned char calledbit2;
-       static unsigned char calledbit3;
-       static unsigned char calledbit4;
-       static const char *notiTestMode;
-};
-
-modes_h ClientNotiTest::handle = NULL;
-int ClientNotiTest::expectedState = 1;
-unsigned char ClientNotiTest::calledbit1 = 0;
-unsigned char ClientNotiTest::calledbit2 = 0;
-unsigned char ClientNotiTest::calledbit3 = 0;
-unsigned char ClientNotiTest::calledbit4 = 0;
-GMainLoop *ClientNotiTest::loop = NULL;
-const char *ClientNotiTest::notiTestMode = "ex2";
-
-TEST_F(ClientNotiTest, subscribeCB)
-{
-       const char *testMode = "ex2";
-       modes_noti_ID id = modes_subscribe_mode_changes(handle, notiFunc, (void*)testMode);
-       EXPECT_NE(nullptr , id);
-
-       ClientNotiTest::expectedState = 1;
-       int ret = modes_apply_mode(handle, testMode);
-       EXPECT_EQ(MODES_ERROR_NONE, ret);
-
-       g_timeout_add_seconds(1, undoTimeout, (void*)testMode);
-
-       g_main_loop_run(loop);
-
-       modes_unsubscribe_mode_changes(handle, id);
-}
-TEST_F(ClientNotiTest, subscribeMultiCb)
-{
-       calledbit1 = 0;
-       calledbit2 = 0;
-       calledbit3 = 0;
-
-       modes_noti_ID id1 = modes_subscribe_mode_changes(handle, notiMultiFunc1, NULL);
-       EXPECT_NE(nullptr, id1);
-
-       modes_noti_ID id2 = modes_subscribe_mode_changes(handle, notiMultiFunc2, NULL);
-       EXPECT_NE(nullptr, id2);
-
-       modes_noti_ID id3 = modes_subscribe_mode_changes(handle, notiMultiFunc3, (void*)notiTestMode);
-       EXPECT_NE(nullptr, id3);
-
-       modes_noti_ID id4 = modes_subscribe_mode_changes(handle, notiMultiFunc3, NULL);
-       EXPECT_NE(nullptr, id4);
-
-       int ret = modes_apply_mode(handle, notiTestMode);
-       EXPECT_EQ(MODES_ERROR_NONE, ret);
-
-       g_timeout_add_seconds(1, undoTimeout, (void*)notiTestMode);
-       g_main_loop_run(loop);
-
-       modes_unsubscribe_mode_changes(handle, id1);
-       modes_unsubscribe_mode_changes(handle, id2);
-       modes_unsubscribe_mode_changes(handle, id3);
-       modes_unsubscribe_mode_changes(handle, id4);
-
-       EXPECT_EQ(calledbit1, 1 << 0 | 1 << 1);
-       EXPECT_EQ(calledbit2, 1 << 0 | 1 << 1);
-       EXPECT_EQ(calledbit3, 1 << 0 | 1 << 1);
-       EXPECT_EQ(calledbit4, 1 << 0 | 1 << 1);
-}
-
-TEST_F(ClientNotiTest, essentialAction)
-{
-       const char *testMode = "essential_ex";
-       modes_noti_ID id = modes_subscribe_mode_changes(handle, changeFn, (void*)testMode);
-       EXPECT_NE(nullptr, id);
-
-       int ret = modes_apply_mode(handle, testMode);
-       EXPECT_EQ(MODES_ERROR_NONE, ret);
-
-       g_main_loop_run(loop);
-
-       modes_unsubscribe_mode_changes(handle, id);
-}
diff --git a/unittest/modes_test_parser.cpp b/unittest/modes_test_parser.cpp
deleted file mode 100644 (file)
index 8a5d110..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (c) 2019-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 <iostream>
-#include <memory>
-#include <gtest/gtest.h>
-#include "supervisor/Mode.h"
-#include "supervisor/ModesEx.h"
-#include "supervisor/RuleManager.h"
-#include "supervisor/ModeXMLParser.h"
-
-using namespace std;
-MODES_NAMESPACE_USE;
-
-MODES_NAMESPACE_BEGIN
-class ParserTest : public ::testing::Test {
-public:
-       ParserTest();
-
-       void parserTest(const string &fileName);
-       list<shared_ptr<Action>> getActionList(Mode& m);
-
-protected:
-       void SetUp() override
-       {
-       }
-
-       void TearDown() override
-       {
-       }
-
-       RuleManager ruleMgr;
-};
-MODES_NAMESPACE_END
-
-ParserTest::ParserTest()
-       : ruleMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR)
-{
-       ruleMgr.start();
-}
-
-list<shared_ptr<Action>> ParserTest::getActionList(Mode& m)
-{
-       return m.actionList;
-}
-
-TEST_F(ParserTest, modeGetName)
-{
-       ModeXMLParser modeparser("tizen_normalEx2_mode.xml", ruleMgr);
-       Mode mode = modeparser.getMode();
-       EXPECT_EQ("ex2", mode.getName());
-}
-
-TEST_F(ParserTest, isHiddenTrue)
-{
-       ModeXMLParser modeparser("tizen_normalEx2_mode.xml", ruleMgr);
-       Mode mode = modeparser.getMode();
-       EXPECT_EQ(true, mode.isHidden());
-}
-
-TEST_F(ParserTest, isHiddenFalse)
-{
-       ModeXMLParser modeparser("tizen_normalEx1_mode.xml", ruleMgr);
-       Mode mode = modeparser.getMode();
-       EXPECT_EQ(false, mode.isHidden());
-}
-
-TEST_F(ParserTest, getModeType)
-{
-       ModeXMLParser modeparser("tizen_normalEx1_mode.xml", ruleMgr);
-       Mode mode = modeparser.getMode();
-       EXPECT_EQ(Mode::MODE_NORMAL, mode.getModeType());
-}
-
-TEST_F(ParserTest, printAction)
-{
-       ModeXMLParser modeparser("tizen_normalEx1_mode.xml", ruleMgr);
-       Mode mode = modeparser.getMode();
-
-       list<std::shared_ptr<Action>> actionList = getActionList(mode);
-       EXPECT_FALSE(actionList.empty());
-
-       for (list<std::shared_ptr<Action>>::iterator it = actionList.begin(); it != actionList.end(); ++it) {
-               cout << "* Action : " << (*it)->getRuleName() << endl;
-               cout << "\t\t- Restrict : " << (*it)->getRestrict() << endl;
-               //cout << "\t\t- Content : " << (*it)->getValue() << endl;
-       }
-}
-
-TEST_F(ParserTest, invalidActionValue)
-{
-       ModeXMLParser modeparser1("tizen_invalidValErr1_mode.xml", ruleMgr);
-       EXPECT_THROW(modeparser1.getMode(), ModesEx);
-
-       ModeXMLParser modeparser2("tizen_invalidValErr2_mode.xml", ruleMgr);
-       EXPECT_THROW(modeparser2.getMode(), ModesEx);
-}
-
-TEST_F(ParserTest, validateAsyncStopOnErr)
-{
-       ModeXMLParser modeparser("tizen_asyncValidErr_mode.xml", ruleMgr);
-
-       EXPECT_THROW(modeparser.getMode(), ModesEx);
-}
-
-TEST_F(ParserTest, printError)
-{
-       EXPECT_NO_THROW(
-               std::cout << "MODES_ERROR_NONE " << MODES_ERROR_NONE << std::endl;
-       std::cout << "MODES_ERROR_ALREADY " << MODES_ERROR_ALREADY << std::endl;
-       std::cout << "MODES_ERROR_NO_DATA " << MODES_ERROR_NO_DATA << std::endl;
-       std::cout << "MODES_ERROR_TIMEOUT " << MODES_ERROR_TIMEOUT << std::endl;
-       std::cout << "MODES_ERROR_IO_ERROR " << MODES_ERROR_IO_ERROR << std::endl;
-       std::cout << "MODES_ERROR_NOT_SUPPORTED " << MODES_ERROR_NOT_SUPPORTED << std::endl;
-       std::cout << "MODES_ERROR_OUT_OF_MEMORY " << MODES_ERROR_OUT_OF_MEMORY << std::endl;
-       std::cout << "MODES_ERROR_PERMISSION_DENIED " << MODES_ERROR_PERMISSION_DENIED << std::endl;
-       std::cout << "MODES_ERROR_INVALID_PARAMETER " << MODES_ERROR_INVALID_PARAMETER << std::endl;
-       std::cout << "MODES_ERROR_SYSTEM " << MODES_ERROR_SYSTEM << std::endl;
-       std::cout << "MODES_ERROR_CONFLICT " << MODES_ERROR_CONFLICT << std::endl;
-       );
-}
diff --git a/unittest/modes_test_plugin.cpp b/unittest/modes_test_plugin.cpp
deleted file mode 100644 (file)
index fe146b7..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (c) 2019-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 <iostream>
-#include <gtest/gtest.h>
-#include "supervisor/PluginMapper.h"
-#include "supervisor/ModesEx.h"
-
-using namespace std;
-
-MODES_NAMESPACE_BEGIN
-class TestPluginBroker {
-public:
-       TestPluginBroker();
-
-       bool emptyPluginMap();
-       string getpluginDir();
-
-       PluginMapper piMapper;
-};
-MODES_NAMESPACE_END
-
-MODES_NAMESPACE_USE;
-
-TestPluginBroker::TestPluginBroker()
-       : piMapper("../../.." MODES_PLUGIN_DEFAULT_DIR)
-{
-}
-
-bool TestPluginBroker::emptyPluginMap()
-{
-       return piMapper.pluginMap.empty();
-}
-
-string TestPluginBroker::getpluginDir()
-{
-       return piMapper.pluginDir;
-}
-
-TEST(PluginMapper, readLibraryList)
-{
-       TestPluginBroker broker;
-
-       EXPECT_NO_THROW(broker.piMapper.loadPlugins());
-       EXPECT_FALSE(broker.emptyPluginMap());
-
-       list<string> pluginList = broker.piMapper.getPluginList();
-       if (pluginList.empty()) {
-               FAIL() << "getPluginList() Fail:This should never be reached";
-       } else {
-               for (auto it = pluginList.begin(); it != pluginList.end(); ++it)
-                       printf("plugin library : %s\n", it->c_str());
-       }
-}
-
-TEST(PluginMapper, unloadClassMap)
-{
-       TestPluginBroker broker;
-
-       int ret = broker.piMapper.unloadPlugins();
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-       EXPECT_TRUE(broker.emptyPluginMap());
-}
-
-TEST(PluginMapper, getPluginTest)
-{
-       int ret;
-       TestPluginBroker broker;
-
-       EXPECT_NO_THROW(broker.piMapper.loadPlugins());
-       EXPECT_FALSE(broker.emptyPluginMap());
-
-       Plugin *plugin = broker.piMapper.getPlugin("test");
-       ASSERT_TRUE(plugin);
-
-       PluginAction *piAction = plugin->newAction("printInt");
-       ret = piAction->set(0);
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-
-       ret = piAction->set(false);
-       EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
-       plugin->deleteAction(piAction);
-
-       piAction = plugin->newAction("printFloat");
-       ret = piAction->set(1.234);
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-       plugin->deleteAction(piAction);
-
-       piAction = plugin->newAction("printBool");
-       ret = piAction->set(false);
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-
-       ret = piAction->set(3);
-       EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
-       plugin->deleteAction(piAction);
-
-       piAction = plugin->newAction("printString");
-       ret = piAction->set(string("String value"));
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-       plugin->deleteAction(piAction);
-
-       piAction = plugin->newAction("alwaySameValue");
-       bool same = piAction->IsCurrentValue(string("String value"));
-       EXPECT_EQ(same, true);
-       ret = piAction->set(string("String value"));
-       EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
-       plugin->deleteAction(piAction);
-
-       ret = broker.piMapper.unloadPlugins();
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-       EXPECT_TRUE(broker.emptyPluginMap());
-}
diff --git a/unittest/modes_test_policy.cpp b/unittest/modes_test_policy.cpp
deleted file mode 100644 (file)
index fa6c190..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (c) 2019-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 <functional>
-#include <gtest/gtest.h>
-#include "Plugin.h"
-#include "supervisor/ModesEx.h"
-#include "supervisor/TAction.h"
-
-using namespace std;
-MODES_NAMESPACE_USE;
-
-extern "C" Plugin* objectCreate(void);
-extern "C" void objectDelete(Plugin *plugin);
-
-MODES_NAMESPACE_BEGIN
-class PolicyTest : public ::testing::Test {
-protected:
-       void SetUp() override
-       {
-               plugin = objectCreate();
-       }
-
-       void TearDown() override
-       {
-               objectDelete(plugin);
-       }
-
-       bool isSubscribed(Action *action)
-       {
-               return !(action->isIgnored());
-       }
-
-       Plugin *plugin;
-};
-MODES_NAMESPACE_END
-
-TEST_F(PolicyTest, OnlyOneSubscribe)
-{
-       int ret;
-       string ruleName = "test.printInt";
-
-       int pos = ruleName.find_first_of(".");
-       std::string actionKey = ruleName.substr(pos + 1);
-       std::shared_ptr<PluginAction> piAction1(plugin->newAction(actionKey),
-               std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
-
-       Action *action1 = nullptr;
-       ASSERT_NO_THROW(action1 = new TAction<int>(ruleName, piAction1));
-
-       ret = action1->setValue("4");
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-       ret = action1->apply();
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-       EXPECT_EQ(isSubscribed(action1), true);
-
-       std::shared_ptr<PluginAction> piAction2(plugin->newAction(actionKey),
-               std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
-       Action *action2 = nullptr;
-       ASSERT_NO_THROW(action2 = new TAction<int>(ruleName, piAction2));
-
-       ret = action2->setValue("2");
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-       ret = action2->apply();
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-       EXPECT_EQ(isSubscribed(action2), true);
-       EXPECT_EQ(isSubscribed(action1), false);
-}
-
-TEST_F(PolicyTest, ignoreSameValue)
-{
-       int ret;
-       string ruleName = "test.printInt";
-
-       int pos = ruleName.find_first_of(".");
-       std::string actionKey = ruleName.substr(pos + 1);
-       std::shared_ptr<PluginAction> piAction1(plugin->newAction(actionKey),
-               std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
-
-       Action *action1 = nullptr;
-       ASSERT_NO_THROW(action1 = new TAction<int>(ruleName, piAction1));
-
-       ret = action1->setValue("4");
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-       ret = action1->apply();
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-       EXPECT_EQ(isSubscribed(action1), true);
-
-       std::shared_ptr<PluginAction> piAction2(plugin->newAction(actionKey),
-               std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
-       Action *action2 = nullptr;
-       ASSERT_NO_THROW(action2 = new TAction<int>(ruleName, piAction2));
-
-       ret = action2->setValue("4");
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-       ret = action2->apply();
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-       EXPECT_EQ(isSubscribed(action2), false);
-       EXPECT_EQ(isSubscribed(action1), true);
-}
-
-TEST_F(PolicyTest, oneShotNoSubscribe)
-{
-       int ret;
-       string ruleName = "test.printInt";
-
-       int pos = ruleName.find_first_of(".");
-       std::string actionKey = ruleName.substr(pos + 1);
-       std::shared_ptr<PluginAction> piAction1(plugin->newAction(actionKey),
-               std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
-
-       Action *action1 = nullptr;
-       ASSERT_NO_THROW(action1 = new TAction<int>(ruleName, piAction1));
-
-       ret = action1->setValue("4");
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-       ret = action1->applyOneShot();
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-       EXPECT_EQ(isSubscribed(action1), false);
-}
diff --git a/unittest/modes_test_rulemgr.cpp b/unittest/modes_test_rulemgr.cpp
deleted file mode 100644 (file)
index dff8805..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2019-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 <gtest/gtest.h>
-#include "supervisor/ModesEx.h"
-#include "supervisor/RuleManager.h"
-
-using namespace std;
-
-MODES_NAMESPACE_BEGIN
-class RuleManagerTest {
-public:
-       RuleManagerTest();
-
-       RuleManager rMgr;
-       void parseActionRule(const string &xmlFile)
-       {
-               rMgr.parseActionRule(xmlFile);
-       }
-       bool emptyRuleMap()
-       {
-               return rMgr.ruleMap.empty();
-       }
-};
-MODES_NAMESPACE_END
-
-MODES_NAMESPACE_USE;
-
-RuleManagerTest::RuleManagerTest()
-       : rMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR)
-{
-       rMgr.piMapper.loadPlugins();
-}
-
-TEST(RuleManagerTest, makeRuleMapP)
-{
-       RuleManagerTest testBroker;
-       EXPECT_NO_THROW(testBroker.rMgr.start());
-}
-
-TEST(RuleManagerTest, parseActionRuleP)
-{
-       RuleManagerTest testBroker;
-       EXPECT_NO_THROW(testBroker.parseActionRule("./tizen_test_rule.xml"));
-}
-
-TEST(RuleManagerTest, DuplicatedRule)
-{
-       RuleManagerTest testBroker;
-       EXPECT_THROW(testBroker.parseActionRule("./tizen_uniqueRuleErr_rule.xml"), ModesEx);
-}
-
-TEST(RuleManagerTest, InvalidValue)
-{
-       RuleManagerTest testBroker;
-       EXPECT_THROW(testBroker.parseActionRule("./tizen_uniqueRuleErr_rule.xml"), ModesEx);
-}
-
-// If there are any errors in a file, the file will be ignored.
-TEST(RuleManagerTest, CheckAtomicity)
-{
-       RuleManagerTest testBroker;
-       EXPECT_THROW(testBroker.parseActionRule("./tizen_aliasValueErr.xml"), ModesEx);
-       EXPECT_TRUE(testBroker.emptyRuleMap());
-}
-
-TEST(RuleManagerTest, UnknownPlugin1)
-{
-       RuleManagerTest testBroker;
-       EXPECT_THROW(testBroker.parseActionRule("./tizen_pluginErr1_rule.xml"), ModesEx);
-}
-
-TEST(RuleManagerTest, UnknownPlugin2)
-{
-       RuleManagerTest testBroker;
-       EXPECT_THROW(testBroker.parseActionRule("./tizen_pluginErr2_rule.xml"), ModesEx);
-}