[glib/filechooserentry: 5/10] tests: Add tests for fileattributematchers



commit 5032c608270423661efb5f9c082c5aa77df18160
Author: Benjamin Otte <otte redhat com>
Date:   Tue Nov 1 19:12:17 2011 +0100

    tests: Add tests for fileattributematchers

 gio/tests/Makefile.am            |    4 ++
 gio/tests/fileattributematcher.c |   88 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+), 0 deletions(-)
---
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index 2091366..3a6d77d 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -56,6 +56,7 @@ TEST_PROGS +=	 		\
 	tls-interaction		\
 	cancellable		\
 	vfs			\
+	fileattributematcher	\
 	$(NULL)
 
 if OS_UNIX
@@ -386,6 +387,9 @@ mimeapps_LDADD   = $(progs_ldadd)
 file_SOURCES = file.c
 file_LDADD   = $(progs_ldadd)
 
+fileattributematcher_SOURCES = fileattributematcher.c
+fileattributematcher_LDADD   = $(progs_ldadd)
+
 gapplication_SOURCES = gapplication.c gdbus-sessionbus.c
 gapplication_LDADD = $(progs_ldadd)
 
diff --git a/gio/tests/fileattributematcher.c b/gio/tests/fileattributematcher.c
new file mode 100644
index 0000000..50bc6d0
--- /dev/null
+++ b/gio/tests/fileattributematcher.c
@@ -0,0 +1,88 @@
+#include <gio/gio.h>
+
+static void
+test_exact (void)
+{
+  char *exact_matches[] = {
+    "*",
+    "a::*",
+    "a::*,b::*",
+    "a::a,a::b",
+    "a::a,a::b,b::*"
+  };
+
+  GFileAttributeMatcher *matcher;
+  char *s;
+  guint i;
+
+  for (i = 0; i < G_N_ELEMENTS (exact_matches); i++)
+    {
+      matcher = g_file_attribute_matcher_new (exact_matches[i]);
+      s = g_file_attribute_matcher_print (matcher);
+      if (! g_str_equal (exact_matches[i], s))
+        {
+          g_test_fail ();
+          g_test_message ("matcher should be %s, but is %s", exact_matches[i], s);
+        }
+      g_free (s);
+      g_file_attribute_matcher_unref (matcher);
+    }
+}
+
+static void
+test_equality (void)
+{
+  struct {
+    char *expected;
+    char *actual;
+  } equals[] = {
+    /* star makes everything else go away */
+    { "*", "*,*" },
+    { "*", "*,a::*" },
+    { "*", "*,a::b" },
+    { "*", "a::*,*" },
+    { "*", "a::b,*" },
+    { "*", "a::b,*,a::*" },
+    /* a::* makes a::<anything> go away */
+    { "a::*", "a::*,a::*" },
+    { "a::*", "a::*,a::b" },
+    { "a::*", "a::b,a::*" },
+    { "a::*", "a::b,a::*,a::c" },
+    /* a::b does not allow duplicates */
+    { "a::b", "a::b,a::b" },
+    { "a::b,a::c", "a::b,a::c,a::b" },
+    /* stuff gets ordered in registration order */
+    { "a::b,a::c", "a::c,a::b" },
+    { "a::*,b::*", "b::*,a::*" },
+  };
+
+  GFileAttributeMatcher *matcher;
+  char *s;
+  guint i;
+
+  for (i = 0; i < G_N_ELEMENTS (equals); i++)
+    {
+      matcher = g_file_attribute_matcher_new (equals[i].actual);
+      s = g_file_attribute_matcher_print (matcher);
+      if (! g_str_equal (equals[i].expected, s))
+        {
+          g_test_fail ();
+          g_test_message ("matcher for %s should be %s, but is %s", equals[i].actual, equals[i].expected, s);
+        }
+      g_free (s);
+      g_file_attribute_matcher_unref (matcher);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+  g_type_init ();
+
+  g_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/fileattributematcher/exact", test_exact);
+  g_test_add_func ("/fileattributematcher/equality", test_equality);
+
+  return g_test_run ();
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]