George Liu | 208acee | 2022-05-10 14:01:30 +0800 | [diff] [blame] | 1 | gtest_dep = dependency('gtest', main: true, disabler: true, required: false) |
| 2 | gmock_dep = dependency('gmock', disabler: true, required: false) |
| 3 | if 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( |
Patrick Williams | 6c79a72 | 2023-11-29 06:44:14 -0600 | [diff] [blame^] | 16 | not get_option('tests').allowed(), |
George Liu | 208acee | 2022-05-10 14:01:30 +0800 | [diff] [blame] | 17 | 'Googletest is required if tests are enabled' |
| 18 | ) |
| 19 | endif |
| 20 | endif |
| 21 | |
| 22 | test_sources = [ |
| 23 | '../snmp_conf_manager.cpp', |
| 24 | '../snmp_client.cpp', |
| 25 | '../snmp_serialize.cpp', |
| 26 | '../snmp_util.cpp', |
| 27 | ] |
| 28 | |
| 29 | tests = [ |
| 30 | 'test_error_notification.cpp', |
| 31 | 'test_snmp_conf_manager.cpp', |
| 32 | 'test_snmp_util.cpp', |
| 33 | 'test_snmp_serialize.cpp', |
| 34 | 'test_snmp_client.cpp', |
| 35 | ] |
| 36 | |
| 37 | foreach t : tests |
| 38 | test(t, executable(t.underscorify(), t, |
| 39 | test_sources, |
| 40 | include_directories: ['..'], |
| 41 | dependencies: [ |
| 42 | gtest_dep, |
| 43 | gmock_dep, |
| 44 | deps |
| 45 | ]), |
| 46 | workdir: meson.current_source_dir()) |
| 47 | endforeach |