xref: /openbmc/sdbusplus/test/meson.build (revision 2a12ae12)
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    'async/fdio',
27    'bus/exception',
28    'bus/list_names',
29    'bus/match',
30    'event/event',
31    'exception/sdbus_error',
32    'message/append',
33    'message/call',
34    'message/native_types',
35    'message/read',
36    'message/types',
37    'timer',
38    'unpack_properties',
39    'utility/tuple_to_array',
40    'utility/type_traits',
41]
42
43foreach t : tests
44    test(
45        'test_' + t.underscorify(),
46        executable(
47            'test-' + t.underscorify(),
48            t + '.cpp',
49            dependencies: [
50                gtest_dep,
51                gmock_dep,
52                sdbusplus_dep,
53            ],
54        )
55    )
56endforeach
57
58assert(
59    not get_option('tests').allowed() or boost_dep.found(),
60    'Boost is required when tests are enabled'
61)
62
63test(
64    'test-bus_aio',
65    executable(
66        'test-bus_aio',
67        'bus/aio.cpp',
68        dependencies: [
69            boost_dep,
70            gmock_dep,
71            gtest_dep,
72            sdbusplus_dep,
73        ],
74    )
75)
76
77test(
78    'test-vtable',
79    executable(
80        'test-vtable',
81        'vtable/vtable.cpp',
82        'vtable/vtable_c.c',
83        dependencies: [
84            gtest_dep,
85            sdbusplus_dep,
86        ],
87    ),
88)
89
90generated_sources = []
91generated_others = []
92subdir('gen')
93subdir('gen/server')
94
95server_test_pre = declare_dependency(
96    include_directories: include_directories('gen'),
97    dependencies: sdbusplus_dep)
98
99server_test_lib = static_library(
100    'server-test',
101    generated_sources,
102    implicit_include_directories: false,
103    dependencies: server_test_pre)
104
105generated_sources_header = []
106foreach s : generated_sources
107    foreach f : s.to_list()
108        if f.full_path().endswith('.hpp')
109            generated_sources_header += f
110        endif
111    endforeach
112endforeach
113
114server_test_dep = declare_dependency(
115  sources: generated_sources_header,
116  link_with: server_test_lib,
117  dependencies: server_test_pre)
118
119test(
120    'test-server',
121    executable(
122        'test-server',
123        'server/object.cpp',
124        dependencies: [
125            gmock_dep,
126            gtest_dep,
127            server_test_dep,
128        ],
129    ),
130)
131
132test(
133    'test-server-message-variant',
134    executable(
135        'test-server-message-variant',
136        'server/message_variant.cpp',
137        dependencies: [
138            gmock_dep,
139            gtest_dep,
140            server_test_dep,
141        ],
142    ),
143)
144