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