4 * Iterate over all pixel types, try to save and load back pixmap.
6 * Copyright (C) 2009-2014 Cyril Hrubis <metan@ucw.cz>
13 #include <core/GP_Pixmap.h>
14 #include <core/GP_GetPutPixel.h>
15 #include <loaders/GP_Loaders.h>
19 typedef int (*Save)(const GP_Pixmap *src, const char *path, GP_ProgressCallback *callback);
20 typedef GP_Pixmap *(*Load)(const char *path, GP_ProgressCallback *callback);
22 static int test(Save Saver, Load Loader, GP_PixelType pixel_type)
27 int ret = TST_SUCCESS;
29 src = GP_PixmapAlloc(100, 100, pixel_type);
32 tst_msg("Malloc failed");
36 for (x = 0; x < src->w; x++)
37 for (y = 0; y < src->w; y++)
38 GP_PutPixel(src, x, y, 0);
40 if (Saver(src, "testfile", NULL)) {
41 if (errno == ENOSYS) {
42 tst_msg("Unimplemented pixel value");
47 if (errno == EINVAL) {
48 tst_msg("Invalid pixel value for the format");
53 tst_msg("Saver failed with %s", strerror(errno));
58 res = Loader("testfile", NULL);
61 tst_msg("Failed to load saved image");
66 tst_msg("Loaded back as %s", GP_PixelTypeName(res->pixel_type));
68 if (res->w != src->w || res->h != src->h) {
69 tst_msg("Invalid loaded image size %ux%u", res->w, res->h);
73 if (GP_GetPixel(res, 0, 0) != 0) {
74 tst_msg("Pixel value is wrong %x", GP_GetPixel(res, 0, 0));
85 @ for pt in pixeltypes:
86 @ if not pt.is_unknown():
87 static int test_{{ fmt }}_{{ pt.name }}(void)
89 return test(GP_Save{{ fmt }}, GP_Load{{ fmt }}, GP_PIXEL_{{ pt.name }});
94 const struct tst_suite tst_suite = {
95 .suite_name = "SaveLoad",
98 @ for pt in pixeltypes:
99 @ if not pt.is_unknown():
100 {.name = "{{ fmt }} {{ pt.name }}",
101 .tst_fn = test_{{ fmt }}_{{ pt.name }},
102 .flags = TST_TMPDIR | TST_MALLOC_CANARIES},