File indexing completed on 2024-04-21 03:50:42

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2014 Calin Cruceru <calin@rosedu.org>
0004 //
0005 
0006 #include <QObject>
0007 
0008 #include "GeoDataMultiTrack.h"
0009 #include "GeoDataPoint.h"
0010 #include "GeoDataPolygon.h"
0011 #include "GeoDataLinearRing.h"
0012 #include "GeoDataTrack.h"
0013 #include "GeoDataMultiGeometry.h"
0014 #include "TestUtils.h"
0015 
0016 
0017 namespace Marble
0018 {
0019 
0020 class TestGeometryDetach : public QObject
0021 {
0022     Q_OBJECT
0023 
0024 private Q_SLOTS:
0025     void initTestCase();
0026 
0027     /**
0028      * @brief testMultiGeometry shows that modifying a child at a given position
0029      * in a copied multi geometry doesn't modify the child at the same position
0030      * in the original one.
0031      */
0032     void testMultiGeometry();
0033 
0034     /**
0035      * @see above.
0036      */
0037     void testMultiTrack();
0038 
0039     /**
0040      * @brief testPoint shows that modifying the coordinates (using setCoordinate()
0041      * method) of a copied point doesn't modify the coordinates of the original one.
0042      */
0043     void testPoint();
0044 
0045     /**
0046      * @brief testPolygon shows that modifying the outerBoundary() of a copied
0047      * polygon doesn't modify the outer boundary of the original one. The same
0048      * applies for innerBoundaries().
0049      */
0050     void testPolygon();
0051 
0052 private:
0053     GeoDataCoordinates m_coords1;
0054     GeoDataCoordinates m_coords2;
0055 };
0056 
0057 void TestGeometryDetach::initTestCase()
0058 {
0059     m_coords1 = GeoDataCoordinates(30, 30, 0, GeoDataCoordinates::Degree);
0060     m_coords2 = GeoDataCoordinates(60, 60, 0, GeoDataCoordinates::Degree);
0061 }
0062 
0063 void TestGeometryDetach::testMultiGeometry()
0064 {
0065     GeoDataPoint *point = new GeoDataPoint;
0066     point->setCoordinates(m_coords1);
0067     GeoDataMultiGeometry multiGeom1;
0068     multiGeom1.append(point);
0069 
0070     GeoDataMultiGeometry multiGeom2 = multiGeom1;
0071     static_cast<GeoDataPoint*>(multiGeom2.child(0))->setCoordinates(m_coords2);
0072     QVERIFY(static_cast<GeoDataPoint*>(multiGeom1.child(0))->coordinates() == m_coords1);
0073 
0074     const GeoDataMultiGeometry multiGeom3 = multiGeom1;
0075     QVERIFY(static_cast<const GeoDataPoint*>(multiGeom3.child(0))->coordinates() == m_coords1);
0076 }
0077 
0078 void TestGeometryDetach::testMultiTrack()
0079 {
0080     GeoDataTrack *track = new GeoDataTrack();
0081     track->setAltitudeMode(Absolute);
0082     GeoDataMultiTrack multiTrack1;
0083     multiTrack1.append(track);
0084 
0085     GeoDataMultiTrack multiTrack2 = multiTrack1;
0086     multiTrack2.child(0)->setAltitudeMode(RelativeToSeaFloor);
0087     QVERIFY(multiTrack1.child(0)->altitudeMode() == Absolute);
0088 
0089     const GeoDataMultiTrack multiTrack3 = multiTrack1;
0090     QVERIFY(multiTrack3.child(0)->altitudeMode() == Absolute);
0091 }
0092 
0093 void TestGeometryDetach::testPoint()
0094 {
0095     GeoDataPoint point1;
0096     point1.setCoordinates(m_coords1);
0097 
0098     GeoDataPoint point2 = point1;
0099     point2.setCoordinates(m_coords2);
0100     QVERIFY(point1.coordinates() == m_coords1);
0101 
0102     const GeoDataPoint point3 = point1;
0103     QVERIFY(point3.coordinates() == m_coords1);
0104 }
0105 
0106 void TestGeometryDetach::testPolygon()
0107 {
0108     GeoDataPolygon poly1;
0109     poly1.outerBoundary().append(m_coords1);
0110     poly1.appendInnerBoundary(GeoDataLinearRing());
0111 
0112     GeoDataPolygon poly2 = poly1;
0113     poly2.outerBoundary().append(m_coords2);
0114     poly2.innerBoundaries().clear();
0115 
0116     QVERIFY(poly2.outerBoundary().size() == 2);
0117     QVERIFY(poly2.innerBoundaries().size() == 0);
0118     QVERIFY(poly1.outerBoundary().size() == 1);
0119     QVERIFY(poly1.innerBoundaries().size() == 1);
0120 
0121     const GeoDataPolygon poly3 = poly1;
0122     QVERIFY(poly3.outerBoundary().size() == 1);
0123     QVERIFY(poly3.innerBoundaries().size() == 1);
0124 }
0125 
0126 }
0127 
0128 QTEST_MAIN( Marble::TestGeometryDetach )
0129 
0130 #include "TestGeometryDetach.moc"