Jacek Caban : jscript: Added possibility to run test scripts from file.
Alexandre Julliard
julliard at winehq.org
Mon Oct 6 09:35:01 CDT 2008
Module: wine
Branch: master
Commit: 68525652a15bcc332f1d48571bdb0f2da86bce47
URL: http://source.winehq.org/git/wine.git/?a=commit;h=68525652a15bcc332f1d48571bdb0f2da86bce47
Author: Jacek Caban <jacek at codeweavers.com>
Date: Thu Oct 2 16:24:02 2008 +0200
jscript: Added possibility to run test scripts from file.
With this patch it's possible to test scripts by running
wine jscript_test.exe.so run <file_name>
Although it's not what Wine tests are for, it proved to be very useful
for me.
---
dlls/jscript/tests/run.c | 62 ++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/dlls/jscript/tests/run.c b/dlls/jscript/tests/run.c
index c40653a..3904a36 100644
--- a/dlls/jscript/tests/run.c
+++ b/dlls/jscript/tests/run.c
@@ -578,7 +578,7 @@ static void parse_script(BSTR script_str)
ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
- ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
+ ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
@@ -594,6 +594,56 @@ static void parse_script_a(const char *src)
SysFreeString(tmp);
}
+static BSTR get_script_from_file(const char *filename)
+{
+ DWORD size, len;
+ HANDLE file, map;
+ const char *file_map;
+ BSTR ret;
+
+ file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
+ if(file == INVALID_HANDLE_VALUE) {
+ trace("Could not open file: %u\n", GetLastError());
+ return NULL;
+ }
+
+ size = GetFileSize(file, NULL);
+
+ map = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
+ CloseHandle(file);
+ if(map == INVALID_HANDLE_VALUE) {
+ trace("Could not create file mapping: %u\n", GetLastError());
+ return NULL;
+ }
+
+ file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
+ CloseHandle(map);
+ if(!file_map) {
+ trace("MapViewOfFile failed: %u\n", GetLastError());
+ return NULL;
+ }
+
+ len = MultiByteToWideChar(CP_ACP, 0, file_map, size, NULL, 0);
+ ret = SysAllocStringLen(NULL, len);
+ MultiByteToWideChar(CP_ACP, 0, file_map, size, ret, len);
+
+ UnmapViewOfFile(file_map);
+
+ return ret;
+}
+
+static void run_from_file(const char *filename)
+{
+ BSTR script_str = get_script_from_file(filename);
+
+ strict_dispid_check = FALSE;
+
+ if(script_str)
+ parse_script(script_str);
+
+ SysFreeString(script_str);
+}
+
static void run_from_res(const char *name)
{
const char *data;
@@ -659,9 +709,17 @@ static void run_tests(void)
START_TEST(run)
{
+ int argc;
+ char **argv;
+
+ argc = winetest_get_mainargs(&argv);
+
CoInitialize(NULL);
- run_tests();
+ if(argc > 2)
+ run_from_file(argv[2]);
+ else
+ run_tests();
CoUninitialize();
}
More information about the wine-cvs
mailing list