File: TestFeatureDetach.cpp

package info (click to toggle)
marble 4%3A25.08.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 159,996 kB
  • sloc: cpp: 191,890; xml: 39,908; ansic: 7,204; python: 2,190; sh: 1,187; makefile: 235; perl: 218; ruby: 97; java: 66
file content (148 lines) | stat: -rw-r--r-- 4,665 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// SPDX-License-Identifier: LGPL-2.1-or-later
//
// SPDX-FileCopyrightText: 2014 Calin Cruceru <calin@rosedu.org>
//

#include <QObject>

#include "GeoDataCamera.h"
#include "GeoDataContainer.h"
#include "GeoDataPlacemark.h"
#include "GeoDataPlaylist.h"
#include "GeoDataPoint.h"
#include "GeoDataRelation.h"
#include "GeoDataTour.h"
#include "MarbleGlobal.h"
#include "TestUtils.h"

namespace Marble
{

class TestFeatureDetach : public QObject
{
    Q_OBJECT

private Q_SLOTS:
    /**
     * FIXME: Doesn't work for the moment because calling detach() in
     * GeoDataFeature::set/abstractView() doesn't help because the object
     * isn't deep-copied in the private class.
     *
     * @brief testRelation shows that getting the abstractView() of a copied
     * feature and modifying it doesn't modify the original one.
     */
    void testRelation();

    /**
     * @brief testDocument shows that getting some child and modifying it,
     * doesn't modify the child at the same position in the original container.
     */
    void testDocument();

    /**
     * @brief testPlacemark shows that getting the geometry() and modifying it
     * doesn't modify the geometry of the original placemark.
     */
    void testPlacemark();

    /**
     * @brief testTour shows that modifying the playlist of a copied tour doesn't
     * modify the playlist of the original one.
     */
    void testTour();

    /**
     * @brief testGeometryParentInPlacemark shows that copying a placemark correctly
     * keeps the geometries of both the copied one and the original one pointing to its
     * parent. Before the changes made in GeoDataPlacemark (calling setParent() after
     * each detach() call and not calling anymore in the
     * GeoDataPlacemark( const GeoDataGeometry &other ) constructor), after the operation
     * highlighted in this test, the geometry of the first one (the original one) ended
     * pointing (its parent) to the second placemark and the second one had its geometry's
     * parent a null pointer.
     */
    void testGeometryParentInPlacemark();
};

void TestFeatureDetach::testRelation()
{
    GeoDataRelation feat1;
    auto view1 = new GeoDataCamera();
    view1->setAltitudeMode(Absolute);
    feat1.setAbstractView(view1);

    GeoDataRelation feat2 = feat1;
    feat2.abstractView()->setAltitudeMode(ClampToSeaFloor);
    // FIXME: See above (method description).
    // QVERIFY(feat1.abstractView()->altitudeMode() == Absolute);
}

void TestFeatureDetach::testDocument()
{
    GeoDataDocument cont1;
    GeoDataFeature *feat1 = new GeoDataPlacemark();
    feat1->setName("Feat1");
    cont1.insert(0, feat1);

    GeoDataDocument cont2 = cont1;
    cont2.child(0)->setName("Feat2");
    QCOMPARE(cont1.child(0)->name(), QLatin1StringView("Feat1"));

    const GeoDataDocument cont3 = cont1;
    QCOMPARE(cont3.child(0)->name(), QLatin1StringView("Feat1"));
}

void TestFeatureDetach::testPlacemark()
{
    GeoDataCoordinates coords1(30, 30, 0, GeoDataCoordinates::Degree);
    GeoDataPlacemark place1;
    place1.setCoordinate(coords1);

    GeoDataPlacemark place2 = place1;

    GeoDataCoordinates coords2(60, 60, 0, GeoDataCoordinates::Degree);
    auto point = static_cast<GeoDataPoint *>(place2.geometry());
    point->setCoordinates(coords2);
    QVERIFY(place1.coordinate() == coords1);

    const GeoDataPlacemark place3 = place1;
    QVERIFY(place3.coordinate() == coords1);
}

void TestFeatureDetach::testTour()
{
    auto newPlaylist = new GeoDataPlaylist;
    newPlaylist->setId("Playlist1");
    GeoDataTour tour1;
    tour1.setPlaylist(newPlaylist);

    GeoDataTour tour2 = tour1;
    tour2.playlist()->setId("Playlist2");
    QCOMPARE(tour1.playlist()->id(), QLatin1StringView("Playlist1"));

    const GeoDataTour tour3 = tour1;
    QCOMPARE(tour3.playlist()->id(), QLatin1StringView("Playlist1"));
}

void TestFeatureDetach::testGeometryParentInPlacemark()
{
    GeoDataPlacemark place1;
    QVERIFY(place1.geometry()->parent() == &place1);

    GeoDataPlacemark place2 = place1;

    // With the changes (regarding setParent() multiple calls after each
    // detach() call) the only moment when some invariant is broken is right now,
    // after the copy constructor has been called and no other method (which calls
    // detach()) hasn't. This is because the geometry is not immediately copied,
    // so the geometry of place2 has as parent place1. This is immediately solved
    // when calling geometry() below.
    QVERIFY(place2.geometry()->parent() == &place2);
    QVERIFY(place1.geometry()->parent() == &place1);
}

}

QTEST_MAIN(Marble::TestFeatureDetach)

#include "TestFeatureDetach.moc"