Merge remote-tracking branch 'whot/for-keith'

This commit is contained in:
Keith Packard 2011-04-22 10:48:37 -07:00
commit 302bdc3c96
39 changed files with 1076 additions and 818 deletions

View File

@ -423,7 +423,7 @@ ProcXTestFakeInput(ClientPtr client)
break; break;
case KeyPress: case KeyPress:
case KeyRelease: case KeyRelease:
nevents = GetKeyboardEvents(xtest_evlist, dev, type, ev->u.u.detail); nevents = GetKeyboardEvents(xtest_evlist, dev, type, ev->u.u.detail, NULL);
break; break;
} }

View File

@ -535,6 +535,7 @@ DeepCopyPointerClasses(DeviceIntPtr from, DeviceIntPtr to)
if (from->valuator) if (from->valuator)
{ {
ValuatorClassPtr v; ValuatorClassPtr v;
if (!to->valuator) if (!to->valuator)
{ {
classes = to->unused_classes; classes = to->unused_classes;
@ -543,18 +544,14 @@ DeepCopyPointerClasses(DeviceIntPtr from, DeviceIntPtr to)
classes->valuator = NULL; classes->valuator = NULL;
} }
to->valuator = realloc(to->valuator, sizeof(ValuatorClassRec) + v = AllocValuatorClass(to->valuator, from->valuator->numAxes);
from->valuator->numAxes * sizeof(AxisInfo) +
from->valuator->numAxes * sizeof(double));
v = to->valuator;
if (!v) if (!v)
FatalError("[Xi] no memory for class shift.\n"); FatalError("[Xi] no memory for class shift.\n");
v->numAxes = from->valuator->numAxes; to->valuator = v;
v->axes = (AxisInfoPtr)&v[1];
memcpy(v->axes, from->valuator->axes, v->numAxes * sizeof(AxisInfo)); memcpy(v->axes, from->valuator->axes, v->numAxes * sizeof(AxisInfo));
v->axisVal = (double*)(v->axes + from->valuator->numAxes);
v->sourceid = from->id; v->sourceid = from->id;
} else if (to->valuator && !from->valuator) } else if (to->valuator && !from->valuator)
{ {

View File

@ -511,7 +511,7 @@ SReplyIDispatch(ClientPtr client, int len, xGrabDeviceReply * rep)
SRepXIQueryDevice(client, len, (xXIQueryDeviceReply*)rep); SRepXIQueryDevice(client, len, (xXIQueryDeviceReply*)rep);
else if (rep->RepType == X_XIGrabDevice) else if (rep->RepType == X_XIGrabDevice)
SRepXIGrabDevice(client, len, (xXIGrabDeviceReply *) rep); SRepXIGrabDevice(client, len, (xXIGrabDeviceReply *) rep);
else if (rep->RepType == X_XIGrabDevice) else if (rep->RepType == X_XIPassiveGrabDevice)
SRepXIPassiveGrabDevice(client, len, (xXIPassiveGrabDeviceReply *) rep); SRepXIPassiveGrabDevice(client, len, (xXIPassiveGrabDeviceReply *) rep);
else if (rep->RepType == X_XIListProperties) else if (rep->RepType == X_XIListProperties)
SRepXIListProperties(client, len, (xXIListPropertiesReply *) rep); SRepXIListProperties(client, len, (xXIListPropertiesReply *) rep);

View File

@ -116,7 +116,9 @@ void XISendDeviceHierarchyEvent(int flags[MAXDEVICES])
ev->length = bytes_to_int32(ev->num_info * sizeof(xXIHierarchyInfo)); ev->length = bytes_to_int32(ev->num_info * sizeof(xXIHierarchyInfo));
memset(&dummyDev, 0, sizeof(dummyDev));
dummyDev.id = XIAllDevices; dummyDev.id = XIAllDevices;
dummyDev.type = SLAVE;
SendEventToAllWindows(&dummyDev, (XI_HierarchyChangedMask >> 8), (xEvent*)ev, 1); SendEventToAllWindows(&dummyDev, (XI_HierarchyChangedMask >> 8), (xEvent*)ev, 1);
free(ev); free(ev);
} }

View File

@ -43,6 +43,7 @@
#include "exevents.h" #include "exevents.h"
#include "xipassivegrab.h" #include "xipassivegrab.h"
#include "dixgrabs.h" #include "dixgrabs.h"
#include "misc.h"
int int
SProcXIPassiveGrabDevice(ClientPtr client) SProcXIPassiveGrabDevice(ClientPtr client)
@ -87,6 +88,7 @@ ProcXIPassiveGrabDevice(ClientPtr client)
GrabParameters param; GrabParameters param;
void *tmp; void *tmp;
int mask_len; int mask_len;
int n;
REQUEST(xXIPassiveGrabDeviceReq); REQUEST(xXIPassiveGrabDeviceReq);
REQUEST_AT_LEAST_SIZE(xXIPassiveGrabDeviceReq); REQUEST_AT_LEAST_SIZE(xXIPassiveGrabDeviceReq);
@ -99,8 +101,11 @@ ProcXIPassiveGrabDevice(ClientPtr client)
{ {
ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess); ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess);
if (ret != Success) if (ret != Success)
{
client->errorValue = stuff->deviceid;
return ret; return ret;
} }
}
if (stuff->grab_type != XIGrabtypeButton && if (stuff->grab_type != XIGrabtypeButton &&
stuff->grab_type != XIGrabtypeKeycode && stuff->grab_type != XIGrabtypeKeycode &&
@ -156,6 +161,8 @@ ProcXIPassiveGrabDevice(ClientPtr client)
return status; return status;
status = CheckGrabValues(client, &param); status = CheckGrabValues(client, &param);
if (status != Success)
return status;
modifiers = (uint32_t*)&stuff[1] + stuff->mask_len; modifiers = (uint32_t*)&stuff[1] + stuff->mask_len;
modifiers_failed = calloc(stuff->num_modifiers, sizeof(xXIGrabModifierInfo)); modifiers_failed = calloc(stuff->num_modifiers, sizeof(xXIGrabModifierInfo));
@ -190,6 +197,9 @@ ProcXIPassiveGrabDevice(ClientPtr client)
info->status = status; info->status = status;
info->modifiers = *modifiers; info->modifiers = *modifiers;
if (client->swapped)
swapl(&info->modifiers, n);
rep.num_modifiers++; rep.num_modifiers++;
rep.length += bytes_to_int32(sizeof(xXIGrabModifierInfo)); rep.length += bytes_to_int32(sizeof(xXIGrabModifierInfo));
} }
@ -197,10 +207,8 @@ ProcXIPassiveGrabDevice(ClientPtr client)
WriteReplyToClient(client, sizeof(rep), &rep); WriteReplyToClient(client, sizeof(rep), &rep);
if (rep.num_modifiers) if (rep.num_modifiers)
{ WriteToClient(client, rep.length * 4, (char*)modifiers_failed);
client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
WriteSwappedDataToClient(client, rep.length * 4, (char*)modifiers_failed);
}
free(modifiers_failed); free(modifiers_failed);
return ret; return ret;
} }

View File

@ -35,7 +35,7 @@ AM_MAINTAINER_MODE
# Require xorg-macros minimum of 1.13 for XORG_ENABLE_UNIT_TESTS # Require xorg-macros minimum of 1.13 for XORG_ENABLE_UNIT_TESTS
m4_ifndef([XORG_MACROS_VERSION], m4_ifndef([XORG_MACROS_VERSION],
[m4_fatal([must install xorg-macros 1.13 or later before running autoconf/autogen])]) [m4_fatal([must install xorg-macros 1.13 or later before running autoconf/autogen])])
XORG_MACROS_VERSION(1.10) XORG_MACROS_VERSION(1.13)
XORG_DEFAULT_OPTIONS XORG_DEFAULT_OPTIONS
XORG_WITH_DOXYGEN(1.6.1) XORG_WITH_DOXYGEN(1.6.1)
XORG_CHECK_SGML_DOCTOOLS(1.5) XORG_CHECK_SGML_DOCTOOLS(1.5)
@ -44,7 +44,6 @@ XORG_ENABLE_DEVEL_DOCS
XORG_WITH_XMLTO(0.0.20) XORG_WITH_XMLTO(0.0.20)
XORG_WITH_FOP XORG_WITH_FOP
XORG_ENABLE_UNIT_TESTS XORG_ENABLE_UNIT_TESTS
XORG_WITH_GLIB
XORG_LD_WRAP XORG_LD_WRAP
m4_ifndef([XORG_FONT_MACROS_VERSION], [m4_fatal([must install fontutil 1.1 or later before running autoconf/autogen])]) m4_ifndef([XORG_FONT_MACROS_VERSION], [m4_fatal([must install fontutil 1.1 or later before running autoconf/autogen])])
@ -791,7 +790,6 @@ LIBXFONT="xfont >= 1.4.2"
LIBXI="xi >= 1.2.99.1" LIBXI="xi >= 1.2.99.1"
LIBXTST="xtst >= 1.0.99.2" LIBXTST="xtst >= 1.0.99.2"
LIBPCIACCESS="pciaccess >= 0.8.0" LIBPCIACCESS="pciaccess >= 0.8.0"
LIBGLIB="glib-2.0 >= 2.16"
LIBUDEV="libudev >= 143" LIBUDEV="libudev >= 143"
LIBSELINUX="libselinux >= 2.0.86" LIBSELINUX="libselinux >= 2.0.86"
LIBDBUS="dbus-1 >= 1.0" LIBDBUS="dbus-1 >= 1.0"

View File

