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:
rfm 2011-02-16 08:21:17 +00:00
parent 48cc36811f
commit b179b29898
374 changed files with 20864 additions and 0 deletions

View file

@ -1,3 +1,8 @@
2011-02-16 Richard Frith-Macdonald <rfm@gnu.org>
* Tests/base: import the testsuite here
* Tests/GNUmakefile: add trivial makefile to run tests
2011-02-16 Wolfgang Lux <wolfgang.lux@gmail.com>
* Resources/German.lproj/Localizable.strings: Add translation for

49
Tests/GNUmakefile Normal file
View file

@ -0,0 +1,49 @@
#
# Tests Makefile for GNUstep Base Library.
#
# Copyright (C) 2011 Free Software Foundation, Inc.
#
# Written by: Richard Frith-Macdonald <rfm@gnu.org>
#
# This file is part of the GNUstep Base Library.
#
# This library 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 library 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 library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02111 USA
#
ifeq ($(GNUSTEP_MAKEFILES),)
GNUSTEP_MAKEFILES := $(shell gnustep-config --variable=GNUSTEP_MAKEFILES 2>/dev/null)
ifeq ($(GNUSTEP_MAKEFILES),)
$(warning )
$(warning Unable to obtain GNUSTEP_MAKEFILES setting from gnustep-config!)
$(warning Perhaps gnustep-make is not properly installed,)
$(warning so gnustep-config is not in your PATH.)
$(warning )
$(warning Your PATH is currently $(PATH))
$(warning )
endif
endif
ifeq ($(GNUSTEP_MAKEFILES),)
$(error You need to set GNUSTEP_MAKEFILES before running this!)
endif
check:
gnustep-tests base
clean:
gnustep-tests --clean

View file

@ -0,0 +1,139 @@
/* NSGeometry tests */
#import <Foundation/Foundation.h>
#import "Testing.h"
static BOOL MacOSXCompatibleGeometry()
{
NSUserDefaults *dflt = [NSUserDefaults standardUserDefaults];
if ([dflt boolForKey: @"GSOldStyleGeometry"] == YES)
return NO;
return [dflt boolForKey: @"GSMacOSXCompatible"];
}
/* Test the string functions */
int
geom_string()
{
#if defined(GNUSTEP_BASE_LIBRARY)
NSUserDefaults *dflt = [NSUserDefaults standardUserDefaults];
BOOL compat_mode = MacOSXCompatibleGeometry();
#endif
NSPoint p, p2;
NSRect r, r2;
NSSize s, s2;
NSString *sp, *sr, *ss;
p = NSMakePoint(23.45, -3.45);
r = NSMakeRect(23.45, -3.45, 2044.3, 2033);
s = NSMakeSize(0.5, 0.22);
PASS(NSEqualPoints(p, NSMakePoint(23.45, -3.45)),
"identical points are equal");
if (sizeof(CGFloat) == sizeof(float))
{
PASS(NSEqualPoints(p, NSMakePoint(23.450001, -3.45)),
"near identical points are equal");
}
else
{
PASS(NSEqualPoints(p, NSMakePoint(23.450000000000001, -3.45)),
"near identical points are equal");
}
PASS(!NSEqualPoints(p, NSMakePoint(23.4500019, -3.45)),
"moderately similar points are not equal");
PASS(NSEqualSizes(s, NSMakeSize(0.5, 0.22)),
"identical sizes are equal");
if (sizeof(CGFloat) == sizeof(float))
{
PASS(NSEqualSizes(s, NSMakeSize(0.50000001, 0.22)),
"near identical sizes are equal");
}
else
{
PASS(NSEqualSizes(s, NSMakeSize(0.50000000000000001, 0.22)),
"near identical sizes are equal");
}
PASS(!NSEqualSizes(s, NSMakeSize(0.50000003, 0.22)),
"moderately similar sizes are not equal");
PASS(NSEqualRects(r, NSMakeRect(23.45, -3.45, 2044.3, 2033)),
"identical rects are equal");
if (sizeof(CGFloat) == sizeof(float))
{
PASS(NSEqualRects(r, NSMakeRect(23.45, -3.45, 2044.3, 2033.00001)),
"near identical rects are equal");
}
else
{
PASS(NSEqualRects(r, NSMakeRect(23.45, -3.45, 2044.3, 2033.0000000000001)),
"near identical rects are equal");
}
PASS(!NSEqualRects(r, NSMakeRect(23.45, -3.45, 2044.3, 2033.0001)),
"moderately similar rects are not equal");
#if defined(GNUSTEP_BASE_LIBRARY)
if (compat_mode == YES)
{
[dflt setBool: NO forKey: @"GSMacOSXCompatible"];
[NSUserDefaults resetStandardUserDefaults];
}
PASS((MacOSXCompatibleGeometry() == NO),
"Not in MacOSX geometry compat mode");
sp = NSStringFromPoint(p);
p2 = NSPointFromString(sp);
PASS((EQ(p2.x, p.x) && EQ(p2.y, p.y)),
"Can read output of NSStringFromPoint");
sr = NSStringFromRect(r);
r2 = NSRectFromString(sr);
PASS((EQ(r2.origin.x, r.origin.x) && EQ(r2.origin.y, r.origin.y)
&& EQ(r2.size.width, r.size.width) && EQ(r2.size.height, r.size.height)),
"Can read output of NSStringFromRect");
ss = NSStringFromSize(s);
s2 = NSSizeFromString(ss);
PASS((EQ(s2.width, s.width) && EQ(s2.height, s.height)),
"Can read output of NSStringFromSize");
dflt = [NSUserDefaults standardUserDefaults];
[dflt setBool: YES forKey: @"GSMacOSXCompatible"];
[NSUserDefaults resetStandardUserDefaults];
PASS((MacOSXCompatibleGeometry() == YES),
"In MacOSX geometry compat mode");
#endif
sp = NSStringFromPoint(p);
p2 = NSPointFromString(sp);
PASS((EQ(p2.x, p.x) && EQ(p2.y, p.y)),
"Can read output of NSStringFromPoint (MacOSX compat)");
sr = NSStringFromRect(r);
r2 = NSRectFromString(sr);
PASS((EQ(r2.origin.x, r.origin.x) && EQ(r2.origin.y, r.origin.y)
&& EQ(r2.size.width, r.size.width) && EQ(r2.size.height, r.size.height)),
"Can read output of NSStringFromRect (MacOSX compat)");
ss = NSStringFromSize(s);
s2 = NSSizeFromString(ss);
PASS((EQ(s2.width, s.width) && EQ(s2.height, s.height)),
"Can read output of NSStringFromSize (MacOSX compat)");
#if defined(GNUSTEP_BASE_LIBRARY)
if (compat_mode != MacOSXCompatibleGeometry())
{
[dflt setBool: NO forKey: @"GSMacOSXCompatible"];
}
#endif
return 0;
}
int main()
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
geom_string();
[pool release]; pool = nil;
return 0;
}

View file

@ -0,0 +1,37 @@
#import <Foundation/Foundation.h>
#import "Testing.h"
int main()
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
id o;
/* The path utilities provide information about the current user and
* the current filesystem layout ... and are inherently system dependent
* so we can't know if they are operating correctly. The best we can do
* are trivial checks to see if their results look sane.
*/
NSLog(@"NSUserName() %@", o = NSUserName());
PASS([o length] > 0, "we can get a user name");
NSLog(@"NSFullUserName() %@", o = NSFullUserName());
PASS([o length] > 0, "we can get a full user name");
NSLog(@"NSHomeDirectory() %@", o = NSHomeDirectory());
PASS([o length] > 0, "we can get a home directory");
NSLog(@"NSTemporaryDirectory() %@", o = NSTemporaryDirectory());
PASS([o length] > 0, "we can get a temporary directory");
NSLog(@"NSOpenStepRootDirectory() %@", o = NSOpenStepRootDirectory());
PASS([o length] > 0, "we can get a root directory");
/* These functions have been removed in recent OSX but are retained in GNUstep
*/
#if defined(GNUSTEP_BASE_LIBRARY)
NSLog(@"NSStandardApplicationPaths() %@", o = NSStandardApplicationPaths());
PASS([o count] > 0, "we have application paths");
NSLog(@"NSStandardLibraryPaths() %@", o = NSStandardLibraryPaths());
PASS([o count] > 0, "we have library paths");
#endif
[pool release]; pool = nil;
return 0;
}

View file

@ -0,0 +1,90 @@
#import <Foundation/Foundation.h>
#import "Testing.h"
int main()
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSZone *aZone;
char *vp;
void *ovp;
aZone = NSDefaultMallocZone();
PASS((aZone != NULL), "NSDefaultMallocZone() returns something");
aZone = NSCreateZone(1024,1024,0);
PASS((aZone != NULL), "NSCreateZone() works for an unfreeable zone");
aZone = NSCreateZone(1024,1024,1);
PASS((aZone != NULL), "NSCreateZone() works for a normal zone");
if ([NSGarbageCollector defaultCollector] == nil)
{
NSSetZoneName(aZone, @"My Zone");
PASS(([NSZoneName(aZone) isEqual: @"My Zone"]),
"NSZoneName() returns previously set string");
vp = NSZoneCalloc(aZone,17,12);
memset(vp,1,17*12);
NS_DURING
{
NSZoneFree(aZone,vp);
PASS(1, "NSZoneFree() calloc'd buffer");
}
NS_HANDLER
PASS(0, "NSZoneFree() calloc'd buffer %s",
[[localException name] cString]);
NS_ENDHANDLER
NS_DURING
NSZoneFree(aZone,vp);
PASS(0, "NSZoneFree() free'd buffer throws exception");
NS_HANDLER
PASS(1, "NSZoneFree() free'd buffer throws exception: %s",
[[localException name] cString]);
NS_ENDHANDLER
vp = NSZoneMalloc(aZone,2000);
memset(vp,2,2000);
NS_DURING
{
NSZoneFree(aZone,vp);
PASS(1, "NSZoneFree() malloc'd buffer");
}
NS_HANDLER
PASS(0, "NSZoneFree() malloc'd buffer %s",
[[localException name] cString]);
NS_ENDHANDLER
ovp = NSZoneMalloc(aZone, 1000);
vp = NSZoneRealloc(aZone, ovp, 2000);
memset(vp,3,2000);
NSZoneRealloc(aZone, vp, 1000);
memset(vp,4,1000);
NS_DURING
NSZoneFree(aZone,vp);
PASS(1,"NSZoneFree() releases memory held after realloc");
NS_HANDLER
PASS(0,"NSZoneFree() releases memory held after realloc");
NS_ENDHANDLER
PASS((NSZoneFromPointer(vp) == aZone),
"NSZoneFromPointer() returns zone where memory came from");
NS_DURING
[NSString allocWithZone:aZone];
NSRecycleZone(aZone);
PASS(1,"NSRecycleZone seems to operate");
NS_HANDLER
PASS(0,"NSRecycleZone seems to operate");
NS_ENDHANDLER
}
[pool release]; pool = nil;
return 0;
}

View file

@ -0,0 +1,239 @@
#import "Testing.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSException.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
#import <Foundation/NSObjCRuntime.h>
#include <string.h>
#if defined(GNUSTEP)
#import <GNUstepBase/GSObjCRuntime.h>
#else
#include <objc/runtime.h>
#endif
static int c1count = 0;
static int c1initialize = 0;
static int c1load = 0;
@interface Class1 : NSObject
{
int ivar1;
Class1 *ivar1obj;
}
- (const char *) sel1;
@end
@implementation Class1
+ (void) initialize
{
if (self == [Class1 class])
c1initialize = ++c1count;
}
+ (void) load
{
c1load = ++c1count;
}
- (const char *) sel1
{
return "";
}
@end
@protocol SubProto
- (const char *) sel2;
@end
@interface SubClass1 : Class1 <SubProto>
{
int ivar2;
}
- (const char *) sel2;
@end
@implementation SubClass1
- (const char *) sel2
{
return "";
}
@end
@interface SubClass1 (Cat1)
- (BOOL) catMethod;
- (const char *) sel2;
@end
@implementation SubClass1 (Cat1)
- (BOOL) catMethod
{
return YES;
}
- (const char *) sel2
{
return "category sel2";
}
@end
int
main(int argc, char *argv[])
{
id obj;
Class cls;
Class meta;
SEL sel;
Ivar ivar;
Ivar *ivars;
unsigned int count;
unsigned int index;
Method method;
Method *methods;
Protocol **protocols;
NSUInteger s;
NSUInteger a;
const char *t0;
const char *t1;
t0 = "1@1:@";
t1 = NSGetSizeAndAlignment(t0, &s, &a);
PASS(t1 == &t0[2], "NSGetSizeAndAlignment() steps through id");
t1 = NSGetSizeAndAlignment(t1, &s, &a);
PASS(t1 == &t0[4], "NSGetSizeAndAlignment() steps through sel");
PASS(NO == class_isMetaClass(Nil),
"class_isMetaClass() returns NO for Nil");
PASS(Nil == class_getSuperclass(Nil),
"class_getSuperclass() returns NO for Nil");
PASS(strcmp(class_getName(Nil), "nil") == 0,
"class_getName() for Nil is nil");
PASS(0 == class_getInstanceVariable(Nil, 0),
"class_getInstanceVariables() for Nil,0 is 0");
PASS(0 == class_getVersion(Nil),
"class_getVersion() for Nil is 0");
obj = [NSObject new];
cls = [SubClass1 class];
PASS(c1initialize != 0, "+initialize was called");
PASS(c1load != 0, "+load was called");
PASS(c1initialize > c1load, "+load occurs before +initialize");
PASS(strcmp(class_getName(cls), "SubClass1") == 0, "class name works");
PASS(YES == class_respondsToSelector(cls, @selector(sel2)),
"class_respondsToSelector() works for class method");
PASS(YES == class_respondsToSelector(cls, @selector(sel1)),
"class_respondsToSelector() works for superclass method");
PASS(NO == class_respondsToSelector(cls, @selector(rangeOfString:)),
"class_respondsToSelector() returns NO for unknown method");
PASS(NO == class_respondsToSelector(cls, 0),
"class_respondsToSelector() returns NO for nul selector");
PASS(NO == class_respondsToSelector(0, @selector(sel1)),
"class_respondsToSelector() returns NO for nul class");
meta = object_getClass(cls);
PASS(class_isMetaClass(meta), "object_getClass() retrieves meta class");
PASS(strcmp(class_getName(meta), "SubClass1") == 0, "metaclass name works");
ivar = class_getInstanceVariable(cls, 0);
PASS(ivar == 0, "class_getInstanceVariable() returns 0 for null name");
ivar = class_getInstanceVariable(cls, "bad name");
PASS(ivar == 0, "class_getInstanceVariable() returns 0 for non-existent");
ivar = class_getInstanceVariable(0, "ivar2");
PASS(ivar == 0, "class_getInstanceVariable() returns 0 for Nil class");
ivar = class_getInstanceVariable(cls, "ivar2");
PASS(ivar != 0, "class_getInstanceVariable() works");
ivar = class_getInstanceVariable(cls, "ivar1");
PASS(ivar != 0, "class_getInstanceVariable() works for superclass ivar");
ivar = class_getInstanceVariable(cls, "ivar1obj");
PASS(ivar != 0, "class_getInstanceVariable() works for superclass obj ivar");
methods = class_copyMethodList(cls, &count);
PASS(count == 3, "SubClass1 has three methods");
PASS(methods[count] == 0, "method list is terminated");
method = methods[2];
sel = method_getName(method);
PASS(sel_isEqual(sel, sel_getUid("sel2")),
"last method is sel2");
PASS(method_getImplementation(method) != [cls instanceMethodForSelector: sel],
"method 2 is the original, overridden by the category");
method = methods[0];
sel = method_getName(method);
PASS(sel_isEqual(sel, sel_getUid("catMethod"))
|| sel_isEqual(sel, sel_getUid("sel2")),
"method 0 has expected name");
if (sel_isEqual(sel, sel_getUid("catMethod")))
{
method = methods[1];
sel = method_getName(method);
PASS(sel_isEqual(sel, sel_getUid("sel2")),
"method 1 has expected name");
PASS(method_getImplementation(method)
== [cls instanceMethodForSelector: sel],
"method 1 is the category method overriding original");
}
else
{
PASS(method_getImplementation(method)
== [cls instanceMethodForSelector: sel],
"method 0 is the category method overriding original");
method = methods[1];
sel = method_getName(method);
PASS(sel_isEqual(sel, sel_getUid("catMethod")),
"method 1 has expected name");
}
ivars = class_copyIvarList(cls, &count);
PASS(count == 1, "SubClass1 has one ivar");
PASS(ivars[count] == 0, "ivar list is terminated");
PASS(strcmp(ivar_getName(ivars[0]), "ivar2") == 0,
"ivar has correct name");
PASS(strcmp(ivar_getTypeEncoding(ivars[0]), @encode(int)) == 0,
"ivar has correct type");
protocols = class_copyProtocolList(cls, &count);
PASS(count == 1, "SubClass1 has one protocol");
PASS(protocols[count] == 0, "protocol list is terminated");
PASS(strcmp(protocol_getName(protocols[0]), "SubProto") == 0,
"protocol has correct name");
cls = objc_allocateClassPair([NSString class], "runtime generated", 0);
PASS(cls != Nil, "can allocate a class pair");
PASS(class_addIvar(cls, "iv1", 1, 6, "c") == YES,
"able to add iVar 'iv1'");
PASS(class_addIvar(cls, "iv2", 1, 5, "c") == YES,
"able to add iVar 'iv2'");
PASS(class_addIvar(cls, "iv3", 1, 4, "c") == YES,
"able to add iVar 'iv3'");
PASS(class_addIvar(cls, "iv4", 1, 3, "c") == YES,
"able to add iVar 'iv4'");
objc_registerClassPair (cls);
ivar = class_getInstanceVariable(cls, "iv1");
PASS(ivar != 0, "iv1 exists");
PASS(ivar_getOffset(ivar) == 64, "iv1 offset is 64");
ivar = class_getInstanceVariable(cls, "iv2");
PASS(ivar != 0, "iv2 exists");
PASS(ivar_getOffset(ivar) == 96, "iv2 offset is 96");
ivar = class_getInstanceVariable(cls, "iv3");
PASS(ivar != 0, "iv3 exists");
PASS(ivar_getOffset(ivar) == 112, "iv3 offset is 112");
ivar = class_getInstanceVariable(cls, "iv4");
PASS(ivar != 0, "iv4 exists");
PASS(ivar_getOffset(ivar) == 120, "iv4 offset is 120");
/* NSObjCRuntime function tests.
*/
sel = NSSelectorFromString(nil);
PASS(sel == 0,
"NSSelectorFromString() returns 0 for nil string");
PASS(NSStringFromSelector(0) == nil,
"NSStringFromSelector() returns nil for null selector");
sel = NSSelectorFromString(@"xxxyyy_odd_name_xxxyyy");
PASS(sel != 0,
"NSSelectorFromString() creates for non-existent selector");
PASS([NSStringFromSelector(sel) isEqual: @"xxxyyy_odd_name_xxxyyy"],
"NSStringFromSelector() works for existing selector");
return 0;
}

View file

@ -0,0 +1,32 @@
#
# GNUmakefile.postamble for base tests
#
# Find all all subdirectories and run a clean in them independantly
#
after-clean::
$(ECHO_NOTHING)\
RUNDIR=`pwd`; \
TESTDIRS=`find . -type d`; \
for dir in $$TESTDIRS __done; do \
if [ $$dir != . -a -f $$dir/GNUmakefile ]; then \
echo Cleaning $$dir; cd $$dir; make clean; cd $$RUNDIR; \
fi \
done \
$(END_ECHO)
after-distclean::
$(ECHO_NOTHING)\
RUNDIR=`pwd`; \
TESTDIRS=`find . -type d`; \
for dir in $$TESTDIRS __done; do \
if [ $$dir != . -a -f $$dir/GNUmakefile ]; then \
echo Cleaning $$dir; cd $$dir; make distclean; \
if [ \! -f IGNORE ]; then \
$(RM) GNUmakefile; \
fi; \
cd $$RUNDIR; \
fi \
done \
$(END_ECHO)

View file

@ -0,0 +1,9 @@
HTTP/1.1 200 OK
Date: Thu, 02 Oct 2008 17:07:20 GMT
Server: Microsoft-IIS/6.0
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Length: 0

31
Tests/base/GSMime/build.m Normal file
View file

@ -0,0 +1,31 @@
#if defined(GNUSTEP_BASE_LIBRARY)
#import <Foundation/Foundation.h>
#import <GNUstepBase/GSMime.h>
#import "Testing.h"
int main(int argc,char **argv)
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSString *data = nil;
GSMimeDocument *doc = [[GSMimeDocument alloc] init];
NSMutableDictionary *par = [[NSMutableDictionary alloc] init];
[par setObject: @"my/type" forKey: @"type"];
[doc setContent: @"Hello\r\n"];
[doc setHeader: [[GSMimeHeader alloc] initWithName: @"content-type"
value: @"text/plain"
parameters: par]];
[doc setHeader: [[GSMimeHeader alloc] initWithName: @"content-transfer-encoding"
value: @"binary"
parameters: nil]];
data = [NSData dataWithContentsOfFile: @"mime8.dat"];
PASS([[doc rawMimeData] isEqual: data], "Can make a simple document");
[arp release]; arp = nil;
return 0;
}
#else
int main(int argc,char **argv)
{
return 0;
}
#endif

141
Tests/base/GSMime/general.m Normal file
View file

