~kalikiana/midori/beetle

« back to all changes in this revision

Viewing changes to tests/magic-uri.c

  • Committer: Christian Dywan
  • Date: 2008-11-15 23:03:34 UTC
  • Revision ID: git-v1:59ff9878c9d087c26bbb570db3fce656d4a0e2a3
Actually commit the 'tests' folder

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
 
3
 
 
4
 This library is free software; you can redistribute it and/or
 
5
 modify it under the terms of the GNU Lesser General Public
 
6
 License as published by the Free Software Foundation; either
 
7
 version 2.1 of the License, or (at your option) any later version.
 
8
 
 
9
 See the file COPYING for the full license text.
 
10
*/
 
11
 
 
12
#if HAVE_CONFIG_H
 
13
    #include <config.h>
 
14
#endif
 
15
 
 
16
#include "compat.h"
 
17
#include "sokoke.h"
 
18
 
 
19
int
 
20
main (int    argc,
 
21
      char** argv)
 
22
{
 
23
    KatzeArray* search_engines;
 
24
    KatzeItem* item;
 
25
    gchar* uri;
 
26
    gchar* a, *b;
 
27
 
 
28
    gtk_init (&argc, &argv);
 
29
 
 
30
    search_engines = katze_array_new (KATZE_TYPE_ITEM);
 
31
    item = g_object_new (KATZE_TYPE_ITEM,
 
32
                         "uri", "http://www.searchmash.com/search/%s",
 
33
                         "token", "sm", NULL);
 
34
    katze_array_add_item (search_engines, item);
 
35
 
 
36
#define test_input(input, expected) \
 
37
  uri = sokoke_magic_uri (input, search_engines); \
 
38
  if (g_strcmp0 (uri, expected)) \
 
39
    { \
 
40
      g_print ("Input: %s\nExpected: %s\nResult: %s\n\n", \
 
41
               input ? input : "NULL", \
 
42
               expected ? expected : "NULL", \
 
43
               uri ? uri : "NULL"); \
 
44
      return 1; \
 
45
    } \
 
46
  g_free (uri)
 
47
 
 
48
    test_input ("ftp://ftp.mozilla.org", "ftp://ftp.mozilla.org");
 
49
    test_input ("ftp://ftp.mozilla.org/pub", "ftp://ftp.mozilla.org/pub");
 
50
    test_input ("http://www.example.com", "http://www.example.com");
 
51
    test_input ("http://example.com", "http://example.com");
 
52
    test_input ("example.com", "http://example.com");
 
53
    test_input ("example.com", "http://example.com");
 
54
    test_input ("/home/user/midori.html", "file:///home/user/midori.html");
 
55
    a = g_get_current_dir ();
 
56
    b = g_strconcat ("file://", a, G_DIR_SEPARATOR_S, "magic-uri.c", NULL);
 
57
    g_free (a);
 
58
    test_input ("magic-uri.c", b);
 
59
    g_free (b);
 
60
    test_input ("localhost", "http://localhost");
 
61
    test_input ("localhost:8000", "http://localhost:8000");
 
62
    test_input ("192.168.1.1", "http://192.168.1.1");
 
63
    test_input ("192.168.1.1:8000", "http://192.168.1.1:8000");
 
64
    test_input ("sm midori", "http://www.searchmash.com/search/midori");
 
65
    test_input ("sm cats dogs", "http://www.searchmash.com/search/cats dogs");
 
66
    test_input ("dict midori", NULL);
 
67
    test_input ("cats", NULL);
 
68
    test_input ("cats dogs", NULL);
 
69
    test_input ("gtk 2.0", NULL);
 
70
    test_input ("gtk2.0", NULL);
 
71
    test_input ("midori0.1.0", NULL);
 
72
    test_input ("midori 0.1.0", NULL);
 
73
 
 
74
    return 0;
 
75
}