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) Lumiera.org
5  2009, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
33 #include "lib/test/test-helper.hpp"
34 #include "lib/test/testdummy.hpp"
35 #include "lib/format-string.hpp"
36 #include "lib/format-cout.hpp"
38 
39 #include <string>
40 
41 using util::_Fmt;
42 using std::string;
43 
44 namespace lib {
45 namespace test{
46 
47 
49  long Dummy::_local_checksum = 0;
50  bool Dummy::_throw_in_ctor = false;
51 
52  EventLog Tracker::log{"Instance-Tracker"};
53 
54 
55 
56  string
57  showSizeof (size_t siz, string name)
58  {
59  static _Fmt fmt{"sizeof( %s ) %|40t|= %3d"};
60  return fmt % name % siz;
61  }
62 
63 
64 
65 
68  string
69  randStr (size_t len)
70  {
71  static const string alpha ("aaaabbccddeeeeffgghiiiijjkkllmmnnooooppqqrrssttuuuuvvwwxxyyyyzz0123456789");
72  static const size_t MAXAL (alpha.size());
73 
74  string garbage(len,'\0');
75  size_t p = len;
76  while (p)
77  garbage[--p] = alpha[rand() % MAXAL];
78  return garbage;
79  }
80 
81 
82 
87  bool
88  ExpectString::verify (std::string const& actual) const
89  {
90  std::string const& expected{*this}; // to avoid endless recursion
91  bool expectationMatch {actual == expected};
92  if (not expectationMatch)
93  {
94  cerr << "FAIL___expectation___________"
95  << "\nexpect:"<<expected
96  << "\nactual:"<<actual
97  << endl;
98  }
99  return expectationMatch;
100  }
101 
102 
103 }} // namespace lib::test
static long _local_checksum
to verify ctor/dtor calls
Definition: testdummy.hpp:56
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:49
bool verify(std::string const &actual) const
Definition: test-helper.cpp:88
Front-end for printf-style string template interpolation.
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:57
Implementation namespace for support and library code.
unittest helper code: test dummy objects to track instances.
string randStr(size_t len)
create garbage string of given length
Definition: test-helper.cpp:69
A collection of frequently used helper functions to support unit testing.
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption