[ADVAPI32_APITEST]

- Add tests for IS_TEXT_UNICODE_DBCS_LEADBYTE flag

[SDK]
- Add missed IS_TEXT_UNICODE_DBCS_LEADBYTE definition

svn path=/trunk/; revision=72487
This commit is contained in:
Dmitry Chapyshev 2016-08-28 15:59:29 +00:00
parent af19896deb
commit 85d39f7ebe
2 changed files with 84 additions and 0 deletions

View file

@ -915,6 +915,7 @@
#define IS_TEXT_UNICODE_REVERSE_SIGNATURE 128
#define IS_TEXT_UNICODE_ILLEGAL_CHARS 256
#define IS_TEXT_UNICODE_ODD_LENGTH 512
#define IS_TEXT_UNICODE_DBCS_LEADBYTE 1024
#define IS_TEXT_UNICODE_NULL_BYTES 4096
#define IS_TEXT_UNICODE_UNICODE_MASK 15
#define IS_TEXT_UNICODE_REVERSE_MASK 240

View file

@ -8,7 +8,54 @@
#include <apitest.h>
#define WIN32_NO_STATUS
#include <ndk/rtlfuncs.h>
#include <winbase.h>
#include <winnls.h>
#include <wincon.h>
#include <stdio.h>
PVOID LoadCodePageData(ULONG Code)
{
char filename[MAX_PATH], sysdir[MAX_PATH];
HANDLE hFile;
PVOID Data = NULL;
GetSystemDirectoryA(sysdir, MAX_PATH);
if (Code != -1)
sprintf(filename, "%s\\c_%lu.nls", sysdir, Code);
else
sprintf(filename, "%s\\l_intl.nls", sysdir);
hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
DWORD dwRead;
DWORD dwFileSize = GetFileSize(hFile, NULL);
Data = malloc(dwFileSize);
ReadFile(hFile, Data, dwFileSize, &dwRead, NULL);
CloseHandle(hFile);
}
return Data;
}
/* https://www.microsoft.com/resources/msdn/goglobal/default.mspx */
void SetupLocale(ULONG AnsiCode, ULONG OemCode, ULONG Unicode)
{
NLSTABLEINFO NlsTable;
PVOID AnsiCodePageData;
PVOID OemCodePageData;
PVOID UnicodeCaseTableData;
AnsiCodePageData = LoadCodePageData(AnsiCode);
OemCodePageData = LoadCodePageData(OemCode);
UnicodeCaseTableData = LoadCodePageData(Unicode);
RtlInitNlsTables(AnsiCodePageData, OemCodePageData, UnicodeCaseTableData, &NlsTable);
RtlResetRtlTranslations(&NlsTable);
/* Do NOT free the buffers here, they are directly used!
Yes, we leak the old buffers, but this is a test anyway... */
}
START_TEST(IsTextUnicode)
{
@ -89,8 +136,16 @@ START_TEST(IsTextUnicode)
NEW_TEST(L"UNICODE S" L"\x0A0D" L"tring 5 Привет!", IS_TEXT_UNICODE_ILLEGAL_CHARS, IS_TEXT_UNICODE_ILLEGAL_CHARS, FALSE),
/* Unicode 0xFFFF */
NEW_TEST(L"UNICODE S" L"\xFFFF" L"tring 5 Привет!", IS_TEXT_UNICODE_ILLEGAL_CHARS, IS_TEXT_UNICODE_ILLEGAL_CHARS, FALSE),
// 35
NEW_TEST(L"UNICODE String 0", IS_TEXT_UNICODE_DBCS_LEADBYTE, 0, FALSE)
};
const char japanese_with_lead[] = "ABC" "\x83\x40" "D";
const char simplfied_chinese_with_lead[] = "ABC" "\xC5\xC5" "D";
const char korean_with_lead[] = "ABC" "\xBF\xAD" "D";
const char traditional_chinese_with_lead[] = "ABC" "\xB1\xC1" "D";
UINT i;
BOOL Success;
INT Result;
@ -103,4 +158,32 @@ START_TEST(IsTextUnicode)
if (Result != INVALID_FLAG)
ok(Result == Tests[i].ResultFlags, "IsTextUnicode(%u) Result returned 0x%x, expected 0x%x\n", i, Result, Tests[i].ResultFlags);
}
/* Japanese */
SetupLocale(932, 932, -1);
Result = IS_TEXT_UNICODE_DBCS_LEADBYTE;
ok(!IsTextUnicode(japanese_with_lead, sizeof(japanese_with_lead), &Result), "IsTextUnicode() returned TRUE, expected FALSE\n");
ok(Result == IS_TEXT_UNICODE_DBCS_LEADBYTE, "Result returned 0x%x, expected 0x%x\n", Result, IS_TEXT_UNICODE_DBCS_LEADBYTE);
/* Simplified Chinese */
SetupLocale(936, 936, -1);
Result = IS_TEXT_UNICODE_DBCS_LEADBYTE;
ok(!IsTextUnicode(simplfied_chinese_with_lead, sizeof(simplfied_chinese_with_lead), &Result), "IsTextUnicode() returned TRUE, expected FALSE\n");
ok(Result == IS_TEXT_UNICODE_DBCS_LEADBYTE, "Result returned 0x%x, expected 0x%x\n", Result, IS_TEXT_UNICODE_DBCS_LEADBYTE);
/* Korean */
SetupLocale(949, 949, -1);
Result = IS_TEXT_UNICODE_DBCS_LEADBYTE;
ok(!IsTextUnicode(korean_with_lead, sizeof(korean_with_lead), &Result), "IsTextUnicode() returned TRUE, expected FALSE\n");
ok(Result == IS_TEXT_UNICODE_DBCS_LEADBYTE, "Result returned 0x%x, expected 0x%x\n", Result, IS_TEXT_UNICODE_DBCS_LEADBYTE);
/* Traditional Chinese */
SetupLocale(950, 950, -1);
Result = IS_TEXT_UNICODE_DBCS_LEADBYTE;
ok(!IsTextUnicode(traditional_chinese_with_lead, sizeof(traditional_chinese_with_lead), &Result), "IsTextUnicode() returned TRUE, expected FALSE\n");
ok(Result == IS_TEXT_UNICODE_DBCS_LEADBYTE, "Result returned 0x%x, expected 0x%x\n", Result, IS_TEXT_UNICODE_DBCS_LEADBYTE);
}