]> Pileus Git - ~andy/gtk/blob - tests/pixbuf-read.c
image files for testing pixbuf loaders the old test-loaders.c split into
[~andy/gtk] / tests / pixbuf-read.c
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, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #include <config.h>
22 #include "gdk-pixbuf/gdk-pixbuf.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25
26 static gboolean
27 test_loader (const guchar *bytes, gsize len, GError **err)
28 {
29   GdkPixbufLoader *loader;
30
31   loader = gdk_pixbuf_loader_new ();
32   gdk_pixbuf_loader_write (loader, bytes, len, err);
33   if (*err)
34       return FALSE;
35   
36   gdk_pixbuf_loader_close (loader, err);
37   if (*err)
38     return FALSE;
39
40   return TRUE;
41 }
42
43 static void
44 usage (void)
45 {
46   g_print ("usage: pixbuf-read <files>\n");
47   exit (EXIT_FAILURE);
48 }
49   
50 int
51 main (int argc, char **argv)
52 {
53   int i;
54   
55   g_type_init ();
56   g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
57
58   if (argc == 1)
59     usage();
60   
61   for (i = 1; i < argc; ++i)
62     {
63       gchar *contents;
64       gsize size;
65       GError *err = NULL;
66       
67       g_print ("%s\t\t", argv[i]);
68       fflush (stdout);
69       if (!g_file_get_contents (argv[i], &contents, &size, &err))
70         {
71           fprintf (stderr, "%s: error: %s\n", argv[i], err->message);
72         }
73       else
74         {
75           err = NULL;
76
77           if (test_loader (contents, size, &err))
78             g_print ("success\n");
79           else
80             g_print ("error: %s\n", err->message);
81
82           g_free (contents);
83         }
84     }
85   
86   return 0;
87 }