You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by ca...@apache.org on 2008/02/15 07:34:05 UTC

svn commit: r627959 - in /logging/log4cxx/trunk: ./ src/main/cpp/ src/main/include/log4cxx/ src/test/cpp/ src/test/cpp/xml/ src/test/resources/input/xml/

Author: carnold
Date: Thu Feb 14 22:34:03 2008
New Revision: 627959

URL: http://svn.apache.org/viewvc?rev=627959&view=rev
Log:
LOGCXX-241: Add test case and setlocale

Added:
    logging/log4cxx/trunk/src/test/resources/input/xml/DOMTestCase4.xml   (with props)
Modified:
    logging/log4cxx/trunk/build.xml
    logging/log4cxx/trunk/src/main/cpp/file.cpp
    logging/log4cxx/trunk/src/main/cpp/fileinputstream.cpp
    logging/log4cxx/trunk/src/main/include/log4cxx/file.h
    logging/log4cxx/trunk/src/test/cpp/logunit.cpp
    logging/log4cxx/trunk/src/test/cpp/xml/domtestcase.cpp
    logging/log4cxx/trunk/src/test/resources/input/xml/DOMTestCase3.xml

Modified: logging/log4cxx/trunk/build.xml
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/build.xml?rev=627959&r1=627958&r2=627959&view=diff
==============================================================================
--- logging/log4cxx/trunk/build.xml (original)
+++ logging/log4cxx/trunk/build.xml Thu Feb 14 22:34:03 2008
@@ -850,7 +850,12 @@
             <env key="Path"
                    value="${log4cxx.lib.dir};${env.Path}"/>
     </exec>
-
+    <available property="dom3-status" value="" file="src/test/resources/output/dom&#xB3;"/>
+    <available property="dom4-status" value="" file="src/test/resources/output/dom&#x3195;"/>
+    <property name="dom3-status" value="NOT"/>
+    <property name="dom4-status" value="NOT"/>
+    <echo>output/dom&#xB3; was ${dom3-status} created in DOMTestCase::test3</echo>
+    <echo>output/dom&#x3195; was ${dom4-status} created in DOMTestCase::test4</echo>
 </target>
 
 <target name="run-standalone-unittest"
@@ -874,6 +879,12 @@
             <env key="Path"
                    value="${log4cxx.lib.dir};${env.Path}"/>
     </exec>
+    <available property="dom3-status" value="" file="src/test/resources/output/dom&#xB3;"/>
+    <available property="dom4-status" value="" file="src/test/resources/output/dom&#x3195;"/>
+    <property name="dom3-status" value="NOT"/>
+    <property name="dom4-status" value="NOT"/>
+    <echo>output/dom&#xB3; was ${dom3-status} created in DOMTestCase::test3</echo>
+    <echo>output/dom&#x3195; was ${dom4-status} created in DOMTestCase::test4</echo>
 </target>
 
 <target name="run-socketserver" depends="build-unittest, clean-output"

Modified: logging/log4cxx/trunk/src/main/cpp/file.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/file.cpp?rev=627959&r1=627958&r2=627959&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/file.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/file.cpp Thu Feb 14 22:34:03 2008
@@ -105,11 +105,15 @@
     return name;
 }
 
-File& File::setName(const LogString& newName) {
+File& File::setPath(const LogString& newName) {
     name.assign(newName);
     osName.erase();
     Transcoder::encode(newName, osName);
     return *this;
+}
+
+File& File::setName(const LogString& newName) {
+    return setPath(newName);
 }
 
 std::string File::getOSName() const {

Modified: logging/log4cxx/trunk/src/main/cpp/fileinputstream.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/fileinputstream.cpp?rev=627959&r1=627958&r2=627959&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/fileinputstream.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/fileinputstream.cpp Thu Feb 14 22:34:03 2008
@@ -31,11 +31,11 @@
 
 IMPLEMENT_LOG4CXX_OBJECT(FileInputStream)
 
-FileInputStream::FileInputStream(const LogString& filename) {
+FileInputStream::FileInputStream(const LogString& filename) : fileptr(0) {
     open(filename);
 }
 
-FileInputStream::FileInputStream(const logchar* filename) {
+FileInputStream::FileInputStream(const logchar* filename) : fileptr(0) {
     LogString fn(filename);
     open(fn);
 }

Modified: logging/log4cxx/trunk/src/main/include/log4cxx/file.h
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/file.h?rev=627959&r1=627958&r2=627959&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/file.h (original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/file.h Thu Feb 14 22:34:03 2008
@@ -62,6 +62,7 @@
                     log4cxx_time_t lastModified(log4cxx::helpers::Pool& p) const;
                     LogString getName() const;
                     File& setName(const LogString&);
+                    File& setPath(const LogString&);
                     std::string getOSName() const;
 
                     log4cxx_status_t open(apr_file_t** file, int flags,

Modified: logging/log4cxx/trunk/src/test/cpp/logunit.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/logunit.cpp?rev=627959&r1=627958&r2=627959&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/logunit.cpp (original)
+++ logging/log4cxx/trunk/src/test/cpp/logunit.cpp Thu Feb 14 22:34:03 2008
@@ -22,8 +22,15 @@
 
 #include <apr_general.h>
 #include <algorithm>
+#include <stdlib.h>
 
 void initialize() {
+    const char* ctype = setlocale(LC_CTYPE, "");
+    if (ctype == 0) {
+        puts("LC_CTYPE: NULL");
+    } else {
+        printf("LC_CTYPE: %s\n", ctype);
+    }
     apr_initialize();
 }
 
@@ -189,14 +196,14 @@
 }
 
 
-LogUnit::TestSuite::TestSuite(const char* fname) : filename(fname), disabled(false) {
-#if defined(_WIN32)
-    for(size_t i = filename.find('\\');
-        i != std::string::npos;
-        i = filename.find('\\', i+1)) {
-        filename.replace(i, 1, 1, '/');
-    }
-#endif
+LogUnit::TestSuite::TestSuite(const char* fname) : filename(fname), disabled(false) {
+#if defined(_WIN32)
+    for(size_t i = filename.find('\\');
+        i != std::string::npos;
+        i = filename.find('\\', i+1)) {
+        filename.replace(i, 1, 1, '/');
+    }
+#endif
 }
 
 void LogUnit::TestSuite::addTest(const char*, test_func func) {

Modified: logging/log4cxx/trunk/src/test/cpp/xml/domtestcase.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/xml/domtestcase.cpp?rev=627959&r1=627958&r2=627959&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/xml/domtestcase.cpp (original)
+++ logging/log4cxx/trunk/src/test/cpp/xml/domtestcase.cpp Thu Feb 14 22:34:03 2008
@@ -52,6 +52,8 @@
 #if defined(_WIN32)
                 LOGUNIT_TEST(test2);
 #endif
+                LOGUNIT_TEST(test3);
+                LOGUNIT_TEST(test4);                
         LOGUNIT_TEST_SUITE_END();
 
         LoggerPtr root;
@@ -157,34 +159,71 @@
 
         void common()
         {
-                int i = -1;
-                std::ostringstream os;
-                os << "Message " << ++i;
-
-                LOG4CXX_DEBUG(logger, os.str());
-                LOG4CXX_DEBUG(root, os.str());
-
-                os.str("");
-                os << "Message " << ++i;
-                LOG4CXX_INFO(logger,os.str());
-                LOG4CXX_INFO(root, os.str());
-
-                os.str("");
-                os << "Message " << ++i;
-                LOG4CXX_WARN(logger, os.str());
-                LOG4CXX_WARN(root, os.str());
-
-                os.str("");
-                os << "Message " << ++i;
-                LOG4CXX_ERROR(logger, os.str());
-                LOG4CXX_ERROR(root, os.str());
-
-                os.str("");
-                os << "Message " << ++i;
-                LOG4CXX_FATAL(logger, os.str());
-                LOG4CXX_FATAL(root, os.str());
+                int i = 0;
 
+                LOG4CXX_DEBUG(logger, "Message " << i);
+                LOG4CXX_DEBUG(root, "Message " << i);
+
+                i++;
+                LOG4CXX_INFO(logger, "Message " << i);
+                LOG4CXX_INFO(root, "Message " << i);
+
+                i++;
+                LOG4CXX_WARN(logger, "Message " << i);
+                LOG4CXX_WARN(root, "Message " << i);
+
+                i++;
+                LOG4CXX_ERROR(logger, "Message " << i);
+                LOG4CXX_ERROR(root, "Message " << i);
+
+                i++;
+                LOG4CXX_FATAL(logger, "Message " << i);
+                LOG4CXX_FATAL(root, "Message " << i);
+
+        }
+      
+        /**
+         *   Creates a output file that ends with a superscript 3.
+         *   Output file is checked by build.xml after completion.
+         */  
+        void test3() {
+                DOMConfigurator::configure(LOG4CXX_TEST_STR("input/xml/DOMTestCase3.xml"));
+                LOG4CXX_INFO(logger, "File name is expected to end with a superscript 3");
+#if LOG4CXX_LOGCHAR_IS_UTF8
+                const logchar end[] = { 0xC2, 0xB3, 0 };
+#else
+                const logchar end[] = { 0xB3, 0 };
+#endif
+                LogString fname("output/dom");
+                fname.append(end);
+                File file;
+                file.setPath(fname);
+                Pool p;
+                bool exists = file.exists(p);
+                LOGUNIT_ASSERT(exists);
+        }
+
+        /**
+         *   Creates a output file that ends with a superscript 3.
+         *   Output file is checked by build.xml after completion.
+         */  
+        void test4() {
+                DOMConfigurator::configure(LOG4CXX_TEST_STR("input/xml/DOMTestCase4.xml"));
+                LOG4CXX_INFO(logger, "File name is expected to end with an ideographic 4");
+#if LOG4CXX_LOGCHAR_IS_UTF8
+                const logchar end[] = { 0xE3, 0x86, 0x95, 0 };
+#else
+                const logchar end[] = { 0x3195, 0 };
+#endif
+                LogString fname("output/dom");
+                fname.append(end);
+                File file;
+                file.setPath(fname);
+                Pool p;
+                bool exists = file.exists(p);
+                LOGUNIT_ASSERT(exists);
         }
+        
 };
 
 LOGUNIT_TEST_SUITE_REGISTRATION(DOMTestCase);

Modified: logging/log4cxx/trunk/src/test/resources/input/xml/DOMTestCase3.xml
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/resources/input/xml/DOMTestCase3.xml?rev=627959&r1=627958&r2=627959&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/resources/input/xml/DOMTestCase3.xml (original)
+++ logging/log4cxx/trunk/src/test/resources/input/xml/DOMTestCase3.xml Thu Feb 14 22:34:03 2008
@@ -21,7 +21,7 @@
 <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
   <appender name="A1" class="org.apache.log4j.FileAppender">
     
-    <param name="File"   value="e:\tmp\temp.A1" />
+    <param name="File"   value="output/dom&#xB3;" />
     <param name="Append" value="false" />	    
     
     <layout class="org.apache.log4j.PatternLayout">

Added: logging/log4cxx/trunk/src/test/resources/input/xml/DOMTestCase4.xml
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/resources/input/xml/DOMTestCase4.xml?rev=627959&view=auto
==============================================================================
--- logging/log4cxx/trunk/src/test/resources/input/xml/DOMTestCase4.xml (added)
+++ logging/log4cxx/trunk/src/test/resources/input/xml/DOMTestCase4.xml Thu Feb 14 22:34:03 2008
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+  <appender name="A1" class="org.apache.log4j.FileAppender">
+    
+    <param name="File"   value="output/dom&#x3195;" />
+    <param name="Append" value="false" />	    
+    
+    <layout class="org.apache.log4j.PatternLayout">
+      <param name="ConversionPattern" value="%-5p %c{2} - %m%n"/>
+    </layout>	    
+  </appender>
+  
+  <root>
+    <priority value ="debug" />
+    <appender-ref ref="A1" />
+  </root>
+  
+</log4j:configuration>

Propchange: logging/log4cxx/trunk/src/test/resources/input/xml/DOMTestCase4.xml
------------------------------------------------------------------------------
    svn:executable = *