From 32ad5e221e95f752aca8bd651fe620a603f57f55 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 24 Jul 2020 10:45:23 +0900 Subject: [PATCH] Test: make libds-mock.h file. make libds-mock.h file and put the MockWaylandCompositor class and TestClient structure in it. Change-Id: I5df2907b84e91bb3bf63321cea609c39ba39b144 --- tests/DSWaylandCompositor-test.cpp | 56 ++--------------------- tests/libds-mock.h | 91 ++++++++++++++++++++++++++++++++++++++ tests/libds-tests.h | 13 ++++-- 3 files changed, 105 insertions(+), 55 deletions(-) create mode 100644 tests/libds-mock.h diff --git a/tests/DSWaylandCompositor-test.cpp b/tests/DSWaylandCompositor-test.cpp index 857030a..7a459e3 100644 --- a/tests/DSWaylandCompositor-test.cpp +++ b/tests/DSWaylandCompositor-test.cpp @@ -1,14 +1,6 @@ #include "libds-tests.h" -#include "DSWaylandCompositor.h" #include "DSWaylandClient.h" #include "DSWaylandSeat.h" -#include "DSEventLoop.h" -#include -#include -#include -#include -#include -#include using namespace display_server; @@ -157,46 +149,6 @@ TEST_F(DSWaylandCompositorTest, GetDefaultSeat) } } -class MockCompositor : public DSObject -{ -public: - MockCompositor() - : surfaceCreated(false) - { - __compositor = DSWaylandCompositor::getInstance(); - __compositor->create(); - __compositor->registerCallbackSurfaceCreated(this, std::bind(&MockCompositor::onSurfaceCreated, this, std::placeholders::_1)); - } - - ~MockCompositor() { DSWaylandCompositor::releaseInstance(); } - - void onSurfaceCreated(std::shared_ptr) { - surfaceCreated = true; - } - - void run() { - __eventLoop.run(); - } - - void quit() { - __eventLoop.quit(); - } - - bool surfaceCreated; // result of surfaceCreated - -private: - DSWaylandCompositor *__compositor; - DSEventLoop __eventLoop; -}; - -struct TestClient -{ - struct wl_display *display; - struct wl_compositor *compositor; - struct wl_registry *registry; - struct wl_surface *surface; -}; - static void handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) @@ -221,12 +173,12 @@ static const struct wl_registry_listener registry_listener = { TEST_F(DSWaylandCompositorTest, registerCallbackSurfaceCreated) { - auto mockCompositor = std::make_unique(); + auto mockWaylandCompositor = std::make_unique(); Ecore_Timer *serverQuitTimer = nullptr; double severQuitTime = 1.0; auto serverQuitFunc = [](void *data) -> Eina_Bool { - MockCompositor *comp = (MockCompositor *)data; + MockWaylandCompositor *comp = (MockWaylandCompositor *)data; // quit server comp->quit(); @@ -235,7 +187,7 @@ TEST_F(DSWaylandCompositorTest, registerCallbackSurfaceCreated) return EINA_FALSE; }; - serverQuitTimer = ecore_timer_loop_add(severQuitTime, serverQuitFunc, mockCompositor.get()); + serverQuitTimer = ecore_timer_loop_add(severQuitTime, serverQuitFunc, mockWaylandCompositor.get()); EXPECT_TRUE(serverQuitTimer != nullptr); // create the wayland client which creates the wl_surface. @@ -262,7 +214,7 @@ TEST_F(DSWaylandCompositorTest, registerCallbackSurfaceCreated) } ); - mockCompositor->run(); + mockWaylandCompositor->run(); EXPECT_TRUE(clientThread.get()); // join(wait) and get the return value. } diff --git a/tests/libds-mock.h b/tests/libds-mock.h new file mode 100644 index 0000000..4554dd6 --- /dev/null +++ b/tests/libds-mock.h @@ -0,0 +1,91 @@ +/************************************************************************** + * + * Copyright 2020 Samsung Electronics co., Ltd. All Rights Reserved. + * + * Contact: SooChan Lim + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * +**************************************************************************/ + +#ifndef __LIBDS_MOCK_H__ +#define __LIBDS_MOCK_H__ + +#include "DSWaylandCompositor.h" +#include "DSWaylandSurface.h" +#include "DSEventLoop.h" +#include "DSDebugLog.h" + +using namespace display_server; + +///////////////////////////////////////////////////////////////////////////////////////////////////////// +// wayland MockCompositor +///////////////////////////////////////////////////////////////////////////////////////////////////////// +class MockWaylandCompositor : public DSObject +{ +public: + MockWaylandCompositor() + : surfaceCreated(false) + { + __waylandCompositor = DSWaylandCompositor::getInstance(); + __waylandCompositor->create(); + __waylandCompositor->registerCallbackSurfaceCreated(this, std::bind(&MockWaylandCompositor::onSurfaceCreated, this, std::placeholders::_1)); + } + + ~MockWaylandCompositor() + { + DSWaylandCompositor::releaseInstance(); + } + + void onSurfaceCreated(std::shared_ptr) + { + surfaceCreated = true; + } + + void run() + { + __eventLoop.run(); + } + + void quit() + { + __eventLoop.quit(); + } + + bool surfaceCreated; // result of surfaceCreated + +private: + DSWaylandCompositor *__waylandCompositor; + DSEventLoop __eventLoop; +}; + +///////////////////////////////////////////////////////////////////////////////////////////////////////// +// wayland Test Client +///////////////////////////////////////////////////////////////////////////////////////////////////////// +struct TestClient +{ + struct wl_display *display; + struct wl_compositor *compositor; + struct wl_registry *registry; + struct wl_surface *surface; +}; + +#endif // UT_H diff --git a/tests/libds-tests.h b/tests/libds-tests.h index 8965fec..0a4656b 100644 --- a/tests/libds-tests.h +++ b/tests/libds-tests.h @@ -26,13 +26,20 @@ * **************************************************************************/ -#ifndef _LIBDS_TESTS_H_ -#define _LIBDS_TESTS_H_ +#ifndef __LIBDS_TESTS_H__ +#define __LIBDS_TESTS_H__ #include #include +#include +#include +#include +#include +#include +#include #include -#include "DSDebugLog.h" + +#include "libds-mock.h" using ::testing::TestWithParam; using ::testing::Bool; -- 2.7.4