tests: add enlightenment-tests for unit testing. 09/249509/2
authorSooChan Lim <sc1.lim@samsung.com>
Mon, 14 Dec 2020 03:53:11 +0000 (12:53 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 14 Dec 2020 08:27:10 +0000 (08:27 +0000)
make a binary and a package
- binary name : enlightenment-tests
- package name : enlightenment-tests-xxx.rpm

Change-Id: Iba34889298a3a94c488dbfe65c9ccd59efc8fd40

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

index 9166e91..7c7358b 100644 (file)
@@ -1,7 +1,7 @@
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 AUTOMAKE_OPTIONS = subdir-objects
 
-SUBDIRS = .
+SUBDIRS = tests
 CLEANFILES =
 DISTCLEANFILES =
 INSTALL_DATA_HOOKS =
index 7d69f8b..7dfb99c 100755 (executable)
@@ -41,6 +41,7 @@ AC_USE_SYSTEM_EXTENSIONS
 AC_PROG_MKDIR_P
 AC_C_BIGENDIAN
 AC_PROG_CC_C99
+AC_PROG_CXX
 AM_PROG_CC_C_O
 AC_FUNC_ALLOCA
 
@@ -537,6 +538,11 @@ PKG_CHECK_MODULES(TZSH,
                   [tzsh-server],
                   [have_tzsh="yes"])
 
+#gmock
+PKG_CHECK_MODULES(GMOCK,
+                  [gmock],
+                  [have_gmock]="yes")
+
 POLICY_CFLAGS="${CAPI_SYSTEM_DEVICE_CFLAGS} ${CYNARA_CFLAGS} ${TZSH_CFLAGS}"
 POLICY_LIBS="${CAPI_SYSTEM_DEVICE_LIBS} ${CYNARA_LIBS} ${TZSH_LIBS}"
 AC_SUBST(POLICY_CFLAGS)
@@ -616,6 +622,7 @@ AC_SUBST([SUID_LDFLAGS])
 
 AC_OUTPUT([
 Makefile
+tests/Makefile
 enlightenment.pc
 ])
 
index 731bb75..c480531 100644 (file)
@@ -61,6 +61,9 @@ BuildRequires:  pkgconfig(linux-explicit-synchronization-unstable-v1-server)
 BuildRequires:  pkgconfig(tizen-hwc-server)
 Requires:       libwayland-extension-server
 
+# for gtest/gmock
+BuildRequires:  pkgconfig(gmock)
+
 # for recording video in enlightenment_info
 BuildRequires:  pkgconfig(wayland-client)
 BuildRequires:  pkgconfig(capi-media-streamrecorder)
@@ -81,6 +84,13 @@ Requires:       pkgconfig(tizen-extension-server)
 %description devel
 Development files for enlightenment
 
+%package tests
+Summary: enlightenment tests package
+Group: System/Libraries
+
+%description tests
+Tests binary for internal API in enlightenment
+
 %prep
 %setup -q -n %{name}-%{version}
 cp %{SOURCE1001} .
@@ -113,6 +123,7 @@ ln -sf %{_bindir}/enlightenment_input_key %{buildroot}%{_bindir}/input_keyevent
 /usr/bin/chsmack %{_bindir}/enlightenment_input_key* -a "System::Tools"
 /usr/bin/chsmack %{_bindir}/enlightenment_info* -a "System::Tools"
 /usr/bin/chsmack %{_bindir}/winfo* -a "System::Tools"
+/usr/bin/chsmack %{_bindir}/enlightenment-tests -a "System::Tools"
 
 %files
 %manifest %{name}.manifest
@@ -133,3 +144,7 @@ ln -sf %{_bindir}/enlightenment_input_key %{buildroot}%{_bindir}/input_keyevent
 %defattr(-,root,root,-)
 %{_includedir}/enlightenment/*
 %{_libdir}/pkgconfig/*.pc
+
+%files tests
+%defattr(-,root,root,-)
+%attr(550,root,root) %{_bindir}/enlightenment-tests
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644 (file)
index 0000000..97aaf93
--- /dev/null
@@ -0,0 +1,24 @@
+
+bin_PROGRAMS = enlightenment-tests
+
+enlightenment_tests_SOURCES = \
+       tc-main.cpp
+
+enlightenment_tests_CXXFLAGS = \
+       @DLOG_CFLAGS@ \
+       @GMOCK_CFLAGS@ \
+       @SUID_CFLAGS@ \
+       ${CXXFLAGS} \
+       -I$(top_builddir)/src/bin \
+       -I$(top_builddir)/src/modules
+
+enlightenment_tests_LDFLAGS = \
+       @DLOG_LIBS@ \
+       @GMOCK_LIBS@ \
+       @SUID_CFLAGS@ \
+       ${LDFLAGS} \
+       -lpthread
+
+check:
+       ./enlightenment-tests
+
diff --git a/tests/tc-main.cpp b/tests/tc-main.cpp
new file mode 100644 (file)
index 0000000..a24d9c0
--- /dev/null
@@ -0,0 +1,66 @@
+/**************************************************************************
+ *
+ * Copyright 2020 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
+ * Contact: Andrii Sokolenko <a.sokolenko@samsung.com>
+ * Contact: Roman Marchenko <r.marchenko@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;
+}