ReactOS  0.4.15-dev-3303-g1ade494
RtlUnicodeStringToCountedOemString.c File Reference
#include "precomp.h"
Include dependency graph for RtlUnicodeStringToCountedOemString.c:

Go to the source code of this file.

Functions

 START_TEST (RtlUnicodeStringToCountedOemString)
 

Variables

struct {
   ULONG   AnsiCp
 
   ULONG   OemCp
 
   const UNICODE_STRING   StrU
 
   NTSTATUS   Status
 
   const OEM_STRING   StrOem
 
TestData []
 

Function Documentation

◆ START_TEST()

START_TEST ( RtlUnicodeStringToCountedOemString  )

Definition at line 45 of file RtlUnicodeStringToCountedOemString.c.

46 {
47  WCHAR BufferU[10];
48  CHAR BufferOem[10];
49  UNICODE_STRING StringU;
50  OEM_STRING StringOem;
52  int i;
53 
54  memset(BufferU, 0xAA, sizeof(BufferU));
55  memset(BufferOem, 0xAA, sizeof(BufferOem));
56 
57  BufferU[0] = L'A';
58  BufferU[1] = UNICODE_NULL;
59 
60  StringU.Buffer = BufferU;
61  StringU.MaximumLength = 10 * sizeof(WCHAR);
62 
63  RtlInitUnicodeString(&StringU, BufferU);
64  ok(StringU.Length == 1 * sizeof(WCHAR), "Invalid size: %d\n", StringU.Length);
65  ok(StringU.MaximumLength == 2 * sizeof(WCHAR), "Invalid size: %d\n", StringU.MaximumLength);
66  ok(StringU.Buffer == BufferU, "Invalid buffer: %p\n", StringU.Buffer);
67 
68  StringOem.Buffer = BufferOem;
69  StringOem.Length = 0;
70  StringOem.MaximumLength = 10 * sizeof(CHAR);
71 
72  Status = RtlUnicodeStringToCountedOemString(&StringOem, &StringU, FALSE);
73  ok(NT_SUCCESS(Status), "RtlUnicodeStringToCountedOemString failed: %lx\n", Status);
74  ok(StringOem.Length == 1 * sizeof(CHAR), "Invalid size: %d\n", StringOem.Length);
75  ok(StringOem.MaximumLength == 10 * sizeof(CHAR), "Invalid size: %d\n", StringOem.MaximumLength);
76  ok(StringOem.Buffer == BufferOem, "Invalid buffer: %p\n", StringOem.Buffer);
77 
78  ok(BufferOem[0] == 'A', "Unexpected first char 0x%02x for OEM string.\n", BufferOem[0]);
79  for (i = 1; i < 10; ++i)
80  {
81  ok(BufferOem[i] == (CHAR)0xAA, "Unexpected char 0x%02x at position %d.\n", BufferOem[i], i);
82  }
83 
84  ok(i == 10, "String was not null terminated!\n");
85 
86  /* Test buffer overflow */
87  wcsncpy(BufferU, L"Test", _countof(BufferU));
88  RtlInitUnicodeString(&StringU, BufferU);
89  StringU.MaximumLength = sizeof(BufferU);
90  StringOem.Buffer = BufferOem;
91  StringOem.MaximumLength = 1 * sizeof(CHAR);
92  StringOem.Length = 0;
93  memset(BufferOem, 0xAA, sizeof(BufferOem));
94 
95  Status = RtlUnicodeStringToCountedOemString(&StringOem, &StringU, FALSE);
97  ok(StringOem.Length == 4 * sizeof(CHAR), "Invalid size: %d\n", StringOem.Length);
98  ok(StringOem.MaximumLength == 1 * sizeof(CHAR), "Invalid size: %d\n", StringOem.MaximumLength);
99  ok(StringOem.Buffer == BufferOem, "Invalid buffer: %p\n", StringOem.Buffer);
100 
101  for (i = 0; i < 10; ++i)
102  {
103  ok(BufferOem[i] == (CHAR)0xAA, "Unexpected char 0x%02x at position %d.\n", BufferOem[i], i);
104  }
105 
106  for (i = 0; i < _countof(TestData); i++)
107  {
109 
110  trace("Testing locale %u. ANSI: %u, OEM %u\n", i, (UINT)TestData[i].AnsiCp, (UINT)TestData[i].OemCp);
111 
112  /* Get the right length */
113  StringOem.Buffer = NULL;
114  StringOem.Length = 0;
115  StringOem.MaximumLength = 0;
116 
117  Status = RtlUnicodeStringToCountedOemString(&StringOem, &TestData[i].StrU, FALSE);
119  ok_long(StringOem.Length, TestData[i].StrOem.Length);
120  ok_long(StringOem.MaximumLength, 0);
121 
122  StringOem.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, StringOem.Length);
123  StringOem.MaximumLength = StringOem.Length;
124  StringOem.Length = 0;
125 
126  Status = RtlUnicodeStringToCountedOemString(&StringOem, &TestData[i].StrU, FALSE);
128 
129  ok_long(StringOem.Length, TestData[i].StrOem.Length);
130  ok_long(StringOem.MaximumLength, TestData[i].StrOem.Length); /* Untouched */
131  ok_long(memcmp(StringOem.Buffer, TestData[i].StrOem.Buffer, min(StringOem.Length, TestData[i].StrOem.Length)), 0);
132 
133  RtlFreeHeap(RtlGetProcessHeap(), 0, StringOem.Buffer);
134  }
135 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
USHORT MaximumLength
Definition: env_spec_w32.h:370
void SetupLocale(ULONG AnsiCode, ULONG OemCode, ULONG Unicode)
Definition: IsTextUnicode.c:38
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
STRING OEM_STRING
Definition: umtypes.h:203
#define ok_long(expression, result)
Definition: atltest.h:133
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
Status
Definition: gdiplustypes.h:24
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define _countof(array)
Definition: sndvol32.h:68
static const WCHAR L[]
Definition: oid.c:1250
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
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 ok(value,...)
Definition: atltest.h:57
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
const UNICODE_STRING StrU
#define memset(x, y, z)
Definition: compat.h:39
#define CHAR(Char)

Variable Documentation

◆ AnsiCp

ULONG AnsiCp

Definition at line 12 of file RtlUnicodeStringToCountedOemString.c.

Referenced by START_TEST().

◆ OemCp

ULONG OemCp

Definition at line 13 of file RtlUnicodeStringToCountedOemString.c.

Referenced by START_TEST().

◆ Status

Definition at line 15 of file RtlUnicodeStringToCountedOemString.c.

Referenced by START_TEST().

◆ StrOem

const OEM_STRING StrOem

Definition at line 16 of file RtlUnicodeStringToCountedOemString.c.

◆ StrU

Definition at line 14 of file RtlUnicodeStringToCountedOemString.c.

Referenced by InitTestData(), and START_TEST().

◆ TestData

const { ... } TestData[]
Initial value:
=
{
{
1252, 932,
RTL_CONSTANT_STRING(L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7"),
},
{
932, 1252,
RTL_CONSTANT_STRING(L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7"),
},
{
932, 932,
RTL_CONSTANT_STRING(L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7"),
},
{
1252, 1252,
RTL_CONSTANT_STRING(L"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7"),
},
}
static const WCHAR L[]
Definition: oid.c:1250
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define STATUS_UNMAPPABLE_CHARACTER
Definition: ntstatus.h:590
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14