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 "test-common.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
30static gboolean
31pixbuf_equal (GdkPixbuf *p1, GdkPixbuf *p2)
32{
33 if (!pixdata_equal (test: p1, ref: p2, NULL))
34 return FALSE;
35 if (compare_option (p1, p2, "Title") != 0)
36 return FALSE;
37 if (compare_option (p1, p2, "Artist") != 0)
38 return FALSE;
39 if (compare_option (p1, p2, "x_hot") != 0)
40 return FALSE;
41 if (compare_option (p1, p2, "y_hot") != 0)
42 return FALSE;
43 if (compare_option (p1, p2, "orientation") != 0)
44 return FALSE;
45 if (compare_option (p1, p2, "icc-profile") != 0)
46 return FALSE;
47
48 return TRUE;
49}
50
51static void
52test_resource (void)
53{
54 const gchar *path;
55 GError *error = NULL;
56 GdkPixbuf *pixbuf, *ref;
57
58 if (!format_supported (filename: "png"))
59 {
60 g_test_skip (msg: "format not supported");
61 return;
62 }
63
64 path = g_test_get_filename (file_type: G_TEST_DIST, first_path: "icc-profile.png", NULL);
65 ref = gdk_pixbuf_new_from_file (filename: path, error: &error);
66 g_assert_no_error (error);
67
68 pixbuf = gdk_pixbuf_new_from_resource (resource_path: "/test/resource/icc-profile.png", error: &error);
69 g_assert_no_error (error);
70 g_assert (pixbuf_equal (pixbuf, ref));
71 g_object_unref (object: pixbuf);
72
73 pixbuf = gdk_pixbuf_new_from_resource (resource_path: "/test/resource/icc-profile.pixdata", error: &error);
74 g_assert_no_error (error);
75 g_assert (pixdata_equal (pixbuf, ref, NULL));
76 g_object_unref (object: pixbuf);
77
78 pixbuf = gdk_pixbuf_new_from_resource (resource_path: "/no/such/resource", error: &error);
79 g_assert (pixbuf == NULL);
80 g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
81 g_clear_error (err: &error);
82
83 pixbuf = gdk_pixbuf_new_from_resource (resource_path: "resource:///test/resource/icc-profile.png", error: &error);
84 g_assert (pixbuf == NULL);
85 g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
86 g_clear_error (err: &error);
87
88 g_object_unref (object: ref);
89}
90
91static void
92test_resource_at_scale (void)
93{
94 const gchar *path;
95 GError *error = NULL;
96 GdkPixbuf *pixbuf, *ref;
97
98 if (!format_supported (filename: "png"))
99 {
100 g_test_skip (msg: "format not supported");
101 return;
102 }
103
104 path = g_test_get_filename (file_type: G_TEST_DIST, first_path: "icc-profile.png", NULL);
105 ref = gdk_pixbuf_new_from_file_at_scale (filename: path, width: 40, height: 10, FALSE, error: &error);
106 g_assert_no_error (error);
107
108 pixbuf = gdk_pixbuf_new_from_resource_at_scale (resource_path: "/test/resource/icc-profile.png", width: 40, height: 10, FALSE, error: &error);
109 g_assert_no_error (error);
110 g_assert (pixbuf_equal (pixbuf, ref));
111 g_object_unref (object: pixbuf);
112
113 g_object_unref (object: ref);
114}
115
116int
117main (int argc, char **argv)
118{
119 g_test_init (argc: &argc, argv: &argv, NULL);
120
121 g_test_add_func (testpath: "/pixbuf/resource", test_func: test_resource);
122 g_test_add_func (testpath: "/pixbuf/resource/at-scale", test_func: test_resource_at_scale);
123
124 return g_test_run ();
125}
126

source code of gtk/subprojects/gdk-pixbuf/tests/pixbuf-resource.c