4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer NETwork research (NET)
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.test 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[] = { "NONE", "VERBOSE", "NOTICE", "MESSAGE",
47 "IMPORTANT", "CRITICAL","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 target.route<senf::log::Debug>();
63 target.route<senf::log::test::myStream, senf::log::DefaultArea>(senf::log::Target::REJECT);
64 target.route<senf::log::test::myStream, senf::log::VERBOSE>(senf::log::Target::ACCEPT, 0);
65 target.route<senf::log::test::myStream, senf::log::test::Foo, senf::log::VERBOSE>(
66 senf::log::Target::ACCEPT, 2);
67 target.route("senf::log::test::myStream", "", senf::log::IMPORTANT::value,
68 senf::log::Target::REJECT, 4);
69 target.route("senf::log::Debug", "senf::log::test::Foo", senf::log::VERBOSE::value,
70 senf::log::Target::REJECT, -5);
71 target.route("senf::log::Debug", "", senf::log::MESSAGE::value,
72 senf::log::Target::ACCEPT, -7);
74 typedef boost::transform_iterator<RouteCheck, senf::log::Target::iterator> iterator;
75 iterator i (boost::make_transform_iterator(target.begin(), RouteCheck()));
76 iterator const i_end (boost::make_transform_iterator(target.end(), RouteCheck()));
78 char const * data[] = {
79 "senf::log::Debug--MESSAGE-ACCEPT",
80 "senf::log::test::myStream--VERBOSE-ACCEPT",
81 "senf::log::Debug-senf::log::test::Foo-VERBOSE-REJECT",
82 "senf::log::Debug--NONE-ACCEPT",
83 "senf::log::test::myStream-senf::log::test::Foo-VERBOSE-ACCEPT",
84 "senf::log::test::myStream--NONE-REJECT",
85 "senf::log::test::myStream--IMPORTANT-REJECT",
88 BOOST_CHECK_EQUAL_COLLECTIONS( i, i_end, data, data + sizeof(data)/sizeof(data[0]) );
90 target.unroute<senf::log::Debug>();
91 target.unroute<senf::log::test::myStream, senf::log::VERBOSE>();
92 target.unroute<senf::log::test::myStream, senf::log::DefaultArea>(senf::log::Target::REJECT);
93 target.unroute<senf::log::test::myStream, senf::log::test::Foo, senf::log::VERBOSE>();
94 target.unroute("senf::log::test::myStream", "", senf::log::IMPORTANT::value,
95 senf::log::Target::REJECT);
99 BOOST_CHECK( target.begin() == target.end() );
102 ///////////////////////////////cc.e////////////////////////////////////////
109 // comment-column: 40
110 // c-file-style: "senf"
111 // indent-tabs-mode: nil
112 // ispell-local-dictionary: "american"
113 // compile-command: "scons -u test"