From ef892af6556724b6d04dfb1767dce132f9d97257 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Thu, 16 Jan 2014 00:27:51 +0100 Subject: Do not make calls to setlocale() in a library. Use default user locale in tests and examples. --- tests/parser/emailAddressTest.cpp | 24 ++++++++++++++++++++++++ tests/parser/parameterTest.cpp | 24 ++++++++++++++++++++++++ tests/parser/textTest.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 72 insertions(+) (limited to 'tests') diff --git a/tests/parser/emailAddressTest.cpp b/tests/parser/emailAddressTest.cpp index 378cc065..4916aaa9 100644 --- a/tests/parser/emailAddressTest.cpp +++ b/tests/parser/emailAddressTest.cpp @@ -25,6 +25,9 @@ #include "vmime/platform.hpp" +#include +#include + VMIME_TEST_SUITE_BEGIN(emailAddressTest) @@ -41,6 +44,27 @@ VMIME_TEST_SUITE_BEGIN(emailAddressTest) VMIME_TEST_LIST_END + void setUp() + { + // Set the global C and C++ locale to the user-configured locale. + // The locale should use UTF-8 encoding for these tests to run successfully. + try + { + std::locale::global(std::locale("")); + } + catch (std::exception &) + { + std::setlocale(LC_ALL, ""); + } + } + + void tearDown() + { + // Restore default locale + std::locale::global(std::locale("C")); + } + + void testParseASCII() { vmime::emailAddress eml1("local@domain"); diff --git a/tests/parser/parameterTest.cpp b/tests/parser/parameterTest.cpp index 3b0edebf..4f6f8677 100644 --- a/tests/parser/parameterTest.cpp +++ b/tests/parser/parameterTest.cpp @@ -23,6 +23,9 @@ #include "tests/testUtils.hpp" +#include +#include + VMIME_TEST_SUITE_BEGIN(parameterTest) @@ -62,6 +65,27 @@ VMIME_TEST_SUITE_BEGIN(parameterTest) (p.getParameterAt(n)->getValue().getBuffer()) + void setUp() + { + // Set the global C and C++ locale to the user-configured locale. + // The locale should use UTF-8 encoding for these tests to run successfully. + try + { + std::locale::global(std::locale("")); + } + catch (std::exception &) + { + std::setlocale(LC_ALL, ""); + } + } + + void tearDown() + { + // Restore default locale + std::locale::global(std::locale("C")); + } + + void testParse() { // Simple parameter diff --git a/tests/parser/textTest.cpp b/tests/parser/textTest.cpp index 274687a5..f56f972d 100644 --- a/tests/parser/textTest.cpp +++ b/tests/parser/textTest.cpp @@ -23,6 +23,9 @@ #include "tests/testUtils.hpp" +#include +#include + VMIME_TEST_SUITE_BEGIN(textTest) @@ -78,6 +81,27 @@ VMIME_TEST_SUITE_BEGIN(textTest) } + void setUp() + { + // Set the global C and C++ locale to the user-configured locale. + // The locale should use UTF-8 encoding for these tests to run successfully. + try + { + std::locale::global(std::locale("")); + } + catch (std::exception &) + { + std::setlocale(LC_ALL, ""); + } + } + + void tearDown() + { + // Restore default locale + std::locale::global(std::locale("C")); + } + + void testConstructors() { vmime::text t1; -- cgit v1.2.3