Preparations for unit tests

This commit is contained in:
2021-02-14 23:22:47 +01:00
parent f623ffd842
commit b8fe94f78b
6 changed files with 57 additions and 0 deletions

1
cpputils.pri Normal file
View File

@ -0,0 +1 @@
INCLUDEPATH += $$PWD/src

13
cpputils_src.pri Normal file
View File

@ -0,0 +1,13 @@
HEADERS += \
$$PWD/src/cleanuphelper.h \
$$PWD/src/cppflags.h \
$$PWD/src/cppmacros.h \
$$PWD/src/cppoverloadutils.h \
$$PWD/src/cppsignal.h \
$$PWD/src/cpptypesafeenum.h \
$$PWD/src/cpputils.h \
$$PWD/src/delayedconstruction.h \
$$PWD/src/strutils.h
SOURCES += \
$$PWD/src/strutils.cpp

View File

@ -0,0 +1,9 @@
#include "cpputilstestutils.h"
namespace QTest {
template<>
char *toString(const std::string &str)
{
return ::QTest::toString(QString::fromStdString(str));
}
} // namespace QTest

28
test/cpputilstestutils.h Normal file
View File

@ -0,0 +1,28 @@
#pragma once
#include <QMetaType>
#include <QtTest>
Q_DECLARE_METATYPE(std::string)
// only needed if there is a nameclash between std::string *::toString(const T &) and template<typename T> char *QTest::toString(const T &)
#define FIXEDCOMPARE(actual, expected) \
do {\
if (!fixedCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\
return;\
} while (false)
namespace {
template <typename T1, typename T2>
inline bool fixedCompare(T1 const &t1, T2 const &t2, const char *actual, const char *expected,
const char *file, int line)
{
return QTest::compare_helper(t1 == t2, "Compared values are not the same",
::QTest::toString(t1), ::QTest::toString(t2), actual, expected, file, line);
}
}
namespace QTest {
template<>
char *toString(const std::string &str);
} // namespace QTest

View File

@ -0,0 +1 @@
INCLUDEPATH += $$PWD

View File

@ -0,0 +1,5 @@
HEADERS += \
$$PWD/cpputilstestutils.h
SOURCES += \
$$PWD/cpputilstestutils.cpp