@ -0,0 +1,141 @@
#if defined(GNUSTEP_BASE_LIBRARY)
#import <Foundation/Foundation.h>
#import <GNUstepBase/GSMime.h>
#import "Testing.h"
static GSMimeDocument *
parse(GSMimeParser *parser, NSData *data)
{
unsigned length = [data length];
unsigned index;
for (index = 0; index < length-1; index++)
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSData *d;
d = [data subdataWithRange: NSMakeRange(index, 1)];
if ([parser parse: d] == NO)
{
return [parser mimeDocument];
}
[arp release];
}
data = [data subdataWithRange: NSMakeRange(index, 1)];
if ([parser parse: data] == YES)
{
[parser parse: nil];
}
return [parser mimeDocument];
}
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSData *data;
GSMimeDocument *doc;
GSMimeDocument *idoc;
data = [NSData dataWithContentsOfFile: @"mime1.dat"];
idoc = parse([[GSMimeParser new] autorelease], data);
PASS(([[[[idoc content] objectAtIndex:0] content] isEqual: @"a"]),
"can parse one char base64 mime1.dat incrementally");
doc = [GSMimeParser documentFromData: data];
PASS(([[[[doc content] objectAtIndex:0] content] isEqual: @"a"]),
"can parse one char base64 mime1.dat in one go");
PASS([idoc isEqual: doc], "mime1.dat documents are the same");
data = [NSData dataWithContentsOfFile: @"mime2.dat"];
idoc = parse([[GSMimeParser new] autorelease], data);
PASS(([[idoc content] isEqual: @"aa"]),
"can parse two char base64 mime2.dat incrementally");
doc = [GSMimeParser documentFromData: data];
PASS(([[doc content] isEqual: @"aa"]),
"can parse two char base64 mime2.dat in one go");
PASS([idoc isEqual: doc], "mime2.dat documents are the same");
data = [NSData dataWithContentsOfFile: @"mime3.dat"];
idoc = parse([[GSMimeParser new] autorelease], data);
PASS(([[idoc content] isEqual: @"aaa"]),
"can parse three char base64 mime3.dat incrementally");
doc = [GSMimeParser documentFromData: data];
PASS(([[doc content] isEqual: @"aaa"]),
"can parse three char base64 mime3.dat in one go");
PASS([idoc isEqual: doc], "mime3.dat documents are the same");
data = [NSData dataWithContentsOfFile: @"mime4.dat"];
idoc = parse([[GSMimeParser new] autorelease], data);
PASS(([[[[idoc content] objectAtIndex:0] content] isEqual: @"hello\n"]
&& [[[[idoc content] objectAtIndex:1] content] isEqual: @"there\n"]),
"can parse multi-part text mime4.dat incrementally");
PASS(([[[[idoc content] objectAtIndex:0] contentFile] isEqual: @"a.a"]),
"can extract content file name from mime4.dat (incrementally parsed)");
PASS(([[[[idoc content] objectAtIndex:0] contentType] isEqual: @"text"]),
"can extract content type from mime4.dat (incrementally parsed)");
PASS(([[[[idoc content] objectAtIndex:0] contentSubtype] isEqual: @"plain"]),
"can extract content sub type from mime4.dat (incrementally parsed)");
doc = [GSMimeParser documentFromData: data];
PASS(([[[[doc content] objectAtIndex:0] content] isEqual: @"hello\n"]
&& [[[[doc content] objectAtIndex:1] content] isEqual: @"there\n"]),
"can parse multi-part text mime4.dat in one go");
PASS(([[[[doc content] objectAtIndex:0] contentFile] isEqual: @"a.a"]),
"can extract content file name from mime4.dat (parsed in one go)");
PASS(([[[[doc content] objectAtIndex:0] contentType] isEqual: @"text"]),
"can extract content type from mime4.dat (parsed in one go)");
PASS(([[[[doc content] objectAtIndex:0] contentSubtype] isEqual: @"plain"]),
"can extract content sub type from mime4.dat (parsed in one go)");
PASS([idoc isEqual: doc], "mime4.dat documents are the same");
data = [NSData dataWithContentsOfFile: @"mime5.dat"];
idoc = parse([[GSMimeParser new] autorelease], data);
PASS(([[idoc contentSubtype] isEqual: @"xml"]),
"can parse http document mime5.dat incrementally");
doc = [GSMimeParser documentFromData: data];
PASS(([[doc contentSubtype] isEqual: @"xml"]),
"can parse http document mime5.dat in one go");
PASS([idoc isEqual: doc], "mime5.dat documents are the same");
data = [NSData dataWithContentsOfFile: @"mime6.dat"];
idoc = parse([[GSMimeParser new] autorelease], data);
PASS(([[idoc content] count] == 3),
"can parse multipart mixed mime6.dat incrementally");
doc = [GSMimeParser documentFromData: data];
PASS(([[doc content] count] == 3),
"can parse multipart mixed mime6.dat in one go");
PASS([idoc isEqual: doc], "mime6.dat documents are the same");
data = [NSData dataWithContentsOfFile: @"mime7.dat"];
PASS(([[[[doc content] objectAtIndex:1] content] isEqual: data]),
"mime6.dat binary data part matches mime7.dat");
data = [NSData dataWithContentsOfFile: @"mime9.dat"];
idoc = parse([[GSMimeParser new] autorelease], data);
PASS(([[[idoc headerNamed: @"Long"] value] isEqual: @"first second third"]),
"mime9.dat folded header unfolds correctly incrementally");
doc = [GSMimeParser documentFromData: data];
//NSLog(@"'%@'", [[doc headerNamed: @"Long"] value]);
PASS(([[[doc headerNamed: @"Long"] value] isEqual: @"first second third"]),
"mime9.dat folded header unfolds correctly in one go");
PASS([idoc isEqual: doc], "mime9.dat documents are the same");
/* Test a document containing nested multipart documents
*/
data = [NSData dataWithContentsOfFile: @"mime10.dat"];
idoc = parse([[GSMimeParser new] autorelease], data);
doc = [GSMimeParser documentFromData: data];
PASS([idoc isEqual: doc], "mime10.dat documents are the same");
data = [idoc rawMimeData];
doc = [GSMimeParser documentFromData: data];
PASS([idoc isEqual: doc], "rawMimeData reproduces docuement");
[arp release]; arp = nil;
return 0;
}
#else
int main(int argc,char **argv)
{
return 0;
}
#endif

View file

@ -0,0 +1,18 @@
content-type: multipart/mixed; boundary=xxxx
--xxxx
content-transfer-encoding: base64
YQ==
--xxxx
content-transfer-encoding: 8bit
Hello there
--xxxx
content-transfer-encoding: 7bit
Testing again.
--xxxx--

View file

@ -0,0 +1,194 @@
Date: Mon, 27 May 2002 09:41:03 +0100
Mime-Version: 1.0 (Apple Message framework v481)
Content-Type: multipart/mixed; boundary=Apple-Mail-2--915493160
Subject: test
From: Richard Frith-Macdonald <richard@brainstorm.co.uk>
To: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Message-Id: <7A6B10F5-714D-11D6-9738-00306544502E@brainstorm.co.uk>
X-Mailer: Apple Mail (2.481)
X-SpamBouncer: 1.4 (10/07/01)
X-SBClass: OK
--Apple-Mail-2--915493160
Content-Disposition: attachment;
filename=a.a
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
x-unix-mode=0644;
name="a.a"
hello
--Apple-Mail-2--915493160
Content-Disposition: attachment;
filename=b.b
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
x-unix-mode=0644;
name="b.b"
there
--Apple-Mail-2--915493160
Content-Transfer-Encoding: 7bit
Content-Type: multipart/mixed; boundary="e7paaJyQU/hlJOcvRPG4PgAAAAU="
--e7paaJyQU/hlJOcvRPG4PgAAAAU=
Content-Type: application/smil; charset=us-ascii; name=mms.smil
Content-Transfer-Encoding: 7bit
<smil>
<head>
<layout>
<root-layout background-color="#FFFFFF"/>
<region id="Image" top="0" left="0" height="50%" width="100%" />
<region id="Text" top="50%" left="0" height="50%" width="100%" />
</layout>
</head>
<body>
<par dur="5000ms">
<img src="SME46224_1.gif" region="Image" />
</par>
<par dur="5000ms">
<text src="SME46224_2.txt" region="Text" />
</par>
</body>
</smil>
--e7paaJyQU/hlJOcvRPG4PgAAAAU=
Content-Type: image/gif; name=SME46224_1.gif
Content-Transfer-Encoding: base64
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
--e7paaJyQU/hlJOcvRPG4PgAAAAU=
Content-Type: text/plain; charset=us-ascii; name=SME46224_2.txt
Content-Transfer-Encoding: 7bit
You won't be worried about what people think of you once you see how they flock around today. The mere fact that someone has questions and interest in what you're doing suggests that they admire you for who and what you are.
--e7paaJyQU/hlJOcvRPG4PgAAAAU=
Content-Transfer-Encoding: 7bit
Content-Type: multipart/mixed; boundary="f7paaJyQU/hlJOcvRPG4PgAAAAU="
--f7paaJyQU/hlJOcvRPG4PgAAAAU=
Content-Type: application/smil; charset=us-ascii; name=mms.smil
Content-Transfer-Encoding: 7bit
<smil>
<head>
<layout>
<root-layout background-color="#FFFFFF"/>
<region id="Image" top="0" left="0" height="50%" width="100%" />
<region id="Text" top="50%" left="0" height="50%" width="100%" />
</layout>
</head>
<body>
<par dur="5000ms">
<img src="SME46224_1.gif" region="Image" />
</par>
<par dur="5000ms">
<text src="SME46224_2.txt" region="Text" />
</par>
</body>
</smil>
--f7paaJyQU/hlJOcvRPG4PgAAAAU=
Content-Type: image/gif; name=SME46224_1.gif
Content-Transfer-Encoding: base64
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
--f7paaJyQU/hlJOcvRPG4PgAAAAU=
Content-Type: text/plain; charset=us-ascii; name=SME46224_2.txt
Content-Transfer-Encoding: 7bit
You won't be worried about what people think of you once you see how they flock around today. The mere fact that someone has questions and interest in what you're doing suggests that they admire you for who and what you are.
--f7paaJyQU/hlJOcvRPG4PgAAAAU=--
--e7paaJyQU/hlJOcvRPG4PgAAAAU=--
--Apple-Mail-2--915493160--

View file

@ -0,0 +1,3 @@
content-transfer-encoding: base64
YWE=

View file

@ -0,0 +1,3 @@
content-transfer-encoding: base64
YWFh

View file

@ -0,0 +1,34 @@
Date: Mon, 27 May 2002 09:41:03 +0100
Mime-Version: 1.0 (Apple Message framework v481)
Content-Type: multipart/mixed; boundary=Apple-Mail-2--915493160
Subject: test
From: Richard Frith-Macdonald <richard@brainstorm.co.uk>
To: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Message-Id: <7A6B10F5-714D-11D6-9738-00306544502E@brainstorm.co.uk>
X-Mailer: Apple Mail (2.481)
X-SpamBouncer: 1.4 (10/07/01)
X-SBClass: OK
--Apple-Mail-2--915493160
Content-Disposition: attachment;
filename=a.a
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
x-unix-mode=0644;
name="a.a"
hello
--Apple-Mail-2--915493160
Content-Disposition: attachment;
filename=b.b
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
x-unix-mode=0644;
name="b.b"
there
--Apple-Mail-2--915493160--

View file

@ -0,0 +1,63 @@
HTTP/1.0 200 OK
Set-Cookie: WEBTRENDS_ID=213.86.45.65-35905744.29522136; expires=Fri, 31-Dec-2010 00:00:00 GMT; path=/
Server: Microsoft-IIS/4.0
Date: Mon, 21 Oct 2002 08:01:06 GMT
Content-Length: 3956
Content-Type: text/xml
Set-Cookie: ASPSESSIONIDGGQGQQDK=JJIMJBOCFKDOKHDJENONIFLG; path=/
Cache-Control: private
X-Cache: MISS from pcproxy.uk1.brainstorm.co.uk
Proxy-Connection: keep-alive
<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
<s:ElementType name='row' content='eltOnly' rs:CommandTimeout='30'>
<s:AttributeType name='horoscopeStartDate' rs:number='1'
rs:writeunknown='true'>
<s:datatype dt:type='dateTime' rs:dbtype='timestamp'
dt:maxLength='16' rs:scale='0' rs:precision='16' rs:fixedlength='true'
rs:maybenull='false'/>
</s:AttributeType>
<s:AttributeType name='horoscopeDescription' rs:number='2'
rs:writeunknown='true'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='2147483647'
rs:long='true' rs:maybenull='false'/>
</s:AttributeType>
<s:AttributeType name='horoscopeTypeComponentsDescription'
rs:number='3' rs:writeunknown='true'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='50'
rs:maybenull='false'/>
</s:AttributeType>
<s:extends type='rs:rowbase'/>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row horoscopeStartDate='2002-10-21T00:00:00' horoscopeDescription=' a conflict of interest can cause arguments and pettiness today, do not make it too personal if you are to retaliate.'
horoscopeTypeComponentsDescription='Aries'/>
<z:row horoscopeStartDate='2002-10-21T00:00:00' horoscopeDescription='surprise someone today with a rare show of your spontaneity and leadership ability. Their opinion of you will soar.'
horoscopeTypeComponentsDescription='Taurus'/>
<z:row horoscopeStartDate='2002-10-21T00:00:00' horoscopeDescription='the games you play may only increase your vulnerability, particularly with friendships, repair fragile bonds.'
horoscopeTypeComponentsDescription='Gemini'/>
<z:row horoscopeStartDate='2002-10-21T00:00:00' horoscopeDescription='sudden disruptions can strain your relationships, be prepared to reprioritise and make sure you land on your feet.'
horoscopeTypeComponentsDescription='Cancer'/>
<z:row horoscopeStartDate='2002-10-21T00:00:00' horoscopeDescription=' the path ahead divides and you must choose today what you want to do, you can seize this opportunity with some help.'
horoscopeTypeComponentsDescription='Leo'/>
<z:row horoscopeStartDate='2002-10-21T00:00:00' horoscopeDescription='mercurys aspects make it tempting to pour your heart out today, but if you must then select the listener carefully.'
horoscopeTypeComponentsDescription='Virgo'/>
<z:row horoscopeStartDate='2002-10-21T00:00:00' horoscopeDescription=' you are not often one to leap into action but today take a chance to prove your enthusiasm, surprise someone.'
horoscopeTypeComponentsDescription='Libra'/>
<z:row horoscopeStartDate='2002-10-21T00:00:00' horoscopeDescription='you can gain success over your anxiety today, take a little time to yourself or possibly a journey to regain strength.'
horoscopeTypeComponentsDescription='Scorpio'/>
<z:row horoscopeStartDate='2002-10-21T00:00:00' horoscopeDescription='Confusion over what to do today, work may prove more difficult than usual. Bear it and make no decision yet.'
horoscopeTypeComponentsDescription='Sagittarius'/>
<z:row horoscopeStartDate='2002-10-21T00:00:00' horoscopeDescription='be the strong and efficient one today in the face of a mess without becoming overbearing and you will reap the results.'
horoscopeTypeComponentsDescription='Capricorn'/>
<z:row horoscopeStartDate='2002-10-21T00:00:00' horoscopeDescription='You need to prove yourself to a doubter as their patience with you is waning, be the friend you need to be.'
horoscopeTypeComponentsDescription='Aquarius'/>
<z:row horoscopeStartDate='2002-10-21T00:00:00' horoscopeDescription='your senses are muffled by a new fun distraction, but be careful you do not neglect your responsibilities.'
horoscopeTypeComponentsDescription='Pisces'/>
</rs:data>
</xml>

View file

@ -0,0 +1,84 @@
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Bsmil-Feed: VDataFeed
X-Bsmil-Type: VDailyAries
X-Bsmil-Subtype:
X-Bsmil-Reference: 20021119
Content-Type: multipart/mixed; boundary="e7paaJyQU/hlJOcvRPG4PgAAAAU="
--e7paaJyQU/hlJOcvRPG4PgAAAAU=
Content-Type: application/smil; charset=us-ascii; name=mms.smil
Content-Transfer-Encoding: 7bit
<smil>
<head>
<layout>
<root-layout background-color="#FFFFFF"/>
<region id="Image" top="0" left="0" height="50%" width="100%" />
<region id="Text" top="50%" left="0" height="50%" width="100%" />
</layout>
</head>
<body>
<par dur="5000ms">
<img src="SME46224_1.gif" region="Image" />
</par>
<par dur="5000ms">
<text src="SME46224_2.txt" region="Text" />
</par>
</body>
</smil>
--e7paaJyQU/hlJOcvRPG4PgAAAAU=
Content-Type: image/gif; name=SME46224_1.gif
Content-Transfer-Encoding: base64
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
--e7paaJyQU/hlJOcvRPG4PgAAAAU=
Content-Type: text/plain; charset=us-ascii; name=SME46224_2.txt
Content-Transfer-Encoding: 7bit
You won't be worried about what people think of you once you see how they flock around today. The mere fact that someone has questions and interest in what you're doing suggests that they admire you for who and what you are.
--e7paaJyQU/hlJOcvRPG4PgAAAAU=--

BIN
Tests/base/GSMime/mime7.dat Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

@ -0,0 +1,5 @@
MIME-Version: 1.0
Content-Type: text/plain; type="my/type"
Content-Transfer-Encoding: binary
Hello

View file

@ -0,0 +1,8 @@
MIME-Version: 1.0
Content-Type: text/plain; type="my/type"
Content-Transfer-Encoding: binary
Long: first
second
third
Hello

View file

@ -0,0 +1,82 @@
#if defined(GNUSTEP_BASE_LIBRARY)
#import <Foundation/Foundation.h>
#import <GNUstepBase/GSMime.h>
#import "Testing.h"
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
GSMimeParser *parser = [GSMimeParser mimeParser];
NSStringEncoding enc = [GSMimeDocument encodingFromCharset: @"utf-8"];
NSData *data;
GSMimeDocument *doc = [[parser mimeDocument] retain];
GSMimeHeader *hdr;
NSString *val;
NSString *raw;
BOOL complete;
data = [@"Content-type: application/xxx\r\n" dataUsingEncoding: enc];
PASS([parser parse:data] && [parser isInHeaders] && (doc != nil),
"can parse one header");
PASS([doc contentType] == nil, "First Header not complete until next starts");
data = [@"Content-id: <" dataUsingEncoding:enc];
PASS([parser parse: data] &&
[parser isInHeaders],
"Adding partial headers is ok");
PASS([[doc contentType] isEqual: @"application"] &&
[[doc contentSubtype] isEqual:@"xxx"],"Parsed first header as expected");
data = [@"hello>\r\n" dataUsingEncoding: enc];
PASS([parser parse: data] &&
[parser isInHeaders],
"Completing partial header is ok");
PASS([doc contentID] == nil, "Partial header not complete until next starts");
data = [@"Folded\r\n : testing\r\n" dataUsingEncoding:enc];
PASS([parser parse:data] && [parser isInHeaders], "Folded header is ok");
PASS([@"<hello>" isEqual: [doc contentID]],"Parsed partial header as expected %s",[[doc contentID] cString]);
PASS([doc headerNamed: @"Folded"] == nil,"Folded header not complete until next starts");
data = [@"\r" dataUsingEncoding:enc];
PASS([parser parse:data] && [parser isInHeaders], "partial end-of-line is ok");
PASS([[[doc headerNamed:@"Folded"] value] isEqual: @"testing"],"Parsed folded header as expected %s",[[[doc headerNamed:@"Folded"] value] cString]);
data = [@"\n" dataUsingEncoding:enc];
PASS([parser parse:data] && ![parser isInHeaders], "completing end-of-line is ok");
doc = [GSMimeDocument documentWithContent:[@"\"\\UFE66???\"" propertyList]
type:@"text/plain"
name:nil];
[doc rawMimeData];
PASS([[[doc headerNamed:@"content-type"] parameterForKey:@"charset"] isEqual:@"utf-8"],"charset is inferred");
val = @"by mail.turbocat.net (Postfix, from userid 1002) id 90885422ECBF; Sat, 22 Dec 2007 15:40:10 +0100 (CET)";
raw = @"Received: by mail.turbocat.net (Postfix, from userid 1002) id 90885422ECBF;\r\n\tSat, 22 Dec 2007 15:40:10 +0100 (CET)\r\n";
hdr = [[GSMimeHeader alloc] initWithName: @"Received" value: val];
data = [hdr rawMimeDataPreservingCase: YES];
//NSLog(@"Header: '%*.*s'", [data length], [data length], [data bytes]);
PASS([data isEqual: [raw dataUsingEncoding: NSASCIIStringEncoding]],
"raw mime data for long header is OK");
data = [NSData dataWithContentsOfFile: @"HTTP1.dat"];
parser = [GSMimeParser mimeParser];
PASS ([parser parse: data] == NO, "can parse HTTP 200 reponse in one go");
PASS ([parser isComplete], "parse is complete");
[arp release]; arp = nil;
return 0;
}
#else
int main(int argc,char **argv)
{
return 0;
}
#endif

355
Tests/base/GSMime/test02.m Normal file
View file

