ReactOS  0.4.15-dev-3303-g1ade494
CJournaledTestList Class Reference

#include <CJournaledTestList.h>

Inheritance diagram for CJournaledTestList:
Collaboration diagram for CJournaledTestList:

Public Member Functions

 CJournaledTestList (CTest *Test)
 
 ~CJournaledTestList ()
 
CTestInfoGetNextTestInfo ()
 

Private Member Functions

void LoadJournalFile ()
 
void OpenJournal (DWORD DesiredAccess, bool CreateNew=false)
 
void SerializeIntoJournal (const string &String)
 
void SerializeIntoJournal (const wstring &String)
 
void UnserializeFromBuffer (char **Buffer, string &Output)
 
void UnserializeFromBuffer (char **Buffer, wstring &Output)
 
void UpdateJournal ()
 
void WriteInitialJournalFile ()
 

Private Attributes

HANDLE m_hJournal
 
size_t m_ListIterator
 
vector< CTestInfom_List
 
wstring m_JournalFile
 

Additional Inherited Members

- Protected Member Functions inherited from CTestList
 CTestList (CTest *Test)
 
- Protected Attributes inherited from CTestList
CTestm_Test
 

Detailed Description

Definition at line 8 of file CJournaledTestList.h.

Constructor & Destructor Documentation

◆ CJournaledTestList()

CJournaledTestList::CJournaledTestList ( CTest Test)

Constructs a CJournaledTestList object for an associated CTest-derived object.

Parameters
TestPointer to a CTest-derived object, for which this test list shall serve.

Definition at line 19 of file CJournaledTestList.cpp.

20  : CTestList(Test)
21 {
22  WCHAR JournalFile[MAX_PATH];
23 
25 
26  /* Build the path to the journal file */
28  FATAL("SHGetFolderPathW failed\n");
29 
30  m_JournalFile = JournalFile;
31  m_JournalFile += L"\\rosautotest\\";
32 
33  /* Create the directory if necessary */
36 
38 
39  /* Check if the journal already exists */
42  else
44 }
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
#define FATAL(Message)
Definition: precomp.h:57
static const WCHAR szJournalFileName[]
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
CTestList(CTest *Test)
Definition: CTestList.cpp:16
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CSIDL_APPDATA
Definition: shlobj.h:2037
#define MAX_PATH
Definition: compat.h:34
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
static const WCHAR L[]
Definition: oid.c:1250
#define S_OK
Definition: intsafe.h:52
#define NULL
Definition: types.h:112
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2447

◆ ~CJournaledTestList()

CJournaledTestList::~CJournaledTestList ( )

Destructs a CJournaledTestList object.

Definition at line 49 of file CJournaledTestList.cpp.

50 {
53 }
#define CloseHandle
Definition: compat.h:598
#define INVALID_HANDLE_VALUE
Definition: compat.h:590

Member Function Documentation

◆ GetNextTestInfo()

CTestInfo * CJournaledTestList::GetNextTestInfo ( )
virtual

Interface to other classes for receiving information about the next test to be run.

Returns
A pointer to a CTestInfo object, which contains all available information about the next test. The caller needs to free that object.

Implements CTestList.

Definition at line 276 of file CJournaledTestList.cpp.

277 {
278  CTestInfo* TestInfo;
279 
280  /* Always jump to the next test here.
281  - If we're at the beginning of a new test list, the iterator will be set to 0.
282  - If we started with a loaded one, we assume that the test m_ListIterator is currently set
283  to crashed, so we move to the next test. */
284  ++m_ListIterator;
285 
286  /* Check whether the iterator would already exceed the number of stored elements */
287  if(m_ListIterator == m_List.size())
288  {
289  /* Delete the journal and return no pointer */
290  DeleteFileW(m_JournalFile.c_str());
291 
292  TestInfo = NULL;
293  }
294  else
295  {
296  /* Update the journal with the current iterator and return the test information */
297  UpdateJournal();
298 
299  TestInfo = new CTestInfo(m_List[m_ListIterator]);
300  }
301 
302  return TestInfo;
303 }
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
vector< CTestInfo > m_List
#define NULL
Definition: types.h:112
size_type size() const
Definition: _vector.h:192

◆ LoadJournalFile()

void CJournaledTestList::LoadJournalFile ( )
private

Loads the existing journal file and sets all members to the values saved in that file.

Definition at line 195 of file CJournaledTestList.cpp.

196 {
197  char* Buffer;
198  char* pBuffer;
199  char FileHeader[sizeof(szJournalHeader)];
201  DWORD RemainingSize;
202 
203  StringOut("Loading journal file...\n\n");
204 
206  RemainingSize = GetFileSize(m_hJournal, NULL);
207 
208  /* Verify the header of the journal file */
209  ReadFile(m_hJournal, FileHeader, sizeof(szJournalHeader), &BytesRead, NULL);
210  RemainingSize -= BytesRead;
211 
212  if(BytesRead != sizeof(szJournalHeader))
213  EXCEPTION("Journal file contains no header!\n");
214 
215  if(strcmp(FileHeader, szJournalHeader))
216  EXCEPTION("Journal file has an unsupported header!\n");
217 
218  /* Read the iterator */
220  RemainingSize -= BytesRead;
221 
222  if(BytesRead != sizeof(m_ListIterator))
223  EXCEPTION("Journal file contains no m_ListIterator member!\n");
224 
225  /* Read the rest of the file into a buffer */
226  Buffer = new char[RemainingSize];
227  pBuffer = Buffer;
228  ReadFile(m_hJournal, Buffer, RemainingSize, &BytesRead, NULL);
229 
231  m_hJournal = NULL;
232 
233  /* Now recreate the m_List vector out of that information */
234  while(*pBuffer)
235  {
236  CTestInfo TestInfo;
237 
240  UnserializeFromBuffer(&pBuffer, TestInfo.Test);
241 
242  m_List.push_back(TestInfo);
243  }
244 
245  delete[] Buffer;
246 }
static const char szJournalHeader[]
#define CloseHandle
Definition: compat.h:598
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:859
PVOID pBuffer
Definition: bufpool.h:45
#define EXCEPTION(Message)
Definition: precomp.h:56
vector< CTestInfo > m_List
void push_back(const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:379
unsigned long DWORD
Definition: ntddk_ex.h:95
string StringOut(const string &String, bool forcePrint=true)
Definition: tools.cpp:96
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
wstring CommandLine
Definition: CTestInfo.h:11
string Module
Definition: CTestInfo.h:12
void OpenJournal(DWORD DesiredAccess, bool CreateNew=false)
#define GENERIC_READ
Definition: compat.h:135
#define ReadFile(a, b, c, d, e)
Definition: compat.h:601
#define NULL
Definition: types.h:112
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
void UnserializeFromBuffer(char **Buffer, string &Output)
string Test
Definition: CTestInfo.h:13

Referenced by CJournaledTestList().

◆ OpenJournal()

void CJournaledTestList::OpenJournal ( DWORD  DesiredAccess,
bool  CreateNew = false 
)
private

Opens the journal file through the CreateFileW API using the m_hJournal handle.

Parameters
DesiredAccessdwDesiredAccess parameter passed to CreateFileW
CreateNewtrue if the journal file shall be created, false if an existing one shall be opened

Definition at line 65 of file CJournaledTestList.cpp.

66 {
68  m_JournalFile.c_str(),
70  0,
71  NULL,
72  (CreateNew ? CREATE_ALWAYS : OPEN_EXISTING),
74  NULL
75  );
76 
78  FATAL("CreateFileW failed\n");
79 }
#define FATAL(Message)
Definition: precomp.h:57
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2654
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
#define OPEN_EXISTING
Definition: compat.h:634
#define FILE_FLAG_WRITE_THROUGH
Definition: disk.h:47
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define CREATE_ALWAYS
Definition: disk.h:72
#define NULL
Definition: types.h:112
#define CreateFileW
Definition: compat.h:600

Referenced by LoadJournalFile(), UpdateJournal(), and WriteInitialJournalFile().

◆ SerializeIntoJournal() [1/2]

void CJournaledTestList::SerializeIntoJournal ( const string String)
private

Serializes a std::string and writes it into the opened journal file.

Parameters
StringThe std::string to serialize
See also
UnserializeFromBuffer

Definition at line 90 of file CJournaledTestList.cpp.

91 {
93  WriteFile(m_hJournal, String.c_str(), (ULONG)String.size() + 1, &BytesWritten, NULL);
95 }
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:949
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2430
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:25
unsigned long DWORD
Definition: ntddk_ex.h:95
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1

Referenced by WriteInitialJournalFile().

◆ SerializeIntoJournal() [2/2]

void CJournaledTestList::SerializeIntoJournal ( const wstring &  String)
private

Serializes a std::wstring and writes it into the opened journal file.

Parameters
StringThe std::wstring to serialize
See also
UnserializeFromBuffer

Definition at line 106 of file CJournaledTestList.cpp.

