add libds-tests 47/279247/1
authorSooChan Lim <sc1.lim@samsung.com>
Thu, 4 Aug 2022 01:06:17 +0000 (10:06 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Thu, 4 Aug 2022 08:36:04 +0000 (17:36 +0900)
libds-tests is unit tests using gtest framwork.

Change-Id: I323fe81972d8f79018a39b55c820052c090db40c

meson.build
meson_options.txt
packaging/libds.spec
tests/meson.build
tests/tc_main.cpp [new file with mode: 0644]
tests/tc_main.h [new file with mode: 0644]

index 03d6bc7..22f625e 100644 (file)
@@ -1,4 +1,5 @@
-project('libds', 'c',
+project('libds',
+  ['c', 'cpp'],
   license: 'MIT',
   version: '0.1.2',
   default_options: [
@@ -52,7 +53,9 @@ wayland_scanner = find_program(
 )
 
 subdir('src')
-subdir('tests')
+if get_option('tests')
+  subdir('tests')
+endif
 subdir('examples')
 subdir('clients')
 subdir('include')
index e69de29..193594f 100644 (file)
@@ -0,0 +1 @@
+option('tests', description: 'Display Server tests', type: 'boolean', value: 'false')
index ac79499..43071ed 100644 (file)
@@ -16,6 +16,7 @@ BuildRequires:  pkgconfig(libdrm)
 BuildRequires:  pkgconfig(xkbcommon)
 BuildRequires:  pkgconfig(libinput)
 BuildRequires:  pkgconfig(libudev)
+BuildRequires:  pkgconfig(gmock)
 
 %description
 Wayland Compositor Library
@@ -52,6 +53,7 @@ meson setup \
     --prefix /usr \
     --libdir %{_libdir} \
     --bindir %{_bindir} \
+    -Dtests=true \
     builddir
 ninja -C builddir all
 
@@ -77,6 +79,7 @@ ninja -C builddir install
 %{_bindir}/input-device-test
 %{_bindir}/libinput-backend
 %{_bindir}/ds-simple-shm-shell
+%{_bindir}/libds-tests
 
 %files xdg-shell-v6
 %manifest %{name}.manifest
index dd52176..6314d8a 100644 (file)
@@ -1,25 +1,15 @@
-tests = [
-  { 'name': 'test-compositor' },
-  { 'name': 'test-backend' },
-  { 
-    'name': 'test-surface',
-    'deps': [ dependency('wayland-client') ],
-  },
-  {
-    'name': 'test-subsurface',
-    'deps': [ dependency('wayland-client') ],
-  },
+test_files = [
+  'tc_main.cpp',
 ]
 
-foreach t : tests
-  t_deps = [ dep_libds ]
-  t_deps += t.get('deps', [])
-
-  test('libds-' + t.get('name'),
-    executable('libds-' + t.get('name'), t.get('name') + '.c',
-      dependencies: t_deps ,
-      include_directories: common_inc,
-      install: false
-    )
-  )
-endforeach
+executable('libds-tests',
+  test_files,
+  dependencies: [
+    libds_deps,
+    dependency('gmock', required: true),
+    dependency('wayland-client', required: true),
+    dependency('libdrm', required: true),
+  ],
+  install_dir: libds_bindir,
+  install : true
+)
diff --git a/tests/tc_main.cpp b/tests/tc_main.cpp
new file mode 100644 (file)
index 0000000..5e99a34
--- /dev/null
@@ -0,0 +1,26 @@
+#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;
+}
diff --git a/tests/tc_main.h b/tests/tc_main.h
new file mode 100644 (file)
index 0000000..41e630a
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef TC_MAIN_H
+#define TC_MAIN_H
+
+#include <iostream>
+#include <gmock/gmock.h>
+
+using ::testing::Bool;
+using ::testing::Combine;
+using ::testing::TestWithParam;
+using ::testing::Values;
+
+#endif