xref: /openbmc/sdbusplus/test/meson.build (revision 44c6013c)
1gtest_dep = dependency('gtest', main: true, disabler: true, required: false)
2gmock_dep = dependency('gmock', disabler: true, required: false)
3if not gtest_dep.found() or not gmock_dep.found()
4    gtest_proj = import('cmake').subproject('googletest', required: false)
5    if gtest_proj.found()
6        gtest_dep = declare_dependency(
7            dependencies: [
8                dependency('threads'),
9                gtest_proj.dependency('gtest'),
10                gtest_proj.dependency('gtest_main'),
11            ]
12        )
13        gmock_dep = gtest_proj.dependency('gmock')
14    else
15        assert(
16            not get_option('tests').enabled(),
17            'Googletest is required if tests are enabled'
18        )
19    endif
20endif
21
22tests = [
23    'async/context',
24    'async/task',
25    'async/timer',
26    'bus/list_names',
27    'bus/match',
28    'event/event',
29    'exception/sdbus_error',
30    'message/append',
31    'message/call',
32    'message/native_types',
33    'message/read',
34    'message/types',
35    'timer',
36    'unpack_properties',
37    'utility/tuple_to_array',
38    'utility/type_traits',
39]
40
41foreach t : tests
42    test(
43        'test_' + t.underscorify(),
44        executable(
45            'test-' + t.underscorify(),
46            t + '.cpp',
47            dependencies: [
48                gtest_dep,
49                gmock_dep,
50                sdbusplus_dep,
51            ],
52        )
53    )
54endforeach
55
56assert(
57    not get_option('tests').enabled() or boost_dep.found(),
58    'Boost is required when tests are enabled'
59)
60
61test(
62    'test-bus_aio',
63    executable(
64        'test-bus_aio',
65        'bus/aio.cpp',
66        dependencies: [
67            boost_dep,
68            gmock_dep,
69            gtest_dep,
70            sdbusplus_dep,
71        ],
72    )
73)
74
75test(
76    'test-vtable',
77    executable(
78        'test-vtable',
79        'vtable/vtable.cpp',
80        'vtable/vtable_c.c',
81        dependencies: [
82            gtest_dep,
83            sdbusplus_dep,
84        ],
85    ),
86)
87
88generated_sources = []
89generated_others = []
90subdir('gen')
91subdir('gen/server')
92
93server_test_pre = declare_dependency(
94    include_directories: include_directories('gen'),
95    dependencies: sdbusplus_dep)
96
97server_test_lib = static_library(
98    'server-test',
99    generated_sources,
100    implicit_include_directories: false,
101    dependencies: server_test_pre)
102
103generated_sources_header = []
104foreach s : generated_sources
105    foreach f : s.to_list()
106        if f.full_path().endswith('.hpp')
107            generated_sources_header += f
108        endif
109    endforeach
110endforeach
111
112server_test_dep = declare_dependency(
113  sources: generated_sources_header,
114  link_with: server_test_lib,
115  dependencies: server_test_pre)
116
117test(
118    'test-server',
119    executable(
120        'test-server',
121        'server/object.cpp',
122        dependencies: [
123            gmock_dep,
124            gtest_dep,
125            server_test_dep,
126        ],
127    ),
128)
129
130test(
131    'test-server-message-variant',
132    executable(
133        'test-server-message-variant',
134        'server/message_variant.cpp',
135        dependencies: [
136            gmock_dep,
137            gtest_dep,
138            server_test_dep,
139        ],
140    ),
141)
142