0

What is wrong, here I am doing?

ptr == NULL is true,

This is also ok,

STAssertTrue(ptr == NULL, @"ptr is null"); //succeeded

But,

STAssertEquals(ptr, NULL, @"");

is giving error, "Type mismatch --- ".

- (void) testNilEncoding {
    NSString * nils = nil;
    const char * ptr = [nils dataUsingEncoding:NSUTF8StringEncoding].bytes;
    const char * ptr2 = [nils cStringUsingEncoding:NSUTF8StringEncoding];

    if (ptr == NULL) {
        NSLog(@"Ptr is null"); // ok
    }
    STAssertTrue(ptr == NULL, @"ptr is null"); //ok
    STAssertEquals(ptr, NULL, @""); //fails
    STAssertEquals(ptr2, NULL, @""); //fails
}
karim
  • 15,408
  • 7
  • 58
  • 96
  • 1
    This is a side effect of how the assertion macros are implemented. You would have to do a cast like `STAssertEquals((void*)ptr, NULL, nil);` – Mike Weller Sep 04 '13 at 12:18
  • Similar Q&A: http://stackoverflow.com/questions/18578536/type-mismatch-when-comparing-an-nsuinteger-to-0. – Martin R Sep 04 '13 at 12:31

0 Answers0