From 0152286fa0a585e729d0a39efc1dc926b11b0ab2 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 15 May 2023 16:49:12 -0400 Subject: [PATCH] Improve test coverage for GdkGLContext --- testsuite/gdk/glcontext.c | 82 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/testsuite/gdk/glcontext.c b/testsuite/gdk/glcontext.c index 2f825ac121..2fecec2f24 100644 --- a/testsuite/gdk/glcontext.c +++ b/testsuite/gdk/glcontext.c @@ -67,6 +67,85 @@ test_allowed_backends (gconstpointer data) g_object_unref (context); } +static void +test_use_es (void) +{ + GdkDisplay *display; + GdkGLContext *context; + GError *error = NULL; + GdkGLAPI allowed_apis, api; + GdkGLContext *shared; + + display = gdk_display_get_default (); + if (!gdk_display_prepare_gl (display, &error)) + { + g_test_skip_printf ("no GL support: %s", error->message); + g_clear_error (&error); + return; + } + + context = gdk_display_create_gl_context (display, &error); + g_assert_nonnull (context); + g_assert_no_error (error); + + g_object_set (context, "allowed-apis", GDK_GL_API_GL | GDK_GL_API_GLES, NULL); + +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + gdk_gl_context_set_use_es (context, 1); + g_assert_true (gdk_gl_context_get_allowed_apis (context) == GDK_GL_API_GLES); + gdk_gl_context_set_use_es (context, 0); + g_assert_true (gdk_gl_context_get_allowed_apis (context) == GDK_GL_API_GL); + gdk_gl_context_set_use_es (context, -1); + g_assert_true (gdk_gl_context_get_allowed_apis (context) == (GDK_GL_API_GL | GDK_GL_API_GLES)); +G_GNUC_END_IGNORE_DEPRECATIONS + + api = gdk_gl_context_realize (context, &error); + g_assert_no_error (error); + g_assert_true (api != 0); + + g_object_get (context, + "allowed-apis", &allowed_apis, + "api", &api, + "shared-context", &shared, + NULL); + + g_assert_true (allowed_apis == (GDK_GL_API_GL | GDK_GL_API_GLES)); + g_assert_true (api == GDK_GL_API_GL || api == GDK_GL_API_GLES); + g_assert_null (shared); + + g_object_unref (context); +} + +static void +test_version (void) +{ + GdkDisplay *display; + GdkGLContext *context; + GError *error = NULL; + int major, minor; + + display = gdk_display_get_default (); + if (!gdk_display_prepare_gl (display, &error)) + { + g_test_skip_printf ("no GL support: %s", error->message); + g_clear_error (&error); + return; + } + + context = gdk_display_create_gl_context (display, &error); + g_assert_nonnull (context); + g_assert_no_error (error); + + gdk_gl_context_get_required_version (context, &major, &minor); + g_assert_true (major == 0 && minor == 0); + + gdk_gl_context_set_required_version (context, 4, 0); + gdk_gl_context_get_required_version (context, &major, &minor); + g_assert_true (major == 4 && minor == 0); + + g_object_unref (context); +} + int main (int argc, char *argv[]) { @@ -77,5 +156,8 @@ main (int argc, char *argv[]) g_test_add_data_func ("/allowed-apis/gles", GSIZE_TO_POINTER (GDK_GL_API_GLES), test_allowed_backends); g_test_add_data_func ("/allowed-apis/all", GSIZE_TO_POINTER (GDK_GL_API_GL | GDK_GL_API_GLES), test_allowed_backends); + g_test_add_func ("/allowed-apis/use-es", test_use_es); + g_test_add_func ("/allowed-apis/version", test_version); + return g_test_run (); } -- 2.30.2