@ -1221,13 +1221,46 @@ InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons, Atom* labels,
return TRUE; return TRUE;
} }
/**
* Allocate a valuator class and set up the pointers for the axis values
* appropriately.
*
* @param src If non-NULL, the memory is reallocated from src. If NULL, the
* memory is calloc'd.
* @parma numAxes Number of axes to allocate.
* @return The allocated valuator struct.
*/
ValuatorClassPtr
AllocValuatorClass(ValuatorClassPtr src, int numAxes)
{
ValuatorClassPtr v;
/* force alignment with double */
union align_u { ValuatorClassRec valc; double d; } *align;
int size;
size = sizeof(union align_u) + numAxes * (sizeof(double) + sizeof(AxisInfo));
align = (union align_u *) realloc(src, size);
if (!align)
return NULL;
if (!src)
memset(align, 0, size);
v = &align->valc;
v->numAxes = numAxes;
v->axisVal = (double*)(align + 1);
v->axes = (AxisInfoPtr)(v->axisVal + numAxes);
return v;
}
Bool Bool
InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels, InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels,
int numMotionEvents, int mode) int numMotionEvents, int mode)
{ {
int i; int i;
ValuatorClassPtr valc; ValuatorClassPtr valc;
union align_u { ValuatorClassRec valc; double d; } *align;
if (!dev) if (!dev)
return FALSE; return FALSE;
@ -1240,13 +1273,10 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels,
numAxes = MAX_VALUATORS; numAxes = MAX_VALUATORS;
} }
align = (union align_u *) calloc(1, sizeof(union align_u) + valc = AllocValuatorClass(NULL, numAxes);
numAxes * sizeof(double) + if (!valc)
numAxes * sizeof(AxisInfo));
if (!align)
return FALSE; return FALSE;
valc = &align->valc;
valc->sourceid = dev->id; valc->sourceid = dev->id;
valc->motion = NULL; valc->motion = NULL;
valc->first_motion = 0; valc->first_motion = 0;
@ -1254,9 +1284,6 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels,
valc->numMotionEvents = numMotionEvents; valc->numMotionEvents = numMotionEvents;
valc->motionHintWindow = NullWindow; valc->motionHintWindow = NullWindow;
valc->numAxes = numAxes;
valc->axisVal = (double *)(align + 1);
valc->axes = (AxisInfoPtr)(valc->axisVal + numAxes);
if (mode & OutOfProximity) if (mode & OutOfProximity)
InitProximityClassDeviceStruct(dev); InitProximityClassDeviceStruct(dev);
@ -2365,7 +2392,7 @@ ReleaseButtonsAndKeys(DeviceIntPtr dev)
{ {
if (BitIsOn(k->down, i)) if (BitIsOn(k->down, i))
{ {
nevents = GetKeyboardEvents(eventlist, dev, KeyRelease, i); nevents = GetKeyboardEvents(eventlist, dev, KeyRelease, i, NULL);
for (j = 0; j < nevents; j++) for (j = 0; j < nevents; j++)
mieqProcessDeviceEvent(dev, (InternalEvent*)(eventlist+j)->event, NULL); mieqProcessDeviceEvent(dev, (InternalEvent*)(eventlist+j)->event, NULL);
} }

View File

@ -616,8 +616,8 @@ updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, ValuatorMask *mask,
/** /**
* Returns the maximum number of events GetKeyboardEvents, * Returns the maximum number of events GetKeyboardEvents
* GetKeyboardValuatorEvents, and GetPointerEvents will ever return. * and GetPointerEvents will ever return.
* *
* This MUST be absolutely constant, from init until exit. * This MUST be absolutely constant, from init until exit.
*/ */
@ -925,19 +925,6 @@ updateHistory(DeviceIntPtr dev, ValuatorMask *mask, CARD32 ms)
} }
} }
/**
* Convenience wrapper around GetKeyboardValuatorEvents, that takes no
* valuators.
*/
int
GetKeyboardEvents(EventList *events, DeviceIntPtr pDev, int type, int key_code) {
ValuatorMask mask;
valuator_mask_zero(&mask);
return GetKeyboardValuatorEvents(events, pDev, type, key_code, &mask);
}
/** /**
* Returns a set of InternalEvents for KeyPress/KeyRelease, optionally * Returns a set of InternalEvents for KeyPress/KeyRelease, optionally
* also with valuator events. * also with valuator events.
@ -947,7 +934,7 @@ GetKeyboardEvents(EventList *events, DeviceIntPtr pDev, int type, int key_code)
* place via GetMaximumEventsNum(), and for freeing it. * place via GetMaximumEventsNum(), and for freeing it.
*/ */
int int
GetKeyboardValuatorEvents(EventList *events, DeviceIntPtr pDev, int type, GetKeyboardEvents(EventList *events, DeviceIntPtr pDev, int type,
int key_code, const ValuatorMask *mask_in) { int key_code, const ValuatorMask *mask_in) {
int num_events = 0; int num_events = 0;
CARD32 ms = 0; CARD32 ms = 0;

View File

@ -429,82 +429,115 @@ InitTrackers(DeviceVelocityPtr vel, int ntracker)
vel->num_tracker = ntracker; vel->num_tracker = ntracker;
} }
enum directions {
N = (1 << 0),
NE = (1 << 1),
E = (1 << 2),
SE = (1 << 3),
S = (1 << 4),
SW = (1 << 5),
W = (1 << 6),
NW = (1 << 7),
UNDEFINED = 0xFF
};
/** /**
* return a bit field of possible directions. * return a bit field of possible directions.
* 0 = N, 2 = E, 4 = S, 6 = W, in-between is as you guess.
* There's no reason against widening to more precise directions (<45 degrees), * There's no reason against widening to more precise directions (<45 degrees),
* should it not perform well. All this is needed for is sort out non-linear * should it not perform well. All this is needed for is sort out non-linear
* motion, so precision isn't paramount. However, one should not flag direction * motion, so precision isn't paramount. However, one should not flag direction
* too narrow, since it would then cut the linear segment to zero size way too * too narrow, since it would then cut the linear segment to zero size way too
* often. * often.
*
* @return A bitmask for N, NE, S, SE, etc. indicating the directions for
* this movement.
*/ */
static int static int
DoGetDirection(int dx, int dy){ DoGetDirection(int dx, int dy){
float r; int dir = 0;
int i1, i2;
/* on insignificant mickeys, flag 135 degrees */ /* on insignificant mickeys, flag 135 degrees */
if(abs(dx) < 2 && abs(dy < 2)){ if(abs(dx) < 2 && abs(dy) < 2){
/* first check diagonal cases */ /* first check diagonal cases */
if(dx > 0 && dy > 0) if(dx > 0 && dy > 0)
return 4+8+16; dir = E | SE | S;
if(dx > 0 && dy < 0) else if(dx > 0 && dy < 0)
return 1+2+4; dir = N | NE | E;
if(dx < 0 && dy < 0) else if(dx < 0 && dy < 0)
return 1+128+64; dir = W | NW | N;
if(dx < 0 && dy > 0) else if(dx < 0 && dy > 0)
return 16+32+64; dir = W | SW | S;
/* check axis-aligned directions */ /* check axis-aligned directions */
if(dx > 0) else if(dx > 0)
return 2+4+8; /*E*/ dir = NE | E | SE;
if(dx < 0) else if(dx < 0)
return 128+64+32; /*W*/ dir = NW | W | SW;
if(dy > 0) else if(dy > 0)
return 32+16+8; /*S*/ dir = SE | S | SW;
if(dy < 0) else if(dy < 0)
return 128+1+2; /*N*/ dir = NE | N | NW;
return 255; /* shouldn't happen */ else
} dir = UNDEFINED; /* shouldn't happen */
/* else, compute angle and set appropriate flags */ } else { /* compute angle and set appropriate flags */
float r;
int i1, i2;
#ifdef _ISOC99_SOURCE #ifdef _ISOC99_SOURCE
r = atan2f(dy, dx); r = atan2f(dy, dx);
#else #else
r = atan2(dy, dx); r = atan2(dy, dx);
#endif #endif
/* find direction. We avoid r to become negative, /* find direction.
* since C has no well-defined modulo for such cases. */ *
* Add 360° to avoid r become negative since C has no well-defined
* modulo for such cases. Then divide by 45° to get the octant
* number, e.g.
* 0 <= r <= 1 is [0-45]°
* 1 <= r <= 2 is [45-90]°
* etc.
* But we add extra 90° to match up with our N, S, etc. defines up
* there, rest stays the same.
*/
r = (r+(M_PI*2.5))/(M_PI/4); r = (r+(M_PI*2.5))/(M_PI/4);
/* this intends to flag 2 directions (90 degrees), /* this intends to flag 2 directions (45 degrees),
* except on very well-aligned mickeys. */ * except on very well-aligned mickeys. */
i1 = (int)(r+0.1) % 8; i1 = (int)(r+0.1) % 8;
i2 = (int)(r+0.9) % 8; i2 = (int)(r+0.9) % 8;
if(i1 < 0 || i1 > 7 || i2 < 0 || i2 > 7) if(i1 < 0 || i1 > 7 || i2 < 0 || i2 > 7)
return 255; /* shouldn't happen */ dir = UNDEFINED; /* shouldn't happen */
return 1 << i1 | 1 << i2; else
dir = (1 << i1 | 1 << i2);
}
return dir;
} }
#define DIRECTION_CACHE_RANGE 5 #define DIRECTION_CACHE_RANGE 5
#define DIRECTION_CACHE_SIZE (DIRECTION_CACHE_RANGE*2+1) #define DIRECTION_CACHE_SIZE (DIRECTION_CACHE_RANGE*2+1)
/* cache DoGetDirection(). */ /* cache DoGetDirection().
* To avoid excessive use of direction calculation, cache the values for
* [-5..5] for both x/y. Anything outside of that is calcualted on the fly.
*
* @return A bitmask for N, NE, S, SE, etc. indicating the directions for
* this movement.
*/
static int static int
GetDirection(int dx, int dy){ GetDirection(int dx, int dy){
static int cache[DIRECTION_CACHE_SIZE][DIRECTION_CACHE_SIZE]; static int cache[DIRECTION_CACHE_SIZE][DIRECTION_CACHE_SIZE];
int i; int dir;
if (abs(dx) <= DIRECTION_CACHE_RANGE && if (abs(dx) <= DIRECTION_CACHE_RANGE &&
abs(dy) <= DIRECTION_CACHE_RANGE) { abs(dy) <= DIRECTION_CACHE_RANGE) {
/* cacheable */ /* cacheable */
i = cache[DIRECTION_CACHE_RANGE+dx][DIRECTION_CACHE_RANGE+dy]; dir = cache[DIRECTION_CACHE_RANGE+dx][DIRECTION_CACHE_RANGE+dy];
if(i != 0){ if(dir == 0) {
return i; dir = DoGetDirection(dx, dy);
}else{ cache[DIRECTION_CACHE_RANGE+dx][DIRECTION_CACHE_RANGE+dy] = dir;
i = DoGetDirection(dx, dy);
cache[DIRECTION_CACHE_RANGE+dx][DIRECTION_CACHE_RANGE+dy] = i;
return i;
} }
}else{ }else{
/* non-cacheable */ /* non-cacheable */
return DoGetDirection(dx, dy); dir = DoGetDirection(dx, dy);
} }
return dir;
} }
#undef DIRECTION_CACHE_RANGE #undef DIRECTION_CACHE_RANGE
@ -513,7 +546,12 @@ GetDirection(int dx, int dy){
/* convert offset (age) to array index */ /* convert offset (age) to array index */
#define TRACKER_INDEX(s, d) (((s)->num_tracker + (s)->cur_tracker - (d)) % (s)->num_tracker) #define TRACKER_INDEX(s, d) (((s)->num_tracker + (s)->cur_tracker - (d)) % (s)->num_tracker)
#define TRACKER(s, d) &(s)->tracker[TRACKER_INDEX(s,d)]
/**
* Add the delta motion to each tracker, then reset the latest tracker to
* 0/0 and set it as the current one.
*/
static inline void static inline void
FeedTrackers(DeviceVelocityPtr vel, int dx, int dy, int cur_t) FeedTrackers(DeviceVelocityPtr vel, int dx, int dy, int cur_t)
{ {
@ -539,11 +577,9 @@ FeedTrackers(DeviceVelocityPtr vel, int dx, int dy, int cur_t)
* This assumes linear motion. * This assumes linear motion.
*/ */
static float static float
CalcTracker(DeviceVelocityPtr vel, int offset, int cur_t){ CalcTracker(const MotionTracker *tracker, int cur_t){
int index = TRACKER_INDEX(vel, offset); float dist = sqrt(tracker->dx * tracker->dx + tracker->dy * tracker->dy);
float dist = sqrt( vel->tracker[index].dx * vel->tracker[index].dx int dtime = cur_t - tracker->time;
+ vel->tracker[index].dy * vel->tracker[index].dy);
int dtime = cur_t - vel->tracker[index].time;
if(dtime > 0) if(dtime > 0)
return dist / dtime; return dist / dtime;
else else
@ -551,22 +587,24 @@ CalcTracker(DeviceVelocityPtr vel, int offset, int cur_t){
} }
/* find the most plausible velocity. That is, the most distant /* find the most plausible velocity. That is, the most distant
* (in time) tracker which isn't too old, beyond a linear partition, * (in time) tracker which isn't too old, the movement vector was
* or simply too much off initial velocity. * in the same octant, and where the velocity is within an
* acceptable range to the inital velocity.
* *
* May return 0. * @return The tracker's velocity or 0 if the above conditions are unmet
*/ */
static float static float
QueryTrackers(DeviceVelocityPtr vel, int cur_t){ QueryTrackers(DeviceVelocityPtr vel, int cur_t){
int n, offset, dir = 255, i = -1, age_ms; int offset, dir = UNDEFINED, used_offset = -1, age_ms;
/* initial velocity: a low-offset, valid velocity */ /* initial velocity: a low-offset, valid velocity */
float iveloc = 0, res = 0, tmp, vdiff; float initial_velocity = 0, result = 0, velocity_diff;
float vfac = vel->corr_mul * vel->const_acceleration; /* premultiply */ float velocity_factor = vel->corr_mul * vel->const_acceleration; /* premultiply */
/* loop from current to older data */ /* loop from current to older data */
for(offset = 1; offset < vel->num_tracker; offset++){ for(offset = 1; offset < vel->num_tracker; offset++){
n = TRACKER_INDEX(vel, offset); MotionTracker *tracker = TRACKER(vel, offset);
float tracker_velocity;
age_ms = cur_t - vel->tracker[n].time; age_ms = cur_t - tracker->time;
/* bail out if data is too old and protect from overrun */ /* bail out if data is too old and protect from overrun */
if (age_ms >= vel->reset_time || age_ms < 0) { if (age_ms >= vel->reset_time || age_ms < 0) {
@ -580,60 +618,60 @@ QueryTrackers(DeviceVelocityPtr vel, int cur_t){
* even more precision we could subdivide as a final step, so possible * even more precision we could subdivide as a final step, so possible
* non-linearities are accounted for. * non-linearities are accounted for.
*/ */
dir &= vel->tracker[n].dir; dir &= tracker->dir;
if(dir == 0){ if(dir == 0){ /* we've changed octant of movement (e.g. NE → NW) */
DebugAccelF("(dix prtacc) query: no longer linear\n"); DebugAccelF("(dix prtacc) query: no longer linear\n");
/* instead of breaking it we might also inspect the partition after, /* instead of breaking it we might also inspect the partition after,
* but actual improvement with this is probably rare. */ * but actual improvement with this is probably rare. */
break; break;
} }
tmp = CalcTracker(vel, offset, cur_t) * vfac; tracker_velocity = CalcTracker(tracker, cur_t) * velocity_factor;
if ((iveloc == 0 || offset <= vel->initial_range) && tmp != 0) { if ((initial_velocity == 0 || offset <= vel->initial_range) && tracker_velocity != 0) {
/* set initial velocity and result */ /* set initial velocity and result */
res = iveloc = tmp; result = initial_velocity = tracker_velocity;
i = offset; used_offset = offset;
} else if (iveloc != 0 && tmp != 0) { } else if (initial_velocity != 0 && tracker_velocity != 0) {
vdiff = fabs(iveloc - tmp); velocity_diff = fabs(initial_velocity - tracker_velocity);
if (vdiff <= vel->max_diff ||
vdiff/(iveloc + tmp) < vel->max_rel_diff) { if (velocity_diff > vel->max_diff &&
/* we're in range with the initial velocity, velocity_diff/(initial_velocity + tracker_velocity) >= vel->max_rel_diff) {
* so this result is likely better
* (it contains more information). */
res = tmp;
i = offset;
}else{
/* we're not in range, quit - it won't get better. */ /* we're not in range, quit - it won't get better. */
DebugAccelF("(dix prtacc) query: tracker too different:" DebugAccelF("(dix prtacc) query: tracker too different:"
" old %2.2f initial %2.2f diff: %2.2f\n", " old %2.2f initial %2.2f diff: %2.2f\n",
tmp, iveloc, vdiff); tracker_velocity, initial_velocity, velocity_diff);
break; break;
} }
/* we're in range with the initial velocity,
* so this result is likely better
* (it contains more information). */
result = tracker_velocity;
used_offset = offset;
} }
} }
if(offset == vel->num_tracker){ if(offset == vel->num_tracker){
DebugAccelF("(dix prtacc) query: last tracker in effect\n"); DebugAccelF("(dix prtacc) query: last tracker in effect\n");
i = vel->num_tracker-1; used_offset = vel->num_tracker-1;
} }
if(i>=0){ #ifdef PTRACCEL_DEBUGGING
n = TRACKER_INDEX(vel, i); if(used_offset >= 0){
MotionTracker *tracker = TRACKER(vel, used_offset);
DebugAccelF("(dix prtacc) result: offset %i [dx: %i dy: %i diff: %i]\n", DebugAccelF("(dix prtacc) result: offset %i [dx: %i dy: %i diff: %i]\n",
i, used_offset, tracker->dx, tracker->dy, cur_t - tracker->time);
vel->tracker[n].dx,
vel->tracker[n].dy,
cur_t - vel->tracker[n].time);
} }
return res; #endif
return result;
} }
#undef TRACKER_INDEX #undef TRACKER_INDEX
#undef TRACKER
/** /**
* Perform velocity approximation based on 2D 'mickeys' (mouse motion delta). * Perform velocity approximation based on 2D 'mickeys' (mouse motion delta).
* return true if non-visible state reset is suggested * return true if non-visible state reset is suggested
*/ */
short BOOL
ProcessVelocityData2D( ProcessVelocityData2D(
DeviceVelocityPtr vel, DeviceVelocityPtr vel,
int dx, int dx,
@ -657,36 +695,41 @@ ProcessVelocityData2D(
* constant-velocity response * constant-velocity response
*/ */
static inline float static inline float
ApplySimpleSoftening(int od, int d) ApplySimpleSoftening(int prev_delta, int delta)
{ {
float res = d; float result = delta;
if (d <= 1 && d >= -1)
return res; if (delta < -1 || delta > 1) {
if (d > od) if (delta > prev_delta)
res -= 0.5; result -= 0.5;
else if (d < od) else if (delta < prev_delta)
res += 0.5; result += 0.5;
return res; }
return result;
} }
/**
* Soften the delta based on previous deltas stored in vel.
*
* @param[in,out] fdx Delta X, modified in-place.
* @param[in,out] fdx Delta Y, modified in-place.
*/
static void
ApplySoftening(
DeviceVelocityPtr vel,
float* fdx,
float* fdy)
{
if (vel->use_softening) {
*fdx = ApplySimpleSoftening(vel->last_dx, *fdx);
*fdy = ApplySimpleSoftening(vel->last_dy, *fdy);
}
}
static void static void
ApplySofteningAndConstantDeceleration( ApplyConstantDeceleration(DeviceVelocityPtr vel, float *fdx, float *fdy)
DeviceVelocityPtr vel,
int dx,
int dy,
float* fdx,
float* fdy,
short do_soften)
{ {
if (do_soften && vel->use_softening) {
*fdx = ApplySimpleSoftening(vel->last_dx, dx);
*fdy = ApplySimpleSoftening(vel->last_dy, dy);
} else {
*fdx = dx;
*fdy = dy;
}
*fdx *= vel->const_acceleration; *fdx *= vel->const_acceleration;
*fdy *= vel->const_acceleration; *fdy *= vel->const_acceleration;
} }
@ -713,6 +756,8 @@ BasicComputeAcceleration(
/** /**
* Compute acceleration. Takes into account averaging, nv-reset, etc. * Compute acceleration. Takes into account averaging, nv-reset, etc.
* If the velocity has changed, an average is taken of 6 velocity factors:
* current velocity, last velocity and 4 times the average between the two.
*/ */
static float static float
ComputeAcceleration( ComputeAcceleration(
@ -720,7 +765,7 @@ ComputeAcceleration(
DeviceVelocityPtr vel, DeviceVelocityPtr vel,
float threshold, float threshold,
float acc){ float acc){
float res; float result;
if(vel->velocity <= 0){ if(vel->velocity <= 0){
DebugAccelF("(dix ptracc) profile skipped\n"); DebugAccelF("(dix ptracc) profile skipped\n");
@ -735,24 +780,24 @@ ComputeAcceleration(
* current and previous velocity. * current and previous velocity.
* Though being the more natural choice, it causes a minor delay * Though being the more natural choice, it causes a minor delay
* in comparison, so it can be disabled. */ * in comparison, so it can be disabled. */
res = BasicComputeAcceleration( result = BasicComputeAcceleration(
dev, vel, vel->velocity, threshold, acc); dev, vel, vel->velocity, threshold, acc);
res += BasicComputeAcceleration( result += BasicComputeAcceleration(
dev, vel, vel->last_velocity, threshold, acc); dev, vel, vel->last_velocity, threshold, acc);
res += 4.0f * BasicComputeAcceleration(dev, vel, result += 4.0f * BasicComputeAcceleration(dev, vel,
(vel->last_velocity + vel->velocity) / 2, (vel->last_velocity + vel->velocity) / 2,
threshold, acc); threshold, acc);
res /= 6.0f; result /= 6.0f;
DebugAccelF("(dix ptracc) profile average [%.2f ... %.2f] is %.3f\n", DebugAccelF("(dix ptracc) profile average [%.2f ... %.2f] is %.3f\n",
vel->velocity, vel->last_velocity, res); vel->velocity, vel->last_velocity, result);
return res;
}else{ }else{
res = BasicComputeAcceleration(dev, vel, result = BasicComputeAcceleration(dev, vel,
vel->velocity, threshold, acc); vel->velocity, threshold, acc);
DebugAccelF("(dix ptracc) profile sample [%.2f] is %.3f\n", DebugAccelF("(dix ptracc) profile sample [%.2f] is %.3f\n",
vel->velocity, res); vel->velocity, res);
return res;
} }
return result;
} }
@ -1074,7 +1119,6 @@ acceleratePointerPredictable(
ValuatorMask* val, ValuatorMask* val,
CARD32 evtime) CARD32 evtime)
{ {
float fdx, fdy, tmp, mult; /* no need to init */
int dx = 0, dy = 0, tmpi; int dx = 0, dy = 0, tmpi;
DeviceVelocityPtr velocitydata = GetDevicePredictableAccelData(dev); DeviceVelocityPtr velocitydata = GetDevicePredictableAccelData(dev);
Bool soften = TRUE; Bool soften = TRUE;
@ -1102,6 +1146,8 @@ acceleratePointerPredictable(
} }
if (dev->ptrfeed && dev->ptrfeed->ctrl.num) { if (dev->ptrfeed && dev->ptrfeed->ctrl.num) {
float mult;
/* invoke acceleration profile to determine acceleration */ /* invoke acceleration profile to determine acceleration */
mult = ComputeAcceleration (dev, velocitydata, mult = ComputeAcceleration (dev, velocitydata,
dev->ptrfeed->ctrl.threshold, dev->ptrfeed->ctrl.threshold,
@ -1109,12 +1155,17 @@ acceleratePointerPredictable(
(float)dev->ptrfeed->ctrl.den); (float)dev->ptrfeed->ctrl.den);
if(mult != 1.0f || velocitydata->const_acceleration != 1.0f) { if(mult != 1.0f || velocitydata->const_acceleration != 1.0f) {
ApplySofteningAndConstantDeceleration(velocitydata, float fdx = dx,
dx, dy, fdy = dy;
&fdx, &fdy,
(mult > 1.0f) && soften);
if (mult > 1.0f && soften)
ApplySoftening(velocitydata, &fdx, &fdy);
ApplyConstantDeceleration(velocitydata, &fdx, &fdy);
/* Calculate the new delta (with accel) and drop it back
* into the valuator masks */
if (dx) { if (dx) {
float tmp;
tmp = mult * fdx + dev->last.remainder[0]; tmp = mult * fdx + dev->last.remainder[0];
/* Since it may not be apparent: lrintf() does not offer /* Since it may not be apparent: lrintf() does not offer
* strong statements about rounding; however because we * strong statements about rounding; however because we
@ -1126,6 +1177,7 @@ acceleratePointerPredictable(
dev->last.remainder[0] = tmp - (float)tmpi; dev->last.remainder[0] = tmp - (float)tmpi;
} }
if (dy) { if (dy) {
float tmp;
tmp = mult * fdy + dev->last.remainder[1]; tmp = mult * fdy + dev->last.remainder[1];
tmpi = lrintf(tmp); tmpi = lrintf(tmp);
valuator_mask_set(val, 1, tmpi); valuator_mask_set(val, 1, tmpi);

View File

@ -489,7 +489,7 @@ AddResource(XID id, RESTYPE type, pointer value)
rrec = &clientTable[client]; rrec = &clientTable[client];
if (!rrec->buckets) if (!rrec->buckets)
{ {
ErrorF("[dix] AddResource(%lx, %lx, %lx), client=%d \n", ErrorF("[dix] AddResource(%lx, %x, %lx), client=%d \n",
(unsigned long)id, type, (unsigned long)value, client); (unsigned long)id, type, (unsigned long)value, client);
FatalError("client not in use\n"); FatalError("client not in use\n");
} }

View File

@ -453,7 +453,7 @@ static int dmxTranslateAndEnqueueExtEvent(DMXLocalInputInfoPtr dmxLocal,
if (block) if (block)
dmxSigioBlock(); dmxSigioBlock();
GetEventList(&events); GetEventList(&events);
nevents = GetKeyboardValuatorEvents(events, pDevice, event, nevents = GetKeyboardEvents(events, pDevice, event,
ke->keycode, &mask); ke->keycode, &mask);
for (i = 0; i < nevents; i++) for (i = 0; i < nevents; i++)
mieqEnqueue(pDevice, (InternalEvent*)(events + i)->event); mieqEnqueue(pDevice, (InternalEvent*)(events + i)->event);
@ -685,7 +685,7 @@ void dmxEnqueue(DevicePtr pDev, int type, int detail, KeySym keySym,
GetEventList(&events); GetEventList(&events);
/*ErrorF("KEY %d sym %d\n", detail, (int) keySym);*/ /*ErrorF("KEY %d sym %d\n", detail, (int) keySym);*/
nevents = GetKeyboardEvents(events, p, type, detail); nevents = GetKeyboardEvents(events, p, type, detail, NULL);
for (i = 0; i < nevents; i++) for (i = 0; i < nevents; i++)
mieqEnqueue(p, (InternalEvent*)(events + i)->event); mieqEnqueue(p, (InternalEvent*)(events + i)->event);
return; return;

View File

@ -1804,7 +1804,7 @@ KdReleaseAllKeys (void)
if (key_is_down(ki->dixdev, key, KEY_POSTED | KEY_PROCESSED)) { if (key_is_down(ki->dixdev, key, KEY_POSTED | KEY_PROCESSED)) {
KdHandleKeyboardEvent(ki, KeyRelease, key); KdHandleKeyboardEvent(ki, KeyRelease, key);
GetEventList(&kdEvents); GetEventList(&kdEvents);
nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, KeyRelease, key); nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, KeyRelease, key, NULL);
for (i = 0; i < nEvents; i++) for (i = 0; i < nEvents; i++)
KdQueueEvent (ki->dixdev, (kdEvents + i)->event); KdQueueEvent (ki->dixdev, (kdEvents + i)->event);
} }
@ -1864,7 +1864,7 @@ KdEnqueueKeyboardEvent(KdKeyboardInfo *ki,
GetEventList(&kdEvents); GetEventList(&kdEvents);
nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, type, key_code); nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, type, key_code, NULL);
for (i = 0; i < nEvents; i++) for (i = 0; i < nEvents; i++)
KdQueueEvent(ki->dixdev, (InternalEvent *)((kdEvents + i)->event)); KdQueueEvent(ki->dixdev, (InternalEvent *)((kdEvents + i)->event));
} }

View File

@ -63,6 +63,9 @@ static char *DFLT_MOUSE_PROTO = "auto";
#elif defined(linux) #elif defined(linux)
static char DFLT_MOUSE_DEV[] = "/dev/input/mice"; static char DFLT_MOUSE_DEV[] = "/dev/input/mice";
static char DFLT_MOUSE_PROTO[] = "auto"; static char DFLT_MOUSE_PROTO[] = "auto";
#elif defined(WSCONS_SUPPORT)
static char *DFLT_MOUSE_DEV = "/dev/wsmouse";
static char *DFLT_MOUSE_PROTO = "wsmouse";
#else #else
static char *DFLT_MOUSE_DEV = "/dev/mouse"; static char *DFLT_MOUSE_DEV = "/dev/mouse";
static char *DFLT_MOUSE_PROTO = "auto"; static char *DFLT_MOUSE_PROTO = "auto";
@ -154,16 +157,6 @@ configureInputSection (void)
/* Crude mechanism to auto-detect mouse (os dependent) */ /* Crude mechanism to auto-detect mouse (os dependent) */
{ {
int fd; int fd;
#ifdef WSCONS_SUPPORT
fd = open("/dev/wsmouse", 0);
if (fd >= 0) {
DFLT_MOUSE_DEV = "/dev/wsmouse";
DFLT_MOUSE_PROTO = "wsmouse";
close(fd);
} else {
ErrorF("cannot open /dev/wsmouse\n");
}
#endif
fd = open(DFLT_MOUSE_DEV, 0); fd = open(DFLT_MOUSE_DEV, 0);
if (fd != -1) { if (fd != -1) {

View File

@ -399,7 +399,7 @@ xf86ReleaseKeys(DeviceIntPtr pDev)
i++) { i++) {
if (key_is_down(pDev, i, KEY_POSTED)) { if (key_is_down(pDev, i, KEY_POSTED)) {
sigstate = xf86BlockSIGIO (); sigstate = xf86BlockSIGIO ();
nevents = GetKeyboardEvents(xf86Events, pDev, KeyRelease, i); nevents = GetKeyboardEvents(xf86Events, pDev, KeyRelease, i, NULL);
for (j = 0; j < nevents; j++) for (j = 0; j < nevents; j++)
mieqEnqueue(pDev, (InternalEvent*)(xf86Events + j)->event); mieqEnqueue(pDev, (InternalEvent*)(xf86Events + j)->event);
xf86UnblockSIGIO(sigstate); xf86UnblockSIGIO(sigstate);

View File

@ -1013,7 +1013,6 @@ xf86PostMotionEventM(DeviceIntPtr device,
const ValuatorMask *mask) const ValuatorMask *mask)
{ {
int i = 0, nevents = 0; int i = 0, nevents = 0;
DeviceEvent *event;
int flags = 0; int flags = 0;
if (valuator_mask_num_valuators(mask) > 0) if (valuator_mask_num_valuators(mask) > 0)
@ -1054,7 +1053,6 @@ xf86PostMotionEventM(DeviceIntPtr device,
nevents = GetPointerEvents(xf86Events, device, MotionNotify, 0, flags, mask); nevents = GetPointerEvents(xf86Events, device, MotionNotify, 0, flags, mask);
for (i = 0; i < nevents; i++) { for (i = 0; i < nevents; i++) {
event = (DeviceEvent*)((xf86Events + i)->event);
mieqEnqueue(device, (InternalEvent*)((xf86Events + i)->event)); mieqEnqueue(device, (InternalEvent*)((xf86Events + i)->event));
} }
} }
@ -1252,16 +1250,9 @@ xf86PostKeyEventM(DeviceIntPtr device,
} }
#endif #endif
if (is_absolute) {
nevents = GetKeyboardValuatorEvents(xf86Events, device,
is_down ? KeyPress : KeyRelease,
key_code, mask);
}
else {
nevents = GetKeyboardEvents(xf86Events, device, nevents = GetKeyboardEvents(xf86Events, device,
is_down ? KeyPress : KeyRelease, is_down ? KeyPress : KeyRelease,
key_code); key_code, mask);
}
for (i = 0; i < nevents; i++) for (i = 0; i < nevents; i++)
mieqEnqueue(device, (InternalEvent*)((xf86Events + i)->event)); mieqEnqueue(device, (InternalEvent*)((xf86Events + i)->event));

View File

@ -108,7 +108,7 @@ xnestQueueKeyEvent(int type, unsigned int keycode)
GetEventList(&xnestEvents); GetEventList(&xnestEvents);
lastEventTime = GetTimeInMillis(); lastEventTime = GetTimeInMillis();
n = GetKeyboardEvents(xnestEvents, xnestKeyboardDevice, type, keycode); n = GetKeyboardEvents(xnestEvents, xnestKeyboardDevice, type, keycode, NULL);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
mieqEnqueue(xnestKeyboardDevice, (InternalEvent*)(xnestEvents + i)->event); mieqEnqueue(xnestKeyboardDevice, (InternalEvent*)(xnestEvents + i)->event);
} }

View File

@ -482,7 +482,7 @@ void DarwinSendKeyboardEvents(int ev_type, int keycode) {
} }
darwinEvents_lock(); { darwinEvents_lock(); {
num_events = GetKeyboardEvents(darwinEvents, darwinKeyboard, ev_type, keycode + MIN_KEYCODE); num_events = GetKeyboardEvents(darwinEvents, darwinKeyboard, ev_type, keycode + MIN_KEYCODE, NULL);
for(i=0; i<num_events; i++) mieqEnqueue(darwinKeyboard, (InternalEvent*)darwinEvents[i].event); for(i=0; i<num_events; i++) mieqEnqueue(darwinKeyboard, (InternalEvent*)darwinEvents[i].event);
if(num_events > 0) DarwinPokeEQ(); if(num_events > 0) DarwinPokeEQ();
} darwinEvents_unlock(); } darwinEvents_unlock();

View File

@ -485,7 +485,7 @@ winSendKeyEvent (DWORD dwKey, Bool fDown)
g_winKeyState[dwKey] = fDown; g_winKeyState[dwKey] = fDown;
GetEventList(&events); GetEventList(&events);
nevents = GetKeyboardEvents(events, g_pwinKeyboard, fDown ? KeyPress : KeyRelease, dwKey + MIN_KEYCODE); nevents = GetKeyboardEvents(events, g_pwinKeyboard, fDown ? KeyPress : KeyRelease, dwKey + MIN_KEYCODE, NULL);
for (i = 0; i < nevents; i++) for (i = 0; i < nevents; i++)
mieqEnqueue(g_pwinKeyboard, (InternalEvent*)events[i].event); mieqEnqueue(g_pwinKeyboard, (InternalEvent*)events[i].event);

View File

@ -102,6 +102,7 @@ typedef unsigned long Leds;
typedef struct _OtherClients *OtherClientsPtr; typedef struct _OtherClients *OtherClientsPtr;
typedef struct _InputClients *InputClientsPtr; typedef struct _InputClients *InputClientsPtr;
typedef struct _DeviceIntRec *DeviceIntPtr; typedef struct _DeviceIntRec *DeviceIntPtr;
typedef struct _ValuatorClassRec *ValuatorClassPtr;
typedef struct _ClassesRec *ClassesPtr; typedef struct _ClassesRec *ClassesPtr;
typedef struct _SpriteRec *SpritePtr; typedef struct _SpriteRec *SpritePtr;
typedef union _GrabMask GrabMask; typedef union _GrabMask GrabMask;
@ -300,6 +301,10 @@ extern _X_EXPORT Bool InitButtonClassDeviceStruct(
Atom* /* labels */, Atom* /* labels */,
CARD8* /*map*/); CARD8* /*map*/);
extern _X_INTERNAL ValuatorClassPtr AllocValuatorClass(
ValuatorClassPtr src,
int numAxes);
extern _X_EXPORT Bool InitValuatorClassDeviceStruct( extern _X_EXPORT Bool InitValuatorClassDeviceStruct(
DeviceIntPtr /*device*/, DeviceIntPtr /*device*/,
int /*numAxes*/, int /*numAxes*/,
@ -457,12 +462,6 @@ extern _X_EXPORT int GetPointerEvents(
const ValuatorMask *mask); const ValuatorMask *mask);
extern _X_EXPORT int GetKeyboardEvents( extern _X_EXPORT int GetKeyboardEvents(
EventListPtr events,
DeviceIntPtr pDev,
int type,
int key_code);
extern int GetKeyboardValuatorEvents(
EventListPtr events, EventListPtr events,
DeviceIntPtr pDev, DeviceIntPtr pDev,
int type, int type,

View File

@ -283,7 +283,7 @@ typedef struct _ValuatorClassRec {
unsigned short numAxes; unsigned short numAxes;
double *axisVal; /* always absolute, but device-coord system */ double *axisVal; /* always absolute, but device-coord system */
ValuatorAccelerationRec accelScheme; ValuatorAccelerationRec accelScheme;
} ValuatorClassRec, *ValuatorClassPtr; } ValuatorClassRec;
typedef struct _ButtonClassRec { typedef struct _ButtonClassRec {
int sourceid; int sourceid;

View File

@ -106,7 +106,7 @@ InitVelocityData(DeviceVelocityPtr vel);
extern _X_EXPORT void extern _X_EXPORT void
InitTrackers(DeviceVelocityPtr vel, int ntracker); InitTrackers(DeviceVelocityPtr vel, int ntracker);
extern _X_EXPORT short extern _X_EXPORT BOOL
ProcessVelocityData2D(DeviceVelocityPtr vel, int dx, int dy, int time); ProcessVelocityData2D(DeviceVelocityPtr vel, int dx, int dy, int time);
extern _X_EXPORT float extern _X_EXPORT float

View File

@ -1,5 +1,4 @@
if ENABLE_UNIT_TESTS if ENABLE_UNIT_TESTS
if HAVE_GLIB
if HAVE_LD_WRAP if HAVE_LD_WRAP
SUBDIRS= . xi2 SUBDIRS= . xi2
noinst_PROGRAMS = xkb input xtest list noinst_PROGRAMS = xkb input xtest list
@ -7,9 +6,9 @@ check_LTLIBRARIES = libxservertest.la
TESTS=$(noinst_PROGRAMS) TESTS=$(noinst_PROGRAMS)
AM_CFLAGS = $(DIX_CFLAGS) $(GLIB_CFLAGS) @XORG_CFLAGS@ AM_CFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@
INCLUDES = @XORG_INCS@ INCLUDES = @XORG_INCS@
TEST_LDADD=libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS) $(GLIB_LIBS) TEST_LDADD=libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS)
if SPECIAL_DTRACE_OBJECTS if SPECIAL_DTRACE_OBJECTS
TEST_LDADD += $(OS_LIB) $(DIX_LIB) TEST_LDADD += $(OS_LIB) $(DIX_LIB)
@ -38,7 +37,6 @@ libxservertest_la_LIBADD = \
@XORG_LIBS@ @XORG_LIBS@
endif endif
endif endif
endif
CLEANFILES=libxservertest.c CLEANFILES=libxservertest.c

File diff suppressed because it is too large Load Diff

View File

@ -28,7 +28,7 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <list.h> #include <list.h>
#include <string.h> #include <string.h>
#include <glib.h> #include <assert.h>
struct parent { struct parent {
int a; int a;
@ -56,10 +56,10 @@ test_list_init(void)
list_init(&parent.children); list_init(&parent.children);
/* test we haven't touched anything else. */ /* test we haven't touched anything else. */
g_assert(parent.a == tmp.a); assert(parent.a == tmp.a);
g_assert(parent.b == tmp.b); assert(parent.b == tmp.b);
g_assert(list_is_empty(&parent.children)); assert(list_is_empty(&parent.children));
} }
static void static void
@ -72,19 +72,19 @@ test_list_add(void)
list_init(&parent.children); list_init(&parent.children);
list_add(&child[0].node, &parent.children); list_add(&child[0].node, &parent.children);
g_assert(!list_is_empty(&parent.children)); assert(!list_is_empty(&parent.children));
c = list_first_entry(&parent.children, struct child, node); c = list_first_entry(&parent.children, struct child, node);
g_assert(memcmp(c, &child[0], sizeof(struct child)) == 0); assert(memcmp(c, &child[0], sizeof(struct child)) == 0);
/* note: list_add prepends */ /* note: list_add prepends */
list_add(&child[1].node, &parent.children); list_add(&child[1].node, &parent.children);
c = list_first_entry(&parent.children, struct child, node); c = list_first_entry(&parent.children, struct child, node);
g_assert(memcmp(c, &child[1], sizeof(struct child)) == 0); assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
list_add(&child[2].node, &parent.children); list_add(&child[2].node, &parent.children);
c = list_first_entry(&parent.children, struct child, node); c = list_first_entry(&parent.children, struct child, node);
g_assert(memcmp(c, &child[2], sizeof(struct child)) == 0); assert(memcmp(c, &child[2], sizeof(struct child)) == 0);
}; };
static void static void
@ -97,40 +97,40 @@ test_list_del(void)
list_init(&parent.children); list_init(&parent.children);
list_add(&child[0].node, &parent.children); list_add(&child[0].node, &parent.children);
g_assert(!list_is_empty(&parent.children)); assert(!list_is_empty(&parent.children));
list_del(&parent.children); list_del(&parent.children);
g_assert(list_is_empty(&parent.children)); assert(list_is_empty(&parent.children));
list_add(&child[0].node, &parent.children); list_add(&child[0].node, &parent.children);
list_del(&child[0].node); list_del(&child[0].node);
g_assert(list_is_empty(&parent.children)); assert(list_is_empty(&parent.children));
list_add(&child[0].node, &parent.children); list_add(&child[0].node, &parent.children);
list_add(&child[1].node, &parent.children); list_add(&child[1].node, &parent.children);
c = list_first_entry(&parent.children, struct child, node); c = list_first_entry(&parent.children, struct child, node);
g_assert(memcmp(c, &child[1], sizeof(struct child)) == 0); assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
/* delete first node */ /* delete first node */
list_del(&child[1].node); list_del(&child[1].node);
g_assert(!list_is_empty(&parent.children)); assert(!list_is_empty(&parent.children));
g_assert(list_is_empty(&child[1].node)); assert(list_is_empty(&child[1].node));
c = list_first_entry(&parent.children, struct child, node); c = list_first_entry(&parent.children, struct child, node);
g_assert(memcmp(c, &child[0], sizeof(struct child)) == 0); assert(memcmp(c, &child[0], sizeof(struct child)) == 0);
/* delete last node */ /* delete last node */
list_add(&child[1].node, &parent.children); list_add(&child[1].node, &parent.children);
list_del(&child[0].node); list_del(&child[0].node);
c = list_first_entry(&parent.children, struct child, node); c = list_first_entry(&parent.children, struct child, node);
g_assert(memcmp(c, &child[1], sizeof(struct child)) == 0); assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
/* delete list head */ /* delete list head */
list_add(&child[0].node, &parent.children); list_add(&child[0].node, &parent.children);
list_del(&parent.children); list_del(&parent.children);
g_assert(list_is_empty(&parent.children)); assert(list_is_empty(&parent.children));
g_assert(!list_is_empty(&child[1].node)); assert(!list_is_empty(&child[1].node));
g_assert(!list_is_empty(&child[2].node)); assert(!list_is_empty(&child[2].node));
} }
static void static void
@ -148,29 +148,26 @@ test_list_for_each(void)
list_add(&child[0].node, &parent.children); list_add(&child[0].node, &parent.children);
list_for_each_entry(c, &parent.children, node) { list_for_each_entry(c, &parent.children, node) {
g_assert(memcmp(c, &child[i], sizeof(struct child)) == 0); assert(memcmp(c, &child[i], sizeof(struct child)) == 0);
i++; i++;
} }
/* foreach on empty list */ /* foreach on empty list */
list_del(&parent.children); list_del(&parent.children);
g_assert(list_is_empty(&parent.children)); assert(list_is_empty(&parent.children));
list_for_each_entry(c, &parent.children, node) { list_for_each_entry(c, &parent.children, node) {
g_assert(0); /* we must not get here */ assert(0); /* we must not get here */
} }
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
g_test_init(&argc, &argv,NULL); test_list_init();
g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id="); test_list_add();
test_list_del();
test_list_for_each();
g_test_add_func("/list/init", test_list_init); return 0;
g_test_add_func("/list/add", test_list_add);
g_test_add_func("/list/del", test_list_del);
g_test_add_func("/list/for_each", test_list_for_each);
return g_test_run();
} }

View File

@ -1,5 +1,4 @@
if ENABLE_UNIT_TESTS if ENABLE_UNIT_TESTS
if HAVE_GLIB
if HAVE_LD_WRAP if HAVE_LD_WRAP
noinst_PROGRAMS = \ noinst_PROGRAMS = \
protocol-xiqueryversion \ protocol-xiqueryversion \
@ -8,15 +7,16 @@ noinst_PROGRAMS = \
protocol-xigetselectedevents \ protocol-xigetselectedevents \
protocol-xisetclientpointer \ protocol-xisetclientpointer \
protocol-xigetclientpointer \ protocol-xigetclientpointer \
protocol-xipassivegrabdevice \
protocol-xiquerypointer \ protocol-xiquerypointer \
protocol-xiwarppointer \ protocol-xiwarppointer \
protocol-eventconvert protocol-eventconvert
TESTS=$(noinst_PROGRAMS) TESTS=$(noinst_PROGRAMS)
AM_CFLAGS = $(DIX_CFLAGS) $(GLIB_CFLAGS) @XORG_CFLAGS@ AM_CFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@
INCLUDES = @XORG_INCS@ INCLUDES = @XORG_INCS@
TEST_LDADD=../libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS) $(GLIB_LIBS) TEST_LDADD=../libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS)
COMMON_SOURCES=protocol-common.h protocol-common.c COMMON_SOURCES=protocol-common.h protocol-common.c
if SPECIAL_DTRACE_OBJECTS if SPECIAL_DTRACE_OBJECTS
@ -30,6 +30,7 @@ protocol_xigetselectedevents_LDADD=$(TEST_LDADD)
protocol_xisetclientpointer_LDADD=$(TEST_LDADD) protocol_xisetclientpointer_LDADD=$(TEST_LDADD)
protocol_xigetclientpointer_LDADD=$(TEST_LDADD) protocol_xigetclientpointer_LDADD=$(TEST_LDADD)
protocol_xiquerypointer_LDADD=$(TEST_LDADD) protocol_xiquerypointer_LDADD=$(TEST_LDADD)
protocol_xipassivegrabdevice_LDADD=$(TEST_LDADD)
protocol_xiwarppointer_LDADD=$(TEST_LDADD) protocol_xiwarppointer_LDADD=$(TEST_LDADD)
protocol_eventconvert_LDADD=$(TEST_LDADD) protocol_eventconvert_LDADD=$(TEST_LDADD)
@ -39,6 +40,7 @@ protocol_xiselectevents_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,dixLookupWindow -Wl,-wra
protocol_xigetselectedevents_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow -Wl,-wrap,AddResource protocol_xigetselectedevents_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow -Wl,-wrap,AddResource
protocol_xisetclientpointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,dixLookupClient protocol_xisetclientpointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,dixLookupClient
protocol_xigetclientpointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupClient protocol_xigetclientpointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupClient
protocol_xipassivegrabdevice_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,GrabButton -Wl,-wrap,dixLookupWindow -Wl,-wrap,WriteToClient
protocol_xiquerypointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow protocol_xiquerypointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow
protocol_xiwarppointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow protocol_xiwarppointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow
@ -49,7 +51,7 @@ protocol_xigetselectedevents_SOURCES=$(COMMON_SOURCES) protocol-xigetselectedeve
protocol_xisetclientpointer_SOURCES=$(COMMON_SOURCES) protocol-xisetclientpointer.c protocol_xisetclientpointer_SOURCES=$(COMMON_SOURCES) protocol-xisetclientpointer.c
protocol_xigetclientpointer_SOURCES=$(COMMON_SOURCES) protocol-xigetclientpointer.c protocol_xigetclientpointer_SOURCES=$(COMMON_SOURCES) protocol-xigetclientpointer.c
protocol_xiquerypointer_SOURCES=$(COMMON_SOURCES) protocol-xiquerypointer.c protocol_xiquerypointer_SOURCES=$(COMMON_SOURCES) protocol-xiquerypointer.c
protocol_xipassivegrabdevice_SOURCES=$(COMMON_SOURCES) protocol-xipassivegrabdevice.c
protocol_xiwarppointer_SOURCES=$(COMMON_SOURCES) protocol-xiwarppointer.c protocol_xiwarppointer_SOURCES=$(COMMON_SOURCES) protocol-xiwarppointer.c
endif endif
endif endif
endif

View File

@ -29,7 +29,6 @@
#include "extinit.h" /* for XInputExtensionInit */ #include "extinit.h" /* for XInputExtensionInit */
#include "exglobals.h" #include "exglobals.h"
#include "xkbsrv.h" /* for XkbInitPrivates */ #include "xkbsrv.h" /* for XkbInitPrivates */
#include <glib.h>
#include "protocol-common.h" #include "protocol-common.h"
@ -134,7 +133,7 @@ void init_window(WindowPtr window, WindowPtr parent, int id)
} }
window->parent = parent; window->parent = parent;
window->optional = calloc(1, sizeof(WindowOptRec)); window->optional = calloc(1, sizeof(WindowOptRec));
g_assert(window->optional); assert(window->optional);
} }
extern DevPrivateKeyRec miPointerScreenKeyRec; extern DevPrivateKeyRec miPointerScreenKeyRec;
@ -171,7 +170,7 @@ void init_simple(void)
void __wrap_WriteToClient(ClientPtr client, int len, void *data) void __wrap_WriteToClient(ClientPtr client, int len, void *data)
{ {
g_assert(reply_handler != NULL); assert(reply_handler != NULL);
(*reply_handler)(client, len, data, userdata); (*reply_handler)(client, len, data, userdata);
} }

View File

@ -29,6 +29,7 @@
#include "windowstr.h" #include "windowstr.h"
#include "scrnintstr.h" #include "scrnintstr.h"
#include "exevents.h" #include "exevents.h"
#include <assert.h>
#ifndef PROTOCOL_COMMON_H #ifndef PROTOCOL_COMMON_H
#define PROTOCOL_COMMON_H #define PROTOCOL_COMMON_H
@ -38,11 +39,11 @@ extern int BadDevice;
/* Check default values in a reply */ /* Check default values in a reply */
#define reply_check_defaults(rep, len, type) \ #define reply_check_defaults(rep, len, type) \
{ \ { \
g_assert((len) >= sz_x##type##Reply); \ assert((len) >= sz_x##type##Reply); \
g_assert((rep)->repType == X_Reply); \ assert((rep)->repType == X_Reply); \
g_assert((rep)->RepType == X_##type); \ assert((rep)->RepType == X_##type); \
g_assert((rep)->sequenceNumber == CLIENT_SEQUENCE); \ assert((rep)->sequenceNumber == CLIENT_SEQUENCE); \
g_assert((rep)->length >= (sz_x##type##Reply - 32)/4); \ assert((rep)->length >= (sz_x##type##Reply - 32)/4); \
} }
/* initialise default values for request */ /* initialise default values for request */

View File

@ -25,7 +25,6 @@
#endif #endif
#include <stdint.h> #include <stdint.h>
#include <glib.h>
#include "inputstr.h" #include "inputstr.h"
#include "eventstr.h" #include "eventstr.h"
@ -33,7 +32,6 @@
#include "exevents.h" #include "exevents.h"
#include <X11/extensions/XI2proto.h> #include <X11/extensions/XI2proto.h>
static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out, static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
BOOL swap) BOOL swap)
{ {
@ -58,21 +56,21 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
} }
g_assert(out->type == GenericEvent); assert(out->type == GenericEvent);
g_assert(out->extension == 0); /* IReqCode defaults to 0 */ assert(out->extension == 0); /* IReqCode defaults to 0 */
g_assert(out->evtype == GetXI2Type((InternalEvent*)in)); assert(out->evtype == GetXI2Type((InternalEvent*)in));
g_assert(out->time == in->time); assert(out->time == in->time);
g_assert(out->detail == in->detail.button); assert(out->detail == in->detail.button);
g_assert(out->deviceid == in->deviceid); assert(out->deviceid == in->deviceid);
g_assert(out->valuators_len >= bytes_to_int32(bits_to_bytes(sizeof(in->valuators.mask)))); assert(out->valuators_len >= bytes_to_int32(bits_to_bytes(sizeof(in->valuators.mask))));
g_assert(out->flags == 0); /* FIXME: we don't set the flags yet */ assert(out->flags == 0); /* FIXME: we don't set the flags yet */
ptr = (unsigned char*)&out[1]; ptr = (unsigned char*)&out[1];
bits_set = 0; bits_set = 0;
for (i = 0; out->valuators_len && i < sizeof(in->valuators.mask) * 8; i++) for (i = 0; out->valuators_len && i < sizeof(in->valuators.mask) * 8; i++)
{ {
g_assert (XIMaskIsSet(in->valuators.mask, i) == XIMaskIsSet(ptr, i)); assert (XIMaskIsSet(in->valuators.mask, i) == XIMaskIsSet(ptr, i));
if (XIMaskIsSet(in->valuators.mask, i)) if (XIMaskIsSet(in->valuators.mask, i))
bits_set++; bits_set++;
} }
@ -81,13 +79,13 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
* set. Each bit set represents 2 8-byte values, hence the * set. Each bit set represents 2 8-byte values, hence the
* 'bits_set * 4' */ * 'bits_set * 4' */
len = out->valuators_len + bits_set * 4; len = out->valuators_len + bits_set * 4;
g_assert(out->length == len); assert(out->length == len);
nvals = 0; nvals = 0;
for (i = 0; out->valuators_len && i < MAX_VALUATORS; i++) for (i = 0; out->valuators_len && i < MAX_VALUATORS; i++)
{ {
g_assert (XIMaskIsSet(in->valuators.mask, i) == XIMaskIsSet(ptr, i)); assert (XIMaskIsSet(in->valuators.mask, i) == XIMaskIsSet(ptr, i));
if (XIMaskIsSet(in->valuators.mask, i)) if (XIMaskIsSet(in->valuators.mask, i))
{ {
FP3232 vi, vo; FP3232 vi, vo;
@ -106,8 +104,8 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
swapl(&vo.frac, n); swapl(&vo.frac, n);
} }
g_assert(vi.integral == vo.integral); assert(vi.integral == vo.integral);
g_assert(vi.frac == vo.frac); assert(vi.frac == vo.frac);
raw_value = value + bits_set; raw_value = value + bits_set;
@ -123,8 +121,8 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
swapl(&vo.frac, n); swapl(&vo.frac, n);
} }
g_assert(vi.integral == vo.integral); assert(vi.integral == vo.integral);
g_assert(vi.frac == vo.frac); assert(vi.frac == vo.frac);
nvals++; nvals++;
} }
@ -137,7 +135,7 @@ static void test_XIRawEvent(RawDeviceEvent *in)
int rc; int rc;
rc = EventToXI2((InternalEvent*)in, (xEvent**)&out); rc = EventToXI2((InternalEvent*)in, (xEvent**)&out);
g_assert(rc == Success); assert(rc == Success);
test_values_XIRawEvent(in, out, FALSE); test_values_XIRawEvent(in, out, FALSE);
@ -158,24 +156,24 @@ static void test_convert_XIFocusEvent(void)
in.header = ET_Internal; in.header = ET_Internal;
in.type = ET_Enter; in.type = ET_Enter;
rc = EventToXI2((InternalEvent*)&in, &out); rc = EventToXI2((InternalEvent*)&in, &out);
g_assert(rc == Success); assert(rc == Success);
g_assert(out == NULL); assert(out == NULL);
in.header = ET_Internal; in.header = ET_Internal;
in.type = ET_FocusIn; in.type = ET_FocusIn;
rc = EventToXI2((InternalEvent*)&in, &out); rc = EventToXI2((InternalEvent*)&in, &out);
g_assert(rc == Success); assert(rc == Success);
g_assert(out == NULL); assert(out == NULL);
in.header = ET_Internal; in.header = ET_Internal;
in.type = ET_FocusOut; in.type = ET_FocusOut;
rc = EventToXI2((InternalEvent*)&in, &out); rc = EventToXI2((InternalEvent*)&in, &out);
g_assert(rc == BadImplementation); assert(rc == BadImplementation);
in.header = ET_Internal; in.header = ET_Internal;
in.type = ET_Leave; in.type = ET_Leave;
rc = EventToXI2((InternalEvent*)&in, &out); rc = EventToXI2((InternalEvent*)&in, &out);
g_assert(rc == BadImplementation); assert(rc == BadImplementation);
} }
@ -186,7 +184,7 @@ static void test_convert_XIRawEvent(void)
memset(&in, 0, sizeof(in)); memset(&in, 0, sizeof(in));
g_test_message("Testing all event types"); printf("Testing all event types\n");
in.header = ET_Internal; in.header = ET_Internal;
in.type = ET_RawMotion; in.type = ET_RawMotion;
test_XIRawEvent(&in); test_XIRawEvent(&in);
@ -207,7 +205,7 @@ static void test_convert_XIRawEvent(void)
in.type = ET_RawButtonRelease; in.type = ET_RawButtonRelease;
test_XIRawEvent(&in); test_XIRawEvent(&in);
g_test_message("Testing details and other fields"); printf("Testing details and other fields\n");
in.detail.button = 1L; in.detail.button = 1L;
test_XIRawEvent(&in); test_XIRawEvent(&in);
in.detail.button = 1L << 8; in.detail.button = 1L << 8;
@ -239,7 +237,7 @@ static void test_convert_XIRawEvent(void)
in.deviceid = ~0 & 0xFF; in.deviceid = ~0 & 0xFF;
test_XIRawEvent(&in); test_XIRawEvent(&in);
g_test_message("Testing valuator masks"); printf("Testing valuator masks\n");
for (i = 0; i < sizeof(in.valuators.mask) * 8; i++) for (i = 0; i < sizeof(in.valuators.mask) * 8; i++)
{ {
XISetMask(in.valuators.mask, i); XISetMask(in.valuators.mask, i);
@ -301,14 +299,14 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
swapl(&out->flags, n); swapl(&out->flags, n);
} }
g_assert(out->extension == 0); /* IReqCode defaults to 0 */ assert(out->extension == 0); /* IReqCode defaults to 0 */
g_assert(out->evtype == GetXI2Type((InternalEvent*)in)); assert(out->evtype == GetXI2Type((InternalEvent*)in));
g_assert(out->time == in->time); assert(out->time == in->time);
g_assert(out->detail == in->detail.button); assert(out->detail == in->detail.button);
g_assert(out->length >= 12); assert(out->length >= 12);
g_assert(out->deviceid == in->deviceid); assert(out->deviceid == in->deviceid);
g_assert(out->sourceid == in->sourceid); assert(out->sourceid == in->sourceid);
switch (in->type) { switch (in->type) {
case ET_KeyPress: case ET_KeyPress:
@ -318,41 +316,41 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
flagmask = 0; flagmask = 0;
break; break;
} }
g_assert((out->flags & ~flagmask) == 0); assert((out->flags & ~flagmask) == 0);
g_assert(out->root == in->root); assert(out->root == in->root);
g_assert(out->event == None); /* set in FixUpEventFromWindow */ assert(out->event == None); /* set in FixUpEventFromWindow */
g_assert(out->child == None); /* set in FixUpEventFromWindow */ assert(out->child == None); /* set in FixUpEventFromWindow */
g_assert(out->mods.base_mods == in->mods.base); assert(out->mods.base_mods == in->mods.base);
g_assert(out->mods.latched_mods == in->mods.latched); assert(out->mods.latched_mods == in->mods.latched);
g_assert(out->mods.locked_mods == in->mods.locked); assert(out->mods.locked_mods == in->mods.locked);
g_assert(out->mods.effective_mods == in->mods.effective); assert(out->mods.effective_mods == in->mods.effective);
g_assert(out->group.base_group == in->group.base); assert(out->group.base_group == in->group.base);
g_assert(out->group.latched_group == in->group.latched); assert(out->group.latched_group == in->group.latched);
g_assert(out->group.locked_group == in->group.locked); assert(out->group.locked_group == in->group.locked);
g_assert(out->group.effective_group == in->group.effective); assert(out->group.effective_group == in->group.effective);
g_assert(out->event_x == 0); /* set in FixUpEventFromWindow */ assert(out->event_x == 0); /* set in FixUpEventFromWindow */
g_assert(out->event_y == 0); /* set in FixUpEventFromWindow */ assert(out->event_y == 0); /* set in FixUpEventFromWindow */
g_assert(out->root_x == FP1616(in->root_x, in->root_x_frac)); assert(out->root_x == FP1616(in->root_x, in->root_x_frac));
g_assert(out->root_y == FP1616(in->root_y, in->root_y_frac)); assert(out->root_y == FP1616(in->root_y, in->root_y_frac));
buttons = 0; buttons = 0;
for (i = 0; i < bits_to_bytes(sizeof(in->buttons)); i++) for (i = 0; i < bits_to_bytes(sizeof(in->buttons)); i++)
{ {
if (XIMaskIsSet(in->buttons, i)) if (XIMaskIsSet(in->buttons, i))
{ {
g_assert(out->buttons_len >= bytes_to_int32(bits_to_bytes(i))); assert(out->buttons_len >= bytes_to_int32(bits_to_bytes(i)));
buttons++; buttons++;
} }
} }
ptr = (unsigned char*)&out[1]; ptr = (unsigned char*)&out[1];
for (i = 0; i < sizeof(in->buttons) * 8; i++) for (i = 0; i < sizeof(in->buttons) * 8; i++)
g_assert(XIMaskIsSet(in->buttons, i) == XIMaskIsSet(ptr, i)); assert(XIMaskIsSet(in->buttons, i) == XIMaskIsSet(ptr, i));
valuators = 0; valuators = 0;
@ -360,7 +358,7 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
if (XIMaskIsSet(in->valuators.mask, i)) if (XIMaskIsSet(in->valuators.mask, i))
valuators++; valuators++;
g_assert(out->valuators_len >= bytes_to_int32(bits_to_bytes(valuators))); assert(out->valuators_len >= bytes_to_int32(bits_to_bytes(valuators)));
ptr += out->buttons_len * 4; ptr += out->buttons_len * 4;
values = (FP3232*)(ptr + out->valuators_len * 4); values = (FP3232*)(ptr + out->valuators_len * 4);
@ -368,11 +366,11 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
i < (out->valuators_len * 4) * 8; i++) i < (out->valuators_len * 4) * 8; i++)
{ {
if (i > sizeof(in->valuators.mask) * 8) if (i > sizeof(in->valuators.mask) * 8)
g_assert(!XIMaskIsSet(ptr, i)); assert(!XIMaskIsSet(ptr, i));
else if (i > out->valuators_len * 4 * 8) else if (i > out->valuators_len * 4 * 8)
g_assert(!XIMaskIsSet(in->valuators.mask, i)); assert(!XIMaskIsSet(in->valuators.mask, i));
else { else {
g_assert(XIMaskIsSet(in->valuators.mask, i) == assert(XIMaskIsSet(in->valuators.mask, i) ==
XIMaskIsSet(ptr, i)); XIMaskIsSet(ptr, i));
if (XIMaskIsSet(ptr, i)) if (XIMaskIsSet(ptr, i))
@ -392,8 +390,8 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
} }
g_assert(vi.integral == vo.integral); assert(vi.integral == vo.integral);
g_assert(vi.frac == vo.frac); assert(vi.frac == vo.frac);
values++; values++;
} }
} }
@ -406,7 +404,7 @@ static void test_XIDeviceEvent(DeviceEvent *in)
int rc; int rc;
rc = EventToXI2((InternalEvent*)in, (xEvent**)&out); rc = EventToXI2((InternalEvent*)in, (xEvent**)&out);
g_assert(rc == Success); assert(rc == Success);
test_values_XIDeviceEvent(in, out, FALSE); test_values_XIDeviceEvent(in, out, FALSE);
@ -425,7 +423,7 @@ static void test_convert_XIDeviceEvent(void)
memset(&in, 0, sizeof(in)); memset(&in, 0, sizeof(in));
g_test_message("Testing simple field values"); printf("Testing simple field values\n");
in.header = ET_Internal; in.header = ET_Internal;
in.type = ET_Motion; in.type = ET_Motion;
in.length = sizeof(DeviceEvent); in.length = sizeof(DeviceEvent);
@ -449,7 +447,7 @@ static void test_convert_XIDeviceEvent(void)
test_XIDeviceEvent(&in); test_XIDeviceEvent(&in);
g_test_message("Testing field ranges"); printf("Testing field ranges\n");
/* 32 bit */ /* 32 bit */
in.detail.button = 1L; in.detail.button = 1L;
test_XIDeviceEvent(&in); test_XIDeviceEvent(&in);
@ -597,7 +595,7 @@ static void test_convert_XIDeviceEvent(void)
in.mods.effective = ~0 & 0xFF; in.mods.effective = ~0 & 0xFF;
test_XIDeviceEvent(&in); test_XIDeviceEvent(&in);
g_test_message("Testing button masks"); printf("Testing button masks\n");
for (i = 0; i < sizeof(in.buttons) * 8; i++) for (i = 0; i < sizeof(in.buttons) * 8; i++)
{ {
XISetMask(in.buttons, i); XISetMask(in.buttons, i);
@ -611,7 +609,7 @@ static void test_convert_XIDeviceEvent(void)
test_XIDeviceEvent(&in); test_XIDeviceEvent(&in);
} }
g_test_message("Testing valuator masks"); printf("Testing valuator masks\n");
for (i = 0; i < sizeof(in.valuators.mask) * 8; i++) for (i = 0; i < sizeof(in.valuators.mask) * 8; i++)
{ {
XISetMask(in.valuators.mask, i); XISetMask(in.valuators.mask, i);
@ -656,12 +654,12 @@ static void test_values_XIDeviceChangedEvent(DeviceChangedEvent *in,
swaps(&out->num_classes, n); swaps(&out->num_classes, n);
} }
g_assert(out->type == GenericEvent); assert(out->type == GenericEvent);
g_assert(out->extension == 0); /* IReqCode defaults to 0 */ assert(out->extension == 0); /* IReqCode defaults to 0 */
g_assert(out->evtype == GetXI2Type((InternalEvent*)in)); assert(out->evtype == GetXI2Type((InternalEvent*)in));
g_assert(out->time == in->time); assert(out->time == in->time);
g_assert(out->deviceid == in->deviceid); assert(out->deviceid == in->deviceid);
g_assert(out->sourceid == in->sourceid); assert(out->sourceid == in->sourceid);
ptr = (unsigned char*)&out[1]; ptr = (unsigned char*)&out[1];
for (i = 0; i < out->num_classes; i++) for (i = 0; i < out->num_classes; i++)
@ -689,11 +687,11 @@ static void test_values_XIDeviceChangedEvent(DeviceChangedEvent *in,
swaps(&b->num_buttons, n); swaps(&b->num_buttons, n);
} }
g_assert(b->length == assert(b->length ==
bytes_to_int32(sizeof(xXIButtonInfo)) + bytes_to_int32(sizeof(xXIButtonInfo)) +
bytes_to_int32(bits_to_bytes(b->num_buttons)) + bytes_to_int32(bits_to_bytes(b->num_buttons)) +
b->num_buttons); b->num_buttons);
g_assert(b->num_buttons == in->buttons.num_buttons); assert(b->num_buttons == in->buttons.num_buttons);
names = (Atom*)((char*)&b[1] + names = (Atom*)((char*)&b[1] +
pad_to_int32(bits_to_bytes(b->num_buttons))); pad_to_int32(bits_to_bytes(b->num_buttons)));
@ -704,7 +702,7 @@ static void test_values_XIDeviceChangedEvent(DeviceChangedEvent *in,
char n; char n;
swapl(&names[j], n); swapl(&names[j], n);
} }
g_assert(names[j] == in->buttons.names[j]); assert(names[j] == in->buttons.names[j]);
} }
} }
break; break;
@ -719,10 +717,10 @@ static void test_values_XIDeviceChangedEvent(DeviceChangedEvent *in,
swaps(&k->num_keycodes, n); swaps(&k->num_keycodes, n);
} }
g_assert(k->length == assert(k->length ==
bytes_to_int32(sizeof(xXIKeyInfo)) + bytes_to_int32(sizeof(xXIKeyInfo)) +
k->num_keycodes); k->num_keycodes);
g_assert(k->num_keycodes == in->keys.max_keycode - assert(k->num_keycodes == in->keys.max_keycode -
in->keys.min_keycode + 1); in->keys.min_keycode + 1);
kc = (uint32_t*)&k[1]; kc = (uint32_t*)&k[1];
@ -733,21 +731,22 @@ static void test_values_XIDeviceChangedEvent(DeviceChangedEvent *in,
char n; char n;
swapl(&kc[j], n); swapl(&kc[j], n);
} }
g_assert(kc[j] >= in->keys.min_keycode); assert(kc[j] >= in->keys.min_keycode);
g_assert(kc[j] <= in->keys.max_keycode); assert(kc[j] <= in->keys.max_keycode);
} }
} }
break; break;
case XIValuatorClass: case XIValuatorClass:
{ {
xXIValuatorInfo *v = (xXIValuatorInfo*)any; xXIValuatorInfo *v = (xXIValuatorInfo*)any;
g_assert(v->length == assert(v->length ==
bytes_to_int32(sizeof(xXIValuatorInfo))); bytes_to_int32(sizeof(xXIValuatorInfo)));
} }
break; break;
default: default:
g_error("Invalid class type.\n"); printf("Invalid class type.\n\n");
assert(1);
break; break;
} }
@ -762,7 +761,7 @@ static void test_XIDeviceChangedEvent(DeviceChangedEvent *in)
int rc; int rc;
rc = EventToXI2((InternalEvent*)in, (xEvent**)&out); rc = EventToXI2((InternalEvent*)in, (xEvent**)&out);
g_assert(rc == Success); assert(rc == Success);
test_values_XIDeviceChangedEvent(in, out, FALSE); test_values_XIDeviceChangedEvent(in, out, FALSE);
@ -779,7 +778,7 @@ static void test_convert_XIDeviceChangedEvent(void)
DeviceChangedEvent in; DeviceChangedEvent in;
int i; int i;
g_test_message("Testing simple field values"); printf("Testing simple field values\n");
memset(&in, 0, sizeof(in)); memset(&in, 0, sizeof(in));
in.header = ET_Internal; in.header = ET_Internal;
in.type = ET_DeviceChanged; in.type = ET_DeviceChanged;
@ -905,13 +904,10 @@ static void test_convert_XIDeviceChangedEvent(void)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
g_test_init(&argc, &argv,NULL); test_convert_XIRawEvent();
g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id="); test_convert_XIFocusEvent();
test_convert_XIDeviceEvent();
test_convert_XIDeviceChangedEvent();
g_test_add_func("/xi2/eventconvert/XIRawEvent", test_convert_XIRawEvent); return 0;
g_test_add_func("/xi2/eventconvert/XIFocusEvent", test_convert_XIFocusEvent);
g_test_add_func("/xi2/eventconvert/XIDeviceEvent", test_convert_XIDeviceEvent);
g_test_add_func("/xi2/eventconvert/XIDeviceChangedEvent", test_convert_XIDeviceChangedEvent);
return g_test_run();
} }

View File

@ -39,7 +39,6 @@
#include "exevents.h" #include "exevents.h"
#include "protocol-common.h" #include "protocol-common.h"
#include <glib.h>
struct { struct {
int cp_is_set; int cp_is_set;
@ -79,9 +78,9 @@ static void reply_XIGetClientPointer(ClientPtr client, int len, char *data, void
reply_check_defaults(rep, len, XIGetClientPointer); reply_check_defaults(rep, len, XIGetClientPointer);
g_assert(rep->set == test_data.cp_is_set); assert(rep->set == test_data.cp_is_set);
if (rep->set) if (rep->set)
g_assert(rep->deviceid == test_data.dev->id); assert(rep->deviceid == test_data.dev->id);
} }
static void request_XIGetClientPointer(ClientPtr client, xXIGetClientPointerReq* req, int error) static void request_XIGetClientPointer(ClientPtr client, xXIGetClientPointerReq* req, int error)
@ -92,19 +91,19 @@ static void request_XIGetClientPointer(ClientPtr client, xXIGetClientPointerReq*
test_data.win = req->win; test_data.win = req->win;
rc = ProcXIGetClientPointer(&client_request); rc = ProcXIGetClientPointer(&client_request);
g_assert(rc == error); assert(rc == error);
if (rc == BadWindow) if (rc == BadWindow)
g_assert(client_request.errorValue == req->win); assert(client_request.errorValue == req->win);
client_request.swapped = TRUE; client_request.swapped = TRUE;
swapl(&req->win, n); swapl(&req->win, n);
swaps(&req->length, n); swaps(&req->length, n);
rc = SProcXIGetClientPointer(&client_request); rc = SProcXIGetClientPointer(&client_request);
g_assert(rc == error); assert(rc == error);
if (rc == BadWindow) if (rc == BadWindow)
g_assert(client_request.errorValue == req->win); assert(client_request.errorValue == req->win);
} }
@ -121,21 +120,21 @@ static void test_XIGetClientPointer(void)
client_request = init_client(request.length, &request); client_request = init_client(request.length, &request);
g_test_message("Testing invalid window"); printf("Testing invalid window\n");
request.win = INVALID_WINDOW_ID; request.win = INVALID_WINDOW_ID;
request_XIGetClientPointer(&client_request, &request, BadWindow); request_XIGetClientPointer(&client_request, &request, BadWindow);
test_data.cp_is_set = FALSE; test_data.cp_is_set = FALSE;
g_test_message("Testing window None, unset ClientPointer."); printf("Testing window None, unset ClientPointer.\n");
request.win = None; request.win = None;
request_XIGetClientPointer(&client_request, &request, Success); request_XIGetClientPointer(&client_request, &request, Success);
g_test_message("Testing valid window, unset ClientPointer."); printf("Testing valid window, unset ClientPointer.\n");
request.win = CLIENT_WINDOW_ID; request.win = CLIENT_WINDOW_ID;
request_XIGetClientPointer(&client_request, &request, Success); request_XIGetClientPointer(&client_request, &request, Success);
g_test_message("Testing valid window, set ClientPointer."); printf("Testing valid window, set ClientPointer.\n");
client_window.clientPtr = devices.vcp; client_window.clientPtr = devices.vcp;
test_data.dev = devices.vcp; test_data.dev = devices.vcp;
test_data.cp_is_set = TRUE; test_data.cp_is_set = TRUE;
@ -144,7 +143,7 @@ static void test_XIGetClientPointer(void)
client_window.clientPtr = NULL; client_window.clientPtr = NULL;
g_test_message("Testing window None, set ClientPointer."); printf("Testing window None, set ClientPointer.\n");
client_request.clientPtr = devices.vcp; client_request.clientPtr = devices.vcp;
test_data.dev = devices.vcp; test_data.dev = devices.vcp;
test_data.cp_is_set = TRUE; test_data.cp_is_set = TRUE;
@ -154,14 +153,10 @@ static void test_XIGetClientPointer(void)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
g_test_init(&argc, &argv,NULL);
g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
init_simple(); init_simple();
client_window = init_client(0, NULL); client_window = init_client(0, NULL);
test_XIGetClientPointer();
g_test_add_func("/xi2/protocol/XIGetClientPointer", test_XIGetClientPointer); return 0;
return g_test_run();
} }

View File

@ -48,7 +48,6 @@
#include "exevents.h" #include "exevents.h"
#include "protocol-common.h" #include "protocol-common.h"
#include <glib.h>
static void reply_XIGetSelectedEvents(ClientPtr client, int len, char *data, void *userdata); static void reply_XIGetSelectedEvents(ClientPtr client, int len, char *data, void *userdata);
static void reply_XIGetSelectedEvents_data(ClientPtr client, int len, char *data, void *userdata); static void reply_XIGetSelectedEvents_data(ClientPtr client, int len, char *data, void *userdata);
@ -100,7 +99,7 @@ static void reply_XIGetSelectedEvents(ClientPtr client, int len, char *data, voi
reply_check_defaults(rep, len, XIGetSelectedEvents); reply_check_defaults(rep, len, XIGetSelectedEvents);
g_assert(rep->num_masks == test_data.num_masks_expected); assert(rep->num_masks == test_data.num_masks_expected);
reply_handler = reply_XIGetSelectedEvents_data; reply_handler = reply_XIGetSelectedEvents_data;
} }
@ -121,11 +120,11 @@ static void reply_XIGetSelectedEvents_data(ClientPtr client, int len, char *data
swaps(&mask->mask_len, n); swaps(&mask->mask_len, n);
} }
g_assert(mask->deviceid < 6); assert(mask->deviceid < 6);
g_assert(mask->mask_len <= (((XI2LASTEVENT + 8)/8) + 3)/4) ; assert(mask->mask_len <= (((XI2LASTEVENT + 8)/8) + 3)/4) ;
bitmask = (unsigned char*)&mask[1]; bitmask = (unsigned char*)&mask[1];
g_assert(memcmp(bitmask, assert(memcmp(bitmask,
test_data.mask[mask->deviceid], test_data.mask[mask->deviceid],
mask->mask_len * 4) == 0); mask->mask_len * 4) == 0);
@ -145,14 +144,14 @@ static void request_XIGetSelectedEvents(xXIGetSelectedEventsReq* req, int error)
reply_handler = reply_XIGetSelectedEvents; reply_handler = reply_XIGetSelectedEvents;
rc = ProcXIGetSelectedEvents(&client); rc = ProcXIGetSelectedEvents(&client);
g_assert(rc == error); assert(rc == error);
reply_handler = reply_XIGetSelectedEvents; reply_handler = reply_XIGetSelectedEvents;
client.swapped = TRUE; client.swapped = TRUE;
swapl(&req->win, n); swapl(&req->win, n);
swaps(&req->length, n); swaps(&req->length, n);
rc = SProcXIGetSelectedEvents(&client); rc = SProcXIGetSelectedEvents(&client);
g_assert(rc == error); assert(rc == error);
} }
static void test_XIGetSelectedEvents(void) static void test_XIGetSelectedEvents(void)
@ -165,11 +164,11 @@ static void test_XIGetSelectedEvents(void)
request_init(&request, XIGetSelectedEvents); request_init(&request, XIGetSelectedEvents);
g_test_message("Testing for BadWindow on invalid window."); printf("Testing for BadWindow on invalid window.\n");
request.win = None; request.win = None;
request_XIGetSelectedEvents(&request, BadWindow); request_XIGetSelectedEvents(&request, BadWindow);
g_test_message("Testing for zero-length (unset) masks."); printf("Testing for zero-length (unset) masks.\n");
/* No masks set yet */ /* No masks set yet */
test_data.num_masks_expected = 0; test_data.num_masks_expected = 0;
request.win = ROOT_WINDOW_ID; request.win = ROOT_WINDOW_ID;
@ -181,7 +180,7 @@ static void test_XIGetSelectedEvents(void)
memset(test_data.mask, 0, memset(test_data.mask, 0,
sizeof(test_data.mask)); sizeof(test_data.mask));
g_test_message("Testing for valid masks"); printf("Testing for valid masks\n");
memset(&dev, 0, sizeof(dev)); /* dev->id is enough for XISetEventMask */ memset(&dev, 0, sizeof(dev)); /* dev->id is enough for XISetEventMask */
request.win = ROOT_WINDOW_ID; request.win = ROOT_WINDOW_ID;
@ -210,7 +209,7 @@ static void test_XIGetSelectedEvents(void)
} }
} }
g_test_message("Testing removing all masks"); printf("Testing removing all masks\n");
/* Unset all masks one-by-one */ /* Unset all masks one-by-one */
for (j = MAXDEVICES - 1; j >= 0; j--) for (j = MAXDEVICES - 1; j >= 0; j--)
{ {
@ -229,13 +228,10 @@ static void test_XIGetSelectedEvents(void)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
g_test_init(&argc, &argv,NULL);
g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
init_simple(); init_simple();
g_test_add_func("/xi2/protocol/XIGetSelectedEvents", test_XIGetSelectedEvents); test_XIGetSelectedEvents();
return g_test_run(); return 0;
} }

