diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/core/core.pro | 2 | ||||
-rw-r--r-- | tests/auto/core/qiviproperty/qiviproperty.pro | 13 | ||||
-rw-r--r-- | tests/auto/core/qiviproperty/testdata/readWrite.qml | 48 | ||||
-rw-r--r-- | tests/auto/core/qiviproperty/testdata/writeError.qml | 44 | ||||
-rw-r--r-- | tests/auto/core/qiviproperty/tst_qiviproperty.cpp | 491 | ||||
-rw-r--r-- | tests/auto/core/qivipropertyattribute/qivipropertyattribute.pro | 13 | ||||
-rw-r--r-- | tests/auto/core/qivipropertyattribute/tst_qivipropertyattribute.cpp | 159 |
7 files changed, 0 insertions, 770 deletions
diff --git a/tests/auto/core/core.pro b/tests/auto/core/core.pro index 3f687ad..43c91c2 100644 --- a/tests/auto/core/core.pro +++ b/tests/auto/core/core.pro @@ -1,8 +1,6 @@ TEMPLATE = subdirs SUBDIRS = servicemanagertest \ - qivipropertyattribute \ - qiviproperty \ qiviabstractfeature \ qivipendingreply \ queryparser \ diff --git a/tests/auto/core/qiviproperty/qiviproperty.pro b/tests/auto/core/qiviproperty/qiviproperty.pro deleted file mode 100644 index 7105bda..0000000 --- a/tests/auto/core/qiviproperty/qiviproperty.pro +++ /dev/null @@ -1,13 +0,0 @@ -QT += testlib ivicore qml - -TARGET = tst_qiviproperty -QMAKE_PROJECT_NAME = $$TARGET -CONFIG += testcase - -TEMPLATE = app - -SOURCES += \ - tst_qiviproperty.cpp - -DEFINES += SRCDIR=\\\"$$PWD/\\\" -TESTDATA = testdata/* diff --git a/tests/auto/core/qiviproperty/testdata/readWrite.qml b/tests/auto/core/qiviproperty/testdata/readWrite.qml deleted file mode 100644 index 8f84162..0000000 --- a/tests/auto/core/qiviproperty/testdata/readWrite.qml +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 Luxoft Sweden AB -** Copyright (C) 2018 Pelagicore AG -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtIvi module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT-QTAS$ -** Commercial License Usage -** Licensees holding valid commercial Qt Automotive Suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import TestObject 1.0 - -Item { - - property int intProperty: testObject.intAttributeProperty.value - property int enumProperty: testObject.enumAttributeProperty.value - property var flagsProperty: testObject.flagsAttributeProperty.value - property var extendFlag: testObject.flagsAttributeProperty.value - property bool isFlag2Set: testObject.flagsAttributeProperty.value & TestObject.TestFlag_2 - property bool isFlag3Set: testObject.flagsAttributeProperty.value & TestObject.TestFlag_3 - - function updateValues() { - testObject.intAttributeProperty.value = 2.4 - testObject.enumAttributeProperty.value = TestObject.TestValue_2 - testObject.flagsAttributeProperty.value = TestObject.TestFlag_1 | TestObject.TestFlag_2 - extendFlag = testObject.flagsAttributeProperty.value | TestObject.TestFlag_3 - } -} diff --git a/tests/auto/core/qiviproperty/testdata/writeError.qml b/tests/auto/core/qiviproperty/testdata/writeError.qml deleted file mode 100644 index bf975c6..0000000 --- a/tests/auto/core/qiviproperty/testdata/writeError.qml +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 Luxoft Sweden AB -** Copyright (C) 2018 Pelagicore AG -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtIvi module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT-QTAS$ -** Commercial License Usage -** Licensees holding valid commercial Qt Automotive Suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Item { - - property int intProperty: testObject.intAttributeProperty.value - property int enumProperty: testObject.enumAttributeProperty.value - - function intTest() { - testObject.intAttributeProperty.value = "foo" - } - - function enumTest() { - testObject.enumAttributeProperty.value = 50 - } -} diff --git a/tests/auto/core/qiviproperty/tst_qiviproperty.cpp b/tests/auto/core/qiviproperty/tst_qiviproperty.cpp deleted file mode 100644 index 551bfc2..0000000 --- a/tests/auto/core/qiviproperty/tst_qiviproperty.cpp +++ /dev/null @@ -1,491 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 Luxoft Sweden AB -** Copyright (C) 2018 Pelagicore AG -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtIvi module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT-QTAS$ -** Commercial License Usage -** Licensees holding valid commercial Qt Automotive Suite 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$ -** -****************************************************************************/ - - -#include <QtTest> -#include <QQmlEngine> -#include <QQmlComponent> -#include <QQmlContext> -#include <qivipropertyattribute.h> -#include <qivipropertyfactory.h> - -#define QIVIPROPERTY(_type_, _name_) \ -Q_PROPERTY(QIviProperty* _name_##Property READ _name_##Property CONSTANT) \ -QIviProperty *m_##_name_##Property; \ -QIviPropertyAttribute<_type_> m_##_name_; \ -_type_ m_##_name_##Value; \ - \ -public: \ -QIviProperty *_name_##Property() const { return m_##_name_##Property; } \ -QIviPropertyAttribute<_type_> _name_() const { return m_##_name_; } \ -void set##_name_(QIviPropertyAttribute<_type_> attribute) { if (attribute == m_##_name_) return; m_##_name_ = attribute; emit _name_##Changed(attribute); } \ - \ -_type_ _name_##Value() const { return m_##_name_##Value; } \ -void set##_name_##Value(_type_ value) { if (value == m_##_name_##Value) return; m_##_name_##Value = value; emit _name_##ValueChanged(value); } \ - \ -Q_SIGNALS: \ -void _name_##ValueChanged(_type_ value); \ -void _name_##Changed(const QIviPropertyAttribute<_type_> _name_); \ -private: - -class TestObject : public QObject -{ - Q_OBJECT - -public: - enum TestEnum { - TestValue_1 = 1, - TestValue_2, - TestValue_3, - }; - Q_ENUM(TestEnum) - - enum TestFlag { - TestFlag_1 = 0x1, - TestFlag_2 = 0x2, - TestFlag_3 = 0x4, - }; - Q_DECLARE_FLAGS(TestFlags, TestFlag) - Q_FLAG(TestFlags) - - enum InvalidEnum { - InvalidValue_1 = 1, - InvalidValue_2, - InvalidValue_3, - }; - Q_ENUMS(InvalidEnum) - - QIVIPROPERTY(int, intAttribute) - QIVIPROPERTY(QString, readOnlyAttribute) - QIVIPROPERTY(TestObject::TestEnum, enumAttribute) - QIVIPROPERTY(TestObject::TestFlags, flagsAttribute) - -public: - TestObject(QObject *parent = nullptr) - : QObject(parent) - , m_intAttributeProperty(QIviPropertyFactory<int>::create(this, - &TestObject::intAttribute, - &TestObject::intAttributeChanged, - &TestObject::intAttributeValue, - &TestObject::intAttributeValueChanged, - &TestObject::setintAttributeValue)) - , m_intAttributeValue(-1) - , m_readOnlyAttributeProperty(QIviPropertyFactory<QString>::create(this, - &TestObject::readOnlyAttribute, - &TestObject::readOnlyAttributeChanged, - &TestObject::readOnlyAttributeValue, - &TestObject::readOnlyAttributeValueChanged)) - , m_enumAttributeProperty(QIviPropertyFactory<TestObject::TestEnum>::create(this, - &TestObject::enumAttribute, - &TestObject::enumAttributeChanged, - &TestObject::enumAttributeValue, - &TestObject::enumAttributeValueChanged, - &TestObject::setenumAttributeValue)) - , m_enumAttributeValue(TestObject::TestEnum()) - , m_flagsAttributeProperty(QIviPropertyFactory<TestObject::TestFlags>::create(this, - &TestObject::flagsAttribute, - &TestObject::flagsAttributeChanged, - &TestObject::flagsAttributeValue, - &TestObject::flagsAttributeValueChanged, - &TestObject::setflagsAttributeValue)) - , m_flagsAttributeValue(TestObject::TestFlags()) - {} -}; - -Q_DECLARE_METATYPE(TestObject::TestEnum) -Q_DECLARE_METATYPE(QIviPropertyAttribute<TestObject::TestEnum>) -Q_DECLARE_METATYPE(TestObject::TestFlags) -Q_DECLARE_METATYPE(QIviPropertyAttribute<TestObject::TestFlags>) -Q_DECLARE_OPERATORS_FOR_FLAGS(TestObject::TestFlags) -Q_DECLARE_METATYPE(QList<QQmlError>) - -class tst_QIviProperty : public QObject -{ - Q_OBJECT - -public: - tst_QIviProperty(); - -private Q_SLOTS: - void selfTest(); - void attribute_data(); - void attribute(); - void setGetValue(); - void setGetValue_flags(); - void setGetValue_qml(); - void setValueError_qml(); - void readOnly(); - void readOnly_qml(); - -private: - void initializeEnumAttribute(TestObject *testObject) - { - QSignalSpy propertyValueChangedSpy(testObject->enumAttributeProperty(), &QIviProperty::valueChanged); - QSignalSpy valueChangedSpy(testObject, &TestObject::enumAttributeValueChanged); - - //Initialize - testObject->setenumAttributeValue(TestObject::TestValue_3); - - QCOMPARE(propertyValueChangedSpy.count(), 1); - QCOMPARE(propertyValueChangedSpy.at(0).at(0), QVariant::fromValue<TestObject::TestEnum>(TestObject::TestValue_3)); - QCOMPARE(valueChangedSpy.count(), 1); - QCOMPARE(valueChangedSpy.at(0).at(0), QVariant::fromValue<TestObject::TestEnum>(TestObject::TestValue_3)); - } - - void initializeFlagsAttribute(TestObject *testObject) - { - QSignalSpy propertyValueChangedSpy(testObject->flagsAttributeProperty(), &QIviProperty::valueChanged); - QSignalSpy valueChangedSpy(testObject, &TestObject::flagsAttributeValueChanged); - - //Initialize - testObject->setflagsAttributeValue(TestObject::TestFlag_3); - - QCOMPARE(propertyValueChangedSpy.count(), 1); - QCOMPARE(propertyValueChangedSpy.at(0).at(0), QVariant::fromValue<TestObject::TestFlags>(TestObject::TestFlag_3)); - QCOMPARE(valueChangedSpy.count(), 1); - QCOMPARE(valueChangedSpy.at(0).at(0), QVariant::fromValue<TestObject::TestFlags>(TestObject::TestFlag_3)); - } - - void initializeIntAttribute(TestObject *testObject) - { - QSignalSpy propertyValueChangedSpy(testObject->intAttributeProperty(), &QIviProperty::valueChanged); - QSignalSpy valueChangedSpy(testObject, &TestObject::intAttributeValueChanged); - - //Initialize - testObject->setintAttributeValue(1); - - QCOMPARE(propertyValueChangedSpy.count(), 1); - QCOMPARE(propertyValueChangedSpy.at(0).at(0), QVariant(1)); - QCOMPARE(valueChangedSpy.count(), 1); - QCOMPARE(valueChangedSpy.at(0).at(0), QVariant(1)); - } -}; - -tst_QIviProperty::tst_QIviProperty() -{ - qRegisterMetaType<QIviPropertyAttribute<int>>(); - qRegisterMetaType<QIviPropertyAttribute<QString>>(); - qRegisterMetaType<TestObject::TestEnum>(); - qRegisterMetaType<QIviPropertyAttribute<TestObject::TestEnum>>(); - qRegisterMetaType<TestObject::TestFlags>(); - qRegisterMetaType<QIviPropertyAttribute<TestObject::TestFlags>>(); - qRegisterMetaType<QList<QQmlError>>(); -} - -void tst_QIviProperty::selfTest() -{ - TestObject *testObject = new TestObject(); - - QCOMPARE(testObject->intAttributeValue(), -1); - QCOMPARE(testObject->intAttribute().type(), QIviPropertyAttributeBase::Invalid); - QVERIFY(testObject->intAttributeProperty()); - - QCOMPARE(testObject->readOnlyAttributeValue(), QString()); - QCOMPARE(testObject->readOnlyAttribute().type(), QIviPropertyAttributeBase::Invalid); - QVERIFY(testObject->readOnlyAttributeProperty()); - - QCOMPARE(testObject->enumAttributeValue(), TestObject::TestEnum()); - QCOMPARE(testObject->enumAttribute().type(), QIviPropertyAttributeBase::Invalid); - QVERIFY(testObject->enumAttributeProperty()); - - QCOMPARE(testObject->flagsAttributeValue(), TestObject::TestFlags()); - QCOMPARE(testObject->flagsAttribute().type(), QIviPropertyAttributeBase::Invalid); - QVERIFY(testObject->flagsAttributeProperty()); -} - -void tst_QIviProperty::attribute_data() -{ - QTest::addColumn<QIviPropertyAttribute<int>>("attribute"); - QTest::addColumn<QVariantList>("exptectedList"); - QTest::newRow("noAttribute") << QIviPropertyAttribute<int>(true) << QVariantList(); - QTest::newRow("minimumMaximum") << QIviPropertyAttribute<int>(0,10) << QVariantList(); - QVector<int> avValues; - QVariantList avVariant; - avValues << 0 << 5 << 10; - avVariant << 0 << 5 << 10; - QTest::newRow("availableValues") << QIviPropertyAttribute<int>(avValues) << QVariantList(avVariant); -} - -void tst_QIviProperty::attribute() -{ - QFETCH(QIviPropertyAttribute<int>, attribute); - QFETCH(QVariantList, exptectedList); - - TestObject *testObject = new TestObject(); - - QSignalSpy maximumChangedSpy(testObject->intAttributeProperty(), &QIviProperty::maximumValueChanged); - QSignalSpy minimumChangedSpy(testObject->intAttributeProperty(), &QIviProperty::minimumValueChanged); - QSignalSpy availableValuesChangedSpy(testObject->intAttributeProperty(), &QIviProperty::availableValuesChanged); - QSignalSpy availableChangedSpy(testObject->intAttributeProperty(), &QIviProperty::availableChanged); - QSignalSpy noAttChangedSpy(testObject, &TestObject::intAttributeChanged); - - testObject->setintAttribute(attribute); - QVariant attributeVariant = QVariant::fromValue<QIviPropertyAttribute<int>>(attribute); - - QCOMPARE(maximumChangedSpy.count(), 1); - QCOMPARE(maximumChangedSpy.at(0).at(0), QVariant::fromValue<int>(attribute.maximumValue())); - QCOMPARE(minimumChangedSpy.count(), 1); - QCOMPARE(minimumChangedSpy.at(0).at(0), QVariant::fromValue<int>(attribute.minimumValue())); - QCOMPARE(availableValuesChangedSpy.count(), 1); - QCOMPARE(availableValuesChangedSpy.at(0).at(0), QVariant(exptectedList)); - QCOMPARE(availableChangedSpy.count(), 1); - QCOMPARE(availableChangedSpy.at(0).at(0), QVariant::fromValue<bool>(attribute.isAvailable())); - QCOMPARE(noAttChangedSpy.count(), 1); - QCOMPARE(noAttChangedSpy.at(0).at(0), attributeVariant); - QCOMPARE(testObject->intAttribute(), attribute); - QCOMPARE(testObject->intAttributeProperty()->isAvailable(), attribute.isAvailable()); - QCOMPARE(testObject->intAttributeProperty()->minimumValue(), QVariant::fromValue<int>(attribute.minimumValue())); - QCOMPARE(testObject->intAttributeProperty()->maximumValue(), QVariant::fromValue<int>(attribute.maximumValue())); - QCOMPARE(testObject->intAttributeProperty()->availableValues(), exptectedList); -} - -void tst_QIviProperty::setGetValue() -{ - TestObject *testObject = new TestObject(); - QSignalSpy propertyValueChangedSpy(testObject->enumAttributeProperty(), &QIviProperty::valueChanged); - QSignalSpy valueChangedSpy(testObject, &TestObject::enumAttributeValueChanged); - - //Initialize - testObject->setenumAttributeValue(TestObject::TestValue_3); - - QCOMPARE(propertyValueChangedSpy.count(), 1); - QCOMPARE(propertyValueChangedSpy.at(0).at(0), QVariant::fromValue<TestObject::TestEnum>(TestObject::TestValue_3)); - QCOMPARE(valueChangedSpy.count(), 1); - QCOMPARE(valueChangedSpy.at(0).at(0), QVariant::fromValue<TestObject::TestEnum>(TestObject::TestValue_3)); - - //Read value - QCOMPARE(testObject->enumAttributeValue(), TestObject::TestValue_3); - QCOMPARE(testObject->enumAttributeProperty()->value(), QVariant::fromValue<TestObject::TestEnum>(TestObject::TestValue_3)); - - propertyValueChangedSpy.clear(); - valueChangedSpy.clear(); - - //Set value - QVariant newValueVariant(TestObject::TestValue_2); - testObject->enumAttributeProperty()->setValue(newValueVariant); - - QCOMPARE(propertyValueChangedSpy.count(), 1); - QCOMPARE(propertyValueChangedSpy.at(0).at(0), newValueVariant); - QCOMPARE(valueChangedSpy.count(), 1); - QCOMPARE(valueChangedSpy.at(0).at(0), newValueVariant); - - //Read value - QCOMPARE(testObject->enumAttributeValue(), TestObject::TestValue_2); - QCOMPARE(testObject->enumAttributeProperty()->value(), newValueVariant); -} - -void tst_QIviProperty::setGetValue_flags() -{ - TestObject *testObject = new TestObject(); - QSignalSpy propertyValueChangedSpy(testObject->flagsAttributeProperty(), &QIviProperty::valueChanged); - QSignalSpy valueChangedSpy(testObject, &TestObject::flagsAttributeValueChanged); - - //Initialize - testObject->setflagsAttributeValue(TestObject::TestFlag_3); - - QCOMPARE(propertyValueChangedSpy.count(), 1); - QCOMPARE(propertyValueChangedSpy.at(0).at(0), QVariant::fromValue<TestObject::TestFlags>(TestObject::TestFlag_3)); - QCOMPARE(valueChangedSpy.count(), 1); - QCOMPARE(valueChangedSpy.at(0).at(0), QVariant::fromValue<TestObject::TestFlags>(TestObject::TestFlag_3)); - - //Read value - QCOMPARE(testObject->flagsAttributeValue(), TestObject::TestFlag_3); - QCOMPARE(testObject->flagsAttributeProperty()->value(), QVariant::fromValue<TestObject::TestFlags>(TestObject::TestFlag_3)); - - propertyValueChangedSpy.clear(); - valueChangedSpy.clear(); - - //Set value - QVariant newValueVariant = QVariant::fromValue(TestObject::TestFlags(TestObject::TestFlag_1 | TestObject::TestFlag_2)); - testObject->flagsAttributeProperty()->setValue(newValueVariant); - - QCOMPARE(propertyValueChangedSpy.count(), 1); - QCOMPARE(propertyValueChangedSpy.at(0).at(0), newValueVariant); - QCOMPARE(valueChangedSpy.count(), 1); - QCOMPARE(valueChangedSpy.at(0).at(0), newValueVariant); - - //Read value - QCOMPARE(testObject->flagsAttributeValue(), TestObject::TestFlag_1 | TestObject::TestFlag_2); - QCOMPARE(testObject->flagsAttributeProperty()->value(), newValueVariant); -} - -void tst_QIviProperty::setGetValue_qml() -{ - TestObject *testObject = new TestObject(); - - initializeEnumAttribute(testObject); - initializeFlagsAttribute(testObject); - initializeIntAttribute(testObject); - - QQmlEngine engine; - qmlRegisterType<TestObject>("TestObject", 1, 0, "TestObject"); - engine.rootContext()->setContextProperty(QStringLiteral("testObject"), testObject); - QQmlComponent component(&engine, QUrl::fromLocalFile(QFINDTESTDATA("testdata/readWrite.qml"))); - QObject *obj = component.create(); - - QVERIFY(obj); - QCOMPARE(obj->property("intProperty").toInt(), 1); - QCOMPARE(obj->property("enumProperty").toInt(), 3); - QCOMPARE(obj->property("flagsProperty").toInt(), 0x4); - QCOMPARE(obj->property("extendFlag").toInt(), 0x4); - QVERIFY(!obj->property("isFlag2Set").toBool()); - QVERIFY(obj->property("isFlag3Set").toBool()); - - QVERIFY(QMetaObject::invokeMethod(obj, "updateValues")); - QCOMPARE(obj->property("intProperty").toInt(), 2); - QCOMPARE(obj->property("enumProperty").toInt(), 2); - QCOMPARE(obj->property("flagsProperty").toInt(), int(TestObject::TestFlags(TestObject::TestFlag_1 | TestObject::TestFlag_2))); - QCOMPARE(obj->property("extendFlag").toInt(), int(TestObject::TestFlags(TestObject::TestFlag_1 | TestObject::TestFlag_2 | TestObject::TestFlag_3))); - QVERIFY(obj->property("isFlag2Set").toBool()); - QVERIFY(!obj->property("isFlag3Set").toBool()); -} - -void tst_QIviProperty::setValueError_qml() -{ - TestObject *testObject = new TestObject(); - - initializeEnumAttribute(testObject); - initializeIntAttribute(testObject); - - QQmlEngine engine; - engine.setOutputWarningsToStandardError(false); - engine.rootContext()->setContextProperty(QStringLiteral("testObject"), testObject); - QSignalSpy warningsSpy(&engine, &QQmlEngine::warnings); - QString testData = QFINDTESTDATA("testdata/writeError.qml"); - QQmlComponent component(&engine, QUrl::fromLocalFile(testData)); - QObject *obj = component.create(); - - QVERIFY(obj); - QVERIFY(QMetaObject::invokeMethod(obj, "enumTest")); - - if (!warningsSpy.count()) - QVERIFY(warningsSpy.wait()); - - QVERIFY(warningsSpy.count()); - QVERIFY(warningsSpy.at(0).count()); - QList<QQmlError> errorList = warningsSpy.at(0).at(0).value<QList<QQmlError>>(); - QCOMPARE(errorList.count(), 1); - QCOMPARE(errorList.at(0).toString(), QUrl::fromLocalFile(testData).toString() + ":42: Error: Enum value out of range"); - warningsSpy.clear(); - - QVERIFY(QMetaObject::invokeMethod(obj, "intTest")); - - if (!warningsSpy.count()) - QVERIFY(warningsSpy.wait()); - - QVERIFY(warningsSpy.count()); - QVERIFY(warningsSpy.at(0).count()); - errorList = warningsSpy.at(0).at(0).value<QList<QQmlError>>(); - QCOMPARE(errorList.count(), 1); - QCOMPARE(errorList.at(0).toString(), QUrl::fromLocalFile(testData).toString() + ":38: Error: Expected: int but got QString"); -} - -void tst_QIviProperty::readOnly() -{ - TestObject *testObject = new TestObject(); - QSignalSpy propertyValueChangedSpy(testObject->readOnlyAttributeProperty(), &QIviProperty::valueChanged); - QSignalSpy valueChangedSpy(testObject, &TestObject::readOnlyAttributeValueChanged); - - //Initialize - QString value = QString("foo"); - QVariant valueVariant = QVariant::fromValue<QString>(value); - testObject->setreadOnlyAttributeValue(value); - - QCOMPARE(propertyValueChangedSpy.count(), 1); - QCOMPARE(propertyValueChangedSpy.at(0).at(0), valueVariant); - QCOMPARE(valueChangedSpy.count(), 1); - QCOMPARE(valueChangedSpy.at(0).at(0), valueVariant); - - //Read value - QCOMPARE(testObject->readOnlyAttributeValue(), value); - QCOMPARE(testObject->readOnlyAttributeProperty()->value(), valueVariant); - - propertyValueChangedSpy.clear(); - valueChangedSpy.clear(); - - //Try to set the value - QString newValue = QString("bar"); - QVariant newValueVariant(newValue); - QTest::ignoreMessage(QtWarningMsg, "TypeError: Cannot assign to read-only property \"value\""); - testObject->readOnlyAttributeProperty()->setValue(newValueVariant); - - QCOMPARE(propertyValueChangedSpy.count(), 0); - QCOMPARE(valueChangedSpy.count(), 0); - - //Verify that the value is still the old - QCOMPARE(testObject->readOnlyAttributeValue(), value); - QCOMPARE(testObject->readOnlyAttributeProperty()->value(), valueVariant); -} - -void tst_QIviProperty::readOnly_qml() -{ - TestObject *testObject = new TestObject(); - QSignalSpy propertyValueChangedSpy(testObject->readOnlyAttributeProperty(), &QIviProperty::valueChanged); - QSignalSpy valueChangedSpy(testObject, &TestObject::readOnlyAttributeValueChanged); - - //Initialize - QString value = QString("foo"); - QVariant valueVariant = QVariant::fromValue<QString>(value); - testObject->setreadOnlyAttributeValue(value); - - QCOMPARE(propertyValueChangedSpy.count(), 1); - QCOMPARE(propertyValueChangedSpy.at(0).at(0), valueVariant); - QCOMPARE(valueChangedSpy.count(), 1); - QCOMPARE(valueChangedSpy.at(0).at(0), valueVariant); - - //Read value - QCOMPARE(testObject->readOnlyAttributeValue(), value); - QCOMPARE(testObject->readOnlyAttributeProperty()->value(), valueVariant); - - propertyValueChangedSpy.clear(); - valueChangedSpy.clear(); - - QQmlEngine engine; - engine.setOutputWarningsToStandardError(false); - QQmlComponent component(&engine); - QSignalSpy warningsSpy(&engine, &QQmlEngine::warnings); - engine.rootContext()->setContextProperty(QStringLiteral("testObject"), testObject); - component.setData("import QtQuick 2.0; Item { Component.onCompleted: testObject.readOnlyAttributeProperty.value = \"bar\"; }", QUrl()); - QObject *obj = component.create(); - - QVERIFY(obj); - if (!warningsSpy.count()) - QVERIFY(warningsSpy.wait()); - - QVERIFY(warningsSpy.count()); - QVERIFY(warningsSpy.at(0).count()); - QList<QQmlError> errorList = warningsSpy.at(0).at(0).value<QList<QQmlError>>(); - QCOMPARE(errorList.count(), 1); - QCOMPARE(errorList.at(0).toString(), QStringLiteral("<Unknown File>:1: Error: TypeError: Cannot assign to read-only property \"value\"")); -} - -QTEST_MAIN(tst_QIviProperty) - -#include "tst_qiviproperty.moc" - diff --git a/tests/auto/core/qivipropertyattribute/qivipropertyattribute.pro b/tests/auto/core/qivipropertyattribute/qivipropertyattribute.pro deleted file mode 100644 index 65a8033..0000000 --- a/tests/auto/core/qivipropertyattribute/qivipropertyattribute.pro +++ /dev/null @@ -1,13 +0,0 @@ -QT += testlib ivicore - -TARGET = tst_qivipropertyattribute -QMAKE_PROJECT_NAME = $$TARGET -CONFIG += testcase - -TEMPLATE = app - -SOURCES += \ - tst_qivipropertyattribute.cpp - -DEFINES += SRCDIR=\\\"$$PWD/\\\" - diff --git a/tests/auto/core/qivipropertyattribute/tst_qivipropertyattribute.cpp b/tests/auto/core/qivipropertyattribute/tst_qivipropertyattribute.cpp deleted file mode 100644 index a73c6f3..0000000 --- a/tests/auto/core/qivipropertyattribute/tst_qivipropertyattribute.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 Luxoft Sweden AB -** Copyright (C) 2018 Pelagicore AG -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtIvi module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT-QTAS$ -** Commercial License Usage -** Licensees holding valid commercial Qt Automotive Suite 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$ -** -****************************************************************************/ - - -#include <QtTest> -#include <qivipropertyattribute.h> - -struct ComplexType -{ - ComplexType(bool b = false, const QString &string = QString()) - : m_bool(b) - , m_string(string) - {} - - bool operator==(const ComplexType &other) const - { - return (m_bool == other.m_bool && - m_string == other.m_string); - } - - bool m_bool; - QString m_string; -}; -Q_DECLARE_METATYPE(ComplexType) -Q_DECLARE_METATYPE(QIviPropertyAttribute<ComplexType>) - -class tst_QIviPropertyAttribute : public QObject -{ - Q_OBJECT - -public: - tst_QIviPropertyAttribute(); - -private Q_SLOTS: - void equal(); - void simple(); - void complex(); -}; - -tst_QIviPropertyAttribute::tst_QIviPropertyAttribute() -{ - qRegisterMetaType<ComplexType>(); -} - -void tst_QIviPropertyAttribute::equal() -{ - QIviPropertyAttribute<int> minMax(5, 10); - QIviPropertyAttribute<int> minMax2(5, 10); - QCOMPARE(minMax, minMax2); - - QIviPropertyAttribute<int> noAtt(false); - QIviPropertyAttribute<int> noAtt2(false); - QCOMPARE(noAtt, noAtt2); - - QVector<int> list; - list << 0 << 5 << 10 << 50; - QIviPropertyAttribute<int> avVal(list); - QIviPropertyAttribute<int> avVal2(list); - QCOMPARE(avVal, avVal2); -} - -void tst_QIviPropertyAttribute::simple() -{ - QIviPropertyAttribute<int> invalid; - QCOMPARE(invalid.type(), QIviPropertyAttributeBase::Invalid); - QCOMPARE(invalid.isAvailable(), false); - QCOMPARE(invalid.minimumValue(), int()); - QCOMPARE(invalid.maximumValue(), int()); - QCOMPARE(invalid.availableValues(), QVector<int>()); - - QIviPropertyAttribute<int> noAttribute(true); - QCOMPARE(noAttribute.type(), QIviPropertyAttributeBase::NoAttributes); - QCOMPARE(noAttribute.isAvailable(), true); - QCOMPARE(noAttribute.minimumValue(), int()); - QCOMPARE(noAttribute.maximumValue(), int()); - QCOMPARE(noAttribute.availableValues(), QVector<int>()); - - QIviPropertyAttribute<int> minimumMaximum(5, 10); - QCOMPARE(minimumMaximum.type(), QIviPropertyAttributeBase::MinimumMaximum); - QCOMPARE(minimumMaximum.isAvailable(), true); - QCOMPARE(minimumMaximum.minimumValue(), 5); - QCOMPARE(minimumMaximum.maximumValue(), 10); - QCOMPARE(minimumMaximum.availableValues(), QVector<int>()); - - QVector<int> list; - list << 0 << 5 << 10 << 50; - QIviPropertyAttribute<int> availableValues(list); - QCOMPARE(availableValues.type(), QIviPropertyAttributeBase::AvailableValues); - QCOMPARE(availableValues.isAvailable(), true); - QCOMPARE(availableValues.minimumValue(), int()); - QCOMPARE(availableValues.maximumValue(), int()); - QCOMPARE(availableValues.availableValues(), list); -} - -void tst_QIviPropertyAttribute::complex() -{ - QIviPropertyAttribute<ComplexType> invalid; - QCOMPARE(invalid.type(), QIviPropertyAttributeBase::Invalid); - QCOMPARE(invalid.isAvailable(), false); - QCOMPARE(invalid.minimumValue(), ComplexType()); - QCOMPARE(invalid.maximumValue(), ComplexType()); - QCOMPARE(invalid.availableValues(), QVector<ComplexType>()); - - QIviPropertyAttribute<ComplexType> noAttribute(true); - QCOMPARE(noAttribute.type(), QIviPropertyAttributeBase::NoAttributes); - QCOMPARE(noAttribute.isAvailable(), true); - QCOMPARE(noAttribute.minimumValue(), ComplexType()); - QCOMPARE(noAttribute.maximumValue(), ComplexType()); - QCOMPARE(noAttribute.availableValues(), QVector<ComplexType>()); - - ComplexType min(false, QStringLiteral("min")); - ComplexType max(true, QStringLiteral("max")); - QIviPropertyAttribute<ComplexType> minimumMaximum(min, max); - QCOMPARE(minimumMaximum.type(), QIviPropertyAttributeBase::MinimumMaximum); - QCOMPARE(minimumMaximum.isAvailable(), true); - QCOMPARE(minimumMaximum.minimumValue(), min); - QCOMPARE(minimumMaximum.maximumValue(), max); - QCOMPARE(minimumMaximum.availableValues(), QVector<ComplexType>()); - - QVector<ComplexType> list; - list << ComplexType(false, "1") << ComplexType(true, "2") << ComplexType(true, "3") << ComplexType(false, "4"); - QIviPropertyAttribute<ComplexType> availableValues(list); - QCOMPARE(availableValues.type(), QIviPropertyAttributeBase::AvailableValues); - QCOMPARE(availableValues.isAvailable(), true); - QCOMPARE(availableValues.minimumValue(), ComplexType()); - QCOMPARE(availableValues.maximumValue(), ComplexType()); - QCOMPARE(availableValues.availableValues(), list); -} - -QTEST_APPLESS_MAIN(tst_QIviPropertyAttribute) - -#include "tst_qivipropertyattribute.moc" - |