Refactor widget-viewer 60/232260/4
authorJunghoon Park <jh9216.park@samsung.com>
Wed, 29 Apr 2020 09:24:08 +0000 (18:24 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Wed, 13 May 2020 08:13:47 +0000 (17:13 +0900)
 - Use mockup package
 - Add unittests
 - require:
   https://review.tizen.org/gerrit/#/c/platform/core/appfw/screen-connector/+/232184/

Change-Id: I52718759b3835d641104ff8aaa33b5532af6a507
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
ambient-viewer/src/stub.cc
packaging/libwidget_viewer.spec
unittest/CMakeLists.txt
unittest/mock/mock.cc
unittest/mock/screen_connector_mock.h [deleted file]
unittest/src/test_ambient_viewer.cc
unittest/src/test_ambient_viewer_stub.cc
unittest/src/test_viewer_evas.cc [deleted file]
watch-holder/src/watch.hh

index e2ec33f..d8eb136 100644 (file)
@@ -148,24 +148,6 @@ class AmbientViewerStub : public AmbientViewer {
   bool mock_ = false;
 };
 
-extern "C" int ambient_viewer_create_mock(Evas_Object *win,
-    ambient_viewer_h *handle) {
-  if (win == nullptr || handle == nullptr) {
-    LOGE("Invalid parameter");
-    return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
-  }
-
-  AmbientViewerStub* h = new (nothrow) AmbientViewerStub(win, true);
-  if (h == nullptr) {
-    LOGE("out of memory");
-    return AMBIENT_VIEWER_ERROR_OUT_OF_MEMORY;
-  }
-
-  *handle = static_cast<ambient_viewer_h>(h);
-
-  return AMBIENT_VIEWER_ERROR_NONE;
-}
-
 extern "C" EXPORT_API int ambient_viewer_create(Evas_Object *win,
     ambient_viewer_h *handle) {
   if (win == nullptr || handle == nullptr) {
index 63340ad..2bbcc0b 100644 (file)
@@ -42,6 +42,7 @@ BuildRequires: pkgconfig(gmock)
 BuildRequires: pkgconfig(screen_connector_launcher_service)
 BuildRequires: pkgconfig(screen_connector_shared_widget_launch)
 BuildRequires: pkgconfig(libsmack)
+BuildRequires: pkgconfig(screen_connector_remote_surface_evas_mock)
 %if 0%{?gcov:1}
 BuildRequires:  lcov
 BuildRequires:  zip
index a35ffac..b85622e 100644 (file)
@@ -16,8 +16,6 @@ pkg_check_modules(widget-viewer_unittests REQUIRED
     capi-system-info
     capi-appfw-application
     cynara-client
-    screen_connector_watcher_evas
-    screen_connector_remote_surface_evas
     appcore-efl
     ecore
     edje
@@ -26,6 +24,7 @@ pkg_check_modules(widget-viewer_unittests REQUIRED
     efl-extension
     appsvc
     ecore-wl2
+    screen_connector_remote_surface_evas_mock
 )
 
 FOREACH(flag ${widget-viewer_unittests_CFLAGS})
@@ -38,12 +37,10 @@ SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
 SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
 
 ADD_DEFINITIONS("-DPKGNAME=\"org.tizen.widget_unittest\"")
-ADD_DEFINITIONS("-DWIDGET_VIEWER_EVAS_RESOURCE_PO=\"/tmp\"")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
 SET(CMAKE_C_FLAGS_RELEASE "-O2")
 
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../widget_viewer_evas/include)
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../ambient-viewer/src)
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../ambient-viewer/include)
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../watch-holder/src)
@@ -52,24 +49,17 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../)
 
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock UNIT_TEST_SOURCES)
 AUX_SOURCE_DIRECTORY(src SOURCES)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../widget_viewer_evas/src WIDGET_VIEWER_EVAS_SOURCES)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../ambient-viewer/src AMBIENT_VIEWER_SOURCES)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../watch-holder/src WATCH_HOLDER_SOURCES)
 ADD_EXECUTABLE(${PROJECT_NAME}
     ${SOURCES}
-    ${WIDGET_VIEWER_EVAS_SOURCES}
     ${UNIT_TEST_SOURCES}
     ${AMBIENT_VIEWER_SOURCES}
     ${WATCH_HOLDER_SOURCES}
 )
 
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${widget-viewer_unittests_LDFLAGS}
-    ${pkgs_LDFLAGS}
-    ${pkgs_LIBRARIES}
     gmock
