2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #import <NGScripting/NGScriptLanguage.h>
26 #import <NGJavaScript/NGJavaScript.h>
27 #import <NGExtensions/NGExtensions.h>
29 @implementation JSTest
35 language = [NGScriptLanguage languageWithName:@"javascript"];
37 self->mapCtx = [language createMappingContext];
39 if (![[self->mapCtx jsContext] loadStandardClasses])
42 [self->mapCtx pushContext];
44 global = [[[NGJavaScriptObject alloc] init] autorelease];
45 [global applyStandardClasses];
46 [self->mapCtx setGlobalObject:global];
49 [[self->mapCtx jsContext] collectGarbage];
50 [[self->mapCtx jsContext] collectGarbage];
52 [self->mapCtx popContext];
53 [self->mapCtx release];
56 - (void)print:(NSString *)_format arguments:(va_list)ap {
57 NSString *value = nil;
59 value = [[NSString alloc] initWithFormat:_format arguments:ap];
60 printf("%s\n", [value cString]);
63 - (void)print:(NSString *)_format, ... {
66 va_start(ap, _format);
67 [self print:_format arguments:ap];
71 - (void)printJavaScriptObjectInfo:(id)obj {
76 jso = [[NGObjectMappingContext activeObjectMappingContext]
79 [self print:@"info on o0x%08X j0x%08X", obj, jso];
80 [self print:@" description: %@", obj];
82 e = [obj keyEnumerator];
83 [self print:@" keys: (%@)", e];
84 while ((o = [e nextObject]))
85 [self print:@" - '%@' <%@>", o, [o class]];
87 e = [obj objectEnumerator];
88 [self print:@" values: (%@)", e];
89 while ((o = [e nextObject]))
90 [self print:@" - '%@' <%@>", o, [o class]];
92 e = [obj prototypeObjectChain];
93 [self print:@" prototypes: %@", e];
94 while ((o = [e nextObject]))
95 [self print:@" - %@ <%@>", o, [o class]];
97 e = [obj parentObjectChain];
98 [self print:@" parents: %@", e];
99 while ((o = [e nextObject]))
100 [self print:@" - %@ <%@>", o, [o class]];
103 + (void)testSelector:(SEL)_sel failedWithException:(NSException *)_exception {
104 NSLog(@"EXCEPTION: %@", _exception);
107 + (void)runTestSelector:(SEL)_sel {
108 NSAutoreleasePool *pool;
111 pool = [[NSAutoreleasePool alloc] init];
112 fixture = [[[self alloc] init] autorelease];
115 printf("\n--- RUN TEST: %s --------------------\n",
116 [NSStringFromSelector(_sel) cString]);
118 [fixture performSelector:_sel];
120 [self testSelector:_sel failedWithException:localException];
122 printf(">>> DONE\n");
127 + (void)runTest:(NSString *)_name {
130 _name = [@"test" stringByAppendingString:_name];
131 sel = NSSelectorFromString(_name);
132 [self runTestSelector:sel];