Lumiera  0.pre.03
»edit your freedom«
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 
24 #include "lib/test/test-helper.hpp"
27 #include "lib/format-string.hpp"
28 #include "lib/format-cout.hpp"
29 #include "lib/random.hpp"
30 
31 #include <string>
32 
33 using util::_Fmt;
34 using std::string;
35 
36 namespace lib {
37 namespace test{
38 
39 
41  long Dummy::_local_checksum = 0;
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
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:40
bool verify(std::string const &actual) const
Definition: test-helper.cpp:80
Front-end for printf-style string template interpolation.
int rani(uint bound=_iBOUND())
Definition: random.hpp:135
Helper to deal with C-MALLOCed memory automatically.
A front-end for using printf-style formatting.
string showSizeof(size_t siz, string name)
for printing sizeof().
Definition: test-helper.cpp:49
Implementation namespace for support and library code.
string randStr(size_t len)
create garbage string of given length
Definition: test-helper.cpp:61
unittest helper code: test dummy objects to track instances.
A collection of frequently used helper functions to support unit testing.
Generating (pseudo) random numbers with controlled seed.
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption