Add simple regexp unit test to Addons extension
This commit is contained in:
parent
c956b6cb75
commit
583c5be7ef
4 changed files with 73 additions and 17 deletions
|
@ -1861,6 +1861,47 @@ addons_activate_cb (MidoriExtension* extension,
|
||||||
G_CALLBACK (addons_deactivate_cb), app);
|
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*
|
MidoriExtension*
|
||||||
extension_init (void)
|
extension_init (void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1561,3 +1561,27 @@ katze_uri_entry_new (GtkWidget* other_widget)
|
||||||
return entry;
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,11 @@ katze_load_cached_icon (const gchar* uri,
|
||||||
GtkWidget*
|
GtkWidget*
|
||||||
katze_uri_entry_new (GtkWidget* other_widget);
|
katze_uri_entry_new (GtkWidget* other_widget);
|
||||||
|
|
||||||
|
void
|
||||||
|
katze_assert_str_equal (const gchar* input,
|
||||||
|
const gchar* result,
|
||||||
|
const gchar* expected);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __KATZE_UTILS_H__ */
|
#endif /* __KATZE_UTILS_H__ */
|
||||||
|
|
|
@ -14,20 +14,6 @@
|
||||||
|
|
||||||
#define SM "http://www.searchmash.com/search/"
|
#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
|
static void
|
||||||
test_input (const gchar* input,
|
test_input (const gchar* input,
|
||||||
const gchar* expected)
|
const gchar* expected)
|
||||||
|
@ -76,7 +62,7 @@ test_input (const gchar* input,
|
||||||
|
|
||||||
g_free (keywords);
|
g_free (keywords);
|
||||||
}
|
}
|
||||||
sokoke_assert_str_equal (input, uri, expected);
|
katze_assert_str_equal (input, uri, expected);
|
||||||
g_free (uri);
|
g_free (uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +120,7 @@ magic_uri_idn (void)
|
||||||
{
|
{
|
||||||
gchar* result = midori_uri_to_ascii (items[i].before);
|
gchar* result = midori_uri_to_ascii (items[i].before);
|
||||||
const gchar* after = items[i].after ? items[i].after : 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);
|
g_free (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +238,7 @@ magic_uri_format (void)
|
||||||
{
|
{
|
||||||
gchar* result = midori_uri_format_for_display (items[i].before);
|
gchar* result = midori_uri_format_for_display (items[i].before);
|
||||||
const gchar* after = items[i].after ? items[i].after : 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);
|
g_free (result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue