summaryrefslogtreecommitdiff
path: root/xc/test/xsuite/xtest/tset/Xi/setdvbmap/setdvbmap.m
blob: 20e09fc93c2667849acdd83a19ab74d325a02896 (plain)
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
/*

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 by 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: setdvbmap.m,v 1.7 94/04/17 21:12:53 rws Exp dpw $
 */
>>TITLE XSetDeviceButtonMapping XINPUT
>>SET return-value MappingSuccess
int

Display	*display = Dsp;
XDevice *device = Devs.Button;
unsigned char	*map = Map;
int 	nmap = 255;
>>EXTERN

/* Maximum button number allowed. */
#define	MAXBUTTON	255

/*
 * MAPSIZE must be at least one greater than the maximum number of buttons
 * allowed.
 */
#define	MAPSIZE	256
static	unsigned char	Map[MAPSIZE];
static 	XID baddevice; 

static	int 	nbtns;
extern ExtDeviceInfo Devs;

/*
 * Set up the number of buttons.  Also set the nmap value to nbtns (
 * the test may later override this).
 */
>>SET begin-function getnbutton
static	void
getnbutton()
{
	if (!Devs.Button)
	    return;
	device = Devs.Button;
	nbtns = XGetDeviceButtonMapping(Dsp, device, Map, MAPSIZE);
	nmap = nbtns;
	if (isdeleted())
		delete("XGetDeviceButtonMapping failed");
}

/*
 * Save and restore the old map.
 */
static unsigned char	oldmap[MAPSIZE];
>>SET startup savemap
static void
savemap()
{
	startup();
	if (!Setup_Extension_DeviceInfo(BtnMask))
	    {
	    return;
	    }
	device = Devs.Button;
	if(Dsp)
		nbtns = XGetDeviceButtonMapping(Dsp, device, oldmap, MAPSIZE);
}

>>SET cleanup restoremap
static void
restoremap()
{
	device = Devs.Button;
	if(Dsp && Devs.Button)
		{
		(void) XSetDeviceButtonMapping(Dsp, device, oldmap, nbtns);
		XSync(Dsp,0);
		}
	cleanup();
}

>>ASSERTION Good B 3
A successful call to xname sets the pointer mapping for the physical buttons
to the
.A nmap
logical button numbers specified in the array
.A map
and returns
.S MappingSuccess .
>>STRATEGY
Get number of buttons.
Set up a pointer mapping.
Set pointer mapping with xname.
Verify return value.
Get pointer mapping with XGetDeviceButtonMapping.
Verify that pointer mapping is as set.
>>CODE
unsigned char	newmap[MAPSIZE];
int 	i;

	if (!Devs.Button) {
	    untested("%s: No input extension button device.\n", TestName);
	    return;
	    }
	/*
	 * Cycle the current mapping around.
	 */
	for (i = 0; i < nbtns; i++) {
		map[i] = map[i] + 1;
		if (map[i] > MAXBUTTON)
			map[i] = 1;
	}

	device = Devs.Button;

	XCALL;

	(void) XGetDeviceButtonMapping(display, device, newmap, MAPSIZE);
	if (isdeleted()) {
		delete("Could not get device button mapping");
		return;
	}

	for (i = 0; i < nbtns; i++) {
		if (map[i] == newmap[i])
			CHECK;
		else {
			report("Mapping not set correctly in position %d", i);
			report("  was %u, expecting %u", (unsigned)newmap[i], (unsigned)map[i]);
			FAIL;
		}
	}

	CHECKPASS(nbtns);
>>ASSERTION Good B 3
When a call to xname is successful, then a
.S DeviceMappingNotify
event is generated.
>>STRATEGY
Call xname.
Verify that a DeviceMappingNotify event is generated.
>>CODE
XEvent	ev;
XDeviceMappingEvent	good;
int 	i,n,dbmn;
XEventClass dbmnc;

	if (!Devs.Button) {
	    untested("%s: No input extension button device.\n", TestName);
	    return;
	    }
	device = Devs.Button;
	DeviceMappingNotify(Devs.Button, dbmn, dbmnc);
	XSelectExtensionEvent (display, DefaultRootWindow(Dsp), &dbmnc, 1);
	XSync(display,0);
	XCALL;
	XSync(display,0);

	n = getevent(display, &ev);
	if (n == 0 || ev.type != dbmn) {
		report("Expecting a DeviceMappingNotify event, received %s", n? eventname(ev.type): "no event");
		FAIL;
	} else
		CHECK;

	defsetevent(good, display, dbmn);
	good.window = None;	/* Not used */
	good.request = MappingPointer;
	good.deviceid = Devs.Button->device_id;
	if (checkevent((XEvent*)&good, &ev))
		FAIL;
	else
		CHECK;

	CHECKPASS(2);
>>ASSERTION Good B 3
When an element of
.A map
is zero, then the corresponding physical button is
disabled.
>>STRATEGY
If extension available:
  Create and map a window.
  Select DeviceButtonPress on it.
  For i in 1..nbtns
    Set map[i-1] to 0.
    Call xname.
    Discard event queue.
    Simulate button i press with extension.
    Release all buttons etc.
    Check no button press event received.
    Restore map[i-1].
else
  Report untested.
>>CODE
int	i;
unsigned char zmap[255];
Window	win;
XID dbp, dbpclass;

	if (!Devs.Button) {
	    untested("%s: No input extension button device.\n", TestName);
	    return;
	    }
	if (noext(nbtns))
		return;
	else
		CHECK;

	if (nbtns<1 || nbtns>255) {
		report("Protocol limit of 1..255 buttons exceeded (%d).", nbtns);
		return;
	} else
		CHECK;

	for(i=0; i<nbtns; i++)
		zmap[i] = map[i];
	win = defwin(display);
	device = Devs.Button;
	DeviceButtonPress(device, dbp, dbpclass);
	(void) warppointer(display, win, 2,2);
	XSelectExtensionEvent(display, win, &dbpclass, 1);

	for(i=0; i<nbtns; i++) {
		unsigned char mapsave = zmap[i];
		int ret;
		XEvent ev;

		zmap[i] = 0; /* disable button i+1 */
		map = zmap;
		ret = XCALL;

		if (ret != MappingSuccess) {
			delete("Couldn't set zero entry for button %d.", i+1);
			return;
		} else
			CHECK;

		XSync(display, True); /* discard event queue */
		_startcall(display);	/* set error handler etc. */
		devicebuttonpress(display, device, (unsigned int)i+1);
		devicebuttonrel(display, device, (unsigned int)i+1);
		XSync(display,0);
		relalldev();
		_endcall(display);
		if (geterr() != Success) {
			delete("Couldn't simulate pressing button %d.", i+1);
			return;
		} else
			CHECK;
		if (!XPending(display))
		    CHECK;
		else while(XPending(display))
			{
			XNextEvent (display, &ev);
			if (ev.type == dbp)
			    {
			    report("Got event after pressing disabled button %d.", i+1);
			    FAIL;
			    }
			}
		zmap[i] = mapsave; /* restore button i+1 */
	}
	devicerelbuttons(device);
	CHECKPASS(nbtns*3 + 2);

>>ASSERTION Good B 3
Elements of the
.A map
array are not restricted in
value by the number of physical buttons.
>>STRATEGY
Set up map array with button number higher than number of physical buttons.
Call xname.
Verify no error.
>>CODE
int 	i;

	if (!Devs.Button) {
	    untested("%s: No input extension button device.\n", TestName);
	    return;
	    }
	for (i = 0; i < nbtns; i++)
		map[i] = i;

	map[0] = nbtns+1;

	device = Devs.Button;
	XCALL;

	if (geterr() == Success)
		PASS;
	else
		FAIL;
>>ASSERTION Good B 3
When any of the buttons to be altered are logically in the down state,
then a call to xname returns
.S MappingBusy ,
and the mapping is not changed.
>>STRATEGY
If the xtest extension is available, press one of the buttons.  Then
try to change the map.  Verify that a status of MappingBusy was returned.
>>CODE
int i, ret;

	if (!Devs.Button) {
	    untested("%s: No input extension button device.\n", TestName);
	    return;
	    }
	if (noext(0))
	    return;
	getnbutton();
	/*
	 * Cycle the current mapping around.
	 */
	for (i = 0; i < nbtns; i++) {
		map[i] = map[i] + 1;
		if (map[i] > MAXBUTTON)
			map[i] = 1;
	}
	devicebuttonpress(display, Devs.Button, Button1);
	devicebuttonpress(display, Devs.Button, Button2);
	XSync(display,0);
	device = Devs.Button;
	ret = XCALL;

	if (ret == MappingBusy)
		PASS;
	else
		FAIL;
	devicebuttonrel(display, Devs.Button, Button1);
	devicebuttonrel(display, Devs.Button, Button2);
	devicerelbuttons(device);

>>ASSERTION Bad B 3
When
.A nmap
is not the same as the length that
.F XGetDeviceButtonMapping
would return,
then a
.S BadValue
error occurs.
>>STRATEGY
Set nmap to incorrect value.
Call xname.
Verify that a BadValue error occurs.
>>CODE BadValue
int 	i;

	if (!Devs.Button) {
	    untested("%s: No input extension button device.\n", TestName);
	    return;
	    }
	if (nbtns < 254)
	    nmap = nbtns + 2;
	else if (nbtns > 1)
	    nmap = nbtns - 1;
	else
	    {
	    untested("%s: Bad # buttons on extension device.\n", TestName);
	    return;
	    }
	for (i = 0; i < nmap; i++)
		map[i] = i;	/* MAPSIZE is large enough to allow this */
	device = Devs.Button;
	XCALL;

	if (geterr() == BadValue)
		PASS;
	else
		FAIL;	/* done already */
>>ASSERTION Bad C
If there is more than one button:
When two elements of
.A map
have the same non-zero value,
then a
.S BadValue
error occurs.
>>STRATEGY
If less than two buttons
  Report unsupported.
Set up a map with two elements the same.
Call xname.
Verify that a BadValue error occurs.
>>CODE BadValue
int 	i;

	if (!Devs.Button) {
	    untested("%s: No input extension button device.\n", TestName);
	    return;
	    }
	getnbutton();
	if (nbtns < 2) {
		unsupported("There are less than two buttons");
		return;
	}

	for (i = 0; i < nmap; i++)
		map[i] = i;

	map[0] = map[1];
	device = Devs.Button;
	XCALL;

	if (geterr() == BadValue)
		PASS;
	else
		FAIL;

>>ASSERTION Bad B 3
If xname is invoked with an invalid device, a BadDevice error
will result.
>>STRATEGY
Make the call with an invalid device.
>>CODE baddevice
XDevice nodevice;
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)
		CHECK;
	else
		FAIL;

	CHECKPASS(1);