[mutter] tests/cogl: Add unit test framework



commit 9a9e7e471c9cb4824f7f953673552e960b602136
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Thu Aug 4 23:25:00 2022 +0200

    tests/cogl: Add unit test framework
    
    It consists of only a macro and build description logic.
    
    Adds a macro for simpler tests that doesn't require a context; unit
    tests requiring a context should use the same framework as conform
    tests.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2555>

 cogl/cogl/cogl-macros.h         |  1 +
 src/tests/cogl-test-utils.h     | 12 ++++++++++++
 src/tests/cogl/meson.build      |  1 +
 src/tests/cogl/unit/meson.build | 38 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 52 insertions(+)
---
diff --git a/cogl/cogl/cogl-macros.h b/cogl/cogl/cogl-macros.h
index b81035d2c7..f7001d8117 100644
--- a/cogl/cogl/cogl-macros.h
+++ b/cogl/cogl/cogl-macros.h
@@ -74,5 +74,6 @@
 #endif /* COGL_DISABLE_DEPRECATION_WARNINGS */
 
 #define COGL_EXPORT __attribute__((visibility("default"))) extern
+#define COGL_EXPORT_TEST __attribute__((visibility("default"))) extern
 
 #endif /* __COGL_MACROS_H__ */
diff --git a/src/tests/cogl-test-utils.h b/src/tests/cogl-test-utils.h
index 868faaa1ed..66e80c7ce9 100644
--- a/src/tests/cogl-test-utils.h
+++ b/src/tests/cogl-test-utils.h
@@ -66,6 +66,18 @@ main (int    argc, \
                                       META_TEST_RUN_FLAG_NONE); \
 }
 
+#define COGL_TEST_SUITE_MINIMAL(units) \
+int \
+main (int    argc, \
+      char **argv) \
+{ \
+  g_test_init (&argc, &argv, NULL); \
+\
+  units \
+\
+  return g_test_run (); \
+}
+
 MetaContext * meta_create_cogl_test_context (int    argc,
                                              char **argv);
 
diff --git a/src/tests/cogl/meson.build b/src/tests/cogl/meson.build
index 3f06af70b3..5ae7546ad2 100644
--- a/src/tests/cogl/meson.build
+++ b/src/tests/cogl/meson.build
@@ -1 +1,2 @@
 subdir('conform')
+subdir('unit')
diff --git a/src/tests/cogl/unit/meson.build b/src/tests/cogl/unit/meson.build
new file mode 100644
index 0000000000..c4c4f33598
--- /dev/null
+++ b/src/tests/cogl/unit/meson.build
@@ -0,0 +1,38 @@
+cogl_unit_tests = [
+]
+
+test_env = environment()
+test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
+test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
+test_env.set('G_ENABLE_DIAGNOSTIC', '0')
+test_env.set('MUTTER_TEST_PLUGIN_PATH', '@0@'.format(default_plugin.full_path()))
+
+foreach unit_test: cogl_unit_tests
+  test_name = 'cogl-' + unit_test
+
+  test_executable = executable(test_name,
+    sources: [
+      unit_test + '.c',
+      cogl_test_utils,
+    ],
+    c_args: [
+      '-D__COGL_H_INSIDE__',
+      '-DCOGL_ENABLE_MUTTER_API',
+      '-DCOGL_ENABLE_EXPERIMENTAL_API',
+      '-DCOGL_DISABLE_DEPRECATED',
+      '-DCOGL_DISABLE_DEPRECATION_WARNINGS',
+    ],
+    include_directories: [
+      cogl_includepath,
+    ],
+    dependencies: [
+      libmutter_test_dep,
+    ],
+  )
+
+  test(test_name, test_executable,
+    suite: ['cogl', 'cogl/unit'],
+    env: test_env,
+    is_parallel: false,
+  )
+endforeach


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]