Add unit test 56/159456/11
authorHyunho Kang <hhstark.kang@samsung.com>
Thu, 9 Nov 2017 04:55:08 +0000 (13:55 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Tue, 28 Nov 2017 01:26:32 +0000 (01:26 +0000)
Change-Id: I90a106f5efd9d22cdfa64a8a098800d655c4b3da
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
CMakeLists.txt
packaging/libscreen_connector.spec
unittest/CMakeLists.txt [new file with mode: 0644]
unittest/src/sc_remote_surface_test.cpp [new file with mode: 0644]
unittest/src/sc_test_main.cpp [new file with mode: 0644]

index badb10bacfaf91f82f9f5a37ac3c5799bb63c3b9..bd6837e3166edc53b48997218cc5e42f9f7742ac 100644 (file)
@@ -5,6 +5,8 @@ ADD_SUBDIRECTORY(screen_connector_remote_surface)
 ADD_SUBDIRECTORY(screen_connector_remote_surface_evas)
 ADD_SUBDIRECTORY(screen_connector_watcher)
 ADD_SUBDIRECTORY(screen_connector_watcher_evas)
+ADD_SUBDIRECTORY(unittest)
 
 ADD_DEPENDENCIES(screen_connector_remote_surface_evas screen_connector_remote_surface)
 ADD_DEPENDENCIES(screen_connector_watcher_evas screen_connector_watcher screen_connector_remote_surface_evas)
+ADD_DEPENDENCIES(gtest-screen-connector screen_connector_watcher_evas)
index 2f1b68ef4923518925bf8c9d3e686addfa1b8069..6760316bb397360e5ba6a04225bfa537fae4be62 100644 (file)
@@ -19,6 +19,7 @@ BuildRequires: pkgconfig(wayland-tbm-client)
 BuildRequires: pkgconfig(elementary)
 BuildRequires: pkgconfig(wayland-client)
 BuildRequires: pkgconfig(ecore-wayland)
+BuildRequires: pkgconfig(gmock)
 
 %description
 API for creating a new instance of the widget and managing its life-cycle.
@@ -213,4 +214,19 @@ Header & package files to support development of the widget viewer applications.
 %attr(0644,root,root) %{_libdir}/%{name}_remote_surface_evas.so
 
 
+#################################################
+# gtest-screen-connector
+#################################################
+%package -n gtest-screen-connector
+Summary:    GTest for screen-connector
+Group:      Development/Libraries
+Requires:   %{name}_watcher_evas
+
+%description -n gtest-screen-connector
+GTest for screen-connector
+
+%files -n gtest-screen-connector
+%{_bindir}/gtest-screen-connector
+
+
 # End of a file
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
new file mode 100644 (file)
index 0000000..78a6b42
--- /dev/null
@@ -0,0 +1,30 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-screen-connector CXX)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(gtest-screen-connector REQUIRED
+    glib-2.0
+    gmock
+    aul
+    elementary
+)
+
+FOREACH(flag ${gtest-screen-connector_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline")
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++11")
+SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
+SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../)
+
+AUX_SOURCE_DIRECTORY(src SOURCES)
+ADD_EXECUTABLE(${PROJECT_NAME}
+       ${SOURCES}
+)
+
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${gtest-screen-connector_LDFLAGS} screen_connector_watcher_evas screen_connector_remote_surface_evas screen_connector_remote_surface)
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/)
diff --git a/unittest/src/sc_remote_surface_test.cpp b/unittest/src/sc_remote_surface_test.cpp
new file mode 100644 (file)
index 0000000..266b99a
--- /dev/null
@@ -0,0 +1,105 @@
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+#include <iostream>
+#include <stdbool.h>
+#include <stdexcept>
+#include <glib.h>
+#include "screen_connector_remote_surface/buffer_event_interface.h"
+#include "screen_connector_remote_surface/remote_surface_implementation.h"
+#include "screen_connector_remote_surface/remote_surface.h"
+
+using namespace std;
+using ::testing::AtLeast;
+
+GMainLoop *mainloop = NULL;
+class SimpleRs : public screen_connector::RemoteSurface {
+ public:
+   enum Event {
+     None,
+     Added,
+     Removed,
+     Changed
+   };
+
+   Event curEvent;
+   string curInstId;
+   int curType = -1;
+   SimpleRs(const std::string& id,
+     screen_connector::RemoteSurface::Type type, bool mock, Event evType)
+       : screen_connector::RemoteSurface(id, type, mock), curEvent(evType) {
+   }
+   void OnBufferAdded(const std::string& appId,
+                      const std::string& instId, int pid) override {
+     cout << "OnBufferAdded  " << instId << endl;
+     if (curEvent == Added && g_main_loop_is_running(mainloop)) {
+       g_main_loop_quit(mainloop);
+       curInstId = instId;
+       cout << "OnBufferAdded done  ?? " << curInstId << endl;
+     }
+   }
+   void OnBufferRemoved(const std::string& appId,
+                      const std::string& instId, int pid) override {
+
+     cout << "OnBufferRemoved  " << instId << endl;
+     if (curEvent == Removed && g_main_loop_is_running(mainloop)) {
+       g_main_loop_quit(mainloop);
+       curInstId = instId;
+       cout << "OnBufferRemoved done  ?? " << curInstId << endl;
+     }
+   }
+   void OnBufferChanged(int type, const screen_connector::WlBuffer& tbm, int fd,
+                        uint32_t size, uint32_t time) override {
+     cout << "OnBufferChanged event " << type << endl;
+     if (curEvent == Changed && g_main_loop_is_running(mainloop)) {
+       g_main_loop_quit(mainloop);
+       curType = type;
+       cout << "OnBufferChanged event done " << curType << endl;
+     }
+   }
+};
+
+class SCRemoteSurface : public ::testing::Test {
+ public:
+  string testId = "org.tizen.screen_connector.test.appid.instid";
+  void RunMainLoop() {
+    g_main_loop_run(mainloop);
+  }
+  virtual void SetUp() {
+    mainloop = g_main_loop_new(NULL, FALSE);
+  }
+  virtual void TearDown() {
+    g_main_loop_unref(mainloop);
+       mainloop = NULL;
+  }
+};
+
+TEST_F(SCRemoteSurface, SCRemoteSurface_CONST) {
+  SimpleRs *rs = new SimpleRs(testId.c_str(),
+    screen_connector::RemoteSurface::WIDGET, true, SimpleRs::Event::None);
+  EXPECT_NE(rs, nullptr);
+  delete rs;
+}
+
+TEST_F(SCRemoteSurface, SCRemoteSurface_ADDED) {
+  SimpleRs *rs = new SimpleRs(testId.c_str(),
+    screen_connector::RemoteSurface::WIDGET, true, SimpleRs::Event::Added);
+  RunMainLoop();
+  EXPECT_EQ(testId, rs->curInstId);
+  delete rs;
+}
+
+TEST_F(SCRemoteSurface, SCRemoteSurface_CHANGED) {
+  SimpleRs *rs = new SimpleRs(testId.c_str(),
+    screen_connector::RemoteSurface::WIDGET, true, SimpleRs::Event::Changed);
+  RunMainLoop();
+  EXPECT_EQ(TIZEN_REMOTE_SURFACE_BUFFER_TYPE_TBM, rs->curType);
+  delete rs;
+}
+
+TEST_F(SCRemoteSurface, SCRemoteSurface_REMOVED) {
+  SimpleRs *rs = new SimpleRs(testId.c_str(),
+    screen_connector::RemoteSurface::WIDGET, true, SimpleRs::Event::Removed);
+  RunMainLoop();
+  EXPECT_EQ(testId, rs->curInstId);
+  delete rs;
+}
diff --git a/unittest/src/sc_test_main.cpp b/unittest/src/sc_test_main.cpp
new file mode 100644 (file)
index 0000000..6efbf98
--- /dev/null
@@ -0,0 +1,7 @@
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+int main(int argc, char** argv){
+  testing::InitGoogleTest(&argc, argv);
+  return RUN_ALL_TESTS();
+}