You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2023/11/20 05:09:54 UTC
(logging-log4cxx) branch improve_charset_tests created (now 1e57b718)
This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a change to branch improve_charset_tests
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
at 1e57b718 Warn rather than fail when the locale 'en_US.UTF-8' is not available
This branch includes the following new commits:
new 3fb84fe7 Warn rather than fail when the locale 'en_US.UTF-8' is not available
new 1e57b718 Warn rather than fail when the locale 'en_US.UTF-8' is not available
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(logging-log4cxx) 01/02: Warn rather than fail when the locale 'en_US.UTF-8' is not available
Posted by sw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch improve_charset_tests
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit 3fb84fe7a23e8427b7313917c51af0a396c3e6fd
Author: Stephen Webb <sw...@gmail.com>
AuthorDate: Sun Nov 19 15:11:41 2023 +1100
Warn rather than fail when the locale 'en_US.UTF-8' is not available
---
src/test/cpp/helpers/charsetdecodertestcase.cpp | 32 +++++++++++------
src/test/cpp/helpers/charsetencodertestcase.cpp | 46 ++++++++++++++++---------
2 files changed, 51 insertions(+), 27 deletions(-)
diff --git a/src/test/cpp/helpers/charsetdecodertestcase.cpp b/src/test/cpp/helpers/charsetdecodertestcase.cpp
index ba7539db..f894e850 100644
--- a/src/test/cpp/helpers/charsetdecodertestcase.cpp
+++ b/src/test/cpp/helpers/charsetdecodertestcase.cpp
@@ -20,6 +20,7 @@
#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 +123,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..2d6620f9 100644
--- a/src/test/cpp/helpers/charsetencodertestcase.cpp
+++ b/src/test/cpp/helpers/charsetencodertestcase.cpp
@@ -19,6 +19,7 @@
#include "../logunit.h"
#include "../insertwide.h"
#include <log4cxx/helpers/bytebuffer.h>
+#include <log4cxx/helpers/loglog.h>
#include <apr.h>
#include <apr_atomic.h>
#include <condition_variable>
@@ -200,28 +201,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
(logging-log4cxx) 02/02: Warn rather than fail when the locale 'en_US.UTF-8' is not available
Posted by sw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch improve_charset_tests
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit 1e57b71815a2514ba5889e128b22e04a6dc5a9af
Author: Stephen Webb <sw...@gmail.com>
AuthorDate: Sun Nov 19 21:41:20 2023 +1100
Warn rather than fail when the locale 'en_US.UTF-8' is not available
---
src/test/cpp/helpers/charsetdecodertestcase.cpp | 1 +
src/test/cpp/helpers/charsetencodertestcase.cpp | 1 +
2 files changed, 2 insertions(+)
diff --git a/src/test/cpp/helpers/charsetdecodertestcase.cpp b/src/test/cpp/helpers/charsetdecodertestcase.cpp
index f894e850..81497a7a 100644
--- a/src/test/cpp/helpers/charsetdecodertestcase.cpp
+++ b/src/test/cpp/helpers/charsetdecodertestcase.cpp
@@ -17,6 +17,7 @@
#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>
diff --git a/src/test/cpp/helpers/charsetencodertestcase.cpp b/src/test/cpp/helpers/charsetencodertestcase.cpp
index 2d6620f9..b4ca980e 100644
--- a/src/test/cpp/helpers/charsetencodertestcase.cpp
+++ b/src/test/cpp/helpers/charsetencodertestcase.cpp
@@ -19,6 +19,7 @@
#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>