libds-tests is unit tests using gtest framwork.
Change-Id: I323fe81972d8f79018a39b55c820052c090db40c
-project('libds', 'c',
+project('libds',
+ ['c', 'cpp'],
license: 'MIT',
version: '0.1.2',
default_options: [
)
subdir('src')
-subdir('tests')
+if get_option('tests')
+ subdir('tests')
+endif
subdir('examples')
subdir('clients')
subdir('include')
+option('tests', description: 'Display Server tests', type: 'boolean', value: 'false')
BuildRequires: pkgconfig(xkbcommon)
BuildRequires: pkgconfig(libinput)
BuildRequires: pkgconfig(libudev)
+BuildRequires: pkgconfig(gmock)
%description
Wayland Compositor Library
--prefix /usr \
--libdir %{_libdir} \
--bindir %{_bindir} \
+ -Dtests=true \
builddir
ninja -C builddir all
%{_bindir}/input-device-test
%{_bindir}/libinput-backend
%{_bindir}/ds-simple-shm-shell
+%{_bindir}/libds-tests
%files xdg-shell-v6
%manifest %{name}.manifest
-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
+)
--- /dev/null
+#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;
+}
--- /dev/null
+#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