177 lines
5.8 KiB
C
177 lines
5.8 KiB
C
/*
|
|
* test_x11_event.c -- unit tests for x11_translate_event
|
|
*
|
|
* These tests are display-free: they exercise only field-mapping logic.
|
|
* Compile with:
|
|
* gcc -I../src -o test_x11_event test_x11_event.c \
|
|
* ../src/backend/x11/x11_event.c -lX11
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "backend/x11/x11_event.h"
|
|
|
|
static int failures = 0;
|
|
static int passed = 0;
|
|
|
|
#define EXPECT_EQ(label, actual, expected) do { \
|
|
if ((actual) != (expected)) { \
|
|
fprintf(stderr, "FAIL %s: got %ld, want %ld\n", \
|
|
(label), (long)(actual), (long)(expected)); \
|
|
failures++; \
|
|
} else { \
|
|
passed++; \
|
|
} \
|
|
} while (0)
|
|
|
|
static void test_button_press(void)
|
|
{
|
|
XEvent xev;
|
|
WBackendEvent bev;
|
|
|
|
memset(&xev, 0, sizeof(xev));
|
|
xev.type = ButtonPress;
|
|
xev.xbutton.window = 0x1000;
|
|
xev.xbutton.button = Button2;
|
|
xev.xbutton.state = ShiftMask | ControlMask;
|
|
xev.xbutton.x = 10;
|
|
xev.xbutton.y = 20;
|
|
xev.xbutton.x_root = 110;
|
|
xev.xbutton.y_root = 120;
|
|
xev.xbutton.time = 987654;
|
|
xev.xbutton.send_event = True;
|
|
|
|
x11_translate_event(&xev, &bev);
|
|
|
|
EXPECT_EQ("button_press.type", bev.type, WBE_BUTTON_PRESS);
|
|
EXPECT_EQ("button_press.window", bev.window, 0x1000UL);
|
|
EXPECT_EQ("button_press.u.window", bev.u.button.window, 0x1000UL);
|
|
EXPECT_EQ("button_press.button", bev.u.button.button, Button2);
|
|
EXPECT_EQ("button_press.state", bev.u.button.state, (unsigned)(ShiftMask | ControlMask));
|
|
EXPECT_EQ("button_press.x", bev.u.button.x, 10);
|
|
EXPECT_EQ("button_press.y", bev.u.button.y, 20);
|
|
EXPECT_EQ("button_press.x_root", bev.u.button.x_root, 110);
|
|
EXPECT_EQ("button_press.y_root", bev.u.button.y_root, 120);
|
|
EXPECT_EQ("button_press.time", bev.u.button.time, 987654UL);
|
|
EXPECT_EQ("button_press.send_event", bev.u.button.send_event, True);
|
|
EXPECT_EQ("button_press._x11_raw", (void *)bev._x11_raw == (void *)&xev, 1);
|
|
}
|
|
|
|
static void test_button_release(void)
|
|
{
|
|
XEvent xev;
|
|
WBackendEvent bev;
|
|
|
|
memset(&xev, 0, sizeof(xev));
|
|
xev.type = ButtonRelease;
|
|
xev.xbutton.window = 0x2000;
|
|
xev.xbutton.button = Button3;
|
|
xev.xbutton.state = 0;
|
|
|
|
x11_translate_event(&xev, &bev);
|
|
|
|
EXPECT_EQ("button_release.type", bev.type, WBE_BUTTON_RELEASE);
|
|
EXPECT_EQ("button_release.window", bev.window, 0x2000UL);
|
|
EXPECT_EQ("button_release.button", bev.u.button.button, Button3);
|
|
}
|
|
|
|
static void test_expose(void)
|
|
{
|
|
XEvent xev;
|
|
WBackendEvent bev;
|
|
|
|
memset(&xev, 0, sizeof(xev));
|
|
xev.type = Expose;
|
|
xev.xexpose.window = 0x3000;
|
|
xev.xexpose.x = 5;
|
|
xev.xexpose.y = 7;
|
|
xev.xexpose.width = 100;
|
|
xev.xexpose.height = 80;
|
|
xev.xexpose.count = 2;
|
|
xev.xany.window = 0x3000;
|
|
|
|
x11_translate_event(&xev, &bev);
|
|
|
|
EXPECT_EQ("expose.type", bev.type, WBE_EXPOSE);
|
|
EXPECT_EQ("expose.window", bev.u.expose.window, 0x3000UL);
|
|
EXPECT_EQ("expose.x", bev.u.expose.x, 5);
|
|
EXPECT_EQ("expose.y", bev.u.expose.y, 7);
|
|
EXPECT_EQ("expose.width", bev.u.expose.width, 100);
|
|
EXPECT_EQ("expose.height", bev.u.expose.height, 80);
|
|
EXPECT_EQ("expose.count", bev.u.expose.count, 2);
|
|
}
|
|
|
|
static void test_enter_notify(void)
|
|
{
|
|
XEvent xev;
|
|
WBackendEvent bev;
|
|
|
|
memset(&xev, 0, sizeof(xev));
|
|
xev.type = EnterNotify;
|
|
xev.xcrossing.window = 0x4000;
|
|
xev.xcrossing.time = 11111;
|
|
xev.xcrossing.mode = NotifyNormal;
|
|
xev.xcrossing.detail = NotifyAncestor;
|
|
xev.xany.window = 0x4000;
|
|
|
|
x11_translate_event(&xev, &bev);
|
|
|
|
EXPECT_EQ("enter.type", bev.type, WBE_ENTER_NOTIFY);
|
|
EXPECT_EQ("enter.window", bev.u.crossing.window, 0x4000UL);
|
|
EXPECT_EQ("enter.time", bev.u.crossing.time, 11111UL);
|
|
EXPECT_EQ("enter.mode", bev.u.crossing.mode, NotifyNormal);
|
|
EXPECT_EQ("enter.detail", bev.u.crossing.detail, NotifyAncestor);
|
|
}
|
|
|
|
static void test_leave_notify(void)
|
|
{
|
|
XEvent xev;
|
|
WBackendEvent bev;
|
|
|
|
memset(&xev, 0, sizeof(xev));
|
|
xev.type = LeaveNotify;
|
|
xev.xcrossing.window = 0x5000;
|
|
xev.xcrossing.time = 22222;
|
|
xev.xcrossing.mode = NotifyGrab;
|
|
xev.xcrossing.detail = NotifyInferior;
|
|
xev.xany.window = 0x5000;
|
|
|
|
x11_translate_event(&xev, &bev);
|
|
|
|
EXPECT_EQ("leave.type", bev.type, WBE_LEAVE_NOTIFY);
|
|
EXPECT_EQ("leave.window", bev.u.crossing.window, 0x5000UL);
|
|
EXPECT_EQ("leave.time", bev.u.crossing.time, 22222UL);
|
|
EXPECT_EQ("leave.mode", bev.u.crossing.mode, NotifyGrab);
|
|
EXPECT_EQ("leave.detail", bev.u.crossing.detail, NotifyInferior);
|
|
}
|
|
|
|
static void test_unknown_event(void)
|
|
{
|
|
XEvent xev;
|
|
WBackendEvent bev;
|
|
|
|
memset(&xev, 0, sizeof(xev));
|
|
xev.type = MotionNotify; /* not translated yet */
|
|
xev.xany.window = 0x6000;
|
|
|
|
x11_translate_event(&xev, &bev);
|
|
|
|
EXPECT_EQ("unknown.type", bev.type, WBE_NONE);
|
|
EXPECT_EQ("unknown._x11_raw", (void *)bev._x11_raw == (void *)&xev, 1);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
test_button_press();
|
|
test_button_release();
|
|
test_expose();
|
|
test_enter_notify();
|
|
test_leave_notify();
|
|
test_unknown_event();
|
|
|
|
printf("%d passed, %d failed\n", passed, failures);
|
|
return failures ? EXIT_FAILURE : EXIT_SUCCESS;
|
|
}
|