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 f0473b58 Use CFString in OSX integration builds (#243)
f0473b58 is described below

commit f0473b58fedfa36e610386d5ddbaebab0688e7af
Author: Stephen Webb <[email protected]>
AuthorDate: Wed Aug 2 09:20:52 2023 +1000

    Use CFString in OSX integration builds (#243)
    
    * Convert CFString without using std::basic_string<UniCode>
    
    * Add CFString decode debug logging
    
    * Fix failing CFString tests
---
 .../{log4cxx-posix.yml => log4cxx-macos.yml}       | 30 ++-------------
 .../{log4cxx-posix.yml => log4cxx-ubuntu.yml}      | 17 ++-------
 src/main/cpp/CMakeLists.txt                        |  4 ++
 src/main/cpp/logger.cpp                            | 14 +++----
 src/main/cpp/logstream.cpp                         |  6 +--
 src/main/cpp/messagebuffer.cpp                     | 44 ++++++++++++++++++----
 src/main/cpp/transcoder.cpp                        | 38 ++++++++++---------
 src/main/include/log4cxx/helpers/messagebuffer.h   | 40 ++++++++++++++++++--
 src/main/include/log4cxx/helpers/transcoder.h      |  2 +-
 src/main/include/log4cxx/logger.h                  |  2 +-
 src/main/include/log4cxx/logstring.h               |  2 +-
 src/main/include/log4cxx/stream.h                  |  2 +-
 src/test/cpp/CMakeLists.txt                        |  7 ++++
 src/test/cpp/filetestcase.cpp                      | 12 +++++-
 src/test/cpp/helpers/messagebuffertest.cpp         | 25 +++++++++++-
 src/test/cpp/insertwide.h                          |  2 +-
 src/test/cpp/leveltestcase.cpp                     | 10 +++++
 src/test/cpp/logunit.cpp                           |  2 +-
 src/test/cpp/logunit.h                             |  2 +-
 src/test/cpp/streamtestcase.cpp                    | 20 ++++++++--
 20 files changed, 188 insertions(+), 93 deletions(-)

diff --git a/.github/workflows/log4cxx-posix.yml 
b/.github/workflows/log4cxx-macos.yml
similarity index 65%
copy from .github/workflows/log4cxx-posix.yml
copy to .github/workflows/log4cxx-macos.yml
index 752eae86..bdc5f75e 100644
--- a/.github/workflows/log4cxx-posix.yml
+++ b/.github/workflows/log4cxx-macos.yml
@@ -12,7 +12,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-name: log4cxx-posix
+name: log4cxx-osx
 
 on: [push, pull_request]
 
@@ -24,24 +24,8 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        name: [ubuntu20-gcc, ubuntu20-clang, ubuntu22-gcc, ubuntu22-clang, 
osx-11, osx-12]
+        name: [osx-11, osx-12]
         include:
-          - name: ubuntu20-gcc
-            os: ubuntu-20.04
-            cxx: g++
-            cc: gcc
-          - name: ubuntu20-clang
-            os: ubuntu-20.04
-            cxx: clang++
-            cc: clang
-          - name: ubuntu22-gcc
-            os: ubuntu-22.04
-            cxx: g++
-            cc: gcc
-          - name: ubuntu22-clang
-            os: ubuntu-22.04
-            cxx: clang++
-            cc: clang
           - name: osx-11
             os: macos-11
             cxx: clang++
@@ -56,18 +40,12 @@ jobs:
       with:
         path: main
 
-    - name: 'Configure Dependencies - Ubuntu'
-      if: startsWith( matrix.name,'ubuntu' )
-      run: |
-        sudo apt-get update
-        sudo apt-get install -y libapr1-dev libaprutil1-dev libfmt-dev 
unixodbc-dev
-
-    - name: 'run cmake - posix'
+    - name: 'configure and build'
       run: |
         cd main
         mkdir build
         cd build
-        cmake -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} -DCMAKE_C_COMPILER=${{ 
matrix.cc }} -DLOG4CXX_ENABLE_ODBC=on ..
+        cmake -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} -DCMAKE_C_COMPILER=${{ 
matrix.cc }} -DLOG4CXX_ENABLE_ODBC=ON -DLOG4CXX_CFSTRING=ON 
-DCMAKE_BUILD_TYPE=Debug ..
         cmake --build .
 
     - name: run unit tests
diff --git a/.github/workflows/log4cxx-posix.yml 
b/.github/workflows/log4cxx-ubuntu.yml
similarity index 83%
rename from .github/workflows/log4cxx-posix.yml
rename to .github/workflows/log4cxx-ubuntu.yml
index 752eae86..ee8ac96c 100644
--- a/.github/workflows/log4cxx-posix.yml
+++ b/.github/workflows/log4cxx-ubuntu.yml
@@ -12,7 +12,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-name: log4cxx-posix
+name: log4cxx-ubuntu
 
 on: [push, pull_request]
 
@@ -24,7 +24,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        name: [ubuntu20-gcc, ubuntu20-clang, ubuntu22-gcc, ubuntu22-clang, 
osx-11, osx-12]
+        name: [ubuntu20-gcc, ubuntu20-clang, ubuntu22-gcc, ubuntu22-clang]
         include:
           - name: ubuntu20-gcc
             os: ubuntu-20.04
@@ -42,22 +42,13 @@ jobs:
             os: ubuntu-22.04
             cxx: clang++
             cc: clang
-          - name: osx-11
-            os: macos-11
-            cxx: clang++
-            cc: clang
-          - name: osx-12
-            os: macos-12
-            cxx: clang++
-            cc: clang
 
     steps:
     - uses: actions/checkout@v3
       with:
         path: main
 
-    - name: 'Configure Dependencies - Ubuntu'
-      if: startsWith( matrix.name,'ubuntu' )
+    - name: 'Configure Dependencies'
       run: |
         sudo apt-get update
         sudo apt-get install -y libapr1-dev libaprutil1-dev libfmt-dev 
unixodbc-dev
@@ -67,7 +58,7 @@ jobs:
         cd main
         mkdir build
         cd build
-        cmake -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} -DCMAKE_C_COMPILER=${{ 
matrix.cc }} -DLOG4CXX_ENABLE_ODBC=on ..
+        cmake -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} -DCMAKE_C_COMPILER=${{ 
matrix.cc }} -DLOG4CXX_ENABLE_ODBC=ON ..
         cmake --build .
 
     - name: run unit tests
diff --git a/src/main/cpp/CMakeLists.txt b/src/main/cpp/CMakeLists.txt
index 16419ffe..be187a7b 100644
--- a/src/main/cpp/CMakeLists.txt
+++ b/src/main/cpp/CMakeLists.txt
@@ -216,6 +216,10 @@ if(${ENABLE_FMT_LAYOUT})
     target_link_libraries(log4cxx PUBLIC fmt::fmt)
 endif()
 
+if (LOG4CXX_CFSTRING)
+    target_link_libraries(log4cxx PRIVATE "-framework CoreFoundation")
+endif()
+
 if(LOG4CXX_ABI_CHECK)
     message("Getting dependencies for ABI compatability check...")
     # Get the latest version of abi-dumper and abi-compliance-checker
diff --git a/src/main/cpp/logger.cpp b/src/main/cpp/logger.cpp
index 3b94eaac..c328034a 100644
--- a/src/main/cpp/logger.cpp
+++ b/src/main/cpp/logger.cpp
@@ -887,7 +887,7 @@ void Logger::warn(const std::wstring& msg) const
 #endif
 
 
-#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#if LOG4CXX_UNICHAR_API
 void Logger::addEvent(const LevelPtr& level1, std::basic_string<UniChar>&& 
message,    const LocationInfo& location) const
 {
        if (!getHierarchy()) // Has removeHierarchy() been called?
@@ -919,9 +919,7 @@ void Logger::forcedLog(const LevelPtr& level1, const 
std::basic_string<UniChar>&
                        LocationInfo::getLocationUnavailable());
        callAppenders(event, p);
 }
-#endif
 
