tests: Make css-parser test take files as argument

Takes the css files to be tested as argument and runs with it.
This commit is contained in:
Benjamin Otte 2011-04-10 01:53:43 +02:00
parent 1f4b09b2fb
commit 796d593cc1

View File

@ -225,15 +225,57 @@ test_css_file (GFile *file)
g_free (css_file); g_free (css_file);
} }
static void
add_test_for_file (GFile *file)
{
g_test_add_vtable (g_file_get_path (file),
0,
g_object_ref (file),
NULL,
(GTestFixtureFunc) test_css_file,
(GTestFixtureFunc) g_object_unref);
}
static void
add_tests_for_files_in_directory (GFile *dir)
{
GFileEnumerator *enumerator;
GFileInfo *info;
GError *error = NULL;
enumerator = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &error);
g_assert_no_error (error);
while ((info = g_file_enumerator_next_file (enumerator, NULL, &error)))
{
GFile *file;
const char *filename;
filename = g_file_info_get_name (info);
if (!g_str_has_suffix (filename, ".css") ||
g_str_has_suffix (filename, ".out.css") ||
g_str_has_suffix (filename, ".ref.css"))
{
g_object_unref (info);
continue;
}
file = g_file_get_child (dir, filename);
add_test_for_file (file);
g_object_unref (file);
g_object_unref (info);
}
g_assert_no_error (error);
g_object_unref (enumerator);
}
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
const char *basedir;
GError *error = NULL;
GFile *dir;
GFileEnumerator *enumerator;
GFileInfo *info;
gtk_test_init (&argc, &argv); gtk_test_init (&argc, &argv);
/* Add a bunch of properties so we can test that we parse them properly */ /* Add a bunch of properties so we can test that we parse them properly */
@ -327,44 +369,35 @@ main (int argc, char **argv)
GTK_STATE_FLAG_NORMAL, GTK_STATE_FLAG_NORMAL,
G_PARAM_READABLE)); G_PARAM_READABLE));
if (g_getenv ("srcdir")) if (argc < 2)
basedir = g_getenv ("srcdir");
else
basedir = ".";
dir = g_file_new_for_path (basedir);
enumerator = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &error);
g_assert_no_error (error);
while ((info = g_file_enumerator_next_file (enumerator, NULL, &error)))
{ {
GFile *file; const char *basedir;
const char *filename; GFile *dir;
filename = g_file_info_get_name (info); if (g_getenv ("srcdir"))
basedir = g_getenv ("srcdir");
else
basedir = ".";
if (!g_str_has_suffix (filename, ".css") || dir = g_file_new_for_path (basedir);
g_str_has_suffix (filename, ".out.css") ||
g_str_has_suffix (filename, ".ref.css"))
{
g_object_unref (info);
continue;
}
file = g_file_get_child (dir, filename); add_tests_for_files_in_directory (dir);
g_test_add_vtable (g_file_get_path (file), g_object_unref (dir);
0,
file,
NULL,
(GTestFixtureFunc) test_css_file,
(GTestFixtureFunc) g_object_unref);
g_object_unref (info);
} }
else
{
guint i;
g_assert_no_error (error); for (i = 1; i < argc; i++)
g_object_unref (enumerator); {
GFile *file = g_file_new_for_commandline_arg (argv[i]);
add_test_for_file (file);
g_object_unref (file);
}
}
return g_test_run (); return g_test_run ();
} }