mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
import testsuite
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32187 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
734c214892
commit
0e02133729
374 changed files with 20864 additions and 0 deletions
98
Tests/base/NSInvocation/test01.m
Normal file
98
Tests/base/NSInvocation/test01.m
Normal file
|
@ -0,0 +1,98 @@
|
|||
#import "Testing.h"
|
||||
#import "ObjectTesting.h"
|
||||
#import "InvokeProxyProtocol.h"
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSBundle.h>
|
||||
#import <Foundation/NSException.h>
|
||||
#import <Foundation/NSFileManager.h>
|
||||
#import <Foundation/NSInvocation.h>
|
||||
#import <Foundation/NSMethodSignature.h>
|
||||
#import <Foundation/NSProxy.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSInvocation *inv = nil;
|
||||
NSObject <InvokeTarget>*tar;
|
||||
NSMethodSignature *sig;
|
||||
id ret;
|
||||
Class tClass = Nil;
|
||||
NSString *bundlePath;
|
||||
NSBundle *bundle;
|
||||
int retc;
|
||||
bundlePath = [[[NSFileManager defaultManager]
|
||||
currentDirectoryPath]
|
||||
stringByAppendingPathComponent:@"Resources"];
|
||||
bundlePath = [[NSBundle bundleWithPath:bundlePath]
|
||||
pathForResource:@"InvokeProxy"
|
||||
ofType:@"bundle"];
|
||||
bundle = [NSBundle bundleWithPath:bundlePath];
|
||||
PASS([bundle load],
|
||||
"loading resources from bundle");
|
||||
tClass = NSClassFromString(@"InvokeTarget");
|
||||
|
||||
|
||||
tar = [tClass new];
|
||||
|
||||
/*
|
||||
Test if the return value is retained. It is in the Apple OpenStep edition
|
||||
for Windows (YellowBox)
|
||||
matt: this doesn't seem like a valid test as PASS/fail will vary on
|
||||
platforms
|
||||
*/
|
||||
sig = [tar methodSignatureForSelector:@selector(retObject)];
|
||||
inv = [NSInvocation invocationWithMethodSignature: sig];
|
||||
retc = [[tar retObject] retainCount];
|
||||
[inv setSelector:@selector(retObject)];
|
||||
[inv invokeWithTarget:tar];
|
||||
PASS(retc + 1 == [[tar retObject] retainCount],
|
||||
"Retain return value");
|
||||
|
||||
sig = [tar methodSignatureForSelector:@selector(loopObject:)];
|
||||
inv = [NSInvocation invocationWithMethodSignature: sig];
|
||||
retc = [tar retainCount];
|
||||
[inv setSelector:@selector(loopObject:)];
|
||||
[inv invokeWithTarget:tar];
|
||||
[inv retainArguments];
|
||||
[inv setArgument:&tar atIndex:2];
|
||||
PASS(retc + 1 == [tar retainCount],
|
||||
"Will Retain arguments after -retainArguments");
|
||||
|
||||
sig = [tar methodSignatureForSelector:@selector(loopObject:)];
|
||||
inv = [NSInvocation invocationWithMethodSignature: sig];
|
||||
retc = [tar retainCount];
|
||||
[inv setSelector:@selector(loopObject:)];
|
||||
[inv invokeWithTarget:tar];
|
||||
[inv setArgument:&tar atIndex:2];
|
||||
PASS(retc == [tar retainCount],
|
||||
"default will not retain arguments");
|
||||
|
||||
sig = [tar methodSignatureForSelector:@selector(retObject)];
|
||||
inv = [NSInvocation invocationWithMethodSignature: sig];
|
||||
[inv setSelector:@selector(retObject)];
|
||||
[inv invokeWithTarget:nil];
|
||||
[inv getReturnValue:&ret];
|
||||
PASS(ret == nil,"Check if nil target works");
|
||||
|
||||
sig = [tar methodSignatureForSelector:@selector(returnIdButThrowException)];
|
||||
inv = [NSInvocation invocationWithMethodSignature: sig];
|
||||
[inv setSelector:@selector(returnIdButThrowException)];
|
||||
TEST_EXCEPTION([inv invokeWithTarget:tar];,@"AnException",YES,"Exception in invocation #1");
|
||||
TEST_EXCEPTION([inv getReturnValue:&ret];,NSGenericException,YES,"Exception getting return value #1");
|
||||
|
||||
/* same as above but with a successful call first */
|
||||
sig = [tar methodSignatureForSelector:@selector(returnIdButThrowException)];
|
||||
inv = [NSInvocation invocationWithMethodSignature: sig];
|
||||
[inv setSelector:@selector(retObject)];
|
||||
|
||||
[inv invokeWithTarget:tar]; /* these two lines */
|
||||
[inv getReturnValue:&ret];
|
||||
|
||||
[inv setSelector:@selector(returnIdButThrowException)];
|
||||
TEST_EXCEPTION([inv invokeWithTarget:tar];,@"AnException",YES,"Exception in invocation #2");
|
||||
TEST_EXCEPTION([inv getReturnValue:&ret];,NSGenericException,YES,"Exception getting return value #2");
|
||||
|
||||
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue