1 /* -*- Mode: C; c-basic-offset: 2; -*- */
2 /* GdkPixbuf library - assault loaders with random data
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"
29 assault (const gchar *header, gsize header_size, int n_images)
32 enum { N_CHARACTERS = 10000 };
36 for (j = 0; j < n_images; ++j)
40 GdkPixbufLoader *loader;
42 f = fopen ("pixbuf-random-image", "w");
49 loader = gdk_pixbuf_loader_new ();
51 gdk_pixbuf_loader_write (loader, header, header_size, &err);
58 for (i = 0; i < N_CHARACTERS; ++i)
60 int r = g_random_int ();
62 fwrite (&r, 1, sizeof (r), f);
69 gdk_pixbuf_loader_write (loader, (guchar *)&r, sizeof (r), &err);
80 gdk_pixbuf_loader_close (loader, &err);
87 g_object_unref (loader);
95 /* write this so you can reproduce failed tests */
96 f = fopen ("pixbuf-random-seed", "w");
102 if (fprintf (f, "%d\n", seed) < 0)
112 g_print ("seed: %d\n", seed);
116 main (int argc, char **argv)
121 seed = atoi (argv[1]);
127 g_print ("the last tested image is saved to the file \"pixbuf-random-image\"\n\n");
130 g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
132 g_random_set_seed (seed);
134 #define GIF_HEADER 'G', 'I', 'F', '8', '9', 'a'
135 #define PNG_HEADER 0x89, 'P', 'N', 'G', 0x0d, 0x0a, 0x1a, 0x0a
136 #define TIFF1_HEADER 'M', 'M', 0x00, 0x2a
137 #define TIFF2_HEADER 'I', 'I', 0x2a, 0x00
138 #define JPEG_HEADER 0xFF, 0xd8
139 #define PNM_HEADER 'P', '6'
140 #define XBM_HEADER '#', 'd', 'e', 'f', 'i', 'n', 'e', ' '
141 #define BMP_HEADER 'B', 'M'
142 #define XPM_HEADER '/', '*', ' ', 'X', 'P', 'M', ' ', '*', '/'
143 #define RAS_HEADER 0x59, 0xA6, 0x6A, 0x95
145 #define TEST_RANDOM(header, n_img) \
147 static guchar h[] = { header }; \
150 assault (h, sizeof (h), n_img); \
151 g_print ("\t\tpassed\n"); \
156 TEST_RANDOM (GIF_HEADER, 150);
157 TEST_RANDOM (PNG_HEADER, 110);
158 TEST_RANDOM (JPEG_HEADER, 800);
159 TEST_RANDOM (TIFF1_HEADER, 150);
160 TEST_RANDOM (TIFF2_HEADER, 150);
161 TEST_RANDOM (PNM_HEADER, 150);
162 TEST_RANDOM (XBM_HEADER, 150);
163 TEST_RANDOM (BMP_HEADER, 150);
164 TEST_RANDOM (XPM_HEADER, 150);
165 TEST_RANDOM (RAS_HEADER, 300);
166 g_print ("===========================\n");