CMake: improved Unicode tests

CodecvtTest.cpp: fix error codes
IconvTest.cpp: add Japanese, Korean, Russian and Taiwanese tests
WincvtTest.cpp: fix error codes
This commit is contained in:
Syping 2022-12-28 07:18:15 +01:00
parent 91404a5f77
commit 087534bf6e
3 changed files with 215 additions and 25 deletions

View file

@ -218,23 +218,23 @@ int main(int argc, char *argv[])
// Korean
photoString = convert.to_bytes(reinterpret_cast<const char16_t*>(photoHeader_korean));
if (convert.converted() == 0)
return 4;
if (strcmp(photoString.c_str(), "사진 - 12/28/22 04:18:28") != 0)
return 5;
if (strcmp(photoString.c_str(), "사진 - 12/28/22 04:18:28") != 0)
return 6;
// Russian
photoString = convert.to_bytes(reinterpret_cast<const char16_t*>(photoHeader_russian));
if (convert.converted() == 0)
return 6;
if (strcmp(photoString.c_str(), "ФОТО - 12/28/22 04:25:10") != 0)
return 7;
if (strcmp(photoString.c_str(), "ФОТО - 12/28/22 04:25:10") != 0)
return 8;
// Taiwanese
photoString = convert.to_bytes(reinterpret_cast<const char16_t*>(photoHeader_taiwanese));
if (convert.converted() == 0)
return 8;
if (strcmp(photoString.c_str(), "相片 - 12/28/22 04:21:01") != 0)
return 9;
if (strcmp(photoString.c_str(), "相片 - 12/28/22 04:21:01") != 0)
return 10;
return 0;
}

View file

@ -22,7 +22,7 @@
int main(int argc, char *argv[])
{
char photoHeader[256] = {
unsigned char photoHeader_english[256] = {
0x50, 0x00, 0x48, 0x00, 0x4f, 0x00, 0x54, 0x00,
0x4f, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00,
0x30, 0x00, 0x32, 0x00, 0x2f, 0x00, 0x30, 0x00,
@ -56,18 +56,208 @@ int main(int argc, char *argv[])
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
char photoHeader_string[256];
unsigned char photoHeader_japanese[256] = {
0x99, 0x51, 0x1f, 0x77, 0x20, 0x00, 0x2d, 0x00,
0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00,
0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00,
0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00,
0x3a, 0x00, 0x32, 0x00, 0x32, 0x00, 0x3a, 0x00,
0x35, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
unsigned char photoHeader_korean[256] = {
0xac, 0xc0, 0xc4, 0xc9, 0x20, 0x00, 0x2d, 0x00,
0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00,
0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00,
0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00,
0x3a, 0x00, 0x31, 0x00, 0x38, 0x00, 0x3a, 0x00,
0x32, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
unsigned char photoHeader_russian[256] = {
0x24, 0x04, 0x1e, 0x04, 0x22, 0x04, 0x1e, 0x04,
0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x31, 0x00,
0x32, 0x00, 0x2f, 0x00, 0x32, 0x00, 0x38, 0x00,
0x2f, 0x00, 0x32, 0x00, 0x32, 0x00, 0x20, 0x00,
0x30, 0x00, 0x34, 0x00, 0x3a, 0x00, 0x32, 0x00,
0x35, 0x00, 0x3a, 0x00, 0x31, 0x00, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
unsigned char photoHeader_taiwanese[256] = {
0xf8, 0x76, 0x47, 0x72, 0x20, 0x00, 0x2d, 0x00,
0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00,
0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00,
0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00,
0x3a, 0x00, 0x32, 0x00, 0x31, 0x00, 0x3a, 0x00,
0x30, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
size_t src_s, dst_s, ret;
char photoString[256];
iconv_t iconv_in = iconv_open("UTF-8", "UTF-16LE");
if (iconv_in == (iconv_t)-1)
return -1;
size_t src_s = sizeof(photoHeader);
size_t dst_s = sizeof(photoHeader_string);
char *src = photoHeader;
char *dst = photoHeader_string;
const size_t ret = iconv(iconv_in, &src, &src_s, &dst, &dst_s);
// English
src_s = sizeof(photoHeader_english);
dst_s = sizeof(photoString);
char *src_english = (char*)photoHeader_english;
char *dst_english = photoString;
ret = iconv(iconv_in, &src_english, &src_s, &dst_english, &dst_s);
if (ret == static_cast<size_t>(-1))
return 1;
if (strcmp(photoString, "PHOTO - 02/01/17 08:42:44") != 0)
return 2;
// Japanese
src_s = sizeof(photoHeader_japanese);
dst_s = sizeof(photoString);
char *src_japanese = (char*)photoHeader_japanese;
char *dst_japanese = photoString;
ret = iconv(iconv_in, &src_japanese, &src_s, &dst_japanese, &dst_s);
if (ret == static_cast<size_t>(-1))
return 3;
if (strcmp(photoString, "写真 - 12/28/22 04:22:57") != 0)
return 4;
// Korean
src_s = sizeof(photoHeader_korean);
dst_s = sizeof(photoString);
char *src_korean = (char*)photoHeader_korean;
char *dst_korean = photoString;
ret = iconv(iconv_in, &src_korean, &src_s, &dst_korean, &dst_s);
if (ret == static_cast<size_t>(-1))
return 5;
if (strcmp(photoString, "사진 - 12/28/22 04:18:28") != 0)
return 6;
// Russian
src_s = sizeof(photoHeader_russian);
dst_s = sizeof(photoString);
char *src_russian = (char*)photoHeader_russian;
char *dst_russian = photoString;
ret = iconv(iconv_in, &src_russian, &src_s, &dst_russian, &dst_s);
if (ret == static_cast<size_t>(-1))
return 7;
if (strcmp(photoString, "ФОТО - 12/28/22 04:25:10") != 0)
return 8;
// Taiwanese
src_s = sizeof(photoHeader_taiwanese);
dst_s = sizeof(photoString);
char *src_taiwanese = (char*)photoHeader_taiwanese;
char *dst_taiwanese = photoString;
ret = iconv(iconv_in, &src_taiwanese, &src_s, &dst_taiwanese, &dst_s);
if (ret == static_cast<size_t>(-1))
return 9;
if (strcmp(photoString, "相片 - 12/28/22 04:21:01") != 0)
return 10;
iconv_close(iconv_in);
if (ret == static_cast<size_t>(-1)) {
return -1;
}
return strcmp(photoHeader_string, "PHOTO - 02/01/17 08:42:44");
return 0;
}

View file

@ -210,30 +210,30 @@ int main(int argc, char *argv[])
// Japanese
converted = WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<const wchar_t*>(photoHeader_japanese), -1, photoString, 256, NULL, NULL);
if (converted == 0)
return 2;
if (strcmp(photoString, "写真 - 12/28/22 04:22:57") != 0)
return 3;
if (strcmp(photoString, "写真 - 12/28/22 04:22:57") != 0)
return 4;
// Korean
converted = WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<const wchar_t*>(photoHeader_korean), -1, photoString, 256, NULL, NULL);
if (converted == 0)
return 4;
if (strcmp(photoString, "사진 - 12/28/22 04:18:28") != 0)
return 5;
if (strcmp(photoString, "사진 - 12/28/22 04:18:28") != 0)
return 6;
// Russian
converted = WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<const wchar_t*>(photoHeader_russian), -1, photoString, 256, NULL, NULL);
if (converted == 0)
return 6;
if (strcmp(photoString, "ФОТО - 12/28/22 04:25:10") != 0)
return 7;
if (strcmp(photoString, "ФОТО - 12/28/22 04:25:10") != 0)
return 8;
// Taiwanese
converted = WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<const wchar_t*>(photoHeader_taiwanese), -1, photoString, 256, NULL, NULL);
if (converted == 0)
return 8;
if (strcmp(photoString, "相片 - 12/28/22 04:21:01") != 0)
return 9;
if (strcmp(photoString, "相片 - 12/28/22 04:21:01") != 0)
return 10;
return 0;
}