Jacek Caban : jscript: Added infrastructure for test scripts.

Alexandre Julliard julliard at winehq.org
Tue Sep 9 05:50:47 CDT 2008


Module: wine
Branch: master
Commit: b60898353c47a507f08ccbf45748922adde93afb
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=b60898353c47a507f08ccbf45748922adde93afb

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Tue Sep  9 01:25:23 2008 +0200

jscript: Added infrastructure for test scripts.

---

 dlls/jscript/tests/Makefile.in |    2 +
 dlls/jscript/tests/lang.js     |   21 +++++++++
 dlls/jscript/tests/rsrc.rc     |   20 +++++++++
 dlls/jscript/tests/run.c       |   91 +++++++++++++++++++++++++++++++++++++--
 4 files changed, 129 insertions(+), 5 deletions(-)

diff --git a/dlls/jscript/tests/Makefile.in b/dlls/jscript/tests/Makefile.in
index 01cd58e..1730cae 100644
--- a/dlls/jscript/tests/Makefile.in
+++ b/dlls/jscript/tests/Makefile.in
@@ -9,6 +9,8 @@ CTESTS = \
 	jscript.c \
 	run.c
 
+RC_SRCS = rsrc.rc
+
 @MAKE_TEST_RULES@
 
 @DEPENDENCIES@  # everything below this line is overwritten by make depend
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
new file mode 100644
index 0000000..f70bb16
--- /dev/null
+++ b/dlls/jscript/tests/lang.js
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2008 Jacek Caban for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+ok(true, "true is not true?");
+
+reportSuccess();
diff --git a/dlls/jscript/tests/rsrc.rc b/dlls/jscript/tests/rsrc.rc
new file mode 100644
index 0000000..ba7a460
--- /dev/null
+++ b/dlls/jscript/tests/rsrc.rc
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2008 Jacek Caban for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/* @makedep: lang.js */
+lang.js 40 "lang.js"
diff --git a/dlls/jscript/tests/run.c b/dlls/jscript/tests/run.c
index 10c97cd..46e3387 100644
--- a/dlls/jscript/tests/run.c
+++ b/dlls/jscript/tests/run.c
@@ -67,9 +67,14 @@ DEFINE_EXPECT(global_success_i);
 #define DISPID_GLOBAL_TESTPROPGET   0x1000
 #define DISPID_GLOBAL_TESTPROPPUT   0x1001
 #define DISPID_GLOBAL_REPORTSUCCESS 0x1002
+#define DISPID_GLOBAL_TRACE         0x1003
+#define DISPID_GLOBAL_OK            0x1004
 
 static const WCHAR testW[] = {'t','e','s','t',0};
 
+static BOOL strict_dispid_check;
+static const char *test_name = "(null)";
+
 static const char *debugstr_w(LPCWSTR str)
 {
     static char buf[1024];
@@ -191,6 +196,16 @@ static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown
 
 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
 {
+    if(!strcmp_wa(bstrName, "ok")) {
+        ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
+        *pid = DISPID_GLOBAL_OK;
+        return S_OK;
+    }
+    if(!strcmp_wa(bstrName, "trace")) {
+        ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
+        *pid = DISPID_GLOBAL_TRACE;
+        return S_OK;
+    }
     if(!strcmp_wa(bstrName, "reportSuccess")) {
         CHECK_EXPECT(global_success_d);
         ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
@@ -210,16 +225,49 @@ static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD
         return S_OK;
     }
 
-    ok(0, "unexpected call %s\n", debugstr_w(bstrName));
+    if(strict_dispid_check)
+        ok(0, "unexpected call %s\n", debugstr_w(bstrName));
     return DISP_E_UNKNOWNNAME;
 }
 
 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
 {
-     switch(id) {
-     case DISPID_GLOBAL_REPORTSUCCESS:
-         CHECK_EXPECT(global_success_i);
+    switch(id) {
+    case DISPID_GLOBAL_OK:
+        ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
+        ok(pdp != NULL, "pdp == NULL\n");
+        ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
+        ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
+        ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
+        ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
+        ok(!pvarRes, "pvarRes != NULL\n");
+        ok(pei != NULL, "pei == NULL\n");
+
+        ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
+        ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
+        ok(V_BOOL(pdp->rgvarg+1), "%s: %s\n", test_name, debugstr_w(V_BSTR(pdp->rgvarg)));
+
+        return S_OK;
+
+     case DISPID_GLOBAL_TRACE:
+        ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
+        ok(pdp != NULL, "pdp == NULL\n");
+        ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
+        ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
+        ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
+        ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
+        ok(!pvarRes, "pvarRes != NULL\n");
+        ok(pei != NULL, "pei == NULL\n");
+
+        ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
+        if(V_VT(pdp->rgvarg) == VT_BSTR)
+            trace("%s: %s\n", test_name, debugstr_w(V_BSTR(pdp->rgvarg)));
+
+        return S_OK;
+
+    case DISPID_GLOBAL_REPORTSUCCESS:
+        CHECK_EXPECT(global_success_i);
 
         ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
         ok(pdp != NULL, "pdp == NULL\n");
@@ -266,7 +314,7 @@ static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid,
         return S_OK;
      }
 
-     ok(0, "unexpected call %x\n", id);
+    ok(0, "unexpected call %x\n", id);
     return DISP_E_MEMBERNOTFOUND;
 }
 
@@ -433,8 +481,39 @@ static void parse_script_a(const char *src)
     SysFreeString(tmp);
 }
 
+static void run_from_res(const char *name)
+{
+    const char *data;
+    DWORD size, len;
+    BSTR str;
+    HRSRC src;
+
+    strict_dispid_check = FALSE;
+    test_name = name;
+
+    src = FindResourceA(NULL, name, (LPCSTR)40);
+    ok(src != NULL, "Could not find resource %s\n", name);
+
+    size = SizeofResource(NULL, src);
+    data = LoadResource(NULL, src);
+
+    len = MultiByteToWideChar(CP_ACP, 0, data, size, NULL, 0);
+    str = SysAllocStringLen(NULL, len-1);
+    len = MultiByteToWideChar(CP_ACP, 0, data, size, str, len);
+
+    SET_EXPECT(global_success_d);
+    SET_EXPECT(global_success_i);
+    parse_script(str);
+    CHECK_CALLED(global_success_d);
+    CHECK_CALLED(global_success_i);
+
+    SysFreeString(str);
+}
+
 static void run_tests(void)
 {
+    strict_dispid_check = TRUE;
+
     parse_script_a("");
     parse_script_a("/* empty */ ;");
 
@@ -455,6 +534,8 @@ static void run_tests(void)
     parse_script_a("reportSuccess();");
     CHECK_CALLED(global_success_d);
     CHECK_CALLED(global_success_i);
+
+    run_from_res("lang.js");
 }
 
 START_TEST(run)




More information about the wine-cvs mailing list