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
23 #include "JSArchivingTests.h"
28 #import <NGJavaScript/NGJavaScript.h>
29 #import <NGScripting/NGScriptLanguage.h>
30 #import <NGExtensions/NGExtensions.h>
32 @implementation JSArchivingTests
35 [self runTest:@"Archiving"];
36 [self runTest:@"JSArrayArchiveEvalProblem"];
39 - (void)testArchiving {
40 static NSString *testScript =
42 @"var myArray=[1,2,3];\n"
43 @"function doIt(sender) {\n"
44 @" print('doIt, a='+a+', b='+b+', c='+c);\n"
50 original = [[NGJavaScriptObject alloc] init];
51 [original setObject:@"10" forKey:@"a"];
52 [original setObject:@"20" forKey:@"b"];
53 [original evaluateScript:testScript language:@"javascript"];
54 [self print:@" a: %@", [original objectForKey:@"a"]];
55 [self print:@" b: %@", [original objectForKey:@"b"]];
56 [self print:@" doIt: %@", [original objectForKey:@"doIt"]];
58 [self print:@"archive object %@ (keys=%@) ...",
60 [[original allKeys] componentsJoinedByString:@","]];
62 archive = [NSArchiver archivedDataWithRootObject:original];
63 [self print:@"archived to data, size %i", [archive length]];
65 copy = [NSUnarchiver unarchiveObjectWithData:archive];
66 [self print:@"unarchived object %@ (keys=%@)",
68 [[copy allKeys] componentsJoinedByString:@","]];
69 [self print:@" a: %@", [copy objectForKey:@"a"]];
70 [self print:@" b: %@", [copy objectForKey:@"b"]];
71 [self print:@" doIt: %@", [copy objectForKey:@"doIt"]];
72 [self print:@" myArray: %@ (%@)",
73 [copy objectForKey:@"myArray"],
74 [[copy objectForKey:@"myArray"] class]];
80 - (void)testJSArrayArchiveEvalProblem {
81 static NSString *testScriptA =
85 @" { 'a': 5, 'b': 10 }\n"
88 @" print('JS CODE CATCHED: '+exc);\n"
94 /* create an object */
96 wrapper = [[[NGJavaScriptObject alloc] init] autorelease];
97 [self print:@"object: %@ (keys=%@)", wrapper, [wrapper allKeys]];
99 [wrapper evaluateScript:testScriptA language:@"javascript"];
100 [self print:@"object: %@ (keys=%@)", wrapper, [wrapper allKeys]];
101 [self printJavaScriptObjectInfo:wrapper];
103 /* do the archiving/unarchiving transaction to create a copy */
105 archive = [NSArchiver archivedDataWithRootObject:wrapper];
106 NSAssert1([archive length] > 0,
107 @"archiver didn't generate a proper archive: %@",
110 copy = [NSUnarchiver unarchiveObjectWithData:archive];
111 NSAssert(copy != nil, @"couldn't unarchive the object at all");
112 NSAssert1([copy isKindOfClass:[NGJavaScriptObject class]],
113 @"unexpected object class: %@", [copy class]);
115 [self print:@"copy: %@ (keys=%@)", copy, [copy allKeys]];
116 [self printJavaScriptObjectInfo:wrapper];
119 the following broke with: "JS ERROR(<string>:1): null" which is
120 why we have this test
122 [copy evaluateScript:testScriptA language:@"javascript"];
125 @end /* JSArchivingTests */