summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-09-21 08:33:05 +0200
committerLiang Qi <liang.qi@qt.io>2016-09-21 08:33:05 +0200
commit06c412094b60517af015637322798da6224e34c2 (patch)
tree0f8e68383c9fc08f07e80ca3e24e5a4531e65365 /tests
parent105d75533d31ceee0c39ef9e084294ed49ecbd89 (diff)
parent6e224c11080feef2c6d7857d061a92e320e50899 (diff)
Merge remote-tracking branch 'origin/5.8' into dev
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/qareaseries/qareaseries.pro4
-rw-r--r--tests/auto/qareaseries/tst_qareaseries.cpp183
-rw-r--r--tests/auto/qml-qtquicktest/tst_pieseries.qml6
-rw-r--r--tests/auto/qml-qtquicktest/tst_pieseries_1_1.qml6
-rw-r--r--tests/auto/qml-qtquicktest/tst_pieseries_1_2.qml6
-rw-r--r--tests/auto/qml-qtquicktest/tst_pieseries_1_3.qml6
-rw-r--r--tests/auto/qml-qtquicktest/tst_pieseries_1_4.qml6
-rw-r--r--tests/auto/qml-qtquicktest/tst_pieseries_2_0.qml6
9 files changed, 206 insertions, 18 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 1b04ac7c..81557a7f 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -23,6 +23,7 @@ SUBDIRS += \
domain \
chartdataset \
qlegend \
+ qareaseries \
cmake \
qcandlestickmodelmapper \
qcandlestickseries \
diff --git a/tests/auto/qareaseries/qareaseries.pro b/tests/auto/qareaseries/qareaseries.pro
new file mode 100644
index 00000000..a87857ab
--- /dev/null
+++ b/tests/auto/qareaseries/qareaseries.pro
@@ -0,0 +1,4 @@
+!include( ../auto.pri ) {
+ error( "Couldn't find the auto.pri file!" )
+}
+SOURCES += tst_qareaseries.cpp
diff --git a/tests/auto/qareaseries/tst_qareaseries.cpp b/tests/auto/qareaseries/tst_qareaseries.cpp
new file mode 100644
index 00000000..e03989c0
--- /dev/null
+++ b/tests/auto/qareaseries/tst_qareaseries.cpp
@@ -0,0 +1,183 @@
+/******************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Charts module.
+**
+** $QT_BEGIN_LICENSE:COMM$
+**
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** $QT_END_LICENSE$
+**
+******************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtGui/QImage>
+#include <QtCharts/QChartView>
+#include <QtCharts/QAreaSeries>
+#include <QtCharts/QLineSeries>
+#include <QtCharts/QChartView>
+#include <QtCharts/QValueAxis>
+#include <tst_definitions.h>
+
+QT_CHARTS_USE_NAMESPACE
+
+class tst_QAreaSeries : public QObject
+{
+ Q_OBJECT
+
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void init();
+ void cleanup();
+private slots:
+ void areaSeries();
+ void dynamicEdgeSeriesChange();
+
+protected:
+ QLineSeries *createUpperSeries();
+ QLineSeries *createLowerSeries();
+ void checkPixels(const QColor &upperColor, const QColor &centerColor, const QColor &lowerColor);
+
+ QChartView *m_view;
+ QChart *m_chart;
+ QColor m_brushColor;
+ QColor m_backgroundColor;
+ QValueAxis *m_axisX;
+ QValueAxis *m_axisY;
+};
+
+void tst_QAreaSeries::initTestCase()
+{
+ m_brushColor = QColor("#123456");
+ m_backgroundColor = QColor("#abcfef");
+}
+
+void tst_QAreaSeries::cleanupTestCase()
+{
+ QTest::qWait(1); // Allow final deleteLaters to run
+}
+
+void tst_QAreaSeries::init()
+{
+ m_view = new QChartView(newQChartOrQPolarChart());
+ m_view->setGeometry(0, 0, 400, 400);
+ m_chart = m_view->chart();
+ m_chart->setBackgroundBrush(m_backgroundColor);
+ m_chart->legend()->setVisible(false);
+ m_axisX = new QValueAxis;
+ m_axisY = new QValueAxis;
+ m_axisX->setRange(0, 4);
+ m_axisY->setRange(0, 10);
+ m_chart->addAxis(m_axisX, Qt::AlignBottom);
+ m_chart->addAxis(m_axisY, Qt::AlignRight);
+}
+
+void tst_QAreaSeries::cleanup()
+{
+ delete m_view;
+ m_view = 0;
+ m_chart = 0;
+}
+
+void tst_QAreaSeries::areaSeries()
+{
+ QLineSeries *series0 = createUpperSeries();
+ QLineSeries *series1 = createLowerSeries();
+ QAreaSeries *series = new QAreaSeries(series0, series1);
+
+ QCOMPARE(series->brush(), QBrush());
+ QCOMPARE(series->pen(), QPen());
+ QCOMPARE(series->pointsVisible(), false);
+ QCOMPARE(series->pointLabelsVisible(), false);
+ QCOMPARE(series->pointLabelsFormat(), QLatin1String("@xPoint, @yPoint"));
+ QCOMPARE(series->pointLabelsClipping(), true);
+ QCOMPARE(series->pointLabelsColor(), QPen().color());
+ QCOMPARE(series->upperSeries(), series0);
+ QCOMPARE(series->lowerSeries(), series1);
+ QCOMPARE(series->color(), QPen().color());
+ QCOMPARE(series->borderColor(), QPen().color());
+
+ series->setBrush(QBrush(m_brushColor));
+ m_chart->addSeries(series);
+ series->attachAxis(m_axisX);
+ series->attachAxis(m_axisY);
+ m_view->show();
+ QTest::qWaitForWindowShown(m_view);
+
+ checkPixels(m_backgroundColor, m_brushColor, m_backgroundColor);
+}
+
+void tst_QAreaSeries::dynamicEdgeSeriesChange()
+{
+ QAreaSeries *series = new QAreaSeries;
+ series->setBrush(QBrush(m_brushColor));
+
+ m_chart->addSeries(series);
+ series->attachAxis(m_axisX);
+ series->attachAxis(m_axisY);
+ m_view->show();
+ QTest::qWaitForWindowShown(m_view);
+
+ checkPixels(m_backgroundColor, m_backgroundColor, m_backgroundColor);
+
+ QLineSeries *series0 = createUpperSeries();
+ series->setUpperSeries(series0);
+
+ QApplication::processEvents();
+ checkPixels(m_backgroundColor, m_brushColor, m_brushColor);
+
+ QLineSeries *series1 = createLowerSeries();
+ series->setLowerSeries(series1);
+
+ QApplication::processEvents();
+ checkPixels(m_backgroundColor, m_brushColor, m_backgroundColor);
+
+ series->setLowerSeries(nullptr);
+
+ QApplication::processEvents();
+ checkPixels(m_backgroundColor, m_brushColor, m_brushColor);
+
+ series->setUpperSeries(nullptr);
+
+ QApplication::processEvents();
+ checkPixels(m_backgroundColor, m_backgroundColor, m_backgroundColor);
+}
+
+QLineSeries *tst_QAreaSeries::createUpperSeries()
+{
+ QLineSeries *series = new QLineSeries();
+ *series << QPointF(0, 10) << QPointF(1, 7) << QPointF(2, 6) << QPointF(3, 7) << QPointF(4, 10);
+ return series;
+}
+
+QLineSeries *tst_QAreaSeries::createLowerSeries()
+{
+ QLineSeries *series = new QLineSeries();
+ *series << QPointF(0, 0) << QPointF(1, 3) << QPointF(2, 4) << QPointF(3, 3) << QPointF(4, 0);
+ return series;
+}
+
+void tst_QAreaSeries::checkPixels(const QColor &upperColor,
+ const QColor &centerColor,
+ const QColor &lowerColor)
+{
+ QImage screenGrab = m_view->grab().toImage();
+ QCOMPARE(QColor(screenGrab.pixel(200, 50)), upperColor);
+ QCOMPARE(QColor(screenGrab.pixel(200, 200)), centerColor);
+ QCOMPARE(QColor(screenGrab.pixel(200, 350)), lowerColor);
+}
+
+QTEST_MAIN(tst_QAreaSeries)
+
+#include "tst_qareaseries.moc"
+
diff --git a/tests/auto/qml-qtquicktest/tst_pieseries.qml b/tests/auto/qml-qtquicktest/tst_pieseries.qml
index 7d5c95b4..3e6a82e8 100644
--- a/tests/auto/qml-qtquicktest/tst_pieseries.qml
+++ b/tests/auto/qml-qtquicktest/tst_pieseries.qml
@@ -76,7 +76,7 @@ Rectangle {
sumChangedSpy.clear();
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
compare(addedSpy.count, count);
compare(countChangedSpy.count, count);
compare(sumChangedSpy.count, count);
@@ -89,7 +89,7 @@ Rectangle {
sumChangedSpy.clear();
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
for (var j = 0; j < count; j++)
pieSeries.remove(pieSeries.at(0));
compare(removedSpy.count, count);
@@ -101,7 +101,7 @@ Rectangle {
function test_find_and_at() {
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
for (var j = 0; j < count; j++) {
compare(pieSeries.find("slice" + j).label, "slice" + j);
compare(pieSeries.find("slice" + j).brushFilename, "");
diff --git a/tests/auto/qml-qtquicktest/tst_pieseries_1_1.qml b/tests/auto/qml-qtquicktest/tst_pieseries_1_1.qml
index 01b03827..5016d15e 100644
--- a/tests/auto/qml-qtquicktest/tst_pieseries_1_1.qml
+++ b/tests/auto/qml-qtquicktest/tst_pieseries_1_1.qml
@@ -75,7 +75,7 @@ Rectangle {
sumChangedSpy.clear();
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
compare(addedSpy.count, count);
compare(countChangedSpy.count, count);
compare(sumChangedSpy.count, count);
@@ -88,7 +88,7 @@ Rectangle {
sumChangedSpy.clear();
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
for (var j = 0; j < count; j++)
pieSeries.remove(pieSeries.at(0));
compare(removedSpy.count, count);
@@ -100,7 +100,7 @@ Rectangle {
function test_find() {
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
for (var j = 0; j < count; j++)
compare(pieSeries.find("slice" + j).label, "slice" + j);
pieSeries.clear();
diff --git a/tests/auto/qml-qtquicktest/tst_pieseries_1_2.qml b/tests/auto/qml-qtquicktest/tst_pieseries_1_2.qml
index 5160975f..74ad1511 100644
--- a/tests/auto/qml-qtquicktest/tst_pieseries_1_2.qml
+++ b/tests/auto/qml-qtquicktest/tst_pieseries_1_2.qml
@@ -75,7 +75,7 @@ Rectangle {
sumChangedSpy.clear();
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
compare(addedSpy.count, count);
compare(countChangedSpy.count, count);
compare(sumChangedSpy.count, count);
@@ -88,7 +88,7 @@ Rectangle {
sumChangedSpy.clear();
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
for (var j = 0; j < count; j++)
pieSeries.remove(pieSeries.at(0));
compare(removedSpy.count, count);
@@ -100,7 +100,7 @@ Rectangle {
function test_find() {
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
for (var j = 0; j < count; j++)
compare(pieSeries.find("slice" + j).label, "slice" + j);
pieSeries.clear();
diff --git a/tests/auto/qml-qtquicktest/tst_pieseries_1_3.qml b/tests/auto/qml-qtquicktest/tst_pieseries_1_3.qml
index 8e53b42f..15fd4b6e 100644
--- a/tests/auto/qml-qtquicktest/tst_pieseries_1_3.qml
+++ b/tests/auto/qml-qtquicktest/tst_pieseries_1_3.qml
@@ -75,7 +75,7 @@ Rectangle {
sumChangedSpy.clear();
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
compare(addedSpy.count, count);
compare(countChangedSpy.count, count);
compare(sumChangedSpy.count, count);
@@ -88,7 +88,7 @@ Rectangle {
sumChangedSpy.clear();
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
for (var j = 0; j < count; j++)
pieSeries.remove(pieSeries.at(0));
compare(removedSpy.count, count);
@@ -100,7 +100,7 @@ Rectangle {
function test_find() {
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
for (var j = 0; j < count; j++)
compare(pieSeries.find("slice" + j).label, "slice" + j);
pieSeries.clear();
diff --git a/tests/auto/qml-qtquicktest/tst_pieseries_1_4.qml b/tests/auto/qml-qtquicktest/tst_pieseries_1_4.qml
index 393f631c..ccd133dd 100644
--- a/tests/auto/qml-qtquicktest/tst_pieseries_1_4.qml
+++ b/tests/auto/qml-qtquicktest/tst_pieseries_1_4.qml
@@ -76,7 +76,7 @@ Rectangle {
sumChangedSpy.clear();
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
compare(addedSpy.count, count);
compare(countChangedSpy.count, count);
compare(sumChangedSpy.count, count);
@@ -89,7 +89,7 @@ Rectangle {
sumChangedSpy.clear();
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
for (var j = 0; j < count; j++)
pieSeries.remove(pieSeries.at(0));
compare(removedSpy.count, count);
@@ -101,7 +101,7 @@ Rectangle {
function test_find_and_at() {
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
for (var j = 0; j < count; j++) {
compare(pieSeries.find("slice" + j).label, "slice" + j);
compare(pieSeries.find("slice" + j).brushFilename, "");
diff --git a/tests/auto/qml-qtquicktest/tst_pieseries_2_0.qml b/tests/auto/qml-qtquicktest/tst_pieseries_2_0.qml
index b1d3fa27..6a594fde 100644
--- a/tests/auto/qml-qtquicktest/tst_pieseries_2_0.qml
+++ b/tests/auto/qml-qtquicktest/tst_pieseries_2_0.qml
@@ -76,7 +76,7 @@ Rectangle {
sumChangedSpy.clear();
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
compare(addedSpy.count, count);
compare(countChangedSpy.count, count);
compare(sumChangedSpy.count, count);
@@ -89,7 +89,7 @@ Rectangle {
sumChangedSpy.clear();
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
for (var j = 0; j < count; j++)
pieSeries.remove(pieSeries.at(0));
compare(removedSpy.count, count);
@@ -101,7 +101,7 @@ Rectangle {
function test_find_and_at() {
var count = 50;
for (var i = 0; i < count; i++)
- pieSeries.append("slice" + i, Math.random());
+ pieSeries.append("slice" + i, Math.random() + 0.01); // Add 0.01 to avoid zero
for (var j = 0; j < count; j++) {
compare(pieSeries.find("slice" + j).label, "slice" + j);
compare(pieSeries.find("slice" + j).brushFilename, "");