[Xfce4-commits] <midori:master> Add simple regexp unit test to Addons extension
Christian Dywan
noreply at xfce.org
Fri Nov 18 00:58:02 CET 2011
Updating branch refs/heads/master
to 583c5be7ef07fc609afc7f89a9448cd5236b7c1a (commit)
from c956b6cb75e8ce804770861f1c87e325a8bc84d5 (commit)
commit 583c5be7ef07fc609afc7f89a9448cd5236b7c1a
Author: Christian Dywan <christian at twotoasts.de>
Date: Fri Nov 18 00:52:10 2011 +0100
Add simple regexp unit test to Addons extension
extensions/addons.c | 41 +++++++++++++++++++++++++++++++++++++++++
katze/katze-utils.c | 24 ++++++++++++++++++++++++
katze/katze-utils.h | 5 +++++
tests/magic-uri.c | 20 +++-----------------
4 files changed, 73 insertions(+), 17 deletions(-)
diff --git a/extensions/addons.c b/extensions/addons.c
index 462285c..5ded3fa 100644
--- a/extensions/addons.c
+++ b/extensions/addons.c
@@ -1861,6 +1861,47 @@ addons_activate_cb (MidoriExtension* extension,
G_CALLBACK (addons_deactivate_cb), app);
}
+#ifdef G_ENABLE_DEBUG
+static void
+test_addons_simple_regexp (void)
+{
+ typedef struct
+ {
+ const gchar* before;
+ const gchar* after;
+ } RegexItem;
+ guint i;
+
+ static const RegexItem items[] = {
+ { "*", "^.*" },
+ { "http://", "^http://" },
+ { "https://", "^https://" },
+ { "about:blank", "^about:blank" },
+ { "file://", "^file://" },
+ { "ftp://", "^ftp://" },
+ { "https://bugzilla.mozilla.org/", "^https://bugzilla\\.mozilla\\.org/" },
+ { "http://92.48.103.52/fantasy3/*", "^http://92\\.48\\.103\\.52/fantasy3/.*" },
+ { "http://www.rpg.co.uk/fantasy/*", "^http://www\\.rpg\\.co\\.uk/fantasy/.*" },
+ { "http://cookpad.com/recipe/*", "^http://cookpad\\.com/recipe/.*" },
+ { "https://*/*post_bug.cgi", "^https://.*/.*post_bug\\.cgi" },
+ };
+
+ for (i = 0; i < G_N_ELEMENTS (items); i++)
+ {
+ gchar* result = addons_convert_to_simple_regexp (items[i].before);
+ const gchar* after = items[i].after ? items[i].after : items[i].before;
+ katze_assert_str_equal (items[i].before, result, after);
+ g_free (result);
+ }
+}
+
+void
+extension_test (void)
+{
+ g_test_add_func ("/extensions/addons/simple_regexp", test_addons_simple_regexp);
+}
+#endif
+
MidoriExtension*
extension_init (void)
{
diff --git a/katze/katze-utils.c b/katze/katze-utils.c
index 27b2e47..ac9df02 100644
--- a/katze/katze-utils.c
+++ b/katze/katze-utils.c
@@ -1561,3 +1561,27 @@ katze_uri_entry_new (GtkWidget* other_widget)
return entry;
}
+/**
+ * katze_assert_str_equal:
+ * @input: a string
+ * @result: a string
+ * @expected: a string
+ *
+ * Compares the two strings for equality, with verbose errors.
+ *
+ * Since: 0.4.3
+ */
+void
+katze_assert_str_equal (const gchar* input,
+ const gchar* result,
+ const gchar* expected)
+{
+ if (g_strcmp0 (result, expected))
+ {
+ g_error ("Input: %s\nExpected: %s\nResult: %s",
+ input ? input : "NULL",
+ expected ? expected : "NULL",
+ result ? result : "NULL");
+ }
+}
+
diff --git a/katze/katze-utils.h b/katze/katze-utils.h
index eb67a1f..c00ebd7 100644
--- a/katze/katze-utils.h
+++ b/katze/katze-utils.h
@@ -142,6 +142,11 @@ katze_load_cached_icon (const gchar* uri,
GtkWidget*
katze_uri_entry_new (GtkWidget* other_widget);
+void
+katze_assert_str_equal (const gchar* input,
+ const gchar* result,
+ const gchar* expected);
+
G_END_DECLS
#endif /* __KATZE_UTILS_H__ */
diff --git a/tests/magic-uri.c b/tests/magic-uri.c
index 259802f..008d1b5 100644
--- a/tests/magic-uri.c
+++ b/tests/magic-uri.c
@@ -15,20 +15,6 @@
#define SM "http://www.searchmash.com/search/"
static void
-sokoke_assert_str_equal (const gchar* input,
- const gchar* result,
- const gchar* expected)
-{
- if (g_strcmp0 (result, expected))
- {
- g_error ("Input: %s\nExpected: %s\nResult: %s",
- input ? input : "NULL",
- expected ? expected : "NULL",
- result ? result : "NULL");
- }
-}
-
-static void
test_input (const gchar* input,
const gchar* expected)
{
@@ -76,7 +62,7 @@ test_input (const gchar* input,
g_free (keywords);
}
- sokoke_assert_str_equal (input, uri, expected);
+ katze_assert_str_equal (input, uri, expected);
g_free (uri);
}
@@ -134,7 +120,7 @@ magic_uri_idn (void)
{
gchar* result = midori_uri_to_ascii (items[i].before);
const gchar* after = items[i].after ? items[i].after : items[i].before;
- sokoke_assert_str_equal (items[i].before, result, after);
+ katze_assert_str_equal (items[i].before, result, after);
g_free (result);
}
@@ -252,7 +238,7 @@ magic_uri_format (void)
{
gchar* result = midori_uri_format_for_display (items[i].before);
const gchar* after = items[i].after ? items[i].after : items[i].before;
- sokoke_assert_str_equal (items[i].before, result, after);
+ katze_assert_str_equal (items[i].before, result, after);
g_free (result);
}
}
More information about the Xfce4-commits
mailing list