From 0c0d1903761c37b9da0bebf5b8712a08e86fa9cd Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Wed, 13 Sep 2006 14:36:33 +0200 Subject: [PATCH] dnsapi: Implement and test DnsRecordSetDetach. --- dlls/dnsapi/dnsapi.spec | 2 +- dlls/dnsapi/record.c | 22 ++++++++++++++++++++++ dlls/dnsapi/tests/record.c | 25 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/dlls/dnsapi/dnsapi.spec b/dlls/dnsapi/dnsapi.spec index 2d00d38ef9e..977bde48a20 100644 --- a/dlls/dnsapi/dnsapi.spec +++ b/dlls/dnsapi/dnsapi.spec @@ -88,7 +88,7 @@ @ stdcall DnsRecordListFree(ptr long) @ stdcall DnsRecordSetCompare(ptr ptr ptr ptr) @ stdcall DnsRecordSetCopyEx(ptr long long) -@ stub DnsRecordSetDetach +@ stdcall DnsRecordSetDetach(ptr) @ stub DnsRecordStringForType @ stub DnsRecordStringForWritableType @ stub DnsRecordTypeForName diff --git a/dlls/dnsapi/record.c b/dlls/dnsapi/record.c index ee8062b939b..0c34697157f 100644 --- a/dlls/dnsapi/record.c +++ b/dlls/dnsapi/record.c @@ -748,3 +748,25 @@ PDNS_RECORD WINAPI DnsRecordSetCopyEx( PDNS_RECORD src_set, DNS_CHARSET in, DNS_ DNS_RRSET_TERMINATE( dst_set ); return dst_set.pFirstRR; } + +/****************************************************************************** + * DnsRecordSetDetach [DNSAPI.@] + * + */ +PDNS_RECORD WINAPI DnsRecordSetDetach( PDNS_RECORD set ) +{ + DNS_RECORD *r, *s; + + TRACE( "(%p)\n", set ); + + for (r = set; (set = r); r = set->pNext) + { + if (r->pNext && !r->pNext->pNext) + { + s = r->pNext; + r->pNext = NULL; + return s; + } + } + return NULL; +} diff --git a/dlls/dnsapi/tests/record.c b/dlls/dnsapi/tests/record.c index b0e34c7c4bb..7da1c295996 100644 --- a/dlls/dnsapi/tests/record.c +++ b/dlls/dnsapi/tests/record.c @@ -32,6 +32,7 @@ static HMODULE dnsapi; static BOOL (WINAPI *pDnsRecordCompare)(PDNS_RECORD,PDNS_RECORD); static BOOL (WINAPI *pDnsRecordSetCompare)(PDNS_RECORD,PDNS_RECORD,PDNS_RECORD*,PDNS_RECORD*); +static DNS_RECORD* (WINAPI *pDnsRecordSetDetach)(PDNS_RECORD); #define GETFUNCPTR(func) p##func = (void *)GetProcAddress( dnsapi, #func ); \ if (!p##func) return FALSE; @@ -40,6 +41,7 @@ static BOOL init_function_ptrs( void ) { GETFUNCPTR( DnsRecordCompare ) GETFUNCPTR( DnsRecordSetCompare ) + GETFUNCPTR( DnsRecordSetDetach ) return TRUE; } @@ -48,6 +50,7 @@ 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 DNS_RECORDA r3 = { NULL, name1, DNS_TYPE_A, sizeof(DNS_A_DATA), { 0 }, 1200, 0, { { 0xffffffff } } }; static void test_DnsRecordCompare( void ) { @@ -123,6 +126,27 @@ static void test_DnsRecordSetCompare( void ) ok( pDnsRecordSetCompare( rr1.pFirstRR, rr2.pFirstRR, &diff1, &diff2 ) == FALSE, "succeeded unexpectedly\n" ); } +static void test_DnsRecordSetDetach( void ) +{ + DNS_RRSET rr; + DNS_RECORDA *r, *s; + + DNS_RRSET_INIT( rr ); + DNS_RRSET_ADD( rr, &r1 ); + DNS_RRSET_ADD( rr, &r2 ); + DNS_RRSET_ADD( rr, &r3 ); + DNS_RRSET_TERMINATE( rr ); + + ok( !pDnsRecordSetDetach( NULL ), "succeeded unexpectedly\n" ); + + r = rr.pFirstRR; + s = pDnsRecordSetDetach( r ); + + ok( s == &r3, "failed unexpectedly: got %p, expected %p\n", s, &r3 ); + ok( r == &r1, "failed unexpectedly: got %p, expected %p\n", r, &r1 ); + ok( !r2.pNext, "failed unexpectedly\n" ); +} + START_TEST(record) { dnsapi = LoadLibraryA( "dnsapi.dll" ); @@ -136,6 +160,7 @@ START_TEST(record) test_DnsRecordCompare(); test_DnsRecordSetCompare(); + test_DnsRecordSetDetach(); FreeLibrary( dnsapi ); }