Tuukka Norri avatar Tuukka Norri committed 3f305d3

Added tests for BXHostRsolver (fixes #222)
- Also removed references to CFHost from where they aren't needed.

Comments (0)

Files changed (6)

Sources/BXHostResolver.m

 #import "BXLogger.h"
 #import "BXError.h"
 #import "BXConstants.h"
+#import "BXCFHostCompatibility.h"
 #import <SystemConfiguration/SystemConfiguration.h>
 #import <netdb.h>
 

Sources/PGTSConnector.h

 //
 
 #import <Foundation/Foundation.h>
-#import <BaseTen/BXCFHostCompatibility.h> 
 #import <BaseTen/BXExport.h>
 #import <BaseTen/libpq-fe.h>
 

UnitTests/Sources/BXHostResolverTests.h

+//
+// BXHostResolverTests.h
+// BaseTen
+//
+// Copyright (C) 2010 Marko Karppinen & Co. LLC.
+//
+// Before using this software, please review the available licensing options
+// by visiting http://basetenframework.org/licensing/ or by contacting
+// us at sales@karppinen.fi. Without an additional license, this software
+// may be distributed only in compliance with the GNU General Public License.
+//
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License, version 2.0,
+// as published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+// $Id$
+//
+
+#import "BXTestCase.h"
+
+
+@interface BXHostResolverTests : BXTestCase
+{
+}
+@end

UnitTests/Sources/BXHostResolverTests.m

+//
+// BXHostResolverTests.m
+// BaseTen
+//
+// Copyright (C) 2010 Marko Karppinen & Co. LLC.
+//
+// Before using this software, please review the available licensing options
+// by visiting http://basetenframework.org/licensing/ or by contacting
+// us at sales@karppinen.fi. Without an additional license, this software
+// may be distributed only in compliance with the GNU General Public License.
+//
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License, version 2.0,
+// as published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+// $Id$
+//
+
+#import "BXHostResolverTests.h"
+#import <BaseTen/BXHostResolver.h>
+#import <OCMock/OCMock.h>
+
+
+@implementation BXHostResolverTests
+- (void) runResolverForNodename: (NSString *) nodename useDefaultRunLoopMode: (BOOL) useDefaultMode shouldFail: (BOOL) shouldFail
+{
+	BXHostResolver *resolver = [[BXHostResolver alloc] init];
+	
+	OCMockObject *mock = [OCMockObject mockForProtocol: @protocol (BXHostResolverDelegate)];
+	// FIXME: use a HC matcher for addresses and error in the expected case.
+	if (shouldFail)
+	{
+		[[mock expect] hostResolverDidFail: resolver error: OCMOCK_ANY];
+		NSException *exc = [NSException exceptionWithName: NSInternalInconsistencyException
+												   reason: @"Expected resolver to fail."
+												 userInfo: nil];
+		[[[mock stub] andThrow: exc] hostResolverDidSucceed: resolver addresses: OCMOCK_ANY];
+	}
+	else
+	{
+		[[mock expect] hostResolverDidSucceed: resolver addresses: OCMOCK_ANY];
+		NSException *exc = [NSException exceptionWithName: NSInternalInconsistencyException 
+												   reason: @"Expected resolver to succeed." 
+												 userInfo: nil];
+		[[[mock stub] andThrow: exc] hostResolverDidFail: resolver error: OCMOCK_ANY];
+	}
+	
+	CFRunLoopRef runLoop = CFRunLoopGetCurrent ();
+	
+	[resolver setRunLoop: runLoop];
+	[resolver setRunLoopMode: (id) (useDefaultMode ? kCFRunLoopDefaultMode : kCFRunLoopCommonModes)];
+	[resolver setDelegate: (id <BXHostResolverDelegate>) mock];
+	[resolver resolveHost: nodename];
+	
+	SInt32 status = CFRunLoopRunInMode (kCFRunLoopDefaultMode, 5.0, FALSE);
+	status = 0;
+	[mock verify];
+}
+
+
+- (void) test01
+{
+	[self runResolverForNodename: @"langley.macsinracks.net" useDefaultRunLoopMode: YES shouldFail: NO];
+}
+
+
+- (void) test02
+{
+	[self runResolverForNodename: @"langley.macsinracks.net" useDefaultRunLoopMode: NO shouldFail: NO];
+}
+
+
+- (void) test03
+{
+	[self runResolverForNodename: @"karppinen.fi" useDefaultRunLoopMode: YES shouldFail: NO];
+}
+
+
+- (void) test04
+{
+	[self runResolverForNodename: @"karppinen.fi" useDefaultRunLoopMode: NO shouldFail: NO];
+}
+
+
+- (void) test05
+{
+	[self runResolverForNodename: @"karppinen.invalid" useDefaultRunLoopMode: YES shouldFail: YES];
+}
+
+
+- (void) test06
+{
+	[self runResolverForNodename: @"karppinen.invalid" useDefaultRunLoopMode: NO shouldFail: YES];
+}
+
+
+- (void) test07
+{
+	[self runResolverForNodename: @"127.0.0.1" useDefaultRunLoopMode: YES shouldFail: NO];
+}
+
+
+- (void) test08
+{
+	[self runResolverForNodename: @"127.0.0.1" useDefaultRunLoopMode: NO shouldFail: NO];
+}
+
+
+- (void) test09
+{
+	[self runResolverForNodename: @"::1" useDefaultRunLoopMode: YES shouldFail: NO];
+}
+
+
+- (void) test10
+{
+	[self runResolverForNodename: @"::1" useDefaultRunLoopMode: YES shouldFail: NO];
+}
+@end

UnitTests/Sources/TestLoader.m

 #import "PGTSValueTests.h"
 #import "BXKeyPathComponentTest.h"
 #import "BXPredicateTests.h"
+#import "BXHostResolverTests.h"
 #import "BXDatabaseContextTests.h"
 
 #import "PGTSMetadataTests.h"
 							[PGTSValueTests class],
 							[BXKeyPathComponentTest class],
 							[BXPredicateTests class],
+							[BXHostResolverTests class],
 							[BXDatabaseContextTests class],
 							
 							[PGTSMetadataTests class],
 							[ToOneChangeNotificationTests class],
 							nil];
 	