107 {
109  WriteFile(m_hJournal, String.c_str(), ((ULONG)String.size() + 1) * sizeof(WCHAR), &BytesWritten, NULL);
111 }
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:949
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2430
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:25
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1

◆ UnserializeFromBuffer() [1/2]

void CJournaledTestList::UnserializeFromBuffer ( char **  Buffer,
string Output 
)
private

Referenced by LoadJournalFile().

◆ UnserializeFromBuffer() [2/2]

void CJournaledTestList::UnserializeFromBuffer ( char **  Buffer,
wstring &  Output 
)
private

Unserializes the next std::wstring from the journal buffer. The passed buffer pointer will point at the next element afterwards.

Parameters
BufferPointer to a pointer to a char array containing the journal buffer
OutputThe std::wstring to unserialize the value into.

Definition at line 141 of file CJournaledTestList.cpp.

142 {
143  Output = wstring((PWSTR)*Buffer);
144  *Buffer += (Output.size() + 1) * sizeof(WCHAR);
145 }
uint16_t * PWSTR
Definition: typedefs.h:56
Definition: bufpool.h:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
Definition: arc.h:85

◆ UpdateJournal()

void CJournaledTestList::UpdateJournal ( )
private

Writes the current m_ListIterator value into the journal.

Definition at line 252 of file CJournaledTestList.cpp.

253 {
255 
257 
258  /* Skip the header */
260 
263 
265  m_hJournal = NULL;
266 }
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:949
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
static const char szJournalHeader[]
#define CloseHandle
Definition: compat.h:598
#define FILE_CURRENT
Definition: winbase.h:113
#define GENERIC_WRITE
Definition: nt_native.h:90
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:25
unsigned long DWORD
Definition: ntddk_ex.h:95
void OpenJournal(DWORD DesiredAccess, bool CreateNew=false)
#define NULL
Definition: types.h:112
#define SetFilePointer
Definition: compat.h:602

Referenced by GetNextTestInfo().

◆ WriteInitialJournalFile()

void CJournaledTestList::WriteInitialJournalFile ( )
private

Gets all tests to be run and writes an initial journal file with this information.

Definition at line 151 of file CJournaledTestList.cpp.

152 {
153  char TerminatingNull = 0;
154  CTestInfo* TestInfo;
156 
157  StringOut("Writing initial journal file...\n\n");
158 
159  m_ListIterator = 0;
160 
161  /* Store all command lines in the m_List vector */
162  while((TestInfo = m_Test->GetNextTestInfo()) != 0)
163  {
164  m_List.push_back(*TestInfo);
165  delete TestInfo;
166  }
167 
168  /* Serialize the vector and the iterator into a file */
169  OpenJournal(GENERIC_WRITE, true);
170 
173 
174  for(size_t i = 0; i < m_List.size(); i++)
175  {
176  SerializeIntoJournal(m_List[i].CommandLine);
177  SerializeIntoJournal(m_List[i].Module);
179  }
180 
181  WriteFile(m_hJournal, &TerminatingNull, sizeof(TerminatingNull), &BytesWritten, NULL);
183 
186 
187  /* m_ListIterator will be incremented before its first use */
188  m_ListIterator = (size_t)-1;
189 }
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:949
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
static const char szJournalHeader[]
#define CloseHandle
Definition: compat.h:598
virtual CTestInfo * GetNextTestInfo()=0
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
#define GENERIC_WRITE
Definition: nt_native.h:90
__kernel_size_t size_t
Definition: linux.h:237
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:25
vector< CTestInfo > m_List
void push_back(const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:379
unsigned long DWORD
Definition: ntddk_ex.h:95
string StringOut(const string &String, bool forcePrint=true)
Definition: tools.cpp:96
void OpenJournal(DWORD DesiredAccess, bool CreateNew=false)
void SerializeIntoJournal(const string &String)
CTest * m_Test
Definition: CTestList.h:11
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 NULL
Definition: types.h:112
size_type size() const
Definition: _vector.h:192

Referenced by CJournaledTestList().

Member Data Documentation

◆ m_hJournal

◆ m_JournalFile

wstring CJournaledTestList::m_JournalFile
private

Definition at line 14 of file CJournaledTestList.h.

Referenced by CJournaledTestList(), GetNextTestInfo(), and OpenJournal().

◆ m_List

vector<CTestInfo> CJournaledTestList::m_List
private

Definition at line 13 of file CJournaledTestList.h.

Referenced by GetNextTestInfo(), LoadJournalFile(), and WriteInitialJournalFile().

◆ m_ListIterator

size_t CJournaledTestList::m_ListIterator
private

The documentation for this class was generated from the following files: