1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
|
/*
Copyright (c) 1990, 1991 X Consortium
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 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
X CONSORTIUM 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.
Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.
* Copyright 1993 by the Hewlett-Packard Company.
*
* Copyright 1990, 1991 UniSoft Group Limited.
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the names of HP, and UniSoft not be
* used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission. HP, and UniSoft
* make no representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* $XConsortium: querydvst.m,v 1.6 94/04/17 21:13:13 rws Exp dpw $
*/
>>TITLE XQueryDeviceState XINPUT
XDeviceState *
Display *display = Dsp;
XDevice *device;
>>EXTERN
#define KEYMAPLEN 32
#define VALMAPLEN 6
extern ExtDeviceInfo Devs;
static NumValuators;
>>ASSERTION Good B 3
A successful call to QueryDeviceState resets the DeviceMotionHint state so
that the next motion event generated will be sent to interested clients.
>>STRATEGY
Select DeviceMotionNotify and DevicePointerMotionHint classes.
Generate some motion events, verify only one is sent.
Now call xname.
Generate some motion events, verify another one is sent.
>>CODE
XID dmn, dmnh;
XEventClass classes[2];
Window w;
int axes=1, n, i;
XEvent ev;
XDeviceMotionEvent *d;
if (!Setup_Extension_DeviceInfo(ValMask))
{
untested("%s: Required input extension device not present.\n",
TestName);
return;
}
if(noext(0))
return;
device = Devs.Valuator;
DeviceMotionNotify(device, dmn, classes[0]);
DevicePointerMotionHint(device, dmnh, classes[1]);
w = defwin(display);
XSelectExtensionEvent(display, w, classes, 2);
warppointer (display, w, 1, 1);
XSync(display,1);
for (i=0; i<10; i++)
SimulateDeviceMotionEvent(display, device, False, 1, &axes, 0);
XSync(display,0);
n = getevent(display, &ev);
if (n != 1)
{
report("Expecting one event with DeviceMotionHint, got %d",n);
FAIL;
}
else
CHECK;
if (ev.type != dmn)
{
report("Expecting DeviceMotionNotify event, got event type %d",
ev.type);
FAIL;
}
else
CHECK;
d = (XDeviceMotionEvent *) &ev;
if (d->is_hint != True)
{
report("Expecting is_hint = True, was False");
FAIL;
}
else
CHECK;
XCALL;
if (geterr() == Success)
CHECK;
else
{
report("Expecting Success, got error\n");
FAIL;
return;
}
XSync(display,1);
for (i=0; i<10; i++)
SimulateDeviceMotionEvent(display, device, False, 1, &axes, 0);
XSync(display,0);
n = getevent(display, &ev);
if (n != 1)
{
report("Expecting one event with DeviceMotionHint, got %d",n);
FAIL;
}
else
CHECK;
if (ev.type != dmn)
{
report("Expecting DeviceMotionNotify event, got event type %d",
ev.type);
FAIL;
}
else
CHECK;
d = (XDeviceMotionEvent *) &ev;
if (d->is_hint != True)
{
report("Expecting is_hint = True, was False");
FAIL;
}
else
CHECK;
axes=0;
SimulateDeviceMotionEvent(display, device, False, 1, &axes, 0);
XSync(display,1);
CHECKPASS(7);
>>ASSERTION Good B 3
A successful call to QueryDeviceState returns the state of the keys,
buttons, and valuators on the extension device.
>>STRATEGY
Press some keys.
Press some buttons, if the device has any.
Move some valuators, if the device has any.
Call QueryDeviceState.
Check to see if those keys, buttons, and valuators are reported as being down.
>>EXTERN
devtype(dpy, dev, haskeys, hasbuttons, hasvaluators)
Display *dpy;
XDevice *dev;
int *haskeys, *hasbuttons, *hasvaluators;
{
int i, j, ndevices;
XDeviceInfo *list;
XAnyClassPtr any;
list = XListInputDevices (dpy, &ndevices);
for (i=0; i<ndevices; i++,list++)
{
if (list->id != dev->device_id)
continue;
*haskeys = False;
*hasbuttons = False;
*hasvaluators = False;
any = (XAnyClassPtr) (list->inputclassinfo);
for (j=0; j<list->num_classes; j++)
{
switch (any->class)
{
case KeyClass:
{
if (((XKeyInfo *)any)->num_keys)
*haskeys=True;
break;
}
case ButtonClass:
{
if (((XButtonInfo *)any)->num_buttons)
*hasbuttons=True;
break;
}
case ValuatorClass:
{
if (((XValuatorInfo *)any)->num_axes)
{
*hasvaluators=True;
NumValuators = (((XValuatorInfo *)any)->num_axes);
}
break;
}
default:
break;
}
any = (XAnyClassPtr) ((char *) any + any->length);
}
}
}
>>EXTERN
pokedev(display, device)
Display *display;
XDevice *device;
{
int i, j, key1;
XDeviceState *state;
XKeyState *ks;
XButtonState *bs;
XValuatorState *vs;
char *keys;
int *vals;
int axes[256];
int haskeys, hasbuttons, hasvaluators, pass=0, fail=0, count=1;
devtype(display, device, &haskeys, &hasbuttons, &hasvaluators);
if (!(haskeys & hasbuttons & hasvaluators))
{
untested("Extension device has no keys, buttons, or valuators");
return;
}
key1 = getkeycode(display);
if (haskeys)
{
devicekeyrel (display, device, key1);
devicerelkeys (device);
}
if (hasbuttons)
{
devicebuttonrel (display, device, Button1);
devicerelbuttons(device);
}
if (hasvaluators)
{
int count;
int nvals = NumValuators < 6 ? NumValuators : 6;
for (i=0; i<nvals; i++)
axes[i] = 0;
for (i=0; i<NumValuators; i+=6) {
count = NumValuators-i < 6 ? NumValuators-i : 6;
SimulateDeviceMotionEvent (display, device, False, count, axes,
i);
XSync(display,0);
}
XSync(display,0);
}
state = XCALL;
if (state)
CHECK;
else
{
report("Expecting Success, got error (NULL state returned).");
FAIL;
return;
}
ks = (XKeyState *) state->data;
for (i=0; i<state->num_classes; i++)
{
if (ks->class == KeyClass)
{
for (j=0,keys=ks->keys; j<KEYMAPLEN; j++,keys++)
if (*keys != 0)
{
report("%s: byte %d of keys was %x, should be 0\n",
TestName,j,*keys);
FAIL;
}
else
CHECK;
count += KEYMAPLEN;
}
else if (ks->class == ButtonClass)
{
bs = (XButtonState *) ks;
for (j=0,keys=bs->buttons; j<KEYMAPLEN; j++,keys++)
if (*keys != 0)
{
report("%s: byte %d of buttons was %x, should be 0\n",
TestName,j,*keys);
FAIL;
}
else
CHECK;
count += KEYMAPLEN;
}
else if (ks->class == ValuatorClass)
{
vs = (XValuatorState *) ks;
for (j=0,vals=vs->valuators; j<vs->num_valuators; j++,vals++)
if (*vals != 0)
{
report("%s: valuator %d was %x, should be 0\n",
TestName,j,*vals);
FAIL;
}
else
CHECK;
count += vs->num_valuators;
}
ks = (XKeyState *) ((char *) ks + ks->length);
}
if (haskeys)
devicekeypress (display, device, key1);
if (hasbuttons)
devicebuttonpress (display, device, Button1);
if (hasvaluators)
{
int nvals = vs->num_valuators < 6 ? vs->num_valuators : 6;
for (i=0; i<vs->num_valuators; i++)
axes[i] = i;
SimulateDeviceMotionEvent(display, device, False, nvals, axes, 0);
XSync(display,0);
}
state = XCALL;
ks = (XKeyState *) state->data;
for (i=0; i<state->num_classes; i++)
{
if (ks->class == KeyClass)
{
for (j=0,keys=ks->keys; j<KEYMAPLEN; j++,keys++)
if (j != key1 >> 3 && *keys != 0)
{
report("%s: byte %d of keys was %x, should be 0\n",
TestName,j,*keys);
FAIL;
}
else if (j== key1 >> 3 && *keys != 1 << (key1 & 7))
{
report("%s: byte %d of keys was %x, should be %x\n",
TestName,j,*keys, 1 << (key1 & 7));
FAIL;
}
else
CHECK;
count += KEYMAPLEN;
}
else if (ks->class == ButtonClass)
{
bs = (XButtonState *) ks;
for (j=0,keys=bs->buttons; j<KEYMAPLEN; j++,keys++)
if (j != Button1 >> 3 && *keys != 0)
{
report("%s: byte %d of buttons was %x, should be 0\n",
TestName,j,*keys);
FAIL;
}
else if (j== Button1 >> 3 && *keys != 1 << (Button1 & 7))
{
report("%s: byte %d of buttons was %x, should be %x\n",
TestName,j,*keys, 1 << (key1 & 7));
FAIL;
}
else
CHECK;
count += KEYMAPLEN;
}
else if (ks->class == ValuatorClass)
{
int nval = vs->num_valuators < 6 ? vs->num_valuators : 6;
vs = (XValuatorState *) ks;
for (j=0,vals=vs->valuators; j<nval; j++,vals++)
if (*vals != j)
{
report("%s: valuator %d was %x, should be %d\n",
TestName,j,*vals,j);
FAIL;
}
else
CHECK;
for (j=nval; j<vs->num_valuators; j++,vals++)
if (*vals != 0)
{
report("%s: valuator %d was %x, should be 0\n",
TestName,j,*vals);
FAIL;
}
else
CHECK;
count += vs->num_valuators;
}
ks = (XKeyState *) ((char *) ks + ks->length);
}
if (haskeys)
{
devicekeyrel (display, device, key1);
devicerelkeys (device);
}
if (hasbuttons)
{
devicebuttonrel (display, device, Button1);
devicerelbuttons(device);
}
if (hasvaluators)
{
int nvals = vs->num_valuators < 6 ? vs->num_valuators : 6;
for (i=0; i<nvals; i++)
axes[i] = 0;
for (i=0; i<vs->num_valuators; i+=6) {
if (i >= vs->num_valuators - 6)
nvals = vs->num_valuators - i;
SimulateDeviceMotionEvent (display, device, False, nvals, axes,
i);
XSync(display,0);
}
}
CHECKPASS(count);
}
>>CODE
if (!Setup_Extension_DeviceInfo(KeyMask))
{
untested("%s: Required input extension device not present.\n", TestName);
return;
}
if(noext(0))
return;
device = Devs.Key;
pokedev (display, device);
>>ASSERTION Good B 3
A successful call to QueryDeviceState returns the state of the keys,
buttons, and valuators on the extension device.
>>STRATEGY
Press some keys.
Press some buttons, if the device has any.
Move some valuators, if the device has any.
Call QueryDeviceState.
Check to see if those keys, buttons, and valuators are reported as being down.
>>CODE
if (!Setup_Extension_DeviceInfo(BtnMask))
{
untested("%s: Required input extension device not present.\n", TestName);
return;
}
if(noext(0))
return;
device = Devs.Button;
pokedev (display, device);
>>ASSERTION Good B 3
A successful call to QueryDeviceState returns the state of the keys,
buttons, and valuators on the extension device.
>>STRATEGY
Press some keys.
Press some buttons, if the device has any.
Move some valuators, if the device has any.
Call QueryDeviceState.
Check to see if those keys, buttons, and valuators are reported as being down.
>>CODE
if (!Setup_Extension_DeviceInfo(ValMask))
{
untested("%s: Required input extension device not present.\n", TestName);
return;
}
if(noext(0))
return;
device = Devs.Valuator;
pokedev (display, device);
>>ASSERTION Good B 3
A successful call to QueryDeviceState returns the state of the keys,
buttons, and valuators on the extension device.
>>STRATEGY
Call QueryDeviceState for a device with no keys.
>>CODE
if (!Setup_Extension_DeviceInfo(NKeysMask))
{
untested("%s: Required input extension device not present.\n", TestName);
return;
}
if(noext(0))
return;
device = Devs.NoKeys;
pokedev (display, device);
>>ASSERTION Good B 3
A successful call to QueryDeviceState returns the state of the keys,
buttons, and valuators on the extension device.
>>STRATEGY
Call QueryDeviceState for a device with no buttons.
>>CODE
if (!Setup_Extension_DeviceInfo(NBtnsMask))
{
untested("%s: Required input extension device not present.\n", TestName);
return;
}
if(noext(0))
return;
device = Devs.NoButtons;
pokedev (display, device);
>>ASSERTION Good B 3
A successful call to QueryDeviceState returns the state of the keys,
buttons, and valuators on the extension device.
>>STRATEGY
Call QueryDeviceState for a device with no valuators.
>>CODE
if (!Setup_Extension_DeviceInfo(NValsMask))
{
untested("%s: Required input extension device not present.\n", TestName);
return;
}
if(noext(0))
return;
device = Devs.NoValuators;
pokedev (display, device);
>>ASSERTION Bad B 3
A call to xname will fail with a BadDevice error if an invalid device
is specified.
>>STRATEGY
Make the call with an invalid device.
>>CODE baddevice
XDevice nodevice;
XID baddevice;
int ximajor, first, err;
if (!XQueryExtension (display, INAME, &ximajor, &first, &err))
{
untested("%s: Input extension not supported.\n", TestName);
return;
}
BadDevice (display, baddevice);
nodevice.device_id = -1;
device = &nodevice;
XCALL;
if (geterr() == baddevice)
PASS;
else
FAIL;
|