12to11/tests/simple_test.c
hujianwei 5d033bc93f Add new damage test and unify buffer release code in xdg_surface
* 12to11-test.xml (test_surface): <description>: Document when
frame callbacks are run.
* 12to11.c (HandleCmdline): Accept new arg `printsocket'.
(XLMain): Pass socket to HandleCmdline.
* 12to11.man: Document new `printsocket' option.
* mime0.awk:
* mime1.awk:
* mime2.awk:
* mime3.awk:
* mime4.awk: Fix typos in copyright blurb.
* test.c (NoteBounds): Sync with X server after XResizeWindow.
(Commit): Run frame callbacks after unmap as well.
(GetTestSurface): Make windows override redirect.

* tests/Imakefile (SRCS2, OBJS2): New program.
(PROGRAMS): Add damage_test.
(damage_test): New program.  Depend on SRCS2.
* tests/README: Improve documentation on how to run tests.
* tests/simple_test.c (test_names): New list.
(LAST_TEST): New define.
(verify_single_step): Complete test upon last test being run.
(test_single_step): Submit correct surface damage.
(test_next_step): New function.  Does nothing here.
(handle_wl_callback_done): Run the next test.
(submit_surface_damage): New function.
* tests/svnignore.txt: Add damage_test and Makefile.bak.
* tests/test_harness.c (test_complete): New function.
* tests/test_harness.h: New prototypes.
* xdg_surface.c (struct _XdgRole): Use a buffer release helper.
(struct _ReleaseLaterRecord, DeleteRecord, FreeRecords)
(AddRecordAfter): Delete unused structs and functions.
(RunFrameCallbacksConditionally, BufferIdleCallback)
(ReleaseBacking, ReleaseBuffer, XLGetXdgSurface): Use and free
buffer release helper; run frame callbacks from its callback.
2022-11-04 05:36:10 +00:00

223 lines
4.9 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* Tests for the Wayland compositor running on the X server.
Copyright (C) 2022 to various contributors.
This file is part of 12to11.
12to11 is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
12to11 is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with 12to11. If not, see <https://www.gnu.org/licenses/>. */
#include "test_harness.h"
enum test_kind
{
MAP_WINDOW_KIND,
BASIC_TEST_CARD_IMAGE_KIND,
};
static const char *test_names[] =
{
"map_window",
"basic_test_card_image",
};
#define LAST_TEST BASIC_TEST_CARD_IMAGE_KIND
/* The display. */
static struct test_display *display;
/* Test interfaces. */
static struct test_interface test_interfaces[] =
{
/* No interfaces yet. */
};
/* The test surface window. */
static Window test_surface_window;
/* The test surface and Wayland surface. */
static struct test_surface *test_surface;
static struct wl_surface *wayland_surface;
/* Forward declarations. */
static void submit_frame_callback (struct wl_surface *, enum test_kind);
static void submit_surface_damage (struct wl_surface *, int, int, int, int);
static void
verify_single_step (enum test_kind kind)
{
switch (kind)
{
case BASIC_TEST_CARD_IMAGE_KIND:
verify_image_data (display, test_surface_window,
"simple_test.dump");
break;
default:
break;
}
if (kind == LAST_TEST)
test_complete ();
}
static void
test_single_step (enum test_kind kind)
{
struct wl_buffer *buffer;
test_log ("running test step: %s", test_names[kind]);
switch (kind)
{
case MAP_WINDOW_KIND:
buffer = load_png_image (display, "blue.png");
if (!buffer)
report_test_failure ("failed to load blue.png");
wl_surface_attach (wayland_surface, buffer, 0, 0);
submit_surface_damage (wayland_surface, 0, 0,
INT_MAX, INT_MAX);
wl_surface_commit (wayland_surface);
wl_buffer_destroy (buffer);
break;
case BASIC_TEST_CARD_IMAGE_KIND:
buffer = load_png_image (display, "basic_test_card.png");
if (!buffer)
report_test_failure ("failed to load basic_test_card.png");
wl_surface_attach (wayland_surface, buffer, 0, 0);
submit_frame_callback (wayland_surface, kind);
submit_surface_damage (wayland_surface, 0, 0,
INT_MAX, INT_MAX);
wl_surface_commit (wayland_surface);
wl_buffer_destroy (buffer);
break;
}
}
static void
test_next_step (enum test_kind kind)
{
switch (kind)
{
default:
break;
}
}
static void
handle_test_surface_mapped (void *data, struct test_surface *surface,
uint32_t xid, const char *display_string)
{
/* Sleep for 1 second to ensure that the window is exposed and
redirected. */
sleep (1);
/* Start the test. */
test_surface_window = xid;
/* Run the test again. */
test_single_step (BASIC_TEST_CARD_IMAGE_KIND);
}
static const struct test_surface_listener test_surface_listener =
{
handle_test_surface_mapped,
};
static void
handle_wl_callback_done (void *data, struct wl_callback *callback,
uint32_t callback_data)
{
enum test_kind kind;
/* kind is not a pointer. It is an enum test_kind stuffed into a
pointer. */
kind = (intptr_t) data;
wl_callback_destroy (callback);
verify_single_step (kind);
/* Now run the next test in this sequence. */
test_next_step (kind);
}
static const struct wl_callback_listener wl_callback_listener =
{
handle_wl_callback_done,
};
static void
submit_frame_callback (struct wl_surface *surface, enum test_kind kind)
{
struct wl_callback *callback;
callback = wl_surface_frame (surface);
wl_callback_add_listener (callback, &wl_callback_listener,
(void *) (intptr_t) kind);
}
static void
submit_surface_damage (struct wl_surface *surface, int x, int y, int width,
int height)
{
test_log ("damaging surface by %d, %d, %d, %d", x, y, width,
height);
wl_surface_damage (surface, x, y, width, height);
}
static void
run_test (void)
{
if (!make_test_surface (display, &wayland_surface,
&test_surface))
report_test_failure ("failed to create test surface");
test_surface_add_listener (test_surface, &test_surface_listener,
NULL);
test_single_step (MAP_WINDOW_KIND);
while (true)
{
if (wl_display_dispatch (display->display) == -1)
die ("wl_display_dispatch");
}
}
int
main (void)
{
test_init ();
display = open_test_display (test_interfaces,
ARRAYELTS (test_interfaces));
if (!display)
report_test_failure ("failed to open display");
run_test ();
}