summaryrefslogtreecommitdiff
path: root/xts5/Xlib17/XReadBitmapFile.m
blob: a25ff7957dcb76e04385d00e251e96b74f50f592 (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
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
Copyright (c) 2005 X.Org Foundation L.L.C.

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
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.

Copyright (c) Applied Testing and Technology, Inc. 1995
All Rights Reserved.

>># Project: VSW5
>># 
>># File: xts5/Xlib17/XReadBitmapFile.m
>># 
>># Description:
>># 	Tests for XReadBitmapFile()
>># 
>># Modifications:
>># $Log: rdbtmpfl.m,v $
>># Revision 1.2  2005-11-03 08:43:11  jmichael
>># clean up all vsw5 paths to use xts5 instead.
>>#
>># Revision 1.1.1.2  2005/04/15 14:05:23  anderson
>># Reimport of the base with the legal name in the copyright fixed.
>>#
>># Revision 8.0  1998/12/23 23:34:51  mar
>># Branch point for Release 5.0.2
>>#
>># Revision 7.0  1998/10/30 22:57:15  mar
>># Branch point for Release 5.0.2b1
>>#
>># Revision 6.0  1998/03/02 05:26:08  tbr
>># Branch point for Release 5.0.1
>>#
>># Revision 5.0  1998/01/26 03:22:40  tbr
>># Branch point for Release 5.0.1b1
>>#
>># Revision 4.0  1995/12/15 09:11:39  tbr
>># Branch point for Release 5.0.0
>>#
>># Revision 3.1  1995/12/15  01:14:22  andy
>># Prepare for GA Release
>>#
/*
Portions of this software are based on Xlib and X Protocol Test Suite.
We have used this material under the terms of its copyright, which grants
free use, subject to the conditions below.  Note however that those
portions of this software that are based on the original Test Suite have
been significantly revised and that all such revisions are copyright (c)
1995 Applied Testing and Technology, Inc.  Insomuch as the proprietary
revisions cannot be separated from the freely copyable material, the net
result is that use of this software is governed by the ApTest copyright.

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.

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 name of UniSoft not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.  UniSoft
makes no representations about the suitability of this software for any
purpose.  It is provided "as is" without express or implied warranty.
*/
>>TITLE XReadBitmapFile Xlib17
int

Display *display = Dsp;
Drawable d = (Drawable)defwin(display);
char *filename = xrbf_name;
unsigned int *width_return = &width;
unsigned int *height_return = &height;
Pixmap *bitmap_return = &bitmap;
int *x_hot_return = &x_hot;
int *y_hot_return = &y_hot;
>>EXTERN
#include <stdio.h>

/* Function return variables. */
static unsigned int width;
static unsigned int height;
static Pixmap bitmap;
static int x_hot;
static int y_hot;

/* Temporary bitmap filename. */
static char *xrbf_name = "xrbf_temp";
static char *xrbf_bad_name = "xrbf_nofile";

/* Valid bitmap file without hotspot definition. */
static char *xrbf_one[] = {
	"#define test_width 16",
	"#define test_height 8",
	"static char test_bits[] = {",
	"0x80, 0x00, 0x3f, 0xfe, 0x04, 0x07, 0x88, 0x41,",
	"0xfc, 0x09, 0x00, 0x80, 0x40, 0x20, 0x08, 0x04};",
} ;
static int xrbf_n_one = NELEM(xrbf_one);

/* Valid bitmap file with hotspot definition. */
static char *xrbf_two[] = {
	"#define test_width 16",
	"#define test_height 8",
	"#define test_x_hot 5",
	"#define test_y_hot 6",
	"static char test_bits[] = {",
	"0x80, 0x00, 0x3f, 0xfe, 0x04, 0x07, 0x88, 0x41,",
	"0xfc, 0x09, 0x00, 0x80, 0x40, 0x20, 0x08, 0x04};",
} ;
static int xrbf_n_two = NELEM(xrbf_two);

/* Invalid bitmap file. */
static char *xrbf_three[] = {
	"#define not bit map data",
	"static char data_bits[]={",
	"};",
};
static int xrbf_n_three = NELEM(xrbf_three);

static char *xrbf_verify_array[8]={
	"0000000100000000",
	"1111110001111111",
	"0010000011100000",
	"0001000110000010",
	"0011111110010000",
	"0000000000000001",
	"0000001000000100",
	"0001000000100000",
};


static int
xrbf_create(file, data, elements)
char *file;
char **data;
int elements;
{
	FILE *fp;
	int a;

	fp = fopen(file, "w");
	if (fp == (FILE *)NULL) {
		delete("Could not create temporary bitmap file '%s'", file);
		return -1;
	}

	a = 0;
	while( a<elements ) {
		(void) fprintf(fp, "%s\n", data[a++]);
	}

	fclose(fp);
	return 0;
}

static void
xrbf_b_start() {
	tpstartup();
	(void) xrbf_create(xrbf_name, xrbf_one, xrbf_n_one);
}


static void
xrbf_b_end()  {
	(void) unlink(xrbf_name);
	tpcleanup();
}

static int
xrbf_check(pm, array, w, h)
Pixmap pm;
char **array;
int w;
int h;
{
	int lh, lw, bad;
	unsigned long exp;

	bad = 0;
	for(lh=0; lh<h; lh++) {
		for(lw=0; lw<w; lw++) {
			int pix;
			exp = (array[lh][lw]=='0'?W_BG:W_FG);
			pix = checkpixel(display, pm, lw, lh, exp);
			if ( !pix ) {
				trace("Bad Pixel at %d,%d", lw, lh);
				bad++;
			}
		}
	}

	return bad;
}

>>ASSERTION Good A
When the file
.A filename
is readable and in the X11 bitmap format, then a call to xname returns
.S BitmapSuccess . 
>>SET return-value BitmapSuccess
>>STRATEGY
Create a valid, readable, bitmap file.
Call xname to read the bitmap file.
Verify that BitmapSuccess was returned.
>>CODE

/* Create a valid, readable, bitmap file. */
	if (xrbf_create(filename, xrbf_two, xrbf_n_two)) {
		return;
	} else
		CHECK;

/* Call xname to read the bitmap file. */
	XCALL;

	(void) unlink(filename);
	CHECKPASS(1);

>>ASSERTION Good A
When the file
.A filename
is readable and in the X11 bitmap format, then a call to xname
returns the bitmap's height and width as read
from the file in
.A width_return
and
.A height_return ,
and a pixmap containing the bitmap with the bitmap's height and width, on
the same screen as the
.A drawable ,
in
.A bitmap_return .
>>STRATEGY
Create a valid, readable, bitmap file.
Call xname to read the bitmap file.
Verify that the width was returned as expected.
Verify that the height was returned as expected.
Call XGetGeometry to obtain the bitmap width, height and depth.
Verify that the bitmap was of the correct height, width and depth.
Verify that the bitmap contents were correct.
Verify that the bitmap was created on the correct screen.
>>CODE
Window rw_ret, rw2_ret;
int i_tmp;
unsigned int h_ret, w_ret, d_ret, ui_tmp;

/* Create a valid, readable, bitmap file. */
	if (xrbf_create(filename, xrbf_one, xrbf_n_one)) {
		return;
	} else
		CHECK;

/* Call xname to read the bitmap file. */
	width = 0;
	height = 0;
	bitmap = (Pixmap)NULL;

	XCALL;

/* Verify that the width was returned as expected. */
	if (width != 16) {
		FAIL;
		report("%s did not return the expected width",
			TestName);
		report("Expected width: 16");
		report("Returned width: %d", width);
	} else
		CHECK;

/* Verify that the height was returned as expected. */
	if (height != 8) {
		FAIL;
		report("%s did not return the expected height",
			TestName);
		report("Expected height: 8");
		report("Returned height: %d", height);
	} else
		CHECK;

/* Call XGetGeometry to obtain the bitmap width, height and depth. */
	(void)XGetGeometry(display, bitmap, &rw_ret, &i_tmp, &i_tmp,
		&w_ret, &h_ret, &ui_tmp, &d_ret);

/* Verify that the bitmap was of the correct height, width and depth. */
	if (w_ret != 16 || h_ret != 8 || d_ret != 1) {
		FAIL;
		report("%s created a pixmap of unexpected dimensions.",
			TestName);
		report("Expected width :16; Returned width :%u", w_ret);
		report("Expected height: 8; Returned height:%u", h_ret);
		report("Expected depth : 1; Returned depth :%u", d_ret);
	} else
		CHECK;

/* Verify that the bitmap contents were correct. */
	if (xrbf_check(bitmap, xrbf_verify_array, 16, 8)) {
		FAIL;
		report("%s did not generate the expected pixmap.",
			TestName);
	} else
		CHECK;

/* Verify that the bitmap was created on the correct screen. */
	(void)XGetGeometry(display, d, &rw2_ret, &i_tmp, &i_tmp,
		&ui_tmp, &ui_tmp, &ui_tmp, &ui_tmp);
	if(rw2_ret != rw_ret) {
		FAIL;
		report("%s did not generate the pixmap on the expected screen.",
			TestName);
		report("Root window for drawable and bitmap differ.");
	} else
		CHECK;
		
	(void) unlink(filename);

	CHECKPASS(6);

>>ASSERTION Good A
When the file
.A filename
is readable, and in the X11 bitmap format, and contains 
.M name_x_hot
and
.M name_y_hot ,
then a call to xname returns the value of
.M name_x_hot
to
.A x_hot_return ,
and the value of
.M name_y_hot
to
.A y_hot_return .
>>STRATEGY
Create a valid, readable, bitmap file containing a hotspot.
Call xname to read the bitmap file.
Verify that the x_hot_return was returned as expected.
Verify that the y_hot_return was returned as expected.
>>CODE

/* Create a valid, readable, bitmap file containing a hotspot. */
	if (xrbf_create(filename, xrbf_two, xrbf_n_two)) {
		return;
	} else
		CHECK;

/* Call xname to read the bitmap file. */
	x_hot = 0;
	y_hot = 0;
	XCALL;

/* Verify that the x_hot_return was returned as expected. */
	if (x_hot != 5) {
		FAIL;
		report("%s did not return the expected x_hot_return",
			TestName);
		report("Expected x_hot_return: 5");
		report("Returned x_hot_return: %d", x_hot);
	} else
		CHECK;

/* Verify that the y_hot_return was returned as expected. */
	if (y_hot != 6) {
		FAIL;
		report("%s did not return the expected y_hot_return",
			TestName);
		report("Expected y_hot_return: 6");
		report("Returned y_hot_return: %d", y_hot);
	} else
		CHECK;

	(void) unlink(filename);

	CHECKPASS(3);

>>ASSERTION Good A
When the file
.A filename
is readable, and in the X11 bitmap format, and does not contain
.M name_x_hot
and
.M name_y_hot ,
then a call to xname returns -1 to
.A x_hot_return
and
.A y_hot_return .
>>STRATEGY
Create a valid, readable, bitmap file containing no hotspot.
Call xname to read the bitmap file.
Verify that the x_hot_return was returned as expected.
Verify that the y_hot_return was returned as expected.
>>CODE

/* Create a valid, readable, bitmap file containing no hotspot. */
	if (xrbf_create(filename, xrbf_one, xrbf_n_one)) {
		return;
	} else
		CHECK;

/* Call xname to read the bitmap file. */
	x_hot = 0;
	y_hot = 0;
	XCALL;

/* Verify that the x_hot_return was returned as expected. */
	if (x_hot != -1) {
		FAIL;
		report("%s did not return the expected x_hot_return",
			TestName);
		report("Expected x_hot_return: -1");
		report("Returned x_hot_return: %d", x_hot);
	} else
		CHECK;

/* Verify that the y_hot_return was returned as expected. */
	if (y_hot != -1) {
		FAIL;
		report("%s did not return the expected y_hot_return",
			TestName);
		report("Expected y_hot_return: -1");
		report("Returned y_hot_return: %d", y_hot);
	} else
		CHECK;

	(void) unlink(filename);

	CHECKPASS(3);
>>ASSERTION Bad A
When the file
.A filename
cannot be opened, then a call to xname returns 
.S BitmapOpenFailed .
>>STRATEGY
Call xname with a non-existant bitmap filename.
Verify that BitmapOpenFailed was returned.
>>CODE
int ret;

/* Call xname with a non-existant bitmap filename. */
	filename = xrbf_bad_name;
	ret = XCALL;

/* Verify that BitmapOpenFailed was returned. */
	if (ret != BitmapOpenFailed) {
		FAIL;
		report("%s did not return correct value with a nonexistant",
			TestName);
		report("bitmap file.");
		report("Expected: %d (BitmapOpenFailed)");
		report("Returned: %d", ret);
	} else
		CHECK;

	CHECKPASS(1);

>>ASSERTION Bad A
When the file
.A filename
is readable and does not contain valid bitmap data, then a call to
xname returns
.S BitmapFileInvalid .
>>STRATEGY
Create an invalid, bitmap file.
Call xname to read the bitmap file.
Verify that BitmapFileInvalid was returned.
>>CODE
int ret;

/* Create an invalid, bitmap file. */
	if (xrbf_create(filename, xrbf_three, xrbf_n_three)) {
		return;
	} else
		CHECK;

/* Call xname to read the bitmap file. */
	ret = XCALL;

/* Verify that BitmapFileInvalid was returned. */
	if (ret != BitmapFileInvalid) {
		FAIL;
		report("%s did not return correct value with an invalid",
			TestName);
		report("bitmap file.");
		report("Expected: %d (BitmapFileInvalid)");
		report("Returned: %d", ret);
	} else
		CHECK;

	(void) unlink(filename);

	CHECKPASS(2);

>>ASSERTION Bad B 1
When insufficient memory is allocated, then a call to xname returns
.S BitmapNoMemory .
>>ASSERTION Bad A
.ER BadAlloc
>>SET tpstartup xrbf_b_start
>>SET tpcleanup xrbf_b_end
>>ASSERTION Bad A
When a drawable argument does not name a valid drawable, then one or more
.S BadDrawable
errors, one or more
.S BadGC
errors or both types of error occur.
>>STRATEGY
Create a bad drawable by creating and destroying a window.
Call test function using bad drawable as the drawable argument.
Verify that a BadDrawable and BadGC error occurs.
>>CODE BadDrawable

	seterrdef();

	A_DRAWABLE = (Drawable)badwin(A_DISPLAY);

>>SET no-error-status-check
	XCALL;

	if (geterr() == BadDrawable || geterr() == BadGC)
		PASS;
	else
		FAIL;