]> git.meshlink.io Git - catta/blob - tests/domain-test.c
ws2tcpip.h defines socklen_t
[catta] / tests / domain-test.c
1 /***
2   This file is part of catta.
3
4   catta is free software; you can redistribute it and/or modify it
5   under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2.1 of the
7   License, or (at your option) any later version.
8
9   catta is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
12   Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with catta; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA.
18 ***/
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <stdio.h>
25 #include <string.h>
26 #include <assert.h>
27
28 #include <catta/domain.h>
29 #include <catta/malloc.h>
30
31 int main(CATTA_GCC_UNUSED int argc, CATTA_GCC_UNUSED char *argv[]) {
32     char *s;
33     char t[256], r[256];
34     const char *p;
35     size_t size;
36     char name[64], type[CATTA_DOMAIN_NAME_MAX], domain[CATTA_DOMAIN_NAME_MAX];
37
38     printf("%s\n", s = catta_normalize_name_strdup("foo.foo\\046."));
39     catta_free(s);
40
41     printf("%s\n", s = catta_normalize_name_strdup("foo.foo\\.foo."));
42     catta_free(s);
43
44
45     printf("%s\n", s = catta_normalize_name_strdup("fo\\\\o\\..f oo."));
46     catta_free(s);
47
48     printf("%i\n", catta_domain_equal("\\065aa bbb\\.\\046cc.cc\\\\.dee.fff.", "Aaa BBB\\.\\.cc.cc\\\\.dee.fff"));
49     printf("%i\n", catta_domain_equal("A", "a"));
50
51     printf("%i\n", catta_domain_equal("a", "aaa"));
52
53     printf("%u = %u\n", catta_domain_hash("ccc\\065aa.aa\\.b\\\\."), catta_domain_hash("cccAaa.aa\\.b\\\\"));
54
55
56     catta_service_name_join(t, sizeof(t), "foo.foo.foo \\.", "_http._tcp", "test.local");
57     printf("<%s>\n", t);
58
59     catta_service_name_split(t, name, sizeof(name), type, sizeof(type), domain, sizeof(domain));
60     printf("name: <%s>; type: <%s>; domain <%s>\n", name, type, domain);
61
62     catta_service_name_join(t, sizeof(t), NULL, "_http._tcp", "one.two\\. .local");
63     printf("<%s>\n", t);
64
65     catta_service_name_split(t, NULL, 0, type, sizeof(type), domain, sizeof(domain));
66     printf("name: <>; type: <%s>; domain <%s>\n", type, domain);
67
68
69     p = "--:---\\\\\\123\\065_äöü\\064\\.\\\\sjöödfhh.sdfjhskjdf";
70     printf("unescaped: <%s>, rest: %s\n", catta_unescape_label(&p, t, sizeof(t)), p);
71
72     size = sizeof(r);
73     s = r;
74
75     printf("escaped: <%s>\n", catta_escape_label(t, strlen(t), &s, &size));
76
77     p = r;
78     printf("unescaped: <%s>\n", catta_unescape_label(&p, t, sizeof(t)));
79
80     assert(catta_is_valid_service_type_generic("_foo._bar._waldo"));
81     assert(!catta_is_valid_service_type_strict("_foo._bar._waldo"));
82     assert(!catta_is_valid_service_subtype("_foo._bar._waldo"));
83
84     assert(catta_is_valid_service_type_generic("_foo._tcp"));
85     assert(catta_is_valid_service_type_strict("_foo._tcp"));
86     assert(!catta_is_valid_service_subtype("_foo._tcp"));
87
88     assert(!catta_is_valid_service_type_generic("_foo._bar.waldo"));
89     assert(!catta_is_valid_service_type_strict("_foo._bar.waldo"));
90     assert(!catta_is_valid_service_subtype("_foo._bar.waldo"));
91
92     assert(!catta_is_valid_service_type_generic(""));
93     assert(!catta_is_valid_service_type_strict(""));
94     assert(!catta_is_valid_service_subtype(""));
95
96     assert(catta_is_valid_service_type_generic("_foo._sub._bar._tcp"));
97     assert(!catta_is_valid_service_type_strict("_foo._sub._bar._tcp"));
98     assert(catta_is_valid_service_subtype("_foo._sub._bar._tcp"));
99
100     printf("%s\n", catta_get_type_from_subtype("_foo._sub._bar._tcp"));
101
102     assert(!catta_is_valid_host_name("sf.ooo."));
103     assert(catta_is_valid_host_name("sfooo."));
104     assert(catta_is_valid_host_name("sfooo"));
105
106     assert(catta_is_valid_domain_name("."));
107     assert(catta_is_valid_domain_name(""));
108
109     assert(catta_normalize_name(".", t, sizeof(t)));
110     assert(catta_normalize_name("", t, sizeof(t)));
111
112     assert(!catta_is_valid_fqdn("."));
113     assert(!catta_is_valid_fqdn(""));
114     assert(!catta_is_valid_fqdn("foo"));
115     assert(catta_is_valid_fqdn("foo.bar"));
116     assert(catta_is_valid_fqdn("foo.bar."));
117     assert(catta_is_valid_fqdn("gnurz.foo.bar."));
118     assert(!catta_is_valid_fqdn("192.168.50.1"));
119     assert(!catta_is_valid_fqdn("::1"));
120     assert(!catta_is_valid_fqdn(".192.168.50.1."));
121
122     return 0;
123 }