ReactOS  0.4.14-dev-998-g623dd26
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  {
90  ULONG Line;
92  PREFIX_TYPE PrefixType;
93  PCWSTR FullPathName;
94  PREFIX_TYPE FilePartPrefixType;
95  SIZE_T FilePartSize;
96  } TestCases[] =
97  {
98 // { __LINE__, L"C:", PrefixCurrentPath, L"", PrefixCurrentPathWithoutLastPart },
99  { __LINE__, L"C:\\", PrefixNone, L"C:\\" },
100  { __LINE__, L"C:\\test", PrefixNone, L"C:\\test", PrefixCurrentDrive },
101  { __LINE__, L"C:\\test\\", PrefixNone, L"C:\\test\\" },
102  { __LINE__, L"C:/test/", PrefixNone, L"C:\\test\\" },
103 
104  { __LINE__, L"C:\\\\test", PrefixNone, L"C:\\test", PrefixCurrentDrive },
105  { __LINE__, L"test", PrefixCurrentPath, L"\\test", PrefixCurrentPath, sizeof(WCHAR) },
106  { __LINE__, L"\\test", PrefixCurrentDrive, L"test", PrefixCurrentDrive },
107  { __LINE__, L"/test", PrefixCurrentDrive, L"test", PrefixCurrentDrive },
108  { __LINE__, L".\\test", PrefixCurrentPath, L"\\test", PrefixCurrentPath, sizeof(WCHAR) },
109 
110  { __LINE__, L"\\.", PrefixCurrentDrive, L"" },
111  { __LINE__, L"\\.\\", PrefixCurrentDrive, L"" },
112  { __LINE__, L"\\\\.", PrefixNone, L"\\\\.\\" },
113  { __LINE__, L"\\\\.\\", PrefixNone, L"\\\\.\\" },
114  { __LINE__, L"\\\\.\\Something\\", PrefixNone, L"\\\\.\\Something\\" },
115 
116  { __LINE__, L"\\??\\", PrefixCurrentDrive, L"??\\" },
117  { __LINE__, L"\\??\\C:", PrefixCurrentDrive, L"??\\C:", PrefixCurrentDrive, 3 * sizeof(WCHAR) },
118  { __LINE__, L"\\??\\C:\\", PrefixCurrentDrive, L"??\\C:\\" },
119  { __LINE__, L"\\??\\C:\\test", PrefixCurrentDrive, L"??\\C:\\test", PrefixCurrentDrive, 6 * sizeof(WCHAR) },
120  { __LINE__, L"\\??\\C:\\test\\", PrefixCurrentDrive, L"??\\C:\\test\\" },
121 
122  { __LINE__, L"\\\\??\\", PrefixNone, L"\\\\??\\" },
123  { __LINE__, L"\\\\??\\C:", PrefixNone, L"\\\\??\\C:" },
124  { __LINE__, L"\\\\??\\C:\\", PrefixNone, L"\\\\??\\C:\\" },
125  { __LINE__, L"\\\\??\\C:\\test", PrefixNone, L"\\\\??\\C:\\test", PrefixNone, sizeof(L"\\\\??\\C:\\") },
126  { __LINE__, L"\\\\??\\C:\\test\\", PrefixNone, L"\\\\??\\C:\\test\\" },
127  };
128  WCHAR FullPathNameBuffer[MAX_PATH];
130  SIZE_T Length;
131  WCHAR ExpectedPathName[MAX_PATH];
132  SIZE_T FilePartSize;
133  SIZE_T ExpectedFilePartSize;
134  const INT TestCount = sizeof(TestCases) / sizeof(TestCases[0]);
135  INT i;
136  BOOLEAN Okay;
137 
138  for (i = 0; i < TestCount; i++)
139  {
140  trace("i = %d\n", i);
141  switch (TestCases[i].PrefixType)
142  {
143  case PrefixNone:
144  ExpectedPathName[0] = UNICODE_NULL;
145  break;
146  case PrefixCurrentDrive:
147  GetCurrentDirectoryW(sizeof(ExpectedPathName) / sizeof(WCHAR), ExpectedPathName);
148  ExpectedPathName[3] = UNICODE_NULL;
149  break;
150  case PrefixCurrentPath:
151  Length = GetCurrentDirectoryW(sizeof(ExpectedPathName) / sizeof(WCHAR), ExpectedPathName);
152  if (Length == 3 && TestCases[i].FullPathName[0])
153  ExpectedPathName[2] = UNICODE_NULL;
154  break;
155  default:
156  skip("Invalid test!\n");
157  continue;
158  }
159  wcscat(ExpectedPathName, TestCases[i].FullPathName);
160  RtlFillMemory(FullPathNameBuffer, sizeof(FullPathNameBuffer), 0xAA);
161  Length = 0;
162  StartSeh()
164  sizeof(FullPathNameBuffer),
165  FullPathNameBuffer,
166  &ShortName);
168 
169  Okay = CheckStringBuffer(FullPathNameBuffer, Length, sizeof(FullPathNameBuffer), ExpectedPathName);
170  ok(Okay, "Line %lu: Wrong path name '%S', expected '%S'\n", TestCases[i].Line, FullPathNameBuffer, ExpectedPathName);
171 
172  if (!ShortName)
173  FilePartSize = 0;
174  else
175  FilePartSize = ShortName - FullPathNameBuffer;
176 
177  switch (TestCases[i].FilePartPrefixType)
178  {
179  case PrefixNone:
180  ExpectedFilePartSize = 0;
181  break;
182  case PrefixCurrentDrive:
183  ExpectedFilePartSize = sizeof(L"C:\\");
184  break;
185  case PrefixCurrentPath:
186  ExpectedFilePartSize = GetCurrentDirectoryW(0, NULL) * sizeof(WCHAR);
187  if (ExpectedFilePartSize == sizeof(L"C:\\"))
188  ExpectedFilePartSize -= sizeof(WCHAR);
189  break;
191  {
192  WCHAR CurrentPath[MAX_PATH];
194  ExpectedFilePartSize = GetCurrentDirectoryW(sizeof(CurrentPath) / sizeof(WCHAR), CurrentPath) * sizeof(WCHAR) + sizeof(UNICODE_NULL);
195  if (ExpectedFilePartSize == sizeof(L"C:\\"))
196  ExpectedFilePartSize = 0;
197  else
198  {
199  BackSlash = wcsrchr(CurrentPath, L'\\');
200  if (BackSlash)
201  ExpectedFilePartSize -= wcslen(BackSlash + 1) * sizeof(WCHAR);
202  else
203  ok(0, "Line %lu: GetCurrentDirectory returned %S\n", TestCases[i].Line, CurrentPath);
204  }
205  break;
206  }
207  default:
208  skip("Invalid test!\n");
209  continue;
210  }
211  ExpectedFilePartSize += TestCases[i].FilePartSize;
212  if (ExpectedFilePartSize != 0)
213  ExpectedFilePartSize = (ExpectedFilePartSize - sizeof(UNICODE_NULL)) / sizeof(WCHAR);
214  ok(FilePartSize == ExpectedFilePartSize,
215  "Line %lu: FilePartSize = %lu, expected %lu\n", TestCases[i].Line, (ULONG)FilePartSize, (ULONG)ExpectedFilePartSize);
216  }
217 }
218 
220 {
223  ULONG Length;
224 
225  /* Parameter checks */
226  StartSeh()
228  ok(Length == 0, "Length = %lu\n", Length);
230 
231  StartSeh()
233  ok(Length == 0, "Length = %lu\n", Length);
235 
237  StartSeh()
239  ok(Length == 0, "Length = %lu\n", Length);
242  broken(ShortName == NULL) /* Win7 */, "ShortName = %p\n", ShortName);
243 
244  StartSeh()
246  ok(Length == 0, "Length = %lu\n", Length);
248 
250  StartSeh()
252  ok(Length == 0, "Length = %lu\n", Length);
255  broken(ShortName == NULL) /* Win7 */, "ShortName = %p\n", ShortName);
256 
257  StartSeh()
258  Length = RtlGetFullPathName_U(L"C:\\test", 0, NULL, NULL);
259  ok(Length == sizeof(L"C:\\test"), "Length = %lu\n", Length);
261 
262  FileName = L"C:\\test";
264  StartSeh()
266  ok(Length == sizeof(L"C:\\test"), "Length = %lu\n", Length);
269  broken(ShortName == NULL) /* Win7 */, "ShortName = %p\n", ShortName);
270 
271  /* Check the actual functionality with different paths */
272  RunTestCases();
273 }
IN PDCB IN POEM_STRING IN PUNICODE_STRING IN OUT POEM_STRING ShortName
Definition: fatprocs.h:1294
const uint16_t * PCWSTR
Definition: typedefs.h:56
#define TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:55
unsigned char * PUCHAR
Definition: retypes.h:3
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:421
START_TEST(RtlGetFullPathName_U)
#define StartSeh()
Definition: _sntprintf.h:16
int32_t INT
Definition: typedefs.h:57
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 RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
#define MAX_PATH
Definition: compat.h:26
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Definition: ncftp.h:79
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:79
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
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
struct Line Line
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17