From 9a9e7e471c9cb4824f7f953673552e960b602136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 4 Aug 2022 23:25:00 +0200 Subject: [PATCH] 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: --- 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(+) create mode 100644 src/tests/cogl/unit/meson.build diff --git a/cogl/cogl/cogl-macros.h b/cogl/cogl/cogl-macros.h index b81035d2c..f7001d811 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 868faaa1e..66e80c7ce 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 3f06af70b..5ae7546ad 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 000000000..c4c4f3359 --- /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