Add unit tests 09/216209/2
authorhyunho <hhstark.kang@samsung.com>
Tue, 22 Oct 2019 08:38:08 +0000 (17:38 +0900)
committerhyunho <hhstark.kang@samsung.com>
Tue, 22 Oct 2019 08:47:42 +0000 (17:47 +0900)
Change-Id: Ia8e9cac4c529f9e3e3ba07139ff4adaec5bae47c
Signed-off-by: hyunho <hhstark.kang@samsung.com>
unit_tests/src/base/test_base_base_stub.cc [new file with mode: 0644]
unit_tests/src/base/test_base_frame_stub.cc [new file with mode: 0644]
unit_tests/src/base/test_base_service_stub.cc [new file with mode: 0644]

diff --git a/unit_tests/src/base/test_base_base_stub.cc b/unit_tests/src/base/test_base_base_stub.cc
new file mode 100644 (file)
index 0000000..feb673b
--- /dev/null
@@ -0,0 +1,321 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * 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 <stdlib.h>
+#include <gtest/gtest.h>
+
+#include <iostream>
+#include <memory>
+
+#include "component_based/base/api/component_based_app_base.h"
+#include "component_based/base/api/base_component.h"
+
+#include "unit_tests/mock/mock_app_common.h"
+#include "unit_tests/mock/mock_app_control.h"
+#include "unit_tests/mock/mock_appcore_multiwindow_base.h"
+#include "unit_tests/mock/mock_aul.h"
+#include "unit_tests/mock/mock_elementary.h"
+
+namespace {
+
+static appcore_multiwindow_base_ops __ops;
+static int __argc;
+static char** __argv;
+static void* __user_data;
+static appcore_multiwindow_base_class __cls;
+static appcore_base_event_cb __event_cb[APPCORE_BASE_EVENT_MAX];
+static void* __event_data[APPCORE_BASE_EVENT_MAX];
+
+static int __fake_aul_comp_notify_start(const char *id) {
+  return 0;
+}
+
+static int __fake_aul_comp_status_update(const char *id, int status) {
+  return 0;
+}
+
+static void __generate_system_event(void)
+{
+  char lang[] = "en-US";
+  int intval = 1;
+  void* event;
+
+  for (int i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) {
+    if (i == APPCORE_BASE_EVENT_LANG_CHANGE ||
+        i == APPCORE_BASE_EVENT_REGION_CHANGE) {
+      event = static_cast<void*>(lang);
+    } else {
+      event = static_cast<void*>(&intval);
+    }
+
+    if (__event_cb[i]) {
+      __event_cb[i](event, __event_data[i]);
+    }
+  }
+}
+
+static int __fake_appcore_multiwindow_base_init(
+    appcore_multiwindow_base_ops ops,
+    int argc,
+    char** argv,
+    void* user_data) {
+  __ops = ops;
+  __argc = argc;
+  __argv = argv;
+  __user_data = user_data;
+
+  __ops.base.init(__argc, __argv, __user_data);
+  __ops.base.create(__user_data);
+  __ops.base.run(__user_data);
+
+  bundle* b = bundle_create();
+  bundle_add_str(b, AUL_K_COMPONENT_ID, "test-base-component");
+  bundle_add_str(b, AUL_K_INSTANCE_ID, "@test-base-component");
+  bundle_add_str(b, AUL_K_NEW_INSTANCE, "true");
+  std::unique_ptr<bundle, decltype(bundle_free)*> ptr(b, bundle_free);
+
+  __ops.base.receive(AUL_START, b, __user_data);
+
+  __generate_system_event();
+
+  __ops.base.control(b, __user_data);
+
+  __ops.base.receive(AUL_RESUME, b, __user_data);
+  __ops.base.receive(AUL_PAUSE, b, __user_data);
+
+  __ops.base.receive(AUL_WAKE, b, __user_data);
+  __ops.base.receive(AUL_SUSPEND, b, __user_data);
+
+  __ops.base.receive(AUL_TERMINATE_INST, b, __user_data);
+  __ops.base.receive(AUL_TERMINATE_BG_INST, b, __user_data);
+  __ops.base.receive(AUL_TERMINATE_BGAPP, b, __user_data);
+
+  return 0;
+}
+
+static void __fake_appcore_multiwindow_base_fini(void) {
+  __cls.terminate(nullptr, __cls.data);
+
+  __ops.base.terminate(__user_data);
+  __ops.base.finish();
+}
+
+static void __fake_appcore_multiwindow_base_exit(void) {
+  __ops.base.exit(__user_data);
+}
+
+static int __fake_elm_init(int argc, char** argv) {
+  return 0;
+}
+
+static int __fake_elm_shutdown(void) {
+  return 0;
+}
+
+static void __fake_appcore_multiwindow_base_class_add(
+    appcore_multiwindow_base_class cls) {
+  __cls = cls;
+}
+
+static appcore_multiwindow_base_instance_h
+__fake_appcore_multiwindow_base_instance_run(const char* class_id,
+    const char* id, void* extra)
+{
+  static appcore_multiwindow_base_instance_h inst =
+      reinterpret_cast<appcore_multiwindow_base_instance_h>(&inst);
+
+  __cls.create(inst, __cls.data);
+
+  return inst;
+}
+
+static const char* __fake_appcore_multiwindow_base_instance_get_id(
+    appcore_multiwindow_base_instance_h context) {
+  return "@test-base-component";
+}
+
+static appcore_base_event_h __fake_appcore_base_add_event(
+    enum appcore_base_event type, appcore_base_event_cb cb, void* data) {
+  __event_cb[type] = cb;
+  __event_data[type] = data;
+  return nullptr;
+}
+
+static int __fake_app_control_add_action_handler(const char* action,
+    app_control_action_cb callback, void* user_data,
+    app_control_action_h* handle) {
+  callback(action, nullptr, user_data);
+  return 0;
+}
+
+static int __fake_app_control_send_launch_request_async(
+    app_control_h app_control,
+    app_control_result_cb result_cb,
+    app_control_reply_cb reply_cb,
+    void* user_data) {
+  result_cb(app_control, APP_CONTROL_ERROR_NONE, user_data);
+  reply_cb(app_control, app_control, APP_CONTROL_RESULT_SUCCEEDED, user_data);
+  return 0;
+}
+
+static int __fake_app_control_send_launch_request_sync(
+    app_control_h app_control,
+    app_control_h* reply,
+    app_control_result_e* result) {
+  app_control_h handle = nullptr;
+  app_control_create(&handle);
+  *reply = handle;
+  *result = APP_CONTROL_RESULT_SUCCEEDED;
+  return 0;
+}
+
+class BaseCompStubTest : public ::testing::Test {
+ public:
+  virtual void SetUp() {
+    appcore_multiwindow_base_init_fake.custom_fake =
+        __fake_appcore_multiwindow_base_init;
+    appcore_multiwindow_base_fini_fake.custom_fake =
+        __fake_appcore_multiwindow_base_fini;
+    appcore_multiwindow_base_exit_fake.custom_fake =
+        __fake_appcore_multiwindow_base_exit;
+    appcore_multiwindow_base_instance_run_fake.custom_fake =
+        __fake_appcore_multiwindow_base_instance_run;
+    appcore_multiwindow_base_class_add_fake.custom_fake =
+        __fake_appcore_multiwindow_base_class_add;
+    appcore_multiwindow_base_instance_get_id_fake.custom_fake =
+        __fake_appcore_multiwindow_base_instance_get_id;
+    appcore_base_add_event_fake.custom_fake =
+        __fake_appcore_base_add_event;
+
+    elm_init_fake.custom_fake =
+        __fake_elm_init;
+    elm_shutdown_fake.custom_fake =
+        __fake_elm_shutdown;
+    aul_comp_notify_start_fake.custom_fake =
+        __fake_aul_comp_notify_start;
+    aul_comp_status_update_fake.custom_fake =
+        __fake_aul_comp_status_update;
+    app_control_add_action_handler_fake.custom_fake =
+        __fake_app_control_add_action_handler;
+    app_control_send_launch_request_async_fake.custom_fake =
+        __fake_app_control_send_launch_request_async;
+    app_control_send_launch_request_sync_fake.custom_fake =
+        __fake_app_control_send_launch_request_sync;
+  }
+
+  virtual void TearDown(){
+  }
+};
+
+static void __base_component_restore_content_cb(component_h context,
+    bundle* content, void* user_data) {
+}
+
+static void __base_component_save_content_cb(component_h context,
+    bundle* content, void* user_data) {
+}
+
+static void __base_component_device_orientation_changed_cb(
+    component_h context, component_device_orientation_e orientation,
+    void* user_data) {
+}
+
+static void __base_component_language_changed_cb(component_h context,
+    const char* language, void* user_data) {
+}
+
+static void __base_component_region_format_changed_cb(component_h context,
+    const char* region, void* user_data) {
+}
+
+static void __base_component_low_battery_cb(component_h context,
+    component_low_battery_status_e status, void* user_data) {
+}
+
+static void __base_component_low_memory_cb(component_h context,
+    component_low_memory_status_e status, void* user_data) {
+}
+
+static void __base_component_suspended_state_changed_cb(component_h context,
+    component_suspended_state_e state, void* user_data) {
+}
+
+component_class_h base_component_add(component_class_h comp_class,
+               const char *component_id, void *user_data)
+{
+       base_component_lifecycle_callback_s callback = {
+               .restore_content = __base_component_restore_content_cb,
+               .save_content = __base_component_save_content_cb,
+               .device_orientation_changed = __base_component_device_orientation_changed_cb,
+               .language_changed = __base_component_language_changed_cb,
+               .region_format_changed = __base_component_region_format_changed_cb,
+               .low_battery = __base_component_low_battery_cb,
+               .low_memory = __base_component_low_memory_cb,
+               .suspended_state_changed = __base_component_suspended_state_changed_cb,
+       };
+
+       return component_based_app_base_add_base_component(comp_class,
+      COMPONENT_TYPE_SERVICE, component_id, &callback, user_data);
+}
+
+void __app_init_cb(int argc, char** argv, void *user_data)
+{
+}
+
+void __app_fini_cb(void *user_data)
+{
+}
+
+void __app_run_cb(void *user_data)
+{
+}
+
+void __app_exit_cb(void *user_data)
+{
+}
+
+component_class_h __app_create_cb(void *user_data)
+{
+       component_class_h comp_class = NULL;
+       comp_class = base_component_add(comp_class,
+                       "test-base-component", NULL);
+
+       return comp_class;
+}
+
+void __app_terminate_cb(void *user_data)
+{
+}
+
+TEST_F(BaseCompStubTest, component_based_app_base_add_base_component)
+{
+  component_based_app_base_lifecycle_callback_s callback = {
+               .init = __app_init_cb,
+               .fini = __app_fini_cb,
+               .run = __app_run_cb,
+               .exit = __app_exit_cb,
+               .create = __app_create_cb,
+               .terminate = __app_terminate_cb
+       };
+  int argc = 1;
+  char tmp_arg[] = "test";
+  char** argv = reinterpret_cast<char**>(&tmp_arg);
+
+  int ret = component_based_app_base_main(argc, argv, &callback, this);
+  EXPECT_EQ(COMPONENT_ERROR_NONE, ret);
+}
+
+}
\ No newline at end of file
diff --git a/unit_tests/src/base/test_base_frame_stub.cc b/unit_tests/src/base/test_base_frame_stub.cc
new file mode 100644 (file)
index 0000000..7376fad
--- /dev/null
@@ -0,0 +1,631 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * 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 <stdlib.h>
+#include <gtest/gtest.h>
+
+#include <iostream>
+#include <memory>
+
+#include "frame_component_util.h"
+#include "component_based/base/api/component_based_app_base.h"
+#include "component_based/base/api/base_component.h"
+#include "component_based/base/api/base_frame_component.h"
+#include "component_based/base/api/base_service_component.h"
+
+#include "unit_tests/mock/mock_app_common.h"
+#include "unit_tests/mock/mock_app_control.h"
+#include "unit_tests/mock/mock_appcore_multiwindow_base.h"
+#include "unit_tests/mock/mock_aul.h"
+#include "unit_tests/mock/mock_elementary.h"
+
+namespace {
+
+static appcore_multiwindow_base_ops __ops;
+static int __argc;
+static char** __argv;
+static void* __user_data;
+static appcore_multiwindow_base_class __cls;
+static bool __is_resumed;
+static appcore_base_event_cb __event_cb[APPCORE_BASE_EVENT_MAX];
+static void* __event_data[APPCORE_BASE_EVENT_MAX];
+
+static void __generate_show_event(void) {
+  Ecore_Wl2_Event_Window_Show ev = {
+    .win = 1,
+    .parent_win = 1,
+    .event_win = 1,
+    .data = { 1, }
+  };
+  __ops.window.show(ECORE_WL2_EVENT_WINDOW_SHOW, &ev, __user_data);
+}
+
+static void __generate_hide_event(void) {
+  Ecore_Wl2_Event_Window_Hide ev = {
+    .win = 1,
+    .parent_win = 1,
+    .event_win = 1
+  };
+
+  __ops.window.hide(ECORE_WL2_EVENT_WINDOW_HIDE, &ev, __user_data);
+}
+
+static void __generate_lower_event(void) {
+  Ecore_Wl2_Event_Window_Lower ev = {
+    .win = 1,
+    .timestamp = 2
+  };
+
+  __ops.window.lower(ECORE_WL2_EVENT_WINDOW_LOWER, &ev, __user_data);
+}
+
+static void __generate_aux_message(void) {
+  Ecore_Wl2_Event_Aux_Message ev = {
+    .win = 1,
+    .key = "dpms",
+    .val = "on",
+  };
+
+  __ops.window.aux_message(ECORE_WL2_EVENT_AUX_MESSAGE, &ev, __user_data);
+}
+
+static void __generate_pre_visibility_change_event(void) {
+  Ecore_Wl2_Event_Window_Pre_Visibility_Change ev = {
+    .win = 1,
+    .type = ECORE_WL2_WINDOW_VISIBILITY_TYPE_UNOBSCURED,
+  };
+
+  __ops.window.pre_visibility(ECORE_WL2_EVENT_WINDOW_PRE_VISIBILITY_CHANGE, &ev,
+      __user_data);
+}
+
+static void __generate_visibility_change_event(int fully_obscured) {
+  Ecore_Wl2_Event_Window_Visibility_Change ev = {
+    .win = 1,
+    .fully_obscured = fully_obscured
+  };
+
+  __ops.window.visibility(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE,
+      &ev, __user_data);
+}
+
+static void __fake_appcore_multiwindow_base_window_on_visibility(int type,
+    void* event) {
+  Ecore_Wl2_Event_Window_Visibility_Change* ev =
+      static_cast<Ecore_Wl2_Event_Window_Visibility_Change*>(event);
+
+  if (ev->fully_obscured)
+    appcore_multiwindow_base_instance_pause(nullptr);
+  else
+    appcore_multiwindow_base_instance_resume(nullptr);
+}
+
+static int __fake_aul_comp_notify_start(const char *id) {
+  return 0;
+}
+
+static int __fake_aul_comp_status_update(const char *id, int status) {
+  return 0;
+}
+
+static void __generate_system_event(void)
+{
+  char lang[] = "en-US";
+  int intval = 1;
+  void* event;
+
+  for (int i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) {
+    if (i == APPCORE_BASE_EVENT_LANG_CHANGE ||
+        i == APPCORE_BASE_EVENT_REGION_CHANGE) {
+      event = static_cast<void*>(lang);
+    } else {
+      event = static_cast<void*>(&intval);
+    }
+
+    if (__event_cb[i]) {
+      __event_cb[i](event, __event_data[i]);
+    }
+  }
+}
+
+static int __fake_appcore_multiwindow_base_init(
+    appcore_multiwindow_base_ops ops,
+    int argc,
+    char** argv,
+    void* user_data) {
+  __ops = ops;
+  __argc = argc;
+  __argv = argv;
+  __user_data = user_data;
+
+  __ops.base.init(__argc, __argv, __user_data);
+  __ops.base.create(__user_data);
+  __ops.base.run(__user_data);
+
+  bundle* b = bundle_create();
+  bundle_add_str(b, AUL_K_COMPONENT_ID, "base-frame");
+  bundle_add_str(b, AUL_K_INSTANCE_ID, "@base-frame");
+  bundle_add_str(b, AUL_K_NEW_INSTANCE, "true");
+  std::unique_ptr<bundle, decltype(bundle_free)*> ptr(b, bundle_free);
+
+  __ops.base.receive(AUL_START, b, __user_data);
+  __generate_system_event();
+
+  __ops.base.control(b, __user_data);
+  __generate_show_event();
+
+  __ops.base.receive(AUL_RESUME, b, __user_data);
+  __ops.base.receive(AUL_PAUSE, b, __user_data);
+
+  __generate_hide_event();
+  __generate_lower_event();
+  __generate_aux_message();
+
+  __ops.base.receive(AUL_WAKE, b, __user_data);
+  __ops.base.receive(AUL_SUSPEND, b, __user_data);
+
+  __ops.base.receive(AUL_TERMINATE_INST, b, __user_data);
+  __ops.base.receive(AUL_TERMINATE_BG_INST, b, __user_data);
+  __ops.base.receive(AUL_TERMINATE_BGAPP, b, __user_data);
+
+  return 0;
+}
+
+static void __fake_appcore_multiwindow_base_fini(void) {
+  __cls.terminate(nullptr, __cls.data);
+
+  __ops.base.terminate(__user_data);
+  __ops.base.finish();
+}
+
+static void __fake_appcore_multiwindow_base_exit(void) {
+  __ops.base.exit(__user_data);
+}
+
+static int __fake_elm_init(int argc, char** argv) {
+  return 0;
+}
+
+static int __fake_elm_shutdown(void) {
+  return 0;
+}
+
+static Evas_Object* __fake_elm_win_util_standard_add(const char* name,
+    const char* title) {
+  Evas_Object* win = reinterpret_cast<Evas_Object*>(malloc(sizeof(void*)));
+  return win;
+}
+
+static void __fake_evas_object_del(Evas_Object* object) {
+  free(object);
+}
+
+static void __fake_elm_config_accel_preference_set(const char* pref) {
+}
+
+static void __fake_ecore_wl2_window_activate(Ecore_Wl2_Window* window) {
+  __generate_pre_visibility_change_event();
+  __generate_visibility_change_event(0);
+}
+
+static void __fake_ecore_wl2_window_iconified_set(Ecore_Wl2_Window* window,
+                                                  Eina_Bool iconified) {
+  __generate_visibility_change_event(1);
+}
+
+static int __fake_aul_app_group_lower_v2(const char* id, bool* exit) {
+  *exit = true;
+  return 0;
+}
+
+static int __fake_aul_app_group_set_window_v2(const char* id, int wid) {
+  return 0;
+}
+
+static Ecore_Wl2_Window* __fake_ecore_wl2_display_window_find(
+    Ecore_Wl2_Display* display, unsigned int id) {
+  static int window;
+  return reinterpret_cast<Ecore_Wl2_Window*>(&window);
+}
+
+static void __fake_appcore_multiwindow_base_class_add(
+    appcore_multiwindow_base_class cls) {
+  __cls = cls;
+}
+
+static appcore_multiwindow_base_instance_h
+__fake_appcore_multiwindow_base_instance_run(const char* class_id,
+    const char* id, void* extra)
+{
+  static appcore_multiwindow_base_instance_h inst =
+      reinterpret_cast<appcore_multiwindow_base_instance_h>(&inst);
+  __cls.create(inst, __cls.data);
+
+  return inst;
+}
+
+static const char* __fake_appcore_multiwindow_base_instance_get_id(
+    appcore_multiwindow_base_instance_h context) {
+  return "@base-frame";
+}
+
+static bool __fake_appcore_multiwindow_base_instance_is_resumed(
+    appcore_multiwindow_base_instance_h context) {
+  return __is_resumed;
+}
+
+static void __fake_appcore_multiwindow_base_instance_resume(
+    appcore_multiwindow_base_instance_h context) {
+  if (__is_resumed)
+    return;
+
+  __cls.resume(context, __cls.data);
+  __is_resumed = true;
+}
+
+static void __fake_appcore_multiwindow_base_instance_pause(
+    appcore_multiwindow_base_instance_h context) {
+  if (!__is_resumed)
+    return;
+
+  __cls.pause(context, __cls.data);
+  __is_resumed = false;
+}
+
+appcore_multiwindow_base_instance_h __fake_appcore_multiwindow_base_instance_find(const char* id)
+{
+  typedef struct _appcore_multiwindow_base_instance {
+    unsigned int window_id;
+    char *id;
+    void *extra;
+    appcore_multiwindow_base_class *shell;
+    bool is_resumed;
+  } appcore_multiwindow_base_instance;
+
+  appcore_multiwindow_base_instance *s =
+    (appcore_multiwindow_base_instance*)malloc(sizeof(appcore_multiwindow_base_instance));
+  return s;
+}
+
+static appcore_base_event_h __fake_appcore_base_add_event(
+    enum appcore_base_event type, appcore_base_event_cb cb, void* data) {
+  __event_cb[type] = cb;
+  __event_data[type] = data;
+  return nullptr;
+}
+
+static Ecore_Evas* __fake_ecore_evas_ecore_evas_get(const Evas* evas) {
+  static int ecore_evas;
+  return reinterpret_cast<Ecore_Evas*>(&ecore_evas);
+}
+
+static Evas* __fake_evas_object_evas_get(const Eo* eo) {
+  static int evas;
+  return reinterpret_cast<Evas*>(&evas);
+}
+
+static Ecore_Wl2_Window* __fake_ecore_evas_wayland2_window_get(
+    const Ecore_Evas* ee) {
+  static int wl2_window;
+  return reinterpret_cast<Ecore_Wl2_Window*>(&wl2_window);
+}
+
+static int __fake_ecore_wl2_window_id_get(Ecore_Wl2_Window* window) {
+  return 1;
+}
+
+static int __fake_app_get_display_state(app_display_state_e *state) {
+  *state = APP_DISPLAY_STATE_ON;
+  return 0;
+}
+
+static int __fake_app_control_add_action_handler(const char* action,
+    app_control_action_cb callback, void* user_data,
+    app_control_action_h* handle) {
+  callback(action, nullptr, user_data);
+  return 0;
+}
+
+class BaseStubTest : public ::testing::Test {
+ public:
+  virtual void SetUp() {
+    appcore_multiwindow_base_init_fake.custom_fake =
+        __fake_appcore_multiwindow_base_init;
+    appcore_multiwindow_base_fini_fake.custom_fake =
+        __fake_appcore_multiwindow_base_fini;
+    appcore_multiwindow_base_exit_fake.custom_fake =
+        __fake_appcore_multiwindow_base_exit;
+    appcore_multiwindow_base_instance_run_fake.custom_fake =
+        __fake_appcore_multiwindow_base_instance_run;
+    appcore_multiwindow_base_class_add_fake.custom_fake =
+        __fake_appcore_multiwindow_base_class_add;
+    appcore_multiwindow_base_instance_get_id_fake.custom_fake =
+        __fake_appcore_multiwindow_base_instance_get_id;
+    appcore_multiwindow_base_instance_is_resumed_fake.custom_fake =
+        __fake_appcore_multiwindow_base_instance_is_resumed;
+    appcore_multiwindow_base_instance_resume_fake.custom_fake =
+        __fake_appcore_multiwindow_base_instance_resume;
+    appcore_multiwindow_base_instance_pause_fake.custom_fake =
+        __fake_appcore_multiwindow_base_instance_pause;
+    appcore_multiwindow_base_window_on_visibility_fake.custom_fake =
+        __fake_appcore_multiwindow_base_window_on_visibility;
+    appcore_multiwindow_base_instance_find_fake.custom_fake =
+        __fake_appcore_multiwindow_base_instance_find;
+    appcore_base_add_event_fake.custom_fake =
+        __fake_appcore_base_add_event;
+
+    elm_init_fake.custom_fake =
+        __fake_elm_init;
+    elm_shutdown_fake.custom_fake =
+        __fake_elm_shutdown;
+    elm_win_util_standard_add_fake.custom_fake =
+        __fake_elm_win_util_standard_add;
+    evas_object_del_fake.custom_fake =
+        __fake_evas_object_del;
+    elm_config_accel_preference_set_fake.custom_fake =
+        __fake_elm_config_accel_preference_set;
+    ecore_wl2_window_activate_fake.custom_fake =
+        __fake_ecore_wl2_window_activate;
+    ecore_wl2_window_iconified_set_fake.custom_fake =
+        __fake_ecore_wl2_window_iconified_set;
+    ecore_wl2_display_window_find_fake.custom_fake =
+        __fake_ecore_wl2_display_window_find;
+    ecore_evas_ecore_evas_get_fake.custom_fake =
+        __fake_ecore_evas_ecore_evas_get;
+    evas_object_evas_get_fake.custom_fake =
+        __fake_evas_object_evas_get;
+    ecore_evas_wayland2_window_get_fake.custom_fake =
+        __fake_ecore_evas_wayland2_window_get;
+    ecore_wl2_window_id_get_fake.custom_fake =
+        __fake_ecore_wl2_window_id_get;
+
+    aul_app_group_set_window_v2_fake.custom_fake =
+        __fake_aul_app_group_set_window_v2;
+    aul_app_group_lower_v2_fake.custom_fake =
+        __fake_aul_app_group_lower_v2;
+    aul_comp_notify_start_fake.custom_fake =
+        __fake_aul_comp_notify_start;
+    aul_comp_status_update_fake.custom_fake =
+        __fake_aul_comp_status_update;
+
+    app_get_display_state_fake.custom_fake =
+        __fake_app_get_display_state;
+
+    app_control_add_action_handler_fake.custom_fake =
+        __fake_app_control_add_action_handler;
+  }
+
+  virtual void TearDown(){
+  }
+};
+
+
+static frame_window_h __base_frame_component_create_cb(
+               component_h context,
+               void *user_data)
+{
+  frame_window_h frm_win = NULL;
+       Evas_Object* raw = elm_win_util_standard_add("frame", "frame");
+       int wid = 1;
+  base_frame_create_window(&frm_win, wid, (void*)raw);
+       return frm_win;
+}
+
+static void __base_frame_component_start_cb(
+               component_h context,
+               app_control_h app_control,
+               bool restarted,
+               void *user_data)
+{
+  component_register_action(context, "action");
+}
+
+static void __base_frame_component_resume_cb(
+               component_h context,
+               void *user_data)
+{
+  component_display_status_e display_status;
+  base_frame_get_display_status(context, &display_status);
+}
+
+static void __base_frame_component_pause_cb(
+               component_h context,
+               void *user_data)
+{
+}
+
+static void __base_frame_component_stop_cb(
+               component_h context,
+               void *user_data)
+{
+}
+
+static void __base_frame_component_destroy_cb(
+               component_h context,
+               void *user_data)
+{
+}
+
+static void __base_frame_component_restore_content_cb(
+               component_h context,
+               bundle *content,
+               void *user_data)
+{
+}
+
+static void __base_frame_component_save_content_cb(
+               component_h context,
+               bundle *content,
+               void *user_data)
+{
+}
+
+static void __base_frame_component_action_cb(component_h context,
+               const char *action, app_control_h app_control,
+               void *user_data)
+{
+}
+
+static void __base_frame_component_device_orientation_changed_cb(
+               component_h context,
+               component_device_orientation_e orientation,
+               void *user_data)
+{
+}
+
+static void __base_frame_component_language_changed_cb(
+               component_h context,
+               const char *language,
+               void *user_data)
+{
+}
+
+static void __base_frame_component_region_format_changed_cb(
+               component_h context,
+               const char *region,
+               void *user_data)
+{
+}
+
+static void __base_frame_component_low_battery_cb(
+               component_h context,
+               component_low_battery_status_e status,
+               void *user_data)
+{
+}
+
+static void __base_frame_component_low_memory_cb(
+               component_h context,
+               component_low_memory_status_e status,
+               void *user_data)
+{
+}
+
+static void __base_frame_component_suspended_state_changed_cb(
+               component_h context,
+               component_suspended_state_e state,
+               void *user_data)
+{
+}
+
+component_class_h base_frame_component_add(component_class_h comp_class,
+               const char *component_id, void *user_data)
+{
+       base_frame_component_lifecycle_callback_s callback = {
+               .create = __base_frame_component_create_cb,
+               .start = __base_frame_component_start_cb,
+               .resume = __base_frame_component_resume_cb,
+               .pause = __base_frame_component_pause_cb,
+               .stop = __base_frame_component_stop_cb,
+               .destroy = __base_frame_component_destroy_cb,
+               .restore_content = __base_frame_component_restore_content_cb,
+               .save_content = __base_frame_component_save_content_cb,
+               .action = __base_frame_component_action_cb,
+               .device_orientation_changed = __base_frame_component_device_orientation_changed_cb,
+               .language_changed = __base_frame_component_language_changed_cb,
+               .region_format_changed = __base_frame_component_region_format_changed_cb,
+               .low_battery = __base_frame_component_low_battery_cb,
+               .low_memory = __base_frame_component_low_memory_cb,
+               .suspended_state_changed = __base_frame_component_suspended_state_changed_cb,
+       };
+
+       return component_based_app_base_add_frame_component(comp_class,
+                       component_id, &callback, user_data);
+}
+
+TEST_F(BaseStubTest, base_frame_create_window)
+{
+  frame_window_h handle;
+  int ret = base_frame_create_window(
+      &handle, 1, nullptr);
+  EXPECT_EQ(COMPONENT_ERROR_NONE, ret);
+}
+
+TEST_F(BaseStubTest, base_frame_window_get_id)
+{
+  frame_window_h handle;
+  int ret = base_frame_create_window(
+      &handle, 1, nullptr);
+  EXPECT_EQ(COMPONENT_ERROR_NONE, ret);
+
+  int id;
+  ret = base_frame_window_get_id(handle, &id);
+  EXPECT_EQ(COMPONENT_ERROR_NONE, ret);
+  EXPECT_EQ(id, 1);
+}
+
+TEST_F(BaseStubTest, base_frame_window_get_raw)
+{
+  frame_window_h handle;
+  char* test = strdup("raw");
+  int ret = base_frame_create_window(
+      &handle, 1, (void *)test);
+  EXPECT_EQ(COMPONENT_ERROR_NONE, ret);
+
+  void* raw;
+  ret = base_frame_window_get_raw(handle, &raw);
+  EXPECT_EQ(COMPONENT_ERROR_NONE, ret);
+  free(test);
+}
+
+void __app_init_cb(int argc, char** argv, void *user_data)
+{
+}
+
+void __app_fini_cb(void *user_data)
+{
+}
+
+void __app_run_cb(void *user_data)
+{
+}
+
+void __app_exit_cb(void *user_data)
+{
+}
+
+component_class_h __app_create_cb(void *user_data)
+{
+       component_class_h comp_class = NULL;
+       comp_class = base_frame_component_add(comp_class,
+                       "base-frame", NULL);
+
+       return comp_class;
+}
+
+void __app_terminate_cb(void *user_data)
+{
+}
+
+TEST_F(BaseStubTest, component_based_app_base_main)
+{
+  component_based_app_base_lifecycle_callback_s callback = {
+               .init = __app_init_cb,
+               .fini = __app_fini_cb,
+               .run = __app_run_cb,
+               .exit = __app_exit_cb,
+               .create = __app_create_cb,
+               .terminate = __app_terminate_cb
+       };
+  int argc = 1;
+  char tmp_arg[] = "test";
+  char** argv = reinterpret_cast<char**>(&tmp_arg);
+
+  int ret = component_based_app_base_main(argc, argv, &callback, this);
+  EXPECT_EQ(COMPONENT_ERROR_NONE, ret);
+}
+
+}
\ No newline at end of file
diff --git a/unit_tests/src/base/test_base_service_stub.cc b/unit_tests/src/base/test_base_service_stub.cc
new file mode 100644 (file)
index 0000000..92b533a
--- /dev/null
@@ -0,0 +1,383 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * 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 <stdlib.h>
+#include <gtest/gtest.h>
+
+#include <iostream>
+#include <memory>
+
+#include "component_based/base/api/component_based_app_base.h"
+#include "component_based/base/api/base_service_component.h"
+
+#include "unit_tests/mock/mock_app_common.h"
+#include "unit_tests/mock/mock_app_control.h"
+#include "unit_tests/mock/mock_appcore_multiwindow_base.h"
+#include "unit_tests/mock/mock_aul.h"
+#include "unit_tests/mock/mock_elementary.h"
+
+namespace {
+
+static appcore_multiwindow_base_ops __ops;
+static int __argc;
+static char** __argv;
+static void* __user_data;
+static appcore_multiwindow_base_class __cls;
+static appcore_base_event_cb __event_cb[APPCORE_BASE_EVENT_MAX];
+static void* __event_data[APPCORE_BASE_EVENT_MAX];
+
+static int __fake_aul_comp_notify_start(const char *id) {
+  return 0;
+}
+
+static int __fake_aul_comp_status_update(const char *id, int status) {
+  return 0;
+}
+
+static void __generate_system_event(void)
+{
+  char lang[] = "en-US";
+  int intval = 1;
+  void* event;
+
+  for (int i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) {
+    if (i == APPCORE_BASE_EVENT_LANG_CHANGE ||
+        i == APPCORE_BASE_EVENT_REGION_CHANGE) {
+      event = static_cast<void*>(lang);
+    } else {
+      event = static_cast<void*>(&intval);
+    }
+
+    if (__event_cb[i]) {
+      __event_cb[i](event, __event_data[i]);
+    }
+  }
+}
+
+static int __fake_appcore_multiwindow_base_init(
+    appcore_multiwindow_base_ops ops,
+    int argc,
+    char** argv,
+    void* user_data) {
+  __ops = ops;
+  __argc = argc;
+  __argv = argv;
+  __user_data = user_data;
+
+  __ops.base.init(__argc, __argv, __user_data);
+  __ops.base.create(__user_data);
+  __ops.base.run(__user_data);
+
+  bundle* b = bundle_create();
+  bundle_add_str(b, AUL_K_COMPONENT_ID, "test-service-base");
+  bundle_add_str(b, AUL_K_INSTANCE_ID, "@test-service-base");
+  bundle_add_str(b, AUL_K_NEW_INSTANCE, "true");
+  std::unique_ptr<bundle, decltype(bundle_free)*> ptr(b, bundle_free);
+
+  __ops.base.receive(AUL_START, b, __user_data);
+
+  __generate_system_event();
+
+  __ops.base.control(b, __user_data);
+
+  __ops.base.receive(AUL_RESUME, b, __user_data);
+  __ops.base.receive(AUL_PAUSE, b, __user_data);
+
+  __ops.base.receive(AUL_WAKE, b, __user_data);
+  __ops.base.receive(AUL_SUSPEND, b, __user_data);
+
+  __ops.base.receive(AUL_TERMINATE_INST, b, __user_data);
+  __ops.base.receive(AUL_TERMINATE_BG_INST, b, __user_data);
+  __ops.base.receive(AUL_TERMINATE_BGAPP, b, __user_data);
+
+  return 0;
+}
+
+static void __fake_appcore_multiwindow_base_fini(void) {
+  __cls.terminate(nullptr, __cls.data);
+
+  __ops.base.terminate(__user_data);
+  __ops.base.finish();
+}
+
+static void __fake_appcore_multiwindow_base_exit(void) {
+  __ops.base.exit(__user_data);
+}
+
+static int __fake_elm_init(int argc, char** argv) {
+  return 0;
+}
+
+static int __fake_elm_shutdown(void) {
+  return 0;
+}
+
+static void __fake_appcore_multiwindow_base_class_add(
+    appcore_multiwindow_base_class cls) {
+  __cls = cls;
+}
+
+static appcore_multiwindow_base_instance_h
+__fake_appcore_multiwindow_base_instance_run(const char* class_id,
+    const char* id, void* extra)
+{
+  static appcore_multiwindow_base_instance_h inst =
+      reinterpret_cast<appcore_multiwindow_base_instance_h>(&inst);
+
+  __cls.create(inst, __cls.data);
+
+  return inst;
+}
+
+static const char* __fake_appcore_multiwindow_base_instance_get_id(
+    appcore_multiwindow_base_instance_h context) {
+  return "@test-service-base";
+}
+
+static appcore_base_event_h __fake_appcore_base_add_event(
+    enum appcore_base_event type, appcore_base_event_cb cb, void* data) {
+  __event_cb[type] = cb;
+  __event_data[type] = data;
+  return nullptr;
+}
+
+static int __fake_app_control_add_action_handler(const char* action,
+    app_control_action_cb callback, void* user_data,
+    app_control_action_h* handle) {
+  callback(action, nullptr, user_data);
+  return 0;
+}
+
+static int __fake_app_control_send_launch_request_async(
+    app_control_h app_control,
+    app_control_result_cb result_cb,
+    app_control_reply_cb reply_cb,
+    void* user_data) {
+  result_cb(app_control, APP_CONTROL_ERROR_NONE, user_data);
+  reply_cb(app_control, app_control, APP_CONTROL_RESULT_SUCCEEDED, user_data);
+  return 0;
+}
+
+static int __fake_app_control_send_launch_request_sync(
+    app_control_h app_control,
+    app_control_h* reply,
+    app_control_result_e* result) {
+  app_control_h handle = nullptr;
+  app_control_create(&handle);
+  *reply = handle;
+  *result = APP_CONTROL_RESULT_SUCCEEDED;
+  return 0;
+}
+
+class BaseServiceStubTest : public ::testing::Test {
+ public:
+  virtual void SetUp() {
+    appcore_multiwindow_base_init_fake.custom_fake =
+        __fake_appcore_multiwindow_base_init;
+    appcore_multiwindow_base_fini_fake.custom_fake =
+        __fake_appcore_multiwindow_base_fini;
+    appcore_multiwindow_base_exit_fake.custom_fake =
+        __fake_appcore_multiwindow_base_exit;
+    appcore_multiwindow_base_instance_run_fake.custom_fake =
+        __fake_appcore_multiwindow_base_instance_run;
+    appcore_multiwindow_base_class_add_fake.custom_fake =
+        __fake_appcore_multiwindow_base_class_add;
+    appcore_multiwindow_base_instance_get_id_fake.custom_fake =
+        __fake_appcore_multiwindow_base_instance_get_id;
+    appcore_base_add_event_fake.custom_fake =
+        __fake_appcore_base_add_event;
+
+    elm_init_fake.custom_fake =
+        __fake_elm_init;
+    elm_shutdown_fake.custom_fake =
+        __fake_elm_shutdown;
+    aul_comp_notify_start_fake.custom_fake =
+        __fake_aul_comp_notify_start;
+    aul_comp_status_update_fake.custom_fake =
+        __fake_aul_comp_status_update;
+    app_control_add_action_handler_fake.custom_fake =
+        __fake_app_control_add_action_handler;
+    app_control_send_launch_request_async_fake.custom_fake =
+        __fake_app_control_send_launch_request_async;
+    app_control_send_launch_request_sync_fake.custom_fake =
+        __fake_app_control_send_launch_request_sync;
+  }
+
+  virtual void TearDown(){
+  }
+};
+
+static void __app_control_result_cb(app_control_h request,
+    app_control_error_e result, void* user_data) {
+}
+
+static void __app_control_reply_cb(app_control_h request,
+    app_control_h reply, app_control_result_e result, void* user_data) {
+}
+
+static bool __service_component_create_cb(component_h context,
+    void* user_data) {
+  char* id = nullptr;
+  component_get_id(context, &id);
+  free(id);
+
+  char* inst_id = nullptr;
+  component_get_instance_id(context, &inst_id);
+  free(inst_id);
+  return true;
+}
+
+static void __service_component_start_command_cb(component_h context,
+    app_control_h app_control, bool restarted, void* user_data) {
+  component_register_action(context, "action");
+  component_deregister_action(context, "action");
+
+  app_control_h handle = nullptr;
+  app_control_create(&handle);
+  component_send_launch_request_async(context, handle, __app_control_result_cb,
+      __app_control_reply_cb, nullptr);
+
+  app_control_h reply = nullptr;
+  app_control_result_e result;
+  component_send_launch_request_sync(context, handle, &reply, &result);
+  app_control_destroy(reply);
+  app_control_destroy(handle);
+
+  component_finish(context);
+}
+
+static void __service_component_destroy_cb(component_h context,
+    void *user_data) {
+}
+
+static void __service_component_restore_content_cb(component_h context,
+    bundle* content, void* user_data) {
+}
+
+static void __service_component_save_content_cb(component_h context,
+    bundle* content, void* user_data) {
+}
+
+static void __service_component_action_cb(component_h context,
+    const char* action, app_control_h app_control, void* user_data) {
+}
+
+static void __service_component_device_orientation_changed_cb(
+    component_h context, component_device_orientation_e orientation,
+    void* user_data) {
+}
+
+static void __service_component_language_changed_cb(component_h context,
+    const char* language, void* user_data) {
+}
+
+static void __service_component_region_format_changed_cb(component_h context,
+    const char* region, void* user_data) {
+}
+
+static void __service_component_low_battery_cb(component_h context,
+    component_low_battery_status_e status, void* user_data) {
+}
+
+static void __service_component_low_memory_cb(component_h context,
+    component_low_memory_status_e status, void* user_data) {
+}
+
+static void __service_component_suspended_state_changed_cb(component_h context,
+    component_suspended_state_e state, void* user_data) {
+}
+
+static component_class_h __service_component_add(
+    component_class_h component_class, const char* component_id,
+    void* user_data) {
+  base_service_component_lifecycle_callback_s callback;
+  callback.create =
+      __service_component_create_cb;
+  callback.start_command =
+      __service_component_start_command_cb;
+  callback.destroy =
+      __service_component_destroy_cb;
+  callback.restore_content =
+      __service_component_restore_content_cb;
+  callback.save_content =
+      __service_component_save_content_cb;
+  callback.action =
+      __service_component_action_cb;
+  callback.device_orientation_changed =
+      __service_component_device_orientation_changed_cb;
+  callback.language_changed =
+      __service_component_language_changed_cb;
+  callback.region_format_changed =
+      __service_component_region_format_changed_cb;
+  callback.low_battery =
+      __service_component_low_battery_cb;
+  callback.low_memory =
+      __service_component_low_memory_cb;
+  callback.suspended_state_changed =
+      __service_component_suspended_state_changed_cb;
+
+  return component_based_app_base_add_service_component(component_class,
+      component_id, &callback, user_data);
+}
+
+void __app_init_cb(int argc, char** argv, void *user_data)
+{
+}
+
+void __app_fini_cb(void *user_data)
+{
+}
+
+void __app_run_cb(void *user_data)
+{
+}
+
+void __app_exit_cb(void *user_data)
+{
+}
+
+component_class_h __app_create_cb(void *user_data)
+{
+       component_class_h comp_class = NULL;
+       comp_class = __service_component_add(comp_class,
+                       "test-service-base", NULL);
+
+       return comp_class;
+}
+
+void __app_terminate_cb(void *user_data)
+{
+}
+
+TEST_F(BaseServiceStubTest, component_based_app_base_add_service_component)
+{
+  component_based_app_base_lifecycle_callback_s callback = {
+               .init = __app_init_cb,
+               .fini = __app_fini_cb,
+               .run = __app_run_cb,
+               .exit = __app_exit_cb,
+               .create = __app_create_cb,
+               .terminate = __app_terminate_cb
+       };
+  int argc = 1;
+  char tmp_arg[] = "test";
+  char** argv = reinterpret_cast<char**>(&tmp_arg);
+
+  int ret = component_based_app_base_main(argc, argv, &callback, this);
+  EXPECT_EQ(COMPONENT_ERROR_NONE, ret);
+}
+
+}
\ No newline at end of file