Use GTest for magic-uri and group cases in proper paths

This commit is contained in:
Christian Dywan 2009-03-26 23:47:54 +01:00
parent 73b26c53f9
commit 2134db5ac2

View file

@ -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
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)
{
KatzeArray* search_engines;
KatzeItem* item;
gchar* uri;
gchar* a, *b;
#define SM "http://www.searchmash.com/search/"
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);
item = g_object_new (KATZE_TYPE_ITEM,
"uri", "http://www.searchmash.com/search/%s",
"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", "http://www.searchmash.com/search/",
"uri", SM,
"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");
return 0;
}
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 g_test_run ();
}