mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 14:10:30 +00:00
gdk: Add some subsurface tests
Test that the stacking order is properly maintained.
This commit is contained in:
parent
32abe5b8bb
commit
906661d40b
@ -60,6 +60,7 @@ internal_tests = [
|
||||
{ 'name': 'image' },
|
||||
{ 'name': 'texture' },
|
||||
{ 'name': 'gltexture' },
|
||||
{ 'name': 'subsurface' },
|
||||
]
|
||||
|
||||
if host_machine.system() != 'windows'
|
||||
|
104
testsuite/gdk/subsurface.c
Normal file
104
testsuite/gdk/subsurface.c
Normal file
@ -0,0 +1,104 @@
|
||||
#include <gtk/gtk.h>
|
||||
#include "gdk/gdksurfaceprivate.h"
|
||||
#include "gdk/gdksubsurfaceprivate.h"
|
||||
|
||||
#ifdef GDK_WINDOWING_WAYLAND
|
||||
#include "gdk/wayland/gdkwayland.h"
|
||||
#endif
|
||||
|
||||
static void
|
||||
test_subsurface_stacking (void)
|
||||
{
|
||||
GdkSurface *surface;
|
||||
GdkSubsurface *sub0, *sub1, *sub2;
|
||||
GdkTexture *texture;
|
||||
|
||||
#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);
|
||||
|
||||
sub0 = gdk_surface_create_subsurface (surface);
|
||||
sub1 = gdk_surface_create_subsurface (surface);
|
||||
sub2 = gdk_surface_create_subsurface (surface);
|
||||
|
||||
g_assert_true (gdk_surface_get_n_subsurfaces (surface) == 3);
|
||||
g_assert_true (gdk_surface_get_subsurface (surface, 0) == sub0);
|
||||
g_assert_true (gdk_surface_get_subsurface (surface, 1) == sub1);
|
||||
g_assert_true (gdk_surface_get_subsurface (surface, 2) == sub2);
|
||||
|
||||
texture = gdk_texture_new_from_resource ("/org/gtk/libgtk/icons/16x16/actions/media-eject.png");
|
||||
|
||||
gdk_subsurface_attach (sub0, texture, &GRAPHENE_RECT_INIT (0, 0, 10, 10), TRUE, NULL);
|
||||
gdk_subsurface_attach (sub1, texture, &GRAPHENE_RECT_INIT (0, 0, 10, 10), TRUE, NULL);
|
||||
gdk_subsurface_attach (sub2, texture, &GRAPHENE_RECT_INIT (0, 0, 10, 10), TRUE, NULL);
|
||||
|
||||
g_assert_true (surface->subsurfaces_above == sub2);
|
||||
g_assert_true (sub2->sibling_below == NULL);
|
||||
g_assert_true (sub2->sibling_above == sub1);
|
||||
g_assert_true (sub2->above_parent);
|
||||
g_assert_true (sub1->sibling_below == sub2);
|
||||
g_assert_true (sub1->sibling_above == sub0);
|
||||
g_assert_true (sub1->above_parent);
|
||||
g_assert_true (sub0->sibling_below == sub1);
|
||||
g_assert_true (sub0->sibling_above == NULL);
|
||||
g_assert_true (sub0->above_parent);
|
||||
|
||||
gdk_subsurface_detach (sub1);
|
||||
|
||||
g_assert_true (surface->subsurfaces_above == sub2);
|
||||
g_assert_true (sub2->sibling_below == NULL);
|
||||
g_assert_true (sub2->sibling_above == sub0);
|
||||
g_assert_true (sub2->above_parent);
|
||||
g_assert_true (sub0->sibling_below == sub2);
|
||||
g_assert_true (sub0->sibling_above == NULL);
|
||||
g_assert_true (sub0->above_parent);
|
||||
|
||||
gdk_subsurface_attach (sub2, texture, &GRAPHENE_RECT_INIT (0, 0, 10, 10), FALSE, NULL);
|
||||
|
||||
g_assert_true (surface->subsurfaces_above == sub0);
|
||||
g_assert_true (sub0->sibling_below == NULL);
|
||||
g_assert_true (sub0->sibling_above == NULL);
|
||||
g_assert_true (sub0->above_parent);
|
||||
|
||||
g_assert_true (surface->subsurfaces_below == sub2);
|
||||
g_assert_true (sub2->sibling_below == NULL);
|
||||
g_assert_true (sub2->sibling_above == NULL);
|
||||
g_assert_false (sub2->above_parent);
|
||||
|
||||
gdk_subsurface_attach (sub1, texture, &GRAPHENE_RECT_INIT (0, 0, 10, 10), TRUE, sub2);
|
||||
|
||||
g_assert_true (surface->subsurfaces_below == sub1);
|
||||
g_assert_true (sub1->sibling_above == NULL);
|
||||
g_assert_true (sub1->sibling_below == sub2);
|
||||
g_assert_false (sub1->above_parent);
|
||||
g_assert_true (sub2->sibling_above == sub1);
|
||||
g_assert_true (sub2->sibling_below == NULL);
|
||||
g_assert_false (sub2->above_parent);
|
||||
|
||||
g_object_unref (sub0);
|
||||
g_object_unref (sub1);
|
||||
g_object_unref (sub2);
|
||||
|
||||
g_object_unref (texture);
|
||||
|
||||
gdk_surface_destroy (surface);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
gtk_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/subsurface/stacking", test_subsurface_stacking);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
Loading…
Reference in New Issue
Block a user