Add unit tests for ambient viewer 30/231530/2
authorJunghoon Park <jh9216.park@samsung.com>
Wed, 22 Apr 2020 08:05:07 +0000 (17:05 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Wed, 22 Apr 2020 08:24:01 +0000 (17:24 +0900)
Change-Id: Id399fed778e324c16ab99d4adb8fad8a5e0f30f8
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
unittest/mock/evas_mock.h
unittest/mock/mock.cc
unittest/src/test_ambient_viewer.cc

index 2369307..603998f 100644 (file)
 #ifndef MOCK_EVAS_H_
 #define MOCK_EVAS_H_
 
+#include <tbm_surface.h>
 #include <Evas.h>
+#include <Elementary.h>
 #include "mock.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#define ELM_WIN_UNKNOWN              0
-#define ELM_WIN_BASIC                1
-#define ELM_WIN_DIALOG_BASIC         2
-#define ELM_WIN_DESKTOP              3
-#define ELM_WIN_DOCK                 4
-#define ELM_WIN_TOOLBAR              5
-#define ELM_WIN_MENU                 6
-#define ELM_WIN_UTILITY              7
-#define ELM_WIN_SPLASH               8
-#define ELM_WIN_DROPDOWN_MENU        9
-#define ELM_WIN_POPUP_MENU           10
-#define ELM_WIN_TOOLTIP              11
-#define ELM_WIN_NOTIFICATION         12
-#define ELM_WIN_COMBO                13
-
-typedef int         Elm_Win_Type;
-
-typedef void (*Efl_Signal_Cb) (void *data, Evas_Object *obj, const char *emission, const char *source); /**< Edje signal callback functions's prototype definition. @c data will have the auxiliary data pointer set at the time the callback registration. @c obj will be a pointer the Edje object where the signal comes from. @c emission will identify the exact signal's emission string and @c source the exact signal's source one. */
-typedef Efl_Signal_Cb Edje_Signal_Cb;
-
 DECLARE_FAKE_VALUE_FUNC(Evas_Object *, elm_win_add, Evas_Object *,
                const char *, Elm_Win_Type);
 
@@ -73,6 +55,14 @@ DECLARE_FAKE_VALUE_FUNC(Evas_Object *, elm_object_part_content_get,
 DECLARE_FAKE_VOID_FUNC(elm_object_signal_emit, Evas_Object *, const char  *,
                 const char  *);
 
+DECLARE_FAKE_VOID_FUNC(evas_object_geometry_get, const Evas_Object *,
+    Evas_Coord *, Evas_Coord *, Evas_Coord *, Evas_Coord *);
+DECLARE_FAKE_VALUE_FUNC(Evas_Native_Surface *,
+    evas_object_image_native_surface_get, const Evas_Object *);
+DECLARE_FAKE_VALUE_FUNC(int, tbm_surface_map, tbm_surface_h,
+    int, tbm_surface_info_s *);
+DECLARE_FAKE_VALUE_FUNC(int, tbm_surface_unmap, tbm_surface_h);
+
 #ifdef __cplusplus
 }
 #endif
index 186de22..8693789 100644 (file)
@@ -53,6 +53,13 @@ DEFINE_FAKE_VALUE_FUNC(Evas_Object *, elm_object_part_content_get,
                const Evas_Object *, const char *);
 DEFINE_FAKE_VOID_FUNC(elm_object_signal_emit, Evas_Object *, const char  *,
         const char  *);
+DEFINE_FAKE_VOID_FUNC(evas_object_geometry_get, const Evas_Object *,
+    Evas_Coord *, Evas_Coord *, Evas_Coord *, Evas_Coord *);
+DEFINE_FAKE_VALUE_FUNC(Evas_Native_Surface *,
+    evas_object_image_native_surface_get, const Evas_Object *);
+DEFINE_FAKE_VALUE_FUNC(int, tbm_surface_map, tbm_surface_h,
+    int, tbm_surface_info_s *);
+DEFINE_FAKE_VALUE_FUNC(int, tbm_surface_unmap, tbm_surface_h);
 
 /* aul */
 DEFINE_FAKE_VALUE_FUNC(int, aul_app_get_appid_bypid, int, char *, int);
index f7afd00..48ac824 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "unittest/mock/vconf_mock.h"
 #include "unittest/mock/aul_mock.h"
+#include "unittest/mock/system_info_mock.h"
+#include "unittest/mock/evas_mock.h"
 #include "ambient-viewer/include/ambient_viewer.h"
 #include "ambient-viewer/include/ambient_viewer_common.h"
 
@@ -34,8 +36,41 @@ using namespace std;
 using namespace ambient_viewer;
 using namespace tizen_base;
 
+static gchar __not_null;
 static app_com_cb __app_com_callback;
 static void* __app_com_user_data;
+static Evas_Native_Surface __fake_ns;
+static tbm_surface_info_s __fake_surf_info;
+static int __fake_buf[100][100];
+
+static int __system_info_get_platform_bool(const char* key, bool* value) {
+  *value = true;
+  return 0;
+}
+
+static void __evas_object_geometry_get(const Evas_Object *eo_obj, Evas_Coord *x,
+    Evas_Coord *y, Evas_Coord *w, Evas_Coord *h) {
+  *w = 100;
+  *h = 100;
+}
+
+static Evas_Native_Surface* __evas_object_image_native_surface_get(
+    const Evas_Object *eo_obj) {
+  __fake_ns.data.tbm.buffer = &__not_null;
+  return &__fake_ns;
+}
+
+static int __tbm_surface_map(tbm_surface_h surface, int opt,
+    tbm_surface_info_s *info) {
+  __fake_surf_info.planes[0].ptr = reinterpret_cast<unsigned char*>(
+      &__fake_buf[0][0]);
+  *info = __fake_surf_info;
+  return TBM_SURFACE_ERROR_NONE;
+}
+
+static int __tbm_surface_unmap(tbm_surface_h surface) {
+  return TBM_SURFACE_ERROR_NONE;
+}
 
 static void __receive_fake_message() {
   Bundle b;
@@ -90,17 +125,20 @@ class WatchSurfaceMock : public WatchSurface {
     : WatchSurface(rid, id, std::move(appid), viewer_win, listener, true) {}
 
   void InvokeEvasAdded() {
-    screen_connector::EvasObject eo(nullptr, false);
+    screen_connector::EvasObject eo(reinterpret_cast<Evas_Object*>(&__not_null),
+        false);
     OnEvasAdded("TestAppId", "TestInstId", 99, eo);
   }
 
   void InvokeEvasRemoved() {
-    screen_connector::EvasObject eo(nullptr, false);
+    screen_connector::EvasObject eo(reinterpret_cast<Evas_Object*>(&__not_null),
+        false);
     OnEvasRemoved("TestAppId", "TestInstId", 99, eo);
   }
 
   void InvokeEvasChanged() {
-    screen_connector::EvasObject eo(nullptr, false);
+    screen_connector::EvasObject eo(reinterpret_cast<Evas_Object*>(&__not_null),
+        false);
     OnEvasChanged("TestAppId", "TestInstId", 99, eo);
   }
 };
@@ -115,7 +153,8 @@ class TopAppSurfaceMock : public TopAppSurface {
   }
 
   void InvokeWatcherChanged() {
-    screen_connector::EvasObject image(nullptr, false);
+    screen_connector::EvasObject image(reinterpret_cast<Evas_Object*>(
+      &__not_null), false);
     OnWatcherChanged("TestAppId", "TestInstId", 99, image);
   }
 
@@ -186,6 +225,14 @@ class AmbientViewerTest : public ::testing::Test {
     aul_app_com_create_fake.custom_fake = __aul_app_com_create;
     aul_app_com_leave_fake.custom_fake = __aul_app_com_leave;
     aul_app_com_send_fake.custom_fake = __aul_app_com_send;
+    system_info_get_platform_bool_fake.custom_fake =
+        __system_info_get_platform_bool;
+    evas_object_geometry_get_fake.custom_fake =
+        __evas_object_geometry_get;
+    evas_object_image_native_surface_get_fake.custom_fake =
+        __evas_object_image_native_surface_get;
+    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);
@@ -254,6 +301,20 @@ TEST_F(AmbientViewerTest, WatchSurface_GetInstId) {
   stub->Unmonitor();
 }
 
+TEST_F(AmbientViewerTest, WatchSurface_GetOpr) {
+  stub->Monitor();
+  const auto& ws = AmbientViewerTest::stub->GetWatchSurface();
+  ASSERT_NE(&ws, nullptr);
+  WatchSurfaceMock* mock = const_cast<WatchSurfaceMock*>(
+      static_cast<const WatchSurfaceMock*>(&ws));
+  mock->InvokeEvasAdded();
+  EXPECT_TRUE(stub->added_);
+
+  EXPECT_EQ(ws.GetOpr(), 0);
+
+  stub->Unmonitor();
+}
+
 TEST_F(AmbientViewerTest, AmbientViewer_Events) {
   stub->Monitor();
   const auto& ws = AmbientViewerTest::stub->GetWatchSurface();
@@ -330,6 +391,21 @@ TEST_F(AmbientViewerTest, TopAppSurface_GetInstId) {
   stub->Unmonitor();
 }
 
+TEST_F(AmbientViewerTest, TopAppSurface_GetOpr) {
+  stub->Monitor();
+  const auto& ws = AmbientViewerTest::stub->GetTopAppSurface();
+  ASSERT_NE(&ws, nullptr);
+  TopAppSurfaceMock* mock = const_cast<TopAppSurfaceMock*>(
+      static_cast<const TopAppSurfaceMock*>(&ws));
+  mock->InvokeWatcherAdded();
+  mock->InvokeWatcherChanged();
+  mock->InvokeWatcherFocusChanged();
+
+  EXPECT_EQ(ws.GetOpr(), 0);
+
+  stub->Unmonitor();
+}
+
 TEST_F(AmbientViewerTest, AmbientViewer_OnReceived2) {
   stub->Monitor();
   const auto& ws = AmbientViewerTest::stub->GetWatchSurface();
@@ -348,79 +424,129 @@ class AmbientViewerStubTest : public ::testing::Test {
   virtual void TearDown() {}
 };
 
-TEST_F(AmbientViewerStubTest, ambient_viewer_create) {
+TEST_F(AmbientViewerStubTest, ambient_viewer_create_n) {
   EXPECT_EQ(ambient_viewer_create(nullptr, nullptr),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
 
-TEST_F(AmbientViewerStubTest, ambient_viewer_destroy) {
+TEST_F(AmbientViewerStubTest, ambient_viewer_create) {
+  ambient_viewer_h handle = nullptr;
+
+  EXPECT_EQ(ambient_viewer_create(reinterpret_cast<Evas_Object*>(&__not_null),
+    &handle), AMBIENT_VIEWER_ERROR_NONE);
+  EXPECT_NE(handle, nullptr);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_destroy_n) {
   EXPECT_EQ(ambient_viewer_destroy(nullptr),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
 
-TEST_F(AmbientViewerStubTest, ambient_viewer_notify_ambient_event) {
+TEST_F(AmbientViewerStubTest, ambient_viewer_destroy) {
+  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_destroy(handle),
+      AMBIENT_VIEWER_ERROR_NONE);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_notify_ambient_event_n) {
   EXPECT_EQ(ambient_viewer_notify_ambient_event(nullptr, true,
       AMBIENT_VIEWER_DIRECTION_ALL, nullptr),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
 
-TEST_F(AmbientViewerStubTest, ambient_viewer_block_update) {
+TEST_F(AmbientViewerStubTest, ambient_viewer_block_update_n) {
   EXPECT_EQ(ambient_viewer_block_update(nullptr, true),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
 
-TEST_F(AmbientViewerStubTest, ambient_viewer_monitor) {
+TEST_F(AmbientViewerStubTest, ambient_viewer_monitor_n) {
   ambient_viewer_lifecycle_s lifecycle;
   EXPECT_EQ(ambient_viewer_monitor(nullptr, lifecycle, nullptr),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
 
-TEST_F(AmbientViewerStubTest, ambient_viewer_unmonitor) {
+TEST_F(AmbientViewerStubTest, ambient_viewer_unmonitor_n) {
   EXPECT_EQ(ambient_viewer_unmonitor(nullptr),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
 
-TEST_F(AmbientViewerStubTest, ambient_viewer_set_event_listener) {
+TEST_F(AmbientViewerStubTest, ambient_viewer_set_event_listener_n) {
   EXPECT_EQ(ambient_viewer_set_event_listener(nullptr, nullptr, nullptr),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
 
-TEST_F(AmbientViewerStubTest, ambient_viewer_unset_event_listener) {
+static void __ambient_viewer_event_cb(ambient_event_type_e event,
+    const char *sender, bundle *extra, void *user_data) {
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_set_event_listener) {
+  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_set_event_listener(handle, __ambient_viewer_event_cb,
+      nullptr), AMBIENT_VIEWER_ERROR_NONE);
+
+  ASSERT_EQ(ambient_viewer_destroy(handle),
+      AMBIENT_VIEWER_ERROR_NONE);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_unset_event_listener_n) {
   EXPECT_EQ(ambient_viewer_unset_event_listener(nullptr),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
 
-TEST_F(AmbientViewerStubTest, ambient_viewer_get_watch_surface) {
+TEST_F(AmbientViewerStubTest, ambient_viewer_unset_event_listener) {
+  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);
+  ASSERT_EQ(ambient_viewer_set_event_listener(handle, __ambient_viewer_event_cb,
+      nullptr), AMBIENT_VIEWER_ERROR_NONE);
+
+  EXPECT_EQ(ambient_viewer_unset_event_listener(handle),
+      AMBIENT_VIEWER_ERROR_NONE);
+
+  ASSERT_EQ(ambient_viewer_destroy(handle),
+      AMBIENT_VIEWER_ERROR_NONE);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_get_watch_surface_n) {
   EXPECT_EQ(ambient_viewer_get_watch_surface(nullptr, nullptr),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
 
-TEST_F(AmbientViewerStubTest, ambient_viewer_get_top_app_surface) {
+TEST_F(AmbientViewerStubTest, ambient_viewer_get_top_app_surface_n) {
   EXPECT_EQ(ambient_viewer_get_top_app_surface(nullptr, nullptr),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
 
-TEST_F(AmbientViewerStubTest, ambient_viewer_surface_get_cur_image) {
+TEST_F(AmbientViewerStubTest, ambient_viewer_surface_get_cur_image_n) {
   EXPECT_EQ(ambient_viewer_surface_get_cur_image(nullptr, nullptr),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
 
-TEST_F(AmbientViewerStubTest, ambient_viewer_surface_is_watch) {
+TEST_F(AmbientViewerStubTest, ambient_viewer_surface_is_watch_n) {
   EXPECT_EQ(ambient_viewer_surface_is_watch(nullptr, nullptr),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
 
-TEST_F(AmbientViewerStubTest, ambient_viewer_surface_get_app_id) {
+TEST_F(AmbientViewerStubTest, ambient_viewer_surface_get_app_id_n) {
   EXPECT_EQ(ambient_viewer_surface_get_app_id(nullptr, nullptr),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
 
-TEST_F(AmbientViewerStubTest, ambient_viewer_surface_get_inst_id) {
+TEST_F(AmbientViewerStubTest, ambient_viewer_surface_get_inst_id_n) {
   EXPECT_EQ(ambient_viewer_surface_get_inst_id(nullptr, nullptr),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }
 
-TEST_F(AmbientViewerStubTest, ambient_viewer_surface_get_opr) {
+TEST_F(AmbientViewerStubTest, ambient_viewer_surface_get_opr_n) {
   EXPECT_EQ(ambient_viewer_surface_get_opr(nullptr, nullptr),
       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
 }