]> git.0d.be Git - empathy.git/commitdiff
Add unit test for the live search matching
authorXavier Claessens <xclaesse@gmail.com>
Tue, 8 Jun 2010 15:15:03 +0000 (17:15 +0200)
committerXavier Claessens <xclaesse@gmail.com>
Tue, 8 Jun 2010 15:22:03 +0000 (17:22 +0200)
tests/.gitignore
tests/Makefile.am
tests/empathy-live-search-test.c [new file with mode: 0644]

index f3af9c7fea8c7735097b47fc4532203764e22590..095174015159ac11a19d4957ee01a842a8996546 100644 (file)
@@ -6,4 +6,5 @@ empathy-irc-network-manager-test
 empathy-chatroom-test
 empathy-chatroom-manager-test
 empathy-parser-test
+empathy-live-search-test
 test-report.xml
index 9367615333a96ed992d17cafba24901a6e910bdf..cf3d84cba9deb83fc11ea0280067c932dc63e2f9 100644 (file)
@@ -28,7 +28,8 @@ TEST_PROGS =                                     \
      empathy-irc-network-manager-test            \
      empathy-chatroom-test                       \
      empathy-chatroom-manager-test               \
-     empathy-parser-test
+     empathy-parser-test                         \
+     empathy-live-search-test
 
 empathy_utils_test_SOURCES = empathy-utils-test.c \
      test-helper.c test-helper.h
@@ -54,6 +55,9 @@ empathy_chatroom_manager_test_SOURCES = empathy-chatroom-manager-test.c \
 empathy_parser_test_SOURCES = empathy-parser-test.c \
      test-helper.c test-helper.h
 
+empathy_live_search_test_SOURCES = empathy-live-search-test.c \
+     test-helper.c test-helper.h
+
 check_PROGRAMS = $(TEST_PROGS)
 
 TESTS_ENVIRONMENT = EMPATHY_SRCDIR=@abs_top_srcdir@ \
diff --git a/tests/empathy-live-search-test.c b/tests/empathy-live-search-test.c
new file mode 100644 (file)
index 0000000..6263481
--- /dev/null
@@ -0,0 +1,75 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "test-helper.h"
+
+#define DEBUG_FLAG EMPATHY_DEBUG_TESTS
+#include <libempathy/empathy-debug.h>
+
+#include <libempathy-gtk/empathy-live-search.h>
+
+typedef struct
+{
+  const gchar *string;
+  const gchar *prefix;
+  gboolean should_match;
+} LiveSearchTest;
+
+static void
+test_live_search (void)
+{
+  LiveSearchTest tests[] =
+    {
+      /* Test word separators and case */
+      { "Hello World", "he", TRUE },
+      { "Hello World", "wo", TRUE },
+      { "Hello World", "lo", FALSE },
+      { "Hello World", "ld", FALSE },
+      { "Hello-World", "wo", TRUE },
+      { "HelloWorld", "wo", FALSE },
+
+      /* Test accentued letters */
+      { "Jörgen", "jor", TRUE },
+      { "Gaëtan", "gaetan", TRUE },
+      { "élève", "ele", TRUE },
+      { "Azais", "AzaÏs", TRUE },
+
+      { NULL, NULL, FALSE }
+    };
+  guint i;
+  gboolean failed = FALSE;
+
+  DEBUG ("Started");
+  for (i = 0; tests[i].string != NULL; i ++)
+    {
+      gboolean match;
+      gboolean ok;
+
+      match = empathy_live_search_match_string (tests[i].string, tests[i].prefix);
+      ok = (match == tests[i].should_match);
+
+      DEBUG ("'%s' - '%s': %s", tests[i].string, tests[i].prefix, ok ? "OK" : "FAILED");
+
+      if (!ok)
+        failed = TRUE;
+    }
+
+  g_assert (!failed);
+}
+
+int
+main (int argc,
+    char **argv)
+{
+  int result;
+
+  test_init (argc, argv);
+
+  g_test_add_func ("/live-search", test_live_search);
+
+  result = g_test_run ();
+  test_deinit ();
+
+  return result;
+}