ReactOS 0.4.15-dev-7928-g68a8619
precomp.h File Reference
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
#include <iomanip>
#include <windef.h>
#include <winbase.h>
#include <winnls.h>
#include <reason.h>
#include <shlobj.h>
#include <wininet.h>
#include <winreg.h>
#include <ndk/rtlfuncs.h>
#include <reactos/buildno.h>
#include "auto_array_ptr.h"
#include "CConfiguration.h"
#include "CFatalException.h"
#include "CInvalidParameterException.h"
#include "CPipe.h"
#include "CProcess.h"
#include "CPipedProcess.h"
#include "CSimpleException.h"
#include "CTestException.h"
#include "CTestInfo.h"
#include "CTest.h"
#include "CTestList.h"
#include "CJournaledTestList.h"
#include "CVirtualTestList.h"
#include "CWebService.h"
#include "CWineTest.h"
#include <rosautotestmsg.h>
Include dependency graph for precomp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define _INC_WINDOWS
 
#define COM_NO_WINDOWS_H
 
#define EXCEPTION(Message)   throw CSimpleException(Message)
 
#define FATAL(Message)   throw CFatalException(__FILE__, __LINE__, Message)
 
#define SSEXCEPTION   throw CSimpleException(ss.str())
 
#define TESTEXCEPTION(Message)   throw CTestException(Message)
 

Functions

VOID FreeLogs (VOID)
 
VOID InitLogs (VOID)
 
bool ShutdownSystem ()
 
wstring AsciiToUnicode (const char *AsciiString)
 
wstring AsciiToUnicode (const string &AsciiString)
 
string EscapeString (const char *Input)
 
string EscapeString (const string &Input)
 
string GetINIValue (PCWCH AppName, PCWCH KeyName, PCWCH FileName)
 
bool IsNumber (const char *Input)
 
string StringOut (const string &String, bool forcePrint=true)
 
string UnicodeToAscii (PCWSTR UnicodeString)
 
string UnicodeToAscii (const wstring &UnicodeString)
 

Variables

CConfiguration Configuration
 
HANDLE hLog
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 22 of file precomp.h.

◆ COM_NO_WINDOWS_H

#define COM_NO_WINDOWS_H

Definition at line 23 of file precomp.h.

◆ EXCEPTION

#define EXCEPTION (   Message)    throw CSimpleException(Message)

Definition at line 56 of file precomp.h.

◆ FATAL

#define FATAL (   Message)    throw CFatalException(__FILE__, __LINE__, Message)

Definition at line 57 of file precomp.h.

◆ SSEXCEPTION

#define SSEXCEPTION   throw CSimpleException(ss.str())

Definition at line 58 of file precomp.h.

◆ TESTEXCEPTION

#define TESTEXCEPTION (   Message)    throw CTestException(Message)

Definition at line 59 of file precomp.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 21 of file precomp.h.

Function Documentation

◆ AsciiToUnicode() [1/2]

wstring AsciiToUnicode ( const char AsciiString)

Converts an ASCII string to a Unicode one.

Parameters
AsciiStringConstant pointer to a char array containing the ASCII string
Returns
The Unicode string as std::wstring

Definition at line 220 of file tools.cpp.

221{
224 wstring ReturnString;
225
226 Length = MultiByteToWideChar(CP_ACP, 0, AsciiString, -1, NULL, 0);
227
229 MultiByteToWideChar(CP_ACP, 0, AsciiString, -1, UnicodeString, Length);
230 ReturnString = UnicodeString;
231 delete UnicodeString;
232
233 return ReturnString;
234}
#define NULL
Definition: types.h:112
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
uint16_t * PWSTR
Definition: typedefs.h:56
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by AddPrinterA(), AddPrintProcessorA(), AsciiToUnicode(), DeleteFormA(), DeletePrinterDriverExA(), DeletePrintProcessorA(), DeletePrintProvidorA(), EnumPrinterDriversA(), CWineTest::GetNextTestInfo(), ResetPrinterA(), SetJobA(), SetPrinterA(), and StartDocDlgA().

◆ AsciiToUnicode() [2/2]

wstring AsciiToUnicode ( const string AsciiString)

Converts an ASCII string to a Unicode one.

Parameters
AsciiStringPointer to a std::string containing the ASCII string
Returns
The Unicode string as std::wstring

Definition at line 246 of file tools.cpp.

