Author: carnold
Date: Sun May 18 13:58:02 2008
New Revision: 657640
URL:
http://svn.apache.org/viewvc?rev=657640&view=rev
Log:
LOGCXX-276: AndFilter and others defined but not
implemented
Added:
logging/log4cxx/trunk/src/main/cpp/andfilter.cpp
logging/log4cxx/trunk/src/main/cpp/loggermatchfilter.cpp
logging/log4cxx/trunk/src/main/include/log4cxx/filter/logger
matchfilter.h
logging/log4cxx/trunk/src/test/cpp/filter/
logging/log4cxx/trunk/src/test/cpp/filter/andfiltertest.cpp
logging/log4cxx/trunk/src/test/cpp/filter/denyallfiltertest.
cpp
logging/log4cxx/trunk/src/test/cpp/filter/levelmatchfilterte
st.cpp
logging/log4cxx/trunk/src/test/cpp/filter/levelrangefilterte
st.cpp
logging/log4cxx/trunk/src/test/cpp/filter/loggermatchfiltert
est.cpp
logging/log4cxx/trunk/src/test/cpp/filter/stringmatchfiltert
est.cpp
Modified:
logging/log4cxx/trunk/src/changes/changes.xml
logging/log4cxx/trunk/src/main/cpp/Makefile.am
logging/log4cxx/trunk/src/main/include/log4cxx/filter/andfil
ter.h
logging/log4cxx/trunk/src/main/include/log4cxx/filter/levelm
atchfilter.h
logging/log4cxx/trunk/src/test/cpp/Makefile.am
Modified: logging/log4cxx/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4cxx/
trunk/src/changes/changes.xml?rev=657640&r1=657639&r
2=657640&view=diff
============================================================
==================
--- logging/log4cxx/trunk/src/changes/changes.xml
(original)
+++ logging/log4cxx/trunk/src/changes/changes.xml Sun May 18
13:58:02 2008
 -31,6
+31,7 
<action issue="LOGCXX-271">MDC::put will
not overwrite existing key value pair</action>
<action issue="LOGCXX-272">Apache log4cxx
0.10.1 release</action>
<action issue="LOGCXX-275">Headers cannot
be included with very strict warning
settings</action>
+<action issue="LOGCXX-276">AndFilter and
others defined but not implemented</action>
<action issue="LOGCXX-277">Reconnection not
working for sockets</action>
<action issue="LOGCXX-278">Threads for
reconnecting sockets do not end cleanly when program
exits</action>
<action issue="LOGCXX-280">tests and sample
code unnecessarily compiled during default make
target</action>
Modified: logging/log4cxx/trunk/src/main/cpp/Makefile.am
URL: http://svn.apache.org/viewvc/logging/log4cxx
/trunk/src/main/cpp/Makefile.am?rev=657640&r1=657639&
;r2=657640&view=diff
============================================================
==================
--- logging/log4cxx/trunk/src/main/cpp/Makefile.am
(original)
+++ logging/log4cxx/trunk/src/main/cpp/Makefile.am Sun May
18 13:58:02 2008
 -20,6
+20,7 
liblog4cxx_la_SOURCES =
action.cpp
+ andfilter.cpp
appenderattachableimpl.cpp
appenderskeleton.cpp
aprinitializer.cpp
 -81,6
+82,7 
linelocationpatternconverter.cpp
lineseparatorpatternconverter.cpp
literalpatternconverter.cpp
+ loggermatchfilter.cpp
loggerpatternconverter.cpp
loggingeventpatternconverter.cpp
loader.cpp
Added: logging/log4cxx/trunk/src/main/cpp/andfilter.cpp
URL: http://svn
.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/andfil
ter.cpp?rev=657640&view=auto
============================================================
==================
--- logging/log4cxx/trunk/src/main/cpp/andfilter.cpp
(added)
+++ logging/log4cxx/trunk/src/main/cpp/andfilter.cpp Sun May
18 13:58:02 2008
 -0,0
+1,67 
+/*
+ * 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 <log4cxx/filter/andfilter.h>
+#include <log4cxx/spi/loggingevent.h>
+#include <log4cxx/helpers/stringhelper.h>
+#include <log4cxx/helpers/optionconverter.h>
+
+using namespace log4cxx;
+using namespace log4cxx::filter;
+using namespace log4cxx::spi;
+using namespace log4cxx::helpers;
+
+IMPLEMENT_LOG4CXX_OBJECT(AndFilter)
+
+
+AndFilter::AndFilter()
+: headFilter(), tailFilter(), acceptOnMatch(true)
+{
+}
+
+void AndFilter::addFilter(const FilterPtr& filter) {
+ if (headFilter == NULL) {
+ headFilter = filter;
+ tailFilter = filter;
+ } else {
+ tailFilter->setNext(filter);
+ }
+}
+
+
+void AndFilter::setAcceptOnMatch(bool newValue) {
+ acceptOnMatch = newValue;
+}
+
+Filter::FilterDecision AndFilter::decide(
+ const spi::LoggingEventPtr& event) const
+{
+ bool accepted = true;
+ FilterPtr f(headFilter);
+ while (f != NULL) {
+ accepted = accepted && (Filter::ACCEPT ==
f->decide(event));
+ f = f->getNext();
+ }
+ if (accepted) {
+ if(acceptOnMatch) {
+ return Filter::ACCEPT;
+ }
+ return Filter: ENY;
+ }
+ return Filter::NEUTRAL;
+}
+
Added:
logging/log4cxx/trunk/src/main/cpp/loggermatchfilter.cpp
URL: ht
tp://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cp
p/loggermatchfilter.cpp?rev=657640&view=auto
============================================================
==================
--- logging/log4cxx/trunk/src/main/cpp/loggermatchfilter.cpp
(added)
+++ logging/log4cxx/trunk/src/main/cpp/loggermatchfilter.cpp
Sun May 18 13:58:02 2008
 -0,0
+1,75 
+/*
+ * 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 <log4cxx/logstring.h>
+#include <log4cxx/filter/loggermatchfilter.h>
+#include <log4cxx/spi/loggingevent.h>
+#include <log4cxx/helpers/stringhelper.h>
+#include <log4cxx/helpers/optionconverter.h>
+
+using namespace log4cxx;
+using namespace log4cxx::filter;
+using namespace log4cxx::spi;
+using namespace log4cxx::helpers;
+
+IMPLEMENT_LOG4CXX_OBJECT(LoggerMatchFilter)
+
+
+LoggerMatchFilter::LoggerMatchFilter()
+: acceptOnMatch(true),
loggerToMatch(LOG4CXX_STR("root"))
+{
+}
+
+void LoggerMatchFilter::setLoggerToMatch(const
LogString& value) {
+ loggerToMatch = value;
+}
+
+LogString LoggerMatchFilter::getLoggerToMatch() const {
+ return loggerToMatch;
+}
+
+void LoggerMatchFilter::setOption(const LogString&
option,
+ const LogString& value)
+{
+
+ if (StringHelper::equalsIgnoreCase(option,
+ LOG4CXX_STR("LOGGERTOMATCH"),
LOG4CXX_STR("loggertomatch")))
+ {
+ setLoggerToMatch(value);
+ }
+ else if (StringHelper::equalsIgnoreCase(option,
+ LOG4CXX_STR("ACCEPTONMATCH"),
LOG4CXX_STR("acceptonmatch")))
+ {
+ acceptOnMatch = OptionConverter::toBoolean(value,
acceptOnMatch);
+ }
+}
+
+Filter::FilterDecision LoggerMatchFilter::decide(
+ const spi::LoggingEventPtr& event) const
+{
+ bool matchOccured = loggerToMatch ==
event->getLoggerName();
+ if (matchOccured) {
+ if (acceptOnMatch) {
+ return Filter::ACCEPT;
+ } else {
+ return Filter: ENY;
+ }
+ } else {
+ return Filter::NEUTRAL;
+ }
+}
+
Modified:
logging/log4cxx/trunk/src/main/include/log4cxx/filter/andfil
ter.h
URL: http://svn.apache.org/vie
wvc/logging/log4cxx/trunk/src/main/include/log4cxx/filter/an
dfilter.h?rev=657640&r1=657639&r2=657640&view=di
ff
============================================================
==================
---
logging/log4cxx/trunk/src/main/include/log4cxx/filter/andfil
ter.h (original)
+++
logging/log4cxx/trunk/src/main/include/log4cxx/filter/andfil
ter.h Sun May 18 13:58:02 2008
 -95,9
+95,10 
void addFilter(const log4cxx::spi::FilterPtr
& filter);
void setAcceptOnMatch(bool acceptOnMatch);
-
+
FilterDecision decide(const
spi::LoggingEventPtr & event) const;
};
+ LOG4CXX_PTR_DEF(AndFilter);
}
}
Modified:
logging/log4cxx/trunk/src/main/include/log4cxx/filter/levelm
atchfilter.h
URL: http://svn.apache.
org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/fi
lter/levelmatchfilter.h?rev=657640&r1=657639&r2=6576
40&view=diff
============================================================
==================
---
logging/log4cxx/trunk/src/main/include/log4cxx/filter/levelm
atchfilter.h (original)
+++
logging/log4cxx/trunk/src/main/include/log4cxx/filter/levelm
atchfilter.h Sun May 18 13:58:02 2008
 -99,4
+99,4 
#pragma warning ( pop )
#endif
-#endif // _LOG4CXX_FILTER_STRING_MATCH_FILTER_H
+#endif // _LOG4CXX_FILTER_LEVEL_MATCH_FILTER_H
Added:
logging/log4cxx/trunk/src/main/include/log4cxx/filter/logger
matchfilter.h
URL: http://svn.apache.org/viewvc/logging/log4cxx/
trunk/src/main/include/log4cxx/filter/loggermatchfilter.h?re
v=657640&view=auto
============================================================
==================
---
logging/log4cxx/trunk/src/main/include/log4cxx/filter/logger
matchfilter.h (added)
+++
logging/log4cxx/trunk/src/main/include/log4cxx/filter/logger
matchfilter.h Sun May 18 13:58:02 2008
 -0,0
+1,104 
+/*
+ * 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.
+ */
+
+#ifndef _LOG4CXX_FILTER_LOGGER_MATCH_FILTER_H
+#define _LOG4CXX_FILTER_LOGGER_MATCH_FILTER_H
+
+#if defined(_MSC_VER)
+#pragma warning ( push )
+#pragma warning ( disable: 4231 4251 4275 4786 )
+#endif
+
+
+#include <log4cxx/spi/filter.h>
+#include <log4cxx/level.h>
+
+namespace log4cxx
+{
+ class Level;
+
+ namespace filter
+ {
+/**
+ This is a very simple filter based on logger name
matching.
+
+ <p>The filter admits two options
<b>LoggerToMatch</b> and
+ <b>AcceptOnMatch</b>. If there is an exact
match between the value
+ of the <b>LoggerToMatch</b> option and the
logger of the { link
+ spi::LoggingEvent LoggingEvent}, then the
#decide method returns { link
+ spi::Filter#ACCEPT ACCEPT} in case the
<b>AcceptOnMatch</b> option value is set
+ to <code>true</code>, if it is
<code>false</code> then { link
+ spi::filter::Filter#DENY} is returned. If there is no
match, { link
+ spi::filter::Filter#NEUTRAL} is returned. A
loggerToMatch of "root"
+ matches both the root logger and a logger named
"root".
+
+ */
+
+ class LOG4CXX_EXPORT LoggerMatchFilter :
public spi::Filter
+ {
+ private:
+ bool acceptOnMatch;
+ LogString loggerToMatch;
+
+ public:
+ typedef spi::Filter BASE_CLASS;
+
DECLARE_LOG4CXX_OBJECT(LoggerMatchFilter)
+ BEGIN_LOG4CXX_CAST_MAP()
+
LOG4CXX_CAST_ENTRY(LoggerMatchFilter)
+
LOG4CXX_CAST_ENTRY_CHAIN(BASE_CLASS)
+ END_LOG4CXX_CAST_MAP()
+
+ LoggerMatchFilter();
+
+ /**
+ Set options
+ */
+ virtual void setOption(const
LogString& option,
+ const LogString&
value);
+
+ void setLoggerToMatch(const
LogString& levelToMatch);
+
+ LogString getLoggerToMatch()
const;
+
+ inline void setAcceptOnMatch(bool
acceptOnMatch1)
+ { this->acceptOnMatch =
acceptOnMatch1; }
+
+ inline bool getAcceptOnMatch()
const
+ { return acceptOnMatch; }
+
+ /**
+ Return the decision of this
filter.
+
+ Returns { link spi::Filter#NEUTRAL
NEUTRAL} if the
+ <b>LoggerToMatch</b>
option is not set or if there is not match.
+ Otherwise, if there is a match,
then the returned decision is
+ { link spi::Filter#ACCEPT
ACCEPT} if the <b>AcceptOnMatch</b>
+ property is set to
<code>true</code>. The returned decision is
+ { link spi::Filter#DENY DENY}
if the
+ <b>AcceptOnMatch</b>
property is set to false.
+ */
+ FilterDecision decide(const
spi::LoggingEventPtr& event) const;
+ }; // class LoggerMatchFilter
+ LOG4CXX_PTR_DEF(LoggerMatchFilter);
+ } // namespace filter
+} // namespace log4cxx
+
+#if defined(_MSC_VER)
+#pragma warning ( pop )
+#endif
+
+#endif // _LOG4CXX_FILTER_LOGGER_MATCH_FILTER_H
Modified: logging/log4cxx/trunk/src/test/cpp/Makefile.am
URL: http://svn.apache.org/viewvc/logging/log4cxx
/trunk/src/test/cpp/Makefile.am?rev=657640&r1=657639&
;r2=657640&view=diff
============================================================
==================
--- logging/log4cxx/trunk/src/test/cpp/Makefile.am
(original)
+++ logging/log4cxx/trunk/src/test/cpp/Makefile.am Sun May
18 13:58:02 2008
 -35,6
+35,14 
defaultinit/testcase2.cpp
defaultinit/testcase3.cpp
defaultinit/testcase4.cpp
+
+filter_tests =
+ filter/andfiltertest.cpp
+ filter/denyallfiltertest.cpp
+ filter/levelmatchfiltertest.cpp
+ filter/levelrangefiltertest.cpp
+ filter/loggermatchfiltertest.cpp
+ filter/stringmatchfiltertest.cpp
helpers =
helpers/absolutetimedateformattestcase.cpp
 -118,6
+126,7 
testsuite_SOURCES =
$(customlogger_tests)
$(defaultinit_tests)
+ $(filter_tests)
$(helpers)
$(net_tests)
$(pattern_tests)
Added:
logging/log4cxx/trunk/src/test/cpp/filter/andfiltertest.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test
/cpp/filter/andfiltertest.cpp?rev=657640&view=auto
============================================================
==================
---
logging/log4cxx/trunk/src/test/cpp/filter/andfiltertest.cpp
(added)
+++
logging/log4cxx/trunk/src/test/cpp/filter/andfiltertest.cpp
Sun May 18 13:58:02 2008
 -0,0
+1,179 
+/*
+ * 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 <log4cxx/filter/andfilter.h>
+#include <log4cxx/logger.h>
+#include <log4cxx/spi/filter.h>
+#include <log4cxx/spi/loggingevent.h>
+#include <log4cxx/filter/levelmatchfilter.h>
+#include <log4cxx/filter/denyallfilter.h>
+#include <log4cxx/filter/stringmatchfilter.h>
+#include "../logunit.h"
+
+using namespace log4cxx;
+using namespace log4cxx::filter;
+using namespace log4cxx::spi;
+using namespace log4cxx::helpers;
+
+
+/**
+ * Unit tests for AndFilter.
+ */
+LOGUNIT_CLASS(AndFilterTest) {
+ LOGUNIT_TEST_SUITE(AndFilterTest);
+ LOGUNIT_TEST(test1);
+ LOGUNIT_TEST(test2);
+ LOGUNIT_TEST(test3);
+ LOGUNIT_TEST(test4);
+ LOGUNIT_TEST(test5);
+ LOGUNIT_TEST(test6);
+ LOGUNIT_TEST_SUITE_END();
+
+public:
+
+
+ /**
+ * Check that AndFilter.decide() returns Filter.ACCEPT
if no filters added.
+ */
+ void test1() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.AndFilterTest"
;),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ FilterPtr filter(new AndFilter());
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT,
filter->decide(event));
+ }
+
+ /**
+ * Check that AndFilter.decide() returns Filter.ACCEPT
if
+ * only nested filter returns Filter.ACCEPT.
+ */
+ void test2() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.AndFilterTest"
;),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ AndFilterPtr filter(new AndFilter());
+ LevelMatchFilterPtr filter1(new
LevelMatchFilter());
+
filter1->setLevelToMatch(LOG4CXX_STR("info"));
+ Pool p;
+ filter1->activateOptions(p);
+ filter->addFilter(filter1);
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT,
filter->decide(event));
+ }
+
+ /**
+ * Check that AndFilter.decide() returns Filter.ACCEPT
if
+ * two nested filters return Filter.ACCEPT.
+ */
+ void test3() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.AndFilterTest"
;),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ AndFilterPtr filter(new AndFilter());
+ LevelMatchFilterPtr filter1(new
LevelMatchFilter());
+
filter1->setLevelToMatch(LOG4CXX_STR("info"));
+ Pool p;
+ filter1->activateOptions(p);
+ filter->addFilter(filter1);
+ LevelMatchFilterPtr filter2(new
LevelMatchFilter());
+
filter2->setLevelToMatch(LOG4CXX_STR("info"));
+ filter2->activateOptions(p);
+ filter->addFilter(filter2);
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT,
filter->decide(event));
+ }
+
+ /**
+ * Check that AndFilter.decide() returns Filter.DENY
if
+ * only nested filter returns Filter.ACCEPT
+ * and acceptOnMatch is false.
+ */
+ void test4() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.AndFilterTest"
;),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ AndFilterPtr filter(new AndFilter());
+ LevelMatchFilterPtr filter1(new
LevelMatchFilter());
+
filter1->setLevelToMatch(LOG4CXX_STR("info"));
+ Pool p;
+ filter1->activateOptions(p);
+ filter->addFilter(filter1);
+ filter->setAcceptOnMatch(false);
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter: ENY,
filter->decide(event));
+ }
+
+ /**
+ * Check that AndFilter.decide() returns Filter.NEUTRAL
if
+ * nested filters return Filter.ACCEPT and
Filter.DENY.
+ */
+ void test5() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.AndFilterTest"
;),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ AndFilterPtr filter(new AndFilter());
+ LevelMatchFilterPtr filter1(new
LevelMatchFilter());
+
filter1->setLevelToMatch(LOG4CXX_STR("info"));
+ Pool p;
+ filter1->activateOptions(p);
+ filter->addFilter(filter1);
+ FilterPtr filter2(new DenyAllFilter());
+ filter2->activateOptions(p);
+ filter->addFilter(filter2);
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::NEUTRAL,
filter->decide(event));
+ }
+
+ /**
+ * Check that AndFilter.decide() returns Filter.NEUTRAL
if
+ * nested filters return Filter.ACCEPT and
Filter.NEUTRAL.
+ */
+ void test6() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.AndFilterTest"
;),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ AndFilterPtr filter(new AndFilter());
+ LevelMatchFilterPtr filter1(new
LevelMatchFilter());
+
filter1->setLevelToMatch(LOG4CXX_STR("info"));
+ Pool p;
+ filter1->activateOptions(p);
+ filter->addFilter(filter1);
+ FilterPtr filter2(new StringMatchFilter());
+ filter2->activateOptions(p);
+ filter->addFilter(filter2);
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::NEUTRAL,
filter->decide(event));
+ }
+};
+
+
+LOGUNIT_TEST_SUITE_REGISTRATION(AndFilterTest);
+
Added:
logging/log4cxx/trunk/src/test/cpp/filter/denyallfiltertest.
cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/
test/cpp/filter/denyallfiltertest.cpp?rev=657640&view=au
to
============================================================
==================
---
logging/log4cxx/trunk/src/test/cpp/filter/denyallfiltertest.
cpp (added)
+++
logging/log4cxx/trunk/src/test/cpp/filter/denyallfiltertest.
cpp Sun May 18 13:58:02 2008
 -0,0
+1,56 
+/*
+ * 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 <log4cxx/filter/denyallfilter.h>
+#include <log4cxx/logger.h>
+#include <log4cxx/spi/filter.h>
+#include <log4cxx/spi/loggingevent.h>
+#include "../logunit.h"
+
+using namespace log4cxx;
+using namespace log4cxx::filter;
+using namespace log4cxx::spi;
+using namespace log4cxx::helpers;
+
+
+/**
+ * Unit tests for DenyAllFilter.
+ */
+LOGUNIT_CLASS(DenyAllFilterTest) {
+ LOGUNIT_TEST_SUITE(DenyAllFilterTest);
+ LOGUNIT_TEST(test1);
+ LOGUNIT_TEST_SUITE_END();
+
+ /**
+ * Check that DenyAllFilter.decide() returns
Filter.DENY.
+ */
+ void test1() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.DenyAllFilterTest&
quot;),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ FilterPtr filter(new DenyAllFilter());
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter: ENY,
filter->decide(event));
+ }
+
+};
+
+LOGUNIT_TEST_SUITE_REGISTRATION(DenyAllFilterTest);
+
+
Added:
logging/log4cxx/trunk/src/test/cpp/filter/levelmatchfilterte
st.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/s
rc/test/cpp/filter/levelmatchfiltertest.cpp?rev=657640&v
iew=auto
============================================================
==================
---
logging/log4cxx/trunk/src/test/cpp/filter/levelmatchfilterte
st.cpp (added)
+++
logging/log4cxx/trunk/src/test/cpp/filter/levelmatchfilterte
st.cpp Sun May 18 13:58:02 2008
 -0,0
+1,129 
+/*
+ * 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 <log4cxx/filter/levelmatchfilter.h>
+#include <log4cxx/logger.h>
+#include <log4cxx/spi/filter.h>
+#include <log4cxx/spi/loggingevent.h>
+#include "../logunit.h"
+
+using namespace log4cxx;
+using namespace log4cxx::filter;
+using namespace log4cxx::spi;
+using namespace log4cxx::helpers;
+
+
+/**
+ * Unit tests for LevelMatchFilter.
+ */
+LOGUNIT_CLASS(LevelMatchFilterTest) {
+ LOGUNIT_TEST_SUITE(LevelMatchFilterTest);
+ LOGUNIT_TEST(test1);
+ LOGUNIT_TEST(test2);
+ LOGUNIT_TEST(test3);
+ LOGUNIT_TEST(test4);
+ LOGUNIT_TEST(test5);
+ LOGUNIT_TEST_SUITE_END();
+
+public:
+ /**
+ * Check that LevelMatchFilter.decide() returns
Filter.ACCEPT when level matches.
+ */
+ void test1() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.LevelMatchFilterTe
st"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ LevelMatchFilterPtr filter(new
LevelMatchFilter());
+
filter->setLevelToMatch(LOG4CXX_STR("info"));
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT,
filter->decide(event));
+ }
+
+ /**
+ * Check that LevelMatchFilter.decide() returns
Filter.DENY
+ * when level matches and acceptOnMatch = false.
+ */
+ void test2() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.LevelMatchFilterTe
st"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ LevelMatchFilterPtr filter(new
LevelMatchFilter());
+
filter->setLevelToMatch(LOG4CXX_STR("info"));
+ filter->setAcceptOnMatch(false);
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter: ENY,
filter->decide(event));
+ }
+
+ /**
+ * Check that LevelMatchFilter.decide() returns
Filter.NEUTRAL
+ * when levelToMatch is unspecified.
+ */
+ void test3() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.LevelMatchFilterTe
st"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ LevelMatchFilterPtr filter(new
LevelMatchFilter());
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::NEUTRAL,
filter->decide(event));
+ }
+
+ /**
+ * Check that LevelMatchFilter.decide() returns
Filter.NEUTRAL
+ * when event level is higher than level to match.
+ */
+ void test4() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.LevelMatchFilterTe
st"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ LevelMatchFilterPtr filter(new
LevelMatchFilter());
+
filter->setLevelToMatch(LOG4CXX_STR("debug"));
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::NEUTRAL,
filter->decide(event));
+ }
+
+ /**
+ * Check that LevelMatchFilter.decide() returns
Filter.NEUTRAL
+ * when event level is lower than level to match.
+ */
+ void test5() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.LevelMatchFilterTe
st"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ LevelMatchFilterPtr filter(new
LevelMatchFilter());
+
filter->setLevelToMatch(LOG4CXX_STR("warn"));
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::NEUTRAL,
filter->decide(event));
+ }
+};
+
+LOGUNIT_TEST_SUITE_REGISTRATION(LevelMatchFilterTest);
+
+
Added:
logging/log4cxx/trunk/src/test/cpp/filter/levelrangefilterte
st.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/s
rc/test/cpp/filter/levelrangefiltertest.cpp?rev=657640&v
iew=auto
============================================================
==================
---
logging/log4cxx/trunk/src/test/cpp/filter/levelrangefilterte
st.cpp (added)
+++
logging/log4cxx/trunk/src/test/cpp/filter/levelrangefilterte
st.cpp Sun May 18 13:58:02 2008
 -0,0
+1,149 
+/*
+ * 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 <log4cxx/filter/levelrangefilter.h>
+#include <log4cxx/logger.h>
+#include <log4cxx/spi/filter.h>
+#include <log4cxx/spi/loggingevent.h>
+#include "../logunit.h"
+
+using namespace log4cxx;
+using namespace log4cxx::filter;
+using namespace log4cxx::spi;
+using namespace log4cxx::helpers;
+
+
+/**
+ * Unit tests for LevelRangeFilter.
+ */
+LOGUNIT_CLASS(LevelRangeFilterTest) {
+ LOGUNIT_TEST_SUITE(LevelRangeFilterTest);
+ LOGUNIT_TEST(test1);
+ LOGUNIT_TEST(test2);
+ LOGUNIT_TEST(test3);
+ LOGUNIT_TEST(test4);
+ LOGUNIT_TEST(test5);
+ LOGUNIT_TEST(test6);
+ LOGUNIT_TEST_SUITE_END();
+
+public:
+ /**
+ * Check that LevelRangefilter->decide() returns
Filter: ENY
+ * when event level is below min level.
+ */
+ void test1() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.Filter::LevelRangeFilterT
est"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ LevelRangeFilterPtr filter(new
LevelRangeFilter());
+ filter->setLevelMin(Level::getWarn());
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter: ENY,
filter->decide(event));
+ }
+
+ /**
+ * Check that LevelRangefilter->decide() returns
Filter: ENY
+ * when event level is above max level.
+ */
+ void test2() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.Filter::LevelRangeFilterT
est"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ LevelRangeFilterPtr filter(new
LevelRangeFilter());
+ filter->setLevelMax(Level::getDebug());
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter: ENY,
filter->decide(event));
+ }
+
+ /**
+ * Check that LevelRangefilter->decide() returns
Filter::ACCEPT
+ * when event level is above min level.
+ */
+ void test3() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.Filter::LevelRangeFilterT
est"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ LevelRangeFilterPtr filter(new
LevelRangeFilter());
+ filter->setLevelMin(Level::getDebug());
+ filter->setAcceptOnMatch(true);
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT,
filter->decide(event));
+ }
+
+ /**
+ * Check that LevelRangefilter->decide() returns
Filter::ACCEPT
+ * when event level is below max level.
+ */
+ void test4() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.Filter::LevelRangeFilterT
est"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ LevelRangeFilterPtr filter(new
LevelRangeFilter());
+ filter->setLevelMax(Level::getError());
+ filter->setAcceptOnMatch(true);
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT,
filter->decide(event));
+ }
+
+ /**
+ * Check that LevelRangeFilter::decide() returns
Filter::NEUTRAL
+ * when event level is above min level and accept on
match is false.
+ */
+ void test5() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.Filter::LevelRangeFilterT
est"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ LevelRangeFilterPtr filter(new
LevelRangeFilter());
+ filter->setLevelMin(Level::getDebug());
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::NEUTRAL,
filter->decide(event));
+ }
+
+ /**
+ * Check that LevelRangeFilter::decide() returns
Filter::NEUTRAL
+ * when event level is below max level and accept on
match is false.
+ */
+ void test6() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.Filter::LevelRangeFilterT
est"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ LevelRangeFilterPtr filter(new
LevelRangeFilter());
+ filter->setLevelMax(Level::getError());
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::NEUTRAL,
filter->decide(event));
+ }
+};
+
+LOGUNIT_TEST_SUITE_REGISTRATION(LevelRangeFilterTest);
+
Added:
logging/log4cxx/trunk/src/test/cpp/filter/loggermatchfiltert
est.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/
src/test/cpp/filter/loggermatchfiltertest.cpp?rev=657640&
;view=auto
============================================================
==================
---
logging/log4cxx/trunk/src/test/cpp/filter/loggermatchfiltert
est.cpp (added)
+++
logging/log4cxx/trunk/src/test/cpp/filter/loggermatchfiltert
est.cpp Sun May 18 13:58:02 2008
 -0,0
+1,109 
+/*
+ * 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 <log4cxx/filter/loggermatchfilter.h>
+#include <log4cxx/logger.h>
+#include <log4cxx/spi/filter.h>
+#include <log4cxx/spi/loggingevent.h>
+#include "../logunit.h"
+
+using namespace log4cxx;
+using namespace log4cxx::filter;
+using namespace log4cxx::spi;
+using namespace log4cxx::helpers;
+
+
+/**
+ * Unit tests for LoggerMatchFilter.
+ */
+LOGUNIT_CLASS(LoggerMatchFilterTest) {
+ LOGUNIT_TEST_SUITE(LoggerMatchFilterTest);
+ LOGUNIT_TEST(test1);
+ LOGUNIT_TEST(test2);
+ LOGUNIT_TEST(test3);
+ LOGUNIT_TEST(test4);
+ LOGUNIT_TEST_SUITE_END();
+
+public:
+ /**
+ * Check that LoggerMatchFilter::decide() with
unspecified level
+ * returns Filter::ACCEPT for root logger.
+ */
+ void test1() {
+ LoggingEventPtr event(new LoggingEvent(
+ LOG4CXX_STR("root"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ FilterPtr filter(new LoggerMatchFilter());
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT,
filter->decide(event));
+ }
+
+ /**
+ * Check that LoggerMatchFilter::decide() with
unspecified level
+ * returns Filter: ENY for
root logger when accept on match is false.
+ */
+ void test2() {
+ LoggingEventPtr event(new LoggingEvent(
+ LOG4CXX_STR("root"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ LoggerMatchFilterPtr filter(new
LoggerMatchFilter());
+ filter->setAcceptOnMatch(false);
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter: ENY,
filter->decide(event));
+ }
+
+ /**
+ * Check that LoggerMatchFilter::decide() with
unspecified level
+ * returns Filter::NEUTRAL for non-root logger.
+ */
+ void test3() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.LoggerMatchFilterT
est"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ FilterPtr filter(new LoggerMatchFilter());
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::NEUTRAL,
filter->decide(event));
+ }
+
+ /**
+ * Check that LoggerMatchFilter::decide()
+ * returns Filter::ACCEPT for matching logger.
+ */
+ void test4() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.LoggerMatchFilterT
est"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ LoggerMatchFilterPtr filter(new
LoggerMatchFilter());
+
filter->setLoggerToMatch(LOG4CXX_STR("org.apache.log
4j.filter.LoggerMatchFilterTest"));
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT,
filter->decide(event));
+ }
+
+};
+
+LOGUNIT_TEST_SUITE_REGISTRATION(LoggerMatchFilterTest);
Added:
logging/log4cxx/trunk/src/test/cpp/filter/stringmatchfiltert
est.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/
src/test/cpp/filter/stringmatchfiltertest.cpp?rev=657640&
;view=auto
============================================================
==================
---
logging/log4cxx/trunk/src/test/cpp/filter/stringmatchfiltert
est.cpp (added)
+++
logging/log4cxx/trunk/src/test/cpp/filter/stringmatchfiltert
est.cpp Sun May 18 13:58:02 2008
 -0,0
+1,133 
+/*
+ * 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 <log4cxx/filter/stringmatchfilter.h>
+#include <log4cxx/logger.h>
+#include <log4cxx/spi/filter.h>
+#include <log4cxx/spi/loggingevent.h>
+#include "../logunit.h"
+
+using namespace log4cxx;
+using namespace log4cxx::filter;
+using namespace log4cxx::spi;
+using namespace log4cxx::helpers;
+
+
+/**
+ * Unit tests for StringMatchFilter.
+ */
+LOGUNIT_CLASS(StringMatchFilterTest) {
+ LOGUNIT_TEST_SUITE(StringMatchFilterTest);
+ LOGUNIT_TEST(test1);
+ LOGUNIT_TEST(test2);
+ LOGUNIT_TEST(test3);
+ LOGUNIT_TEST(test4);
+ LOGUNIT_TEST_SUITE_END();
+
+public:
+
+ /**
+ * Check that StringMatchFilter.decide() returns
Filter.NEUTRAL
+ * when string to match is unspecified.
+ */
+ void test1() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.StringMatchFilterT
est"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ FilterPtr filter(new StringMatchFilter());
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::NEUTRAL,
filter->decide(event));
+ }
+
+ /**
+ * Check that StringMatchFilter.decide() returns
Filter.NEUTRAL
+ * when string to match does not appear in message.
+ */
+ void test2() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.StringMatchFilterT
est"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ StringMatchFilterPtr filter(new
StringMatchFilter());
+
filter->setStringToMatch(LOG4CXX_STR("Monde"));
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::NEUTRAL,
filter->decide(event));
+ }
+
+ /**
+ * Check that StringMatchFilter.decide() returns
Filter.ACCEPT
+ * when string to match does appear in message.
+ */
+ void test3() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.StringMatchFilterT
est"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ StringMatchFilterPtr filter(new
StringMatchFilter());
+
filter->setStringToMatch(LOG4CXX_STR("World"));
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT,
filter->decide(event));
+ }
+
+ /**
+ * Check that StringMatchFilter.decide() returns
Filter.DENY
+ * when string to match does appear in message and
+ * accept on match is false.
+ */
+ void test4() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.StringMatchFilterT
est"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ StringMatchFilterPtr filter(new
StringMatchFilter());
+
filter->setStringToMatch(LOG4CXX_STR("World"));
+ filter->setAcceptOnMatch(false);
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter: ENY,
filter->decide(event));
+ }
+
+ /**
+ * Check that StringMatchFilter.decide() returns
Filter.NEUTRAL
+ * when string to match does appear in message but
differs in case.
+ */
+ void test5() {
+ LoggingEventPtr event(new LoggingEvent(
+
LOG4CXX_STR("org.apache.log4j.filter.StringMatchFilterT
est"),
+ Level::getInfo(),
+ LOG4CXX_STR("Hello, World"),
+ LOG4CXX_LOCATION));
+ StringMatchFilterPtr filter(new
StringMatchFilter());
+
filter->setStringToMatch(LOG4CXX_STR("world"));
+ Pool p;
+ filter->activateOptions(p);
+ LOGUNIT_ASSERT_EQUAL(Filter::NEUTRAL,
filter->decide(event));
+ }
+
+};
+
+
+LOGUNIT_TEST_SUITE_REGISTRATION(StringMatchFilterTest);
+
+
|