Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -41,11 +41,12 @@ ${USE_SRCS_SUBPROCESSES} \ ${USE_SRCS_THREADS} \ testfile_bin.m \ testfile_ini.m SRCS_PLUGINS = OFPluginTests.m -SRCS_SOCKETS = OFSocketTests.m +SRCS_SOCKETS = OFDNSResolverTests.m \ + OFSocketTests.m SRCS_SUBPROCESSES = OFSubprocessTests.m SRCS_THREADS = OFThreadTests.m include ../buildsys.mk ADDED new_tests/OFDNSResolverTests.m Index: new_tests/OFDNSResolverTests.m ================================================================== --- new_tests/OFDNSResolverTests.m +++ new_tests/OFDNSResolverTests.m @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "ObjFW.h" +#import "ObjFWTest.h" + +@interface OFDNSResolverTests: OTTestCase +@end + +@implementation OFDNSResolverTests ++ (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, id) *) *)summary +{ + OFMutableArray *summary = [OFMutableArray array]; + OFDNSResolver *resolver = [OFDNSResolver resolver]; + OFMutableString *staticHosts = [OFMutableString string]; + +#define ADD(name, value) \ + [summary addObject: [OFPair pairWithFirstObject: name \ + secondObject: value]]; +#define ADD_DOUBLE(name, value) \ + ADD(name, [OFNumber numberWithDouble: value]) +#define ADD_UINT(name, value) \ + ADD(name, [OFNumber numberWithUnsignedInt: value]); +#define ADD_BOOL(name, value) \ + ADD(name, [OFNumber numberWithBool: value]); + + for (OFString *host in resolver.staticHosts) { + OFString *IPs; + + if (staticHosts.length > 0) + [staticHosts appendString: @"; "]; + + IPs = [[resolver.staticHosts objectForKey: host] + componentsJoinedByString: @", "]; + + [staticHosts appendFormat: @"%@=(%@)", host, IPs]; + } + ADD(@"Static hosts", staticHosts) + + ADD(@"Name servers", + [resolver.nameServers componentsJoinedByString: @", "]); + ADD(@"Local domain", resolver.localDomain); + ADD(@"Search domains", + [resolver.searchDomains componentsJoinedByString: @", "]); + + ADD_DOUBLE(@"Timeout", resolver.timeout); + ADD_UINT(@"Max attempts", resolver.maxAttempts); + ADD_UINT(@"Min number of dots in absolute name", + resolver.minNumberOfDotsInAbsoluteName); + ADD_BOOL(@"Forces TCP", resolver.forcesTCP); + ADD_DOUBLE(@"Config reload interval", resolver.configReloadInterval); + +#undef ADD +#undef ADD_DOUBLE +#undef ADD_UINT +#undef ADD_BOOL + + return summary; +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -32,12 +32,11 @@ ${RUNTIME_ARC_TESTS_M} \ TestsAppDelegate.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_WINDOWS} -SRCS_SOCKETS = OFDNSResolverTests.m \ - ${OF_HTTP_CLIENT_TESTS_M} \ +SRCS_SOCKETS = ${OF_HTTP_CLIENT_TESTS_M} \ OFHTTPCookieTests.m \ OFHTTPCookieManagerTests.m \ OFKernelEventObserverTests.m \ OFTCPSocketTests.m \ OFUDPSocketTests.m \ DELETED tests/OFDNSResolverTests.m Index: tests/OFDNSResolverTests.m ================================================================== --- tests/OFDNSResolverTests.m +++ tests/OFDNSResolverTests.m @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "TestsAppDelegate.h" - -@implementation TestsAppDelegate (OFDNSResolverTests) -- (void)DNSResolverTests -{ - void *pool = objc_autoreleasePoolPush(); - OFDNSResolver *resolver = [OFDNSResolver resolver]; - OFMutableString *staticHosts = [OFMutableString string]; - - [OFStdOut setForegroundColor: [OFColor lime]]; - - for (OFString *host in resolver.staticHosts) { - OFString *IPs; - - if (staticHosts.length > 0) - [staticHosts appendString: @"; "]; - - IPs = [[resolver.staticHosts objectForKey: host] - componentsJoinedByString: @", "]; - - [staticHosts appendFormat: @"%@=(%@)", host, IPs]; - } - [OFStdOut writeFormat: @"[OFDNSResolver] Static hosts: %@\n", - staticHosts]; - - [OFStdOut writeFormat: @"[OFDNSResolver] Name servers: %@\n", - [resolver.nameServers componentsJoinedByString: @", "]]; - - [OFStdOut writeFormat: @"[OFDNSResolver] Local domain: %@\n", - resolver.localDomain]; - - [OFStdOut writeFormat: @"[OFDNSResolver] Search domains: %@\n", - [resolver.searchDomains componentsJoinedByString: @", "]]; - - [OFStdOut writeFormat: @"[OFDNSResolver] Timeout: %lf\n", - resolver.timeout]; - - [OFStdOut writeFormat: @"[OFDNSResolver] Max attempts: %u\n", - resolver.maxAttempts]; - - [OFStdOut writeFormat: - @"[OFDNSResolver] Min number of dots in absolute name: %u\n", - resolver.minNumberOfDotsInAbsoluteName]; - - [OFStdOut writeFormat: @"[OFDNSResolver] Forces TCP: %u\n", - resolver.forcesTCP]; - - [OFStdOut writeFormat: - @"[OFDNSResolver] Config reload interval: %lf\n", - resolver.configReloadInterval]; - - objc_autoreleasePoolPop(pool); -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -65,14 +65,10 @@ @interface TestsAppDelegate (OFDDPSocketTests) - (void)DDPSocketTests; @end -@interface TestsAppDelegate (OFDNSResolverTests) -- (void)DNSResolverTests; -@end - @interface TestsAppDelegate (OFDataTests) - (void)dataTests; @end @interface TestsAppDelegate (OFDictionaryTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -417,13 +417,10 @@ #ifdef OF_WINDOWS [self windowsRegistryKeyTests]; #endif -#ifdef OF_HAVE_SOCKETS - [self DNSResolverTests]; -#endif [self localeTests]; [OFStdOut reset]; #if defined(OF_IOS)