test: add xi2 directory, prepare for protocol testing.
These two files provide a couple of common defines, functions and variables that will be used in a number of protocol tests. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
4b93413b2a
commit
1d635ae65b
|
@ -2012,5 +2012,6 @@ hw/kdrive/linux/Makefile
|
||||||
hw/kdrive/sdl/Makefile
|
hw/kdrive/sdl/Makefile
|
||||||
hw/kdrive/src/Makefile
|
hw/kdrive/src/Makefile
|
||||||
test/Makefile
|
test/Makefile
|
||||||
|
test/xi2/Makefile
|
||||||
xorg-server.pc
|
xorg-server.pc
|
||||||
])
|
])
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
if UNITTESTS
|
if UNITTESTS
|
||||||
|
SUBDIRS= . xi2
|
||||||
check_PROGRAMS = xkb input
|
check_PROGRAMS = xkb input
|
||||||
check_LTLIBRARIES = libxservertest.la
|
check_LTLIBRARIES = libxservertest.la
|
||||||
|
|
||||||
|
|
6
test/xi2/Makefile.am
Normal file
6
test/xi2/Makefile.am
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
if UNITTESTS
|
||||||
|
AM_CFLAGS = $(DIX_CFLAGS) $(GLIB_CFLAGS) @XORG_CFLAGS@
|
||||||
|
INCLUDES = @XORG_INCS@
|
||||||
|
TEST_LDADD=../libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS) $(GLIB_LIBS)
|
||||||
|
COMMON_SOURCES=protocol-common.h protocol-common.c
|
||||||
|
endif
|
132
test/xi2/protocol-common.c
Normal file
132
test/xi2/protocol-common.c
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
/**
|
||||||
|
* Copyright © 2009 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice (including the next
|
||||||
|
* paragraph) shall be included in all copies or substantial portions of the
|
||||||
|
* Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_DIX_CONFIG_H
|
||||||
|
#include <dix-config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "extinit.h" /* for XInputExtensionInit */
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include "protocol-common.h"
|
||||||
|
|
||||||
|
struct devices devices;
|
||||||
|
WindowRec root;
|
||||||
|
WindowRec window;
|
||||||
|
|
||||||
|
void *userdata;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create and init 2 master devices (VCP + VCK) and two slave devices, one
|
||||||
|
* default mouse, one default keyboard.
|
||||||
|
*/
|
||||||
|
struct devices init_devices(void)
|
||||||
|
{
|
||||||
|
ClientRec client;
|
||||||
|
struct devices devices;
|
||||||
|
|
||||||
|
client = init_client(0, NULL);
|
||||||
|
|
||||||
|
AllocDevicePair(&client, "Virtual core", &devices.vcp, &devices.vck, TRUE);
|
||||||
|
inputInfo.pointer = devices.vcp;
|
||||||
|
inputInfo.keyboard = devices.vck;
|
||||||
|
ActivateDevice(devices.vcp, FALSE);
|
||||||
|
ActivateDevice(devices.vck, FALSE);
|
||||||
|
EnableDevice(devices.vcp, FALSE);
|
||||||
|
EnableDevice(devices.vck, FALSE);
|
||||||
|
|
||||||
|
AllocDevicePair(&client, "", &devices.mouse, &devices.kbd, FALSE);
|
||||||
|
ActivateDevice(devices.mouse, FALSE);
|
||||||
|
ActivateDevice(devices.kbd, FALSE);
|
||||||
|
EnableDevice(devices.mouse, FALSE);
|
||||||
|
EnableDevice(devices.kbd, FALSE);
|
||||||
|
|
||||||
|
devices.num_devices = 4;
|
||||||
|
devices.num_master_devices = 2;
|
||||||
|
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Create minimal client, with the given buffer and len as request buffer */
|
||||||
|
ClientRec init_client(int len, void *data)
|
||||||
|
{
|
||||||
|
ClientRec client = { 0 };
|
||||||
|
|
||||||
|
/* we store the privates now and reassign it after the memset. this way
|
||||||
|
* we can share them across multiple test runs and don't have to worry
|
||||||
|
* about freeing them after each test run. */
|
||||||
|
PrivateRec *privates = client.devPrivates;
|
||||||
|
|
||||||
|
client.index = CLIENT_INDEX;
|
||||||
|
client.clientAsMask = CLIENT_MASK;
|
||||||
|
client.sequence = CLIENT_SEQUENCE;
|
||||||
|
client.req_len = len;
|
||||||
|
|
||||||
|
client.requestBuffer = data;
|
||||||
|
client.devPrivates = privates;
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_window(WindowPtr window, WindowPtr parent, int id)
|
||||||
|
{
|
||||||
|
memset(window, 0, sizeof(window));
|
||||||
|
|
||||||
|
window->drawable.id = id;
|
||||||
|
window->parent = parent;
|
||||||
|
window->optional = xcalloc(1, sizeof(WindowOptRec));
|
||||||
|
g_assert(window->optional);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Needed for the screen setup, otherwise we crash during sprite initialization */
|
||||||
|
static Bool device_cursor_init(DeviceIntPtr dev, ScreenPtr screen) { return TRUE; }
|
||||||
|
void init_simple(void)
|
||||||
|
{
|
||||||
|
static ScreenRec screen;
|
||||||
|
|
||||||
|
screenInfo.arraySize = MAXSCREENS;
|
||||||
|
screenInfo.numScreens = 1;
|
||||||
|
screenInfo.screens[0] = &screen;
|
||||||
|
|
||||||
|
screen.myNum = 0;
|
||||||
|
screen.id = 100;
|
||||||
|
screen.width = 640;
|
||||||
|
screen.height = 480;
|
||||||
|
screen.DeviceCursorInitialize = device_cursor_init;
|
||||||
|
|
||||||
|
dixResetPrivates();
|
||||||
|
XInputExtensionInit();
|
||||||
|
init_window(&root, NULL, ROOT_WINDOW_ID);
|
||||||
|
init_window(&window, &root, CLIENT_WINDOW_ID);
|
||||||
|
|
||||||
|
devices = init_devices();
|
||||||
|
}
|
||||||
|
|
||||||
|
void __wrap_WriteToClient(ClientPtr client, int len, void *data)
|
||||||
|
{
|
||||||
|
g_assert(reply_handler != NULL);
|
||||||
|
|
||||||
|
(*reply_handler)(client, len, data, userdata);
|
||||||
|
}
|
||||||
|
|
143
test/xi2/protocol-common.h
Normal file
143
test/xi2/protocol-common.h
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
/**
|
||||||
|
* Copyright © 2009 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice (including the next
|
||||||
|
* paragraph) shall be included in all copies or substantial portions of the
|
||||||
|
* Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_DIX_CONFIG_H
|
||||||
|
#include <dix-config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "scrnintstr.h"
|
||||||
|
#include "windowstr.h"
|
||||||
|
#include "scrnintstr.h"
|
||||||
|
#include "exevents.h"
|
||||||
|
|
||||||
|
#ifndef PROTOCOL_COMMON_H
|
||||||
|
#define PROTOCOL_COMMON_H
|
||||||
|
|
||||||
|
extern int BadDevice;
|
||||||
|
|
||||||
|
/* Check default values in a reply */
|
||||||
|
#define reply_check_defaults(rep, len, type) \
|
||||||
|
{ \
|
||||||
|
g_assert((len) >= sz_x##type##Reply); \
|
||||||
|
g_assert((rep)->repType == X_Reply); \
|
||||||
|
g_assert((rep)->RepType == X_##type); \
|
||||||
|
g_assert((rep)->sequenceNumber == CLIENT_SEQUENCE); \
|
||||||
|
g_assert((rep)->length >= (sz_x##type##Reply - 32)/4); \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* initialise default values for request */
|
||||||
|
#define request_init(req, type) \
|
||||||
|
{ \
|
||||||
|
(req)->reqType = 128; /* doesn't matter */ \
|
||||||
|
(req)->ReqType = X_##type; \
|
||||||
|
(req)->length = (sz_x##type##Req >> 2); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Various defines used in the tests. Some tests may use different values
|
||||||
|
* than these defaults */
|
||||||
|
/* default client index */
|
||||||
|
#define CLIENT_INDEX 1
|
||||||
|
/* default client mask for resources and windows */
|
||||||
|
#define CLIENT_MASK ((CLIENT_INDEX) << CLIENTOFFSET)
|
||||||
|
/* default client sequence number for replies */
|
||||||
|
#define CLIENT_SEQUENCE 0x100
|
||||||
|
/* default root window id */
|
||||||
|
#define ROOT_WINDOW_ID 0x10
|
||||||
|
/* default client window id */
|
||||||
|
#define CLIENT_WINDOW_ID 0x100001
|
||||||
|
|
||||||
|
/* Various structs used throughout the tests */
|
||||||
|
|
||||||
|
|
||||||
|
/* The default devices struct, contains one pointer + keyboard and the
|
||||||
|
* matching master devices. Initialize with init_devices() if needed. */
|
||||||
|
struct devices {
|
||||||
|
DeviceIntPtr vcp;
|
||||||
|
DeviceIntPtr vck;
|
||||||
|
DeviceIntPtr mouse;
|
||||||
|
DeviceIntPtr kbd;
|
||||||
|
|
||||||
|
int num_devices;
|
||||||
|
int num_master_devices;
|
||||||
|
} devices;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The set of default devices available in all tests if necessary.
|
||||||
|
*/
|
||||||
|
extern struct devices devices;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test-specific userdata, passed into the reply handler.
|
||||||
|
*/
|
||||||
|
extern void *userdata;
|
||||||
|
/**
|
||||||
|
* The reply handler called from WriteToClient. Set this handler if you need
|
||||||
|
* to check the reply values.
|
||||||
|
*/
|
||||||
|
void (*reply_handler)(ClientPtr client, int len, char *data, void *userdata);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Semi-initialized root window. initialized by init().
|
||||||
|
*/
|
||||||
|
extern WindowRec root;
|
||||||
|
/**
|
||||||
|
* Semi-initialized top-level window. initialized by init().
|
||||||
|
*/
|
||||||
|
extern WindowRec window;
|
||||||
|
|
||||||
|
/* various simple functions for quick setup */
|
||||||
|
/**
|
||||||
|
* Initialize the above struct with default devices and return the struct.
|
||||||
|
* Usually not needed if you call ::init_simple.
|
||||||
|
*/
|
||||||
|
struct devices init_devices(void);
|
||||||
|
/**
|
||||||
|
* Init a mostly zeroed out client with default values for index and mask.
|
||||||
|
*/
|
||||||
|
ClientRec init_client(int request_len, void *request_data);
|
||||||
|
/**
|
||||||
|
* Init a mostly zeroed out window with the given window ID.
|
||||||
|
* Usually not needed if you call ::init_simple which sets up root and
|
||||||
|
* window.
|
||||||
|
*/
|
||||||
|
void init_window(WindowPtr window, WindowPtr parent, int id);
|
||||||
|
/**
|
||||||
|
* Create a very simple setup that provides the minimum values for most
|
||||||
|
* tests, including a screen, the root and client window and the default
|
||||||
|
* device setup.
|
||||||
|
*/
|
||||||
|
void init_simple(void);
|
||||||
|
|
||||||
|
/* Declarations for various overrides in the test files. */
|
||||||
|
void __wrap_WriteToClient(ClientPtr client, int len, void *data);
|
||||||
|
void __wrap_XISetEventMask(DeviceIntPtr dev, WindowPtr win, int len, unsigned char* mask);
|
||||||
|
int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access);
|
||||||
|
int __real_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access);
|
||||||
|
Bool __wrap_AddResource(XID id, RESTYPE type, pointer value);
|
||||||
|
int __wrap_dixLookupClient(ClientPtr *c, XID id, ClientPtr client, Mask access);
|
||||||
|
int __real_dixLookupClient(ClientPtr *c, XID id, ClientPtr client, Mask access);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* PROTOCOL_COMMON_H */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user