Lumiera  0.pre.03
»edit your freedom«
run.hpp
Go to the documentation of this file.
1 /*
2  RUN.hpp - helper class for grouping, registering and invoking testcases
3 
4  Copyright (C)
5  2007,2008 Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
27 #ifndef TESTHELPER_RUN_H
28 #define TESTHELPER_RUN_H
29 
30 #include "lib/error.hpp"
31 #include "lib/random.hpp"
32 
33 #include "lib/test/suite.hpp"
34 #include "lib/util.hpp"
35 
36 #include <memory>
37 #include <string>
38 
39 
40 namespace test {
41 
42  using std::string;
43  using std::shared_ptr;
44 
45  using Arg = std::vector<string> &;
46 
47 
48 
53  class Test
54  {
55  public:
56  virtual ~Test() = default;
57  virtual void run(Arg arg) = 0;
58 
59  void seedRand();
61  static string firstTok (Arg);
62  static uint firstVal (Arg, uint =1);
63  };
64 
65 
66 
68  class Launcher
69  {
70  public:
71  virtual ~Launcher() = default;
72  virtual shared_ptr<Test> makeInstance() =0;
73  };
74 
75 
87  template<class TEST>
88  class Launch : public Launcher
89  {
90  public:
91  Launch (string testID, string groups)
92  {
93  Suite::enrol (this,testID,groups);
94  }
95 
96  virtual shared_ptr<Test>
97  makeInstance () override
98  {
99  return shared_ptr<Test> (new TEST );
100  }
101  };
102 
103 } // namespace test
104 
105 // make those global for convenience....
106 using ::test::Arg;
107 using ::test::Test;
108 using ::test::Launch;
109 using lib::rani;
110 using lib::ranHash;
111 using lib::ranRange;
112 using lib::ranNormal;
113 using lib::defaultGen;
114 
115 // and provide shortcut for registration
116 #define LAUNCHER(_TEST_CLASS_, _GROUPS_) \
117  \
118  Launch<_TEST_CLASS_> run_##_TEST_CLASS_##_(STRINGIFY(_TEST_CLASS_), _GROUPS_);
119 
120 
121 #endif /*TESTHELPER_RUN_H*/
virtual ~Test()=default
this is an interface
lib::Random makeRandGen()
build a dedicated new RandomGen, seeded from the default-Gen
Definition: suite.cpp:218
Definition: run.hpp:40
int rani(uint bound=_iBOUND())
Definition: random.hpp:135
double ranRange(double start, double bound)
Definition: random.hpp:142
lib::HashVal ranHash()
Definition: random.hpp:155
Helper class for running a collection of tests.
Definition: run.hpp:88
Abstract Base Class for all testcases.
Definition: run.hpp:53
void seedRand()
draw a new random seed from a common nucleus, and re-seed the default-Gen.
Definition: suite.cpp:211
static string firstTok(Arg)
conveniently pick the first token from the argument line
Definition: suite.cpp:233
Building and running a suite of tests, implemented as test classes.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
static uint firstVal(Arg, uint=1)
conveniently use some number given as argument, with optional default
Definition: suite.cpp:225
interface: generic testcase creating functor.
Definition: run.hpp:68
Lumiera error handling (C++ interface).
Generating (pseudo) random numbers with controlled seed.
static void enrol(Launcher *test, string testID, string groups)
register the given test-launcher, so it can be later accessed either as a member of one of the specif...
Definition: suite.cpp:131
Random defaultGen
a global default RandomSequencer for mundane purposes
Definition: random.cpp:70