2009-05-30 23:49:02 +02:00
|
|
|
|
/*
|
|
|
|
|
|
TestHelper(Test) - validate the unittest support functions
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**Lumiera** is free software; you can redistribute it and/or modify it
|
|
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
|
|
Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
|
option) any later version. See the file COPYING for further details.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
* *****************************************************************/
|
2009-05-30 23:49:02 +02:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file test-helper-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref TestHelper_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2009-05-30 23:49:02 +02:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2023-11-08 19:27:08 +01:00
|
|
|
|
#include "lib/time/timevalue.hpp"
|
2009-06-20 06:46:21 +02:00
|
|
|
|
#include "lib/error.hpp"
|
2009-12-29 04:39:27 +01:00
|
|
|
|
#include "lib/util-foreach.hpp"
|
2016-01-07 03:58:29 +01:00
|
|
|
|
#include "lib/format-cout.hpp"
|
2009-05-30 23:49:02 +02:00
|
|
|
|
|
2009-10-30 03:53:51 +01:00
|
|
|
|
#include <boost/algorithm/string.hpp>
|
2014-04-03 22:42:48 +02:00
|
|
|
|
#include <functional>
|
2009-10-30 03:53:51 +01:00
|
|
|
|
#include <string>
|
2009-05-30 23:49:02 +02:00
|
|
|
|
|
2009-10-30 03:53:51 +01:00
|
|
|
|
using util::for_each;
|
2009-06-20 06:46:21 +02:00
|
|
|
|
using lumiera::Error;
|
2024-03-16 02:04:47 +01:00
|
|
|
|
using LERR_(EXCEPTION);
|
|
|
|
|
|
using LERR_(ASSERTION);
|
2023-11-08 19:27:08 +01:00
|
|
|
|
using lib::time::TimeVar;
|
|
|
|
|
|
using lib::time::Time;
|
2009-05-30 23:49:02 +02:00
|
|
|
|
|
2009-10-30 03:53:51 +01:00
|
|
|
|
using boost::algorithm::is_lower;
|
|
|
|
|
|
using boost::algorithm::is_digit;
|
2014-04-03 22:42:48 +02:00
|
|
|
|
using std::function;
|
2009-10-30 03:53:51 +01:00
|
|
|
|
using std::string;
|
|
|
|
|
|
|
2009-05-30 23:49:02 +02:00
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
|
namespace test{
|
|
|
|
|
|
namespace test{
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
2023-11-08 19:27:08 +01:00
|
|
|
|
class Wrmrmpft
|
2009-05-30 23:49:02 +02:00
|
|
|
|
{
|
|
|
|
|
|
T tt_;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct Murpf { };
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-06-20 06:46:21 +02:00
|
|
|
|
void doThrow() { throw Error("because I feel like it"); }
|
|
|
|
|
|
int dontThrow() { return 2+2; }
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/*********************************************//**
|
2009-05-30 23:49:02 +02:00
|
|
|
|
* verifies the proper working of helper functions
|
|
|
|
|
|
* frequently used within the Lumiera testsuite.
|
|
|
|
|
|
* @see test-helper.hpp
|
|
|
|
|
|
*/
|
|
|
|
|
|
class TestHelper_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
void
|
|
|
|
|
|
run (Arg)
|
|
|
|
|
|
{
|
2009-10-30 03:53:51 +01:00
|
|
|
|
checkGarbageStr();
|
2009-05-30 23:49:02 +02:00
|
|
|
|
checkTypeDisplay();
|
2009-06-20 06:46:21 +02:00
|
|
|
|
checkThrowChecker();
|
2023-11-08 19:27:08 +01:00
|
|
|
|
checkLocalManipulation();
|
2009-05-30 23:49:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @test prints "sizeof()" including some type name. */
|
|
|
|
|
|
void
|
|
|
|
|
|
checkTypeDisplay ()
|
|
|
|
|
|
{
|
|
|
|
|
|
std::cout << "Displaying types and sizes....\n";
|
|
|
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
|
typedef Wrmrmpft<Murpf> Wrmpf1;
|
2009-05-30 23:49:02 +02:00
|
|
|
|
typedef Wrmrmpft<char[2]> Wrmpf2;
|
|
|
|
|
|
typedef Wrmrmpft<char[3]> Wrmpf3;
|
|
|
|
|
|
|
|
|
|
|
|
Wrmpf1 rmpf1;
|
|
|
|
|
|
Wrmpf2 rmpf2;
|
|
|
|
|
|
Wrmpf3 rmpf3;
|
|
|
|
|
|
Murpf murpf;
|
|
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (1 == sizeof (rmpf1));
|
|
|
|
|
|
CHECK (2 == sizeof (rmpf2));
|
|
|
|
|
|
CHECK (3 == sizeof (rmpf3));
|
2009-05-30 23:49:02 +02:00
|
|
|
|
|
2016-01-10 00:31:13 +01:00
|
|
|
|
cout << showSizeof<char>("just a char") << endl;
|
|
|
|
|
|
cout << showSizeof(murpf) << endl;
|
|
|
|
|
|
cout << showSizeof(rmpf1) << endl;
|
|
|
|
|
|
cout << showSizeof(rmpf2) << endl;
|
|
|
|
|
|
cout << showSizeof<Wrmpf3>() << endl;
|
|
|
|
|
|
cout << showSizeof(size_t(42),
|
|
|
|
|
|
string{"Universe"}) << endl;
|
2009-05-30 23:49:02 +02:00
|
|
|
|
|
2016-01-10 12:25:45 +01:00
|
|
|
|
// all the following ways to refer to an object are equivalent...
|
2009-05-30 23:49:02 +02:00
|
|
|
|
Wrmpf1 *p1 = &rmpf1;
|
|
|
|
|
|
Wrmpf1 *p2 = 0;
|
|
|
|
|
|
cout << showSizeof(p1) << endl;
|
|
|
|
|
|
cout << showSizeof(p2) << endl;
|
2016-01-10 00:31:13 +01:00
|
|
|
|
|
|
|
|
|
|
Wrmpf1 & r = rmpf1;
|
|
|
|
|
|
Wrmpf1 const& cr = r;
|
|
|
|
|
|
Wrmpf1 const* cp = &r;
|
|
|
|
|
|
|
|
|
|
|
|
cout << showSizeof(r) << endl;
|
|
|
|
|
|
cout << showSizeof(cr) << endl;
|
|
|
|
|
|
cout << showSizeof(cp) << endl;
|
2009-05-30 23:49:02 +02:00
|
|
|
|
}
|
2009-06-20 06:46:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-10-30 03:53:51 +01:00
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
checkGarbageStr()
|
|
|
|
|
|
{
|
|
|
|
|
|
string garN = randStr(0);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (0 == garN.size());
|
2009-10-30 03:53:51 +01:00
|
|
|
|
|
|
|
|
|
|
typedef function<bool(string::value_type)> ChPredicate;
|
2025-06-07 23:59:57 +02:00
|
|
|
|
ChPredicate is_OK (is_lower() or is_digit());
|
2009-10-30 03:53:51 +01:00
|
|
|
|
|
|
|
|
|
|
string garM = randStr(1000000);
|
|
|
|
|
|
for_each (garM, is_OK);
|
|
|
|
|
|
|
|
|
|
|
|
cout << randStr(80) << endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-08 19:27:08 +01:00
|
|
|
|
/** @test check the VERIFY_ERROR macro,
|
2009-06-20 06:46:21 +02:00
|
|
|
|
* which ensures a given error is raised.
|
|
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
checkThrowChecker()
|
|
|
|
|
|
{
|
|
|
|
|
|
// verify the exception is indeed raised
|
|
|
|
|
|
VERIFY_ERROR (EXCEPTION, doThrow() );
|
|
|
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
|
#if false ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT
|
2009-06-20 06:46:21 +02:00
|
|
|
|
// and when actually no exception is raised, this is an ASSERTION failure
|
|
|
|
|
|
VERIFY_ERROR (ASSERTION, VERIFY_ERROR (EXCEPTION, dontThrow() ));
|
2010-04-02 21:51:39 +02:00
|
|
|
|
#endif ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT
|
2009-06-20 06:46:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-08 19:27:08 +01:00
|
|
|
|
|
|
|
|
|
|
/** @test check a local manipulations,
|
|
|
|
|
|
* which are undone when leaving the scope.
|
|
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
checkLocalManipulation()
|
|
|
|
|
|
{
|
|
|
|
|
|
int equilibrium = 42;
|
|
|
|
|
|
{
|
|
|
|
|
|
// manipulate the value temporarily...
|
|
|
|
|
|
TRANSIENTLY(equilibrium) = 49;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (49 == equilibrium);
|
|
|
|
|
|
}
|
|
|
|
|
|
CHECK (42 == equilibrium);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TimeVar day_of_reckoning{Time{555,5}};
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
TRANSIENTLY(equilibrium) = 55;
|
|
|
|
|
|
TRANSIENTLY(day_of_reckoning) = Time::ANYTIME;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (55 == equilibrium);
|
|
|
|
|
|
CHECK (Time::ANYTIME == day_of_reckoning);
|
|
|
|
|
|
throw "RRRrrevenge!!!!!!!!!!!!!!!!1!!11!!";
|
|
|
|
|
|
}
|
|
|
|
|
|
catch(...) { }
|
|
|
|
|
|
CHECK (42 == equilibrium);
|
|
|
|
|
|
CHECK (Time(555,5) == day_of_reckoning);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ // can also use λ for manipulation and clean-up
|
|
|
|
|
|
TRANSIENTLY ([&]{ day_of_reckoning *= 2; })
|
|
|
|
|
|
.cleanUp ([&]{ equilibrium /= 2; });
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (42 == equilibrium); // not yet touched...
|
|
|
|
|
|
CHECK (Time(110,11) == day_of_reckoning);
|
|
|
|
|
|
}
|
|
|
|
|
|
CHECK (Time(110,11) == day_of_reckoning);
|
|
|
|
|
|
CHECK (21 == equilibrium);
|
|
|
|
|
|
}
|
2009-05-30 23:49:02 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
2009-06-20 06:46:21 +02:00
|
|
|
|
LAUNCHER (TestHelper_test, "unit common");
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-05-30 23:49:02 +02:00
|
|
|
|
}}} // namespace lib::test::test
|
|
|
|
|
|
|