4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief Target unit tests */
31 //#include "Target.test.hh"
32 //#include "Target.test.ih"
36 #include "main.test.hh"
38 #include <senf/Utils/auto_unit_test.hh>
39 #include <boost/test/test_tools.hpp>
42 //-/////////////////////////////////////////////////////////////////////////////////////////////////
48 typedef std::string result_type;
49 std::string operator()(senf::log::Target::RoutingEntry const & entry) const
51 static char const * levels[] = {
52 "NONE", "VERBOSE", "NOTICE", "MESSAGE", "IMPORTANT", "CRITICAL", "FATAL", "DISABLED" };
53 static char const * actions[] = { "ACCEPT", "REJECT" };
55 s << entry.stream() << "-" << entry.area() << "-" << levels[entry.level()] << "-"
56 << actions[entry.action()];
63 SENF_AUTO_UNIT_TEST(target)
65 senf::log::StringTarget target;
67 BOOST_CHECK_THROW( target.route("senf::log::test::myStream", "invalid_area"),
68 senf::log::Target::InvalidAreaException );
69 BOOST_CHECK_THROW( target.route("invalid_stream", ""),
70 senf::log::Target::InvalidStreamException );
71 BOOST_CHECK_THROW( target.unroute("senf::log::test::myStream", "invalid_area"),
72 senf::log::Target::InvalidAreaException );
73 BOOST_CHECK_THROW( target.unroute("invalid_stream", ""),
74 senf::log::Target::InvalidStreamException );
76 target.route<senf::log::Debug>();
77 target.route<senf::log::test::myStream, senf::log::DefaultArea>(senf::log::Target::REJECT);
78 target.route<senf::log::test::myStream, senf::log::VERBOSE>(senf::log::Target::ACCEPT, 0);
79 target.route<senf::log::test::myStream, senf::log::test::Foo, senf::log::VERBOSE>(
80 senf::log::Target::ACCEPT, 2);
81 target.route("senf::log::test::myStream", "", senf::log::IMPORTANT::value,
82 senf::log::Target::REJECT, 4);
83 target.route("senf::log::Debug", "senf::log::test::Foo", senf::log::VERBOSE::value,
84 senf::log::Target::REJECT, -5);
85 target.route("senf::log::Debug", "", senf::log::MESSAGE::value,
86 senf::log::Target::ACCEPT, -7);
88 typedef boost::transform_iterator<RouteCheck, senf::log::Target::iterator> iterator;
89 iterator i (boost::make_transform_iterator(target.begin(), RouteCheck()));
90 iterator const i_end (boost::make_transform_iterator(target.end(), RouteCheck()));
92 char const * data[] = {
93 "senf::log::Debug--MESSAGE-ACCEPT",
94 "senf::log::test::myStream--VERBOSE-ACCEPT",
95 "senf::log::Debug-senf::log::test::Foo-VERBOSE-REJECT",
96 "senf::log::Debug--NONE-ACCEPT",
97 "senf::log::test::myStream-senf::log::test::Foo-VERBOSE-ACCEPT",
98 "senf::log::test::myStream-senf::log::DefaultArea-NONE-REJECT",
99 "senf::log::test::myStream--IMPORTANT-REJECT",
102 BOOST_CHECK_EQUAL_COLLECTIONS( i, i_end, data, data + sizeof(data)/sizeof(data[0]) );
103 BOOST_CHECK( *target.begin() == target[0] );
105 target.unroute<senf::log::Debug>();
106 target.unroute<senf::log::test::myStream, senf::log::VERBOSE>();
107 target.unroute<senf::log::test::myStream, senf::log::DefaultArea>(senf::log::Target::REJECT);
108 target.unroute("senf::log::test::myStream", "", senf::log::IMPORTANT::value,
109 senf::log::Target::REJECT);
113 BOOST_CHECK( target.begin() == target.end() );
114 BOOST_CHECK( target.empty() );
115 BOOST_CHECK_EQUAL( target.size(), 0u );
118 //-/////////////////////////////////////////////////////////////////////////////////////////////////
125 // comment-column: 40
126 // c-file-style: "senf"
127 // indent-tabs-mode: nil
128 // ispell-local-dictionary: "american"
129 // compile-command: "scons -u test"