]> spindle.queued.net Git - midori/commitdiff
Add simple regexp unit test to Addons extension
authorChristian Dywan <christian@twotoasts.de>
Thu, 17 Nov 2011 23:52:10 +0000 (00:52 +0100)
committerChristian Dywan <christian@twotoasts.de>
Thu, 17 Nov 2011 23:54:32 +0000 (00:54 +0100)
extensions/addons.c
katze/katze-utils.c
katze/katze-utils.h
tests/magic-uri.c

index 462285c023b5177a686259187c807ee68a8625f6..5ded3fa8179c563db66f3e4a8909682ade8433cb 100644 (file)
@@ -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)
 {
index 27b2e4711c07c58d7666ae0263a9073b4b6b0baa..ac9df02d67530fcd6d95b2b3191875d2fbef3d88 100644 (file)
@@ -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");
+    }
+}
+
index eb67a1ff9973e62b7d298a41dccf3648f7de5c73..c00ebd7c4e3d10b3b8e9a7e2ca83c3b3c72a806b 100644 (file)
@@ -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__ */
index 259802f1888be21ce929952d154d11fcdce2853d..008d1b51009bd069ddd6f8a5cbd6a2674efa1e32 100644 (file)
 
 #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);
     }
 }