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 "config.h" |
23 | #include "gdk-pixbuf/gdk-pixbuf.h" |
24 | #include "gdk-pixbuf/gdk-pixdata.h" |
25 | #include "test-common.h" |
26 | #include <string.h> |
27 | |
28 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
29 | static void |
30 | test_pixdata_deserialize (gconstpointer data) |
31 | { |
32 | const gchar *filename = data; |
33 | GdkPixbuf *pixbuf; |
34 | GdkPixdata pixdata; |
35 | GError *error = NULL; |
36 | gchar *contents; |
37 | gsize size; |
38 | |
39 | g_file_get_contents (filename: g_test_get_filename (file_type: G_TEST_DIST, first_path: filename, NULL), contents: &contents, length: &size, error: &error); |
40 | g_assert_no_error (error); |
41 | |
42 | gdk_pixdata_deserialize (pixdata: &pixdata, stream_length: size, stream: (const guint8 *) contents, error: &error); |
43 | g_assert_no_error (error); |
44 | |
45 | pixbuf = gdk_pixbuf_from_pixdata (pixdata: &pixdata, TRUE, error: &error); |
46 | g_assert_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE); |
47 | g_clear_error (err: &error); |
48 | g_free (mem: contents); |
49 | |
50 | pixbuf = gdk_pixbuf_from_pixdata (pixdata: &pixdata, FALSE, error: &error); |
51 | g_assert_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE); |
52 | g_clear_error (err: &error); |
53 | |
54 | g_clear_object (&pixbuf); |
55 | } |
56 | |
57 | static void |
58 | test_pixdata_success (void) |
59 | { |
60 | const gchar *path; |
61 | GdkPixbuf *pixbuf; |
62 | GdkPixdata pixdata1, pixdata2; |
63 | GError *error = NULL; |
64 | GdkPixbuf *ref; |
65 | gchar *contents; |
66 | gsize size; |
67 | |
68 | path = g_test_get_filename (file_type: G_TEST_DIST, first_path: "test-image.png" , NULL); |
69 | ref = gdk_pixbuf_new_from_file (filename: path, error: &error); |
70 | g_assert_no_error (error); |
71 | |
72 | g_file_get_contents (filename: g_test_get_filename (file_type: G_TEST_DIST, first_path: "test-image.pixdata" , NULL), contents: &contents, length: &size, error: &error); |
73 | g_assert_no_error (error); |
74 | gdk_pixdata_deserialize (pixdata: &pixdata1, stream_length: size, stream: (const guint8 *) contents, error: &error); |
75 | g_assert_no_error (error); |
76 | pixbuf = gdk_pixbuf_from_pixdata (pixdata: &pixdata1, FALSE, error: &error); |
77 | g_assert_no_error (error); |
78 | |
79 | pixdata_equal (test: ref, ref: pixbuf, error: &error); |
80 | g_assert_no_error (error); |
81 | g_free (mem: contents); |
82 | g_object_unref (object: pixbuf); |
83 | |
84 | g_file_get_contents (filename: g_test_get_filename (file_type: G_TEST_DIST, first_path: "test-image-rle.pixdata" , NULL), contents: &contents, length: &size, error: &error); |
85 | g_assert_no_error (error); |
86 | gdk_pixdata_deserialize (pixdata: &pixdata2, stream_length: size, stream: (const guint8 *) contents, error: &error); |
87 | g_assert_no_error (error); |
88 | pixbuf = gdk_pixbuf_from_pixdata (pixdata: &pixdata2, FALSE, error: &error); |
89 | g_assert_no_error (error); |
90 | |
91 | pixdata_equal (test: ref, ref: pixbuf, error: &error); |
92 | g_assert_no_error (error); |
93 | g_free (mem: contents); |
94 | g_object_unref (object: pixbuf); |
95 | g_object_unref (object: ref); |
96 | } |
97 | G_GNUC_END_IGNORE_DEPRECATIONS |
98 | |
99 | static void |
100 | test_pixdata (void) |
101 | { |
102 | const gchar *path; |
103 | GError *error = NULL; |
104 | GdkPixbuf *ref; |
105 | |
106 | ref = gdk_pixbuf_new_from_resource (resource_path: "/test/resource/icc-profile.pixdata" , error: &error); |
107 | g_assert_no_error (error); |
108 | g_object_unref (object: ref); |
109 | |
110 | ref = gdk_pixbuf_new_from_resource (resource_path: "/test/resource/icc-profile-compressed.pixdata" , error: &error); |
111 | g_assert_no_error (error); |
112 | g_object_unref (object: ref); |
113 | |
114 | path = g_test_get_filename (file_type: G_TEST_DIST, first_path: "test-image.pixdata" , NULL); |
115 | ref = gdk_pixbuf_new_from_file (filename: path, error: &error); |
116 | g_assert_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_UNKNOWN_TYPE); |
117 | g_clear_error (err: &error); |
118 | g_clear_object (&ref); |
119 | } |
120 | |
121 | int |
122 | main (int argc, char **argv) |
123 | { |
124 | g_test_init (argc: &argc, argv: &argv, NULL); |
125 | |
126 | g_test_add_func (testpath: "/pixbuf/pixdata" , test_func: test_pixdata); |
127 | g_test_add_func (testpath: "/pixbuf/pixdata/success" , test_func: test_pixdata_success); |
128 | g_test_add_data_func (testpath: "/pixbuf/pixdata/bug775693" , test_data: "bug775693.pixdata" , test_func: test_pixdata_deserialize); |
129 | g_test_add_data_func (testpath: "/pixbuf/pixdata/bug775229" , test_data: "bug775229.pixdata" , test_func: test_pixdata_deserialize); |
130 | |
131 | return g_test_run (); |
132 | } |
133 | |