Commit b0664560 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

wscript: Added WScript.Quit tests.

parent 341bb46f
...@@ -339,11 +339,12 @@ static const IClassFactoryVtbl ClassFactoryVtbl = { ...@@ -339,11 +339,12 @@ static const IClassFactoryVtbl ClassFactoryVtbl = {
static IClassFactory testobj_cf = { &ClassFactoryVtbl }; static IClassFactory testobj_cf = { &ClassFactoryVtbl };
static void run_test(const char *file_name) static void run_script_file(const char *file_name, DWORD expected_exit_code)
{ {
char command[MAX_PATH]; char command[MAX_PATH];
STARTUPINFOA si = {sizeof(si)}; STARTUPINFOA si = {sizeof(si)};
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
DWORD exit_code;
BOOL bres; BOOL bres;
script_name = file_name; script_name = file_name;
...@@ -360,37 +361,29 @@ static void run_test(const char *file_name) ...@@ -360,37 +361,29 @@ static void run_test(const char *file_name)
wscript_process = pi.hProcess; wscript_process = pi.hProcess;
WaitForSingleObject(pi.hProcess, INFINITE); WaitForSingleObject(pi.hProcess, INFINITE);
bres = GetExitCodeProcess(pi.hProcess, &exit_code);
ok(bres, "GetExitCodeProcess failed: %u\n", GetLastError());
ok(exit_code == expected_exit_code, "exit_code = %u, expected %u\n", exit_code, expected_exit_code);
CloseHandle(pi.hThread); CloseHandle(pi.hThread);
CloseHandle(pi.hProcess); CloseHandle(pi.hProcess);
CHECK_CALLED(reportSuccess); CHECK_CALLED(reportSuccess);
} }
static BOOL WINAPI test_enum_proc(HMODULE module, LPCSTR type, LPSTR name, LONG_PTR param) static void run_script(const char *name, const char *script_data, size_t script_size, DWORD expected_exit_code)
{ {
const char *script_data, *ext;
DWORD script_size, size;
char file_name[MAX_PATH]; char file_name[MAX_PATH];
const char *ext;
HANDLE file; HANDLE file;
HRSRC src; DWORD size;
BOOL res; BOOL res;
trace("running %s test...\n", name);
src = FindResourceA(NULL, name, type);
ok(src != NULL, "Could not find resource %s: %u\n", name, GetLastError());
if(!src)
return TRUE;
script_data = LoadResource(NULL, src);
script_size = SizeofResource(NULL, src);
while(script_size && !script_data[script_size-1])
script_size--;
ext = strrchr(name, '.'); ext = strrchr(name, '.');
ok(ext != NULL, "no script extension\n"); ok(ext != NULL, "no script extension\n");
if(!ext) if(!ext)
return TRUE; return;
sprintf(file_name, "test%s", ext); sprintf(file_name, "test%s", ext);
...@@ -398,17 +391,43 @@ static BOOL WINAPI test_enum_proc(HMODULE module, LPCSTR type, LPSTR name, LONG_ ...@@ -398,17 +391,43 @@ static BOOL WINAPI test_enum_proc(HMODULE module, LPCSTR type, LPSTR name, LONG_
FILE_ATTRIBUTE_NORMAL, NULL); FILE_ATTRIBUTE_NORMAL, NULL);
ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError()); ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
if(file == INVALID_HANDLE_VALUE) if(file == INVALID_HANDLE_VALUE)
return TRUE; return;
res = WriteFile(file, script_data, script_size, &size, NULL); res = WriteFile(file, script_data, script_size, &size, NULL);
CloseHandle(file); CloseHandle(file);
ok(res, "Could not write to file: %u\n", GetLastError()); ok(res, "Could not write to file: %u\n", GetLastError());
if(!res) if(!res)
return TRUE; return;
run_test(file_name); run_script_file(file_name, expected_exit_code);
DeleteFileA(file_name); DeleteFileA(file_name);
}
static void run_simple_script(const char *script, DWORD expected_exit_code)
{
run_script("simple.js", script, strlen(script), expected_exit_code);
}
static BOOL WINAPI test_enum_proc(HMODULE module, LPCSTR type, LPSTR name, LONG_PTR param)
{
const char *script_data;
DWORD script_size;
HRSRC src;
trace("running %s test...\n", name);
src = FindResourceA(NULL, name, type);
ok(src != NULL, "Could not find resource %s: %u\n", name, GetLastError());
if(!src)
return TRUE;
script_data = LoadResource(NULL, src);
script_size = SizeofResource(NULL, src);
while(script_size && !script_data[script_size-1])
script_size--;
run_script(name, script_data, script_size, 0);
return TRUE; return TRUE;
} }
...@@ -468,11 +487,17 @@ START_TEST(run) ...@@ -468,11 +487,17 @@ START_TEST(run)
} }
argc = winetest_get_mainargs(&argv); argc = winetest_get_mainargs(&argv);
if(argc > 2) if(argc > 2) {
run_test(argv[2]); run_script_file(argv[2], 0);
else }else {
EnumResourceNamesA(NULL, "TESTSCRIPT", test_enum_proc, 0); EnumResourceNamesA(NULL, "TESTSCRIPT", test_enum_proc, 0);
run_simple_script("var winetest = new ActiveXObject('Wine.Test');\n"
"winetest.reportSuccess();\n"
"WScript.Quit(3);\n"
"winetest.ok(false, 'not quit?');\n", 3);
}
init_registry(FALSE); init_registry(FALSE);
CoUninitialize(); CoUninitialize();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment