2 * Tests for record 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
29 #include "wine/test.h"
31 static HMODULE dnsapi;
33 static BOOL (WINAPI *pDnsRecordCompare)(PDNS_RECORD,PDNS_RECORD);
34 static BOOL (WINAPI *pDnsRecordSetCompare)(PDNS_RECORD,PDNS_RECORD,PDNS_RECORD*,PDNS_RECORD*);
35 static DNS_RECORD* (WINAPI *pDnsRecordSetDetach)(PDNS_RECORD);
37 #define GETFUNCPTR(func) p##func = (void *)GetProcAddress( dnsapi, #func ); \
38 if (!p##func) return FALSE;
40 static BOOL init_function_ptrs( void )
42 GETFUNCPTR( DnsRecordCompare )
43 GETFUNCPTR( DnsRecordSetCompare )
44 GETFUNCPTR( DnsRecordSetDetach )
48 static char name1[] = "localhost";
49 static char name2[] = "LOCALHOST";
51 static DNS_RECORDA r1 = { NULL, name1, DNS_TYPE_A, sizeof(DNS_A_DATA), { 0 }, 1200, 0, { { 0xffffffff } } };
52 static DNS_RECORDA r2 = { NULL, name1, DNS_TYPE_A, sizeof(DNS_A_DATA), { 0 }, 1200, 0, { { 0xffffffff } } };
53 static DNS_RECORDA r3 = { NULL, name1, DNS_TYPE_A, sizeof(DNS_A_DATA), { 0 }, 1200, 0, { { 0xffffffff } } };
55 static void test_DnsRecordCompare( void )
57 ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r1 ) == TRUE, "failed unexpectedly\n" );
60 ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r2 ) == TRUE, "failed unexpectedly\n" );
62 r2.Flags.S.CharSet = DnsCharSetUnicode;
63 ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r2 ) == FALSE, "succeeded unexpectedly\n" );
65 r2.Flags.S.CharSet = DnsCharSetAnsi;
66 ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r2 ) == FALSE, "succeeded unexpectedly\n" );
68 r1.Flags.S.CharSet = DnsCharSetAnsi;
69 ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r2 ) == TRUE, "failed unexpectedly\n" );
72 ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r2 ) == TRUE, "failed unexpectedly\n" );
74 r2.Data.A.IpAddress = 0;
75 ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r2 ) == FALSE, "succeeded unexpectedly\n" );
78 static void test_DnsRecordSetCompare( void )
86 r2.Data.A.IpAddress = 0xffffffff;
88 DNS_RRSET_INIT( rr1 );
89 DNS_RRSET_INIT( rr2 );
91 DNS_RRSET_ADD( rr1, &r1 );
92 DNS_RRSET_ADD( rr2, &r2 );
94 DNS_RRSET_TERMINATE( rr1 );
95 DNS_RRSET_TERMINATE( rr2 );
97 ok( pDnsRecordSetCompare( NULL, NULL, NULL, NULL ) == FALSE, "succeeded unexpectedly\n" );
98 ok( pDnsRecordSetCompare( rr1.pFirstRR, NULL, NULL, NULL ) == FALSE, "succeeded unexpectedly\n" );
99 ok( pDnsRecordSetCompare( NULL, rr2.pFirstRR, NULL, NULL ) == FALSE, "succeeded unexpectedly\n" );
104 ok( pDnsRecordSetCompare( NULL, NULL, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
105 ok( diff1 == NULL && diff2 == NULL, "unexpected result: %p, %p\n", diff1, diff2 );
107 ok( pDnsRecordSetCompare( rr1.pFirstRR, NULL, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
108 ok( diff1 != NULL && diff2 == NULL, "unexpected result: %p, %p\n", diff1, diff2 );
110 ok( pDnsRecordSetCompare( NULL, rr2.pFirstRR, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
111 ok( diff1 == NULL && diff2 != NULL, "unexpected result: %p, %p\n", diff1, diff2 );
113 ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, NULL, &diff2 ) == TRUE, "failed unexpectedly\n" );
114 ok( diff2 == NULL, "unexpected result: %p\n", diff2 );
116 ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, NULL ) == TRUE, "failed unexpectedly\n" );
117 ok( diff1 == NULL, "unexpected result: %p\n", diff1 );
119 ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, &diff2 ) == TRUE, "failed unexpectedly\n" );
120 ok( diff1 == NULL && diff2 == NULL, "unexpected result: %p, %p\n", diff1, diff2 );
122 r2.Data.A.IpAddress = 0;
124 ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, NULL, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
125 ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, NULL ) == FALSE, "succeeded unexpectedly\n" );
126 ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
129 static void test_DnsRecordSetDetach( void )
134 DNS_RRSET_INIT( rr );
135 DNS_RRSET_ADD( rr, &r1 );
136 DNS_RRSET_ADD( rr, &r2 );
137 DNS_RRSET_ADD( rr, &r3 );
138 DNS_RRSET_TERMINATE( rr );
140 ok( !pDnsRecordSetDetach( NULL ), "succeeded unexpectedly\n" );
143 s = pDnsRecordSetDetach( r );
145 ok( s == &r3, "failed unexpectedly: got %p, expected %p\n", s, &r3 );
146 ok( r == &r1, "failed unexpectedly: got %p, expected %p\n", r, &r1 );
147 ok( !r2.pNext, "failed unexpectedly\n" );
152 dnsapi = LoadLibraryA( "dnsapi.dll" );
155 if (!init_function_ptrs())
157 FreeLibrary( dnsapi );
161 test_DnsRecordCompare();
162 test_DnsRecordSetCompare();
163 test_DnsRecordSetDetach();
165 FreeLibrary( dnsapi );