Debian Codegraph @

test_suite/unit_tests/Network/test_swiftAircraftManager.cxx

raw symbols SCIP
1 /*
2 * SPDX-FileCopyrightText: (C) 2022 Lars Toenning <[email protected]>
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
6 #include "test_swiftAircraftManager.hxx"
7
8 #include "test_suite/FGTestApi/testGlobals.hxx"
9
10 #include "Network/Swift/SwiftAircraftManager.h"
11 #include <Main/fg_props.hxx>
12 #include <Main/globals.hxx>
13
14 void SwiftAircraftManagerTest::setUp()
15 {
16 FGTestApi::setUp::initTestGlobals("SwiftService");
17 }
18
19 void SwiftAircraftManagerTest::tearDown()
20 {
21 FGTestApi::tearDown::shutdownTestGlobals();
22 }
23
24
25 std::vector<SGSharedPtr<FGAIBase>> SwiftAircraftManagerTest::getAIList()
26 {
27 return globals->get_subsystem<FGAIManager>()->get_ai_list();
28 }
29
30 void SwiftAircraftManagerTest::testAircraftManager()
31 {
32 globals->get_subsystem_mgr()->add<FGAIManager>();
33 globals->get_subsystem<FGAIManager>()->bind();
34 globals->get_subsystem<FGAIManager>()->init();
35
36 flightgear::swift::FGSwiftAircraftManager acm;
37 acm.addPlane("BER123", "PATH_TO_MODEL");
38 CPPUNIT_ASSERT_EQUAL(globals->get_subsystem<FGAIManager>()->get_ai_list().size(), (size_t)1);
39
40 acm.addPlane("BAW123", "PATH_TO_MODEL");
41 CPPUNIT_ASSERT_EQUAL(globals->get_subsystem<FGAIManager>()->get_ai_list().size(), (size_t)2);
42
43 for (auto& aircraft : getAIList()) {
44 CPPUNIT_ASSERT(!aircraft->getDie());
45 }
46
47 acm.removeAllPlanes();
48 for (auto& aircraft : getAIList()) {
49 CPPUNIT_ASSERT(aircraft->getDie());
50 }
51
52 acm.addPlane("BER123", "PATH_TO_MODEL");
53 CPPUNIT_ASSERT(!getAIList()[2]->getDie());
54 acm.removePlane("BER123");
55 CPPUNIT_ASSERT(getAIList()[2]->getDie());
56
57 // Test position updates
58 acm.addPlane("SAS123", "PATH_TO_MODEL");
59 SGGeod position;
60 position.setLatitudeDeg(50.0);
61 position.setLongitudeDeg(6.0);
62 position.setElevationM(1024);
63
64 acm.updatePlanes({{"SAS123", position, SGVec3d(1.0, 2.0, 3.0), 200, false}});
65 CPPUNIT_ASSERT_EQUAL(fgGetString("/ai/models/swift[3]/callsign"), std::string("SAS123"));
66 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/orientation/pitch-deg"), 1.0, 0.1);
67 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/orientation/roll-deg"), 2.0, 0.1);
68 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/orientation/true-heading-deg"), 3.0, 0.1);
69 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/position/latitude-deg"), 50.0, 0.1);
70 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/position/longitude-deg"), 6.0, 0.1);
71 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/velocities/true-airspeed-kt"), 200, 0.1);
72
73 position.setLatitudeDeg(20.0);
74 position.setLongitudeDeg(4.0);
75 acm.updatePlanes({{"SAS123", position, SGVec3d(5.0, 6.0, 7.0), 400, false}});
76 CPPUNIT_ASSERT_EQUAL(fgGetString("/ai/models/swift[3]/callsign"), std::string("SAS123"));
77 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/orientation/pitch-deg"), 5.0, 0.1);
78 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/orientation/roll-deg"), 6.0, 0.1);
79 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/orientation/true-heading-deg"), 7.0, 0.1);
80 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/position/latitude-deg"), 20.0, 0.1);
81 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/position/longitude-deg"), 4.0, 0.1);
82 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/velocities/true-airspeed-kt"), 400, 0.1);
83
84
85 // Update another aircraft
86 acm.addPlane("DAL123", "PATH_TO_MODEL");
87 position.setLatitudeDeg(-20.0);
88 position.setLongitudeDeg(5.0);
89 acm.updatePlanes({{"DAL123", position, SGVec3d(1.0, 1.0, 1.0), 250, false}});
90 CPPUNIT_ASSERT_EQUAL(fgGetString("/ai/models/swift[4]/callsign"), std::string("DAL123"));
91 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[4]/orientation/pitch-deg"), 1.0, 0.1);
92 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[4]/orientation/roll-deg"), 1.0, 0.1);
93 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[4]/orientation/true-heading-deg"), 1.0, 0.1);
94 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[4]/position/latitude-deg"), -20.0, 0.1);
95 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[4]/position/longitude-deg"), 5.0, 0.1);
96 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[4]/velocities/true-airspeed-kt"), 250, 0.1);
97
98 CPPUNIT_ASSERT_EQUAL(fgGetString("/ai/models/swift[3]/callsign"), std::string("SAS123"));
99 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/orientation/pitch-deg"), 5.0, 0.1);
100 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/orientation/roll-deg"), 6.0, 0.1);
101 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/orientation/true-heading-deg"), 7.0, 0.1);
102 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/position/latitude-deg"), 20.0, 0.1);
103 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/position/longitude-deg"), 4.0, 0.1);
104 CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/ai/models/swift[3]/velocities/true-airspeed-kt"), 400, 0.1);
105 }