ReactOS 0.4.16-dev-122-g325d74c
IsTextUnicode.c File Reference
#include "precomp.h"
#include <stdio.h>
Include dependency graph for IsTextUnicode.c:

Go to the source code of this file.

Macros

#define INVALID_FLAG   0xFFFFFFFF
 
#define NEW_TEST(Buffer, Flags, ResultFlags, Success)    { __LINE__, (PVOID)(Buffer), sizeof((Buffer)), (Flags), (ResultFlags), (Success) }
 

Functions

PVOID LoadCodePageData (ULONG Code)
 
void SetupLocale (ULONG AnsiCode, ULONG OemCode, ULONG Unicode)
 
 START_TEST (IsTextUnicode)
 

Macro Definition Documentation

◆ INVALID_FLAG

#define INVALID_FLAG   0xFFFFFFFF

◆ NEW_TEST

#define NEW_TEST (   Buffer,
  Flags,
  ResultFlags,
  Success 
)     { __LINE__, (PVOID)(Buffer), sizeof((Buffer)), (Flags), (ResultFlags), (Success) }

Function Documentation

◆ LoadCodePageData()

PVOID LoadCodePageData ( ULONG  Code)

Definition at line 14 of file IsTextUnicode.c.

15{
16 char filename[MAX_PATH], sysdir[MAX_PATH];
18 PVOID Data = NULL;
20
21 if (Code != -1)
22 StringCbPrintfA(filename, sizeof(filename), "%s\\c_%lu.nls", sysdir, Code);
23 else
24 StringCbPrintfA(filename, sizeof(filename), "%s\\l_intl.nls", sysdir);
25
28 {
29 DWORD dwRead;
32 ReadFile(hFile, Data, dwFileSize, &dwRead, NULL);
34 }
35 return Data;
36}
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define FILE_SHARE_READ
Definition: compat.h:136
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2283
unsigned long DWORD
Definition: ntddk_ex.h:95
const char * filename
Definition: ioapi.h:137
DWORD dwFileSize
Definition: more.c:40
_In_ HANDLE hFile
Definition: mswsock.h:90
STRSAFEAPI StringCbPrintfA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:547
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
Definition: wdfdevice.h:1701
#define CreateFile
Definition: winbase.h:3749

Referenced by SetupLocale().

◆ SetupLocale()

void SetupLocale ( ULONG  AnsiCode,
ULONG  OemCode,
ULONG  Unicode 
)

Definition at line 39 of file IsTextUnicode.c.

40{
41 NLSTABLEINFO NlsTable;
42 PVOID AnsiCodePageData;
43 PVOID OemCodePageData;
44 PVOID UnicodeCaseTableData;
45
46 AnsiCodePageData = LoadCodePageData(AnsiCode);
47 OemCodePageData = LoadCodePageData(OemCode);
48 UnicodeCaseTableData = LoadCodePageData(Unicode);
49
50 RtlInitNlsTables(AnsiCodePageData, OemCodePageData, UnicodeCaseTableData, &NlsTable);
51 RtlResetRtlTranslations(&NlsTable);
52 /* Do NOT free the buffers here, they are directly used!
53 Yes, we leak the old buffers, but this is a test anyway... */
54
55}
PVOID LoadCodePageData(ULONG Code)
Definition: IsTextUnicode.c:14
NTSYSAPI VOID NTAPI RtlInitNlsTables(_In_ PUSHORT AnsiTableBase, _In_ PUSHORT OemTableBase, _In_ PUSHORT CaseTableBase, _Out_ PNLSTABLEINFO NlsTable)
NTSYSAPI VOID NTAPI RtlResetRtlTranslations(_In_ PNLSTABLEINFO NlsTable)

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( IsTextUnicode  )

Definition at line 57 of file IsTextUnicode.c.

