From: Wincent Colaiuta Date: Tue, 24 Jul 2007 17:49:05 +0000 (+0200) Subject: Allow pointer-to-pointer comparisons X-Git-Url: https://git.wincent.com/WOTest.git/commitdiff_plain/8210f41cfe29b34a9927a5fb12b305762d40de69 Allow pointer-to-pointer comparisons 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 --- diff --git a/NSValue+WOTest.m b/NSValue+WOTest.m index da1dfb4..9bb24c0 100644 --- a/NSValue+WOTest.m +++ b/NSValue+WOTest.m @@ -755,6 +755,15 @@ [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]) {