diff --git a/misc/TestUtil.cc b/misc/TestUtil.cc index 678b61e..e7ef074 100755 --- a/misc/TestUtil.cc +++ b/misc/TestUtil.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include "../shared/DebugClient.h" @@ -120,3 +121,22 @@ static void cprintf(const wchar_t *fmt, ...) { cvprintf(fmt, ap); va_end(ap); } + +std::string narrowString(const std::wstring &input) +{ + int mblen = WideCharToMultiByte( + CP_UTF8, 0, + input.data(), input.size(), + NULL, 0, NULL, NULL); + if (mblen <= 0) { + return std::string(); + } + std::vector tmp(mblen); + int mblen2 = WideCharToMultiByte( + CP_UTF8, 0, + input.data(), input.size(), + tmp.data(), tmp.size(), + NULL, NULL); + assert(mblen2 == mblen); + return std::string(tmp.data(), tmp.size()); +} diff --git a/misc/UnicodeDoubleWidthTest.cc b/misc/UnicodeDoubleWidthTest.cc index fd850e5..4f1d059 100644 --- a/misc/UnicodeDoubleWidthTest.cc +++ b/misc/UnicodeDoubleWidthTest.cc @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) { for (int px = 1; px < 50; ++px) { setFont(kFaceName, px); if (!performTest()) { - trace("FAILURE: %ls %dpx", kFaceName, px); + trace("FAILURE: %s %dpx", narrowString(kFaceName).c_str(), px); } } trace("Test complete");