Skip to content

Commit b401a03

Browse files
committed
Move and revise testFindFeatures
1 parent 1bf23da commit b401a03

File tree

4 files changed

+70
-93
lines changed

4 files changed

+70
-93
lines changed

test/object_query_t.cpp

Lines changed: 4 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2016 Mitchell Krome
3-
* Copyright 2017-2022, 2025 Kai Pastor
3+
* Copyright 2017-2022 Kai Pastor
44
*
55
* This file is part of OpenOrienteering.
66
*
@@ -20,25 +20,20 @@
2020

2121
#include "object_query_t.h"
2222

23-
#include <algorithm>
2423
#include <memory>
24+
#include <algorithm>
2525

2626
#include <QtGlobal>
2727
#include <QtTest>
2828
#include <QByteArray>
2929
#include <QLatin1String>
3030
#include <QString>
3131

32-
#include "global.h"
3332
#include "core/map.h"
34-
#include "core/map_part.h"
3533
#include "core/objects/object.h"
36-
#include "core/objects/object_query.h"
3734
#include "core/objects/text_object.h"
35+
#include "core/objects/object_query.h"
3836
#include "core/symbols/point_symbol.h"
39-
#include "gui/main_window.h"
40-
#include "gui/map/map_editor.h"
41-
#include "gui/map/map_find_feature.h"
4237

4338
using namespace OpenOrienteering;
4439

@@ -58,7 +53,6 @@ ObjectQueryTest::ObjectQueryTest(QObject* parent)
5853
// nothing
5954
}
6055

61-
6256
const Object* ObjectQueryTest::testObject()
6357
{
6458
static TextObject obj;
@@ -515,88 +509,11 @@ void ObjectQueryTest::testParser()
515509
}
516510

517511

518-
void ObjectQueryTest::testFindObjects()
519-
{
520-
Q_INIT_RESOURCE(resources);
521-
doStaticInitializations();
522-
523-
Map map;
524-
auto* window = new MainWindow();
525-
auto* editor = new MapEditorController(MapEditorController::MapEditor, &map);
526-
window->setController(editor);
527-
const auto* part = map.getCurrentPart();
528-
529-
auto* point_symbol_1 = new PointSymbol();
530-
point_symbol_1->setNumberComponent(0, 123);
531-
map.addSymbol(point_symbol_1, 0);
532-
auto* point_object_1 = new PointObject(point_symbol_1);
533-
point_object_1->setTag(QLatin1String("match"), QLatin1String("yes"));
534-
QVERIFY(map.addObject(point_object_1) == 0); // object pos 0
535-
536-
auto* point_object_2 = new PointObject(point_symbol_1);
537-
point_object_2->setTag(QLatin1String("match"), QLatin1String("no"));
538-
QVERIFY(map.addObject(point_object_2) == 1); // object pos 1
539-
540-
point_object_2 = new PointObject(point_symbol_1);
541-
point_object_2->setTag(QLatin1String("match"), QLatin1String("yes"));
542-
QVERIFY(map.addObject(point_object_2) == 2); // object pos 2
543-
544-
auto* point_symbol_2 = new PointSymbol();
545-
point_symbol_2->setNumberComponent(0, 124);
546-
point_symbol_2->setHidden(true);
547-
map.addSymbol(point_symbol_2, 1);
548-
point_object_2 = new PointObject(point_symbol_2);
549-
point_object_2->setTag(QLatin1String("match"), QLatin1String("yes"));
550-
QVERIFY(map.addObject(point_object_2) == 3); // object pos 3
551-
552-
point_object_2 = new PointObject(point_symbol_1);
553-
point_object_2->setTag(QLatin1String("match"), QLatin1String("yes"));
554-
QVERIFY(map.addObject(point_object_2) == 4); // object pos 4
555-
556-
auto* point_symbol_3 = new PointSymbol();
557-
point_symbol_3->setNumberComponent(0, 125);
558-
point_symbol_3->setProtected(true);
559-
map.addSymbol(point_symbol_3, 2);
560-
point_object_2 = new PointObject(point_symbol_3);
561-
point_object_2->setTag(QLatin1String("match"), QLatin1String("yes"));
562-
QVERIFY(map.addObject(point_object_2) == 5); // object pos 5
563-
564-
std::unique_ptr<MapFindFeature> find_feature = std::make_unique<MapFindFeature>(*editor);
565-
ObjectQuery single_query_is_true{QLatin1String("match"), ObjectQuery::OperatorIs, QLatin1String("yes")};
566-
567-
map.clearObjectSelection(false);
568-
auto symbol_query = ObjectQuery(single_query_is_true);
569-
find_feature->findAllMatchingObjects(symbol_query);
570-
QVERIFY(map.getNumSelectedObjects() == 3); // matching objects at pos 0, 2, 4 while ignoring objects at pos 1, 3, 5
571-
572-
map.clearObjectSelection(false);
573-
find_feature->findNextMatchingObject(symbol_query);
574-
QVERIFY(map.getNumSelectedObjects() == 1);
575-
auto* selected_object = map.getFirstSelectedObject();
576-
QCOMPARE(part->findObjectIndex(selected_object), 4); // search first returns the last matching object
577-
578-
find_feature->findNextMatchingObject(symbol_query);
579-
QVERIFY(map.getNumSelectedObjects() == 1);
580-
selected_object = map.getFirstSelectedObject();
581-
QCOMPARE(part->findObjectIndex(selected_object), 2);
582-
583-
find_feature->findNextMatchingObject(symbol_query);
584-
QVERIFY(map.getNumSelectedObjects() == 1);
585-
selected_object = map.getFirstSelectedObject();
586-
QCOMPARE(part->findObjectIndex(selected_object), 0);
587-
588-
find_feature->findNextMatchingObject(symbol_query);
589-
QVERIFY(map.getNumSelectedObjects() == 1);
590-
selected_object = map.getFirstSelectedObject();
591-
QCOMPARE(part->findObjectIndex(selected_object), 4);
592-
}
593-
594-
595512
/*
596513
* We don't need a real GUI window.
597514
*/
598515
namespace {
599-
auto const Q_DECL_UNUSED qpa_selected = qputenv("QT_QPA_PLATFORM", "minimal"); // clazy:exclude=non-pod-global-static
516+
auto Q_DECL_UNUSED qpa_selected = qputenv("QT_QPA_PLATFORM", "minimal"); // clazy:exclude=non-pod-global-static
600517
}
601518

602519

test/object_query_t.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2016 Mitchell Krome
3-
* Copyright 2017-2020, 2025 Kai Pastor
3+
* Copyright 2017-2020 Kai Pastor
44
*
55
* This file is part of OpenOrienteering.
66
*
@@ -48,7 +48,6 @@ private slots:
4848
void testNegation();
4949
void testToString();
5050
void testParser();
51-
void testFindObjects();
5251

5352
private:
5453
const Object* testObject();

test/tools_t.cpp

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright 2012, 2013 Thomas Schöps
3-
* Copyright 2015-2020 Kai Pastor
3+
* Copyright 2015-2020, 2025 Kai Pastor
4+
* Copyright 2025 Matthias Kühlewein
45
*
56
* This file is part of OpenOrienteering.
67
*
@@ -35,10 +36,13 @@
3536
#include "core/map_color.h"
3637
#include "core/map_coord.h"
3738
#include "core/objects/object.h"
39+
#include "core/objects/object_query.h"
3840
#include "core/symbols/line_symbol.h"
41+
#include "core/symbols/point_symbol.h"
3942
#include "global.h"
4043
#include "gui/main_window.h"
4144
#include "gui/map/map_editor.h"
45+
#include "gui/map/map_find_feature.h"
4246
#include "gui/map/map_widget.h"
4347
#include "templates/paint_on_template_feature.h"
4448
#include "tools/edit_point_tool.h"
@@ -161,7 +165,7 @@ void TestMapEditor::simulateDrag(const QPointF& start_pos, const QPointF& end_po
161165
}
162166

