This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


The following commit(s) were added to refs/heads/master by this push:
     new 89b013d6 Warn rather than fail the test when the locale 'en_US.UTF-8' 
is not available (#296)
89b013d6 is described below

commit 89b013d6935836d80bfcbab672aa94aea295867a
Author: Stephen Webb <[email protected]>
AuthorDate: Tue Nov 21 09:56:17 2023 +1100

    Warn rather than fail the test when the locale 'en_US.UTF-8' is not 
available (#296)
---
 src/test/cpp/helpers/charsetdecodertestcase.cpp | 33 +++++++++++------
 src/test/cpp/helpers/charsetencodertestcase.cpp | 47 ++++++++++++++++---------
 2 files changed, 53 insertions(+), 27 deletions(-)

diff --git a/src/test/cpp/helpers/charsetdecodertestcase.cpp 
b/src/test/cpp/helpers/charsetdecodertestcase.cpp
index ba7539db..81497a7a 100644
--- a/src/test/cpp/helpers/charsetdecodertestcase.cpp
+++ b/src/test/cpp/helpers/charsetdecodertestcase.cpp
@@ -17,9 +17,11 @@
 
 #include <log4cxx/private/string_c11.h>
 #include <log4cxx/helpers/charsetdecoder.h>
+#include <log4cxx/helpers/transcoder.h>
 #include "../logunit.h"
 #include "../insertwide.h"
 #include <log4cxx/helpers/bytebuffer.h>
+#include <log4cxx/helpers/loglog.h>
 
 using namespace log4cxx;
 using namespace log4cxx::helpers;
@@ -122,16 +124,27 @@ public:
                const logchar* greet = utf8_greet;
 #endif
 
-               std::locale::global(std::locale("en_US.UTF-8"));
-               auto dec = CharsetDecoder::getDecoder(LOG4CXX_STR("locale"));
-
-               ByteBuffer in(utf8_greet, sizeof (utf8_greet));
-               LogString out;
-               log4cxx_status_t stat = dec->decode(in, out);
-               LOGUNIT_ASSERT_EQUAL(false, CharsetDecoder::isError(stat));
-               stat = dec->decode(in, out);
-               LOGUNIT_ASSERT_EQUAL(false, CharsetDecoder::isError(stat));
-               LOGUNIT_ASSERT(out == greet);
+               try
+               {
+                       std::locale::global(std::locale("en_US.UTF-8"));
+                       auto dec = 
CharsetDecoder::getDecoder(LOG4CXX_STR("locale"));
+
+                       ByteBuffer in(utf8_greet, sizeof (utf8_greet));
+                       LogString out;
+                       log4cxx_status_t stat = dec->decode(in, out);
+                       LOGUNIT_ASSERT_EQUAL(false, 
CharsetDecoder::isError(stat));
+                       stat = dec->decode(in, out);
+                       LOGUNIT_ASSERT_EQUAL(false, 
CharsetDecoder::isError(stat));
+                       LOGUNIT_ASSERT(out == greet);
+               }
+               catch (std::runtime_error& ex)
+               {
+                       LogString msg;
+                       Transcoder::decode(ex.what(), msg);
+                       msg.append(LOG4CXX_STR(": "));
+                       msg.append(LOG4CXX_STR("en_US.UTF-8"));
+                       LogLog::warn(msg);
+               }
        }
 
 
diff --git a/src/test/cpp/helpers/charsetencodertestcase.cpp 
b/src/test/cpp/helpers/charsetencodertestcase.cpp
index b44a6e4c..b4ca980e 100644
--- a/src/test/cpp/helpers/charsetencodertestcase.cpp
+++ b/src/test/cpp/helpers/charsetencodertestcase.cpp
@@ -19,6 +19,8 @@
 #include "../logunit.h"
 #include "../insertwide.h"
 #include <log4cxx/helpers/bytebuffer.h>
+#include <log4cxx/helpers/transcoder.h>
+#include <log4cxx/helpers/loglog.h>
 #include <apr.h>
 #include <apr_atomic.h>
 #include <condition_variable>
@@ -200,28 +202,39 @@ public:
 #endif
                LogString greeting(greet);
 
-               std::locale::global(std::locale("en_US.UTF-8"));
-               auto enc = CharsetEncoder::getEncoder(LOG4CXX_STR("locale"));
+               try
+               {
+                       std::locale::global(std::locale("en_US.UTF-8"));
+                       auto enc = 
CharsetEncoder::getEncoder(LOG4CXX_STR("locale"));
 
-               char buf[BUFSIZE];
-               ByteBuffer out(buf, BUFSIZE);
-               LogString::const_iterator iter = greeting.begin();
-               log4cxx_status_t stat = enc->encode(greeting, iter, out);
-               LOGUNIT_ASSERT_EQUAL(false, CharsetEncoder::isError(stat));
-               stat = enc->encode(greeting, iter, out);
-               LOGUNIT_ASSERT_EQUAL(false, CharsetEncoder::isError(stat));
+                       char buf[BUFSIZE];
+                       ByteBuffer out(buf, BUFSIZE);
+                       LogString::const_iterator iter = greeting.begin();
+                       log4cxx_status_t stat = enc->encode(greeting, iter, 
out);
+                       LOGUNIT_ASSERT_EQUAL(false, 
CharsetEncoder::isError(stat));
+                       stat = enc->encode(greeting, iter, out);
+                       LOGUNIT_ASSERT_EQUAL(false, 
CharsetEncoder::isError(stat));
 
-               out.flip();
-               LOGUNIT_ASSERT_EQUAL((size_t) 13, out.limit());
+                       out.flip();
+                       LOGUNIT_ASSERT_EQUAL((size_t) 13, out.limit());
 
-               for (size_t i = 0; i < out.limit(); i++)
+                       for (size_t i = 0; i < out.limit(); i++)
+                       {
+                               unsigned expected = (unsigned)utf8_greet[i];
+                               unsigned actual = (unsigned)out.data()[i];
+                               LOGUNIT_ASSERT_EQUAL(expected, actual);
+                       }
+
+                       LOGUNIT_ASSERT(iter == greeting.end());
+               }
+               catch (std::runtime_error& ex)
                {
-                       unsigned expected = (unsigned)utf8_greet[i];
-                       unsigned actual = (unsigned)out.data()[i];
-                       LOGUNIT_ASSERT_EQUAL(expected, actual);
+                       LogString msg;
+                       Transcoder::decode(ex.what(), msg);
+                       msg.append(LOG4CXX_STR(": "));
+                       msg.append(LOG4CXX_STR("en_US.UTF-8"));
+                       LogLog::warn(msg);
                }
-
-               LOGUNIT_ASSERT(iter == greeting.end());
        }
 
 #if APR_HAS_THREADS

Reply via email to