247{
248 return AsciiToUnicode(AsciiString.c_str());
249}
const _CharT * c_str() const
Definition: _string.h:949
wstring AsciiToUnicode(const char *AsciiString)
Definition: tools.cpp:220

◆ EscapeString() [1/2]

string EscapeString ( const char Input)

Escapes a string according to RFC 1738. Required for passing parameters to the web service.

Parameters
InputConstant pointer to a char array, which contains the input buffer to escape.
Returns
The escaped string as std::string.

Definition at line 24 of file tools.cpp.

25{
26 string ReturnedString;
27
28 do
29 {
30 if(strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~", *Input))
31 {
32 /* It's a character we don't need to escape, just add it to the output string */
33 ReturnedString += *Input;
34 }
35 else
36 {
37 /* We need to escape this character */
38 ReturnedString += '%';
39 ReturnedString += HexCharacters[((UCHAR)*Input >> 4) % 16];
40 ReturnedString += HexCharacters[(UCHAR)*Input % 16];
41 }
42 }
43 while(*++Input);
44
45 return ReturnedString;
46}
char * strchr(const char *String, int ch)
Definition: utclib.c:501
static const char HexCharacters[]
Definition: tools.cpp:11
@ Input
Definition: arc.h:84
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by EscapeString(), CConfiguration::GetConfigurationFromFile(), and CWebService::Submit().

◆ EscapeString() [2/2]

string EscapeString ( const string Input)

Escapes a string according to RFC 1738. Required for passing parameters to the web service.

Parameters
InputPointer to a std::string, which contains the input buffer to escape.
Returns
The escaped string as std::string.

Definition at line 59 of file tools.cpp.

60{
61 return EscapeString(Input.c_str());
62}
string EscapeString(const char *Input)
Definition: tools.cpp:24

◆ FreeLogs()

VOID FreeLogs ( VOID  )

Definition at line 85 of file misc.cpp.

86{
88}
BOOL WINAPI DeregisterEventSource(IN HANDLE hEventLog)
Definition: eventlog.c:473
HANDLE hLog
Definition: misc.cpp:9

◆ GetINIValue()

string GetINIValue ( PCWCH  AppName,
PCWCH  KeyName,
PCWCH  FileName 
)

Gets a value from a specified INI file and returns it converted to ASCII.

Parameters
AppNameConstant pointer to a WCHAR array with the INI section to look in (lpAppName parameter passed to GetPrivateProfileStringW)
KeyNameConstant pointer to a WCHAR array containing the key to look for in the specified section (lpKeyName parameter passed to GetPrivateProfileStringW)
FileNameConstant pointer to a WCHAR array containing the path to the INI file
Returns
Returns the data of the value as std::string or an empty string if no data could be retrieved.

Definition at line 187 of file tools.cpp.

188{
190 PCHAR AsciiBuffer;
191 string ReturnedString;
192 WCHAR Buffer[2048];
193
194 /* Load the value into a temporary Unicode buffer */
196
197 if(Length)
198 {
199 /* Convert the string to ASCII charset */
200 AsciiBuffer = new char[Length + 1];
201 WideCharToMultiByte(CP_ACP, 0, Buffer, Length + 1, AsciiBuffer, Length + 1, NULL, NULL);
202
203 ReturnedString = AsciiBuffer;
204 delete[] AsciiBuffer;
205 }
206
207 return ReturnedString;
208}
Definition: bufpool.h:45
static CHAR AppName[MAX_PATH]
Definition: dem.c:252
#define WideCharToMultiByte
Definition: compat.h:111
INT WINAPI GetPrivateProfileStringW(LPCWSTR section, LPCWSTR entry, LPCWSTR def_val, LPWSTR buffer, UINT len, LPCWSTR filename)
Definition: profile.c:1142
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699

Referenced by CConfiguration::GetConfigurationFromFile().

◆ InitLogs()

VOID InitLogs ( VOID  )

Definition at line 12 of file misc.cpp.

13{
14 WCHAR szBuf[MAX_PATH] = L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\RosAutotest";
16 DWORD dwCategoryNum = 1;
17 DWORD dwDisp, dwData;
18 HKEY hKey;
19
21 szBuf, 0, NULL,
23 KEY_WRITE, NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
24 {
25 return;
26 }
27
28 if (!GetModuleFileName(NULL, szPath, sizeof(szPath) / sizeof(szPath[0])))
29 return;
30
32 L"EventMessageFile",
33 0,
36 (DWORD)(wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
37 {
39 return;
40 }
41
44
46 L"TypesSupported",
47 0,
49 (LPBYTE)&dwData,
50 sizeof(DWORD)) != ERROR_SUCCESS)
51 {
53 return;
54 }
55
57 L"CategoryMessageFile",
58 0,
61 (DWORD)(wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
62 {
64 return;
65 }
66
68 L"CategoryCount",
69 0,
71 (LPBYTE)&dwCategoryNum,
72 sizeof(DWORD)) != ERROR_SUCCESS)
73 {
75 return;
76 }
77
79
80 hLog = RegisterEventSourceW(NULL, L"RosAutotest");
81}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
HANDLE WINAPI RegisterEventSourceW(IN LPCWSTR lpUNCServerName, IN LPCWSTR lpSourceName)
Definition: eventlog.c:1295
#define MAX_PATH
Definition: compat.h:34
FxAutoRegKey hKey
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
LPCWSTR szPath
Definition: env.c:37
static HANDLE ULONG_PTR dwData
Definition: file.c:35
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define L(x)
Definition: ntvdm.h:50
#define REG_DWORD
Definition: sdbapi.c:596
unsigned char * LPBYTE
Definition: typedefs.h:53
#define GetModuleFileName
Definition: winbase.h:3831
#define EVENTLOG_ERROR_TYPE
Definition: winnt_old.h:2834
#define EVENTLOG_INFORMATION_TYPE
Definition: winnt_old.h:2836
#define EVENTLOG_WARNING_TYPE
Definition: winnt_old.h:2835
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

