2001-06-21 04:52:12 +00:00
|
|
|
#include <Foundation/Foundation.h>
|
2003-07-31 23:49:32 +00:00
|
|
|
#include <GNUstepBase/GCObject.h>
|
2004-06-03 14:46:41 +00:00
|
|
|
#include <GNUstepBase/GSMime.h>
|
2001-06-21 04:52:12 +00:00
|
|
|
#include <stdio.h>
|
1996-05-28 18:33:00 +00:00
|
|
|
|
2000-09-22 13:45:58 +00:00
|
|
|
|
2001-06-21 04:52:12 +00:00
|
|
|
#if 1
|
2002-08-24 06:00:44 +00:00
|
|
|
|
2005-07-01 08:53:32 +00:00
|
|
|
static void uncaught(NSException* e)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "In uncaught exception handler.\n");
|
|
|
|
[NSException raise: NSGenericException format: @"Recursive exception"];
|
|
|
|
}
|
|
|
|
|
2002-08-24 06:00:44 +00:00
|
|
|
static void test1(void)
|
|
|
|
{
|
|
|
|
NSURL *baseURL = [NSURL fileURLWithPath:@"/usr/local/bin"];
|
|
|
|
NSURL *url = [NSURL URLWithString:@"filename" relativeToURL:baseURL];
|
|
|
|
NSString *result = [url absoluteString];
|
2002-08-24 06:16:13 +00:00
|
|
|
NSString *expected = @"file://localhost/usr/local/bin/filename";
|
2002-08-24 06:00:44 +00:00
|
|
|
|
|
|
|
if ([result isEqualToString:expected])
|
|
|
|
NSLog(@"test 1 ok");
|
|
|
|
else
|
|
|
|
NSLog(@"-[NSURL absoluteString] returned \"%@\", expected \"%@\"", result, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test2(void)
|
|
|
|
{
|
|
|
|
NSURL *url = [NSURL fileURLWithPath:@"/tmp/foo"];
|
|
|
|
NSString *result = [url path];
|
|
|
|
NSString *expected = @"/tmp/foo";
|
|
|
|
|
|
|
|
if ([result isEqualToString:expected])
|
|
|
|
NSLog(@"Test 2 ok");
|
|
|
|
else
|
|
|
|
NSLog(@"-[NSURL path] returned \"%@\", expected \"%@\"", result, expected);
|
|
|
|
}
|
|
|
|
|
2004-06-03 14:46:41 +00:00
|
|
|
static try(GSMimeParser *p, NSData *d)
|
|
|
|
{
|
|
|
|
if ([p parse: d] == NO)
|
|
|
|
{
|
|
|
|
NSLog(@"HTTP parse failure - %@", p);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BOOL complete = [p isComplete];
|
|
|
|
GSMimeDocument *document = [p mimeDocument];
|
|
|
|
|
|
|
|
if (complete == NO && [p isInHeaders] == NO)
|
|
|
|
{
|
|
|
|
NSString *enc;
|
|
|
|
NSString *len;
|
|
|
|
int ver;
|
|
|
|
|
|
|
|
ver = [[[document headerNamed: @"http"]
|
|
|
|
objectForKey: NSHTTPPropertyServerHTTPVersionKey] intValue];
|
|
|
|
len = [[document headerNamed: @"content-length"] value];
|
|
|
|
enc = [[document headerNamed: @"content-transfer-encoding"] value];
|
|
|
|
if (enc == nil)
|
|
|
|
{
|
|
|
|
enc = [[document headerNamed: @"transfer-encoding"] value];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([enc isEqualToString: @"chunked"] == YES)
|
|
|
|
{
|
|
|
|
complete = NO; // Read chunked body data
|
|
|
|
}
|
|
|
|
else if (ver >= 1 && [len intValue] == 0)
|
|
|
|
{
|
|
|
|
complete = YES; // No content
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
complete = NO; // No
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (complete == YES)
|
|
|
|
{
|
|
|
|
NSLog(@"Got data %@", [p data]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-21 04:52:12 +00:00
|
|
|
int main ()
|
1996-05-28 18:33:00 +00:00
|
|
|
{
|
2001-06-21 04:52:12 +00:00
|
|
|
id pool = [NSAutoreleasePool new];
|
2001-07-07 04:36:01 +00:00
|
|
|
id o = [NSObject new];
|
2002-11-10 10:20:05 +00:00
|
|
|
id x;
|
|
|
|
NSString *s;
|
2002-04-05 16:26:47 +00:00
|
|
|
NSArray *a = [NSArray arrayWithObjects: @"a", @"b", nil];
|
2003-04-10 16:28:07 +00:00
|
|
|
struct aa {char a; double b; char c;} bb[2];
|
|
|
|
struct objc_struct_layout layout;
|
|
|
|
unsigned i;
|
|
|
|
|
2005-03-21 12:29:02 +00:00
|
|
|
NSLog(@"%@", [@"//home//nicola" pathComponents]);
|
|
|
|
|
2004-04-12 04:55:43 +00:00
|
|
|
NSLog(@"Orig: %@", [NSUserDefaults userLanguages]);
|
|
|
|
[NSUserDefaults setUserLanguages: [NSArray arrayWithObject: @"Bletch"]];
|
|
|
|
NSLog(@"Set: %@", [NSUserDefaults userLanguages]);
|
|
|
|
[NSUserDefaults setUserLanguages: [NSArray arrayWithObject: @"English"]];
|
|
|
|
NSLog(@"Set: %@", [NSUserDefaults userLanguages]);
|
|
|
|
|
2003-04-10 16:28:07 +00:00
|
|
|
printf("size = %d\n", objc_sizeof_type(@encode(struct aa)));
|
|
|
|
printf("pos = %d\n", (void*)&bb[1] - (void*)&bb[0]);
|
|
|
|
|
|
|
|
objc_layout_structure (@encode(struct aa), &layout);
|
|
|
|
while (objc_layout_structure_next_member (&layout))
|
|
|
|
{
|
|
|
|
int position, align;
|
|
|
|
const char *type;
|
|
|
|
|
|
|
|
objc_layout_structure_get_info (&layout, &position, &align, &type);
|
|
|
|
printf ("element %d has offset %d, alignment %d\n",
|
|
|
|
i++, position, align);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-05 16:26:47 +00:00
|
|
|
|
2002-11-19 15:50:31 +00:00
|
|
|
o = [GCMutableArray new];
|
|
|
|
x = [GCMutableArray new];
|
|
|
|
[o addObject: x];
|
|
|
|
[x addObject: o];
|
|
|
|
[o release];
|
|
|
|
[x release];
|
|
|
|
[GCObject gcCollectGarbage];
|
|
|
|
|
2002-11-10 10:20:05 +00:00
|
|
|
o = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"test", @"one",
|
|
|
|
[NSNumber numberWithBool: YES], @"two",
|
|
|
|
[NSDate date], @"three",
|
|
|
|
[NSNumber numberWithInt: 33], @"four",
|
|
|
|
[NSNumber numberWithFloat: 4.5], @"five",
|
|
|
|
nil];
|
|
|
|
s = [o description];
|
|
|
|
NSLog(@"%@", s);
|
|
|
|
x = [s propertyList];
|
|
|
|
NSLog(@"%d", [o isEqual: x]);
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2002-08-24 06:00:44 +00:00
|
|
|
|
|
|
|
test1();
|
|
|
|
test2();
|
|
|
|
|
2001-06-21 04:52:12 +00:00
|
|
|
printf ("Hello from object at 0x%x\n", (unsigned)[o self]);
|
2001-07-07 04:36:01 +00:00
|
|
|
|
2005-07-01 08:53:32 +00:00
|
|
|
NS_DURING
|
|
|
|
{
|
|
|
|
NSLog(@"Value for foo is %@", [a valueForKey: @"foo"]);
|
|
|
|
}
|
|
|
|
NS_HANDLER
|
|
|
|
{
|
|
|
|
NSLog(@"Caught expected exception: %@", localException);
|
|
|
|
}
|
|
|
|
NS_ENDHANDLER
|
2002-04-05 16:26:47 +00:00
|
|
|
|
2002-03-27 09:55:57 +00:00
|
|
|
[o release];
|
2001-07-07 04:36:01 +00:00
|
|
|
o = [NSString stringWithFormat: @"/proc/%d/status", getpid()];
|
|
|
|
NSLog(@"'%@'", o);
|
|
|
|
o = [NSString stringWithContentsOfFile: o];
|
|
|
|
NSLog(@"'%@'", o);
|
|
|
|
|
2005-07-01 08:53:32 +00:00
|
|
|
NSLog(@"This test should now cause program termination after a recursive exception");
|
|
|
|
|
|
|
|
NSSetUncaughtExceptionHandler(uncaught);
|
|
|
|
[NSException raise: NSGenericException format: @"an artifical exception"];
|
2001-06-21 04:52:12 +00:00
|
|
|
exit (0);
|
1996-05-28 18:33:00 +00:00
|
|
|
}
|
2001-06-21 04:52:12 +00:00
|
|
|
#else
|
|
|
|
int main (int argc, char **argv)
|
2000-09-20 13:48:49 +00:00
|
|
|
{
|
2001-06-21 04:52:12 +00:00
|
|
|
NSString *string;
|
|
|
|
id pool = [NSAutoreleasePool new];
|
|
|
|
NSProcessInfo *info = [NSProcessInfo processInfo];
|
|
|
|
NSUserDefaults *defaults;
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2001-06-21 04:52:12 +00:00
|
|
|
NSLog(@"Temporary directory - %@", NSTemporaryDirectory());
|
|
|
|
[info setProcessName: @"TestProcess"];
|
|
|
|
defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
NSLog(@"%@", [defaults dictionaryRepresentation]);
|
|
|
|
return 0;
|
2000-09-20 13:48:49 +00:00
|
|
|
}
|
2001-06-21 04:52:12 +00:00
|
|
|
#endif
|