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
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) \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 called_ ## func = TRUE; \
48 #define CHECK_EXPECT(func) \
50 CHECK_EXPECT2(func); \
51 expect_ ## func = FALSE; \
54 #define CHECK_CALLED(func) \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
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_success_d);
65 DEFINE_EXPECT(global_success_i);
66 DEFINE_EXPECT(testobj_delete);
67 DEFINE_EXPECT(GetItemInfo_testVal);
69 #define DISPID_GLOBAL_TESTPROPGET 0x1000
70 #define DISPID_GLOBAL_TESTPROPPUT 0x1001
71 #define DISPID_GLOBAL_REPORTSUCCESS 0x1002
72 #define DISPID_GLOBAL_TRACE 0x1003
73 #define DISPID_GLOBAL_OK 0x1004
74 #define DISPID_GLOBAL_GETVT 0x1005
75 #define DISPID_GLOBAL_TESTOBJ 0x1006
77 static const WCHAR testW[] = {'t','e','s','t',0};
78 static const CHAR testA[] = "test";
79 static const WCHAR test_valW[] = {'t','e','s','t','V','a','l',0};
80 static const CHAR test_valA[] = "testVal";
82 static BOOL strict_dispid_check;
83 static const char *test_name = "(null)";
85 static const char *debugstr_w(LPCWSTR str)
87 static char buf[1024];
92 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
96 static BSTR a2bstr(const char *str)
101 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
102 ret = SysAllocStringLen(NULL, len-1);
103 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
108 static int strcmp_wa(LPCWSTR strw, const char *stra)
111 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
112 return lstrcmpA(buf, stra);
115 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
119 if(IsEqualGUID(riid, &IID_IUnknown)
120 || IsEqualGUID(riid, &IID_IDispatch)
121 || IsEqualGUID(riid, &IID_IDispatchEx))
124 return E_NOINTERFACE;
129 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
134 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
139 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
141 ok(0, "unexpected call\n");
145 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
146 LCID lcid, ITypeInfo **ppTInfo)
148 ok(0, "unexpected call\n");
152 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
153 LPOLESTR *rgszNames, UINT cNames,
154 LCID lcid, DISPID *rgDispId)
156 ok(0, "unexpected call\n");
160 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
161 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
162 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
164 ok(0, "unexpected call\n");
168 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
170 ok(0, "unexpected call %s %x\n", debugstr_w(bstrName), grfdex);
174 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
176 ok(0, "unexpected call\n");
180 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
182 ok(0, "unexpected call\n");
186 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
188 ok(0, "unexpected call\n");
192 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
194 ok(0, "unexpected call\n");
198 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
200 ok(0, "unexpected call\n");
204 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
206 ok(0, "unexpected call\n");
210 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
211 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
213 ok(0, "unexpected call\n");
217 static HRESULT WINAPI testObj_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
219 CHECK_EXPECT(testobj_delete);
221 ok(!strcmp_wa(bstrName, "deleteTest"), "unexpected name %s\n", debugstr_w(bstrName));
222 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
226 static IDispatchExVtbl testObjVtbl = {
227 DispatchEx_QueryInterface,
230 DispatchEx_GetTypeInfoCount,
231 DispatchEx_GetTypeInfo,
232 DispatchEx_GetIDsOfNames,
234 DispatchEx_GetDispID,
236 testObj_DeleteMemberByName,
237 DispatchEx_DeleteMemberByDispID,
238 DispatchEx_GetMemberProperties,
239 DispatchEx_GetMemberName,
240 DispatchEx_GetNextDispID,
241 DispatchEx_GetNameSpaceParent
244 static IDispatchEx testObj = { &testObjVtbl };
246 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
248 if(!strcmp_wa(bstrName, "ok")) {
249 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
250 *pid = DISPID_GLOBAL_OK;
253 if(!strcmp_wa(bstrName, "trace")) {
254 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
255 *pid = DISPID_GLOBAL_TRACE;
258 if(!strcmp_wa(bstrName, "reportSuccess")) {
259 CHECK_EXPECT(global_success_d);
260 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
261 *pid = DISPID_GLOBAL_REPORTSUCCESS;
264 if(!strcmp_wa(bstrName, "testPropGet")) {
265 CHECK_EXPECT(global_propget_d);
266 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
267 *pid = DISPID_GLOBAL_TESTPROPGET;
270 if(!strcmp_wa(bstrName, "testPropPut")) {
271 CHECK_EXPECT(global_propput_d);
272 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
273 *pid = DISPID_GLOBAL_TESTPROPPUT;
276 if(!strcmp_wa(bstrName, "getVT")) {
277 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
278 *pid = DISPID_GLOBAL_GETVT;
281 if(!strcmp_wa(bstrName, "testObj")) {
282 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
283 *pid = DISPID_GLOBAL_TESTOBJ;
287 if(strict_dispid_check)
288 ok(0, "unexpected call %s\n", debugstr_w(bstrName));
289 return DISP_E_UNKNOWNNAME;
292 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
293 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
296 case DISPID_GLOBAL_OK:
297 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
298 ok(pdp != NULL, "pdp == NULL\n");
299 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
300 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
301 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
302 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
303 if(wFlags & INVOKE_PROPERTYGET)
304 ok(pvarRes != NULL, "pvarRes == NULL\n");
306 ok(!pvarRes, "pvarRes != NULL\n");
307 ok(pei != NULL, "pei == NULL\n");
309 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
310 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
311 ok(V_BOOL(pdp->rgvarg+1), "%s: %s\n", test_name, debugstr_w(V_BSTR(pdp->rgvarg)));
315 case DISPID_GLOBAL_TRACE:
316 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
317 ok(pdp != NULL, "pdp == NULL\n");
318 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
319 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
320 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
321 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
322 ok(!pvarRes, "pvarRes != NULL\n");
323 ok(pei != NULL, "pei == NULL\n");
325 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
326 if(V_VT(pdp->rgvarg) == VT_BSTR)
327 trace("%s: %s\n", test_name, debugstr_w(V_BSTR(pdp->rgvarg)));
331 case DISPID_GLOBAL_REPORTSUCCESS:
332 CHECK_EXPECT(global_success_i);
334 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
335 ok(pdp != NULL, "pdp == NULL\n");
336 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
337 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
338 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
339 ok(!pvarRes, "pvarRes != NULL\n");
340 ok(pei != NULL, "pei == NULL\n");
344 case DISPID_GLOBAL_TESTPROPGET:
345 CHECK_EXPECT(global_propget_i);
347 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
348 ok(pdp != NULL, "pdp == NULL\n");
349 ok(!pdp->rgvarg, "rgvarg != NULL\n");
350 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
351 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
352 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
353 ok(pvarRes != NULL, "pvarRes == NULL\n");
354 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
355 ok(pei != NULL, "pei == NULL\n");
357 V_VT(pvarRes) = VT_I4;
362 case DISPID_GLOBAL_TESTPROPPUT:
363 CHECK_EXPECT(global_propput_i);
365 ok(wFlags == INVOKE_PROPERTYPUT, "wFlags = %x\n", wFlags);
366 ok(pdp != NULL, "pdp == NULL\n");
367 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
368 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
369 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
370 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
371 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
372 ok(!pvarRes, "pvarRes != NULL\n");
374 ok(V_VT(pdp->rgvarg) == VT_I4, "V_VT(pdp->rgvarg)=%d\n", V_VT(pdp->rgvarg));
375 ok(V_I4(pdp->rgvarg) == 1, "V_I4(pdp->rgvarg)=%d\n", V_I4(pdp->rgvarg));
378 case DISPID_GLOBAL_GETVT:
379 ok(pdp != NULL, "pdp == NULL\n");
380 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
381 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
382 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
383 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
384 ok(pvarRes != NULL, "pvarRes == NULL\n");
385 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
386 ok(pei != NULL, "pei == NULL\n");
388 V_VT(pvarRes) = VT_BSTR;
389 switch(V_VT(pdp->rgvarg)) {
391 V_BSTR(pvarRes) = a2bstr("VT_EMPTY");
394 V_BSTR(pvarRes) = a2bstr("VT_NULL");
397 V_BSTR(pvarRes) = a2bstr("VT_I4");
400 V_BSTR(pvarRes) = a2bstr("VT_R8");
403 V_BSTR(pvarRes) = a2bstr("VT_BSTR");
406 V_BSTR(pvarRes) = a2bstr("VT_DISPATCH");
409 V_BSTR(pvarRes) = a2bstr("VT_BOOL");
412 ok(0, "unknown vt %d\n", V_VT(pdp->rgvarg));
418 case DISPID_GLOBAL_TESTOBJ:
419 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
420 ok(pdp != NULL, "pdp == NULL\n");
421 ok(!pdp->rgvarg, "rgvarg != NULL\n");
422 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
423 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
424 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
425 ok(pvarRes != NULL, "pvarRes == NULL\n");
426 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
427 ok(pei != NULL, "pei == NULL\n");
429 V_VT(pvarRes) = VT_DISPATCH;
430 V_DISPATCH(pvarRes) = (IDispatch*)&testObj;
434 ok(0, "unexpected call %x\n", id);
435 return DISP_E_MEMBERNOTFOUND;
438 static IDispatchExVtbl GlobalVtbl = {
439 DispatchEx_QueryInterface,
442 DispatchEx_GetTypeInfoCount,
443 DispatchEx_GetTypeInfo,
444 DispatchEx_GetIDsOfNames,
448 DispatchEx_DeleteMemberByName,
449 DispatchEx_DeleteMemberByDispID,
450 DispatchEx_GetMemberProperties,
451 DispatchEx_GetMemberName,
452 DispatchEx_GetNextDispID,
453 DispatchEx_GetNameSpaceParent
456 static IDispatchEx Global = { &GlobalVtbl };
458 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
462 if(IsEqualGUID(&IID_IUnknown, riid))
464 else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
467 return E_NOINTERFACE;
469 IUnknown_AddRef((IUnknown*)*ppv);
473 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
478 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
483 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
485 *plcid = GetUserDefaultLCID();
489 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
490 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
492 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
493 ok(!ppti, "ppti != NULL\n");
495 if(!strcmp_wa(pstrName, test_valA))
496 CHECK_EXPECT(GetItemInfo_testVal);
497 else if(strcmp_wa(pstrName, testA))
498 ok(0, "unexpected pstrName %s\n", debugstr_w(pstrName));
500 *ppiunkItem = (IUnknown*)&Global;
504 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
509 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
510 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
515 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
520 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
525 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
530 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
535 #undef ACTSCPSITE_THIS
537 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
538 ActiveScriptSite_QueryInterface,
539 ActiveScriptSite_AddRef,
540 ActiveScriptSite_Release,
541 ActiveScriptSite_GetLCID,
542 ActiveScriptSite_GetItemInfo,
543 ActiveScriptSite_GetDocVersionString,
544 ActiveScriptSite_OnScriptTerminate,
545 ActiveScriptSite_OnStateChange,
546 ActiveScriptSite_OnScriptError,
547 ActiveScriptSite_OnEnterScript,
548 ActiveScriptSite_OnLeaveScript
551 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
553 static IActiveScript *create_script(void)
555 IActiveScript *script;
558 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
559 &IID_IActiveScript, (void**)&script);
560 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
565 static void parse_script(BSTR script_str)
567 IActiveScriptParse *parser;
568 IActiveScript *engine;
571 engine = create_script();
575 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
576 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
579 IActiveScript_Release(engine);
583 hres = IActiveScriptParse64_InitNew(parser);
584 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
586 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
587 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
589 hres = IActiveScript_AddNamedItem(engine, testW,
590 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
591 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
593 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
594 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
596 hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
597 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
599 IActiveScript_Release(engine);
600 IUnknown_Release(parser);
603 static HRESULT parse_htmlscript(BSTR script_str)
605 IActiveScriptParse *parser;
606 IActiveScript *engine;
608 BSTR tmp = a2bstr("</SCRIPT>");
610 engine = create_script();
614 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
615 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
618 IActiveScript_Release(engine);
622 hres = IActiveScriptParse64_InitNew(parser);
623 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
625 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
626 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
628 hres = IActiveScript_AddNamedItem(engine, testW,
629 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
630 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
632 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
633 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
635 hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, tmp, 0, 0, 0, NULL, NULL);
637 IActiveScript_Release(engine);
638 IUnknown_Release(parser);
644 static void parse_script_a(const char *src)
646 BSTR tmp = a2bstr(src);
651 static HRESULT parse_htmlscript_a(const char *src)
654 BSTR tmp = a2bstr(src);
655 hres = parse_htmlscript(tmp);
661 static BSTR get_script_from_file(const char *filename)
665 const char *file_map;
668 file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
669 if(file == INVALID_HANDLE_VALUE) {
670 trace("Could not open file: %u\n", GetLastError());
674 size = GetFileSize(file, NULL);
676 map = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
678 if(map == INVALID_HANDLE_VALUE) {
679 trace("Could not create file mapping: %u\n", GetLastError());
683 file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
686 trace("MapViewOfFile failed: %u\n", GetLastError());
690 len = MultiByteToWideChar(CP_ACP, 0, file_map, size, NULL, 0);
691 ret = SysAllocStringLen(NULL, len);
692 MultiByteToWideChar(CP_ACP, 0, file_map, size, ret, len);
694 UnmapViewOfFile(file_map);
699 static void run_from_file(const char *filename)
701 BSTR script_str = get_script_from_file(filename);
703 strict_dispid_check = FALSE;
706 parse_script(script_str);
708 SysFreeString(script_str);
711 static void run_from_res(const char *name)
718 strict_dispid_check = FALSE;
721 src = FindResourceA(NULL, name, (LPCSTR)40);
722 ok(src != NULL, "Could not find resource %s\n", name);
724 size = SizeofResource(NULL, src);
725 data = LoadResource(NULL, src);
727 len = MultiByteToWideChar(CP_ACP, 0, data, size, NULL, 0);
728 str = SysAllocStringLen(NULL, len);
729 len = MultiByteToWideChar(CP_ACP, 0, data, size, str, len);
731 SET_EXPECT(global_success_d);
732 SET_EXPECT(global_success_i);
734 CHECK_CALLED(global_success_d);
735 CHECK_CALLED(global_success_i);
740 static void test_isvisible(BOOL global_members)
742 IActiveScriptParse *parser;
743 IActiveScript *engine;
746 static const WCHAR script_textW[] =
747 {'v','a','r',' ','v',' ','=',' ','t','e','s','t','V','a','l',';',0};
749 engine = create_script();
753 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
754 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
757 IActiveScript_Release(engine);
761 hres = IActiveScriptParse64_InitNew(parser);
762 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
764 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
765 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
768 SET_EXPECT(GetItemInfo_testVal);
769 hres = IActiveScript_AddNamedItem(engine, test_valW,
770 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|
771 (global_members ? SCRIPTITEM_GLOBALMEMBERS : 0));
772 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
774 CHECK_CALLED(GetItemInfo_testVal);
776 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
777 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
780 SET_EXPECT(GetItemInfo_testVal);
781 hres = IActiveScriptParse64_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
782 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
784 CHECK_CALLED(GetItemInfo_testVal);
786 hres = IActiveScriptParse64_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
787 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
789 IActiveScript_Release(engine);
790 IUnknown_Release(parser);
793 static void run_tests(void)
797 strict_dispid_check = TRUE;
800 parse_script_a("/* empty */ ;");
802 SET_EXPECT(global_propget_d);
803 SET_EXPECT(global_propget_i);
804 parse_script_a("testPropGet;");
805 CHECK_CALLED(global_propget_d);
806 CHECK_CALLED(global_propget_i);
808 SET_EXPECT(global_propput_d);
809 SET_EXPECT(global_propput_i);
810 parse_script_a("testPropPut = 1;");
811 CHECK_CALLED(global_propput_d);
812 CHECK_CALLED(global_propput_i);
814 SET_EXPECT(global_success_d);
815 SET_EXPECT(global_success_i);
816 parse_script_a("reportSuccess();");
817 CHECK_CALLED(global_success_d);
818 CHECK_CALLED(global_success_i);
820 SET_EXPECT(testobj_delete);
821 parse_script_a("delete testObj.deleteTest;");
822 CHECK_CALLED(testobj_delete);
824 parse_script_a("ok(typeof(test) === 'object', \"typeof(test) != 'object'\");");
826 run_from_res("lang.js");
827 run_from_res("api.js");
828 run_from_res("regexp.js");
830 test_isvisible(FALSE);
831 test_isvisible(TRUE);
833 hres = parse_htmlscript_a("<!--");
834 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
835 hres = parse_htmlscript_a("-->");
836 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
837 hres = parse_htmlscript_a("<!--\nvar a=1;\n-->\n");
838 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
839 hres = parse_htmlscript_a("<!--\n<!-- ignore this\n-->\n");
840 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
841 hres = parse_htmlscript_a("var a=1;\nif(a-->0) a=5;\n");
842 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
843 hres = parse_htmlscript_a("var a=1;\nif(a\n-->0) a=5;\n");
844 ok(hres != S_OK, "ParseScriptText have not failed\n");
852 argc = winetest_get_mainargs(&argv);
857 run_from_file(argv[2]);