@ -0,0 +1,355 @@
#if defined(GNUSTEP_BASE_LIBRARY)
#import <Foundation/Foundation.h>
#import <GNUstepBase/GSMime.h>
#import "Testing.h"
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
// Test charset conversions.
PASS([GSMimeDocument encodingFromCharset: @"ansi_x3.4-1968"]
== NSASCIIStringEncoding,
"charset 'ansi_x3.4-1968' is NSASCIIStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"ansi_x3.4-1986"]
== NSASCIIStringEncoding,
"charset 'ansi_x3.4-1986' is NSASCIIStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"apple-roman"]
== NSMacOSRomanStringEncoding,
"charset 'apple-roman' is NSMacOSRomanStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"ascii"]
== NSASCIIStringEncoding,
"charset 'ascii' is NSASCIIStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"big5"]
== NSBIG5StringEncoding,
"charset 'big5' is NSBIG5StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"cp367"]
== NSASCIIStringEncoding,
"charset 'cp367' is NSASCIIStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"cp819"]
== NSISOLatin1StringEncoding,
"charset 'cp819' is NSISOLatin1StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"csascii"]
== NSASCIIStringEncoding,
"charset 'csascii' is NSASCIIStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"csisolatin1"]
== NSISOLatin1StringEncoding,
"charset 'csisolatin1' is NSISOLatin1StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"gb2312.1980"]
== NSGB2312StringEncoding,
"charset 'gb2312.1980' is NSGB2312StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"gsm0338"]
== NSGSM0338StringEncoding,
"charset 'gsm0338' is NSGSM0338StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"ia5"]
== NSASCIIStringEncoding,
"charset 'ia5' is NSASCIIStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"ibm367"]
== NSASCIIStringEncoding,
"charset 'ibm367' is NSASCIIStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"ibm819"]
== NSISOLatin1StringEncoding,
"charset 'ibm819' is NSISOLatin1StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-10646-ucs-2"]
== NSUnicodeStringEncoding,
"charset 'iso-10646-ucs-2' is NSUnicodeStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso10646-ucs-2"]
== NSUnicodeStringEncoding,
"charset 'iso10646-ucs-2' is NSUnicodeStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-8859-1"]
== NSISOLatin1StringEncoding,
"charset 'iso-8859-1' is NSISOLatin1StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso8859-1"]
== NSISOLatin1StringEncoding,
"charset 'iso8859-1' is NSISOLatin1StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-8859-10"]
== NSISOLatin6StringEncoding,
"charset 'iso-8859-10' is NSISOLatin6StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso8859-10"]
== NSISOLatin6StringEncoding,
"charset 'iso8859-10' is NSISOLatin6StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-8859-11"]
== NSISOThaiStringEncoding,
"charset 'iso-8859-11' is NSISOThaiStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso8859-11"]
== NSISOThaiStringEncoding,
"charset 'iso8859-11' is NSISOThaiStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-8859-13"]
== NSISOLatin7StringEncoding,
"charset 'iso-8859-13' is NSISOLatin7StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso8859-13"]
== NSISOLatin7StringEncoding,
"charset 'iso8859-13' is NSISOLatin7StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-8859-14"]
== NSISOLatin8StringEncoding,
"charset 'iso-8859-14' is NSISOLatin8StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso8859-14"]
== NSISOLatin8StringEncoding,
"charset 'iso8859-14' is NSISOLatin8StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-8859-15"]
== NSISOLatin9StringEncoding,
"charset 'iso-8859-15' is NSISOLatin9StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso8859-15"]
== NSISOLatin9StringEncoding,
"charset 'iso8859-15' is NSISOLatin9StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-8859-1:1987"]
== NSISOLatin1StringEncoding,
"charset 'iso-8859-1:1987' is NSISOLatin1StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso8859-1:1987"]
== NSISOLatin1StringEncoding,
"charset 'iso8859-1:1987' is NSISOLatin1StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-8859-2"]
== NSISOLatin2StringEncoding,
"charset 'iso-8859-2' is NSISOLatin2StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso8859-2"]
== NSISOLatin2StringEncoding,
"charset 'iso8859-2' is NSISOLatin2StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-8859-3"]
== NSISOLatin3StringEncoding,
"charset 'iso-8859-3' is NSISOLatin3StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso8859-3"]
== NSISOLatin3StringEncoding,
"charset 'iso8859-3' is NSISOLatin3StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-8859-4"]
== NSISOLatin4StringEncoding,
"charset 'iso-8859-4' is NSISOLatin4StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso8859-4"]
== NSISOLatin4StringEncoding,
"charset 'iso8859-4' is NSISOLatin4StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-8859-5"]
== NSISOCyrillicStringEncoding,
"charset 'iso-8859-5' is NSISOCyrillicStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso8859-5"]
== NSISOCyrillicStringEncoding,
"charset 'iso8859-5' is NSISOCyrillicStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-8859-6"]
== NSISOArabicStringEncoding,
"charset 'iso-8859-6' is NSISOArabicStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso8859-6"]
== NSISOArabicStringEncoding,
"charset 'iso8859-6' is NSISOArabicStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-8859-7"]
== NSISOGreekStringEncoding,
"charset 'iso-8859-7' is NSISOGreekStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso8859-7"]
== NSISOGreekStringEncoding,
"charset 'iso8859-7' is NSISOGreekStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-8859-8"]
== NSISOHebrewStringEncoding,
"charset 'iso-8859-8' is NSISOHebrewStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso8859-8"]
== NSISOHebrewStringEncoding,
"charset 'iso8859-8' is NSISOHebrewStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-8859-9"]
== NSISOLatin5StringEncoding,
"charset 'iso-8859-9' is NSISOLatin5StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso8859-9"]
== NSISOLatin5StringEncoding,
"charset 'iso8859-9' is NSISOLatin5StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-ir-100"]
== NSISOLatin1StringEncoding,
"charset 'iso-ir-100' is NSISOLatin1StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-ir-6"]
== NSASCIIStringEncoding,
"charset 'iso-ir-6' is NSASCIIStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso-10646-1"]
== NSUnicodeStringEncoding,
"charset 'iso-10646-1' is NSUnicodeStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso10646-1"]
== NSUnicodeStringEncoding,
"charset 'iso10646-1' is NSUnicodeStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso646-us"]
== NSASCIIStringEncoding,
"charset 'iso646-us' is NSASCIIStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso_646.991-irv"]
== NSASCIIStringEncoding,
"charset 'iso_646.991-irv' is NSASCIIStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso_646.irv:1991"]
== NSASCIIStringEncoding,
"charset 'iso_646.irv:1991' is NSASCIIStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"iso_8859-1"]
== NSISOLatin1StringEncoding,
"charset 'iso_8859-1' is NSISOLatin1StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"jisx0201.1976"]
== NSShiftJISStringEncoding,
"charset 'jisx0201.1976' is NSShiftJISStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"koi8-r"]
== NSKOI8RStringEncoding,
"charset 'koi8-r' is NSKOI8RStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"ksc5601.1987"]
== NSKoreanEUCStringEncoding,
"charset 'ksc5601.1987' is NSKoreanEUCStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"ksc5601.1997"]
== NSKoreanEUCStringEncoding,
"charset 'ksc5601.1997' is NSKoreanEUCStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"l1"]
== NSISOLatin1StringEncoding,
"charset 'l1' is NSISOLatin1StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"latin1"]
== NSISOLatin1StringEncoding,
"charset 'latin1' is NSISOLatin1StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"microsoft-cp1250"]
== NSWindowsCP1250StringEncoding,
"charset 'microsoft-cp1250' is NSWindowsCP1250StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"microsoft-cp1251"]
== NSWindowsCP1251StringEncoding,
"charset 'microsoft-cp1251' is NSWindowsCP1251StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"microsoft-cp1252"]
== NSWindowsCP1252StringEncoding,
"charset 'microsoft-cp1252' is NSWindowsCP1252StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"microsoft-cp1253"]
== NSWindowsCP1253StringEncoding,
"charset 'microsoft-cp1253' is NSWindowsCP1253StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"microsoft-cp1254"]
== NSWindowsCP1254StringEncoding,
"charset 'microsoft-cp1254' is NSWindowsCP1254StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"microsoft-symbol"]
== NSSymbolStringEncoding,
"charset 'microsoft-symbol' is NSSymbolStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"shift_JIS"]
== NSShiftJISStringEncoding,
"charset 'shift_JIS' is NSShiftJISStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"us"]
== NSASCIIStringEncoding,
"charset 'us' is NSASCIIStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"us-ascii"]
== NSASCIIStringEncoding,
"charset 'us-ascii' is NSASCIIStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"utf-16"]
== NSUnicodeStringEncoding,
"charset 'utf-16' is NSUnicodeStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"utf16"]
== NSUnicodeStringEncoding,
"charset 'utf16' is NSUnicodeStringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"utf-7"]
== NSUTF7StringEncoding,
"charset 'utf-7' is NSUTF7StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"utf7"]
== NSUTF7StringEncoding,
"charset 'utf7' is NSUTF7StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"utf-8"]
== NSUTF8StringEncoding,
"charset 'utf-8' is NSUTF8StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"utf8"]
== NSUTF8StringEncoding,
"charset 'utf8' is NSUTF8StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"windows-1250"]
== NSWindowsCP1250StringEncoding,
"charset 'windows-1250' is NSWindowsCP1250StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"windows-1251"]
== NSWindowsCP1251StringEncoding,
"charset 'windows-1251' is NSWindowsCP1251StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"windows-1252"]
== NSWindowsCP1252StringEncoding,
"charset 'windows-1252' is NSWindowsCP1252StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"windows-1253"]
== NSWindowsCP1253StringEncoding,
"charset 'windows-1253' is NSWindowsCP1253StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"windows-1254"]
== NSWindowsCP1254StringEncoding,
"charset 'windows-1254' is NSWindowsCP1254StringEncoding");
PASS([GSMimeDocument encodingFromCharset: @"windows-symbol"]
== NSSymbolStringEncoding,
"charset 'windows-symbol' is NSSymbolStringEncoding");
// Test canonical charset names.
PASS([[GSMimeDocument charsetFromEncoding: NSASCIIStringEncoding]
isEqualToString: @"us-ascii"],
"NSASCIIStringEncoding canonical charset is us-ascii");
PASS([[GSMimeDocument charsetFromEncoding: NSBIG5StringEncoding]
isEqualToString: @"big5"],
"NSBIG5StringEncoding canonical charset is big5");
PASS([[GSMimeDocument charsetFromEncoding: NSGB2312StringEncoding]
isEqualToString: @"gb2312.1980"],
"NSGB2312StringEncoding canonical charset is gb2312.1980");
PASS([[GSMimeDocument charsetFromEncoding: NSGSM0338StringEncoding]
isEqualToString: @"gsm0338"],
"NSGSM0338StringEncoding canonical charset is gsm0338");
PASS([[GSMimeDocument charsetFromEncoding: NSISOArabicStringEncoding]
isEqualToString: @"iso-8859-6"],
"NSISOArabicStringEncoding canonical charset is iso-8859-6");
PASS([[GSMimeDocument charsetFromEncoding: NSISOCyrillicStringEncoding]
isEqualToString: @"iso-8859-5"],
"NSISOCyrillicStringEncoding canonical charset is iso-8859-5");
PASS([[GSMimeDocument charsetFromEncoding: NSISOGreekStringEncoding]
isEqualToString: @"iso-8859-7"],
"NSISOGreekStringEncoding canonical charset is iso-8859-7");
PASS([[GSMimeDocument charsetFromEncoding: NSISOHebrewStringEncoding]
isEqualToString: @"iso-8859-8"],
"NSISOHebrewStringEncoding canonical charset is iso-8859-8");
PASS([[GSMimeDocument charsetFromEncoding: NSISOLatin1StringEncoding]
isEqualToString: @"iso-8859-1"],
"NSISOLatin1StringEncoding canonical charset is iso-8859-1");
PASS([[GSMimeDocument charsetFromEncoding: NSISOLatin2StringEncoding]
isEqualToString: @"iso-8859-2"],
"NSISOLatin2StringEncoding canonical charset is iso-8859-2");
PASS([[GSMimeDocument charsetFromEncoding: NSISOLatin3StringEncoding]
isEqualToString: @"iso-8859-3"],
"NSISOLatin3StringEncoding canonical charset is iso-8859-3");
PASS([[GSMimeDocument charsetFromEncoding: NSISOLatin4StringEncoding]
isEqualToString: @"iso-8859-4"],
"NSISOLatin4StringEncoding canonical charset is iso-8859-4");
PASS([[GSMimeDocument charsetFromEncoding: NSISOLatin5StringEncoding]
isEqualToString: @"iso-8859-9"],
"NSISOLatin5StringEncoding canonical charset is iso-8859-9");
PASS([[GSMimeDocument charsetFromEncoding: NSISOLatin6StringEncoding]
isEqualToString: @"iso-8859-10"],
"NSISOLatin6StringEncoding canonical charset is iso-8859-10");
PASS([[GSMimeDocument charsetFromEncoding: NSISOLatin7StringEncoding]
isEqualToString: @"iso-8859-13"],
"NSISOLatin7StringEncoding canonical charset is iso-8859-13");
PASS([[GSMimeDocument charsetFromEncoding: NSISOLatin8StringEncoding]
isEqualToString: @"iso-8859-14"],
"NSISOLatin8StringEncoding canonical charset is iso-8859-14");
PASS([[GSMimeDocument charsetFromEncoding: NSISOLatin9StringEncoding]
isEqualToString: @"iso-8859-15"],
"NSISOLatin9StringEncoding canonical charset is iso-8859-15");
PASS([[GSMimeDocument charsetFromEncoding: NSISOThaiStringEncoding]
isEqualToString: @"iso-8859-11"],
"NSISOThaiStringEncoding canonical charset is iso-8859-11");
PASS([[GSMimeDocument charsetFromEncoding: NSKOI8RStringEncoding]
isEqualToString: @"koi8-r"],
"NSKOI8RStringEncoding canonical charset is koi8-r");
PASS([[GSMimeDocument charsetFromEncoding: NSKoreanEUCStringEncoding]
isEqualToString: @"ksc5601.1987"],
"NSKoreanEUCStringEncoding canonical charset is ksc5601.1987");
PASS([[GSMimeDocument charsetFromEncoding: NSMacOSRomanStringEncoding]
isEqualToString: @"apple-roman"],
"NSMacOSRomanStringEncoding canonical charset is apple-roman");
PASS([[GSMimeDocument charsetFromEncoding: NSShiftJISStringEncoding]
isEqualToString: @"shift_JIS"],
"NSShiftJISStringEncoding canonical charset is shift_JIS");
PASS([[GSMimeDocument charsetFromEncoding: NSUTF7StringEncoding]
isEqualToString: @"utf-7"],
"NSUTF7StringEncoding canonical charset is utf-7");
PASS([[GSMimeDocument charsetFromEncoding: NSUTF8StringEncoding]
isEqualToString: @"utf-8"],
"NSUTF8StringEncoding canonical charset is utf-8");
PASS([[GSMimeDocument charsetFromEncoding: NSUnicodeStringEncoding]
isEqualToString: @"utf-16"],
"NSUnicodeStringEncoding canonical charset is utf-16");
PASS([[GSMimeDocument charsetFromEncoding: NSWindowsCP1250StringEncoding]
isEqualToString: @"windows-1250"],
"NSWindowsCP1250StringEncoding canonical charset is windows-1250");
PASS([[GSMimeDocument charsetFromEncoding: NSWindowsCP1251StringEncoding]
isEqualToString: @"windows-1251"],
"NSWindowsCP1251StringEncoding canonical charset is windows-1251");
PASS([[GSMimeDocument charsetFromEncoding: NSWindowsCP1252StringEncoding]
isEqualToString: @"windows-1252"],
"NSWindowsCP1252StringEncoding canonical charset is windows-1252");
PASS([[GSMimeDocument charsetFromEncoding: NSWindowsCP1253StringEncoding]
isEqualToString: @"windows-1253"],
"NSWindowsCP1253StringEncoding canonical charset is windows-1253");
PASS([[GSMimeDocument charsetFromEncoding: NSWindowsCP1254StringEncoding]
isEqualToString: @"windows-1254"],
"NSWindowsCP1254StringEncoding canonical charset is windows-1254");
[arp release]; arp = nil;
return 0;
}
#else
int main(int argc,char **argv)
{
return 0;
}
#endif

156
Tests/base/GSXML/basic.m Normal file
View file

@ -0,0 +1,156 @@
#if defined(GNUSTEP_BASE_LIBRARY)
#import <Foundation/Foundation.h>
#import <GNUstepBase/GSXML.h>
#import "Testing.h"
#import "ObjectTesting.h"
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
GSXMLDocument *doc;
volatile GSXMLNamespace *namespace;
NSMutableArray *iparams;
NSMutableArray *oparams;
GSXMLNode *node;
GSXMLRPC *rpc;
NSString *str;
NSData *dat;
TEST_FOR_CLASS(@"GSXMLDocument",[GSXMLDocument alloc],
"GSXMLDocument +alloc returns a GSXMLDocument");
TEST_FOR_CLASS(@"GSXMLDocument",[GSXMLDocument documentWithVersion: @"1.0"],
"GSXMLDocument +documentWithVersion: returns a GSXMLDocument");
TEST_FOR_CLASS(@"GSXMLNode",[GSXMLNode alloc],
"GSXMLNode +alloc returns a GSXMLNode");
TEST_FOR_CLASS(@"GSXMLRPC",[GSXMLRPC alloc],
"GSXMLRPC +alloc returns a GSXMLRPC instance");
NS_DURING
node = [GSXMLNode new];
PASS(node == nil, "GSXMLNode +new returns nil");
NS_HANDLER
PASS(node == nil, "GSXMLNode +new returns nil");
NS_ENDHANDLER
TEST_FOR_CLASS(@"GSXMLNamespace",[GSXMLNamespace alloc],
"GSXMLNamespace +alloc returns a GSXMLNamespace");
NS_DURING
namespace = [GSXMLNamespace new];
PASS(namespace == nil, "GSXMLNamespace +new returns nil");
NS_HANDLER
PASS(namespace == nil, "GSXMLNamespace +new returns nil");
NS_ENDHANDLER
doc = [GSXMLDocument documentWithVersion: @"1.0"];
node = [doc makeNodeWithNamespace: nil name: @"nicola" content: nil];
PASS (node != nil,"Can create a document node");
[doc setRoot: node];
PASS([[doc root] isEqual: node],"Can set document node as root node");
[doc makeNodeWithNamespace: nil name: @"nicola" content: nil];
[node makeChildWithNamespace: nil
name: @"paragraph"
content: @"Hi this is some text"];
[node makeChildWithNamespace: nil
name: @"paragraph"
content: @"Hi this is even some more text"];
[doc setRoot: node];
PASS([[doc root] isEqual: node],
"Can set a document node (with children) as root node");
namespace = [node makeNamespaceHref: @"http: //www.gnustep.org"
prefix: @"gnustep"];
PASS(namespace != nil,"Can create a node namespace");
node = [doc makeNodeWithNamespace: namespace name: @"nicola" content: nil];
PASS([[node namespace] isEqual: namespace],
"Can create a node with a namespace");
node = [doc makeNodeWithNamespace: namespace name: @"another" content: nil];
PASS([[node namespace] isEqual: namespace],
"Can create a node with same namespace as another node");
PASS([[namespace prefix] isEqual: @"gnustep"],
"A namespace remembers its prefix");
rpc = [(GSXMLRPC*)[GSXMLRPC alloc] initWithURL: @"http://localhost/"];
PASS(rpc != nil, "Can initialise an RPC instance");
iparams = [NSMutableArray array];
oparams = [NSMutableArray array];
dat = [rpc buildMethod: @"method" params: nil];
PASS(dat != nil, "Can build an empty method call (nil params)");
str = [rpc parseMethod: dat params: oparams];
PASS([str isEqual: @"method"] && [iparams isEqual: oparams],
"Can parse an empty method call (nil params)");
dat = [rpc buildMethod: @"method" params: iparams];
PASS(dat != nil, "Can build an empty method call");
str = [rpc parseMethod: dat params: oparams];
PASS([str isEqual: @"method"] && [iparams isEqual: oparams],
"Can parse an empty method call");
[iparams addObject: @"a string"];
dat = [rpc buildMethod: @"method" params: iparams];
PASS(dat != nil, "Can build a method call with a string");
str = [rpc parseMethod: dat params: oparams];
PASS([str isEqual: @"method"] && [iparams isEqual: oparams],
"Can parse a method call with a string");
[rpc setCompact: YES];
str = [rpc buildMethodCall: @"method" params: iparams];
[rpc setCompact: NO];
str = [str stringByReplacingString: @"<string>" withString: @""];
str = [str stringByReplacingString: @"</string>" withString: @""];
str = [rpc parseMethod: [str dataUsingEncoding: NSUTF8StringEncoding]
params: oparams];
PASS([str isEqual: @"method"] && [iparams isEqual: oparams],
"Can parse a method call with a string without the <string> element");
[iparams addObject: [NSNumber numberWithInt: 4]];
dat = [rpc buildMethod: @"method" params: iparams];
PASS(dat != nil, "Can build a method call with an integer");
str = [rpc parseMethod: dat params: oparams];
PASS([str isEqual: @"method"] && [iparams isEqual: oparams],
"Can parse a method call with an integer");
[iparams addObject: [NSNumber numberWithFloat: 4.5]];
dat = [rpc buildMethod: @"method" params: iparams];
PASS(dat != nil, "Can build a method call with a float");
str = [rpc parseMethod: dat params: oparams];
PASS([str isEqual: @"method"] && [iparams isEqual: oparams],
"Can parse a method call with a float");
[iparams addObject: [NSData dataWithBytes: "1234" length: 4]];
dat = [rpc buildMethod: @"method" params: iparams];
PASS(dat != nil, "Can build a method call with binary data");
str = [rpc parseMethod: dat params: oparams];
PASS([str isEqual: @"method"] && [iparams isEqual: oparams],
"Can parse a method call with binary data");
[iparams addObject: [NSDate date]];
dat = [rpc buildMethod: @"method" params: iparams];
PASS(dat != nil, "Can build a method call with a date");
str = [rpc parseMethod: dat params: oparams];
PASS([str isEqual: @"method"]
&& [[iparams description] isEqual: [oparams description]],
"Can parse a method call with a date");
[arp release]; arp = nil;
return 0;
}
#else
int main(int argc,char **argv)
{
return 0;
}
#endif

View file

@ -0,0 +1,23 @@
#import <Foundation/Foundation.h>
#import "ObjectTesting.h"
int
main()
{
NSGarbageCollector *collector = [NSGarbageCollector defaultCollector];
NSZone *z;
if (collector == nil) return 0; // No garbage collection.
PASS([collector zone] == NSDefaultMallocZone(),
"collector zone is default");
PASS([[NSObject new] zone] == NSDefaultMallocZone(),
"object zone is default");
PASS((z = NSCreateZone(1024, 128, YES)) == NSDefaultMallocZone(),
"created zone is default");
PASS((z = NSCreateZone(1024, 128, YES)) == NSDefaultMallocZone(),
"created zone is default");
NSRecycleZone(z);
return 0;
}

View file

@ -0,0 +1,56 @@
#import <Foundation/Foundation.h>
#import "ObjectTesting.h"
@interface MyClass : NSObject
+ (unsigned) finalisationCounter;
+ (unsigned) notificationCounter;
- (void) notified: (NSNotification*)n;
@end
@implementation MyClass
static unsigned notificationCounter = 0;
static unsigned finalisationCounter = 0;
+ (unsigned) finalisationCounter
{
return finalisationCounter;
}
+ (unsigned) notificationCounter
{
return notificationCounter;
}
- (void) finalize
{
finalisationCounter++;
}
- (void) notified: (NSNotification*)n
{
notificationCounter++;
}
@end
int
main()
{
NSGarbageCollector *collector = [NSGarbageCollector defaultCollector];
NSNotificationCenter *center;
MyClass *object;
if (collector == nil) return 0; // No garbage collection.
center = [NSNotificationCenter defaultCenter];
object = [MyClass new];
[center addObserver: object
selector: @selector(notified:)
name: @"Notification"
object: nil];
[center postNotificationName: @"Notification" object: nil];
PASS([MyClass notificationCounter] == 1, "simple notification works");
object = nil;
[collector collectExhaustively];
PASS([MyClass finalisationCounter] == 1, "finalisation done");
[center postNotificationName: @"Notification" object: nil];
PASS([MyClass notificationCounter] == 1, "automatic removal works");
return 0;
}

View file

@ -0,0 +1,11 @@
#
#
#
include $(GNUSTEP_MAKEFILES)/common.make
SUBPROJECT_NAME=generictests
generictests_OBJC_FILES=generic.m
include $(GNUSTEP_MAKEFILES)/subproject.make

View file

View file

@ -0,0 +1,10 @@
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
@interface NSObject(TestsAdditions)
-(BOOL)testEquals: (id)anObject;
-(BOOL)testForString;
-(BOOL)testForClass;
@end

View file

@ -0,0 +1,20 @@
#import "generic.h"
@interface NSObject (PretendToBeNSString)
- (NSUInteger)length;
@end
@implementation NSObject(TestAdditions)
-(BOOL)testEquals:(id)anObject
{
return ([self isEqual:anObject] && [anObject isEqual:self]);
}
- (int) length
{
return 0;
}
-(BOOL)testForString
{
return ([self isKindOfClass:[NSString class]] && [self length]);
}
@end

69
Tests/base/KVC/array.m Normal file
View file

@ -0,0 +1,69 @@
#import "ObjectTesting.h"
#import <Foundation/Foundation.h>
@interface ArrayIVar : NSObject
{
NSArray *_testArray;
}
- (void) setTestArray: (NSArray*)array;
- (NSArray*) testArray;
@end
@implementation ArrayIVar
- (void) setTestArray: (NSArray*)array
{
[array retain];
[_testArray release];
_testArray = array;
}
- (NSArray*) testArray
{
return _testArray;
}
@end
int main(int argc,char **argv)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
volatile BOOL result = NO;
NSDictionary *root;
NSArray *array;
NSArray *ivar;
ArrayIVar *aiv;
NSString *plist;
id tmp = nil;
array = [@"({value=10;},{value=12;})" propertyList];
plist = @"{displayGroup={allObjects=({detailArray=({value=4;},{value=2;});},{detailArray=({value=8;},{value=10;});});};}";
root = [plist propertyList];
result = [[array valueForKeyPath:@"@sum.value"] intValue] == 22;
PASS(result, "-[NSArray valueForKeyPath: @\"@sum.value\"]");
result = [[array valueForKeyPath:@"@count.value"] intValue] == 2;
PASS(result, "-[NSArray valueForKeyPath: @\"@count.value\"]");
result = [[array valueForKeyPath:@"@count"] intValue] == 2;
PASS(result, "-[NSArray valueForKeyPath: @\"@count\"]");
aiv = [ArrayIVar new];
ivar = [NSArray arrayWithObjects: @"Joe", @"Foo", @"Bar", @"Cat", nil];
[aiv setTestArray: ivar];
PASS([aiv valueForKeyPath: @"testArray.@count"]
== [ivar valueForKey: @"@count"], "valueForKey: matches valueForKeypath:");
/* Advanced KVC */
result = [[root valueForKeyPath:@"displayGroup.allObjects.@sum.detailArray.@avg.value"] intValue] == 12;
PASS(result, "-[NSArray valueForKeyPath: @\"displayGroup.allObjects.@sum.detailArray.@avg.value\"]");
result = [[root valueForKeyPath:@"displayGroup.allObjects.@sum.detailArray.@count.value"] intValue] == 4;
PASS(result, "-[NSArray valueForKeyPath: @\"displayGroup.allObjects.@sum.detailArray.@count.value\"]");
result = [[root valueForKeyPath:@"displayGroup.allObjects.@sum.detailArray.@count"] intValue] == 4;
PASS(result, "-[NSArray valueForKeyPath: @\"displayGroup.allObjects.@sum.detailArray.@count\"]");
[pool release];
return (0);
}

257
Tests/base/KVC/basic.m Normal file
View file

