1 /* 2 * Tests for name handling functions 3 * 4 * Copyright 2006 Hans Leidekker 5 * 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. 10 * 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. 15 * 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 19 */ 20 21 #include <stdarg.h> 22 23 #include "windef.h" 24 #include "winbase.h" 25 #include "winnls.h" 26 #include "windns.h" 27 28 #include "wine/test.h" 29 30 BOOL WINAPI DnsFlushResolverCacheEntry_A(PCSTR); 31 32 static const struct 33 { 34 LPCSTR name; 35 DNS_NAME_FORMAT format; 36 DNS_STATUS status; 37 DNS_STATUS status_broken; 38 } 39 test_data[] = 40 { 41 { "", DnsNameDomain, ERROR_INVALID_NAME }, 42 { ".", DnsNameDomain, ERROR_SUCCESS }, 43 { "..", DnsNameDomain, ERROR_INVALID_NAME }, 44 { ".a", DnsNameDomain, ERROR_INVALID_NAME }, 45 { "a.", DnsNameDomain, ERROR_SUCCESS }, 46 { "a..", DnsNameDomain, ERROR_INVALID_NAME }, 47 { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", DnsNameDomain, ERROR_INVALID_NAME }, 48 { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", DnsNameDomain, ERROR_INVALID_NAME }, 49 { "a.?", DnsNameDomain, DNS_ERROR_INVALID_NAME_CHAR }, 50 { "a.*", DnsNameDomain, DNS_ERROR_INVALID_NAME_CHAR }, 51 { "a ", DnsNameDomain, DNS_ERROR_INVALID_NAME_CHAR }, 52 { "a._b", DnsNameDomain, DNS_ERROR_NON_RFC_NAME }, 53 { "123", DnsNameDomain, ERROR_SUCCESS, DNS_ERROR_NUMERIC_NAME }, 54 { "123.456", DnsNameDomain, ERROR_SUCCESS, DNS_ERROR_NUMERIC_NAME }, 55 { "a.b", DnsNameDomain, ERROR_SUCCESS }, 56 57 { "", DnsNameDomainLabel, ERROR_INVALID_NAME }, 58 { ".", DnsNameDomainLabel, ERROR_INVALID_NAME }, 59 { "..", DnsNameDomainLabel, ERROR_INVALID_NAME }, 60 { ".c", DnsNameDomainLabel, ERROR_INVALID_NAME }, 61 { "c.", DnsNameDomainLabel, ERROR_INVALID_NAME }, 62 { "c..", DnsNameDomainLabel, ERROR_INVALID_NAME }, 63 { "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", DnsNameDomainLabel, ERROR_INVALID_NAME }, 64 { "?", DnsNameDomainLabel, DNS_ERROR_INVALID_NAME_CHAR }, 65 { "*", DnsNameDomainLabel, DNS_ERROR_INVALID_NAME_CHAR }, 66 { "c ", DnsNameDomainLabel, DNS_ERROR_INVALID_NAME_CHAR }, 67 { "_c", DnsNameDomainLabel, DNS_ERROR_NON_RFC_NAME }, 68 { "456", DnsNameDomainLabel, ERROR_SUCCESS }, 69 { "456.789", DnsNameDomainLabel, ERROR_INVALID_NAME }, 70 { "c.d", DnsNameDomainLabel, ERROR_INVALID_NAME }, 71 72 { "", DnsNameHostnameFull, ERROR_INVALID_NAME }, 73 { ".", DnsNameHostnameFull, ERROR_SUCCESS }, 74 { "..", DnsNameHostnameFull, ERROR_INVALID_NAME }, 75 { ".e", DnsNameHostnameFull, ERROR_INVALID_NAME }, 76 { "e.", DnsNameHostnameFull, ERROR_SUCCESS }, 77 { "e..", DnsNameHostnameFull, ERROR_INVALID_NAME }, 78 { "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", DnsNameDomain, ERROR_INVALID_NAME }, 79 { "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", DnsNameHostnameFull, ERROR_INVALID_NAME }, 80 { "?", DnsNameHostnameLabel, DNS_ERROR_INVALID_NAME_CHAR }, 81 { "e.?", DnsNameHostnameFull, DNS_ERROR_INVALID_NAME_CHAR }, 82 { "e.*", DnsNameHostnameFull, DNS_ERROR_INVALID_NAME_CHAR }, 83 { "e ", DnsNameHostnameFull, DNS_ERROR_INVALID_NAME_CHAR }, 84 { "e._f", DnsNameHostnameFull, DNS_ERROR_NON_RFC_NAME }, 85 { "789", DnsNameHostnameFull, ERROR_SUCCESS, DNS_ERROR_NUMERIC_NAME }, 86 { "789.456", DnsNameHostnameFull, ERROR_SUCCESS, DNS_ERROR_NUMERIC_NAME }, 87 { "e.f", DnsNameHostnameFull, ERROR_SUCCESS }, 88 89 { "", DnsNameHostnameLabel, ERROR_INVALID_NAME }, 90 { ".", DnsNameHostnameLabel, ERROR_INVALID_NAME }, 91 { "..", DnsNameHostnameLabel, ERROR_INVALID_NAME }, 92 { ".g", DnsNameHostnameLabel, ERROR_INVALID_NAME }, 93 { "g.", DnsNameHostnameLabel, ERROR_INVALID_NAME }, 94 { "g..", DnsNameHostnameLabel, ERROR_INVALID_NAME }, 95 { "gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", DnsNameHostnameLabel, ERROR_INVALID_NAME }, 96 { "*", DnsNameHostnameLabel, DNS_ERROR_INVALID_NAME_CHAR }, 97 { "g ", DnsNameHostnameLabel, DNS_ERROR_INVALID_NAME_CHAR }, 98 { "_g", DnsNameHostnameLabel, DNS_ERROR_NON_RFC_NAME }, 99 { "123", DnsNameHostnameLabel, ERROR_SUCCESS, DNS_ERROR_NUMERIC_NAME }, 100 { "123.456", DnsNameHostnameLabel, ERROR_INVALID_NAME }, 101 { "g.h", DnsNameHostnameLabel, ERROR_INVALID_NAME }, 102 103 { "", DnsNameWildcard, ERROR_INVALID_NAME }, 104 { ".", DnsNameWildcard, ERROR_INVALID_NAME }, 105 { "..", DnsNameWildcard, ERROR_INVALID_NAME }, 106 { ".j", DnsNameWildcard, ERROR_INVALID_NAME }, 107 { "j.", DnsNameWildcard, ERROR_INVALID_NAME }, 108 { "j..", DnsNameWildcard, ERROR_INVALID_NAME }, 109 { "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj", DnsNameWildcard, ERROR_INVALID_NAME }, 110 { "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj.jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj.jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj.jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj", DnsNameWildcard, ERROR_INVALID_NAME }, 111 { "?", DnsNameWildcard, ERROR_INVALID_NAME }, 112 { "i ", DnsNameWildcard, ERROR_INVALID_NAME }, 113 { "_i", DnsNameWildcard, ERROR_INVALID_NAME }, 114 { "123", DnsNameWildcard, ERROR_INVALID_NAME }, 115 { "123.456", DnsNameWildcard, ERROR_INVALID_NAME }, 116 { "i.j", DnsNameWildcard, ERROR_INVALID_NAME }, 117 { "*", DnsNameWildcard, ERROR_SUCCESS }, 118 { "*j", DnsNameWildcard, DNS_ERROR_INVALID_NAME_CHAR }, 119 { "*.j", DnsNameWildcard, ERROR_SUCCESS }, 120 { "i.*", DnsNameWildcard, ERROR_INVALID_NAME }, 121 122 { "", DnsNameSrvRecord, ERROR_INVALID_NAME }, 123 { ".", DnsNameSrvRecord, ERROR_INVALID_NAME }, 124 { "..", DnsNameSrvRecord, ERROR_INVALID_NAME }, 125 { ".k", DnsNameSrvRecord, ERROR_INVALID_NAME }, 126 { "k.", DnsNameSrvRecord, ERROR_INVALID_NAME }, 127 { "k..", DnsNameSrvRecord, ERROR_INVALID_NAME }, 128 { "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk", DnsNameSrvRecord, ERROR_INVALID_NAME }, 129 { "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk.kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk.kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk.kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk", DnsNameSrvRecord, ERROR_INVALID_NAME }, 130 { "?", DnsNameSrvRecord, ERROR_INVALID_NAME }, 131 { "k ", DnsNameSrvRecord, ERROR_INVALID_NAME }, 132 { "_k", DnsNameSrvRecord, ERROR_SUCCESS }, 133 { "123", DnsNameSrvRecord, ERROR_INVALID_NAME }, 134 { "123.456", DnsNameSrvRecord, ERROR_INVALID_NAME }, 135 { "k.l", DnsNameSrvRecord, ERROR_INVALID_NAME }, 136 { "_", DnsNameSrvRecord, DNS_ERROR_NON_RFC_NAME }, 137 { "_k.l", DnsNameSrvRecord, ERROR_SUCCESS }, 138 { "k._l", DnsNameSrvRecord, ERROR_INVALID_NAME } 139 }; 140 141 static void test_DnsValidateName_A( void ) 142 { 143 unsigned int i; 144 DNS_STATUS status; 145 146 status = DnsValidateName_A( NULL, DnsNameDomain ); 147 ok( status == ERROR_INVALID_NAME, "succeeded unexpectedly\n" ); 148 149 for (i = 0; i < ARRAY_SIZE(test_data); i++) 150 { 151 status = DnsValidateName_A( test_data[i].name, test_data[i].format ); 152 ok( status == test_data[i].status || broken(status == test_data[i].status_broken), 153 "%d: \'%s\': got %d, expected %d\n", i, test_data[i].name, status, test_data[i].status ); 154 } 155 } 156 157 static void test_DnsNameCompare_A( void ) 158 { 159 static const CHAR empty[] = "", 160 dot[] = ".", 161 dotdot[] = "..", 162 A[] = "A", 163 a[] = "a", 164 B[] = "B", 165 b[] = "b", 166 A_dot_B[] = "A.B", 167 a_dot_a[] = "a.a", 168 a_dot_b[] = "a.b", 169 a_dot_b_dot[] = "a.b.", 170 a_dot_b_dotdot[] = "a.b..", 171 B_dot_A[] = "B.A", 172 b_dot_a[] = "b.a", 173 b_dot_a_dot[] = "b.a.", 174 b_dot_a_dotdot[] = "b.a.."; 175 176 ok( DnsNameCompare_A( NULL, NULL ) == TRUE, "failed unexpectedly\n" ); 177 178 ok( DnsNameCompare_A( empty, empty ) == TRUE, "failed unexpectedly\n" ); 179 ok( DnsNameCompare_A( dot, empty ) == TRUE, "failed unexpectedly\n" ); 180 ok( DnsNameCompare_A( empty, dot ) == TRUE, "failed unexpectedly\n" ); 181 ok( DnsNameCompare_A( dot, dotdot ) == TRUE, "failed unexpectedly\n" ); 182 ok( DnsNameCompare_A( dotdot, dot ) == TRUE, "failed unexpectedly\n" ); 183 ok( DnsNameCompare_A( a, a ) == TRUE, "failed unexpectedly\n" ); 184 ok( DnsNameCompare_A( a, A ) == TRUE, "failed unexpectedly\n" ); 185 ok( DnsNameCompare_A( A, a ) == TRUE, "failed unexpectedly\n" ); 186 ok( DnsNameCompare_A( a_dot_b, A_dot_B ) == TRUE, "failed unexpectedly\n" ); 187 ok( DnsNameCompare_A( a_dot_b, a_dot_b ) == TRUE, "failed unexpectedly\n" ); 188 ok( DnsNameCompare_A( a_dot_b_dot, a_dot_b_dot ) == TRUE, "failed unexpectedly\n" ); 189 ok( DnsNameCompare_A( a_dot_b_dotdot, a_dot_b_dotdot ) == TRUE, "failed unexpectedly\n" ); 190 191 ok( DnsNameCompare_A( empty, NULL ) == FALSE, "succeeded unexpectedly\n" ); 192 ok( DnsNameCompare_A( NULL, empty ) == FALSE, "succeeded unexpectedly\n" ); 193 194 ok( DnsNameCompare_A( a, b ) == FALSE, "succeeded unexpectedly\n" ); 195 ok( DnsNameCompare_A( a, B ) == FALSE, "succeeded unexpectedly\n" ); 196 ok( DnsNameCompare_A( A, b ) == FALSE, "succeeded unexpectedly\n" ); 197 ok( DnsNameCompare_A( a_dot_b, B_dot_A ) == FALSE, "succeeded unexpectedly\n" ); 198 ok( DnsNameCompare_A( a_dot_b_dot, b_dot_a_dot ) == FALSE, "succeeded unexpectedly\n" ); 199 ok( DnsNameCompare_A( a_dot_b, a_dot_a ) == FALSE, "succeeded unexpectedly\n" ); 200 ok( DnsNameCompare_A( a_dot_b_dotdot, b_dot_a_dotdot ) == FALSE, "succeeded unexpectedly\n" ); 201 ok( DnsNameCompare_A( a_dot_b_dot, b_dot_a_dotdot ) == FALSE, "succeeded unexpectedly\n" ); 202 ok( DnsNameCompare_A( a_dot_b_dotdot, b_dot_a_dot ) == FALSE, "succeeded unexpectedly\n" ); 203 ok( DnsNameCompare_A( a_dot_b_dot, b_dot_a ) == FALSE, "succeeded unexpectedly\n" ); 204 ok( DnsNameCompare_A( a_dot_b, b_dot_a_dot ) == FALSE, "succeeded unexpectedly\n" ); 205 } 206 207 static void test_DnsFlushResolverCacheEntry_A(void) 208 { 209 BOOL ret; 210 DWORD err; 211 212 SetLastError( 0xdeadbeef ); 213 ret = DnsFlushResolverCacheEntry_A( NULL ); 214 err = GetLastError(); 215 ok( !ret, "got %d\n", ret ); 216 ok( err == 0xdeadbeef, "got %u\n", err ); 217 218 ret = DnsFlushResolverCacheEntry_A( "localhost" ); 219 ok( ret, "got %d\n", ret ); 220 221 ret = DnsFlushResolverCacheEntry_A( "nxdomain.test.winehq.org" ); 222 ok( ret, "got %d\n", ret ); 223 } 224 225 START_TEST(name) 226 { 227 test_DnsValidateName_A(); 228 test_DnsNameCompare_A(); 229 test_DnsFlushResolverCacheEntry_A(); 230 } 231