diff options
Diffstat (limited to 'tests/auto')
26 files changed, 657 insertions, 36 deletions
diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt index 64996503eb..480f986830 100644 --- a/tests/auto/CMakeLists.txt +++ b/tests/auto/CMakeLists.txt @@ -31,7 +31,7 @@ endif() # special case begin # Build only corelib and gui tests when targeting uikit (iOS), # because the script can't handle the SUBDIRS assignment well. -if (APPLE_UIKIT) +if (UIKIT) return() endif() # special case end diff --git a/tests/auto/corelib/.prev_CMakeLists.txt b/tests/auto/corelib/.prev_CMakeLists.txt index 1029b14654..2019a771c0 100644 --- a/tests/auto/corelib/.prev_CMakeLists.txt +++ b/tests/auto/corelib/.prev_CMakeLists.txt @@ -1,7 +1,7 @@ # Generated from corelib.pro. add_subdirectory(kernel) -if(NOT APPLE_UIKIT) +if(NOT UIKIT) add_subdirectory(animation) add_subdirectory(codecs) add_subdirectory(global) diff --git a/tests/auto/corelib/CMakeLists.txt b/tests/auto/corelib/CMakeLists.txt index 1029b14654..2019a771c0 100644 --- a/tests/auto/corelib/CMakeLists.txt +++ b/tests/auto/corelib/CMakeLists.txt @@ -1,7 +1,7 @@ # Generated from corelib.pro. add_subdirectory(kernel) -if(NOT APPLE_UIKIT) +if(NOT UIKIT) add_subdirectory(animation) add_subdirectory(codecs) add_subdirectory(global) diff --git a/tests/auto/corelib/io/qdir/CMakeLists.txt b/tests/auto/corelib/io/qdir/CMakeLists.txt index 84136283c1..f77185bc2b 100644 --- a/tests/auto/corelib/io/qdir/CMakeLists.txt +++ b/tests/auto/corelib/io/qdir/CMakeLists.txt @@ -37,7 +37,7 @@ add_qt_resource(tst_qdir "qdir" ## Scopes: ##################################################################### -#### Keys ignored in scope 2:.:.:qdir.pro:APPLE_IOS: +#### Keys ignored in scope 2:.:.:qdir.pro:IOS: # QMAKE_INFO_PLIST = "Info.plist" extend_target(tst_qdir CONDITION CONFIG___contains___builtin_testdata diff --git a/tests/auto/corelib/kernel/.prev_CMakeLists.txt b/tests/auto/corelib/kernel/.prev_CMakeLists.txt index 5415a23a98..515720e282 100644 --- a/tests/auto/corelib/kernel/.prev_CMakeLists.txt +++ b/tests/auto/corelib/kernel/.prev_CMakeLists.txt @@ -17,11 +17,11 @@ add_subdirectory(qmetaenum) if(TARGET Qt::Gui) add_subdirectory(qmimedata) endif() -if(TARGET Qt::Network AND NOT ANDROID AND NOT APPLE_UIKIT) +if(TARGET Qt::Network AND NOT ANDROID AND NOT UIKIT) add_subdirectory(qobject) endif() add_subdirectory(qpointer) -if(QT_FEATURE_private_tests AND NOT ANDROID AND NOT APPLE_UIKIT) +if(QT_FEATURE_private_tests AND NOT ANDROID AND NOT UIKIT) add_subdirectory(qsharedmemory) endif() add_subdirectory(qsignalblocker) @@ -29,7 +29,7 @@ add_subdirectory(qsignalmapper) if(QT_FEATURE_private_tests AND TARGET Qt::Network) add_subdirectory(qsocketnotifier) endif() -if(QT_FEATURE_systemsemaphore AND NOT ANDROID AND NOT APPLE_UIKIT) +if(QT_FEATURE_systemsemaphore AND NOT ANDROID AND NOT UIKIT) add_subdirectory(qsystemsemaphore) endif() add_subdirectory(qtimer) diff --git a/tests/auto/corelib/kernel/CMakeLists.txt b/tests/auto/corelib/kernel/CMakeLists.txt index 9fbe2b8b7a..c72018db6c 100644 --- a/tests/auto/corelib/kernel/CMakeLists.txt +++ b/tests/auto/corelib/kernel/CMakeLists.txt @@ -17,11 +17,11 @@ add_subdirectory(qmetaenum) if(TARGET Qt::Gui) add_subdirectory(qmimedata) endif() -if(TARGET Qt::Network AND NOT ANDROID AND NOT APPLE_UIKIT) +if(TARGET Qt::Network AND NOT ANDROID AND NOT UIKIT) # add_subdirectory(qobject) # special case endif() add_subdirectory(qpointer) -if(QT_FEATURE_private_tests AND NOT ANDROID AND NOT APPLE_UIKIT) +if(QT_FEATURE_private_tests AND NOT ANDROID AND NOT UIKIT) add_subdirectory(qsharedmemory) endif() add_subdirectory(qsignalblocker) @@ -29,7 +29,7 @@ add_subdirectory(qsignalmapper) if(QT_FEATURE_private_tests AND TARGET Qt::Network) add_subdirectory(qsocketnotifier) endif() -if(QT_FEATURE_systemsemaphore AND NOT ANDROID AND NOT APPLE_UIKIT) +if(QT_FEATURE_systemsemaphore AND NOT ANDROID AND NOT UIKIT) add_subdirectory(qsystemsemaphore) endif() # add_subdirectory(qtimer) # special case diff --git a/tests/auto/corelib/kernel/kernel.pro b/tests/auto/corelib/kernel/kernel.pro index 09074a9e8a..26cc00ea40 100644 --- a/tests/auto/corelib/kernel/kernel.pro +++ b/tests/auto/corelib/kernel/kernel.pro @@ -23,7 +23,8 @@ SUBDIRS=\ qtimer \ qtranslator \ qvariant \ - qwineventnotifier + qwineventnotifier \ + qproperty !qtHaveModule(gui): SUBDIRS -= \ qmimedata @@ -35,7 +36,8 @@ SUBDIRS=\ !qtConfig(private_tests): SUBDIRS -= \ qsocketnotifier \ - qsharedmemory + qsharedmemory \ + qproperty # This test is only applicable on Windows !win32*|winrt: SUBDIRS -= qwineventnotifier diff --git a/tests/auto/corelib/kernel/qproperty/qproperty.pro b/tests/auto/corelib/kernel/qproperty/qproperty.pro new file mode 100644 index 0000000000..bae67e70a4 --- /dev/null +++ b/tests/auto/corelib/kernel/qproperty/qproperty.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qproperty +QT = core core-private testlib +SOURCES = tst_qproperty.cpp diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp new file mode 100644 index 0000000000..7f64072df6 --- /dev/null +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -0,0 +1,615 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $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$ +** +****************************************************************************/ + +#include <QObject> +#include <qtest.h> +#include <qproperty.h> +#include <private/qproperty_p.h> +#include <private/qpropertybinding_p.h> + +using namespace QtPrivate; + +class tst_QProperty : public QObject +{ + Q_OBJECT +private slots: + void functorBinding(); + void basicDependencies(); + void multipleDependencies(); + void bindingWithDeletedDependency(); + void recursiveDependency(); + void bindingAfterUse(); + void switchBinding(); + void avoidDependencyAllocationAfterFirstEval(); + void propertyArrays(); + void boolProperty(); + void takeBinding(); + void replaceBinding(); + void swap(); + void moveNotifies(); + void moveCtor(); + void changeHandler(); + void propertyChangeHandlerApi(); + void subscribe(); + void changeHandlerThroughBindings(); + void dontTriggerDependenciesIfUnchangedValue(); + void bindingSourceLocation(); + void bindingError(); + void bindingLoop(); + void changePropertyFromWithinChangeHandler(); + void changePropertyFromWithinChangeHandlerThroughDependency(); + void changePropertyFromWithinChangeHandler2(); + void settingPropertyValueDoesRemoveBinding(); +}; + +void tst_QProperty::functorBinding() +{ + QProperty<int> property([]() { return 42; }); + QCOMPARE(property.value(), int(42)); + property = Qt::makePropertyBinding([]() { return 100; }); + QCOMPARE(property.value(), int(100)); + property.setBinding([]() { return 50; }); + QCOMPARE(property.value(), int(50)); +} + +void tst_QProperty::basicDependencies() +{ + QProperty<int> right(100); + + QProperty<int> left = Qt::makePropertyBinding(right); + + QCOMPARE(left.value(), int(100)); + + right = 42; + + QCOMPARE(left.value(), int(42)); +} + +void tst_QProperty::multipleDependencies() +{ + QProperty<int> firstDependency(1); + QProperty<int> secondDependency(2); + + QProperty<int> sum; + sum = Qt::makePropertyBinding([&]() { return firstDependency + secondDependency; }); + + QCOMPARE(QPropertyBasePointer::get(firstDependency).observerCount(), 0); + QCOMPARE(QPropertyBasePointer::get(secondDependency).observerCount(), 0); + + QCOMPARE(sum.value(), int(3)); + QCOMPARE(QPropertyBasePointer::get(firstDependency).observerCount(), 1); + QCOMPARE(QPropertyBasePointer::get(secondDependency).observerCount(), 1); + + firstDependency = 10; + + QCOMPARE(sum.value(), int(12)); + QCOMPARE(QPropertyBasePointer::get(firstDependency).observerCount(), 1); + QCOMPARE(QPropertyBasePointer::get(secondDependency).observerCount(), 1); + + secondDependency = 20; + + QCOMPARE(sum.value(), int(30)); + QCOMPARE(QPropertyBasePointer::get(firstDependency).observerCount(), 1); + QCOMPARE(QPropertyBasePointer::get(secondDependency).observerCount(), 1); + + firstDependency = 1; + secondDependency = 1; + QCOMPARE(sum.value(), int(2)); + QCOMPARE(QPropertyBasePointer::get(firstDependency).observerCount(), 1); + QCOMPARE(QPropertyBasePointer::get(secondDependency).observerCount(), 1); +} + +void tst_QProperty::bindingWithDeletedDependency() +{ + QScopedPointer<QProperty<int>> dynamicProperty(new QProperty<int>(100)); + + QProperty<int> staticProperty(1000); + + QProperty<bool> bindingReturnsDynamicProperty(false); + + QProperty<int> propertySelector; + propertySelector = Qt::makePropertyBinding([&]() { + if (bindingReturnsDynamicProperty && !dynamicProperty.isNull()) + return dynamicProperty->value(); + else + return staticProperty.value(); + }); + + QCOMPARE(propertySelector.value(), staticProperty.value()); + + bindingReturnsDynamicProperty = true; + + QCOMPARE(propertySelector.value(), dynamicProperty->value()); + + dynamicProperty.reset(); + + QCOMPARE(propertySelector.value(), 100); + + bindingReturnsDynamicProperty = false; + + QCOMPARE(propertySelector.value(), staticProperty.value()); +} + +void tst_QProperty::recursiveDependency() +{ + QProperty<int> first(1); + + QProperty<int> second; + second = Qt::makePropertyBinding(first); + + QProperty<int> third; + third = Qt::makePropertyBinding(second); + + QCOMPARE(third.value(), int(1)); + + first = 2; + + QCOMPARE(third.value(), int(2)); +} + +void tst_QProperty::bindingAfterUse() +{ + QProperty<int> propWithBindingLater(1); + + QProperty<int> propThatUsesFirstProp; + propThatUsesFirstProp = Qt::makePropertyBinding(propWithBindingLater); + + QCOMPARE(propThatUsesFirstProp.value(), int(1)); + QCOMPARE(QPropertyBasePointer::get(propWithBindingLater).observerCount(), 1); + + QProperty<int> injectedValue(42); + propWithBindingLater = Qt::makePropertyBinding(injectedValue); + + QCOMPARE(propThatUsesFirstProp.value(), int(42)); + QCOMPARE(QPropertyBasePointer::get(propWithBindingLater).observerCount(), 1); +} + +void tst_QProperty::switchBinding() +{ + QProperty<int> first(1); + + QProperty<int> propWithChangingBinding; + propWithChangingBinding = Qt::makePropertyBinding(first); + + QCOMPARE(propWithChangingBinding.value(), 1); + + QProperty<int> output; + output = Qt::makePropertyBinding(propWithChangingBinding); + QCOMPARE(output.value(), 1); + + QProperty<int> second(2); + propWithChangingBinding = Qt::makePropertyBinding(second); + QCOMPARE(output.value(), 2); +} + +void tst_QProperty::avoidDependencyAllocationAfterFirstEval() +{ + QProperty<int> firstDependency(1); + QProperty<int> secondDependency(10); + + QProperty<int> propWithBinding; + propWithBinding = Qt::makePropertyBinding([&]() { return firstDependency + secondDependency; }); + + QCOMPARE(propWithBinding.value(), int(11)); + + QVERIFY(QPropertyBasePointer::get(propWithBinding).bindingPtr()); + QCOMPARE(QPropertyBasePointer::get(propWithBinding).bindingPtr()->dependencyObservers.size(), 2); + QVERIFY(QPropertyBasePointer::get(propWithBinding).bindingPtr()->dependencyObservers.capacity() >= 2); + + firstDependency = 100; + QCOMPARE(propWithBinding.value(), int(110)); + QCOMPARE(QPropertyBasePointer::get(propWithBinding).bindingPtr()->dependencyObservers.size(), 2); + QVERIFY(QPropertyBasePointer::get(propWithBinding).bindingPtr()->dependencyObservers.capacity() >= 2); +} + +void tst_QProperty::propertyArrays() +{ + std::vector<QProperty<int>> properties; + + int expectedSum = 0; + for (int i = 0; i < 10; ++i) { + properties.emplace_back(i); + expectedSum += i; + } + + QProperty<int> sum; + sum = Qt::makePropertyBinding([&]() { + return std::accumulate(properties.begin(), properties.end(), 0); + }); + + QCOMPARE(sum.value(), expectedSum); + + properties[4] = properties[4] + 42; + expectedSum += 42; + QCOMPARE(sum.value(), expectedSum); +} + +void tst_QProperty::boolProperty() +{ + static_assert(sizeof(QProperty<bool>) == sizeof(void*), "Size of QProperty<bool> specialization must not exceed size of pointer"); + + QProperty<bool> first(true); + QProperty<bool> second(false); + QProperty<bool> all; + all = Qt::makePropertyBinding([&]() { return first && second; }); + + QCOMPARE(all.value(), false); + + second = true; + + QCOMPARE(all.value(), true); +} + +void tst_QProperty::takeBinding() +{ + QPropertyBinding<int> existingBinding; + QVERIFY(existingBinding.isNull()); + + QProperty<int> first(100); + QProperty<int> second = Qt::makePropertyBinding(first); + + QCOMPARE(second.value(), int(100)); + + existingBinding = second.takeBinding(); + QVERIFY(!existingBinding.isNull()); + + first = 10; + QCOMPARE(second.value(), int(100)); + + second = 25; + QCOMPARE(second.value(), int(25)); + + second = existingBinding; + QCOMPARE(second.value(), int(10)); + QVERIFY(!existingBinding.isNull()); +} + +void tst_QProperty::replaceBinding() +{ + QProperty<int> first(100); + QProperty<int> second = Qt::makePropertyBinding(first); + + QCOMPARE(second.value(), 100); + + auto constantBinding = Qt::makePropertyBinding([]() { return 42; }); + auto oldBinding = second.setBinding(constantBinding); + QCOMPARE(second.value(), 42); + + second = oldBinding; + QCOMPARE(second.value(), 100); +} + +void tst_QProperty::swap() +{ + QProperty<int> firstDependency(1); + QProperty<int> secondDependency(2); + + QProperty<int> first = Qt::makePropertyBinding(firstDependency); + QProperty<int> second = Qt::makePropertyBinding(secondDependency); + + QCOMPARE(first.value(), 1); + QCOMPARE(second.value(), 2); + + std::swap(first, second); + + QCOMPARE(first.value(), 2); + QCOMPARE(second.value(), 1); + + secondDependency = 20; + QCOMPARE(first.value(), 20); + QCOMPARE(second.value(), 1); + + firstDependency = 100; + QCOMPARE(first.value(), 20); + QCOMPARE(second.value(), 100); +} + +void tst_QProperty::moveNotifies() +{ + QProperty<int> first(1); + QProperty<int> second(2); + + QProperty<int> propertyInTheMiddle = Qt::makePropertyBinding(first); + + QProperty<int> finalProp1 = Qt::makePropertyBinding(propertyInTheMiddle); + QProperty<int> finalProp2 = Qt::makePropertyBinding(propertyInTheMiddle); + + QCOMPARE(finalProp1.value(), 1); + QCOMPARE(finalProp2.value(), 1); + + QCOMPARE(QPropertyBasePointer::get(propertyInTheMiddle).observerCount(), 2); + + QProperty<int> other = Qt::makePropertyBinding(second); + QCOMPARE(other.value(), 2); + + QProperty<int> otherDep = Qt::makePropertyBinding(other); + QCOMPARE(otherDep.value(), 2); + QCOMPARE(QPropertyBasePointer::get(other).observerCount(), 1); + + propertyInTheMiddle = std::move(other); + + QCOMPARE(QPropertyBasePointer::get(other).observerCount(), 0); + + QCOMPARE(finalProp1.value(), 2); + QCOMPARE(finalProp2.value(), 2); +} + +void tst_QProperty::moveCtor() +{ + QProperty<int> first(1); + + QProperty<int> intermediate = Qt::makePropertyBinding(first); + QCOMPARE(intermediate.value(), 1); + QCOMPARE(QPropertyBasePointer::get(first).observerCount(), 1); + + QProperty<int> targetProp(std::move(first)); + + QCOMPARE(QPropertyBasePointer::get(targetProp).observerCount(), 0); +} + +void tst_QProperty::changeHandler() +{ + QProperty<int> testProperty(0); + QVector<int> recordedValues; + + { + auto handler = testProperty.onValueChanged([&]() { + recordedValues << testProperty; + }); + + testProperty = 1; + testProperty = 2; + } + testProperty = 3; + + QCOMPARE(recordedValues.count(), 2); + QCOMPARE(recordedValues.at(0), 1); + QCOMPARE(recordedValues.at(1), 2); +} + +void tst_QProperty::propertyChangeHandlerApi() +{ + int changeHandlerCallCount = 0; + QPropertyChangeHandler handler([&changeHandlerCallCount]() { + ++changeHandlerCallCount; + }); + + QProperty<int> source1; + QProperty<int> source2; + + handler.setSource(source1); + + source1 = 100; + QCOMPARE(changeHandlerCallCount, 1); + + handler.setSource(source2); + source1 = 101; + QCOMPARE(changeHandlerCallCount, 1); + + source2 = 200; + QCOMPARE(changeHandlerCallCount, 2); +} + +void tst_QProperty::subscribe() +{ + QProperty<int> testProperty(42); + QVector<int> recordedValues; + + { + auto handler = testProperty.subscribe([&]() { + recordedValues << testProperty; + }); + + testProperty = 1; + testProperty = 2; + } + testProperty = 3; + + QCOMPARE(recordedValues.count(), 3); + QCOMPARE(recordedValues.at(0), 42); + QCOMPARE(recordedValues.at(1), 1); + QCOMPARE(recordedValues.at(2), 2); +} + +void tst_QProperty::changeHandlerThroughBindings() +{ + QProperty<bool> trigger(false); + QProperty<bool> blockTrigger(false); + QProperty<bool> condition = Qt::makePropertyBinding([&]() { + bool triggerValue = trigger; + bool blockTriggerValue = blockTrigger; + return triggerValue && !blockTriggerValue; + }); + bool changeHandlerCalled = false; + auto handler = condition.onValueChanged([&]() { + changeHandlerCalled = true; + }); + + QVERIFY(!condition); + QVERIFY(!changeHandlerCalled); + + trigger = true; + + QVERIFY(condition); + QVERIFY(changeHandlerCalled); + changeHandlerCalled = false; + + trigger = false; + + QVERIFY(!condition); + QVERIFY(changeHandlerCalled); + changeHandlerCalled = false; + + blockTrigger = true; + + QVERIFY(!condition); + QVERIFY(!changeHandlerCalled); +} + +void tst_QProperty::dontTriggerDependenciesIfUnchangedValue() +{ + QProperty<int> property(42); + + bool triggered = false; + QProperty<int> observer = Qt::makePropertyBinding([&]() { triggered = true; return property.value(); }); + + QCOMPARE(observer.value(), 42); + QVERIFY(triggered); + triggered = false; + property = 42; + QCOMPARE(observer.value(), 42); + QVERIFY(!triggered); +} + +void tst_QProperty::bindingSourceLocation() +{ +#if defined(QT_PROPERTY_COLLECT_BINDING_LOCATION) + auto bindingLine = std::experimental::source_location::current().line() + 1; + auto binding = Qt::makePropertyBinding([]() { return 42; }); + QCOMPARE(QPropertyBindingPrivate::get(binding)->location.line, bindingLine); +#else + QSKIP("Skipping this in the light of missing binding source location support"); +#endif +} + +void tst_QProperty::bindingError() +{ + QProperty<int> prop = Qt::makePropertyBinding([]() -> std::variant<int, QPropertyBindingError> { + QPropertyBindingError error(QPropertyBindingError::UnknownError); + error.setDescription(QLatin1String("my error")); + return error; + }); + QCOMPARE(prop.value(), 0); + QCOMPARE(prop.binding().error().description(), QString("my error")); +} + +void tst_QProperty::bindingLoop() +{ + QScopedPointer<QProperty<int>> firstProp; + + QProperty<int> secondProp = Qt::makePropertyBinding([&]() -> int { + return firstProp ? firstProp->value() : 0; + }); + + QProperty<int> thirdProp = Qt::makePropertyBinding([&]() -> int { + return secondProp.value(); + }); + + firstProp.reset(new QProperty<int>()); + *firstProp = Qt::makePropertyBinding([&]() -> int { + return secondProp.value(); + }); + + QCOMPARE(thirdProp.value(), 0); + QCOMPARE(secondProp.binding().error().type(), QPropertyBindingError::BindingLoop); +} + +void tst_QProperty::changePropertyFromWithinChangeHandler() +{ + QProperty<int> property(100); + bool resetPropertyOnChange = false; + int changeHandlerCallCount = 0; + + auto handler = property.onValueChanged([&]() { + ++changeHandlerCallCount; + if (resetPropertyOnChange) + property = 100; + }); + + QCOMPARE(property.value(), 100); + + resetPropertyOnChange = true; + property = 42; + QCOMPARE(property.value(), 100); + // changing the property value inside the change handler won't result in the change + // handler being called again. + QCOMPARE(changeHandlerCallCount, 1); + changeHandlerCallCount = 0; +} + +void tst_QProperty::changePropertyFromWithinChangeHandlerThroughDependency() +{ + QProperty<int> sourceProperty(100); + QProperty<int> property = Qt::makePropertyBinding(sourceProperty); + bool resetPropertyOnChange = false; + int changeHandlerCallCount = 0; + + auto handler = property.onValueChanged([&]() { + ++changeHandlerCallCount; + if (resetPropertyOnChange) + sourceProperty = 100; + }); + + QCOMPARE(property.value(), 100); + + resetPropertyOnChange = true; + sourceProperty = 42; + QCOMPARE(property.value(), 100); + // changing the property value inside the change handler won't result in the change + // handler being called again. + QCOMPARE(changeHandlerCallCount, 1); + changeHandlerCallCount = 0; +} + +void tst_QProperty::changePropertyFromWithinChangeHandler2() +{ + QProperty<int> property(100); + int changeHandlerCallCount = 0; + + auto handler = property.onValueChanged([&]() { + ++changeHandlerCallCount; + property = property.value() + 1; + }); + + QCOMPARE(property.value(), 100); + + property = 42; + QCOMPARE(property.value(), 43); +} + +void tst_QProperty::settingPropertyValueDoesRemoveBinding() +{ + QProperty<int> source(42); + + QProperty<int> property = Qt::makePropertyBinding(source); + + QCOMPARE(property.value(), 42); + QVERIFY(!property.binding().isNull()); + + property = 100; + QCOMPARE(property.value(), 100); + QVERIFY(property.binding().isNull()); + + source = 1; + QCOMPARE(property.value(), 100); + QVERIFY(property.binding().isNull()); +} + +QTEST_MAIN(tst_QProperty); + +#include "tst_qproperty.moc" diff --git a/tests/auto/corelib/plugin/qpluginloader/CMakeLists.txt b/tests/auto/corelib/plugin/qpluginloader/CMakeLists.txt index ba7d375e3b..a051bb3ea6 100644 --- a/tests/auto/corelib/plugin/qpluginloader/CMakeLists.txt +++ b/tests/auto/corelib/plugin/qpluginloader/CMakeLists.txt @@ -7,6 +7,6 @@ add_subdirectory(tst) if(UNIX AND NOT ANDROID AND NOT APPLE) add_subdirectory(almostplugin) endif() -if(APPLE_OSX AND QT_FEATURE_private_tests AND TARGET Qt::Gui) +if(MACOS AND QT_FEATURE_private_tests AND TARGET Qt::Gui) add_subdirectory(machtest) endif() diff --git a/tests/auto/gui/.prev_CMakeLists.txt b/tests/auto/gui/.prev_CMakeLists.txt index 8cbfa78aad..e7317e932c 100644 --- a/tests/auto/gui/.prev_CMakeLists.txt +++ b/tests/auto/gui/.prev_CMakeLists.txt @@ -1,7 +1,7 @@ # Generated from gui.pro. add_subdirectory(kernel) -if(NOT APPLE_UIKIT) +if(NOT UIKIT) add_subdirectory(image) add_subdirectory(math3d) add_subdirectory(painting) @@ -10,10 +10,10 @@ if(NOT APPLE_UIKIT) add_subdirectory(itemmodels) add_subdirectory(rhi) endif() -if(QT_FEATURE_opengl AND NOT APPLE_UIKIT AND NOT WINRT) +if(QT_FEATURE_opengl AND NOT UIKIT AND NOT WINRT) add_subdirectory(qopenglconfig) add_subdirectory(qopengl) endif() -if(QT_FEATURE_vulkan AND NOT APPLE_UIKIT) +if(QT_FEATURE_vulkan AND NOT UIKIT) add_subdirectory(qvulkan) endif() diff --git a/tests/auto/gui/CMakeLists.txt b/tests/auto/gui/CMakeLists.txt index 9a1312bd48..e9c9ffe9fe 100644 --- a/tests/auto/gui/CMakeLists.txt +++ b/tests/auto/gui/CMakeLists.txt @@ -1,7 +1,7 @@ # Generated from gui.pro. add_subdirectory(kernel) -if(NOT APPLE_UIKIT) +if(NOT UIKIT) add_subdirectory(image) add_subdirectory(math3d) add_subdirectory(painting) @@ -10,10 +10,10 @@ if(NOT APPLE_UIKIT) add_subdirectory(itemmodels) add_subdirectory(rhi) endif() -if(QT_FEATURE_opengl AND NOT APPLE_UIKIT AND NOT WINRT) +if(QT_FEATURE_opengl AND NOT UIKIT AND NOT WINRT) add_subdirectory(qopenglconfig) add_subdirectory(qopengl) endif() -if(QT_FEATURE_vulkan AND NOT APPLE_UIKIT) +if(QT_FEATURE_vulkan AND NOT UIKIT) add_subdirectory(qvulkan) endif() diff --git a/tests/auto/gui/kernel/CMakeLists.txt b/tests/auto/gui/kernel/CMakeLists.txt index b2397bed19..ecac48d1c1 100644 --- a/tests/auto/gui/kernel/CMakeLists.txt +++ b/tests/auto/gui/kernel/CMakeLists.txt @@ -20,7 +20,7 @@ add_subdirectory(qwindow) add_subdirectory(qguiapplication) add_subdirectory(qpixelformat) add_subdirectory(qrasterwindow) -if(NOT ANDROID AND NOT APPLE_UIKIT) +if(NOT ANDROID AND NOT UIKIT) add_subdirectory(qclipboard) endif() if(TARGET Qt::Network) diff --git a/tests/auto/gui/kernel/qclipboard/test/.prev_CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/test/.prev_CMakeLists.txt index 620ef96a5b..36d9f7b00c 100644 --- a/tests/auto/gui/kernel/qclipboard/test/.prev_CMakeLists.txt +++ b/tests/auto/gui/kernel/qclipboard/test/.prev_CMakeLists.txt @@ -15,7 +15,7 @@ add_qt_test(tst_qclipboard ## Scopes: ##################################################################### -extend_target(tst_qclipboard CONDITION APPLE_OSX +extend_target(tst_qclipboard CONDITION MACOS PUBLIC_LIBRARIES ${FWAppKit} ) diff --git a/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt index 620ef96a5b..36d9f7b00c 100644 --- a/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt +++ b/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt @@ -15,7 +15,7 @@ add_qt_test(tst_qclipboard ## Scopes: ##################################################################### -extend_target(tst_qclipboard CONDITION APPLE_OSX +extend_target(tst_qclipboard CONDITION MACOS PUBLIC_LIBRARIES ${FWAppKit} ) diff --git a/tests/auto/network/kernel/CMakeLists.txt b/tests/auto/network/kernel/CMakeLists.txt index c1082f60b7..6ce3fcdf32 100644 --- a/tests/auto/network/kernel/CMakeLists.txt +++ b/tests/auto/network/kernel/CMakeLists.txt @@ -13,7 +13,7 @@ endif() if(QT_FEATURE_private_tests) add_subdirectory(qauthenticator) - if(NOT APPLE_OSX) + if(NOT MACOS) add_subdirectory(qhostinfo) endif() endif() diff --git a/tests/auto/other/CMakeLists.txt b/tests/auto/other/CMakeLists.txt index e1d3c0e839..88a29b479b 100644 --- a/tests/auto/other/CMakeLists.txt +++ b/tests/auto/other/CMakeLists.txt @@ -15,7 +15,7 @@ if(TARGET Qt::Network AND TARGET Qt::Widgets AND NOT WINRT) add_subdirectory(lancelot) add_subdirectory(qnetworkaccessmanager_and_qprogressdialog) endif() -if(APPLE_OSX AND TARGET Qt::Gui AND TARGET Qt::Widgets) +if(MACOS AND TARGET Qt::Gui AND TARGET Qt::Widgets) add_subdirectory(macgui) add_subdirectory(macplist) add_subdirectory(qaccessibilitymac) @@ -35,7 +35,7 @@ endif() if(TARGET Qt::Network AND NOT WINRT) add_subdirectory(networkselftest) endif() -if(APPLE_OSX AND TARGET Qt::Gui) +if(MACOS AND TARGET Qt::Gui) add_subdirectory(macnativeevents) endif() if(embedded) diff --git a/tests/auto/other/macgui/.prev_CMakeLists.txt b/tests/auto/other/macgui/.prev_CMakeLists.txt index 4923568a89..1ae468c40e 100644 --- a/tests/auto/other/macgui/.prev_CMakeLists.txt +++ b/tests/auto/other/macgui/.prev_CMakeLists.txt @@ -26,7 +26,7 @@ add_qt_test(tst_macgui ## Scopes: ##################################################################### -extend_target(tst_macgui CONDITION APPLE_OSX +extend_target(tst_macgui CONDITION MACOS PUBLIC_LIBRARIES ${FWApplicationServices} ) diff --git a/tests/auto/other/macgui/CMakeLists.txt b/tests/auto/other/macgui/CMakeLists.txt index de69c43765..4a5aa0aaef 100644 --- a/tests/auto/other/macgui/CMakeLists.txt +++ b/tests/auto/other/macgui/CMakeLists.txt @@ -26,7 +26,7 @@ add_qt_test(tst_macgui ## Scopes: ##################################################################### -extend_target(tst_macgui CONDITION APPLE_OSX +extend_target(tst_macgui CONDITION MACOS PUBLIC_LIBRARIES ${FWApplicationServices} ) diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/CMakeLists.txt b/tests/auto/widgets/dialogs/qfilesystemmodel/CMakeLists.txt index 38c0547390..346e2a7d5a 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/CMakeLists.txt +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/CMakeLists.txt @@ -23,5 +23,5 @@ add_qt_test(tst_qfilesystemmodel #### Keys ignored in scope 2:.:.:qfilesystemmodel.pro:WIN32: # testcase.timeout = "900" -#### Keys ignored in scope 3:.:.:qfilesystemmodel.pro:APPLE_OSX: +#### Keys ignored in scope 3:.:.:qfilesystemmodel.pro:MACOS: # testcase.timeout = "900" diff --git a/tests/auto/widgets/styles/CMakeLists.txt b/tests/auto/widgets/styles/CMakeLists.txt index 4fc260fe39..4ded7b9d80 100644 --- a/tests/auto/widgets/styles/CMakeLists.txt +++ b/tests/auto/widgets/styles/CMakeLists.txt @@ -1,10 +1,10 @@ # Generated from styles.pro. -if (APPLE_OSX) +if (MACOS) add_subdirectory(qmacstyle) endif() add_subdirectory(qstyle) -if (NOT APPLE_UIKIT AND NOT ANDROID AND NOT QNX) +if (NOT UIKIT AND NOT ANDROID AND NOT QNX) add_subdirectory(qstyleoption) endif() if (QT_FEATURE_private_tests) diff --git a/tests/auto/widgets/widgets/qlineedit/CMakeLists.txt b/tests/auto/widgets/widgets/qlineedit/CMakeLists.txt index f95094aa7d..615a5a98cb 100644 --- a/tests/auto/widgets/widgets/qlineedit/CMakeLists.txt +++ b/tests/auto/widgets/widgets/qlineedit/CMakeLists.txt @@ -19,7 +19,7 @@ add_qt_test(tst_qlineedit ## Scopes: ##################################################################### -extend_target(tst_qlineedit CONDITION APPLE_OSX +extend_target(tst_qlineedit CONDITION MACOS PUBLIC_LIBRARIES ${FWAppKit} ) diff --git a/tests/auto/widgets/widgets/qmenu/CMakeLists.txt b/tests/auto/widgets/widgets/qmenu/CMakeLists.txt index a20fe70492..63037b7eaa 100644 --- a/tests/auto/widgets/widgets/qmenu/CMakeLists.txt +++ b/tests/auto/widgets/widgets/qmenu/CMakeLists.txt @@ -17,14 +17,14 @@ add_qt_test(tst_qmenu ## Scopes: ##################################################################### -extend_target(tst_qmenu CONDITION APPLE_OSX +extend_target(tst_qmenu CONDITION MACOS SOURCES tst_qmenu_mac.mm PUBLIC_LIBRARIES objc ) -extend_target(tst_qmenu CONDITION NOT APPLE_OSX +extend_target(tst_qmenu CONDITION NOT MACOS DEFINES QTEST_QPA_MOUSE_HANDLING ) diff --git a/tests/auto/widgets/widgets/qmenubar/CMakeLists.txt b/tests/auto/widgets/widgets/qmenubar/CMakeLists.txt index 43875cd113..415f2aa79f 100644 --- a/tests/auto/widgets/widgets/qmenubar/CMakeLists.txt +++ b/tests/auto/widgets/widgets/qmenubar/CMakeLists.txt @@ -16,7 +16,7 @@ add_qt_test(tst_qmenubar ## Scopes: ##################################################################### -extend_target(tst_qmenubar CONDITION APPLE_OSX +extend_target(tst_qmenubar CONDITION MACOS SOURCES tst_qmenubar_mac.mm PUBLIC_LIBRARIES diff --git a/tests/auto/widgets/widgets/qplaintextedit/CMakeLists.txt b/tests/auto/widgets/widgets/qplaintextedit/CMakeLists.txt index 4106de04de..cb00d5dd93 100644 --- a/tests/auto/widgets/widgets/qplaintextedit/CMakeLists.txt +++ b/tests/auto/widgets/widgets/qplaintextedit/CMakeLists.txt @@ -19,7 +19,7 @@ add_qt_test(tst_qplaintextedit ## Scopes: ##################################################################### -extend_target(tst_qplaintextedit CONDITION APPLE_OSX +extend_target(tst_qplaintextedit CONDITION MACOS PUBLIC_LIBRARIES ${FWAppKit} ) diff --git a/tests/auto/widgets/widgets/qtextedit/CMakeLists.txt b/tests/auto/widgets/widgets/qtextedit/CMakeLists.txt index 61641707b9..719acd8dbc 100644 --- a/tests/auto/widgets/widgets/qtextedit/CMakeLists.txt +++ b/tests/auto/widgets/widgets/qtextedit/CMakeLists.txt @@ -22,7 +22,7 @@ add_qt_test(tst_qtextedit ## Scopes: ##################################################################### -extend_target(tst_qtextedit CONDITION APPLE_OSX +extend_target(tst_qtextedit CONDITION MACOS PUBLIC_LIBRARIES ${FWAppKit} ) |