[glib] Add testcase for search utilities functions
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add testcase for search utilities functions
- Date: Mon, 14 Oct 2013 20:49:45 +0000 (UTC)
commit 04202954308471196817318b12df64665656fcda
Author: Xavier Claessens <xavier claessens collabora co uk>
Date: Wed Oct 9 14:32:58 2013 -0400
Add testcase for search utilities functions
https://bugzilla.gnome.org/show_bug.cgi?id=709753
glib/tests/.gitignore | 1 +
glib/tests/Makefile.am | 1 +
glib/tests/search-utils.c | 76 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/.gitignore b/glib/tests/.gitignore
index 1bc83c5..22bce40 100644
--- a/glib/tests/.gitignore
+++ b/glib/tests/.gitignore
@@ -53,6 +53,7 @@ rec-mutex
regex
rwlock
scannerapi
+search-utils
sequence
shell
slice
diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am
index ac077dd..eaa99ae 100644
--- a/glib/tests/Makefile.am
+++ b/glib/tests/Makefile.am
@@ -76,6 +76,7 @@ test_programs = \
regex \
rwlock \
scannerapi \
+ search-utils \
sequence \
shell \
slice \
diff --git a/glib/tests/search-utils.c b/glib/tests/search-utils.c
new file mode 100644
index 0000000..95c9b2b
--- /dev/null
+++ b/glib/tests/search-utils.c
@@ -0,0 +1,76 @@
+#include "config.h"
+
+#include <locale.h>
+#include <glib.h>
+
+typedef struct
+{
+ const gchar *string;
+ const gchar *prefix;
+ gboolean should_match;
+} SearchTest;
+
+static void
+test_search (void)
+{
+ SearchTest 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 composed chars (accentued letters) */
+ { "Jörgen", "jor", TRUE },
+ { "Gaëtan", "gaetan", TRUE },
+ { "élève", "ele", TRUE },
+ { "Azais", "AzaÏs", FALSE },
+ { "AzaÏs", "Azais", TRUE },
+
+ /* Test decomposed chars, they looks the same, but are actually
+ * composed of multiple unicodes */
+ { "Jorgen", "Jör", FALSE },
+ { "Jörgen", "jor", TRUE },
+
+ /* Multi words */
+ { "Xavier Claessens", "Xav Cla", TRUE },
+ { "Xavier Claessens", "Cla Xav", TRUE },
+ { "Foo Bar Baz", " b ", TRUE },
+ { "Foo Bar Baz", "bar bazz", FALSE },
+
+ { NULL, NULL, FALSE }
+ };
+ guint i;
+
+ setlocale(LC_ALL, "");
+
+ g_debug ("Started");
+ for (i = 0; tests[i].string != NULL; i ++)
+ {
+ gboolean match;
+ gboolean ok;
+
+ match = g_str_match_string (tests[i].prefix, tests[i].string, TRUE);
+ ok = (match == tests[i].should_match);
+
+ g_debug ("'%s' - '%s' %s: %s", tests[i].prefix, tests[i].string,
+ tests[i].should_match ? "should match" : "should NOT match",
+ ok ? "OK" : "FAILED");
+
+ g_assert (ok);
+ }
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/search", test_search);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]