1 | /* -*- Mode: C; c-basic-offset: 2; -*- */ |
2 | /* GdkPixbuf library - test loaders |
3 | * |
4 | * Copyright (C) 2001 Søren Sandmann (sandmann@daimi.au.dk) |
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 | |
20 | #include "config.h" |
21 | #include "gdk-pixbuf/gdk-pixbuf.h" |
22 | #include <stdio.h> |
23 | #include <stdlib.h> |
24 | |
25 | static gboolean |
26 | test_loader (const guchar *bytes, gsize len, GError **err) |
27 | { |
28 | GdkPixbufLoader *loader; |
29 | |
30 | loader = gdk_pixbuf_loader_new (); |
31 | gdk_pixbuf_loader_write (loader, buf: bytes, count: len, error: err); |
32 | if (*err) |
33 | return FALSE; |
34 | |
35 | gdk_pixbuf_loader_close (loader, error: err); |
36 | if (*err) |
37 | return FALSE; |
38 | |
39 | return TRUE; |
40 | } |
41 | |
42 | static void |
43 | usage (void) |
44 | { |
45 | g_print (format: "usage: pixbuf-read <files>\n" ); |
46 | exit (EXIT_FAILURE); |
47 | } |
48 | |
49 | int |
50 | main (int argc, char **argv) |
51 | { |
52 | int i; |
53 | |
54 | g_log_set_always_fatal (fatal_mask: G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL); |
55 | |
56 | if (argc == 1) |
57 | usage(); |
58 | |
59 | for (i = 1; i < argc; ++i) |
60 | { |
61 | gchar *contents; |
62 | gsize size; |
63 | GError *err = NULL; |
64 | |
65 | g_print (format: "%s\t\t" , argv[i]); |
66 | fflush (stdout); |
67 | if (!g_file_get_contents (filename: argv[i], contents: &contents, length: &size, error: &err)) |
68 | { |
69 | fprintf (stderr, format: "%s: error: %s\n" , argv[i], err->message); |
70 | } |
71 | else |
72 | { |
73 | err = NULL; |
74 | |
75 | if (test_loader (bytes: (guchar *) contents, len: size, err: &err)) |
76 | g_print (format: "success\n" ); |
77 | else |
78 | g_print (format: "error: %s\n" , err->message); |
79 | |
80 | g_free (mem: contents); |
81 | } |
82 | } |
83 | |
84 | return 0; |
85 | } |
86 | |