| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 or (at your option) any later version |
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
| 22 | ** included in the packaging of this file. Please review the following |
| 23 | ** information to ensure the GNU General Public License requirements will |
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 25 | ** |
| 26 | ** $QT_END_LICENSE$ |
| 27 | ** |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | #ifndef TST_DEFINITIONS_H |
| 31 | #define TST_DEFINITIONS_H |
| 32 | |
| 33 | #include <QtCharts/qpolarchart.h> |
| 34 | #include <QtTest/QtTest> |
| 35 | #include <QtWidgets/QPushButton> |
| 36 | |
| 37 | QT_BEGIN_NAMESPACE |
| 38 | namespace QTest |
| 39 | { |
| 40 | // This was deprecated in Qt5. This is a small hack for the sake of compatibility. |
| 41 | inline static bool qWaitForWindowShown(QWidget *window) |
| 42 | { |
| 43 | return QTest::qWaitForWindowExposed(widget: window); |
| 44 | } |
| 45 | } |
| 46 | QT_END_NAMESPACE |
| 47 | |
| 48 | #define TRY_COMPARE(actual, expected) { \ |
| 49 | do { \ |
| 50 | const int timeout(1000); \ |
| 51 | const int waitStep(30); \ |
| 52 | /* always wait before comparing to catch possible extra signals */ \ |
| 53 | QTest::qWait(waitStep); \ |
| 54 | for (int time(0); (actual != expected) && (time < timeout); time += waitStep) \ |
| 55 | QTest::qWait(waitStep); \ |
| 56 | QCOMPARE(actual, expected); \ |
| 57 | } while (0); \ |
| 58 | } |
| 59 | |
| 60 | // Some bamboo clients have trouble passing mouse events to the test application. |
| 61 | // This can be used to skip those tests so that they don't show up as a failure |
| 62 | // in the test report. |
| 63 | #define SKIP_IF_CANNOT_TEST_MOUSE_EVENTS() { \ |
| 64 | do { \ |
| 65 | QPushButton b; \ |
| 66 | b.resize(120, 100); \ |
| 67 | b.show(); \ |
| 68 | QTest::qWaitForWindowShown(&b); \ |
| 69 | QSignalSpy spy(&b, SIGNAL(clicked())); \ |
| 70 | QTest::mouseClick(&b, Qt::LeftButton, {}, b.rect().center()); \ |
| 71 | QApplication::processEvents(); \ |
| 72 | if (spy.count() == 0) \ |
| 73 | QSKIP("Cannot test mouse events in this environment"); \ |
| 74 | } while (0); \ |
| 75 | QApplication::processEvents(); \ |
| 76 | } |
| 77 | |
| 78 | #define SKIP_ON_POLAR() { \ |
| 79 | if (isPolarTest()) \ |
| 80 | QSKIP("Test not supported by polar chart"); \ |
| 81 | } |
| 82 | |
| 83 | #define SKIP_ON_CARTESIAN() { \ |
| 84 | if (!isPolarTest()) \ |
| 85 | QSKIP("Test not supported by cartesian chart"); \ |
| 86 | } |
| 87 | |
| 88 | // Synthetic mouse moves do not trigger hover events reliably in many virtual machines, |
| 89 | // so we skip tests involving mouse moves. |
| 90 | #define SKIP_IF_FLAKY_MOUSE_MOVE() { \ |
| 91 | QSKIP("Skipping test with synthetic mouse moves."); \ |
| 92 | } |
| 93 | |
| 94 | static inline bool isPolarTest() |
| 95 | { |
| 96 | static bool isPolar = false; |
| 97 | static bool polarEnvChecked = false; |
| 98 | if (!polarEnvChecked) { |
| 99 | isPolar = !(qgetenv(varName: "TEST_POLAR_CHART" ).isEmpty()); |
| 100 | polarEnvChecked = true; |
| 101 | if (isPolar) |
| 102 | qDebug() << "TEST_POLAR_CHART found -> Testing polar chart!" ; |
| 103 | } |
| 104 | return isPolar; |
| 105 | } |
| 106 | |
| 107 | static inline QtCharts::QChart *newQChartOrQPolarChart() |
| 108 | { |
| 109 | if (isPolarTest()) |
| 110 | return new QtCharts::QPolarChart(); |
| 111 | else |
| 112 | return new QtCharts::QChart(); |
| 113 | } |
| 114 | |
| 115 | |
| 116 | |
| 117 | #endif // TST_DEFINITIONS_H |
| 118 | |