FV3 Bundle
Test.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 OOPS_RUNS_TEST_H_
12 #define OOPS_RUNS_TEST_H_
13 
14 #include <cstring>
15 #include <string>
16 #include <vector>
17 
18 #include <boost/test/unit_test.hpp>
19 #include <boost/tokenizer.hpp>
20 
21 #include "eckit/config/Configuration.h"
22 #include "oops/runs/Application.h"
23 #include "oops/util/Logger.h"
24 #include "test/TestEnvironment.h"
25 
26 namespace oops {
27 
28 // -----------------------------------------------------------------------------
29 
30 class Test : public Application {
31  public:
32  Test() {}
33  virtual ~Test() {}
34  int execute(const eckit::Configuration & config) const;
35  private:
36  virtual void register_tests() const = 0;
37  virtual std::string testid() const = 0;
38  static bool init_unit_test() {return true;}
39  std::string appname() const {return "oops::Test running " + testid();}
40 };
41 
42 // -----------------------------------------------------------------------------
43 
44 int Test::execute(const eckit::Configuration & config) const {
45 // Setup configuration for tests
47 
48 // Extract the runtime config for the tests from the config file.
49  std::string args = config.getString("test_framework_runtime_config");
50 
51 // Create a string version of argv
52  std::vector<std::string> argvec;
53  argvec.push_back(std::string("abcd"));
54 
55  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
56  boost::char_separator<char> sep(" \n\t");
57  tokenizer tok(args, sep);
58  for (tokenizer::iterator it = tok.begin(); it != tok.end(); ++it) {
59  argvec.push_back(*it);
60  }
61 
62 // Generate the argc and argv arguments for unit_test_main(...)
63  int argc = argvec.size();
64  char * argv[argc];
65  for (int i = 0; i < argc; ++i) {
66  argv[i] = new char[argvec[i].size()+1];
67  strcpy(argv[i], argvec[i].c_str());
68  }
69 
70 // Run the tests
71  Log::trace() << "Registering the unit tests" << std::endl;
73  Log::trace() << "Running the unit tests" << std::endl;
74  int result = boost::unit_test::unit_test_main(&init_unit_test, argc, argv);
75  Log::trace() << "Finished running the unit tests" << std::endl;
76  Log::error() << "Finished running the unit tests, result = " << result << std::endl;
77 
78 // Tidy up
79  for (int i = 0; i < argc; ++i) {
80  delete [] argv[i];
81  }
82 
83 // Return test status
84  return result;
85 }
86 
87 // -----------------------------------------------------------------------------
88 
89 } // namespace oops
90 #endif // OOPS_RUNS_TEST_H_
static bool init_unit_test()
Definition: Test.h:38
l_size ! loop over number of fields ke do je do i
static TestEnvironment & getInstance()
virtual void register_tests() const =0
int execute(const eckit::Configuration &config) const
Definition: Test.h:44
virtual ~Test()
Definition: Test.h:33
void setup(const eckit::Configuration &conf)
The namespace for the main oops code.
Test()
Definition: Test.h:32
integer error
Definition: mpp.F90:1310
virtual std::string testid() const =0
std::string appname() const
Definition: Test.h:39