File indexing completed on 2025-01-12 04:18:15
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2015 Jarosław Staniek <staniek@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public 0015 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0016 */ 0017 0018 #ifndef KREPORT_TEST_UTILS_H 0019 #define KREPORT_TEST_UTILS_H 0020 0021 #include "kreporttestutils_export.h" 0022 #include "KReportUtils.h" 0023 0024 #include <QTest> 0025 #include <QRect> 0026 0027 char *numberToString(int val) { return qstrdup(qPrintable(QString::number(val))); } 0028 0029 namespace QTest 0030 { 0031 //! For convenience. 0032 KREPORTTESTUTILS_EXPORT bool qCompare(qreal val1, qreal val2, qreal epsilon, const char *actual, 0033 const char *expected, const char *file, int line); 0034 0035 //! For convenience. 0036 KREPORTTESTUTILS_EXPORT bool qCompare(const QString &val1, const char* val2, const char *actual, 0037 const char *expected, const char *file, int line); 0038 0039 #if QT_VERSION < QT_VERSION_CHECK(5, 7, 0) 0040 template<> 0041 char *toString(const QColor &val) { return qstrdup(qPrintable(QVariant(val).toString())); } 0042 #endif 0043 0044 template<> 0045 char *toString(const Qt::Alignment &val) { 0046 return qstrdup(qPrintable(QString::fromLatin1("horizontal=%1,vertical=%2") 0047 .arg(KReportUtils::horizontalToString(val)).arg(KReportUtils::verticalToString(val)))); 0048 } 0049 0050 template<> 0051 char *toString(const QFont::Capitalization &val) { return numberToString(val); } 0052 0053 } 0054 0055 #define QFUZZYCOMPARE(actual, expected, epsilon) \ 0056 do {\ 0057 if (!QTest::qCompare(actual, expected, epsilon, #actual, #expected, __FILE__, __LINE__))\ 0058 return;\ 0059 } while (0) 0060 0061 #endif // KREPORT_TEST_UTILS_H