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
48cc36811f
commit
b179b29898
374 changed files with 20864 additions and 0 deletions
119
Tests/base/NSString/NSString_custom.m
Normal file
119
Tests/base/NSString/NSString_custom.m
Normal file
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
copyright 2004 Alexander Malmberg <alexander@malmberg.org>
|
||||
|
||||
Test that a minimal custom subclass works. This tests the generic
|
||||
implementations of the NSString methods in NSString itself.
|
||||
*/
|
||||
|
||||
#import "NSString_tests.h"
|
||||
|
||||
#import <Foundation/NSString.h>
|
||||
|
||||
@interface CustomString : NSString
|
||||
{
|
||||
unichar *characters;
|
||||
NSUInteger length;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CustomString
|
||||
|
||||
- initWithBytes: (void *)c
|
||||
length: (NSUInteger)l
|
||||
encoding: (NSStringEncoding)encoding
|
||||
{
|
||||
if (l > 0)
|
||||
{
|
||||
if (encoding == NSUnicodeStringEncoding)
|
||||
{
|
||||
characters = malloc(l);
|
||||
memcpy(characters, c, l);
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *s;
|
||||
|
||||
s = [[NSString alloc] initWithBytes: c
|
||||
length: l
|
||||
encoding: encoding];
|
||||
if (s == nil) return nil;
|
||||
l = [s length] * sizeof(unichar);
|
||||
characters = malloc(l);
|
||||
[s getCharacters: characters];
|
||||
[s release];
|
||||
}
|
||||
}
|
||||
length = l / sizeof(unichar);
|
||||
return self;
|
||||
}
|
||||
|
||||
- initWithBytesNoCopy: (void *)c
|
||||
length: (NSUInteger)l
|
||||
encoding: (NSStringEncoding)encoding
|
||||
freeWhenDone: (BOOL)freeWhenDone
|
||||
{
|
||||
if (l > 0)
|
||||
{
|
||||
if (encoding == NSUnicodeStringEncoding)
|
||||
{
|
||||
characters = malloc(l);
|
||||
memcpy(characters, c, l);
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *s;
|
||||
|
||||
s = [[NSString alloc] initWithBytesNoCopy: c
|
||||
length: l
|
||||
encoding: encoding
|
||||
freeWhenDone: freeWhenDone];
|
||||
if (s == nil) return nil;
|
||||
l = [s length] * sizeof(unichar);
|
||||
characters = malloc(l);
|
||||
[s getCharacters: characters];
|
||||
[s release];
|
||||
}
|
||||
}
|
||||
length = l / sizeof(unichar);
|
||||
return self;
|
||||
}
|
||||
|
||||
- initWithCharactersNoCopy: (void *)c
|
||||
length: (NSUInteger)l
|
||||
freeWhenDone: (BOOL)flag
|
||||
{
|
||||
return [self initWithBytesNoCopy: c
|
||||
length: l*sizeof(unichar)
|
||||
encoding: NSUnicodeStringEncoding
|
||||
freeWhenDone: flag];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (characters)
|
||||
{
|
||||
free(characters);
|
||||
characters = NULL;
|
||||
}
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSUInteger) length
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
- (unichar) characterAtIndex: (NSUInteger)index
|
||||
{
|
||||
return characters[index];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
TestNSStringClass([CustomString class]);
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue