dnsapi/tests: Load dnsapi dynamically and use skip.
[wine/wine64.git] / dlls / dnsapi / tests / record.c
blobee7df92ab728ab5fe80f2e9c3e956cc3be847aaa
1 /*
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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winnls.h"
27 #include "windns.h"
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 )
45 return TRUE;
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" );
59 r2.pName = name2;
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" );
71 r1.dwTtl = 0;
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 )
80 DNS_RECORD *diff1;
81 DNS_RECORD *diff2;
82 DNS_RRSET rr1, rr2;
84 r1.Flags.DW = 0x2019;
85 r2.Flags.DW = 0x2019;
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" );
101 diff1 = NULL;
102 diff2 = NULL;
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 )
131 DNS_RRSET rr;
132 DNS_RECORDA *r, *s;
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" );
142 r = rr.pFirstRR;
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" );
150 START_TEST(record)
152 dnsapi = LoadLibraryA( "dnsapi.dll" );
153 if (!dnsapi)
155 /* Doesn't exist before W2K */
156 skip("dnsapi.dll cannot be loaded\n");
157 return;
160 if (!init_function_ptrs())
162 skip("Needed functions are not available\n");
163 FreeLibrary( dnsapi );
164 return;
167 test_DnsRecordCompare();
168 test_DnsRecordSetCompare();
169 test_DnsRecordSetDetach();
171 FreeLibrary( dnsapi );