diff options
author | Jake Petroules <jake.petroules@qt.io> | 2017-05-25 16:35:48 -0700 |
---|---|---|
committer | Jake Petroules <jake.petroules@qt.io> | 2017-05-30 14:14:23 +0000 |
commit | 73da5637c1ee9a2ee2efecbcc050d885b9385f51 (patch) | |
tree | 6b3505125a86f9582f32e05ac7b633fe7be765e5 /tests/auto/blackbox/testdata-qt/dbus-adaptors | |
parent | 8e9bab9072941196bf6709ac762c1f99e67a21a8 (diff) |
Migrate blackbox tests depending on Qt into a new tst_blackboxqt target
This new test suite collects all the tests which actually rely on
Qt and test qbs' support for Qt in some way.
Change-Id: Id13d0bee6639314c26bfd87d2abee8fd31dcf770
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'tests/auto/blackbox/testdata-qt/dbus-adaptors')
5 files changed, 320 insertions, 0 deletions
diff --git a/tests/auto/blackbox/testdata-qt/dbus-adaptors/THIS.IS.A.STRANGE.FILENAME.CAR.XML b/tests/auto/blackbox/testdata-qt/dbus-adaptors/THIS.IS.A.STRANGE.FILENAME.CAR.XML new file mode 100644 index 000000000..6d8c9d19f --- /dev/null +++ b/tests/auto/blackbox/testdata-qt/dbus-adaptors/THIS.IS.A.STRANGE.FILENAME.CAR.XML @@ -0,0 +1,11 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node name="/com/trollech/examples/car"> + <interface name="org.example.Examples.CarInterface"> + <method name="accelerate"/> + <method name="decelerate"/> + <method name="turnLeft"/> + <method name="turnRight"/> + <signal name="crashed"/> + </interface> +</node>
\ No newline at end of file diff --git a/tests/auto/blackbox/testdata-qt/dbus-adaptors/car.cpp b/tests/auto/blackbox/testdata-qt/dbus-adaptors/car.cpp new file mode 100644 index 000000000..466ed4b8e --- /dev/null +++ b/tests/auto/blackbox/testdata-qt/dbus-adaptors/car.cpp @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qbs. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "car.h" +#include <QtWidgets/QtWidgets> +#include <math.h> + +static const double Pi = 3.14159265358979323846264338327950288419717; + +QRectF Car::boundingRect() const +{ + return QRectF(-35, -81, 70, 115); +} + +Car::Car() : color(Qt::green), wheelsAngle(0), speed(0) +{ + startTimer(1000 / 33); + setFlag(QGraphicsItem::ItemIsMovable, true); + setFlag(QGraphicsItem::ItemIsFocusable, true); +} + +void Car::accelerate() +{ + if (speed < 10) + ++speed; +} + +void Car::decelerate() +{ + if (speed > -10) + --speed; +} + +void Car::turnLeft() +{ + if (wheelsAngle > -30) + wheelsAngle -= 5; +} + +void Car::turnRight() +{ + if (wheelsAngle < 30) + wheelsAngle += 5; +} + +void Car::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option); + Q_UNUSED(widget); + + painter->setBrush(Qt::gray); + painter->drawRect(-20, -58, 40, 2); // front axel + painter->drawRect(-20, 7, 40, 2); // rear axel + + painter->setBrush(color); + painter->drawRect(-25, -79, 50, 10); // front wing + + painter->drawEllipse(-25, -48, 50, 20); // side pods + painter->drawRect(-25, -38, 50, 35); // side pods + painter->drawRect(-5, 9, 10, 10); // back pod + + painter->drawEllipse(-10, -81, 20, 100); // main body + + painter->drawRect(-17, 19, 34, 15); // rear wing + + painter->setBrush(Qt::black); + painter->drawPie(-5, -51, 10, 15, 0, 180 * 16); + painter->drawRect(-5, -44, 10, 10); // cocpit + + painter->save(); + painter->translate(-20, -58); + painter->rotate(wheelsAngle); + painter->drawRect(-10, -7, 10, 15); // front left + painter->restore(); + + painter->save(); + painter->translate(20, -58); + painter->rotate(wheelsAngle); + painter->drawRect(0, -7, 10, 15); // front left + painter->restore(); + + painter->drawRect(-30, 0, 12, 17); // rear left + painter->drawRect(19, 0, 12, 17); // rear right +} + +void Car::timerEvent(QTimerEvent *event) +{ + Q_UNUSED(event); + + const qreal axelDistance = 54; + qreal wheelsAngleRads = (wheelsAngle * Pi) / 180; + qreal turnDistance = ::cos(wheelsAngleRads) * axelDistance * 2; + qreal turnRateRads = wheelsAngleRads / turnDistance; // rough estimate + qreal turnRate = (turnRateRads * 180) / Pi; + qreal rotation = speed * turnRate; + + setTransform(QTransform().rotate(rotation), true); + setTransform(QTransform::fromTranslate(0, -speed), true); + update(); +} diff --git a/tests/auto/blackbox/testdata-qt/dbus-adaptors/car.h b/tests/auto/blackbox/testdata-qt/dbus-adaptors/car.h new file mode 100644 index 000000000..f14b1062d --- /dev/null +++ b/tests/auto/blackbox/testdata-qt/dbus-adaptors/car.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qbs. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CAR_H +#define CAR_H + +#include <QGraphicsObject> +#include <QBrush> + +class Car : public QGraphicsObject +{ + Q_OBJECT +public: + Car(); + QRectF boundingRect() const; + +public Q_SLOTS: + void accelerate(); + void decelerate(); + void turnLeft(); + void turnRight(); + +Q_SIGNALS: + void crashed(); + +protected: + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + void timerEvent(QTimerEvent *event); + +private: + QBrush color; + qreal wheelsAngle; // used when applying rotation + qreal speed; // delta movement along the body axis +}; + +#endif // CAR_H diff --git a/tests/auto/blackbox/testdata-qt/dbus-adaptors/car.qbs b/tests/auto/blackbox/testdata-qt/dbus-adaptors/car.qbs new file mode 100644 index 000000000..67ba5e7ea --- /dev/null +++ b/tests/auto/blackbox/testdata-qt/dbus-adaptors/car.qbs @@ -0,0 +1,19 @@ +import qbs + +CppApplication { + name: "car" + condition: Qt.dbus.present + Depends { name: "Qt.dbus"; required: false } + Depends { name: "Qt.widgets" } + files: [ + "car.cpp", + "car.h", + "main.cpp", + ] + + Group { + name: "DBUS Adaptor" + files: ["THIS.IS.A.STRANGE.FILENAME.CAR.XML"] + fileTags: ["qt.dbus.adaptor"] + } +} diff --git a/tests/auto/blackbox/testdata-qt/dbus-adaptors/main.cpp b/tests/auto/blackbox/testdata-qt/dbus-adaptors/main.cpp new file mode 100644 index 000000000..2c6db4403 --- /dev/null +++ b/tests/auto/blackbox/testdata-qt/dbus-adaptors/main.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qbs. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "car.h" +#include "car_adaptor.h" +#include <QtWidgets/QApplication> +#include <QtWidgets/QGraphicsView> +#include <QtWidgets/QGraphicsScene> +#include <QtDBus/QDBusConnection> + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QGraphicsScene scene; + scene.setSceneRect(-500, -500, 1000, 1000); + scene.setItemIndexMethod(QGraphicsScene::NoIndex); + + Car *car = new Car(); + scene.addItem(car); + + QGraphicsView view(&scene); + view.setRenderHint(QPainter::Antialiasing); + view.setBackgroundBrush(Qt::darkGray); + view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Qt DBus Controlled Car")); + view.resize(400, 300); + view.show(); + + new CarInterfaceAdaptor(car); + QDBusConnection connection = QDBusConnection::sessionBus(); + connection.registerObject("/Car", car); + connection.registerService("org.example.CarExample"); + + return app.exec(); +} |