FV3 Bundle
test/interface/ObsAuxControl.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_OBSAUXCONTROL_H_
12 #define TEST_INTERFACE_OBSAUXCONTROL_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 ObsAuxControlFixture : private boost::noncopyable {
33  public:
34  static const eckit::Configuration & config() {return *getInstance().conf_;}
35 
36  private:
38  static ObsAuxControlFixture<MODEL> theObsAuxControlFixture;
39  return theObsAuxControlFixture;
40  }
41 
43  conf_.reset(new eckit::LocalConfiguration(TestEnvironment::config(), "ObsBias"));
44  }
45 
47 
48  boost::scoped_ptr<const eckit::LocalConfiguration> conf_;
49 };
50 
51 // -----------------------------------------------------------------------------
52 
53 template <typename MODEL> void testConstructor() {
54  typedef ObsAuxControlFixture<MODEL> Test_;
55  typedef oops::ObsAuxControl<MODEL> ObsAux_;
56 
57  boost::scoped_ptr<ObsAux_> bias(new ObsAux_(Test_::config()));
58  BOOST_CHECK(bias.get());
59 
60  bias.reset();
61  BOOST_CHECK(!bias.get());
62 }
63 
64 // -----------------------------------------------------------------------------
65 
66 template <typename MODEL> void testCopyConstructor() {
67  typedef ObsAuxControlFixture<MODEL> Test_;
68  typedef oops::ObsAuxControl<MODEL> ObsAux_;
69 
70  boost::scoped_ptr<ObsAux_> bias(new ObsAux_(Test_::config()));
71 
72  boost::scoped_ptr<ObsAux_> other(new ObsAux_(*bias));
73  BOOST_CHECK(other.get());
74 
75  other.reset();
76  BOOST_CHECK(!other.get());
77 
78  BOOST_CHECK(bias.get());
79 }
80 
81 // -----------------------------------------------------------------------------
82 
83 template <typename MODEL> class ObsAuxControl : public oops::Test {
84  public:
86  virtual ~ObsAuxControl() {}
87  private:
88  std::string testid() const {return "test::ObsAuxControl<" + MODEL::name() + ">";}
89 
90  void register_tests() const {
91  boost::unit_test::test_suite * ts = BOOST_TEST_SUITE("interface/ObsAuxControl");
92 
93  ts->add(BOOST_TEST_CASE(&testConstructor<MODEL>));
94  ts->add(BOOST_TEST_CASE(&testCopyConstructor<MODEL>));
95 
96  boost::unit_test::framework::master_test_suite().add(ts);
97  }
98 };
99 
100 // =============================================================================
101 
102 } // namespace test
103 
104 #endif // TEST_INTERFACE_OBSAUXCONTROL_H_
static const eckit::Configuration & config()
character(len=32) name
void testConstructor()
boost::scoped_ptr< const eckit::LocalConfiguration > conf_
void testCopyConstructor()
static const eckit::Configuration & config()
static ObsAuxControlFixture< MODEL > & getInstance()