context/test: Make type derivable

This makes it possible to declare the type in an installed header (so
that e.g. META_CONTEXT_TEST(context) works), but without having to
expose the MetaContextClass struct.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1861>
This commit is contained in:
Jonas Ådahl 2021-05-10 09:15:02 +02:00
parent acb0a44224
commit 3d5a2b2ffb
2 changed files with 26 additions and 13 deletions

View File

@ -25,6 +25,7 @@
#include <glib.h> #include <glib.h>
#include <gio/gio.h> #include <gio/gio.h>
#include "core/meta-context-private.h"
#include "tests/meta-backend-test.h" #include "tests/meta-backend-test.h"
#include "tests/meta-test-utils.h" #include "tests/meta-test-utils.h"
#include "wayland/meta-wayland.h" #include "wayland/meta-wayland.h"
@ -44,15 +45,19 @@ enum
static guint signals[N_SIGNALS]; static guint signals[N_SIGNALS];
struct _MetaContextTest typedef struct _MetaContextTestPrivate
{ {
GObject parent;
MetaContextTestType type; MetaContextTestType type;
MetaContextTestFlag flags; MetaContextTestFlag flags;
} MetaContextTestPrivate;
struct _MetaContextTestClass
{
MetaContextClass parent_class;
}; };
G_DEFINE_TYPE (MetaContextTest, meta_context_test, META_TYPE_CONTEXT) G_DEFINE_TYPE_WITH_PRIVATE (MetaContextTest, meta_context_test,
META_TYPE_CONTEXT)
static gboolean static gboolean
meta_context_test_configure (MetaContext *context, meta_context_test_configure (MetaContext *context,
@ -61,6 +66,8 @@ meta_context_test_configure (MetaContext *context,
GError **error) GError **error)
{ {
MetaContextTest *context_test = META_CONTEXT_TEST (context); MetaContextTest *context_test = META_CONTEXT_TEST (context);
MetaContextTestPrivate *priv =
meta_context_test_get_instance_private (context_test);
MetaContextClass *context_class = MetaContextClass *context_class =
META_CONTEXT_CLASS (meta_context_test_parent_class); META_CONTEXT_CLASS (meta_context_test_parent_class);
const char *plugin_name; const char *plugin_name;
@ -71,7 +78,7 @@ meta_context_test_configure (MetaContext *context,
g_test_init (argc, argv, NULL); g_test_init (argc, argv, NULL);
g_test_bug_base ("https://gitlab.gnome.org/GNOME/mutter/issues/"); g_test_bug_base ("https://gitlab.gnome.org/GNOME/mutter/issues/");
if (context_test->flags & META_CONTEXT_TEST_FLAG_TEST_CLIENT) if (priv->flags & META_CONTEXT_TEST_FLAG_TEST_CLIENT)
meta_ensure_test_client_path (*argc, *argv); meta_ensure_test_client_path (*argc, *argv);
meta_wayland_override_display_name ("mutter-test-display"); meta_wayland_override_display_name ("mutter-test-display");
@ -95,8 +102,10 @@ static MetaX11DisplayPolicy
meta_context_test_get_x11_display_policy (MetaContext *context) meta_context_test_get_x11_display_policy (MetaContext *context)
{ {
MetaContextTest *context_test = META_CONTEXT_TEST (context); MetaContextTest *context_test = META_CONTEXT_TEST (context);
MetaContextTestPrivate *priv =
meta_context_test_get_instance_private (context_test);
if (context_test->flags & META_CONTEXT_TEST_FLAG_NO_X11) if (priv->flags & META_CONTEXT_TEST_FLAG_NO_X11)
return META_X11_DISPLAY_POLICY_DISABLED; return META_X11_DISPLAY_POLICY_DISABLED;
else else
return META_X11_DISPLAY_POLICY_ON_DEMAND; return META_X11_DISPLAY_POLICY_ON_DEMAND;
@ -159,8 +168,10 @@ meta_context_test_create_backend (MetaContext *context,
GError **error) GError **error)
{ {
MetaContextTest *context_test = META_CONTEXT_TEST (context); MetaContextTest *context_test = META_CONTEXT_TEST (context);
MetaContextTestPrivate *priv =
meta_context_test_get_instance_private (context_test);
switch (context_test->type) switch (priv->type)
{ {
case META_CONTEXT_TEST_TYPE_NESTED: case META_CONTEXT_TEST_TYPE_NESTED:
return create_nested_backend (context, error); return create_nested_backend (context, error);
@ -250,12 +261,14 @@ meta_create_test_context (MetaContextTestType type,
MetaContextTestFlag flags) MetaContextTestFlag flags)
{ {
MetaContextTest *context_test; MetaContextTest *context_test;
MetaContextTestPrivate *priv;
context_test = g_object_new (META_TYPE_CONTEXT_TEST, context_test = g_object_new (META_TYPE_CONTEXT_TEST,
"name", "Mutter Test", "name", "Mutter Test",
NULL); NULL);
context_test->type = type; priv = meta_context_test_get_instance_private (context_test);
context_test->flags = flags; priv->type = type;
priv->flags = flags;
return META_CONTEXT (context_test); return META_CONTEXT (context_test);
} }

View File

@ -21,7 +21,7 @@
#ifndef META_CONTEXT_TEST_H #ifndef META_CONTEXT_TEST_H
#define META_CONTEXT_TEST_H #define META_CONTEXT_TEST_H
#include "core/meta-context-private.h" #include "meta/meta-context.h"
typedef enum _MetaContextTestType typedef enum _MetaContextTestType
{ {
@ -39,9 +39,9 @@ typedef enum _MetaContextTestFlag
} MetaContextTestFlag; } MetaContextTestFlag;
#define META_TYPE_CONTEXT_TEST (meta_context_test_get_type ()) #define META_TYPE_CONTEXT_TEST (meta_context_test_get_type ())
G_DECLARE_FINAL_TYPE (MetaContextTest, meta_context_test, G_DECLARE_DERIVABLE_TYPE (MetaContextTest, meta_context_test,
META, CONTEXT_TEST, META, CONTEXT_TEST,
MetaContext) MetaContext)
MetaContext * meta_create_test_context (MetaContextTestType type, MetaContext * meta_create_test_context (MetaContextTestType type,
MetaContextTestFlag flags); MetaContextTestFlag flags);