163167

164-
// ### TestTools ###
168+
// ### ToolsTest ###
165169

166170
void ToolsTest::initTestCase()
167171
{
@@ -229,14 +233,69 @@ void ToolsTest::paintOnTemplateFeature()
229233
}
230234

231235

236+
void ToolsTest::testFindObjects()
237+
{
238+
auto* map = new Map;
239+
{
240+
auto* normal_point_symbol = new PointSymbol();
241+
map->addSymbol(normal_point_symbol, 0);
242+
243+
auto* hidden_point_symbol = new PointSymbol();
244+
hidden_point_symbol->setHidden(true);
245+
map->addSymbol(hidden_point_symbol, 1);
246+
247+
auto* protected_point_symbol = new PointSymbol();
248+
protected_point_symbol->setProtected(true);
249+
map->addSymbol(protected_point_symbol, 2);
250+
251+
auto add_object = [map](Symbol* symbol, const char* label) {
252+
auto* object = new PointObject(symbol);
253+
object->setTag(QLatin1String("match"), QLatin1String(label));
254+
map->addObject(object);
255+
};
256+
add_object(normal_point_symbol, "yes"); // expected match
257+
add_object(normal_point_symbol, "no");
258+
add_object(normal_point_symbol, "yes"); // expected match
259+
add_object(hidden_point_symbol, "yes");
260+
add_object(normal_point_symbol, "yes"); // expected match
261+
add_object(protected_point_symbol, "yes");
262+
}
263+
264+
TestMapEditor editor(map); // taking ownership
265+
MapFindFeature find_feature {*editor.editor};
266+
ObjectQuery query {QLatin1String("match"), ObjectQuery::OperatorIs, QLatin1String("yes")};
267+
268+
map->clearObjectSelection(false);
269+
find_feature.findAllMatchingObjects(query);
270+
QCOMPARE(map->getNumSelectedObjects(), 3);
271+
272+
map->clearObjectSelection(false);
273+
find_feature.findNextMatchingObject(query);
274+
QCOMPARE(map->getNumSelectedObjects(), 1);
275+
auto* first_match = map->getFirstSelectedObject();
276+
277+
find_feature.findNextMatchingObject(query);
278+
QCOMPARE(map->getNumSelectedObjects(), 1);
279+
QVERIFY(map->getFirstSelectedObject() != first_match);
280+
281+
find_feature.findNextMatchingObject(query);
282+
QCOMPARE(map->getNumSelectedObjects(), 1);
283+
QVERIFY(map->getFirstSelectedObject() != first_match);
284+
285+
find_feature.findNextMatchingObject(query);
286+
QCOMPARE(map->getNumSelectedObjects(), 1);
287+
QVERIFY(map->getFirstSelectedObject() == first_match);
288+
}
289+
290+
232291
/*
233292
* We select a non-standard QPA because we don't need a real GUI window.
234293
*
235294
* Normally, the "offscreen" plugin would be the correct one.
236295
* However, it bails out with a QFontDatabase error (cf. QTBUG-33674)
237296
*/
238297
namespace {
239-
auto Q_DECL_UNUSED qpa_selected = qputenv("QT_QPA_PLATFORM", "minimal"); // clazy:exclude=non-pod-global-static
298+
auto const Q_DECL_UNUSED qpa_selected = qputenv("QT_QPA_PLATFORM", "minimal"); // clazy:exclude=non-pod-global-static
240299
}
241300

242301

test/tools_t.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2012, 2013 Thomas Schöps
3-
* Copyright 2017 Kai Pastor
3+
* Copyright 2017, 2020, 2025 Kai Pastor
44
*
55
* This file is part of OpenOrienteering.
66
*
@@ -36,6 +36,8 @@ private slots:
3636
void editTool();
3737

3838
void paintOnTemplateFeature();
39+
40+
void testFindObjects();
3941
};
4042

4143
#endif

0 commit comments

Comments
 (0)