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(global_notexists_d);
67 DEFINE_EXPECT(testobj_delete);
68 DEFINE_EXPECT(GetItemInfo_testVal);
70 #define DISPID_GLOBAL_TESTPROPGET 0x1000
71 #define DISPID_GLOBAL_TESTPROPPUT 0x1001
72 #define DISPID_GLOBAL_REPORTSUCCESS 0x1002
73 #define DISPID_GLOBAL_TRACE 0x1003
74 #define DISPID_GLOBAL_OK 0x1004
75 #define DISPID_GLOBAL_GETVT 0x1005
76 #define DISPID_GLOBAL_TESTOBJ 0x1006
77 #define DISPID_GLOBAL_NULL_BSTR 0x1007
79 static const WCHAR testW[] = {'t','e','s','t',0};
80 static const CHAR testA[] = "test";
81 static const WCHAR test_valW[] = {'t','e','s','t','V','a','l',0};
82 static const CHAR test_valA[] = "testVal";
84 static BOOL strict_dispid_check;
85 static const char *test_name = "(null)";
87 static const char *debugstr_w(LPCWSTR str)
89 static char buf[1024];
94 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
98 static BSTR a2bstr(const char *str)
103 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
104 ret = SysAllocStringLen(NULL, len-1);
105 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
110 static int strcmp_wa(LPCWSTR strw, const char *stra)
113 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
114 return lstrcmpA(buf, stra);
117 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
121 if(IsEqualGUID(riid, &IID_IUnknown)
122 || IsEqualGUID(riid, &IID_IDispatch)
123 || IsEqualGUID(riid, &IID_IDispatchEx))
126 return E_NOINTERFACE;
131 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
136 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
141 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
143 ok(0, "unexpected call\n");
147 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
148 LCID lcid, ITypeInfo **ppTInfo)
150 ok(0, "unexpected call\n");
154 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
155 LPOLESTR *rgszNames, UINT cNames,
156 LCID lcid, DISPID *rgDispId)
158 ok(0, "unexpected call\n");
162 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
163 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
164 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
166 ok(0, "unexpected call\n");
170 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
172 ok(0, "unexpected call %s %x\n", debugstr_w(bstrName), grfdex);
176 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
178 ok(0, "unexpected call\n");
182 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
184 ok(0, "unexpected call\n");
188 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
190 ok(0, "unexpected call\n");
194 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
196 ok(0, "unexpected call\n");
200 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
202 ok(0, "unexpected call\n");
206 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
208 ok(0, "unexpected call\n");
212 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
213 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
215 ok(0, "unexpected call\n");
219 static HRESULT WINAPI testObj_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
221 CHECK_EXPECT(testobj_delete);
223 ok(!strcmp_wa(bstrName, "deleteTest"), "unexpected name %s\n", debugstr_w(bstrName));
224 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
228 static IDispatchExVtbl testObjVtbl = {
229 DispatchEx_QueryInterface,
232 DispatchEx_GetTypeInfoCount,
233 DispatchEx_GetTypeInfo,
234 DispatchEx_GetIDsOfNames,
236 DispatchEx_GetDispID,
238 testObj_DeleteMemberByName,
239 DispatchEx_DeleteMemberByDispID,
240 DispatchEx_GetMemberProperties,
241 DispatchEx_GetMemberName,
242 DispatchEx_GetNextDispID,
243 DispatchEx_GetNameSpaceParent
246 static IDispatchEx testObj = { &testObjVtbl };
248 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
250 if(!strcmp_wa(bstrName, "ok")) {
251 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
252 *pid = DISPID_GLOBAL_OK;
255 if(!strcmp_wa(bstrName, "trace")) {
256 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
257 *pid = DISPID_GLOBAL_TRACE;
260 if(!strcmp_wa(bstrName, "reportSuccess")) {
261 CHECK_EXPECT(global_success_d);
262 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
263 *pid = DISPID_GLOBAL_REPORTSUCCESS;
266 if(!strcmp_wa(bstrName, "testPropGet")) {
267 CHECK_EXPECT(global_propget_d);
268 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
269 *pid = DISPID_GLOBAL_TESTPROPGET;
272 if(!strcmp_wa(bstrName, "testPropPut")) {
273 CHECK_EXPECT(global_propput_d);
274 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
275 *pid = DISPID_GLOBAL_TESTPROPPUT;
278 if(!strcmp_wa(bstrName, "getVT")) {
279 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
280 *pid = DISPID_GLOBAL_GETVT;
283 if(!strcmp_wa(bstrName, "testObj")) {
284 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
285 *pid = DISPID_GLOBAL_TESTOBJ;
288 if(!strcmp_wa(bstrName, "createNullBSTR")) {
289 *pid = DISPID_GLOBAL_NULL_BSTR;
292 if(!strcmp_wa(bstrName, "notExists")) {
293 CHECK_EXPECT(global_notexists_d);
294 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
295 return DISP_E_UNKNOWNNAME;
298 if(strict_dispid_check)
299 ok(0, "unexpected call %s\n", debugstr_w(bstrName));
300 return DISP_E_UNKNOWNNAME;
303 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
304 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
307 case DISPID_GLOBAL_OK:
308 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
309 ok(pdp != NULL, "pdp == NULL\n");
310 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
311 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
312 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
313 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
314 if(wFlags & INVOKE_PROPERTYGET)
315 ok(pvarRes != NULL, "pvarRes == NULL\n");
317 ok(!pvarRes, "pvarRes != NULL\n");
318 ok(pei != NULL, "pei == NULL\n");
320 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
321 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
322 ok(V_BOOL(pdp->rgvarg+1), "%s: %s\n", test_name, debugstr_w(V_BSTR(pdp->rgvarg)));
326 case DISPID_GLOBAL_TRACE:
327 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
328 ok(pdp != NULL, "pdp == NULL\n");
329 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
330 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
331 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
332 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
333 ok(!pvarRes, "pvarRes != NULL\n");
334 ok(pei != NULL, "pei == NULL\n");
336 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
337 if(V_VT(pdp->rgvarg) == VT_BSTR)
338 trace("%s: %s\n", test_name, debugstr_w(V_BSTR(pdp->rgvarg)));
342 case DISPID_GLOBAL_REPORTSUCCESS:
343 CHECK_EXPECT(global_success_i);
345 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
346 ok(pdp != NULL, "pdp == NULL\n");
347 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
348 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
349 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
350 ok(!pvarRes, "pvarRes != NULL\n");
351 ok(pei != NULL, "pei == NULL\n");
355 case DISPID_GLOBAL_TESTPROPGET:
356 CHECK_EXPECT(global_propget_i);
358 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
359 ok(pdp != NULL, "pdp == NULL\n");
360 ok(!pdp->rgvarg, "rgvarg != NULL\n");
361 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
362 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
363 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
364 ok(pvarRes != NULL, "pvarRes == NULL\n");
365 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
366 ok(pei != NULL, "pei == NULL\n");
368 V_VT(pvarRes) = VT_I4;
373 case DISPID_GLOBAL_TESTPROPPUT:
374 CHECK_EXPECT(global_propput_i);
376 ok(wFlags == INVOKE_PROPERTYPUT, "wFlags = %x\n", wFlags);
377 ok(pdp != NULL, "pdp == NULL\n");
378 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
379 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
380 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
381 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
382 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
383 ok(!pvarRes, "pvarRes != NULL\n");
385 ok(V_VT(pdp->rgvarg) == VT_I4, "V_VT(pdp->rgvarg)=%d\n", V_VT(pdp->rgvarg));
386 ok(V_I4(pdp->rgvarg) == 1, "V_I4(pdp->rgvarg)=%d\n", V_I4(pdp->rgvarg));
389 case DISPID_GLOBAL_GETVT:
390 ok(pdp != NULL, "pdp == NULL\n");
391 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
392 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
393 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
394 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
395 ok(pvarRes != NULL, "pvarRes == NULL\n");
396 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
397 ok(pei != NULL, "pei == NULL\n");
399 V_VT(pvarRes) = VT_BSTR;
400 switch(V_VT(pdp->rgvarg)) {
402 V_BSTR(pvarRes) = a2bstr("VT_EMPTY");
405 V_BSTR(pvarRes) = a2bstr("VT_NULL");
408 V_BSTR(pvarRes) = a2bstr("VT_I4");
411 V_BSTR(pvarRes) = a2bstr("VT_R8");
414 V_BSTR(pvarRes) = a2bstr("VT_BSTR");
417 V_BSTR(pvarRes) = a2bstr("VT_DISPATCH");
420 V_BSTR(pvarRes) = a2bstr("VT_BOOL");
423 ok(0, "unknown vt %d\n", V_VT(pdp->rgvarg));
429 case DISPID_GLOBAL_TESTOBJ:
430 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
431 ok(pdp != NULL, "pdp == NULL\n");
432 ok(!pdp->rgvarg, "rgvarg != NULL\n");
433 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
434 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
435 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
436 ok(pvarRes != NULL, "pvarRes == NULL\n");
437 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
438 ok(pei != NULL, "pei == NULL\n");
440 V_VT(pvarRes) = VT_DISPATCH;
441 V_DISPATCH(pvarRes) = (IDispatch*)&testObj;
444 case DISPID_GLOBAL_NULL_BSTR:
446 V_VT(pvarRes) = VT_BSTR;
447 V_BSTR(pvarRes) = NULL;
452 ok(0, "unexpected call %x\n", id);
453 return DISP_E_MEMBERNOTFOUND;
456 static IDispatchExVtbl GlobalVtbl = {
457 DispatchEx_QueryInterface,
460 DispatchEx_GetTypeInfoCount,
461 DispatchEx_GetTypeInfo,
462 DispatchEx_GetIDsOfNames,
466 DispatchEx_DeleteMemberByName,
467 DispatchEx_DeleteMemberByDispID,
468 DispatchEx_GetMemberProperties,
469 DispatchEx_GetMemberName,
470 DispatchEx_GetNextDispID,
471 DispatchEx_GetNameSpaceParent
474 static IDispatchEx Global = { &GlobalVtbl };
476 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
480 if(IsEqualGUID(&IID_IUnknown, riid))
482 else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
485 return E_NOINTERFACE;
487 IUnknown_AddRef((IUnknown*)*ppv);
491 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
496 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
501 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
503 *plcid = GetUserDefaultLCID();
507 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
508 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
510 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
511 ok(!ppti, "ppti != NULL\n");
513 if(!strcmp_wa(pstrName, test_valA))
514 CHECK_EXPECT(GetItemInfo_testVal);
515 else if(strcmp_wa(pstrName, testA))
516 ok(0, "unexpected pstrName %s\n", debugstr_w(pstrName));
518 *ppiunkItem = (IUnknown*)&Global;
522 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
527 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
528 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
533 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
538 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
543 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
548 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
553 #undef ACTSCPSITE_THIS
555 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
556 ActiveScriptSite_QueryInterface,
557 ActiveScriptSite_AddRef,
558 ActiveScriptSite_Release,
559 ActiveScriptSite_GetLCID,
560 ActiveScriptSite_GetItemInfo,
561 ActiveScriptSite_GetDocVersionString,
562 ActiveScriptSite_OnScriptTerminate,
563 ActiveScriptSite_OnStateChange,
564 ActiveScriptSite_OnScriptError,
565 ActiveScriptSite_OnEnterScript,
566 ActiveScriptSite_OnLeaveScript
569 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
571 static IActiveScript *create_script(void)
573 IActiveScript *script;
576 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
577 &IID_IActiveScript, (void**)&script);
578 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
583 static void parse_script(BSTR script_str)
585 IActiveScriptParse *parser;
586 IActiveScript *engine;
589 engine = create_script();
593 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
594 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
597 IActiveScript_Release(engine);
601 hres = IActiveScriptParse64_InitNew(parser);
602 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
604 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
605 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
607 hres = IActiveScript_AddNamedItem(engine, testW,
608 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
609 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
611 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
612 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
614 hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
615 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
617 IActiveScript_Release(engine);
618 IUnknown_Release(parser);
621 static HRESULT parse_htmlscript(BSTR script_str)
623 IActiveScriptParse *parser;
624 IActiveScript *engine;
626 BSTR tmp = a2bstr("</SCRIPT>");
628 engine = create_script();
632 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
633 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
636 IActiveScript_Release(engine);
640 hres = IActiveScriptParse64_InitNew(parser);
641 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
643 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
644 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
646 hres = IActiveScript_AddNamedItem(engine, testW,
647 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
648 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
650 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
651 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
653 hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, tmp, 0, 0, 0, NULL, NULL);
655 IActiveScript_Release(engine);
656 IUnknown_Release(parser);
662 static void parse_script_a(const char *src)
664 BSTR tmp = a2bstr(src);
669 static HRESULT parse_htmlscript_a(const char *src)
672 BSTR tmp = a2bstr(src);
673 hres = parse_htmlscript(tmp);
679 static BSTR get_script_from_file(const char *filename)
683 const char *file_map;
686 file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
687 if(file == INVALID_HANDLE_VALUE) {
688 trace("Could not open file: %u\n", GetLastError());
692 size = GetFileSize(file, NULL);
694 map = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
696 if(map == INVALID_HANDLE_VALUE) {
697 trace("Could not create file mapping: %u\n", GetLastError());
701 file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
704 trace("MapViewOfFile failed: %u\n", GetLastError());
708 len = MultiByteToWideChar(CP_ACP, 0, file_map, size, NULL, 0);
709 ret = SysAllocStringLen(NULL, len);
710 MultiByteToWideChar(CP_ACP, 0, file_map, size, ret, len);
712 UnmapViewOfFile(file_map);
717 static void run_from_file(const char *filename)
719 BSTR script_str = get_script_from_file(filename);
721 strict_dispid_check = FALSE;
724 parse_script(script_str);
726 SysFreeString(script_str);
729 static void run_from_res(const char *name)
736 strict_dispid_check = FALSE;
739 src = FindResourceA(NULL, name, (LPCSTR)40);
740 ok(src != NULL, "Could not find resource %s\n", name);
742 size = SizeofResource(NULL, src);
743 data = LoadResource(NULL, src);
745 len = MultiByteToWideChar(CP_ACP, 0, data, size, NULL, 0);
746 str = SysAllocStringLen(NULL, len);
747 len = MultiByteToWideChar(CP_ACP, 0, data, size, str, len);
749 SET_EXPECT(global_success_d);
750 SET_EXPECT(global_success_i);
752 CHECK_CALLED(global_success_d);
753 CHECK_CALLED(global_success_i);
758 static void test_isvisible(BOOL global_members)
760 IActiveScriptParse *parser;
761 IActiveScript *engine;
764 static const WCHAR script_textW[] =
765 {'v','a','r',' ','v',' ','=',' ','t','e','s','t','V','a','l',';',0};
767 engine = create_script();
771 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
772 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
775 IActiveScript_Release(engine);
779 hres = IActiveScriptParse64_InitNew(parser);
780 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
782 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
783 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
786 SET_EXPECT(GetItemInfo_testVal);
787 hres = IActiveScript_AddNamedItem(engine, test_valW,
788 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|
789 (global_members ? SCRIPTITEM_GLOBALMEMBERS : 0));
790 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
792 CHECK_CALLED(GetItemInfo_testVal);
794 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
795 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
798 SET_EXPECT(GetItemInfo_testVal);
799 hres = IActiveScriptParse64_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
800 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
802 CHECK_CALLED(GetItemInfo_testVal);
804 hres = IActiveScriptParse64_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
805 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
807 IActiveScript_Release(engine);
808 IUnknown_Release(parser);
811 static void run_tests(void)
815 strict_dispid_check = TRUE;
818 parse_script_a("/* empty */ ;");
820 SET_EXPECT(global_propget_d);
821 SET_EXPECT(global_propget_i);
822 parse_script_a("testPropGet;");
823 CHECK_CALLED(global_propget_d);
824 CHECK_CALLED(global_propget_i);
826 SET_EXPECT(global_propput_d);
827 SET_EXPECT(global_propput_i);
828 parse_script_a("testPropPut = 1;");
829 CHECK_CALLED(global_propput_d);
830 CHECK_CALLED(global_propput_i);
832 SET_EXPECT(global_success_d);
833 SET_EXPECT(global_success_i);
834 parse_script_a("reportSuccess();");
835 CHECK_CALLED(global_success_d);
836 CHECK_CALLED(global_success_i);
838 SET_EXPECT(testobj_delete);
839 parse_script_a("delete testObj.deleteTest;");
840 CHECK_CALLED(testobj_delete);
842 parse_script_a("ok(typeof(test) === 'object', \"typeof(test) != 'object'\");");
844 parse_script_a("function reportSuccess() {}; reportSuccess();");
846 SET_EXPECT(global_propget_d);
847 parse_script_a("var testPropGet");
848 CHECK_CALLED(global_propget_d);
850 SET_EXPECT(global_notexists_d);
851 parse_script_a("var notExists; notExists = 1;");
852 CHECK_CALLED(global_notexists_d);
854 parse_script_a("function f() { var testPropGet; }");
856 run_from_res("lang.js");
857 run_from_res("api.js");
858 run_from_res("regexp.js");
860 test_isvisible(FALSE);
861 test_isvisible(TRUE);
863 hres = parse_htmlscript_a("<!--");
864 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
865 hres = parse_htmlscript_a("-->");
866 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
867 hres = parse_htmlscript_a("<!--\nvar a=1;\n-->\n");
868 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
869 hres = parse_htmlscript_a("<!--\n<!-- ignore this\n-->\n");
870 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
871 hres = parse_htmlscript_a("var a=1;\nif(a-->0) a=5;\n");
872 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
873 hres = parse_htmlscript_a("var a=1;\nif(a\n-->0) a=5;\n");
874 ok(hres != S_OK, "ParseScriptText have not failed\n");
882 argc = winetest_get_mainargs(&argv);
887 run_from_file(argv[2]);