COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-log-stamp-filter.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for CF log stamp filter"
9 
10 #include <boost/test/unit_test.hpp>
11 
12 #include <boost/iostreams/device/back_inserter.hpp>
13 
15 
16 using namespace std;
17 using namespace boost;
18 using namespace cf3;
19 using namespace cf3::common;
20 
22 
24 {
27  m_buffer(),
28  m_sink(iostreams::back_inserter(m_buffer))
29  {
30  m_filter = new LogStampFilter("TestStream");
31  }
32 
34  ~LogStampFilter_Fixture() { delete m_filter; }
35 
37 
40 
41  string m_buffer;
42 
43  iostreams::back_insert_device<string> m_sink;
44 };
45 
47 
48 BOOST_FIXTURE_TEST_SUITE( LogStampFilter_TestSuite, LogStampFilter_Fixture )
49 
50 
52 
54 {
57  string str = "Hello world!";
58  Uint nbbytes_wrtitten;
59 
60  nbbytes_wrtitten = f.m_filter->write(f.m_sink, str.c_str(), str.length());
61  f.m_filter->endMessage();
62  BOOST_CHECK_EQUAL(str, f.m_buffer);
63  BOOST_CHECK_EQUAL(nbbytes_wrtitten, f.m_buffer.length());
64 
65  f.m_buffer.clear();
66 
67  // test the stamps ("TestStream" is the name of the filter created by
68  // LogStampFilter_Fixture class)
69  f.m_filter->setStamp("<%type%> ");
70  nbbytes_wrtitten = f.m_filter->write(f.m_sink, str.c_str(), str.length());
71  f.m_filter->endMessage();
72  BOOST_CHECK_EQUAL(string("<TestStream> ") + str, f.m_buffer);
73  // below : +13 because of the stamp size
74  BOOST_CHECK_EQUAL(nbbytes_wrtitten, str.length() + 13);
75 
76  f.m_buffer.clear();
77 
78  // test the stamps ("TestStream" is the name of the filter created by
79  // LogStampFilter_Fixture class)
80  f.m_filter->setStamp("<%tpye%> ");
81  nbbytes_wrtitten = f.m_filter->write(f.m_sink, str.c_str(), str.length());
82  f.m_filter->endMessage();
83  BOOST_CHECK_EQUAL(string("<%tpye%> ") + str, f.m_buffer);
84  // below : +9 because of the stamp size
85  BOOST_CHECK_EQUAL(nbbytes_wrtitten, str.length() + 9);
86 
87 }
88 
90 
91 
93 {
95  CodeLocation cl = FromHere();
96  string str = "Hello world!";
97  unsigned int nbbytes_wrtitten;
98 
99  f.m_filter->setStamp("--%place%-- ");
100  f.m_filter->setPlace(cl);
101  nbbytes_wrtitten = f.m_filter->write(f.m_sink, str.c_str(), str.length());
102  f.m_filter->endMessage();
103  BOOST_CHECK_EQUAL(string("--") + cl.short_str() + string("-- ") + str, f.m_buffer);
104  BOOST_CHECK_EQUAL(nbbytes_wrtitten, str.length() + cl.short_str().length() + 5);
105 }
106 
108 
109 BOOST_AUTO_TEST_SUITE_END()
external boost library namespace
iostreams::back_insert_device< string > m_sink
STL namespace.
BOOST_AUTO_TEST_CASE(write)
LogStampFilter_Fixture()
common setup for each test case
~LogStampFilter_Fixture()
common tear-down for each test case
Prepends a stamp to the log messages.
std::string short_str() const
void setStamp(const std::string &stamp)
Sets stamp.
Top-level namespace for coolfluid.
Definition: Action.cpp:18
void endMessage()
Ends message.
LogStampFilter * m_filter
possibly common functions used on the tests below
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
std::streamsize write(Sink &sink, const char_type *data, std::streamsize size)
Writes data to a sink.
Most basic kernel library.
Definition: Action.cpp:19
void setPlace(const CodeLocation &place)
Sets the code location.
#define FromHere()
Send comments to:
COOLFluiD Web Admin