@ -0,0 +1,257 @@
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSDate.h>
#import <Foundation/NSKeyValueCoding.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSDecimalNumber.h>
typedef struct {
int i;
char c;
} myStruct;
@interface TestClass : NSObject
{
NSString *name;
NSDate *date;
int num1;
double num2;
int num3;
int num4;
TestClass *child;
myStruct s;
}
- (void) setNum3:(int) num;
- (int) num3;
- (void) _setNum4:(int) num;
- (int) _num4;
- (char) sc;
- (int) si;
- (myStruct) sv;
- (void) setSv: (myStruct)v;
@end
@implementation TestClass
- (id) init
{
s.i = 1;
s.c = 2;
return self;
}
- (void) setNum3:(int) num
{
num3 = num;
if (num3 == 8) num3 = 7;
}
- (int) num3
{
return num3;
}
- (void) _setNum4:(int) num
{
num4 = num;
if (num4 == 8) num4 = 7;
}
- (int) _num4
{
return num4;
}
- (char) sc
{
return s.c;
}
- (int) si
{
return s.i;
}
- (myStruct) sv
{
return s;
}
- (void) setSv: (myStruct)v
{
s = v;
}
@end
@interface UndefinedKey : NSObject
{
int num1;
NSString *string;
}
@end
@implementation UndefinedKey
- (void) dealloc
{
[string release];
[super dealloc];
}
- (void) setValue:(id) value forUndefinedKey:(NSString *) key
{
if ([key isEqualToString: @"Lücke"]) {
[string release];
string = [value copy];
}
}
- (id) valueForUndefinedKey:(NSString *) key
{
if ([key isEqualToString: @"Lücke"]) {
return string;
}
return nil;
}
@end
@interface UndefinedKey2 : NSObject
{
int num1;
NSString *string;
}
@end
@implementation UndefinedKey2
- (void) dealloc
{
[string release];
[super dealloc];
}
- (void) handleTakeValue:(id) value forUnboundKey:(NSString *) key
{
if ([key isEqualToString: @"Lücke"]) {
[string release];
string = [value copy];
}
}
- (id) handleQueryWithUnboundKey:(NSString *) key
{
if ([key isEqualToString: @"Lücke"]) {
return string;
}
return nil;
}
@end
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSMutableString *m = [NSMutableString string];
TestClass *tester = [[[TestClass alloc] init] autorelease];
NSUInteger rc;
NSValue *v;
myStruct s;
[m appendString: @"testing"];
[tester setValue:[[[TestClass alloc] init] autorelease] forKey: @"child"];
UndefinedKey *undefinedKey = [[[UndefinedKey alloc] init] autorelease];
UndefinedKey2 *undefinedKey2 = [[[UndefinedKey2 alloc] init] autorelease];
NSNumber *n = [NSNumber numberWithInt:8];
NSNumber *adjustedN = [NSNumber numberWithInt:7];
NSNumber *n2 = [NSNumber numberWithDouble:87.999];
[tester setValue: @"tester" forKey: @"name"];
PASS([[tester valueForKey: @"name"] isEqualToString: @"tester"],
"KVC works with strings");
rc = [m retainCount];
[tester setValue: m forKey: @"name"];
PASS([tester valueForKey: @"name"] == m,
"KVC works with mutable string");
PASS(rc + 1 == [m retainCount], "KVC retains object values");
[tester setValue:n forKey: @"num1"];
PASS([[tester valueForKey: @"num1"] isEqualToNumber:n],
"KVC works with ints");
[tester setValue:n2 forKey: @"num2"];
PASS([[tester valueForKey: @"num2"] isEqualToNumber:n2],
"KVC works with doubles");
[tester setValue:n forKey: @"num3"];
PASS([[tester valueForKey: @"num3"] isEqualToNumber:adjustedN],
"KVC works with setKey:");
[tester setValue:n forKey: @"num4"];
PASS([[tester valueForKey: @"num4"] isEqualToNumber:adjustedN],
"KVC works with _setKey:");
v = [tester valueForKey: @"s"];
s.i = 0;
s.c = 0;
[v getValue: &s];
PASS(s.i == 1 && s.c == 2, "KVC valueForKey: works for a struct (direct)");
v = [tester valueForKey: @"sv"];
s.i = 0;
s.c = 0;
[v getValue: &s];
PASS(s.i == 1 && s.c == 2, "KVC valueForKey: works for a struct (getter)");
s.i = 3;
s.c = 4;
v = [NSValue valueWithBytes: &s objCType: @encode(myStruct)];
[tester setValue: v forKey: @"s"];
PASS([tester si] == s.i && [tester sc] == s.c,
"KVC setValue:forKey: works for a struct (direct)");
s.i = 5;
s.c = 6;
v = [NSValue valueWithBytes: &s objCType: @encode(myStruct)];
[tester setValue: v forKey: @"sv"];
PASS([tester si] == s.i && [tester sc] == s.c,
"KVC setValue:forKey: works for a struct (setter)");
[undefinedKey setValue: @"GNUstep" forKey: @"Lücke"];
PASS([[undefinedKey valueForKey: @"Lücke"] isEqualToString: @"GNUstep"],
"KVC works with undefined keys");
[undefinedKey2 setValue: @"GNUstep" forKey: @"Lücke"];
PASS([[undefinedKey2 valueForKey: @"Lücke"] isEqualToString: @"GNUstep"],
"KVC works with undefined keys (using deprecated methods) ");
PASS_EXCEPTION(
[tester setValue: @"" forKey: @"nonexistent"],
NSUndefinedKeyException,
"KVC properly throws @\"NSUnknownKeyException\"");
PASS_EXCEPTION(
[tester setValue: @"" forKey: @"nonexistent"],
NSUndefinedKeyException,
"KVC properly throws NSUndefinedKeyException");
PASS_EXCEPTION(
[tester setValue: @"" forKeyPath: @"child.nonexistent"],
@"NSUnknownKeyException",
"KVC properly throws @\"NSUnknownKeyException\" with key paths");
PASS_EXCEPTION(
[tester setValue: @"" forKeyPath: @"child.nonexistent"],
NSUndefinedKeyException,
"KVC properly throws NSUndefinedKeyException with key paths");
PASS(sel_getUid(0) == 0, "null string gives null selector");
PASS(sel_registerName(0) == 0, "register null string gives null selector");
PASS(strcmp(sel_getName(0) , "<null selector>") == 0, "null selector name");
[arp release]; arp = nil;
return 0;
}

250
Tests/base/KVC/mutable.m Normal file
View file

@ -0,0 +1,250 @@
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSKeyValueCoding.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSSet.h>
@interface Observer : NSObject
- (void) observeValueForKeyPath: (NSString *)keyPath
ofObject: (id)object
change: (NSDictionary *)change
context: (void *)context;
@end
@implementation Observer
- (void) observeValueForKeyPath: (NSString *)keyPath
ofObject: (id)object
change: (NSDictionary *)change
context: (void *)context
{
NSLog(@"observeValueForKeyPath: %@\nofObject:%@\nchange:%@\ncontext:%p",
keyPath, object, change, context);
}
@end
@interface Lists : NSObject
{
NSMutableArray * cities;
NSMutableArray * numbers;
NSMutableArray * third;
NSString *string;
}
@end
@implementation Lists
- (id)init
{
cities = [[NSMutableArray alloc] initWithObjects:
@"Grand Rapids",
@"Chicago",
nil];
numbers = [[NSMutableArray alloc] initWithObjects:
@"One",
@"Ten",
@"Three",
@"Ninety",
nil];
third = [[NSMutableArray alloc] initWithObjects:
@"a",
@"b",
@"c",
nil];
return self;
}
- (void)insertObject:(id)obj inNumbersAtIndex:(unsigned int)index
{
if (![obj isEqualToString:@"NaN"])
{
[numbers addObject:obj];
}
}
- (void)removeObjectFromNumbersAtIndex:(unsigned int)index
{
if (![[numbers objectAtIndex:index] isEqualToString:@"One"])
[numbers removeObjectAtIndex:index];
}
- (void)replaceObjectInNumbersAtIndex:(unsigned int)index withObject:(id)obj
{
if (index == 1)
obj = @"Two";
[numbers replaceObjectAtIndex:index withObject:obj];
}
- (void)setCities:(NSArray *)other
{
[cities setArray:other];
}
- (void) didChangeValueForKey: (NSString*)k
{
NSLog(@"%@ %@", NSStringFromSelector(_cmd), k);
[super didChangeValueForKey: k];
}
- (void) willChangeValueForKey: (NSString*)k
{
[super willChangeValueForKey: k];
NSLog(@"%@ %@", NSStringFromSelector(_cmd), k);
}
@end
@interface Sets : NSObject
{
NSMutableSet * one;
NSMutableSet * two;
NSMutableSet * three;
}
@end
@implementation Sets
- (id)init
{
[super init];
one = [[NSMutableSet alloc] initWithObjects:
@"one",
@"two",
@"eight",
nil];
two = [[NSMutableSet alloc] initWithSet:one];
three = [[NSMutableSet alloc] initWithSet:one];
return self;
}
- (void)addOneObject:(id)anObject
{
if (![anObject isEqualToString:@"ten"])
[one addObject:anObject];
}
- (void)removeOneObject:(id)anObject
{
if (![anObject isEqualToString:@"one"])
{
[one removeObject:anObject];
}
}
- (void)setTwo:(NSMutableSet *)set
{
[two setSet:set];
}
@end
int main(void)
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
Lists *list = [[[Lists alloc] init] autorelease];
Observer *observer = [Observer new];
id o;
NSMutableArray * proxy;
NSDictionary * temp;
[list addObserver: observer forKeyPath: @"numbers" options: 15 context: 0];
[list addObserver: observer forKeyPath: @"string" options: 15 context: 0];
[list setValue: @"x" forKey: @"string"];
proxy = [list mutableArrayValueForKey:@"numbers"];
PASS([proxy isKindOfClass:[NSMutableArray class]],
"proxy is a kind of NSMutableArray")
[proxy removeLastObject];
PASS_EXCEPTION([proxy addObject:@"NaN"];,
NSRangeException,"bad removal causes range exception when observing")
[proxy replaceObjectAtIndex:1 withObject:@"Seven"];
[proxy addObject:@"Four"];
[proxy removeObject:@"One"];
o = [NSArray arrayWithObjects:
@"One",
@"Two",
@"Three",
@"Four",
nil];
PASS([[list valueForKey:@"numbers"] isEqualToArray: o],
"KVC mutableArrayValueForKey: proxy works with array proxy methods")
proxy = [list mutableArrayValueForKey:@"cities"];
PASS([proxy isKindOfClass:[NSMutableArray class]],
"proxy is a kind of NSMutableArray")
[proxy addObject:@"Lima"];
o = [NSArray arrayWithObjects:
@"Grand Rapids",
@"Chicago",
@"Lima",
nil];
PASS([[list valueForKey:@"cities"] isEqualToArray: o],
"KVC mutableArrayValueForKey: proxy works with set<Key>:")
proxy = [list mutableArrayValueForKey:@"third"];
PASS([proxy isKindOfClass:[NSMutableArray class]],
"proxy is a kind of NSMutableArray")
PASS(proxy != [list valueForKey:@"third"],
"KVC mutableArrayValueForKey: returns a proxy array for the ivar")
PASS([[proxy objectAtIndex:1] isEqualToString:@"b"],
"This proxy works")
temp = [NSDictionary dictionaryWithObject:list forKey:@"list"];
proxy = [temp mutableArrayValueForKeyPath:@"list.numbers"];
PASS([proxy isKindOfClass:NSClassFromString(@"NSKeyValueMutableArray")],
"mutableArrayValueForKey: works")
Sets * set = [[[Sets alloc] init] autorelease];
NSMutableSet * setProxy;
setProxy = [set mutableSetValueForKey:@"one"];
PASS([setProxy isKindOfClass:[NSMutableSet class]],
"proxy is a kind of NSMutableSet")
[setProxy removeObject:@"one"];
[setProxy addObject:@"ten"];
[setProxy removeObject:@"eight"];
[setProxy addObject:@"three"];
o = [NSSet setWithObjects:@"one", @"two", @"three", nil];
PASS([setProxy isEqualToSet: o],
"KVC mutableSetValueForKey: proxy uses methods")
setProxy = [set mutableSetValueForKey:@"two"];
PASS([setProxy isKindOfClass:[NSMutableSet class]],
"proxy is a kind of NSMutableSet")
[setProxy addObject:@"seven"];
[setProxy minusSet:[NSSet setWithObject:@"eight"]];
o = [NSSet setWithObjects:@"one", @"two", @"seven", nil];
PASS([setProxy isEqualToSet: o],
"KVC mutableSetValueForKey: proxy works with set<Key>:")
setProxy = [set mutableSetValueForKey:@"three"];
PASS([setProxy isKindOfClass:[NSMutableSet class]],
"proxy is kind of NSMutableSet")
PASS(setProxy != [set valueForKey:@"three"],
"KVC mutableSetValueForKey: returns a proxy set for the ivar")
[setProxy addObject:@"seven"];
[setProxy removeObject:@"eight"];
o = [NSSet setWithObjects:@"one", @"two", @"seven", nil];
PASS([setProxy isEqualToSet: o], "this proxy works")
temp = [NSDictionary dictionaryWithObject:set forKey:@"set"];
setProxy = [temp mutableSetValueForKeyPath:@"set.three"];
PASS([setProxy isKindOfClass:NSClassFromString(@"NSKeyValueMutableSet")],
"mutableSetValueForKey: works")
[list removeObserver: observer forKeyPath: @"numbers"];
[list removeObserver: observer forKeyPath: @"string"];
[arp release]; arp = nil;
return 0;
}

67
Tests/base/KVC/nil.m Normal file
View file

@ -0,0 +1,67 @@
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSKeyValueCoding.h>
@interface DefaultNil : NSObject
{
int num;
}
@end
@implementation DefaultNil
- (id)init
{
num = 7;
return self;
}
@end
@interface DeprecatedNil : DefaultNil
- (void)unableToSetNilForKey:(NSString *)key;
@end
@implementation DeprecatedNil
- (void)unableToSetNilForKey:(NSString *)key
{
num = 0;
}
@end
@interface SetNil : DefaultNil
- (void)setNilValueForKey:(NSString *)key;
@end
@implementation SetNil
- (void)setNilValueForKey:(NSString *)key
{
num = 0;
}
@end
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
DefaultNil * defaultNil = [DefaultNil new];
DeprecatedNil * deprecatedNil = [DeprecatedNil new];
SetNil * setNil = [SetNil new];
PASS_EXCEPTION([defaultNil setValue: nil forKey: @"num"],
NSInvalidArgumentException, "KVC handles setting nil for a scalar")
PASS_EXCEPTION([defaultNil takeValue: nil forKey: @"num"],
NSInvalidArgumentException,
"KVC handles setting nil for a scalar via takeValue:")
[setNil setValue:nil forKey: @"num"];
PASS([[setNil valueForKey: @"num"] intValue] == 0,
"KVC uses setNilValueForKey:")
[deprecatedNil setValue:nil forKey: @"num"];
PASS([[deprecatedNil valueForKey: @"num"] intValue] == 0,
"KVC uses deprecated unableToSetNilForKey:")
[arp release]; arp = nil;
return 0;
}

139
Tests/base/KVC/path.m Normal file
View file

@ -0,0 +1,139 @@
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSKeyValueCoding.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSDecimalNumber.h>
#import <Foundation/NSDictionary.h>
@interface Tester : NSObject
{
int num1;
double num2;
id child;
NSMutableDictionary * dict;
}
@end
@implementation Tester
@end
@interface CustomKVC : NSObject
{
int num1;
NSString * string;
}
@end
@implementation CustomKVC
- (void)dealloc
{
[string release];
[super dealloc];
}
- (void)setValue:(id)value forKey:(NSString *)key
{
if ([key isEqualToString:@"num1"]) {
num1 = [value intValue];
} else if ([key isEqualToString:@"Lücke"]) {
[string release];
string = [value copy];
}
}
- (id)valueForKey:(NSString *)key
{
if ([key isEqualToString:@"num1"]) {
return [NSNumber numberWithInt:num1];
} else if ([key isEqualToString:@"Lücke"]) {
return string;
}
}
@end
@interface DeprecatedCustomKVC : NSObject
{
NSMutableDictionary * storage;
}
- (id)init;
- (id)valueForKey:(NSString *)key;
- (void)takeValue:(id)value forKey:(NSString *)key;
@end
@implementation DeprecatedCustomKVC
- (id)init
{
self = [super init];
storage = [[NSMutableDictionary alloc] init];
return self;
}
- (id)valueForKey:(NSString *)key
{
if ([key isEqualToString:@"dict"]) {
return storage;
}
return nil;
}
- (void)takeValue:(id)value forKey:(NSString *)key
{
if ([key isEqualToString:@"dict"]) {
[storage release];
storage = [value retain];
}
}
@end
int main(void) {
NSAutoreleasePool * arp = [NSAutoreleasePool new];
NSString * string = @"GNUstep";
Tester * tester = [[[Tester alloc] init] autorelease];
[tester setValue:[NSMutableDictionary dictionary] forKey:@"dict"];
[tester setValue:[[[Tester alloc] init] autorelease] forKey:@"child"];
[tester setValue:[[CustomKVC new] autorelease]
forKeyPath:@"child.child"];
DeprecatedCustomKVC * deprecated = [[[DeprecatedCustomKVC alloc] init]
autorelease];
NSNumber * n = [NSNumber numberWithInt:8];
NSNumber * adjustedN = [NSNumber numberWithInt:7];
NSNumber * n2 = [NSNumber numberWithDouble:87.999];
[tester setValue:n2 forKeyPath:@"child.num2"];
PASS([[tester valueForKeyPath:@"child.num2"] isEqualToNumber:n2],
"KVC works with simple paths");
[deprecated takeValue:[NSDictionary dictionaryWithObject:@"test"
forKey:@"key"]
forKey:@"dict"];
PASS_RUNS(
[tester setValue:n forKeyPath:@"child.child.num1"],
"KVC appears to work with key path");
PASS([[tester valueForKeyPath:@"child.child.num1"] isEqualToNumber:n],
"KVC works with key paths");
NSLog(@"tester.child.child = %@", [tester valueForKeyPath:
@"child.child"]);
PASS_RUNS(
[tester setValue:string forKeyPath:@"child.child.Lücke"],
"KVC appears to work with a unicode key path");
PASS([[tester valueForKeyPath:@"child.child.Lücke"] isEqualToString:string],
"KVC works with unicode path");
PASS_RUNS(
[tester setValue:string forKeyPath:@"dict.Lücke"],
"KVC appears to work with a unicode key path (test2)");
PASS([[tester valueForKeyPath:@"dict.Lücke"] isEqualToString:string],
"KVC works with unicode path (test2)");
[arp release];
return 0;
}

View file

@ -0,0 +1,70 @@
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSAffineTransform.h>
#include <math.h>
static BOOL eq(double d1, double d2)
{
if (abs(d1 - d2) < 0.000001)
return YES;
return NO;
}
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSAffineTransform *testObj;
NSAffineTransformStruct flip = {1.0,0.0,0.0,-1.0,0.0,0.0};
NSMutableArray *testObjs = [NSMutableArray new];
NSPoint p;
NSSize s;
testObj = [NSAffineTransform new];
[testObjs addObject:testObj];
PASS(testObj != nil, "can create a new transfor");
test_NSObject(@"NSAffineTransform", testObjs);
test_NSCoding(testObjs);
test_NSCopying(@"NSAffineTransform", @"NSAffineTransform", testObjs, NO, YES);
testObj = [NSAffineTransform transform];
PASS(testObj != nil, "can create an autoreleased transform");
[testObj setTransformStruct: flip];
p = [testObj transformPoint: NSMakePoint(10,10)];
PASS(eq(p.x, 10) && eq(p.y, -10), "flip transform inverts point y");
s = [testObj transformSize: NSMakeSize(10,10)];
PASS(s.width == 10 && s.height == -10, "flip transform inverts size height");
p = [testObj transformPoint: p];
s = [testObj transformSize: s];
PASS(eq(p.x, 10) && eq(p.y, 10) && s.width == 10 && s.height == 10,
"flip is reversible");
testObj = [NSAffineTransform transform];
[testObj translateXBy: 5.0 yBy: 6.0];
p = [testObj transformPoint: NSMakePoint(10,10)];
PASS(eq(p.x, 15.0) && eq(p.y, 16.0), "simple translate works");
[testObj translateXBy: 5.0 yBy: 4.0];
p = [testObj transformPoint: NSMakePoint(10,10)];
PASS(eq(p.x, 20.0) && eq(p.y, 20.0), "two simple translates work");
[testObj rotateByDegrees: 90.0];
p = [testObj transformPoint: NSMakePoint(10,10)];
PASS(eq(p.x, 0.0) && eq(p.y, 20.0), "translate and rotate works");
testObj = [NSAffineTransform transform];
[testObj rotateByDegrees: 90.0];
p = [testObj transformPoint: NSMakePoint(10,10)];
PASS(eq(p.x, -10.0) && eq(p.y, 10.0), "simple rotate works");
[testObj translateXBy: 5.0 yBy: 6.0];
p = [testObj transformPoint: NSMakePoint(10,10)];
PASS(eq(p.x, -16.0) && eq(p.y, 15.0), "rotate and translate works");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,13 @@
#import <Foundation/Foundation.h>
#import "ObjectTesting.h"
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
test_alloc(@"NSArchiver");
test_NSObject(@"NSArchiver",[NSArray arrayWithObject:[[NSArchiver alloc] init]]);
test_alloc(@"NSUnarchiver");
test_NSObject(@"NSUnarchiver",[NSArray arrayWithObject:[[NSUnarchiver alloc] init]]);
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,30 @@
#import <Foundation/NSArchiver.h>
#import <Foundation/NSException.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSData.h>
#import "Testing.h"
#import "ObjectTesting.h"
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
id obj = [NSArchiver new];
NSMutableData *data1;
PASS((obj != nil && [obj isKindOfClass:[NSArchiver class]] &&
[obj archiverData] != nil), "+new creates an empty NSArchiver");
[obj release];
obj = [NSArchiver alloc];
data1 = [NSMutableData dataWithLength: 0];
obj = [obj initForWritingWithMutableData: data1];
PASS((obj != nil && [obj isKindOfClass:[NSArchiver class]] && data1 == [obj archiverData]), "-initForWritingWithMutableData seems ok");
PASS_EXCEPTION([[NSUnarchiver alloc] initForReadingWithData:nil];,
@"NSInvalidArgumentException",
"Creating an NSUnarchiver with nil data throws an exception");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,44 @@
#import <Foundation/NSString.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSArchiver.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSData.h>
#import <Foundation/NSFileManager.h>
#import "Testing.h"
#import "ObjectTesting.h"
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSString *val1, *val2, *val3;
NSArray *vals1, *vals2;
NSData *data1;
NSArray *a;
PASS_RUNS(val1 = [NSString stringWithCString:"Archiver.dat"];
val2 = [NSString stringWithCString:"A Goodbye"];
val3 = [NSString stringWithCString:"Testing all strings"];
vals1 = [[NSArray arrayWithObject:val1] arrayByAddingObject:val2];
vals2 = [vals1 arrayByAddingObject:val2];,
"We can build basic strings and arrays for tests");
data1 = [NSArchiver archivedDataWithRootObject:vals2];
PASS((data1 != nil && [data1 length] != 0),
"archivedDataWithRootObject: seems ok");
PASS([NSArchiver archiveRootObject:vals2 toFile:val1],
"archiveRootObject:toFile: seems ok");
a = [NSUnarchiver unarchiveObjectWithData:data1];
PASS((a != nil && [a isKindOfClass:[NSArray class]] && [a isEqual:vals2]),
"unarchiveObjectWithData: seems ok");
a = [NSUnarchiver unarchiveObjectWithFile:val1];
PASS((a != nil && [a isKindOfClass:[NSArray class]] && [a isEqual:vals2]),
"unarchiveObjectWithFile: seems ok");
[[NSFileManager defaultManager] removeFileAtPath: val1 handler: nil];
[arp release]; arp = nil;
return 0;
}

View 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;
}

View 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;
}

View 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;
}

View file

@ -0,0 +1,3 @@
(
(1, 2, 3)
)

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:[NSAttributedString new]];
test_alloc(@"NSAttributedString");
test_NSObject(@"NSAttributedString", 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,45 @@
#import <Foundation/NSString.h>
#import <Foundation/NSAttributedString.h>
#import <Foundation/NSAutoreleasePool.h>
#import "ObjectTesting.h"
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSString *key1, *val1, *str1;
NSRange r = NSMakeRange(0,6);
NSAttributedString *astr1, *astr2;
NSDictionary *dict1;
NSRange range = NSMakeRange(0,0);
id obj;
key1 = @"Helvetica 12-point";
val1 = @"NSFontAttributeName";
str1 = @"Attributed string test";
dict1 = [NSDictionary dictionaryWithObject:val1 forKey:key1];
astr1 = [[NSAttributedString alloc] initWithString:str1 attributes:dict1];
PASS(astr1 != nil && [astr1 isKindOfClass:[NSAttributedString class]] &&
[[astr1 string] isEqual: str1],"-initWithString:attributes: works");
obj = [astr1 attributesAtIndex:0 effectiveRange:&range];
PASS(obj != nil && [obj isKindOfClass:[NSDictionary class]] &&
[obj count] == 1 && range.length != 0,
"-attributesAtIndex:effectiveRange: works");
obj = [astr1 attribute:key1 atIndex:0 effectiveRange:&range];
PASS(obj != nil && [obj isEqual:val1] && range.length != 0,
"-attribute:atIndex:effectiveRange: works");
obj = [astr1 attributedSubstringFromRange:r];
PASS(obj != nil && [obj isKindOfClass:[NSAttributedString class]] &&
[obj length] == r.length,"-attributedSubstringFromRange works");
r = NSMakeRange(0,[astr1 length]);
astr2 = [astr1 attributedSubstringFromRange:r];
PASS(astr2 != nil && [astr1 isEqualToAttributedString:astr2],
"extract and compare using -isEqualToAttributedString works");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,9 @@
ADDITIONAL_OBJCFLAGS += -I../GenericTests/ -I../../.. -Wall
$(GNUSTEP_INSTANCE)_SUBPROJECTS = ../GenericTests
SUBPROJECTS = ../GenericTests Resources
include $(GNUSTEP_MAKEFILES)/aggregate.make

View file

@ -0,0 +1 @@
English resource

View file

@ -0,0 +1 @@
French resource

View file

@ -0,0 +1,14 @@
include $(GNUSTEP_MAKEFILES)/common.make
BUNDLE_NAME = TestBundle
TestBundle_OBJC_FILES = TestBundle.m
TestBundle_RESOURCE_FILES = NonLocalRes.txt
TestBundle_LANGUAGES = English French
TestBundle_LOCALIZED_RESOURCE_FILES = TextRes.txt
TestBundle_NEEDS_GUI = NO
include $(GNUSTEP_MAKEFILES)/bundle.make
check:: all

View file

View file

@ -0,0 +1 @@
Non-localized Text resource

View file

@ -0,0 +1,16 @@
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
@interface TestBundle : NSObject
{
}
-(NSString *)test;
@end
@implementation TestBundle
-(NSString *)test
{
return @"Something";
}
@end

View file

@ -0,0 +1,3 @@
{
CFBundleIdentifier = "Test Bundle Identifier 1";
}

View file

@ -0,0 +1,13 @@
#import "ObjectTesting.h"
#import <Foundation/NSBundle.h>
#import <Foundation/NSAutoreleasePool.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
test_alloc(@"NSBundle");
test_NSObject(@"NSBundle", [NSArray arrayWithObject:[NSBundle new]]);
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,43 @@
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSFileManager.h>
#import "ObjectTesting.h"
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSString *path;
NSBundle *bundle;
path = [[[NSFileManager defaultManager] currentDirectoryPath]
stringByAppendingPathComponent:@"Resources"];
PASS([NSBundle mainBundle] != nil,
"+mainBundle returns non-nil if the tool has no bundle");
bundle = [NSBundle bundleWithPath:path];
[bundle retain];
TEST_FOR_CLASS(@"NSBundle", bundle, "+bundleWithPath returns a bundle");
TEST_STRING([bundle bundlePath],"a bundle has a path");
PASS([path isEqual:[bundle bundlePath]] &&
[[bundle bundlePath] isEqual:path],
"bundlePath returns the correct path");
TEST_FOR_CLASS(@"NSDictionary",[bundle infoDictionary],
"a bundle has an infoDictionary");
PASS([NSBundle bundleWithPath:
[path stringByAppendingPathComponent:@"nonexistent"]] == nil,
"+bundleWithPath returns nil for a non-existing path");
{
NSArray *arr = [NSBundle allBundles];
PASS(arr != nil && [arr isKindOfClass:[NSArray class]] && [arr count] != 0,
"+allBundles returns an array");
}
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,78 @@
#import "ObjectTesting.h"
#import <Foundation/Foundation.h>
@interface TestClass : NSObject
@end
@implementation TestClass
@end
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSBundle *classBundle, *gnustepBundle, *identifierBundle, *bundle;
NSFileManager *fm = [NSFileManager defaultManager];
NSString *path, *exepath;
gnustepBundle = [NSBundle bundleForLibrary: @"gnustep-base"];
TEST_FOR_CLASS(@"NSBundle",gnustepBundle,
"+bundleForLibrary: makes a bundle for us");
PASS([gnustepBundle principalClass] == [NSObject class],
"-principalClass returns NSObject for the +bundleForLibrary:gnustep-base");
classBundle = [NSBundle bundleForClass: [TestClass class]];
TEST_FOR_CLASS(@"NSBundle",classBundle,
"+bundleForClass: makes a bundle for us");
NSLog(@"%@", [classBundle principalClass]);
PASS([classBundle principalClass] == [TestClass class],
"-principalClass returns TestClass for +bundleForClass:[TestClass class]");
PASS(classBundle == [NSBundle mainBundle],
"-mainBundle is the same as +bundleForClass:[TestClass class]");
PASS([[gnustepBundle classNamed:@"NSArray"] isEqual:[NSArray class]] &&
[[NSArray class] isEqual: [gnustepBundle classNamed:@"NSArray"]],
"-classNamed returns the correct class");
TEST_STRING([gnustepBundle resourcePath],"-resourcePath returns a string");
[gnustepBundle setBundleVersion:42];
PASS([gnustepBundle bundleVersion] == 42,
"we can set and get gnustep bundle version");
PASS([gnustepBundle load], "-load behaves properly on the gnustep bundle");
exepath = [gnustepBundle executablePath];
PASS([fm fileExistsAtPath: exepath],
"-executablePath returns an executable path (gnustep bundle)");
path = [[[fm currentDirectoryPath]
stringByAppendingPathComponent:@"Resources"]
stringByAppendingPathComponent: @"TestBundle.bundle"];
bundle = [NSBundle bundleWithPath: path];
PASS([bundle isKindOfClass:[NSBundle class]],
"+bundleWithPath returns an NSBundle");
exepath = [bundle executablePath];
PASS([fm fileExistsAtPath: exepath],
"-executablePath returns an executable path (real bundle)");
identifierBundle
= [NSBundle bundleWithIdentifier: @"Test Bundle Identifier 1"];
PASS(identifierBundle == bundle,
"+bundleWithIdentifier returns correct bundle");
identifierBundle
= [NSBundle bundleWithIdentifier: @"Test Bundle Identifier 2"];
PASS(identifierBundle == nil,
"+bundleWithIdentifier returns nil for non-existent identifier");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,9 @@
ADDITIONAL_OBJCFLAGS += -I../../GenericTests/ -I../../../.. -Wall
$(GNUSTEP_INSTANCE)_SUBPROJECTS = ../../GenericTests
SUBPROJECTS=../../GenericTests ../Resources
include $(GNUSTEP_MAKEFILES)/aggregate.make

View file

@ -0,0 +1,56 @@
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSString.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSString *path;
NSBundle *bundle;
Class aClass;
id anObj;
path = RETAIN([[[[[NSFileManager defaultManager] currentDirectoryPath]
stringByDeletingLastPathComponent]
stringByAppendingPathComponent:@"Resources"]
stringByAppendingPathComponent: @"TestBundle.bundle"]);
bundle = RETAIN([NSBundle bundleWithPath: path]);
pass([bundle isKindOfClass:[NSBundle class]],
"+bundleWithPath returns a bundle");
pass([[bundle bundlePath] testForString],"the bundle has a path");
pass([path testEquals: [bundle bundlePath]],
"bundlePath returns the correct path");
pass([[bundle resourcePath] testForString],"a bundle has a resource path");
pass([[bundle infoDictionary] isKindOfClass:[NSDictionary class]],
"a bundle has an infoDictionary");
pass([bundle load],"bundle -load returns YES");
aClass = NSClassFromString(@"TestBundle");
pass(aClass != Nil,"-load actually loaded the class");
anObj = [aClass new];
pass(anObj != nil, "we can instantiate a loaded class");
pass([bundle principalClass] != nil, "-principalClass is not nil");
pass([[[bundle principalClass] description] testEquals:@"TestBundle"],
"-principalClass works");
pass([[bundle principalClass] new] != nil, "we can instantiate -principalClass");
pass([[bundle classNamed:@"TestBundle"] testEquals:[bundle principalClass]],
"-classNamed works");
pass([bundle testEquals: [NSBundle bundleForClass: NSClassFromString(@"TestBundle")]],
"+bundleForClass works");
[bundle setBundleVersion:42];
pass([bundle bundleVersion] == 42, "we can set and get a bundle version");
pass([[NSBundle allBundles] containsObject:bundle],
"+allBundles contains a bundle after we loaded it");
RELEASE(bundle);
RELEASE(path);
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,85 @@
#import "Testing.h"
#import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSString.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSBundle *bundle;
NSBundle *gstepBundle;
NSArray *arr;
bundle = [NSBundle bundleWithPath: [[NSFileManager defaultManager]
currentDirectoryPath]];
gstepBundle = [NSBundle bundleForLibrary: @"gnustep-base"];
PASS([bundle isKindOfClass: [NSBundle class]],
"+bundleWithPath returns anNSBundle");
arr = [bundle pathsForResourcesOfType: @"m" inDirectory: nil];
PASS([arr isKindOfClass: [NSArray class]] && [arr count],
"-pathsForResourcesOfType: inDirectory: returns an array");
PASS([bundle pathForResource: @"hiwelf0-2"
ofType: nil
inDirectory: nil] == nil,
"-pathForResource:ofType:inDirectory: works with nil args");
PASS([bundle pathForResource: @"hiwelf0-2" ofType: nil] == nil,
"-pathForResource:ofType: works with nil type");
PASS([bundle pathForResource: nil ofType: @"tiff"] == nil,
"-pathForResource:ofType: works with nil name");
PASS([bundle pathForResource: @"hiwelf0-2" ofType: @""] == nil,
"-pathForResource:ofType: works with empty type");
PASS([bundle pathForResource: @"" ofType: @"tiff"] == nil,
"-pathForResource:ofType: works with empty name");
PASS([[bundle resourcePath] testEquals: [[bundle bundlePath]
stringByAppendingPathComponent: @"Resources"]],
"-resourcePath returns the correct path");
PASS([[NSBundle pathForResource: @"abbreviations"
ofType: @"plist"
inDirectory: [[gstepBundle bundlePath]
stringByAppendingPathComponent: @"NSTimeZones"]] testForString],
"+pathForResource:ofType:inDirectory: works");
PASS([[NSBundle pathForResource: @"abbreviations"
ofType: @"plist"
inDirectory: [[gstepBundle bundlePath]
stringByAppendingPathComponent: @"NSTimeZones"] withVersion: 0]
testForString],
"+pathForResource:ofType:inDirectory:withVersion: works");
arr = [gstepBundle pathsForResourcesOfType: @"m"
inDirectory: @"NSTimeZones"];
PASS(([arr isKindOfClass: [NSArray class]] && [arr count] > 0),
"-pathsForResourcesOfType:inDirectory: returns an array");
PASS([[gstepBundle pathForResource: @"abbreviations"
ofType: @"plist"
inDirectory: @"NSTimeZones"] testForString],
"-pathForResource:ofType:inDirectory: finds a file");
PASS([gstepBundle pathForResource: @"abbreviations"
ofType: @"8nicola8"
inDirectory: @"NSTimeZones"] == nil,
"-pathForResource:ofType:inDirectory: doesn't find a non-existing file");
PASS([gstepBundle pathForResource: @"abbreviations"
ofType: @"plist"
inDirectory: @"NSTimeZones_dummy"] == nil,
"-pathForResource:ofType:inDirectory: doesn't find files in"
"a non-existing dir");
PASS([[gstepBundle pathForResource: @"abbreviations"
ofType: nil
inDirectory: @"NSTimeZones"] testForString],
"-pathForResource:ofType:inDirectory: with nil type finds a file");
PASS([gstepBundle pathForResource: @"whasssdlkf"
ofType: nil
inDirectory: @"NSTimeZones"] == nil,
"-pathForResource:ofType:inDirectory: with nil type doesn't find"
"non-existing files");
PASS([[gstepBundle pathForResource: @"NSTimeZones" ofType: nil]
testForString],
"-pathForResource:ofType: finds a file");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,43 @@
#import "Testing.h"
#import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSString.h>
#import <Foundation/NSPathUtilities.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSString *path, *localPath;
NSBundle *bundle;
NSArray *arr, *carr;
path = [[[[NSFileManager defaultManager] currentDirectoryPath]
stringByAppendingPathComponent:@"Resources"]
stringByAppendingPathComponent: @"TestBundle.bundle"];
/* --- [NSBundle -pathsForResourcesOfType:inDirectory:] --- */
bundle = [NSBundle bundleWithPath: path];
arr = [bundle pathsForResourcesOfType:@"txt" inDirectory: nil];
PASS((arr && [arr count]), "-pathsForResourcesOfType:inDirectory: returns an array");
localPath = [path stringByAppendingPathComponent: @"Resources/NonLocalRes.txt"];
PASS([arr containsObject: localPath], "Returned array contains non-localized resource");
localPath = [path stringByAppendingPathComponent: @"Resources/English.lproj/TextRes.txt"];
PASS([arr containsObject: localPath], "Returned array contains localized resource");
/* --- [NSBundle +pathsForResourcesOfType:inDirectory:] --- */
carr = [NSBundle pathsForResourcesOfType:@"txt" inDirectory: path];
PASS([arr isEqual: carr], "+pathsForResourcesOfType:inDirectory: returns same array");
/* --- [NSBundle -pathsForResourcesOfType:inDirectory:forLocalization:] --- */
arr = [bundle pathsForResourcesOfType:@"txt" inDirectory: nil forLocalization: @"English"];
PASS((arr && [arr count]), "-pathsForResourcesOfType:inDirectory:forLocalization returns an array");
localPath = [path stringByAppendingPathComponent: @"Resources/NonLocalRes.txt"];
PASS([arr containsObject: localPath], "Returned array contains non-localized resource");
localPath = [path stringByAppendingPathComponent: @"Resources/English.lproj/TextRes.txt"];
PASS([arr containsObject: localPath], "Returned array contains localized resource");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,23 @@
#import "Testing.h"
#import "ObjectTesting.h"
#import <Foundation/NSCalendar.h>
#if defined(GS_USE_ICU)
#define NSCALENDAR_SUPPORTED GS_USE_ICU
#else
#define NSCALENDAR_SUPPORTED 1 /* Assume Apple support */
#endif
int main()
{
START_SET(NSCALENDAR_SUPPORTED)
id testObj = [NSCalendar currentCalendar];
test_NSObject(@"NSCalendar", [NSArray arrayWithObject: testObj]);
test_NSCoding([NSArray arrayWithObject: testObj]);
test_NSCopying(@"NSCalendar", @"NSCalendar",
[NSArray arrayWithObject: testObj], NO, NO);
END_SET("NSCalendar basic")
return 0;
}

View file

@ -0,0 +1,29 @@
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSLocale.h>
#import <Foundation/NSCalendar.h>
#import "ObjectTesting.h"
#if defined(GS_USE_ICU)
#define NSCALENDAR_SUPPORTED GS_USE_ICU
#else
#define NSCALENDAR_SUPPORTED 1 /* Assume Apple support */
#endif
int main(void)
{
START_SET(NSCALENDAR_SUPPORTED)
NSCalendar *cal;
cal = [NSCalendar currentCalendar];
PASS (cal != nil, "+currentCalendar returns non-nil");
TEST_FOR_CLASS(@"NSCalendar", cal, "+currentCalendar return a NSCalendar");
cal = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
PASS (cal != nil, "-initWithCalendarIdentifier: return non-nil");
TEST_FOR_CLASS(@"NSCalendar", cal,
"-initWithCalendarIdentifier: return a NSCalendar");
RELEASE(cal);
END_SET("NSCalendar create")
return 0;
}

View file

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

View file

@ -0,0 +1,396 @@
#import "Testing.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSCalendarDate.h>
#import <Foundation/NSString.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSTimeZone.h>
@interface NSCalendarDate(TestAdditions)
-(BOOL) testDateValues: (int)y : (int)m : (int)d : (int)h : (int)i : (int)s;
@end
@implementation NSCalendarDate(TestAdditions)
-(BOOL) testDateValues: (int)y : (int)m : (int)d : (int)h : (int)i : (int)s
{
return (y == [self yearOfCommonEra] && m == [self monthOfYear]
&& d == [self dayOfMonth] && h == [self hourOfDay]
&& i == [self minuteOfHour] && s == [self secondOfMinute]);
}
@end
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSString *val1, *val2;
NSCalendarDate *date1, *date2;
NSDictionary *locale;
NSTimeZone *tz;
val1 = @"1999-12-31 23:59:59";
val2 = @"%Y-%m-%d %H:%M:%S";
/* Y2K checks */
date1 = [NSCalendarDate calendarDate];
PASS(date1 != nil && [date1 isKindOfClass: [NSCalendarDate class]],
"+calendarDate works");
date1 = [NSCalendarDate dateWithString: val1 calendarFormat: val2];
PASS(date1 != nil, "+dateWithString:calendarFormat: works");
locale = [NSDictionary dictionaryWithObjectsAndKeys:
[NSArray arrayWithObjects:
@"Sun", @"Mon", @"Tue", @"Wed", @"Thu", @"Fri", @"Sat",
nil], NSShortWeekDayNameArray,
nil];
date1 = [NSCalendarDate dateWithString: @"Fri Oct 27 08:41:14GMT 2000"
calendarFormat: nil
locale: locale];
PASS(date1 != nil,
"+dateWithString:calendarFormat:locale: with nil format works");
date1 = [NSCalendarDate dateWithString: @"1999-12-31 23:59:"
calendarFormat: val2];
PASS(date1 == nil,
"+dateWithString:calendarFormat:locale: objects to missing seconds");
date1 = [NSCalendarDate dateWithString: @"1999-12-31 23::00"
calendarFormat: val2];
PASS(date1 == nil,
"+dateWithString:calendarFormat:locale: objects to missing minutes");
date1 = [NSCalendarDate dateWithString: @"1999-12-31 :00:00"
calendarFormat: val2];
PASS(date1 == nil,
"+dateWithString:calendarFormat:locale: objects to missing hours");
date1 = [NSCalendarDate dateWithString: @"1999-12-00 00:00:00"
calendarFormat: val2];
PASS(date1 == nil,
"+dateWithString:calendarFormat:locale: objects to zero day");
date1 = [NSCalendarDate dateWithString: @"1999-00-01 00:00:00"
calendarFormat: val2];
PASS(date1 == nil,
"+dateWithString:calendarFormat:locale: objects to zero month");
date1 = [NSCalendarDate dateWithString: @"1999-12-31 00:00:00"
calendarFormat: @"%Y-%m-%d %H:%M:%S %Z"];
PASS(date1 == nil,
"+dateWithString:calendarFormat:locale: objects to missing timezone");
date1 = [NSCalendarDate dateWithString: @"1999-12-31 00:00:00 this_is_a_ridiculously_long_timezone_name_and_is_in_fact_designed_to_exceed_the_one_hundred_and_twenty_bytes_temporary_data_buffer_size_used_within_the_gnustep_base_method_which_parses_it"
calendarFormat: @"%Y-%m-%d %H:%M:%S %Z"];
PASS(date1 == nil,
"+dateWithString:calendarFormat:locale: objects to long timezone");
date1 = [NSCalendarDate dateWithString: @"1999-12-31 00:00:00 GMT+0100"
calendarFormat: @"%Y-%m-%d %H:%M:%S %Z"];
PASS(date1 != nil,
"+dateWithString:calendarFormat:locale: handles GMT+0100 timezone");
date1 = [NSCalendarDate dateWithString: @"1999-12-31 00:00:00 GMT-0100"
calendarFormat: @"%Y-%m-%d %H:%M:%S %Z"];
PASS(date1 != nil,
"+dateWithString:calendarFormat:locale: handles GMT-0100 timezone");
date1 = [NSCalendarDate dateWithString:
@"1999-12-31 00:00:00 Africa/Addis_Ababa"
calendarFormat: @"%Y-%m-%d %H:%M:%S %Z"];
PASS(date1 != nil,
"+dateWithString:calendarFormat:locale: handles Africa/Addis_Ababa");
date1 = [NSCalendarDate dateWithString: @"1999-12-31 23:59:59"
calendarFormat: val2];
PASS([date1 testDateValues: 1999 : 12 : 31 : 23 : 59 : 59],
"date check with %s", [[date1 description] cString]);
date2 = [date1 dateByAddingYears: 0
months: 0 days: 0 hours: 0 minutes: 0 seconds: 1];
PASS([date2 testDateValues: 2000 : 01 : 01 : 00 : 00 : 00],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 0 minutes: 0 seconds: 1];
PASS([date2 testDateValues: 2000 : 01 : 01 : 00 : 00 : 01],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 1 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2000 : 01 : 01 : 01 : 00 : 01],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: -2 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 1999 : 12 : 31 : 23 : 00 : 01],
"date check with %s", [[date2 description] cString]);
/* Y2K is a leap year checks */
date2 = [NSCalendarDate dateWithString: @"2000-2-28 23:59:59"
calendarFormat: val2];
PASS([date2 testDateValues: 2000 : 02 : 28 : 23 : 59 : 59],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 0 minutes: 0 seconds: 1];
PASS([date2 testDateValues: 2000 : 02 : 29 : 00 : 00 : 00],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 0 minutes: 0 seconds: 1];
PASS([date2 testDateValues: 2000 : 02 : 29 : 00 : 00 : 01],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 1 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2000 : 02 : 29 : 01 : 00 : 01],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: -2 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2000 : 02 : 28 : 23 : 00 : 01],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 5 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2000 : 02 : 29 : 04 : 00 : 01],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 1
months: 0 days: 0 hours: 0 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2001 : 03 : 01 : 04 : 00 : 01],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: -1 hours: 0 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2001 : 02 : 28 : 04 : 00 : 01],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 1
months: 0 days: 1 hours: 0 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 03 : 01 : 04 : 00 : 01],
"date check with %s", [[date2 description] cString]);
/* 2004 is a year leap check */
date2 = [NSCalendarDate dateWithString: @"2004-2-28 23:59:59"
calendarFormat: val2];
PASS([date2 testDateValues: 2004 : 02 : 28 : 23 : 59 : 59],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 0 minutes: 0 seconds: 1];
PASS([date2 testDateValues: 2004 : 02 : 29 : 00 : 00 : 00],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 0 minutes: 0 seconds: 1];
PASS([date2 testDateValues: 2004 : 02 : 29 : 00 : 00 : 01],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 1 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2004 : 02 : 29 : 01 : 00 : 01],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: -2 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2004 : 02 : 28 : 23 : 00 : 01],
"date check with %s", [[date2 description] cString]);
/* 2100 is not a leap year */
date2 = [NSCalendarDate dateWithString: @"2100-2-28 23:59:59"
calendarFormat: val2];
PASS([date2 testDateValues: 2100 : 02 : 28 : 23 : 59 : 59],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 0 minutes: 0 seconds: 1];
PASS([date2 testDateValues: 2100 : 03 : 01 : 00 : 00 : 00],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 0 minutes: 0 seconds: 1];
PASS([date2 testDateValues: 2100 : 03 : 01 : 00 : 00 : 01],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 1 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2100 : 03 : 01 : 01 : 00 : 01],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: -2 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2100 : 02 : 28 : 23 : 00 : 01],
"date check with %s", [[date2 description] cString]);
/* daylight savings time checks */
[NSTimeZone setDefaultTimeZone: [NSTimeZone timeZoneWithName: @"GB"]];
date2 = [NSCalendarDate dateWithString: @"2002-3-31 00:30:00"
calendarFormat: val2];
PASS([date2 testDateValues: 2002 : 03 : 31 : 00 : 30 : 00],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 1 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 03 : 31 : 02 : 30 : 00],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: -1 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 03 : 31 : 00 : 30 : 00],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 2 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 03 : 31 : 02 : 30 : 00],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: -1 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 03 : 31 : 00 : 30 : 00],
"date check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: -1 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 03 : 30 : 23 : 30 : 00],
"date check with %s", [[date2 description] cString]);
/* End daylight savings checks */
/* Seconds calculation checks */
date2 = [NSCalendarDate dateWithString: @"2002-10-27 00:30:00"
calendarFormat: val2];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 30 : 00],
"date second calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 0 minutes: 0 seconds: -1];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 29 : 59],
"date second calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 0 minutes: 0 seconds: 1];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 30 : 00],
"date second calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 0 minutes: 0 seconds: 2];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 30 : 02],
"date second calculation check with %s", [[date2 description] cString]);
/* Minutes calculation checks */
date2 = [NSCalendarDate dateWithString: @"2002-10-27 00:30:00"
calendarFormat: val2];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 30 : 00],
"date minute calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 0 minutes: -1 seconds: 0];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 29 : 00],
"date minute calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 0 minutes: 1 seconds: 0];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 30 : 00],
"date minute calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 0 minutes: 1 seconds: 0];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 31 : 00],
"date minute calculation check with %s", [[date2 description] cString]);
/* Hour calculation checks */
date2 = [NSCalendarDate dateWithString: @"2002-10-27 00:30:00"
calendarFormat: val2];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 30 : 00],
"date hour calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: -1 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 10 : 26 : 23 : 30 : 00],
"date hour calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 1 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 30 : 00],
"date hour calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 0 hours: 2 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 10 : 27 : 02 : 30 : 00],
"date hour calculation check with %s", [[date2 description] cString]);
/* Days calculation checks */
date2 = [NSCalendarDate dateWithString: @"2002-10-27 00:30:00"
calendarFormat: val2];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 30 : 00],
"date day calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: -1 hours: 0 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 10 : 26 : 00 : 30 : 00],
"date day calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 1 hours: 0 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 30 : 00],
"date day calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 0 days: 2 hours: 0 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 10 : 29 : 00 : 30 : 00],
"date day calculation check with %s", [[date2 description] cString]);
/* Months calculation checks */
date2 = [NSCalendarDate dateWithString: @"2002-10-27 00:30:00"
calendarFormat: val2];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 30 : 00],
"date month calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: -1 days: 0 hours: 0 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 9 : 27 : 00 : 30 : 00],
"date month calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 1 days: 0 hours: 0 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 30 : 00],
"date month calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 0
months: 2 days: 0 hours: 0 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 12 : 27 : 00 : 30 : 00],
"date month calculation check with %s", [[date2 description] cString]);
/* Years calculation checks */
date2 = [NSCalendarDate dateWithString: @"2002-10-27 00:30:00"
calendarFormat: val2];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 30 : 00],
"date year calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: -1
months: 0 days: 0 hours: 0 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2001 : 10 : 27 : 00 : 30 : 00],
"date year calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 1
months: 0 days: 0 hours: 0 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2002 : 10 : 27 : 00 : 30 : 00],
"date year calculation check with %s", [[date2 description] cString]);
date2 = [date2 dateByAddingYears: 2
months: 0 days: 0 hours: 0 minutes: 0 seconds: 0];
PASS([date2 testDateValues: 2004 : 10 : 27 : 00 : 30 : 00],
"date year calculation check with %s", [[date2 description] cString]);
[NSTimeZone setDefaultTimeZone: [NSTimeZone timeZoneWithName: @"GMT"]];
tz = [NSTimeZone timeZoneWithName: @"GB"];
date2 = [NSCalendarDate dateWithYear: 2006
month: 10 day: 1 hour: 0 minute: 0 second: 0 timeZone: tz];
date2 = [date2 dateByAddingYears: 0
months: 1 days: 0 hours: 2 minutes: 10 seconds: 0];
PASS([date2 testDateValues: 2006 : 11 : 1 : 2 : 10 : 00],
"date year calculation check with %s", [[date2 description] cString]);
PASS([[date2 timeZone] isEqual: tz],
"date year calculation preserves timezone");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,75 @@
#import "Testing.h"
#import <Foundation/NSCalendarDate.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSString.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSTimeInterval time1, time2, time3, time4, time5, time6, time7, time8, time9;
NSCalendarDate *date1;
time1 = [[NSCalendarDate dateWithString: @"Nov 20 02 01:54:22"
calendarFormat: @"%b %d %y %H:%M:%S"]
timeIntervalSinceReferenceDate];
time2 = [[NSCalendarDate dateWithString: @"Nov 20 02 02:54:22"
calendarFormat: @"%b %d %y %H:%M:%S"]
timeIntervalSinceReferenceDate];
time3 = [[NSCalendarDate dateWithString: @"Nov 20 02 03:54:22"
calendarFormat: @"%b %d %y %H:%M:%S"]
timeIntervalSinceReferenceDate];
time4 = [[NSCalendarDate dateWithString: @"Nov 20 02 04:54:22"
calendarFormat: @"%b %d %y %H:%M:%S"]
timeIntervalSinceReferenceDate];
time5 = [[NSCalendarDate dateWithString: @"Nov 20 02 05:54:22"
calendarFormat: @"%b %d %y %H:%M:%S"]
timeIntervalSinceReferenceDate];
time6 = [[NSCalendarDate dateWithString: @"Nov 20 02 06:54:22"
calendarFormat: @"%b %d %y %H:%M:%S"]
timeIntervalSinceReferenceDate];
time7 = [[NSCalendarDate dateWithString: @"Nov 20 02 07:54:22"
calendarFormat: @"%b %d %y %H:%M:%S"]
timeIntervalSinceReferenceDate];
time8 = [[NSCalendarDate dateWithString: @"Nov 20 02 08:54:22"
calendarFormat: @"%b %d %y %H:%M:%S"]
timeIntervalSinceReferenceDate];
time9 = [[NSCalendarDate dateWithString: @"Nov 20 02 09:54:22"
calendarFormat: @"%b %d %y %H:%M:%S"]
timeIntervalSinceReferenceDate];
PASS ((time1 < time2 && time2 < time3 && time3 < time4 && time4 < time5
&& time5 < time6 && time6 < time7 && time7 < time8 && time8 < time9),
"+dateWithString:calendarFormat: works if no time zone is specified");
date1 = [NSCalendarDate dateWithString: @"Nov 29 06 12:00am"
calendarFormat: @"%b %d %y %H:%M%p"];
PASS(date1 != nil && [date1 hourOfDay] == 0, "12:00am is midnight");
date1 = [NSCalendarDate dateWithString: @"Nov 29 06 12:00pm"
calendarFormat: @"%b %d %y %H:%M%p"];
PASS(date1 != nil && [date1 hourOfDay] == 12, "12:00pm is noon");
date1 = [NSCalendarDate dateWithString: @"Nov 29 06 01:25:38"
calendarFormat: @"%b %d %y %H:%M:%S"];
PASS([date1 timeIntervalSinceReferenceDate] + 1 == [[date1 addTimeInterval:1]
timeIntervalSinceReferenceDate],
"-addTimeInterval: works on a NSCalendarDate parsed with no timezone");
{
NSString *fmt = @"%Y-%m-%d %H:%M:%S:%F";
NSString *fmt2 = @"%Y-%m-%e %H:%M:%S:%F";
NSString *dateString = @"2006-04-22 22:22:22:901";
NSString *dateString2 = @"2006-04-2 22:22:22:901";
NSCalendarDate *date = [NSCalendarDate
dateWithString:dateString calendarFormat:fmt];
NSCalendarDate *date2 = [NSCalendarDate
dateWithString:dateString2 calendarFormat:fmt2];
NSLog(@"%@\n%@", dateString, [date descriptionWithCalendarFormat:fmt]);
PASS([dateString isEqual: [date descriptionWithCalendarFormat:fmt]],
"formatting milliseconds works");
PASS([dateString2 isEqual: [date2 descriptionWithCalendarFormat:fmt2]],
"formatting with %%e works");
}
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,207 @@
#import "Testing.h"
#import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSCalendarDate.h>
#import <Foundation/NSString.h>
#import <Foundation/NSTimeZone.h>
#import <Foundation/NSUserDefaults.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSMutableArray *tmpArray;
NSMutableDictionary *myLocale;
NSCalendarDate *myBirthday;
NSCalendarDate *anotherDay;
myLocale = [NSMutableDictionary new];
tmpArray = [NSMutableArray new];
[tmpArray addObject: @"Gen"];
[tmpArray addObject: @"Feb"];
[tmpArray addObject: @"Mar"];
[tmpArray addObject: @"Apr"];
[tmpArray addObject: @"Mag"];
[tmpArray addObject: @"Giu"];
[tmpArray addObject: @"Lug"];
[tmpArray addObject: @"Ago"];
[tmpArray addObject: @"Set"];
[tmpArray addObject: @"Ott"];
[tmpArray addObject: @"Nov"];
[tmpArray addObject: @"Dic"];
[myLocale setObject: tmpArray forKey: NSShortMonthNameArray];
ASSIGN(tmpArray,[NSMutableArray new]);
[tmpArray addObject: @"Gennaio"];
[tmpArray addObject: @"Febbraio"];
[tmpArray addObject: @"Marzo"];
[tmpArray addObject: @"Aprile"];
[tmpArray addObject: @"Maggio"];
[tmpArray addObject: @"Giugno"];
[tmpArray addObject: @"Luglio"];
[tmpArray addObject: @"Agosto"];
[tmpArray addObject: @"Settembre"];
[tmpArray addObject: @"Ottobre"];
[tmpArray addObject: @"Novembre"];
[tmpArray addObject: @"Dicembre"];
[myLocale setObject: tmpArray forKey: NSMonthNameArray];
ASSIGN(tmpArray,[NSMutableArray new]);
[tmpArray addObject: @"Dom"];
[tmpArray addObject: @"Lun"];
[tmpArray addObject: @"Mar"];
[tmpArray addObject: @"Mer"];
[tmpArray addObject: @"Gio"];
[tmpArray addObject: @"Ven"];
[tmpArray addObject: @"Sab"];
[myLocale setObject: tmpArray forKey: NSShortWeekDayNameArray];
ASSIGN(tmpArray,[NSMutableArray new]);
[tmpArray addObject: @"Domencia"];
[tmpArray addObject: @"Lunedi"];
[tmpArray addObject: @"Martedi"];
[tmpArray addObject: @"Mercoledi"];
[tmpArray addObject: @"Giovedi"];
[tmpArray addObject: @"Venerdi"];
[tmpArray addObject: @"Sabato"];
[myLocale setObject: tmpArray forKey: NSWeekDayNameArray];
ASSIGN(tmpArray,[NSMutableArray new]);
[tmpArray addObject: @"AM"];
[tmpArray addObject: @"PM"];
[myLocale setObject: tmpArray forKey: NSAMPMDesignation];
myBirthday = [NSCalendarDate dateWithYear: 1974
month: 11
day: 20
hour: 13
minute: 0
second: 0
timeZone: [NSTimeZone timeZoneWithName: @"MET"]];
anotherDay = [NSCalendarDate dateWithYear: 1974
month: 1
day: 2
hour: 3
minute: 0
second: 0
timeZone: [NSTimeZone timeZoneWithName: @"MET"]];
PASS([[myBirthday descriptionWithCalendarFormat: @"%%"
locale: myLocale] isEqualToString: @"%"],
"%% format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%a"
locale: myLocale] isEqualToString: @"Mer"],
"%%a format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%A"
locale: myLocale] isEqualToString: @"Mercoledi"],
"%%A format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%b"
locale: myLocale] isEqualToString: @"Nov"],
"%%b format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%B"
locale: myLocale] isEqualToString: @"Novembre"],
"%%B format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%d"
locale: myLocale] isEqualToString: @"20"],
"%%d format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%e"
locale: myLocale] isEqualToString: @"20"],
"%%e format works in description");
PASS([[anotherDay descriptionWithCalendarFormat: @"%e"
locale: myLocale] isEqualToString: @"2"],
"%%e format has no leading space with single digit");
PASS([[anotherDay descriptionWithCalendarFormat: @"%2e"
locale: myLocale] isEqualToString: @" 2"],
"%%2e format has leading space with single digit");
PASS([[myBirthday descriptionWithCalendarFormat: @"%F"
locale: myLocale] isEqualToString: @"000"],
"%%F format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%H"
locale: myLocale] isEqualToString: @"13"],
"%%H format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%I"
locale: myLocale] isEqualToString: @"01"],
"%%I format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%j"
locale: myLocale] isEqualToString: @"324"],
"%%j format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%m"
locale: myLocale] isEqualToString: @"11"],
"%%m format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%M"
locale: myLocale] isEqualToString: @"00"],
"%%M format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%p"
locale: myLocale] isEqualToString: @"PM"],
"%%p format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%S"
locale: myLocale] isEqualToString: @"00"],
"%%S format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%w"
locale: myLocale] isEqualToString: @"3"],
"%%w format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%y"
locale: myLocale] isEqualToString: @"74"],
"%%y format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%Y"
locale: myLocale] isEqualToString: @"1974"],
"%%Y format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%Z"
locale: myLocale] isEqualToString: @"MET"],
"%%Z format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%z"
locale: myLocale] isEqualToString: @"+0100"],
"%%z format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%d %m %Y"
locale: myLocale] isEqualToString: @"20 11 1974"],
"%%d %%m %%Y format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%d %B %y"
locale: myLocale] isEqualToString: @"20 Novembre 74"],
"%%d %%B %%Y format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%H:%M:%S"
locale: myLocale] isEqualToString: @"13:00:00"],
"%%H:%%M:%%S format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%H%%%M%%%S"
locale: myLocale] isEqualToString: @"13%00%00"],
"%%H%%%%%%M%%%%%%S format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%H:%M (%Z)"
locale: myLocale] isEqualToString: @"13:00 (MET)"],
"%%H%%M format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%R"
locale: myLocale] isEqualToString: @"13:00"],
"%%R format works in description");
PASS([[myBirthday descriptionWithCalendarFormat: @"%r"
locale: myLocale] isEqualToString: @"01:00:00 PM"],
"%%r format works in description");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,19 @@
#import "Testing.h"
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSCharacterSet.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
id testObj = [NSCharacterSet alphanumericCharacterSet];
test_alloc(@"NSCharacterSet");
test_NSObject(@"NSCharacterSet", [NSArray arrayWithObject:testObj]);
test_NSCoding([NSArray arrayWithObject:testObj]);
test_NSCopying(@"NSCharacterSet", @"NSMutableCharacterSet", [NSArray arrayWithObject:testObj], NO, NO);
test_NSMutableCopying(@"NSCharacterSet",@"NSMutableCharacterSet", [NSArray arrayWithObject:testObj]);
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,67 @@
#import "Testing.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSCharacterSet.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSCharacterSet *theSet = nil;
theSet = [NSCharacterSet alphanumericCharacterSet];
PASS(theSet != nil, "NSCharacterSet understands [+alphanumericCharacterSet]");
PASS([NSCharacterSet alphanumericCharacterSet] == theSet,
"NSCharacterSet uniques alphanumericCharacterSet");
theSet = [NSCharacterSet controlCharacterSet];
PASS(theSet != nil,"NSCharacterSet understands [+controlCharacterSet]");
PASS([NSCharacterSet controlCharacterSet] == theSet,
"NSCharacterSet uniques controlCharacterSet");
theSet = [NSCharacterSet decimalDigitCharacterSet];
PASS(theSet != nil,"NSCharacterSet understands [+decimalDigitCharacterSet]");
PASS([NSCharacterSet decimalDigitCharacterSet] == theSet,
"NSCharacterSet uniques [+decimalDigitCharacterSet]");
theSet = [NSCharacterSet illegalCharacterSet];
PASS(theSet != nil,"NSCharacterSet understands [+illegalCharacterSet]");
PASS([NSCharacterSet illegalCharacterSet] == theSet,
"NSCharacterSet uniques [+illegalCharacterSet]");
theSet = [NSCharacterSet letterCharacterSet];
PASS(theSet != nil,"NSCharacterSet understands [+letterCharacterSet]");
PASS([NSCharacterSet letterCharacterSet] == theSet,
"NSCharacterSet uniques [+letterCharacterSet]");
theSet = [NSCharacterSet lowercaseLetterCharacterSet];
PASS(theSet != nil,"NSCharacterSet understands [+lowercaseLetterCharacterSet]");
PASS([NSCharacterSet lowercaseLetterCharacterSet] == theSet,
"NSCharacterSet uniques [+lowercaseLetterCharacterSet]");
theSet = [NSCharacterSet nonBaseCharacterSet];
PASS(theSet != nil,"NSCharacterSet understands [+nonBaseCharacterSet]");
PASS([NSCharacterSet nonBaseCharacterSet] == theSet,
"NSCharacterSet uniques [+nonBaseCharacterSet]");
theSet = [NSCharacterSet punctuationCharacterSet];
PASS(theSet != nil,"NSCharacterSet understands [+punctuationCharacterSet]");
PASS([NSCharacterSet punctuationCharacterSet] == theSet,
"NSCharacterSet uniques [+punctuationCharacterSet]");
theSet = [NSCharacterSet uppercaseLetterCharacterSet];
PASS(theSet != nil,"NSCharacterSet understands [+uppercaseLetterCharacterSet]");
PASS([NSCharacterSet uppercaseLetterCharacterSet] == theSet,
"NSCharacterSet uniques [+uppercaseLetterCharacterSet]");
theSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
PASS(theSet != nil,"NSCharacterSet understands [+whitespaceAndNewlineCharacterSet]");
PASS([NSCharacterSet whitespaceAndNewlineCharacterSet] == theSet,
"NSCharacterSet uniques [+whitespaceAndNewlineCharacterSet]");
theSet = [NSCharacterSet whitespaceCharacterSet];
PASS(theSet != nil,"NSCharacterSet understands [+whitespaceCharacterSet]");
PASS([NSCharacterSet whitespaceCharacterSet] == theSet,
"NSCharacterSet uniques [+whitespaceCharacterSet]");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,93 @@
#import "Testing.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSCharacterSet.h>
#import <Foundation/NSData.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSCharacterSet *theSet,*iSet;
NSData *data1 = nil;
theSet = [NSCharacterSet alphanumericCharacterSet];
PASS([theSet characterIsMember:'A'] &&
[theSet characterIsMember:'Z'] &&
[theSet characterIsMember:'a'] &&
[theSet characterIsMember:'z'] &&
[theSet characterIsMember:'9'] &&
[theSet characterIsMember:'0'] &&
![theSet characterIsMember:'#'] &&
![theSet characterIsMember:' '] &&
![theSet characterIsMember:'\n'],
"Check some characters from alphanumericCharacterSet");
theSet = [NSCharacterSet lowercaseLetterCharacterSet];
PASS(![theSet characterIsMember:'A'] &&
![theSet characterIsMember:'Z'] &&
[theSet characterIsMember:'a'] &&
[theSet characterIsMember:'z'] &&
![theSet characterIsMember:'9'] &&
![theSet characterIsMember:'0'] &&
![theSet characterIsMember:'#'] &&
![theSet characterIsMember:' '] &&
![theSet characterIsMember:'\n'],
"Check some characters from lowercaseLetterCharacterSet");
theSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
PASS(![theSet characterIsMember:'A'] &&
![theSet characterIsMember:'Z'] &&
![theSet characterIsMember:'a'] &&
![theSet characterIsMember:'z'] &&
![theSet characterIsMember:'9'] &&
![theSet characterIsMember:'0'] &&
![theSet characterIsMember:'#'] &&
[theSet characterIsMember:' '] &&
[theSet characterIsMember:'\n'] &&
[theSet characterIsMember:'\t'],
"Check some characters from whitespaceAndNewlineCharacterSet");
data1 = [theSet bitmapRepresentation];
PASS(data1 != nil && [data1 isKindOfClass:[NSData class]],
"-bitmapRepresentation works");
iSet = [theSet invertedSet];
PASS([iSet characterIsMember:'A'] &&
[iSet characterIsMember:'Z'] &&
[iSet characterIsMember:'a'] &&
[iSet characterIsMember:'z'] &&
[iSet characterIsMember:'9'] &&
[iSet characterIsMember:'0'] &&
[iSet characterIsMember:'#'] &&
![iSet characterIsMember:' '] &&
![iSet characterIsMember:'\n'] &&
![iSet characterIsMember:'\t'],
"-invertedSet works");
{
NSCharacterSet *firstSet,*secondSet,*thirdSet,*fourthSet;
firstSet = [NSCharacterSet decimalDigitCharacterSet];
secondSet = [NSCharacterSet decimalDigitCharacterSet];
thirdSet = nil;
fourthSet = [NSMutableCharacterSet decimalDigitCharacterSet];
thirdSet = [[firstSet class] decimalDigitCharacterSet];
PASS (firstSet == secondSet &&
firstSet == thirdSet &&
firstSet != fourthSet,
"Caching of standard sets");
}
theSet = [NSCharacterSet characterSetWithCharactersInString:@"Not a set"];
PASS(theSet != nil && [theSet isKindOfClass:[NSCharacterSet class]],
"Create custom set with characterSetWithCharactersInString:");
PASS([theSet characterIsMember:' '] &&
[theSet characterIsMember:'N'] &&
[theSet characterIsMember:'o'] &&
![theSet characterIsMember:'A'] &&
![theSet characterIsMember:'#'],
"Check custom set");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,59 @@
#import "Testing.h"
#import "ObjectTesting.h"
#import <Foundation/Foundation.h>
int
main (int argc, char**argv)
{
id pool = [NSAutoreleasePool new];
NSCharacterSet *illegal = [NSCharacterSet illegalCharacterSet];
NSCharacterSet *legal = [illegal invertedSet];
NSMutableData *data;
NSString *s;
unichar cp;
PASS([illegal characterIsMember: 0xfffe], "0xfffe is illegal");
PASS(![legal characterIsMember: 0xfffe], "0xfffe is bnot legal");
PASS([illegal characterIsMember: 0xffff], "0xffff is illegal");
PASS(![legal characterIsMember: 0xffff], "0xffff is not legal");
PASS([illegal characterIsMember: 0xfdd0], "0xfdd0 is illegal");
PASS(![legal characterIsMember: 0xfdd0], "0xfdd0 is not legal");
PASS([illegal longCharacterIsMember: 0x0010fffe], "0x0010fffe is illegal");
PASS(![legal longCharacterIsMember: 0x0010fffe], "0x0010fffe is not legal");
// Null character
PASS(![illegal characterIsMember: 0x0000], "0x0000 is not illegal");
PASS([legal characterIsMember: 0x0000], "0x0000 is legal");
// First half of surrogate pair
PASS(![illegal characterIsMember: 0xd800], "0xd800 is not illegal");
PASS([legal characterIsMember: 0xd800], "0xd800 is legal");
// Second half of surrogate pair
PASS(![illegal characterIsMember: 0xdc00], "0xdc00 is not illegal");
PASS([legal characterIsMember: 0xdc00], "0xdc00 is legal");
// Private use character in code plane 16
PASS([illegal longCharacterIsMember: 0x0010fffd], "0x0010fffd illegal");
PASS(![legal longCharacterIsMember: 0x0010fffd], "0x0010fffd is illegal");
// Entire UCS-2 set (UTF-16 surrogates start above 0xD800)
// (still looking for official information on the range of UCS-2 code points,
// i.e. whether UCS-4/UCS-2 are actually official code point sets
// or whether they are just commonly used terms to differentiate
// the full UCS code point set from it's UTF-16 encoding.)
data = [NSMutableData dataWithCapacity: sizeof(cp) * 0xD800];
// Do not start with 0x0000 otherwise a leading BOM could misinterpreted.
for (cp=0x0001;cp<0xFFFF;cp++)
{
/* Skip code points that are reserved for surrogate characters. */
if (cp == 0xD800) cp = 0xF900;
if ([legal characterIsMember:cp])
{
[data appendBytes: &cp length: sizeof(cp)];
}
}
s = [[NSString alloc] initWithData: data encoding: NSUnicodeStringEncoding];
PASS([s length],"legal UCS-2 set can be represented in an NSString.");
[s release];
[pool release];
return (0);
}

