ReactOS  0.4.14-dev-384-g5b37caa
symtest.c
Go to the documentation of this file.
1 // ntest.cpp : Defines the entry point for the console application.
2 //
3 #include "stdafx.h"
4 #include "windows.h"
5 #include "ntndk.h"
6 
9 
10 #define TEST_ASSERT( exp ) \
11  ((!(exp)) ? \
12  (printf("%s, %s, %d\n", #exp, __FILE__, __LINE__), Failures++, FALSE) : \
13  TRUE), Runs++
14 
15 HANDLE
17 {
19  HANDLE LinkHandle;
21  UNICODE_STRING TargetName2 = RTL_CONSTANT_STRING(L"\\");
22  UNICODE_STRING TargetName3 = RTL_CONSTANT_STRING(L"\\");
23  UNICODE_STRING TargetName4 = RTL_CONSTANT_STRING(L"\\");
24  UNICODE_STRING TargetName5 = RTL_CONSTANT_STRING(L"\\");
25  UNICODE_STRING OkName = RTL_CONSTANT_STRING(L"\\OddLink");
26  UNICODE_STRING OkName2 = RTL_CONSTANT_STRING(L"\\TestLink");
27 
28  //
29  // Test1: Empty Attributes
30  //
31  {
33  Status = NtCreateSymbolicLinkObject(&LinkHandle,
35  &Test1,
36  &TargetName);
38  }
39 
40  //
41  // Test2: No Attributes
42  //
43  {
45  Status = NtCreateSymbolicLinkObject(&LinkHandle,
47  Test2,
48  &TargetName);
50  }
51 
52  //
53  // Test3: Attributes with an empty name
54  //
55  {
56  UNICODE_STRING TestName1 = {0, 0, NULL};
58  Status = NtCreateSymbolicLinkObject(&LinkHandle,
60  &Test3,
61  &TargetName);
63  }
64 
65  //
66  // Test4: Attributes with an invalid name
67  //
68  {
69  UNICODE_STRING TestName2 = {10, 12, UlongToPtr(0x81000000)};
70  OBJECT_ATTRIBUTES Test4 = RTL_INIT_OBJECT_ATTRIBUTES(&TestName2, 0);
71  Status = NtCreateSymbolicLinkObject(&LinkHandle,
73  &Test4,
74  &TargetName);
76  }
77 
78  //
79  // Test5: Target with an odd name len
80  //
81  {
82  UNICODE_STRING OddName = RTL_CONSTANT_STRING(L"\\TestLink");
84  TargetName3.Length--;
85  Status = NtCreateSymbolicLinkObject(&LinkHandle,
87  &Test5,
88  &TargetName3);
90  }
91 
92  //
93  // Test6: Target with an emtpy name len
94  //
95  {
97  TargetName4.MaximumLength = 0;
98  Status = NtCreateSymbolicLinkObject(&LinkHandle,
100  &Test5,
101  &TargetName4);
103  }
104 
105  //
106  // Test7: Target with an name len larger then maxlen
107  //
108  {
109  OBJECT_ATTRIBUTES Test6 = RTL_INIT_OBJECT_ATTRIBUTES(&OkName, 0);
110  TargetName5.Length = TargetName5.MaximumLength + 2;
111  Status = NtCreateSymbolicLinkObject(&LinkHandle,
113  &Test6,
114  &TargetName5);
116  }
117 
118  //
119  // Test5: Target with an odd name maxlen
120  //
121  {
122  OBJECT_ATTRIBUTES Test5 = RTL_INIT_OBJECT_ATTRIBUTES(&OkName, 0);
123  TargetName2.MaximumLength--;
124  TEST_ASSERT(TargetName2.MaximumLength % sizeof(WCHAR));
125  Status = NtCreateSymbolicLinkObject(&LinkHandle,
127  &Test5,
128  &TargetName2);
129  *OddLink = LinkHandle;
131  TEST_ASSERT(TargetName2.MaximumLength % sizeof(WCHAR));
132  }
133 
134  //
135  // Test6: collission
136  //
137  {
138  OBJECT_ATTRIBUTES Test6 = RTL_INIT_OBJECT_ATTRIBUTES(&OkName, 0);
139  TargetName2.MaximumLength++;
140  Status = NtCreateSymbolicLinkObject(&LinkHandle,
142  &Test6,
143  &TargetName2);
145  }
146 
147  //
148  // Test7: OK!
149  //
150  {
151  OBJECT_ATTRIBUTES Test7 = RTL_INIT_OBJECT_ATTRIBUTES(&OkName2, 0);
152  Status = NtCreateSymbolicLinkObject(&LinkHandle,
154  &Test7,
155  &TargetName2);
157  }
158 
159  //
160  // Return the last valid handle
161  //
162  return LinkHandle;
163 };
164 
165 
166 int _tmain(int argc, _TCHAR* argv[])
167 {
169  HANDLE LinkHandle, OddHandle;
170  WCHAR TargetBuffer[MAX_PATH] = {0};
171  WCHAR TargetBuffer2[MAX_PATH] = {0};
173  UNICODE_STRING TargetName2;
174  UNICODE_STRING OkName = RTL_CONSTANT_STRING(L"\\TestLink");
175  ULONG NameSize;
176 
177  //
178  // Start with the create tests
179  //
180  LinkHandle = SymlinkCreateTests(&OddHandle);
181 
182  //
183  // Setup the two empty strings. One will have a magic-char at the end
184  //
185  RtlInitEmptyUnicodeString(&TargetName, TargetBuffer, sizeof(TargetBuffer));
186  RtlInitEmptyUnicodeString(&TargetName2, TargetBuffer2, sizeof(TargetBuffer2));
187 
188  //
189  // Now query the odd link
190  //
191  Status = NtQuerySymbolicLinkObject(OddHandle,
192  &TargetName,
193  &NameSize);
195  TEST_ASSERT(NameSize == sizeof(WCHAR));
196  TEST_ASSERT(TargetName.Length == NameSize);
198  NtClose(OddHandle);
199 
200  //
201  // Now query the test link
202  //
203  Status = NtQuerySymbolicLinkObject(LinkHandle,
204  &TargetName,
205  &NameSize);
207  TEST_ASSERT(NameSize == 2 * sizeof(WCHAR));
208  TEST_ASSERT(TargetName.Length == NameSize - sizeof(WCHAR));
210 
211  //
212  // Corrupt the characters
213  //
214  TargetName.Buffer[(NameSize - 2) / sizeof(WCHAR)] = 'v';
215  TargetName.Buffer[(NameSize - 3) / sizeof(WCHAR)] = 'v';
216 
217  //
218  // Now query the test link
219  //
220  Status = NtQuerySymbolicLinkObject(LinkHandle,
221  &TargetName,
222  &NameSize);
225  TEST_ASSERT(TargetName.Buffer[1] == UNICODE_NULL);
226 
227  //
228  // Corrupt the characters
229  //
230  TargetName.Buffer[(NameSize - 2) / sizeof(WCHAR)] = 'v';
231  TargetName.Buffer[(NameSize - 3) / sizeof(WCHAR)] = 'v';
232 
233  //
234  // Now query the test link
235  //
236  Status = NtQuerySymbolicLinkObject(LinkHandle,
237  &TargetName,
238  NULL);
241  TEST_ASSERT(TargetName.Buffer[1] == 'v');
242 
243  //
244  // Print out results
245  //
246  {
247  RTL_OSVERSIONINFOW VersionInfo;
248  VersionInfo.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOW);
249  RtlGetVersion(&VersionInfo);
250  printf("Test complete on: %d\n", VersionInfo.dwBuildNumber);
251  printf("Number of Failures: %d\n", Failures);
252  printf("Number of Runs: %d\n", Runs);
253  }
254  return 0;
255 }
256 
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
static int argc
Definition: ServiceArgs.c:12
#define RTL_INIT_OBJECT_ATTRIBUTES(n, a)
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define argv
Definition: mplay32.c:18
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
VOID Test3(PTEST Test, HANDLE hEvent)
Definition: tmrqueue.c:266
VOID Test1(PTEST Test, HANDLE hEvent)
Definition: tmrqueue.c:155
int _tmain(int argc, _TCHAR *argv[])
Definition: symtest.c:166
#define UNICODE_NULL
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
smooth NULL
Definition: ftsmooth.c:416
HANDLE SymlinkCreateTests(OUT PHANDLE OddLink)
Definition: symtest.c:16
struct _OSVERSIONINFOW RTL_OSVERSIONINFOW
#define UlongToPtr(u)
Definition: config.h:106
char _TCHAR
Definition: tchar.h:1392
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:242
#define MAX_PATH
Definition: compat.h:26
ULONG Failures
Definition: symtest.c:8
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
ULONG dwBuildNumber
Definition: rtltypes.h:245
static const WCHAR L[]
Definition: oid.c:1250
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
WCHAR TargetName[256]
Definition: arping.c:27
ULONG Runs
Definition: symtest.c:7
Status
Definition: gdiplustypes.h:24
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
#define TEST_ASSERT(exp)
Definition: symtest.c:10
VOID Test2(PTEST Test, HANDLE hEvent)
Definition: tmrqueue.c:192
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
#define printf
Definition: config.h:203
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14