summaryrefslogtreecommitdiff
path: root/xc/test/xsuite/xtest/tset/CH05/stdshs/stdshs.m
blob: b0bb511a843ff5915a678adc920b0cb6618b2d26 (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
/*
 
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 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 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.
 *
 * $XConsortium: stdshs.m,v 1.7 92/06/11 16:18:04 rws Exp $
 */
>>TITLE XSetDashes CH05
void
XSetDashes(display, gc, dash_offset, dash_list, n)
Display *display = Dsp;
GC gc;
int dash_offset;
char *dash_list = dashes;
int n = sizeof(dashes)/sizeof(char);
>>EXTERN
char dashes[] = { 2, 1};
char odashes[] = {1, 3, 2};
char edashes[] = {1, 3, 2, 1, 3, 2};
char errdashes[] = {1, 0, 1};
>>SET need-gc-flush
>>ASSERTION Good A
A call to xname sets the 
.M dash_offset
and
.M dash_list
attributes for dashed line styles
in the specified GC to the values of the
.A dash_offset
and
.A dash_list
arguments.
>>STRATEGY
Create Window.
Create GC with dashes component = 1 , LineStyle = LineDoubleDash, fg = WhitePixel, bg = BlackPixel.
Set pixel at (1, 0) with XDrawPoint.
Draw line from (0, 0) to (2, 0) with XDrawLines.
Verify pixel at (1, 0) is bg using XGetImage and XGetpixel.
Set dashes component of GC to [2, 1] with XSetDashes.
Draw line from (0, 0) to (2, 0) using XDrawLine.
Verify pixel at (1, 0) is fg using XGetImage and XGetPixel.
>>CODE
XVisualInfo *vp;
XGCValues values;
GC gc;
Window win;
int twidth;

	for(twidth = 0; twidth < 2; twidth++) {
		resetvinf(VI_WIN);
		nextvinf(&vp);
		win = makewin(display, vp);

		values.foreground = W_FG;
		values.background = W_BG;
		values.line_style = LineDoubleDash;
		values.line_width = twidth;
		values.dashes = 1; /* [1, 1] */


		gc = XCreateGC(display, win, (GCLineWidth |GCLineStyle | GCDashList | GCForeground | GCBackground), &values);

		XDrawPoint(display, win, gc, 1, 0);
		XDrawLine(display, win, gc, 0, 0, 2, 0);

		if( ! checkpixel(display, win, 1, 0, W_BG)) {
			delete("Pixel at (1, 0) was not set to background (width %d)", twidth);
			return;
		} else
			CHECK;

		dash_offset = 0;
		dash_list= dashes;
		n = sizeof(dashes)/sizeof(char);
		XCALL;

		XDrawLine(display, win, gc, 0, 0, 2, 0);

		if( ! checkpixel(display, win, 1, 0, W_FG)) {
			report("Pixel at (1, 0) was not set to foreground (width %d)", twidth);			
			FAIL;
		} else
			CHECK;

	}
	CHECKPASS(4);

>>ASSERTION Good A
The initial and alternate elements of the
.A dash_list
argument specify the lengths of the even dashes and 
the second and alternate elements specify the lengths of the odd dashes.
>>STRATEGY
For zero width and non-zero width lines:
    Create GC with line_style = LineDoubleDashed.
    Set dashes component of GC to [2, 1] with XSetDashes.
    Draw horizontal line from (0, 0) to (4, 0) using XDrawLine.
    Verify pixels at (0, 0) and (1, 0) are fg using XGetImage and XGetPixel.
    Verify pixel at (2, 0) is bg using XGetImage and XGetPixel.
    Verify pixel at (3, 0) is fg using XGetImage and XGetPixel.
    Draw vertical line from (0, 1) to (0, 5) using XDrawLine.
    Verify pixels at (0, 1) and (0, 2) are fg using XGetImage and XGetPixel.
    Verify pixel at (0, 3) is bg using XGetImage and XGetPixel.
    Verify pixel at (0, 4) is fg using XGetImage and XGetPixel.
>>CODE
XVisualInfo *vp;
GC gc;
XGCValues values;
Window win;
int twidth;


	for(twidth=0; twidth < 2; twidth++) {
		resetvinf(VI_WIN);
		nextvinf(&vp);
		win = makewin(display, vp);
	
		values.foreground = W_FG;
		values.background = W_BG;
		values.line_style = LineDoubleDash;
		values.line_width = twidth;
	
		gc = XCreateGC(display, win, (GCLineWidth | GCLineStyle | GCForeground | GCBackground ), &values);
	
		dash_offset = 0;
		dash_list = dashes;
		n = sizeof(dashes)/sizeof(char);
	
		XCALL;

		XDrawLine(display, win, gc, 0, 0, 4, 0);
	
		if( (checkpixels(display, win, 0, 0, 1, 0, 2, W_FG) == True) &&
		    (checkpixel(display, win, 2, 0, W_BG) == True) &&
		    (checkpixel(display, win, 3, 0, W_FG) == True) )
			CHECK;
		else {
			report("Horizontal dashing incorrect for width %d.", twidth);
			FAIL;
		}

		XDrawLine(display, win, gc, 0, 1, 0, 5);
	
		if(  (checkpixels(display, win, 0, 1, 0, 1, 2, W_FG) == True) &&
		     (checkpixel(display, win, 0, 3, W_BG) == True) &&
		     (checkpixel(display, win, 0, 4, W_FG) == True) )
			 CHECK;
		 else {
			 report("Vertical dashing incorrect for width %d.", twidth);
			 FAIL;
		 }

	}
	CHECKPASS(4);

>>ASSERTION Good A
When an odd-length list is specified, then it is
concatenated with itself to produce an even-length list.
>>STRATEGY
Create GC with line_style = LineDoubleDashed.
Set dashes component of GC to [1, 3, 2] with XSetDashes.
Draw horizontal line from (0, 0) to (10, 0) using XDrawLine.
Set dashes component of GC to [1, 3, 2, 1, 3, 2] with XSetDashes.
Draw horizontal line from (0, 1) to (10, 1) using XDrawLine.
Verify that the two lines are identical using XGetImage and XGetPixel.
>>CODE
XVisualInfo *vp;
XGCValues values;
XImage *image;
Window win;
int i;

	resetvinf(VI_WIN);
	nextvinf(&vp);
	win = makewin(display, vp);

	values.foreground = W_FG;
	values.background = W_BG;
	values.line_style = LineDoubleDash;
	gc = XCreateGC(display, win, (GCLineStyle | GCForeground | GCBackground), &values);

	dash_offset = 0;
	dash_list = odashes;
	n = sizeof(odashes)/sizeof(char);
	XCALL;

	XDrawLine(display, win, gc, 0, 0, 10, 0);


	dash_offset = 0;
	dash_list = edashes;
	n = sizeof(edashes)/sizeof(char);
	XCALL;

	XDrawLine(display, win, gc, 0, 1, 10, 1);

	image = XGetImage(display, win, 0, 0, 10, 2, AllPlanes, ZPixmap);

	for(i=0; i<10; i++)
		if(XGetPixel(image, i, 0) != XGetPixel(image, i, 1)) {
			report("Pixel at (%d,0) was not the same as pixel at (%d,1).", i, i);
			FAIL;
		} else
			CHECK;

	CHECKPASS(10);

>>ASSERTION Bad B 1
.ER Alloc
>>ASSERTION Bad A
.ER GC
>>ASSERTION Bad A
When the specified dash list is empty, then a
.S BadValue 
error occurs.
>>STRATEGY
Call XSetDashes with dash_list set to NULL and n set to 0.
Verify that a BadValue error occurs.
>>CODE BadValue

	gc = XCreateGC(display, DRW(display), 0L, (XGCValues*) 0);

	dash_offset = 0;
	dash_list = (char *)NULL;
	n = 0;
	XCALL;

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

>>ASSERTION Bad A
When an element of the dash list is 0, then a
.S BadValue 
error occurs.
>>STRATEGY
Set dashes component of GC to [1, 0, 1] with XSetDashes.
Verify that a BadValue error occurs.
>>CODE BadValue
int screen;
GC gc;

	screen = DefaultScreen(display);
	gc = XCreateGC(display, RootWindow(display, screen), 0L, (XGCValues*) 0);
	dash_offset = 0;
	dash_list = errdashes;
	n = sizeof(errdashes)/sizeof(char);
	XCALL;

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

>># HISTORY cal Completed	Written in new format and style
>># HISTORY kieron Completed	Global and pixel checking to do - 19/11/90
>># HISTORY dave Completed	Final checking to do - 21/11/90
>># HISTORY cal Action		Writing code.