◆ IsNumber()

bool IsNumber ( const char Input)

Determines whether a string contains entirely numeric values.

Parameters
InputConstant pointer to a char array containing the input to check.
Returns
true if the string is entirely numeric, false otherwise.

Definition at line 74 of file tools.cpp.

75{
76 do
77 {
78 if(!isdigit(*Input))
79 return false;
80
81 ++Input;
82 }
83 while(*Input);
84
85 return true;
86}
#define isdigit(c)
Definition: acclib.h:68

Referenced by CWebService::GetSuiteID(), and CWebService::GetTestID().

◆ ShutdownSystem()

bool ShutdownSystem ( )

Shuts down the system.

Returns
true if everything went well, false if there was a problem while trying to shut down the system.

Definition at line 16 of file shutdown.cpp.

17{
18 HANDLE hToken;
20
22 {
23 StringOut("OpenProcessToken failed\n");
24 return false;
25 }
26
27 /* Get the LUID for the Shutdown privilege */
28 if (!LookupPrivilegeValueW(NULL, SE_SHUTDOWN_NAME, &Privileges.Privileges[0].Luid))
29 {
30 StringOut("LookupPrivilegeValue failed\n");
31 return false;
32 }
33
34 /* Assign the Shutdown privilege to our process */
35 Privileges.PrivilegeCount = 1;
36 Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
37
38 if (!AdjustTokenPrivileges(hToken, FALSE, &Privileges, 0, NULL, NULL))
39 {
40 StringOut("AdjustTokenPrivileges failed\n");
41 return false;
42 }
43
44 /* Finally shut down the system */
45 if(!ExitWindowsEx(EWX_POWEROFF, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER | SHTDN_REASON_FLAG_PLANNED))
46 {
47 StringOut("ExitWindowsEx failed\n");
48 return false;
49 }
50
51 return true;
52}
#define FALSE
Definition: types.h:117
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:374
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
#define GetCurrentProcess()
Definition: compat.h:759
string StringOut(const string &String, bool forcePrint=true)
Definition: tools.cpp:96
#define SE_SHUTDOWN_NAME
Definition: winnt_old.h:384
#define EWX_POWEROFF
Definition: winuser.h:637
BOOL WINAPI ExitWindowsEx(_In_ UINT, _In_ DWORD)
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET * Privileges
Definition: sefuncs.h:17
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:930
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63

Referenced by wmain().

◆ StringOut()

string StringOut ( const string String,
bool  forcePrint 
)

Outputs a string through the standard output and the debug output. The string may have LF or CRLF line endings.

Parameters
StringThe std::string to output

Definition at line 96 of file tools.cpp.

