File: KReportTestUtils.h

package info (click to toggle)
kreport 3.2.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,032 kB
  • sloc: cpp: 23,245; python: 779; xml: 197; sh: 108; makefile: 9
file content (61 lines) | stat: -rw-r--r-- 2,176 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* This file is part of the KDE project
 * Copyright (C) 2015 Jarosław Staniek <staniek@kde.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef KREPORT_TEST_UTILS_H
#define KREPORT_TEST_UTILS_H

#include "kreporttestutils_export.h"
#include "KReportUtils.h"

#include <QTest>
#include <QRect>

char *numberToString(int val) { return qstrdup(qPrintable(QString::number(val))); }

namespace QTest
{
//! For convenience.
KREPORTTESTUTILS_EXPORT bool qCompare(qreal val1, qreal val2, qreal epsilon, const char *actual,
                                      const char *expected, const char *file, int line);

//! For convenience.
KREPORTTESTUTILS_EXPORT bool qCompare(const QString &val1, const char* val2, const char *actual,
                                      const char *expected, const char *file, int line);

#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
template<>
char *toString(const QColor &val) { return qstrdup(qPrintable(QVariant(val).toString())); }
#endif

template<>
char *toString(const Qt::Alignment &val) {
    return qstrdup(qPrintable(QString::fromLatin1("horizontal=%1,vertical=%2")
                       .arg(KReportUtils::horizontalToString(val)).arg(KReportUtils::verticalToString(val))));
}

template<>
char *toString(const QFont::Capitalization &val) { return numberToString(val); }

}

#define QFUZZYCOMPARE(actual, expected, epsilon) \
    do {\
        if (!QTest::qCompare(actual, expected, epsilon, #actual, #expected, __FILE__, __LINE__))\
            return;\
    } while (0)

#endif // KREPORT_TEST_UTILS_H