ReactOS 0.4.15-dev-7994-gb388cb6
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
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 {
35 &Test1,
36 &TargetName);
38 }
39
40 //
41 // Test2: No Attributes
42 //
43 {
47 Test2,
48 &TargetName);
50 }
51
52 //
53 // Test3: Attributes with an empty name
54 //
55 {
56 UNICODE_STRING TestName1 = {0, 0, NULL};
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);
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--;
87 &Test5,
88 &TargetName3);
90 }
91
92 //
93 // Test6: Target with an emtpy name len
94 //
95 {
97 TargetName4.MaximumLength = 0;
100 &Test5,
101 &TargetName4);
103 }
104
105 //
106 // Test7: Target with an name len larger then maxlen
107 //
108 {
110 TargetName5.Length = TargetName5.MaximumLength + 2;
113 &Test6,
114 &TargetName5);
116 }
117
118 //
119 // Test5: Target with an odd name maxlen
120 //
121 {
123 TargetName2.MaximumLength--;
124 TEST_ASSERT(TargetName2.MaximumLength % sizeof(WCHAR));
127 &Test5,
128 &TargetName2);
129 *OddLink = LinkHandle;
131 TEST_ASSERT(TargetName2.MaximumLength % sizeof(WCHAR));
132 }
133
134 //
135 // Test6: collission
136 //
137 {
139 TargetName2.MaximumLength++;
142 &Test6,
143 &TargetName2);
145 }
146
147 //
148 // Test7: OK!
149 //
150 {
154 &Test7,
155 &TargetName2);
157 }
158
159 //
160 // Return the last valid handle
161 //
162 return LinkHandle;
163};
164
165
166int _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 //
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 //
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 //
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 //
237 &TargetName,
238 NULL);
241 TEST_ASSERT(TargetName.Buffer[1] == 'v');
242
243 //
244 // Print out results
245 //
246 {
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
static int argc
Definition: ServiceArgs.c:12
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
LONG NTSTATUS
Definition: precomp.h:26
OSVERSIONINFOW VersionInfo
Definition: wkssvc.c:40
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
#define MAX_PATH
Definition: compat.h:34
#define UlongToPtr(u)
Definition: config.h:106
#define printf
Definition: freeldr.h:97
Status
Definition: gdiplustypes.h:25
static void Test1(void)
Definition: himc.c:10
#define _tmain
Definition: tchar.h:497
char _TCHAR
Definition: tchar.h:1392
void Test2(void)
Definition: terminate.cpp:76
#define argv
Definition: mplay32.c:18
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define UNICODE_NULL
#define RTL_INIT_OBJECT_ATTRIBUTES(n, a)
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define L(x)
Definition: ntvdm.h:50
static PCWSTR TargetName
Definition: ping.c:67
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:246
ULONG dwBuildNumber
Definition: rtltypes.h:249
USHORT MaximumLength
Definition: env_spec_w32.h:370
ULONG Runs
Definition: symtest.c:7
ULONG Failures
Definition: symtest.c:8
HANDLE SymlinkCreateTests(OUT PHANDLE OddLink)
Definition: symtest.c:16
#define TEST_ASSERT(exp)
Definition: symtest.c:10
VOID Test3(PTEST Test, HANDLE hEvent)
Definition: tmrqueue.c:266
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
struct _OSVERSIONINFOW RTL_OSVERSIONINFOW
__wchar_t WCHAR
Definition: xmlstorage.h:180