]> git.mxchange.org Git - simgear.git/commitdiff
Package work on version support.
authorJames Turner <zakalawe@mac.com>
Wed, 22 Apr 2015 22:38:40 +0000 (23:38 +0100)
committerJames Turner <zakalawe@mac.com>
Wed, 22 Apr 2015 22:50:08 +0000 (23:50 +0100)
- start adding test coverage for packages

simgear/package/CMakeLists.txt
simgear/package/Catalog.cxx
simgear/package/CatalogTest.cxx [new file with mode: 0644]
simgear/package/catalogTest1/catalog.xml [new file with mode: 0644]

index 3367268088baf74b0af01d2f42c2415f76c22146..37e7a504902defdcb0178e7c279c13ff8d3c0755 100644 (file)
@@ -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
index ac33ffb3577844276db338de5e058b17cf284a92..c12a53a0dee94be84c99535933e97bb320c5cd74 100644 (file)
@@ -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 (file)
index 0000000..ef7da7a
--- /dev/null
@@ -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 <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;
+}
diff --git a/simgear/package/catalogTest1/catalog.xml b/simgear/package/catalogTest1/catalog.xml
new file mode 100644 (file)
index 0000000..c557bfe
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+
+<PropertyList>
+    <id>org.flightgear.test.catalog1</id>
+    <description>First test catalog</description>
+    <url>http://download.flightgear.org/catalog1/catalog.xml</url>
+    <version>8.1.*</version>
+</PropertyList>
+    
\ No newline at end of file