~ubuntu-branches/ubuntu/utopic/gdk-pixbuf/utopic

« back to all changes in this revision

Viewing changes to tests/pixbuf-stream.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2014-01-15 10:41:02 UTC
  • mfrom: (1.5.8)
  • Revision ID: package-import@ubuntu.com-20140115104102-fzml65xmzuyjr2dj
Tags: 2.30.3-0ubuntu1
* New upstream release:
  - Expand the test suite
  - Enable coverage testing with --enable-coverage
  - Unify sniff buffer sizes across loaders: 4k everywhere
  - Port to GTask
  - xpm: Fix scaling
  - xpm: Update colors from pango
  - qtif: fix fread() error check
* debian/control:
  - Bump build-depends on libglib2.0-dev
  - Add build-depends on gawk
* debian/patches/fix-xpm-scaling.patch:
  - Applied upstream
* debian/patches/0001-Fix-test-failure-if-PNG_iTXt_SUPPORTED-not-defined.patch:
  - Fix test failing due to how our libpng is compiled

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 
19
 *
 
20
 * Author: Matthias Clasen
 
21
 */
 
22
 
 
23
#include "config.h"
 
24
#include "gdk-pixbuf/gdk-pixbuf.h"
 
25
#include <string.h>
 
26
 
 
27
#define compare_option(p1, p2, key) \
 
28
  g_strcmp0 (gdk_pixbuf_get_option (p1, key), gdk_pixbuf_get_option (p2, key))
 
29
 
 
30
static gboolean
 
31
pixbuf_equal (GdkPixbuf *p1, GdkPixbuf *p2)
 
32
{
 
33
  if (gdk_pixbuf_get_colorspace (p1) != gdk_pixbuf_get_colorspace (p2))
 
34
    return FALSE;
 
35
  if (gdk_pixbuf_get_n_channels (p1) != gdk_pixbuf_get_n_channels (p2))
 
36
    return FALSE;
 
37
  if (gdk_pixbuf_get_bits_per_sample (p1) != gdk_pixbuf_get_bits_per_sample (p2))
 
38
    return FALSE;
 
39
  if (gdk_pixbuf_get_width (p1) != gdk_pixbuf_get_width (p2))
 
40
    return FALSE;
 
41
  if (gdk_pixbuf_get_height (p1) != gdk_pixbuf_get_height (p2))
 
42
    return FALSE;
 
43
  if (gdk_pixbuf_get_rowstride (p1) != gdk_pixbuf_get_rowstride (p2))
 
44
    return FALSE;
 
45
  if (memcmp (gdk_pixbuf_get_pixels (p1), gdk_pixbuf_get_pixels (p2),
 
46
          gdk_pixbuf_get_byte_length (p1)) != 0)
 
47
    return FALSE;
 
48
  if (compare_option (p1, p2, "Title") != 0)
 
49
    return FALSE;
 
50
  if (compare_option (p1, p2, "Artist") != 0)
 
51
    return FALSE;
 
52
  if (compare_option (p1, p2, "x_hot") != 0)
 
53
    return FALSE;
 
54
  if (compare_option (p1, p2, "y_hot") != 0)
 
55
    return FALSE;
 
56
  if (compare_option (p1, p2, "orientation") != 0)
 
57
    return FALSE;
 
58
  if (compare_option (p1, p2, "icc-profile") != 0)
 
59
    return FALSE;
 
60
 
 
61
  return TRUE;
 
62
}
 
63
 
 
64
static void
 
65
test_stream (gconstpointer data)
 
66
{
 
67
  const gchar *filename = data;
 
68
  const gchar *path;
 
69
  GError *error = NULL;
 
70
  GdkPixbuf *pixbuf, *ref;
 
71
  GFile *file;
 
72
  GInputStream *stream;
 
73
 
 
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);
 
77
 
 
78
  file = g_file_new_for_path (path);
 
79
  stream = (GInputStream *)g_file_read (file, NULL, &error);
 
80
  g_assert_no_error (error);
 
81
 
 
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);
 
86
  
 
87
  g_object_unref (stream);
 
88
  g_object_unref (file);
 
89
  g_object_unref (ref);
 
90
}
 
91
 
 
92
static void
 
93
async_done_cb (GObject *source, GAsyncResult *res, gpointer data)
 
94
{
 
95
  GdkPixbuf *ref = data;
 
96
  GdkPixbuf *pixbuf;
 
97
  GError *error = NULL;
 
98
 
 
99
  pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error);
 
100
  g_assert_no_error (error);
 
101
 
 
102
  g_assert (pixbuf_equal (pixbuf, ref));
 
103
 
 
104
  g_object_unref (pixbuf);
 
105
  g_object_unref (ref);
 
106
}
 
107
 
 
108
static void
 
109
test_stream_async (gconstpointer data)
 
110
{
 
111
  const gchar *filename = data;
 
112
  const gchar *path;
 
113
  GError *error = NULL;
 
114
  GdkPixbuf *ref;
 
115
  gchar *buffer;
 
116
  gsize size;
 
117
  GInputStream *stream;
 
118
 
 
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);
 
122
 
 
123
  g_file_get_contents (path, &buffer, &size, &error);
 
124
  g_assert_no_error (error);
 
125
 
 
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);
 
129
}
 
130
 
 
131
static void
 
132
test_stream_at_scale (gconstpointer data)
 
133
{
 
134
  const gchar *filename = data;
 
135
  const gchar *path;
 
136
  GError *error = NULL;
 
137
  GdkPixbuf *pixbuf, *ref;
 
138
  GFile *file;
 
139
  GInputStream *stream;
 
140
 
 
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);
 
144
 
 
145
  file = g_file_new_for_path (path);
 
146
  stream = (GInputStream *)g_file_read (file, NULL, &error);
 
147
  g_assert_no_error (error);
 
148
 
 
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);
 
153
  
 
154
  g_object_unref (stream);
 
155
  g_object_unref (file);
 
156
  g_object_unref (ref);
 
157
}
 
158
 
 
159
static void
 
160
test_stream_at_scale_async (gconstpointer data)
 
161
{
 
162
  const gchar *filename = data;
 
163
  const gchar *path;
 
164
  GError *error = NULL;
 
165
  GdkPixbuf *ref;
 
166
  gchar *buffer;
 
167
  gsize size;
 
168
  GInputStream *stream;
 
169
 
 
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);
 
173
 
 
174
  g_file_get_contents (path, &buffer, &size, &error);
 
175
  g_assert_no_error (error);
 
176
 
 
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);
 
180
}
 
181
 
 
182
int
 
183
main (int argc, char **argv)
 
184
{
 
185
  g_test_init (&argc, &argv, NULL);
 
186
 
 
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);
 
191
 
 
192
  return g_test_run ();
 
193
}