Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -1,21 +1,17 @@ LIB = ${LIB_PREFIX}objfw${LIB_SUFFIX} LIB_MAJOR = 1 LIB_MINOR = 0 SRCS = OFArray.m \ - OFConstCString.m \ - OFCString.m \ - OFConstWideCString.m \ OFExceptions.m \ OFHashes.m \ OFFile.m \ OFList.m \ OFListObject.m \ OFObject.m \ OFString.m \ - OFWideCString.m \ OFXMLFactory.m INCLUDES = ${SRCS:.m=.h} \ OFMacros.h DELETED src/OFCString.h Index: src/OFCString.h ================================================================== --- src/OFCString.h +++ src/OFCString.h @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2008 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of libobjfw. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE included in - * the packaging of this file. - */ - -#import - -#import "OFString.h" - -/** - * An OFString using a C string as internal storage. - */ -@interface OFCString: OFString -{ - char *string; - size_t length; -} - -/** - * Initializes an already allocated OFCString. - * - * \param str A C string to initialize the OFCString with - * \return An initialized OFCString - */ -- initAsCString: (char*)str; - -/** - * \return The OFCString as a C string - */ -- (char*)cString; - -/** - * \return The length of the OFCString - */ -- (size_t)length; - -/** - * Clones the OFCString, creating a new one. - * - * \return A copy of the OFCString - */ -- (OFString*)clone; - -/** - * Compares the OFCString to another OFString. - * - * \param str An OFString in a compatible type to compare with - * \return An integer which is the result of the comparison, see strcmp - */ -- (int)compareTo: (OFString*)str; - -/** - * Append another OFString to the OFCString. - * - * \param str An OFString in a compatible type to append - */ -- append: (OFString*)str; - -/** - * Append a C string to the OFCString. - * - * \param str A C string to append - */ -- appendCString: (const char*)str; - -/** - * Reverse the OFCString. - */ -- reverse; -@end DELETED src/OFCString.m Index: src/OFCString.m ================================================================== --- src/OFCString.m +++ src/OFCString.m @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2008 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of libobjfw. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE included in - * the packaging of this file. - */ - -#import "config.h" - -#import -#import - -#import "OFCString.h" -#import "OFExceptions.h" - -@implementation OFCString -- initAsCString: (char*)str -{ - if ((self = [super init])) { - if (str == NULL) { - length = 0; - string = NULL; - } else { - length = strlen(str); - string = [self getMemWithSize: length + 1]; - memcpy(string, str, length + 1); - } - } - return self; -} - -- (char*)cString -{ - return string; -} - -- (size_t)length -{ - return length; -} - -- (OFString*)clone -{ - return [OFString newAsCString: string]; -} - -- (int)compareTo: (OFString*)str -{ - return strcmp(string, [str cString]); -} - -- append: (OFString*)str -{ - return [self appendCString: [str cString]]; -} - -- appendCString: (const char*)str -{ - char *newstr; - size_t newlen, strlength; - - if (string == NULL) - return [self setTo: [OFString newAsCString: (char*)str]]; - - strlength = strlen(str); - newlen = length + strlength; - - newstr = [self resizeMem: string - toSize: newlen + 1]; - - memcpy(newstr + length, str, strlength + 1); - - length = newlen; - string = newstr; - - return self; -} - -- reverse -{ - size_t i, j, len = length / 2; - - for (i = 0, j = length - 1; i < len; i++, j--) { - string[i] ^= string[j]; - string[j] ^= string[i]; - string[i] ^= string[j]; - } - - return self; -} -@end DELETED src/OFConstCString.h Index: src/OFConstCString.h ================================================================== --- src/OFConstCString.h +++ src/OFConstCString.h @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2008 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of libobjfw. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE included in - * the packaging of this file. - */ - -#import "OFString.h" - -/** - * An OFString using a constant C string as internal storage. - */ -@interface OFConstCString: OFString -{ - const char *string; - size_t length; -} - -/** - * Initializes an already allocated OFConstCString. - * - * \param str A constant C string to initialize the OFConstCString with - * \return An initialized OFConstCString - */ -- initAsConstCString: (const char*)str; - -/** - * \return The OFConstCString as a constant C strin - */ -- (const char*)cString; - -/** - * \return The length of the OFConstCString - */ -- (size_t)length; - -/** - * Clones the OFConstCString, creating a new one. - * - * \return A copy of the OFConstCString - */ -- (OFString*)clone; - -/** - * Compares the OFConstCString to another OFString. - * - * \param str An OFString in a compatible type to compare with - * \return An integer which is the result of the comparison, see strcmp - */ -- (int)compareTo: (OFString*)str; -@end DELETED src/OFConstCString.m Index: src/OFConstCString.m ================================================================== --- src/OFConstCString.m +++ src/OFConstCString.m @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2008 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of libobjfw. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE included in - * the packaging of this file. - */ - -#import "config.h" - -#import -#import "OFConstCString.h" - -@implementation OFConstCString -- initAsConstCString: (const char*)str -{ - if ((self = [super init])) { - if (str == NULL) { - length = 0; - string = NULL; - } else { - length = strlen(str); - string = str; - } - } - return self; -} - -- (const char*)cString -{ - return string; -} - -- (size_t)length -{ - return length; -} - -- (OFString*)clone -{ - return [OFString newAsConstCString: string]; -} - -- (int)compareTo: (OFString*)str -{ - return strcmp(string, [str cString]); -} -@end DELETED src/OFConstWideCString.h Index: src/OFConstWideCString.h ================================================================== --- src/OFConstWideCString.h +++ src/OFConstWideCString.h @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2008 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of libobjfw. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE included in - * the packaging of this file. - */ - -#import -#import -#import "OFString.h" - -/** - * An OFString using a constant wide C string as internal storage. - */ -@interface OFConstWideCString: OFString -{ - const wchar_t *string; - size_t length; -} - -/** - * Initializes an already allocated OFConstWideCString. - * - * \param str A constant wide C string to initialize the OFConstWideCString - * with - * \return An initialized OFConstWideCString - */ -- initAsConstWideCString: (const wchar_t*)str; - -/** - * \return The OFConstWideCString as a constant wide C string - */ -- (const wchar_t*)wCString; - -/** - * \return The length of the OFConstWideCString - */ -- (size_t)length; - -/** - * Clones the OFConstWideCString, creating a new one. - * - * \return A copy of the OFConstWideCString - */ -- (OFString*)clone; - -/** - * Compares the OFConstWideCString to another OFString. - * - * \param str An OFString in a compatible type to compare with - * \return An integer which is the result of the comparison, see wcscmp - */ -- (int)compareTo: (OFString*)str; -@end DELETED src/OFConstWideCString.m Index: src/OFConstWideCString.m ================================================================== --- src/OFConstWideCString.m +++ src/OFConstWideCString.m @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2008 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of libobjfw. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE included in - * the packaging of this file. - */ - -#import "config.h" - -#import -#import "OFConstWideCString.h" - -@implementation OFConstWideCString -- initAsConstWideCString: (const wchar_t*)str -{ - if ((self = [super init])) { - if (str == NULL) { - length = 0; - string = NULL; - } else { - length = wcslen(str); - string = str; - } - } - return self; -} - -- (const wchar_t*)wCString -{ - return string; -} - -- (size_t)length -{ - return length; -} - -- (OFString*)clone -{ - return [OFString newAsConstWideCString: string]; -} - -- (int)compareTo: (OFString*)str -{ - return wcscmp(string, [str wCString]); -} -@end Index: src/OFExceptions.h ================================================================== --- src/OFExceptions.h +++ src/OFExceptions.h @@ -90,49 +90,10 @@ * \return The size of the memoory that couldn't be allocated */ - (size_t)requestedSize; @end -/** - * An OFException indicating the requested selector is not implemented. - */ -@interface OFNotImplementedException: OFException -{ - SEL selector; -} - -/** - * Creates a new not impemented exception. - * - * \param obj The object which caused the exception - * \param sel A selector for the function not implemented - * \return A new not implemented exception - */ -+ newWithObject: (id)obj - andSelector: (SEL)sel; - -/** - * Initializes an already allocated not implemented exception. - * - * \param obj The object which caused the exception - * \param sel A selector for the function not implemented - * \return An initialized not implemented exception - */ -- initWithObject: (id)obj - andSelector: (SEL)sel; - -/** - * \return An error message for the exception as a C String - */ -- (char*)cString; - -/** - * \return The requested selector that is not implemented - */ -- (SEL)selector; -@end - /** * An OFException indicating the given memory is not part of the object. */ @interface OFMemNotPartOfObjException: OFException { Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -94,44 +94,10 @@ - (size_t)requestedSize { return req_size; } -@end - -@implementation OFNotImplementedException -+ newWithObject: (id)obj - andSelector: (SEL)sel -{ - return [[OFNotImplementedException alloc] initWithObject: obj - andSelector: sel]; -} - -- initWithObject: (id)obj - andSelector: (SEL)sel -{ - if ((self = [super initWithObject: obj])) - selector = sel; - - return self; -} - -- (char*)cString -{ - if (string != NULL) - return string; - - asprintf(&string, "ERROR: Requested selector %s not implemented in " - "%s!\n", SEL_NAME(selector), [object name]); - - return string; -} - -- (SEL)selector -{ - return selector; -} @end @implementation OFMemNotPartOfObjException + newWithObject: (id)obj andPointer: (void*)ptr Index: src/OFMacros.h ================================================================== --- src/OFMacros.h +++ src/OFMacros.h @@ -7,16 +7,10 @@ * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ -/* Return is only to make the compiler happy - it is never reached */ -#define OF_NOT_IMPLEMENTED(ret) \ - [[OFNotImplementedException newWithObject: self \ - andSelector: _cmd] raise]; \ - return ret; - #ifdef OF_BIG_ENDIAN static inline void OF_BSWAP_V(uint8_t *buf, size_t len) { uint32_t t; Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -13,80 +13,107 @@ #import #import "OFObject.h" /** - * The OFString class can store and modify string of different types. - */ -@interface OFString: OFObject {} -/** - * \param str A constant C string from which the new OFConstCString will be - * created - * \return A new OFConstCString - */ -+ newAsConstCString: (const char*)str; - -/** - * \param str A constant wide C string from which the new OFConstCString will be - * created - * \return A new OFConstWideCString - */ -+ newAsConstWideCString: (const wchar_t*)str; - -/** - * \param str A C string from which the new OFConstCString will be created - * \return A new OFCString - */ -+ newAsCString: (char*)str; - -/** - * \param str A wide C string from which the new OFConstCString will be created - * \return A new OFWideCString - */ -+ newAsWideCString: (wchar_t*)str; - -/** - * \return The OFString as a C-type string of the type it was created as + * A class for storing and modifying strings. + */ +@interface OFString: OFObject +{ + wchar_t *string; + size_t length; +} + +/** + * Creates a new OFString. + * + * \return An initialized OFString + */ ++ new; + +/** + * Creates a new OFString from a C string. + * + * \param str A C string to initialize the OFString with + * \return A new OFString + */ ++ newFromCString: (const char*)str; + +/** + * Creates a new OFString from a wide C string. + * + * \param str A wide C string to initialize the OFString with + * \return A new OFString + */ ++ newFromWideCString: (const wchar_t*)str; + +/** + * Initializes an already allocated OFString. + * + * \return An initialized OFString + */ +- init; + +/** + * Initializes an already allocated OFString from a C string. + * + * \param str A C string to initialize the OFString with + * \return An initialized OFString + */ +- initFromCString: (const char*)str; + +/** + * Initializes an already allocated OFString from a wide C string. + * + * \param str A wide C string to initialize the OFString with + * \return An initialized OFString + */ +- initFromWideCString: (const wchar_t*)str; + +/** + * \return The OFString as a C string, if possible (if not, returns NULL). + * If not needed anymore, it is usefull to call freeMem:. */ - (char*)cString; /** - * \return The OFString as a C-type wide string of the type it was created as + * \return The OFString as a wide C string */ -- (wchar_t*)wCString; +- (wchar_t*)wideCString; /** * \return The length of the OFString */ - (size_t)length; -/** - * Sets the OFString to the specified OFString. - * - * \param str The OFString to set the current OFString to - */ -- (OFString*)setTo: (OFString*)str; - /** * Clones the OFString, creating a new one. * * \return A copy of the OFString */ - (OFString*)clone; +/** + * Frees the OFString and sets it to the specified OFString. + * + * \param str An OFString to set the OFString to. + * \return The new OFString + */ +- (OFString*)setTo: (OFString*)str; + /** * Compares the OFString to another OFString. * - * \param str An OFString in a compatible type to compare with - * \return An integer which is the result of the comparison, see strcmp + * \param str An OFString to compare with + * \return An integer which is the result of the comparison, see wcscmp */ -- (int)compareTo: (OFString*)str; +- (int)compare: (OFString*)str; /** * Append another OFString to the OFString. * - * \param str An OFString in a compatible type to append + * \param str An OFString to append */ - append: (OFString*)str; /** * Append a C string to the OFString. Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -11,87 +11,204 @@ #import "config.h" #import #import +#import #import "OFString.h" -#import "OFConstCString.h" -#import "OFConstWideCString.h" -#import "OFCString.h" -#import "OFWideCString.h" #import "OFExceptions.h" -#import "OFMacros.h" @implementation OFString -+ newAsConstCString: (const char*)str -{ - return [[OFConstCString alloc] initAsConstCString: str]; -} - -+ newAsConstWideCString: (const wchar_t*)str -{ - return [[OFConstWideCString alloc] initAsConstWideCString: str]; -} - -+ newAsCString: (char*)str -{ - return [[OFCString alloc] initAsCString: str]; -} - -+ newAsWideCString: (wchar_t*)str -{ - return [[OFWideCString alloc] initAsWideCString: str]; ++ new +{ + return [[OFString alloc] init]; +} + ++ newFromCString: (const char*)str +{ + return [[OFString alloc] initFromCString: str]; +} + ++ newFromWideCString: (const wchar_t*)str +{ + return [[OFString alloc] initFromWideCString: str]; +} + +- init +{ + if ((self = [super init])) { + length = 0; + string = NULL; + } + + return self; +} + +- initFromCString: (const char*)str +{ + if ((self = [super init])) { + if (str == NULL) { + length = 0; + string = NULL; + } else { + if ((length = mbstowcs(NULL, str, 0)) == (size_t)-1) { + /* FIXME: Throw exception */ + [super free]; + return nil; + } + + string = [self getMemForNItems: length + 1 + ofSize: sizeof(wchar_t)]; + + if (mbstowcs(string, str, length) != length) { + [super free]; + return nil; + } + } + } + + return self; +} + +- initFromWideCString: (const wchar_t*)str +{ + if ((self = [super init])) { + if (str == NULL) { + length = 0; + string = NULL; + } else { + length = wcslen(str); + string = [self getMemForNItems: length + 1 + ofSize: sizeof(wchar_t)]; + wmemcpy(string, str, length + 1); + } + } + + return self; } - (char*)cString { - OF_NOT_IMPLEMENTED(NULL) + char *str; + size_t len; + + if ((len = wcstombs(NULL, string, 0)) == (size_t)-1) { + /* FIXME: Throw exception */ + return NULL; + } + + str = [self getMemWithSize: len]; + + if (wcstombs(str, string, len) != len) { + /* FIXME: Throw exception */ + [self freeMem: str]; + return NULL; + } + + return str; } -- (wchar_t*)wCString +- (wchar_t*)wideCString { - OF_NOT_IMPLEMENTED(NULL) + return string; } - (size_t)length { - OF_NOT_IMPLEMENTED(0) + return length; +} + +- (OFString*)clone +{ + return [OFString newFromWideCString: string]; } - (OFString*)setTo: (OFString*)str { [self free]; - self = [str clone]; - return self; + return (self = [str clone]); } -- (OFString*)clone -{ - OF_NOT_IMPLEMENTED(nil) -} - -- (int)compareTo: (OFString*)str -{ - OF_NOT_IMPLEMENTED(0) +- (int)compare: (OFString*)str +{ + return wcscmp(string, [str wideCString]); } - append: (OFString*)str { - OF_NOT_IMPLEMENTED(nil) + return [self appendWideCString: [str wideCString]]; } - appendCString: (const char*)str { - OF_NOT_IMPLEMENTED(nil) + wchar_t *newstr, *tmpstr; + size_t newlen, strlength; + + if (string == NULL) + return [self setTo: [OFString newFromCString: str]]; + + if ((strlength = mbstowcs(NULL, str, 0)) == (size_t)-1) { + /* FIXME: Throw exception */ + return nil; + } + + tmpstr = [self getMemForNItems: strlength + 1 + ofSize: sizeof(wchar_t)]; + + if (mbstowcs(tmpstr, str, strlength) != strlength) { + /* FIXME: Throw exception */ + [self freeMem: tmpstr]; + return nil; + } + + newlen = length + strlength; + newstr = [self resizeMem: string + toNItems: newlen + 1 + ofSize: sizeof(wchar_t)]; + + wmemcpy(newstr + length, tmpstr, strlength + 1); + + length = newlen; + string = newstr; + + [self freeMem: tmpstr]; + + return self; } - appendWideCString: (const wchar_t*)str { - OF_NOT_IMPLEMENTED(nil) + wchar_t *newstr; + size_t newlen, strlength; + + if (string == NULL) + return [self setTo: [OFString newFromWideCString: str]]; + + strlength = wcslen(str); + newlen = length + strlength; + + newstr = [self resizeMem: string + toNItems: newlen + 1 + ofSize: sizeof(wchar_t)]; + + wmemcpy(newstr + length, str, strlength + 1); + + length = newlen; + string = newstr; + + return self; } - reverse { - OF_NOT_IMPLEMENTED(nil) + size_t i, j, len = length / 2; + + for (i = 0, j = length - 1; i < len; i++, j--) { + string[i] ^= string[j]; + string[j] ^= string[i]; + string[i] ^= string[j]; + } + + return self; } @end DELETED src/OFWideCString.h Index: src/OFWideCString.h ================================================================== --- src/OFWideCString.h +++ src/OFWideCString.h @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2008 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of libobjfw. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE included in - * the packaging of this file. - */ - -#import -#import - -#import "OFString.h" - -/** - * An OFString using a wide C string as internal storage. - */ -@interface OFWideCString: OFString -{ - wchar_t *string; - size_t length; -} - -/** - * Initializes an already allocated OFWideCString. - * - * \param str A wide C string to initialize the OFWideCString with - * \return An initialized OFWideCString - */ -- initAsWideCString: (wchar_t*)str; - -/** - * \return The OFWideCString as a wide C string - */ -- (wchar_t*)wCString; - -/** - * \return The length of the OFWideCString - */ -- (size_t)length; - -/** - * Clones the OFWideCString, creating a new one. - * - * \return A copy of the OFWideCString - */ -- (OFString*)clone; - -/** - * Compares the OFWideCString to another OFString. - * - * \param str An OFString in a compatible type to compare with - * \return An integer which is the result of the comparison, see wcscmp - */ -- (int)compareTo: (OFString*)str; - -/** - * Append another OFString to the OFWideCString. - * - * \param str An OFString in a compatible type to append - */ -- append: (OFString*)str; - -/** - * Append a wide C string to the OFWideCString. - * - * \param str A wide C string to append - */ -- appendWideCString: (const wchar_t*)str; - -/** - * Reverse the OFWideCString. - */ -- reverse; -@end DELETED src/OFWideCString.m Index: src/OFWideCString.m ================================================================== --- src/OFWideCString.m +++ src/OFWideCString.m @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2008 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of libobjfw. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE included in - * the packaging of this file. - */ - -#import "config.h" - -#import -#import -#import - -#import "OFWideCString.h" -#import "OFExceptions.h" - -@implementation OFWideCString -- initAsWideCString: (wchar_t*)str -{ - if ((self = [super init])) { - if (str == NULL) { - length = 0; - string = NULL; - } else { - length = wcslen(str); - string = [self getMemWithSize: (length + 1) * - sizeof(wchar_t)]; - wmemcpy(string, str, length + 1); - } - } - return self; -} - -- (wchar_t*)wCString -{ - return string; -} - -- (size_t)length -{ - return length; -} - -- (OFString*)clone -{ - return [OFString newAsWideCString: string]; -} - -- (int)compareTo: (OFString*)str -{ - return wcscmp(string, [str wCString]); -} - -- append: (OFString*)str -{ - return [self appendWideCString: [str wCString]]; -} - -- appendWideCString: (const wchar_t*)str -{ - wchar_t *newstr; - size_t newlen, strlength; - - if (string == NULL) - return [self setTo: [OFString - newAsWideCString: (wchar_t*)str]]; - - strlength = wcslen(str); - newlen = length + strlength; - - newstr = [self resizeMem: string - toSize: (newlen + 1) * sizeof(wchar_t)]; - - wmemcpy(newstr + length, str, strlength + 1); - - length = newlen; - string = newstr; - - return self; -} - -- reverse -{ - size_t i, j, len = length / 2; - - for (i = 0, j = length - 1; i < len; i++, j--) { - string[i] ^= string[j]; - string[j] ^= string[i]; - string[i] ^= string[j]; - } - - return self; -} -@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -1,3 +1,8 @@ -SUBDIRS = OFObject OFArray OFHashes OFString OFList OFWideString OFXMLFactory +SUBDIRS = OFObject \ + OFArray \ + OFHashes \ + OFString \ + OFList \ + OFXMLFactory include ../buildsys.mk Index: tests/OFList/OFList.m ================================================================== --- tests/OFList/OFList.m +++ tests/OFList/OFList.m @@ -7,22 +7,23 @@ * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ +#import #import #import #import "OFString.h" #import "OFList.h" /* TODO: Do real checks */ -const char *strings[] = { - "First String Object", - "Second String Object", - "Third String Object" +const wchar_t *strings[] = { + L"First String Object", + L"Second String Object", + L"Third String Object" }; int main() { @@ -30,30 +31,30 @@ OFList *list; OFListObject *iter; list = [OFList new]; - [list addNew: [OFString newAsConstCString: strings[0]]]; - [list addNew: [OFString newAsConstCString: strings[1]]]; - [list addNew: [OFString newAsConstCString: strings[2]]]; + [list addNew: [OFString newFromWideCString: strings[0]]]; + [list addNew: [OFString newFromWideCString: strings[1]]]; + [list addNew: [OFString newFromWideCString: strings[2]]]; for (iter = [list first], i = 0; iter != nil; iter = [iter next], i++) - if (!strcmp([(OFString*)[iter data] cString], strings[i])) + if (!wcscmp([(OFString*)[iter data] wideCString], strings[i])) printf("Element %zu is expected element. GOOD!\n", i); else { printf("Element %zu is not expected element!\n", i); return 1; } - if (!strcmp([(OFString*)[[list first] data] cString], strings[0])) + if (!wcscmp([(OFString*)[[list first] data] wideCString], strings[0])) puts("First element is expected element. GOOD!"); else { puts("First element is not expected element!"); return 1; } - if (!strcmp([(OFString*)[[list last] data] cString], strings[2])) + if (!wcscmp([(OFString*)[[list last] data] wideCString], strings[2])) puts("Last element is expected element. GOOD!"); else { puts("Last element is not expected element!"); return 1; } Index: tests/OFString/OFString.m ================================================================== --- tests/OFString/OFString.m +++ tests/OFString/OFString.m @@ -17,31 +17,31 @@ /* TODO: Do real checks */ int main() { - OFString *s1 = [OFString newAsCString: "test"]; - OFString *s2 = [OFString newAsCString: ""]; + OFString *s1 = [OFString newFromCString: "test"]; + OFString *s2 = [OFString newFromCString: ""]; OFString *s3; - OFString *s4 = [OFString newAsConstCString: NULL]; + OFString *s4 = [OFString new]; - [s2 appendCString: "123"]; s3 = [s1 clone]; - [s4 setTo: s2]; - - if (![s1 compareTo: s3]) + if (![s1 compare: s3]) puts("s1 and s3 match! GOOD!"); else { puts("s1 and s3 don't match!"); return 1; } - if (![s2 compareTo: s4]) + [s2 appendCString: "123"]; + [s4 setTo: s2]; + + if (![s2 compare: s4]) puts("s2 and s4 match! GOOD!"); else { - puts("s1 and s3 don't match!"); + puts("s2 and s4 don't match!"); return 1; } if (!strcmp([[s1 append: s2] cString], "test123")) puts("s1 appended with s2 is the expected string! GOOD!"); DELETED tests/OFWideString/Makefile Index: tests/OFWideString/Makefile ================================================================== --- tests/OFWideString/Makefile +++ tests/OFWideString/Makefile @@ -1,20 +0,0 @@ -PROG_NOINST = ofwidestring -SRCS = OFWideString.m - -include ../../buildsys.mk - -CPPFLAGS += -I../../src -LIBS += -lobjc -L../../src -lobjfw - -.PHONY: run - -all: run -run: ${PROG_NOINST} - rm -f libobjfw.so.1 libobjfw.so.1.0 libobjfw.dylib - ln -s ../../src/libobjfw.so libobjfw.so.1 - ln -s ../../src/libobjfw.so libobjfw.so.1.0 - ln -s ../../src/libobjfw.dylib libobjfw.dylib - LD_LIBRARY_PATH=. \ - DYLD_LIBRARY_PATH=. \ - ./${PROG_NOINST} - rm -f libobjfw.so.1 libobjfw.so.1.0 libobjfw.dylib DELETED tests/OFWideString/OFWideString.m Index: tests/OFWideString/OFWideString.m ================================================================== --- tests/OFWideString/OFWideString.m +++ tests/OFWideString/OFWideString.m @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2008 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of libobjfw. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE included in - * the packaging of this file. - */ - -#import - -#import "OFString.h" - -/* TODO: Do real checks */ - -int -main() -{ - OFString *s1 = [OFString newAsWideCString: L"test"]; - OFString *s2 = [OFString newAsWideCString: L""]; - OFString *s3; - OFString *s4 = [OFString newAsConstWideCString: NULL]; - - [s2 appendWideCString: L"123"]; - s3 = [s1 clone]; - - [s4 setTo: s2]; - - if (![s1 compareTo: s3]) - puts("s1 and s3 match! GOOD!"); - else { - puts("s1 and s3 don't match!"); - return 1; - } - - if (![s2 compareTo: s4]) - puts("s2 and s4 match! GOOD!"); - else { - puts("s1 and s3 don't match!"); - return 1; - } - - if (!wcscmp([[s1 append: s2] wCString], L"test123")) - puts("s1 appended with s2 is the expected string! GOOD!"); - else { - puts("s1 appended with s2 is not the expected string!"); - return 1; - } - - if (wcslen([s1 wCString]) == [s1 length] && [s1 length] == 7) - puts("s1 has the expected length. GOOD!"); - else { - puts("s1 does not have the expected length!"); - return 1; - } - - if (!wcscmp([[s1 reverse] wCString], L"321tset")) - puts("Reversed s1 is expected string! GOOD!"); - else { - puts("Reversed s1 is NOT the expected string!"); - return 1; - } - - [s1 free]; - [s2 free]; - [s3 free]; - [s4 free]; - - return 0; -}