ReactOS 0.4.15-dev-8332-ga943bb4
wsf.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4 * PURPOSE: Tests for wscript.exe
5 * COPYRIGHT: Whindmar Saksit (whindsaks@proton.me)
6 */
7
8#include <apitest.h>
9#include <windows.h>
10#include <shlwapi.h>
11#include <stdio.h>
12
13#define MYGUID "{898AC78E-BFC7-41FF-937D-EDD01E666707}"
14
16{
17 LRESULT e;
18 DWORD size = sizeof(*out);
19 *out = 0;
20 e = SHGetValueA(hKey, sub, name, NULL, out, &size);
21 if (e)
22 *out = defval;
23 return e;
24}
25
26static BOOL makestringfile(LPWSTR path, SIZE_T cchpath, LPCSTR ext, LPCSTR string, const BYTE *map)
27{
28 UINT cch = GetTempPathW(cchpath, path);
29 UINT16 i = 0;
30 if (!cch || cch > cchpath)
31 return FALSE;
32 while (++i)
33 {
35 if (_snwprintf(path + cch, cchpath - cch, L"~%u.%hs", i, ext ? ext : "tmp") >= cchpath - cch)
36 return FALSE;
39 {
40 BOOL succ = TRUE;
41 for (; *string && succ; ++string)
42 {
43 BYTE ch = *string;
44 DWORD j;
45 for (j = 0; map && map[j + 0]; j += 2)
46 {
47 if (ch == map[j + 0])
48 ch = map[j + 1];
49 }
50 succ = WriteFile(hFile, &ch, 1, &j, NULL);
51 }
53 return succ;
54 }
55 }
56 return FALSE;
57}
58
60{
61 STARTUPINFOW si;
63 LPCWSTR exe = engine ? engine : L"wscript.exe";
64 WCHAR cmd[MAX_PATH * 2];
65
66 if (_snwprintf(cmd, _countof(cmd), L"\"%s\" //nologo \"%s\"", exe, path) >= _countof(cmd))
68 ZeroMemory(&si, sizeof(si));
69 si.cb = sizeof(si);
70 if (CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
71 {
74 GetExitCodeProcess(pi.hProcess, &code);
75 CloseHandle(pi.hProcess);
76 CloseHandle(pi.hThread);
77 return code;
78 }
79 return GetLastError();
80}
81
83{
84 DWORD code;
87 {
88 skip("Unable to create script\n");
90 }
93 return code;
94}
95
96static void test_defaultscriptisjs(void)
97{
98 LPCSTR script = ""
99 "<job>"
100 "<script>" /* No language attribute should default to Javascript */
101 "var x = 42;"
102 "WScript.Quit(x);"
103 "</script>"
104 "</job>";
105
106 ok(runscript("wsf", script, NULL) == 42, "Script failed\n");
107}
108
109static void test_simplevb(void)
110{
111 LPCSTR script = ""
112 "<job>"
113 "<script language=\"VBScript\">"
114 "Dim x\n"
115 "x = 42\n"
116 "WScript.Quit x\n"
117 "</script>"
118 "</job>";
119
120 ok(runscript("wsf", script, NULL) == 42, "Script failed\n");
121}
122
123static void test_defpackagejob(void)
124{
125 LPCSTR script = ""
126 "<package>"
127 "<job id=\"PickMePlease\">"
128 "<script language=\"VBScript\">"
129 "WScript.Quit 42"
130 "</script>"
131 "</job>"
132 "<job id=\"DontExecuteMe\">"
133 "<script language=\"VBScript\">"
134 "WScript.Quit 33"
135 "</script>"
136 "</job>"
137 "</package>";
138
139 ok(runscript("wsf", script, NULL) == 42, "Script failed\n");
140}
141
142static void test_objecttag(void)
143{
144 DWORD dw;
145 static const BYTE map[] = { '#', '\"', '$', '\\', 0, 0 };
146 LPCSTR script = ""
147 "<job>"
148 "<object id=#ws1# clsid=#{72C24DD5-D70A-438B-8A42-98424B88AFB8}# />"
149 "<script language=#JScript#>"
150 "var dontcare = ws1.ExpandEnvironmentStrings(#SystemRoot#);"
151 "var p = #HKCU/Software/" MYGUID "#.replace(/$//g,'$$');"
152 "ws2.RegWrite(p, 42, #REG_DWORD#);"
153 "</script>"
154 "<object id=#ws2# progid=#WScript.Shell# />" /* Placing the object tag after the script just for fun */
155 "</job>";
156
157 ok(runscript("wsf", script, map) == 0, "Script failed\n");
158
159 getregdw(HKEY_CURRENT_USER, "Software", MYGUID, &dw, 0);
160 ok(dw == 42, "Value does not match\n");
162}
163
165{
170}
unsigned short UINT16
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
Definition: _map.h:48
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_SHARE_READ
Definition: compat.h:136
static const WCHAR *const ext[]
Definition: module.c:53
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4592
BOOL WINAPI GetExitCodeProcess(IN HANDLE hProcess, IN LPDWORD lpExitCode)
Definition: proc.c:1168
DWORD WINAPI SHGetValueA(HKEY hKey, LPCSTR lpszSubKey, LPCSTR lpszValue, LPDWORD pwType, LPVOID pvData, LPDWORD pcbData)
Definition: reg.c:1207
DWORD WINAPI SHDeleteValueA(HKEY hKey, LPCSTR lpszSubKey, LPCSTR lpszValue)
Definition: reg.c:1741
#define INFINITE
Definition: serial.h:102
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
GLsizeiptr size
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
REFIID LPVOID DWORD_PTR dw
Definition: atlbase.h:40
#define e
Definition: ke_i.h:82
char string[160]
Definition: util.h:11
#define CREATE_NEW
Definition: disk.h:69
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
static refpint_t pi[]
Definition: server.c:96
script
Definition: msipriv.h:383
_In_ HANDLE hFile
Definition: mswsock.h:90
unsigned int UINT
Definition: ndis.h:50
#define GENERIC_WRITE
Definition: nt_native.h:90
#define L(x)
Definition: ntvdm.h:50
static FILE * out
Definition: regtests2xml.c:44
#define _countof(array)
Definition: sndvol32.h:70
DWORD cb
Definition: winbase.h:852
Definition: ftp_var.h:139
Definition: inflate.c:139
Definition: fci.c:127
Definition: name.c:39
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
LONG_PTR LRESULT
Definition: windef.h:209
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
#define ERROR_INTERNAL_ERROR
Definition: winerror.h:840
#define HKEY_CURRENT_USER
Definition: winreg.h:11
static void test_defaultscriptisjs(void)
Definition: wsf.c:96
static DWORD getregdw(HKEY hKey, LPCSTR sub, LPCSTR name, DWORD *out, DWORD defval)
Definition: wsf.c:15
static void test_objecttag(void)
Definition: wsf.c:142
static BOOL makestringfile(LPWSTR path, SIZE_T cchpath, LPCSTR ext, LPCSTR string, const BYTE *map)
Definition: wsf.c:26
#define MYGUID
Definition: wsf.c:13
static void test_defpackagejob(void)
Definition: wsf.c:123
static void test_simplevb(void)
Definition: wsf.c:109
static DWORD runscript(LPCSTR ext, LPCSTR script, const BYTE *map)
Definition: wsf.c:82
static DWORD runscriptfile(LPCWSTR path, LPCWSTR engine)
Definition: wsf.c:59
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
unsigned char BYTE
Definition: xxhash.c:193