COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-foreach.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 simplifying for loops"
9 
10 #include <boost/test/unit_test.hpp>
11 
12 #include "common/CF.hpp"
13 #include "common/Foreach.hpp"
14 
16 
18 {
21  {
22  }
23 
26  {
27  }
28 
29 private:
30 
31 };
32 
34 
35 BOOST_FIXTURE_TEST_SUITE( ForeachTests, ForeachFixture )
36 
37 
39 BOOST_AUTO_TEST_CASE ( test_boost_foreach )
40 {
41  std::vector<int> vec(5,1);
42 
43  boost_foreach(int value, vec)
44  BOOST_CHECK_EQUAL(value,1);
45 }
46 
48 
49 BOOST_AUTO_TEST_CASE ( test_foreach_container )
50 {
51  std::map<std::string,int> my_map;
52  my_map["first"] = 1;
53  my_map["second"] = 2;
54 
55  foreach_container((const std::string& key)(const int value), my_map)
56  {
57  if (key == "first")
58  BOOST_CHECK_EQUAL(value,1);
59  else if (key == "second")
60  BOOST_CHECK_EQUAL(value,2);
61  else
62  BOOST_CHECK(false);
63  }
64 }
65 
67 
68 
69 BOOST_AUTO_TEST_SUITE_END()
70 
71 
ForeachFixture()
common setup for each test case
#define boost_foreach
lowercase version of BOOST_FOREACH
Definition: Foreach.hpp:16
#define foreach_container(VARS, COL)
boost_foreach version that allows to use std::map's, boost::tuple's, std::pair's internal variables ...
Definition: Foreach.hpp:36
~ForeachFixture()
common tear-down for each test case
BOOST_AUTO_TEST_CASE(test_boost_foreach)
coolfluid3 header, included almost everywhere
Send comments to:
COOLFluiD Web Admin