gdk-pixbuf/test-loaders
- From: Matthias Clasen <maclas gmx de>
- To: Soeren Sandmann <sandmann daimi au dk>
- Cc: gtk-devel-list gnome org
- Subject: gdk-pixbuf/test-loaders
- Date: 18 Mar 2002 23:21:50 +0100
Hi,
I'd like to hear your opinion on the following larger changes to
test-loaders.c:
- unless argv[1] is a valid seed, make the random tests loop forever
- two new macros TEST_FILES and TEST_RANDOMLY_MODIFIED_FILES allow to
run tests on directories containing image files
- interpret argv[2] as directory containing valid files, argv[3] as
directory containing invalid files (you can use "-" or some other
non-integer as argv[1] if you want looping with directories)
What do you think about these changes? IMO it is a lot more convenient
to just dump test images in directories instead of having to convert
them to char arrays, add them to a header, and recompile.
Matthias
Index: test-loaders.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk-pixbuf/test-loaders.c,v
retrieving revision 1.13
diff -u -b -B -p -r1.13 test-loaders.c
--- test-loaders.c 13 Mar 2002 18:11:14 -0000 1.13
+++ test-loaders.c 18 Mar 2002 22:12:33 -0000
@@ -318,6 +319,73 @@ do { \
g_print ("\tpassed\n"); \
} while (0)
+static gboolean
+test_file (const gchar *filename, gboolean data_is_ok)
+{
+ GError *err = NULL;
+
+ gdk_pixbuf_new_from_file (filename, &err);
+
+ return data_is_ok == (err == NULL);
+}
+
+static void
+test_files(const gchar *path, gboolean data_is_ok, gboolean do_random, gboolean verbose)
+{
+ GDir *dir;
+ GError *err = NULL;
+ const gchar *name;
+ gchar *filename, *contents, *tmp;
+ gsize length;
+
+ dir = g_dir_open (path, 0, &err);
+ if (err)
+ return;
+ g_print("%s\n", path);
+ fflush (stdout);
+ while (NULL != (name = g_dir_read_name (dir))) {
+ filename = g_build_filename (path, name, NULL);
+ if (!g_file_get_contents (filename, &contents, &length, &err)) {
+ g_free (filename);
+ continue;
+ }
+ if (do_random) {
+ tmp = g_strconcat ("randomly modified ", name, " ", NULL);
+ g_print ("%-40s", tmp);
+ fflush (stdout);
+ g_free (tmp);
+
+ randomly_modify (contents, length, verbose);
+ g_print ("\tpassed\n");
+ } else {
+ tmp = g_strconcat ("simple ", name, " ", NULL);
+ g_print("%-40s", tmp);
+ fflush (stdout);
+ g_free (tmp);
+
+ if (test_file (filename, data_is_ok))
+ g_print ("\tpassed\n");
+ else
+ g_print ("\tFAILED\n");
+
+ tmp = g_strconcat ("incremental ", name, " ", NULL);
+ g_print("%-40s", tmp);
+ fflush (stdout);
+ g_free (tmp);
+
+ if (test_loader (contents, length, data_is_ok))
+ g_print ("\tpassed\n");
+ else
+ g_print ("\tFAILED\n");
+ }
+ g_free (contents);
+ g_free (filename);
+ }
+ g_dir_close (dir);
+}
+
+#define TEST_FILES(path, data_is_ok) test_files (path, data_is_ok, FALSE, FALSE)
+#define TEST_RANDOMLY_MODIFIED_FILES(path, verbose) test_files (path, FALSE, TRUE, verbose)
static void
@@ -356,16 +424,8 @@ write_seed (int seed)
int
main (int argc, char **argv)
{
- int seed;
-
- if (argc > 1)
- seed = atoi (argv[1]);
- else
- {
- seed = time (NULL);
- write_seed (seed);
- }
- g_random_set_seed (seed);
+ int seed, i;
+ gboolean cycle = FALSE;
/* Set a malloc which emulates low mem */
max_allocation = G_MAXINT;
@@ -410,11 +470,12 @@ main (int argc, char **argv)
TEST (valid_tiff1_test, TRUE);
TEST (tiff1_test_1, FALSE);
TEST (tiff1_test_2, FALSE);
-#if 0
+#if 1
TEST (tiff1_test_3, FALSE); /* Segfault in TIFFReadDirectory */
#endif
TEST (valid_tga_test, TRUE);
+ TEST (valid_tga_2, TRUE);
TEST (tga_test_1, FALSE);
TEST (xpm_test_1, FALSE);
@@ -426,6 +487,31 @@ main (int argc, char **argv)
TEST (valid_ras_test, TRUE);
+ if (argc > 3) {
+ TEST_FILES (argv[3], FALSE);
+ }
+
+ if (argc > 2) {
+ TEST_FILES (argv[2], TRUE);
+ }
+
+ if (argc > 1)
+ {
+ gchar *err;
+ seed = strtol (argv[1], &err, 10);
+ cycle = (*err != '\0');
+ }
+ else
+ {
+ cycle = TRUE;
+ seed = time (NULL);
+ }
+
+ do {
+
+ write_seed (seed);
+ g_random_set_seed (seed);
+
TEST_RANDOM (GIF_HEADER, 150, FALSE);
TEST_RANDOM (PNG_HEADER, 1100, FALSE);
TEST_RANDOM (JPEG_HEADER, 800, FALSE);
@@ -446,6 +532,7 @@ main (int argc, char **argv)
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_tga_2, FALSE);
TEST_RANDOMLY_MODIFIED (valid_jpeg_test, FALSE);
TEST_RANDOMLY_MODIFIED (valid_ico_test, FALSE);
TEST_RANDOMLY_MODIFIED (valid_bmp_test, FALSE);
@@ -453,6 +540,14 @@ main (int argc, char **argv)
TEST_RANDOMLY_MODIFIED (valid_ras_test, FALSE);
TEST_RANDOMLY_MODIFIED (valid_ppm_4, FALSE);
+ for (i = 2; i < argc; i++) {
+ TEST_RANDOMLY_MODIFIED_FILES (argv[i], FALSE);
+ }
+
+ seed = g_random_int ();
+
+ } while (cycle);
+
/* memory tests */
/* How do the loaders behave when memory is low?
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]