View File

@ -0,0 +1,234 @@
/**
* Copyright © 2011 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
/*
* Protocol testing for XIPassiveGrab request.
*/
#include <stdint.h>
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/extensions/XI2proto.h>
#include "inputstr.h"
#include "windowstr.h"
#include "scrnintstr.h"
#include "xipassivegrab.h"
#include "exevents.h"
#include "protocol-common.h"
static ClientRec client_request;
#define N_MODS 7
static uint32_t modifiers[N_MODS] = {1, 2, 3, 4, 5, 6, 7};
struct test_data {
int num_modifiers;
} testdata;
int __wrap_GrabButton(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
int button, GrabParameters *param, GrabType grabtype,
GrabMask *mask);
static void reply_XIPassiveGrabDevice_data(ClientPtr client, int len, char *data, void *userdata);
int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access)
{
if (id == root.drawable.id)
{
*win = &root;
return Success;
} else if (id == window.drawable.id)
{
*win = &window;
return Success;
}
return __real_dixLookupWindow(win, id, client, access);
}
int __wrap_GrabButton(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
int button, GrabParameters *param, GrabType grabtype,
GrabMask *mask)
{
/* Fail every odd modifier */
if (param->modifiers % 2)
return BadAccess;
return Success;
}
static void reply_XIPassiveGrabDevice(ClientPtr client, int len, char *data, void *userdata)
{
xXIPassiveGrabDeviceReply *rep = (xXIPassiveGrabDeviceReply*)data;
if (client->swapped)
{
char n;
swaps(&rep->sequenceNumber, n);
swapl(&rep->length, n);
swaps(&rep->num_modifiers, n);
testdata.num_modifiers = rep->num_modifiers;
}
reply_check_defaults(rep, len, XIPassiveGrabDevice);
/* ProcXIPassiveGrabDevice sends the data in two batches, let the second
* handler handle the modifier data */
if (rep->num_modifiers > 0)
reply_handler = reply_XIPassiveGrabDevice_data;
}
static void reply_XIPassiveGrabDevice_data(ClientPtr client, int len, char *data, void *userdata)
{
int i;
int n;
xXIGrabModifierInfo *mods = (xXIGrabModifierInfo*)data;
for (i = 0; i < testdata.num_modifiers; i++, mods++)
{
if (client->swapped)
swapl(&mods->modifiers, n);
/* 1 - 7 is the range we use for the global modifiers array
* above */
assert(mods->modifiers > 0);
assert(mods->modifiers <= 7);
assert(mods->modifiers % 2 == 1); /* because we fail odd ones */
assert(mods->status != Success);
assert(mods->pad0 == 0);
assert(mods->pad1 == 0);
}
reply_handler = reply_XIPassiveGrabDevice;
}
static void request_XIPassiveGrabDevice(ClientPtr client, xXIPassiveGrabDeviceReq* req, int error, int errval)
{
char n;
int rc;
int modifiers;
rc = ProcXIPassiveGrabDevice(&client_request);
assert(rc == error);
if (rc != Success)
assert(client_request.errorValue == errval);
client_request.swapped = TRUE;
swaps(&req->length, n);
swapl(&req->time, n);
swapl(&req->grab_window, n);
swapl(&req->cursor, n);
swapl(&req->detail, n);
swaps(&req->deviceid, n);
modifiers = req->num_modifiers;
swaps(&req->num_modifiers, n);
swaps(&req->mask_len, n);
while(modifiers--)
{
CARD32 *mod = ((CARD32*)(req + 1)) + modifiers;
swapl(mod, n);
}
rc = SProcXIPassiveGrabDevice(&client_request);
assert(rc == error);
if (rc != Success)
assert(client_request.errorValue == errval);
}
static unsigned char *data[4096]; /* the request buffer */
static void test_XIPassiveGrabDevice(void)
{
int i;
xXIPassiveGrabDeviceReq *request = (xXIPassiveGrabDeviceReq*)data;
unsigned char *mask;
request_init(request, XIPassiveGrabDevice);
request->grab_window = CLIENT_WINDOW_ID;
reply_handler = reply_XIPassiveGrabDevice;
client_request = init_client(request->length, request);
printf("Testing invalid device\n");
request->deviceid = 12;
request_XIPassiveGrabDevice(&client_request, request, BadDevice, request->deviceid);
request->deviceid = XIAllMasterDevices;
printf("Testing invalid grab types\n");
for (i = XIGrabtypeFocusIn + 1; i < 0xFF; i++)
{
request->grab_type = i;
request_XIPassiveGrabDevice(&client_request, request, BadValue, request->grab_type);
}
printf("Testing invalid grab type + detail combinations\n");
request->grab_type = XIGrabtypeEnter;
request->detail = 1;
request_XIPassiveGrabDevice(&client_request, request, BadValue, request->detail);
request->grab_type = XIGrabtypeFocusIn;
request_XIPassiveGrabDevice(&client_request, request, BadValue, request->detail);
request->detail = 0;
printf("Testing invalid masks\n");
mask = (unsigned char*)&request[1];
request->mask_len = bytes_to_int32(XI2LASTEVENT + 1);
request->length += request->mask_len;
SetBit(mask, XI2LASTEVENT + 1);
request_XIPassiveGrabDevice(&client_request, request, BadValue, XI2LASTEVENT + 1);
ClearBit(mask, XI2LASTEVENT + 1);
/* tested all special cases now, test a few valid cases */
/* no modifiers */
request->deviceid = XIAllDevices;
request->grab_type = XIGrabtypeButton;
request->detail = XIAnyButton;
request_XIPassiveGrabDevice(&client_request, request, Success, 0);
/* some modifiers */
request->num_modifiers = N_MODS;
request->length += N_MODS;
memcpy((uint32_t*)(request + 1) + request->mask_len, modifiers, sizeof(modifiers));
request_XIPassiveGrabDevice(&client_request, request, Success, 0);
}
int main(int argc, char** argv)
{
init_simple();
test_XIPassiveGrabDevice();
return 0;
}

