summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2011-11-06 09:43:47 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2011-11-06 09:43:47 +0000
commitc76714c29d29687f941a9112e80223c817185d53 (patch)
tree635e2681bbb6110b66f13519efc41b64a15cca47
parentc1e1e20fe7875262530a4d522e970985642c3f13 (diff)
test: Add a basic line tester
Starting with exercising drawing of a single segment. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r--test/.gitignore1
-rw-r--r--test/Makefile.am1
-rw-r--r--test/basic-copyarea-size.c6
-rw-r--r--test/basic-copyarea.c3
-rw-r--r--test/basic-fillrect.c3
-rw-r--r--test/basic-lines.c147
-rw-r--r--test/basic-putimage.c3
-rw-r--r--test/basic-stress.c3
-rw-r--r--test/mixed-stress.c3
-rw-r--r--test/render-composite-solid.c3
-rw-r--r--test/render-copyarea-size.c6
-rw-r--r--test/render-copyarea.c3
-rw-r--r--test/render-fill-copy.c3
-rw-r--r--test/render-fill.c3
-rw-r--r--test/render-trapezoid-image.c6
-rw-r--r--test/render-trapezoid.c6
-rw-r--r--test/test.h2
-rw-r--r--test/test_image.c7
18 files changed, 188 insertions, 21 deletions
diff --git a/test/.gitignore b/test/.gitignore
index e44eb3f3..4bfc70db 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -2,6 +2,7 @@ basic-copyarea
basic-copyarea-size
basic-fillrect
basic-putimage
+basic-lines
basic-stress
render-fill
render-trapezoid
diff --git a/test/Makefile.am b/test/Makefile.am
index 475cb17b..dc35f9f4 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -3,6 +3,7 @@ stress_TESTS = \
basic-copyarea \
basic-copyarea-size \
basic-putimage \
+ basic-lines \
basic-stress \
render-fill \
render-trapezoid \
diff --git a/test/basic-copyarea-size.c b/test/basic-copyarea-size.c
index 3c4249e3..732bb816 100644
--- a/test/basic-copyarea-size.c
+++ b/test/basic-copyarea-size.c
@@ -88,11 +88,13 @@ int main(int argc, char **argv)
test_compare(&test,
real.a, real.format,
ref.a, ref.format,
- 0, 0, size, size);
+ 0, 0, size, size,
+ "");
test_compare(&test,
real.b, real.format,
ref.b, ref.format,
- 0, 0, size, size);
+ 0, 0, size, size,
+ "");
target_fini(&test.real, &real);
target_fini(&test.ref, &ref);
diff --git a/test/basic-copyarea.c b/test/basic-copyarea.c
index a4302f3a..a3a4ae7e 100644
--- a/test/basic-copyarea.c
+++ b/test/basic-copyarea.c
@@ -264,7 +264,8 @@ static void rect_tests(struct test *t, int reps, int sets, enum target target, i
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
- 0, 0, real.width, real.height);
+ 0, 0, real.width, real.height,
+ ""
}
printf("passed [%d iterations x %d]\n", reps, sets);
diff --git a/test/basic-fillrect.c b/test/basic-fillrect.c
index 55dacb63..67d7067e 100644
--- a/test/basic-fillrect.c
+++ b/test/basic-fillrect.c
@@ -228,7 +228,8 @@ static void rect_tests(struct test *t, int reps, int sets, enum target target)
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
- 0, 0, real.width, real.height);
+ 0, 0, real.width, real.height,
+ "");
}
printf("passed [%d iterations x %d]\n", reps, sets);
diff --git a/test/basic-lines.c b/test/basic-lines.c
new file mode 100644
index 00000000..b710b248
--- /dev/null
+++ b/test/basic-lines.c
@@ -0,0 +1,147 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include <pixman.h> /* for pixman blt functions */
+
+#include "test.h"
+
+static const XPoint points[]= {
+ /* top */
+ { 0, 0},
+ { 1, 0},
+ { 2, 0},
+ { 3, 0},
+ { 4, 0},
+ { 5, 0},
+ { 6, 0},
+ { 7, 0},
+ { 8, 0},
+ /* right */
+ { 8, 1},
+ { 8, 2},
+ { 8, 3},
+ { 8, 4},
+ { 8, 5},
+ { 8, 6},
+ { 8, 7},
+ { 8, 8},
+ /* bottom */
+ { 7, 8},
+ { 6, 8},
+ { 5, 8},
+ { 4, 8},
+ { 3, 8},
+ { 2, 8},
+ { 1, 8},
+ { 0, 8},
+ /* left */
+ { 0, 7},
+ { 0, 6},
+ { 0, 5},
+ { 0, 4},
+ { 0, 3},
+ { 0, 2},
+ { 0, 1},
+ { 0, 0} /* and origin again for luck */
+};
+#define NUM_POINTS (sizeof(points)/sizeof(points[0]))
+
+static void clear(struct test_display *dpy, struct test_target *tt)
+{
+ XRenderColor render_color = {0};
+ XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
+ 0, 0, tt->width, tt->height);
+}
+
+static void draw_line(struct test_display *dpy, struct test_target *tt,
+ int alu, int width, int style, int cap,
+ const XPoint *p1, const XPoint *p2,
+ int dx, int dy)
+{
+ XGCValues val;
+ GC gc;
+
+ val.function = GXcopy;
+ val.foreground = WhitePixel(dpy->dpy, 0);
+ val.line_width = width;
+ val.line_style = style;
+ val.cap_style = cap;
+
+ gc = XCreateGC(dpy->dpy, tt->draw,
+ GCForeground |
+ GCFunction |
+ GCLineWidth |
+ GCLineStyle |
+ GCCapStyle,
+ &val);
+ XDrawLine(dpy->dpy, tt->draw, gc,
+ p1->x + dx, p1->y + dy,
+ p2->x + dx, p2->y + dy);
+ XFreeGC(dpy->dpy, gc);
+}
+
+static void line_tests(struct test *t, enum target target)
+{
+ char buf[1024];
+ struct test_target real, ref;
+ int a, b, alu, lw, style, cap;
+
+ printf("Testing drawing of single line segments (%s): ",
+ test_target_name(target));
+ fflush(stdout);
+
+ test_target_create_render(&t->real, target, &real);
+ test_target_create_render(&t->ref, target, &ref);
+
+ style = LineSolid;
+
+ for (alu = 0; alu < 16; alu++) {
+ for (cap = CapNotLast; cap <= CapProjecting; cap++) {
+ for (lw = 0; lw <= 4; lw++) {
+ for (a = 0; a < NUM_POINTS; a++) {
+ for (b = 0; b < NUM_POINTS; b++) {
+ sprintf(buf,
+ "p1=(%d, %d), p2=(%d, %d), width=%d, cap=%d, alu=%d",
+ points[a].x, points[a].y,
+ points[b].x, points[b].y,
+ lw, cap, alu);
+
+ clear(&t->real, &real);
+ clear(&t->ref, &ref);
+
+ draw_line(&t->real, &real, alu, lw, style, cap,
+ &points[a], &points[b], 64, 64);
+ draw_line(&t->ref, &ref, alu, lw, style, cap,
+ &points[a], &points[b], 64, 64);
+
+ test_compare(t,
+ real.draw, real.format,
+ ref.draw, ref.format,
+ 0, 0, real.width, real.height,
+ buf);
+ }
+ }
+ }
+ }
+ }
+
+ test_target_destroy_render(&t->real, &real);
+ test_target_destroy_render(&t->ref, &ref);
+
+ printf("\n");
+}
+
+int main(int argc, char **argv)
+{
+ struct test test;
+ enum target t;
+
+ test_init(&test, argc, argv);
+
+ for (t = TARGET_FIRST; t <= TARGET_LAST; t++)
+ line_tests(&test, t);
+
+ return 0;
+}
diff --git a/test/basic-putimage.c b/test/basic-putimage.c
index ce319764..5d689088 100644
--- a/test/basic-putimage.c
+++ b/test/basic-putimage.c
@@ -245,7 +245,8 @@ static void rect_tests(struct test *t, int reps, int sets, enum target target, i
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
- 0, 0, real.width, real.height);
+ 0, 0, real.width, real.height,
+ "");
}
printf("passed [%d iterations x %d]\n", reps, sets);
diff --git a/test/basic-stress.c b/test/basic-stress.c
index 28fe5c96..56571734 100644
--- a/test/basic-stress.c
+++ b/test/basic-stress.c
@@ -130,7 +130,8 @@ static void rect_tests(struct test *test, int iterations, enum target target)
test_compare(test,
real.draw, real.format,
ref.draw, ref.format,
- 0, 0, real.width, real.height);
+ 0, 0, real.width, real.height,
+ "");
printf("passed [%d iterations]\n", n);
diff --git a/test/mixed-stress.c b/test/mixed-stress.c
index 8aa7ca91..42e2c082 100644
--- a/test/mixed-stress.c
+++ b/test/mixed-stress.c
@@ -183,7 +183,8 @@ static void rect_tests(struct test *test, int iterations, enum target target)
test_compare(test,
real.draw, real.format,
ref.draw, ref.format,
- 0, 0, real.width, real.height);
+ 0, 0, real.width, real.height,
+ "");
printf("passed [%d iterations]\n", n);
diff --git a/test/render-composite-solid.c b/test/render-composite-solid.c
index 3918247d..6609c4bc 100644
--- a/test/render-composite-solid.c
+++ b/test/render-composite-solid.c
@@ -220,7 +220,8 @@ static void rect_tests(struct test *t, int reps, int sets, enum target target)
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
- 0, 0, real.width, real.height);
+ 0, 0, real.width, real.height,
+ "");
}
printf("passed [%d iterations x %d]\n", reps, sets);
diff --git a/test/render-copyarea-size.c b/test/render-copyarea-size.c
index 89d1ed31..65fb6caf 100644
--- a/test/render-copyarea-size.c
+++ b/test/render-copyarea-size.c
@@ -101,11 +101,13 @@ int main(int argc, char **argv)
test_compare(&test,
real.a, real.format,
ref.a, ref.format,
- 0, 0, size, size);
+ 0, 0, size, size,
+ "");
test_compare(&test,
real.b, real.format,
ref.b, ref.format,
- 0, 0, size, size);
+ 0, 0, size, size,
+ "");
target_fini(&test.real, &real);
target_fini(&test.ref, &ref);
diff --git a/test/render-copyarea.c b/test/render-copyarea.c
index d45a4569..bcab553b 100644
--- a/test/render-copyarea.c
+++ b/test/render-copyarea.c
@@ -287,7 +287,8 @@ static void rect_tests(struct test *t, int reps, int sets, enum target target, i
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
- 0, 0, real.width, real.height);
+ 0, 0, real.width, real.height,
+ "");
}
printf("passed [%d iterations x %d]\n", reps, sets);
diff --git a/test/render-fill-copy.c b/test/render-fill-copy.c
index 2017e083..bc4a734d 100644
--- a/test/render-fill-copy.c
+++ b/test/render-fill-copy.c
@@ -244,7 +244,8 @@ static void rect_tests(struct test *t, int reps, int sets, enum target target)
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
- 0, 0, real.width, real.height);
+ 0, 0, real.width, real.height,
+ "");
}
printf("passed [%d iterations x %d]\n", reps, sets);
diff --git a/test/render-fill.c b/test/render-fill.c
index 709c2175..27d565bc 100644
--- a/test/render-fill.c
+++ b/test/render-fill.c
@@ -212,7 +212,8 @@ static void rect_tests(struct test *t, int reps, int sets, enum target target)
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
- 0, 0, real.width, real.height);
+ 0, 0, real.width, real.height,
+ "");
}
printf("passed [%d iterations x %d]\n", reps, sets);
diff --git a/test/render-trapezoid-image.c b/test/render-trapezoid-image.c
index 4f6ddd78..c794cbb8 100644
--- a/test/render-trapezoid-image.c
+++ b/test/render-trapezoid-image.c
@@ -418,7 +418,8 @@ static void rect_tests(struct test *t,
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
- 0, 0, real.width, real.height);
+ 0, 0, real.width, real.height,
+ "");
}
printf("passed [%d iterations x %d]\n", reps, sets);
@@ -562,7 +563,8 @@ static void trap_tests(struct test *t,
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
- 0, 0, real.width, real.height);
+ 0, 0, real.width, real.height,
+ "");
}
printf("passed [%d iterations x %d]\n", reps, sets);
diff --git a/test/render-trapezoid.c b/test/render-trapezoid.c
index 13683e1d..f7fd5bbf 100644
--- a/test/render-trapezoid.c
+++ b/test/render-trapezoid.c
@@ -267,7 +267,8 @@ static void rect_tests(struct test *t,
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
- 0, 0, real.width, real.height);
+ 0, 0, real.width, real.height,
+ "");
}
printf("passed [%d iterations x %d]\n", reps, sets);
@@ -391,7 +392,8 @@ static void trap_tests(struct test *t,
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
- 0, 0, real.width, real.height);
+ 0, 0, real.width, real.height,
+ "");
}
printf("passed [%d iterations x %d]\n", reps, sets);
diff --git a/test/test.h b/test/test.h
index b46dbb5d..1e3995bb 100644
--- a/test/test.h
+++ b/test/test.h
@@ -43,7 +43,7 @@ void test_init(struct test *test, int argc, char **argv);
void test_compare(struct test *real,
Drawable real_draw, XRenderPictFormat *real_format,
Drawable ref_draw, XRenderPictFormat *ref_format,
- int x, int y, int w, int h);
+ int x, int y, int w, int h, const char *info);
#define MAX_DELTA 3
int pixel_difference(uint32_t a, uint32_t b);
diff --git a/test/test_image.c b/test/test_image.c
index a2fdbf0b..f2cf9069 100644
--- a/test/test_image.c
+++ b/test/test_image.c
@@ -117,7 +117,8 @@ static void test_compare_fallback(struct test *t,
void test_compare(struct test *t,
Drawable real_draw, XRenderPictFormat *real_format,
Drawable ref_draw, XRenderPictFormat *ref_format,
- int x, int y, int w, int h)
+ int x, int y, int w, int h,
+ const char *info)
{
XImage real_image, ref_image;
Pixmap tmp;
@@ -172,8 +173,8 @@ void test_compare(struct test *t,
show_pixels(buf,
&real_image, &ref_image,
i, j, w, h);
- die("discrepancy found at (%d+%d, %d+%d): found %08x, expected %08x (delta: %d)\n%s",
- x,i, y,j, a, b, pixel_difference(a, b), buf);
+ die("discrepancy found at (%d+%d, %d+%d): found %08x, expected %08x (delta: %d)\n%s%s\n",
+ x,i, y,j, a, b, pixel_difference(a, b), buf, info);
}
}
real += real_image.bytes_per_line;