Signed-off-by: Andreas Maier staubim@quantentunnel.de --- dlls/jscript/tests/api.js | 36 +++++++++ dlls/jscript/tests/run.c | 200 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 235 insertions(+), 1 deletion(-)
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index f3d07f89f4..c6ffb20714 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -3009,4 +3009,40 @@ ok(tmp.toArray() == "2,3,12,13,22,23,32,33,42,43", "tmp.toArray() = " + tmp.toAr ok(createArray().toArray() == "2,3,12,13,22,23,32,33,42,43", "createArray.toArray()=" + createArray().toArray());
+obj = new Enumerator(); +ok(obj.atEnd(), "atEnd() = " + obj.atEnd()); +obj.moveFirst(); +ok(obj.atEnd(), "atEnd() = " + obj.atEnd()); + +obj = new Enumerator([]); +ok(!obj.atEnd(), "atEnd() = " + obj.atEnd()); +obj.moveFirst(); +ok(!obj.atEnd(), "atEnd() = " + obj.atEnd()); +obj.moveNext(); +ok(obj.atEnd(), "atEnd() = " + obj.atEnd()); +obj.moveNext(); + +objdata = ["A","B"]; +obj = new Enumerator(objdata); +ok(obj.atEnd() == false, "atEnd() = " + obj.atEnd()); +ok(obj.item() === objdata[0], "obj.item() = " + obj.item() + + ", expected " + objdata[0]); +obj.moveFirst(); +for (var i1 = 0; i1 < objdata.length; i1++) +{ + if (obj.atEnd()) + { + ok(false, i1 + "missing items!"); + break; + } + ok(obj.item() === objdata[i1], "obj.item() = " + obj.item() + + ", expected " + objdata[i1]); + obj.moveNext(); +} +ok(!obj.atEnd(), "obj.atEnd() = " + obj.atEnd()); +obj.moveNext(); +ok(obj.item() === undefined, "obj.item() = " + obj.item() + + ", expected " + undefined); +ok(obj.atEnd(), "obj.atEnd() = " + obj.atEnd()); + reportSuccess(); diff --git a/dlls/jscript/tests/run.c b/dlls/jscript/tests/run.c index e79e02f189..9b68643d49 100644 --- a/dlls/jscript/tests/run.c +++ b/dlls/jscript/tests/run.c @@ -106,6 +106,10 @@ DEFINE_EXPECT(testobj_noprop_d); DEFINE_EXPECT(testobj_onlydispid_d); DEFINE_EXPECT(testobj_onlydispid_i); DEFINE_EXPECT(testobj_notexists_d); +DEFINE_EXPECT(testobj_newenum); +DEFINE_EXPECT(enumvariant_next_0); +DEFINE_EXPECT(enumvariant_next_1); +DEFINE_EXPECT(enumvariant_reset); DEFINE_EXPECT(GetItemInfo_testVal); DEFINE_EXPECT(ActiveScriptSite_OnScriptError); DEFINE_EXPECT(invoke_func); @@ -144,6 +148,7 @@ DEFINE_EXPECT(BindHandler); #define DISPID_GLOBAL_TESTPROPPUTREF 0x101b #define DISPID_GLOBAL_GETSCRIPTSTATE 0x101c #define DISPID_GLOBAL_BINDEVENTHANDLER 0x101d +#define DISPID_GLOBAL_TESTENUMOBJ 0x101e
#define DISPID_GLOBAL_TESTPROPDELETE 0x2000 #define DISPID_GLOBAL_TESTNOPROPDELETE 0x2001 @@ -219,6 +224,97 @@ static void _test_grfdex(unsigned line, DWORD grfdex, DWORD expect) ok_(__FILE__,line)(grfdex == expect, "grfdex = %x, expected %x\n", grfdex, expect); }
+static HRESULT WINAPI EnumVARIANT_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppv) +{ + *ppv = NULL; + + if (IsEqualGUID(riid, &IID_IEnumVARIANT)) + *ppv = iface; + else + return E_NOINTERFACE; + + return S_OK; +} + +static ULONG WINAPI EnumVARIANT_AddRef(IEnumVARIANT *iface) +{ + return 2; +} + +static ULONG WINAPI EnumVARIANT_Release(IEnumVARIANT *iface) +{ + return 1; +} + +static int EnumVARIANT_index = 0; +static HRESULT WINAPI EnumVARIANT_Next( + IEnumVARIANT *This, + ULONG celt, + VARIANT *rgVar, + ULONG *pCeltFetched) +{ + ok(rgVar != NULL, "rgVar is NULL\n"); + ok(celt == 1, "celt = %d\n", celt); + ok(pCeltFetched == NULL, "pCeltFetched is not NULL\n"); + + if (!rgVar) + return S_FALSE; + + if (EnumVARIANT_index == 0) + { + CHECK_EXPECT(enumvariant_next_0); + V_VT(rgVar) = VT_I4; + V_I4(rgVar) = 123; + + if (pCeltFetched) + *pCeltFetched = 1; + EnumVARIANT_index++; + return S_OK; + } + + CHECK_EXPECT(enumvariant_next_1); + + if (pCeltFetched) + *pCeltFetched = 0; + return S_FALSE; + +} + +static HRESULT WINAPI EnumVARIANT_Skip( + IEnumVARIANT *This, + ULONG celt) +{ + ok(0, "EnumVariant_Skip: unexpected call\n"); + return E_NOTIMPL; +} +static HRESULT WINAPI EnumVARIANT_Reset( + IEnumVARIANT *This) +{ + CHECK_EXPECT(enumvariant_reset); + EnumVARIANT_index = 0; + return S_OK; +} + +static HRESULT WINAPI EnumVARIANT_Clone( + IEnumVARIANT *This, + IEnumVARIANT **ppEnum) +{ + ok(0, "EnumVariant_Clone: unexpected call\n"); + return E_NOTIMPL; +} + +static IEnumVARIANTVtbl testEnumVARIANTVtbl = { + EnumVARIANT_QueryInterface, + EnumVARIANT_AddRef, + EnumVARIANT_Release, + EnumVARIANT_Next, + EnumVARIANT_Skip, + EnumVARIANT_Reset, + EnumVARIANT_Clone +}; + +static IEnumVARIANT testEnumVARIANT = { &testEnumVARIANTVtbl }; + static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv) { *ppv = NULL; @@ -320,6 +416,29 @@ static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown return E_NOTIMPL; }
+static HRESULT WINAPI testObj_Invoke(IDispatchEx *iface, DISPID id, + REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdp, + VARIANT *pvarRes, EXCEPINFO *pei, UINT *puArgErr) +{ + switch(id) { + case DISPID_NEWENUM: + ok(pdp != NULL, "pdp == NULL\n"); + ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); + ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); + ok(pvarRes != NULL, "pvarRes == NULL\n"); + ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes)); + ok(pei == NULL, "pei != NULL\n"); + + CHECK_EXPECT(testobj_newenum); + V_VT(pvarRes) = VT_DISPATCH; + V_DISPATCH(pvarRes) = (IDispatch*)&testEnumVARIANT; + return S_OK; + } + + ok(0, "unexpected call %x\n", id); + return DISP_E_MEMBERNOTFOUND; +} + static HRESULT WINAPI testObj_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid) { if(!strcmp_wa(bstrName, "prop")) { @@ -453,7 +572,7 @@ static IDispatchExVtbl testObjVtbl = { DispatchEx_GetTypeInfoCount, DispatchEx_GetTypeInfo, DispatchEx_GetIDsOfNames, - DispatchEx_Invoke, + testObj_Invoke, testObj_GetDispID, testObj_InvokeEx, testObj_DeleteMemberByName, @@ -466,6 +585,9 @@ static IDispatchExVtbl testObjVtbl = {
static IDispatchEx testObj = { &testObjVtbl };
+static VARIANT testEnumObj; +static BOOL testEnumObjValid = FALSE; + static HRESULT WINAPI dispexFunc_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp, VARIANT *res, EXCEPINFO *pei, IServiceProvider *pspCaller) { @@ -861,6 +983,11 @@ static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD return S_OK; }
+ if(!strcmp_wa(bstrName, "testEnumObj")) { + *pid = DISPID_GLOBAL_TESTENUMOBJ; + return S_OK; + } + if(strict_dispid_check && strcmp_wa(bstrName, "t")) ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName)); return DISP_E_UNKNOWNNAME; @@ -1365,6 +1492,54 @@ static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid,
return S_OK; } + case DISPID_GLOBAL_TESTENUMOBJ: + { + HRESULT hres; + + if (wFlags == (INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF)) + { + ok(wFlags == (INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF), "wFlags = %x\n", wFlags); + ok(pdp != NULL, "pdp == NULL\n"); + ok(pdp->rgvarg != NULL, "rgvarg == NULL\n"); + ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n"); + ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs); + ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs); + ok(!pvarRes, "pvarRes != NULL\n"); + if ((pdp->rgvarg != NULL) && + (pdp->cArgs == 1) && + (pdp->cNamedArgs == 1) && + (pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT)) + { + if (!testEnumObjValid) + { + memset(&testEnumObj, 0, sizeof(VARIANT)); + testEnumObjValid = TRUE; + VariantInit(&testEnumObj); + } + else + VariantClear(&testEnumObj); + hres = VariantCopy(&testEnumObj, pdp->rgvarg); + ok(SUCCEEDED(hres), "VariantCopy failed!\n"); + } + } + else + { + ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags); + ok(pdp != NULL, "pdp == NULL\n"); + ok(!pdp->rgvarg, "rgvarg != NULL\n"); + ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n"); + ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs); + ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); + ok(pvarRes != NULL, "pvarRes == NULL\n"); + + if ((pvarRes != NULL) && (testEnumObjValid)) + { + hres = VariantCopy(pvarRes, &testEnumObj); + ok(SUCCEEDED(hres), "VariantCopy failed!\n"); + } + } + return S_OK; + } }
ok(0, "unexpected call %x\n", id); @@ -2682,6 +2857,29 @@ static BOOL run_tests(void) CHECK_CALLED(global_success_d); CHECK_CALLED(global_success_i);
+ EnumVARIANT_index = 0; + SET_EXPECT(testobj_newenum); + SET_EXPECT(enumvariant_next_0); + parse_script_a("new Enumerator(testObj);"); + CHECK_CALLED(testobj_newenum); + CHECK_CALLED(enumvariant_next_0); + + EnumVARIANT_index = 0; + SET_EXPECT(testobj_newenum); + SET_EXPECT(enumvariant_next_0); + SET_EXPECT(enumvariant_next_1); + parse_script_a("var testEnumObj = new Enumerator(testObj);" + "while (!testEnumObj.atEnd())" + "{" + " ok(testEnumObj.item() == 123, " + " "testEnumObj.item() = "+testEnumObj.item());" + " testEnumObj.moveNext();" + "}" + ); + CHECK_CALLED(testobj_newenum); + CHECK_CALLED(enumvariant_next_0); + CHECK_CALLED(enumvariant_next_1); + run_from_res("lang.js"); run_from_res("api.js"); run_from_res("regexp.js"); -- 2.11.0