wined3d: Add the bulk of the GLSL string generation functions.
[wine] / dlls / dnsapi / tests / record.c
1 /*
2  * Tests for record 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 #include <stdio.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winnls.h"
27 #include "windns.h"
28
29 #include "wine/test.h"
30
31 static HMODULE dnsapi;
32
33 static BOOL        (WINAPI *pDnsRecordCompare)(PDNS_RECORD,PDNS_RECORD);
34 static BOOL        (WINAPI *pDnsRecordSetCompare)(PDNS_RECORD,PDNS_RECORD,PDNS_RECORD*,PDNS_RECORD*);
35
36 #define GETFUNCPTR(func) p##func = (void *)GetProcAddress( dnsapi, #func ); \
37     if (!p##func) return FALSE;
38
39 static BOOL init_function_ptrs( void )
40 {
41     GETFUNCPTR( DnsRecordCompare )
42     GETFUNCPTR( DnsRecordSetCompare )
43     return TRUE;
44 }
45
46 static char name1[] = "localhost";
47 static char name2[] = "LOCALHOST";
48
49 static DNS_RECORDA r1 = { NULL, name1, DNS_TYPE_A, sizeof(DNS_A_DATA), { 0 }, 1200, 0, { { 0xffffffff } } };
50 static DNS_RECORDA r2 = { NULL, name1, DNS_TYPE_A, sizeof(DNS_A_DATA), { 0 }, 1200, 0, { { 0xffffffff } } };
51
52 static void test_DnsRecordCompare( void )
53 {
54     ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r1 ) == TRUE, "failed unexpectedly\n" );
55
56     r2.pName = name2;
57     ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r2 ) == TRUE, "failed unexpectedly\n" );
58
59     r2.Flags.S.CharSet = DnsCharSetUnicode;
60     ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r2 ) == FALSE, "succeeded unexpectedly\n" );
61
62     r2.Flags.S.CharSet = DnsCharSetAnsi;
63     ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r2 ) == FALSE, "succeeded unexpectedly\n" );
64
65     r1.Flags.S.CharSet = DnsCharSetAnsi;
66     ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r2 ) == TRUE, "failed unexpectedly\n" );
67
68     r1.dwTtl = 0;
69     ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r2 ) == TRUE, "failed unexpectedly\n" );
70
71     r2.Data.A.IpAddress = 0;
72     ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r2 ) == FALSE, "succeeded unexpectedly\n" );
73 }
74
75 static void test_DnsRecordSetCompare( void )
76 {
77     DNS_RECORD *diff1;
78     DNS_RECORD *diff2;
79     DNS_RRSET rr1, rr2;
80
81     r1.Flags.DW = 0x2019;
82     r2.Flags.DW = 0x2019;
83     r2.Data.A.IpAddress = 0xffffffff;
84
85     DNS_RRSET_INIT( rr1 );
86     DNS_RRSET_INIT( rr2 );
87
88     DNS_RRSET_ADD( rr1, &r1 );
89     DNS_RRSET_ADD( rr2, &r2 );
90
91     DNS_RRSET_TERMINATE( rr1 );
92     DNS_RRSET_TERMINATE( rr2 );
93
94     ok( pDnsRecordSetCompare( NULL, NULL, NULL, NULL ) == FALSE, "succeeded unexpectedly\n" );
95     ok( pDnsRecordSetCompare( rr1.pFirstRR, NULL, NULL, NULL ) == FALSE, "succeeded unexpectedly\n" );
96     ok( pDnsRecordSetCompare( NULL, rr2.pFirstRR, NULL, NULL ) == FALSE, "succeeded unexpectedly\n" );
97
98     diff1 = NULL;
99     diff2 = NULL;
100
101     ok( pDnsRecordSetCompare( NULL, NULL, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
102     ok( diff1 == NULL && diff2 == NULL, "unexpected result: %p, %p\n", diff1, diff2 );
103
104     ok( pDnsRecordSetCompare( rr1.pFirstRR, NULL, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
105     ok( diff1 != NULL && diff2 == NULL, "unexpected result: %p, %p\n", diff1, diff2 );
106
107     ok( pDnsRecordSetCompare( NULL, rr2.pFirstRR, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
108     ok( diff1 == NULL && diff2 != NULL, "unexpected result: %p, %p\n", diff1, diff2 );
109
110     ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, NULL, &diff2 ) == TRUE, "failed unexpectedly\n" );
111     ok( diff2 == NULL, "unexpected result: %p\n", diff2 );
112
113     ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, NULL ) == TRUE, "failed unexpectedly\n" );
114     ok( diff1 == NULL, "unexpected result: %p\n", diff1 );
115
116     ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, &diff2 ) == TRUE, "failed unexpectedly\n" );
117     ok( diff1 == NULL && diff2 == NULL, "unexpected result: %p, %p\n", diff1, diff2 );
118
119     r2.Data.A.IpAddress = 0;
120
121     ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, NULL, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
122     ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, NULL ) == FALSE, "succeeded unexpectedly\n" );
123     ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
124 }
125
126 START_TEST(record)
127 {
128     dnsapi = LoadLibraryA( "dnsapi.dll" );
129     if (!dnsapi) return;
130
131     if (!init_function_ptrs())
132     {
133         FreeLibrary( dnsapi );
134         return;
135     }
136
137     test_DnsRecordCompare();
138     test_DnsRecordSetCompare();
139
140     FreeLibrary( dnsapi );
141 }