Permalink
Browse files

Added assertion helper functions for CFTypeRefs, currently enabled fo…

…r CFStringRef and CFCharacterSetRef.
  • Loading branch information...
1 parent 6fa75de commit 5d6d9dee1cbea6fb8eddcfca647f5f66921083ff @robrix committed Jun 12, 2010
Showing with 17 additions and 0 deletions.
  1. +3 −0 RXAssertions.h
  2. +14 −0 RXAssertions.m
View
3 RXAssertions.h
@@ -58,6 +58,9 @@ typedef NSString *(*RXAssertionHelperDescriptionFunction)(const void *ref);
BOOL RXAssertionHelperObjectComparison(const void *a, const void *b);
NSString *RXAssertionHelperObjectDescription(const void *ref);
+BOOL RXAssertionHelperCFTypeRefComparison(const void *a, const void *b);
+NSString *RXAssertionHelperCFTypeRefDescription(const void *ref);
+
@interface RXAssertionHelper : NSObject
View
14 RXAssertions.m
@@ -41,6 +41,10 @@ BOOL RXAssertionHelperObjectComparison(const void *a, const void *b) {
return (_a == _b) || [_a isEqual: _b];
}
+BOOL RXAssertionHelperCFTypeRefComparison(const void *a, const void *b) {
+ return CFEqual(*RXCast(a, CFTypeRef *), *RXCast(b, CFTypeRef *));
+}
+
BOOL RXAssertionHelperNSPointComparison(const void *a, const void *b) {
return NSEqualPoints(*RXCast(a, const NSPoint *), *RXCast(b, const NSPoint *));
}
@@ -98,6 +102,10 @@ BOOL RXAssertionHelperNSRangeComparison(const void *a, const void *b) {
return [NSString stringWithFormat: @"%@", *RXCast(ref, const id *)];
}
+NSString *RXAssertionHelperCFTypeRefDescription(const void *ref) {
+ return [(id)CFCopyDescription(*RXCast(ref, CFTypeRef *)) autorelease];
+}
+
NSString *RXAssertionHelperNSPointDescription(const void *ref) {
return NSStringFromPoint(*RXCast(ref, const NSPoint *));
}
@@ -134,6 +142,10 @@ +(void)initialize {
[self registerComparisonFunction: RXAssertionHelperDoubleComparison forObjCType: @encode(double)];
[self registerComparisonFunction: RXAssertionHelperObjectComparison forObjCType: @encode(id)];
[self registerComparisonFunction: RXAssertionHelperObjectComparison forObjCType: @encode(Class)];
+ CFStringRef string = NULL;
+ CFCharacterSetRef characterSet = NULL;
+ [self registerComparisonFunction: RXAssertionHelperCFTypeRefComparison forObjCType: @encode(__typeof__(string))]; // __typeof__ keeps qualifiers, e.g. const
+ [self registerComparisonFunction: RXAssertionHelperCFTypeRefComparison forObjCType: @encode(__typeof__(characterSet))]; // __typeof__ keeps qualifiers, e.g. const
[self registerComparisonFunction: RXAssertionHelperNSPointComparison forObjCType: @encode(NSPoint)];
[self registerComparisonFunction: RXAssertionHelperNSPointComparison forObjCType: @encode(CGPoint)];
[self registerComparisonFunction: RXAssertionHelperNSRangeComparison forObjCType: @encode(NSRange)];
@@ -151,6 +163,8 @@ +(void)initialize {
[self registerDescriptionFunction: RXAssertionHelperDoubleDescription forObjCType: @encode(double)];
[self registerDescriptionFunction: RXAssertionHelperObjectDescription forObjCType: @encode(id)];
[self registerDescriptionFunction: RXAssertionHelperObjectDescription forObjCType: @encode(Class)];
+ [self registerDescriptionFunction: RXAssertionHelperCFTypeRefDescription forObjCType: @encode(__typeof__(string))]; // __typeof__ keeps qualifiers, e.g. const
+ [self registerDescriptionFunction: RXAssertionHelperCFTypeRefDescription forObjCType: @encode(__typeof__(characterSet))]; // __typeof__ keeps qualifiers, e.g. const
[self registerDescriptionFunction: RXAssertionHelperNSPointDescription forObjCType: @encode(NSPoint)];
[self registerDescriptionFunction: RXAssertionHelperNSPointDescription forObjCType: @encode(CGPoint)];
[self registerDescriptionFunction: RXAssertionHelperNSRangeDescription forObjCType: @encode(NSRange)];

0 comments on commit 5d6d9de

Please sign in to comment.