View file

@ -0,0 +1,9 @@
ADDITIONAL_OBJCFLAGS += -I../GenericTests/ -I../../.. -Wall
$(GNUSTEP_INSTANCE)_SUBPROJECTS = ../GenericTests
SUBPROJECTS= ../GenericTests Resources
include $(GNUSTEP_MAKEFILES)/aggregate.make

View file

@ -0,0 +1,73 @@
#include <Foundation/Foundation.h>
#include <Foundation/NSPort.h>
id myServer;
@interface Tester : NSObject
{
}
+ (void) connectWithPorts: (NSArray*)portArray;
+ (void) setServer: (id)anObject;
+ (void) startup;
- (int) doIt;
@end
@implementation Tester
+ (void) connectWithPorts: (NSArray*)portArray
{
NSAutoreleasePool *pool;
NSConnection *serverConnection;
Tester *serverObject;
pool = [[NSAutoreleasePool alloc] init];
serverConnection = [NSConnection
connectionWithReceivePort: [portArray objectAtIndex: 0]
sendPort: [portArray objectAtIndex: 1]];
serverObject = [[self alloc] init];
[(id)[serverConnection rootProxy] setServer: serverObject];
[serverObject release];
[[NSRunLoop currentRunLoop] run];
[pool release];
[NSThread exit];
return;
}
+ (void) setServer: (id)anObject
{
myServer = [anObject retain];
NSLog(@"Got %d", [myServer doIt]);
}
+ (void) startup
{
NSPort *port1;
NSPort *port2;
NSArray *portArray;
NSConnection *conn;
port1 = [NSPort port];
port2 = [NSPort port];
conn = [[NSConnection alloc] initWithReceivePort: port1 sendPort: port2];
[conn setRootObject: self];
/* Ports switched here. */
portArray = [NSArray arrayWithObjects: port2, port1, nil];
[NSThread detachNewThreadSelector: @selector(connectWithPorts:)
toTarget: self
withObject: portArray];
return;
}
- (int) doIt
{
return 42;
}
@end

