From b7fbb7956535ea89cdf6f9d1a77fc8799efd93b0 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 22 Apr 2015 23:38:40 +0100 Subject: [PATCH] Package work on version support. - start adding test coverage for packages --- simgear/package/CMakeLists.txt | 12 +++++ simgear/package/Catalog.cxx | 23 ++++----- simgear/package/CatalogTest.cxx | 59 ++++++++++++++++++++++++ simgear/package/catalogTest1/catalog.xml | 9 ++++ 4 files changed, 92 insertions(+), 11 deletions(-) create mode 100644 simgear/package/CatalogTest.cxx create mode 100644 simgear/package/catalogTest1/catalog.xml diff --git a/simgear/package/CMakeLists.txt b/simgear/package/CMakeLists.txt index 33672680..37e7a504 100644 --- a/simgear/package/CMakeLists.txt +++ b/simgear/package/CMakeLists.txt @@ -26,3 +26,15 @@ if(ENABLE_PKGUTIL) add_executable(sg_pkgutil pkgutil.cxx) target_link_libraries(sg_pkgutil ${TEST_LIBS}) endif() + +if(ENABLE_TESTS) + +add_executable(catalog_test CatalogTest.cxx) +target_link_libraries(catalog_test ${TEST_LIBS}) + +set_target_properties(catalog_test PROPERTIES + COMPILE_DEFINITIONS "SRC_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"" ) + +add_test(catalog_test ${EXECUTABLE_OUTPUT_PATH}/catalog_test) + +endif(ENABLE_TESTS) \ No newline at end of file diff --git a/simgear/package/Catalog.cxx b/simgear/package/Catalog.cxx index ac33ffb3..c12a53a0 100644 --- a/simgear/package/Catalog.cxx +++ b/simgear/package/Catalog.cxx @@ -39,9 +39,19 @@ namespace pkg { bool checkVersion(const std::string& aVersion, SGPropertyNode_ptr props) { BOOST_FOREACH(SGPropertyNode* v, props->getChildren("version")) { - if (v->getStringValue() == aVersion) { + std::string s(v->getStringValue()); + if (s== aVersion) { return true; } + + // allow 3.5.* to match any of 3.5.0, 3.5.1rc1, 3.5.11 or so on + if (strutils::ends_with(s, ".*")) { + size_t lastDot = aVersion.rfind('.'); + std::string ver = aVersion.substr(0, lastDot); + if (ver == s.substr(0, s.length() - 2)) { + return true; + } + } } return false; } @@ -132,15 +142,6 @@ protected: } private: - bool checkVersion(const std::string& aVersion, SGPropertyNode* aProps) - { - BOOST_FOREACH(SGPropertyNode* v, aProps->getChildren("version")) { - if (v->getStringValue() == aVersion) { - return true; - } - } - return false; - } CatalogRef m_owner; std::string m_buffer; @@ -185,7 +186,7 @@ CatalogRef Catalog::createFromPath(Root* aRoot, const SGPath& aPath) return NULL; } - if (props->getStringValue("version") != aRoot->catalogVersion()) { + if (!checkVersion(aRoot->catalogVersion(), props)) { std::string redirect = redirectUrlForVersion(aRoot->catalogVersion(), props); if (!redirect.empty()) { SG_LOG(SG_GENERAL, SG_WARN, "catalog at " << aPath << ", version mismatch:\n\t" diff --git a/simgear/package/CatalogTest.cxx b/simgear/package/CatalogTest.cxx new file mode 100644 index 00000000..ef7da7a6 --- /dev/null +++ b/simgear/package/CatalogTest.cxx @@ -0,0 +1,59 @@ +// Copyright (C) 2015 James Turner - zakalawe@mac.com +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include +#include + +#include +#include + +#include + +using namespace simgear; + +int parseTest() +{ + SGPath rootPath = simgear::Dir::current().path(); + rootPath.append("testRoot"); + pkg::Root* root = new pkg::Root(rootPath, "8.1.12"); + pkg::CatalogRef cat = pkg::Catalog::createFromPath(root, SGPath(SRC_DIR "/catalogTest1")); + + VERIFY(cat.valid()); + + COMPARE(cat->id(), "org.flightgear.test.catalog1"); + COMPARE(cat->url(), "http://download.flightgear.org/catalog1/catalog.xml"); + COMPARE(cat->description(), "First test catalog"); + +// check the packages too + + delete root; + + return EXIT_SUCCESS; +} + +int main(int argc, char* argv[]) +{ + parseTest(); + std::cout << "Successfully passed all tests!" << std::endl; + return EXIT_SUCCESS; +} diff --git a/simgear/package/catalogTest1/catalog.xml b/simgear/package/catalogTest1/catalog.xml new file mode 100644 index 00000000..c557bfe6 --- /dev/null +++ b/simgear/package/catalogTest1/catalog.xml @@ -0,0 +1,9 @@ + + + + org.flightgear.test.catalog1 + First test catalog + http://download.flightgear.org/catalog1/catalog.xml + 8.1.* + + \ No newline at end of file -- 2.39.5