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 /* TLD with only 1 rule. */
26 { "domain.biz", "domain.biz" },
27 { "b.domain.biz", "domain.biz" },
28 { "a.b.domain.biz", "domain.biz" },
29 /* TLD with some 2-level rules. */
31 { "example.com", "example.com" },
32 { "b.example.com", "example.com" },
33 { "a.b.example.com", "example.com" },
35 { "example.uk.com", "example.uk.com" },
36 { "b.example.uk.com", "example.uk.com" },
37 { "a.b.example.uk.com", "example.uk.com" },
38 { "test.ac", "test.ac" },
39 /* TLD with only 1 (wildcard) rule. */
42 { "b.c.cy", "b.c.cy" },
43 { "a.b.c.cy", "b.c.cy" },
44 /* More complex TLD. */
46 { "test.jp", "test.jp" },
47 { "www.test.jp", "test.jp" },
49 { "test.ac.jp", "test.ac.jp" },
50 { "www.test.ac.jp", "test.ac.jp" },
52 { "minami.kyoto.jp", NULL },
53 { "b.minami.kyoto.jp", "b.minami.kyoto.jp" },
54 { "a.b.minami.kyoto.jp", "b.minami.kyoto.jp" },
55 { "pref.kyoto.jp", "pref.kyoto.jp" },
56 { "www.pref.kyoto.jp", "pref.kyoto.jp" },
57 { "city.kyoto.jp", "city.kyoto.jp" },
58 { "www.city.kyoto.jp", "city.kyoto.jp" },
59 /* TLD with a wildcard rule and exceptions. */
62 { "b.test.om", "b.test.om" },
63 { "a.b.test.om", "b.test.om" },
64 { "songfest.om", "songfest.om" },
65 { "www.songfest.om", "songfest.om" },
68 { "test.us", "test.us" },
69 { "www.test.us", "test.us" },
71 { "test.ak.us", "test.ak.us" },
72 { "www.test.ak.us", "test.ak.us" },
73 { "k12.ak.us", NULL },
74 { "test.k12.ak.us", "test.k12.ak.us" },
75 { "www.test.k12.ak.us", "test.k12.ak.us" },
76 /* This is not in http://publicsuffix.org/list/test.txt but we want to check it anyway. */
78 /* The original list does not include non-ASCII tests. Let's add a couple. */
80 { "a.b.åfjord.no", "b.åfjord.no" }
82 /* Non Internet TLDs have NULL as expected result
84 non_inet_tld_tests[] = {
87 { "example.example", NULL },
88 { "b.example.example", NULL },
89 { "a.b.example.example", NULL },
90 /* Listed, but non-Internet, TLD. */
92 { "example.local", NULL },
93 { "b.example.local", NULL },
94 { "a.b.example.local", NULL }
98 main (int argc, char **argv)
102 test_init (argc, argv, NULL);
105 for (i = 0; i < G_N_ELEMENTS (tld_tests); ++i) {
106 GError *error = NULL;
107 gboolean is_public = soup_tld_domain_is_public_suffix (tld_tests[i].hostname);
108 const char *base_domain = soup_tld_get_base_domain (tld_tests[i].hostname, &error);
110 debug_printf (1, "Testing %s: ", tld_tests[i].hostname);
112 if (is_public && tld_tests[i].result) {
113 debug_printf (1, "ERROR: domain is public but base_domain is not NULL (%s)\n",
116 } else if (g_strcmp0 (tld_tests[i].result, base_domain)) {
117 debug_printf (1, "ERROR: %s expected as base domain but got %s\n",
118 tld_tests[i].result, base_domain);
121 } else if (!tld_tests[i].result && !is_public &&
122 !g_error_matches (error, SOUP_TLD_ERROR, SOUP_TLD_ERROR_INVALID_HOSTNAME)) {
123 debug_printf (1, "ERROR: not public domain with NULL expected result\n");
126 debug_printf (1, "OK\n");
128 g_clear_error(&error);
131 for (i = 0; i < G_N_ELEMENTS (non_inet_tld_tests); ++i) {
132 gboolean is_public = soup_tld_domain_is_public_suffix (non_inet_tld_tests[i].hostname);
133 const char *base_domain = soup_tld_get_base_domain (non_inet_tld_tests[i].hostname, NULL);
135 debug_printf (1, "Testing %s: ", non_inet_tld_tests[i].hostname);
138 debug_printf (1, "ERROR: domain incorrectly clasified as public\n");
140 } else if (base_domain) {
141 debug_printf (1, "ERROR: non NULL base domain (%s) for local url\n",
145 debug_printf (1, "OK\n");