From 72b23b6482110e79ac4d942fa7fbfabd1e6c0ec1 Mon Sep 17 00:00:00 2001 From: mccallum Date: Wed, 2 Aug 1995 18:51:42 +0000 Subject: [PATCH] Initial revision git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@521 72102866-910b-0410-8b05-ffd578937521 --- Testing/MyCategory.h | 16 ++++++++ Testing/MyCategory.m | 20 ++++++++++ Testing/SecondClass.h | 21 ++++++++++ Testing/SecondClass.m | 28 ++++++++++++++ Testing/nsbundle.m | 89 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 174 insertions(+) create mode 100644 Testing/MyCategory.h create mode 100644 Testing/MyCategory.m create mode 100644 Testing/SecondClass.h create mode 100644 Testing/SecondClass.m create mode 100644 Testing/nsbundle.m diff --git a/Testing/MyCategory.h b/Testing/MyCategory.h new file mode 100644 index 000000000..9244ffc56 --- /dev/null +++ b/Testing/MyCategory.h @@ -0,0 +1,16 @@ +/* Test Category for NSBundle. + Copyright (C) 1993,1994,1995 Free Software Foundation, Inc. + + Written by: Adam Fedor + Date: Jul 1995 + + This file is part of the GNU Objective C Class Library. + +*/ +#include + +@interface NSObject(MyCategory) + +- printMyName; + +@end diff --git a/Testing/MyCategory.m b/Testing/MyCategory.m new file mode 100644 index 000000000..fadb37648 --- /dev/null +++ b/Testing/MyCategory.m @@ -0,0 +1,20 @@ +/* Test Category for NSBundle. + Copyright (C) 1993,1994,1995 Free Software Foundation, Inc. + + Written by: Adam Fedor + Date: Jul 1995 + + This file is part of the GNU Objective C Class Library. + +*/ +#include "MyCategory.h" + +@implementation NSObject(MyCategory) + +- printMyName +{ + printf("Class %s had MyCategory added to it\n", [self name]); + return self; +} + +@end diff --git a/Testing/SecondClass.h b/Testing/SecondClass.h new file mode 100644 index 000000000..32ebb6251 --- /dev/null +++ b/Testing/SecondClass.h @@ -0,0 +1,21 @@ +/* Test Class for NSBundle. + Copyright (C) 1993,1994,1995 Free Software Foundation, Inc. + + Written by: Adam Fedor + Date: Jul 1995 + + This file is part of the GNU Objective C Class Library. + +*/ +#include + +@interface SecondClass : NSObject +{ + int h; + char *dummy; +} + +- init; +- printName; + +@end diff --git a/Testing/SecondClass.m b/Testing/SecondClass.m new file mode 100644 index 000000000..d56bc5d43 --- /dev/null +++ b/Testing/SecondClass.m @@ -0,0 +1,28 @@ +/* Test Class for NSBundle. + Copyright (C) 1993,1994,1995 Free Software Foundation, Inc. + + Written by: Adam Fedor + Date: Jul 1995 + + This file is part of the GNU Objective C Class Library. + +*/ +#include "SecondClass.h" + +@implementation SecondClass + +- init +{ + [super init]; + h = 25; + return self; +} + +- printName + +{ + printf("Hi my name is %s\n", [self name]); + return self; +} + +@end diff --git a/Testing/nsbundle.m b/Testing/nsbundle.m new file mode 100644 index 000000000..bb20b0f4e --- /dev/null +++ b/Testing/nsbundle.m @@ -0,0 +1,89 @@ +/* nsbundle - Program to test out dynamic linking via NSBundle. + Copyright (C) 1993,1994,1995 Free Software Foundation, Inc. + + Written by: Adam Fedor + Date: Jul 1995 + + This file is part of the GNU Objective C Class Library. + +*/ +#include +#include "Foundation/NSBundle.h" +#include "Foundation/NSException.h" +#include "Foundation/NSString.h" +#include "LoadMe.h" +#include "SecondClass.h" +#include "MyCategory.h" + +/* Realize externals needed by objc-load */ +char **NSArgv; + +int +main(int ac, char *av[]) +{ + NSBundle *main; + NSBundle *bundle; + NSString *path; + id object; + + NSArgv = av; + + main = [NSBundle mainBundle]; + printf("Looking for main bundle...\n"); + if (!main) { + fprintf(stderr, "* ERROR: Can't get main bundle\n"); + exit(1); + } + printf(" Main bundle directory is %s\n", [[main bundlePath] cString]); + + printf("Looking for LoadMe bundle...\n"); + path = [main pathForResource:@"LoadMe" ofType:@"bundle"]; + if (!path) { + fprintf(stderr, "* ERROR: Can't find LoadMe bundle in main bundle\n"); + exit(1); + } + printf(" Found LoadMe in: %s\n\n", [path cString]); + + printf("Initializing LoadMe bundle...\n"); + bundle = [[NSBundle alloc] initWithPath:path]; + if (!bundle) { + fprintf(stderr, "* ERROR: Can't init LoadMe bundle\n"); + exit(1); + } + path = [bundle pathForResource:@"NXStringTable" ofType:@"example"]; + if (!path) { + fprintf(stderr, "* ERROR: Can't find example in LoadMe bundle\n"); + exit(1); + } + printf(" Found example file: %s\n\n", [path cString]); + + printf("Retreiving principal class...\n"); + NS_DURING + object = [bundle principalClass]; + NS_HANDLER + object = nil; + fprintf(stderr, " ERROR: %s\n", [[exception reason] cString]); + fprintf(stderr, " Either there is a problem with dynamic loading,\n"); + fprintf(stderr, " or there is no dynamic loader on your system\n"); + exit(1); + NS_ENDHANDLER + if (!object) { + fprintf(stderr, "* ERROR: Can't find principal class\n"); + exit(1); + } + printf(" Principal class is: %s\n", [object name]); + + printf("Testing LoadMe bundle classes...\n"); + printf(" This is LoadMe:\n"); + object = [[[bundle classNamed:@"LoadMe"] alloc] init]; + [object afterLoad]; + [object release]; + + printf("\n This is SecondClass:\n"); + object = [[[bundle classNamed:@"SecondClass"] alloc] init]; + [object printName]; + [object printMyName]; + [object release]; + + return 0; +}