Permalink
Browse files

Unit tests!

  • Loading branch information...
1 parent 0c9fe28 commit 6eb3ef2b742b7523d6dfb95f1b5016774acbbc26 @schwa committed Dec 21, 2011
Showing with 110 additions and 27 deletions.
  1. +6 −10 Test/Test.xcodeproj/project.pbxproj
  2. +1 −5 Test/Unit Tests/UnitTests.h
  3. +103 −12 Test/Unit Tests/UnitTests.m
@@ -216,7 +216,6 @@
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
- GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h";
@@ -228,7 +227,6 @@
"-framework",
AppKit,
);
- PREBINDING = NO;
PRODUCT_NAME = KVOTest;
SDKROOT = macosx;
};
@@ -242,7 +240,6 @@
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_ENABLE_FIX_AND_CONTINUE = NO;
- GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h";
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
@@ -253,26 +250,25 @@
"-framework",
AppKit,
);
- PREBINDING = NO;
PRODUCT_NAME = KVOTest;
SDKROOT = macosx;
- ZERO_LINK = NO;
};
name = Release;
};
4577CD6D106150E5006432BE /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks";
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
- GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/Cocoa.framework/Headers/Cocoa.h";
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "Unit Tests/Unit Tests-Info.plist";
INSTALL_PATH = "$(USER_LIBRARY_DIR)/Bundles";
OTHER_LDFLAGS = (
@@ -281,8 +277,8 @@
"-framework",
SenTestingKit,
);
- PREBINDING = NO;
PRODUCT_NAME = "Unit Tests";
+ SDKROOT = macosx;
WRAPPER_EXTENSION = octest;
};
name = Debug;
@@ -291,14 +287,15 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks";
GCC_ENABLE_FIX_AND_CONTINUE = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
- GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/Cocoa.framework/Headers/Cocoa.h";
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "Unit Tests/Unit Tests-Info.plist";
INSTALL_PATH = "$(USER_LIBRARY_DIR)/Bundles";
OTHER_LDFLAGS = (
@@ -307,10 +304,9 @@
"-framework",
SenTestingKit,
);
- PREBINDING = NO;
PRODUCT_NAME = "Unit Tests";
+ SDKROOT = macosx;
WRAPPER_EXTENSION = octest;
- ZERO_LINK = NO;
};
name = Release;
};
@@ -31,10 +31,6 @@
#import <SenTestingKit/SenTestingKit.h>
-@interface UnitTests : SenTestCase {
- NSString *testValue;
-}
-
-@property (readwrite, copy) NSString *testValue;
+@interface UnitTests : SenTestCase
@end
View
@@ -31,26 +31,117 @@
#import "UnitTests.h"
-#import "NSObject_KVOBlockNotificationExtensions.h"
+#import "NSObject_KVOBlock.h"
+
+@interface UnitTests ()
+@property (readwrite, nonatomic, retain) NSString *testValue;
+@property (readwrite, nonatomic, retain) id token;
+@end
+
+#pragma mark -
@implementation UnitTests
@synthesize testValue;
+@synthesize token;
+
+- (void)setUp
+ {
+ testValue = NULL;
+ token = NULL;
+ }
+
+- (void)tearDown
+ {
+ testValue = NULL;
+ token = NULL;
+ }
+
+- (void)testIdentifiers
+ {
+ __block NSString *theOldValue = @"";
+ __block NSString *theNewValue = @"";
+
+ self.testValue = @"1";
+ STAssertEqualObjects(theOldValue, @"", @"Failed.");
+ STAssertEqualObjects(theNewValue, @"", @"Failed.");
+
+ [self addKVOBlockForKeyPath:@"testValue" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld identifier:@"my_handler" handler:^(NSString *keyPath, id object, NSDictionary *change) {
+ theOldValue = [change objectForKey:NSKeyValueChangeOldKey];
+ theNewValue = [change objectForKey:NSKeyValueChangeNewKey];
+ }];
+
+ self.testValue = @"2";
+ STAssertEqualObjects(theOldValue, @"1", @"Failed.");
+ STAssertEqualObjects(theNewValue, @"2", @"Failed.");
+
+ self.testValue = @"3";
+ STAssertEqualObjects(theOldValue, @"2", @"Failed.");
+ STAssertEqualObjects(theNewValue, @"3", @"Failed.");
+
+ theOldValue = @"";
+ theNewValue = @"";
+
+ [self removeKVOBlockForKeyPath:@"testValue" identifier:@"my_handler"];
+
+ self.testValue = @"4";
+ STAssertEqualObjects(theOldValue, @"", @"Failed.");
+ STAssertEqualObjects(theNewValue, @"", @"Failed.");
+ }
+
+- (void)testTokens
+ {
+ __block NSString *theOldValue = @"";
+ __block NSString *theNewValue = @"";
+
+ self.testValue = @"1";
+ STAssertEqualObjects(theOldValue, @"", @"Failed.");
+ STAssertEqualObjects(theNewValue, @"", @"Failed.");
+
+ NSString *theToken = [self addKVOBlockForKeyPath:@"testValue" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld handler:^(NSString *keyPath, id object, NSDictionary *change) {
+ theOldValue = [change objectForKey:NSKeyValueChangeOldKey];
+ theNewValue = [change objectForKey:NSKeyValueChangeNewKey];
+ }];
+
+ self.testValue = @"2";
+ STAssertEqualObjects(theOldValue, @"1", @"Failed.");
+ STAssertEqualObjects(theNewValue, @"2", @"Failed.");
+
+ self.testValue = @"3";
+ STAssertEqualObjects(theOldValue, @"2", @"Failed.");
+ STAssertEqualObjects(theNewValue, @"3", @"Failed.");
-- (void)testFoo
-{
-__block NSString *theValue = NULL;
-KVOBlock theBlock = ^(NSString *keyPath, id object, NSDictionary *change, id identifier) {
- theValue = [change objectForKey:@"new"];
- };
+ theOldValue = @"";
+ theNewValue = @"";
+
+ [self removeKVOBlockForToken:theToken];
+
+ self.testValue = @"4";
+ STAssertEqualObjects(theOldValue, @"", @"Failed.");
+ STAssertEqualObjects(theNewValue, @"", @"Failed.");
+ }
-[self addObserver:self handler:theBlock forKeyPath:@"testValue" options:NSKeyValueObservingOptionNew identifier:@"FOO"];
+- (void)testOneShot
+ {
+ __block NSString *theOldValue = @"";
+ __block NSString *theNewValue = @"";
-self.testValue = @"New Value";
+ self.testValue = @"1";
+ STAssertEqualObjects(theOldValue, @"", @"Failed.");
+ STAssertEqualObjects(theNewValue, @"", @"Failed.");
+
+ [self addOneShotKVOBlockForKeyPath:@"testValue" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld handler:^(NSString *keyPath, id object, NSDictionary *change) {
+ theOldValue = [change objectForKey:NSKeyValueChangeOldKey];
+ theNewValue = [change objectForKey:NSKeyValueChangeNewKey];
+ }];
-STAssertEqualObjects(theValue, self.testValue, @"Value not expected (is %@)", theValue);
+ self.testValue = @"2";
+ STAssertEqualObjects(theOldValue, @"1", @"Failed.");
+ STAssertEqualObjects(theNewValue, @"2", @"Failed.");
-[self removeObserver:self forKeyPath:@"testValue" identifier:@"FOO"];
-}
+ self.testValue = @"3";
+ STAssertEqualObjects(theOldValue, @"1", @"Failed.");
+ STAssertEqualObjects(theNewValue, @"2", @"Failed.");
+ }
@end

0 comments on commit 6eb3ef2

Please sign in to comment.