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.
22 #include "gdk-pixbuf/gdk-pixbuf.h"
30 disaster (const char *what)
37 randomly_modify (const guchar *image, guint size)
41 guchar *img_copy = g_malloc (size);
42 g_memmove (img_copy, image, size);
44 for (i = 0; i < size / 4; i++)
47 GdkPixbufLoader *loader;
49 guint index = g_random_int_range (0, size);
50 guchar byte = g_random_int_range (0, 256);
52 img_copy[index] = byte;
53 f = fopen ("pixbuf-randomly-modified-image", "w");
56 fwrite (img_copy, size, 1, f);
61 loader = gdk_pixbuf_loader_new ();
62 gdk_pixbuf_loader_write (loader, img_copy, size, NULL);
63 gdk_pixbuf_loader_close (loader, NULL);
64 g_object_unref (loader);
73 /* write this so you can reproduce failed tests */
74 f = fopen ("pixbuf-randomly-modified-seed", "w");
79 if (fprintf (f, "%d\n", seed) < 0)
85 g_print ("seed: %d\n", seed);
91 g_print ("usage: pixbuf-randomly-modified [-s <seed>] <files> ... \n");
96 main (int argc, char **argv)
99 gboolean got_seed = FALSE;
100 GPtrArray *files = g_ptr_array_new ();
107 for (i = 1; i < argc; ++i)
109 if (strncmp (argv[i], "-s", 2) == 0)
111 if (strlen (argv[i]) > 2)
115 seed = atoi (argv[i+1]);
123 g_ptr_array_add (files, strdup (argv[i]));
129 g_random_set_seed (seed);
131 g_print ("the last tested image is saved to pixbuf-randomly-modified-image\n");
134 g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
137 for (i = 0; i < files->len; ++i)
144 if (!g_file_get_contents (files->pdata[i], &contents, &size, &err))
146 g_print ("%s: error: %s\n", (char *)files->pdata[i], err->message);
150 g_print ("%s\t\t", (char *)files->pdata[i]);
151 randomly_modify (contents, size);