basic-lines.c revision 428d7b3d
1#include <stdint.h>
2#include <stdio.h>
3#include <stdlib.h>
4
5#include <X11/Xutil.h> /* for XDestroyImage */
6#include <pixman.h> /* for pixman blt functions */
7
8#include "test.h"
9
10static const XPoint points[]= {
11	/* top */
12	{ 0, 0},
13	{ 1, 0},
14	{ 2, 0},
15	{ 3, 0},
16	{ 4, 0},
17	{ 5, 0},
18	{ 6, 0},
19	{ 7, 0},
20	{ 8, 0},
21	/* right */
22	{ 8, 1},
23	{ 8, 2},
24	{ 8, 3},
25	{ 8, 4},
26	{ 8, 5},
27	{ 8, 6},
28	{ 8, 7},
29	{ 8, 8},
30	/* bottom */
31	{ 7, 8},
32	{ 6, 8},
33	{ 5, 8},
34	{ 4, 8},
35	{ 3, 8},
36	{ 2, 8},
37	{ 1, 8},
38	{ 0, 8},
39	/* left */
40	{ 0, 7},
41	{ 0, 6},
42	{ 0, 5},
43	{ 0, 4},
44	{ 0, 3},
45	{ 0, 2},
46	{ 0, 1},
47	{ 0, 0} /* and origin again for luck */
48};
49#define NUM_POINTS (sizeof(points)/sizeof(points[0]))
50
51static void clear(struct test_display *dpy, struct test_target *tt)
52{
53	XRenderColor render_color = {0};
54	XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
55			     0, 0, tt->width, tt->height);
56}
57
58static void draw_line(struct test_display *dpy, struct test_target *tt,
59		      int alu, int width, int style, int cap,
60		      const XPoint *p1, const XPoint *p2,
61		      int dx, int dy)
62{
63	XGCValues val;
64	GC gc;
65
66	val.function = GXcopy;
67	val.foreground = WhitePixel(dpy->dpy, 0);
68	val.line_width = width;
69	val.line_style = style;
70	val.cap_style = cap;
71
72	gc = XCreateGC(dpy->dpy, tt->draw,
73		       GCForeground |
74		       GCFunction |
75		       GCLineWidth |
76		       GCLineStyle |
77		       GCCapStyle,
78		       &val);
79	XDrawLine(dpy->dpy, tt->draw, gc,
80		  p1->x + dx, p1->y + dy,
81		  p2->x + dx, p2->y + dy);
82	XFreeGC(dpy->dpy, gc);
83}
84
85static void line_tests(struct test *t, enum target target)
86{
87	char buf[1024];
88	struct test_target out, ref;
89	int a, b, alu, lw, style, cap;
90
91	printf("Testing drawing of single line segments (%s): ",
92	       test_target_name(target));
93	fflush(stdout);
94
95	test_target_create_render(&t->out, target, &out);
96	test_target_create_render(&t->ref, target, &ref);
97
98	style = LineSolid;
99
100	for (alu = 0; alu < 16; alu++) {
101		for (cap = CapNotLast; cap <= CapProjecting; cap++) {
102			for (lw = 0; lw <= 4; lw++) {
103				for (a = 0; a < NUM_POINTS; a++) {
104					for (b = 0; b < NUM_POINTS; b++) {
105						sprintf(buf,
106							"p1=(%d, %d), p2=(%d, %d), width=%d, cap=%d, alu=%d",
107							points[a].x, points[a].y,
108							points[b].x, points[b].y,
109							lw, cap, alu);
110
111						clear(&t->out, &out);
112						clear(&t->ref, &ref);
113
114						draw_line(&t->out, &out, alu, lw, style, cap,
115							  &points[a], &points[b], 64, 64);
116						draw_line(&t->ref, &ref, alu, lw, style, cap,
117							  &points[a], &points[b], 64, 64);
118
119						test_compare(t,
120							     out.draw, out.format,
121							     ref.draw, ref.format,
122							     0, 0, out.width, out.height,
123							     buf);
124					}
125				}
126			}
127		}
128	}
129
130	test_target_destroy_render(&t->out, &out);
131	test_target_destroy_render(&t->ref, &ref);
132
133	printf("\n");
134}
135
136int main(int argc, char **argv)
137{
138	struct test test;
139	enum target t;
140
141	test_init(&test, argc, argv);
142
143	for (t = TARGET_FIRST; t <= TARGET_LAST; t++)
144		line_tests(&test, t);
145
146	return 0;
147}
148