blob: cb71973c8e00437050b69de8184ae1fde947da99 [file] [log] [blame]
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
int main (void) {
/**
* Test "C" locale
*/
assert (setlocale (LC_ALL, "C") != NULL);
/**
* All bytes in range [0,255] are valid and must convert to themselves
*/
for (int c = 0; c < 0x100; ++c) {
assert (btowc (c) == c);
}
/**
* Try convert sign-extended input
*/
for (char c = CHAR_MIN; c < 0; ++c) {
assert (btowc (c) == (c == EOF ? WEOF : (BYTE) c));
}
/**
* Test SBCS code page
*/
assert (setlocale (LC_ALL, "English_United States.1252") != NULL);
assert (MB_CUR_MAX == 1);
/**
* All bytes in range [0,127] are valid and must convert to themselves
*/
for (int c = 0; c < 0x80; ++c) {
assert (btowc (c) == c);
}
/**
* All bytes in range [0,255] are valid
*/
for (int c = 0x80; c < 0x100; ++c) {
assert (btowc (c) != WEOF);
}
/**
* Disable tests for DBCS code pages with msvcrt10.dll since it does not
* support multibyte characters.
*
* Calling setlocale with locale string which requests DBCS code page
* result in runtime error.
*/
#if __MSVCRT_VERSION__ != 0x0100
/**
* Test DBCS code page
*/
assert (setlocale (LC_ALL, "Japanese_Japan.932") != NULL);
assert (MB_CUR_MAX == 2);
/**
* All bytes in range [0,127] are valid and must convert to themselves
*/
for (int c = 0; c < 0x80; ++c) {
assert (btowc (c) == c);
}
/**
* Try to convert lead bytes
*/
for (int c = 0x80; c < 0x100; ++c) {
if (IsDBCSLeadByteEx (932, (BYTE) c)) {
assert (btowc (c) == WEOF);
}
}
#endif
#ifdef _UCRT
/**
* Test UTF-8
*/
if (setlocale (LC_ALL, ".UTF-8") != NULL) {
assert (MB_CUR_MAX == 4);
/**
* All bytes in range [0,127] are valid and must convert to themselves
*/
for (int c = 0; c < 0x80; ++c) {
assert (btowc (c) == c);
}
/**
* All bytes in range [128,255] are invalid
*/
for (int c = 0x80; c < 0x100; ++c) {
assert (btowc (c) == WEOF);
}
}
#endif
return 0;
}