Commit efe9ceda authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

dnsapi: Implement and test DnsRecordSetCompare.

parent 969ae13e
......@@ -86,7 +86,7 @@
@ stdcall DnsRecordCompare(ptr ptr)
@ stdcall DnsRecordCopyEx(ptr long long)
@ stdcall DnsRecordListFree(ptr long)
@ stub DnsRecordSetCompare
@ stdcall DnsRecordSetCompare(ptr ptr ptr ptr)
@ stdcall DnsRecordSetCopyEx(ptr long long)
@ stub DnsRecordSetDetach
@ stub DnsRecordStringForType
......
......@@ -640,6 +640,88 @@ void WINAPI DnsRecordListFree( PDNS_RECORD list, DNS_FREE_TYPE type )
}
/******************************************************************************
* DnsRecordSetCompare [DNSAPI.@]
*
*/
BOOL WINAPI DnsRecordSetCompare( PDNS_RECORD set1, PDNS_RECORD set2,
PDNS_RECORD *diff1, PDNS_RECORD *diff2 )
{
BOOL ret = TRUE;
DNS_RECORD *r, *s1, *s2, *t, *u;
DNS_RRSET rr1, rr2;
TRACE( "(%p,%p,%p,%p)\n", set1, set2, diff1, diff2 );
if (!set1 && !set2) return FALSE;
if (diff1) *diff1 = NULL;
if (diff2) *diff2 = NULL;
if (set1 && !set2)
{
if (diff1) *diff1 = DnsRecordSetCopyEx( set1, 0, set1->Flags.S.CharSet );
return FALSE;
}
if (!set1 && set2)
{
if (diff2) *diff2 = DnsRecordSetCopyEx( set2, 0, set2->Flags.S.CharSet );
return FALSE;
}
DNS_RRSET_INIT( rr1 );
DNS_RRSET_INIT( rr2 );
for (r = s1 = set1; (s1 = r); r = r->pNext)
{
for (t = s2 = set2; (s2 = t); t = t->pNext)
{
u = DnsRecordCopyEx( r, r->Flags.S.CharSet, t->Flags.S.CharSet );
if (!u) goto error;
if (!DnsRecordCompare( t, u ))
{
DNS_RRSET_ADD( rr1, u );
ret = FALSE;
}
else dns_free( u );
}
}
for (t = s2 = set2; (s2 = t); t = t->pNext)
{
for (r = s1 = set1; (s1 = r); r = r->pNext)
{
u = DnsRecordCopyEx( t, t->Flags.S.CharSet, r->Flags.S.CharSet );
if (!u) goto error;
if (!DnsRecordCompare( r, u ))
{
DNS_RRSET_ADD( rr2, u );
ret = FALSE;
}
else dns_free( u );
}
}
DNS_RRSET_TERMINATE( rr1 );
DNS_RRSET_TERMINATE( rr2 );
if (diff1) *diff1 = rr1.pFirstRR;
if (diff2) *diff2 = rr2.pFirstRR;
return ret;
error:
DNS_RRSET_TERMINATE( rr1 );
DNS_RRSET_TERMINATE( rr2 );
DnsRecordListFree( rr1.pFirstRR, DnsFreeRecordList );
DnsRecordListFree( rr2.pFirstRR, DnsFreeRecordList );
return FALSE;
}
/******************************************************************************
* DnsRecordSetCopyEx [DNSAPI.@]
*
*/
......
......@@ -19,6 +19,7 @@
*/
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
......@@ -30,6 +31,7 @@
static HMODULE dnsapi;
static BOOL (WINAPI *pDnsRecordCompare)(PDNS_RECORD,PDNS_RECORD);
static BOOL (WINAPI *pDnsRecordSetCompare)(PDNS_RECORD,PDNS_RECORD,PDNS_RECORD*,PDNS_RECORD*);
#define GETFUNCPTR(func) p##func = (void *)GetProcAddress( dnsapi, #func ); \
if (!p##func) return FALSE;
......@@ -37,25 +39,18 @@ static BOOL (WINAPI *pDnsRecordCompare)(PDNS_RECORD,PDNS_RECORD);
static BOOL init_function_ptrs( void )
{
GETFUNCPTR( DnsRecordCompare )
GETFUNCPTR( DnsRecordSetCompare )
return TRUE;
}
static char name1[] = "localhost";
static char name2[] = "LOCALHOST";
static DNS_RECORDA r1 = { NULL, name1, DNS_TYPE_A, sizeof(DNS_A_DATA), { 0 }, 1200, 0, { { 0xffffffff } } };
static DNS_RECORDA r2 = { NULL, name1, DNS_TYPE_A, sizeof(DNS_A_DATA), { 0 }, 1200, 0, { { 0xffffffff } } };
static void test_DnsRecordCompare( void )
{
char name1[] = "localhost";
char name2[] = "LOCALHOST";
static DNS_RECORDA r1, r2;
r1.pName = name1;
r1.wType = DNS_TYPE_A;
r1.wDataLength = sizeof(DNS_A_DATA);
r1.Data.A.IpAddress = 0xffffffff;
r2.pName = name1;
r2.wType = DNS_TYPE_A;
r2.wDataLength = sizeof(DNS_A_DATA);
r2.Data.A.IpAddress = 0xffffffff;
ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r1 ) == TRUE, "failed unexpectedly\n" );
r2.pName = name2;
......@@ -74,6 +69,57 @@ static void test_DnsRecordCompare( void )
ok( pDnsRecordCompare( (PDNS_RECORD)&r1, (PDNS_RECORD)&r2 ) == FALSE, "succeeded unexpectedly\n" );
}
static void test_DnsRecordSetCompare( void )
{
DNS_RECORD *diff1;
DNS_RECORD *diff2;
DNS_RRSET rr1, rr2;
r1.Flags.DW = 0x2019;
r2.Flags.DW = 0x2019;
r2.Data.A.IpAddress = 0xffffffff;
DNS_RRSET_INIT( rr1 );
DNS_RRSET_INIT( rr2 );
DNS_RRSET_ADD( rr1, &r1 );
DNS_RRSET_ADD( rr2, &r2 );
DNS_RRSET_TERMINATE( rr1 );
DNS_RRSET_TERMINATE( rr2 );
ok( pDnsRecordSetCompare( NULL, NULL, NULL, NULL ) == FALSE, "succeeded unexpectedly\n" );
ok( pDnsRecordSetCompare( rr1.pFirstRR, NULL, NULL, NULL ) == FALSE, "succeeded unexpectedly\n" );
ok( pDnsRecordSetCompare( NULL, rr2.pFirstRR, NULL, NULL ) == FALSE, "succeeded unexpectedly\n" );
diff1 = NULL;
diff2 = NULL;
ok( pDnsRecordSetCompare( NULL, NULL, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
ok( diff1 == NULL && diff2 == NULL, "unexpected result: %p, %p\n", diff1, diff2 );
ok( pDnsRecordSetCompare( rr1.pFirstRR, NULL, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
ok( diff1 != NULL && diff2 == NULL, "unexpected result: %p, %p\n", diff1, diff2 );
ok( pDnsRecordSetCompare( NULL, rr2.pFirstRR, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
ok( diff1 == NULL && diff2 != NULL, "unexpected result: %p, %p\n", diff1, diff2 );
ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, NULL, &diff2 ) == TRUE, "failed unexpectedly\n" );
ok( diff2 == NULL, "unexpected result: %p\n", diff2 );
ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, NULL ) == TRUE, "failed unexpectedly\n" );
ok( diff1 == NULL, "unexpected result: %p\n", diff1 );
ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, &diff2 ) == TRUE, "failed unexpectedly\n" );
ok( diff1 == NULL && diff2 == NULL, "unexpected result: %p, %p\n", diff1, diff2 );
r2.Data.A.IpAddress = 0;
ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, NULL, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, NULL ) == FALSE, "succeeded unexpectedly\n" );
ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" );
}
START_TEST(record)
{
dnsapi = LoadLibraryA( "dnsapi.dll" );
......@@ -86,6 +132,7 @@ START_TEST(record)
}
test_DnsRecordCompare();
test_DnsRecordSetCompare();
FreeLibrary( dnsapi );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment