Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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
40namespace 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
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....
106using ::test::Arg;
107using ::test::Test;
108using ::test::Launch;
109using lib::rani;
110using lib::ranHash;
111using lib::ranRange;
112using lib::ranNormal;
113using 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*/
Helper class for running a collection of tests.
Definition run.hpp:89
Launch(string testID, string groups)
Definition run.hpp:91
virtual shared_ptr< Test > makeInstance() override
Definition run.hpp:97
interface: generic testcase creating functor.
Definition run.hpp:69
virtual ~Launcher()=default
virtual shared_ptr< Test > makeInstance()=0
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
Abstract Base Class for all testcases.
Definition run.hpp:54
virtual ~Test()=default
this is an interface
virtual void run(Arg arg)=0
lib::Random makeRandGen()
build a dedicated new RandomGen, seeded from the default-Gen
Definition suite.cpp:218
static uint firstVal(Arg, uint=1)
conveniently use some number given as argument, with optional default
Definition suite.cpp:225
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
Lumiera error handling (C++ interface).
unsigned int uint
Definition integral.hpp:29
double ranRange(double start, double bound)
Definition random.hpp:142
lib::HashVal ranHash()
Definition random.hpp:155
int rani(uint bound=_iBOUND())
Definition random.hpp:135
Random defaultGen
a global default RandomSequencer for mundane purposes
Definition random.cpp:70
double ranNormal(double mean=0.0, double stdev=1.0)
Definition random.hpp:148
Test runner and basic definitions for tests.
std::vector< string > & Arg
Definition run.hpp:45
Generating (pseudo) random numbers with controlled seed.
Building and running a suite of tests, implemented as test classes.
#define TEST(name)
Definition test.h:45
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...