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:
Richard Frith-MacDonald 2011-02-16 08:21:17 +00:00
parent 734c214892
commit 0e02133729
374 changed files with 20864 additions and 0 deletions

View file

@ -0,0 +1,18 @@
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSAttributedString.h>
#import "ObjectTesting.h"
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSArray *arr = [NSArray arrayWithObject:[NSMutableAttributedString new]];
test_alloc(@"NSMutableAttributedString");
test_NSObject(@"NSMutableAttributedString", arr);
test_NSCoding(arr);
test_NSCopying(@"NSAttributedString",@"NSMutableAttributedString",arr,NO, NO);
test_NSMutableCopying(@"NSAttributedString",@"NSMutableAttributedString",arr);
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,251 @@
#import "Testing.h"
#import <Foundation/NSAttributedString.h>
#import <Foundation/NSAutoreleasePool.h>
@interface NSMutableAttributedString (TestingAdditions)
-(BOOL)checkAttributes:(NSDictionary *)attr location:(int)location;
-(BOOL)checkAttributes:(NSDictionary *)attr range:(NSRange)range;
@end
@implementation NSMutableAttributedString (TestingAdditions)
-(BOOL)checkAttributes:(NSDictionary *)attr location:(int)loc
{
return [[self attributesAtIndex:loc
effectiveRange:NULL] isEqual:attr];
}
-(BOOL)checkAttributes:(NSDictionary *)attr range:(NSRange)range
{
NSRange aRange = range;
while (aRange.length > 0)
{
BOOL attrEqual;
attrEqual= [[self attributesAtIndex:aRange.location + (aRange.length - 1)
effectiveRange:NULL] isEqual:attr];
if (attrEqual == NO)
return NO;
aRange.length -= 1;
}
return YES;
}
@end
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSMutableAttributedString *attrStr;
NSString *baseString = @"0123456789";
NSDictionary *red, *gray, *blue;
red = [NSDictionary dictionaryWithObject:@"Red" forKey:@"Color"];
gray = [NSDictionary dictionaryWithObject:@"Gray" forKey:@"Color"];
blue = [NSDictionary dictionaryWithObject:@"Blue" forKey:@"Color"];
attrStr = [[NSMutableAttributedString alloc] initWithString:baseString
attributes:red];
PASS([[attrStr string] isEqual:baseString] &&
[attrStr checkAttributes:red range:NSMakeRange(0,10)],
"-initWithString:attributes: works");
[attrStr setAttributes:blue range:NSMakeRange(0,10)];
PASS([attrStr checkAttributes:blue range:NSMakeRange(0,10)],
"-setAttributes:range: works for the whole string");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:blue range:NSMakeRange(0,5)];
PASS([attrStr checkAttributes:blue range:NSMakeRange(0,5)] &&
[attrStr checkAttributes:red range:NSMakeRange(5,5)],
"-setAttributes:range: works for the first half of the string");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:blue range:NSMakeRange(3,5)];
PASS([attrStr checkAttributes:red range:NSMakeRange(0,3)] &&
[attrStr checkAttributes:blue range:NSMakeRange(3,5)] &&
[attrStr checkAttributes:red range:NSMakeRange(8,2)],
"-setAttributes:range: works for the middle of the string");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:blue range:NSMakeRange(5,5)];
PASS([attrStr checkAttributes:red range:NSMakeRange(0,5)] &&
[attrStr checkAttributes:blue range:NSMakeRange(5,5)],
"-setAttributes:range: works for the last half of the string");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:blue range:NSMakeRange(0,3)];
[attrStr setAttributes:red range:NSMakeRange(3,4)];
[attrStr setAttributes:gray range:NSMakeRange(7,3)];
PASS([attrStr checkAttributes:blue range:NSMakeRange(0,3)] &&
[attrStr checkAttributes:red range:NSMakeRange(3,4)] &&
[attrStr checkAttributes:gray range:NSMakeRange(7,3)],
"-setAttributes:range: works in three parts of the string");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:blue range:NSMakeRange(0,5)];
[attrStr setAttributes:red range:NSMakeRange(3,5)];
[attrStr setAttributes:gray range:NSMakeRange(4,5)];
PASS([attrStr checkAttributes:blue range:NSMakeRange(0,3)] &&
[attrStr checkAttributes:red range:NSMakeRange(3,1)] &&
[attrStr checkAttributes:gray range:NSMakeRange(4,5)] &&
[attrStr checkAttributes:red range:NSMakeRange(9,1)],
"-setAttributes:range: works with overlapping");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:blue range:NSMakeRange(1,2)];
[attrStr setAttributes:blue range:NSMakeRange(4,2)];
[attrStr setAttributes:blue range:NSMakeRange(7,2)];
[attrStr setAttributes:gray range:NSMakeRange(2,6)];
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
[attrStr checkAttributes:blue range:NSMakeRange(1,1)] &&
[attrStr checkAttributes:gray range:NSMakeRange(2,6)] &&
[attrStr checkAttributes:blue range:NSMakeRange(8,1)] &&
[attrStr checkAttributes:red range:NSMakeRange(9,1)],
"-setAttributes:range: works with overlapping (2)");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:blue range:NSMakeRange(2,5)];
[attrStr setAttributes:gray range:NSMakeRange(2,5)];
PASS([attrStr checkAttributes:red range:NSMakeRange(0,2)] &&
[attrStr checkAttributes:gray range:NSMakeRange(2,5)] &&
[attrStr checkAttributes:red range:NSMakeRange(7,3)],
"-setAttributes:range: works with replacing");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:blue range:NSMakeRange(1,8)];
[attrStr setAttributes:red range:NSMakeRange(2,6)];
[attrStr setAttributes:gray range:NSMakeRange(3,4)];
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
[attrStr checkAttributes:blue range:NSMakeRange(1,1)] &&
[attrStr checkAttributes:red range:NSMakeRange(2,1)] &&
[attrStr checkAttributes:gray range:NSMakeRange(3,4)] &&
[attrStr checkAttributes:red range:NSMakeRange(7,1)] &&
[attrStr checkAttributes:blue range:NSMakeRange(8,1)] &&
[attrStr checkAttributes:red range:NSMakeRange(9,1)],
"-setAttributes:range: works with chinese boxes");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:blue range:NSMakeRange(1,3)];
[attrStr setAttributes:gray range:NSMakeRange(1,4)];
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
[attrStr checkAttributes:gray range:NSMakeRange(1,4)] &&
[attrStr checkAttributes:red range:NSMakeRange(5,5)],
"-setAttributes:range: works with extending at the end (diff color)");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:gray range:NSMakeRange(1,3)];
[attrStr setAttributes:gray range:NSMakeRange(1,4)];
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
[attrStr checkAttributes:gray range:NSMakeRange(1,4)] &&
[attrStr checkAttributes:red range:NSMakeRange(5,5)],
"-setAttributes:range: works with extending at the end (diff color)");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:blue range:NSMakeRange(2,3)];
[attrStr setAttributes:gray range:NSMakeRange(1,4)];
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
[attrStr checkAttributes:gray range:NSMakeRange(1,4)] &&
[attrStr checkAttributes:red range:NSMakeRange(5,5)],
"-setAttributes:range: works with extending at the beginning (diff color)");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:gray range:NSMakeRange(2,3)];
[attrStr setAttributes:gray range:NSMakeRange(1,4)];
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
[attrStr checkAttributes:gray range:NSMakeRange(1,4)] &&
[attrStr checkAttributes:red range:NSMakeRange(5,5)],
"-setAttributes:range: works with extending at the beginning (same color)");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:blue range:NSMakeRange(1,3)];
[attrStr setAttributes:gray range:NSMakeRange(2,2)];
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
[attrStr checkAttributes:blue range:NSMakeRange(1,1)] &&
[attrStr checkAttributes:gray range:NSMakeRange(2,2)] &&
[attrStr checkAttributes:red range:NSMakeRange(4,6)],
"-setAttributes:range: works with subset at the end (diff color)");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:gray range:NSMakeRange(1,3)];
[attrStr setAttributes:gray range:NSMakeRange(2,2)];
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
[attrStr checkAttributes:gray range:NSMakeRange(1,3)] &&
[attrStr checkAttributes:red range:NSMakeRange(4,6)],
"-setAttributes:range: works with subset at the end (same color)");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:blue range:NSMakeRange(2,3)];
[attrStr setAttributes:gray range:NSMakeRange(2,2)];
PASS([attrStr checkAttributes:red range:NSMakeRange(0,2)] &&
[attrStr checkAttributes:gray range:NSMakeRange(2,2)] &&
[attrStr checkAttributes:blue range:NSMakeRange(4,1)] &&
[attrStr checkAttributes:red range:NSMakeRange(5,5)],
"-setAttributes:range: works with subset at the beginning (diff color)");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:gray range:NSMakeRange(2,3)];
[attrStr setAttributes:gray range:NSMakeRange(2,2)];
PASS([attrStr checkAttributes:red range:NSMakeRange(0,2)] &&
[attrStr checkAttributes:gray range:NSMakeRange(2,3)] &&
[attrStr checkAttributes:red range:NSMakeRange(5,5)],
"-setAttributes:range: works with subset at the beginning (same color)");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:gray range:NSMakeRange(2,1)];
[attrStr setAttributes:gray range:NSMakeRange(4,1)];
[attrStr setAttributes:blue range:NSMakeRange(1,5)];
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
[attrStr checkAttributes:blue range:NSMakeRange(1,5)] &&
[attrStr checkAttributes:red range:NSMakeRange(6,4)],
"-setAttributes:range: works with subsets (diff color)");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:blue range:NSMakeRange(2,1)];
[attrStr setAttributes:blue range:NSMakeRange(4,1)];
[attrStr setAttributes:blue range:NSMakeRange(1,5)];
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
[attrStr checkAttributes:blue range:NSMakeRange(1,5)] &&
[attrStr checkAttributes:red range:NSMakeRange(6,4)],
"-setAttributes:range: works with subsets (same color)");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:blue range:NSMakeRange(2,1)];
[attrStr setAttributes:blue range:NSMakeRange(4,1)];
[attrStr setAttributes:blue range:NSMakeRange(7,2)];
[attrStr setAttributes:red range:NSMakeRange(3,2)];
[attrStr setAttributes:gray range:NSMakeRange(0,10)];
PASS([attrStr checkAttributes:gray range:NSMakeRange(0,10)],
"-setAttributes:range: works with setting attributes for the whole string");
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
attributes:red]);
[attrStr setAttributes:blue range:NSMakeRange(0,1)];
[attrStr setAttributes:blue range:NSMakeRange(1,1)];
[attrStr setAttributes:blue range:NSMakeRange(2,1)];
PASS([attrStr checkAttributes:blue range:NSMakeRange(0,3)] &&
[attrStr checkAttributes:red range:NSMakeRange(3,7)],
"-setAttributes:range: works with nearby attributes");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,162 @@
#import "Testing.h"
#import <Foundation/NSAttributedString.h>
#import <Foundation/NSAutoreleasePool.h>
/* get rid of compiler warnings */
@interface NSMutableAttributedString(evil)
-(void) _sanity;
@end
#if defined(GNUSTEP_BASE_LIBRARY)
@implementation NSMutableAttributedString(evil)
-(void) _sanity
{
}
@end
#endif
@interface NSMutableAttributedString (TestingAdditions)
-(BOOL)checkAttributes:(NSDictionary *)attr location:(int)location;
-(BOOL)checkAttributes:(NSDictionary *)attr range:(NSRange)range;
@end
@implementation NSMutableAttributedString (TestingAdditions)
-(BOOL)checkAttributes:(NSDictionary *)attr location:(int)loc
{
return [[self attributesAtIndex:loc
effectiveRange:NULL] isEqual:attr];
}
-(BOOL)checkAttributes:(NSDictionary *)attr range:(NSRange)range
{
NSRange aRange = range;
while (aRange.length > 0)
{
BOOL attrEqual;
attrEqual= [[self attributesAtIndex:aRange.location + (aRange.length - 1)
effectiveRange:NULL] isEqual:attr];
if (attrEqual == NO)
return NO;
aRange.length -= 1;
}
return YES;
}
@end
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSMutableAttributedString *as;
NSString *base1 = @"base-1";
NSString *base2 = @"base-2";
NSDictionary *attrE, *attr1, *attr2;
int start,length,index;
[[[NSMutableAttributedString new] autorelease] _sanity];
as = [[NSMutableAttributedString alloc] initWithString:base1 attributes:nil];
[as replaceCharactersInRange:NSMakeRange(2,2) withString:@""];
[as _sanity];
PASS([[as string] isEqual:@"ba-1"],
"-replaceCharactersInRange: withString: works with zero length string");
as = [[NSMutableAttributedString alloc] initWithString:base1 attributes:nil];
[as replaceCharactersInRange:NSMakeRange(2,2) withString:base2];
[as _sanity];
PASS([[as string] isEqual:@"babase-2-1"],
"-replaceCharactersInRange:withString: works in middle of string");
as = [[NSMutableAttributedString alloc] initWithString:base1 attributes:nil];
[as replaceCharactersInRange:NSMakeRange(6,0) withString:base2];
[as _sanity];
PASS([[as string] isEqual:@"base-1base-2"],
"-replaceCharactersInRange:withString: works at end of string works");
as = [[NSMutableAttributedString alloc] initWithString:base1 attributes:nil];
[as replaceCharactersInRange:NSMakeRange(0,0) withString:base2];
[as _sanity];
PASS([[as string] isEqual:@"base-2base-1"],
"-replaceCharactersInRange:withString: works at start of string works");
attrE = [NSDictionary dictionary];
attr1 = [NSDictionary dictionaryWithObject:@"a" forKey:@"1"];
attr2 = [NSDictionary dictionaryWithObject:@"b" forKey:@"2"];
as = [[NSMutableAttributedString alloc] initWithString:base1
attributes:attr1];
[as setAttributes:attr2 range:NSMakeRange(2,4)];
[as replaceCharactersInRange:NSMakeRange(0,6) withString:@""];
[as replaceCharactersInRange:NSMakeRange(0,0) withString:@"aa"];
[as replaceCharactersInRange:NSMakeRange(2,0) withString:@"bb"];
[as _sanity];
PASS([as checkAttributes:attrE range:NSMakeRange(0,4)],
"-replaceCharactersInRange:withString: keeps attributes if entire string is replaced");
as = [[NSMutableAttributedString alloc] initWithString:base1
attributes:attr1];
[as replaceCharactersInRange:NSMakeRange(0,6) withString:base2];
[as _sanity];
PASS([[as string] isEqual:base2] &&
[as checkAttributes:attr1 range:NSMakeRange(0,6)],
"-replaceCharactersInRange:withString: keeps attributes if entire string is replaced");
for (start=0;start != 9; start++)
{
for (length = 0; (length + start) != 9; length++)
{
BOOL removeAll,replaceAll;
NSDictionary *aBegin,*aEnd;
as = [[NSMutableAttributedString alloc] initWithString:@"aabbccdd"
attributes:attr2];
removeAll = (start == 0 && length == 8);
[as setAttributes:attr1 range:NSMakeRange(2,2)];
[as setAttributes:attrE range:NSMakeRange(4,2)];
if (removeAll)
{
aBegin = attrE;
aEnd = attrE;
}
else
{
aBegin = [as attributesAtIndex: (start == 0) ? length : 0
effectiveRange:NULL];
aEnd = [as attributesAtIndex: ((start + length) == 8) ? (start - 1) : 8
effectiveRange:NULL];
[as replaceCharactersInRange:NSMakeRange(start, length)
withString:@""];
[as _sanity];
PASS([[as string] length] == (8 - length) &&
[as checkAttributes:aBegin location:0] &&
[as checkAttributes:aEnd location: (8 - length)],
"attribute/(replaceCharacters... with zero length string) interaction _sanity checks %i %i",start, length);
}
as = [[NSMutableAttributedString alloc] initWithString:@"aabbccdd"
attributes:attr2];
replaceAll = (start == 0 && length == 8);
[as setAttributes:attr1 range:NSMakeRange(2,2)];
[as setAttributes:attrE range:NSMakeRange(4,2)];
if (length == 0 && start == 0)
index = 0;
else if (length == 0)
index = (start - 1);
else
index = start;
aBegin = [as attributesAtIndex:index effectiveRange:NULL];
[as replaceCharactersInRange:NSMakeRange(start,length)
withString:@"foo"];
[as _sanity];
PASS([[as string] length] == (11 - length) &&
[as checkAttributes:aBegin range:NSMakeRange(start,3)],
"attribute/replaceCharacters... interaction _sanity checks %i %i",start,length);
}
}
[arp release]; arp = nil;
return 0;
}