-	//testClasses = [NSArray arrayWithObject: [BXModificationTests class]];
+	//testClasses = [NSArray arrayWithObject: [BXHostResolverTests class]];
 	
 	for (Class testCaseClass in testClasses)
 	{

UnitTests/UnitTests.xcodeproj/project.pbxproj

 
 /* Begin PBXBuildFile section */
 		3FC3D13211918C3D00D3CA68 /* PGTSPgBouncerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3FC3D13111918C3D00D3CA68 /* PGTSPgBouncerTests.m */; };
+		5304521E119D9BC5000B89CF /* BXHostResolverTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5304521D119D9BC5000B89CF /* BXHostResolverTests.m */; };
 		530925290FA89023000DC21C /* BXDataModelTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 530925280FA89023000DC21C /* BXDataModelTests.m */; };
 		530927A90FA894D2000DC21C /* people-departments.xcdatamodel in Sources */ = {isa = PBXBuildFile; fileRef = 530927A80FA894D2000DC21C /* people-departments.xcdatamodel */; };
 		530927BB0FA89BBE000DC21C /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 530927BA0FA89BBE000DC21C /* CoreData.framework */; };
 		3FC3D13011918C3D00D3CA68 /* PGTSPgBouncerTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PGTSPgBouncerTests.h; path = Sources/PGTSPgBouncerTests.h; sourceTree = "<group>"; };
 		3FC3D13111918C3D00D3CA68 /* PGTSPgBouncerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PGTSPgBouncerTests.m; path = Sources/PGTSPgBouncerTests.m; sourceTree = "<group>"; };
 		3FC3D243119190D000D3CA68 /* libpq-fe.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "libpq-fe.h"; path = "../Sources/libpq-fe.h"; sourceTree = SOURCE_ROOT; };
+		5304521C119D9BC5000B89CF /* BXHostResolverTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BXHostResolverTests.h; path = Sources/BXHostResolverTests.h; sourceTree = "<group>"; };
+		5304521D119D9BC5000B89CF /* BXHostResolverTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BXHostResolverTests.m; path = Sources/BXHostResolverTests.m; sourceTree = "<group>"; };
 		530925270FA89023000DC21C /* BXDataModelTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BXDataModelTests.h; path = Sources/BXDataModelTests.h; sourceTree = "<group>"; };
 		530925280FA89023000DC21C /* BXDataModelTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BXDataModelTests.m; path = Sources/BXDataModelTests.m; sourceTree = "<group>"; };
 		530927A80FA894D2000DC21C /* people-departments.xcdatamodel */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = wrapper.xcdatamodel; name = "people-departments.xcdatamodel"; path = "Sources/people-departments.xcdatamodel"; sourceTree = "<group>"; };
 				53DAA0580E6EEB46001DC1D9 /* BXKeyPathComponentTest.m */,
 				535627B70E6E805D002EA3FD /* BXPredicateTests.h */,
 				535627B80E6E805D002EA3FD /* BXPredicateTests.m */,
+				5304521C119D9BC5000B89CF /* BXHostResolverTests.h */,
+				5304521D119D9BC5000B89CF /* BXHostResolverTests.m */,
 				5375C2500F3BAD88002CBF78 /* BXDatabaseContextTests.h */,
 				5375C2510F3BAD88002CBF78 /* BXDatabaseContextTests.m */,
 			);
 				53C4C62111943C8E003FB842 /* NSPredicate+BaseTenAdditionsTests.m in Sources */,
 				53C4C67B119443E1003FB842 /* BXMetadataTests.m in Sources */,
 				538102BE119823D8006A6017 /* BXArbitrarySQLTests.m in Sources */,
+				5304521E119D9BC5000B89CF /* BXHostResolverTests.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.