-#if LOG4CXX_UNICHAR_API
 void Logger::getName(std::basic_string<UniChar>& rv) const
 {
        Transcoder::encode(m_priv->name, rv);
@@ -1050,31 +1048,31 @@ void Logger::warn(const std::basic_string<UniChar>& 
msg) const
 
 
 #if LOG4CXX_CFSTRING_API
-void Logger::forcedLog(const LevelPtr& level1, const CFStringRef& message,
+void Logger::forcedLog(const LevelPtr& level, const CFStringRef& message,
        const LocationInfo& location) const
 {
        if (!getHierarchy()) // Has removeHierarchy() been called?
                return;
        Pool p;
        LOG4CXX_DECODE_CFSTRING(msg, message);
-       auto event = std::make_shared<LoggingEvent>(name, level1, location, 
std::move(msg));
+       auto event = std::make_shared<LoggingEvent>(m_priv->name, level, 
location, std::move(msg));
        callAppenders(event, p);
 }
 
-void Logger::forcedLog(const LevelPtr& level1, const CFStringRef& message) 
const
+void Logger::forcedLog(const LevelPtr& level, const CFStringRef& message) const
 {
        if (!getHierarchy()) // Has removeHierarchy() been called?
                return;
        Pool p;
        LOG4CXX_DECODE_CFSTRING(msg, message);
-       auto event = std::make_shared<LoggingEvent>(name, level1, msg,
+       auto event = std::make_shared<LoggingEvent>(m_priv->name, level, msg,
                        LocationInfo::getLocationUnavailable());
        callAppenders(event, p);
 }
 
 void Logger::getName(CFStringRef& rv) const
 {
-       rv = Transcoder::encode(name);
+       rv = Transcoder::encode(m_priv->name);
 }
 
 LoggerPtr Logger::getLogger(const CFStringRef& name)
diff --git a/src/main/cpp/logstream.cpp b/src/main/cpp/logstream.cpp
index a914040c..ce4aff09 100644
--- a/src/main/cpp/logstream.cpp
+++ b/src/main/cpp/logstream.cpp
@@ -17,7 +17,7 @@
 
 #include <log4cxx/log4cxx.h>
 /* Prevent std::basic_streambuf etc destructor ... already defined in 
logstream.obj */
-#if defined(_MSC_VER) && (LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API)
+#if defined(_MSC_VER) && LOG4CXX_UNICHAR_API
 #define __FORCE_INSTANCE
 #endif
 #include <log4cxx/logstring.h>
@@ -482,7 +482,7 @@ ulogstream::ulogstream(const std::basic_string<Ch>& 
loggerName,
 }
 #endif
 
-#if LOG4CXX_CFSTRING_API
+#if LOG4CXX_UNICHAR_API && LOG4CXX_CFSTRING_API
 ulogstream::ulogstream(const CFStringRef& loggerName,
        const log4cxx::LevelPtr& level)
        : logstream_base(log4cxx::Logger::getLogger(loggerName), level), 
stream(0)
@@ -492,7 +492,7 @@ ulogstream::ulogstream(const CFStringRef& loggerName,
 #endif
 
 
-#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#if LOG4CXX_UNICHAR_API
 
 ulogstream::ulogstream(const log4cxx::LoggerPtr& logger,
        const log4cxx::LevelPtr& level) : logstream_base(logger, level), 
stream(0)
diff --git a/src/main/cpp/messagebuffer.cpp b/src/main/cpp/messagebuffer.cpp
index e17a6ef4..aec85f01 100644
--- a/src/main/cpp/messagebuffer.cpp
+++ b/src/main/cpp/messagebuffer.cpp
@@ -17,7 +17,7 @@
 
 #include <log4cxx/log4cxx.h>
 /* Prevent error C2491: 'std::numpunct<_Elem>::id': definition of dllimport 
static data member not allowed */
-#if defined(_MSC_VER) && (LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API)
+#if defined(_MSC_VER) && LOG4CXX_UNICHAR_API
 #define __FORCE_INSTANCE
 #endif
 #include <log4cxx/helpers/messagebuffer.h>
@@ -379,7 +379,7 @@ struct MessageBuffer::MessageBufferPrivate{
         * Encapsulated wide message buffer, created on demand.
         */
        std::unique_ptr<WideMessageBuffer> wbuf;
-#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#if LOG4CXX_UNICHAR_API
        /**
         * Encapsulated wide message buffer, created on demand.
         */
@@ -399,7 +399,7 @@ MessageBuffer::~MessageBuffer()
 bool MessageBuffer::hasStream() const
 {
        bool retval = m_priv->cbuf.hasStream() || (m_priv->wbuf != 0 && 
m_priv->wbuf->hasStream());
-#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#if LOG4CXX_UNICHAR_API
        retval = retval || (m_priv->ubuf != 0 && m_priv->ubuf->hasStream());
 #endif
        return retval;
@@ -540,7 +540,7 @@ std::ostream& MessageBuffer::operator<<(void* val)
        return m_priv->cbuf.operator << (val);
 }
 
-#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#if LOG4CXX_UNICHAR_API
 UniCharMessageBuffer& MessageBuffer::operator<<(const 
std::basic_string<log4cxx::UniChar>& msg)
 {
        m_priv->ubuf = std::make_unique<UniCharMessageBuffer>();
@@ -583,10 +583,11 @@ const std::basic_string<log4cxx::UniChar>& 
MessageBuffer::str(std::basic_ostream
 {
        return m_priv->ubuf->str(os);
 }
-#endif //LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#endif //LOG4CXX_UNICHAR_API
+
 #endif // LOG4CXX_WCHAR_T_API
 
-#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#if LOG4CXX_UNICHAR_API
 struct UniCharMessageBuffer::UniCharMessageBufferPrivate : public 
StringOrStream<UniChar> {};
 
 UniCharMessageBuffer::UniCharMessageBuffer() :
@@ -732,10 +733,10 @@ UniCharMessageBuffer::uostream& 
UniCharMessageBuffer::operator<<(void* val)
        return ((UniCharMessageBuffer::uostream&) * this).operator << (val);
 }
 
-#endif // LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#endif // LOG4CXX_UNICHAR_API
 
 
-#if LOG4CXX_CFSTRING_API
+#if LOG4CXX_UNICHAR_API && LOG4CXX_CFSTRING_API
 #include <CoreFoundation/CFString.h>
 #include <vector>
 
@@ -773,5 +774,32 @@ UniCharMessageBuffer& MessageBuffer::operator<<(const 
CFStringRef& msg)
        m_priv->ubuf = std::make_unique<UniCharMessageBuffer>();
        return (*m_priv->ubuf) << msg;
 }
+
+#elif LOG4CXX_CFSTRING_API
+#include <CoreFoundation/CFString.h>
+#include <vector>
+
+CharMessageBuffer& CharMessageBuffer::operator<<(const CFStringRef& msg)
+{
+       LOG4CXX_DECODE_CFSTRING(tmp, msg);
+       if (m_priv->stream)
+       {
+               *m_priv->stream << tmp;
+       }
+       else
+       {
+               m_priv->buf.append(&tmp[0], tmp.size());
+       }
+       return *this;
+}
+
+#if LOG4CXX_WCHAR_T_API
+CharMessageBuffer& MessageBuffer::operator<<(const CFStringRef& msg)
+{
+       LOG4CXX_DECODE_CFSTRING(tmp, msg);
+       return m_priv->cbuf << tmp;
+}
+#endif // LOG4CXX_WCHAR_T_API
+
 #endif // LOG4CXX_CFSTRING_API
 
diff --git a/src/main/cpp/transcoder.cpp b/src/main/cpp/transcoder.cpp
index 9b4b96b8..6cbe9f26 100644
--- a/src/main/cpp/transcoder.cpp
+++ b/src/main/cpp/transcoder.cpp
@@ -23,6 +23,8 @@
 #include <log4cxx/helpers/bytebuffer.h>
 #include <log4cxx/helpers/charsetdecoder.h>
 #include <log4cxx/helpers/charsetencoder.h>
+#include <log4cxx/helpers/stringhelper.h>
+#include <log4cxx/helpers/loglog.h>
 #include <vector>
 #include <cstring>
 #if !defined(LOG4CXX)
@@ -574,7 +576,7 @@ void Transcoder::encode(unsigned int sv, std::wstring& dst)
 
 
 
-#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#if LOG4CXX_UNICHAR_API
 void Transcoder::decode(const std::basic_string<UniChar>& src, LogString& dst)
 {
 #if LOG4CXX_LOGCHAR_IS_UNICHAR
@@ -623,32 +625,32 @@ void Transcoder::encode(unsigned int sv, 
std::basic_string<UniChar>& dst)
 #if LOG4CXX_CFSTRING_API
 void Transcoder::decode(const CFStringRef& src, LogString& dst)
 {
-       const UniChar* chars = CFStringGetCharactersPtr(src);
+       auto length = CFStringGetLength(src);
+#if defined(_DEBUG)
+       Pool pool;
+       LogString msg(LOG4CXX_STR("Transcoder::decodeCFString"));
+       msg += LOG4CXX_STR(" length ");
+       StringHelper::toString((size_t)length, pool, msg);
+       LogLog::debug(msg);
+#endif
 
-       if (chars)
+       if (length > 0)
        {
-               decode(chars, dst);
-       }
-       else
-       {
-               size_t length = CFStringGetLength(src);
-
-               if (length > 0)
+               std::vector<unsigned short> tmp(length);
+               CFStringGetCharacters(src, CFRangeMake(0, length), &tmp[0]);
+               for (auto i = tmp.begin(); i != tmp.end(); )
                {
-                       std::vector<UniChar> tmp(length);
-                       CFStringGetCharacters(src, CFRangeMake(0, length), 
&tmp[0]);
-#if LOG4CXX_LOGCHAR_IS_UNICHAR
-                       dst.append(&tmp[0], tmp.size());
-#else
-                       decode(std::basic_string<UniChar>(&tmp[0], tmp.size()), 
dst);
-#endif
+                       unsigned int cp = decodeUTF16(tmp, i);
+                       encode(cp, dst);
                }
        }
 }
 
 CFStringRef Transcoder::encode(const LogString& src)
 {
-       LOG4CXX_ENCODE_UNICHAR(tmp, src);
+       std::basic_string<unsigned short> tmp;
+       for (auto ch : src)
+               encodeUTF16(ch, tmp);
        return CFStringCreateWithCharacters(kCFAllocatorDefault, tmp.data(), 
tmp.size());
 }
 #endif // #if LOG4CXX_CFSTRING_API
diff --git a/src/main/include/log4cxx/helpers/messagebuffer.h 
b/src/main/include/log4cxx/helpers/messagebuffer.h
index a2bbefbe..cc568f25 100644
--- a/src/main/include/log4cxx/helpers/messagebuffer.h
+++ b/src/main/include/log4cxx/helpers/messagebuffer.h
@@ -74,6 +74,15 @@ class LOG4CXX_EXPORT CharMessageBuffer
                 *   @return this buffer.
                 */
                CharMessageBuffer& operator<<(const char msg);
+#if LOG4CXX_CFSTRING_API
+               /**
+                  *   Appends a string into the buffer and
+                  *   fixes the buffer to use char characters.
+                  *   @param msg message to append.
+                  *   @return encapsulated CharMessageBuffer.
+                  */
+               CharMessageBuffer& operator<<(const CFStringRef& msg);
+#endif
 
                /**
                 *   Insertion operator for STL manipulators such as std::fixed.
@@ -201,7 +210,7 @@ std::basic_ostream<char>& operator<<(CharMessageBuffer& os, 
const V& val)
        return ((std::basic_ostream<char>&) os) << val;
 }
 
-#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API || LOG4CXX_LOGCHAR_IS_UNICHAR
+#if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR
 /**
  *   This class is designed to support insertion operations
 *   in the message argument to the LOG4CXX_INFO and similar
@@ -671,7 +680,7 @@ class LOG4CXX_EXPORT MessageBuffer
                 */
                WideMessageBuffer& operator<<(const wchar_t msg);
 
-#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#if LOG4CXX_UNICHAR_API
                /**
                   *   Appends a string into the buffer and
                   *   fixes the buffer to use char characters.
@@ -700,9 +709,23 @@ class LOG4CXX_EXPORT MessageBuffer
                 *   @return encapsulated CharMessageBuffer.
                 */
                UniCharMessageBuffer& operator<<(const UniChar msg);
+
+               /**
+                *   Remove the constructed string.
+                *   @param buf used only to signal that
+                *       the embedded stream was not used.
+                */
+               std::basic_string<UniChar> extract_str(UniCharMessageBuffer& 
buf);
+
+               /**
+                *   Remove the constructed string.
+                *   @param buf used only to signal that
+                *       the embedded stream was not used.
+                */
+               std::basic_string<UniChar> 
extract_str(std::basic_ostream<UniChar>& os);
 #endif
 
-#if LOG4CXX_CFSTRING_API
+#if LOG4CXX_UNICHAR_API && LOG4CXX_CFSTRING_API
                /**
                   *   Appends a string into the buffer and
                   *   fixes the buffer to use char characters.
@@ -710,6 +733,15 @@ class LOG4CXX_EXPORT MessageBuffer
                   *   @return encapsulated CharMessageBuffer.
                   */
                UniCharMessageBuffer& operator<<(const CFStringRef& msg);
+
+#elif LOG4CXX_CFSTRING_API
+               /**
+                  *   Appends a string into the buffer and
+                  *   fixes the buffer to use char characters.
+                  *   @param msg message to append.
+                  *   @return encapsulated CharMessageBuffer.
+                  */
+               CharMessageBuffer& operator<<(const CFStringRef& msg);
 #endif
 
                /**
@@ -812,7 +844,7 @@ class LOG4CXX_EXPORT MessageBuffer
                 */
                const std::wstring& str(std::basic_ostream<wchar_t>& os);
 
-#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#if LOG4CXX_UNICHAR_API
                /**
                 *   Get content of buffer.
                 *   @param buf used only to signal
diff --git a/src/main/include/log4cxx/helpers/transcoder.h 
b/src/main/include/log4cxx/helpers/transcoder.h
index a0d0ef34..477bc7c9 100644
--- a/src/main/include/log4cxx/helpers/transcoder.h
+++ b/src/main/include/log4cxx/helpers/transcoder.h
@@ -130,7 +130,7 @@ class LOG4CXX_EXPORT Transcoder
 #endif
 
 
-#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API || LOG4CXX_LOGCHAR_IS_UNICHAR
+#if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR
                static void decode(const std::basic_string<UniChar>& src, 
LogString& dst);
                static void encode(const LogString& src, 
std::basic_string<UniChar>& dst);
 
diff --git a/src/main/include/log4cxx/logger.h 
b/src/main/include/log4cxx/logger.h
index 3b822ee0..2e198b64 100644
--- a/src/main/include/log4cxx/logger.h
+++ b/src/main/include/log4cxx/logger.h
@@ -551,7 +551,7 @@ class LOG4CXX_EXPORT Logger :
                */
                void forcedLog(const LevelPtr& level, const std::wstring& 
message) const;
 #endif
-#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#if LOG4CXX_UNICHAR_API
                /**
                Add a new logging event containing \c message and \c location 
to attached appender(s).
                without further checks.
diff --git a/src/main/include/log4cxx/logstring.h 
b/src/main/include/log4cxx/logstring.h
index eca33fe9..e8c5bb55 100644
--- a/src/main/include/log4cxx/logstring.h
+++ b/src/main/include/log4cxx/logstring.h
@@ -34,7 +34,7 @@ extern "C" {
 namespace log4cxx
 {
 
-#if LOG4CXX_LOGCHAR_IS_UNICHAR || LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#if LOG4CXX_LOGCHAR_IS_UNICHAR || LOG4CXX_UNICHAR_API
        typedef unsigned short UniChar;
 #endif
 
diff --git a/src/main/include/log4cxx/stream.h 
b/src/main/include/log4cxx/stream.h
index 8dcaf41a..3a90d08d 100644
--- a/src/main/include/log4cxx/stream.h
+++ b/src/main/include/log4cxx/stream.h
@@ -420,7 +420,7 @@ class LOG4CXX_EXPORT wlogstream : public logstream_base
 };
 #endif
 
-#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#if LOG4CXX_UNICHAR_API
 /**
  *  An STL-like stream API for log4cxx using UniChar as the character type.
 *. Instances of log4cxx::logstream
diff --git a/src/test/cpp/CMakeLists.txt b/src/test/cpp/CMakeLists.txt
index 74d9a3f9..3b66d1c5 100644
--- a/src/test/cpp/CMakeLists.txt
+++ b/src/test/cpp/CMakeLists.txt
@@ -104,7 +104,14 @@ else()
 endif()
 
 get_filename_component(UNIT_TEST_WORKING_DIR ../resources ABSOLUTE)
+if(LOG4CXX_CFSTRING)
+  set(CFSTR_TESTS filetestcase messagebuffertest leveltestcase streamtestcase)
+endif()
 foreach(testName IN LISTS ALL_LOG4CXX_TESTS)
+    if (${testName} IN_LIST CFSTR_TESTS)
+        target_compile_options(${testName} PRIVATE "-fconstant-cfstrings")
+        target_link_libraries(${testName} PRIVATE "-framework CoreFoundation")
+    endif()
     target_compile_definitions(${testName} PRIVATE ${TEST_COMPILE_DEFINITIONS} 
${LOG4CXX_COMPILE_DEFINITIONS} ${APR_COMPILE_DEFINITIONS} 
${APR_UTIL_COMPILE_DEFINITIONS} )
     target_include_directories(${testName} PRIVATE ${CMAKE_CURRENT_LIST_DIR} 
$<TARGET_PROPERTY:log4cxx,INCLUDE_DIRECTORIES>)
     target_link_libraries(${testName} PRIVATE testingFramework 
testingUtilities log4cxx ${APR_LIBRARIES} ${APR_SYSTEM_LIBS} Threads::Threads 
${ODBC_LIBRARIES} )
diff --git a/src/test/cpp/filetestcase.cpp b/src/test/cpp/filetestcase.cpp
index 3b1c2b5f..00146c83 100644
--- a/src/test/cpp/filetestcase.cpp
+++ b/src/test/cpp/filetestcase.cpp
@@ -27,6 +27,7 @@
 #include <log4cxx/helpers/fileoutputstream.h>
 #include <log4cxx/helpers/inputstreamreader.h>
 #include <log4cxx/helpers/fileinputstream.h>
+#include <log4cxx/helpers/loglog.h>
 
 #if LOG4CXX_CFSTRING_API
        #include <CoreFoundation/CFString.h>
@@ -59,6 +60,15 @@ LOGUNIT_CLASS(FileTestCase)
        LOGUNIT_TEST(deleteBackslashedFileName);
        LOGUNIT_TEST_SUITE_END();
 
+#ifdef _DEBUG
+       struct Fixture
+       {
+               Fixture() {
+                       helpers::LogLog::setInternalDebugging(true);
+               }
+       } suiteFixture;
+#endif
+
 public:
        void defaultConstructor()
        {
@@ -123,7 +133,7 @@ public:
 #if LOG4CXX_CFSTRING_API
        void cfstringConstructor()
        {
-               File propFile(CFSTR("input/patternLayout.properties"));
+               File propFile(CFSTR("input/patternLayout1.properties"));
                Pool pool;
                bool exists = propFile.exists(pool);
                LOGUNIT_ASSERT_EQUAL(true, exists);
diff --git a/src/test/cpp/helpers/messagebuffertest.cpp 
b/src/test/cpp/helpers/messagebuffertest.cpp
index b0dee799..deba396b 100644
--- a/src/test/cpp/helpers/messagebuffertest.cpp
+++ b/src/test/cpp/helpers/messagebuffertest.cpp
@@ -20,6 +20,7 @@
 #include "../insertwide.h"
 #include "../logunit.h"
 #include <log4cxx/logstring.h>
+#include <log4cxx/helpers/loglog.h>
 
 #if LOG4CXX_CFSTRING_API
        #include <CoreFoundation/CFString.h>
@@ -56,6 +57,15 @@ LOGUNIT_CLASS(MessageBufferTest)
        LOGUNIT_TEST_SUITE_END();
 
 
+#ifdef _DEBUG
+       struct Fixture
+       {
+               Fixture() {
+                       helpers::LogLog::setInternalDebugging(true);
+               }
+       } suiteFixture;
+#endif
+
 public:
        void testInsertChar()
        {
@@ -191,7 +201,7 @@ public:
 
 #endif
 
-#if LOG4CXX_CFSTRING_API
+#if LOG4CXX_UNICHAR_API && LOG4CXX_CFSTRING_API
        void testInsertCFString()
        {
                MessageBuffer buf;
@@ -203,7 +213,18 @@ public:
                
LOGUNIT_ASSERT_EQUAL(std::basic_string<log4cxx::UniChar>(greeting), 
buf.str(retval));
                LOGUNIT_ASSERT_EQUAL(false, buf.hasStream());
        }
-
+#elif LOG4CXX_CFSTRING_API
+       void testInsertCFString()
+       {
+               MessageBuffer buf;
+               const log4cxx::logchar greeting[] = { 'H', 'e', 'l', 'l', 'o',
+                               ',', ' ', 'W', 'o', 'r', 'l', 'd', 0
+                       };
+               CharMessageBuffer& retval = buf << CFSTR("Hello")
+                       << CFSTR(", World");
+               
LOGUNIT_ASSERT_EQUAL(std::basic_string<log4cxx::logchar>(greeting), 
buf.str(retval));
+               LOGUNIT_ASSERT_EQUAL(false, buf.hasStream());
+       }
 #endif
 
 };
diff --git a/src/test/cpp/insertwide.h b/src/test/cpp/insertwide.h
index c53b75a6..613a55f0 100644
--- a/src/test/cpp/insertwide.h
+++ b/src/test/cpp/insertwide.h
@@ -26,7 +26,7 @@ std::ostream& operator<<(std::ostream& os,
        const std::wstring& str);
 #endif
 
-#if LOG4CXX_LOGCHAR_IS_UNICHAR  || LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#if LOG4CXX_LOGCHAR_IS_UNICHAR  || LOG4CXX_UNICHAR_API
 std::ostream& operator<<(std::ostream& os,
        const std::basic_string<log4cxx::UniChar>& str);
 #endif
diff --git a/src/test/cpp/leveltestcase.cpp b/src/test/cpp/leveltestcase.cpp
index e9f90eab..176697e6 100644
--- a/src/test/cpp/leveltestcase.cpp
+++ b/src/test/cpp/leveltestcase.cpp
@@ -19,6 +19,7 @@
 #include <log4cxx/level.h>
 #include "testchar.h"
 #include "logunit.h"
+#include <log4cxx/helpers/loglog.h>
 
 #if LOG4CXX_CFSTRING_API
        #include <CoreFoundation/CFString.h>
@@ -46,6 +47,15 @@ LOGUNIT_CLASS(LevelTestCase)
        LOGUNIT_TEST(testTrimmedToTrace);
        LOGUNIT_TEST_SUITE_END();
 
+#ifdef _DEBUG
+       struct Fixture
+       {
+               Fixture() {
+                       helpers::LogLog::setInternalDebugging(true);
+               }
+       } suiteFixture;
+#endif
+
 public:
        void testToLevelFatal()
        {
diff --git a/src/test/cpp/logunit.cpp b/src/test/cpp/logunit.cpp
index 3e044b89..ce03206a 100644
--- a/src/test/cpp/logunit.cpp
+++ b/src/test/cpp/logunit.cpp
@@ -206,7 +206,7 @@ void TestFixture::assertEquals(const std::wstring expected,
        }
 }
 #endif
-#if LOG4CXX_LOGCHAR_IS_UNICHAR || LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#if LOG4CXX_LOGCHAR_IS_UNICHAR || LOG4CXX_UNICHAR_API
 void TestFixture::assertEquals(const std::basic_string<log4cxx::UniChar> 
expected,
        const std::basic_string<log4cxx::UniChar> actual,
        const char* expectedExpr,
diff --git a/src/test/cpp/logunit.h b/src/test/cpp/logunit.h
index 2e0e3d9e..cdd7ac66 100644
--- a/src/test/cpp/logunit.h
+++ b/src/test/cpp/logunit.h
@@ -77,7 +77,7 @@ class TestFixture
                        const char* actualExpr,
                        int lineno);
 #endif
-#if LOG4CXX_LOGCHAR_IS_UNICHAR || LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+#if LOG4CXX_LOGCHAR_IS_UNICHAR || LOG4CXX_UNICHAR_API
                void assertEquals(const std::basic_string<log4cxx::UniChar> 
expected,
                        const std::basic_string<log4cxx::UniChar> actual,
                        const char* expectedExpr,
diff --git a/src/test/cpp/streamtestcase.cpp b/src/test/cpp/streamtestcase.cpp
index e89d7192..c90efd90 100644
--- a/src/test/cpp/streamtestcase.cpp
+++ b/src/test/cpp/streamtestcase.cpp
@@ -17,7 +17,7 @@
 
 #include <log4cxx/log4cxx.h>
  /* Prevent error C2491: 'std::numpunct<_Elem>::id': definition of dllimport 
static data member not allowed */
-#if defined(_MSC_VER) && (LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API)
+#if defined(_MSC_VER) && LOG4CXX_UNICHAR_API
 #define __FORCE_INSTANCE
 #endif
 #include <ostream>
@@ -30,6 +30,7 @@
 #include "insertwide.h"
 #include "logunit.h"
 #include <log4cxx/stream.h>
+#include <log4cxx/helpers/loglog.h>
 
 #if LOG4CXX_CFSTRING_API
        #include <CoreFoundation/CFString.h>
@@ -121,6 +122,8 @@ LOGUNIT_CLASS(StreamTestCase)
 #if LOG4CXX_CFSTRING_API
        LOGUNIT_TEST(testCFString);
        LOGUNIT_TEST(testCFStringAppend);
+#endif
+#if LOG4CXX_UNICHAR_API && LOG4CXX_CFSTRING_API
        LOGUNIT_TEST(testULogStreamCFString);
        LOGUNIT_TEST(testULogStreamCFString2);
 #endif
@@ -128,6 +131,15 @@ LOGUNIT_CLASS(StreamTestCase)
 
        VectorAppenderPtr vectorAppender;
 
+#ifdef _DEBUG
+       struct Fixture
+       {
+               Fixture() {
+                       helpers::LogLog::setInternalDebugging(true);
+               }
+       } suiteFixture;
+#endif
+
 public:
        void setUp()
        {
@@ -623,17 +635,19 @@ public:
        void testCFString()
        {
                LoggerPtr root(Logger::getRootLogger());
-               LOG4CXX_INFO(root, CFSTR("This is a test"))
+               LOG4CXX_INFO(root, CFSTR("This is a test"));
                LOGUNIT_ASSERT_EQUAL((size_t) 1, 
vectorAppender->getVector().size());
        }
 
        void testCFStringAppend()
        {
                LoggerPtr root(Logger::getRootLogger());
-               LOG4CXX_INFO(root, CFSTR("This is a test") << CFSTR(": Details 
to follow"))
+               LOG4CXX_INFO(root, CFSTR("This is a test") << CFSTR(": Details 
to follow"));
                LOGUNIT_ASSERT_EQUAL((size_t) 1, 
vectorAppender->getVector().size());
        }
+#endif
 
+#if LOG4CXX_UNICHAR_API && LOG4CXX_CFSTRING_API
        void testULogStreamCFString()
        {
                ulogstream root(Logger::getRootLogger(), Level::getInfo());

Reply via email to