summaryrefslogtreecommitdiff
path: root/test-tree-magic.c
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2008-07-20 00:30:38 +0000
committerBastien Nocera <hadess@hadess.net>2008-07-20 00:30:38 +0000
commite82409afecf0ba038907b002c735a2a342d57881 (patch)
tree2c945f480e312242e8ba04e8d3de180cfa99180a /test-tree-magic.c
parent1bac8224c7439452a85693dc1a25f64d3a467e7d (diff)
2008-07-19 Bastien Nocera <hadess@hadess.net>
* Makefile.am: Fail if the tree test failed * freedesktop.org.xml.in: Move some types from nautilus, not fully implemented yet * test-tree-magic.c (handle_one_line), (type_to_path), (print_matchlet), (main): Add some debug functionality * tests/tree-list: Add a test for VCDs
Diffstat (limited to 'test-tree-magic.c')
-rw-r--r--test-tree-magic.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/test-tree-magic.c b/test-tree-magic.c
index b943727..0730416 100644
--- a/test-tree-magic.c
+++ b/test-tree-magic.c
@@ -556,6 +556,7 @@ handle_one_line (const char *line)
if (supposed_to_fail == FALSE) {
g_warning ("Tree %s didn't match %s (found nothing)",
filename, items[1]);
+ retval = FALSE;
} else {
g_message ("Tree %s failed to match %s (expected)",
filename, items[1]);
@@ -599,6 +600,34 @@ bail:
return retval;
}
+static const char *
+type_to_path (GFileType type)
+{
+ switch (type) {
+ case G_FILE_TYPE_REGULAR:
+ return "Regular";
+ case G_FILE_TYPE_DIRECTORY:
+ return "Directory";
+ case G_FILE_TYPE_SYMBOLIC_LINK:
+ return "Symbolic link";
+ default:
+ return "Unknown";
+ }
+}
+
+static void
+print_matchlet (TreeMatchlet *matchlet, guint depth)
+{
+ GList *l;
+ guint i;
+
+ for (i = depth + 1; i != 0; i--)
+ g_print ("\t");
+ g_print ("%s (type=%s)\n", matchlet->path, type_to_path (matchlet->type));
+ for (l = matchlet->matches ; l != NULL; l = l->next)
+ print_matchlet (l->data, depth + 1);
+}
+
int main (int argc, char **argv)
{
GError *error = NULL;
@@ -620,6 +649,22 @@ int main (int argc, char **argv)
return 1;
}
+ if (strcmp (argv[1], "-d") == 0) {
+ GList *l;
+
+ tree_magic_init ();
+ for (l = tree_matches ; l != NULL; l = l->next) {
+ GList *k;
+ TreeMatch *match = (TreeMatch *) l->data;
+ g_print ("Type: %s\n", match->contenttype);
+ for (k = match->matches ; k != NULL; k = k->next) {
+ TreeMatchlet *matchlet = (TreeMatchlet *) k->data;
+ print_matchlet (matchlet, 0);
+ }
+ }
+ return 0;
+ }
+
if (g_file_get_contents (argv[1], &content, NULL, &error) == FALSE) {
g_warning ("Failed to load %s: %s", argv[1], error->message);
return 1;