2009-05-30 23:49:02 +02:00
|
|
|
/*
|
|
|
|
|
Test-Helper - collection of functions supporting unit testing
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-05-30 23:49:02 +02:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-05-30 23:49:02 +02:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
2009-05-30 23:49:02 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-05-30 23:49:02 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-05-30 23:49:02 +02:00
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
2015-11-27 19:24:00 +01:00
|
|
|
/** @file test-helper.cpp
|
|
|
|
|
** definition of some widely used test helper functions.
|
|
|
|
|
**
|
|
|
|
|
** @see TestHelper_test
|
|
|
|
|
** @see TestHelperDemangling_test
|
|
|
|
|
**
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2009-05-30 23:49:02 +02:00
|
|
|
#include "lib/test/test-helper.hpp"
|
2024-06-15 18:14:00 +02:00
|
|
|
#include "lib/test/tracking-dummy.hpp"
|
2024-11-13 02:23:23 +01:00
|
|
|
#include "lib/unique-malloc-owner.hpp"
|
2013-09-01 17:36:05 +02:00
|
|
|
#include "lib/format-string.hpp"
|
2023-05-04 00:48:29 +02:00
|
|
|
#include "lib/format-cout.hpp"
|
2024-11-13 02:23:23 +01:00
|
|
|
#include "lib/random.hpp"
|
2014-11-22 03:31:59 +01:00
|
|
|
|
2013-09-01 17:36:05 +02:00
|
|
|
#include <string>
|
2009-05-30 23:49:02 +02:00
|
|
|
|
2016-01-08 08:20:59 +01:00
|
|
|
using util::_Fmt;
|
2013-09-01 17:36:05 +02:00
|
|
|
using std::string;
|
2009-05-31 02:41:00 +02:00
|
|
|
|
2009-05-30 23:49:02 +02:00
|
|
|
namespace lib {
|
|
|
|
|
namespace test{
|
2023-05-04 00:48:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/** storage for test-dummy flags */
|
|
|
|
|
long Dummy::_local_checksum = 0;
|
|
|
|
|
bool Dummy::_throw_in_ctor = false;
|
|
|
|
|
|
2023-10-11 21:06:56 +02:00
|
|
|
EventLog Tracker::log{"Instance-Tracker"};
|
|
|
|
|
|
2009-05-30 23:49:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
string
|
2016-01-08 08:20:59 +01:00
|
|
|
showSizeof (size_t siz, string name)
|
2009-05-30 23:49:02 +02:00
|
|
|
{
|
2016-01-10 12:25:45 +01:00
|
|
|
static _Fmt fmt{"sizeof( %s ) %|40t|= %3d"};
|
2016-01-08 08:20:59 +01:00
|
|
|
return fmt % name % siz;
|
2009-05-30 23:49:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-11-22 03:31:59 +01:00
|
|
|
|
|
|
|
|
|
2009-10-30 03:53:51 +01:00
|
|
|
/** @todo probably this can be done in a more clever way. Anyone...?
|
|
|
|
|
*/
|
|
|
|
|
string
|
|
|
|
|
randStr (size_t len)
|
|
|
|
|
{
|
2024-11-13 02:23:23 +01:00
|
|
|
static const string alpha{"aaaabbccddeeeeffgghiiiijjkkllmmnnooooppqqrrssttuuuuvvwwxxyyyyzz0123456789"};
|
|
|
|
|
static const size_t MAXAL{alpha.size()};
|
2009-10-30 03:53:51 +01:00
|
|
|
|
|
|
|
|
string garbage(len,'\0');
|
|
|
|
|
size_t p = len;
|
|
|
|
|
while (p)
|
2024-11-13 02:23:23 +01:00
|
|
|
garbage[--p] = alpha[rani (MAXAL)];
|
2009-10-30 03:53:51 +01:00
|
|
|
return garbage;
|
|
|
|
|
}
|
2014-11-22 03:31:59 +01:00
|
|
|
|
|
|
|
|
|
2009-10-30 03:53:51 +01:00
|
|
|
|
2023-05-04 00:48:29 +02:00
|
|
|
/**
|
|
|
|
|
* @internal check equality and print difference
|
|
|
|
|
* @remark defined here to avoid inclusion of `<iostream>` in header
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
ExpectString::verify (std::string const& actual) const
|
|
|
|
|
{
|
|
|
|
|
std::string const& expected{*this}; // to avoid endless recursion
|
|
|
|
|
bool expectationMatch {actual == expected};
|
|
|
|
|
if (not expectationMatch)
|
|
|
|
|
{
|
|
|
|
|
cerr << "FAIL___expectation___________"
|
|
|
|
|
<< "\nexpect:"<<expected
|
|
|
|
|
<< "\nactual:"<<actual
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
return expectationMatch;
|
|
|
|
|
}
|
2009-10-30 03:53:51 +01:00
|
|
|
|
2009-05-30 23:49:02 +02:00
|
|
|
|
|
|
|
|
}} // namespace lib::test
|