4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Target unit tests */
26 //#include "Target.test.hh"
27 //#include "Target.test.ih"
31 #include "main.test.hh"
33 #include "../../Utils/auto_unit_test.hh"
34 #include <boost/test/test_tools.hpp>
37 ///////////////////////////////cc.p////////////////////////////////////////
43 typedef std::string result_type;
44 std::string operator()(senf::log::Target::RoutingEntry const & entry) const
46 static char const * levels[] = {
47 "NONE", "VERBOSE", "NOTICE", "MESSAGE", "IMPORTANT", "CRITICAL", "FATAL", "DISABLED" };
48 static char const * actions[] = { "ACCEPT", "REJECT" };
50 s << entry.stream() << "-" << entry.area() << "-" << levels[entry.level()] << "-"
51 << actions[entry.action()];
58 BOOST_AUTO_UNIT_TEST(target)
60 senf::log::StringTarget target;
62 BOOST_CHECK_THROW( target.route("senf::log::test::myStream", "invalid_area"),
63 senf::log::Target::InvalidAreaException );
64 BOOST_CHECK_THROW( target.route("invalid_stream", ""),
65 senf::log::Target::InvalidStreamException );
66 BOOST_CHECK_THROW( target.unroute("senf::log::test::myStream", "invalid_area"),
67 senf::log::Target::InvalidAreaException );
68 BOOST_CHECK_THROW( target.unroute("invalid_stream", ""),
69 senf::log::Target::InvalidStreamException );
71 target.route<senf::log::Debug>();
72 target.route<senf::log::test::myStream, senf::log::DefaultArea>(senf::log::Target::REJECT);
73 target.route<senf::log::test::myStream, senf::log::VERBOSE>(senf::log::Target::ACCEPT, 0);
74 target.route<senf::log::test::myStream, senf::log::test::Foo, senf::log::VERBOSE>(
75 senf::log::Target::ACCEPT, 2);
76 target.route("senf::log::test::myStream", "", senf::log::IMPORTANT::value,
77 senf::log::Target::REJECT, 4);
78 target.route("senf::log::Debug", "senf::log::test::Foo", senf::log::VERBOSE::value,
79 senf::log::Target::REJECT, -5);
80 target.route("senf::log::Debug", "", senf::log::MESSAGE::value,
81 senf::log::Target::ACCEPT, -7);
83 typedef boost::transform_iterator<RouteCheck, senf::log::Target::iterator> iterator;
84 iterator i (boost::make_transform_iterator(target.begin(), RouteCheck()));
85 iterator const i_end (boost::make_transform_iterator(target.end(), RouteCheck()));
87 char const * data[] = {
88 "senf::log::Debug--MESSAGE-ACCEPT",
89 "senf::log::test::myStream--VERBOSE-ACCEPT",
90 "senf::log::Debug-senf::log::test::Foo-VERBOSE-REJECT",
91 "senf::log::Debug--NONE-ACCEPT",
92 "senf::log::test::myStream-senf::log::test::Foo-VERBOSE-ACCEPT",
93 "senf::log::test::myStream-senf::log::DefaultArea-NONE-REJECT",
94 "senf::log::test::myStream--IMPORTANT-REJECT",
97 BOOST_CHECK_EQUAL_COLLECTIONS( i, i_end, data, data + sizeof(data)/sizeof(data[0]) );
98 BOOST_CHECK( *target.begin() == target[0] );
100 target.unroute<senf::log::Debug>();
101 target.unroute<senf::log::test::myStream, senf::log::VERBOSE>();
102 target.unroute<senf::log::test::myStream, senf::log::DefaultArea>(senf::log::Target::REJECT);
103 target.unroute("senf::log::test::myStream", "", senf::log::IMPORTANT::value,
104 senf::log::Target::REJECT);
108 BOOST_CHECK( target.begin() == target.end() );
109 BOOST_CHECK( target.empty() );
110 BOOST_CHECK_EQUAL( target.size(), 0u );
113 ///////////////////////////////cc.e////////////////////////////////////////
120 // comment-column: 40
121 // c-file-style: "senf"
122 // indent-tabs-mode: nil
123 // ispell-local-dictionary: "american"
124 // compile-command: "scons -u test"