From 9ea24cb6a08865346b60b9679e1ab5a6e283cd53 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 13 Jul 2018 18:35:49 +0200 Subject: [PATCH] Explicitly set the locale for local string conversion test. --- src/tl/unit_tests/tlString.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/tl/unit_tests/tlString.cc b/src/tl/unit_tests/tlString.cc index f218dddc4..93c254a04 100644 --- a/src/tl/unit_tests/tlString.cc +++ b/src/tl/unit_tests/tlString.cc @@ -26,6 +26,7 @@ #include "tlUnitTest.h" #include +#include using namespace tl; @@ -484,7 +485,16 @@ TEST(14) TEST(15) { // NOTE: we don't know the local setting, but translation back and forth should work. - EXPECT_EQ (tl::to_string_from_local (tl::to_local ("Hällo\tWörld!").c_str ()), "Hällo\tWörld!"); + std::string locale = setlocale (LC_ALL, NULL); + setlocale (LC_ALL, "en_US.UTF-8"); + try { + EXPECT_EQ (tl::to_string_from_local (tl::to_local ("Hällo\tWörld!").c_str ()), "Hällo\tWörld!"); + setlocale (LC_ALL, locale.c_str ()); + } catch (...) { + setlocale (LC_ALL, locale.c_str ()); + throw; + } + EXPECT_EQ (std::string ("Ä").size (), size_t (2)); EXPECT_EQ (tl::to_string (std::wstring (L"Ä")), "Ä"); EXPECT_EQ (tl::to_wstring (std::string ("Ä")).size (), size_t (1));