View File

@ -38,7 +38,6 @@
#include "xiquerydevice.h" #include "xiquerydevice.h"
#include "protocol-common.h" #include "protocol-common.h"
#include <glib.h>
/* /*
* Protocol testing for XIQueryDevice request and reply. * Protocol testing for XIQueryDevice request and reply.
* *
@ -74,11 +73,11 @@ static void reply_XIQueryDevice(ClientPtr client, int len, char* data, void *use
reply_check_defaults(rep, len, XIQueryDevice); reply_check_defaults(rep, len, XIQueryDevice);
if (querydata->which_device == XIAllDevices) if (querydata->which_device == XIAllDevices)
g_assert(rep->num_devices == devices.num_devices); assert(rep->num_devices == devices.num_devices);
else if (querydata->which_device == XIAllMasterDevices) else if (querydata->which_device == XIAllMasterDevices)
g_assert(rep->num_devices == devices.num_master_devices); assert(rep->num_devices == devices.num_master_devices);
else else
g_assert(rep->num_devices == 1); assert(rep->num_devices == 1);
querydata->num_devices_in_reply = rep->num_devices; querydata->num_devices_in_reply = rep->num_devices;
reply_handler = reply_XIQueryDevice_data; reply_handler = reply_XIQueryDevice_data;
@ -107,46 +106,46 @@ static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void
} }
if (querydata->which_device > XIAllMasterDevices) if (querydata->which_device > XIAllMasterDevices)
g_assert(info->deviceid == querydata->which_device); assert(info->deviceid == querydata->which_device);
g_assert(info->deviceid >= 2); /* 0 and 1 is reserved */ assert(info->deviceid >= 2); /* 0 and 1 is reserved */
switch(info->deviceid) switch(info->deviceid)
{ {
case 2: /* VCP */ case 2: /* VCP */
dev = devices.vcp; dev = devices.vcp;
g_assert(info->use == XIMasterPointer); assert(info->use == XIMasterPointer);
g_assert(info->attachment == devices.vck->id); assert(info->attachment == devices.vck->id);
g_assert(info->num_classes == 3); /* 2 axes + button */ assert(info->num_classes == 3); /* 2 axes + button */
break; break;
case 3: /* VCK */ case 3: /* VCK */
dev = devices.vck; dev = devices.vck;
g_assert(info->use == XIMasterKeyboard); assert(info->use == XIMasterKeyboard);
g_assert(info->attachment == devices.vcp->id); assert(info->attachment == devices.vcp->id);
g_assert(info->num_classes == 1); assert(info->num_classes == 1);
break; break;
case 4: /* mouse */ case 4: /* mouse */
dev = devices.mouse; dev = devices.mouse;
g_assert(info->use == XISlavePointer); assert(info->use == XISlavePointer);
g_assert(info->attachment == devices.vcp->id); assert(info->attachment == devices.vcp->id);
g_assert(info->num_classes == 3); /* 2 axes + button */ assert(info->num_classes == 3); /* 2 axes + button */
break; break;
case 5: /* keyboard */ case 5: /* keyboard */
dev = devices.kbd; dev = devices.kbd;
g_assert(info->use == XISlaveKeyboard); assert(info->use == XISlaveKeyboard);
g_assert(info->attachment == devices.vck->id); assert(info->attachment == devices.vck->id);
g_assert(info->num_classes == 1); assert(info->num_classes == 1);
break; break;
default: default:
/* We shouldn't get here */ /* We shouldn't get here */
g_assert(0); assert(0);
break; break;
} }
g_assert(info->enabled == dev->enabled); assert(info->enabled == dev->enabled);
g_assert(info->name_len == strlen(dev->name)); assert(info->name_len == strlen(dev->name));
g_assert(strncmp((char*)&info[1], dev->name, info->name_len) == 0); assert(strncmp((char*)&info[1], dev->name, info->name_len) == 0);
any = (xXIAnyInfo*)((char*)&info[1] + ((info->name_len + 3)/4) * 4); any = (xXIAnyInfo*)((char*)&info[1] + ((info->name_len + 3)/4) * 4);
for (j = 0; j < info->num_classes; j++) for (j = 0; j < info->num_classes; j++)
@ -171,9 +170,9 @@ static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void
if (client->swapped) if (client->swapped)
swaps(&ki->num_keycodes, n); swaps(&ki->num_keycodes, n);
g_assert(any->type == XIKeyClass); assert(any->type == XIKeyClass);
g_assert(ki->num_keycodes == (xkb->max_key_code - xkb->min_key_code + 1)); assert(ki->num_keycodes == (xkb->max_key_code - xkb->min_key_code + 1));
g_assert(any->length == (2 + ki->num_keycodes)); assert(any->length == (2 + ki->num_keycodes));
kc = (uint32_t*)&ki[1]; kc = (uint32_t*)&ki[1];
for (k = 0; k < ki->num_keycodes; k++, kc++) for (k = 0; k < ki->num_keycodes; k++, kc++)
@ -181,15 +180,15 @@ static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void
if (client->swapped) if (client->swapped)
swapl(kc, n); swapl(kc, n);
g_assert(*kc >= xkb->min_key_code); assert(*kc >= xkb->min_key_code);
g_assert(*kc <= xkb->max_key_code); assert(*kc <= xkb->max_key_code);
} }
break; break;
} }
case 2: /* VCP and mouse have the same properties */ case 2: /* VCP and mouse have the same properties */
case 4: case 4:
{ {
g_assert(any->type == XIButtonClass || assert(any->type == XIButtonClass ||
any->type == XIValuatorClass); any->type == XIValuatorClass);
if (any->type == XIButtonClass) if (any->type == XIButtonClass)
@ -200,10 +199,10 @@ static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void
if (client->swapped) if (client->swapped)
swaps(&bi->num_buttons, n); swaps(&bi->num_buttons, n);
g_assert(bi->num_buttons == devices.vcp->button->numButtons); assert(bi->num_buttons == devices.vcp->button->numButtons);
len = 2 + bi->num_buttons + bytes_to_int32(bits_to_bytes(bi->num_buttons)); len = 2 + bi->num_buttons + bytes_to_int32(bits_to_bytes(bi->num_buttons));
g_assert(bi->length == len); assert(bi->length == len);
} else if (any->type == XIValuatorClass) } else if (any->type == XIValuatorClass)
{ {
xXIValuatorInfo *vi = (xXIValuatorInfo*)any; xXIValuatorInfo *vi = (xXIValuatorInfo*)any;
@ -219,17 +218,17 @@ static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void
swapl(&vi->resolution, n); swapl(&vi->resolution, n);
} }
g_assert(vi->length == 11); assert(vi->length == 11);
g_assert(vi->number == 0 || assert(vi->number == 0 ||
vi->number == 1); vi->number == 1);
g_assert(vi->mode == XIModeRelative); assert(vi->mode == XIModeRelative);
/* device was set up as relative, so standard /* device was set up as relative, so standard
* values here. */ * values here. */
g_assert(vi->min.integral == -1); assert(vi->min.integral == -1);
g_assert(vi->min.frac == 0); assert(vi->min.frac == 0);
g_assert(vi->max.integral == -1); assert(vi->max.integral == -1);
g_assert(vi->max.frac == 0); assert(vi->max.frac == 0);
g_assert(vi->resolution == 0); assert(vi->resolution == 0);
} }
} }
break; break;
@ -257,10 +256,10 @@ static void request_XIQueryDevice(struct test_data *querydata,
request.deviceid = deviceid; request.deviceid = deviceid;
rc = ProcXIQueryDevice(&client); rc = ProcXIQueryDevice(&client);
g_assert(rc == error); assert(rc == error);
if (rc != Success) if (rc != Success)
g_assert(client.errorValue == deviceid); assert(client.errorValue == deviceid);
reply_handler = reply_XIQueryDevice; reply_handler = reply_XIQueryDevice;
@ -268,10 +267,10 @@ static void request_XIQueryDevice(struct test_data *querydata,
swaps(&request.length, n); swaps(&request.length, n);
swaps(&request.deviceid, n); swaps(&request.deviceid, n);
rc = SProcXIQueryDevice(&client); rc = SProcXIQueryDevice(&client);
g_assert(rc == error); assert(rc == error);
if (rc != Success) if (rc != Success)
g_assert(client.errorValue == deviceid); assert(client.errorValue == deviceid);
} }
static void test_XIQueryDevice(void) static void test_XIQueryDevice(void)
@ -284,16 +283,16 @@ static void test_XIQueryDevice(void)
userdata = &data; userdata = &data;
request_init(&request, XIQueryDevice); request_init(&request, XIQueryDevice);
g_test_message("Testing XIAllDevices."); printf("Testing XIAllDevices.\n");
request_XIQueryDevice(&data, XIAllDevices, Success); request_XIQueryDevice(&data, XIAllDevices, Success);
g_test_message("Testing XIAllMasterDevices."); printf("Testing XIAllMasterDevices.\n");
request_XIQueryDevice(&data, XIAllMasterDevices, Success); request_XIQueryDevice(&data, XIAllMasterDevices, Success);
g_test_message("Testing existing device ids."); printf("Testing existing device ids.\n");
for (i = 2; i < 6; i++) for (i = 2; i < 6; i++)
request_XIQueryDevice(&data, i, Success); request_XIQueryDevice(&data, i, Success);
g_test_message("Testing non-existing device ids."); printf("Testing non-existing device ids.\n");
for (i = 6; i <= 0xFFFF; i++) for (i = 6; i <= 0xFFFF; i++)
request_XIQueryDevice(&data, i, BadDevice); request_XIQueryDevice(&data, i, BadDevice);
@ -304,13 +303,10 @@ static void test_XIQueryDevice(void)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
g_test_init(&argc, &argv,NULL);
g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
init_simple(); init_simple();
g_test_add_func("/dix/xi2protocol/XIQueryDevice", test_XIQueryDevice); test_XIQueryDevice();
return g_test_run(); return 0;
} }

