From 3cb3084725a834a1356b08d1b6acbae447863283 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 10 Jan 2017 18:05:40 +0000 Subject: [PATCH] =?UTF-8?q?Rename=20=E2=80=98new=E2=80=99=20thumbnails=20t?= =?UTF-8?q?o=20=E2=80=98previews=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids an XML naming clash, and allows both systems to exist in parallel peacefully. Update the tests to check both the thumbnails and preview system in parallel with each other. --- simgear/package/CatalogTest.cxx | 31 +++++++++++------- simgear/package/Package.cxx | 26 +++++++-------- simgear/package/Package.hxx | 12 +++---- simgear/package/catalogTest1/catalog-v2.xml | 36 ++++++++++----------- simgear/package/catalogTest1/catalog.xml | 32 ++++++++++-------- 5 files changed, 75 insertions(+), 62 deletions(-) diff --git a/simgear/package/CatalogTest.cxx b/simgear/package/CatalogTest.cxx index 619561ca..5fbf83ae 100644 --- a/simgear/package/CatalogTest.cxx +++ b/simgear/package/CatalogTest.cxx @@ -150,22 +150,31 @@ int parseTest() SG_CHECK_EQUAL(p2->qualifiedId(), "org.flightgear.test.catalog1.c172p"); SG_CHECK_EQUAL(p2->description(), "A plane made by Cessna on Jupiter"); - pkg::Package::ThumbnailVec thumbs = p2->thumbnailsForVariant(0); + pkg::Package::PreviewVec thumbs = p2->previewsForVariant(0); SG_CHECK_EQUAL(thumbs.size(), 3); - auto index = std::find_if(thumbs.begin(), thumbs.end(), [](const pkg::Package::Thumbnail& t) - { return (t.type == pkg::Package::Thumbnail::Type::EXTERIOR); }); + auto index = std::find_if(thumbs.begin(), thumbs.end(), [](const pkg::Package::Preview& t) + { return (t.type == pkg::Package::Preview::Type::EXTERIOR); }); SG_VERIFY(index != thumbs.end()); SG_CHECK_EQUAL(index->path, "thumb-exterior.png"); SG_CHECK_EQUAL(index->url, "http://foo.bar.com/thumb-exterior.png"); - SG_VERIFY(index->type == pkg::Package::Thumbnail::Type::EXTERIOR); + SG_VERIFY(index->type == pkg::Package::Preview::Type::EXTERIOR); - index = std::find_if(thumbs.begin(), thumbs.end(), [](const pkg::Package::Thumbnail& t) - { return (t.type == pkg::Package::Thumbnail::Type::PANEL); }); + index = std::find_if(thumbs.begin(), thumbs.end(), [](const pkg::Package::Preview& t) + { return (t.type == pkg::Package::Preview::Type::PANEL); }); SG_VERIFY(index != thumbs.end()); SG_CHECK_EQUAL(index->path, "thumb-panel.png"); SG_CHECK_EQUAL(index->url, "http://foo.bar.com/thumb-panel.png"); - SG_VERIFY(index->type == pkg::Package::Thumbnail::Type::PANEL); + SG_VERIFY(index->type == pkg::Package::Preview::Type::PANEL); + +// old-style thumbnails + string_list oldThumbUrls = p2->thumbnailUrls(); + SG_CHECK_EQUAL(oldThumbUrls.size(), 1); + SG_CHECK_EQUAL(oldThumbUrls.at(0), "http://foo.bar.com/thumb-exterior.png"); + + string_list oldThumbPaths = p2->thumbnails(); + SG_CHECK_EQUAL(oldThumbPaths.size(), 1); + SG_CHECK_EQUAL(oldThumbPaths.at(0), "exterior.png"); // test variants try { @@ -196,15 +205,15 @@ int parseTest() SG_CHECK_EQUAL(p2->getLocalisedProp("author", floatsVariant), "Floats variant author"); - pkg::Package::ThumbnailVec thumbs2 = p2->thumbnailsForVariant(skisVariant); + pkg::Package::PreviewVec thumbs2 = p2->previewsForVariant(skisVariant); SG_CHECK_EQUAL(thumbs2.size(), 2); - index = std::find_if(thumbs2.begin(), thumbs2.end(), [](const pkg::Package::Thumbnail& t) - { return (t.type == pkg::Package::Thumbnail::Type::EXTERIOR); }); + index = std::find_if(thumbs2.begin(), thumbs2.end(), [](const pkg::Package::Preview& t) + { return (t.type == pkg::Package::Preview::Type::EXTERIOR); }); SG_VERIFY(index != thumbs2.end()); SG_CHECK_EQUAL(index->path, "thumb-exterior-skis.png"); SG_CHECK_EQUAL(index->url, "http://foo.bar.com/thumb-exterior-skis.png"); - SG_VERIFY(index->type == pkg::Package::Thumbnail::Type::EXTERIOR); + SG_VERIFY(index->type == pkg::Package::Preview::Type::EXTERIOR); // test filtering / searching too diff --git a/simgear/package/Package.cxx b/simgear/package/Package.cxx index df86945d..9748d328 100644 --- a/simgear/package/Package.cxx +++ b/simgear/package/Package.cxx @@ -429,35 +429,35 @@ SGPropertyNode_ptr Package::propsForVariant(const unsigned int vIndex, const cha throw sg_exception("Unknow variant in package " + id()); } -Package::ThumbnailVec Package::thumbnailsForVariant(unsigned int vIndex) const +Package::PreviewVec Package::previewsForVariant(unsigned int vIndex) const { SGPropertyNode_ptr var = propsForVariant(vIndex); - return thumbnailsFromProps(var); + return previewsFromProps(var); } -Package::Thumbnail::Type thumbnailTypeFromString(const std::string& s) +Package::Preview::Type previewTypeFromString(const std::string& s) { - if (s == "exterior") return Package::Thumbnail::Type::EXTERIOR; - if (s == "interior") return Package::Thumbnail::Type::INTERIOR; - if (s == "panel") return Package::Thumbnail::Type::PANEL; - return Package::Thumbnail::Type::UNKNOWN; + if (s == "exterior") return Package::Preview::Type::EXTERIOR; + if (s == "interior") return Package::Preview::Type::INTERIOR; + if (s == "panel") return Package::Preview::Type::PANEL; + return Package::Preview::Type::UNKNOWN; } -Package::Thumbnail::Thumbnail(const std::string& aUrl, const std::string& aPath, Type aType) : +Package::Preview::Preview(const std::string& aUrl, const std::string& aPath, Type aType) : url(aUrl), path(aPath), type(aType) { } -Package::ThumbnailVec Package::thumbnailsFromProps(const SGPropertyNode_ptr& ptr) const +Package::PreviewVec Package::previewsFromProps(const SGPropertyNode_ptr& ptr) const { - ThumbnailVec result; + PreviewVec result; - for (auto thumbNode : ptr->getChildren("thumbnail")) { - Thumbnail t(thumbNode->getStringValue("url"), + for (auto thumbNode : ptr->getChildren("preview")) { + Preview t(thumbNode->getStringValue("url"), thumbNode->getStringValue("path"), - thumbnailTypeFromString(thumbNode->getStringValue("type"))); + previewTypeFromString(thumbNode->getStringValue("type"))); result.push_back(t); } diff --git a/simgear/package/Package.hxx b/simgear/package/Package.hxx index 052d8feb..e4c0704b 100644 --- a/simgear/package/Package.hxx +++ b/simgear/package/Package.hxx @@ -140,9 +140,9 @@ public: string_list thumbnails() const; /** - * information about a thumbnail + * information about a preview image */ - struct Thumbnail { + struct Preview { enum class Type { UNKNOWN, @@ -154,19 +154,19 @@ public: // actual value for GUIs? }; - Thumbnail(const std::string& url, const std::string& path, Type ty = Type::UNKNOWN); + Preview(const std::string& url, const std::string& path, Type ty = Type::UNKNOWN); std::string url; std::string path; Type type = Type::UNKNOWN; }; - typedef std::vector ThumbnailVec; + typedef std::vector PreviewVec; /** * retrieve all the thumbnails for a variant */ - ThumbnailVec thumbnailsForVariant(unsigned int vIndex) const; + PreviewVec previewsForVariant(unsigned int vIndex) const; /** * Packages we depend upon. @@ -194,7 +194,7 @@ private: std::string getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const; - ThumbnailVec thumbnailsFromProps(const SGPropertyNode_ptr& ptr) const; + PreviewVec previewsFromProps(const SGPropertyNode_ptr& ptr) const; SGPropertyNode_ptr propsForVariant(const unsigned int vIndex, const char* propName = nullptr) const; diff --git a/simgear/package/catalogTest1/catalog-v2.xml b/simgear/package/catalogTest1/catalog-v2.xml index 87190d92..2c8961ac 100644 --- a/simgear/package/catalogTest1/catalog-v2.xml +++ b/simgear/package/catalogTest1/catalog-v2.xml @@ -48,22 +48,22 @@ 10 - + exterior thumb-exterior.png http://foo.bar.com/thumb-exterior.png - + - + panel thumb-panel.png http://foo.bar.com/thumb-panel.png - + - + thumb-something.png http://foo.bar.com/thumb-something.png - + c172p-2d-panel @@ -74,34 +74,34 @@ c172p-floats C172 with floats - + exterior thumb-exterior-floats.png http://foo.bar.com/thumb-exterior-floats.png - + - + panel thumb-panel.png http://foo.bar.com/thumb-panel.png - + c172p-skis C172 with skis - + exterior thumb-exterior-skis.png http://foo.bar.com/thumb-exterior-skis.png - + - + panel thumb-panel.png http://foo.bar.com/thumb-panel.png - + ec0e2ffdf98d6a5c05c77445e5447ff5 @@ -141,17 +141,17 @@ a94ca5704f305b90767f40617d194ed6 http://localhost:2000/catalogTest1/b737.tar.gz - + exterior thumb-exterior.png http://foo.bar.com/thumb-exterior.png - + - + panel thumb-panel.png http://foo.bar.com/thumb-panel.png - + diff --git a/simgear/package/catalogTest1/catalog.xml b/simgear/package/catalogTest1/catalog.xml index b964979f..3d811e86 100644 --- a/simgear/package/catalogTest1/catalog.xml +++ b/simgear/package/catalogTest1/catalog.xml @@ -20,6 +20,7 @@ http://localhost:2000/catalogTest1/alpha.zip alpha + @@ -49,22 +50,22 @@ 10 - + exterior thumb-exterior.png http://foo.bar.com/thumb-exterior.png - + - + panel thumb-panel.png http://foo.bar.com/thumb-panel.png - + - + thumb-something.png http://foo.bar.com/thumb-something.png - + c172p-2d-panel @@ -77,17 +78,17 @@ A plane with floats Floats variant author - + exterior thumb-exterior-floats.png http://foo.bar.com/thumb-exterior-floats.png - + - + panel thumb-panel.png http://foo.bar.com/thumb-panel.png - + @@ -95,22 +96,25 @@ C172 with skis A plane with skis - + exterior thumb-exterior-skis.png http://foo.bar.com/thumb-exterior-skis.png - + - + panel thumb-panel.png http://foo.bar.com/thumb-panel.png - + ec0e2ffdf98d6a5c05c77445e5447ff5 http://localhost:2000/catalogTest1/c172p.zip + + http://foo.bar.com/thumb-exterior.png + exterior.png