add unittests for the wayland-extension 96/231196/4
authorSooChan Lim <sc1.lim@samsung.com>
Mon, 20 Apr 2020 04:41:48 +0000 (13:41 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 27 Apr 2020 08:53:03 +0000 (17:53 +0900)
The wayland-extension has the unittests package using GTest.

Change-Id: I37437cf8b419f31ef071c778ff5617ffe61a162c

Makefile.am
configure.ac
packaging/wayland-extension.spec
unittests/Makefile.am [new file with mode: 0644]
unittests/tc-main.cpp [new file with mode: 0644]

index a4c104f..3a9b370 100644 (file)
@@ -1,3 +1,4 @@
+SUBDIRS = unittests
 AM_CPPFLAGS = \
                        -I$(top_builddir)/protocol/tizen \
                        -I$(top_builddir)/protocol/unstable \
index f22c5a1..248e6c7 100644 (file)
@@ -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
index 06e8a06..c550082 100644 (file)
@@ -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 (file)
index 0000000..b4ec744
--- /dev/null
@@ -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 (file)
index 0000000..7f948e2
--- /dev/null
@@ -0,0 +1,52 @@
+/**************************************************************************
+ *
+ * Copyright 2020 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: SooChan Lim <sc1.lim@samsung.com>
+ *
+ * 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;
+}