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.
This commit is contained in:
parent
31b3071552
commit
68525652a1
|
@ -578,7 +578,7 @@ static void parse_script(BSTR script_str)
|
||||||
ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
|
ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
|
||||||
|
|
||||||
hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
|
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);
|
hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
|
||||||
ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
|
ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
|
||||||
|
@ -594,6 +594,56 @@ static void parse_script_a(const char *src)
|
||||||
SysFreeString(tmp);
|
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)
|
static void run_from_res(const char *name)
|
||||||
{
|
{
|
||||||
const char *data;
|
const char *data;
|
||||||
|
@ -659,9 +709,17 @@ static void run_tests(void)
|
||||||
|
|
||||||
START_TEST(run)
|
START_TEST(run)
|
||||||
{
|
{
|
||||||
|
int argc;
|
||||||
|
char **argv;
|
||||||
|
|
||||||
|
argc = winetest_get_mainargs(&argv);
|
||||||
|
|
||||||
CoInitialize(NULL);
|
CoInitialize(NULL);
|
||||||
|
|
||||||
run_tests();
|
if(argc > 2)
|
||||||
|
run_from_file(argv[2]);
|
||||||
|
else
|
||||||
|
run_tests();
|
||||||
|
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue