Set explicit designated requirements to ensure the signing behaves properly on versions of Mac OS X that don't know about Developer ID signing (OS X 10.6)
(transplanted from c5ac17ab998dcf932c5d7e778e153f92263c449a)
/*
* Adium is the legal property of its developers, whose names are listed in the copyright file included
* with this source distribution.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import "TestStringAdditions.h"
#import "AIUnitTestUtilities.h"
#import <AIUtilities/AIStringAdditions.h>
@implementationTestStringAdditions
-(void)testRandomStringOfLength
{
//Test at least two different lengths, and see what happens when we ask for 0.
NSString*str=[NSStringrandomStringOfLength:6];
STAssertEquals([strlength],(NSUInteger)6U,@"+randomStringOfLength:6 did not return a 6-character string; it returned \"%@\", which is %u characters",str,[strlength]);
str=[NSStringrandomStringOfLength:12];
STAssertEquals([strlength],(NSUInteger)12U,@"+randomStringOfLength:12 did not return a 12-character string; it returned \"%@\", which is %u characters",str,[strlength]);
str=[NSStringrandomStringOfLength:0];
STAssertEquals([strlength],(NSUInteger)0U,@"+randomStringOfLength:0 did not return a 0-character string; it returned \"%@\", which is %u characters",str,[strlength]);
}
-(void)testStringWithContentsOfUTF8File
{
//Our octest file contains a sample file to read in testing this method.
AISimplifiedAssertEqualObjects(snowman,snowmanFromFile,@"+stringWithContentsOfUTF8File: incorrectly read the file");
STAssertTrue([snowmanFromFileisKindOfClass:[NSMutableStringclass]],@"Sending +stringWithContentsOfUTF8File: to NSMutableString should result in a mutable string");
}
-(void)testEllipsis
{
STAssertEquals([[NSStringellipsis]length],(NSUInteger)1U,@"+ellipsis did not return a 1-character string; it returned \"%@\"",[NSStringellipsis]);
STAssertEquals((NSUInteger)[[NSStringellipsis]characterAtIndex:0U],(NSUInteger)0x2026U,@"+ellipsis did not return a horizontal ellipsis (U+2026); it returned \"%@\" instead",[NSStringellipsis]);
}
-(void)testMutableEllipsis
{
STAssertEquals([[NSMutableStringellipsis]length],(NSUInteger)1U,@"+ellipsis did not return a 1-character string; it returned \"%@\"",[NSStringellipsis]);
STAssertEquals((NSUInteger)[[NSMutableStringellipsis]characterAtIndex:0U],(NSUInteger)0x2026U,@"+ellipsis did not return a horizontal ellipsis (U+2026); it returned \"%@\" instead",[NSStringellipsis]);
STAssertTrue([[NSMutableStringellipsis]isKindOfClass:[NSMutableStringclass]],@"Sending +ellipsis to NSMutableString should result in a mutable string");
}
-(void)testStringByAppendingEllipsis
{
NSString*before=@"Foo";
NSString*after=[beforestringByAppendingEllipsis];
STAssertEquals(([afterlength]-[beforelength]),(NSUInteger)1U,@"Appending a single character should result in a string that is one character longer. before is \"%@\"; after is \"%@\"",before,after);
STAssertTrue([afterhasSuffix:[NSStringellipsis]],@"String formed by appending [NSString ellipsis] should end with [NSString ellipsis]. before is \"%@\"; after is \"%@\"",before,after);
}
-(void)testCompactedString
{
AISimplifiedAssertEqualObjects([@"FOO"compactedString],@"foo",@"-compactedString should lowercase an all-uppercase string");
AISimplifiedAssertEqualObjects([@"Foo"compactedString],@"foo",@"-compactedString should lowercase a mixed-case string");
AISimplifiedAssertEqualObjects([@"foo"compactedString],@"foo",@"-compactedString should do nothing to an all-lowercase string");
AISimplifiedAssertEqualObjects([@"foo bar"compactedString],@"foobar",@"-compactedString should remove spaces");
STAssertEqualObjects(before,after,@"Truncating to a length greater than that of the string being truncated should not change the string. before is \"%@\"; after is \"%@\"",before,after);
STAssertEqualObjects(before,after,@"Truncating to a length equal to that of the string being truncated should not change the string. before is \"%@\"; after is \"%@\"",before,after);
//Third, try truncating to a shorter length. This one should actually truncate the string and append an ellipsis.
STAssertEquals(([beforelength]-[afterlength]),(NSUInteger)1U,@"Appending a single character should result in a string that is one character longer. before is \"%@\"; after is \"%@\"",before,after);
//The part before the ellipsis in after should be equal to the same portion of before.
@"Truncating a string should not result in any changes before the truncation point before is \"%@\"; after is \"%@\"",before,after);
STAssertTrue([afterhasSuffix:[NSStringellipsis]],@"String formed by appending [NSString ellipsis] should end with [NSString ellipsis]. before is \"%@\"; after is \"%@\"",before,after);
}
-(void)testIdentityMethod
{
NSString*str=@"Foo";
STAssertEquals([strstring],str,@"A method that returns itself must, by definition, return itself.");
}
-(void)testXMLEscaping
{
NSString*originalXMLSource=@"<rel-date><number>Four score</number> & <number>seven</number> years ago</rel-date>";
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that doesn't have one, should return a location of NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that doesn't have one, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a line feed, should return the location of the line feed");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a line feed, should return a length of 1");
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a form feed, should return the location of the form feed");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a form feed, should return a length of 1");
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a carriage return, should return the location of the carriage return");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a carriage return, should return a length of 1");
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a CRLF sequence, should return the location of the carriage return");
STAssertEquals((NSUInteger)range.length,(NSUInteger)2U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a CRLF sequence, should return a length of 2");
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a next line, should return the location of the next line");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a next line, should return a length of 1");
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a line separator, should return the location of the line separator");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a line separator, should return a length of 1");
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a paragraph separator, should return the location of the paragraph separator");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a paragraph separator, should return a length of 1");
}
-(void)testRangeOfLineBreakCharacterInEmptyRange
{
NSRangesearchRange={3U,0U};//3 being the index of the line-break
STAssertEqualObjects([@"foo\nbar"substringWithRange:searchRange],@"",@"Search range returned an unexpected substring");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that doesn't have one, should return a location of NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that doesn't have one, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a line feed, should return NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a line feed, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a form feed, should return NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a form feed, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a carriage return, should return NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a carriage return, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a CRLF sequence, should return NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a CRLF sequence, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a next line, should return NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a next line, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a line separator, should return NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a line separator, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a paragraph separator, should return NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a paragraph separator, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that doesn't have one, should return a location of NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that doesn't have one, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a line feed, should return NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a line feed, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a form feed, should return NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a form feed, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a carriage return, should return NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a carriage return, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a CRLF sequence, should return NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a CRLF sequence, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a next line, should return NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a next line, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a line separator, should return NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a line separator, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a paragraph separator, should return NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0U,@"-rangeOfLineBreakCharacterInRange:, sent to a string that contains a paragraph separator, should return a length of 0");
NSRangesearchRange={5U,3U};//"arX" (where X = outside the string)
STAssertThrowsSpecificNamed([@"foo\nbar"rangeOfLineBreakCharacterInRange:searchRange],NSException,NSRangeException,@"-rangeOfLineBreakCharacterInRange:, with a range that is partially outside the receiver string, should throw NSRangeException");
NSRangesearchRange={12U,3U};//Length of @"foo\nbar": 7; 12 > 7, so the range is wholly invalid
STAssertThrowsSpecificNamed([@"foo\nbar"rangeOfLineBreakCharacterInRange:searchRange],NSException,NSRangeException,@"-rangeOfLineBreakCharacterInRange:, with a range that is wholly outside the receiver string, should throw NSRangeException");
}
-(void)testRangeOfLineBreakCharacterFromIndex
{
STAssertEqualObjects([@"foo\nbar"substringFromIndex:3U],@"\nbar",@"Search range returned an unexpected substring");
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that doesn't have one, should return a location of NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0U,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that doesn't have one, should return a length of 0");
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that contains a line feed, should return the location of the line feed");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that contains a line feed, should return a length of 1");
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that contains a form feed, should return the location of the form feed");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that contains a form feed, should return a length of 1");
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that contains a carriage return, should return the location of the carriage return");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that contains a carriage return, should return a length of 1");
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that contains a CRLF sequence, should return the location of the carriage return");
STAssertEquals((NSUInteger)range.length,(NSUInteger)2U,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that contains a CRLF sequence, should return a length of 2");
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that contains a next line, should return the location of the next line");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that contains a next line, should return a length of 1");
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that contains a line separator, should return the location of the line separator");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that contains a line separator, should return a length of 1");
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that contains a paragraph separator, should return the location of the paragraph separator");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacterFromIndex:, sent to a string that contains a paragraph separator, should return a length of 1");
NSUIntegerstartIdx=7U;//Length of @"foo\nbar": 7, so this index is just outside the string (last valid index: 6).
STAssertThrowsSpecificNamed([@"foo\nbar"rangeOfLineBreakCharacterFromIndex:startIdx],NSException,NSRangeException,@"-rangeOfLineBreakCharacterFromIndex:, with a start index that is outside the receiver string, should throw NSRangeException");
}
-(void)testRangeOfLineBreakCharacter
{
NSRangerange;
//No line-break
range=[@"foo bar"rangeOfLineBreakCharacter];
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacter, sent to a string that doesn't have one, should return a location of NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0U,@"-rangeOfLineBreakCharacter, sent to a string that doesn't have one, should return a length of 0");
//Line feed
range=[@"foo\nbar"rangeOfLineBreakCharacter];
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacter, sent to a string that contains a line feed, should return the location of the line feed");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacter, sent to a string that contains a line feed, should return a length of 1");
//Form feed
range=[@"foo\fbar"rangeOfLineBreakCharacter];
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacter, sent to a string that contains a form feed, should return the location of the form feed");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacter, sent to a string that contains a form feed, should return a length of 1");
//Carriage return
range=[@"foo\rbar"rangeOfLineBreakCharacter];
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacter, sent to a string that contains a carriage return, should return the location of the carriage return");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacter, sent to a string that contains a carriage return, should return a length of 1");
//CRLF sequence
range=[@"foo\r\nbar"rangeOfLineBreakCharacter];
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacter, sent to a string that contains a CRLF sequence, should return the location of the carriage return");
STAssertEquals((NSUInteger)range.length,(NSUInteger)2U,@"-rangeOfLineBreakCharacter, sent to a string that contains a CRLF sequence, should return a length of 2");
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacter, sent to a string that contains a next line, should return the location of the next line");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacter, sent to a string that contains a next line, should return a length of 1");
//Line separator
range=[@"foo\u2028bar"rangeOfLineBreakCharacter];
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacter, sent to a string that contains a line separator, should return the location of the line separator");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacter, sent to a string that contains a line separator, should return a length of 1");
//Paragraph separator
range=[@"foo\u2029bar"rangeOfLineBreakCharacter];
STAssertEquals((NSUInteger)range.location,(NSUInteger)3U,@"-rangeOfLineBreakCharacter, sent to a string that contains a paragraph separator, should return the location of the paragraph separator");
STAssertEquals((NSUInteger)range.length,(NSUInteger)1U,@"-rangeOfLineBreakCharacter, sent to a string that contains a paragraph separator, should return a length of 1");
}
-(void)testRangeOfLineBreakCharacterInEmptyString
{
NSRangerange=[@""rangeOfLineBreakCharacter];
STAssertEquals((NSUInteger)range.location,(NSUInteger)NSNotFound,@"-rangeOfLineBreakCharacter, sent to an empty string, should return a location of NSNotFound");
STAssertEquals((NSUInteger)range.length,(NSUInteger)0U,@"-rangeOfLineBreakCharacter, sent to an empty string, should return a length of 0");
STAssertThrows([strisCaseInsensitivelyEqualToString:[[[NSObjectalloc]init]autorelease]],@"can't compare string to plain object; this should have thrown");
STAssertThrows([strisCaseInsensitivelyEqualToString:(NSString*)[NSNumbernumberWithInteger:42]],@"can't compare string to number; this should have thrown");
STAssertThrows([strisCaseInsensitivelyEqualToString:(NSString*)[NSValuevalueWithRect:NSMakeRect(0.0f,0.0f,128.0f,128.0f)]],@"can't compare string to rect value; this should have thrown");
STAssertThrows([strisCaseInsensitivelyEqualToString:(NSString*)[NSImageimageNamed:@"NSDefaultApplicationIcon"]],@"can't compare string to image; this should have thrown");