]> git.wincent.com - WOTest.git/commitdiff
Allow pointer-to-pointer comparisons
authorWincent Colaiuta <win@wincent.com>
Tue, 24 Jul 2007 17:49:05 +0000 (19:49 +0200)
committerWincent Colaiuta <win@wincent.com>
Tue, 24 Jul 2007 17:49:05 +0000 (19:49 +0200)
Found another case in which comparing nil to nil was leading to a failing
test; ultimately the +[NSValue WOTest_compare:] method was being called where
both objects were encoded with type "pointer-to-void".

This commit adds a special case for such comparisons: truly equal pointers are
considered to be NSOrderedSame; all others fall through to the default path
and an exception is raised.

This is a conservative approach because in reality the only kind of pointer
comparison which makes sense in practice is an equality test, not an ordering
test.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
NSValue+WOTest.m

index da1dfb41d0e78d0cc4ebc671db371726b335121f..9bb24c04972ddf9e4b1419a54dc2f3f2522bf6e8 100644 (file)
         [NSException raise:NSInvalidArgumentException format:@"compared objects must be of same class and implement compare:"];
     }
 
+    // pointer-to-void case
+    if ([self WOTest_isPointerToVoid] && [aValue WOTest_isPointerToVoid])
+    {
+        // test conservatively here: equal pointers are considered equal;
+        // all others fall through and an exception is raised
+        if ([self pointerValue] == [aValue pointerValue])
+            return NSOrderedSame;
+    }
+
     // numeric scalar case
     if ([self WOTest_isNumericScalar] && [aValue WOTest_isNumericScalar])
     {