Files
poco/CppUnit/include/CppUnit/TestRunner.h
Aleksandar Fabijanic 7db9831f32 Netssl/openssl3 (#3575)
* feat(Context): DH init openssl3 port (1/2 hardcoded params)

* create poco-1.11.3 branch, bump version

* update copyright date

* #3567: check legacy provider existence for legacy exception #3567

* fix(Placeholder): comparison for zero value

* feat(Context): DH init openssl3 port (2/2 params from file)

* test(HTTPSClientSession): try/catch to understand CI failure

* chore(cmake): copy the DH parameters file

* fix(OpenSSLInitializer): unload provider on uninitialize

* chore(HTTPSClientSessionTest): remove try/catch

* fix(OpenSSLInitializer): fix provider unloading

* feat(CppUnit): make tests exceptions more descriptive

* chore(CppUnit): a more descriptive name for callback

Co-authored-by: Günter Obiltschnig <guenter.obiltschnig@appinf.com>
2022-04-28 22:24:43 -05:00

112 lines
2.6 KiB
C++

//
// TestRunner.h
//
#ifndef CppUnit_TestRunner_INCLUDED
#define CppUnit_TestRunner_INCLUDED
#include "CppUnit/CppUnit.h"
#include "CppUnit/Test.h"
#include <vector>
#include <string>
#include <ostream>
#if defined(POCO_VXWORKS)
#include <cstdarg>
#endif
#include "Poco/Exception.h"
namespace CppUnit {
/*
* A command line based tool to run tests.
* TestRunner expects as its only argument the name of a TestCase class.
* TestRunner prints out a trace as the tests are executed followed by a
* summary at the end.
*
* You can add to the tests that the TestRunner knows about by
* making additional calls to "addTest (...)" in main.
*
* Here is the synopsis:
*
* TestRunner [-all] [-long] [-print] [-wait] ExampleTestCase
*
*/
class CppUnit_API TestRunner
{
typedef std::pair<std::string, Test*> Mapping;
typedef std::vector<Mapping> Mappings;
public:
TestRunner();
TestRunner(std::ostream& ostr);
~TestRunner();
bool run(const std::vector<std::string>& args, const Test::Callback& callback = nullptr);
void addTest(const std::string& name, Test* test);
protected:
void printBanner();
void print(const std::string& name, Test* pTest, int indent);
Test* find(const std::string& name, Test* pTest, const std::string& testName);
int collectAllTestCases(Test* pTest, std::vector<Test*>& tests);
private:
std::ostream& _ostr;
Mappings _mappings;
};
} // namespace CppUnit
#if defined(POCO_VXWORKS)
#define CppUnitMain(testCase) \
int testCase##Runner(const char* arg0, ...) \
{ \
std::vector<std::string> args; \
args.push_back(#testCase "Runner"); \
args.push_back(std::string(arg0)); \
va_list vargs; \
va_start(vargs, arg0); \
const char* arg = va_arg(vargs, const char*); \
while (arg) \
{ \
args.push_back(std::string(arg)); \
arg = va_arg(vargs, const char*); \
} \
va_end(vargs); \
CppUnit::TestRunner runner; \
runner.addTest(#testCase, testCase::suite()); \
return runner.run(args) ? 0 : 1; \
}
#else
#define CppUnitPocoExceptionText(exc) \
CppUnit::Test::Callback exc = [] (const std::exception& ex) \
{ \
std::string text; \
const Poco::Exception* pEx = dynamic_cast<const Poco::Exception*>(&ex); \
if (pEx) text = pEx->displayText(); \
else text = ex.what(); \
return text; \
}
#define CppUnitMain(testCase) \
int main(int ac, char **av) \
{ \
std::vector<std::string> args; \
for (int i = 0; i < ac; ++i) \
args.push_back(std::string(av[i])); \
CppUnit::TestRunner runner; \
runner.addTest(#testCase, testCase::suite()); \
CppUnitPocoExceptionText(exc); \
return runner.run(args, exc) ? 0 : 1; \
}
#endif
#endif // CppUnit_TestRunner_INCLUDED