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
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;
}
}
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;
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"
--- /dev/null
+// 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 <simgear_config.h>
+#endif
+
+#include <simgear/misc/test_macros.hxx>
+
+#include <cstdlib>
+#include <iostream>
+
+#include <simgear/package/Catalog.hxx>
+#include <simgear/package/Root.hxx>
+
+#include <simgear/misc/sg_dir.hxx>
+
+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;
+}