103b705cfSriastradh#include <stdint.h> 203b705cfSriastradh#include <stdio.h> 303b705cfSriastradh#include <stdlib.h> 403b705cfSriastradh#include <string.h> 503b705cfSriastradh 603b705cfSriastradh#include <X11/Xutil.h> /* for XDestroyImage */ 703b705cfSriastradh 803b705cfSriastradh#include "test.h" 903b705cfSriastradh 1003b705cfSriastradhstatic void draw_string(struct test_display *t, Drawable d, uint8_t alu, 1103b705cfSriastradh int x, int y, uint32_t fg, uint32_t bg, int s, int fill) 1203b705cfSriastradh{ 1303b705cfSriastradh const char *strings[] = { 1403b705cfSriastradh "Hello", 1503b705cfSriastradh "World", 1603b705cfSriastradh "Cairo's twin is Giza", 1703b705cfSriastradh }; 1803b705cfSriastradh XGCValues val; 1903b705cfSriastradh GC gc; 2003b705cfSriastradh 2103b705cfSriastradh val.function = alu; 2203b705cfSriastradh val.foreground = fg; 2303b705cfSriastradh val.background = bg; 2403b705cfSriastradh 2503b705cfSriastradh gc = XCreateGC(t->dpy, d, GCForeground | GCBackground | GCFunction, &val); 2603b705cfSriastradh if (fill) 2703b705cfSriastradh XDrawImageString(t->dpy, d, gc, x, y, strings[s%3], strlen(strings[s%3])); 2803b705cfSriastradh else 2903b705cfSriastradh XDrawString(t->dpy, d, gc, x, y, strings[s%3], strlen(strings[s%3])); 3003b705cfSriastradh XFreeGC(t->dpy, gc); 3103b705cfSriastradh} 3203b705cfSriastradh 3303b705cfSriastradhstatic void clear(struct test_display *dpy, struct test_target *tt) 3403b705cfSriastradh{ 3503b705cfSriastradh XRenderColor render_color = {0}; 3603b705cfSriastradh XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color, 3703b705cfSriastradh 0, 0, tt->width, tt->height); 3803b705cfSriastradh} 3903b705cfSriastradh 4003b705cfSriastradhstatic void string_tests(struct test *t, int reps, int sets, enum target target) 4103b705cfSriastradh{ 4242542f5fSchristos struct test_target out, ref; 4303b705cfSriastradh int r, s; 4403b705cfSriastradh 4503b705cfSriastradh printf("Testing general (%s): ", test_target_name(target)); 4603b705cfSriastradh fflush(stdout); 4703b705cfSriastradh 4842542f5fSchristos test_target_create_render(&t->out, target, &out); 4942542f5fSchristos clear(&t->out, &out); 5003b705cfSriastradh 5103b705cfSriastradh test_target_create_render(&t->ref, target, &ref); 5203b705cfSriastradh clear(&t->ref, &ref); 5303b705cfSriastradh 5403b705cfSriastradh for (s = 0; s < sets; s++) { 5503b705cfSriastradh for (r = 0; r < reps; r++) { 5642542f5fSchristos int x = rand() % (2*out.width) - out.width; 5742542f5fSchristos int y = rand() % (2*out.height) - out.height; 5803b705cfSriastradh uint8_t alu = rand() % (GXset + 1); 5903b705cfSriastradh uint32_t fg = rand(); 6003b705cfSriastradh uint32_t bg = rand(); 6103b705cfSriastradh int str = rand(); 6203b705cfSriastradh int fill = rand() & 1; 6303b705cfSriastradh 6442542f5fSchristos draw_string(&t->out, out.draw, alu, x, y, fg, bg, str, fill); 6503b705cfSriastradh draw_string(&t->ref, ref.draw, alu, x, y, fg, bg, str, fill); 6603b705cfSriastradh } 6703b705cfSriastradh 6803b705cfSriastradh test_compare(t, 6942542f5fSchristos out.draw, out.format, 7003b705cfSriastradh ref.draw, ref.format, 7142542f5fSchristos 0, 0, out.width, out.height, 7203b705cfSriastradh ""); 7303b705cfSriastradh } 7403b705cfSriastradh 7503b705cfSriastradh printf("passed [%d iterations x %d]\n", reps, sets); 7603b705cfSriastradh 7742542f5fSchristos test_target_destroy_render(&t->out, &out); 7803b705cfSriastradh test_target_destroy_render(&t->ref, &ref); 7903b705cfSriastradh} 8003b705cfSriastradh 8103b705cfSriastradhint main(int argc, char **argv) 8203b705cfSriastradh{ 8303b705cfSriastradh struct test test; 8403b705cfSriastradh int i; 8503b705cfSriastradh 8603b705cfSriastradh test_init(&test, argc, argv); 8703b705cfSriastradh 8803b705cfSriastradh for (i = 0; i <= DEFAULT_ITERATIONS; i++) { 8942542f5fSchristos int reps = REPS(i), sets = SETS(i); 9003b705cfSriastradh enum target t; 9103b705cfSriastradh 9203b705cfSriastradh for (t = TARGET_FIRST; t <= TARGET_LAST; t++) { 9303b705cfSriastradh string_tests(&test, reps, sets, t); 9403b705cfSriastradh } 9503b705cfSriastradh } 9603b705cfSriastradh 9703b705cfSriastradh return 0; 9803b705cfSriastradh} 99