Author: carnold
Date: Sat Nov 17 14:12:15 2007
New Revision: 596012

URL: http://svn.apache.org/viewvc?rev=596012&view=rev
Log:
LOGCXX-207: Test cases for reported problem with appender-specific thresholds

Modified:
    logging/log4cxx/trunk/src/test/cpp/propertyconfiguratortest.cpp
    logging/log4cxx/trunk/src/test/cpp/vectorappender.h

Modified: logging/log4cxx/trunk/src/test/cpp/propertyconfiguratortest.cpp
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/propertyconfiguratortest.cpp?rev=596012&r1=596011&r2=596012&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/propertyconfiguratortest.cpp (original)
+++ logging/log4cxx/trunk/src/test/cpp/propertyconfiguratortest.cpp Sat Nov 17 
14:12:15 2007
@@ -1,69 +1,88 @@
-/*
- * 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.
- */
-
-#include <cppunit/extensions/HelperMacros.h>
-#include <log4cxx/helpers/properties.h>
-#include <log4cxx/propertyconfigurator.h>
-#include <log4cxx/logmanager.h>
-
-using namespace log4cxx;
-using namespace log4cxx::helpers;
-
-
-class PropertyConfiguratorTest : public CppUnit::TestFixture
-{
-        CPPUNIT_TEST_SUITE(PropertyConfiguratorTest);
-                CPPUNIT_TEST(testInherited);
-                CPPUNIT_TEST(testNull);
-        CPPUNIT_TEST_SUITE_END();
-
-public:
-    void testInherited() {
-        Properties props;
-        
props.put(LOG4CXX_STR("log4j.rootLogger"),LOG4CXX_STR("DEBUG,VECTOR1"));
-        
props.put(LOG4CXX_STR("log4j.logger.org.apache.log4j.PropertyConfiguratorTest"),
 LOG4CXX_STR("inherited,VECTOR2"));
-        props.put(LOG4CXX_STR("log4j.appender.VECTOR1"), 
LOG4CXX_STR("org.apache.log4j.VectorAppender"));
-        props.put(LOG4CXX_STR("log4j.appender.VECTOR2"), 
LOG4CXX_STR("org.apache.log4j.VectorAppender"));
-        PropertyConfigurator::configure(props);
-        LoggerPtr logger = 
Logger::getLogger("org.apache.log4j.PropertyConfiguratorTest");
-        CPPUNIT_ASSERT_EQUAL((int) Level::DEBUG_INT,
-                logger->getEffectiveLevel()->toInt());
-        Logger::getRootLogger()->setLevel(Level::getError());
-        CPPUNIT_ASSERT_EQUAL((int) Level::ERROR_INT,
-                logger->getEffectiveLevel()->toInt());
-        LogManager::resetConfiguration();
-    }
-
-    void testNull() {
-        Properties props;
-        
props.put(LOG4CXX_STR("log4j.rootLogger"),LOG4CXX_STR("DEBUG,VECTOR1"));
-        
props.put(LOG4CXX_STR("log4j.logger.org.apache.log4j.PropertyConfiguratorTest"),
 LOG4CXX_STR("NuLL,VECTOR2"));
-        props.put(LOG4CXX_STR("log4j.appender.VECTOR1"), 
LOG4CXX_STR("org.apache.log4j.VectorAppender"));
-        props.put(LOG4CXX_STR("log4j.appender.VECTOR2"), 
LOG4CXX_STR("org.apache.log4j.VectorAppender"));
-        PropertyConfigurator::configure(props);
-        LoggerPtr logger = 
Logger::getLogger("org.apache.log4j.PropertyConfiguratorTest");
-        CPPUNIT_ASSERT_EQUAL((int) Level::DEBUG_INT,
-                logger->getEffectiveLevel()->toInt());
-        Logger::getRootLogger()->setLevel(Level::getError());
-        CPPUNIT_ASSERT_EQUAL((int) Level::ERROR_INT,
-                logger->getEffectiveLevel()->toInt());
-        LogManager::resetConfiguration();
-    }
-};
-
-
-CPPUNIT_TEST_SUITE_REGISTRATION(PropertyConfiguratorTest);
+/*
+ * 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.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <log4cxx/helpers/properties.h>
+#include <log4cxx/propertyconfigurator.h>
+#include <log4cxx/logmanager.h>
+#include "vectorappender.h"
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+
+
+class PropertyConfiguratorTest : public CppUnit::TestFixture
+{
+        CPPUNIT_TEST_SUITE(PropertyConfiguratorTest);
+                CPPUNIT_TEST(testInherited);
+                CPPUNIT_TEST(testNull);
+                CPPUNIT_TEST(testAppenderThreshold);
+        CPPUNIT_TEST_SUITE_END();
+
+public:
+    void testInherited() {
+        Properties props;
+        
props.put(LOG4CXX_STR("log4j.rootLogger"),LOG4CXX_STR("DEBUG,VECTOR1"));
+        
props.put(LOG4CXX_STR("log4j.logger.org.apache.log4j.PropertyConfiguratorTest"),
 LOG4CXX_STR("inherited,VECTOR2"));
+        props.put(LOG4CXX_STR("log4j.appender.VECTOR1"), 
LOG4CXX_STR("org.apache.log4j.VectorAppender"));
+        props.put(LOG4CXX_STR("log4j.appender.VECTOR2"), 
LOG4CXX_STR("org.apache.log4j.VectorAppender"));
+        PropertyConfigurator::configure(props);
+        LoggerPtr logger = 
Logger::getLogger("org.apache.log4j.PropertyConfiguratorTest");
+        CPPUNIT_ASSERT_EQUAL((int) Level::DEBUG_INT,
+                logger->getEffectiveLevel()->toInt());
+        Logger::getRootLogger()->setLevel(Level::getError());
+        CPPUNIT_ASSERT_EQUAL((int) Level::ERROR_INT,
+                logger->getEffectiveLevel()->toInt());
+        LogManager::resetConfiguration();
+    }
+
+    void testNull() {
+        Properties props;
+        
props.put(LOG4CXX_STR("log4j.rootLogger"),LOG4CXX_STR("DEBUG,VECTOR1"));
+        
props.put(LOG4CXX_STR("log4j.logger.org.apache.log4j.PropertyConfiguratorTest"),
 LOG4CXX_STR("NuLL,VECTOR2"));
+        props.put(LOG4CXX_STR("log4j.appender.VECTOR1"), 
LOG4CXX_STR("org.apache.log4j.VectorAppender"));
+        props.put(LOG4CXX_STR("log4j.appender.VECTOR2"), 
LOG4CXX_STR("org.apache.log4j.VectorAppender"));
+        PropertyConfigurator::configure(props);
+        LoggerPtr logger = 
Logger::getLogger("org.apache.log4j.PropertyConfiguratorTest");
+        CPPUNIT_ASSERT_EQUAL((int) Level::DEBUG_INT,
+                logger->getEffectiveLevel()->toInt());
+        Logger::getRootLogger()->setLevel(Level::getError());
+        CPPUNIT_ASSERT_EQUAL((int) Level::ERROR_INT,
+                logger->getEffectiveLevel()->toInt());
+        LogManager::resetConfiguration();
+    }
+
+    void testAppenderThreshold() {
+        Properties props;
+        props.put(LOG4CXX_STR("log4j.rootLogger"), LOG4CXX_STR("ALL,VECTOR1"));
+        props.put(LOG4CXX_STR("log4j.appender.VECTOR1"), 
LOG4CXX_STR("org.apache.log4j.VectorAppender"));
+        props.put(LOG4CXX_STR("log4j.appender.VECTOR1.threshold"), 
LOG4CXX_STR("WARN"));
+        PropertyConfigurator::configure(props);
+        LoggerPtr root(Logger::getRootLogger());
+        VectorAppenderPtr appender(root->getAppender("VECTOR1"));
+        CPPUNIT_ASSERT_EQUAL((int) Level::WARN_INT, 
appender->getThreshold()->toInt());
+        LOG4CXX_INFO(root, "Info message");
+        LOG4CXX_WARN(root, "Warn message");
+        LOG4CXX_WARN(root, "Error message");
+        CPPUNIT_ASSERT_EQUAL((size_t) 2, appender->vector.size());        
+        LogManager::resetConfiguration();
+    }
+
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PropertyConfiguratorTest);

Modified: logging/log4cxx/trunk/src/test/cpp/vectorappender.h
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/vectorappender.h?rev=596012&r1=596011&r2=596012&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/vectorappender.h (original)
+++ logging/log4cxx/trunk/src/test/cpp/vectorappender.h Sat Nov 17 14:12:15 2007
@@ -32,6 +32,10 @@
         {
         public:
                 DECLARE_LOG4CXX_OBJECT(VectorAppender)
+                BEGIN_LOG4CXX_CAST_MAP()
+                        LOG4CXX_CAST_ENTRY(VectorAppender)
+                        LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
+                END_LOG4CXX_CAST_MAP()
 
                 std::vector<spi::LoggingEventPtr> vector;
 


Reply via email to