Rename GP_Context -> GP_Pixmap
[gfxprim.git] / tests / loaders / SaveAbort.gen.c.t
blobac2aa2a1e0c7ec8a592c60bbd8c2b728f84b32ff
1 @ include source.t
2 @ include savers.t
3 /*
4  * Iterate over all pixel types, try to save pixmap but abort it from callback.
5  *
6  * Copyright (C) 2009-2014 Cyril Hrubis <metan@ucw.cz>
7  */
9 #include <string.h>
10 #include <errno.h>
11 #include <stdlib.h>
13 #include <core/GP_Pixmap.h>
14 #include <loaders/GP_Loaders.h>
16 #include "tst_test.h"
18 typedef int (*Save)(const GP_Pixmap *src, const char *path, GP_ProgressCallback *callback);
20 static int progress_callback(GP_ProgressCallback *self)
22         (void) self;
23         return 1;
26 static int test(Save Saver, GP_PixelType pixel_type)
28         GP_Pixmap *src;
29         GP_ProgressCallback callback ={.callback = progress_callback};
30         int ret = TST_SUCCESS;
32         src = GP_PixmapAlloc(100, 100, pixel_type);
34         if (!src) {
35                 tst_msg("Malloc failed");
36                 return TST_UNTESTED;
37         }
39         if (Saver(src, "testfile", &callback)) {
40                 if (errno == ENOSYS) {
41                         tst_msg("Unimplemented pixel value");
42                         ret = TST_SKIPPED;
43                         goto err;
44                 }
46                 if (errno == EINVAL) {
47                         tst_msg("Invalid pixel value for the format");
48                         ret = TST_SKIPPED;
49                         goto err;
50                 }
52                 if (errno == ECANCELED) {
53                         if (access("testfile", F_OK) == 0) {
54                                 tst_msg("Operation canceled but file exists");
55                                 ret = TST_FAILED;
56                                 goto err;
57                         } else {
58                                 goto err;
59                         }
60                 }
62                 tst_msg("Saver failed with %s", strerror(errno));
63                 ret = TST_FAILED;
64                 goto err;
65         } else {
66                 tst_msg("Succedded unexpectedly");
67                 ret = TST_FAILED;
68         }
70 err:
71         GP_PixmapFree(src);
72         return ret;
75 @ for fmt in fmts:
76 @     for pt in pixeltypes:
77 @         if not pt.is_unknown():
78 static int test_{{ fmt }}_{{ pt.name }}(void)
80         return test(GP_Save{{ fmt }}, GP_PIXEL_{{ pt.name }});
83 @ end
85 const struct tst_suite tst_suite = {
86         .suite_name = "SaveAbort",
87         .tests = {
88 @ for fmt in fmts:
89 @     for pt in pixeltypes:
90 @         if not pt.is_unknown():
91                 {.name = "{{ fmt }} {{ pt.name }}",
92                  .tst_fn = test_{{ fmt }}_{{ pt.name }},
93                  .flags = TST_TMPDIR | TST_CHECK_MALLOC},
94 @ end
95                 {.name = NULL},
96         }