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 #define UNICODE
22 
23 #include <wine/test.h>
24 
25 //#include <stdarg.h>
26 //#include <stdio.h>
27 
28 //#include "windef.h"
29 //#include "winbase.h"
30 //#include "winnls.h"
31 #include <windns.h>
32 
33 static WCHAR name1[] = {'l','o','c','a','l','h','o','s','t',0};
34 static WCHAR name2[] = {'L','O','C','A','L','H','O','S','T',0};
35 
36 static DNS_RECORDW r1 = { NULL, name1, DNS_TYPE_A, sizeof(DNS_A_DATA), { 0 }, 1200, 0, { { 0xffffffff } } };
37 static DNS_RECORDW r2 = { NULL, name1, DNS_TYPE_A, sizeof(DNS_A_DATA), { 0 }, 1200, 0, { { 0xffffffff } } };
38 static DNS_RECORDW r3 = { NULL, name1, DNS_TYPE_A, sizeof(DNS_A_DATA), { 0 }, 1200, 0, { { 0xffffffff } } };
39 
40 static void test_DnsRecordCompare( void )
41 {
42     ok( DnsRecordCompare( &r1, &r1 ) == TRUE, "failed unexpectedly\n" );
43 
44     r2.pName = name2;
45     ok( DnsRecordCompare( &r1, &r2 ) == TRUE, "failed unexpectedly\n" );
46 
47     r2.Flags.S.CharSet = DnsCharSetUnicode;
48     ok( DnsRecordCompare( &r1, &r2 ) == TRUE, "failed unexpectedly\n" );
49 
50     r2.Flags.S.CharSet = DnsCharSetAnsi;
51     ok( DnsRecordCompare( &r1, &r2 ) == TRUE, "failed unexpectedly\n" );
52 
53     r1.Flags.S.CharSet = DnsCharSetAnsi;
54     ok( DnsRecordCompare( &r1, &r2 ) == TRUE, "failed unexpectedly\n" );
55 
56     r1.dwTtl = 0;
57     ok( DnsRecordCompare( &r1, &r2 ) == TRUE, "failed unexpectedly\n" );
58 
59     r2.Data.A.IpAddress = 0;
60     ok( DnsRecordCompare( &r1, &r2 ) == FALSE, "succeeded unexpectedly\n" );
61 }
62 
63 static void test_DnsRecordSetCompare( void )
64 {
65     DNS_RECORDW *diff1;
66     DNS_RECORDW *diff2;
67     DNS_RRSET rr1, rr2;
68 
69     r1.Flags.DW = 0x2019;
70     r2.Flags.DW = 0x2019;
71     r2.Data.A.IpAddress = 0xffffffff;
72 
73     DNS_RRSET_INIT( rr1 );
74     DNS_RRSET_INIT( rr2 );
75 
76     DNS_RRSET_ADD( rr1, &r1 );
77     DNS_RRSET_ADD( rr2, &r2 );
78 
79     DNS_RRSET_TERMINATE( rr1 );
80     DNS_RRSET_TERMINATE( rr2 );
81 
82     ok( DnsRecordSetCompare( NULL, NULL, NULL, NULL ) == FALSE, "succeeded unexpectedly\n" );
83     ok( DnsRecordSetCompare( rr1.pFirstRR, NULL, NULL, NULL ) == FALSE, "succeeded unexpectedly\n" );
84     ok( DnsRecordSetCompare( NULL, rr2.pFirstRR, NULL, NULL ) == FALSE, "succeeded unexpectedly\n" );
85 
86     diff1 = NULL;
87     diff2 = NULL;
88 
89     ok( DnsRecordSetCompare( NULL, NULL, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
90     ok( diff1 == NULL && diff2 == NULL, "unexpected result: %p, %p\n", diff1, diff2 );
91 
92     ok( DnsRecordSetCompare( rr1.pFirstRR, NULL, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
93     ok( diff1 != NULL && diff2 == NULL, "unexpected result: %p, %p\n", diff1, diff2 );
94     DnsRecordListFree( diff1, DnsFreeRecordList );
95 
96     ok( DnsRecordSetCompare( NULL, rr2.pFirstRR, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
97     ok( diff1 == NULL && diff2 != NULL, "unexpected result: %p, %p\n", diff1, diff2 );
98     DnsRecordListFree( diff2, DnsFreeRecordList );
99 
100     ok( DnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, NULL, &diff2 ) == TRUE, "failed unexpectedly\n" );
101     ok( diff2 == NULL, "unexpected result: %p\n", diff2 );
102 
103     ok( DnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, NULL ) == TRUE, "failed unexpectedly\n" );
104     ok( diff1 == NULL, "unexpected result: %p\n", diff1 );
105 
106     ok( DnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, &diff2 ) == TRUE, "failed unexpectedly\n" );
107     ok( diff1 == NULL && diff2 == NULL, "unexpected result: %p, %p\n", diff1, diff2 );
108 
109     r2.Data.A.IpAddress = 0;
110 
111     ok( DnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, NULL, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
112     DnsRecordListFree( diff2, DnsFreeRecordList );
113 
114     ok( DnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, NULL ) == FALSE, "succeeded unexpectedly\n" );
115     DnsRecordListFree( diff1, DnsFreeRecordList );
116 
117     ok( DnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
118     DnsRecordListFree( diff1, DnsFreeRecordList );
119     DnsRecordListFree( diff2, DnsFreeRecordList );
120 }
121 
122 static void test_DnsRecordSetDetach( void )
123 {
124     DNS_RRSET rr;
125     DNS_RECORDW *r, *s;
126 
127     DNS_RRSET_INIT( rr );
128     DNS_RRSET_ADD( rr, &r1 );
129     DNS_RRSET_ADD( rr, &r2 );
130     DNS_RRSET_ADD( rr, &r3 );
131     DNS_RRSET_TERMINATE( rr );
132 
133     ok( !DnsRecordSetDetach( NULL ), "succeeded unexpectedly\n" );
134 
135     r = rr.pFirstRR;
136     s = DnsRecordSetDetach( r );
137 
138     ok( s == &r3, "failed unexpectedly: got %p, expected %p\n", s, &r3 );
139     ok( r == &r1, "failed unexpectedly: got %p, expected %p\n", r, &r1 );
140     ok( !r2.pNext, "failed unexpectedly\n" );
141 }
142 
143 START_TEST(record)
144 {
145     test_DnsRecordCompare();
146     test_DnsRecordSetCompare();
147     test_DnsRecordSetDetach();
148 }
149