View File

@ -39,7 +39,6 @@
#include "exevents.h" #include "exevents.h"
#include "protocol-common.h" #include "protocol-common.h"
#include <glib.h>
static ClientRec client_request; static ClientRec client_request;
static void reply_XIQueryPointer_data(ClientPtr client, int len, static void reply_XIQueryPointer_data(ClientPtr client, int len,
@ -96,18 +95,18 @@ static void reply_XIQueryPointer(ClientPtr client, int len, char *data,
reply_check_defaults(rep, len, XIQueryPointer); reply_check_defaults(rep, len, XIQueryPointer);
g_assert(rep->root == root.drawable.id); assert(rep->root == root.drawable.id);
g_assert(rep->same_screen == xTrue); assert(rep->same_screen == xTrue);
sprite = test_data.dev->spriteInfo->sprite; sprite = test_data.dev->spriteInfo->sprite;
g_assert((rep->root_x >> 16) == sprite->hot.x); assert((rep->root_x >> 16) == sprite->hot.x);
g_assert((rep->root_y >> 16) == sprite->hot.y); assert((rep->root_y >> 16) == sprite->hot.y);
if (test_data.win == &root) if (test_data.win == &root)
{ {
g_assert(rep->root_x == rep->win_x); assert(rep->root_x == rep->win_x);
g_assert(rep->root_y == rep->win_y); assert(rep->root_y == rep->win_y);
g_assert(rep->child == window.drawable.id); assert(rep->child == window.drawable.id);
} else } else
{ {
int x, y; int x, y;
@ -115,13 +114,13 @@ static void reply_XIQueryPointer(ClientPtr client, int len, char *data,
x = sprite->hot.x - window.drawable.x; x = sprite->hot.x - window.drawable.x;
y = sprite->hot.y - window.drawable.y; y = sprite->hot.y - window.drawable.y;
g_assert((rep->win_x >> 16) == x); assert((rep->win_x >> 16) == x);
g_assert((rep->win_y >> 16) == y); assert((rep->win_y >> 16) == y);
g_assert(rep->child == None); assert(rep->child == None);
} }
g_assert(rep->same_screen == xTrue); assert(rep->same_screen == xTrue);
reply_handler = reply_XIQueryPointer_data; reply_handler = reply_XIQueryPointer_data;
} }
@ -137,19 +136,19 @@ static void request_XIQueryPointer(ClientPtr client, xXIQueryPointerReq* req, in
int rc; int rc;
rc = ProcXIQueryPointer(&client_request); rc = ProcXIQueryPointer(&client_request);
g_assert(rc == error); assert(rc == error);
if (rc == BadDevice) if (rc == BadDevice)
g_assert(client_request.errorValue == req->deviceid); assert(client_request.errorValue == req->deviceid);
client_request.swapped = TRUE; client_request.swapped = TRUE;
swaps(&req->deviceid, n); swaps(&req->deviceid, n);
swaps(&req->length, n); swaps(&req->length, n);
rc = SProcXIQueryPointer(&client_request); rc = SProcXIQueryPointer(&client_request);
g_assert(rc == error); assert(rc == error);
if (rc == BadDevice) if (rc == BadDevice)
g_assert(client_request.errorValue == req->deviceid); assert(client_request.errorValue == req->deviceid);
} }
static void test_XIQueryPointer(void) static void test_XIQueryPointer(void)
@ -209,12 +208,9 @@ static void test_XIQueryPointer(void)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
g_test_init(&argc, &argv,NULL);
g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
init_simple(); init_simple();
g_test_add_func("/xi2/protocol/XIQueryPointer", test_XIQueryPointer); test_XIQueryPointer();
return g_test_run(); return 0;
} }

View File

@ -46,7 +46,6 @@
#include "xiqueryversion.h" #include "xiqueryversion.h"
#include "protocol-common.h" #include "protocol-common.h"
#include <glib.h>
extern XExtensionVersion XIVersion; extern XExtensionVersion XIVersion;
@ -74,14 +73,14 @@ static void reply_XIQueryVersion(ClientPtr client, int len, char* data, void *us
reply_check_defaults(rep, len, XIQueryVersion); reply_check_defaults(rep, len, XIQueryVersion);
g_assert(rep->length == 0); assert(rep->length == 0);
sver = versions->major_server * 1000 + versions->minor_server; sver = versions->major_server * 1000 + versions->minor_server;
cver = versions->major_client * 1000 + versions->minor_client; cver = versions->major_client * 1000 + versions->minor_client;
ver = rep->major_version * 1000 + rep->minor_version; ver = rep->major_version * 1000 + rep->minor_version;
g_assert(ver >= 2000); assert(ver >= 2000);
g_assert((sver > cver) ? ver == cver : ver == sver); assert((sver > cver) ? ver == cver : ver == sver);
} }
/** /**
@ -115,7 +114,7 @@ static void request_XIQueryVersion(int smaj, int smin, int cmaj, int cmin, int e
request.major_version = versions.major_client; request.major_version = versions.major_client;
request.minor_version = versions.minor_client; request.minor_version = versions.minor_client;
rc = ProcXIQueryVersion(&client); rc = ProcXIQueryVersion(&client);
g_assert(rc == error); assert(rc == error);
client.swapped = TRUE; client.swapped = TRUE;
@ -124,7 +123,7 @@ static void request_XIQueryVersion(int smaj, int smin, int cmaj, int cmin, int e
swaps(&request.minor_version, n); swaps(&request.minor_version, n);
rc = SProcXIQueryVersion(&client); rc = SProcXIQueryVersion(&client);
g_assert(rc == error); assert(rc == error);
} }
/* Client version less than 2.0 must return BadValue, all other combinations /* Client version less than 2.0 must return BadValue, all other combinations
@ -133,23 +132,23 @@ static void test_XIQueryVersion(void)
{ {
reply_handler = reply_XIQueryVersion; reply_handler = reply_XIQueryVersion;
g_test_message("Server version 2.0 - client versions [1..3].0"); printf("Server version 2.0 - client versions [1..3].0\n");
/* some simple tests to catch common errors quickly */ /* some simple tests to catch common errors quickly */
request_XIQueryVersion(2, 0, 1, 0, BadValue); request_XIQueryVersion(2, 0, 1, 0, BadValue);
request_XIQueryVersion(2, 0, 2, 0, Success); request_XIQueryVersion(2, 0, 2, 0, Success);
request_XIQueryVersion(2, 0, 3, 0, Success); request_XIQueryVersion(2, 0, 3, 0, Success);
g_test_message("Server version 3.0 - client versions [1..3].0"); printf("Server version 3.0 - client versions [1..3].0\n");
request_XIQueryVersion(3, 0, 1, 0, BadValue); request_XIQueryVersion(3, 0, 1, 0, BadValue);
request_XIQueryVersion(3, 0, 2, 0, Success); request_XIQueryVersion(3, 0, 2, 0, Success);
request_XIQueryVersion(3, 0, 3, 0, Success); request_XIQueryVersion(3, 0, 3, 0, Success);
g_test_message("Server version 2.0 - client versions [1..3].[1..3]"); printf("Server version 2.0 - client versions [1..3].[1..3]\n");
request_XIQueryVersion(2, 0, 1, 1, BadValue); request_XIQueryVersion(2, 0, 1, 1, BadValue);
request_XIQueryVersion(2, 0, 2, 2, Success); request_XIQueryVersion(2, 0, 2, 2, Success);
request_XIQueryVersion(2, 0, 3, 3, Success); request_XIQueryVersion(2, 0, 3, 3, Success);
g_test_message("Server version 2.2 - client versions [1..3].0"); printf("Server version 2.2 - client versions [1..3].0\n");
request_XIQueryVersion(2, 2, 1, 0, BadValue); request_XIQueryVersion(2, 2, 1, 0, BadValue);
request_XIQueryVersion(2, 2, 2, 0, Success); request_XIQueryVersion(2, 2, 2, 0, Success);
request_XIQueryVersion(2, 2, 3, 0, Success); request_XIQueryVersion(2, 2, 3, 0, Success);
@ -158,7 +157,7 @@ static void test_XIQueryVersion(void)
/* this one takes a while */ /* this one takes a while */
unsigned int cmin, cmaj, smin, smaj; unsigned int cmin, cmaj, smin, smaj;
g_test_message("Testing all combinations."); printf("Testing all combinations.\n");
for (smaj = 2; smaj <= 0xFFFF; smaj++) for (smaj = 2; smaj <= 0xFFFF; smaj++)
for (smin = 0; smin <= 0xFFFF; smin++) for (smin = 0; smin <= 0xFFFF; smin++)
for (cmin = 0; cmin <= 0xFFFF; cmin++) for (cmin = 0; cmin <= 0xFFFF; cmin++)
@ -175,12 +174,9 @@ static void test_XIQueryVersion(void)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
g_test_init(&argc, &argv,NULL);
g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
init_simple(); init_simple();
g_test_add_func("/xi2/protocol/XIQueryVersion", test_XIQueryVersion); test_XIQueryVersion();
return g_test_run(); return 0;
} }

View File

@ -58,7 +58,6 @@
#include "xiselectev.h" #include "xiselectev.h"
#include "protocol-common.h" #include "protocol-common.h"
#include <glib.h>
static unsigned char *data[4096 * 20]; /* the request data buffer */ static unsigned char *data[4096 * 20]; /* the request data buffer */
@ -107,7 +106,7 @@ static void request_XISelectEvent(xXISelectEventsReq *req, int error)
client = init_client(req->length, req); client = init_client(req->length, req);
rc = ProcXISelectEvents(&client); rc = ProcXISelectEvents(&client);
g_assert(rc == error); assert(rc == error);
client.swapped = TRUE; client.swapped = TRUE;
@ -124,7 +123,7 @@ static void request_XISelectEvent(xXISelectEventsReq *req, int error)
swaps(&req->length, n); swaps(&req->length, n);
swaps(&req->num_masks, n); swaps(&req->num_masks, n);
rc = SProcXISelectEvents(&client); rc = SProcXISelectEvents(&client);
g_assert(rc == error); assert(rc == error);
} }
static void request_XISelectEvents_masks(xXISelectEventsReq *req) static void request_XISelectEvents_masks(xXISelectEventsReq *req)
@ -250,7 +249,7 @@ static void test_XISelectEvents(void)
request_init(req, XISelectEvents); request_init(req, XISelectEvents);
g_test_message("Testing for BadValue on zero-length masks"); printf("Testing for BadValue on zero-length masks\n");
/* zero masks are BadValue, regardless of the window */ /* zero masks are BadValue, regardless of the window */
req->num_masks = 0; req->num_masks = 0;
@ -263,7 +262,7 @@ static void test_XISelectEvents(void)
req->win = CLIENT_WINDOW_ID; req->win = CLIENT_WINDOW_ID;
request_XISelectEvent(req, BadValue); request_XISelectEvent(req, BadValue);
g_test_message("Testing for BadWindow."); printf("Testing for BadWindow.\n");
/* None window is BadWindow, regardless of the masks. /* None window is BadWindow, regardless of the masks.
* We don't actually need to set the masks here, BadWindow must occur * We don't actually need to set the masks here, BadWindow must occur
* before checking the masks. * before checking the masks.
@ -283,7 +282,7 @@ static void test_XISelectEvents(void)
req->num_masks = 0xFFFC; req->num_masks = 0xFFFC;
request_XISelectEvent(req, BadWindow); request_XISelectEvent(req, BadWindow);
g_test_message("Triggering num_masks/length overflow"); printf("Triggering num_masks/length overflow\n");
req->win = ROOT_WINDOW_ID; req->win = ROOT_WINDOW_ID;
/* Integer overflow - req->length can't hold that much */ /* Integer overflow - req->length can't hold that much */
req->num_masks = 0xFFFF; req->num_masks = 0xFFFF;
@ -292,14 +291,14 @@ static void test_XISelectEvents(void)
req->win = ROOT_WINDOW_ID; req->win = ROOT_WINDOW_ID;
req->num_masks = 1; req->num_masks = 1;
g_test_message("Triggering bogus mask length error"); printf("Triggering bogus mask length error\n");
mask = (xXIEventMask*)&req[1]; mask = (xXIEventMask*)&req[1];
mask->deviceid = 0; mask->deviceid = 0;
mask->mask_len = 0xFFFF; mask->mask_len = 0xFFFF;
request_XISelectEvent(req, BadLength); request_XISelectEvent(req, BadLength);
/* testing various device ids */ /* testing various device ids */
g_test_message("Testing existing device ids."); printf("Testing existing device ids.\n");
for (i = 0; i < 6; i++) for (i = 0; i < 6; i++)
{ {
mask = (xXIEventMask*)&req[1]; mask = (xXIEventMask*)&req[1];
@ -310,7 +309,7 @@ static void test_XISelectEvents(void)
request_XISelectEvent(req, Success); request_XISelectEvent(req, Success);
} }
g_test_message("Testing non-existing device ids."); printf("Testing non-existing device ids.\n");
for (i = 6; i <= 0xFFFF; i++) for (i = 6; i <= 0xFFFF; i++)
{ {
req->win = ROOT_WINDOW_ID; req->win = ROOT_WINDOW_ID;
@ -326,13 +325,10 @@ static void test_XISelectEvents(void)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
g_test_init(&argc, &argv,NULL);
g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
init_simple(); init_simple();
g_test_add_func("/xi2/protocol/XISelectEvents", test_XISelectEvents); test_XISelectEvents();
return g_test_run(); return 0;
} }

