From: Hyunho Kang Date: Thu, 9 Nov 2017 04:55:08 +0000 (+0900) Subject: Add unit test X-Git-Tag: submit/tizen/20180209.053510~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7092499fb28d9e06b55f8c24e4626751d19a0529;p=platform%2Fcore%2Fappfw%2Fscreen-connector.git Add unit test Change-Id: I90a106f5efd9d22cdfa64a8a098800d655c4b3da Signed-off-by: Hyunho Kang --- diff --git a/CMakeLists.txt b/CMakeLists.txt index badb10b..bd6837e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/packaging/libscreen_connector.spec b/packaging/libscreen_connector.spec index 2f1b68e..6760316 100644 --- a/packaging/libscreen_connector.spec +++ b/packaging/libscreen_connector.spec @@ -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 index 0000000..78a6b42 --- /dev/null +++ b/unittest/CMakeLists.txt @@ -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 index 0000000..266b99a --- /dev/null +++ b/unittest/src/sc_remote_surface_test.cpp @@ -0,0 +1,105 @@ +#include +#include +#include +#include +#include +#include +#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 index 0000000..6efbf98 --- /dev/null +++ b/unittest/src/sc_test_main.cpp @@ -0,0 +1,7 @@ +#include +#include + +int main(int argc, char** argv){ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}