winejoystick: Fix a crash on accessing a CFArray past its end due to an off-by-one...
[wine/multimedia.git] / dlls / jscript / tests / cc.js
blob8f45a3dd3313304e1a3ee823c0a72534723d0e9a
1 /*
2  * Copyright 2010 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
19 eval("@_jscript_version");
21 var tmp;
23 /*@ */
24 //@cc_on @*/
26 @_jscript_version;
28 @cc_on
29 @*/
31 // Standard predefined variabled
32 if(isWin64) {
33     ok(@_win64 === true, "@_win64 = " + @_win64);
34     ok(@_amd64 === true, "@_amd64 = " + @_amd64);
35     ok(isNaN(@_win32), "@_win32 = " + @_win32);
36     ok(isNaN(@_x86), "@_x86 = " + @_x86);
37 }else {
38     ok(@_win32 === true, "@_win32 = " + @_win32);
39     ok(@_x86 === true, "@_x86 = " + @_x86);
40     ok(isNaN(@_win64), "@_win64 = " + @_win64);
41     ok(isNaN(@_amd64), "@_amd64 = " + @_amd64);
44 ok(@_jscript === true, "@_jscript = " + @_jscript);
45 ok(@_jscript_build === ScriptEngineBuildVersion(),
46    "@_jscript_build = " + @_jscript_build + " expected " + ScriptEngineBuildVersion());
47 tmp = ScriptEngineMajorVersion() + ScriptEngineMinorVersion()/10;
48 ok(@_jscript_version === tmp, "@_jscript_version = " + @_jscript_version + " expected " + tmp);
49 ok(isNaN(@_win16), "@_win16 = " + @_win16);
50 ok(isNaN(@_mac), "@_mac = " + @_mac);
51 ok(isNaN(@_alpha), "@_alpha = " + @_alpha);
52 ok(isNaN(@_mc680x0), "@_mc680x0 = " + @_mc680x0);
53 ok(isNaN(@_PowerPC), "@_PowerPC = " + @_PowerPC);
55 // Undefined variable
56 ok(isNaN(@xxx), "@xxx = " + @xxx);
57 ok(isNaN(@x$_xx), "@x$_xx = " + @x$_xx);
59 tmp = false;
60 try {
61     eval("/*@cc_on */");
62 }catch(e) {
63     tmp = true;
65 ok(tmp, "expected syntax exception");
67 tmp = false;
68 try {
69     eval("/*@_jscript_version */");
70 }catch(e) {
71     tmp = true;
73 ok(tmp, "expected syntax exception");
75 ok(isNaN(@test), "@test = " + @test);
77 @set @test = 1
78 ok(@test === 1, "@test = " + @test);
80 @set @test = 0
81 ok(@test === 0, "@test = " + @test);
83 tmp = false
84 @set @test = @test tmp=true
85 ok(@test === 0, "@test = " + @test);
86 ok(tmp, "expr after @set not evaluated");
88 @set @test = !@test
89 ok(@test === true, "@test = " + @test);
91 @set @test = (@test+1+true)
92 ok(@test === 3, "@test = " + @test);
94 @set
95  @test
96  =
97  2
98 ok(@test === 2, "@test = " + @test);
100 @set
101  @test
108 ok(@test === 4, "@test = " + @test);
110 @set @test = 2.5
111 ok(@test === 2.5, "@test = " + @test);
113 @set @test = 0x4
114 ok(@test === 4, "@test = " + @test);
116 @set @test = (2 + 2/2)
117 ok(@test === 3, "@test = " + @test);
119 @set @test = (false+false)
120 ok(@test === 0, "@test = " + @test);
122 @set @test = ((1+1)*((3)+1))
123 ok(@test === 8, "@test = " + @test);
125 @set @_test = true
126 ok(@_test === true, "@_test = " + @_test);
128 @set @$test = true
129 ok(@$test === true, "@$test = " + @$test);
131 @set @newtest = (@newtest != @newtest)
132 ok(@newtest === true, "@newtest = " + @newtest);
134 @set @test = (false != 0)
135 ok(@test === false, "@test = " + @test);
137 @set @test = (1 != true)
138 ok(@test === false, "@test = " + @test);
140 @set @test = (0 != true)
141 ok(@test === true, "@test = " + @test);
143 @set @test = (true-2)
144 ok(@test === -1, "@test = " + @test);
146 @set @test = (true-@_jscript)
147 ok(@test === 0, "@test = " + @test);
149 @set @test = (true==1)
150 ok(@test === true, "@test = " + @test);
152 @set @test = (1==false+1)
153 ok(@test === true, "@test = " + @test);
155 function expect(val, exval) {
156     ok(val === exval, "got " + val + " expected " + exval);
159 @set @test = (false < 0.5)
160 expect(@test, true);
162 @set @test = (true == 0 < 0.5)
163 expect(@test, true);
165 @set @test = (false < 0)
166 expect(@test, false);
168 @set @test = (false > 0.5)
169 expect(@test, false);
171 @set @test = (1 < true)
172 expect(@test, false);
174 @set @test = (1 <= true)
175 expect(@test, true);
177 @set @test = (1 >= true)
178 expect(@test, true);
180 @set @test = (1 >= true-1)
181 expect(@test, true);
183 @if (false)
184     this wouldn not parse
185 "@end
187 @if (false) "@end
189 tmp = "@if (false) @end";
190 ok(tmp.length === 16, "tmp.length = " + tmp.length);
192 @if(true)
193 tmp = true
194 @end
195 ok(tmp === true, "tmp = " + tmp);
197 @if(false)
198 @if this would not CC parse
199 this will not parse
200 @elif(true)
201 this will also not parse
202 @else
203 this also will not parse
204 @if let me complicate things a bit
205 @end enough
206 @end
207 @end
209 @if(false)
210 this will not parse
211 @else
212 tmp = 2
213 @else
214 this will not be parsed
215 @else
216 also this
217 @end
218 ok(tmp === 2, "tmp = " + tmp);
220 @if(true)
221 tmp = 3;
222 @else
223 just skip this
224 @end
225 ok(tmp === 3, "tmp = " + tmp);
227 @if(true)
228 tmp = 4;
229 @elif(true)
230 this will not parse
231 @elif nor this
232 @else
233 just skip this
234 @end
235 ok(tmp === 4, "tmp = " + tmp);
237 @if(false)
238 this will not parse
239 @elif(false)
240 nor this would
241 @elif(true)
242 tmp = 5;
243 @elif nor this
244 @else
245 just skip this
246 @end
247 ok(tmp === 5, "tmp = " + tmp);
249 @if (!@_jscript)
250 this would not parse
251 @if(true)
252 @else
253 @if(false)
254 @end
255 @end
256 @elif (@_jscript)
257 tmp = 6;
258 @elif (true)
259 @if xxx
260 @else
261 @if @elif @elif @else @end
262 @end
263 @else
264 this would not parse
265 @end
266 ok(tmp === 6, "tmp = " + tmp);
268 @if(true)
269 @if(false)
270 @else
271 tmp = 7;
272 @end
273 @else
274 this would not parse
275 @end
276 ok(tmp === 7, "tmp = " + tmp);
278 var exception_map = {
279     JS_E_SYNTAX:               {type: "SyntaxError", number: -2146827286},
280     JS_E_MISSING_LBRACKET:     {type: "SyntaxError", number: -2146827283},
281     JS_E_EXPECTED_IDENTIFIER:  {type: "SyntaxError", number: -2146827278},
282     JS_E_EXPECTED_ASSIGN:      {type: "SyntaxError", number: -2146827277},
283     JS_E_EXPECTED_CCEND:       {type: "SyntaxError", number: -2146827259},
284     JS_E_EXPECTED_AT:          {type: "SyntaxError", number: -2146827256}
287 function testException(src, id) {
288     var ex = exception_map[id];
289     var ret = "", num = "";
291     try {
292         eval(src);
293     } catch(e) {
294         ret = e.name;
295         num = e.number;
296     }
298     ok(ret === ex.type, "Exception test, ret = " + ret + ", expected " + ex.type +". Executed code: " + src);
299     ok(num === ex.number, "Exception test, num = " + num + ", expected " + ex.number + ". Executed function: " + src);
302 testException("@set test=true", "JS_E_EXPECTED_AT");
303 testException("@set @1=true", "JS_E_EXPECTED_IDENTIFIER");
304 testException("@set @test x=true", "JS_E_EXPECTED_ASSIGN");
305 testException("@if false\n@end", "JS_E_MISSING_LBRACKET");
306 testException("@if (false)\n", "JS_E_EXPECTED_CCEND");
307 testException("@end\n", "JS_E_SYNTAX");
308 testException("@elif\n", "JS_E_SYNTAX");
309 testException("@else\n", "JS_E_SYNTAX");
310 testException("@if false\n@elif true\n@end", "JS_E_MISSING_LBRACKET");
312 reportSuccess();