ReactOS 0.4.15-dev-8109-gd7be748
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);
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);
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);
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);
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);
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;
72 ok(Status == STATUS_INVALID_PARAMETER, "Status = 0x%lx\n", Status);
73
74 // NULL buffer, zero Length, non-zero MaximumLength.
75 String = ValidString;
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;
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;
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 ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
Status
Definition: gdiplustypes.h:25
NTSYSAPI NTSTATUS NTAPI RtlValidateUnicodeString(_In_ ULONG Flags, _In_ PCUNICODE_STRING String)
Definition: unicode.c:2605
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
__wchar_t WCHAR
Definition: xmlstorage.h:180