Add powerbox hook
[gtk-with-powerbox.git] / tests / pixbuf-read.c
bloba65af3f61b8de0596f38f5afbdbb7420f6444680
1 /* -*- Mode: C; c-basic-offset: 2; -*- */
2 /* GdkPixbuf library - test loaders
4 * Copyright (C) 2001 Søren Sandmann (sandmann@daimi.au.dk)
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.
21 #include "config.h"
22 #include "gdk-pixbuf/gdk-pixbuf.h"
23 #include <stdio.h>
24 #include <stdlib.h>
26 static gboolean
27 test_loader (const guchar *bytes, gsize len, GError **err)
29 GdkPixbufLoader *loader;
31 loader = gdk_pixbuf_loader_new ();
32 gdk_pixbuf_loader_write (loader, bytes, len, err);
33 if (*err)
34 return FALSE;
36 gdk_pixbuf_loader_close (loader, err);
37 if (*err)
38 return FALSE;
40 return TRUE;
43 static void
44 usage (void)
46 g_print ("usage: pixbuf-read <files>\n");
47 exit (EXIT_FAILURE);
50 int
51 main (int argc, char **argv)
53 int i;
55 g_type_init ();
56 g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
58 if (argc == 1)
59 usage();
61 for (i = 1; i < argc; ++i)
63 gchar *contents;
64 gsize size;
65 GError *err = NULL;
67 g_print ("%s\t\t", argv[i]);
68 fflush (stdout);
69 if (!g_file_get_contents (argv[i], &contents, &size, &err))
71 fprintf (stderr, "%s: error: %s\n", argv[i], err->message);
73 else
75 err = NULL;
77 if (test_loader ((guchar *) contents, size, &err))
78 g_print ("success\n");
79 else
80 g_print ("error: %s\n", err->message);
82 g_free (contents);
86 return 0;