From 14c729027cb7f41a26a6ea9545b71ee44d623457 Mon Sep 17 00:00:00 2001 From: legoboyvdlp R Date: Sun, 24 May 2020 23:41:43 +0100 Subject: [PATCH] Tests for cloning flightplan. Two initial tests: basic flightplan and with fgfp-loaded flightplan --- .../unit_tests/Navaids/test_flightplan.cxx | 99 +++++++++++++++++++ .../unit_tests/Navaids/test_flightplan.hxx | 4 + 2 files changed, 103 insertions(+) diff --git a/test_suite/unit_tests/Navaids/test_flightplan.cxx b/test_suite/unit_tests/Navaids/test_flightplan.cxx index aa842aa20..1878230ba 100644 --- a/test_suite/unit_tests/Navaids/test_flightplan.cxx +++ b/test_suite/unit_tests/Navaids/test_flightplan.cxx @@ -851,3 +851,102 @@ void FlightplanTests::loadFGFPWithProcedureIdents() CPPUNIT_ASSERT_EQUAL(f->star()->ident(), string{"EEL1A"}); CPPUNIT_ASSERT_EQUAL(f->starTransition()->ident(), string{"KUBAT"}); } + +void FlightplanTests::testCloningBasic() +{ + FlightPlanRef fp1 = makeTestFP("EGCC", "23L", "EHAM", "24", + "TNT CLN"); + fp1->setIdent("testplan"); + + auto fp2 = fp1->clone("testplan2"); + + CPPUNIT_ASSERT(fp2->ident() == "testplan2"); + CPPUNIT_ASSERT(fp2->departureAirport()->ident() == "EGCC"); + CPPUNIT_ASSERT(fp2->departureRunway()->ident() == "23L"); + CPPUNIT_ASSERT(fp2->destinationAirport()->ident() == "EHAM"); + CPPUNIT_ASSERT(fp2->destinationRunway()->ident() == "24"); + + CPPUNIT_ASSERT_EQUAL(5, fp2->numLegs()); + + CPPUNIT_ASSERT(fp2->legAtIndex(0)->waypoint()->source()->ident() == "23L"); + CPPUNIT_ASSERT(fp2->legAtIndex(1)->waypoint()->source()->ident() == "TNT"); + CPPUNIT_ASSERT(fp2->legAtIndex(2)->waypoint()->source()->ident() == "CLN"); + +} + +void FlightplanTests::testCloningFGFP() +{ + static_factory = std::make_shared(); + FlightPlan::registerDelegateFactory(static_factory); + + FlightPlanRef fp1 = new FlightPlan; + + SGPath fgfpPath = simgear::Dir::current().path() / "test_fgfp_cloning.fgfp"; + { + sg_ofstream s(fgfpPath); + s << R"( + + 2 + + EDDM + 08R + + + EDDF + + + + navaid + GIVMI + 11.364700 + 48.701100 + + + navaid + ERNAS + 11.219400 + 48.844700 + + + navaid + TALAL + 11.085300 + 49.108300 + + + navaid + ERMEL + 11.044700 + 49.187800 + + + navaid + PSA + 9.348300 + 49.862200 + + + + )"; + } + + auto ourDelegate = TestFPDelegateFactory::delegateForPlan(fp1); + CPPUNIT_ASSERT(!ourDelegate->didLoad); + + CPPUNIT_ASSERT(fp1->load(fgfpPath)); + + CPPUNIT_ASSERT(ourDelegate->didLoad); + CPPUNIT_ASSERT(ourDelegate->sawArrivalChange); + CPPUNIT_ASSERT(ourDelegate->sawDepartureChange); + + auto fp2 = fp1->clone(); + CPPUNIT_ASSERT(fp2->departureAirport()->ident() == "EDDM"); + CPPUNIT_ASSERT(fp2->departureRunway()->ident() == "08R"); + CPPUNIT_ASSERT(fp2->destinationAirport()->ident() == "EDDF"); + + CPPUNIT_ASSERT(fp2->legAtIndex(0)->waypoint()->source()->ident() == "08R"); + CPPUNIT_ASSERT(fp2->legAtIndex(1)->waypoint()->source()->ident() == "GIVMI"); + CPPUNIT_ASSERT(fp2->legAtIndex(6)->waypoint()->source()->ident() == "PSA"); + CPPUNIT_ASSERT_EQUAL(7, fp2->numLegs()); + +} \ No newline at end of file diff --git a/test_suite/unit_tests/Navaids/test_flightplan.hxx b/test_suite/unit_tests/Navaids/test_flightplan.hxx index 06411e006..970acc037 100644 --- a/test_suite/unit_tests/Navaids/test_flightplan.hxx +++ b/test_suite/unit_tests/Navaids/test_flightplan.hxx @@ -49,6 +49,8 @@ class FlightplanTests : public CppUnit::TestFixture CPPUNIT_TEST(loadFGFPWithEmbeddedProcedures); CPPUNIT_TEST(loadFGFPWithOldProcedures); CPPUNIT_TEST(loadFGFPWithProcedureIdents); + CPPUNIT_TEST(testCloningBasic); + CPPUNIT_TEST(testCloningFGFP); // CPPUNIT_TEST(testParseICAORoute); // CPPUNIT_TEST(testParseICANLowLevelRoute); @@ -82,6 +84,8 @@ public: void loadFGFPWithEmbeddedProcedures(); void loadFGFPWithOldProcedures(); void loadFGFPWithProcedureIdents(); + void testCloningBasic(); + void testCloningFGFP(); }; #endif // FG_FLIGHTPLAN_UNIT_TESTS_HXX