File: gd2_read.c

package info (click to toggle)
libgd2 2.2.4-2%2Bdeb9u5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 9,956 kB
  • sloc: ansic: 46,953; sh: 5,560; cpp: 1,325; makefile: 295; perl: 223; tcl: 45; awk: 43
file content (62 lines) | stat: -rw-r--r-- 1,214 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "gd.h"
#include <stdio.h>
#include <stdlib.h>
#include "gdtest.h"

int main(int argc, char *argv[])
{
	int error = 0, i = 0;
	gdImagePtr im, exp;
	FILE *fp;
	char *path[] = {
			"conv_test.gd2",
			"invalid_neg_size.gd2",
			"invalid_header.gd2",
			NULL
	};
	char *path_exp[] = {
			"conv_test_exp.png",
			NULL,
			NULL,
			NULL
	};
	while (path[i] != NULL) {
		fp = gdTestFileOpen2("gd2", path[i]);
		if (!fp) {
			gdTestErrorMsg("failed, cannot open file: %s\n", path[0]);
			return 1;
		}
		im = gdImageCreateFromGd2(fp);
		fclose(fp);

		if (path_exp[i] != NULL) {
			fp = gdTestFileOpen2("gd2", path_exp[i]);
			if (!fp) {
				gdTestErrorMsg("failed, cannot open file: %s\n", path_exp[i]);
				return 1;
			}
			exp = gdImageCreateFromPng(fp);
			if (!gdAssertImageEquals(exp, im)) {
				gdTestErrorMsg("image %s differs from expected result\n", path[i]);
				gdImageDestroy(im);
				error = 1;
			} else {
				error = 0;
			}
			if (exp) {
				gdImageDestroy(exp);
			}
		} else {
			/* expected to fail */
			if (im) {
				gdTestErrorMsg("image %s should have failed to be loaded\n", path[i]);
				gdImageDestroy(im);
				error = 1;
			} else {
				error = 0;
			}
		}
		i++;
	}
	return error;
}