From 57d40396f793f4394dd735ae79292c872c887f58 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Mon, 20 Apr 2020 13:41:48 +0900 Subject: [PATCH] add unittests for the wayland-extension The wayland-extension has the unittests package using GTest. Change-Id: I37437cf8b419f31ef071c778ff5617ffe61a162c --- Makefile.am | 1 + configure.ac | 5 +++ packaging/wayland-extension.spec | 13 ++++++++ unittests/Makefile.am | 20 ++++++++++++ unittests/tc-main.cpp | 52 ++++++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 unittests/Makefile.am create mode 100644 unittests/tc-main.cpp diff --git a/Makefile.am b/Makefile.am index a4c104f..3a9b370 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,4 @@ +SUBDIRS = unittests AM_CPPFLAGS = \ -I$(top_builddir)/protocol/tizen \ -I$(top_builddir)/protocol/unstable \ diff --git a/configure.ac b/configure.ac index f22c5a1..248e6c7 100644 --- a/configure.ac +++ b/configure.ac @@ -87,8 +87,13 @@ if test "${want_build_examples}" = "yes"; then PKG_CHECK_MODULES([ELEMENTARY], [elementary]) fi +PKG_CHECK_MODULES(GMOCK, gmock) +GMOCK_CFLAGS="$GMOCK_CLAGS" +GMOCK_LIBS="$GMOCK_LIBS" + AC_CONFIG_FILES([ Makefile + unittests/Makefile src/wayland-extension-version.h src/template-server.pc src/template-client.pc diff --git a/packaging/wayland-extension.spec b/packaging/wayland-extension.spec index 06e8a06..c550082 100644 --- a/packaging/wayland-extension.spec +++ b/packaging/wayland-extension.spec @@ -15,6 +15,7 @@ BuildRequires: libtool >= 2.2 BuildRequires: pkgconfig BuildRequires: pkgconfig(wayland-server) BuildRequires: pkgconfig(wayland-client) +BuildRequires: pkgconfig(gmock) # requires to build examples %if "%{enable_examples}" == "1" @@ -78,6 +79,14 @@ Requires: libwayland-client %description -n wayland-protocols wayland-protocols contains Wayland upstream protocols that add functionality not available in the Wayland core protocol +%package -n libwayland-extension-unittests +Summary: Unit test cases for the libwayland-extension +Group: Graphics & UI Framework/Development +Requires: libwayland-client +Requires: libwayland-server + +%description -n libwayland-extension-unittests +Unit test cases for the libwayland-extension %prep %setup -q @@ -140,4 +149,8 @@ make %{?_smp_mflags} %_datadir/wayland-extension/protocol/unstable/* %_libdir/pkgconfig/wayland-protocols.pc +%files -n libwayland-extension-unittests +%defattr(-,root,root,-) +%{_bindir}/libwayland-extension-unittests + %changelog diff --git a/unittests/Makefile.am b/unittests/Makefile.am new file mode 100644 index 0000000..b4ec744 --- /dev/null +++ b/unittests/Makefile.am @@ -0,0 +1,20 @@ +bin_PROGRAMS = libwayland-extension-unittests + +libwayland_extension_unittests_SOURCES = \ + tc-main.cpp + +libwayland_extension_unittests_CXXFLAGS = \ + -I$(top_srcdir)/protocol/tizen \ + ${CXXFLAGS} \ + @GMOCK_CFLAGS@ \ + @WAYLAND_SERVER_CFLAGS@ \ + @WAYLAND_CLIENT_CFLAGS@ + +libwayland_extension_unittests_LDFLAGS = \ + ${LDFLAGS} \ + @GMOCK_LIBS@ \ + @WAYLAND_SERVER_LIBS@ \ + @WAYLAND_CLIENT_LIBS@ + +check: + ./libwayland-extension-unitests diff --git a/unittests/tc-main.cpp b/unittests/tc-main.cpp new file mode 100644 index 0000000..7f948e2 --- /dev/null +++ b/unittests/tc-main.cpp @@ -0,0 +1,52 @@ +/************************************************************************** + * + * 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. + * +**************************************************************************/ + +#include "gmock/gmock.h" + +int main(int argc, char **argv) +{ + auto AllTestSuccess = false; + + try { + ::testing::InitGoogleMock(&argc, argv); + ::testing::FLAGS_gtest_death_test_style = "fast"; + } catch ( ... ) { + std::cout << "error while trying to init google tests.\n"; + exit(EXIT_FAILURE); + } + + try { + AllTestSuccess = RUN_ALL_TESTS() == 0 ? true : false; + } catch (const ::testing::internal::GoogleTestFailureException & e) { + AllTestSuccess = false; + std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl; + std::cout << "\n"; + } + + return AllTestSuccess; +} -- 2.34.1