context/test: Add 'no-x11' and 'test-client' constructor flags

The 'no-x11' one will inhibit Xwayland from starting, and 'test-client'
will make sure the test client path is properly discovered.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1861>
This commit is contained in:
Jonas Ådahl 2021-03-03 10:42:26 +01:00
parent 07384e18c5
commit 2f19a5f28d
8 changed files with 35 additions and 9 deletions

View File

@ -170,7 +170,8 @@ main (int argc, char *argv[])
{
g_autoptr (MetaContext) context = NULL;
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED);
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED,
META_CONTEXT_TEST_FLAG_NO_X11);
g_assert (meta_context_configure (context, &argc, &argv, NULL));
init_tests ();

View File

@ -25,6 +25,7 @@
#include <glib.h>
#include <gio/gio.h>
#include "core/main-private.h"
#include "tests/meta-backend-test.h"
#include "tests/test-utils.h"
#include "wayland/meta-wayland.h"
@ -49,6 +50,7 @@ struct _MetaContextTest
GObject parent;
MetaContextTestType type;
MetaContextTestFlag flags;
};
G_DEFINE_TYPE (MetaContextTest, meta_context_test, META_TYPE_CONTEXT)
@ -59,6 +61,7 @@ meta_context_test_configure (MetaContext *context,
char ***argv,
GError **error)
{
MetaContextTest *context_test = META_CONTEXT_TEST (context);
MetaContextClass *context_class =
META_CONTEXT_CLASS (meta_context_test_parent_class);
const char *plugin_name;
@ -69,7 +72,8 @@ meta_context_test_configure (MetaContext *context,
g_test_init (argc, argv, NULL);
g_test_bug_base ("https://gitlab.gnome.org/GNOME/mutter/issues/");
meta_ensure_test_client_path (*argc, *argv);
if (context_test->flags & META_CONTEXT_TEST_FLAG_TEST_CLIENT)
meta_ensure_test_client_path (*argc, *argv);
meta_wayland_override_display_name ("mutter-test-display");
meta_xwayland_override_display_number (512);
@ -224,7 +228,8 @@ meta_context_test_run_tests (MetaContextTest *context_test)
}
MetaContext *
meta_create_test_context (MetaContextTestType type)
meta_create_test_context (MetaContextTestType type,
MetaContextTestFlag flags)
{
MetaContextTest *context_test;
@ -232,6 +237,12 @@ meta_create_test_context (MetaContextTestType type)
"name", "Mutter Test",
NULL);
context_test->type = type;
context_test->flags = flags;
/* NOTE: This will be removed in a follow up commit, but is needed
* until the override method is replaced. */
if (flags & META_CONTEXT_TEST_FLAG_NO_X11)
meta_override_x11_display_policy (META_X11_DISPLAY_POLICY_DISABLED);
return META_CONTEXT (context_test);
}

View File

@ -31,12 +31,21 @@ typedef enum _MetaContextTestType
META_CONTEXT_TEST_TYPE_NESTED,
} MetaContextTestType;
typedef enum _MetaContextTestFlag
{
META_CONTEXT_TEST_FLAG_NONE = 0,
META_CONTEXT_TEST_FLAG_TEST_CLIENT = 1 << 0,
META_CONTEXT_TEST_FLAG_NO_X11 = 1 << 1,
} MetaContextTestFlag;
#define META_TYPE_CONTEXT_TEST (meta_context_test_get_type ())
G_DECLARE_FINAL_TYPE (MetaContextTest, meta_context_test,
META, CONTEXT_TEST,
MetaContext)
MetaContext * meta_create_test_context (MetaContextTestType type);
MetaContext * meta_create_test_context (MetaContextTestType type,
MetaContextTestFlag flags);
int meta_context_test_run_tests (MetaContextTest *context_test);

View File

@ -37,7 +37,8 @@ main (int argc,
{
g_autoptr (MetaContext) context = NULL;
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS);
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS,
META_CONTEXT_TEST_FLAG_NO_X11);
g_assert (meta_context_configure (context, &argc, &argv, NULL));
init_tests ();

View File

@ -133,7 +133,8 @@ main (int argc,
{
g_autoptr (MetaContext) context = NULL;
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS);
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS,
META_CONTEXT_TEST_FLAG_NO_X11);
g_assert (meta_context_configure (context, &argc, &argv, NULL));
init_ref_test_sanity_tests ();

View File

@ -1161,7 +1161,8 @@ main (int argc, char *argv[])
{
g_autoptr (MetaContext) context = NULL;
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED);
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED,
META_CONTEXT_TEST_FLAG_NO_X11);
g_assert (meta_context_configure (context, &argc, &argv, NULL));
init_tests ();

View File

@ -1124,7 +1124,8 @@ main (int argc, char **argv)
GPtrArray *tests;
RunTestsInfo info;
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED);
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED,
META_CONTEXT_TEST_FLAG_TEST_CLIENT);
meta_context_add_option_entries (context, options, NULL);

View File

@ -235,7 +235,8 @@ main (int argc, char *argv[])
{
g_autoptr (MetaContext) context = NULL;
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED);
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED,
META_CONTEXT_TEST_FLAG_TEST_CLIENT);
g_assert (meta_context_configure (context, &argc, &argv, NULL));
init_tests ();