Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
test-helper.cpp
Go to the documentation of this file.
1/*
2 Test-Helper - collection of functions supporting unit testing
3
4 Copyright (C)
5 2009, 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
14
27#include "lib/format-string.hpp"
28#include "lib/format-cout.hpp"
29#include "lib/random.hpp"
30
31#include <string>
32
33using util::_Fmt;
34using std::string;
35
36namespace lib {
37namespace test{
38
39
42 bool Dummy::_throw_in_ctor = false;
43
44 EventLog Tracker::log{"Instance-Tracker"};
45
46
47
48 string
49 showSizeof (size_t siz, string name)
50 {
51 static _Fmt fmt{"sizeof( %s ) %|40t|= %3d"};
52 return fmt % name % siz;
53 }
54
55
56
57
60 string
61 randStr (size_t len)
62 {
63 static const string alpha{"aaaabbccddeeeeffgghiiiijjkkllmmnnooooppqqrrssttuuuuvvwwxxyyyyzz0123456789"};
64 static const size_t MAXAL{alpha.size()};
65
66 string garbage(len,'\0');
67 size_t p = len;
68 while (p)
69 garbage[--p] = alpha[rani (MAXAL)];
70 return garbage;
71 }
72
73
74
79 bool
80 ExpectString::verify (std::string const& actual) const
81 {
82 std::string const& expected{*this}; // to avoid endless recursion
83 bool expectationMatch {actual == expected};
84 if (not expectationMatch)
85 {
86 cerr << "FAIL___expectation___________"
87 << "\nexpect:"<<expected
88 << "\nactual:"<<actual
89 << endl;
90 }
91 return expectationMatch;
92 }
93
94
95}} // namespace lib::test
static long _local_checksum
to verify ctor/dtor calls
static bool _throw_in_ctor
bool verify(std::string const &actual) const
A front-end for using printf-style formatting.
Automatically use custom string conversion in C++ stream output.
Front-end for printf-style string template interpolation.
string showSizeof(size_t siz, string name)
for printing sizeof().
string randStr(size_t len)
create garbage string of given length
Implementation namespace for support and library code.
int rani(uint bound=_iBOUND())
Definition random.hpp:135
Test runner and basic definitions for tests.
Generating (pseudo) random numbers with controlled seed.
static lib::test::EventLog log
A collection of frequently used helper functions to support unit testing.
unittest helper code: test dummy objects to track instances.
Helper to deal with C-MALLOCed memory automatically.