COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-properties.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 properties facility"
9 
10 #include <boost/test/unit_test.hpp>
11 
12 #include "common/Assertions.hpp"
14 #include "common/PropertyList.hpp"
15 
16 using namespace std;
17 using namespace boost;
18 
19 using namespace cf3;
20 using namespace cf3::common;
21 
23 
25 {
28  {
29  // int* argc = &boost::unit_test::framework::master_test_suite().argc;
30  // char*** argv = &boost::unit_test::framework::master_test_suite().argv;
31  }
32 
35  {
36  }
37 
39 
41 
42 };
43 
45 
46 BOOST_FIXTURE_TEST_SUITE( Properties_TestSuite, Properties_Fixture )
47 
48 
51 {
52  PropertyList props;
53 
54  // test construction
55 
56  props.add("count", int(10));
57  props.add("name", std::string("lolo"));
58 
59  BOOST_CHECK_EQUAL ( props.check( "nono" ), false );
60  BOOST_CHECK_EQUAL ( props.check( "count" ), true );
61  BOOST_CHECK_EQUAL ( props.check( "name" ), true );
62 
63  // test no duplicates
64 
65 // props["name"] = std::string( "lolo" );
66 
67 // BOOST_CHECK_EQUAL ( props.check( "name" ), 1 );
68 
69 }
70 
72 
74 {
75  PropertyList props;
76 
77  props.add("name", std::string("(empty)"));
78 
79  // test assign
80 
81  props.set("name", std::string( "john" ));
82 
83  BOOST_CHECK_EQUAL ( props.value<std::string>("name"), "john" );
84 
85  // test re-assign
86 
87  props.set("name", std::string( "joanna" ));
88 
89  BOOST_CHECK_EQUAL ( props.value<std::string>("name"), "joanna" );
90 }
91 
93 
95 {
96  PropertyList props;
97 
98  // test construction
99 
100  props.add("count0", Uint(10));
101  props.add("count1", Uint(11));
102  props.add("count2", Uint(12));
103  props.add("count3", Uint(13));
104 
105  Uint counter = 10;
106  PropertyList::PropertyStorage_t::iterator itr = props.store.begin();
107  for ( ; itr != props.store.end(); ++itr, ++counter )
108  {
109  const std::string& pname = itr->first;
110  BOOST_CHECK_EQUAL ( props.value<Uint>(pname), counter );
111  }
112 }
113 
115 
117 {
118  AssertionManager::instance().AssertionThrows = true;
119  PropertyList props;
120 
121  props.add("count", int(10));
122  props.add("name", std::string("john"));
123  props.add("surname", std::string("doe"));
124  props.add("size", int(99));
125 
126  BOOST_CHECK_EQUAL ( props.store.size(), (Uint) 4 );
127 
128  BOOST_CHECK_EQUAL ( props.check( "count" ), true );
129  BOOST_CHECK_EQUAL ( props.check( "name" ), true );
130  BOOST_CHECK_EQUAL ( props.check( "surname" ), true );
131  BOOST_CHECK_EQUAL ( props.check( "size" ), true );
132 
133  BOOST_CHECK_EQUAL ( props.check( "address" ), false );
134  BOOST_CHECK_EQUAL ( props.check( "age" ), false );
135 
136  // test removal of existing properties
137 
138  props.erase("count");
139  props.erase("surname");
140 
141  BOOST_CHECK_EQUAL ( props.store.size(), (Uint) 2 );
142 
143  BOOST_CHECK_EQUAL ( props.check( "count" ), false );
144  BOOST_CHECK_EQUAL ( props.check( "surname" ), false );
145 
146  // test removal of non-existing properties
147  // should not throw or crash
148 
149  BOOST_CHECK_THROW ( props.erase("address"), ValueNotFound);
150  BOOST_CHECK_EQUAL ( props.check( "address" ), false );
151 
152  BOOST_CHECK_THROW(props.erase("age"), ValueNotFound);
153  BOOST_CHECK_EQUAL ( props.check( "age" ), false );
154 
155  BOOST_CHECK_EQUAL ( props.store.size(), (Uint) 2 );
156 }
157 
159 
160 BOOST_AUTO_TEST_SUITE_END()
161 
162 
external boost library namespace
STL namespace.
PropertyList & add(const std::string &name, const boost::any &value)
adds a property to the list
Properties_Fixture()
common setup for each test case
bool check(const std::string &prop_name) const
TYPE value(const std::string &pname) const
Top-level namespace for coolfluid.
Definition: Action.cpp:18
void set(const std::string &pname, const boost::any &val)
void erase(const std::string &pname)
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
BOOST_AUTO_TEST_CASE(construct)
~Properties_Fixture()
common tear-down for each test case
Most basic kernel library.
Definition: Action.cpp:19
PropertyStorage_t store
storage of options
Send comments to:
COOLFluiD Web Admin