From 12249b199d934303a4043fa53717683d6d5ff208 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 3 Oct 2010 17:15:46 +0000 Subject: [PATCH] Run MBConvTestCase::LibcTests() only for MSVC and not other Windows compilers. This test fails for MinGW, probably because its CRT doesn't use the same locale names as MSVC CRT. Just disable it for now, as it was already disabled for non-MSW platforms. Also use LocaleSetter class (extracted from CLocaleSetter) to change the locale for this test duration only to avoid affecting any tests running after it. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65743 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- tests/mbconv/mbconvtest.cpp | 36 ++++++++++++------------------------ tests/testprec.h | 19 +++++++++++++++---- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/tests/mbconv/mbconvtest.cpp b/tests/mbconv/mbconvtest.cpp index 78e4d05932..df5216fe17 100644 --- a/tests/mbconv/mbconvtest.cpp +++ b/tests/mbconv/mbconvtest.cpp @@ -984,35 +984,23 @@ void MBConvTestCase::CP1252Tests() void MBConvTestCase::LibcTests() { - // There isn't a locale that all systems support (except "C"), so leave - // this one disabled for non-Windows systems for the moment, until - // a solution can be found. -#ifdef __WXMSW__ - -#ifdef __WXMSW__ - setlocale( LC_ALL, "English_United States.1252" ); - const unsigned char* systemMB = CP1252; - size_t systemMB_size = sizeof(CP1252); - const unsigned char* systemMB_utf8 = CP1252_utf8; - size_t systemMB_utf8_size = sizeof(CP1252_utf8); -#else - setlocale( LC_ALL, "en_US.iso8859-1" ); - const unsigned char* systemMB = iso8859_1; - size_t systemMB_size = sizeof(iso8859_1); - const unsigned char* systemMB_utf8 = iso8859_1_utf8; - size_t systemMB_utf8_size = sizeof(iso8859_1_utf8); -#endif + // The locale name are OS-dependent so this test is done only under Windows + // when using MSVC (surprisingly it fails with MinGW, even though it's + // supposed to use the same CRT -- no idea why and unfortunately gdb is too + // flaky to debug it) +#ifdef __VISUALC__ + LocaleSetter loc("English_United States.1252"); + wxMBConvLibc convLibc; TestCoder( - (const char*)systemMB, - systemMB_size, - (const char*)systemMB_utf8, - systemMB_utf8_size, + (const char*)CP1252, + sizeof(CP1252), + (const char*)CP1252_utf8, + sizeof(CP1252_utf8), convLibc, 1 ); - -#endif // __WXMSW__ +#endif // __VISUALC__ } // verifies that the specified mb sequences decode to the specified wc sequence diff --git a/tests/testprec.h b/tests/testprec.h index 853a62644b..eb232b128e 100644 --- a/tests/testprec.h +++ b/tests/testprec.h @@ -81,15 +81,26 @@ extern void SetProcessEventFunc(ProcessEventFunc func); extern bool IsNetworkAvailable(); -// helper class setting the locale to "C" for its lifetime -class CLocaleSetter +// Helper class setting the locale to the given one for its lifetime. +class LocaleSetter { public: - CLocaleSetter() : m_locOld(setlocale(LC_ALL, "C")) { } - ~CLocaleSetter() { setlocale(LC_ALL, m_locOld); } + LocaleSetter(const char *loc) : m_locOld(setlocale(LC_ALL, loc)) { } + ~LocaleSetter() { setlocale(LC_ALL, m_locOld); } private: const char * const m_locOld; + + wxDECLARE_NO_COPY_CLASS(LocaleSetter); +}; + +// An even simpler helper for setting the locale to "C" one during its lifetime. +class CLocaleSetter : private LocaleSetter +{ +public: + CLocaleSetter() : LocaleSetter("C") { } + +private: wxDECLARE_NO_COPY_CLASS(CLocaleSetter); }; -- 2.45.2