Do not make calls to setlocale() in a library. Use default user locale in tests and examples.
This commit is contained in:
parent
1a04575750
commit
ef892af655
@ -32,6 +32,8 @@
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
#include <clocale>
|
||||
|
||||
#include "vmime/vmime.hpp"
|
||||
#include "vmime/platforms/posix/posixHandler.hpp"
|
||||
@ -41,8 +43,16 @@ int main()
|
||||
{
|
||||
std::cout << std::endl;
|
||||
|
||||
// VMime initialization
|
||||
vmime::platform::setHandler<vmime::platforms::posix::posixHandler>();
|
||||
// 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, "");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -32,6 +32,8 @@
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
#include <clocale>
|
||||
|
||||
#include "vmime/vmime.hpp"
|
||||
#include "vmime/platforms/posix/posixHandler.hpp"
|
||||
@ -41,8 +43,16 @@ int main()
|
||||
{
|
||||
std::cout << std::endl;
|
||||
|
||||
// VMime initialization
|
||||
vmime::platform::setHandler<vmime::platforms::posix::posixHandler>();
|
||||
// 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, "");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
@ -71,7 +81,7 @@ int main()
|
||||
// Adding an attachment
|
||||
vmime::shared_ptr <vmime::fileAttachment> a = vmime::make_shared <vmime::fileAttachment>
|
||||
(
|
||||
"./example2.cpp", // full path to file
|
||||
__FILE__, // full path to file
|
||||
vmime::mediaType("application/octet-stream"), // content type
|
||||
vmime::text("My first attachment") // description
|
||||
);
|
||||
|
@ -32,6 +32,8 @@
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
#include <clocale>
|
||||
|
||||
#include "vmime/vmime.hpp"
|
||||
#include "vmime/platforms/posix/posixHandler.hpp"
|
||||
@ -41,8 +43,16 @@ int main()
|
||||
{
|
||||
std::cout << std::endl;
|
||||
|
||||
// VMime initialization
|
||||
vmime::platform::setHandler<vmime::platforms::posix::posixHandler>();
|
||||
// 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, "");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -32,6 +32,8 @@
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
#include <clocale>
|
||||
|
||||
#include "vmime/vmime.hpp"
|
||||
#include "vmime/platforms/posix/posixHandler.hpp"
|
||||
@ -41,8 +43,16 @@ int main()
|
||||
{
|
||||
std::cout << std::endl;
|
||||
|
||||
// VMime initialization
|
||||
vmime::platform::setHandler<vmime::platforms::posix::posixHandler>();
|
||||
// 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, "");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -32,6 +32,8 @@
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
#include <clocale>
|
||||
|
||||
#include "vmime/vmime.hpp"
|
||||
#include "vmime/platforms/posix/posixHandler.hpp"
|
||||
@ -41,8 +43,16 @@ int main()
|
||||
{
|
||||
std::cout << std::endl;
|
||||
|
||||
// VMime initialization
|
||||
vmime::platform::setHandler<vmime::platforms::posix::posixHandler>();
|
||||
// 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, "");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <locale>
|
||||
#include <clocale>
|
||||
|
||||
#include "vmime/vmime.hpp"
|
||||
#include "vmime/platforms/posix/posixHandler.hpp"
|
||||
@ -916,8 +918,16 @@ static bool menu()
|
||||
|
||||
int main()
|
||||
{
|
||||
// VMime initialization
|
||||
vmime::platform::setHandler<vmime::platforms::posix::posixHandler>();
|
||||
// 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, "");
|
||||
}
|
||||
|
||||
for (bool quit = false ; !quit ; )
|
||||
{
|
||||
|
@ -32,6 +32,8 @@
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
#include <clocale>
|
||||
|
||||
#include "vmime/vmime.hpp"
|
||||
#include "vmime/platforms/posix/posixHandler.hpp"
|
||||
@ -39,9 +41,6 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
// VMime initialization
|
||||
vmime::platform::setHandler<vmime::platforms::posix::posixHandler>();
|
||||
|
||||
// Enumerate encoders
|
||||
vmime::shared_ptr <vmime::utility::encoder::encoderFactory> ef =
|
||||
vmime::utility::encoder::encoderFactory::getInstance();
|
||||
|
@ -168,11 +168,7 @@ const vmime::charset posixHandler::getLocalCharset() const
|
||||
{
|
||||
const PLockHelper lock;
|
||||
|
||||
const char* prevLocale = ::setlocale(LC_ALL, "");
|
||||
vmime::charset ch(::nl_langinfo(CODESET));
|
||||
::setlocale(LC_ALL, prevLocale);
|
||||
|
||||
return (ch);
|
||||
return vmime::charset(::nl_langinfo(CODESET));
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,6 +25,9 @@
|
||||
|
||||
#include "vmime/platform.hpp"
|
||||
|
||||
#include <locale>
|
||||
#include <clocale>
|
||||
|
||||
|
||||
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");
|
||||
|
@ -23,6 +23,9 @@
|
||||
|
||||
#include "tests/testUtils.hpp"
|
||||
|
||||
#include <locale>
|
||||
#include <clocale>
|
||||
|
||||
|
||||
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
|
||||
|
@ -23,6 +23,9 @@
|
||||
|
||||
#include "tests/testUtils.hpp"
|
||||
|
||||
#include <locale>
|
||||
#include <clocale>
|
||||
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user