-    widget_viewer_evas
-    ambient-viewer
-    watch-holder
 )
 
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/)
index 978c950..7c19be6 100644 (file)
@@ -11,7 +11,6 @@
 #include "aul_mock.h"
 #include "appsvc_mock.h"
 #include "widget_service_mock.h"
-#include "screen_connector_mock.h"
 #include "vconf_mock.h"
 
 DEFINE_FFF_GLOBALS;
@@ -93,10 +92,6 @@ DEFINE_FAKE_VALUE_FUNC(int, appsvc_run_service, bundle*, int, appsvc_res_fn, voi
 DEFINE_FAKE_VALUE_FUNC(int, widget_service_get_widget_max_count, const char *);
 DEFINE_FAKE_VALUE_FUNC(int, widget_instance_create, const char *, char **);
 
-/* screen_connector */
-DEFINE_FAKE_VALUE_FUNC(int, screen_connector_toolkit_evas_init,
-        Evas_Object *, screen_connector_screen_type_e);
-
 /* vconf */
 DEFINE_FAKE_VALUE_FUNC(char *, vconf_get_str, const char *);
 DEFINE_FAKE_VALUE_FUNC(int, vconf_notify_key_changed, const char *,
diff --git a/unittest/mock/screen_connector_mock.h b/unittest/mock/screen_connector_mock.h
deleted file mode 100644 (file)
index ce2c482..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.
- */
-
-#ifndef MOCK_SCREEN_CONNECTOR_H_
-#define MOCK_SCREEN_CONNECTOR_H_
-
-#include <screen_connector_toolkit_evas.h>
-#include "mock.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-DECLARE_FAKE_VALUE_FUNC(int, screen_connector_toolkit_evas_init,
-        Evas_Object *, screen_connector_screen_type_e);
-
-#ifdef __cplusplus
-}
-#endif
-#endif  /* MOCK_SCREEN_CONNECTOR_H_ */
index ce9516d..f184477 100644 (file)
@@ -238,8 +238,7 @@ class AmbientViewerTest : public ::testing::Test {
     tbm_surface_map_fake.custom_fake = __tbm_surface_map;
     tbm_surface_unmap_fake.custom_fake = __tbm_surface_unmap;
 
-    Evas_Object* win = elm_win_add(NULL, "Widget Viewer", ELM_WIN_BASIC);
-    stub = new AmbientViewerStub(win);
+    stub = new AmbientViewerStub(reinterpret_cast<Evas_Object*>(&__not_null));
   }
   virtual void TearDown() {
     delete stub;
index 9f16c28..f93e6fa 100644 (file)
@@ -21,8 +21,6 @@
 #include "ambient-viewer/include/ambient_viewer.h"
 #include "ambient-viewer/include/ambient_viewer_common.h"
 
-extern "C" int ambient_viewer_create_mock(Evas_Object *win,
-    ambient_viewer_h *handle);
 extern "C" int ambient_viewer_monitor_full(ambient_viewer_h handle,
     ambient_viewer_lifecycle_s lifecycle, void *user_data);
 
@@ -81,6 +79,32 @@ TEST_F(AmbientViewerStubTest, ambient_viewer_block_update_n) {
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
 
+TEST_F(AmbientViewerStubTest, ambient_viewer_block_update1) {
+  ambient_viewer_h handle = nullptr;
+  ASSERT_EQ(ambient_viewer_create(reinterpret_cast<Evas_Object*>(&__not_null),
+    &handle), AMBIENT_VIEWER_ERROR_NONE);
+  ASSERT_NE(handle, nullptr);
+
+  EXPECT_EQ(ambient_viewer_block_update(handle, true),
+      AMBIENT_VIEWER_ERROR_NONE);
+
+  ASSERT_EQ(ambient_viewer_destroy(handle),
+      AMBIENT_VIEWER_ERROR_NONE);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_block_update2) {
+  ambient_viewer_h handle = nullptr;
+  ASSERT_EQ(ambient_viewer_create(reinterpret_cast<Evas_Object*>(&__not_null),
+    &handle), AMBIENT_VIEWER_ERROR_NONE);
+  ASSERT_NE(handle, nullptr);
+
+  EXPECT_EQ(ambient_viewer_block_update(handle, false),
+      AMBIENT_VIEWER_ERROR_NONE);
+
+  ASSERT_EQ(ambient_viewer_destroy(handle),
+      AMBIENT_VIEWER_ERROR_NONE);
+}
+
 TEST_F(AmbientViewerStubTest, ambient_viewer_monitor_n) {
   ambient_viewer_lifecycle_s lifecycle;
   EXPECT_EQ(ambient_viewer_monitor(nullptr, lifecycle, nullptr),
@@ -138,7 +162,7 @@ TEST_F(AmbientViewerStubTest, ambient_viewer_get_watch_surface_n) {
 TEST_F(AmbientViewerStubTest, ambient_viewer_get_watch_surface_n2) {
   ambient_viewer_h handle = nullptr;
   ambient_viewer_surface_h surface = nullptr;
-  ASSERT_EQ(ambient_viewer_create_mock(reinterpret_cast<Evas_Object*>(&__not_null),
+  ASSERT_EQ(ambient_viewer_create(reinterpret_cast<Evas_Object*>(&__not_null),
     &handle), AMBIENT_VIEWER_ERROR_NONE);
   ASSERT_NE(handle, nullptr);
 
@@ -157,7 +181,7 @@ TEST_F(AmbientViewerStubTest, ambient_viewer_get_top_app_surface_n) {
 TEST_F(AmbientViewerStubTest, ambient_viewer_get_top_app_surface) {
   ambient_viewer_h handle = nullptr;
   ambient_viewer_surface_h surface = nullptr;
-  ASSERT_EQ(ambient_viewer_create_mock(reinterpret_cast<Evas_Object*>(&__not_null),
+  ASSERT_EQ(ambient_viewer_create(reinterpret_cast<Evas_Object*>(&__not_null),
     &handle), AMBIENT_VIEWER_ERROR_NONE);
   ASSERT_NE(handle, nullptr);
   ambient_viewer_lifecycle_s lifecycle = { 0, };
@@ -177,7 +201,7 @@ TEST_F(AmbientViewerStubTest, ambient_viewer_get_top_app_surface) {
 class AmbientViewerStubSurfaceTest : public ::testing::Test {
  public:
   virtual void SetUp() {
-    ASSERT_EQ(ambient_viewer_create_mock(reinterpret_cast<Evas_Object*>(
+    ASSERT_EQ(ambient_viewer_create(reinterpret_cast<Evas_Object*>(
       &__not_null), &handle_), AMBIENT_VIEWER_ERROR_NONE);
     ASSERT_NE(handle_, nullptr);
     ambient_viewer_lifecycle_s lifecycle = { 0, };
diff --git a/unittest/src/test_viewer_evas.cc b/unittest/src/test_viewer_evas.cc
deleted file mode 100644 (file)
index f82ef63..0000000
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * 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 <glib.h>
-#include <gtest/gtest.h>
-#include <gmock/gmock.h>
-#include <widget_viewer_evas.h>
-#include <widget_viewer_evas_extension.h>
-#include <widget_errno.h>
-
-#include "unittest/mock/gio/gio.h"
-#include "unittest/mock/cynara_mock.h"
-#include "unittest/mock/evas_mock.h"
-#include "unittest/mock/system_info_mock.h"
-#include "unittest/mock/aul_mock.h"
-#include "unittest/mock/widget_service_mock.h"
-#include "unittest/mock/screen_connector_mock.h"
-
-int __fake_system_info_get_platform_bool(const char* key, bool* value) {
-  *value = true;
-  return 0;
-}
-
-int __cynara_check(cynara* c, const char* client, const char* client_session,
-    const char* user,
-    const char* privilege) {
-  return CYNARA_API_ACCESS_ALLOWED;
-}
-
-Evas_Object* __elm_win_add(Evas_Object* parent, const char *name,
-    Elm_Win_Type type) {
-  return (Evas_Object*)g_hash_table_new_full(
-      g_str_hash, g_str_equal, free, nullptr);
-}
-
-int __aul_app_get_appid_bypid(int pid, char *appid, int len) {
-  snprintf(appid, len, "%s", "org.tizen.test");
-  return 0;
-}
-
-int __widget_service_get_widget_max_count(const char *widget_id) {
-  return 5;
-}
-
-int __widget_instance_create(const char *widget_id, char **instance_id) {
-  *instance_id = strdup("test@org.tizen.test");
-  return 0;
-}
-
-Eina_Bool __elm_layout_file_set(Eo *obj, const char *file, const char *group) {
-  return EINA_TRUE;
-}
-
-void *__evas_object_data_get(const Evas_Object *eo_obj, const char *key) {
-  GHashTable* tbl = (GHashTable*)eo_obj;
-  return g_hash_table_lookup(tbl, key);
-}
-
-void __evas_object_data_set(Evas_Object *eo_obj, const char *key,
-    const void *data) {
-  GHashTable* tbl = (GHashTable*)eo_obj;
-  g_hash_table_insert(tbl, strdup(key), (gpointer)data);
-}
-
-void __evas_object_event_callback_add(Evas_Object *eo_obj,
-    Evas_Callback_Type type, Evas_Object_Event_Cb func, const void *data) {
-}
-
-void __elm_object_signal_callback_add(Evas_Object *obj, const char *emission,
-    const char *source, Edje_Signal_Cb func, void *data) {
-}
-
-Evas_Object *__elm_layout_add(Evas_Object *parent) {
-  return (Evas_Object*)g_hash_table_new_full(
-      g_str_hash, g_str_equal, free, nullptr);
-}
-
-void __elm_object_part_content_set(Evas_Object *obj, const char *part,
-    Evas_Object *content) {
-}
-
-Evas_Object *__elm_object_part_content_get(const Evas_Object *obj,
-    const char *part) {
-  return nullptr;
-}
-
-int __aul_widget_write_log(const char *tag, const char *format, va_list ap) {
-  return 0;
-}
-
-int __screen_connector_toolkit_evas_init(Evas_Object *win,
-                                   screen_connector_screen_type_e type) {
-  return 0;
-}
-
-namespace {
-class WVE : public ::testing::Test {
- public:
-  virtual void SetUp() {
-    system_info_get_platform_bool_fake.custom_fake =
-        __fake_system_info_get_platform_bool;
-    cynara_check_fake.custom_fake = __cynara_check;
-    elm_win_add_fake.custom_fake = __elm_win_add;
-    aul_app_get_appid_bypid_fake.custom_fake = __aul_app_get_appid_bypid;
-    widget_service_get_widget_max_count_fake.custom_fake =
-        __widget_service_get_widget_max_count;
-    widget_instance_create_fake.custom_fake = __widget_instance_create;
-
-    elm_layout_add_fake.custom_fake = __elm_layout_add;
-    elm_layout_file_set_fake.custom_fake = __elm_layout_file_set;
-    evas_object_data_set_fake.custom_fake = __evas_object_data_set;
-    evas_object_data_get_fake.custom_fake = __evas_object_data_get;
-    evas_object_event_callback_add_fake.custom_fake =
-        __evas_object_event_callback_add;
-    elm_object_signal_callback_add_fake.custom_fake =
-        __elm_object_signal_callback_add;
-    elm_object_part_content_set_fake.custom_fake =
-        __elm_object_part_content_set;
-    elm_object_part_content_get_fake.custom_fake =
-        __elm_object_part_content_get;
-
-    screen_connector_toolkit_evas_init_fake.custom_fake =
-        __screen_connector_toolkit_evas_init;
-    aul_widget_write_log_fake.custom_fake = __aul_widget_write_log;
-  }
-  virtual void TearDown(){
-  }
-};
-
-TEST_F(WVE, widget_viewer_evas_init_invalid)
-{
-  int ret = widget_viewer_evas_init(NULL);
-  EXPECT_EQ(WIDGET_ERROR_INVALID_PARAMETER, ret);
-}
-
-TEST_F(WVE, widget_viewer_evas_init_fault)
-{
-  int ret = widget_viewer_evas_fini();
-  EXPECT_EQ(WIDGET_ERROR_FAULT, ret);
-}
-
-TEST_F(WVE, widget_viewer_evas_init_fini)
-{
-  Evas_Object* win = elm_win_add(NULL, "Widget Viewer", ELM_WIN_BASIC);
-  widget_viewer_evas_init(win);
-  int ret = widget_viewer_evas_fini();
-  EXPECT_EQ(WIDGET_ERROR_NONE, ret);
-}
-
-TEST_F(WVE, widget_viewer_evas_add_widget)
-{
-  Evas_Object* win = elm_win_add(NULL, "Widget Viewer", ELM_WIN_BASIC);
-  widget_viewer_evas_init(win);
-  Evas_Object* widget = widget_viewer_evas_add_widget(win,
-      "org.tizen.widget", "content", 0.5);
-  int ret = widget_viewer_evas_pause_widget(widget);
-  EXPECT_EQ(WIDGET_ERROR_NONE, ret);
-
-  ret = widget_viewer_evas_resume_widget(widget);
-  EXPECT_EQ(WIDGET_ERROR_NONE, ret);
-  EXPECT_TRUE(widget != nullptr);
-
-  set_last_result(WIDGET_ERROR_NONE);
-  widget_viewer_evas_get_content_info(widget);
-  EXPECT_EQ(WIDGET_ERROR_NONE, get_last_result());
-
-  set_last_result(WIDGET_ERROR_NONE);
-  widget_viewer_evas_get_title_string(widget);
-  EXPECT_EQ(WIDGET_ERROR_NOT_SUPPORTED, get_last_result());
-
-  const char* ret_id = widget_viewer_evas_get_widget_id(widget);
-  EXPECT_EQ(0, strcmp(ret_id, "org.tizen.widget"));
-
-  set_last_result(WIDGET_ERROR_NONE);
-  widget_viewer_evas_get_period(widget);
-  EXPECT_EQ(WIDGET_ERROR_NONE, get_last_result());
-
-  set_last_result(WIDGET_ERROR_NONE);
-  widget_viewer_evas_cancel_click_event(widget);
-  EXPECT_EQ(WIDGET_ERROR_INVALID_PARAMETER, get_last_result());
-
-  set_last_result(WIDGET_ERROR_NONE);
-  ret = widget_viewer_evas_feed_mouse_up_event(widget);
-  EXPECT_EQ(WIDGET_ERROR_NONE, get_last_result());
-
-  set_last_result(WIDGET_ERROR_NONE);
-  widget_viewer_evas_disable_preview(widget);
-  EXPECT_EQ(WIDGET_ERROR_NONE, get_last_result());
-
-  widget_viewer_evas_disable_overlay_text(widget);
-  EXPECT_EQ(WIDGET_ERROR_NONE, get_last_result());
-
-  widget_viewer_evas_disable_loading(widget);
-  EXPECT_EQ(WIDGET_ERROR_NONE, get_last_result());
-
-  widget_viewer_evas_activate_faulted_widget(widget);
-  EXPECT_EQ(WIDGET_ERROR_NONE, get_last_result());
-
-  widget_viewer_evas_is_faulted(widget);
-  EXPECT_EQ(WIDGET_ERROR_NONE, get_last_result());
-
-  ret = widget_viewer_evas_freeze_visibility(widget,
-      WIDGET_VISIBILITY_STATUS_SHOW_FIXED);
-  EXPECT_EQ(WIDGET_ERROR_INVALID_PARAMETER, ret);
-
-  ret = widget_viewer_evas_thaw_visibility(widget);
-  EXPECT_EQ(WIDGET_ERROR_INVALID_PARAMETER, ret);
-
-  bool is_frozon = widget_viewer_evas_is_visibility_frozen(widget);
-  EXPECT_EQ(is_frozon, false);
-
-  bool is_widget = widget_viewer_evas_is_widget(widget);
-  EXPECT_EQ(is_widget, true);
-
-  widget_viewer_evas_set_permanent_delete(widget, 1);
-  EXPECT_EQ(WIDGET_ERROR_NONE, get_last_result());
-
-  const char *ret_inst_id = widget_viewer_evas_get_widget_instance_id(widget);
-  EXPECT_EQ(0, strcmp(ret_inst_id, "test@org.tizen.test"));
-
-  ret = widget_viewer_evas_set_delayed_resuming_time(10);
-  EXPECT_EQ(WIDGET_ERROR_NONE, ret);
-
-  ret = widget_viewer_evas_launch_setup_app(widget);
-  EXPECT_EQ(WIDGET_ERROR_NOT_EXIST, ret);
-}
-
-}
\ No newline at end of file
index 8e93518..e03a392 100644 (file)
@@ -21,7 +21,7 @@
 #include <bundle_cpp.h>
 
 #include <string>
-#include <screen_connector_remote_surface_evas/remote_surface_evas.h>
+#include <remote_surface_evas.h>
 
 #include "common.hh"
 #include "sharable_watch_interface.hh"