View file

@ -0,0 +1,8 @@
include $(GNUSTEP_MAKEFILES)/common.make
BUNDLE_NAME=TestConnection
TestConnection_NEEDS_GUI = NO
TestConnection_OBJC_FILES=Connection.m
include $(GNUSTEP_MAKEFILES)/bundle.make
include $(GNUSTEP_MAKEFILES)/test-tool.make
check:: all

View file

View file

@ -0,0 +1,20 @@
#import "Testing.h"
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSConnection.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
id testObject = nil;
test_alloc(@"NSConnection");
testObject = [NSConnection new];
test_NSObject(@"NSConnection",[NSArray arrayWithObject:testObject]);
testObject = [NSConnection defaultConnection];
PASS(testObject != nil && [testObject isKindOfClass:[NSConnection class]],
"NSConnection +defaultConnection works");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,36 @@
#import "Testing.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSConnection.h>
#import <Foundation/NSException.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSString.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSBundle *bundle;
NSString *bundlePath = [[NSFileManager defaultManager] currentDirectoryPath];
bundlePath = [bundlePath stringByAppendingPathComponent: @"Resources"];
bundlePath = [NSBundle pathForResource:@"TestConnection"
ofType:@"bundle"
inDirectory:bundlePath];
bundle = [NSBundle bundleWithPath:bundlePath];
PASS([bundle load],"We can load the test bundle");
{
/* this should probably be rewritten to uh return a bool */
NS_DURING
NSDate *date;
NSRunLoop *run = [NSRunLoop currentRunLoop];
[NSClassFromString(@"Tester") performSelector:@selector(startup)];
date = [NSDate dateWithTimeIntervalSinceNow:1];
[run runUntilDate:date];
PASS(1, "NSConnection can do a simple connection");
NS_HANDLER
PASS(0, "NSConnection can do a simple connection");
NS_ENDHANDLER
}
[arp release]; arp = nil;
return 0;
}

View file

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

22
Tests/base/NSData/basic.m Normal file
View file

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

View file

@ -0,0 +1,78 @@
#import "Testing.h"
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSData.h>
#import <Foundation/NSString.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
char *str1,*str2;
NSData *data1, *data2;
NSMutableData *mutable;
unsigned char *hold;
str1 = "Test string for data classes";
str2 = (char *) malloc(sizeof("Test string for data classes not copied"));
strcpy(str2,"Test string for data classes not copied");
mutable = [NSMutableData dataWithLength:100];
hold = [mutable mutableBytes];
/* hmpf is this correct */
data1 = [NSData dataWithBytes:str1 length:(strlen(str1) * sizeof(void*))];
PASS(data1 != nil &&
[data1 isKindOfClass:[NSData class]] &&
[data1 length] == (strlen(str1) * sizeof(void*)) &&
[data1 bytes] != str1 &&
strcmp(str1,[data1 bytes]) == 0,
"+dataWithBytes:length: works");
data2 = [NSData dataWithBytesNoCopy:str2 length:(strlen(str2) * sizeof(void*))];
PASS(data2 != nil && [data2 isKindOfClass:[NSData class]] &&
[data2 length] == (strlen(str2) * sizeof(void*)) &&
[data2 bytes] == str2,
"+dataWithBytesNoCopy:length: works");
data1 = [NSData dataWithBytes:nil length:0];
PASS(data1 != nil && [data1 isKindOfClass:[NSData class]] &&
[data1 length] == 0,
"+dataWithBytes:length works with 0 length");
[data2 getBytes:hold range:NSMakeRange(2,6)];
PASS(strcmp(hold,"st str") == 0, "-getBytes:range works");
TEST_EXCEPTION([data2 getBytes:hold
range:NSMakeRange(strlen(str2)*sizeof(void*),1)];,
NSRangeException, YES,
"getBytes:range: with bad location");
TEST_EXCEPTION([data2 getBytes:hold
range:NSMakeRange(1,(strlen(str2)*sizeof(void*)))];,
NSRangeException, YES,
"getBytes:range: with bad length");
TEST_EXCEPTION([data2 subdataWithRange:NSMakeRange((strlen(str2)*sizeof(void*)),1)];,
NSRangeException, YES,
"-subdataWithRange: with bad location");
TEST_EXCEPTION([data2 subdataWithRange:NSMakeRange(1,(strlen(str2)*sizeof(void*)))];,
NSRangeException, YES,
"-subdataWithRange: with bad length");
data2 = [NSData dataWithBytesNoCopy:str1
length:(strlen(str1) * sizeof(void*))
freeWhenDone:NO];
PASS(data2 != nil && [data2 isKindOfClass:[NSData class]] &&
[data2 length] == (strlen(str1) * sizeof(void*)) &&
[data2 bytes] == str1,
"+dataWithBytesNoCopy:length:freeWhenDone: works");
[arp release]; arp = nil;
{
BOOL didNotSegfault = YES;
PASS(didNotSegfault, "+dataWithBytesNoCopy:length:freeWhenDone:NO doesn't free memory");
}
return 0;
}

16
Tests/base/NSDate/basic.m Normal file
View file

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

View file

@ -0,0 +1,53 @@
#import "Testing.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSDate.h>
#import <Foundation/NSCalendarDate.h>
#import <Foundation/NSString.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSString *val;
NSDate *date1,*date2;
val = @"2000-10-19 00:00:00 +0000";
date1 = [NSDate date];
PASS(date1 != nil && [date1 isKindOfClass:[NSDate class]],
"+date works");
date1 = [NSDate dateWithString:val];
PASS(date1 != nil && [date1 isKindOfClass:[NSDate class]],
"+dateWithString works");
date2 = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate:
[date1 timeIntervalSinceReferenceDate]];
PASS(date2 != nil && [date2 isKindOfClass:[NSDate class]],
"+dateWithTimeIntervalSinceReferenceDate: works");
// Make sure we get day in correct zone.
[date2 setTimeZone: [NSTimeZone timeZoneForSecondsFromGMT: 0]];
PASS([date2 dayOfMonth] == 19, "+dateWithString makes correct day");
PASS([date2 monthOfYear] == 10, "+dateWithString makes correct month");
PASS([date2 yearOfCommonEra] == 2000, "+dateWithString makes correct year");
date1 = [NSDate dateWithTimeIntervalSinceNow:0];
PASS(date1 != nil && [date1 isKindOfClass:[NSDate class]],
"+dateWithTimeIntervalSinceNow: works");
date1 = [NSDate dateWithTimeIntervalSince1970:0];
PASS(date1 != nil && [date1 isKindOfClass:[NSDate class]],
"+dateWithTimeIntervalSince1970: works");
date1 = [NSDate dateWithTimeIntervalSinceReferenceDate:0];
PASS(date1 != nil && [date1 isKindOfClass:[NSDate class]],
"+dateWithTimeIntervalSinceReferenceDate: works");
date1 = [NSDate distantFuture];
PASS(date1 != nil && [date1 isKindOfClass:[NSDate class]],
"+distantFuture works");
date1 = [NSDate distantPast];
PASS(date1 != nil && [date1 isKindOfClass:[NSDate class]],
"+distantPast works");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,33 @@
#import "Testing.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSDate.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSDate *cdate, *date1, *date2;
NSComparisonResult comp;
cdate = [NSDate date];
comp = [cdate compare: [NSDate distantFuture]];
PASS(comp == NSOrderedAscending, "+distantFuture is in the future");
comp = [cdate compare: [NSDate distantPast]];
PASS(comp == NSOrderedDescending, "+distantPast is in the past");
date1 = [NSDate dateWithTimeIntervalSinceNow:-600];
date2 = [cdate earlierDate: date1];
PASS(date1 == date2, "-earlierDate works");
date2 = [cdate laterDate: date1];
PASS(cdate == date2, "-laterDate works");
date2 = [date1 addTimeInterval:0];
PASS ([date1 isEqualToDate:date2], "-isEqualToDate works");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,69 @@
#import <Foundation/Foundation.h>
#import "Testing.h"
#import "ObjectTesting.h"
int main(void)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSDateFormatter *inFmt;
NSDateFormatter *outFmt;
NSDate *date;
NSString *str;
NSLocale *locale;
NSCalendar *cal;
unsigned int components;
NSInteger year;
[NSTimeZone setDefaultTimeZone: [NSTimeZone timeZoneWithName: @"GMT"]];
inFmt = [[NSDateFormatter alloc] init];
[inFmt setDateFormat: @"yyyy-MM-dd 'at' HH:mm"];
date = [inFmt dateFromString: @"2011-01-27 at 17:36"];
outFmt = [[NSDateFormatter alloc] init];
[outFmt setLocale: [[NSLocale alloc] initWithLocaleIdentifier: @"pt_BR"]];
[outFmt setDateFormat: @"HH:mm 'on' EEEE MMMM d"];
str = [outFmt stringFromDate: date];
PASS_EQUAL(str, @"17:36 on quinta-feira janeiro 27",
"Output has the same format as Cocoa.");
RELEASE(outFmt);
RELEASE(inFmt);
locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"];
inFmt = [NSDateFormatter new];
[inFmt setDateStyle: NSDateFormatterShortStyle];
[inFmt setTimeStyle: NSDateFormatterNoStyle];
[inFmt setLocale: locale];
[inFmt setTimeZone: [NSTimeZone timeZoneWithName: @"GMT"]];
date = [inFmt dateFromString: @"15/06/1982"];
PASS_EQUAL([date description], @"1982-06-15 00:00:00 +0000",
"GMT time zone is correctly accounted for.");
[inFmt setTimeZone: [NSTimeZone timeZoneWithName: @"EST"]];
date = [inFmt dateFromString: @"15/06/1982"];
PASS_EQUAL([date description], @"1982-06-15 05:00:00 +0000",
"EST time zone is correctly accounted for.");
RELEASE(inFmt);
cal = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
[cal setTimeZone: [NSTimeZone timeZoneWithName: @"CST"]];
[cal setLocale: locale];
components = NSYearCalendarUnit;
year = [[cal components: components fromDate: date] year];
inFmt = [NSDateFormatter new];
[inFmt setLocale: locale];
[inFmt setDateStyle: NSDateFormatterLongStyle];
[inFmt setTimeStyle: NSDateFormatterNoStyle];
str = [inFmt stringFromDate: date];
PASS (year == 1982, "Year is 1982");
PASS_EQUAL(str, @"15 June 1982", "Date is formatted correctly.");
RELEASE(cal);
RELEASE(inFmt);
str = [NSDateFormatter dateFormatFromTemplate: @"MMMdd"
options: 0 locale: locale];
PASS_EQUAL(str, @"dd MMM", "Convert date format as Cocoa.");
RELEASE(locale);
RELEASE(pool);
return 0;
}

View file

@ -0,0 +1,33 @@
#import "Testing.h"
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSString.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSMutableArray *testObjs = [NSMutableArray new];
NSDictionary *obj;
test_alloc(@"NSDictionary");
obj = [NSDictionary new];
[testObjs addObject:obj];
PASS(obj != nil &&
[obj isKindOfClass:[NSDictionary class]] &&
[obj count] == 0,
"can create an empty dictionary");
obj = [NSDictionary dictionaryWithObject:@"Hello" forKey:@"Key"];
[testObjs addObject:obj];
PASS(obj != nil &&
[obj isKindOfClass:[NSDictionary class]] &&
[obj count] == 1,
"can create a dictionary with one element");
test_NSObject(@"NSDictionary", testObjs);
test_NSCoding(testObjs);
test_NSCopying(@"NSDictionary", @"NSMutableDictionary", testObjs, YES, NO);
test_NSMutableCopying(@"NSDictionary", @"NSMutableDictionary", testObjs);
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,79 @@
#import "Testing.h"
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSString *key1, *key2, *key3, *val1, *val2, *val3;
NSArray *keys1, *keys2, *keys3, *vals1, *vals2, *vals3;
NSDictionary *obj,*old;
old = nil;
key1 = @"Key1";
key2 = @"Key2";
key3 = @"Key3";
keys1 = [NSArray arrayWithObjects:key1, key2, nil];
keys2 = [NSArray arrayWithObjects:key1, key2, key3, nil];
/* duplicate keys */
keys3 = [NSArray arrayWithObjects:key1, key2, key2, nil];
val1 = @"Kidnapped";
val2 = @"tied up";
val3 = @"taken away and helf for ransom";
vals1 = [NSArray arrayWithObjects:val1, val2, nil];
/* duplicate values */
vals2 = [NSArray arrayWithObjects:val1, val2, val2, nil];
vals3 = [NSArray arrayWithObjects:val1, val2, val3, nil];
obj = [NSDictionary new];
PASS(obj != nil &&
[obj isKindOfClass:[NSDictionary class]] &&
[obj count] == 0,
"+new creates an empty dictionary");
obj = [NSDictionary dictionary];
PASS(obj != nil &&
[obj isKindOfClass:[NSDictionary class]] &&
[obj count] == 0,
"+dictionary creates an empty dictionary");
TEST_EXCEPTION([NSDictionary dictionaryWithObject:val1 forKey:nil];,
NSInvalidArgumentException,YES,
"+dictionaryWithObject:forKey: with nil key");
TEST_EXCEPTION([NSDictionary dictionaryWithObject:nil forKey:key1];,
NSInvalidArgumentException,YES,
"+dictionaryWithObject:forKey: with nil value");
obj = [NSDictionary dictionaryWithObject:val1 forKey:key1];
PASS(obj != nil &&
[obj isKindOfClass:[NSDictionary class]] &&
[obj count] == 1,
"+dictionaryWithObject:forKey: builds minimal dictionary");
obj = [NSDictionary dictionaryWithObjects:vals1 forKeys:keys1];
PASS(obj != nil &&
[obj isKindOfClass:[NSDictionary class]] &&
[obj count] == 2,
"+dictionaryWithObjects:forKeys: builds a dictionary");
TEST_EXCEPTION([NSDictionary dictionaryWithObjects:vals1 forKeys:keys2];,
NSInvalidArgumentException, YES,
"+dictionaryWithObjects:forKeys: with arrays of different sizes");
obj = [NSDictionary dictionaryWithObjects:vals2 forKeys:keys2];
PASS(obj != nil &&
[obj isKindOfClass:[NSDictionary class]] &&
[obj count] == 3,
"we can have multiple identical objects in a dictionary");
obj = [NSDictionary dictionaryWithObjects:vals3 forKeys:keys3];
PASS(obj != nil &&
[obj isKindOfClass:[NSDictionary class]] &&
[obj count] == 2,
"we can't have multiple identical keys in a dictionary");
old = obj;
obj = [NSDictionary dictionaryWithDictionary:old];
PASS(obj != nil &&
[obj isEqual: old], "+dictionaryWithDictionary: copies dictionary");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,238 @@
#import "Testing.h"
#import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSString.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSData.h>
#import <Foundation/NSDate.h>
#import <Foundation/NSEnumerator.h>
#if defined(GNUSTEP_BASE_LIBRARY)
#import <Foundation/NSSerialization.h>
#endif
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSString *key1, *key2, *key3, *val1, *val2, *val3;
NSArray *keys1, *keys2, *keys3, *keys4, *vals1, *vals2, *vals3, *vals4;
id obj;
NSDictionary *dict;
key1 = @"Key1";
key2 = @"Key2";
key3 = @"Key3";
val1 = @"Hello";
val2 = @"Goodbye";
val3 = @"Testing";
keys1 = [NSArray arrayWithObjects:key1,key2,nil];
keys2 = [NSArray arrayWithObjects:key1,key2,key3,nil];
keys3 = [NSArray arrayWithObjects:key1,key2,key2,nil]; /* duplicate keys */
keys4 = [NSArray arrayWithObjects:key1,key2,nil];
vals1 = [NSArray arrayWithObjects:val1,val2,nil];
vals2 = [NSArray arrayWithObjects:val1,val2,val2,nil]; /* duplicate vals */
vals3 = [NSArray arrayWithObjects:val1,val2,val3,nil];
vals4 = [NSArray arrayWithObjects:val1, val2, val3, [NSDate date],
[NSNumber numberWithInt:2],
[NSData data], nil];
keys4 = [NSArray arrayWithObjects:key1, key2, key2, @"date", @"number",
@"data",nil];
dict = [NSDictionary new];
PASS(dict != nil &&
[dict isKindOfClass:[NSDictionary class]]
&& [dict count] == 0,
"-count returns zero for an empty dictionary");
PASS([dict hash] == 0, "-hash returns zero for an empty dictionary");
obj = [dict allKeys];
PASS(obj != nil &&
[obj isKindOfClass:[NSArray class]] &&
[obj count] == 0,
"-allKeys gives an empty array for an empty dictionary");
obj = [dict allKeysForObject:nil];
PASS(obj == nil, "-allKeysForObject: gives nil for an empty dictionary");
obj = [dict allValues];
PASS(obj != nil &&
[obj isKindOfClass:[NSArray class]] &&
[obj count] == 0,
"-allValues gives an empty array for an empty dictionary");
{
id o1;
id o2;
o1 = [dict objectForKey:nil];
o2 = [dict objectForKey:key1];
PASS(o1 == nil && o2 == nil,
"-objectForKey: gives nil for an empty dictionary");
}
{
NSEnumerator *e = [dict keyEnumerator];
id k1,k2;
k1 = [e nextObject];
k2 = [e nextObject];
PASS(e != nil && k1 == nil && k2 == nil,
"-keyEnumerator: is ok for empty dictionary");
}
{
NSEnumerator *e = [dict objectEnumerator];
id v1,v2;
v1 = [e nextObject];
v2 = [e nextObject];
PASS(e != nil && v1 == nil && v2 == nil,
"-objectEnumerator: is ok for empty dictionary");
}
{
NSString *notFound = @"notFound";
NSArray *a = [dict objectsForKeys:keys1 notFoundMarker:notFound];
PASS(a != nil &&
[a isKindOfClass:[NSArray class]] &&
[a count] == 2 &&
[a objectAtIndex:0] == notFound &&
[a objectAtIndex:1] == notFound,
"-objectsForKeys:notFoundMarker: is ok for empty dictionary");
}
obj = [dict description];
obj = [obj propertyList];
PASS(obj != nil &&
[obj isKindOfClass:[NSDictionary class]] &&
[obj count] == 0,
"-description gives us a text property-list");
dict = [[NSDictionary dictionaryWithObjects:vals1 forKeys:keys1] retain];
PASS(dict != nil &&
[dict isKindOfClass:[NSDictionary class]] &&
[dict count] == 2,
"-count returns two for an dictionary with two keys");
PASS([dict hash] == 2, "-hash returns two for a dictionary with two keys");
obj = [dict allKeys];
PASS(obj != nil &&
[obj isKindOfClass:[NSArray class]] &&
[obj count] == 2 &&
[obj containsObject:key1] &&
[obj containsObject:key1],
"-allKeys gives the keys we put in the dictionary");
{
NSArray *o1,*o2;
o1 = [dict allKeysForObject:val1];
o2 = [dict allKeysForObject:val2];
PASS(o1 != nil &&
[o1 isKindOfClass:[NSArray class]] &&
[o1 count] == 1 &&
[o1 containsObject:key1] &&
o2 != nil &&
[o2 isKindOfClass:[NSArray class]] &&
[o2 count] == 1 &&
[o2 containsObject:key2],
"-allKeysForObject: gives the key we expect");
}
obj = [dict allValues];
PASS(obj != nil &&
[obj isKindOfClass:[NSArray class]] &&
[obj count] == 2 &&
[obj containsObject:val1] &&
[obj containsObject:val2],
"-allValues gives the values we put in the dictionary");
PASS([dict objectForKey:nil] == nil,"-objectForKey: gives nil for a nil key");
PASS([dict objectForKey:key3] == nil,
"-objectForKey: gives nil for a key not in the dictionary");
{
id o1 = [dict objectForKey: key1];
id o2 = [dict objectForKey: key2];
PASS(o1 == val1 && o2 == val2,
"-objectForKey: gives the objects we added for the keys");
}
{
NSEnumerator *e = [dict keyEnumerator];
id k1,k2,k3;
k1 = [e nextObject];
k2 = [e nextObject];
k3 = [e nextObject];
PASS(k1 != nil &&
k2 != nil &&
k3 == nil &&
k1 != k2 &&
[keys1 containsObject:k1] &&
[keys1 containsObject:k2],
"-keyEnumerator: enumerates the dictionary");
}
{
NSEnumerator *e = [dict objectEnumerator];
id v1,v2,v3;
v1 = [e nextObject];
v2 = [e nextObject];
v3 = [e nextObject];
PASS(v1 != nil &&
v2 != nil &&
v3 == nil &&
v1 != v2 &&
[vals1 containsObject:v1] &&
[vals1 containsObject:v2],
"-objectEnumerator: enumerates the dictionary");
}
{
NSString *notFound = @"notFound";
NSArray *a = [dict objectsForKeys:keys2 notFoundMarker:notFound];
PASS(a != nil &&
[a isKindOfClass:[NSArray class]] &&
[a count] == 3 &&
[a objectAtIndex:0] == val1 &&
[a objectAtIndex:1] == val2 &&
[a objectAtIndex:2] == notFound,
"-objectsForKeys:notFoundMarker: is ok for dictionary");
}
{
NSArray *a = [dict keysSortedByValueUsingSelector:@selector(compare:)];
PASS(a != nil &&
[a isKindOfClass:[NSArray class]] &&
[a count] == 2 &&
[a objectAtIndex:0] == key2 &&
[a objectAtIndex:1] == key1,
"-keysSortedByValueUsingSelector: seems ok");
}
obj = [dict description];
obj = [obj propertyList];
PASS(obj != nil &&
[obj isKindOfClass:[NSDictionary class]] &&
[obj isEqual:dict],
"-description gives us a text property-list");
ASSIGN(dict,[NSDictionary dictionaryWithObjects:vals4 forKeys:keys4]);
PASS(dict != nil, "we can create a dictionary with several keys");
#if defined(GNUSTEP_BASE_LIBRARY)
obj = [NSSerializer serializePropertyList:dict];
obj = [NSDeserializer deserializePropertyListFromData:obj
mutableContainers:YES];
PASS(obj != nil &&
[obj isKindOfClass:[NSDictionary class]] &&
[obj isEqual:dict],
"data/number/data are ok in serialized property-list");
#endif
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,69 @@
#import <Foundation/NSException.h>
#import <Foundation/NSAutoreleasePool.h>
#import "ObjectTesting.h"
static void
handler(NSException *e)
{
PASS (YES == [[e reason] isEqual: @"Terminate"],
"uncaught exceptionhandler called as expected");
abort();
}
@interface MyClass : NSObject
+ (void) testAbc;
@end
@implementation MyClass
+ (void) testAbc
{
[NSException raise: NSGenericException format: @"In MyClass"];
}
@end
int main()
{
NSException *obj;
NSMutableArray *testObjs = [[NSMutableArray alloc] init];
NSAutoreleasePool *arp = [NSAutoreleasePool new];
test_alloc_only(@"NSException");
obj = [NSException exceptionWithName: NSGenericException
reason: nil
userInfo: nil];
PASS((obj != nil), "can create an exception");
PASS(([[obj name] isEqualToString: NSGenericException]), "name works");
obj = [NSException exceptionWithName: NSGenericException
reason: nil
userInfo: nil];
[testObjs addObject: obj];
test_NSObject(@"NSException", testObjs);
NS_DURING
[MyClass testAbc];
NS_HANDLER
{
NSArray *a = [localException callStackSymbols];
NSEnumerator *e = [a objectEnumerator];
NSString *s = nil;
while ((s = [e nextObject]) != nil)
if ([s rangeOfString: @"testAbc"].length > 0)
break;
testHopeful = YES;
PASS(s != nil, "working callStackSymbols ... if this has failed it is probably due to a lack of support for objective-c method names (local symbols) in the backtrace_symbols() function of your libc. If so, you might lobby your operating system provider for a fix.");
testHopeful = NO;
}
NS_ENDHANDLER
PASS(NSGetUncaughtExceptionHandler() == 0, "default handler is null");
NSSetUncaughtExceptionHandler(handler);
PASS(NSGetUncaughtExceptionHandler() == handler, "setting handler works");
fprintf(stderr, "We expect a single FAIL without any explanation as\n"
"the test is terminated by an uncaught exception ...\n");
[NSException raise: NSGenericException format: @"Terminate"];
PASS(NO, "shouldn't get here ... exception should have terminated process");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1 @@
# this file is a marker to say that the test is expected to abort.

View file

@ -0,0 +1,35 @@
/*
Copyright (C) 2005 Free Software Foundation, Inc.
Written by: David Ayers <d.ayers@inode.at>
Date: February 2005
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#import "ObjectTesting.h"
#import <Foundation/Foundation.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
test_NSObject(@"NSFileHandle",
[NSArray arrayWithObject:[NSFileHandle fileHandleWithStandardInput]]);
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,87 @@
/*
Copyright (C) 2005 Free Software Foundation, Inc.
Written by: David Ayers <d.ayers@inode.at>
Date: February 2005
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#import "Testing.h"
#import "ObjectTesting.h"
#import <Foundation/Foundation.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
/* We invert the order so that we really test the FD values when they
are not opened in order. */
NSFileHandle *stdErrFH = [NSFileHandle fileHandleWithStandardError];
NSFileHandle *stdOutFH = [NSFileHandle fileHandleWithStandardOutput];
NSFileHandle *stdInFH = [NSFileHandle fileHandleWithStandardInput];
NSFileHandle *stdNullFH = [NSFileHandle fileHandleWithNullDevice];
NSFileHandle *t1FH, *t2FH;
NSString *tPath = [NSString stringWithFormat:@"%@/%@",NSTemporaryDirectory(),[[NSProcessInfo processInfo]globallyUniqueString]];
NSData *t1Data = [tPath dataUsingEncoding:NSUTF8StringEncoding];
NSData *t2Data;
PASS([stdInFH isKindOfClass:[NSFileHandle class]],
"NSFileHandle understands +fileHandleWithStandardInput");
PASS([stdInFH fileDescriptor]==0,
"NSFileHandle +fileHandleWithStandardInput has 0 as fileDescriptor");
PASS([stdOutFH isKindOfClass:[NSFileHandle class]],
"NSFileHandle understands +fileHandleWithStandardOutput");
PASS([stdOutFH fileDescriptor]==1,
"NSFileHandle +fileHandleWithStandardOutput has 1 as fileDescriptor");
PASS([stdErrFH isKindOfClass:[NSFileHandle class]],
"NSFileHandle understands +fileHandleWithStandardError");
PASS([stdErrFH fileDescriptor]==2,
"NSFileHandle +fileHandleWithStandardError has 2 as fileDescriptor");
PASS([stdNullFH isKindOfClass:[NSFileHandle class]],
"NSFileHandle understands +fileHandleWithNullDevice");
t1FH = [[NSFileHandle alloc] initWithFileDescriptor: 0];
PASS([t1FH isKindOfClass:[NSFileHandle class]],
"NSFileHandle understands -initWithFileDescriptor:");
t1FH = [NSFileHandle fileHandleForWritingAtPath: tPath];
PASS(t1FH == nil,
"NSFileHandle +fileHandleForWritingAtPath: with non-existing file return nil");
[@"" writeToFile: tPath atomically: YES];
t1FH = [NSFileHandle fileHandleForWritingAtPath: tPath];
PASS([t1FH isKindOfClass:[NSFileHandle class]],
"NSFileHandle understands +fileHandleForWritingAtPath:");
t2FH = [NSFileHandle fileHandleForReadingAtPath: tPath];
PASS([t2FH isKindOfClass:[NSFileHandle class]],
"NSFileHandle understands +fileHandleForReadingAtPath:");
[t1FH writeData: t1Data];
t2Data = [t2FH availableData];
PASS([t1Data isEqual: t2Data],
"NSFileHandle -writeData:/-availableData match");
[[NSFileManager defaultManager] removeFileAtPath: tPath handler: nil];
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,100 @@
#if defined(GNUSTEP_BASE_LIBRARY)
/*
Copyright (C) 2005 Free Software Foundation, Inc.
Written by: David Ayers <d.ayers@inode.at>
Date: November 2005
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#import "Testing.h"
#import "ObjectTesting.h"
#import <Foundation/Foundation.h>
#define GST_PORT @"32329"
NSFileHandle *rFH = nil;
@interface Handler : NSObject
@end
@implementation Handler
- (id)init
{
if ((self = [super init]))
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver: self
selector: @selector(connect:)
name: NSFileHandleConnectionAcceptedNotification
object: nil];
}
return self;
}
- (void)connect:(NSNotification *)notif
{
NSDictionary *d = [notif userInfo];
NSLog(@"%@", notif);
rFH = [[d objectForKey: NSFileHandleNotificationFileHandleItem] retain];
}
@end
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
Handler *h;
NSFileHandle *sFH, *cFH;
NSData *wData = [@"Socket Test" dataUsingEncoding:NSASCIIStringEncoding];
NSData *rData;
/* Note that the above data should be short enough to fit into the
socket send buffer otherwise we risk being blocked in this single
threaded process. */
h = [[Handler new] autorelease];
sFH = [NSFileHandle fileHandleAsServerAtAddress: @"127.0.0.1"
service: GST_PORT
protocol: @"tcp"];
PASS([sFH isKindOfClass:[NSFileHandle class]],
"NSFileHandle understands +fileHandleAsServerAtAddress:");
[sFH acceptConnectionInBackgroundAndNotify];
cFH = [NSFileHandle fileHandleAsClientAtAddress: @"127.0.0.1"
service: GST_PORT
protocol: @"tcp"];
PASS([cFH isKindOfClass:[NSFileHandle class]],
"NSFileHandle understands +fileHandleAsClientAtAddress:");
[cFH writeData: wData];
[[NSRunLoop currentRunLoop] run];
PASS(rFH != nil, "NSFileHandle connection was made");
rData = [rFH availableData];
PASS([wData isEqual: rData],
"NSFileHandle -writeData:/-availableData match with socket");
[arp release]; arp = nil;
return 0;
}
#else
int main()
{
return 0;
}
#endif

