carnold     2004/12/14 12:26:14

  Modified:    src      transcoder.cpp
               tests/src filetestcase.cpp l7dtestcase.cpp
               tests/src/helpers relativetimedateformattestcase.cpp
  Log:
  LOGCXX-10: tchar.h/unicode, Linux iteration
  
  Revision  Changes    Path
  1.4       +88 -82    logging-log4cxx/src/transcoder.cpp
  
  Index: transcoder.cpp
  ===================================================================
  RCS file: /home/cvs/logging-log4cxx/src/transcoder.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- transcoder.cpp    14 Dec 2004 19:03:14 -0000      1.3
  +++ transcoder.cpp    14 Dec 2004 20:26:13 -0000      1.4
  @@ -1,43 +1,43 @@
  -/*
  - * Copyright 2004 The Apache Software Foundation.
  - *
  - * Licensed under the Apache License, Version 2.0 (the "License");
  - * you may not use this file except in compliance with the License.
  - * You may obtain a copy of the License at
  - *
  - *      http://www.apache.org/licenses/LICENSE-2.0
  - *
  - * Unless required by applicable law or agreed to in writing, software
  - * distributed under the License is distributed on an "AS IS" BASIS,
  - * 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.
  - */
  -
  -#include <log4cxx/helpers/transcoder.h>
  +/*
  + * Copyright 2004 The Apache Software Foundation.
  + *
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *      http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * 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.
  + */
  +
  +#include <log4cxx/helpers/transcoder.h>
   #include <log4cxx/helpers/pool.h>
  -#include <stdlib.h>
  -
  -using namespace log4cxx;
  -using namespace log4cxx::helpers;
  -
  -
  -
  -/**
  -*   Appends an external string to an
  -*     internal string.
  -*/
  +#include <stdlib.h>
  +
  +using namespace log4cxx;
  +using namespace log4cxx::helpers;
  +
  +
  +
  +/**
  +*   Appends an external string to an
  +*     internal string.
  +*/
   #if defined(LOG4CXX_LOGCHAR_IS_WCHAR)
   
   
  -#if !defined(_GCC_VER_)
  +#if !defined(__GCC__)
   namespace log4cxx {
         struct mbstate_t {};
         size_t mbsnrtowcs(wchar_t *dest, const char **src,
             size_t srclenin, size_t destlenin, mbstate_t *ps) {
             size_t destlen = destlenin;
             size_t srclen = srclenin;
  -          size_t mblen = -1;
  +          size_t mblen;
             while(srclen > 0 && destlen > 0) {
               mblen = mbtowc(dest, *src, srclen);
               if (mblen <= 0) break;
  @@ -56,10 +56,16 @@
             size_t destlenin, mbstate_t *ps) {
             size_t destlen = destlenin;
             size_t srclen = srclenin;
  -          size_t mblen = -1;
  +          size_t mblen;
             char buf[12];
             while(srclen > 0 && destlen > 0) {
               mblen = wctomb(buf, **src);
  +            //
  +            //   not enough space
  +            //
  +            if (mblen > destlen) {
  +              return (size_t) -1;
  +            }
               if (mblen <= 0) break;
               *src++;
               memcpy(dest, buf, mblen);
  @@ -76,54 +82,54 @@
   #endif
   
   
  -
  -void Transcoder::decode(const char* src, size_t len, LogString& dst) {
  -  wchar_t buf[BUFSIZE];
  -  mbstate_t ps;
  -  size_t inRemaining = len;
  -  for(const char* in = src;
  -     in < src + len && in != NULL;) {
  -     size_t rv = mbsnrtowcs(buf, &in, len - (in - src), BUFSIZE, &ps);
  -     if (rv > (size_t) 0) {
  -        dst.append(buf, rv);
  -     }
  -     //
  -     //   invalid sequence, add a substitution character and move on
  -     //
  -     if (rv < 0) {
  -       dst.append(1, SUBSTITUTION_WCHAR);
  -       in++;
  -     }
  -  }
  -}
  -
  -void Transcoder::decode(const wchar_t* src, size_t len, LogString& dst) {
  -  dst.append(src, len);
  -}
  -
  -void Transcoder::encode(const LogString& src, std::string& dst) {
  -  char buf[BUFSIZE];
  -  mbstate_t ps;
  -  const wchar_t* pSrc = src.data();
  -  size_t srcLen = src.length();
  -  for(const wchar_t* in = pSrc;
  -      in < pSrc + srcLen && in != NULL;) {
  -        size_t rv = wcsnrtombs(buf, &in, srcLen - (in - pSrc), BUFSIZE, &ps);
  -        if (rv > (size_t) 0) {
  -          dst.append(buf, rv);
  -        }
  -        if (rv < 0) {
  -          dst.append(1, SUBSTITUTION_CHAR);
  -          in++;
  -        }
  -  }
  -}
  -
  -void Transcoder::encode(const LogString& src, std::wstring& dst) {
  -  dst.append(src);
  -}
  -
  -#endif
  -
  -
  -
  +
  +void Transcoder::decode(const char* src, size_t len, LogString& dst) {
  +  wchar_t buf[BUFSIZE];
  +  mbstate_t ps;
  +  size_t inRemaining = len;
  +  for(const char* in = src;
  +     in < src + len && in != NULL;) {
  +     size_t rv = mbsnrtowcs(buf, &in, len - (in - src), BUFSIZE, &ps);
  +     if (rv > (size_t) 0) {
  +        dst.append(buf, rv);
  +     }
  +     //
  +     //   invalid sequence, add a substitution character and move on
  +     //
  +     if (rv < 0) {
  +       dst.append(1, SUBSTITUTION_WCHAR);
  +       in++;
  +     }
  +  }
  +}
  +
  +void Transcoder::decode(const wchar_t* src, size_t len, LogString& dst) {
  +  dst.append(src, len);
  +}
  +
  +void Transcoder::encode(const LogString& src, std::string& dst) {
  +  char buf[BUFSIZE];
  +  mbstate_t ps;
  +  const wchar_t* pSrc = src.data();
  +  size_t srcLen = src.length();
  +  for(const wchar_t* in = pSrc;
  +      in < pSrc + srcLen && in != NULL;) {
  +        size_t rv = wcsnrtombs(buf, &in, srcLen - (in - pSrc), BUFSIZE, &ps);
  +        if (rv > (size_t) 0) {
  +          dst.append(buf, rv);
  +        }
  +        if (rv < 0) {
  +          dst.append(1, SUBSTITUTION_CHAR);
  +          in++;
  +        }
  +  }
  +}
  +
  +void Transcoder::encode(const LogString& src, std::wstring& dst) {
  +  dst.append(src);
  +}
  +
  +#endif
  +
  +
  +
  
  
  
  1.2       +76 -79    logging-log4cxx/tests/src/filetestcase.cpp
  
  Index: filetestcase.cpp
  ===================================================================
  RCS file: /home/cvs/logging-log4cxx/tests/src/filetestcase.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- filetestcase.cpp  14 Dec 2004 19:03:59 -0000      1.1
  +++ filetestcase.cpp  14 Dec 2004 20:26:14 -0000      1.2
  @@ -1,88 +1,85 @@
  -/*
  - * Copyright 2004 The Apache Software Foundation.
  - *
  - * Licensed under the Apache License, Version 2.0 (the "License");
  - * you may not use this file except in compliance with the License.
  - * You may obtain a copy of the License at
  - *
  - *      http://www.apache.org/licenses/LICENSE-2.0
  - *
  - * Unless required by applicable law or agreed to in writing, software
  - * distributed under the License is distributed on an "AS IS" BASIS,
  - * 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.
  - */
  -
  -#include <cppunit/extensions/HelperMacros.h>
  -#include <log4cxx/file.h>
  -
  -
  -using namespace log4cxx;
  -using namespace log4cxx::helpers;
  +/*
  + * Copyright 2004 The Apache Software Foundation.
  + *
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *      http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * 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.
  + */
  +
  +#include <cppunit/extensions/HelperMacros.h>
  +#include <log4cxx/file.h>
  +#include "insertwide.h"
  +#include <log4cxx/helpers/pool.h>
  +#include <apr_errno.h>
  +
  +using namespace log4cxx;
  +using namespace log4cxx::helpers;
   
   
   class FileTestCase : public CppUnit::TestFixture
   {
  -     CPPUNIT_TEST_SUITE(FileTestCase);
  -             CPPUNIT_TEST(defaultConstructor);
  -             CPPUNIT_TEST(defaultExists);
  -             CPPUNIT_TEST(defaultRead);
  -        CPPUNIT_TEST(propertyRead);
  -        CPPUNIT_TEST(fileWrite1);
  -     CPPUNIT_TEST_SUITE_END();
  +        CPPUNIT_TEST_SUITE(FileTestCase);
  +                CPPUNIT_TEST(defaultConstructor);
  +                CPPUNIT_TEST(defaultExists);
  +                CPPUNIT_TEST(defaultRead);
  +                CPPUNIT_TEST(propertyRead);
  +                CPPUNIT_TEST(fileWrite1);
  +        CPPUNIT_TEST_SUITE_END();
   
   public:
  -     void defaultConstructor()
  -     {
  -        File defFile;
  -        CPPUNIT_ASSERT_EQUAL(std::string(), defFile.getMBCSName());
  -        CPPUNIT_ASSERT_EQUAL(LogString(), defFile.getName());
  -     }
  -
  -     void defaultExists()
  -     {
  -        File defFile;
  -        CPPUNIT_ASSERT_EQUAL(false, defFile.exists());
  -     }
  -
  -
  -     void defaultRead()
  -     {
  -        File defFile;
  -        Pool pool;
  -        CPPUNIT_ASSERT_EQUAL(LogString, defFile.read(pool));
  -     }
  -
  -
  -     void defaultWrite()
  -     {
  -        File defFile;
  -        Pool pool;
  -        LogString greeting("Hello, World");
  -        CPPUNIT_ASSERT(defFile.write(greeting, pool) != APR_SUCCESS);
  -     }
  -
  -    void propertyRead() {
  -        File propFile("input//patternLayout1.properties");
  -        Pool pool;
  -        LogString props(propFile.read(pool));
  -        LogString line1(LOG4CXX_STR("log4j.rootCategory=DEBUG, 
testAppender\n"));
  -        CPPUNIT_ASSERT_EQUAL(line1, props.substr(0, line1.length());
  -    }
  -
  -
  -    void fileWrite1() {
  -        File outFile("output//fileWrite1.txt");
  -        Pool pool;
  -        LogString greeting(LOG4CXX_STR("Hello, World\n"));
  -        apr_status_t stat = outFile.write(greeting, pool);
  -        CPPUNIT_ASSERT_EQUAL(0, stat);
  -
  -        LogString reply(outFile.read(pool));
  -        CPPUNIT_ASSERT_EQUAL(greeting, reply);
  -    }
  -
  +        void defaultConstructor() {
  +          File defFile;
  +          CPPUNIT_ASSERT_EQUAL((std::string) "", defFile.getMBCSName());
  +          CPPUNIT_ASSERT_EQUAL((LogString) LOG4CXX_STR(""), 
defFile.getName());
  +        }
  +
  +        void defaultExists() {
  +          File defFile;
  +          CPPUNIT_ASSERT_EQUAL(false, defFile.exists());
  +        }
  +
  +
  +        void defaultRead() {
  +          File defFile;
  +          Pool pool;
  +          CPPUNIT_ASSERT_EQUAL((LogString) LOG4CXX_STR(""), 
defFile.read(pool));
  +        }
  +
  +
  +        void defaultWrite() {
  +          File defFile;
  +          Pool pool;
  +          LogString greeting(LOG4CXX_STR("Hello, World"));
  +          CPPUNIT_ASSERT(defFile.write(greeting, pool) != APR_SUCCESS);
  +        }
  +
  +        void propertyRead() {
  +          File propFile("input//patternLayout1.properties");
  +          Pool pool;
  +          LogString props(propFile.read(pool));
  +          LogString line1(LOG4CXX_STR("log4j.rootCategory=DEBUG, 
testAppender\n"));
  +          CPPUNIT_ASSERT_EQUAL(line1, props.substr(0, line1.length()));
  +        }
  +
  +
  +        void fileWrite1() {
  +          File outFile("output//fileWrite1.txt");
  +          Pool pool;
  +          LogString greeting(LOG4CXX_STR("Hello, World\n"));
  +          apr_status_t stat = outFile.write(greeting, pool);
  +          CPPUNIT_ASSERT_EQUAL(0, stat);
  +
  +          LogString reply(outFile.read(pool));
  +          CPPUNIT_ASSERT_EQUAL(greeting, reply);
  +        }
   };
   
   
  
  
  
  1.5       +97 -97    logging-log4cxx/tests/src/l7dtestcase.cpp
  
  Index: l7dtestcase.cpp
  ===================================================================
  RCS file: /home/cvs/logging-log4cxx/tests/src/l7dtestcase.cpp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- l7dtestcase.cpp   11 Dec 2004 05:42:27 -0000      1.4
  +++ l7dtestcase.cpp   14 Dec 2004 20:26:14 -0000      1.5
  @@ -1,99 +1,99 @@
  -/*
  - * Copyright 2003,2004 The Apache Software Foundation.
  - *
  - * Licensed under the Apache License, Version 2.0 (the "License");
  - * you may not use this file except in compliance with the License.
  - * You may obtain a copy of the License at
  - *
  - *      http://www.apache.org/licenses/LICENSE-2.0
  - *
  - * Unless required by applicable law or agreed to in writing, software
  - * distributed under the License is distributed on an "AS IS" BASIS,
  - * 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.
  - */
  -
  -#include <cppunit/TestFixture.h>
  -#include <cppunit/extensions/HelperMacros.h>
  -
  -#include <log4cxx/logger.h>
  -#include <log4cxx/propertyconfigurator.h>
  -#include <log4cxx/helpers/propertyresourcebundle.h>
  -
  -#include "util/compare.h"
  -
  +/*
  + * Copyright 2003,2004 The Apache Software Foundation.
  + *
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *      http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * 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.
  + */
  +
  +#include <cppunit/TestFixture.h>
  +#include <cppunit/extensions/HelperMacros.h>
  +
  +#include <log4cxx/logger.h>
  +#include <log4cxx/propertyconfigurator.h>
  +#include <log4cxx/helpers/propertyresourcebundle.h>
  +
  +#include "util/compare.h"
  +
   #include <vector>
  -#include <sstream>
  -
  +#include <sstream>
  +
   #define _T(str) L ## str
  -typedef std::basic_ostringstream<wchar_t> StringBuffer;
  -
  -using namespace log4cxx;
  -using namespace log4cxx::helpers;
  -
  -class L7dTestCase : public CppUnit::TestFixture
  -{
  -     CPPUNIT_TEST_SUITE(L7dTestCase);
  -             CPPUNIT_TEST(test1);
  -     CPPUNIT_TEST_SUITE_END();
  -
  -     LoggerPtr root;
  -     ResourceBundlePtr bundles[3];
  -
  -public:
  -     void setUp()
  -     {
  -             bundles[0] =
  -                     ResourceBundle::getBundle(LOG4CXX_STR("L7D"), 
Locale(LOG4CXX_STR("en"), LOG4CXX_STR("US")));
  -             CPPUNIT_ASSERT(bundles[0] != 0);
  -
  -             bundles[1] =
  -                     ResourceBundle::getBundle(LOG4CXX_STR("L7D"), 
Locale(LOG4CXX_STR("fr"), LOG4CXX_STR("FR")));
  -             CPPUNIT_ASSERT(bundles[1] != 0);
  -
  -             bundles[2] =
  -                     ResourceBundle::getBundle(LOG4CXX_STR("L7D"), 
Locale(LOG4CXX_STR("fr"), LOG4CXX_STR("CH")));
  -             CPPUNIT_ASSERT(bundles[2] != 0);
  -
  -             root = Logger::getRootLogger();
  -     }
  -
  -     void tearDown()
  -     {
  -             root->getLoggerRepository()->resetConfiguration();
  -     }
  -
  -     void test1()
  -     {
  -             
PropertyConfigurator::configure(LOG4CXX_FILE("input/l7d1.properties"));
  -
  -        log4cxx::helpers::Pool pool;
  - 
  -             for (int i = 0; i < 3; i++)
  -             {
  -                     root->setResourceBundle(bundles[i]);
  -
  -                     LOG4CXX_L7DLOG(root, Level::DEBUG, _T("bogus1"));
  -                     LOG4CXX_L7DLOG(root, Level::INFO, _T("test"));
  -                     LOG4CXX_L7DLOG(root, Level::WARN, _T("hello_world"));
  -
  -
  -            StringBuffer os;
  -            os << i + 1;
  -                     LOG4CXX_L7DLOG2(root, Level::DEBUG, _T("msg1"), 
os.str(),
  -                              _T("log4j"));
  -                     LOG4CXX_L7DLOG2(root, Level::getError(), 
_T("bogusMsg"), os.str(),
  -                              _T("log4j"));
  -                     LOG4CXX_L7DLOG2(root, Level::getError(), _T("msg1"), 
os.str(),
  -                              _T("log4j"));
  -                     LOG4CXX_L7DLOG(root, Level::INFO, _T("bogus2"));
  -             }
  -
  -             CPPUNIT_ASSERT(Compare::compare(LOG4CXX_FILE("output/temp"),
  -        LOG4CXX_FILE("witness/l7d.1")));
  -     }
  -
  -};
  -
  -CPPUNIT_TEST_SUITE_REGISTRATION(L7dTestCase);
  +typedef std::basic_ostringstream<wchar_t> StringBuffer;
  +
  +using namespace log4cxx;
  +using namespace log4cxx::helpers;
  +
  +class L7dTestCase : public CppUnit::TestFixture
  +{
  +        CPPUNIT_TEST_SUITE(L7dTestCase);
  +                CPPUNIT_TEST(test1);
  +        CPPUNIT_TEST_SUITE_END();
  +
  +        LoggerPtr root;
  +        ResourceBundlePtr bundles[3];
  +
  +public:
  +        void setUp()
  +        {
  +                bundles[0] =
  +                        ResourceBundle::getBundle(LOG4CXX_STR("L7D"), 
Locale(LOG4CXX_STR("en"), LOG4CXX_STR("US")));
  +                CPPUNIT_ASSERT(bundles[0] != 0);
  +
  +                bundles[1] =
  +                        ResourceBundle::getBundle(LOG4CXX_STR("L7D"), 
Locale(LOG4CXX_STR("fr"), LOG4CXX_STR("FR")));
  +                CPPUNIT_ASSERT(bundles[1] != 0);
  +
  +                bundles[2] =
  +                        ResourceBundle::getBundle(LOG4CXX_STR("L7D"), 
Locale(LOG4CXX_STR("fr"), LOG4CXX_STR("CH")));
  +                CPPUNIT_ASSERT(bundles[2] != 0);
  +
  +                root = Logger::getRootLogger();
  +        }
  +
  +        void tearDown()
  +        {
  +                root->getLoggerRepository()->resetConfiguration();
  +        }
  +
  +        void test1()
  +        {
  +                
PropertyConfigurator::configure(LOG4CXX_FILE("input/l7d1.properties"));
  +
  +                log4cxx::helpers::Pool pool;
  +
  +                for (int i = 0; i < 3; i++)
  +                {
  +                        root->setResourceBundle(bundles[i]);
  +
  +                        LOG4CXX_L7DLOG(root, Level::DEBUG, _T("bogus1"));
  +                        LOG4CXX_L7DLOG(root, Level::INFO, _T("test"));
  +                        LOG4CXX_L7DLOG(root, Level::WARN, _T("hello_world"));
  +
  +
  +                        StringBuffer os;
  +                        os << i + 1;
  +                        LOG4CXX_L7DLOG2(root, Level::DEBUG, _T("msg1"), 
os.str().c_str(),
  +                                 _T("log4j"));
  +                        LOG4CXX_L7DLOG2(root, Level::getError(), 
_T("bogusMsg"), os.str().c_str(),
  +                                 _T("log4j"));
  +                        LOG4CXX_L7DLOG2(root, Level::getError(), _T("msg1"), 
os.str().c_str(),
  +                                 _T("log4j"));
  +                        LOG4CXX_L7DLOG(root, Level::INFO, _T("bogus2"));
  +                }
  +
  +                CPPUNIT_ASSERT(Compare::compare(LOG4CXX_FILE("output/temp"),
  +                LOG4CXX_FILE("witness/l7d.1")));
  +        }
  +
  +};
  +
  +CPPUNIT_TEST_SUITE_REGISTRATION(L7dTestCase);
  
  
  
  1.6       +1 -0      
logging-log4cxx/tests/src/helpers/relativetimedateformattestcase.cpp
  
  Index: relativetimedateformattestcase.cpp
  ===================================================================
  RCS file: 
/home/cvs/logging-log4cxx/tests/src/helpers/relativetimedateformattestcase.cpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- relativetimedateformattestcase.cpp        11 Dec 2004 04:53:29 -0000      
1.5
  +++ relativetimedateformattestcase.cpp        14 Dec 2004 20:26:14 -0000      
1.6
  @@ -22,6 +22,7 @@
   #include <apr_strings.h>
   #include <log4cxx/helpers/stringhelper.h>
   #include "../insertwide.h"
  +#include <apr_time.h>
   
   //Define INT64_C for compilers that don't have it
   #if (!defined(INT64_C))
  
  
  

Reply via email to