Debian Codegraph @

test_suite/unit_tests/Navaids/test_navaids2.cxx

raw symbols SCIP
1 #include "test_navaids2.hxx"
2
3 #include "test_suite/FGTestApi/testGlobals.hxx"
4 #include "test_suite/FGTestApi/NavDataCache.hxx"
5
6 #include <Airports/airport.hxx>
7
8 #include <Navaids/NavDataCache.hxx>
9 #include <Navaids/navrecord.hxx>
10 #include <Navaids/navlist.hxx>
11
12
13 // Set up function for each test.
14 void NavaidsTests::setUp()
15 {
16 FGTestApi::setUp::initTestGlobals("navaids2");
17 FGTestApi::setUp::initNavDataCache();
18 }
19
20
21 // Clean up after each test.
22 void NavaidsTests::tearDown()
23 {
24 FGTestApi::tearDown::shutdownTestGlobals();
25 }
26
27
28 void NavaidsTests::testBasic()
29 {
30 SGGeod egccPos = SGGeod::fromDeg(-2.27, 53.35);
31 FGNavRecordRef tla = FGNavList::findByFreq(115.7, egccPos);
32
33 CPPUNIT_ASSERT_EQUAL(strcmp(tla->get_ident(), "TNT"), 0);
34 CPPUNIT_ASSERT(tla->ident() == "TNT");
35 CPPUNIT_ASSERT(tla->name() == "TRENT VOR-DME");
36 CPPUNIT_ASSERT_EQUAL(tla->get_freq(), 11570);
37 CPPUNIT_ASSERT_EQUAL(tla->get_range(), 130);
38 }
39
40 void NavaidsTests::testCustomWaypoint()
41 {
42 // create a transaction, which we don't commit, to avoid making permanent DB changes
43 flightgear::NavDataCache::Transaction txn(flightgear::NavDataCache::instance());
44
45 SGGeod egccPos = SGGeod::fromDeg(-2.27, 53.35);
46 SGGeod offsetPos = SGGeodesy::direct(egccPos, 45.0, 20.0 * SG_NM_TO_METER);
47 auto poi = FGPositioned::createWaypoint(FGPositioned::WAYPOINT,
48 "TEST_WP0", offsetPos, false, "Lovely Waypoint");
49 CPPUNIT_ASSERT(poi);
50 CPPUNIT_ASSERT_EQUAL(poi->ident(), std::string{"TEST_WP0"});
51 CPPUNIT_ASSERT_EQUAL(poi->name(), std::string{"Lovely Waypoint"});
52 CPPUNIT_ASSERT(poi->guid() > 0);
53 CPPUNIT_ASSERT_EQUAL(poi->type(), FGPositioned::WAYPOINT);
54 CPPUNIT_ASSERT(FGTestApi::geodsApproximatelyEqual(offsetPos, poi->geod()));
55
56 // same but a FIX
57 SGGeod offsetPos2 = SGGeodesy::direct(egccPos, 180.0, 35.0 * SG_NM_TO_METER);
58 auto fix = FGPositioned::createWaypoint(FGPositioned::FIX,
59 "TEST_WP1", offsetPos2);
60 CPPUNIT_ASSERT_EQUAL(fix->ident(), std::string{"TEST_WP1"});
61 CPPUNIT_ASSERT_EQUAL(fix->name(), fix->ident());
62 CPPUNIT_ASSERT(fix->guid() > 0);
63 CPPUNIT_ASSERT_EQUAL(fix->type(), FGPositioned::FIX);
64 CPPUNIT_ASSERT(FGTestApi::geodsApproximatelyEqual(offsetPos2, fix->geod()));
65
66 // create same ident but far away
67 FGAirportRef vhhh = FGAirport::getByIdent("VHHH");
68
69 SGGeod pos3 = SGGeodesy::direct(vhhh->geod(), 10.0, 10.0 * SG_NM_TO_METER);
70 auto poi3 = FGPositioned::createWaypoint(FGPositioned::WAYPOINT,
71 "TEST_WP0", pos3, false, "Lovely Hong Kong Waypoint");
72 CPPUNIT_ASSERT_EQUAL(poi3->ident(), std::string{"TEST_WP0"});
73 CPPUNIT_ASSERT_EQUAL(poi3->name(), std::string{"Lovely Hong Kong Waypoint"});
74 CPPUNIT_ASSERT(FGTestApi::geodsApproximatelyEqual(pos3, poi3->geod()));
75
76 // create same ident but nearby
77 SGGeod pos4 = SGGeodesy::direct(egccPos, 270.0, 10.0 * SG_NM_TO_METER);
78 auto duplicatePoi = FGPositioned::createWaypoint(FGPositioned::WAYPOINT,
79 "TEST_WP0", pos4, false, "Lovely Waypoint");
80 CPPUNIT_ASSERT_EQUAL(duplicatePoi, poi);
81
82 // create with invalid type
83 CPPUNIT_ASSERT_THROW(FGPositioned::createWaypoint(FGPositioned::VOR,
84 "TEST_WP99", offsetPos),
85 std::logic_error);
86
87
88 FGPositioned::TypeFilter filt(FGPositioned::WAYPOINT);
89 FGPositionedList wps = FGPositioned::findAllWithIdent("TEST_WP0", &filt);
90 CPPUNIT_ASSERT_EQUAL(wps.size(), static_cast<size_t>(2));
91
92 CPPUNIT_ASSERT(FGPositioned::deleteWaypoint(poi));
93 wps = FGPositioned::findAllWithIdent("TEST_WP0", &filt);
94 CPPUNIT_ASSERT_EQUAL(wps.size(), static_cast<size_t>(1));
95 }
96
97 void NavaidsTests::testTemporaryWaypoint()
98 {
99 SGGeod egccPos = SGGeod::fromDeg(-2.27, 53.35);
100 SGGeod offsetPos = SGGeodesy::direct(egccPos, 45.0, 5.0 * SG_NM_TO_METER);
101 auto poi = FGPositioned::createWaypoint(FGPositioned::WAYPOINT,
102 "TEST_WP_TEMP0", offsetPos, true, "Lovely Waypoint");
103 CPPUNIT_ASSERT(poi);
104 CPPUNIT_ASSERT_EQUAL(poi->ident(), std::string{"TEST_WP_TEMP0"});
105 CPPUNIT_ASSERT_EQUAL(poi->name(), std::string{"Lovely Waypoint"});
106 CPPUNIT_ASSERT(poi->guid() < 0);
107 CPPUNIT_ASSERT_EQUAL(poi->type(), FGPositioned::WAYPOINT);
108 CPPUNIT_ASSERT(FGTestApi::geodsApproximatelyEqual(offsetPos, poi->geod()));
109
110 FGPositioned::TypeFilter filt(FGPositioned::WAYPOINT);
111 FGPositionedList wps = FGPositioned::findAllWithIdent("TEST_WP_TEMP0", &filt);
112 CPPUNIT_ASSERT_EQUAL(wps.size(), static_cast<size_t>(1));
113 CPPUNIT_ASSERT_EQUAL(wps.front(), poi);
114
115 // check temporary points are found spatially
116 auto closest = FGPositioned::findClosestN(egccPos, 1, 50.0, &filt);
117 CPPUNIT_ASSERT_EQUAL(closest.size(), static_cast<size_t>(1));
118 CPPUNIT_ASSERT_EQUAL(closest.front(), poi);
119
120 auto byName = FGPositioned::findAllWithName("lovely", &filt, false);
121 CPPUNIT_ASSERT_EQUAL(byName.size(), static_cast<size_t>(1));
122 CPPUNIT_ASSERT_EQUAL(byName.front(), poi);
123
124
125 // check for gross position update working
126 FGAirportRef vhhh = FGAirport::getByIdent("VHHH");
127 // auto asPoi = fgpositioned_cast<POI>(poi);
128 SGGeod newOffsetPos = SGGeodesy::direct(vhhh->geod(), 10.0, 10.0 * SG_NM_TO_METER);
129 // asPoi->modifyPosition(newOffsetPos);
130 flightgear::NavDataCache::instance()->updatePosition(poi->guid(), newOffsetPos);
131
132 CPPUNIT_ASSERT(FGTestApi::geodsApproximatelyEqual(newOffsetPos, poi->geod()));
133
134 closest = FGPositioned::findClosestN(egccPos, 1, 50.0, &filt);
135 CPPUNIT_ASSERT_EQUAL(closest.size(), static_cast<size_t>(0));
136
137 closest = FGPositioned::findClosestN(vhhh->geod(), 1, 50.0, &filt);
138 CPPUNIT_ASSERT_EQUAL(closest.size(), static_cast<size_t>(1));
139 CPPUNIT_ASSERT_EQUAL(closest.front(), poi);
140
141 // delete it
142 CPPUNIT_ASSERT(FGPositioned::deleteWaypoint(poi));
143 wps = FGPositioned::findAllWithIdent("TEST_WP_TEMP0", &filt);
144 CPPUNIT_ASSERT_EQUAL(wps.size(), static_cast<size_t>(0));
145
146 closest = FGPositioned::findClosestN(vhhh->geod(), 1, 50.0, &filt);
147 CPPUNIT_ASSERT_EQUAL(closest.size(), static_cast<size_t>(0));
148 }