1
/* -*- Mode: C; c-basic-offset: 2; -*- */
2
/* GdkPixbuf library - test loaders
4
* Copyright (C) 2013 Red Hat, Inc.
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.
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.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20
* Author: Matthias Clasen
24
#include "gdk-pixbuf/gdk-pixbuf.h"
27
#define compare_option(p1, p2, key) \
28
g_strcmp0 (gdk_pixbuf_get_option (p1, key), gdk_pixbuf_get_option (p2, key))
31
pixbuf_equal (GdkPixbuf *p1, GdkPixbuf *p2)
33
if (gdk_pixbuf_get_colorspace (p1) != gdk_pixbuf_get_colorspace (p2))
35
if (gdk_pixbuf_get_n_channels (p1) != gdk_pixbuf_get_n_channels (p2))
37
if (gdk_pixbuf_get_bits_per_sample (p1) != gdk_pixbuf_get_bits_per_sample (p2))
39
if (gdk_pixbuf_get_width (p1) != gdk_pixbuf_get_width (p2))
41
if (gdk_pixbuf_get_height (p1) != gdk_pixbuf_get_height (p2))
43
if (gdk_pixbuf_get_rowstride (p1) != gdk_pixbuf_get_rowstride (p2))
45
if (memcmp (gdk_pixbuf_get_pixels (p1), gdk_pixbuf_get_pixels (p2),
46
gdk_pixbuf_get_byte_length (p1)) != 0)
48
if (compare_option (p1, p2, "Title") != 0)
50
if (compare_option (p1, p2, "Artist") != 0)
52
if (compare_option (p1, p2, "x_hot") != 0)
54
if (compare_option (p1, p2, "y_hot") != 0)
56
if (compare_option (p1, p2, "orientation") != 0)
58
if (compare_option (p1, p2, "icc-profile") != 0)
65
test_stream (gconstpointer data)
67
const gchar *filename = data;
70
GdkPixbuf *pixbuf, *ref;
74
path = g_test_get_filename (G_TEST_DIST, filename, NULL);
75
ref = gdk_pixbuf_new_from_file (path, &error);
76
g_assert_no_error (error);
78
file = g_file_new_for_path (path);
79
stream = (GInputStream *)g_file_read (file, NULL, &error);
80
g_assert_no_error (error);
82
pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, &error);
83
g_assert_no_error (error);
84
g_assert (pixbuf_equal (pixbuf, ref));
85
g_object_unref (pixbuf);
87
g_object_unref (stream);
88
g_object_unref (file);
93
async_done_cb (GObject *source, GAsyncResult *res, gpointer data)
95
GdkPixbuf *ref = data;
99
pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error);
100
g_assert_no_error (error);
102
g_assert (pixbuf_equal (pixbuf, ref));
104
g_object_unref (pixbuf);
105
g_object_unref (ref);
109
test_stream_async (gconstpointer data)
111
const gchar *filename = data;
113
GError *error = NULL;
117
GInputStream *stream;
119
path = g_test_get_filename (G_TEST_DIST, filename, NULL);
120
ref = gdk_pixbuf_new_from_file (path, &error);
121
g_assert_no_error (error);
123
g_file_get_contents (path, &buffer, &size, &error);
124
g_assert_no_error (error);
126
stream = g_memory_input_stream_new_from_data (buffer, size, g_free);
127
gdk_pixbuf_new_from_stream_async (stream, NULL, async_done_cb, ref);
128
g_object_unref (stream);
132
test_stream_at_scale (gconstpointer data)
134
const gchar *filename = data;
136
GError *error = NULL;
137
GdkPixbuf *pixbuf, *ref;
139
GInputStream *stream;
141
path = g_test_get_filename (G_TEST_DIST, filename, NULL);
142
ref = gdk_pixbuf_new_from_file_at_scale (path, 20, 30, TRUE, &error);
143
g_assert_no_error (error);
145
file = g_file_new_for_path (path);
146
stream = (GInputStream *)g_file_read (file, NULL, &error);
147
g_assert_no_error (error);
149
pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream, 20, 30, TRUE, NULL, &error);
150
g_assert_no_error (error);
151
g_assert (pixbuf_equal (pixbuf, ref));
152
g_object_unref (pixbuf);
154
g_object_unref (stream);
155
g_object_unref (file);
156
g_object_unref (ref);
160
test_stream_at_scale_async (gconstpointer data)
162
const gchar *filename = data;
164
GError *error = NULL;
168
GInputStream *stream;
170
path = g_test_get_filename (G_TEST_DIST, filename, NULL);
171
ref = gdk_pixbuf_new_from_file_at_scale (path, 40, 10, FALSE, &error);
172
g_assert_no_error (error);
174
g_file_get_contents (path, &buffer, &size, &error);
175
g_assert_no_error (error);
177
stream = g_memory_input_stream_new_from_data (buffer, size, g_free);
178
gdk_pixbuf_new_from_stream_at_scale_async (stream, 40, 10, FALSE, NULL, async_done_cb, ref);
179
g_object_unref (stream);
183
main (int argc, char **argv)
185
g_test_init (&argc, &argv, NULL);
187
g_test_add_data_func ("/pixbuf/stream", "icc-profile.png", test_stream);
188
g_test_add_data_func ("/pixbuf/stream/async", "icc-profile.png", test_stream_async);
189
g_test_add_data_func ("/pixbuf/stream/scale", "icc-profile.png", test_stream_at_scale);
190
g_test_add_data_func ("/pixbuf/stream/scale/async", "icc-profile.png", test_stream_at_scale_async);
192
return g_test_run ();