ReactOS  0.4.15-dev-1070-ge1a01de
RtlValidateUnicodeString.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS API Tests
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Test for RtlValidateUnicodeString
5  * COPYRIGHT: Copyright 2020 Hermes Belusca-Maito
6  */
7 
8 #include "precomp.h"
9 
11 {
14  UNICODE_STRING ValidString = RTL_CONSTANT_STRING(L"My Wild String!");
15 
16  /* Start with a valid Unicode string */
17  String = ValidString;
18 
19  /* Non-zero flags are unsupported! */
21  ok(Status == STATUS_SUCCESS, "Status = 0x%lx\n", Status);
23  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
24  Status = RtlValidateUnicodeString(0xdeadbeef, &String);
25  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
26 
27  /* Empty string is allowed. Test also the flags. */
28  RtlInitEmptyUnicodeString(&String, NULL, 0);
30  ok(Status == STATUS_SUCCESS, "Status = 0x%lx\n", Status);
32  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
33  Status = RtlValidateUnicodeString(0xdeadbeef, &String);
34  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
35 
36  // With a non-NULL but empty buffer, and zero lengths.
37  RtlInitEmptyUnicodeString(&String, L"", 0);
39  ok(Status == STATUS_SUCCESS, "Status = 0x%lx\n", Status);
41  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
42  Status = RtlValidateUnicodeString(0xdeadbeef, &String);
43  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
44 
45  // With a non-NULL but empty buffer, and zero Length, non-zero MaximumLength.
46  RtlInitEmptyUnicodeString(&String, L"", sizeof(WCHAR));
47  String.Length = 0;
49  ok(Status == STATUS_SUCCESS, "Status = 0x%lx\n", Status);
51  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
52  Status = RtlValidateUnicodeString(0xdeadbeef, &String);
53  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
54 
55  /* NULL pointer is also allowed! Test also the flags. */
57  ok(Status == STATUS_SUCCESS, "Status = 0x%lx\n", Status);
59  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
60  Status = RtlValidateUnicodeString(0xdeadbeef, NULL);
61  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
62 
63 
64  /*
65  * Now test invalid strings.
66  */
67 
68  // NULL buffer but non-zero lengths.
69  String = ValidString;
70  String.Buffer = NULL;
72  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
73 
74  // NULL buffer, zero Length, non-zero MaximumLength.
75  String = ValidString;
76  String.Buffer = NULL;
77  String.Length = 0;
79  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
80 
81  // NULL buffer, non-zero Length, zero MaximumLength
82  // (tests also the case Length > MaximumLength that must fail).
83  String = ValidString;
84  String.Buffer = NULL;
85  String.MaximumLength = 0;
87  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
88 
89  // Non-NULL buffer, non-zero Length, zero MaximumLength.
90  String = ValidString;
91  String.MaximumLength = 0;
93  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
94 
95  /* Non-NULL buffer, odd lengths */
96 
97  String = ValidString;
98  String.Length--; // Length was already >= 2 so it remains > 0.
100  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
101 
102  String.MaximumLength--; // MaximumLength was already >= 2 so it remains > 0.
104  ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
105 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
START_TEST(RtlValidateUnicodeString)
LONG NTSTATUS
Definition: precomp.h:26
static WCHAR String[]
Definition: stringtable.c:55
NTSYSAPI NTSTATUS NTAPI RtlValidateUnicodeString(_In_ ULONG Flags, _In_ PCUNICODE_STRING String)
Definition: unicode.c:2544
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
#define ok(value,...)
Definition: atltest.h:57
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14