| 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 test suite of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ | 
| 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 as published by the Free Software | 
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
| 21 | ** included in the packaging of this file. Please review the following | 
| 22 | ** information to ensure the GNU General Public License requirements will | 
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 24 | ** | 
| 25 | ** $QT_END_LICENSE$ | 
| 26 | ** | 
| 27 | ****************************************************************************/ | 
| 28 |  | 
| 29 | #ifndef PARTICLES_TESTS_SHARED | 
| 30 | #define PARTICLES_TESTS_SHARED | 
| 31 | #include <QtQuick/QQuickView> | 
| 32 | #include <QtTest> | 
| 33 | #include <QAbstractAnimation> | 
| 34 | #include <QScopedPointer> | 
| 35 |  | 
| 36 | const qreal EPSILON = 0.0001; | 
| 37 |  | 
| 38 | bool extremelyFuzzyCompare(qreal a, qreal b, qreal e)//For cases which can have larger variances | 
| 39 | { | 
| 40 |     return (a + e >= b) && (a - e <= b); | 
| 41 | } | 
| 42 |  | 
| 43 | bool myFuzzyCompare(qreal a, qreal b)//For cases which might be near 0 so qFuzzyCompare fails | 
| 44 | { | 
| 45 |     return (a + EPSILON > b) && (a - EPSILON < b); | 
| 46 | } | 
| 47 |  | 
| 48 | bool myFuzzyLEQ(qreal a, qreal b) | 
| 49 | { | 
| 50 |     return (a - EPSILON < b); | 
| 51 | } | 
| 52 |  | 
| 53 | bool myFuzzyGEQ(qreal a, qreal b) | 
| 54 | { | 
| 55 |     return (a + EPSILON > b); | 
| 56 | } | 
| 57 |  | 
| 58 | QQuickView* createView(const QUrl &filename, int additionalWait=0) | 
| 59 | { | 
| 60 |     QScopedPointer<QQuickView> view(new QQuickView(nullptr)); | 
| 61 |  | 
| 62 |     view->setSource(filename); | 
| 63 |     if (view->status() != QQuickView::Ready) | 
| 64 |         return nullptr; | 
| 65 |     view->show(); | 
| 66 |     if (!QTest::qWaitForWindowExposed(window: view.data())) | 
| 67 |         return nullptr; | 
| 68 |     if (additionalWait) | 
| 69 |         QTest::qWait(ms: additionalWait); | 
| 70 |  | 
| 71 |     return view.take(); | 
| 72 | } | 
| 73 |  | 
| 74 | void ensureAnimTime(int requiredTime, QAbstractAnimation* anim)//With consistentTiming, who knows how long an animation really takes... | 
| 75 | { | 
| 76 |     while (anim->currentTime() < requiredTime) | 
| 77 |         QTest::qWait(ms: 100); | 
| 78 | } | 
| 79 |  | 
| 80 | #endif | 
| 81 |  |