Use GTest for magic-uri and group cases in proper paths
This commit is contained in:
parent
73b26c53f9
commit
2134db5ac2
1 changed files with 94 additions and 61 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
|
Copyright (C) 2008-2009 Christian Dywan <christian@twotoasts.de>
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
@ -16,41 +16,45 @@
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "sokoke.h"
|
#include "sokoke.h"
|
||||||
|
|
||||||
int
|
#define SM "http://www.searchmash.com/search/"
|
||||||
main (int argc,
|
|
||||||
char** argv)
|
|
||||||
{
|
|
||||||
KatzeArray* search_engines;
|
|
||||||
KatzeItem* item;
|
|
||||||
gchar* uri;
|
|
||||||
gchar* a, *b;
|
|
||||||
|
|
||||||
gtk_init_check (&argc, &argv);
|
static void
|
||||||
|
test_input (const gchar* input,
|
||||||
|
const gchar* expected)
|
||||||
|
{
|
||||||
|
static KatzeArray* search_engines = NULL;
|
||||||
|
if (G_UNLIKELY (!search_engines))
|
||||||
|
{
|
||||||
|
KatzeItem* item;
|
||||||
|
|
||||||
search_engines = katze_array_new (KATZE_TYPE_ITEM);
|
search_engines = katze_array_new (KATZE_TYPE_ITEM);
|
||||||
item = g_object_new (KATZE_TYPE_ITEM,
|
item = g_object_new (KATZE_TYPE_ITEM,
|
||||||
"uri", "http://www.searchmash.com/search/%s",
|
"uri", SM "%s",
|
||||||
"token", "sm", NULL);
|
"token", "sm", NULL);
|
||||||
katze_array_add_item (search_engines, item);
|
katze_array_add_item (search_engines, item);
|
||||||
g_object_unref (item);
|
g_object_unref (item);
|
||||||
item = g_object_new (KATZE_TYPE_ITEM,
|
item = g_object_new (KATZE_TYPE_ITEM,
|
||||||
"uri", "http://www.searchmash.com/search/",
|
"uri", SM,
|
||||||
"token", "se", NULL);
|
"token", "se", NULL);
|
||||||
katze_array_add_item (search_engines, item);
|
katze_array_add_item (search_engines, item);
|
||||||
g_object_unref (item);
|
g_object_unref (item);
|
||||||
|
}
|
||||||
|
|
||||||
#define test_input(input, expected) \
|
gchar* uri = sokoke_magic_uri (input, search_engines);
|
||||||
uri = sokoke_magic_uri (input, search_engines); \
|
if (g_strcmp0 (uri, expected))
|
||||||
if (g_strcmp0 (uri, expected)) \
|
{
|
||||||
{ \
|
g_error ("Input: %s\nExpected: %s\nResult: %s",
|
||||||
g_print ("Input: %s\nExpected: %s\nResult: %s\n\n", \
|
input ? input : "NULL",
|
||||||
input ? input : "NULL", \
|
expected ? expected : "NULL",
|
||||||
expected ? expected : "NULL", \
|
uri ? uri : "NULL");
|
||||||
uri ? uri : "NULL"); \
|
}
|
||||||
return 1; \
|
g_free (uri);
|
||||||
} \
|
}
|
||||||
g_free (uri)
|
|
||||||
#define SM "http://www.searchmash.com/search/"
|
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", "ftp://ftp.mozilla.org");
|
||||||
test_input ("ftp://ftp.mozilla.org/pub", "ftp://ftp.mozilla.org/pub");
|
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 ("localhost/rss", "http://localhost/rss");
|
||||||
test_input ("192.168.1.1", "http://192.168.1.1");
|
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 ("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 midori", SM "midori");
|
||||||
test_input ("sm cats dogs", SM "cats dogs");
|
test_input ("sm cats dogs", SM "cats dogs");
|
||||||
test_input ("se 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 ("verbose de.po", NULL);
|
||||||
test_input ("g de.po verbose", NULL);
|
test_input ("g de.po verbose", NULL);
|
||||||
test_input ("sm de.po verbose", SM "de.po verbose");
|
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",
|
test_input ("sm warning: configure /dev/net: virtual",
|
||||||
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/");
|
static void
|
||||||
test_input ("айкидо.com", "http://xn--80aildf0a.com");
|
magic_uri_pseudo (void)
|
||||||
test_input ("http://東京理科大学.jp", "http://xn--1lq68wkwbj6ugkpigi.jp");
|
{
|
||||||
test_input ("https://青のネコ", "https://xn--u9jthzcs263c");
|
test_input ("javascript:alert(1)", "javascript:alert(1)");
|
||||||
#else
|
test_input ("mailto:christian@twotoasts.de", "mailto:christian@twotoasts.de");
|
||||||
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");
|
int
|
||||||
test_input ("http://東京理科大学.jp", "http://東京理科大学.jp");
|
main (int argc,
|
||||||
test_input ("https://青のネコ.co.jp", "https://青のネコ.co.jp");
|
char** argv)
|
||||||
#endif
|
{
|
||||||
test_input ("http://en.wikipedia.org/wiki/Kölsch_language",
|
g_test_init (&argc, &argv, NULL);
|
||||||
"http://en.wikipedia.org/wiki/Kölsch_language");
|
gtk_init_check (&argc, &argv);
|
||||||
test_input ("en.wikipedia.org/wiki/Kölsch_language",
|
|
||||||
"http://en.wikipedia.org/wiki/Kölsch_language");
|
g_test_add_func ("/magic-uri/uri", magic_uri_uri);
|
||||||
test_input ("sm Küchenzubehör", SM "Küchenzubehör");
|
g_test_add_func ("/magic-uri/idn", magic_uri_idn);
|
||||||
test_input ("sm 東京理科大学", SM "東京理科大学");
|
g_test_add_func ("/magic-uri/search", magic_uri_search);
|
||||||
test_input ("file:///home/mark/foo/bar.html",
|
g_test_add_func ("/magic-uri/pseudo", magic_uri_pseudo);
|
||||||
"file:///home/mark/foo/bar.html");
|
|
||||||
test_input ("file:///home/mark/frühstück",
|
return g_test_run ();
|
||||||
"file:///home/mark/frühstück");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue