File indexing completed on 2024-04-28 04:37:35
0001 /* 0002 SPDX-FileCopyrightText: 2012 Milian Wolff <mail@milianw.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KDEVPLATFORM_TESTHELPERS_H 0008 #define KDEVPLATFORM_TESTHELPERS_H 0009 0010 #include "testsexport.h" 0011 0012 #include <language/editor/rangeinrevision.h> 0013 #include <language/duchain/types/abstracttype.h> 0014 #include <language/duchain/declaration.h> 0015 #include <serialization/indexedstring.h> 0016 0017 #include <QTest> 0018 0019 #define QVERIFY_RETURN(statement, retval) \ 0020 do { \ 0021 if (!QTest::qVerify(static_cast<bool>(statement), #statement, "", __FILE__, __LINE__)) \ 0022 return retval; \ 0023 } while (false) 0024 0025 #define QCOMPARE_RETURN(actual, expected, retval) \ 0026 do { \ 0027 if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__)) \ 0028 return retval; \ 0029 } while (false) 0030 0031 #define RETURN_IF_TEST_FAILED(...) \ 0032 do { \ 0033 if (QTest::currentTestFailed()) { \ 0034 qCritical("FAILED AT: %s:%d", __FILE__, __LINE__); \ 0035 return __VA_ARGS__; \ 0036 } \ 0037 } while (false) 0038 0039 namespace QTest { 0040 template<> 0041 inline char* toString(const KDevelop::CursorInRevision& c) 0042 { 0043 return toString(c.castToSimpleCursor()); 0044 } 0045 0046 template<> 0047 inline char* toString(const KDevelop::RangeInRevision& r) 0048 { 0049 return toString(r.castToSimpleRange()); 0050 } 0051 0052 template<> 0053 inline char* toString(const KDevelop::QualifiedIdentifier& id) 0054 { 0055 return qstrdup(qPrintable(id.toString())); 0056 } 0057 0058 template<> 0059 inline char* toString(const KDevelop::Identifier& id) 0060 { 0061 return qstrdup(qPrintable(id.toString())); 0062 } 0063 0064 template<> 0065 inline char* toString(const KDevelop::Declaration& dec) 0066 { 0067 QString s = QStringLiteral("Declaration %1 (%2): %3") 0068 .arg(dec.identifier().toString(), 0069 dec.qualifiedIdentifier().toString(), 0070 QString::number(reinterpret_cast<qint64>(&dec), 10)); 0071 return qstrdup(s.toLatin1().constData()); 0072 } 0073 0074 template<> 0075 inline char* toString(const KDevelop::AbstractType::Ptr& type) 0076 { 0077 QString s = QStringLiteral("Type: %1") 0078 .arg(type ? type->toString() : QStringLiteral("<null>")); 0079 return qstrdup(s.toLatin1().constData()); 0080 } 0081 0082 template<> 0083 inline char* toString(const KDevelop::IndexedString& string) 0084 { 0085 return qstrdup(qPrintable(string.str())); 0086 } 0087 } 0088 0089 #endif // KDEVPLATFORM_TESTHELPERS_H