meson: Add meson build for test

This commit is to add meson build for test.
and later, we will remove autotools and replace it with meson.

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Ia36cec4eda7937461f62f43dd74907e82a164bf6
diff --git a/meson.build b/meson.build
index f8de17d..d62d0ff 100644
--- a/meson.build
+++ b/meson.build
@@ -125,3 +125,8 @@
     install: true,
     install_dir: get_option('bindir'),
 )
+
+build_tests = get_option('tests')
+if not build_tests.disabled()
+    subdir('test')
+endif
diff --git a/meson_options.txt b/meson_options.txt
index 8d5578a..3c8b28b 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,4 +1,10 @@
 option(
+    'tests', type : 'feature',
+    value: 'enabled',
+    description : 'Build tests'
+)
+
+option(
     'associations', type : 'feature',
     value: 'enabled',
     description : 'Enable creating D-Bus associations from a JSON definition'
diff --git a/test/meson.build b/test/meson.build
new file mode 100644
index 0000000..3039090
--- /dev/null
+++ b/test/meson.build
@@ -0,0 +1,56 @@
+gtest_dep = dependency('gtest', main: true, disabler: true, required: false)
+gmock_dep = dependency('gmock', disabler: true, required: false)
+if not gtest_dep.found() or not gmock_dep.found()
+    gtest_proj = import('cmake').subproject('googletest', required: false)
+    if gtest_proj.found()
+        gtest_dep = declare_dependency(
+            dependencies: [
+                dependency('threads'),
+                gtest_proj.dependency('gtest'),
+                gtest_proj.dependency('gtest_main'),
+            ]
+        )
+        gmock_dep = gtest_proj.dependency('gmock')
+    else
+        assert(
+            not get_option('tests').enabled(),
+            'Googletest is required if tests are enabled'
+        )
+    endif
+endif
+
+test_sources = [
+    generated_cpp,
+    gen_serialization_hpp,
+    '../association_manager.cpp',
+    '../manager.cpp',
+    '../functor.cpp',
+    '../errors.cpp',
+]
+
+tests = [
+    'associations_test.cpp',
+    'interface_ops_test.cpp',
+    'manager_test.cpp',
+    'serialize_test.cpp',
+    'types_test.cpp',
+    'utils_test.cpp',
+]
+
+test_deps = [
+    sdbusplus_dep,
+    phosphor_dbus_interfaces_dep,
+    phosphor_logging_dep,
+]
+
+foreach t : tests
+    test(t, executable(t.underscorify(), t,
+                     test_sources,
+                     include_directories: ['..'],
+                     dependencies: [
+                         gtest_dep,
+                         gmock_dep,
+                         test_deps,
+                         ]),
+        workdir: meson.current_source_dir())
+endforeach