From f19cf6d56a1d3d09dbc64b497a6ed45410c523f4 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 23 Apr 2015 22:05:50 +0100 Subject: [PATCH] Packages: more unit-test coverage --- simgear/package/CatalogTest.cxx | 30 +++++++++++++- simgear/package/Package.cxx | 7 +++- simgear/package/Package.hxx | 4 +- simgear/package/catalogTest1/catalog.xml | 51 +++++++++++++++++++----- 4 files changed, 79 insertions(+), 13 deletions(-) diff --git a/simgear/package/CatalogTest.cxx b/simgear/package/CatalogTest.cxx index e2b98aca..12dd42d7 100644 --- a/simgear/package/CatalogTest.cxx +++ b/simgear/package/CatalogTest.cxx @@ -46,7 +46,7 @@ int parseTest() COMPARE(cat->description(), "First test catalog"); // check the packages too - COMPARE(cat->packages().size(), 2); + COMPARE(cat->packages().size(), 3); pkg::PackageRef p1 = cat->packages().front(); COMPARE(p1->catalog(), cat.ptr()); @@ -66,6 +66,34 @@ int parseTest() // test filtering / searching too + string_set tags(p2->tags()); + COMPARE(tags.size(), 4); + VERIFY(tags.find("ifr") != tags.end()); + VERIFY(tags.find("cessna") != tags.end()); + VERIFY(tags.find("jet") == tags.end()); + + + SGPropertyNode_ptr queryA(new SGPropertyNode); + queryA->setStringValue("tag", "ifr"); + VERIFY(p2->matches(queryA.ptr())); + + SGPropertyNode_ptr queryB(new SGPropertyNode); + queryB->setStringValue("name", "ces"); + VERIFY(p2->matches(queryB.ptr())); + + SGPropertyNode_ptr queryC(new SGPropertyNode); + queryC->setStringValue("name", "foo"); + VERIFY(!p2->matches(queryC.ptr())); + + SGPropertyNode_ptr queryD(new SGPropertyNode); + queryD->setIntValue("rating-FDM", 3); + VERIFY(p2->matches(queryD.ptr())); + + SGPropertyNode_ptr queryE(new SGPropertyNode); + queryE->setIntValue("rating-model", 5); + queryE->setStringValue("description", "cessna"); + VERIFY(p2->matches(queryE.ptr())); + delete root; return EXIT_SUCCESS; diff --git a/simgear/package/Package.cxx b/simgear/package/Package.cxx index 323334b1..59480486 100644 --- a/simgear/package/Package.cxx +++ b/simgear/package/Package.cxx @@ -186,6 +186,11 @@ std::string Package::description() const { return getLocalisedProp("description"); } + +string_set Package::tags() const +{ + return m_tags; +} SGPropertyNode* Package::properties() const { @@ -238,7 +243,7 @@ PackageList Package::dependencies() const // prefer local hangar package if possible, in case someone does something // silly with naming. Of course flightgear's aircraft search doesn't know - // about hanagrs, so names still need to be unique. + // about hangars, so names still need to be unique. PackageRef depPkg = m_catalog->getPackageById(depName); if (!depPkg) { Root* rt = m_catalog->root(); diff --git a/simgear/package/Package.hxx b/simgear/package/Package.hxx index 50783063..b7389920 100644 --- a/simgear/package/Package.hxx +++ b/simgear/package/Package.hxx @@ -112,7 +112,9 @@ public: { return m_catalog; } bool matches(const SGPropertyNode* aFilter) const; - + + string_set tags() const; + /** * download URLs for the package */ diff --git a/simgear/package/catalogTest1/catalog.xml b/simgear/package/catalogTest1/catalog.xml index 80e9983f..79879f2e 100644 --- a/simgear/package/catalogTest1/catalog.xml +++ b/simgear/package/catalogTest1/catalog.xml @@ -7,27 +7,58 @@ 8.1.* 8.0.0 8.2.0 - + alpha Alpha package 8 1234567 - + c172p Cessna 172-P A plane made by Cessna 42 34567 - - - cessna - ga - piston - ifr - + + cessna + ga + piston + ifr + + + 3 + 4 + 5 + 4 + + + + + org.flightgear.test.catalog1.common-sounds + 10 + + + + c172p-2d-panel + C172 with 2d panel only + + + + c172p-floats + C172 with floats + + + + c172p-skis + C172 with skis + + + + + common-sounds + Common sound files for test catalog aircraft + 10 - \ No newline at end of file -- 2.39.5