1/* -*- Mode: C; c-basic-offset: 2; -*- */
2/* GdkPixbuf library - test loaders
3 *
4 * Copyright (C) 2014 Canonical Ltd.
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: Robert Ancell
20 */
21
22#include <string.h>
23
24#include "config.h"
25#include "gdk-pixbuf/gdk-pixbuf.h"
26#include "test-common.h"
27
28static void
29test_incremental (gconstpointer data)
30{
31 const gchar *filename = data;
32 GdkPixbufLoader *loader;
33 GdkPixbuf *pixbuf;
34 GError *error = NULL;
35 const gchar *x_dpi, *y_dpi;
36 gchar *contents;
37 gsize size;
38
39 if (!format_supported (filename))
40 {
41 g_test_skip (msg: "format not supported");
42 return;
43 }
44
45 g_file_get_contents (filename: g_test_get_filename (file_type: G_TEST_DIST, first_path: filename, NULL), contents: &contents, length: &size, error: &error);
46 g_assert_no_error (error);
47
48 loader = gdk_pixbuf_loader_new ();
49
50 gdk_pixbuf_loader_write (loader, buf: (const guchar*)contents, count: size, error: &error);
51 g_assert_no_error (error);
52
53 gdk_pixbuf_loader_close (loader, error: &error);
54 g_assert_no_error (error);
55
56 pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
57 g_assert_nonnull (pixbuf);
58 x_dpi = gdk_pixbuf_get_option (pixbuf, key: "x-dpi");
59 y_dpi = gdk_pixbuf_get_option (pixbuf, key: "y-dpi");
60 g_assert_nonnull (x_dpi);
61 g_assert_nonnull (y_dpi);
62 g_assert_cmpstr (x_dpi, ==, "300");
63 g_assert_cmpstr (y_dpi, ==, "600");
64
65 g_object_unref (object: loader);
66 g_free (mem: contents);
67}
68
69static void
70test_nonincremental (gconstpointer data)
71{
72 const gchar *filename = data;
73 GError *error = NULL;
74 GdkPixbuf *pixbuf;
75 const gchar *x_dpi, *y_dpi;
76
77 if (!format_supported (filename))
78 {
79 g_test_skip (msg: "format not supported");
80 return;
81 }
82
83 pixbuf = gdk_pixbuf_new_from_file (filename: g_test_get_filename (file_type: G_TEST_DIST, first_path: filename, NULL), error: &error);
84 g_assert_no_error (error);
85
86 x_dpi = gdk_pixbuf_get_option (pixbuf, key: "x-dpi");
87 y_dpi = gdk_pixbuf_get_option (pixbuf, key: "y-dpi");
88 g_assert_nonnull (x_dpi);
89 g_assert_nonnull (y_dpi);
90 g_assert_cmpstr (x_dpi, ==, "300");
91 g_assert_cmpstr (y_dpi, ==, "600");
92
93 g_object_unref (object: pixbuf);
94}
95
96int
97main (int argc, char **argv)
98{
99 g_test_init (argc: &argc, argv: &argv, NULL);
100
101 g_test_add_data_func (testpath: "/pixbuf/dpi/png", test_data: "dpi.png", test_func: test_nonincremental);
102 g_test_add_data_func (testpath: "/pixbuf/dpi/png-incremental", test_data: "dpi.png", test_func: test_incremental);
103 g_test_add_data_func (testpath: "/pixbuf/dpi/jpeg", test_data: "dpi.jpeg", test_func: test_nonincremental);
104 g_test_add_data_func (testpath: "/pixbuf/dpi/jpeg-incremental", test_data: "dpi.jpeg", test_func: test_incremental);
105 g_test_add_data_func (testpath: "/pixbuf/dpi/tiff", test_data: "dpi.tiff", test_func: test_nonincremental);
106 g_test_add_data_func (testpath: "/pixbuf/dpi/tiff-incremental", test_data: "dpi.tiff", test_func: test_incremental);
107
108 return g_test_run ();
109}
110

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