FV3 Bundle
test/interface/Geometry.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #ifndef TEST_INTERFACE_GEOMETRY_H_
12 #define TEST_INTERFACE_GEOMETRY_H_
13 
14 #include <string>
15 
16 #define BOOST_TEST_NO_MAIN
17 #define BOOST_TEST_ALTERNATIVE_INIT_API
18 #define BOOST_TEST_DYN_LINK
19 #include <boost/test/unit_test.hpp>
20 
21 #include <boost/noncopyable.hpp>
22 #include <boost/scoped_ptr.hpp>
23 
24 #include "eckit/config/Configuration.h"
26 #include "oops/runs/Test.h"
27 #include "test/TestEnvironment.h"
28 
29 namespace test {
30 
31 // -----------------------------------------------------------------------------
32 template <typename MODEL> class GeometryFixture : private boost::noncopyable {
33  public:
34  static const eckit::Configuration & getConfig() {return *getInstance().conf_;}
35 
36  private:
38  static GeometryFixture<MODEL> theGeometryFixture;
39  return theGeometryFixture;
40  }
41 
43  conf_.reset(new eckit::LocalConfiguration(TestEnvironment::config(), "Geometry"));
44  }
45 
47 
48  boost::scoped_ptr<const eckit::LocalConfiguration> conf_;
49 };
50 // -----------------------------------------------------------------------------
51 
52 template <typename MODEL> void testConstructor() {
53  typedef oops::Geometry<MODEL> Geometry_;
54 
55  boost::scoped_ptr<Geometry_> geom(new Geometry_(GeometryFixture<MODEL>::getConfig()));
56  BOOST_CHECK(geom.get());
57 
58  geom.reset();
59  BOOST_CHECK(!geom.get());
60 }
61 
62 // -----------------------------------------------------------------------------
63 
64 template <typename MODEL> void testCopyConstructor() {
65  typedef oops::Geometry<MODEL> Geometry_;
66  boost::scoped_ptr<Geometry_> geom(new Geometry_(GeometryFixture<MODEL>::getConfig()));
67 
68  boost::scoped_ptr<Geometry_> other(new Geometry_(*geom));
69  BOOST_CHECK(other.get());
70 
71  other.reset();
72  BOOST_CHECK(!other.get());
73 
74  BOOST_CHECK(geom.get());
75 }
76 
77 // -----------------------------------------------------------------------------
78 
79 template <typename MODEL> class Geometry : public oops::Test {
80  public:
81  Geometry() {}
82  virtual ~Geometry() {}
83  private:
84  std::string testid() const {return "test::Geometry<" + MODEL::name() + ">";}
85 
86  void register_tests() const {
87  boost::unit_test::test_suite * ts = BOOST_TEST_SUITE("interface/Geometry");
88 
89  ts->add(BOOST_TEST_CASE(&testConstructor<MODEL>));
90  ts->add(BOOST_TEST_CASE(&testCopyConstructor<MODEL>));
91 
92  boost::unit_test::framework::master_test_suite().add(ts);
93  }
94 };
95 
96 // =============================================================================
97 
98 } // namespace test
99 
100 #endif // TEST_INTERFACE_GEOMETRY_H_
static const eckit::Configuration & config()
character(len=32) name
void register_tests() const
std::string testid() const
void testConstructor()
static const eckit::Configuration & getConfig()
void testCopyConstructor()
boost::scoped_ptr< const eckit::LocalConfiguration > conf_
static GeometryFixture< MODEL > & getInstance()