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
= IActiveScriptParse_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
= IActiveScriptParse_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 IActiveScriptParse_Release(parser
);
603 static void parse_script_a(const char *src
)
605 BSTR tmp
= a2bstr(src
);
610 static BSTR
get_script_from_file(const char *filename
)
614 const char *file_map
;
617 file
= CreateFileA(filename
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_READONLY
, NULL
);
618 if(file
== INVALID_HANDLE_VALUE
) {
619 trace("Could not open file: %u\n", GetLastError());
623 size
= GetFileSize(file
, NULL
);
625 map
= CreateFileMapping(file
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
627 if(map
== INVALID_HANDLE_VALUE
) {
628 trace("Could not create file mapping: %u\n", GetLastError());
632 file_map
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
635 trace("MapViewOfFile failed: %u\n", GetLastError());
639 len
= MultiByteToWideChar(CP_ACP
, 0, file_map
, size
, NULL
, 0);
640 ret
= SysAllocStringLen(NULL
, len
);
641 MultiByteToWideChar(CP_ACP
, 0, file_map
, size
, ret
, len
);
643 UnmapViewOfFile(file_map
);
648 static void run_from_file(const char *filename
)
650 BSTR script_str
= get_script_from_file(filename
);
652 strict_dispid_check
= FALSE
;
655 parse_script(script_str
);
657 SysFreeString(script_str
);
660 static void run_from_res(const char *name
)
667 strict_dispid_check
= FALSE
;
670 src
= FindResourceA(NULL
, name
, (LPCSTR
)40);
671 ok(src
!= NULL
, "Could not find resource %s\n", name
);
673 size
= SizeofResource(NULL
, src
);
674 data
= LoadResource(NULL
, src
);
676 len
= MultiByteToWideChar(CP_ACP
, 0, data
, size
, NULL
, 0);
677 str
= SysAllocStringLen(NULL
, len
);
678 len
= MultiByteToWideChar(CP_ACP
, 0, data
, size
, str
, len
);
680 SET_EXPECT(global_success_d
);
681 SET_EXPECT(global_success_i
);
683 CHECK_CALLED(global_success_d
);
684 CHECK_CALLED(global_success_i
);
689 static void test_isvisible(BOOL global_members
)
691 IActiveScriptParse
*parser
;
692 IActiveScript
*engine
;
695 static const WCHAR script_textW
[] =
696 {'v','a','r',' ','v',' ','=',' ','t','e','s','t','V','a','l',';',0};
698 engine
= create_script();
702 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptParse
, (void**)&parser
);
703 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
706 IActiveScript_Release(engine
);
710 hres
= IActiveScriptParse_InitNew(parser
);
711 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
713 hres
= IActiveScript_SetScriptSite(engine
, &ActiveScriptSite
);
714 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
717 SET_EXPECT(GetItemInfo_testVal
);
718 hres
= IActiveScript_AddNamedItem(engine
, test_valW
,
719 SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|
720 (global_members
? SCRIPTITEM_GLOBALMEMBERS
: 0));
721 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
723 CHECK_CALLED(GetItemInfo_testVal
);
725 hres
= IActiveScript_SetScriptState(engine
, SCRIPTSTATE_STARTED
);
726 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
729 SET_EXPECT(GetItemInfo_testVal
);
730 hres
= IActiveScriptParse_ParseScriptText(parser
, script_textW
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
731 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
733 CHECK_CALLED(GetItemInfo_testVal
);
735 hres
= IActiveScriptParse_ParseScriptText(parser
, script_textW
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
736 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
738 IActiveScript_Release(engine
);
739 IActiveScriptParse_Release(parser
);
742 static void run_tests(void)
744 strict_dispid_check
= TRUE
;
747 parse_script_a("/* empty */ ;");
749 SET_EXPECT(global_propget_d
);
750 SET_EXPECT(global_propget_i
);
751 parse_script_a("testPropGet;");
752 CHECK_CALLED(global_propget_d
);
753 CHECK_CALLED(global_propget_i
);
755 SET_EXPECT(global_propput_d
);
756 SET_EXPECT(global_propput_i
);
757 parse_script_a("testPropPut = 1;");
758 CHECK_CALLED(global_propput_d
);
759 CHECK_CALLED(global_propput_i
);
761 SET_EXPECT(global_success_d
);
762 SET_EXPECT(global_success_i
);
763 parse_script_a("reportSuccess();");
764 CHECK_CALLED(global_success_d
);
765 CHECK_CALLED(global_success_i
);
767 SET_EXPECT(testobj_delete
);
768 parse_script_a("delete testObj.deleteTest;");
769 CHECK_CALLED(testobj_delete
);
771 parse_script_a("ok(typeof(test) === 'object', \"typeof(test) != 'object'\");");
773 run_from_res("lang.js");
774 run_from_res("api.js");
775 run_from_res("regexp.js");
777 test_isvisible(FALSE
);
778 test_isvisible(TRUE
);
786 argc
= winetest_get_mainargs(&argv
);
791 run_from_file(argv
[2]);