1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2012 Igalia S.L.
6 #include "test-utils.h"
8 /* From http://publicsuffix.org/list/test.txt */
13 /* NULL input. Not checked here because the API requires a valid hostname. */
15 /* Mixed case. Not checked because the API requires a valid hostname. */
16 /* { "COM", NULL }, */
17 /* { "example.COM", "example.com" }, */
18 /* { "WwW.example.COM", "example.com" }, */
22 { ".example.com", NULL },
23 { ".example.example", NULL },
24 /* Unlisted TLD. Not checked because we do not want to force every URL to have a public suffix.*/
25 /* { "example", NULL }, */
26 /* { "example.example", NULL }, */
27 /* { "b.example.example", NULL }, */
28 /* { "a.b.example.example", NULL }, */
29 /* Listed, but non-Internet, TLD. */
30 /*{ "local", NULL }, */
31 /*{ "example.local", NULL }, */
32 /*{ "b.example.local", NULL }, */
33 /*{ "a.b.example.local", NULL }, */
34 /* TLD with only 1 rule. */
36 { "domain.biz", "domain.biz" },
37 { "b.domain.biz", "domain.biz" },
38 { "a.b.domain.biz", "domain.biz" },
39 /* TLD with some 2-level rules. */
41 { "example.com", "example.com" },
42 { "b.example.com", "example.com" },
43 { "a.b.example.com", "example.com" },
45 { "example.uk.com", "example.uk.com" },
46 { "b.example.uk.com", "example.uk.com" },
47 { "a.b.example.uk.com", "example.uk.com" },
48 { "test.ac", "test.ac" },
49 /* TLD with only 1 (wildcard) rule. */
52 { "b.c.cy", "b.c.cy" },
53 { "a.b.c.cy", "b.c.cy" },
54 /* More complex TLD. */
56 { "test.jp", "test.jp" },
57 { "www.test.jp", "test.jp" },
59 { "test.ac.jp", "test.ac.jp" },
60 { "www.test.ac.jp", "test.ac.jp" },
62 { "c.kyoto.jp", NULL },
63 { "b.c.kyoto.jp", "b.c.kyoto.jp" },
64 { "a.b.c.kyoto.jp", "b.c.kyoto.jp" },
65 { "pref.kyoto.jp", "pref.kyoto.jp" }, /* Exception rule. */
66 { "www.pref.kyoto.jp", "pref.kyoto.jp" }, /* Exception rule. */
67 { "city.kyoto.jp", "city.kyoto.jp" }, /* Exception rule. */
68 { "www.city.kyoto.jp", "city.kyoto.jp" }, /* Exception rule. */
69 /* TLD with a wildcard rule and exceptions. */
72 { "b.test.om", "b.test.om" },
73 { "a.b.test.om", "b.test.om" },
74 { "songfest.om", "songfest.om" },
75 { "www.songfest.om", "songfest.om" },
78 { "test.us", "test.us" },
79 { "www.test.us", "test.us" },
81 { "test.ak.us", "test.ak.us" },
82 { "www.test.ak.us", "test.ak.us" },
83 { "k12.ak.us", NULL },
84 { "test.k12.ak.us", "test.k12.ak.us" },
85 { "www.test.k12.ak.us", "test.k12.ak.us" },
86 /* This is not in http://publicsuffix.org/list/test.txt but we want to check it anyway. */
88 /* The original list does not include non-ASCII tests. Let's add a couple. */
90 { "a.b.åfjord.no", "b.åfjord.no" }
94 main (int argc, char **argv)
98 test_init (argc, argv, NULL);
101 for (i = 0; i < G_N_ELEMENTS (tld_tests); ++i) {
102 gboolean is_public = soup_tld_domain_is_public_suffix (tld_tests[i].hostname);
103 const char *base_domain = soup_tld_get_base_domain (tld_tests[i].hostname, NULL);
105 if (tld_tests[i].result) {
106 /* Public domains have NULL expected results. */
107 if (is_public || g_strcmp0 (tld_tests[i].result, base_domain)) {
108 debug_printf (1, "ERROR: %s got %s (%s expected)\n",
109 tld_tests[i].hostname, base_domain, tld_tests[i].result);
113 /* If there is no expected result then either the domain is public or
114 * the hostname invalid (for example starts with a leading dot).
116 if (!is_public && base_domain) {
117 debug_printf (1, "ERROR: public domain %s got %s (none expected)\n",
118 tld_tests[i].hostname, base_domain);