View file

@ -0,0 +1,12 @@
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSFileManager.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
test_NSObject(@"NSFileManager",
[NSArray arrayWithObject:[NSFileManager defaultManager]]);
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,163 @@
#import "Testing.h"
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSProcessInfo.h>
#import <Foundation/NSPathUtilities.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSFileManager *mgr = [NSFileManager defaultManager];
NSString *dir = @"NSFileManagerTestDir";
NSString *str1,*str2;
PASS(mgr != nil && [mgr isKindOfClass: [NSFileManager class]],
"NSFileManager understands +defaultManager");
/* remove test directory if it exists */
{
BOOL exists,isDir;
exists = [mgr fileExistsAtPath: dir isDirectory: &isDir];
if (exists)
{
[mgr removeFileAtPath: dir handler: nil];
}
}
PASS([mgr fileAttributesAtPath: dir traverseLink: NO] == nil,
"NSFileManager returns nil for attributes of non-existent file");
{
NSDictionary *attr;
BOOL isDir;
PASS([mgr createDirectoryAtPath: dir attributes: nil],
"NSFileManager can create a directory");
PASS([mgr fileExistsAtPath: dir isDirectory: &isDir] &&
isDir == YES,
"exists and is a directory");
PASS([mgr fileAttributesAtPath: dir traverseLink: NO] != nil,
"NSFileManager returns non-nil for attributes of existing file");
attr = [mgr fileAttributesAtPath: dir traverseLink: NO];
PASS(attr != nil,
"NSFileManager returns non-nil for attributes of existing file");
PASS([NSUserName() isEqual: [attr fileOwnerAccountName]],
"newly created file is owned by current user");
NSLog(@"'%@', '%@'", NSUserName(), [attr fileOwnerAccountName]);
}
PASS([mgr changeCurrentDirectoryPath: dir],
"NSFileManager can change directories");
{
NSString *dir1 = [mgr currentDirectoryPath];
PASS(dir1 != nil && [[dir1 lastPathComponent] isEqualToString: dir],
"NSFileManager can get current dir");
}
str1 = @"A string";
PASS([mgr createFileAtPath: @"NSFMFile"
contents: [str1 dataUsingEncoding: 1]
attributes: nil],
"NSFileManager creates a file");
PASS([mgr fileExistsAtPath: @"NSFMFile"],"-fileExistsAtPath: agrees");
{
NSData *dat1 = [mgr contentsAtPath: @"NSFMFile"];
str2 = [[NSString alloc] initWithData: dat1 encoding: 1];
PASS([str1 isEqualToString: str2], "NSFileManager file contents match");
}
PASS([mgr copyPath: @"NSFMFile"
toPath: @"NSFMCopy"
handler: nil],
"NSFileManager copies a file");
PASS([mgr fileExistsAtPath: @"NSFMCopy"],"-fileExistsAtPath: agrees");
{
NSData *dat1 = [mgr contentsAtPath: @"NSFMCopy"];
str2 = [[NSString alloc] initWithData: dat1 encoding: 1];
PASS([str1 isEqual: str2],"NSFileManager copied file contents match");
}
PASS([mgr movePath: @"NSFMFile"
toPath: @"NSFMMove"
handler: nil],
"NSFileManager moves a file");
PASS([mgr fileExistsAtPath: @"NSFMMove"],
"NSFileManager move destination exists");
PASS(![mgr fileExistsAtPath: @"NSFMFile"],
"NSFileManager move source doesn't exist");
{
NSData *dat1 = [mgr contentsAtPath: @"NSFMMove"];
str2 = [[NSString alloc] initWithData: dat1 encoding: 1];
PASS([str1 isEqualToString: str2],"NSFileManager moved file contents match");
}
if ([[NSProcessInfo processInfo] operatingSystem]
!= NSWindowsNTOperatingSystem)
{
PASS([mgr createSymbolicLinkAtPath: @"NSFMLink" pathContent: @"NSFMMove"],
"NSFileManager creates a symbolic link");
PASS([mgr fileExistsAtPath: @"NSFMLink"], "link exists");
PASS([mgr removeFileAtPath: @"NSFMLink" handler: nil],
"NSFileManager removes a symbolic link");
PASS(![mgr fileExistsAtPath: @"NSFMLink"],
"NSFileManager removed link doesn't exist");
PASS([mgr fileExistsAtPath: @"NSFMMove"],
"NSFileManager removed link's target still exists");
}
PASS([mgr removeFileAtPath: @"NSFMMove" handler: nil],
"NSFileManager removes a file");
PASS(![mgr fileExistsAtPath: @"NSFMMove"],
"NSFileManager removed file doesn't exist");
PASS([mgr isReadableFileAtPath: @"NSFMCopy"],
"NSFileManager isReadableFileAtPath: works");
PASS([mgr isWritableFileAtPath: @"NSFMCopy"],
"NSFileManager isWritableFileAtPath: works");
PASS([mgr isDeletableFileAtPath: @"NSFMCopy"],
"NSFileManager isDeletableFileAtPath: works");
PASS(![mgr isExecutableFileAtPath: @"NSFMCopy"],
"NSFileManager isExecutableFileAtPath: works");
TEST_EXCEPTION([mgr removeFileAtPath: @"." handler: nil];,
NSInvalidArgumentException, YES,
"NSFileManager -removeFileAtPath: @\".\" throws exception");
PASS([mgr createDirectoryAtPath: @"subdir" attributes: nil],
"NSFileManager can create a subdirectory");
PASS([mgr changeCurrentDirectoryPath: @"subdir"],
"NSFileManager can move into subdir");
TEST_EXCEPTION([mgr removeFileAtPath: @"." handler: nil];,
NSInvalidArgumentException, YES,
"NSFileManager -removeFileAtPath: @\".\" throws exception");
TEST_EXCEPTION([mgr removeFileAtPath: @".." handler: nil];,
NSInvalidArgumentException, YES,
"NSFileManager -removeFileAtPath: @\"..\" throws exception");
/* clean up */
{
BOOL exists,isDir;
[mgr changeCurrentDirectoryPath: [[[mgr currentDirectoryPath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]];
exists = [mgr fileExistsAtPath: dir isDirectory: &isDir];
if (exists || isDir)
{
PASS([mgr removeFileAtPath: dir handler: nil],
"NSFileManager removes a directory");
PASS(![mgr fileExistsAtPath: dir],"directory no longer exists");
}
isDir = NO;
}
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,40 @@
/*
copyright 2004 Alexander Malmberg <alexander@malmberg.org>
*/
#import "Testing.h"
#import <Foundation/NSArray.h>
#import <Foundation/NSString.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSFileManager.h>
int main(int argc, char **argv)
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSFileManager *fm=[NSFileManager defaultManager];
NSArray *files;
int i;
BOOL e,d;
files=[fm directoryContentsAtPath: @"."];
printf("%i files\n",[files count]);
for (i=0;i<[files count];i++)
{
int j;
NSString *f=[files objectAtIndex: i];
e=[fm fileExistsAtPath: f
isDirectory: &d];
printf("%5i: %i %i %s\n",i,e,d, [f lossyCString]);
for (j=0;j<[f length];j++)
printf(" %3i: %04x\n",j,[f characterAtIndex: j]);
}
/* const char *test="hallå.txt";
NSString *s=[NSString stringWithCString: test];
printf("s=%s\n", [s lossyCString]);*/
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,49 @@
#import <Foundation/Foundation.h>
#import "Testing.h"
#import "ObjectTesting.h"
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSDictionary *dict;
NSArray *cookies;
NSURL *url;
NSHTTPCookie *cookie;
TEST_FOR_CLASS(@"NSHTTPCookie", [NSHTTPCookie alloc],
"NSHTTPCookie +alloc returns an NSHTTPCookie");
dict = [NSDictionary dictionaryWithObjectsAndKeys: @"myname", @"Name",
@"myvalue", @"Value", @"/", @"Path", @".test.com", @"Domain", nil];
cookie = [NSHTTPCookie cookieWithProperties: dict];
TEST_FOR_CLASS(@"NSHTTPCookie", cookie,
"NSHTTPCookie +cookieWithProperties: returns an NSHTTPCookie");
dict = [NSDictionary dictionaryWithObjectsAndKeys: @"myname", @"Name",
@"myvalue", @"Value", @".test.com", @"Domain", nil];
cookie = [NSHTTPCookie cookieWithProperties: dict];
PASS(cookie == nil, "cookie without path returns nil");
dict = [NSDictionary dictionaryWithObject:
@"S=calendar=R7tjDKqNB5L8YTZSvf29Bg;Expires=Wed, 09-Mar-2011 23:00:35 GMT"
forKey: @"Set-Cookie"];
url = [NSURL URLWithString: @"http://www.google.com/calendar/feeds/default/"];
cookies= [NSHTTPCookie cookiesWithResponseHeaderFields: dict forURL: url];
TEST_FOR_CLASS(@"NSArray", cookies,
"NSHTTPCookie +cookiesWithResponseHeaderFields: returns an NSArray");
PASS([cookies count ] == 1, "cookies array contains a cookie");
cookie = [cookies objectAtIndex: 0];
PASS([[cookie name] isEqual: @"S"], "NSHTTPCookie returns proper name");
PASS([[cookie value] isEqual: @"calendar=R7tjDKqNB5L8YTZSvf29Bg"],
"NSHTTPCookie returns proper value");
PASS([[cookie domain] isEqual: [url host]],
"NSHTTPCookie returns proper domain");
dict = [NSHTTPCookie requestHeaderFieldsWithCookies: cookies];
PASS([[dict objectForKey: @"Cookie"] isEqual: @"S=calendar=R7tjDKqNB5L8YTZSvf29Bg"],
"NSHTTPCookie can generate proper cookie");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,20 @@
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSHashTable.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSHashTable *testObj;
testObj = [[NSHashTable new] autorelease];
[testObj addObject: @"hello"];
test_alloc(@"NSHashTable");
test_NSObject(@"NSHashTable", [NSArray arrayWithObject: testObj]);
test_NSCopying(@"NSHashTable",@"NSHashTable",
[NSArray arrayWithObject: testObj], NO, YES);
// test_NSCoding([NSArray arrayWithObject: testObj]);
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,34 @@
#import "ObjectTesting.h"
#import <Foundation/NSHashTable.h>
#import <Foundation/NSAutoreleasePool.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSString *val1, *val2, *val3;
NSHashTable *obj, *old;
id vals[3];
val1 = @"Hello";
val2 = @"Goodbye";
val3 = @"Testing";
vals[0] = val1;
vals[1] = val2;
vals[2] = val3;
obj = [[NSHashTable new] autorelease];
PASS(obj != nil
&& [obj isKindOfClass:[NSHashTable class]]
&& [obj count] == 0,
"+new creates an empty hash table");
[obj addObject: (void*)@"hello"];
PASS([obj count] == 1, "-addObject: increments count");
TEST_EXCEPTION([obj addObject: nil];,
NSInvalidArgumentException, YES, "-addObject: raises with nil");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,10 @@
#import <Foundation/NSAutoreleasePool.h>
#import "ObjectTesting.h"
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
[arp release]; arp = nil;
return 0;
}

13
Tests/base/NSHost/basic.m Normal file
View file

@ -0,0 +1,13 @@
#import "ObjectTesting.h"
#import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSHost.h>
#import <Foundation/NSString.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
test_NSObject(@"NSHost",[NSArray arrayWithObject:[NSHost currentHost]]);
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,37 @@
#import "ObjectTesting.h"
#import <Foundation/NSHost.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSString.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSHost *current;
NSHost *localh;
NSHost *tmp;
current = [NSHost currentHost];
PASS(current != nil && [current isKindOfClass:[NSHost class]],
"NSHost understands +currentHost");
#if defined(GNUSTEP_BASE_LIBRARY)
localh = [NSHost localHost];
PASS(localh != nil && [localh isKindOfClass:[NSHost class]],
"NSHost understands +localHost");
#else
localh = current;
#endif
tmp = [NSHost hostWithName:[current name]];
PASS([tmp isEqualToHost:current], "NSHost understands +hostWithName:");
tmp = [NSHost hostWithAddress:[current address]];
PASS([tmp isEqualToHost:current], "NSHost understands +hostWithAddress:");
tmp = [NSHost hostWithName:@"127.0.0.1"];
PASS(tmp != nil && [tmp isEqualToHost:localh],
"NSHost understands [+hostWithName: 127.0.0.1]");
[arp release]; arp = nil;
return 0;
}

View file

@ -0,0 +1,79 @@
#import "Testing.h"
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSIndexPath.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSIndexPath *index1;
NSIndexPath *index2;
NSUInteger i0[2];
NSUInteger i1[2];
i0[0] = i1[1] = 0;
i0[1] = i1[0] = 1;
index1 = [NSIndexPath indexPathWithIndex: 1];
PASS(index1 != nil &&
[index1 isKindOfClass:[NSIndexPath class]] &&
[index1 length] == 1 &&
[index1 indexAtPosition: 0] == 1,
"+indexPathWithIndex: works");
index2 = [NSIndexPath indexPathWithIndex: 1];
PASS(index1 == index2,
"index path gives a shared instance");
PASS([index1 indexAtPosition: 1] == NSNotFound,
"indexAtPosition: with bad location gives NSNotFound");
index1 = [index1 indexPathByAddingIndex: 9];
PASS([index1 length] == 2
&& [index1 indexAtPosition: 0] == 1
&& [index1 indexAtPosition: 1] == 9,
"indexPathByAddingIndex: works");
index1 = [index1 indexPathByRemovingLastIndex];
PASS([index1 length] == 1
&& [index1 indexAtPosition: 0] == 1,
"indexPathByRemovingLastIndex works");
index1 = [NSIndexPath indexPathWithIndexes: i0 length: 2];
PASS([index1 length] == 2
&& [index1 indexAtPosition: 0] == i0[0]
&& [index1 indexAtPosition: 1] == i0[1],
"indexPathWithindexes:length: works");
index2 = [NSIndexPath indexPathWithIndexes: i1 length: 2];
PASS([index1 length] == 2
&& [index1 indexAtPosition: 0] == i0[0]
&& [index1 indexAtPosition: 1] == i0[1],
"indexPathWithindexes:length: works for another path");
PASS([index1 isEqual: index2] == NO,
"different index paths are not equal");
PASS([index1 compare: index2] == NSOrderedAscending,
"comparison one way works");
PASS([index2 compare: index1] == NSOrderedDescending,
"comparison the other way works");
index1 = [index1 indexPathByAddingIndex: 1];
PASS([index1 compare: index2] == NSOrderedAscending,
"longer index1 comparison one way works");
PASS([index2 compare: index1] == NSOrderedDescending,
"longer index1 comparison the other way works");
index1 = [index1 indexPathByRemovingLastIndex];
index2 = [index2 indexPathByAddingIndex: 1];
PASS([index1 compare: index2] == NSOrderedAscending,
"longer index2 comparison one way works");
PASS([index2 compare: index1] == NSOrderedDescending,
"longer index2 comparison the other way works");
[arp release]; arp = nil;
{
BOOL didNotSegfault = YES;
PASS(didNotSegfault, "+indexPathWithIndex: doesn't mess up memory");
}
return 0;
}

Some files were not shown because too many files have changed in this diff Show more