]> err.no Git - sope/blob - Recycler/NGJavaScript/tests/JSTest.m
added Kolab sample data
[sope] / Recycler / NGJavaScript / tests / JSTest.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "JSTest.h"
24 #include "common.h"
25 #import <NGScripting/NGScriptLanguage.h>
26 #import <NGJavaScript/NGJavaScript.h>
27 #import <NGExtensions/NGExtensions.h>
28
29 @implementation JSTest
30
31 - (void)setUp {
32   id language;
33   id global;
34   
35   language = [NGScriptLanguage languageWithName:@"javascript"];
36   
37   self->mapCtx = [language createMappingContext];
38     
39   if (![[self->mapCtx jsContext] loadStandardClasses])
40     ;
41     
42   [self->mapCtx pushContext];
43
44   global = [[[NGJavaScriptObject alloc] init] autorelease];
45   [global applyStandardClasses];
46   [self->mapCtx setGlobalObject:global];
47 }
48 - (void)tearDown {
49   [[self->mapCtx jsContext] collectGarbage];
50   [[self->mapCtx jsContext] collectGarbage];
51    
52   [self->mapCtx popContext];
53   [self->mapCtx release];
54 }
55
56 - (void)print:(NSString *)_format arguments:(va_list)ap {
57   NSString *value = nil;
58   
59   value = [[NSString alloc] initWithFormat:_format arguments:ap];
60   printf("%s\n", [value cString]);
61   [value release];
62 }
63 - (void)print:(NSString *)_format, ... {
64   va_list ap;
65   
66   va_start(ap, _format);
67   [self print:_format arguments:ap];
68   va_end(ap);
69 }
70
71 - (void)printJavaScriptObjectInfo:(id)obj {
72   NSEnumerator *e;
73   void *jso;
74   id o;
75
76   jso = [[NGObjectMappingContext activeObjectMappingContext]
77                                  handleForObject:obj];
78   
79   [self print:@"info on o0x%08X j0x%08X", obj, jso];
80   [self print:@"  description: %@", obj];
81   
82   e = [obj keyEnumerator];
83   [self print:@"  keys: (%@)", e];
84   while ((o = [e nextObject]))
85     [self print:@"    - '%@' <%@>", o, [o class]];
86   
87   e = [obj objectEnumerator];
88   [self print:@"  values: (%@)", e];
89   while ((o = [e nextObject]))
90     [self print:@"    - '%@' <%@>", o, [o class]];
91   
92   e = [obj prototypeObjectChain];
93   [self print:@"  prototypes: %@", e];
94   while ((o = [e nextObject]))
95     [self print:@"    - %@ <%@>", o, [o class]];
96   
97   e = [obj parentObjectChain];
98   [self print:@"  parents: %@", e];
99   while ((o = [e nextObject]))
100     [self print:@"    - %@ <%@>", o, [o class]];
101 }
102
103 + (void)testSelector:(SEL)_sel failedWithException:(NSException *)_exception {
104   NSLog(@"EXCEPTION: %@", _exception);
105 }
106
107 + (void)runTestSelector:(SEL)_sel {
108   NSAutoreleasePool *pool;
109   id fixture;
110   
111   pool = [[NSAutoreleasePool alloc] init];
112   fixture = [[[self alloc] init] autorelease];
113   [fixture setUp];
114   
115   printf("\n--- RUN TEST: %s --------------------\n", 
116          [NSStringFromSelector(_sel) cString]);
117   NS_DURING
118     [fixture performSelector:_sel];
119   NS_HANDLER
120     [self testSelector:_sel failedWithException:localException];
121   NS_ENDHANDLER;
122   printf(">>> DONE\n");
123   
124   [fixture tearDown];
125   [pool release];
126 }
127 + (void)runTest:(NSString *)_name {
128   SEL sel;
129   
130   _name = [@"test" stringByAppendingString:_name];
131   sel = NSSelectorFromString(_name);
132   [self runTestSelector:sel];
133 }
134
135 @end /* JSTest */