View File

@ -46,7 +46,6 @@
#include "exevents.h" #include "exevents.h"
#include "protocol-common.h" #include "protocol-common.h"
#include <glib.h>
static ClientRec client_window; static ClientRec client_window;
static ClientRec client_request; static ClientRec client_request;
@ -72,20 +71,20 @@ static void request_XISetClientPointer(xXISetClientPointerReq* req, int error)
client_request = init_client(req->length, req); client_request = init_client(req->length, req);
rc = ProcXISetClientPointer(&client_request); rc = ProcXISetClientPointer(&client_request);
g_assert(rc == error); assert(rc == error);
if (rc == BadDevice) if (rc == BadDevice)
g_assert(client_request.errorValue == req->deviceid); assert(client_request.errorValue == req->deviceid);
client_request.swapped = TRUE; client_request.swapped = TRUE;
swapl(&req->win, n); swapl(&req->win, n);
swaps(&req->length, n); swaps(&req->length, n);
swaps(&req->deviceid, n); swaps(&req->deviceid, n);
rc = SProcXISetClientPointer(&client_request); rc = SProcXISetClientPointer(&client_request);
g_assert(rc == error); assert(rc == error);
if (rc == BadDevice) if (rc == BadDevice)
g_assert(client_request.errorValue == req->deviceid); assert(client_request.errorValue == req->deviceid);
} }
@ -98,36 +97,36 @@ static void test_XISetClientPointer(void)
request.win = CLIENT_WINDOW_ID; request.win = CLIENT_WINDOW_ID;
g_test_message("Testing BadDevice error for XIAllDevices and XIMasterDevices."); printf("Testing BadDevice error for XIAllDevices and XIMasterDevices.\n");
request.deviceid = XIAllDevices; request.deviceid = XIAllDevices;
request_XISetClientPointer(&request, BadDevice); request_XISetClientPointer(&request, BadDevice);
request.deviceid = XIAllMasterDevices; request.deviceid = XIAllMasterDevices;
request_XISetClientPointer(&request, BadDevice); request_XISetClientPointer(&request, BadDevice);
g_test_message("Testing Success for VCP and VCK."); printf("Testing Success for VCP and VCK.\n");
request.deviceid = devices.vcp->id; /* 2 */ request.deviceid = devices.vcp->id; /* 2 */
request_XISetClientPointer(&request, Success); request_XISetClientPointer(&request, Success);
g_assert(client_window.clientPtr->id == 2); assert(client_window.clientPtr->id == 2);
request.deviceid = devices.vck->id; /* 3 */ request.deviceid = devices.vck->id; /* 3 */
request_XISetClientPointer(&request, Success); request_XISetClientPointer(&request, Success);
g_assert(client_window.clientPtr->id == 2); assert(client_window.clientPtr->id == 2);
g_test_message("Testing BadDevice error for all other devices."); printf("Testing BadDevice error for all other devices.\n");
for (i = 4; i <= 0xFFFF; i++) for (i = 4; i <= 0xFFFF; i++)
{ {
request.deviceid = i; request.deviceid = i;
request_XISetClientPointer(&request, BadDevice); request_XISetClientPointer(&request, BadDevice);
} }
g_test_message("Testing window None"); printf("Testing window None\n");
request.win = None; request.win = None;
request.deviceid = devices.vcp->id; /* 2 */ request.deviceid = devices.vcp->id; /* 2 */
request_XISetClientPointer(&request, Success); request_XISetClientPointer(&request, Success);
g_assert(client_request.clientPtr->id == 2); assert(client_request.clientPtr->id == 2);
g_test_message("Testing invalid window"); printf("Testing invalid window\n");
request.win = INVALID_WINDOW_ID; request.win = INVALID_WINDOW_ID;
request.deviceid = devices.vcp->id; request.deviceid = devices.vcp->id;
request_XISetClientPointer(&request, BadWindow); request_XISetClientPointer(&request, BadWindow);
@ -137,13 +136,10 @@ static void test_XISetClientPointer(void)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
g_test_init(&argc, &argv,NULL);
g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
init_simple(); init_simple();
client_window = init_client(0, NULL); client_window = init_client(0, NULL);
g_test_add_func("/xi2/protocol/XISetClientPointer", test_XISetClientPointer); test_XISetClientPointer();
return g_test_run(); return 0;
} }

View File

@ -39,7 +39,6 @@
#include "exevents.h" #include "exevents.h"
#include "protocol-common.h" #include "protocol-common.h"
#include <glib.h>
static int expected_x = SPRITE_X; static int expected_x = SPRITE_X;
static int expected_y = SPRITE_Y; static int expected_y = SPRITE_Y;
@ -70,8 +69,8 @@ int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access
static Bool ScreenSetCursorPosition(DeviceIntPtr dev, ScreenPtr screen, static Bool ScreenSetCursorPosition(DeviceIntPtr dev, ScreenPtr screen,
int x, int y, Bool generateEvent) int x, int y, Bool generateEvent)
{ {
g_assert(x == expected_x); assert(x == expected_x);
g_assert(y == expected_y); assert(y == expected_y);
return TRUE; return TRUE;
} }
@ -83,12 +82,12 @@ static void request_XIWarpPointer(ClientPtr client, xXIWarpPointerReq* req,
int rc; int rc;
rc = ProcXIWarpPointer(client); rc = ProcXIWarpPointer(client);
g_assert(rc == error); assert(rc == error);
if (rc == BadDevice) if (rc == BadDevice)
g_assert(client->errorValue == req->deviceid); assert(client->errorValue == req->deviceid);
else if (rc == BadWindow) else if (rc == BadWindow)
g_assert(client->errorValue == req->dst_win || assert(client->errorValue == req->dst_win ||
client->errorValue == req->src_win); client->errorValue == req->src_win);
@ -105,12 +104,12 @@ static void request_XIWarpPointer(ClientPtr client, xXIWarpPointerReq* req,
swaps(&req->deviceid, n); swaps(&req->deviceid, n);
rc = SProcXIWarpPointer(client); rc = SProcXIWarpPointer(client);
g_assert(rc == error); assert(rc == error);
if (rc == BadDevice) if (rc == BadDevice)
g_assert(client->errorValue == req->deviceid); assert(client->errorValue == req->deviceid);
else if (rc == BadWindow) else if (rc == BadWindow)
g_assert(client->errorValue == req->dst_win || assert(client->errorValue == req->dst_win ||
client->errorValue == req->src_win); client->errorValue == req->src_win);
client->swapped = FALSE; client->swapped = FALSE;
@ -204,13 +203,10 @@ static void test_XIWarpPointer(void)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
g_test_init(&argc, &argv,NULL);
g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
init_simple(); init_simple();
screen.SetCursorPosition = ScreenSetCursorPosition; screen.SetCursorPosition = ScreenSetCursorPosition;
g_test_add_func("/xi2/protocol/XIWarpPointer", test_XIWarpPointer); test_XIWarpPointer();
return g_test_run(); return 0;
} }

View File

@ -46,8 +46,7 @@
#include <X11/extensions/XKMformat.h> #include <X11/extensions/XKMformat.h>
#include "xkbfile.h" #include "xkbfile.h"
#include "../xkb/xkb.h" #include "../xkb/xkb.h"
#include <assert.h>
#include <glib.h>
/** /**
* Initialize an empty XkbRMLVOSet. * Initialize an empty XkbRMLVOSet.
@ -62,16 +61,16 @@ static void xkb_get_rules_test(void)
XkbGetRulesDflts(&rmlvo); XkbGetRulesDflts(&rmlvo);
g_assert(rmlvo.rules); assert(rmlvo.rules);
g_assert(rmlvo.model); assert(rmlvo.model);
g_assert(rmlvo.layout); assert(rmlvo.layout);
g_assert(rmlvo.variant); assert(rmlvo.variant);
g_assert(rmlvo.options); assert(rmlvo.options);
g_assert(strcmp(rmlvo.rules, XKB_DFLT_RULES) == 0); assert(strcmp(rmlvo.rules, XKB_DFLT_RULES) == 0);
g_assert(strcmp(rmlvo.model, XKB_DFLT_MODEL) == 0); assert(strcmp(rmlvo.model, XKB_DFLT_MODEL) == 0);
g_assert(strcmp(rmlvo.layout, XKB_DFLT_LAYOUT) == 0); assert(strcmp(rmlvo.layout, XKB_DFLT_LAYOUT) == 0);
g_assert(strcmp(rmlvo.variant, XKB_DFLT_VARIANT) == 0); assert(strcmp(rmlvo.variant, XKB_DFLT_VARIANT) == 0);
g_assert(strcmp(rmlvo.options, XKB_DFLT_OPTIONS) == 0); assert(strcmp(rmlvo.options, XKB_DFLT_OPTIONS) == 0);
} }
/** /**
@ -95,17 +94,17 @@ static void xkb_set_rules_test(void)
XkbGetRulesDflts(&rmlvo_new); XkbGetRulesDflts(&rmlvo_new);
/* XkbGetRulesDflts strdups the values */ /* XkbGetRulesDflts strdups the values */
g_assert(rmlvo.rules != rmlvo_new.rules); assert(rmlvo.rules != rmlvo_new.rules);
g_assert(rmlvo.model != rmlvo_new.model); assert(rmlvo.model != rmlvo_new.model);
g_assert(rmlvo.layout != rmlvo_new.layout); assert(rmlvo.layout != rmlvo_new.layout);
g_assert(rmlvo.variant != rmlvo_new.variant); assert(rmlvo.variant != rmlvo_new.variant);
g_assert(rmlvo.options != rmlvo_new.options); assert(rmlvo.options != rmlvo_new.options);
g_assert(strcmp(rmlvo.rules, rmlvo_new.rules) == 0); assert(strcmp(rmlvo.rules, rmlvo_new.rules) == 0);
g_assert(strcmp(rmlvo.model, rmlvo_new.model) == 0); assert(strcmp(rmlvo.model, rmlvo_new.model) == 0);
g_assert(strcmp(rmlvo.layout, rmlvo_new.layout) == 0); assert(strcmp(rmlvo.layout, rmlvo_new.layout) == 0);
g_assert(strcmp(rmlvo.variant, rmlvo_new.variant) == 0); assert(strcmp(rmlvo.variant, rmlvo_new.variant) == 0);
g_assert(strcmp(rmlvo.options, rmlvo_new.options) == 0); assert(strcmp(rmlvo.options, rmlvo_new.options) == 0);
} }
@ -145,29 +144,26 @@ static void xkb_set_get_rules_test(void)
/* This test is iffy, because strictly we may be comparing against already /* This test is iffy, because strictly we may be comparing against already
* freed memory */ * freed memory */
g_assert(strcmp(rmlvo.rules, rmlvo_backup.rules) == 0); assert(strcmp(rmlvo.rules, rmlvo_backup.rules) == 0);
g_assert(strcmp(rmlvo.model, rmlvo_backup.model) == 0); assert(strcmp(rmlvo.model, rmlvo_backup.model) == 0);
g_assert(strcmp(rmlvo.layout, rmlvo_backup.layout) == 0); assert(strcmp(rmlvo.layout, rmlvo_backup.layout) == 0);
g_assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0); assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0);
g_assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0); assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0);
XkbGetRulesDflts(&rmlvo); XkbGetRulesDflts(&rmlvo);
g_assert(strcmp(rmlvo.rules, rmlvo_backup.rules) == 0); assert(strcmp(rmlvo.rules, rmlvo_backup.rules) == 0);
g_assert(strcmp(rmlvo.model, rmlvo_backup.model) == 0); assert(strcmp(rmlvo.model, rmlvo_backup.model) == 0);
g_assert(strcmp(rmlvo.layout, rmlvo_backup.layout) == 0); assert(strcmp(rmlvo.layout, rmlvo_backup.layout) == 0);
g_assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0); assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0);
g_assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0); assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0);
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
g_test_init(&argc, &argv,NULL); xkb_set_get_rules_test();
g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id="); xkb_get_rules_test();
xkb_set_rules_test();
g_test_add_func("/xkb/set-get-rules", xkb_set_get_rules_test); return 0;
g_test_add_func("/xkb/get-rules", xkb_get_rules_test);
g_test_add_func("/xkb/set-rules", xkb_set_rules_test);
return g_test_run();
} }

View File

@ -33,8 +33,6 @@
#include "xkbsrv.h" #include "xkbsrv.h"
#include "xserver-properties.h" #include "xserver-properties.h"
#include <glib.h>
/** /**
*/ */
@ -65,14 +63,14 @@ static void xtest_init_devices(void)
/* this also inits the xtest devices */ /* this also inits the xtest devices */
InitCoreDevices(); InitCoreDevices();
g_assert(xtestpointer); assert(xtestpointer);
g_assert(xtestkeyboard); assert(xtestkeyboard);
g_assert(IsXTestDevice(xtestpointer, NULL)); assert(IsXTestDevice(xtestpointer, NULL));
g_assert(IsXTestDevice(xtestkeyboard, NULL)); assert(IsXTestDevice(xtestkeyboard, NULL));
g_assert(IsXTestDevice(xtestpointer, inputInfo.pointer)); assert(IsXTestDevice(xtestpointer, inputInfo.pointer));
g_assert(IsXTestDevice(xtestkeyboard, inputInfo.keyboard)); assert(IsXTestDevice(xtestkeyboard, inputInfo.keyboard));
g_assert(GetXTestDevice(inputInfo.pointer) == xtestpointer); assert(GetXTestDevice(inputInfo.pointer) == xtestpointer);
g_assert(GetXTestDevice(inputInfo.keyboard) == xtestkeyboard); assert(GetXTestDevice(inputInfo.keyboard) == xtestkeyboard);
} }
/** /**
@ -87,32 +85,29 @@ static void xtest_properties(void)
Atom xtest_prop = XIGetKnownProperty(XI_PROP_XTEST_DEVICE); Atom xtest_prop = XIGetKnownProperty(XI_PROP_XTEST_DEVICE);
rc = XIGetDeviceProperty(xtestpointer, xtest_prop, &prop); rc = XIGetDeviceProperty(xtestpointer, xtest_prop, &prop);
g_assert(rc == Success); assert(rc == Success);
g_assert(prop); assert(prop);
rc = XIGetDeviceProperty(xtestkeyboard, xtest_prop, &prop); rc = XIGetDeviceProperty(xtestkeyboard, xtest_prop, &prop);
g_assert(rc == Success); assert(rc == Success);
g_assert(prop != NULL); assert(prop != NULL);
rc = XIChangeDeviceProperty(xtestpointer, xtest_prop, rc = XIChangeDeviceProperty(xtestpointer, xtest_prop,
XA_INTEGER, 8, PropModeReplace, 1, &value, FALSE); XA_INTEGER, 8, PropModeReplace, 1, &value, FALSE);
g_assert(rc == BadAccess); assert(rc == BadAccess);
rc = XIChangeDeviceProperty(xtestkeyboard, xtest_prop, rc = XIChangeDeviceProperty(xtestkeyboard, xtest_prop,
XA_INTEGER, 8, PropModeReplace, 1, &value, FALSE); XA_INTEGER, 8, PropModeReplace, 1, &value, FALSE);
g_assert(rc == BadAccess); assert(rc == BadAccess);
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
g_test_init(&argc, &argv,NULL); xtest_init_devices();
g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id="); xtest_properties();
g_test_add_func("/dix/xtest/init", xtest_init_devices); return 0;
g_test_add_func("/dix/xtest/properties", xtest_properties);
return g_test_run();
} }