summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorErik Mattsson <erik.mattsson@appello.com>2013-09-27 15:44:01 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-07 09:43:44 +0200
commit7ec8919a055e35232b5127e312a525f61b0bc483 (patch)
tree80436fb4170376af1ffc9f31408db9f0a212358b /tests
parent7ca062e008db1543519f9258812b0d577d5da5ac (diff)
downloadqtlocation-7ec8919a055e35232b5127e312a525f61b0bc483.tar.gz
Added possibility to create a georectangle from a list of coordinates
It will create the smallest possible rectangle that contains all of the coordinates. This is accessible from qml using the locationsingleton. The plan is to include the ability to fit the view-port of the map to a georectangle. Change-Id: I616ac8ef169f697e53a3d9ebcf114f4f2cde8298 Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/auto.pro3
-rw-r--r--tests/auto/declarative_geoshape/declarative_geoshape.pro14
-rw-r--r--tests/auto/declarative_geoshape/main.cpp43
-rw-r--r--tests/auto/declarative_geoshape/tst_locationsingleton.qml (renamed from tests/auto/declarative_core/tst_geoshape.qml)26
-rw-r--r--tests/auto/qgeocircle/tst_qgeocircle.cpp52
-rw-r--r--tests/auto/qgeorectangle/tst_qgeorectangle.cpp110
6 files changed, 247 insertions, 1 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index d9517add..ffbd9b84 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -57,7 +57,8 @@ qtHaveModule(location) {
qgeocameratiles
qtHaveModule(quick) {
- SUBDIRS += declarative_core
+ SUBDIRS += declarative_core \
+ declarative_geoshape
!mac: SUBDIRS += declarative_ui
}
diff --git a/tests/auto/declarative_geoshape/declarative_geoshape.pro b/tests/auto/declarative_geoshape/declarative_geoshape.pro
new file mode 100644
index 00000000..54331c57
--- /dev/null
+++ b/tests/auto/declarative_geoshape/declarative_geoshape.pro
@@ -0,0 +1,14 @@
+# QML tests in this directory must not depend on an OpenGL context.
+
+TEMPLATE = app
+TARGET = tst_declarative_geoshape
+CONFIG += qmltestcase
+SOURCES += main.cpp
+
+QT += positioning quick
+
+OTHER_FILES = *.qml
+TESTDATA = $$OTHER_FILES
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+
+CONFIG+=insignificant_test # QTBUG-31798
diff --git a/tests/auto/declarative_geoshape/main.cpp b/tests/auto/declarative_geoshape/main.cpp
new file mode 100644
index 00000000..efc51279
--- /dev/null
+++ b/tests/auto/declarative_geoshape/main.cpp
@@ -0,0 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtQuickTest/quicktest.h>
+QUICK_TEST_MAIN(declarative_geoshape)
diff --git a/tests/auto/declarative_core/tst_geoshape.qml b/tests/auto/declarative_geoshape/tst_locationsingleton.qml
index df03125f..58682721 100644
--- a/tests/auto/declarative_core/tst_geoshape.qml
+++ b/tests/auto/declarative_geoshape/tst_locationsingleton.qml
@@ -90,11 +90,26 @@ Item {
property variant br: QtPositioning.coordinate(0, 1)
property variant ntr: QtPositioning.coordinate(3, 3)
+ property variant invalid: QtPositioning.coordinate(100, 190)
property variant inside: QtPositioning.coordinate(0.5, 0.5)
property variant outside: QtPositioning.coordinate(2, 2)
property variant box: QtPositioning.rectangle(tl, br)
+ property variant coordinates: [bl, tl, tr, br]
+ property variant coordinates2: [bl, tl, tr, br, ntr]
+ property variant coordinates3: [tr]
+ property variant coordinates4: [invalid]
+ property variant coordinates5: []
+
+ property variant listBox: QtPositioning.rectangle(coordinates)
+ property variant listBox2: QtPositioning.rectangle(coordinates2)
+ property variant listBox3: QtPositioning.rectangle(coordinates3)
+ property variant listBox4: QtPositioning.rectangle(coordinates4)
+ property variant listBox5: QtPositioning.rectangle(coordinates5)
+
+ property variant widthBox: QtPositioning.rectangle(inside, 1, 1);
+
// C++ auto test exists for basics of bounding box, testing here
// only added functionality
TestCase {
@@ -106,6 +121,17 @@ Item {
compare (box.contains(outside), false)
box.topRight = ntr
compare (box.contains(outside), true)
+
+ compare (listBox.isValid, true)
+ compare (listBox.contains(outside), false)
+ compare (listBox2.contains(outside), true)
+ compare (listBox3.isValid, true)
+ compare (listBox3.isEmpty, true)
+ compare (listBox4.isValid, false)
+ compare (listBox5.isValid, false)
+
+ compare (widthBox.contains(inside), true)
+ compare (widthBox.contains(outside), false)
}
}
}
diff --git a/tests/auto/qgeocircle/tst_qgeocircle.cpp b/tests/auto/qgeocircle/tst_qgeocircle.cpp
index dde256bd..db8cde66 100644
--- a/tests/auto/qgeocircle/tst_qgeocircle.cpp
+++ b/tests/auto/qgeocircle/tst_qgeocircle.cpp
@@ -73,6 +73,9 @@ private slots:
void contains_data();
void contains();
+ void extendShape();
+ void extendShape_data();
+
void areaComparison();
void areaComparison_data();
@@ -313,6 +316,55 @@ void tst_QGeoCircle::contains()
QCOMPARE(area.contains(probe), result);
}
+void tst_QGeoCircle::extendShape()
+{
+ QFETCH(QGeoCircle, circle);
+ QFETCH(QGeoCoordinate, coord);
+ QFETCH(bool, containsFirst);
+ QFETCH(bool, containsExtended);
+
+ QCOMPARE(circle.contains(coord), containsFirst);
+ circle.extendShape(coord);
+ QCOMPARE(circle.contains(coord), containsExtended);
+
+}
+
+void tst_QGeoCircle::extendShape_data()
+{
+ QTest::addColumn<QGeoCircle>("circle");
+ QTest::addColumn<QGeoCoordinate>("coord");
+ QTest::addColumn<bool>("containsFirst");
+ QTest::addColumn<bool>("containsExtended");
+
+ QGeoCoordinate co1(20.0, 20.0);
+
+ QTest::newRow("own center")
+ << QGeoCircle(co1, 100)
+ << QGeoCoordinate(20.0, 20.0)
+ << true
+ << true;
+ QTest::newRow("inside")
+ << QGeoCircle(co1, 100)
+ << QGeoCoordinate(20.0001, 20.0001)
+ << true
+ << true;
+ QTest::newRow("far away")
+ << QGeoCircle(co1, 100)
+ << QGeoCoordinate(50.0001, 50.0001)
+ << false
+ << true;
+ QTest::newRow("invalid circle")
+ << QGeoCircle()
+ << QGeoCoordinate(20.0, 20.0)
+ << false
+ << false;
+ QTest::newRow("invalid coordinate")
+ << QGeoCircle(co1, 100)
+ << QGeoCoordinate(99.0, 190.0)
+ << false
+ << false;
+}
+
void tst_QGeoCircle::areaComparison_data()
{
QTest::addColumn<QGeoShape>("area");
diff --git a/tests/auto/qgeorectangle/tst_qgeorectangle.cpp b/tests/auto/qgeorectangle/tst_qgeorectangle.cpp
index d0c9672d..7abc6c4c 100644
--- a/tests/auto/qgeorectangle/tst_qgeorectangle.cpp
+++ b/tests/auto/qgeorectangle/tst_qgeorectangle.cpp
@@ -56,6 +56,7 @@ private slots:
void default_constructor();
void center_constructor();
void corner_constructor();
+ void list_constructor();
void copy_constructor();
void assignment();
void destructor();
@@ -95,6 +96,9 @@ private slots:
void unite();
void unite_data();
+ void extendShape();
+ void extendShape_data();
+
void areaComparison();
void areaComparison_data();
@@ -126,6 +130,23 @@ void tst_QGeoRectangle::corner_constructor()
QCOMPARE(b1.bottomRight(), QGeoCoordinate(0.0, 10.0));
}
+void tst_QGeoRectangle::list_constructor()
+{
+ QList<QGeoCoordinate> coordinates;
+ QGeoRectangle b1 = QGeoRectangle(coordinates);
+ QCOMPARE(b1.isValid(), false);
+
+ coordinates << QGeoCoordinate(10.0, 0.0);
+ b1 = QGeoRectangle(coordinates);
+ QCOMPARE(b1.isValid(), true);
+ QCOMPARE(b1.isEmpty(), true);
+
+ coordinates << QGeoCoordinate(0.0, 10.0) << QGeoCoordinate(0.0, 5.0);
+ b1 = QGeoRectangle(coordinates);
+ QCOMPARE(b1.topLeft(), QGeoCoordinate(10.0,0.0));
+ QCOMPARE(b1.bottomRight(), QGeoCoordinate(0.0, 10.0));
+}
+
void tst_QGeoRectangle::copy_constructor()
{
QGeoRectangle b1 = QGeoRectangle(QGeoCoordinate(10.0, 0.0),
@@ -2190,6 +2211,95 @@ void tst_QGeoRectangle::unite_data()
QGeoCoordinate(-30.0, 180.0));
}
+
+void tst_QGeoRectangle::extendShape()
+{
+ QFETCH(QGeoRectangle, box);
+ QFETCH(QGeoCoordinate, coord);
+ QFETCH(QGeoRectangle, out);
+
+ box.extendShape(coord);
+ QCOMPARE(box, out);
+}
+
+void tst_QGeoRectangle::extendShape_data()
+{
+ QTest::addColumn<QGeoRectangle>("box");
+ QTest::addColumn<QGeoCoordinate>("coord");
+ QTest::addColumn<QGeoRectangle>("out");
+
+ QTest::newRow("valid rect - invalid coordinate")
+ << QGeoRectangle(QGeoCoordinate(30.0, -20.0),
+ QGeoCoordinate(-30.0, 20.0))
+ << QGeoCoordinate(100.0, 190.0)
+ << QGeoRectangle(QGeoCoordinate(30.0, -20.0),
+ QGeoCoordinate(-30.0, 20));
+ QTest::newRow("invalid rect - valid coordinate")
+ << QGeoRectangle()
+ << QGeoCoordinate(10.0, 10.0)
+ << QGeoRectangle();
+ QTest::newRow("inside rect - not wrapped")
+ << QGeoRectangle(QGeoCoordinate(30.0, -20.0),
+ QGeoCoordinate(-30.0, 20.0))
+ << QGeoCoordinate(10.0, 10.0)
+ << QGeoRectangle(QGeoCoordinate(30.0, -20.0),
+ QGeoCoordinate(-30.0, 20));
+ QTest::newRow("lat outside rect - not wrapped")
+ << QGeoRectangle(QGeoCoordinate(30.0, -20.0),
+ QGeoCoordinate(-30.0, 20.0))
+ << QGeoCoordinate(40.0, 10.0)
+ << QGeoRectangle(QGeoCoordinate(40.0, -20.0),
+ QGeoCoordinate(-30.0, 20));
+ QTest::newRow("positive lon outside rect - not wrapped")
+ << QGeoRectangle(QGeoCoordinate(30.0, -20.0),
+ QGeoCoordinate(-30.0, 20.0))
+ << QGeoCoordinate(10.0, 40.0)
+ << QGeoRectangle(QGeoCoordinate(30.0, -20.0),
+ QGeoCoordinate(-30.0, 40));
+ QTest::newRow("negative lon outside rect - not wrapped")
+ << QGeoRectangle(QGeoCoordinate(30.0, -20.0),
+ QGeoCoordinate(-30.0, 20.0))
+ << QGeoCoordinate(10.0, -40.0)
+ << QGeoRectangle(QGeoCoordinate(30.0, -40.0),
+ QGeoCoordinate(-30.0, 20.0));
+ QTest::newRow("inside rect - wrapped")
+ << QGeoRectangle(QGeoCoordinate(30.0, 160.0),
+ QGeoCoordinate(-30.0, -160.0))
+ << QGeoCoordinate(10.0, -170.0)
+ << QGeoRectangle(QGeoCoordinate(30.0, 160.0),
+ QGeoCoordinate(-30.0, -160.0));
+ QTest::newRow("lat outside rect - wrapped")
+ << QGeoRectangle(QGeoCoordinate(30.0, 160.0),
+ QGeoCoordinate(-30.0, -160.0))
+ << QGeoCoordinate(-40.0, -170.0)
+ << QGeoRectangle(QGeoCoordinate(30.0, 160.0),
+ QGeoCoordinate(-40.0, -160.0));
+ QTest::newRow("positive lon outside rect - wrapped")
+ << QGeoRectangle(QGeoCoordinate(30.0, 160.0),
+ QGeoCoordinate(-30.0, -160.0))
+ << QGeoCoordinate(10.0, 140.0)
+ << QGeoRectangle(QGeoCoordinate(30.0, 140.0),
+ QGeoCoordinate(-30.0, -160.0));
+ QTest::newRow("negative lon outside rect - wrapped")
+ << QGeoRectangle(QGeoCoordinate(30.0, 160.0),
+ QGeoCoordinate(-30.0, -160.0))
+ << QGeoCoordinate(10.0, -140.0)
+ << QGeoRectangle(QGeoCoordinate(30.0, 160.0),
+ QGeoCoordinate(-30.0, -140.0));
+ QTest::newRow("extending over 180 degree line eastward")
+ << QGeoRectangle(QGeoCoordinate(30.0, 130.0),
+ QGeoCoordinate(-30.0, 160.0))
+ << QGeoCoordinate(10.0, -170.0)
+ << QGeoRectangle(QGeoCoordinate(30.0, 130.0),
+ QGeoCoordinate(-30.0, -170));
+ QTest::newRow("extending over -180 degree line westward")
+ << QGeoRectangle(QGeoCoordinate(30.0, -160.0),
+ QGeoCoordinate(-30.0, -130.0))
+ << QGeoCoordinate(10.0, 170.0)
+ << QGeoRectangle(QGeoCoordinate(30.0, 170.0),
+ QGeoCoordinate(-30.0, -130));
+}
+
void tst_QGeoRectangle::areaComparison_data()
{
QTest::addColumn<QGeoShape>("area");