ReactOS  0.4.15-dev-313-g8fde48b
vbscript.c
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #define COBJMACROS
20 #define CONST_VTABLE
21 
22 #include <initguid.h>
23 #include <ole2.h>
24 #include <activscp.h>
25 #include <objsafe.h>
26 #include <dispex.h>
27 
28 #include "vbsregexp55.h"
29 
30 #include "wine/test.h"
31 
32 #ifdef _WIN64
33 
34 #define IActiveScriptParse_QueryInterface IActiveScriptParse64_QueryInterface
35 #define IActiveScriptParse_Release IActiveScriptParse64_Release
36 #define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
37 #define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
38 #define IActiveScriptParseProcedure2_Release \
39  IActiveScriptParseProcedure2_64_Release
40 
41 #else
42 
43 #define IActiveScriptParse_QueryInterface IActiveScriptParse32_QueryInterface
44 #define IActiveScriptParse_Release IActiveScriptParse32_Release
45 #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
46 #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
47 #define IActiveScriptParseProcedure2_Release \
48  IActiveScriptParseProcedure2_32_Release
49 
50 #endif
51 
52 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
53 
54 #define DEFINE_EXPECT(func) \
55  static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
56 
57 #define SET_EXPECT(func) \
58  expect_ ## func = TRUE
59 
60 #define CHECK_EXPECT2(func) \
61  do { \
62  ok(expect_ ##func, "unexpected call " #func "\n"); \
63  called_ ## func = TRUE; \
64  }while(0)
65 
66 #define CHECK_EXPECT(func) \
67  do { \
68  CHECK_EXPECT2(func); \
69  expect_ ## func = FALSE; \
70  }while(0)
71 
72 #define CHECK_CALLED(func) \
73  do { \
74  ok(called_ ## func, "expected " #func "\n"); \
75  expect_ ## func = called_ ## func = FALSE; \
76  }while(0)
77 
78 DEFINE_EXPECT(GetLCID);
79 DEFINE_EXPECT(OnStateChange_UNINITIALIZED);
80 DEFINE_EXPECT(OnStateChange_STARTED);
81 DEFINE_EXPECT(OnStateChange_CONNECTED);
82 DEFINE_EXPECT(OnStateChange_DISCONNECTED);
83 DEFINE_EXPECT(OnStateChange_CLOSED);
84 DEFINE_EXPECT(OnStateChange_INITIALIZED);
85 DEFINE_EXPECT(OnEnterScript);
86 DEFINE_EXPECT(OnLeaveScript);
87 DEFINE_EXPECT(GetItemInfo_global);
88 DEFINE_EXPECT(GetItemInfo_visible);
89 DEFINE_EXPECT(testCall);
90 
91 DEFINE_GUID(CLSID_VBScript, 0xb54f3741, 0x5b07, 0x11cf, 0xa4,0xb0, 0x00,0xaa,0x00,0x4a,0x55,0xe8);
92 DEFINE_GUID(CLSID_VBScriptRegExp, 0x3f4daca4, 0x160d, 0x11d2, 0xa8,0xe9, 0x00,0x10,0x4b,0x36,0x5c,0x9f);
93 
94 static BSTR a2bstr(const char *str)
95 {
96  BSTR ret;
97  int len;
98 
99  len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
101  MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
102 
103  return ret;
104 }
105 
106 #define test_state(s,ss) _test_state(__LINE__,s,ss)
107 static void _test_state(unsigned line, IActiveScript *script, SCRIPTSTATE exstate)
108 {
109  SCRIPTSTATE state = -1;
110  HRESULT hres;
111 
112  hres = IActiveScript_GetScriptState(script, &state);
113  ok_(__FILE__,line) (hres == S_OK, "GetScriptState failed: %08x\n", hres);
114  ok_(__FILE__,line) (state == exstate, "state=%d, expected %d\n", state, exstate);
115 }
116 
118 {
120  *ppv = iface;
121  IDispatch_AddRef(iface);
122  return S_OK;
123  }
124 
125  *ppv = NULL;
126  return E_NOINTERFACE;
127 }
128 
130 
132 {
133  return ++global_named_item_ref;
134 }
135 
137 {
138  return --global_named_item_ref;
139 }
140 
142 {
143  return ++visible_named_item_ref;
144 }
145 
147 {
148  return --visible_named_item_ref;
149 }
150 
152 {
153  ok(0, "unexpected call\n");
154  return E_NOTIMPL;
155 }
156 
157 static HRESULT WINAPI Dispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
158 {
159  return DISP_E_BADINDEX;
160 }
161 
163  LCID lcid, DISPID *ids)
164 {
165  ok(name_cnt == 1, "name_cnt = %u\n", name_cnt);
166  ok(!wcscmp(names[0], L"testCall"), "names[0] = %s\n", wine_dbgstr_w(names[0]));
167  *ids = 1;
168  return S_OK;
169 }
170 
172  DISPPARAMS *dp, VARIANT *res, EXCEPINFO *ei, UINT *err)
173 {
174  CHECK_EXPECT(testCall);
175  ok(id == 1, "id = %u\n", id);
176  ok(flags == DISPATCH_METHOD, "flags = %x\n", flags);
177  ok(!dp->cArgs, "cArgs = %u\n", dp->cArgs);
178  ok(!res, "res = %p\n", res);
179  return S_OK;
180 }
181 
182 static const IDispatchVtbl global_named_item_vtbl = {
190 };
191 
193 
194 static const IDispatchVtbl visible_named_item_vtbl = {
202 };
203 
205 
207 {
208  *ppv = NULL;
209 
211  *ppv = iface;
212  else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
213  *ppv = iface;
214  else
215  return E_NOINTERFACE;
216 
217  IUnknown_AddRef((IUnknown*)*ppv);
218  return S_OK;
219 }
220 
222 {
223  return 2;
224 }
225 
227 {
228  return 1;
229 }
230 
232 {
233  CHECK_EXPECT(GetLCID);
234  return E_NOTIMPL;
235 }
236 
238  DWORD return_mask, IUnknown **item_unk, ITypeInfo **item_ti)
239 {
240  ok(return_mask == SCRIPTINFO_IUNKNOWN, "return_mask = %x\n", return_mask);
241  if(!wcscmp(name, L"globalItem")) {
242  CHECK_EXPECT(GetItemInfo_global);
243  IDispatch_AddRef(&global_named_item);
244  *item_unk = (IUnknown*)&global_named_item;
245  return S_OK;
246  }
247  if(!wcscmp(name, L"visibleItem")) {
248  CHECK_EXPECT(GetItemInfo_visible);
249  IDispatch_AddRef(&visible_named_item);
250  *item_unk = (IUnknown*)&visible_named_item;
251  return S_OK;
252  }
253  ok(0, "unexpected call %s\n", wine_dbgstr_w(name));
254  return E_NOTIMPL;
255 }
256 
258 {
259  ok(0, "unexpected call\n");
260  return E_NOTIMPL;
261 }
262 
264  const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
265 {
266  ok(0, "unexpected call\n");
267  return E_NOTIMPL;
268 }
269 
271 {
272  switch(ssScriptState) {
274  CHECK_EXPECT(OnStateChange_UNINITIALIZED);
275  return S_OK;
276  case SCRIPTSTATE_STARTED:
277  CHECK_EXPECT(OnStateChange_STARTED);
278  return S_OK;
280  CHECK_EXPECT(OnStateChange_CONNECTED);
281  return S_OK;
283  CHECK_EXPECT(OnStateChange_DISCONNECTED);
284  return S_OK;
285  case SCRIPTSTATE_CLOSED:
286  CHECK_EXPECT(OnStateChange_CLOSED);
287  return S_OK;
289  CHECK_EXPECT(OnStateChange_INITIALIZED);
290  return S_OK;
291  default:
292  ok(0, "unexpected call %d\n", ssScriptState);
293  }
294 
295  return E_NOTIMPL;
296 }
297 
299 {
300  ok(0, "unexpected call\n");
301  return E_NOTIMPL;
302 }
303 
305 {
306  CHECK_EXPECT(OnEnterScript);
307  return S_OK;
308 }
309 
311 {
312  CHECK_EXPECT(OnLeaveScript);
313  return S_OK;
314 }
315 
316 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
328 };
329 
331 
333 {
334  IObjectSafety *safety;
335  DWORD supported, enabled;
336  HRESULT hres;
337 
338  hres = IActiveScript_QueryInterface(script, &IID_IObjectSafety, (void**)&safety);
339  ok(hres == S_OK, "Could not get IObjectSafety: %08x\n", hres);
340  if(FAILED(hres))
341  return;
342 
343  hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, &supported, NULL);
344  ok(hres == E_POINTER, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres);
345  hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, NULL, &enabled);
346  ok(hres == E_POINTER, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres);
347 
348  supported = enabled = 0xdeadbeef;
349  hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, &supported, &enabled);
350  ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
351  ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
352  "supported=%x\n", supported);
353  ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
354 
355  supported = enabled = 0xdeadbeef;
356  hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScript, &supported, &enabled);
357  ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
358  ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
359  "supported=%x\n", supported);
360  ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
361 
362  supported = enabled = 0xdeadbeef;
363  hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
364  ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
365  ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
366  "supported=%x\n", supported);
367  ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
368 
369  hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
370  INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER
371  |INTERFACESAFE_FOR_UNTRUSTED_CALLER,
372  INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
373  ok(hres == E_FAIL, "SetInterfaceSafetyOptions failed: %08x, expected E_FAIL\n", hres);
374 
375  hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
376  INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER,
377  INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
378  ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
379 
380  supported = enabled = 0xdeadbeef;
381  hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
382  ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
383  ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
384  "supported=%x\n", supported);
385  ok(enabled == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
386  "enabled=%x\n", enabled);
387 
388  hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, INTERFACESAFE_FOR_UNTRUSTED_DATA, 0);
389  ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
390 
391  supported = enabled = 0xdeadbeef;
392  hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
393  ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
394  ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
395  "supported=%x\n", supported);
396  ok(enabled == (INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER), "enabled=%x\n", enabled);
397 
398  hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
399  INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER, 0);
400  ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
401 
402  supported = enabled = 0xdeadbeef;
403  hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
404  ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
405  ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
406  "supported=%x\n", supported);
407  ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
408 
409  hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
410  INTERFACE_USES_DISPEX, 0);
411  ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
412 
413  supported = enabled = 0xdeadbeef;
414  hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
415  ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
416  ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
417  "supported=%x\n", supported);
418  ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
419 
420  IObjectSafety_Release(safety);
421 }
422 
424 {
425  IDispatchEx *dispex;
426  IDispatch *disp;
427  HRESULT hres;
428 
429  disp = (void*)0xdeadbeef;
430  hres = IActiveScript_GetScriptDispatch(script, NULL, &disp);
431  ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
432  if(FAILED(hres))
433  return NULL;
434 
435  hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
436  IDispatch_Release(disp);
437  ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
438  return dispex;
439 }
440 
441 static void parse_script(IActiveScriptParse *parse, const char *src)
442 {
443  BSTR str;
444  HRESULT hres;
445 
446  SET_EXPECT(OnEnterScript);
447  SET_EXPECT(OnLeaveScript);
448 
449  str = a2bstr(src);
452  ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
453 
454  CHECK_CALLED(OnEnterScript);
455  CHECK_CALLED(OnLeaveScript);
456 }
457 
458 #define get_disp_id(a,b,c,d) _get_disp_id(__LINE__,a,b,c,d)
459 static void _get_disp_id(unsigned line, IDispatchEx *dispex, const char *name, HRESULT exhres, DISPID *id)
460 {
461  DISPID id2;
462  BSTR str;
463  HRESULT hres;
464 
465  str = a2bstr(name);
466  hres = IDispatchEx_GetDispID(dispex, str, 0, id);
467  ok_(__FILE__,line)(hres == exhres, "GetDispID(%s) returned %08x, expected %08x\n", name, hres, exhres);
468 
469  hres = IDispatchEx_GetIDsOfNames(dispex, &IID_NULL, &str, 1, 0, &id2);
471  ok_(__FILE__,line)(hres == exhres, "GetIDsOfNames(%s) returned %08x, expected %08x\n", name, hres, exhres);
472  ok_(__FILE__,line)(*id == id2, "GetIDsOfNames(%s) id != id2\n", name);
473 }
474 
476 {
477  IDispatch *disp;
478  HRESULT hres;
479 
480  disp = (void*)0xdeadbeef;
481  hres = IActiveScript_GetScriptDispatch(script, NULL, &disp);
482  ok(hres == E_UNEXPECTED, "hres = %08x, expected E_UNEXPECTED\n", hres);
483  ok(!disp, "disp != NULL\n");
484 }
485 
487 {
489  HRESULT hres;
490 
491  hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
492  &IID_IActiveScript, (void**)&ret);
493  ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
494 
495  return ret;
496 }
497 
498 static void test_scriptdisp(void)
499 {
500  IDispatchEx *script_disp, *script_disp2;
501  IActiveScriptParse *parser;
502  IActiveScript *vbscript;
503  DISPID id, id2;
504  DISPPARAMS dp;
505  EXCEPINFO ei;
506  VARIANT v;
507  ULONG ref;
508  HRESULT hres;
509 
510  vbscript = create_vbscript();
511 
512  hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParse, (void**)&parser);
513  ok(hres == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hres);
514 
516  test_safety(vbscript);
517 
518  SET_EXPECT(GetLCID);
519  hres = IActiveScript_SetScriptSite(vbscript, &ActiveScriptSite);
520  ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
521  CHECK_CALLED(GetLCID);
522 
523  script_disp2 = get_script_dispatch(vbscript);
524 
526 
527  SET_EXPECT(OnStateChange_INITIALIZED);
529  ok(hres == S_OK, "InitNew failed: %08x\n", hres);
530  CHECK_CALLED(OnStateChange_INITIALIZED);
531 
533 
534  SET_EXPECT(OnStateChange_CONNECTED);
535  hres = IActiveScript_SetScriptState(vbscript, SCRIPTSTATE_CONNECTED);
536  ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
537  CHECK_CALLED(OnStateChange_CONNECTED);
538 
540 
541  script_disp = get_script_dispatch(vbscript);
542  ok(script_disp == script_disp2, "script_disp != script_disp2\n");
543  IDispatchEx_Release(script_disp2);
544 
545  id = 100;
547  ok(id == -1, "id = %d, expected -1\n", id);
548 
549  get_disp_id(script_disp, "globalVariable", DISP_E_UNKNOWNNAME, &id);
550  parse_script(parser, "dim globalVariable\nglobalVariable = 3");
551  get_disp_id(script_disp, "globalVariable", S_OK, &id);
552 
553  memset(&dp, 0, sizeof(dp));
554  memset(&ei, 0, sizeof(ei));
555  V_VT(&v) = VT_EMPTY;
556  hres = IDispatchEx_InvokeEx(script_disp, id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
557  ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
558  ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
559  ok(V_I2(&v) == 3, "V_I2(v) = %d\n", V_I2(&v));
560 
561  get_disp_id(script_disp, "globalVariable2", DISP_E_UNKNOWNNAME, &id);
562  parse_script(parser, "globalVariable2 = 4");
563  get_disp_id(script_disp, "globalVariable2", S_OK, &id);
564 
565  get_disp_id(script_disp, "globalFunction", DISP_E_UNKNOWNNAME, &id);
566  parse_script(parser, "function globalFunction()\nglobalFunction=5\nend function");
567  get_disp_id(script_disp, "globalFunction", S_OK, &id);
568 
569  SET_EXPECT(OnEnterScript);
570  SET_EXPECT(OnLeaveScript);
571 
572  memset(&dp, 0, sizeof(dp));
573  memset(&ei, 0, sizeof(ei));
574  V_VT(&v) = VT_EMPTY;
575  hres = IDispatchEx_InvokeEx(script_disp, id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
576  ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
577  ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
578  ok(V_I2(&v) == 5, "V_I2(v) = %d\n", V_I2(&v));
579 
580  CHECK_CALLED(OnEnterScript);
581  CHECK_CALLED(OnLeaveScript);
582 
583  SET_EXPECT(OnEnterScript);
584  SET_EXPECT(OnLeaveScript);
585 
586  memset(&dp, 0, sizeof(dp));
587  memset(&ei, 0, sizeof(ei));
588  V_VT(&v) = VT_EMPTY;
589  hres = IDispatchEx_Invoke(script_disp, id, &IID_NULL, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
590  ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
591  ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
592  ok(V_I2(&v) == 5, "V_I2(v) = %d\n", V_I2(&v));
593 
594  CHECK_CALLED(OnEnterScript);
595  CHECK_CALLED(OnLeaveScript);
596 
597  get_disp_id(script_disp, "globalSub", DISP_E_UNKNOWNNAME, &id);
598  parse_script(parser, "sub globalSub()\nend sub");
599  get_disp_id(script_disp, "globalSub", S_OK, &id);
600  get_disp_id(script_disp, "globalSub", S_OK, &id2);
601  ok(id == id2, "id != id2\n");
602 
603  get_disp_id(script_disp, "constVariable", DISP_E_UNKNOWNNAME, &id);
604  parse_script(parser, "const constVariable = 6");
605  get_disp_id(script_disp, "ConstVariable", S_OK, &id);
606  get_disp_id(script_disp, "Constvariable", S_OK, &id2);
607  ok(id == id2, "id != id2\n");
608 
609  IDispatchEx_Release(script_disp);
610 
612 
613  SET_EXPECT(OnStateChange_DISCONNECTED);
614  SET_EXPECT(OnStateChange_INITIALIZED);
615  SET_EXPECT(OnStateChange_CLOSED);
616  hres = IActiveScript_Close(vbscript);
617  ok(hres == S_OK, "Close failed: %08x\n", hres);
618  CHECK_CALLED(OnStateChange_DISCONNECTED);
619  CHECK_CALLED(OnStateChange_INITIALIZED);
620  CHECK_CALLED(OnStateChange_CLOSED);
621 
622  ref = IActiveScript_Release(vbscript);
623  ok(!ref, "ref = %d\n", ref);
624 }
625 
626 static void test_vbscript(void)
627 {
628  IActiveScriptParseProcedure2 *parse_proc;
629  IActiveScriptParse *parser;
630  IActiveScript *vbscript;
631  ULONG ref;
632  HRESULT hres;
633 
634  vbscript = create_vbscript();
635 
636  hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParse, (void**)&parser);
637  ok(hres == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hres);
638 
640  test_safety(vbscript);
641  test_no_script_dispatch(vbscript);
642 
643  SET_EXPECT(GetLCID);
644  hres = IActiveScript_SetScriptSite(vbscript, &ActiveScriptSite);
645  ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
646  CHECK_CALLED(GetLCID);
647 
649 
650  SET_EXPECT(OnStateChange_INITIALIZED);
652  ok(hres == S_OK, "InitNew failed: %08x\n", hres);
653  CHECK_CALLED(OnStateChange_INITIALIZED);
654 
656 
658  ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres);
659 
660  SET_EXPECT(OnStateChange_CONNECTED);
661  hres = IActiveScript_SetScriptState(vbscript, SCRIPTSTATE_CONNECTED);
662  ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
663  CHECK_CALLED(OnStateChange_CONNECTED);
664 
666 
667  SET_EXPECT(OnStateChange_DISCONNECTED);
668  SET_EXPECT(OnStateChange_INITIALIZED);
669  SET_EXPECT(OnStateChange_CLOSED);
670  hres = IActiveScript_Close(vbscript);
671  ok(hres == S_OK, "Close failed: %08x\n", hres);
672  CHECK_CALLED(OnStateChange_DISCONNECTED);
673  CHECK_CALLED(OnStateChange_INITIALIZED);
674  CHECK_CALLED(OnStateChange_CLOSED);
675 
676  test_state(vbscript, SCRIPTSTATE_CLOSED);
677  test_no_script_dispatch(vbscript);
678 
680 
681  hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParseProcedure, (void**)&parse_proc);
682  ok(hres == E_NOINTERFACE, "Got IActiveScriptParseProcedure interface, expected E_NOTIMPL\n");
683 
684  hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc);
685  ok(hres == S_OK, "Could not get IActiveScriptParseProcedure2 interface\n");
687 
688  ref = IActiveScript_Release(vbscript);
689  ok(!ref, "ref = %d\n", ref);
690 }
691 
693 {
694  IActiveScriptParse *parse;
696  IDispatchEx *dispex;
697  ULONG ref;
698  HRESULT hres;
699 
700  static const WCHAR script_textW[] =
701  {'F','u','n','c','t','i','o','n',' ','f','\n','E','n','d',' ','F','u','n','c','t','i','o','n','\n',0};
702 
704 
705  hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
706  ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
707 
709 
711  ok(hres == S_OK, "InitNew failed: %08x\n", hres);
712 
714 
715  SET_EXPECT(GetLCID);
716  SET_EXPECT(OnStateChange_INITIALIZED);
717  hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
718  ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
719  CHECK_CALLED(GetLCID);
720  CHECK_CALLED(OnStateChange_INITIALIZED);
721 
723 
724  hres = IActiveScriptParse_ParseScriptText(parse, script_textW, NULL, NULL, NULL, 0, 1, 0x42, NULL, NULL);
725  ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
726 
727  hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
728  ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres);
729 
730  SET_EXPECT(OnStateChange_UNINITIALIZED);
731  hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
732  ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
733  CHECK_CALLED(OnStateChange_UNINITIALIZED);
734 
736 
737  hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
738  ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
739 
740  SET_EXPECT(GetLCID);
741  SET_EXPECT(OnStateChange_INITIALIZED);
742  hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
743  ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
744  CHECK_CALLED(GetLCID);
745  CHECK_CALLED(OnStateChange_INITIALIZED);
746 
747  SET_EXPECT(OnStateChange_CONNECTED);
748  SET_EXPECT(OnEnterScript);
749  SET_EXPECT(OnLeaveScript);
750  hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
751  ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
752  CHECK_CALLED(OnStateChange_CONNECTED);
753  CHECK_CALLED(OnEnterScript);
754  CHECK_CALLED(OnLeaveScript);
755 
757 
758  dispex = get_script_dispatch(script);
759  ok(dispex != NULL, "dispex == NULL\n");
760  if(dispex)
761  IDispatchEx_Release(dispex);
762 
763  SET_EXPECT(OnStateChange_DISCONNECTED);
764  SET_EXPECT(OnStateChange_INITIALIZED);
765  SET_EXPECT(OnStateChange_UNINITIALIZED);
766  hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
767  ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
768  CHECK_CALLED(OnStateChange_DISCONNECTED);
769  CHECK_CALLED(OnStateChange_INITIALIZED);
770  CHECK_CALLED(OnStateChange_UNINITIALIZED);
771 
773 
774  hres = IActiveScript_Close(script);
775  ok(hres == S_OK, "Close failed: %08x\n", hres);
776 
778 
779  hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
780  ok(hres == E_UNEXPECTED, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x, expected E_UNEXPECTED\n", hres);
781 
783 
784  SET_EXPECT(GetLCID);
785  SET_EXPECT(OnStateChange_INITIALIZED);
786  hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
787  ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
788  CHECK_CALLED(GetLCID);
789  CHECK_CALLED(OnStateChange_INITIALIZED);
790 
792 
793  SET_EXPECT(OnStateChange_CLOSED);
794  hres = IActiveScript_Close(script);
795  ok(hres == S_OK, "Close failed: %08x\n", hres);
796  CHECK_CALLED(OnStateChange_CLOSED);
797 
799 
801  ok(hres == E_UNEXPECTED, "InitNew failed: %08x\n", hres);
802 
804 
805  ref = IActiveScript_Release(script);
806  ok(!ref, "ref = %d\n", ref);
807 }
808 
809 static void test_vbscript_release(void)
810 {
811  IActiveScriptParse *parser;
812  IActiveScript *vbscript;
813  ULONG ref;
814  HRESULT hres;
815 
816  vbscript = create_vbscript();
817 
818  hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParse, (void**)&parser);
819  ok(hres == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hres);
820 
822  test_safety(vbscript);
823 
824  SET_EXPECT(GetLCID);
825  hres = IActiveScript_SetScriptSite(vbscript, &ActiveScriptSite);
826  ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
827  CHECK_CALLED(GetLCID);
828 
830 
831  SET_EXPECT(OnStateChange_INITIALIZED);
833  ok(hres == S_OK, "InitNew failed: %08x\n", hres);
834  CHECK_CALLED(OnStateChange_INITIALIZED);
835 
837 
838  SET_EXPECT(OnStateChange_CONNECTED);
839  hres = IActiveScript_SetScriptState(vbscript, SCRIPTSTATE_CONNECTED);
840  ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
841  CHECK_CALLED(OnStateChange_CONNECTED);
842 
844 
846 
847  SET_EXPECT(OnStateChange_DISCONNECTED);
848  SET_EXPECT(OnStateChange_INITIALIZED);
849  SET_EXPECT(OnStateChange_CLOSED);
850  ref = IActiveScript_Release(vbscript);
851  ok(!ref, "ref = %d\n", ref);
852  CHECK_CALLED(OnStateChange_DISCONNECTED);
853  CHECK_CALLED(OnStateChange_INITIALIZED);
854  CHECK_CALLED(OnStateChange_CLOSED);
855 }
856 
857 static void test_vbscript_simplecreate(void)
858 {
860  ULONG ref;
861  HRESULT hres;
862 
864 
865  hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
866  ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
867 
868  ref = IActiveScript_Release(script);
869  ok(!ref, "ref = %d\n", ref);
870 }
871 
872 static void test_vbscript_initializing(void)
873 {
874  IActiveScriptParse *parse;
876  ULONG ref;
877  HRESULT hres;
878 
880 
881  hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
882  ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
883 
885 
886  SET_EXPECT(GetLCID);
887  hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
888  ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
889  CHECK_CALLED(GetLCID);
890 
891  SET_EXPECT(OnStateChange_INITIALIZED);
893  ok(hres == S_OK, "InitNew failed: %08x\n", hres);
894  CHECK_CALLED(OnStateChange_INITIALIZED);
895 
896  hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
897  ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres);
898 
899  SET_EXPECT(OnStateChange_CLOSED);
900  hres = IActiveScript_Close(script);
901  ok(hres == S_OK, "Close failed: %08x\n", hres);
902  CHECK_CALLED(OnStateChange_CLOSED);
903 
905 
907 
908  ref = IActiveScript_Release(script);
909  ok(!ref, "ref = %d\n", ref);
910 }
911 
912 static void test_named_items(void)
913 {
914  IActiveScriptParse *parse;
916  ULONG ref;
917  HRESULT hres;
918 
920 
921  hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
922  ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
923 
925 
926  hres = IActiveScript_AddNamedItem(script, L"visibleItem", SCRIPTITEM_ISVISIBLE);
927  ok(hres == E_UNEXPECTED, "AddNamedItem returned: %08x\n", hres);
928  hres = IActiveScript_AddNamedItem(script, L"globalItem", SCRIPTITEM_GLOBALMEMBERS);
929  ok(hres == E_UNEXPECTED, "AddNamedItem returned: %08x\n", hres);
930 
931  SET_EXPECT(GetLCID);
932  hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
933  ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
934  CHECK_CALLED(GetLCID);
935 
936  SET_EXPECT(GetItemInfo_global);
937  hres = IActiveScript_AddNamedItem(script, L"globalItem", SCRIPTITEM_GLOBALMEMBERS);
938  ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
939  CHECK_CALLED(GetItemInfo_global);
940 
941  hres = IActiveScript_AddNamedItem(script, L"visibleItem", SCRIPTITEM_ISVISIBLE);
942  ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
943 
944  ok(global_named_item_ref > 0, "global_named_item_ref = %u\n", global_named_item_ref);
945  ok(visible_named_item_ref == 0, "visible_named_item_ref = %u\n", visible_named_item_ref);
946 
947  SET_EXPECT(OnStateChange_INITIALIZED);
949  ok(hres == S_OK, "InitNew failed: %08x\n", hres);
950  CHECK_CALLED(OnStateChange_INITIALIZED);
951 
952  SET_EXPECT(OnStateChange_CONNECTED);
953  hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
954  ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
955  CHECK_CALLED(OnStateChange_CONNECTED);
956 
957  SET_EXPECT(testCall);
958  parse_script(parse, "testCall\n");
959  CHECK_CALLED(testCall);
960 
961  SET_EXPECT(GetItemInfo_visible);
962  SET_EXPECT(testCall);
963  parse_script(parse, "visibleItem.testCall\n");
964  CHECK_CALLED(GetItemInfo_visible);
965  CHECK_CALLED(testCall);
966 
967  ok(global_named_item_ref > 0, "global_named_item_ref = %u\n", global_named_item_ref);
968  ok(visible_named_item_ref == 1, "visible_named_item_ref = %u\n", visible_named_item_ref);
969 
970  SET_EXPECT(testCall);
971  parse_script(parse, "visibleItem.testCall\n");
972  CHECK_CALLED(testCall);
973 
974  SET_EXPECT(OnStateChange_DISCONNECTED);
975  SET_EXPECT(OnStateChange_INITIALIZED);
976  SET_EXPECT(OnStateChange_CLOSED);
977  hres = IActiveScript_Close(script);
978  ok(hres == S_OK, "Close failed: %08x\n", hres);
979  CHECK_CALLED(OnStateChange_DISCONNECTED);
980  CHECK_CALLED(OnStateChange_INITIALIZED);
981  CHECK_CALLED(OnStateChange_CLOSED);
982 
983  ok(global_named_item_ref == 0, "global_named_item_ref = %u\n", global_named_item_ref);
984  ok(visible_named_item_ref == 0, "visible_named_item_ref = %u\n", visible_named_item_ref);
985 
987 
989 
990  ref = IActiveScript_Release(script);
991  ok(!ref, "ref = %d\n", ref);
992 }
993 
994 static void test_RegExp(void)
995 {
996  IRegExp2 *regexp;
997  IMatchCollection2 *mc;
998  IMatch2 *match;
999  ISubMatches *sm;
1000  IEnumVARIANT *ev;
1001  IUnknown *unk;
1002  IDispatch *disp;
1003  HRESULT hres;
1004  BSTR bstr;
1005  LONG count;
1006  VARIANT v;
1007  ULONG fetched;
1008 
1010  CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1011  &IID_IUnknown, (void**)&unk);
1012  if(hres == REGDB_E_CLASSNOTREG) {
1013  win_skip("VBScriptRegExp is not registered\n");
1014  return;
1015  }
1016  ok(hres == S_OK, "CoCreateInstance(CLSID_VBScriptRegExp) failed: %x\n", hres);
1017 
1018  hres = IUnknown_QueryInterface(unk, &IID_IRegExp2, (void**)&regexp);
1019  if(hres == E_NOINTERFACE) {
1020  win_skip("IRegExp2 interface is not available\n");
1021  return;
1022  }
1023  ok(hres == S_OK, "QueryInterface(IID_IRegExp2) failed: %x\n", hres);
1024  IUnknown_Release(unk);
1025 
1026  hres = IRegExp2_QueryInterface(regexp, &IID_IRegExp, (void**)&unk);
1027  ok(hres == S_OK, "QueryInterface(IID_IRegExp) returned %x\n", hres);
1028  IUnknown_Release(unk);
1029 
1030  hres = IRegExp2_QueryInterface(regexp, &IID_IDispatchEx, (void**)&unk);
1031  ok(hres == E_NOINTERFACE, "QueryInterface(IID_IDispatchEx) returned %x\n", hres);
1032 
1033  hres = IRegExp2_get_Pattern(regexp, &bstr);
1034  ok(bstr == NULL, "bstr != NULL\n");
1035  ok(hres == S_OK, "get_Pattern returned %x, expected S_OK\n", hres);
1036 
1037  hres = IRegExp2_get_Pattern(regexp, NULL);
1038  ok(hres == E_POINTER, "get_Pattern returned %x, expected E_POINTER\n", hres);
1039 
1040  hres = IRegExp2_get_IgnoreCase(regexp, NULL);
1041  ok(hres == E_POINTER, "get_IgnoreCase returned %x, expected E_POINTER\n", hres);
1042 
1043  hres = IRegExp2_get_Global(regexp, NULL);
1044  ok(hres == E_POINTER, "get_Global returned %x, expected E_POINTER\n", hres);
1045 
1046  hres = IRegExp2_Execute(regexp, NULL, &disp);
1047  ok(hres == S_OK, "Execute returned %x, expected S_OK\n", hres);
1048  hres = IDispatch_QueryInterface(disp, &IID_IMatchCollection2, (void**)&mc);
1049  ok(hres == S_OK, "QueryInterface(IID_IMatchCollection2) returned %x\n", hres);
1050  IDispatch_Release(disp);
1051 
1052  hres = IMatchCollection2_QueryInterface(mc, &IID_IMatchCollection, (void**)&unk);
1053  ok(hres == S_OK, "QueryInterface(IID_IMatchCollection) returned %x\n", hres);
1054  IUnknown_Release(unk);
1055 
1056  hres = IMatchCollection2_get_Count(mc, NULL);
1057  ok(hres == E_POINTER, "get_Count returned %x, expected E_POINTER\n", hres);
1058 
1059  hres = IMatchCollection2_get_Count(mc, &count);
1060  ok(hres == S_OK, "get_Count returned %x, expected S_OK\n", hres);
1061  ok(count == 1, "count = %d\n", count);
1062 
1063  hres = IMatchCollection2_get_Item(mc, 1, &disp);
1064  ok(hres == E_INVALIDARG, "get_Item returned %x, expected E_INVALIDARG\n", hres);
1065 
1066  hres = IMatchCollection2_get_Item(mc, 1, NULL);
1067  ok(hres == E_POINTER, "get_Item returned %x, expected E_POINTER\n", hres);
1068 
1069  hres = IMatchCollection2_get_Item(mc, 0, &disp);
1070  ok(hres == S_OK, "get_Item returned %x, expected S_OK\n", hres);
1071  hres = IDispatch_QueryInterface(disp, &IID_IMatch2, (void**)&match);
1072  ok(hres == S_OK, "QueryInterface(IID_IMatch2) returned %x\n", hres);
1073  IDispatch_Release(disp);
1074 
1075  hres = IMatch2_QueryInterface(match, &IID_IMatch, (void**)&unk);
1076  ok(hres == S_OK, "QueryInterface(IID_IMatch) returned %x\n", hres);
1077  IUnknown_Release(unk);
1078 
1079  hres = IMatch2_get_Value(match, NULL);
1080  ok(hres == E_POINTER, "get_Value returned %x, expected E_POINTER\n", hres);
1081 
1082  hres = IMatch2_get_FirstIndex(match, NULL);
1083  ok(hres == E_POINTER, "get_FirstIndex returned %x, expected E_POINTER\n", hres);
1084 
1085  hres = IMatch2_get_Length(match, NULL);
1086  ok(hres == E_POINTER, "get_Length returned %x, expected E_POINTER\n", hres);
1087 
1088  hres = IMatch2_get_SubMatches(match, NULL);
1089  ok(hres == E_POINTER, "get_SubMatches returned %x, expected E_POINTER\n", hres);
1090 
1091  hres = IMatch2_get_SubMatches(match, &disp);
1092  ok(hres == S_OK, "get_SubMatches returned %x, expected S_OK\n", hres);
1093  IMatch2_Release(match);
1094  hres = IDispatch_QueryInterface(disp, &IID_ISubMatches, (void**)&sm);
1095  ok(hres == S_OK, "QueryInterface(IID_ISubMatches) returned %x\n", hres);
1096  IDispatch_Release(disp);
1097 
1098  hres = ISubMatches_get_Item(sm, 0, &v);
1099  ok(hres == E_INVALIDARG, "get_Item returned %x, expected E_INVALIDARG\n", hres);
1100 
1101  hres = ISubMatches_get_Item(sm, 0, NULL);
1102  ok(hres == E_POINTER, "get_Item returned %x, expected E_POINTER\n", hres);
1103 
1104  hres = ISubMatches_get_Count(sm, NULL);
1105  ok(hres == E_POINTER, "get_Count returned %x, expected E_POINTER\n", hres);
1106  ISubMatches_Release(sm);
1107 
1108  hres = IMatchCollection2_get__NewEnum(mc, &unk);
1109  ok(hres == S_OK, "get__NewEnum returned %x, expected S_OK\n", hres);
1110  hres = IUnknown_QueryInterface(unk, &IID_IEnumVARIANT, (void**)&ev);
1111  ok(hres == S_OK, "QueryInterface(IID_IEnumVARIANT) returned %x\n", hres);
1112  IUnknown_Release(unk);
1113  IMatchCollection2_Release(mc);
1114 
1115  hres = IEnumVARIANT_Skip(ev, 2);
1116  ok(hres == S_OK, "Skip returned %x\n", hres);
1117 
1118  hres = IEnumVARIANT_Next(ev, 1, &v, &fetched);
1119  ok(hres == S_FALSE, "Next returned %x, expected S_FALSE\n", hres);
1120  ok(fetched == 0, "fetched = %d\n", fetched);
1121 
1122  hres = IEnumVARIANT_Skip(ev, -1);
1123  ok(hres == S_OK, "Skip returned %x\n", hres);
1124 
1125  hres = IEnumVARIANT_Next(ev, 1, &v, &fetched);
1126  ok(hres == S_OK, "Next returned %x\n", hres);
1127  ok(fetched == 1, "fetched = %d\n", fetched);
1128  VariantClear(&v);
1129  IEnumVARIANT_Release(ev);
1130 
1131  IRegExp2_Release(regexp);
1132 }
1133 
1134 static BOOL check_vbscript(void)
1135 {
1136  IActiveScriptParseProcedure2 *vbscript;
1137  HRESULT hres;
1138 
1139  hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1140  &IID_IActiveScriptParseProcedure2, (void**)&vbscript);
1141  if(SUCCEEDED(hres))
1143 
1144  return hres == S_OK;
1145 }
1146 
1147 START_TEST(vbscript)
1148 {
1149  CoInitialize(NULL);
1150 
1151  if(check_vbscript()) {
1152  test_vbscript();
1157  test_named_items();
1158  test_scriptdisp();
1159  test_RegExp();
1160  }else {
1161  win_skip("VBScript engine not available or too old\n");
1162  }
1163 
1164  CoUninitialize();
1165 }
#define DISP_E_UNKNOWNNAME
Definition: winerror.h:2515
static void parse_script(IActiveScriptParse *parse, const char *src)
Definition: vbscript.c:441
disp
Definition: i386-dis.c:3181
static void test_RegExp(void)
Definition: vbscript.c:994
#define REFIID
Definition: guiddef.h:118
static BSTR a2bstr(const char *str)
Definition: vbscript.c:94
#define E_NOINTERFACE
Definition: winerror.h:2364
#define DISPATCH_PROPERTYGET
Definition: oleauto.h:1007
static IActiveScript * create_vbscript(void)
Definition: vbscript.c:486
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:339
Definition: match.c:28
REFIID riid
Definition: precomp.h:44
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
#define CP_ACP
Definition: compat.h:99
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define DEFINE_EXPECT(func)
Definition: vbscript.c:54
static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
Definition: vbscript.c:257
#define V_I2(A)
Definition: oleauto.h:245
REFIID LPVOID * ppv
Definition: atlbase.h:39
static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
Definition: vbscript.c:270
DWORD LCID
Definition: nls.h:13
static void test_safety(IActiveScript *script)
Definition: vbscript.c:332
OLECHAR * BSTR
Definition: compat.h:1943
#define IActiveScriptParse_InitNew
Definition: vbscript.c:45
static LPOLESTR
Definition: stg_prop.c:27
static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
Definition: vbscript.c:226
#define E_FAIL
Definition: ddrawi.h:102
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glext.h:7750
Definition: send.c:48
#define IActiveScriptParse_ParseScriptText
Definition: vbscript.c:46
#define DISPATCH_METHOD
Definition: oleauto.h:1006
const CLSID CLSID_VBScript
static IDispatch visible_named_item
Definition: vbscript.c:204
GLuint GLuint * names
Definition: glext.h:11545
GLuint * ids
Definition: glext.h:5907
static HRESULT WINAPI Dispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
Definition: vbscript.c:151
static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
Definition: vbscript.c:298
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
GLenum GLint ref
Definition: glext.h:6028
#define S_FALSE
Definition: winerror.h:2357
static void test_vbscript_uninitializing(void)
Definition: vbscript.c:692
#define E_INVALIDARG
Definition: ddrawi.h:101
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
script
Definition: msipriv.h:374
static IDispatchEx * get_script_dispatch(IActiveScript *script)
Definition: vbscript.c:423
static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
Definition: vbscript.c:310
Definition: parser.c:48
static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR name, DWORD return_mask, IUnknown **item_unk, ITypeInfo **item_ti)
Definition: vbscript.c:237
enum tagSCRIPTSTATE SCRIPTSTATE
const CLSID CLSID_VBScriptRegExp
static void test_vbscript_simplecreate(void)
Definition: vbscript.c:857
struct match match
Definition: match.c:33
static void test_vbscript_release(void)
Definition: vbscript.c:809
static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
Definition: vbscript.c:231
static void test_vbscript_initializing(void)
Definition: vbscript.c:872
static void _get_disp_id(unsigned line, IDispatchEx *dispex, const char *name, HRESULT exhres, DISPID *id)
Definition: vbscript.c:459
static BOOL check_vbscript(void)
Definition: vbscript.c:1134
static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
Definition: vbscript.c:206
HRESULT hres
Definition: protocol.c:465
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
const GUID IID_IUnknown
static void test_no_script_dispatch(IActiveScript *script)
Definition: vbscript.c:475
static const IDispatchVtbl visible_named_item_vtbl
Definition: vbscript.c:194
static HRESULT WINAPI Dispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
Definition: vbscript.c:157
START_TEST(vbscript)
Definition: vbscript.c:1147
static ULONG WINAPI visible_AddRef(IDispatch *iface)
Definition: vbscript.c:141
#define WINAPI
Definition: msvc.h:6
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define CHECK_EXPECT(func)
Definition: vbscript.c:66
GLbitfield flags
Definition: glext.h:7161
#define IActiveScriptParseProcedure2_Release
Definition: vbscript.c:47
const GUID IID_IDispatch
int ret
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
static const WCHAR L[]
Definition: oid.c:1250
#define IID_NULL
Definition: guiddef.h:98
#define V_VT(A)
Definition: oleauto.h:211
static int state
Definition: maze.c:121
GLenum GLsizei len
Definition: glext.h:6722
#define GUID_NULL
Definition: ks.h:106
static void test_vbscript(void)
Definition: vbscript.c:626
GLenum src
Definition: glext.h:6340
#define err(...)
static IDispatch global_named_item
Definition: vbscript.c:192
static void test_named_items(void)
Definition: vbscript.c:912
static ULONG WINAPI global_Release(IDispatch *iface)
Definition: vbscript.c:136
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
static IDispatch * script_disp
Definition: run.c:178
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
struct stdole::EXCEPINFO EXCEPINFO
static VARIANTARG static DISPID
Definition: ordinal.c:49
#define S_OK
Definition: intsafe.h:59
#define REGDB_E_CLASSNOTREG
Definition: winerror.h:2696
const GLdouble * v
Definition: gl.h:2040
static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl
Definition: vbscript.c:316
static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface, const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
Definition: vbscript.c:263
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
static const IDispatchVtbl global_named_item_vtbl
Definition: vbscript.c:182
#define CHECK_CALLED(func)
Definition: vbscript.c:72
#define ok(value,...)
Definition: atltest.h:57
#define E_NOTIMPL
Definition: ddrawi.h:99
static ULONG visible_named_item_ref
Definition: vbscript.c:129
static ULONG global_named_item_ref
Definition: vbscript.c:129
static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
Definition: vbscript.c:221
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
static void test_scriptdisp(void)
Definition: vbscript.c:498
#define MultiByteToWideChar
Definition: compat.h:100
#define E_UNEXPECTED
Definition: winerror.h:2456
static IActiveScriptSite ActiveScriptSite
Definition: vbscript.c:330
static ULONG WINAPI visible_Release(IDispatch *iface)
Definition: vbscript.c:146
#define IActiveScriptParse_Release
Definition: vbscript.c:44
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
Definition: import.c:85
Definition: name.c:38
static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
Definition: vbscript.c:304
GLuint res
Definition: glext.h:9613
struct stdole::DISPPARAMS DISPPARAMS
unsigned int ULONG
Definition: retypes.h:1
GLenum GLuint id
Definition: glext.h:5579
#define SET_EXPECT(func)
Definition: vbscript.c:57
#define DISP_E_BADINDEX
Definition: winerror.h:2520
static void _test_state(unsigned line, IActiveScript *script, SCRIPTSTATE exstate)
Definition: vbscript.c:107
static HRESULT WINAPI Dispatch_Invoke(IDispatch *iface, DISPID id, REFIID riid, LCID lcid, WORD flags, DISPPARAMS *dp, VARIANT *res, EXCEPINFO *ei, UINT *err)
Definition: vbscript.c:171
#define E_POINTER
Definition: winerror.h:2365
DEFINE_GUID(GUID_NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
static ULONG WINAPI global_AddRef(IDispatch *iface)
Definition: vbscript.c:131
#define test_state(s, ss)
Definition: vbscript.c:106
#define memset(x, y, z)
Definition: compat.h:39
#define win_skip
Definition: test.h:149
static HRESULT WINAPI Dispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *names, UINT name_cnt, LCID lcid, DISPID *ids)
Definition: vbscript.c:162
Definition: compat.h:1947
#define SUCCEEDED(hr)
Definition: intsafe.h:57
#define ok_(x1, x2)
Definition: atltest.h:61
#define get_disp_id(a, b, c, d)
Definition: vbscript.c:458
static HRESULT WINAPI Dispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
Definition: vbscript.c:117
GLuint const GLchar * name
Definition: glext.h:6031