From 59ff9878c9d087c26bbb570db3fce656d4a0e2a3 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sun, 16 Nov 2008 00:03:34 +0100 Subject: [PATCH] Actually commit the 'tests' folder --- tests/magic-uri.c | 75 +++++++++++++++++++++++++++++++++++++++++++++ tests/wscript_build | 11 +++++++ 2 files changed, 86 insertions(+) create mode 100644 tests/magic-uri.c create mode 100644 tests/wscript_build diff --git a/tests/magic-uri.c b/tests/magic-uri.c new file mode 100644 index 00000000..2cdf5709 --- /dev/null +++ b/tests/magic-uri.c @@ -0,0 +1,75 @@ +/* + Copyright (C) 2008 Christian Dywan + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + See the file COPYING for the full license text. +*/ + +#if HAVE_CONFIG_H + #include +#endif + +#include "compat.h" +#include "sokoke.h" + +int +main (int argc, + char** argv) +{ + KatzeArray* search_engines; + KatzeItem* item; + gchar* uri; + gchar* a, *b; + + gtk_init (&argc, &argv); + + 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); + +#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) + + test_input ("ftp://ftp.mozilla.org", "ftp://ftp.mozilla.org"); + test_input ("ftp://ftp.mozilla.org/pub", "ftp://ftp.mozilla.org/pub"); + test_input ("http://www.example.com", "http://www.example.com"); + test_input ("http://example.com", "http://example.com"); + test_input ("example.com", "http://example.com"); + test_input ("example.com", "http://example.com"); + test_input ("/home/user/midori.html", "file:///home/user/midori.html"); + a = g_get_current_dir (); + b = g_strconcat ("file://", a, G_DIR_SEPARATOR_S, "magic-uri.c", NULL); + g_free (a); + test_input ("magic-uri.c", b); + g_free (b); + test_input ("localhost", "http://localhost"); + test_input ("localhost:8000", "http://localhost:8000"); + 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 ("sm midori", "http://www.searchmash.com/search/midori"); + test_input ("sm cats dogs", "http://www.searchmash.com/search/cats dogs"); + test_input ("dict midori", NULL); + test_input ("cats", NULL); + test_input ("cats dogs", NULL); + test_input ("gtk 2.0", NULL); + test_input ("gtk2.0", NULL); + test_input ("midori0.1.0", NULL); + test_input ("midori 0.1.0", NULL); + + return 0; +} diff --git a/tests/wscript_build b/tests/wscript_build new file mode 100644 index 00000000..f0b93d35 --- /dev/null +++ b/tests/wscript_build @@ -0,0 +1,11 @@ +#! /usr/bin/env python +# WAF build script for midori +# This file is licensed under the terms of the expat license, see the file EXPAT. + +obj = bld.create_obj ('cc', 'program') +obj.target = 'magic-uri' +obj.includes = '.. ../midori' +obj.source = 'magic-uri.c ../midori/compat.c ../midori/sokoke.c' +obj.uselib = 'UNIQUE LIBSOUP GIO GTK SQLITE WEBKIT LIBXML' +obj.uselib_local = 'katze' +obj.unit_test = 1