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
CheckBuffer(const VOID * Buffer,SIZE_T Size,UCHAR Value)12 CheckBuffer(
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
CheckStringBufferA(const VOID * Buffer,SIZE_T Size,PCSTR Expected,UCHAR Fill)31 CheckStringBufferA(
32 const VOID *Buffer,
33 SIZE_T Size,
34 PCSTR Expected,
35 UCHAR Fill)
36 {
37 const CHAR *Chars = Buffer;
38 const UCHAR *UChars = Buffer;
39 SIZE_T Length = strlen(Expected);
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
CheckStringBufferW(const VOID * Buffer,SIZE_T Size,PCWSTR Expected,UCHAR Fill)69 CheckStringBufferW(
70 const VOID *Buffer,
71 SIZE_T Size,
72 PCWSTR Expected,
73 UCHAR Fill)
74 {
75 const WCHAR *Chars = Buffer;
76 const UCHAR *UChars = Buffer;
77 SIZE_T Length = wcslen(Expected);
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
TestGetCurrentDirectoryA(VOID)109 TestGetCurrentDirectoryA(VOID)
110 {
111 CHAR Buffer[MAX_PATH];
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
119 Length = GetCurrentDirectoryA(0, NULL);
120 ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
121
122 RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
123 Length = GetCurrentDirectoryA(sizeof(Buffer), Buffer);
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);
129 Length = GetCurrentDirectoryA(0, Buffer);
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);
135 Length = GetCurrentDirectoryA(1, Buffer);
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);
141 Length = GetCurrentDirectoryA(2, Buffer);
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);
147 Length = GetCurrentDirectoryA(3, Buffer);
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);
153 Length = GetCurrentDirectoryA(4, Buffer);
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
TestGetCurrentDirectoryW(VOID)161 TestGetCurrentDirectoryW(VOID)
162 {
163 WCHAR Buffer[MAX_PATH];
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
171 Length = GetCurrentDirectoryW(0, NULL);
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);
181 Length = GetCurrentDirectoryW(0, Buffer);
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);
187 Length = GetCurrentDirectoryW(1, Buffer);
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);
193 Length = GetCurrentDirectoryW(2, Buffer);
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);
199 Length = GetCurrentDirectoryW(3, Buffer);
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);
205 Length = GetCurrentDirectoryW(4, Buffer);
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
START_TEST(GetCurrentDirectory)211 START_TEST(GetCurrentDirectory)
212 {
213 TestGetCurrentDirectoryA();
214 TestGetCurrentDirectoryW();
215 }
216