diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-09 12:30:18 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-14 13:20:00 +0200 |
commit | e96f4fc0957d936385a086cf9b0882b62bcebad3 (patch) | |
tree | 6f8360e5b94842558ec768cb81abd4a313a2f78c /tests | |
parent | 1732bdf40518194d0ee5e0f009de3409dce6280d (diff) | |
download | qtlocation-e96f4fc0957d936385a086cf9b0882b62bcebad3.tar.gz |
Register QPlaceRatings as a value type
Make QPlaceUser a gadget, and register it as a value type with the QML
engine. Remove declarative wrapper, and consolidate the documentation.
To support QML tests setting ratings properties from literal values,
register a converter from QJSValue. That is temporary and will become
obsolete once the QML engine can property-initialize, and perhaps even
instantiate, value types.
Adjust the tests and remove tests that verify that the type behaves like
an object. This is not entirely complete (some tests still compare
Place.ratings with `null`, but those tests pass for now, and will be
changed in later commits when more types get converted in this way.
Task-number: QTBUG-106482
Change-Id: I3694df414bb87adcfda3dc4b88e5206d4272bb82
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative_location_core/tst_place.qml | 33 | ||||
-rw-r--r-- | tests/auto/declarative_location_core/tst_ratings.qml | 26 | ||||
-rw-r--r-- | tests/auto/qmlinterface/data/TestPlace.qml | 2 | ||||
-rw-r--r-- | tests/auto/qmlinterface/data/TestRatings.qml | 12 |
4 files changed, 21 insertions, 52 deletions
diff --git a/tests/auto/declarative_location_core/tst_place.qml b/tests/auto/declarative_location_core/tst_place.qml index cc2ed44f..8f60f8c0 100644 --- a/tests/auto/declarative_location_core/tst_place.qml +++ b/tests/auto/declarative_location_core/tst_place.qml @@ -82,10 +82,7 @@ TestCase { boundingShape: QtPositioning.rectangle(QtPositioning.coordinate(10, 10, 100), 100, 100) } - ratings: Ratings { - average: 3.5 - count: 10 - } + ratings: ({ average: 3.5, count: 10 }) supplier: Supplier { name: "Supplier 1" @@ -183,15 +180,8 @@ TestCase { } // check ratings - if (place1. ratings === null && place2.ratings !== null) - return false; - if (place1.ratings !== null && place2.ratings === null) + if (place1.ratings !== place2.ratings) { return false; - if (place1.ratings !== null && place2.ratings !== null) { - if (place1.ratings.average !== place2.ratings.average) - return false; - if (place1.ratings.count !== place2.ratings.count) - return false; } // check location @@ -405,27 +395,24 @@ TestCase { } function test_ratings() { - var ratings = Qt.createQmlObject('import QtLocation 5.3; Ratings { average: 3; count: 100 }', testCase, "Rating1"); + var ratings1 = emptyPlace.ratings + var ratings2 = savePlace.ratings var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy"); signalSpy.target = testPlace; signalSpy.signalName = "ratingsChanged"; - testPlace.ratings = ratings; - compare(testPlace.ratings.average, 3); - compare(testPlace.ratings.count, 100); - compare(signalSpy.count, 1); + testPlace.ratings = ratings1; + compare(signalSpy.count, 0); - testPlace.ratings = ratings; - compare(testPlace.ratings.average, 3); - compare(testPlace.ratings.count, 100); + testPlace.ratings = ratings2; + compare(testPlace.ratings.count, ratings2.count); compare(signalSpy.count, 1); - testPlace.ratings = null; - compare(testPlace.ratings, null); + testPlace.ratings = ratings1; + compare(testPlace.ratings.count, ratings1.count); compare(signalSpy.count, 2); - ratings.destroy(); signalSpy.destroy(); } diff --git a/tests/auto/declarative_location_core/tst_ratings.qml b/tests/auto/declarative_location_core/tst_ratings.qml index d372d815..e1d76539 100644 --- a/tests/auto/declarative_location_core/tst_ratings.qml +++ b/tests/auto/declarative_location_core/tst_ratings.qml @@ -35,7 +35,7 @@ TestCase { name: "Ratings" - Ratings { id: emptyRatings } + property ratings emptyRatings function test_empty() { compare(emptyRatings.average, 0.0); @@ -43,33 +43,11 @@ TestCase { compare(emptyRatings.count, 0); } - Ratings { - id: qmlRatings - - average: 3.5 - maximum: 5.0 - count: 7 - } + property ratings qmlRatings: ({ average: 3.5, maximum: 5.0, count: 7 }) function test_qmlConstructedRatings() { compare(qmlRatings.average, 3.5); compare(qmlRatings.maximum, 5.0); compare(qmlRatings.count, 7); } - - Ratings { - id: testRatings - } - - function test_setAndGet_data() { - return [ - { tag: "average", property: "average", signal: "averageChanged", value: 4.5, reset: 0.0 }, - { tag: "maximum", property: "maximum", signal: "maximumChanged", value: 5.0, reset: 0.0 }, - { tag: "count", property: "count", signal: "countChanged", value: 10, reset: 0 }, - ]; - } - - function test_setAndGet(data) { - Utils.testObjectProperties(testCase, testRatings, data); - } } diff --git a/tests/auto/qmlinterface/data/TestPlace.qml b/tests/auto/qmlinterface/data/TestPlace.qml index 4a0adc78..1cce22af 100644 --- a/tests/auto/qmlinterface/data/TestPlace.qml +++ b/tests/auto/qmlinterface/data/TestPlace.qml @@ -43,7 +43,7 @@ Place { } ] location: TestLocation { } - ratings: TestRatings { } + ratings: ({ average: 3.5, maximum: 5.0, count: 10 }) icon: TestIcon { } supplier: TestSupplier { } visibility: Place.PrivateVisibility diff --git a/tests/auto/qmlinterface/data/TestRatings.qml b/tests/auto/qmlinterface/data/TestRatings.qml index 67e26cc3..17f7d4f5 100644 --- a/tests/auto/qmlinterface/data/TestRatings.qml +++ b/tests/auto/qmlinterface/data/TestRatings.qml @@ -27,9 +27,13 @@ ****************************************************************************/ import QtLocation +import QtQuick -Ratings { - average: 3.5 - maximum: 5.0 - count: 10 +Item { + property ratings ratings + ratings { + average: 3.5 + maximum: 5.0 + count: 10 + } } |