Commit d269c210 authored by Soeren Sandmann's avatar Soeren Sandmann Committed by Søren Sandmann Pedersen

image files for testing pixbuf loaders the old test-loaders.c split into

Sun May  5 02:22:59 2002  Soeren Sandmann  <sandmann@daimi.au.dk>

	* tests/test-images/*: image files for testing pixbuf loaders
	* tests/pixbuf-*.c: the old test-loaders.c split into four
	different programs
	* tests/Makefile.am: add new pixbuf tests

Sun May  5 02:27:01 2002  Soeren Sandmann  <sandmann@daimi.au.dk>

	* Makefile.am (noinst_PROGRAMS): remove test-loaders (moved to
	gtk+/tests/)
	* test-loaders.c, test-images.h: remove
parent b2a75ec3
Sun May 5 02:22:59 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* tests/test-images/*: image files for testing pixbuf loaders
* tests/pixbuf-*.c: the old test-loaders.c split into four
different programs
* tests/Makefile.am: add new pixbuf tests
2002-05-03 Erwann Chenede - <erwann.chenede@sun.com>
* gdk/x11/gdkvisual-x11.c:
......
Sun May 5 02:22:59 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* tests/test-images/*: image files for testing pixbuf loaders
* tests/pixbuf-*.c: the old test-loaders.c split into four
different programs
* tests/Makefile.am: add new pixbuf tests
2002-05-03 Erwann Chenede - <erwann.chenede@sun.com>
* gdk/x11/gdkvisual-x11.c:
......
Sun May 5 02:22:59 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* tests/test-images/*: image files for testing pixbuf loaders
* tests/pixbuf-*.c: the old test-loaders.c split into four
different programs
* tests/Makefile.am: add new pixbuf tests
2002-05-03 Erwann Chenede - <erwann.chenede@sun.com>
* gdk/x11/gdkvisual-x11.c:
......
Sun May 5 02:22:59 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* tests/test-images/*: image files for testing pixbuf loaders
* tests/pixbuf-*.c: the old test-loaders.c split into four
different programs
* tests/Makefile.am: add new pixbuf tests
2002-05-03 Erwann Chenede - <erwann.chenede@sun.com>
* gdk/x11/gdkvisual-x11.c:
......
Sun May 5 02:22:59 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* tests/test-images/*: image files for testing pixbuf loaders
* tests/pixbuf-*.c: the old test-loaders.c split into four
different programs
* tests/Makefile.am: add new pixbuf tests
2002-05-03 Erwann Chenede - <erwann.chenede@sun.com>
* gdk/x11/gdkvisual-x11.c:
......
Sun May 5 02:22:59 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* tests/test-images/*: image files for testing pixbuf loaders
* tests/pixbuf-*.c: the old test-loaders.c split into four
different programs
* tests/Makefile.am: add new pixbuf tests
2002-05-03 Erwann Chenede - <erwann.chenede@sun.com>
* gdk/x11/gdkvisual-x11.c:
......
Sun May 5 02:27:01 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* Makefile.am (noinst_PROGRAMS): remove test-loaders (moved to
gtk+/tests/)
* test-loaders.c, test-images.h: remove
2002-04-24 Matthias Clasen <maclas@gmx.de>
* gdk-pixbuf-io.c (gdk_pixbuf_save): Remove the ISO8859-1
......
......@@ -229,10 +229,8 @@ INCLUDES = @STRIP_BEGIN@ \
AM_CPPFLAGS = "-DPIXBUF_LIBDIR=\"$(loaderdir)\"" "-DBUILT_MODULES_DIR=\"$(srcdir)/.libs\""
LDADDS = libgdk_pixbuf-$(GTK_API_VERSION).la
noinst_PROGRAMS = test-gdk-pixbuf test-loaders
noinst_PROGRAMS = test-gdk-pixbuf
test_gdk_pixbuf_LDADD = $(LDADDS)
test_loaders_LDADD = $(LDADDS)
test_loaders_SOURCES = test-loaders.c test-images.h
bin_PROGRAMS = gdk-pixbuf-csource
gdk_pixbuf_csource_SOURCES = gdk-pixbuf-csource.c
......
This diff is collapsed.
......@@ -24,27 +24,31 @@ testsocket_programs = testsocket testsocket_child
endif
noinst_PROGRAMS = \
simple \
testcalendar \
testdnd \
testgtk \
testinput \
testmultidisplay \
testmultiscreen \
testrgb \
testselection \
$(testsocket_programs) \
testtext \
testtextbuffer \
testtreeedit \
testtreeview \
testtreefocus \
testtreeflow \
testtreecolumns \
testtreesort \
treestoretest \
testxinerama
noinst_PROGRAMS = \
simple \
testcalendar \
testdnd \
testgtk \
testinput \
testmultidisplay \
testmultiscreen \
testrgb \
testselection \
$(testsocket_programs) \
testtext \
testtextbuffer \
testtreeedit \
testtreeview \
testtreefocus \
testtreeflow \
testtreecolumns \
testtreesort \
treestoretest \
testxinerama \
pixbuf-read \
pixbuf-lowmem \
pixbuf-randomly-modified \
pixbuf-random
simple_DEPENDENCIES = $(TEST_DEPS)
testcalendar_DEPENDENCIES = $(TEST_DEPS)
......@@ -89,6 +93,10 @@ testtreesort_LDADD = $(LDADDS)
testtext_LDADD = $(LDADDS)
treestoretest_LDADD = $(LDADDS)
testxinerama_LDADD = $(LDADDS)
pixbuf_read_LDADD = $(LDADDS)
pixbuf_lowmem_LDADD = $(LDADDS)
pixbuf_randomly_modified_LDADD = $(LDADDS)
pixbuf_random_LDADD = $(LDADDS)
testgtk_SOURCES = \
prop-editor.c \
......
......@@ -19,15 +19,14 @@
*/
#include <config.h>
#include "gdk-pixbuf.h"
#include "gdk-pixbuf/gdk-pixbuf.h"
#include <stdio.h>
#include <stdlib.h>
#include "test-images.h"
#include <time.h>
#include <string.h>
#define PRETEND_MEM_SIZE (16 * 1024 * 1024)
#define REMAINING_MEM_SIZE 5000
#define REMAINING_MEM_SIZE 100000
static int current_allocation = 0;
......@@ -133,36 +132,6 @@ static GMemVTable limited_table = {
limited_try_realloc
};
static gboolean
test_loader (const guchar *bytes, gsize len, gboolean data_is_ok)
{
GdkPixbufLoader *loader;
GError *err = NULL;
gboolean did_fail = FALSE;
loader = gdk_pixbuf_loader_new ();
gdk_pixbuf_loader_write (loader, bytes, len, &err);
if (err)
{
g_error_free (err);
err = NULL;
did_fail = TRUE;
}
gdk_pixbuf_loader_close (loader, &err);
if (err)
{
g_error_free (err);
err = NULL;
did_fail = TRUE;
}
g_object_unref (loader);
if (data_is_ok == did_fail)
return FALSE;
else
return TRUE;
}
static void
mem_test (const guchar *bytes, gsize len)
{
......@@ -196,130 +165,6 @@ mem_test (const guchar *bytes, gsize len)
g_list_free (loaders);
}
void
assault (const gchar *header, gsize header_size,
int n_images, gboolean verbose)
{
enum { N_CHARACTERS = 10000 };
int j;
for (j = 0; j < n_images; ++j)
{
GError *err = NULL;
int i;
GdkPixbufLoader *loader;
if (verbose)
g_print ("'img' no: %d\n", j);
loader = gdk_pixbuf_loader_new ();
gdk_pixbuf_loader_write (loader, header, header_size, &err);
if (err)
{
g_error_free (err);
continue;
}
for (i = 0; i < N_CHARACTERS; ++i)
{
int r = g_random_int ();
if (verbose)
{
int j;
for (j = 0; j < sizeof (r); j++)
g_print ("%u, ", ((guchar *)&r)[j]);
}
gdk_pixbuf_loader_write (loader, (guchar *)&r, sizeof (r), &err);
if (err)
{
g_error_free (err);
err = NULL;
break;
}
}
if (verbose)
g_print ("\n");
gdk_pixbuf_loader_close (loader, &err);
if (err)
{
g_error_free (err);
err = NULL;
}
g_object_unref (loader);
}
}
static void
randomly_modify (const guchar *image, guint size, gboolean verbose)
{
int i;
guchar *img_copy = g_malloc (size);
for (i = 0; i < size; i++)
img_copy [i] = image[i];
for (i = 0; i < size / 4; i++)
{
int j;
guint index = g_random_int_range (0, size);
guchar byte = g_random_int_range (0, 256);
img_copy[index] = byte;
if (verbose)
{
g_print ("img no %d\n", i);
for (j = 0; j < size; j++)
g_print ("%u, ", img_copy[j]);
g_print ("\n\n");
}
test_loader (img_copy, size, FALSE);
}
g_free (img_copy);
}
#define TEST(bytes, data_is_ok) \
do { \
g_print ("%-40s", " " #bytes " "); \
fflush (stdout); \
if (test_loader (bytes, sizeof (bytes), data_is_ok)) \
g_print ("\tpassed\n"); \
else \
g_print ("\tFAILED\n"); \
} while (0)
#define LOWMEMTEST(bytes) \
do { \
g_print ("%-40s", "memory " #bytes " "); \
fflush (stdout); \
mem_test (bytes, sizeof (bytes)); \
g_print ("\tpassed\n"); \
} while (0)
#define TEST_RANDOM(header, n_img, verbose) \
do { \
static guchar h[] = { header }; \
g_print ("%-40s", "random " #header " "); \
fflush (stdout); \
assault (h, sizeof (h), n_img, verbose); \
g_print ("\tpassed\n"); \
} while (0)
#define TEST_RANDOMLY_MODIFIED(image, verbose) \
do { \
g_print ("%-40s", "randomly modified " #image " "); \
fflush (stdout); \
randomly_modify (image, sizeof (image), verbose); \
g_print ("\tpassed\n"); \
} while (0)
static void
almost_exhaust_memory (void)
{
......@@ -330,129 +175,31 @@ almost_exhaust_memory (void)
}
static void
write_seed (int seed)
usage (void)
{
FILE *f;
/* write this so you can reproduce failed tests */
f = fopen ("test-loaders-seed", "w");
if (!f)
{
perror ("fopen");
exit (EXIT_FAILURE);
}
if (fprintf (f, "%d\n", seed) < 0)
{
perror ("fprintf");
exit (EXIT_FAILURE);
}
if (fclose (f) < 0)
{
perror ("fclose");
exit (EXIT_FAILURE);
}
g_print ("seed: %d\n", seed);
g_print ("usage: pixbuf-lowmem <pretend_memory_size> <files>\n");
exit (EXIT_FAILURE);
}
int
main (int argc, char **argv)
{
int seed;
int i;
char *endptr;
if (argc > 1)
seed = atoi (argv[1]);
else
{
seed = time (NULL);
write_seed (seed);
}
g_random_set_seed (seed);
if (argc <= 2)
usage();
max_allocation = strtol (argv[1], &endptr, 10);
if (endptr == argv[1])
usage();
/* Set a malloc which emulates low mem */
max_allocation = G_MAXINT;
g_mem_set_vtable (&limited_table);
g_type_init ();
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
putenv ("GDK_PIXBUF_MODULEDIR="BUILT_MODULES_DIR);
TEST (valid_ppm_1, TRUE);
TEST (valid_ppm_2, TRUE);
TEST (valid_ppm_3, FALSE); /* image is valid, but we don't handle maxval > 255 */
TEST (valid_ppm_4, TRUE);
TEST (invalid_ppm_1, FALSE); /* this test fails to fail, because it's shorter than LOADER_HEADER_SIZE */
TEST (invalid_ppm_2, FALSE);
TEST (invalid_ppm_3, FALSE);
TEST (invalid_ppm_4, FALSE);
TEST (invalid_ppm_5, FALSE);
TEST (invalid_ppm_6, FALSE);
TEST (invalid_ppm_7, FALSE);
TEST (invalid_ppm_8, FALSE);
TEST (valid_gif_test, TRUE);
TEST (gif_test_1, FALSE);
TEST (gif_test_2, FALSE);
TEST (gif_test_3, FALSE);
TEST (gif_test_4, FALSE);
TEST (valid_png_test, TRUE);
TEST (png_test_1, FALSE);
TEST (png_test_2, FALSE);
TEST (valid_ico_test, TRUE);
TEST (ico_test_1, FALSE);
TEST (ico_test_2, FALSE);
TEST (valid_jpeg_test, TRUE);
TEST (valid_tiff1_test, TRUE);
TEST (tiff1_test_1, FALSE);
TEST (tiff1_test_2, FALSE);
#if 0
TEST (tiff1_test_3, FALSE); /* Segfault in TIFFReadDirectory */
#endif
TEST (valid_tga_test, TRUE);
TEST (tga_test_1, FALSE);
TEST (xpm_test_1, FALSE);
TEST (wbmp_test_1, FALSE);
TEST (wbmp_test_2, FALSE);
TEST (invalid_bmp_1, FALSE);
TEST (valid_ras_test, TRUE);
TEST_RANDOM (GIF_HEADER, 150, FALSE);
TEST_RANDOM (PNG_HEADER, 1100, FALSE);
TEST_RANDOM (JPEG_HEADER, 800, FALSE);
TEST_RANDOM (TIFF1_HEADER, 150, FALSE);
TEST_RANDOM (TIFF2_HEADER, 150, FALSE);
#define PNM_HEADER 'P', '6'
TEST_RANDOM (PNM_HEADER, 150, FALSE);
#define XBM_HEADER '#', 'd', 'e', 'f', 'i', 'n', 'e', ' '
TEST_RANDOM (XBM_HEADER, 150, FALSE);
#define BMP_HEADER 'B', 'M'
TEST_RANDOM (BMP_HEADER, 150, FALSE);
#define XPM_HEADER '/', '*', ' ', 'X', 'P', 'M', ' ', '*', '/'
TEST_RANDOM (XPM_HEADER, 150, FALSE);
#define RAS_HEADER 0x59, 0xA6, 0x6A, 0x95
TEST_RANDOM (RAS_HEADER, 300, FALSE);
TEST_RANDOMLY_MODIFIED (valid_tiff1_test, FALSE);
TEST_RANDOMLY_MODIFIED (valid_gif_test, FALSE);
TEST_RANDOMLY_MODIFIED (valid_png_test, FALSE);
TEST_RANDOMLY_MODIFIED (valid_tga_test, FALSE);
TEST_RANDOMLY_MODIFIED (valid_jpeg_test, FALSE);
TEST_RANDOMLY_MODIFIED (valid_ico_test, FALSE);
TEST_RANDOMLY_MODIFIED (valid_bmp_test, FALSE);
TEST_RANDOMLY_MODIFIED (valid_xpm_test, FALSE);
TEST_RANDOMLY_MODIFIED (valid_ras_test, FALSE);
TEST_RANDOMLY_MODIFIED (valid_ppm_4, FALSE);
/* memory tests */
/* How do the loaders behave when memory is low?
......@@ -471,19 +218,32 @@ main (int argc, char **argv)
handler with an 'out of memory' message.
*/
max_allocation = PRETEND_MEM_SIZE;
almost_exhaust_memory ();
g_print ("Allocated %dK of %dK, %dK free during tests\n",
current_allocation / 1024, max_allocation / 1024,
(max_allocation - current_allocation) / 1024);
#if 0
LOWMEMTEST (valid_tiff1_test);
#endif
LOWMEMTEST (valid_gif_test);
LOWMEMTEST (valid_png_test);
LOWMEMTEST (valid_jpeg_test);
for (i = 2; i < argc; ++i)
{
gchar *contents;
gsize size;
GError *err = NULL;
if (!g_file_get_contents (argv[i], &contents, &size, &err))
{
g_print ("couldn't read %s: %s\n", argv[i], err->message);
exit (EXIT_FAILURE);
}
else
{
g_print ("%-40s memory ", argv[i]);
fflush (stdout);
mem_test (contents, size);
g_print ("\tpassed\n");
g_free (contents);
}
}
return 0;
}
/* -*- Mode: C; c-basic-offset: 2; -*- */
/* GdkPixbuf library - assault loaders with random data
*
* Copyright (C) 2001 Sren Sandmann (sandmann@daimi.au.dk)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include "gdk-pixbuf/gdk-pixbuf.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
static void
assault (const gchar *header, gsize header_size, int n_images)
{
FILE *f;
enum { N_CHARACTERS = 10000 };
int j;
for (j = 0; j < n_images; ++j)
{
GError *err = NULL;
int i;
GdkPixbufLoader *loader;
f = fopen ("pixbuf-random-image", "w");
if (!f)
{
perror ("fopen");
exit (EXIT_FAILURE);
}
loader = gdk_pixbuf_loader_new ();
gdk_pixbuf_loader_write (loader, header, header_size, &err);
if (err)
{
g_error_free (err);
continue;
}
for (i = 0; i < N_CHARACTERS; ++i)
{
int r = g_random_int ();
fwrite (&r, 1, sizeof (r), f);
if (ferror (f))
{
perror ("fwrite");
exit (EXIT_FAILURE);
}
gdk_pixbuf_loader_write (loader, (guchar *)&r, sizeof (r), &err);
if (err)
{
g_error_free (err);
err = NULL;
break;
}
}
fclose (f);
gdk_pixbuf_loader_close (loader, &err);
if (err)
{
g_error_free (err);
err = NULL;
}
g_object_unref (loader);
}
}
static void
write_seed (int seed)
{
FILE *f;
/* write this so you can reproduce failed tests */
f = fopen ("pixbuf-random-seed", "w");
if (!f)
{
perror ("fopen");
exit (EXIT_FAILURE);
}
if (fprintf (f, "%d\n", seed) < 0)
{
perror ("fprintf");
exit (EXIT_FAILURE);
}
if (fclose (f) < 0)
{
perror ("fclose");
exit (EXIT_FAILURE);
}
g_print ("seed: %d\n", seed);
}
int
main (int argc, char **argv)
{
int seed;
if (argc > 1)
seed = atoi (argv[1]);
else
{
seed = time (NULL);
write_seed (seed);
}
g_print ("the last tested image is saved to the file \"pixbuf-random-image\"\n\n");
g_type_init ();
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
g_random_set_seed (seed);
#define GIF_HEADER 'G', 'I', 'F', '8', '9', 'a'
#define PNG_HEADER 0x89, 'P', 'N', 'G', 0x0d, 0x0a, 0x1a, 0x0a
#define TIFF1_HEADER 'M', 'M', 0x00, 0x2a
#define TIFF2_HEADER 'I', 'I', 0x2a, 0x00
#define JPEG_HEADER 0xFF, 0xd8
#define PNM_HEADER 'P', '6'
#define XBM_HEADER '#', 'd', 'e', 'f', 'i', 'n', 'e', ' '
#define BMP_HEADER 'B', 'M'
#define XPM_HEADER '/', '*', ' ', 'X', 'P', 'M', ' ', '*', '/'
#define RAS_HEADER 0x59, 0xA6, 0x6A, 0x95
#define TEST_RANDOM(header, n_img) \
do { \
static guchar h[] = { header }; \
g_print (#header); \
fflush (stdout); \
assault (h, sizeof (h), n_img); \
g_print ("\t\tpassed\n"); \
} while (0)
for (;;)
{
TEST_RANDOM (GIF_HEADER, 150);
TEST_RANDOM (PNG_HEADER, 110);
TEST_RANDOM (JPEG_HEADER, 800);
TEST_RANDOM (TIFF1_HEADER, 150);
TEST_RANDOM (TIFF2_HEADER, 150);
TEST_RANDOM (PNM_HEADER, 150);
TEST_RANDOM (XBM_HEADER, 150);
TEST_RANDOM (BMP_HEADER, 150);
TEST_RANDOM (XPM_HEADER, 150);
TEST_RANDOM (RAS_HEADER, 300);
g_print ("===========================\n");
}
return 0;
}
/* -*- Mode: C; c-basic-offset: 2; -*- */
/* GdkPixbuf library - test loaders
*
* Copyright (C) 2001 Sren Sandmann (sandmann@daimi.au.dk)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include "gdk-pixbuf/gdk-pixbuf.h"
#include "glib.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
static void
disaster (const char *what)
{
perror (what);
exit (EXIT_FAILURE);
}
static void
randomly_modify (const guchar *image, guint size)
{
int i;
guchar *img_copy = g_malloc (size);
g_memmove (img_copy, image, size);
for (i = 0; i <