mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +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
39
Tests/base/NSArray/basic.m
Normal file
39
Tests/base/NSArray/basic.m
Normal file
|
@ -0,0 +1,39 @@
|
|||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import "ObjectTesting.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
NSArray *obj;
|
||||
NSMutableArray *testObjs = [[NSMutableArray alloc] init];
|
||||
NSString *str;
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
test_alloc(@"NSArray");
|
||||
obj = [NSArray new];
|
||||
PASS((obj != nil && [obj count] == 0),"can create an empty array");
|
||||
str = @"hello";
|
||||
[testObjs addObject: obj];
|
||||
obj = [NSArray arrayWithObject:str];
|
||||
PASS((obj != nil && [obj count] == 1), "can create an array with one element");
|
||||
[testObjs addObject: obj];
|
||||
test_NSObject(@"NSArray", testObjs);
|
||||
test_NSCoding(testObjs);
|
||||
test_NSCopying(@"NSArray",@"NSMutableArray",testObjs,YES,NO);
|
||||
test_NSMutableCopying(@"NSArray",@"NSMutableArray",testObjs);
|
||||
|
||||
obj = [NSArray arrayWithContentsOfFile: @"test.plist"];
|
||||
PASS((obj != nil && [obj count] > 0),"can create an array from file");
|
||||
#if 1
|
||||
/* The apple foundation is arguably buggy in that it seems to create a
|
||||
* mutable array ... we currently copy that
|
||||
*/
|
||||
PASS([obj isKindOfClass: [NSMutableArray class]] == YES,"array mutable");
|
||||
PASS_RUNS([obj addObject: @"x"],"can add to array");
|
||||
#else
|
||||
PASS([obj isKindOfClass: [NSMutableArray class]] == NO,"array immutable");
|
||||
#endif
|
||||
obj = [obj objectAtIndex: 0];
|
||||
PASS([obj isKindOfClass: [NSMutableArray class]] == YES,"array mutable");
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
45
Tests/base/NSArray/create.m
Normal file
45
Tests/base/NSArray/create.m
Normal file
|
@ -0,0 +1,45 @@
|
|||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import "ObjectTesting.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
id val1,val2,val3;
|
||||
id ptrvals[3];
|
||||
NSArray *obj, *old;
|
||||
val1 = @"Tom";
|
||||
val2 = @"Petty";
|
||||
val3 = @"doesn't want to live like a refugee";
|
||||
|
||||
ptrvals[0] = val1;
|
||||
ptrvals[1] = val2;
|
||||
ptrvals[2] = val3;
|
||||
|
||||
obj = [NSArray new];
|
||||
PASS((obj != nil && [obj isKindOfClass:[NSArray class]] && [obj count] == 0),
|
||||
"+new creates an empty array");
|
||||
[obj release];
|
||||
obj = [NSArray array];
|
||||
PASS((obj != nil && [obj isKindOfClass:[NSArray class]] && [obj count] == 0),
|
||||
"+array creates an empty array");
|
||||
TEST_EXCEPTION([NSArray arrayWithObject:nil];, @"NSInvalidArgumentException",
|
||||
YES, "+arrayWithObject with nil argument throws exception");
|
||||
|
||||
obj = [NSArray arrayWithObject:val1];
|
||||
PASS(obj != nil && [obj isKindOfClass:[NSArray class]] && [obj count] == 1,
|
||||
"+arrayWithObject: builds a minimal array");
|
||||
|
||||
obj = [NSArray arrayWithObjects:ptrvals count:3];
|
||||
old = obj;
|
||||
PASS(obj != nil && [obj isKindOfClass:[NSArray class]] && [obj count] == 3,
|
||||
"+arrayWithObjects: builds an array");
|
||||
|
||||
obj = [NSArray arrayWithArray:old];
|
||||
PASS(obj != nil && [old isEqual:obj], "+arrayWithArray: copies array");
|
||||
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
||||
|
91
Tests/base/NSArray/general.m
Normal file
91
Tests/base/NSArray/general.m
Normal file
|
@ -0,0 +1,91 @@
|
|||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import "ObjectTesting.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
id val1,val2,val3,obj;
|
||||
NSArray *arr,*vals1,*vals2,*vals3;
|
||||
|
||||
val1 = @"Hello";
|
||||
val2 = @"A Goodbye";
|
||||
val3 = @"Testing all strings";
|
||||
vals1 = [[[NSArray arrayWithObject:val1] arrayByAddingObject:val2] retain];
|
||||
vals2 = [[vals1 arrayByAddingObject:val2] retain];
|
||||
vals3 = [[vals1 arrayByAddingObject:val3] retain];
|
||||
|
||||
obj = [NSArray new];
|
||||
arr = obj;
|
||||
PASS(obj != nil && [obj isKindOfClass:[NSArray class]] && [obj count] == 0,
|
||||
"-count returns zero for an empty array");
|
||||
PASS([arr hash] == 0, "-hash returns zero for an empty array");
|
||||
PASS(vals3 != nil && [vals3 containsObject:val2], "-containsObject works");
|
||||
PASS(vals3 != nil && [vals3 indexOfObject:@"A Goodbye"] == 1,
|
||||
"-indexOfObject: finds object");
|
||||
PASS(vals3 != nil && [vals3 indexOfObjectIdenticalTo:val2],
|
||||
"-indexOfObjectIdenticalTo: finds identical object");
|
||||
{
|
||||
NSEnumerator *e;
|
||||
id v1, v2, v3;
|
||||
e = [arr objectEnumerator];
|
||||
v1 = [e nextObject];
|
||||
v2 = [e nextObject];
|
||||
PASS(e != nil && v1 == nil && v2 == nil,
|
||||
"-objectEnumerator: is ok for empty array");
|
||||
e = [vals1 objectEnumerator];
|
||||
v1 = [e nextObject];
|
||||
v2 = [e nextObject];
|
||||
v3 = [e nextObject];
|
||||
PASS(v1 != nil && v2 != nil && v3 == nil && [vals1 containsObject:v1] &&
|
||||
[vals1 containsObject:v2] && [v1 isEqual:val1] && [v2 isEqual: val2],
|
||||
"-objectEnumerator: enumerates the array");
|
||||
}
|
||||
{
|
||||
obj = [arr description];
|
||||
obj = [obj propertyList];
|
||||
PASS(obj != nil && [obj isKindOfClass:[NSArray class]] && [obj count] == 0,
|
||||
"-description gives us a text property-list (empty array)");
|
||||
obj = [arr description];
|
||||
obj = [obj propertyList];
|
||||
PASS(obj != nil && [obj isKindOfClass:[NSArray class]] && [obj isEqual:arr],
|
||||
"-description gives us a text property-list");
|
||||
}
|
||||
PASS(vals1 != nil && [vals1 isKindOfClass: [NSArray class]] &&
|
||||
[vals1 count] == 2, "-count returns two for an array with two objects");
|
||||
PASS([vals1 hash] == 2, "-hash returns two for an array with two objects");
|
||||
PASS([vals1 indexOfObject:nil] == NSNotFound,
|
||||
"-indexOfObject: gives NSNotFound for a nil object");
|
||||
PASS([vals1 indexOfObject:val3] == NSNotFound,
|
||||
"-indexOfObject: gives NSNotFound for a object not in the array");
|
||||
PASS([vals1 isEqualToArray:vals1],
|
||||
"Array is equal to itself using -isEqualToArray:");
|
||||
PASS(![vals1 isEqualToArray:vals2],"Similar arrays are not equal using -isEqualToArray:");
|
||||
|
||||
{
|
||||
NSArray *a;
|
||||
NSRange r = NSMakeRange(0,2);
|
||||
a = [vals2 subarrayWithRange:r];
|
||||
PASS(a != nil && [a isKindOfClass:[NSArray class]] && [a count] == 2 &&
|
||||
[a objectAtIndex:0] == val1 && [a objectAtIndex:1] == val2,
|
||||
"-subarrayWithRange: seems ok");
|
||||
r = NSMakeRange(1,2);
|
||||
TEST_EXCEPTION([arr subarrayWithRange:r];,@"NSRangeException",YES,"-subarrayWithRange with invalid range");
|
||||
}
|
||||
|
||||
{
|
||||
NSString *c = @"/";
|
||||
NSString *s = @"Hello/A Goodbye";
|
||||
NSString *a = [vals1 componentsJoinedByString: c];
|
||||
PASS(a != nil && [a isKindOfClass:[NSString class]] && [a isEqual:s],
|
||||
"-componentsJoinedByString: seems ok");
|
||||
}
|
||||
{
|
||||
NSArray *a = [vals1 sortedArrayUsingSelector:@selector(compare:)];
|
||||
PASS(a != nil && [a isKindOfClass:[NSArray class]] && [a count] == 2 &&
|
||||
[a objectAtIndex:0] == val2 && [a objectAtIndex:1] == val1,
|
||||
"-sortedArrayUsingSelector: seems ok");
|
||||
|
||||
}
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
3
Tests/base/NSArray/test.plist
Normal file
3
Tests/base/NSArray/test.plist
Normal file
|
@ -0,0 +1,3 @@
|
|||
(
|
||||
(1, 2, 3)
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue