Compare with non-remote NSString object

This commit is contained in:
hmelder 2024-09-10 18:45:58 +02:00
parent 95833b1ab4
commit 759bfdf86b

View file

@ -4,51 +4,12 @@
#import <Foundation/NSProxy.h>
#import <Foundation/NSString.h>
@interface MyString : NSString
{
id _remote;
}
@end
@interface MyProxy : NSProxy
{
id _remote;
}
@end
@implementation MyString
- (id) init
{
_remote = nil;
return self;
}
- (void) dealloc
{
[_remote release];
DEALLOC
}
- (unichar) characterAtIndex: (NSUInteger)i
{
return [_remote characterAtIndex: i];
}
- (NSUInteger) hash
{
return [_remote hash];
}
- (NSUInteger) length
{
return [_remote length];
}
- (void) setRemote:(id)remote
{
ASSIGN(_remote,remote);
}
- (id) remote
{
return _remote;
}
@end
@implementation MyProxy
- (id) init
{
@ -107,7 +68,7 @@ int main()
Class theClass = NSClassFromString(@"NSProxy");
id obj = nil;
id rem = @"Remote";
id sub = nil;
id sub = @"Remote";
PASS(theClass == [NSProxy class], "uses +class to return self");
PASS([[NSProxy alloc] isProxy] == YES,
@ -118,9 +79,6 @@ int main()
PASS([obj isEqual: obj], "proxy isEqual: to self without remote");
[obj setRemote: rem];
PASS([obj remote] == rem, "Can set the remote object for the proxy");
sub = [[MyString alloc] init];
PASS(sub != nil, "Can create a MyString instance");
[sub setRemote: rem];
PASS([sub remote] == rem, "Can set the remote object for the subclass");
PASS([obj length] == [rem length], "Get the length of the remote object");
PASS([sub length] == [rem length], "Get the length of the subclass object");