switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / Logger / FileTarget.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
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
10 //
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.
14 //
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.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
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.
24 //
25 // Contributor(s):
26 //   Thorsten Horstmann <tho@berlios.de>
27
28 /** \file
29     \brief FileTarget unit tests */
30
31 //#include "FileTarget.test.hh"
32 //#include "FileTarget.test.ih"
33
34 // Custom includes
35 #include <fstream>
36 #include <boost/filesystem/operations.hpp>
37 #include "FileTarget.hh"
38 #include "Logger.hh"
39
40 #include <senf/Utils/auto_unit_test.hh>
41 #include <boost/test/test_tools.hpp>
42
43 #define prefix_
44 //-/////////////////////////////////////////////////////////////////////////////////////////////////
45
46 SENF_AUTO_UNIT_TEST(fileTarget)
47 {
48     std::string filename ("/tmp/senf_fileTarget_test.log");
49     senf::log::FileTarget target (filename);
50
51     target.tag("");
52     target.showTime(false);
53     target.showLevel(false);
54     target.route();
55
56     std::string message ("Test message");
57     SENF_LOG((message));
58
59     BOOST_REQUIRE( boost::filesystem::exists(filename));
60     std::ifstream inFile;
61     inFile.open(filename.c_str());
62     BOOST_REQUIRE( inFile);
63
64     char buffer[256];
65     inFile.getline(buffer, 256);
66     inFile.close();
67     BOOST_CHECK_EQUAL( std::string(buffer), message);
68
69     SENF_CHECK_NO_THROW( boost::filesystem::remove(filename) );
70
71     target.reopen();
72     BOOST_REQUIRE( boost::filesystem::exists(filename));
73     SENF_CHECK_NO_THROW( boost::filesystem::remove(filename) );
74
75     filename = std::string("/tmp/senf_fileTarget_test2.log");
76     target.reopen( filename);
77     BOOST_REQUIRE( boost::filesystem::exists(filename));
78     SENF_CHECK_NO_THROW( boost::filesystem::remove(filename) );
79 }
80
81 //-/////////////////////////////////////////////////////////////////////////////////////////////////
82 #undef prefix_
83
84 \f
85 // Local Variables:
86 // mode: c++
87 // fill-column: 100
88 // comment-column: 40
89 // c-file-style: "senf"
90 // indent-tabs-mode: nil
91 // ispell-local-dictionary: "american"
92 // compile-command: "scons -u test"
93 // End: