2 * Tests for name handling functions
4 * Copyright 2006 Hans Leidekker
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/test.h"
30 static HMODULE dnsapi;
32 static BOOL (WINAPI *pDnsNameCompare_A)(LPSTR,LPSTR);
33 static DNS_STATUS (WINAPI *pDnsValidateName_A)(LPCSTR,DNS_NAME_FORMAT);
35 #define GETFUNCPTR(func) p##func = (void *)GetProcAddress( dnsapi, #func ); \
36 if (!p##func) return FALSE;
38 static BOOL init_function_ptrs( void )
40 GETFUNCPTR( DnsNameCompare_A )
41 GETFUNCPTR( DnsValidateName_A )
48 DNS_NAME_FORMAT format;
53 { "", DnsNameDomain, ERROR_INVALID_NAME },
54 { ".", DnsNameDomain, ERROR_SUCCESS },
55 { "..", DnsNameDomain, ERROR_INVALID_NAME },
56 { ".a", DnsNameDomain, ERROR_INVALID_NAME },
57 { "a.", DnsNameDomain, ERROR_SUCCESS },
58 { "a..", DnsNameDomain, ERROR_INVALID_NAME },
59 { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", DnsNameDomain, ERROR_INVALID_NAME },
60 { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", DnsNameDomain, ERROR_INVALID_NAME },
61 { "a.?", DnsNameDomain, DNS_ERROR_INVALID_NAME_CHAR },
62 { "a.*", DnsNameDomain, DNS_ERROR_INVALID_NAME_CHAR },
63 { "a ", DnsNameDomain, DNS_ERROR_INVALID_NAME_CHAR },
64 { "a._b", DnsNameDomain, DNS_ERROR_NON_RFC_NAME },
65 { "123", DnsNameDomain, DNS_ERROR_NUMERIC_NAME },
66 { "123.456", DnsNameDomain, DNS_ERROR_NUMERIC_NAME },
67 { "a.b", DnsNameDomain, ERROR_SUCCESS },
69 { "", DnsNameDomainLabel, ERROR_INVALID_NAME },
70 { ".", DnsNameDomainLabel, ERROR_INVALID_NAME },
71 { "..", DnsNameDomainLabel, ERROR_INVALID_NAME },
72 { ".c", DnsNameDomainLabel, ERROR_INVALID_NAME },
73 { "c.", DnsNameDomainLabel, ERROR_INVALID_NAME },
74 { "c..", DnsNameDomainLabel, ERROR_INVALID_NAME },
75 { "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", DnsNameDomainLabel, ERROR_INVALID_NAME },
76 { "?", DnsNameDomainLabel, DNS_ERROR_INVALID_NAME_CHAR },
77 { "*", DnsNameDomainLabel, DNS_ERROR_INVALID_NAME_CHAR },
78 { "c ", DnsNameDomainLabel, DNS_ERROR_INVALID_NAME_CHAR },
79 { "_c", DnsNameDomainLabel, DNS_ERROR_NON_RFC_NAME },
80 { "456", DnsNameDomainLabel, ERROR_SUCCESS },
81 { "456.789", DnsNameDomainLabel, ERROR_INVALID_NAME },
82 { "c.d", DnsNameDomainLabel, ERROR_INVALID_NAME },
84 { "", DnsNameHostnameFull, ERROR_INVALID_NAME },
85 { ".", DnsNameHostnameFull, ERROR_SUCCESS },
86 { "..", DnsNameHostnameFull, ERROR_INVALID_NAME },
87 { ".e", DnsNameHostnameFull, ERROR_INVALID_NAME },
88 { "e.", DnsNameHostnameFull, ERROR_SUCCESS },
89 { "e..", DnsNameHostnameFull, ERROR_INVALID_NAME },
90 { "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", DnsNameDomain, ERROR_INVALID_NAME },
91 { "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", DnsNameHostnameFull, ERROR_INVALID_NAME },
92 { "?", DnsNameHostnameLabel, DNS_ERROR_INVALID_NAME_CHAR },
93 { "e.?", DnsNameHostnameFull, DNS_ERROR_INVALID_NAME_CHAR },
94 { "e.*", DnsNameHostnameFull, DNS_ERROR_INVALID_NAME_CHAR },
95 { "e ", DnsNameHostnameFull, DNS_ERROR_INVALID_NAME_CHAR },
96 { "e._f", DnsNameHostnameFull, DNS_ERROR_NON_RFC_NAME },
97 { "789", DnsNameHostnameFull, DNS_ERROR_NUMERIC_NAME },
98 { "789.456", DnsNameHostnameFull, DNS_ERROR_NUMERIC_NAME },
99 { "e.f", DnsNameHostnameFull, ERROR_SUCCESS },
101 { "", DnsNameHostnameLabel, ERROR_INVALID_NAME },
102 { ".", DnsNameHostnameLabel, ERROR_INVALID_NAME },
103 { "..", DnsNameHostnameLabel, ERROR_INVALID_NAME },
104 { ".g", DnsNameHostnameLabel, ERROR_INVALID_NAME },
105 { "g.", DnsNameHostnameLabel, ERROR_INVALID_NAME },
106 { "g..", DnsNameHostnameLabel, ERROR_INVALID_NAME },
107 { "gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", DnsNameHostnameLabel, ERROR_INVALID_NAME },
108 { "*", DnsNameHostnameLabel, DNS_ERROR_INVALID_NAME_CHAR },
109 { "g ", DnsNameHostnameLabel, DNS_ERROR_INVALID_NAME_CHAR },
110 { "_g", DnsNameHostnameLabel, DNS_ERROR_NON_RFC_NAME },
111 { "123", DnsNameHostnameLabel, DNS_ERROR_NUMERIC_NAME },
112 { "123.456", DnsNameHostnameLabel, ERROR_INVALID_NAME },
113 { "g.h", DnsNameHostnameLabel, ERROR_INVALID_NAME },
115 { "", DnsNameWildcard, ERROR_INVALID_NAME },
116 { ".", DnsNameWildcard, ERROR_INVALID_NAME },
117 { "..", DnsNameWildcard, ERROR_INVALID_NAME },
118 { ".j", DnsNameWildcard, ERROR_INVALID_NAME },
119 { "j.", DnsNameWildcard, ERROR_INVALID_NAME },
120 { "j..", DnsNameWildcard, ERROR_INVALID_NAME },
121 { "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj", DnsNameWildcard, ERROR_INVALID_NAME },
122 { "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj.jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj.jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj.jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj", DnsNameWildcard, ERROR_INVALID_NAME },
123 { "?", DnsNameWildcard, ERROR_INVALID_NAME },
124 { "i ", DnsNameWildcard, ERROR_INVALID_NAME },
125 { "_i", DnsNameWildcard, ERROR_INVALID_NAME },
126 { "123", DnsNameWildcard, ERROR_INVALID_NAME },
127 { "123.456", DnsNameWildcard, ERROR_INVALID_NAME },
128 { "i.j", DnsNameWildcard, ERROR_INVALID_NAME },
129 { "*", DnsNameWildcard, ERROR_SUCCESS },
130 { "*j", DnsNameWildcard, DNS_ERROR_INVALID_NAME_CHAR },
131 { "*.j", DnsNameWildcard, ERROR_SUCCESS },
132 { "i.*", DnsNameWildcard, ERROR_INVALID_NAME },
134 { "", DnsNameSrvRecord, ERROR_INVALID_NAME },
135 { ".", DnsNameSrvRecord, ERROR_INVALID_NAME },
136 { "..", DnsNameSrvRecord, ERROR_INVALID_NAME },
137 { ".k", DnsNameSrvRecord, ERROR_INVALID_NAME },
138 { "k.", DnsNameSrvRecord, ERROR_INVALID_NAME },
139 { "k..", DnsNameSrvRecord, ERROR_INVALID_NAME },
140 { "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk", DnsNameSrvRecord, ERROR_INVALID_NAME },
141 { "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk.kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk.kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk.kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk", DnsNameSrvRecord, ERROR_INVALID_NAME },
142 { "?", DnsNameSrvRecord, ERROR_INVALID_NAME },
143 { "k ", DnsNameSrvRecord, ERROR_INVALID_NAME },
144 { "_k", DnsNameSrvRecord, ERROR_SUCCESS },
145 { "123", DnsNameSrvRecord, ERROR_INVALID_NAME },
146 { "123.456", DnsNameSrvRecord, ERROR_INVALID_NAME },
147 { "k.l", DnsNameSrvRecord, ERROR_INVALID_NAME },
148 { "_", DnsNameSrvRecord, DNS_ERROR_NON_RFC_NAME },
149 { "_k.l", DnsNameSrvRecord, ERROR_SUCCESS },
150 { "k._l", DnsNameSrvRecord, ERROR_INVALID_NAME }
153 static void test_DnsValidateName_A( void )
158 status = pDnsValidateName_A( NULL, DnsNameDomain );
159 ok( status == ERROR_INVALID_NAME, "succeeded unexpectedly\n" );
161 for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++)
163 status = pDnsValidateName_A( test_data[i].name, test_data[i].format );
164 ok( status == test_data[i].status, "%d: \'%s\': got %ld, expected %ld\n",
165 i, test_data[i].name, status, test_data[i].status );
169 static void test_DnsNameCompare_A( void )
171 ok( pDnsNameCompare_A( NULL, NULL ) == TRUE, "failed unexpectedly\n" );
173 ok( pDnsNameCompare_A( "", "" ) == TRUE, "failed unexpectedly\n" );
174 ok( pDnsNameCompare_A( ".", "" ) == TRUE, "failed unexpectedly\n" );
175 ok( pDnsNameCompare_A( "", "." ) == TRUE, "failed unexpectedly\n" );
176 ok( pDnsNameCompare_A( ".", ".." ) == TRUE, "failed unexpectedly\n" );
177 ok( pDnsNameCompare_A( "..", "." ) == TRUE, "failed unexpectedly\n" );
178 ok( pDnsNameCompare_A( "a", "a" ) == TRUE, "failed unexpectedly\n" );
179 ok( pDnsNameCompare_A( "a", "A" ) == TRUE, "failed unexpectedly\n" );
180 ok( pDnsNameCompare_A( "A", "a" ) == TRUE, "failed unexpectedly\n" );
181 ok( pDnsNameCompare_A( "a.b", "A.B" ) == TRUE, "failed unexpectedly\n" );
182 ok( pDnsNameCompare_A( "a.b", "a.b" ) == TRUE, "failed unexpectedly\n" );
183 ok( pDnsNameCompare_A( "a.b.", "a.b." ) == TRUE, "failed unexpectedly\n" );
184 ok( pDnsNameCompare_A( "a.b..", "a.b.." ) == TRUE, "failed unexpectedly\n" );
186 ok( pDnsNameCompare_A( "", NULL ) == FALSE, "succeeded unexpectedly\n" );
187 ok( pDnsNameCompare_A( NULL, "" ) == FALSE, "succeeded unexpectedly\n" );
189 ok( pDnsNameCompare_A( "a", "b" ) == FALSE, "succeeded unexpectedly\n" );
190 ok( pDnsNameCompare_A( "a", "B" ) == FALSE, "succeeded unexpectedly\n" );
191 ok( pDnsNameCompare_A( "A", "b" ) == FALSE, "succeeded unexpectedly\n" );
192 ok( pDnsNameCompare_A( "a.b", "B.A" ) == FALSE, "succeeded unexpectedly\n" );
193 ok( pDnsNameCompare_A( "a.b.", "b.a." ) == FALSE, "succeeded unexpectedly\n" );
194 ok( pDnsNameCompare_A( "a.b", "a.a" ) == FALSE, "succeeded unexpectedly\n" );
195 ok( pDnsNameCompare_A( "a.b..", "b.a.." ) == FALSE, "succeeded unexpectedly\n" );
196 ok( pDnsNameCompare_A( "a.b.", "b.a.." ) == FALSE, "succeeded unexpectedly\n" );
197 ok( pDnsNameCompare_A( "a.b..", "b.a." ) == FALSE, "succeeded unexpectedly\n" );
198 ok( pDnsNameCompare_A( "a.b.", "b.a" ) == FALSE, "succeeded unexpectedly\n" );
199 ok( pDnsNameCompare_A( "a.b", "b.a." ) == FALSE, "succeeded unexpectedly\n" );
204 dnsapi = LoadLibraryA( "dnsapi.dll" );
207 if (!init_function_ptrs())
209 FreeLibrary( dnsapi );
213 test_DnsValidateName_A();
214 test_DnsNameCompare_A();
216 FreeLibrary( dnsapi );