From: Christian Dywan Date: Thu, 26 Mar 2009 22:47:54 +0000 (+0100) Subject: Use GTest for magic-uri and group cases in proper paths X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2134db5ac2851ec4122948aa5c44464108a6f55b;p=midori Use GTest for magic-uri and group cases in proper paths --- diff --git a/tests/magic-uri.c b/tests/magic-uri.c index 3b8554cc..1a67dce7 100644 --- a/tests/magic-uri.c +++ b/tests/magic-uri.c @@ -1,5 +1,5 @@ /* - Copyright (C) 2008 Christian Dywan + Copyright (C) 2008-2009 Christian Dywan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -16,41 +16,45 @@ #include "compat.h" #include "sokoke.h" -int -main (int argc, - char** argv) +#define SM "http://www.searchmash.com/search/" + +static void +test_input (const gchar* input, + const gchar* expected) { - KatzeArray* search_engines; - KatzeItem* item; - gchar* uri; - gchar* a, *b; + static KatzeArray* search_engines = NULL; + if (G_UNLIKELY (!search_engines)) + { + KatzeItem* item; - gtk_init_check (&argc, &argv); + search_engines = katze_array_new (KATZE_TYPE_ITEM); + item = g_object_new (KATZE_TYPE_ITEM, + "uri", SM "%s", + "token", "sm", NULL); + katze_array_add_item (search_engines, item); + g_object_unref (item); + item = g_object_new (KATZE_TYPE_ITEM, + "uri", SM, + "token", "se", NULL); + katze_array_add_item (search_engines, item); + g_object_unref (item); + } - search_engines = katze_array_new (KATZE_TYPE_ITEM); - item = g_object_new (KATZE_TYPE_ITEM, - "uri", "http://www.searchmash.com/search/%s", - "token", "sm", NULL); - katze_array_add_item (search_engines, item); - g_object_unref (item); - item = g_object_new (KATZE_TYPE_ITEM, - "uri", "http://www.searchmash.com/search/", - "token", "se", NULL); - katze_array_add_item (search_engines, item); - g_object_unref (item); - -#define test_input(input, expected) \ - uri = sokoke_magic_uri (input, search_engines); \ - if (g_strcmp0 (uri, expected)) \ - { \ - g_print ("Input: %s\nExpected: %s\nResult: %s\n\n", \ - input ? input : "NULL", \ - expected ? expected : "NULL", \ - uri ? uri : "NULL"); \ - return 1; \ - } \ - g_free (uri) -#define SM "http://www.searchmash.com/search/" + gchar* uri = sokoke_magic_uri (input, search_engines); + if (g_strcmp0 (uri, expected)) + { + g_error ("Input: %s\nExpected: %s\nResult: %s", + input ? input : "NULL", + expected ? expected : "NULL", + uri ? uri : "NULL"); + } + g_free (uri); +} + +static void +magic_uri_uri (void) +{ + gchar* a, *b; test_input ("ftp://ftp.mozilla.org", "ftp://ftp.mozilla.org"); test_input ("ftp://ftp.mozilla.org/pub", "ftp://ftp.mozilla.org/pub"); @@ -69,6 +73,39 @@ main (int argc, test_input ("localhost/rss", "http://localhost/rss"); test_input ("192.168.1.1", "http://192.168.1.1"); test_input ("192.168.1.1:8000", "http://192.168.1.1:8000"); + test_input ("file:///home/mark/foo/bar.html", + "file:///home/mark/foo/bar.html"); +} + +static void +magic_uri_idn (void) +{ + #if HAVE_LIBIDN + test_input ("http://www.münchhausen.at", "http://www.xn--mnchhausen-9db.at"); + test_input ("http://www.خداوند.com/", "http://www.xn--mgbndb8il.com/"); + test_input ("айкидо.com", "http://xn--80aildf0a.com"); + test_input ("http://東京理科大学.jp", "http://xn--1lq68wkwbj6ugkpigi.jp"); + test_input ("https://青のネコ", "https://xn--u9jthzcs263c"); + #else + test_input ("http://www.münchhausen.at", "http://www.münchhausen.at"); + test_input ("http://www.خداوند.com/", "http://www.خداوند.com/"); + test_input ("айкидо.com", "http://айкидо.com"); + test_input ("http://東京理科大学.jp", "http://東京理科大学.jp"); + test_input ("https://青のネコ.co.jp", "https://青のネコ.co.jp"); + #endif + test_input ("http://en.wikipedia.org/wiki/Kölsch_language", + "http://en.wikipedia.org/wiki/Kölsch_language"); + test_input ("en.wikipedia.org/wiki/Kölsch_language", + "http://en.wikipedia.org/wiki/Kölsch_language"); + test_input ("sm Küchenzubehör", SM "Küchenzubehör"); + test_input ("sm 東京理科大学", SM "東京理科大学"); + test_input ("file:///home/mark/frühstück", + "file:///home/mark/frühstück"); +} + +static void +magic_uri_search (void) +{ test_input ("sm midori", SM "midori"); test_input ("sm cats dogs", SM "cats dogs"); test_input ("se cats dogs", SM "cats dogs"); @@ -91,32 +128,28 @@ main (int argc, test_input ("verbose de.po", NULL); test_input ("g de.po verbose", NULL); test_input ("sm de.po verbose", SM "de.po verbose"); - test_input ("javascript:alert(1)", "javascript:alert(1)"); test_input ("sm warning: configure /dev/net: virtual", SM "warning: configure /dev/net: virtual"); - #if HAVE_LIBIDN - test_input ("http://www.münchhausen.at", "http://www.xn--mnchhausen-9db.at"); - test_input ("http://www.خداوند.com/", "http://www.xn--mgbndb8il.com/"); - test_input ("айкидо.com", "http://xn--80aildf0a.com"); - test_input ("http://東京理科大学.jp", "http://xn--1lq68wkwbj6ugkpigi.jp"); - test_input ("https://青のネコ", "https://xn--u9jthzcs263c"); - #else - test_input ("http://www.münchhausen.at", "http://www.münchhausen.at"); - test_input ("http://www.خداوند.com/", "http://www.خداوند.com/"); - test_input ("айкидо.com", "http://айкидо.com"); - test_input ("http://東京理科大学.jp", "http://東京理科大学.jp"); - test_input ("https://青のネコ.co.jp", "https://青のネコ.co.jp"); - #endif - test_input ("http://en.wikipedia.org/wiki/Kölsch_language", - "http://en.wikipedia.org/wiki/Kölsch_language"); - test_input ("en.wikipedia.org/wiki/Kölsch_language", - "http://en.wikipedia.org/wiki/Kölsch_language"); - test_input ("sm Küchenzubehör", SM "Küchenzubehör"); - test_input ("sm 東京理科大学", SM "東京理科大学"); - test_input ("file:///home/mark/foo/bar.html", - "file:///home/mark/foo/bar.html"); - test_input ("file:///home/mark/frühstück", - "file:///home/mark/frühstück"); +} + +static void +magic_uri_pseudo (void) +{ + test_input ("javascript:alert(1)", "javascript:alert(1)"); + test_input ("mailto:christian@twotoasts.de", "mailto:christian@twotoasts.de"); +} + +int +main (int argc, + char** argv) +{ + g_test_init (&argc, &argv, NULL); + gtk_init_check (&argc, &argv); + + g_test_add_func ("/magic-uri/uri", magic_uri_uri); + g_test_add_func ("/magic-uri/idn", magic_uri_idn); + g_test_add_func ("/magic-uri/search", magic_uri_search); + g_test_add_func ("/magic-uri/pseudo", magic_uri_pseudo); - return 0; + return g_test_run (); }