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