Skip to content
Browse files

Corrected handling of null CF objects.

  • Loading branch information...
1 parent 7cc6543 commit fdbb8ab5d431c7f1cc7ec88cfa3f8e3f4c8ac4e4 @robrix committed
Showing with 10 additions and 2 deletions.
  1. +4 −0 RXAssertionHelperTests.m
  2. +6 −2 RXAssertions.m
View
4 RXAssertionHelperTests.m
@@ -18,4 +18,8 @@ -(void)testCanTestRangesForEquality {
// RXAssertNotEquals(NSMakeRange(0, 1), NSMakeRange(1, 2));
}
+-(void)testCanTestCoreFoundationStringsForEquality {
+ RXAssertEquals(CFSTR("foo"), (CFStringRef)@"foo");
+}
+
@end
View
8 RXAssertions.m
@@ -42,7 +42,10 @@ BOOL RXAssertionHelperObjectComparison(const void *a, const void *b) {
}
BOOL RXAssertionHelperCFTypeRefComparison(const void *a, const void *b) {
- return CFEqual(*RXCast(a, CFTypeRef *), *RXCast(b, CFTypeRef *));
+ CFTypeRef _a = *RXCast(a, CFTypeRef *), _b = *RXCast(b, CFTypeRef *);
+ return
+ (_a == _b)
+ || ((_a != nil) && (_b != nil) && CFEqual(_a, _b));
}
BOOL RXAssertionHelperNSPointComparison(const void *a, const void *b) {
@@ -103,7 +106,8 @@ BOOL RXAssertionHelperNSRangeComparison(const void *a, const void *b) {
}
NSString *RXAssertionHelperCFTypeRefDescription(const void *ref) {
- return [(id)CFCopyDescription(*RXCast(ref, CFTypeRef *)) autorelease];
+ CFTypeRef _ref = *RXCast(ref, CFTypeRef *);
+ return _ref ? [(id)CFCopyDescription(_ref) autorelease] : @"(null)";
}
NSString *RXAssertionHelperNSPointDescription(const void *ref) {

0 comments on commit fdbb8ab

Please sign in to comment.
Something went wrong with that request. Please try again.