FV3 Bundle
test/interface/ModelAuxControl.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_MODELAUXCONTROL_H_
12 #define TEST_INTERFACE_MODELAUXCONTROL_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/LocalConfiguration.h"
27 #include "oops/runs/Test.h"
28 #include "test/TestEnvironment.h"
29 
30 namespace test {
31 
32 // -----------------------------------------------------------------------------
33 template <typename MODEL> class ModelAuxControlFixture : private boost::noncopyable {
36 
37  public:
38  static const eckit::Configuration & config() {return *getInstance().conf_;}
39  static const Geometry_ & resol() {return *getInstance().resol_;}
40 
41  private:
43  static ModelAuxControlFixture<MODEL> theModelAuxControlFixture;
44  return theModelAuxControlFixture;
45  }
46 
48  conf_.reset(new eckit::LocalConfiguration(TestEnvironment::config(), "ModelBias"));
49 
50  const eckit::LocalConfiguration resolConfig(TestEnvironment::config(), "Geometry");
51  resol_.reset(new Geometry_(resolConfig));
52  }
53 
55 
56  boost::scoped_ptr<const eckit::LocalConfiguration> conf_;
57  boost::scoped_ptr<Geometry_> resol_;
58 };
59 
60 // -----------------------------------------------------------------------------
61 
62 template <typename MODEL> void testConstructor() {
63  typedef ModelAuxControlFixture<MODEL> Test_;
64  typedef oops::ModelAuxControl<MODEL> ModelAux_;
65 
66  boost::scoped_ptr<ModelAux_> bias(new ModelAux_(Test_::resol(), Test_::config()));
67  BOOST_CHECK(bias.get());
68 
69  bias.reset();
70  BOOST_CHECK(!bias.get());
71 }
72 
73 // -----------------------------------------------------------------------------
74 
75 template <typename MODEL> void testCopyConstructor() {
76  typedef ModelAuxControlFixture<MODEL> Test_;
77  typedef oops::ModelAuxControl<MODEL> ModelAux_;
78 
79  boost::scoped_ptr<ModelAux_> bias(new ModelAux_(Test_::resol(), Test_::config()));
80 
81  boost::scoped_ptr<ModelAux_> other(new ModelAux_(*bias));
82  BOOST_CHECK(other.get());
83 
84  other.reset();
85  BOOST_CHECK(!other.get());
86 
87  BOOST_CHECK(bias.get());
88 }
89 
90 // -----------------------------------------------------------------------------
91 
92 template <typename MODEL> void testChangeRes() {
93  typedef ModelAuxControlFixture<MODEL> Test_;
94  typedef oops::ModelAuxControl<MODEL> ModelAux_;
95 
96  boost::scoped_ptr<ModelAux_> bias(new ModelAux_(Test_::resol(), Test_::config()));
97 
98  boost::scoped_ptr<ModelAux_> other(new ModelAux_(Test_::resol(), *bias));
99  BOOST_CHECK(other.get());
100 
101  other.reset();
102  BOOST_CHECK(!other.get());
103 
104  BOOST_CHECK(bias.get());
105 }
106 
107 // -----------------------------------------------------------------------------
108 
109 template <typename MODEL> class ModelAuxControl : public oops::Test {
110  public:
112  virtual ~ModelAuxControl() {}
113  private:
114  std::string testid() const {return "test::ModelAuxControl<" + MODEL::name() + ">";}
115 
116  void register_tests() const {
117  boost::unit_test::test_suite * ts = BOOST_TEST_SUITE("interface/ModelAuxControl");
118 
119  ts->add(BOOST_TEST_CASE(&testConstructor<MODEL>));
120  ts->add(BOOST_TEST_CASE(&testCopyConstructor<MODEL>));
121  ts->add(BOOST_TEST_CASE(&testChangeRes<MODEL>));
122 
123  boost::unit_test::framework::master_test_suite().add(ts);
124  }
125 };
126 
127 // =============================================================================
128 
129 } // namespace test
130 
131 #endif // TEST_INTERFACE_MODELAUXCONTROL_H_
boost::scoped_ptr< Geometry_ > resol_
static const eckit::Configuration & config()
character(len=32) name
boost::scoped_ptr< const eckit::LocalConfiguration > conf_
static const eckit::Configuration & config()
void testConstructor()
void testCopyConstructor()
oops::ModelAuxControl< MODEL > ModelAux_
static ModelAuxControlFixture< MODEL > & getInstance()