+static void test_parse_context(void)
+{
+ IActiveScriptParse *parser;
+ IActiveScript *engine;
+ BSTR str;
+ HRESULT hres;
+
+ static const WCHAR xW[] = {'x',0};
+ static const WCHAR yW[] = {'y',0};
+
+ global_ref = 1;
+ engine = create_and_init_script(0);
+ if(!engine)
+ return;
+
+ hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
+ ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
+
+ /* unknown identifier context is not a valid argument */
+ str = a2bstr("Call reportSuccess()\n");
+ hres = IActiveScriptParse_ParseScriptText(parser, str, yW, NULL, NULL, 0, 0, 0, NULL, NULL);
+ ok(hres == E_INVALIDARG, "ParseScriptText failed: %08x\n", hres);
+ SysFreeString(str);
+
+ str = a2bstr("class Cl\n"
+ " Public Sub ClMethod\n"
+ " Call reportSuccess()\n"
+ " End Sub\n"
+ "End Class\n"
+ "Dim x\n"
+ "set x = new Cl\n");
+ hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
+ ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
+ SysFreeString(str);
+
+ /* known global variable is not a valid context */
+ str = a2bstr("Call reportSuccess()\n");
+ hres = IActiveScriptParse_ParseScriptText(parser, str, xW, NULL, NULL, 0, 0, 0, NULL, NULL);
+ ok(hres == E_INVALIDARG, "ParseScriptText failed: %08x\n", hres);
+ SysFreeString(str);
+
+ SET_EXPECT(global_success_d);
+ SET_EXPECT(global_success_i);
+ str = a2bstr("Call reportSuccess()\n");
+ hres = IActiveScriptParse_ParseScriptText(parser, str, testW, NULL, NULL, 0, 0, 0, NULL, NULL);
+ ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
+ SysFreeString(str);
+ CHECK_CALLED(global_success_d);
+ CHECK_CALLED(global_success_i);
+
+ IActiveScriptParse_Release(parser);
+ close_script(engine);
+ ok(global_ref == 1, "global_ref = %u\n", global_ref);
+}
+