58{
59#define INVALID_FLAG 0xFFFFFFFF
60
61#define NEW_TEST(Buffer, Flags, ResultFlags, Success) \
62 { __LINE__, (PVOID)(Buffer), sizeof((Buffer)), (Flags), (ResultFlags), (Success) }
63
64 static struct
65 {
66 INT lineno;
67
68 /* Input */
70 INT Size;
71 INT Flags;
72
73 /* Output */
74 INT ResultFlags;
76 } Tests[] =
77 {
78 /* ANSI string */
79 NEW_TEST("ANSI string", IS_TEXT_UNICODE_ASCII16, 0, FALSE),
80 NEW_TEST("ANSI string", IS_TEXT_UNICODE_STATISTICS, 0, FALSE),
81 NEW_TEST("ANSI string", INVALID_FLAG, 0, FALSE),
82
83 /* UNICODE strings */
87 NEW_TEST(L"a", INVALID_FLAG, 0, TRUE),
88
89 NEW_TEST(L"UNICODE String 0", IS_TEXT_UNICODE_ASCII16, 0, FALSE),
92 NEW_TEST(L"UNICODE String 0", INVALID_FLAG, 0, TRUE),
93
94 NEW_TEST(L"\xFEFF" L"UNICODE String 1", IS_TEXT_UNICODE_ASCII16, 0, FALSE),
96 NEW_TEST(L"\xFEFF" L"UNICODE String 1", IS_TEXT_UNICODE_STATISTICS, 0, FALSE),
97 NEW_TEST(L"\xFEFF" L"UNICODE String 1", INVALID_FLAG, 0, TRUE),
98
99 NEW_TEST(L"\xFFFE" L"UNICODE String 2", IS_TEXT_UNICODE_ASCII16, 0, FALSE),
101 NEW_TEST(L"\xFFFE" L"UNICODE String 2", IS_TEXT_UNICODE_STATISTICS, 0, FALSE),
102 NEW_TEST(L"\xFFFE" L"UNICODE String 2", INVALID_FLAG, 0, FALSE),
103
104 NEW_TEST(L"UNICODE String 3 Привет!", IS_TEXT_UNICODE_ASCII16, 0, FALSE),
106 NEW_TEST(L"UNICODE String 3 Привет!", IS_TEXT_UNICODE_STATISTICS, IS_TEXT_UNICODE_STATISTICS, TRUE),
107 NEW_TEST(L"UNICODE String 3 Привет!", INVALID_FLAG, 0, TRUE),
108
109 NEW_TEST(L"\xFEFF" L"UNICODE String 4 Привет!", IS_TEXT_UNICODE_ASCII16, 0, FALSE),
111 NEW_TEST(L"\xFEFF" L"UNICODE String 4 Привет!", IS_TEXT_UNICODE_STATISTICS, 0, FALSE),
112 NEW_TEST(L"\xFEFF" L"UNICODE String 4 Привет!", INVALID_FLAG, 0, TRUE),
113
114 NEW_TEST(L"\xFFFE" L"UNICODE String 5 Привет!", IS_TEXT_UNICODE_ASCII16, 0, FALSE),
115 NEW_TEST(L"\xFFFE" L"UNICODE String 5 Привет!", IS_TEXT_UNICODE_UNICODE_MASK, IS_TEXT_UNICODE_CONTROLS, TRUE),
116 NEW_TEST(L"\xFFFE" L"UNICODE String 5 Привет!", IS_TEXT_UNICODE_STATISTICS, 0, FALSE),
117 NEW_TEST(L"\xFFFE" L"UNICODE String 5 Привет!", INVALID_FLAG, 0, FALSE),
118
119 /* Reverse BOM */
120 NEW_TEST(L"UNICODE S" L"\xFFFE" L"tring 5 Привет!", IS_TEXT_UNICODE_ILLEGAL_CHARS, IS_TEXT_UNICODE_ILLEGAL_CHARS, FALSE),
121 /* UNICODE_NUL */
122 NEW_TEST(L"UNICODE S" L"\x0000" L"tring 5 Привет!", IS_TEXT_UNICODE_ILLEGAL_CHARS, IS_TEXT_UNICODE_ILLEGAL_CHARS, FALSE),
123 /* ASCII CRLF (packed into one word) */
124 NEW_TEST(L"UNICODE S" L"\x0A0D" L"tring 5 Привет!", IS_TEXT_UNICODE_ILLEGAL_CHARS, IS_TEXT_UNICODE_ILLEGAL_CHARS, FALSE),
125 /* Unicode 0xFFFF */
126 NEW_TEST(L"UNICODE S" L"\xFFFF" L"tring 5 Привет!", IS_TEXT_UNICODE_ILLEGAL_CHARS, IS_TEXT_UNICODE_ILLEGAL_CHARS, FALSE),
127
128 NEW_TEST(L"UNICODE String 0", IS_TEXT_UNICODE_DBCS_LEADBYTE, 0, FALSE)
129 };
130
131 const char japanese_with_lead[] = "ABC" "\x83\x40" "D";
132 const char japanese_sjis[] = "\x93\xFA\x96\x7B\x8C\xEA\x31\x32\x33\x93\xFA\x96\x7B\x8C\xEA";
133 const char japanese_utf8[] = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E\x31\x32\x33\xE6\x97\xA5"
134 "\xE6\x9C\xAC\xE8\xAA\x9E";
135 const char simplfied_chinese_with_lead[] = "ABC" "\xC5\xC5" "D";
136 const char korean_with_lead[] = "ABC" "\xBF\xAD" "D";
137 const char traditional_chinese_with_lead[] = "ABC" "\xB1\xC1" "D";
138
139 UINT i;
141 INT Result;
142
143 for (i = 0; i < ARRAYSIZE(Tests); ++i)
144 {
145 Result = Tests[i].Flags;
147 ok(Success == Tests[i].Success, "Line %u: IsTextUnicode() returned 0x%x, expected %s\n", Tests[i].lineno, Success, (Tests[i].Success ? "TRUE" : "FALSE"));
148 if (Result != INVALID_FLAG)
149 ok(Result == Tests[i].ResultFlags, "Line %u: IsTextUnicode() Result returned 0x%x, expected 0x%x\n", Tests[i].lineno, Result, Tests[i].ResultFlags);
150 }
151
152 /* Japanese */
153 SetupLocale(932, 932, -1);
154
156 ok_int(IsTextUnicode(japanese_with_lead, sizeof(japanese_with_lead), &Result), FALSE);
158
159 ok_int(IsTextUnicode(japanese_sjis, sizeof(japanese_sjis) - 1, NULL), FALSE);
160
162 ok_int(IsTextUnicode(japanese_sjis, sizeof(japanese_sjis) - 1, &Result), FALSE);
163 ok_int(Result, 0);
164
167 ok_int(IsTextUnicode(japanese_sjis, sizeof(japanese_sjis) - 1, &Result), FALSE);
169
170 ok_int(IsTextUnicode(japanese_utf8, sizeof(japanese_utf8) - 1, NULL), FALSE);
171
173 ok_int(IsTextUnicode(japanese_utf8, sizeof(japanese_utf8) - 1, &Result), FALSE);
174 ok_int(Result, 0);
175
178 ok_int(IsTextUnicode(japanese_utf8, sizeof(japanese_utf8) - 1, &Result), FALSE);
180
181 /* Simplified Chinese */
182 SetupLocale(936, 936, -1);
183
185 ok(!IsTextUnicode(simplfied_chinese_with_lead, sizeof(simplfied_chinese_with_lead), &Result), "IsTextUnicode() returned TRUE, expected FALSE\n");
186 ok(Result == IS_TEXT_UNICODE_DBCS_LEADBYTE, "Result returned 0x%x, expected 0x%x\n", Result, IS_TEXT_UNICODE_DBCS_LEADBYTE);
187
188 /* Korean */
189 SetupLocale(949, 949, -1);
190
192 ok(!IsTextUnicode(korean_with_lead, sizeof(korean_with_lead), &Result), "IsTextUnicode() returned TRUE, expected FALSE\n");
193 ok(Result == IS_TEXT_UNICODE_DBCS_LEADBYTE, "Result returned 0x%x, expected 0x%x\n", Result, IS_TEXT_UNICODE_DBCS_LEADBYTE);
194
195 /* Traditional Chinese */
196 SetupLocale(950, 950, -1);
197
199 ok(!IsTextUnicode(traditional_chinese_with_lead, sizeof(traditional_chinese_with_lead), &Result), "IsTextUnicode() returned TRUE, expected FALSE\n");
200 ok(Result == IS_TEXT_UNICODE_DBCS_LEADBYTE, "Result returned 0x%x, expected 0x%x\n", Result, IS_TEXT_UNICODE_DBCS_LEADBYTE);
201}
#define NEW_TEST(Buffer, Flags, ResultFlags, Success)
#define INVALID_FLAG
void SetupLocale(ULONG AnsiCode, ULONG OemCode, ULONG Unicode)
Definition: IsTextUnicode.c:39
struct test_data Tests[]
#define ok(value,...)
Definition: atltest.h:57
#define ok_int(expression, result)
Definition: atltest.h:134
Definition: bufpool.h:45
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
BOOL WINAPI IsTextUnicode(IN CONST VOID *lpv, IN INT iSize, IN OUT LPINT lpiResult OPTIONAL)
Definition: unicode.c:27
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
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
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
int32_t INT
Definition: typedefs.h:58
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define IS_TEXT_UNICODE_ILLEGAL_CHARS
Definition: winnt_old.h:894
#define IS_TEXT_UNICODE_UNICODE_MASK
Definition: winnt_old.h:898
#define IS_TEXT_UNICODE_DBCS_LEADBYTE
Definition: winnt_old.h:896
#define IS_TEXT_UNICODE_CONTROLS
Definition: winnt_old.h:890
#define IS_TEXT_UNICODE_STATISTICS
Definition: winnt_old.h:888
#define IS_TEXT_UNICODE_ASCII16
Definition: winnt_old.h:886
#define IS_TEXT_UNICODE_SIGNATURE
Definition: winnt_old.h:892
#define IS_TEXT_UNICODE_REVERSE_STATISTICS
Definition: winnt_old.h:889
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170