ReactOS  0.4.14-dev-342-gdc047f9
GetCurrentDirectory.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPLv2+ - See COPYING in the top level directory
4  * PURPOSE: Test for GetCurrentDirectory
5  * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include "precomp.h"
9 
10 static
11 BOOLEAN
13  const VOID *Buffer,
14  SIZE_T Size,
15  UCHAR Value)
16 {
17  const UCHAR *Array = Buffer;
18  SIZE_T i;
19 
20  for (i = 0; i < Size; i++)
21  if (Array[i] != Value)
22  {
23  trace("Expected %x, found %x at offset %lu\n", Value, Array[i], (ULONG)i);
24  return FALSE;
25  }
26  return TRUE;
27 }
28 
29 static
30 BOOLEAN
32  const VOID *Buffer,
33  SIZE_T Size,
35  UCHAR Fill)
36 {
37  const CHAR *Chars = Buffer;
38  const UCHAR *UChars = Buffer;
40  SIZE_T i;
41 
42  if (Size < Length)
43  {
44  ok(0, "Size = %lu, Length = %lu\n", (ULONG)Size, (ULONG)Length);
45  return FALSE;
46  }
47 
48  for (i = 0; i < Length; i++)
49  if (Chars[i] != Expected[i])
50  {
51  trace("Expected %x, found %x at offset %lu\n", Expected[i], Chars[i], (ULONG)i);
52  return FALSE;
53  }
54 
55  ok(Chars[i] == 0, "Expected null terminator, found %x at offset %lu\n", Chars[i], (ULONG)i);
56  i++;
57 
58  for (; i < Size; i++)
59  if (UChars[i] != Fill)
60  {
61  trace("Expected %x, found %x at offset %lu\n", Fill, UChars[i], (ULONG)i);
62  return FALSE;
63  }
64  return TRUE;
65 }
66 
67 static
68 BOOLEAN
70  const VOID *Buffer,
71  SIZE_T Size,
73  UCHAR Fill)
74 {
75  const WCHAR *Chars = Buffer;
76  const UCHAR *UChars = Buffer;
78  SIZE_T i;
79 
80  if (Size < Length)
81  {
82  ok(0, "Size = %lu, Length = %lu\n", (ULONG)Size, (ULONG)Length);
83  return FALSE;
84  }
85 
86  for (i = 0; i < Length; i++)
87  if (Chars[i] != Expected[i])
88  {
89  trace("Expected %x, found %x at offset %lu\n", Expected[i], Chars[i], (ULONG)i);
90  return FALSE;
91  }
92 
93  ok(Chars[i] == 0, "Expected null terminator, found %x at offset %lu\n", Chars[i], (ULONG)i);
94  i++;
95 
96  i *= sizeof(WCHAR);
97 
98  for (; i < Size; i++)
99  if (UChars[i] != Fill)
100  {
101  trace("Expected %x, found %x at offset %lu\n", Fill, UChars[i], (ULONG)i);
102  return FALSE;
103  }
104  return TRUE;
105 }
106 
107 static
108 VOID
110 {
112  DWORD Length;
113  BOOL Ret;
114  BOOLEAN Okay;
115 
116  Ret = SetCurrentDirectoryA("C:\\");
117  ok(Ret == TRUE, "SetCurrentDirectory failed with %lu\n", GetLastError());
118 
120  ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
121 
122  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
124  ok(Length == sizeof("C:\\") - 1, "Length = %lu\n", Length);
125  Okay = CheckStringBufferA(Buffer, sizeof(Buffer), "C:\\", 0x55);
126  ok(Okay, "CheckStringBufferA failed\n");
127 
128  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
130  ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
131  Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55);
132  ok(Okay, "CheckBuffer failed\n");
133 
134  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
136  ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
137  Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55);
138  ok(Okay, "CheckBuffer failed\n");
139 
140  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
142  ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
143  Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55);
144  ok(Okay, "CheckBuffer failed\n");
145 
146  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
148  ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
149  Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55);
150  ok(Okay, "CheckBuffer failed\n");
151 
152  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
154  ok(Length == sizeof("C:\\") - 1, "Length = %lu\n", Length);
155  Okay = CheckStringBufferA(Buffer, sizeof(Buffer), "C:\\", 0x55);
156  ok(Okay, "CheckStringBufferA failed\n");
157 }
158 
159 static
160 VOID
162 {
164  DWORD Length;
165  BOOL Ret;
166  BOOLEAN Okay;
167 
168  Ret = SetCurrentDirectoryW(L"C:\\");
169  ok(Ret == TRUE, "SetCurrentDirectory failed with %lu\n", GetLastError());
170 
172  ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
173 
174  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
175  Length = GetCurrentDirectoryW(sizeof(Buffer) / sizeof(WCHAR), Buffer);
176  ok(Length == sizeof("C:\\") - 1, "Length = %lu\n", Length);
177  Okay = CheckStringBufferW(Buffer, sizeof(Buffer), L"C:\\", 0x55);
178  ok(Okay, "CheckStringBufferW failed\n");
179 
180  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
182  ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
183  Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55);
184  ok(Okay, "CheckBuffer failed\n");
185 
186  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
188  ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
189  Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55);
190  ok(Okay, "CheckBuffer failed\n");
191 
192  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
194  ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
195  Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55);
196  ok(Okay, "CheckBuffer failed\n");
197 
198  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
200  ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
201  Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55);
202  ok(Okay, "CheckBuffer failed\n");
203 
204  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
206  ok(Length == sizeof("C:\\") - 1, "Length = %lu\n", Length);
207  Okay = CheckStringBufferW(Buffer, sizeof(Buffer), L"C:\\", 0x55);
208  ok(Okay, "CheckStringBufferW failed\n");
209 }
210 
212 {
215 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define TRUE
Definition: types.h:120
void Fill(HDC hdc, LONG x, LONG y, COLORREF color)
Definition: drawing.cpp:109
static BOOLEAN CheckStringBufferA(const VOID *Buffer, SIZE_T Size, PCSTR Expected, UCHAR Fill)
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char CHAR
Definition: xmlstorage.h:175
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:421
START_TEST(GetCurrentDirectory)
static BOOLEAN CheckStringBufferW(const VOID *Buffer, SIZE_T Size, PCWSTR Expected, UCHAR Fill)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static VOID TestGetCurrentDirectoryA(VOID)
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
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetCurrentDirectory
Definition: winbase.h:3629
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static VOID TestGetCurrentDirectoryW(VOID)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
BOOL WINAPI SetCurrentDirectoryA(IN LPCSTR lpPathName)
Definition: path.c:2205
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
ULONG_PTR SIZE_T
Definition: typedefs.h:78
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2248
#define ok(value,...)
Definition: atltest.h:57
DWORD WINAPI GetCurrentDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2145
unsigned int ULONG
Definition: retypes.h:1
const char * PCSTR
Definition: typedefs.h:51
static BOOLEAN CheckBuffer(const VOID *Buffer, SIZE_T Size, UCHAR Value)
BOOLEAN Expected
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)