summaryrefslogtreecommitdiff
path: root/tests/jpeg/bug00338.c
blob: 14c660fb24d0c50f1ba83ce7519c68d7d74104e6 (plain)
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
/**
 * Regression test for <https://github.com/libgd/libgd/issues/338>
 *
 * We're testing that reading a JPEG image with gdImageCreateFromJpeg()
 * raises a GD_WARNING for the fatal libjpeg error, but not a GD_ERROR.
 * We also make sure, that the fatal libjpeg error is actually reported.
 *
 * See also ../png/bug00338.c
 */

#include <string.h>
#include "gd.h"
#include "gd_errors.h"
#include "gdtest.h"

#define MSG "gd-jpeg: JPEG library reports unrecoverable error: %s"

static int error_handler_called = 0;

static void error_handler(int priority, const char *format, va_list args)
{
	ARG_NOT_USED(args);
	if (!strcmp(format, MSG)) {
		gdTestAssertMsg(priority == GD_WARNING, "expected priority %d, but got %d", GD_WARNING, priority);
		error_handler_called = 1;
	}
}

int main()
{
	gdImagePtr im;
	FILE *fp;

	gdSetErrorMethod(error_handler);

	im = gdImageCreateTrueColor(10, 10);
	fp = gdTestTempFp();
	gdImagePng(im, fp);
	gdImageDestroy(im);

	im = gdImageCreateFromJpeg(fp);
	gdTestAssert(im == NULL);

	gdTestAssert(error_handler_called);

	return gdNumFailures();
}