make pepper-tests package 80/261780/1
authorSooChan Lim <sc1.lim@samsung.com>
Mon, 26 Jul 2021 07:35:44 +0000 (16:35 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 26 Jul 2021 07:35:44 +0000 (16:35 +0900)
pepper-tests include the gtest unit tests for libpepper.

Change-Id: Ic241f1829b5c361e79a951b968cf7327534e35b0

Makefile.am
configure.ac
packaging/pepper.spec
tests/Makefile.am [new file with mode: 0644]
tests/tc_main.cpp [new file with mode: 0644]

index 2d93008..b7879a5 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = src
+SUBDIRS = src tests
 
 pkgconfigdir = $(libdir)/pkgconfig
 
index b6602a8..180c34a 100644 (file)
@@ -17,6 +17,7 @@ AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz subdir-objects])
 AM_SILENT_RULES([yes])
 
 AC_PROG_CC
+AC_PROG_CXX
 
 LT_PREREQ([2.2])
 LT_INIT([disable-static])
@@ -386,6 +387,13 @@ if test x$wayland_scanner = x; then
     wayland_scanner=`$PKG_CONFIG --variable=wayland_scanner wayland-scanner`
 fi
 
+# pepper-tests
+PEPPER_TESTS_REQUIRES="gmock"
+PKG_CHECK_MODULES(PEPPER_TESTS, [$PEPPER_TESTS_REQUIRES])
+
+AC_SUBST(PEPPER_TESTS_CFLAGS)
+AC_SUBST(PEPPER_TESTS_LIBS)
+
 # document
 AC_ARG_ENABLE([document],
               [AC_HELP_STRING([--disable-document],
@@ -419,6 +427,7 @@ src/lib/fbdev/Makefile
 src/lib/wayland/Makefile
 src/bin/doctor/Makefile
 src/samples/Makefile
+tests/Makefile
 pkgconfig/pepper.pc
 pkgconfig/pepper-render.pc
 pkgconfig/pepper-fbdev.pc
index 91c3546..5df269b 100644 (file)
@@ -38,6 +38,7 @@ BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(cynara-client)
 BuildRequires:  pkgconfig(cynara-creds-socket)
 BuildRequires:  pkgconfig(libsmack)
+BuildRequires:  pkgconfig(gmock)
 
 %{!?TZ_SYS_RO_SHARE: %global TZ_SYS_RO_SHARE /usr/share}
 
@@ -267,6 +268,13 @@ Requires: pepper-xkb
 %description samples
 This package includes samples files.
 
+###### tests
+%package tests
+Summary: Pepper unit tests package
+
+%description tests
+gtest test cases for pepper
+
 ###### executing
 
 %prep
@@ -570,3 +578,7 @@ rm -f %{_unitdir_user}/basic.target.wants/display-user.service
 %defattr(-,root,root,-)
 %{_bindir}/*-backend
 %{_bindir}/sample-*
+
+%files tests
+%defattr(-,root,root,-)
+%{_bindir}/*-tests
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644 (file)
index 0000000..3ce7d61
--- /dev/null
@@ -0,0 +1,21 @@
+bin_PROGRAMS = libpepper-tests
+
+libpepper_tests_SOURCES = \
+       tc_main.cpp
+
+libpepper_tests_CXXFLAGS = \
+       ${CXXFLAGS} \
+       $(PEPPER_TESTS_CFLAGS) \
+       -fPIC \
+       -I$(top_srcdir)/src
+
+libpepper_tests_LDFLAGS = \
+       ${LDFLAGS} \
+       -pthread
+
+libpepper_tests_LDADD = \
+       $(PEPPER_TESTS_LIBS) \
+       $(top_srcdir)/src/lib/pepper/libpepper.la
+
+check:
+       ./libpepper-tests
\ No newline at end of file
diff --git a/tests/tc_main.cpp b/tests/tc_main.cpp
new file mode 100644 (file)
index 0000000..285653a
--- /dev/null
@@ -0,0 +1,64 @@
+/**************************************************************************
+ *
+ * Copyright 2021 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"
+
+#ifdef TIZEN_TEST_GCOV
+extern "C" void __gcov_flush(void);
+#endif
+
+int main(int argc, char **argv)
+{
+       auto AllTestSuccess = false;
+
+#ifdef TIZEN_TEST_GCOV
+       setenv("GCOV_PREFIX", "/tmp", 1);
+#endif
+
+       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";
+       }
+
+#ifdef TIZEN_TEST_GCOV
+       __gcov_flush();
+#endif
+
+       return AllTestSuccess;
+}