97{
98 char DbgString[DBGPRINT_BUFSIZE + 1];
99 size_t i, start = 0, last_newline = 0, size = 0, curr_pos = 0;
100 string NewString;
101
102 /* Unify the line endings (the piped output of the tests may use CRLF) */
103 for(i = 0; i < String.size(); i++)
104 {
105 /* If this is a CRLF line-ending, only copy a \n to the new string and skip the next character */
106 if(String[i] == '\r' && String[i + 1] == '\n')
107 {
108 NewString += '\n';
109 ++i;
110 }
111 else
112 {
113 /* Otherwise copy the string */
114 NewString += String[i];
115 }
116
117 curr_pos = NewString.size();
118
119 /* Try to print whole lines but obey the 512 bytes chunk size limit*/
120 if(NewString[curr_pos - 1] == '\n' || (curr_pos - start) == DBGPRINT_BUFSIZE)
121 {
122 if((curr_pos - start) >= DBGPRINT_BUFSIZE)
123 {
124 /* No newlines so far, or the string just fits */
125 if(last_newline <= start || ((curr_pos - start == DBGPRINT_BUFSIZE) && NewString[curr_pos - 1] == '\n'))
126 {
127 size = curr_pos - start;
128 memcpy(DbgString, NewString.c_str() + start, size);
129 start = curr_pos;
130 }
131 else
132 {
133 size = last_newline - start;
134 memcpy(DbgString, NewString.c_str() + start, size);
135 start = last_newline;
136 }
137
138 DbgString[size] = 0;
139 DbgPrint("%s", DbgString);
140 }
141
142 last_newline = curr_pos;
143 }
144 }
145
146 size = curr_pos - start;
147
148 /* Only print if forced to or if the rest is a whole line */
149 if(forcePrint == true || NewString[curr_pos - 1] == '\n')
150 {
151 /* Output the whole string */
152 if(Configuration.DoPrint())
153 cout << NewString << flush;
154
155 memcpy(DbgString, NewString.c_str() + start, size);
156 DbgString[size] = 0;
157 DbgPrint("%s", DbgString);
158
159 NewString.clear();
160 return NewString;
161 }
162
163 /* Output full lines only */
164 if(Configuration.DoPrint())
165 cout << NewString.substr(0, start) << flush;
166
167 /* Return the remaining chunk */
168 return NewString.substr(start, size);
169}
void clear()
Definition: _string.h:421
_Self substr(size_type __pos=0, size_type __n=npos) const
Definition: _string.h:1022
size_type size() const
Definition: _string.h:400
GLuint start
Definition: gl.h:1545
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
#define DbgPrint
Definition: hal.h:12
#define cout
Definition: iostream.cpp:38
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define DBGPRINT_BUFSIZE
Definition: tools.cpp:10
int flush
Definition: zlib.h:309
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_INTERRUPT_CONFIG Configuration
Definition: wdfinterrupt.h:374

Referenced by CWineTest::GetNextTestInfo(), LdrpAllocateUnicodeString(), CJournaledTestList::LoadJournalFile(), CWineTest::Run(), CWineTest::RunTest(), ShutdownSystem(), wmain(), and CJournaledTestList::WriteInitialJournalFile().

◆ UnicodeToAscii() [1/2]

string UnicodeToAscii ( const wstring &  UnicodeString)

Converts a Unicode string to an ASCII one.

Parameters
UnicodeStringPointer to a std::wstring containing the Unicode string
Returns
The ASCII string as std::string

Definition at line 287 of file tools.cpp.

288{
289 return UnicodeToAscii(UnicodeString.c_str());
290}
string UnicodeToAscii(PCWSTR UnicodeString)
Definition: tools.cpp:261

◆ UnicodeToAscii() [2/2]

string UnicodeToAscii ( PCWSTR  UnicodeString)

Converts a Unicode string to an ASCII one.

Parameters
UnicodeStringConstant pointer to a WCHAR array containing the Unicode string
Returns
The ASCII string as std::string

Definition at line 261 of file tools.cpp.

262{
264 PCHAR AsciiString;
265 string ReturnString;
266
268
269 AsciiString = new char[Length];
270 WideCharToMultiByte(CP_ACP, 0, UnicodeString, -1, AsciiString, Length, NULL, NULL);
271 ReturnString = AsciiString;
272 delete AsciiString;
273
274 return ReturnString;
275}

Referenced by CWineTest::DoListCommand(), CWineTest::GetNextTestInfo(), CConfiguration::ParseParameters(), and UnicodeToAscii().

Variable Documentation

◆ Configuration

Definition at line 11 of file main.cpp.

◆ hLog

HANDLE hLog
extern

Definition at line 9 of file misc.cpp.

Referenced by FreeLogs(), InitLogs(), and WriteLogMessage().