removed some useless spaces; not very important, I know :)
[senf.git] / Utils / Logger / Target.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief Target.test unit tests */
25
26 //#include "Target.test.hh"
27 //#include "Target.test.ih"
28
29 // Custom includes
30 #include <sstream>
31 #include "main.test.hh"
32
33 #include "../../Utils/auto_unit_test.hh"
34 #include <boost/test/test_tools.hpp>
35
36 #define prefix_
37 ///////////////////////////////cc.p////////////////////////////////////////
38
39 namespace {
40     
41     struct RouteCheck
42     {
43         typedef std::string result_type;
44         std::string operator()(senf::log::Target::RoutingEntry const & entry) const
45             {
46                 static char const * levels[] = { "NONE", "VERBOSE", "NOTICE", "MESSAGE",
47                                                  "IMPORTANT", "CRITICAL","DISABLED" };
48                 static char const * actions[] = { "ACCEPT", "REJECT" };
49                 std::stringstream s;
50                 s << entry.stream() << "-" << entry.area() << "-" << levels[entry.level()] << "-" 
51                   << actions[entry.action()];
52                 return s.str();
53             }
54     };
55
56 }
57
58 BOOST_AUTO_UNIT_TEST(target)
59 {
60     senf::log::StringTarget target;
61
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);
73
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()));
77
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-senf::log::DefaultArea-NONE-REJECT",
85         "senf::log::test::myStream--IMPORTANT-REJECT",
86     };
87
88     BOOST_CHECK_EQUAL_COLLECTIONS( i, i_end, data, data + sizeof(data)/sizeof(data[0]) );
89
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);
96     target.unroute(1);
97     target.unroute(0);
98
99     BOOST_CHECK( target.begin() == target.end() );
100 }
101
102 ///////////////////////////////cc.e////////////////////////////////////////
103 #undef prefix_
104
105 \f
106 // Local Variables:
107 // mode: c++
108 // fill-column: 100
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"
114 // End: