summaryrefslogtreecommitdiff
path: root/tests/x11/test_state.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/x11/test_state.c')
-rw-r--r--tests/x11/test_state.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/x11/test_state.c b/tests/x11/test_state.c
new file mode 100644
index 0000000..abdda95
--- /dev/null
+++ b/tests/x11/test_state.c
@@ -0,0 +1,77 @@
+/* Supply native window-state properties without requiring an X server. */
+#define XGetWindowProperty state_property
+#include "../../src/platform/x11/window.c"
+#undef XGetWindowProperty
+
+static Atom properties[3];
+static unsigned long property_count;
+static int notifications;
+static uint32_t reported_state;
+
+int state_property(Display *display, Window window, Atom property,
+ long offset, long length, Bool delete_property, Atom type,
+ Atom *actual, int *format, unsigned long *count, unsigned long *left,
+ unsigned char **data)
+{
+ assert(display && window == 42 && property == 10);
+ assert(!offset && length >= 3 && !delete_property && type == XA_ATOM);
+ *actual = XA_ATOM;
+ *format = 32;
+ *count = property_count;
+ *left = 0;
+ *data = NULL;
+ if (property_count) {
+ *data = malloc(property_count * sizeof(*properties));
+ assert(*data);
+ memcpy(*data, properties, property_count * sizeof(*properties));
+ }
+ return Success;
+}
+
+static void state_changed(struct yasl_surface *surface, uint32_t state, void *ud)
+{
+ (void)ud;
+ assert(yasl_surface_state(surface) == state);
+ reported_state = state;
+ notifications++;
+}
+
+int main(void)
+{
+ struct x11_display display = {.base.ops = &yasl_x11_backend,
+ .net_state = 10, .fullscreen = 20, .maximized_h = 21, .maximized_v = 22};
+ display.native = (Display *)&display;
+ struct x11_surface surface = {.base = {.display = &display.base,
+ .state = YASL_STATE_ACTIVATED}, .window = 42};
+ set_callbacks(&surface.base, &(struct yasl_window_cbs){.state = state_changed}, NULL);
+
+ properties[0] = display.fullscreen;
+ property_count = 1;
+ update_state(&surface);
+ assert(notifications == 1);
+ assert(reported_state == (YASL_STATE_FULLSCREEN | YASL_STATE_ACTIVATED));
+ update_state(&surface);
+ assert(notifications == 1);
+
+ /* Both maximized axes are required; activation survives property changes. */
+ properties[0] = display.maximized_h;
+ update_state(&surface);
+ assert(notifications == 2 && reported_state == YASL_STATE_ACTIVATED);
+ properties[1] = display.maximized_v;
+ property_count = 2;
+ update_state(&surface);
+ assert(notifications == 3);
+ assert(reported_state == (YASL_STATE_MAXIMIZED | YASL_STATE_ACTIVATED));
+ properties[2] = display.fullscreen;
+ property_count = 3;
+ update_state(&surface);
+ assert(notifications == 4);
+ assert(reported_state == (YASL_STATE_FULLSCREEN | YASL_STATE_MAXIMIZED | YASL_STATE_ACTIVATED));
+
+ property_count = 0;
+ update_state(&surface);
+ assert(notifications == 5 && reported_state == YASL_STATE_ACTIVATED);
+ update_state(&surface);
+ assert(notifications == 5);
+ return 0;
+}