Skip to content

Commit

Permalink
Add unit test for NSNull and KVC
Browse files Browse the repository at this point in the history
  • Loading branch information
hmelder committed Dec 9, 2023
1 parent 1f9bbee commit d7ae73f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Tests/base/KVC/nsnull.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#import "ObjectTesting.h"
#import <Foundation/NSNull.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSKeyValueCoding.h>

int main(void) {
NSAutoreleasePool *arp = [NSAutoreleasePool new];

NSNull *nullObject = [NSNull null];

// Accessing an undefined key
id result = [nullObject valueForKey:@"undefinedKey"];
PASS(result == nullObject, "NSNull returns itself for undefined keys.");

// Attempting to set a value for an undefined key
PASS_EXCEPTION([nullObject setValue:@"value" forKey:@"undefinedKey"],
NSUndefinedKeyException,
"Setting an undefined key on NSNull should not crash.");

// Accessing an undefined key path
id result = [nullObject valueForKeyPath:@"some.path"];
PASS(result == nullObject, "NSNull returns itself for undefined key paths.");

// Attempting to set a value for an undefined key path
PASS_EXCEPTION([nullObject setValue:@"value" forKeyPath:@"some.path"],
NSUndefinedKeyException,
"Setting an undefined key path on NSNull should not crash.");

[arp release];
return 0;
}

0 comments on commit d7ae73f

Please sign in to comment.