diff options
Diffstat (limited to 'tests/test_image.c')
| -rw-r--r-- | tests/test_image.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/test_image.c b/tests/test_image.c new file mode 100644 index 0000000..c637770 --- /dev/null +++ b/tests/test_image.c @@ -0,0 +1,62 @@ +#define _POSIX_C_SOURCE 200809L + +#include "kd_image.h" + +#include <stdio.h> +#include <X11/Xutil.h> + +typedef struct KDTestImageHandle { + XImage *ximage; + GC clip_mask_gc; + Pixmap clip_mask; +} KDTestImageHandle; + +int main(int argc, char **argv) +{ + Display *display; + struct nk_image image; + KDTestImageHandle *handle; + Visual *visual; + unsigned long first_pixel; + unsigned long second_pixel; + + if (argc != 3) { + (void)fprintf(stderr, "Usage: %s red-green-p3.ppm red-green-p6.ppm\n", argv[0]); + return 2; + } + display = XOpenDisplay(NULL); + if (display == NULL) { + (void)fprintf(stderr, "Could not open DISPLAY.\n"); + return 2; + } + image = kd_ppm_load(display, DefaultScreen(display), argv[1], 20U, 20U); + if (image.handle.ptr == NULL || image.w != 2U || image.h != 1U) { + (void)fprintf(stderr, "P3 image failed to load.\n"); + XCloseDisplay(display); + return 1; + } + handle = (KDTestImageHandle *)image.handle.ptr; + visual = DefaultVisual(display, DefaultScreen(display)); + first_pixel = XGetPixel(handle->ximage, 0, 0); + second_pixel = XGetPixel(handle->ximage, 1, 0); + if ((first_pixel & visual->red_mask) == 0UL || + (first_pixel & visual->green_mask) != 0UL || + (second_pixel & visual->green_mask) == 0UL || + (second_pixel & visual->red_mask) != 0UL) { + (void)fprintf(stderr, "P3 pixel colors were incorrect.\n"); + kd_ppm_free(&image); + XCloseDisplay(display); + return 1; + } + kd_ppm_free(&image); + image = kd_ppm_load(display, DefaultScreen(display), argv[2], 20U, 20U); + if (image.handle.ptr == NULL || image.w != 2U || image.h != 1U) { + (void)fprintf(stderr, "P6 image failed to load.\n"); + XCloseDisplay(display); + return 1; + } + kd_ppm_free(&image); + XCloseDisplay(display); + (void)puts("PASS: P3/P6 PPM decoding and XImage pixels"); + return 0; +} |
