ReactOS  0.4.14-dev-317-g96040ec
RtlGetFullPathName_U.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 RtlGetFullPathName_U
5  * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include "precomp.h"
9 
10 /*
11 ULONG
12 NTAPI
13 RtlGetFullPathName_U(
14  IN PCWSTR FileName,
15  IN ULONG Size,
16  IN PWSTR Buffer,
17  OUT PWSTR *ShortName
18 );
19 */
20 
21 static
22 BOOLEAN
24  PCWSTR Buffer,
25  SIZE_T Length,
28 {
29  SIZE_T ExpectedLength = wcslen(Expected) * sizeof(WCHAR);
30  SIZE_T EqualLength;
32  SIZE_T i;
33 
34  if (Length != ExpectedLength)
35  {
36  ok(0, "String length is %lu, expected %lu\n", (ULONG)Length, (ULONG)ExpectedLength);
37  Result = FALSE;
38  }
39 
40  EqualLength = RtlCompareMemory(Buffer, Expected, Length);
41  if (EqualLength != Length)
42  {
43  ok(0, "String is '%S', expected '%S'\n", Buffer, Expected);
44  Result = FALSE;
45  }
46 
47  if (Buffer[Length / sizeof(WCHAR)] != UNICODE_NULL)
48  {
49  ok(0, "Not null terminated\n");
50  Result = FALSE;
51  }
52 
53  /* The function nulls the rest of the buffer! */
54  for (i = Length + sizeof(UNICODE_NULL); i < MaximumLength; i++)
55  {
56  UCHAR Char = ((PUCHAR)Buffer)[i];
57  if (Char != 0)
58  {
59  ok(0, "Found 0x%x at offset %lu, expected 0x%x\n", Char, (ULONG)i, 0);
60  /* Don't count this as a failure unless the string was actually wrong */
61  //Result = FALSE;
62  /* Don't flood the log */
63  break;
64  }
65  }
66 
67  return Result;
68 }
69 
70 /* winetest_platform is "windows" for us, so broken() doesn't do what it should :( */
71 #undef broken
72 #define broken(x) 0
73 
74 typedef enum
75 {
80 } PREFIX_TYPE;
81 
82 static
83 VOID
85 {
86  /* TODO: don't duplicate this in the other tests */
87  /* TODO: Drive Relative tests don't work yet if the current drive isn't C: */
88  struct
89  {
91  PREFIX_TYPE PrefixType;
92  PCWSTR FullPathName;
93  PREFIX_TYPE FilePartPrefixType;
94  SIZE_T FilePartSize;
95  } TestCases[] =
96  {
98  { L"C:\\", PrefixNone, L"C:\\" },
99  { L"C:\\test", PrefixNone, L"C:\\test", PrefixCurrentDrive },
100  { L"C:\\test\\", PrefixNone, L"C:\\test\\" },
101  { L"C:/test/", PrefixNone, L"C:\\test\\" },
102 
103  { L"C:\\\\test", PrefixNone, L"C:\\test", PrefixCurrentDrive },
104  { L"test", PrefixCurrentPath, L"\\test", PrefixCurrentPath, sizeof(WCHAR) },
105  { L"\\test", PrefixCurrentDrive, L"test", PrefixCurrentDrive },
106  { L"/test", PrefixCurrentDrive, L"test", PrefixCurrentDrive },
107  { L".\\test", PrefixCurrentPath, L"\\test", PrefixCurrentPath, sizeof(WCHAR) },
108 
109  { L"\\.", PrefixCurrentDrive, L"" },
110  { L"\\.\\", PrefixCurrentDrive, L"" },
111  { L"\\\\.", PrefixNone, L"\\\\.\\" },
112  { L"\\\\.\\", PrefixNone, L"\\\\.\\" },
113  { L"\\\\.\\Something\\", PrefixNone, L"\\\\.\\Something\\" },
114 
115  { L"\\??\\", PrefixCurrentDrive, L"??\\" },
116  { L"\\??\\C:", PrefixCurrentDrive, L"??\\C:", PrefixCurrentDrive, 3 * sizeof(WCHAR) },
117  { L"\\??\\C:\\", PrefixCurrentDrive, L"??\\C:\\" },
118  { L"\\??\\C:\\test", PrefixCurrentDrive, L"??\\C:\\test", PrefixCurrentDrive, 6 * sizeof(WCHAR) },
119  { L"\\??\\C:\\test\\", PrefixCurrentDrive, L"??\\C:\\test\\" },
120 
121  { L"\\\\??\\", PrefixNone, L"\\\\??\\" },
122  { L"\\\\??\\C:", PrefixNone, L"\\\\??\\C:" },
123  { L"\\\\??\\C:\\", PrefixNone, L"\\\\??\\C:\\" },
124  { L"\\\\??\\C:\\test", PrefixNone, L"\\\\??\\C:\\test", PrefixNone, sizeof(L"\\\\??\\C:\\") },
125  { L"\\\\??\\C:\\test\\", PrefixNone, L"\\\\??\\C:\\test\\" },
126  };
127  WCHAR FullPathNameBuffer[MAX_PATH];
129  SIZE_T Length;
130  WCHAR ExpectedPathName[MAX_PATH];
131  SIZE_T FilePartSize;
132  SIZE_T ExpectedFilePartSize;
133  const INT TestCount = sizeof(TestCases) / sizeof(TestCases[0]);
134  INT i;
135  BOOLEAN Okay;
136 
137  for (i = 0; i < TestCount; i++)
138  {
139  trace("i = %d\n", i);
140  switch (TestCases[i].PrefixType)
141  {
142  case PrefixNone:
143  ExpectedPathName[0] = UNICODE_NULL;
144  break;
145  case PrefixCurrentDrive:
146  GetCurrentDirectoryW(sizeof(ExpectedPathName) / sizeof(WCHAR), ExpectedPathName);
147  ExpectedPathName[3] = UNICODE_NULL;
148  break;
149  case PrefixCurrentPath:
150  Length = GetCurrentDirectoryW(sizeof(ExpectedPathName) / sizeof(WCHAR), ExpectedPathName);
151  if (Length == 3 && TestCases[i].FullPathName[0])
152  ExpectedPathName[2] = UNICODE_NULL;
153  break;
154  default:
155  skip("Invalid test!\n");
156  continue;
157  }
158  wcscat(ExpectedPathName, TestCases[i].FullPathName);
159  RtlFillMemory(FullPathNameBuffer, sizeof(FullPathNameBuffer), 0xAA);
160  Length = 0;
161  StartSeh()
163  sizeof(FullPathNameBuffer),
164  FullPathNameBuffer,
165  &ShortName);
167 
168  Okay = CheckStringBuffer(FullPathNameBuffer, Length, sizeof(FullPathNameBuffer), ExpectedPathName);
169  ok(Okay, "Wrong path name '%S', expected '%S'\n", FullPathNameBuffer, ExpectedPathName);
170 
171  if (!ShortName)
172  FilePartSize = 0;
173  else
174  FilePartSize = ShortName - FullPathNameBuffer;
175 
176  switch (TestCases[i].FilePartPrefixType)
177  {
178  case PrefixNone:
179  ExpectedFilePartSize = 0;
180  break;
181  case PrefixCurrentDrive:
182  ExpectedFilePartSize = sizeof(L"C:\\");
183  break;
184  case PrefixCurrentPath:
185  ExpectedFilePartSize = GetCurrentDirectoryW(0, NULL) * sizeof(WCHAR);
186  if (ExpectedFilePartSize == sizeof(L"C:\\"))
187  ExpectedFilePartSize -= sizeof(WCHAR);
188  break;
190  {
191  WCHAR CurrentPath[MAX_PATH];
193  ExpectedFilePartSize = GetCurrentDirectoryW(sizeof(CurrentPath) / sizeof(WCHAR), CurrentPath) * sizeof(WCHAR) + sizeof(UNICODE_NULL);
194  if (ExpectedFilePartSize == sizeof(L"C:\\"))
195  ExpectedFilePartSize = 0;
196  else
197  {
198  BackSlash = wcsrchr(CurrentPath, L'\\');
199  if (BackSlash)
200  ExpectedFilePartSize -= wcslen(BackSlash + 1) * sizeof(WCHAR);
201  else
202  ok(0, "GetCurrentDirectory returned %S\n", CurrentPath);
203  }
204  break;
205  }
206  default:
207  skip("Invalid test!\n");
208  continue;
209  }
210  ExpectedFilePartSize += TestCases[i].FilePartSize;
211  if (ExpectedFilePartSize != 0)
212  ExpectedFilePartSize = (ExpectedFilePartSize - sizeof(UNICODE_NULL)) / sizeof(WCHAR);
213  ok(FilePartSize == ExpectedFilePartSize,
214  "FilePartSize = %lu, expected %lu\n", (ULONG)FilePartSize, (ULONG)ExpectedFilePartSize);
215  }
216 }
217 
219 {
222  ULONG Length;
223 
224  /* Parameter checks */
225  StartSeh()
227  ok(Length == 0, "Length = %lu\n", Length);
229 
230  StartSeh()
232  ok(Length == 0, "Length = %lu\n", Length);
234 
236  StartSeh()
238  ok(Length == 0, "Length = %lu\n", Length);
241  broken(ShortName == NULL) /* Win7 */, "ShortName = %p\n", ShortName);
242 
243  StartSeh()
245  ok(Length == 0, "Length = %lu\n", Length);
247 
249  StartSeh()
251  ok(Length == 0, "Length = %lu\n", Length);
254  broken(ShortName == NULL) /* Win7 */, "ShortName = %p\n", ShortName);
255 
256  StartSeh()
257  Length = RtlGetFullPathName_U(L"C:\\test", 0, NULL, NULL);
258  ok(Length == sizeof(L"C:\\test"), "Length = %lu\n", Length);
260 
261  FileName = L"C:\\test";
263  StartSeh()
265  ok(Length == sizeof(L"C:\\test"), "Length = %lu\n", Length);
268  broken(ShortName == NULL) /* Win7 */, "ShortName = %p\n", ShortName);
269 
270  /* Check the actual functionality with different paths */
271  RunTestCases();
272 }
IN PDCB IN POEM_STRING IN PUNICODE_STRING IN OUT POEM_STRING ShortName
Definition: fatprocs.h:1294
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:54
unsigned char * PUCHAR
Definition: retypes.h:3
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:413
START_TEST(RtlGetFullPathName_U)
#define StartSeh()
Definition: _sntprintf.h:16
int32_t INT
Definition: typedefs.h:56
static BOOLEAN CheckStringBuffer(PCWSTR Buffer, SIZE_T Length, SIZE_T MaximumLength, PCWSTR Expected)
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 UNICODE_NULL
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcsrchr(_In_z_ const wchar_t *_Str, _In_ wchar_t _Ch)
Definition: bufpool.h:45
static VOID RunTestCases(VOID)
#define InvalidPointer
NTSYSAPI ULONG NTAPI RtlGetFullPathName_U(_In_ PCWSTR FileName, _In_ ULONG Size, _Out_z_bytecap_(Size) PWSTR Buffer, _Out_opt_ PWSTR *ShortName)
Definition: path.c:1868
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static TEST_CASE TestCases[]
Definition: CommandLine.c:101
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
UnicodeString MaximumLength
Definition: rtlfuncs.h:2982
ULONG_PTR SIZE_T
Definition: typedefs.h:78
struct _FileName FileName
Definition: fatprocs.h:884
#define broken(x)
#define ok(value,...)
Definition: atltest.h:57
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define skip(...)
Definition: atltest.h:64
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN Expected
static const WCHAR BackSlash[]
Definition: devclass.c:29
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17