Preparations for unit tests
This commit is contained in:
1
cpputils.pri
Normal file
1
cpputils.pri
Normal file
@ -0,0 +1 @@
|
||||
INCLUDEPATH += $$PWD/src
|
13
cpputils_src.pri
Normal file
13
cpputils_src.pri
Normal 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
|
9
test/cpputilstestutils.cpp
Normal file
9
test/cpputilstestutils.cpp
Normal 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
28
test/cpputilstestutils.h
Normal 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
|
1
test/cpputilstestutils.pri
Normal file
1
test/cpputilstestutils.pri
Normal file
@ -0,0 +1 @@
|
||||
INCLUDEPATH += $$PWD
|
5
test/cpputilstestutils_src.pri
Normal file
5
test/cpputilstestutils_src.pri
Normal file
@ -0,0 +1,5 @@
|
||||
HEADERS += \
|
||||
$$PWD/cpputilstestutils.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/cpputilstestutils.cpp
|
Reference in New Issue
Block a user