| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
import QtQuick 2.0 |
| 5 |
import QtTest 1.0 |
| 6 |
import QtCharts 1.1 |
| 7 |
|
| 8 |
Rectangle { |
| 9 |
width: 400 |
| 10 |
height: 300 |
| 11 |
|
| 12 |
TestCase { |
| 13 |
id: tc1 |
| 14 |
name: "tst_qml-qtquicktest PieSeries 1.1" |
| 15 |
when: windowShown |
| 16 |
|
| 17 |
function test_properties() { |
| 18 |
compare(pieSeries.endAngle, 360); |
| 19 |
compare(pieSeries.holeSize, 0); |
| 20 |
compare(pieSeries.horizontalPosition, 0.5); |
| 21 |
compare(pieSeries.size, 0.7); |
| 22 |
compare(pieSeries.startAngle, 0); |
| 23 |
compare(pieSeries.sum, 0); |
| 24 |
compare(pieSeries.verticalPosition, 0.5); |
| 25 |
} |
| 26 |
|
| 27 |
function test_sliceproperties() { |
| 28 |
var slice = pieSeries.append("slice", 10); |
| 29 |
compare(slice.angleSpan, 360.0); |
| 30 |
verify(slice.borderColor != undefined); |
| 31 |
compare(slice.borderWidth, 1); |
| 32 |
verify(slice.color != undefined); |
| 33 |
compare(slice.explodeDistanceFactor, 0.15); |
| 34 |
compare(slice.exploded, false); |
| 35 |
compare(slice.label, "slice"); |
| 36 |
compare(slice.labelArmLengthFactor, 0.15); |
| 37 |
verify(slice.labelColor != undefined); |
| 38 |
compare(slice.labelFont.bold, false); |
| 39 |
compare(slice.labelPosition, PieSlice.LabelOutside); |
| 40 |
compare(slice.labelVisible, false); |
| 41 |
compare(slice.percentage, 1.0); |
| 42 |
compare(slice.startAngle, 0.0); |
| 43 |
compare(slice.value, 10.0); |
| 44 |
} |
| 45 |
|
| 46 |
function test_append() { |
| 47 |
addedSpy.clear(); |
| 48 |
countChangedSpy.clear(); |
| 49 |
sumChangedSpy.clear(); |
| 50 |
var count = 50; |
| 51 |
for (var i = 0; i < count; i++) |
| 52 |
pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero |
| 53 |
compare(addedSpy.count, count); |
| 54 |
compare(countChangedSpy.count, count); |
| 55 |
compare(sumChangedSpy.count, count); |
| 56 |
pieSeries.clear(); |
| 57 |
} |
| 58 |
|
| 59 |
function test_remove() { |
| 60 |
removedSpy.clear(); |
| 61 |
countChangedSpy.clear(); |
| 62 |
sumChangedSpy.clear(); |
| 63 |
var count = 50; |
| 64 |
for (var i = 0; i < count; i++) |
| 65 |
pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero |
| 66 |
for (var j = 0; j < count; j++) |
| 67 |
pieSeries.remove(pieSeries.at(0)); |
| 68 |
compare(removedSpy.count, count); |
| 69 |
compare(countChangedSpy.count, 2 * count); |
| 70 |
compare(sumChangedSpy.count, 2 * count); |
| 71 |
compare(pieSeries.count, 0); |
| 72 |
} |
| 73 |
|
| 74 |
function test_find() { |
| 75 |
var count = 50; |
| 76 |
for (var i = 0; i < count; i++) |
| 77 |
pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero |
| 78 |
for (var j = 0; j < count; j++) |
| 79 |
compare(pieSeries.find("slice" + j).label, "slice" + j); |
| 80 |
pieSeries.clear(); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
ChartView { |
| 85 |
id: chartView |
| 86 |
anchors.fill: parent |
| 87 |
|
| 88 |
PieSeries { |
| 89 |
id: pieSeries |
| 90 |
name: "pie" |
| 91 |
|
| 92 |
SignalSpy { |
| 93 |
id: addedSpy |
| 94 |
target: pieSeries |
| 95 |
signalName: "added" |
| 96 |
} |
| 97 |
SignalSpy { |
| 98 |
id: removedSpy |
| 99 |
target: pieSeries |
| 100 |
signalName: "removed" |
| 101 |
} |
| 102 |
SignalSpy { |
| 103 |
id: sumChangedSpy |
| 104 |
target: pieSeries |
| 105 |
signalName: "sumChanged" |
| 106 |
} |
| 107 |
SignalSpy { |
| 108 |
id: countChangedSpy |
| 109 |
target: pieSeries |
| 110 |
signalName: "countChanged" |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
} |