Add more subsurface tests

Add some more tests for the basic functioning of the subsurface API.
This commit is contained in:
Matthias Clasen 2024-04-14 08:58:52 -04:00
parent 3f9bdaa4c8
commit c995473407

View File

@ -1,6 +1,7 @@
#include <gtk/gtk.h>
#include "gdk/gdksurfaceprivate.h"
#include "gdk/gdksubsurfaceprivate.h"
#include "gdk/gdkdebugprivate.h"
#ifdef GDK_WINDOWING_WAYLAND
#include "gdk/wayland/gdkwayland.h"
@ -11,6 +12,53 @@
gdk_texture_get_width (t), \
gdk_texture_get_height (t))
static void
test_subsurface_basics (void)
{
GdkSurface *surface;
GdkSubsurface *sub;
GdkTexture *texture;
graphene_rect_t rect;
#ifdef GDK_WINDOWING_WAYLAND
if (!GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ()))
#endif
{
g_test_skip ("No subsurface support");
return;
}
surface = gdk_surface_new_toplevel (gdk_display_get_default ());
g_assert_true (surface->subsurfaces_below == NULL);
g_assert_true (surface->subsurfaces_above == NULL);
sub = gdk_surface_create_subsurface (surface);
g_assert_true (gdk_subsurface_get_parent (sub) == surface);
g_assert_null (gdk_subsurface_get_texture (sub));
g_assert_false (gdk_subsurface_is_above_parent (sub));
g_assert_true (gdk_subsurface_get_transform (sub) == GDK_TEXTURE_TRANSFORM_NORMAL);
texture = gdk_texture_new_from_resource ("/org/gtk/libgtk/icons/16x16/actions/media-eject.png");
gdk_subsurface_attach (sub, texture, &TEXTURE_RECT (texture), &GRAPHENE_RECT_INIT (0, 0, 10, 10), GDK_TEXTURE_TRANSFORM_90, &GRAPHENE_RECT_INIT (0, 0, 20, 20), TRUE, NULL);
g_assert_true (gdk_subsurface_get_texture (sub) == texture);
g_assert_true (gdk_subsurface_is_above_parent (sub));
g_assert_true (gdk_subsurface_get_transform (sub) == GDK_TEXTURE_TRANSFORM_90);
gdk_subsurface_get_source (sub, &rect);
g_assert_true (graphene_rect_equal (&rect, &TEXTURE_RECT (texture)));
gdk_subsurface_get_dest (sub, &rect);
g_assert_true (graphene_rect_equal (&rect, &GRAPHENE_RECT_INIT (0, 0, 10, 10)));
gdk_subsurface_get_background (sub, &rect);
g_assert_true (graphene_rect_equal (&rect, &GRAPHENE_RECT_INIT (0, 0, 20, 20)));
g_object_unref (sub);
g_object_unref (texture);
gdk_surface_destroy (surface);
}
static void
test_subsurface_stacking (void)
{
@ -103,6 +151,9 @@ main (int argc, char *argv[])
{
gtk_test_init (&argc, &argv, NULL);
gdk_display_set_debug_flags (gdk_display_get_default (), GDK_DEBUG_FORCE_OFFLOAD);
g_test_add_func ("/subsurface/basics", test_subsurface_basics);
g_test_add_func ("/subsurface/stacking", test_subsurface_stacking);
return g_test_run ();