From 583c5be7ef07fc609afc7f89a9448cd5236b7c1a Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Fri, 18 Nov 2011 00:52:10 +0100 Subject: [PATCH] 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 462285c0..5ded3fa8 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 27b2e471..ac9df02d 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 eb67a1ff..c00ebd7c 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 259802f1..008d1b51 100644 --- a/tests/magic-uri.c +++ b/tests/magic-uri.c @@ -14,20 +14,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); } } -- 2.39.5