/* * Copyright 2013-2014 Canonical Ltd. * * This program 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; version 3. * * This program 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 program. If not, see . * * Author: Christian Dywan */ #ifndef UCTESTCASE_H #define UCTESTCASE_H #include #include #include #include class LomiriTestCase : public QQuickView { Q_OBJECT public: LomiriTestCase(const QString& file, ResizeMode resize = SizeViewToRootObject, bool assertOnFailure = true, QWindow* parent = 0); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) ~LomiriTestCase(); #endif int warnings() const; // getter template inline T findItem(const QString& objectName) const { T item = rootObject()->findChild(objectName); if (item) return item; if (rootObject()->findChild(objectName)) qFatal("Item '%s' found with unexpected type", qPrintable(objectName)); qFatal("No item '%s' found", qPrintable(objectName)); } static inline QPointF centerOf(QQuickItem *item, bool windowPos = false) { QPointF center; if (item) { center = item->boundingRect().center(); if (windowPos) { center = item->mapToScene(center); } } return center; } static void ignoreWarning(const QString& fileName, uint line, uint column, const QString& message, uint occurences=1); static void ignoreWarning(const QString& fileName, uint line, const QString& message, uint occurences=1); static inline void waitForSignal(QSignalSpy *spy, int timeout = 5000) { QVERIFY(spy); if (!spy->count()) { QVERIFY(spy->wait(timeout)); } else { QCOMPARE(spy->count(), 1); } } private: QSignalSpy* m_spy; }; #endif // UCTESTCASE_H