FV3 Bundle
TestEnvironment.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_TESTENVIRONMENT_H_
12 #define TEST_TESTENVIRONMENT_H_
13 
14 #include <boost/noncopyable.hpp>
15 #include <boost/scoped_ptr.hpp>
16 
17 #include "eckit/config/LocalConfiguration.h"
18 
19 namespace test {
20 
21 /// TestEnvironment is a singleton that defines the unit testing enviroment
22 /*! TestEnvironment contains globally available information for the unit
23  * tests. It is needed because there is no easy method to pass configuration
24  * and other data to the tests. By defining a singleton, each test can
25  * use TestEnvironment::getInstance() to get access to the global data.
26  */
27 
28 class TestEnvironment : private boost::noncopyable {
29  public:
31  static TestEnvironment theTestEnvironment;
32  return theTestEnvironment;
33  }
34 
35  void setup(const eckit::Configuration & conf) {
36  config_.reset(new eckit::LocalConfiguration(conf));
37  }
38 
39  static const eckit::Configuration & config() {return *getInstance().config_;}
40 
41  private:
44 
45  boost::scoped_ptr<const eckit::LocalConfiguration> config_;
46 };
47 
48 } // namespace test
49 
50 #endif // TEST_TESTENVIRONMENT_H_
TestEnvironment is a singleton that defines the unit testing enviroment.
static TestEnvironment & getInstance()
Definition: conf.py:1
static const eckit::Configuration & config()
void setup(const eckit::Configuration &conf)
boost::scoped_ptr< const eckit::LocalConfiguration > config_