1 | /* -*- Mode: C; c-basic-offset: 2; -*- */ |
2 | /* GdkPixbuf library - test loaders |
3 | * |
4 | * Copyright (C) 2013 Red Hat, Inc. |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
18 | * |
19 | * Author: Matthias Clasen |
20 | */ |
21 | |
22 | #include "gdk-pixbuf/gdk-pixbuf.h" |
23 | #include "test-common.h" |
24 | #include <string.h> |
25 | |
26 | static void |
27 | test_inverted_cmyk_jpeg (void) |
28 | { |
29 | GError *error = NULL; |
30 | GdkPixbuf *ref, *ref2; |
31 | gboolean ret; |
32 | |
33 | if (!format_supported (filename: "jpeg" ) || !format_supported (filename: "png" )) |
34 | { |
35 | g_test_skip (msg: "format not supported" ); |
36 | return; |
37 | } |
38 | |
39 | ref = gdk_pixbuf_new_from_file (filename: g_test_get_filename (file_type: G_TEST_DIST, first_path: "premature-end.jpg" , NULL), error: &error); |
40 | g_assert_no_error (error); |
41 | |
42 | ref2 = gdk_pixbuf_new_from_file (filename: g_test_get_filename (file_type: G_TEST_DIST, first_path: "premature-end.png" , NULL), error: &error); |
43 | g_assert_no_error (error); |
44 | |
45 | ret = pixdata_equal (test: ref, ref: ref2, error: &error); |
46 | g_assert_no_error (error); |
47 | g_assert (ret); |
48 | |
49 | g_object_unref (object: ref); |
50 | g_object_unref (object: ref2); |
51 | } |
52 | |
53 | static void |
54 | test_type9_rotation_exif_tag (void) |
55 | { |
56 | GError *error = NULL; |
57 | GdkPixbuf *ref, *ref1, *ref2; |
58 | gboolean ret; |
59 | |
60 | if (!format_supported (filename: "jpeg" ) || !format_supported (filename: "png" )) |
61 | { |
62 | g_test_skip (msg: "format not supported" ); |
63 | return; |
64 | } |
65 | |
66 | ref = gdk_pixbuf_new_from_file (filename: g_test_get_filename (file_type: G_TEST_DIST, first_path: "bug725582-testrotate.jpg" , NULL), error: &error); |
67 | g_assert_no_error (error); |
68 | ref1 = gdk_pixbuf_apply_embedded_orientation (src: ref); |
69 | |
70 | ref2 = gdk_pixbuf_new_from_file (filename: g_test_get_filename (file_type: G_TEST_DIST, first_path: "bug725582-testrotate.png" , NULL), error: &error); |
71 | g_assert_no_error (error); |
72 | |
73 | ret = pixdata_equal (test: ref1, ref: ref2, error: &error); |
74 | g_assert_no_error (error); |
75 | g_assert (ret); |
76 | |
77 | g_assert_cmpstr (gdk_pixbuf_get_option (ref, "orientation" ), ==, "6" ); |
78 | |
79 | g_object_unref (object: ref); |
80 | } |
81 | |
82 | static void |
83 | test_bug_775218 (void) |
84 | { |
85 | GError *error = NULL; |
86 | GdkPixbuf *ref; |
87 | |
88 | if (!format_supported (filename: "jpeg" )) |
89 | { |
90 | g_test_skip (msg: "format not supported" ); |
91 | return; |
92 | } |
93 | |
94 | ref = gdk_pixbuf_new_from_file (filename: g_test_get_filename (file_type: G_TEST_DIST, first_path: "bug775218.jpg" , NULL), error: &error); |
95 | g_assert_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE); |
96 | g_clear_object (&ref); |
97 | } |
98 | |
99 | static void |
100 | (void) |
101 | { |
102 | GError *error = NULL; |
103 | GdkPixbuf *ref; |
104 | |
105 | if (!format_supported (filename: "jpeg" ) || !format_supported (filename: "png" )) |
106 | { |
107 | g_test_skip (msg: "format not supported" ); |
108 | return; |
109 | } |
110 | |
111 | ref = gdk_pixbuf_new_from_file (filename: g_test_get_filename (file_type: G_TEST_DIST, first_path: "bug143608-comment.jpg" , NULL), error: &error); |
112 | g_assert_no_error (error); |
113 | |
114 | g_assert_cmpstr (gdk_pixbuf_get_option (ref, "comment" ), ==, "COMMENT HERE" ); |
115 | g_object_unref (object: ref); |
116 | } |
117 | |
118 | static void |
119 | test_at_size (void) |
120 | { |
121 | GError *error = NULL; |
122 | GdkPixbuf *ref; |
123 | |
124 | if (!format_supported (filename: "jpeg" ) || !format_supported (filename: "png" )) |
125 | { |
126 | g_test_skip (msg: "format not supported" ); |
127 | return; |
128 | } |
129 | |
130 | ref = gdk_pixbuf_new_from_file (filename: g_test_get_filename (file_type: G_TEST_DIST, first_path: "bug753605-atsize.jpg" , NULL), error: &error); |
131 | g_assert_no_error (error); |
132 | g_object_unref (object: ref); |
133 | |
134 | ref = gdk_pixbuf_new_from_file_at_size (filename: g_test_get_filename (file_type: G_TEST_DIST, first_path: "bug753605-atsize.jpg" , NULL), |
135 | width: 50, height: 50, error: &error); |
136 | g_assert_no_error (error); |
137 | g_object_unref (object: ref); |
138 | } |
139 | |
140 | static void |
141 | test_jpeg_markers (void) |
142 | { |
143 | GdkPixbufLoader *loader; |
144 | GdkPixbuf *pixbuf; |
145 | GError *error = NULL; |
146 | gchar *contents; |
147 | gsize size; |
148 | |
149 | if (!format_supported (filename: "jpeg" )) |
150 | { |
151 | g_test_skip (msg: "format not supported" ); |
152 | return; |
153 | } |
154 | |
155 | g_file_get_contents (filename: g_test_get_filename (file_type: G_TEST_DIST, first_path: "issue70.jpg" , NULL), contents: &contents, length: &size, error: &error); |
156 | g_assert_no_error (error); |
157 | |
158 | loader = gdk_pixbuf_loader_new (); |
159 | |
160 | gdk_pixbuf_loader_write (loader, buf: (const guchar*)contents, count: size, error: &error); |
161 | g_assert_no_error (error); |
162 | |
163 | gdk_pixbuf_loader_close (loader, error: &error); |
164 | g_assert_no_error (error); |
165 | |
166 | pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); |
167 | g_assert_nonnull (pixbuf); |
168 | |
169 | g_object_unref (object: loader); |
170 | g_free (mem: contents); |
171 | } |
172 | |
173 | static void |
174 | test_jpeg_fbfbfbfb (void) |
175 | { |
176 | GdkPixbufLoader *loader; |
177 | GdkPixbuf *pixbuf; |
178 | GError *error = NULL; |
179 | gchar *contents; |
180 | gsize size; |
181 | |
182 | if (!format_supported (filename: "jpeg" )) |
183 | { |
184 | g_test_skip (msg: "format not supported" ); |
185 | return; |
186 | } |
187 | |
188 | g_test_message (format: "Load JPEG with size 0xfbfbfbfb (issue: 250)" ); |
189 | |
190 | g_file_get_contents (filename: g_test_get_filename (file_type: G_TEST_DIST, first_path: "issue205.jpg" , NULL), contents: &contents, length: &size, error: &error); |
191 | g_assert_no_error (error); |
192 | |
193 | loader = gdk_pixbuf_loader_new (); |
194 | |
195 | gdk_pixbuf_loader_write (loader, buf: (const guchar*)contents, count: size, error: &error); |
196 | g_assert_no_error (error); |
197 | |
198 | gdk_pixbuf_loader_close (loader, error: &error); |
199 | g_assert_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE); |
200 | |
201 | pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); |
202 | g_assert_nonnull (pixbuf); |
203 | |
204 | g_object_unref (object: loader); |
205 | g_free (mem: contents); |
206 | } |
207 | |
208 | int |
209 | main (int argc, char **argv) |
210 | { |
211 | g_test_init (argc: &argc, argv: &argv, NULL); |
212 | |
213 | g_test_add_func (testpath: "/pixbuf/jpeg/inverted_cmyk_jpeg" , test_func: test_inverted_cmyk_jpeg); |
214 | g_test_add_func (testpath: "/pixbuf/jpeg/type9_rotation_exif_tag" , test_func: test_type9_rotation_exif_tag); |
215 | g_test_add_func (testpath: "/pixbuf/jpeg/bug775218" , test_func: test_bug_775218); |
216 | g_test_add_func (testpath: "/pixbuf/jpeg/comment" , test_func: test_comment); |
217 | g_test_add_func (testpath: "/pixbuf/jpeg/at_size" , test_func: test_at_size); |
218 | g_test_add_func (testpath: "/pixbuf/jpeg/issue70" , test_func: test_jpeg_markers); |
219 | g_test_add_func (testpath: "/pixbuf/jpeg/issue205" , test_func: test_jpeg_fbfbfbfb); |
220 | |
221 | return g_test_run (); |
222 | } |
223 | |