gdi32: Fix the scaling of the width of cosmetic pens.
[wine/multimedia.git] / dlls / jscript / tests / run.c
blob5626bd84e5b963be363f9eb59fbd4ae122fb0cb6
1 /*
2 * Copyright 2008 Jacek Caban for CodeWeavers
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.
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.
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
19 #include <stdio.h>
21 #define COBJMACROS
22 #define CONST_VTABLE
24 #include <ole2.h>
25 #include <dispex.h>
26 #include <activscp.h>
28 #include "wine/test.h"
30 static const CLSID CLSID_JScript =
31 {0xf414c260,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
33 #define DEFINE_EXPECT(func) \
34 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
36 #define SET_EXPECT(func) \
37 expect_ ## func = TRUE
39 #define SET_CALLED(func) \
40 called_ ## func = TRUE
42 #define CHECK_EXPECT2(func) \
43 do { \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 called_ ## func = TRUE; \
46 }while(0)
48 #define CHECK_EXPECT(func) \
49 do { \
50 CHECK_EXPECT2(func); \
51 expect_ ## func = FALSE; \
52 }while(0)
54 #define CHECK_CALLED(func) \
55 do { \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
58 }while(0)
60 DEFINE_EXPECT(global_propget_d);
61 DEFINE_EXPECT(global_propget_i);
62 DEFINE_EXPECT(global_propput_d);
63 DEFINE_EXPECT(global_propput_i);
64 DEFINE_EXPECT(global_propdelete_d);
65 DEFINE_EXPECT(global_success_d);
66 DEFINE_EXPECT(global_success_i);
67 DEFINE_EXPECT(global_notexists_d);
68 DEFINE_EXPECT(puredisp_prop_d);
69 DEFINE_EXPECT(puredisp_noprop_d);
70 DEFINE_EXPECT(testobj_delete);
71 DEFINE_EXPECT(testobj_value);
72 DEFINE_EXPECT(testobj_prop_d);
73 DEFINE_EXPECT(testobj_noprop_d);
74 DEFINE_EXPECT(testobj_onlydispid_d);
75 DEFINE_EXPECT(testobj_onlydispid_i);
76 DEFINE_EXPECT(GetItemInfo_testVal);
77 DEFINE_EXPECT(ActiveScriptSite_OnScriptError);
78 DEFINE_EXPECT(invoke_func);
79 DEFINE_EXPECT(DeleteMemberByDispID);
81 #define DISPID_GLOBAL_TESTPROPGET 0x1000
82 #define DISPID_GLOBAL_TESTPROPPUT 0x1001
83 #define DISPID_GLOBAL_REPORTSUCCESS 0x1002
84 #define DISPID_GLOBAL_TRACE 0x1003
85 #define DISPID_GLOBAL_OK 0x1004
86 #define DISPID_GLOBAL_GETVT 0x1005
87 #define DISPID_GLOBAL_TESTOBJ 0x1006
88 #define DISPID_GLOBAL_NULL_BSTR 0x1007
89 #define DISPID_GLOBAL_NULL_DISP 0x1008
90 #define DISPID_GLOBAL_TESTTHIS 0x1009
91 #define DISPID_GLOBAL_TESTTHIS2 0x100a
92 #define DISPID_GLOBAL_INVOKEVERSION 0x100b
93 #define DISPID_GLOBAL_CREATEARRAY 0x100c
94 #define DISPID_GLOBAL_PROPGETFUNC 0x100d
95 #define DISPID_GLOBAL_OBJECT_FLAG 0x100e
96 #define DISPID_GLOBAL_ISWIN64 0x100f
97 #define DISPID_GLOBAL_PUREDISP 0x1010
98 #define DISPID_GLOBAL_TESTPROPDELETE 0x1010
100 #define DISPID_TESTOBJ_PROP 0x2000
101 #define DISPID_TESTOBJ_ONLYDISPID 0x2001
103 static const WCHAR testW[] = {'t','e','s','t',0};
104 static const CHAR testA[] = "test";
105 static const WCHAR test_valW[] = {'t','e','s','t','V','a','l',0};
106 static const CHAR test_valA[] = "testVal";
108 static BOOL strict_dispid_check;
109 static const char *test_name = "(null)";
110 static IDispatch *script_disp;
111 static int invoke_version;
112 static IActiveScriptError *script_error;
114 /* Returns true if the user interface is in English. Note that this does not
115 * presume of the formatting of dates, numbers, etc.
117 static BOOL is_lang_english(void)
119 static HMODULE hkernel32 = NULL;
120 static LANGID (WINAPI *pGetThreadUILanguage)(void) = NULL;
121 static LANGID (WINAPI *pGetUserDefaultUILanguage)(void) = NULL;
123 if (!hkernel32)
125 hkernel32 = GetModuleHandleA("kernel32.dll");
126 pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
127 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
129 if (pGetThreadUILanguage)
130 return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH;
131 if (pGetUserDefaultUILanguage)
132 return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH;
134 return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
137 static BSTR a2bstr(const char *str)
139 BSTR ret;
140 int len;
142 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
143 ret = SysAllocStringLen(NULL, len-1);
144 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
146 return ret;
149 static int strcmp_wa(LPCWSTR strw, const char *stra)
151 CHAR buf[512];
152 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
153 return lstrcmpA(buf, stra);
156 #define test_grfdex(a,b) _test_grfdex(__LINE__,a,b)
157 static void _test_grfdex(unsigned line, DWORD grfdex, DWORD expect)
159 expect |= invoke_version << 28;
160 ok_(__FILE__,line)(grfdex == expect, "grfdex = %x, expected %x\n", grfdex, expect);
163 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
165 *ppv = NULL;
167 if(IsEqualGUID(riid, &IID_IUnknown)
168 || IsEqualGUID(riid, &IID_IDispatch)
169 || IsEqualGUID(riid, &IID_IDispatchEx))
170 *ppv = iface;
171 else
172 return E_NOINTERFACE;
174 return S_OK;
177 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
179 return 2;
182 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
184 return 1;
187 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
189 ok(0, "unexpected call\n");
190 return E_NOTIMPL;
193 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
194 LCID lcid, ITypeInfo **ppTInfo)
196 ok(0, "unexpected call\n");
197 return E_NOTIMPL;
200 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
201 LPOLESTR *rgszNames, UINT cNames,
202 LCID lcid, DISPID *rgDispId)
204 ok(IsEqualGUID(riid, &IID_NULL), "Expected IID_NULL\n");
205 ok(cNames==1, "cNames = %d\n", cNames);
207 if(!strcmp_wa(*rgszNames, "prop")) {
208 CHECK_EXPECT(puredisp_prop_d);
209 *rgDispId = DISPID_TESTOBJ_PROP;
210 return S_OK;
211 } else if(!strcmp_wa(*rgszNames, "noprop")) {
212 CHECK_EXPECT(puredisp_noprop_d);
213 return DISP_E_UNKNOWNNAME;
216 ok(0, "unexpected call\n");
217 return E_NOTIMPL;
220 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
221 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
222 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
224 ok(0, "unexpected call\n");
225 return E_NOTIMPL;
228 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
230 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
231 return E_NOTIMPL;
234 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
236 ok(0, "unexpected call\n");
237 return E_NOTIMPL;
240 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
242 ok(0, "unexpected call\n");
243 return E_NOTIMPL;
246 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
248 ok(0, "unexpected call\n");
249 return E_NOTIMPL;
252 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
254 ok(0, "unexpected call\n");
255 return E_NOTIMPL;
258 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
260 ok(0, "unexpected call\n");
261 return E_NOTIMPL;
264 static HRESULT WINAPI testObj_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
266 if(!strcmp_wa(bstrName, "prop")) {
267 CHECK_EXPECT(testobj_prop_d);
268 test_grfdex(grfdex, fdexNameCaseSensitive);
269 *pid = DISPID_TESTOBJ_PROP;
270 return S_OK;
272 if(!strcmp_wa(bstrName, "noprop")) {
273 CHECK_EXPECT(testobj_noprop_d);
274 test_grfdex(grfdex, fdexNameCaseSensitive);
275 return DISP_E_UNKNOWNNAME;
277 if(!strcmp_wa(bstrName, "onlyDispID")) {
278 if(strict_dispid_check)
279 CHECK_EXPECT(testobj_onlydispid_d);
280 test_grfdex(grfdex, fdexNameCaseSensitive);
281 *pid = DISPID_TESTOBJ_ONLYDISPID;
282 return S_OK;
285 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
286 return E_NOTIMPL;
289 static HRESULT WINAPI testObj_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
290 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
292 switch(id) {
293 case DISPID_VALUE:
294 ok(pdp != NULL, "pdp == NULL\n");
295 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
296 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
297 ok(pvarRes != NULL, "pvarRes == NULL\n");
298 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
299 ok(pei != NULL, "pei == NULL\n");
301 switch(wFlags) {
302 case INVOKE_PROPERTYGET:
303 CHECK_EXPECT(testobj_value);
304 ok(!pdp->rgvarg, "rgvarg != NULL\n");
305 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
306 break;
307 case INVOKE_FUNC:
308 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
309 break;
310 case INVOKE_FUNC|INVOKE_PROPERTYGET:
311 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
312 break;
313 default:
314 ok(0, "invalid flag (%x)\n", wFlags);
317 V_VT(pvarRes) = VT_I4;
318 V_I4(pvarRes) = 1;
319 return S_OK;
320 case DISPID_TESTOBJ_ONLYDISPID:
321 if(strict_dispid_check)
322 CHECK_EXPECT(testobj_onlydispid_i);
323 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
324 ok(pdp != NULL, "pdp == NULL\n");
325 ok(!pdp->rgvarg, "rgvarg != NULL\n");
326 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
327 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
328 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
329 ok(pvarRes != NULL, "pvarRes == NULL\n");
330 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
331 ok(pei != NULL, "pei == NULL\n");
332 return DISP_E_MEMBERNOTFOUND;
335 ok(0, "unexpected call %x\n", id);
336 return DISP_E_MEMBERNOTFOUND;
339 static HRESULT WINAPI testObj_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
341 CHECK_EXPECT(testobj_delete);
343 ok(!strcmp_wa(bstrName, "deleteTest"), "unexpected name %s\n", wine_dbgstr_w(bstrName));
344 test_grfdex(grfdex, fdexNameCaseSensitive);
345 return S_OK;
348 static IDispatchExVtbl testObjVtbl = {
349 DispatchEx_QueryInterface,
350 DispatchEx_AddRef,
351 DispatchEx_Release,
352 DispatchEx_GetTypeInfoCount,
353 DispatchEx_GetTypeInfo,
354 DispatchEx_GetIDsOfNames,
355 DispatchEx_Invoke,
356 testObj_GetDispID,
357 testObj_InvokeEx,
358 testObj_DeleteMemberByName,
359 DispatchEx_DeleteMemberByDispID,
360 DispatchEx_GetMemberProperties,
361 DispatchEx_GetMemberName,
362 DispatchEx_GetNextDispID,
363 DispatchEx_GetNameSpaceParent
366 static IDispatchEx testObj = { &testObjVtbl };
368 static HRESULT WINAPI pureDisp_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
370 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IDispatch)) {
371 *ppv = iface;
372 return S_OK;
375 *ppv = NULL;
376 return E_NOINTERFACE;
379 static IDispatchExVtbl pureDispVtbl = {
380 pureDisp_QueryInterface,
381 DispatchEx_AddRef,
382 DispatchEx_Release,
383 DispatchEx_GetTypeInfoCount,
384 DispatchEx_GetTypeInfo,
385 DispatchEx_GetIDsOfNames,
386 DispatchEx_Invoke
389 static IDispatchEx pureDisp = { &pureDispVtbl };
391 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
393 if(!strcmp_wa(bstrName, "ok")) {
394 test_grfdex(grfdex, fdexNameCaseSensitive);
395 *pid = DISPID_GLOBAL_OK;
396 return S_OK;
398 if(!strcmp_wa(bstrName, "trace")) {
399 test_grfdex(grfdex, fdexNameCaseSensitive);
400 *pid = DISPID_GLOBAL_TRACE;
401 return S_OK;
403 if(!strcmp_wa(bstrName, "reportSuccess")) {
404 CHECK_EXPECT(global_success_d);
405 test_grfdex(grfdex, fdexNameCaseSensitive);
406 *pid = DISPID_GLOBAL_REPORTSUCCESS;
407 return S_OK;
409 if(!strcmp_wa(bstrName, "testPropGet")) {
410 CHECK_EXPECT(global_propget_d);
411 test_grfdex(grfdex, fdexNameCaseSensitive);
412 *pid = DISPID_GLOBAL_TESTPROPGET;
413 return S_OK;
415 if(!strcmp_wa(bstrName, "testPropPut")) {
416 CHECK_EXPECT(global_propput_d);
417 test_grfdex(grfdex, fdexNameCaseSensitive);
418 *pid = DISPID_GLOBAL_TESTPROPPUT;
419 return S_OK;
421 if(!strcmp_wa(bstrName, "testPropDelete")) {
422 CHECK_EXPECT(global_propdelete_d);
423 test_grfdex(grfdex, fdexNameCaseSensitive);
424 *pid = DISPID_GLOBAL_TESTPROPDELETE;
425 return S_OK;
427 if(!strcmp_wa(bstrName, "getVT")) {
428 test_grfdex(grfdex, fdexNameCaseSensitive);
429 *pid = DISPID_GLOBAL_GETVT;
430 return S_OK;
432 if(!strcmp_wa(bstrName, "testObj")) {
433 test_grfdex(grfdex, fdexNameCaseSensitive);
434 *pid = DISPID_GLOBAL_TESTOBJ;
435 return S_OK;
437 if(!strcmp_wa(bstrName, "createNullBSTR")) {
438 *pid = DISPID_GLOBAL_NULL_BSTR;
439 return S_OK;
441 if(!strcmp_wa(bstrName, "nullDisp")) {
442 *pid = DISPID_GLOBAL_NULL_DISP;
443 return S_OK;
445 if(!strcmp_wa(bstrName, "notExists")) {
446 CHECK_EXPECT(global_notexists_d);
447 test_grfdex(grfdex, fdexNameCaseSensitive);
448 return DISP_E_UNKNOWNNAME;
451 if(!strcmp_wa(bstrName, "testThis")) {
452 test_grfdex(grfdex, fdexNameCaseSensitive);
453 *pid = DISPID_GLOBAL_TESTTHIS;
454 return S_OK;
457 if(!strcmp_wa(bstrName, "testThis2")) {
458 test_grfdex(grfdex, fdexNameCaseSensitive);
459 *pid = DISPID_GLOBAL_TESTTHIS2;
460 return S_OK;
463 if(!strcmp_wa(bstrName, "invokeVersion")) {
464 test_grfdex(grfdex, fdexNameCaseSensitive);
465 *pid = DISPID_GLOBAL_INVOKEVERSION;
466 return S_OK;
468 if(!strcmp_wa(bstrName, "createArray")) {
469 test_grfdex(grfdex, fdexNameCaseSensitive);
470 *pid = DISPID_GLOBAL_CREATEARRAY;
471 return S_OK;
473 if(!strcmp_wa(bstrName, "propGetFunc")) {
474 test_grfdex(grfdex, fdexNameCaseSensitive);
475 *pid = DISPID_GLOBAL_PROPGETFUNC;
476 return S_OK;
478 if(!strcmp_wa(bstrName, "objectFlag")) {
479 test_grfdex(grfdex, fdexNameCaseSensitive);
480 *pid = DISPID_GLOBAL_OBJECT_FLAG;
481 return S_OK;
484 if(!strcmp_wa(bstrName, "isWin64")) {
485 test_grfdex(grfdex, fdexNameCaseSensitive);
486 *pid = DISPID_GLOBAL_ISWIN64;
487 return S_OK;
490 if(!strcmp_wa(bstrName, "pureDisp")) {
491 test_grfdex(grfdex, fdexNameCaseSensitive);
492 *pid = DISPID_GLOBAL_PUREDISP;
493 return S_OK;
496 if(strict_dispid_check)
497 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName));
498 return DISP_E_UNKNOWNNAME;
501 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
502 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
504 switch(id) {
505 case DISPID_GLOBAL_OK:
506 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
507 ok(pdp != NULL, "pdp == NULL\n");
508 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
509 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
510 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
511 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
512 if(wFlags & INVOKE_PROPERTYGET)
513 ok(pvarRes != NULL, "pvarRes == NULL\n");
514 else
515 ok(!pvarRes, "pvarRes != NULL\n");
516 ok(pei != NULL, "pei == NULL\n");
518 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
519 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
520 ok(V_BOOL(pdp->rgvarg+1), "%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
522 return S_OK;
524 case DISPID_GLOBAL_TRACE:
525 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
526 ok(pdp != NULL, "pdp == NULL\n");
527 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
528 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
529 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
530 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
531 ok(!pvarRes, "pvarRes != NULL\n");
532 ok(pei != NULL, "pei == NULL\n");
534 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
535 if(V_VT(pdp->rgvarg) == VT_BSTR)
536 trace("%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
538 return S_OK;
540 case DISPID_GLOBAL_REPORTSUCCESS:
541 CHECK_EXPECT(global_success_i);
543 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
544 ok(pdp != NULL, "pdp == NULL\n");
545 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
546 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
547 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
548 ok(!pvarRes, "pvarRes != NULL\n");
549 ok(pei != NULL, "pei == NULL\n");
551 return S_OK;
553 case DISPID_GLOBAL_TESTPROPGET:
554 CHECK_EXPECT(global_propget_i);
556 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
557 ok(pdp != NULL, "pdp == NULL\n");
558 ok(!pdp->rgvarg, "rgvarg != NULL\n");
559 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
560 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
561 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
562 ok(pvarRes != NULL, "pvarRes == NULL\n");
563 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
564 ok(pei != NULL, "pei == NULL\n");
566 V_VT(pvarRes) = VT_I4;
567 V_I4(pvarRes) = 1;
569 return S_OK;
571 case DISPID_GLOBAL_TESTPROPPUT:
572 CHECK_EXPECT(global_propput_i);
574 ok(wFlags == INVOKE_PROPERTYPUT, "wFlags = %x\n", wFlags);
575 ok(pdp != NULL, "pdp == NULL\n");
576 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
577 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
578 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
579 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
580 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
581 ok(!pvarRes, "pvarRes != NULL\n");
583 ok(V_VT(pdp->rgvarg) == VT_I4, "V_VT(pdp->rgvarg)=%d\n", V_VT(pdp->rgvarg));
584 ok(V_I4(pdp->rgvarg) == 1, "V_I4(pdp->rgvarg)=%d\n", V_I4(pdp->rgvarg));
585 return S_OK;
587 case DISPID_GLOBAL_GETVT:
588 ok(pdp != NULL, "pdp == NULL\n");
589 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
590 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
591 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
592 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
593 ok(pvarRes != NULL, "pvarRes == NULL\n");
594 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
595 ok(pei != NULL, "pei == NULL\n");
597 V_VT(pvarRes) = VT_BSTR;
598 switch(V_VT(pdp->rgvarg)) {
599 case VT_EMPTY:
600 V_BSTR(pvarRes) = a2bstr("VT_EMPTY");
601 break;
602 case VT_NULL:
603 V_BSTR(pvarRes) = a2bstr("VT_NULL");
604 break;
605 case VT_I4:
606 V_BSTR(pvarRes) = a2bstr("VT_I4");
607 break;
608 case VT_R8:
609 V_BSTR(pvarRes) = a2bstr("VT_R8");
610 break;
611 case VT_BSTR:
612 V_BSTR(pvarRes) = a2bstr("VT_BSTR");
613 break;
614 case VT_DISPATCH:
615 V_BSTR(pvarRes) = a2bstr("VT_DISPATCH");
616 break;
617 case VT_BOOL:
618 V_BSTR(pvarRes) = a2bstr("VT_BOOL");
619 break;
620 case VT_ARRAY|VT_VARIANT:
621 V_BSTR(pvarRes) = a2bstr("VT_ARRAY|VT_VARIANT");
622 break;
623 default:
624 ok(0, "unknown vt %d\n", V_VT(pdp->rgvarg));
625 return E_FAIL;
628 return S_OK;
630 case DISPID_GLOBAL_TESTOBJ:
631 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
632 ok(pdp != NULL, "pdp == NULL\n");
633 ok(!pdp->rgvarg, "rgvarg != NULL\n");
634 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
635 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
636 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
637 ok(pvarRes != NULL, "pvarRes == NULL\n");
638 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
639 ok(pei != NULL, "pei == NULL\n");
641 V_VT(pvarRes) = VT_DISPATCH;
642 V_DISPATCH(pvarRes) = (IDispatch*)&testObj;
643 return S_OK;
645 case DISPID_GLOBAL_PUREDISP:
646 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
647 ok(pdp != NULL, "pdp == NULL\n");
648 ok(!pdp->rgvarg, "rgvarg != NULL\n");
649 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
650 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
651 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
652 ok(pvarRes != NULL, "pvarRes == NULL\n");
653 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
654 ok(pei != NULL, "pei == NULL\n");
656 V_VT(pvarRes) = VT_DISPATCH;
657 V_DISPATCH(pvarRes) = (IDispatch*)&pureDisp;
658 return S_OK;
660 case DISPID_GLOBAL_NULL_BSTR:
661 if(pvarRes) {
662 V_VT(pvarRes) = VT_BSTR;
663 V_BSTR(pvarRes) = NULL;
665 return S_OK;
667 case DISPID_GLOBAL_ISWIN64:
668 if(pvarRes) {
669 V_VT(pvarRes) = VT_BOOL;
670 V_BOOL(pvarRes) = sizeof(void*) == 8 ? VARIANT_TRUE : VARIANT_FALSE;
672 return S_OK;
674 case DISPID_GLOBAL_NULL_DISP:
675 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
676 ok(pdp != NULL, "pdp == NULL\n");
677 ok(!pdp->rgvarg, "rgvarg != NULL\n");
678 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
679 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
680 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
681 ok(pvarRes != NULL, "pvarRes == NULL\n");
682 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
683 ok(pei != NULL, "pei == NULL\n");
685 V_VT(pvarRes) = VT_DISPATCH;
686 V_DISPATCH(pvarRes) = NULL;
687 return S_OK;
689 case DISPID_GLOBAL_TESTTHIS:
690 ok(pdp != NULL, "pdp == NULL\n");
691 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
692 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
693 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
694 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
695 ok(pvarRes == NULL, "pvarRes != NULL\n");
696 ok(pei != NULL, "pei == NULL\n");
698 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(arg) = %d\n", V_VT(pdp->rgvarg));
699 ok(V_DISPATCH(pdp->rgvarg) == (IDispatch*)iface, "disp != iface\n");
701 return S_OK;
703 case DISPID_GLOBAL_TESTTHIS2:
704 ok(pdp != NULL, "pdp == NULL\n");
705 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
706 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
707 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
708 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
709 ok(pvarRes == NULL, "pvarRes != NULL\n");
710 ok(pei != NULL, "pei == NULL\n");
712 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(arg) = %d\n", V_VT(pdp->rgvarg));
713 ok(V_DISPATCH(pdp->rgvarg) != (IDispatch*)iface, "disp == iface\n");
714 ok(V_DISPATCH(pdp->rgvarg) == script_disp, "disp != script_disp\n");
716 return S_OK;
718 case DISPID_GLOBAL_INVOKEVERSION:
719 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
720 ok(pdp != NULL, "pdp == NULL\n");
721 ok(!pdp->rgvarg, "rgvarg != NULL\n");
722 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
723 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
724 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
725 ok(pvarRes != NULL, "pvarRes == NULL\n");
726 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
727 ok(pei != NULL, "pei == NULL\n");
729 V_VT(pvarRes) = VT_I4;
730 V_I4(pvarRes) = invoke_version;
732 return S_OK;
734 case DISPID_GLOBAL_CREATEARRAY: {
735 SAFEARRAYBOUND bound[2];
736 VARIANT *data;
737 int i,j;
739 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
740 ok(pdp != NULL, "pdp == NULL\n");
741 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
742 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
743 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
744 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
745 ok(pvarRes != NULL, "pvarRes == NULL\n");
746 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
747 ok(pei != NULL, "pei == NULL\n");
749 bound[0].lLbound = 0;
750 bound[0].cElements = 5;
751 bound[1].lLbound = 2;
752 bound[1].cElements = 2;
754 V_VT(pvarRes) = VT_ARRAY|VT_VARIANT;
755 V_ARRAY(pvarRes) = SafeArrayCreate(VT_VARIANT, 2, bound);
757 SafeArrayAccessData(V_ARRAY(pvarRes), (void**)&data);
758 for(i=0; i<5; i++) {
759 for(j=2; j<4; j++) {
760 V_VT(data) = VT_I4;
761 V_I4(data) = i*10+j;
762 data++;
765 SafeArrayUnaccessData(V_ARRAY(pvarRes));
767 return S_OK;
770 case DISPID_GLOBAL_PROPGETFUNC:
771 switch(wFlags) {
772 case INVOKE_FUNC:
773 CHECK_EXPECT(invoke_func);
774 break;
775 case INVOKE_FUNC|INVOKE_PROPERTYGET:
776 ok(pdp->cArgs != 0, "pdp->cArgs = %d\n", pdp->cArgs);
777 ok(pvarRes != NULL, "pdp->pvarRes == NULL\n");
778 break;
779 default:
780 ok(0, "invalid flag (%x)\n", wFlags);
783 ok(pdp != NULL, "pdp == NULL\n");
784 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
785 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
786 ok(pei != NULL, "pei == NULL\n");
788 if(pvarRes) {
789 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
790 V_VT(pvarRes) = VT_I4;
791 V_I4(pvarRes) = pdp->cArgs;
794 return S_OK;
796 case DISPID_GLOBAL_OBJECT_FLAG: {
797 IDispatchEx *dispex;
798 BSTR str;
799 HRESULT hres;
801 hres = IDispatch_QueryInterface(script_disp, &IID_IDispatchEx, (void**)&dispex);
802 ok(hres == S_OK, "hres = %x\n", hres);
804 str = a2bstr("Object");
805 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
806 SysFreeString(str);
807 ok(hres == S_OK, "hres = %x\n", hres);
809 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_METHOD, pdp, NULL, pei, pspCaller);
810 ok(hres == S_OK, "hres = %x\n", hres);
812 V_VT(pvarRes) = VT_EMPTY;
813 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_METHOD, pdp, pvarRes, pei, pspCaller);
814 ok(hres == S_OK, "hres = %x\n", hres);
815 ok(V_VT(pvarRes) == VT_DISPATCH, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
816 VariantClear(pvarRes);
818 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_METHOD|DISPATCH_PROPERTYGET, pdp, NULL, pei, pspCaller);
819 ok(hres == S_OK, "hres = %x\n", hres);
821 V_VT(pvarRes) = VT_EMPTY;
822 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_CONSTRUCT, pdp, pvarRes, pei, pspCaller);
823 ok(hres == S_OK, "hres = %x\n", hres);
824 ok(V_VT(pvarRes) == VT_DISPATCH, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
825 VariantClear(pvarRes);
827 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_CONSTRUCT, pdp, NULL, pei, pspCaller);
828 ok(hres == S_OK, "hres = %x\n", hres);
830 V_VT(pvarRes) = VT_EMPTY;
831 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_CONSTRUCT|DISPATCH_PROPERTYGET, pdp, pvarRes, pei, pspCaller);
832 ok(hres == E_INVALIDARG, "hres = %x\n", hres);
834 V_VT(pvarRes) = VT_EMPTY;
835 hres = IDispatchEx_InvokeEx(dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
836 ok(hres == S_OK, "hres = %x\n", hres);
837 ok(V_VT(pvarRes) == VT_DISPATCH, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
838 IDispatchEx_Release(dispex);
839 return S_OK;
843 ok(0, "unexpected call %x\n", id);
844 return DISP_E_MEMBERNOTFOUND;
847 static HRESULT WINAPI Global_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
849 CHECK_EXPECT(DeleteMemberByDispID);
850 ok(id == DISPID_GLOBAL_TESTPROPDELETE, "id = %d\n", id);
851 return S_OK;
854 static IDispatchExVtbl GlobalVtbl = {
855 DispatchEx_QueryInterface,
856 DispatchEx_AddRef,
857 DispatchEx_Release,
858 DispatchEx_GetTypeInfoCount,
859 DispatchEx_GetTypeInfo,
860 DispatchEx_GetIDsOfNames,
861 DispatchEx_Invoke,
862 Global_GetDispID,
863 Global_InvokeEx,
864 DispatchEx_DeleteMemberByName,
865 Global_DeleteMemberByDispID,
866 DispatchEx_GetMemberProperties,
867 DispatchEx_GetMemberName,
868 DispatchEx_GetNextDispID,
869 DispatchEx_GetNameSpaceParent
872 static IDispatchEx Global = { &GlobalVtbl };
874 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
876 *ppv = NULL;
878 if(IsEqualGUID(&IID_IUnknown, riid))
879 *ppv = iface;
880 else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
881 *ppv = iface;
882 else
883 return E_NOINTERFACE;
885 IUnknown_AddRef((IUnknown*)*ppv);
886 return S_OK;
889 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
891 return 2;
894 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
896 return 1;
899 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
901 *plcid = GetUserDefaultLCID();
902 return S_OK;
905 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
906 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
908 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
909 ok(!ppti, "ppti != NULL\n");
911 if(!strcmp_wa(pstrName, test_valA))
912 CHECK_EXPECT(GetItemInfo_testVal);
913 else if(strcmp_wa(pstrName, testA))
914 ok(0, "unexpected pstrName %s\n", wine_dbgstr_w(pstrName));
916 *ppiunkItem = (IUnknown*)&Global;
917 return S_OK;
920 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
922 return E_NOTIMPL;
925 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
926 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
928 return E_NOTIMPL;
931 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
933 return E_NOTIMPL;
936 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
938 return E_NOTIMPL;
941 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
943 return E_NOTIMPL;
946 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
948 return E_NOTIMPL;
951 #undef ACTSCPSITE_THIS
953 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
954 ActiveScriptSite_QueryInterface,
955 ActiveScriptSite_AddRef,
956 ActiveScriptSite_Release,
957 ActiveScriptSite_GetLCID,
958 ActiveScriptSite_GetItemInfo,
959 ActiveScriptSite_GetDocVersionString,
960 ActiveScriptSite_OnScriptTerminate,
961 ActiveScriptSite_OnStateChange,
962 ActiveScriptSite_OnScriptError,
963 ActiveScriptSite_OnEnterScript,
964 ActiveScriptSite_OnLeaveScript
967 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
969 static HRESULT WINAPI ActiveScriptSite_OnScriptError_CheckError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
971 ok(pscripterror != NULL, "ActiveScriptSite_OnScriptError -- expected pscripterror to be set, got NULL\n");
973 script_error = pscripterror;
974 IUnknown_AddRef(script_error);
976 CHECK_EXPECT(ActiveScriptSite_OnScriptError);
978 return S_OK;
981 static const IActiveScriptSiteVtbl ActiveScriptSite_CheckErrorVtbl = {
982 ActiveScriptSite_QueryInterface,
983 ActiveScriptSite_AddRef,
984 ActiveScriptSite_Release,
985 ActiveScriptSite_GetLCID,
986 ActiveScriptSite_GetItemInfo,
987 ActiveScriptSite_GetDocVersionString,
988 ActiveScriptSite_OnScriptTerminate,
989 ActiveScriptSite_OnStateChange,
990 ActiveScriptSite_OnScriptError_CheckError,
991 ActiveScriptSite_OnEnterScript,
992 ActiveScriptSite_OnLeaveScript
995 static IActiveScriptSite ActiveScriptSite_CheckError = { &ActiveScriptSite_CheckErrorVtbl };
997 static HRESULT set_script_prop(IActiveScript *engine, DWORD property, VARIANT *val)
999 IActiveScriptProperty *script_prop;
1000 HRESULT hres;
1002 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptProperty,
1003 (void**)&script_prop);
1004 ok(hres == S_OK, "Could not get IActiveScriptProperty iface: %08x\n", hres);
1006 hres = IActiveScriptProperty_SetProperty(script_prop, property, NULL, val);
1007 IActiveScriptProperty_Release(script_prop);
1009 return hres;
1012 static IActiveScript *create_script(void)
1014 IActiveScript *script;
1015 VARIANT v;
1016 HRESULT hres;
1018 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1019 &IID_IActiveScript, (void**)&script);
1020 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1022 V_VT(&v) = VT_I4;
1023 V_I4(&v) = invoke_version;
1024 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
1025 ok(hres == S_OK || broken(hres == E_NOTIMPL), "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
1026 if(invoke_version && FAILED(hres)) {
1027 IActiveScript_Release(script);
1028 return NULL;
1031 return script;
1034 static HRESULT parse_script(DWORD flags, BSTR script_str)
1036 IActiveScriptParse *parser;
1037 IActiveScript *engine;
1038 HRESULT hres;
1040 engine = create_script();
1041 if(!engine)
1042 return S_OK;
1044 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1045 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1046 if (FAILED(hres))
1048 IActiveScript_Release(engine);
1049 return hres;
1052 hres = IActiveScriptParse64_InitNew(parser);
1053 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1055 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1056 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1058 hres = IActiveScript_AddNamedItem(engine, testW,
1059 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags);
1060 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1062 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1063 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1065 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp);
1066 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
1067 ok(script_disp != NULL, "script_disp == NULL\n");
1068 ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n");
1070 hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1072 IDispatch_Release(script_disp);
1073 IActiveScript_Release(engine);
1074 IUnknown_Release(parser);
1076 return hres;
1079 static HRESULT parse_htmlscript(BSTR script_str)
1081 IActiveScriptParse *parser;
1082 IActiveScript *engine;
1083 HRESULT hres;
1084 BSTR tmp = a2bstr("</SCRIPT>");
1086 engine = create_script();
1087 if(!engine)
1088 return E_FAIL;
1090 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1091 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1092 if (FAILED(hres))
1094 IActiveScript_Release(engine);
1095 return E_FAIL;
1098 hres = IActiveScriptParse64_InitNew(parser);
1099 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1101 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1102 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1104 hres = IActiveScript_AddNamedItem(engine, testW,
1105 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
1106 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1108 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1109 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1111 hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, tmp, 0, 0, 0, NULL, NULL);
1113 IActiveScript_Release(engine);
1114 IUnknown_Release(parser);
1115 SysFreeString(tmp);
1117 return hres;
1120 static void test_IActiveScriptError(IActiveScriptError *error, SCODE errorcode, ULONG line, LONG pos, BSTR script_source, BSTR description, BSTR line_text)
1122 HRESULT hres;
1123 DWORD source_context;
1124 ULONG line_number;
1125 LONG char_position;
1126 BSTR linetext;
1127 EXCEPINFO excep;
1129 /* IActiveScriptError_GetSourcePosition */
1131 hres = IActiveScriptError_GetSourcePosition(error, NULL, NULL, NULL);
1132 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
1134 source_context = 0xdeadbeef;
1135 hres = IActiveScriptError_GetSourcePosition(error, &source_context, NULL, NULL);
1136 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
1137 ok(source_context == 0, "IActiveScriptError_GetSourcePosition -- source_context: expected 0, got 0x%08x\n", source_context);
1139 line_number = 0xdeadbeef;
1140 hres = IActiveScriptError_GetSourcePosition(error, NULL, &line_number, NULL);
1141 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
1142 ok(line_number == line, "IActiveScriptError_GetSourcePosition -- line_number: expected %d, got %d\n", line, line_number);
1144 char_position = 0xdeadbeef;
1145 hres = IActiveScriptError_GetSourcePosition(error, NULL, NULL, &char_position);
1146 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
1147 ok(char_position == pos, "IActiveScriptError_GetSourcePosition -- char_position: expected %d, got %d\n", pos, char_position);
1149 /* IActiveScriptError_GetSourceLineText */
1151 hres = IActiveScriptError_GetSourceLineText(error, NULL);
1152 ok(hres == E_POINTER, "IActiveScriptError_GetSourceLineText -- hres: expected E_POINTER, got 0x%08x\n", hres);
1154 linetext = NULL;
1155 hres = IActiveScriptError_GetSourceLineText(error, &linetext);
1156 if (line_text) {
1157 ok(hres == S_OK, "IActiveScriptError_GetSourceLineText -- hres: expected S_OK, got 0x%08x\n", hres);
1158 ok(linetext != NULL && !lstrcmpW(linetext, line_text),
1159 "IActiveScriptError_GetSourceLineText -- expected %s, got %s\n", wine_dbgstr_w(line_text), wine_dbgstr_w(linetext));
1160 } else {
1161 ok(hres == E_FAIL, "IActiveScriptError_GetSourceLineText -- hres: expected S_OK, got 0x%08x\n", hres);
1162 ok(linetext == NULL,
1163 "IActiveScriptError_GetSourceLineText -- expected NULL, got %s\n", wine_dbgstr_w(linetext));
1165 SysFreeString(linetext);
1167 /* IActiveScriptError_GetExceptionInfo */
1169 hres = IActiveScriptError_GetExceptionInfo(error, NULL);
1170 ok(hres == E_POINTER, "IActiveScriptError_GetExceptionInfo -- hres: expected E_POINTER, got 0x%08x\n", hres);
1172 excep.wCode = 0xdead;
1173 excep.wReserved = 0xdead;
1174 excep.bstrSource = (BSTR)0xdeadbeef;
1175 excep.bstrDescription = (BSTR)0xdeadbeef;
1176 excep.bstrHelpFile = (BSTR)0xdeadbeef;
1177 excep.dwHelpContext = 0xdeadbeef;
1178 excep.pvReserved = (void *)0xdeadbeef;
1179 excep.pfnDeferredFillIn = (void *)0xdeadbeef;
1180 excep.scode = 0xdeadbeef;
1182 hres = IActiveScriptError_GetExceptionInfo(error, &excep);
1183 ok(hres == S_OK, "IActiveScriptError_GetExceptionInfo -- hres: expected S_OK, got 0x%08x\n", hres);
1185 ok(excep.wCode == 0, "IActiveScriptError_GetExceptionInfo -- excep.wCode: expected 0, got 0x%08x\n", excep.wCode);
1186 ok(excep.wReserved == 0, "IActiveScriptError_GetExceptionInfo -- excep.wReserved: expected 0, got %d\n", excep.wReserved);
1187 if (!is_lang_english())
1188 skip("Non-english UI (test with hardcoded strings)\n");
1189 else {
1190 ok(excep.bstrSource != NULL && !lstrcmpW(excep.bstrSource, script_source),
1191 "IActiveScriptError_GetExceptionInfo -- excep.bstrSource is not valid: expected %s, got %s\n",
1192 wine_dbgstr_w(script_source), wine_dbgstr_w(excep.bstrSource));
1193 ok(excep.bstrDescription != NULL && !lstrcmpW(excep.bstrDescription, description),
1194 "IActiveScriptError_GetExceptionInfo -- excep.bstrDescription is not valid: got %s\n", wine_dbgstr_w(excep.bstrDescription));
1196 ok(excep.bstrHelpFile == NULL,
1197 "IActiveScriptError_GetExceptionInfo -- excep.bstrHelpFile: expected NULL, got %s\n", wine_dbgstr_w(excep.bstrHelpFile));
1198 ok(excep.dwHelpContext == 0, "IActiveScriptError_GetExceptionInfo -- excep.dwHelpContext: expected 0, got %d\n", excep.dwHelpContext);
1199 ok(excep.pvReserved == NULL, "IActiveScriptError_GetExceptionInfo -- excep.pvReserved: expected NULL, got %p\n", excep.pvReserved);
1200 ok(excep.pfnDeferredFillIn == NULL, "IActiveScriptError_GetExceptionInfo -- excep.pfnDeferredFillIn: expected NULL, got %p\n", excep.pfnDeferredFillIn);
1201 ok(excep.scode == errorcode, "IActiveScriptError_GetExceptionInfo -- excep.scode: expected 0x%08x, got 0x%08x\n", errorcode, excep.scode);
1203 SysFreeString(excep.bstrSource);
1204 SysFreeString(excep.bstrDescription);
1205 SysFreeString(excep.bstrHelpFile);
1208 static void parse_script_with_error(DWORD flags, BSTR script_str, SCODE errorcode, ULONG line, LONG pos, BSTR script_source, BSTR description, BSTR line_text)
1210 IActiveScriptParse *parser;
1211 IActiveScript *engine;
1212 HRESULT hres;
1214 engine = create_script();
1215 if(!engine)
1216 return;
1218 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1219 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1220 if (FAILED(hres))
1222 IActiveScript_Release(engine);
1223 return;
1226 hres = IActiveScriptParse64_InitNew(parser);
1227 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1229 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite_CheckError);
1230 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1232 hres = IActiveScript_AddNamedItem(engine, testW,
1233 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags);
1234 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1236 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1237 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1239 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp);
1240 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
1241 ok(script_disp != NULL, "script_disp == NULL\n");
1242 ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n");
1244 script_error = NULL;
1245 SET_EXPECT(ActiveScriptSite_OnScriptError);
1246 hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1247 todo_wine ok(hres == 0x80020101, "parse_script_with_error should have returned 0x80020101, got: 0x%08x\n", hres);
1248 todo_wine CHECK_CALLED(ActiveScriptSite_OnScriptError);
1250 if (script_error)
1252 test_IActiveScriptError(script_error, errorcode, line, pos, script_source, description, line_text);
1254 IUnknown_Release(script_error);
1257 IDispatch_Release(script_disp);
1258 IActiveScript_Release(engine);
1259 IUnknown_Release(parser);
1262 static void parse_script_af(DWORD flags, const char *src)
1264 BSTR tmp;
1265 HRESULT hres;
1267 tmp = a2bstr(src);
1268 hres = parse_script(flags, tmp);
1269 SysFreeString(tmp);
1270 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1273 static void parse_script_a(const char *src)
1275 parse_script_af(SCRIPTITEM_GLOBALMEMBERS, src);
1278 static void parse_script_with_error_a(const char *src, SCODE errorcode, ULONG line, LONG pos, LPCSTR source, LPCSTR desc, LPCSTR linetext)
1280 BSTR tmp, script_source, description, line_text;
1282 tmp = a2bstr(src);
1283 script_source = a2bstr(source);
1284 description = a2bstr(desc);
1285 line_text = a2bstr(linetext);
1287 parse_script_with_error(SCRIPTITEM_GLOBALMEMBERS, tmp, errorcode, line, pos, script_source, description, line_text);
1289 SysFreeString(line_text);
1290 SysFreeString(description);
1291 SysFreeString(script_source);
1292 SysFreeString(tmp);
1295 static HRESULT parse_htmlscript_a(const char *src)
1297 HRESULT hres;
1298 BSTR tmp = a2bstr(src);
1299 hres = parse_htmlscript(tmp);
1300 SysFreeString(tmp);
1302 return hres;
1305 static BSTR get_script_from_file(const char *filename)
1307 DWORD size, len;
1308 HANDLE file, map;
1309 const char *file_map;
1310 BSTR ret;
1312 file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
1313 if(file == INVALID_HANDLE_VALUE) {
1314 trace("Could not open file: %u\n", GetLastError());
1315 return NULL;
1318 size = GetFileSize(file, NULL);
1320 map = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
1321 CloseHandle(file);
1322 if(map == INVALID_HANDLE_VALUE) {
1323 trace("Could not create file mapping: %u\n", GetLastError());
1324 return NULL;
1327 file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
1328 CloseHandle(map);
1329 if(!file_map) {
1330 trace("MapViewOfFile failed: %u\n", GetLastError());
1331 return NULL;
1334 len = MultiByteToWideChar(CP_ACP, 0, file_map, size, NULL, 0);
1335 ret = SysAllocStringLen(NULL, len);
1336 MultiByteToWideChar(CP_ACP, 0, file_map, size, ret, len);
1338 UnmapViewOfFile(file_map);
1340 return ret;
1343 static void run_from_file(const char *filename)
1345 BSTR script_str;
1346 HRESULT hres;
1348 script_str = get_script_from_file(filename);
1349 if(!script_str)
1350 return;
1352 strict_dispid_check = FALSE;
1353 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, script_str);
1354 SysFreeString(script_str);
1355 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1358 static void run_from_res(const char *name)
1360 const char *data;
1361 DWORD size, len;
1362 BSTR str;
1363 HRSRC src;
1364 HRESULT hres;
1366 strict_dispid_check = FALSE;
1367 test_name = name;
1369 src = FindResourceA(NULL, name, (LPCSTR)40);
1370 ok(src != NULL, "Could not find resource %s\n", name);
1372 size = SizeofResource(NULL, src);
1373 data = LoadResource(NULL, src);
1375 len = MultiByteToWideChar(CP_ACP, 0, data, size, NULL, 0);
1376 str = SysAllocStringLen(NULL, len);
1377 MultiByteToWideChar(CP_ACP, 0, data, size, str, len);
1379 SET_EXPECT(global_success_d);
1380 SET_EXPECT(global_success_i);
1381 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, str);
1382 CHECK_CALLED(global_success_d);
1383 CHECK_CALLED(global_success_i);
1385 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1386 SysFreeString(str);
1389 static void test_isvisible(BOOL global_members)
1391 IActiveScriptParse *parser;
1392 IActiveScript *engine;
1393 HRESULT hres;
1395 static const WCHAR script_textW[] =
1396 {'v','a','r',' ','v',' ','=',' ','t','e','s','t','V','a','l',';',0};
1398 engine = create_script();
1399 if(!engine)
1400 return;
1402 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1403 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1404 if (FAILED(hres))
1406 IActiveScript_Release(engine);
1407 return;
1410 hres = IActiveScriptParse64_InitNew(parser);
1411 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1413 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1414 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1416 if(global_members)
1417 SET_EXPECT(GetItemInfo_testVal);
1418 hres = IActiveScript_AddNamedItem(engine, test_valW,
1419 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|
1420 (global_members ? SCRIPTITEM_GLOBALMEMBERS : 0));
1421 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1422 if(global_members)
1423 CHECK_CALLED(GetItemInfo_testVal);
1425 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1426 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1428 if(!global_members)
1429 SET_EXPECT(GetItemInfo_testVal);
1430 hres = IActiveScriptParse64_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1431 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1432 if(!global_members)
1433 CHECK_CALLED(GetItemInfo_testVal);
1435 hres = IActiveScriptParse64_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1436 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1438 IActiveScript_Release(engine);
1439 IUnknown_Release(parser);
1442 static void run_tests(void)
1444 HRESULT hres;
1446 if(invoke_version) {
1447 IActiveScript *script;
1449 script = create_script();
1450 if(!script) {
1451 win_skip("Could not create script\n");
1452 return;
1454 IActiveScript_Release(script);
1457 strict_dispid_check = TRUE;
1459 parse_script_a("");
1460 parse_script_a("/* empty */ ;");
1462 SET_EXPECT(global_propget_d);
1463 SET_EXPECT(global_propget_i);
1464 parse_script_a("testPropGet;");
1465 CHECK_CALLED(global_propget_d);
1466 CHECK_CALLED(global_propget_i);
1468 SET_EXPECT(global_propput_d);
1469 SET_EXPECT(global_propput_i);
1470 parse_script_a("testPropPut = 1;");
1471 CHECK_CALLED(global_propput_d);
1472 CHECK_CALLED(global_propput_i);
1474 SET_EXPECT(global_success_d);
1475 SET_EXPECT(global_success_i);
1476 parse_script_a("reportSuccess();");
1477 CHECK_CALLED(global_success_d);
1478 CHECK_CALLED(global_success_i);
1480 SET_EXPECT(testobj_delete);
1481 parse_script_a("delete testObj.deleteTest;");
1482 CHECK_CALLED(testobj_delete);
1484 SET_EXPECT(global_propdelete_d);
1485 SET_EXPECT(DeleteMemberByDispID);
1486 parse_script_a("delete testPropDelete;");
1487 CHECK_CALLED(global_propdelete_d);
1488 CHECK_CALLED(DeleteMemberByDispID);
1490 parse_script_a("(function reportSuccess() {})()");
1492 parse_script_a("ok(typeof(test) === 'object', \"typeof(test) != 'object'\");");
1494 parse_script_a("function reportSuccess() {}; reportSuccess();");
1496 SET_EXPECT(global_propget_d);
1497 parse_script_a("var testPropGet");
1498 CHECK_CALLED(global_propget_d);
1500 SET_EXPECT(global_propget_d);
1501 parse_script_a("eval('var testPropGet;');");
1502 CHECK_CALLED(global_propget_d);
1504 SET_EXPECT(global_notexists_d);
1505 parse_script_a("var notExists; notExists = 1;");
1506 CHECK_CALLED(global_notexists_d);
1508 parse_script_a("function f() { var testPropGet; }");
1509 parse_script_a("(function () { var testPropGet; })();");
1510 parse_script_a("(function () { eval('var testPropGet;'); })();");
1512 SET_EXPECT(invoke_func);
1513 parse_script_a("ok(propGetFunc() == 0, \"Incorrect propGetFunc value\");");
1514 CHECK_CALLED(invoke_func);
1515 parse_script_a("ok(propGetFunc(1) == 1, \"Incorrect propGetFunc value\");");
1516 parse_script_a("ok(propGetFunc(1, 2) == 2, \"Incorrect propGetFunc value\");");
1517 SET_EXPECT(invoke_func);
1518 parse_script_a("ok(propGetFunc().toString() == 0, \"Incorrect propGetFunc value\");");
1519 CHECK_CALLED(invoke_func);
1520 parse_script_a("ok(propGetFunc(1).toString() == 1, \"Incorrect propGetFunc value\");");
1521 SET_EXPECT(invoke_func);
1522 parse_script_a("propGetFunc(1);");
1523 CHECK_CALLED(invoke_func);
1525 parse_script_a("objectFlag(1).toString();");
1527 parse_script_a("(function() { var tmp = (function () { return testObj; })()(1);})();");
1528 parse_script_a("(function() { var tmp = (function () { return testObj; })()();})();");
1530 parse_script_a("ok((testObj instanceof Object) === false, 'testObj is instance of Object');");
1532 SET_EXPECT(testobj_prop_d);
1533 parse_script_a("ok(('prop' in testObj) === true, 'prop is not in testObj');");
1534 CHECK_CALLED(testobj_prop_d);
1536 SET_EXPECT(testobj_noprop_d);
1537 parse_script_a("ok(('noprop' in testObj) === false, 'noprop is in testObj');");
1538 CHECK_CALLED(testobj_noprop_d);
1540 SET_EXPECT(testobj_prop_d);
1541 parse_script_a("ok(Object.prototype.hasOwnProperty.call(testObj, 'prop') === true, 'hasOwnProperty(\\\"prop\\\") returned false');");
1542 CHECK_CALLED(testobj_prop_d);
1544 SET_EXPECT(testobj_noprop_d);
1545 parse_script_a("ok(Object.prototype.hasOwnProperty.call(testObj, 'noprop') === false, 'hasOwnProperty(\\\"noprop\\\") returned true');");
1546 CHECK_CALLED(testobj_noprop_d);
1548 SET_EXPECT(puredisp_prop_d);
1549 parse_script_a("ok(Object.prototype.hasOwnProperty.call(pureDisp, 'prop') === true, 'hasOwnProperty(\\\"noprop\\\") returned false');");
1550 CHECK_CALLED(puredisp_prop_d);
1552 SET_EXPECT(puredisp_noprop_d);
1553 parse_script_a("ok(Object.prototype.hasOwnProperty.call(pureDisp, 'noprop') === false, 'hasOwnProperty(\\\"noprop\\\") returned true');");
1554 CHECK_CALLED(puredisp_noprop_d);
1556 SET_EXPECT(testobj_value);
1557 parse_script_a("ok(String(testObj) === '1', 'wrong testObj value');");
1558 CHECK_CALLED(testobj_value);
1560 SET_EXPECT(testobj_value);
1561 parse_script_a("ok(String.prototype.concat.call(testObj, ' OK') === '1 OK', 'wrong concat result');");
1562 CHECK_CALLED(testobj_value);
1564 SET_EXPECT(global_propget_d);
1565 SET_EXPECT(global_propget_i);
1566 parse_script_a("this.testPropGet;");
1567 CHECK_CALLED(global_propget_d);
1568 CHECK_CALLED(global_propget_i);
1570 SET_EXPECT(global_propget_d);
1571 SET_EXPECT(global_propget_i);
1572 parse_script_a("(function () { this.testPropGet; })();");
1573 CHECK_CALLED(global_propget_d);
1574 CHECK_CALLED(global_propget_i);
1576 parse_script_a("testThis(this);");
1577 parse_script_a("(function () { testThis(this); })();");
1579 SET_EXPECT(testobj_onlydispid_d);
1580 SET_EXPECT(testobj_onlydispid_i);
1581 parse_script_a("ok(typeof(testObj.onlyDispID) === 'unknown', 'unexpected typeof(testObj.onlyDispID)');");
1582 CHECK_CALLED(testobj_onlydispid_d);
1583 CHECK_CALLED(testobj_onlydispid_i);
1585 run_from_res("lang.js");
1586 run_from_res("api.js");
1587 run_from_res("regexp.js");
1588 run_from_res("cc.js");
1590 test_isvisible(FALSE);
1591 test_isvisible(TRUE);
1593 parse_script_af(0, "test.testThis2(this);");
1594 parse_script_af(0, "(function () { test.testThis2(this); })();");
1596 hres = parse_htmlscript_a("<!--");
1597 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1598 hres = parse_htmlscript_a("-->");
1599 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1600 hres = parse_htmlscript_a("<!--\nvar a=1;\n-->\n");
1601 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1602 hres = parse_htmlscript_a("<!--\n<!-- ignore this\n-->\n");
1603 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1604 hres = parse_htmlscript_a("var a=1;\nif(a-->0) a=5;\n");
1605 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1606 hres = parse_htmlscript_a("var a=1;\nif(a\n-->0) a=5;\n");
1607 ok(hres != S_OK, "ParseScriptText have not failed\n");
1609 parse_script_with_error_a(
1610 "?",
1611 0x800a03ea, 0, 0,
1612 "Microsoft JScript compilation error",
1613 "Syntax error",
1614 "?");
1616 parse_script_with_error_a(
1617 "var a=1;\nif(a\n-->0) a=5;\n",
1618 0x800a03ee, 2, 0,
1619 "Microsoft JScript compilation error",
1620 "Expected ')'",
1621 "-->0) a=5;");
1623 parse_script_with_error_a(
1624 "new 3;",
1625 0x800a01bd, 0, 0,
1626 "Microsoft JScript runtime error",
1627 "Object doesn't support this action",
1628 NULL);
1630 parse_script_with_error_a(
1631 "new null;",
1632 0x800a138f, 0, 0,
1633 "Microsoft JScript runtime error",
1634 "Object expected",
1635 NULL);
1637 parse_script_with_error_a(
1638 "var a;\nnew null;",
1639 0x800a138f, 1, 0,
1640 "Microsoft JScript runtime error",
1641 "Object expected",
1642 NULL);
1644 parse_script_with_error_a(
1645 "var a; new null;",
1646 0x800a138f, 0, 7,
1647 "Microsoft JScript runtime error",
1648 "Object expected",
1649 NULL);
1652 static BOOL check_jscript(void)
1654 IActiveScriptProperty *script_prop;
1655 BSTR str;
1656 HRESULT hres;
1658 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1659 &IID_IActiveScriptProperty, (void**)&script_prop);
1660 if(FAILED(hres))
1661 return FALSE;
1662 IActiveScriptProperty_Release(script_prop);
1664 str = a2bstr("if(!('localeCompare' in String.prototype)) throw 1;");
1665 hres = parse_script(0, str);
1666 SysFreeString(str);
1668 return hres == S_OK;
1671 START_TEST(run)
1673 int argc;
1674 char **argv;
1676 argc = winetest_get_mainargs(&argv);
1678 CoInitialize(NULL);
1680 if(!check_jscript()) {
1681 win_skip("Broken engine, probably too old\n");
1682 }else if(argc > 2) {
1683 run_from_file(argv[2]);
1684 }else {
1685 trace("invoke version 0\n");
1686 invoke_version = 0;
1687 run_tests();
1689 trace("invoke version 2\n");
1690 invoke_version = 2;
1691 run_tests();
1694 CoUninitialize();