Rename ‘new’ thumbnails to ‘previews’

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.
This commit is contained in:
James Turner
2017-01-10 18:05:40 +00:00
parent 637f67888a
commit 3cb3084725
5 changed files with 75 additions and 62 deletions

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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<Thumbnail> ThumbnailVec;
typedef std::vector<Preview> 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;

View File

@@ -48,22 +48,22 @@
<revision>10</revision>
</depends>
<thumbnail>
<preview>
<type>exterior</type>
<path>thumb-exterior.png</path>
<url>http://foo.bar.com/thumb-exterior.png</url>
</thumbnail>
</preview>
<thumbnail>
<preview>
<type>panel</type>
<path>thumb-panel.png</path>
<url>http://foo.bar.com/thumb-panel.png</url>
</thumbnail>
</preview>
<thumbnail>
<preview>
<path>thumb-something.png</path>
<url>http://foo.bar.com/thumb-something.png</url>
</thumbnail>
</preview>
<variant>
<id>c172p-2d-panel</id>
@@ -74,34 +74,34 @@
<id>c172p-floats</id>
<name>C172 with floats</name>
<thumbnail>
<preview>
<type>exterior</type>
<path>thumb-exterior-floats.png</path>
<url>http://foo.bar.com/thumb-exterior-floats.png</url>
</thumbnail>
</preview>
<thumbnail>
<preview>
<type>panel</type>
<path>thumb-panel.png</path>
<url>http://foo.bar.com/thumb-panel.png</url>
</thumbnail>
</preview>
</variant>
<variant>
<id>c172p-skis</id>
<name>C172 with skis</name>
<thumbnail>
<preview>
<type>exterior</type>
<path>thumb-exterior-skis.png</path>
<url>http://foo.bar.com/thumb-exterior-skis.png</url>
</thumbnail>
</preview>
<thumbnail>
<preview>
<type>panel</type>
<path>thumb-panel.png</path>
<url>http://foo.bar.com/thumb-panel.png</url>
</thumbnail>
</preview>
</variant>
<md5>ec0e2ffdf98d6a5c05c77445e5447ff5</md5>
@@ -141,17 +141,17 @@
<md5>a94ca5704f305b90767f40617d194ed6</md5>
<url>http://localhost:2000/catalogTest1/b737.tar.gz</url>
<thumbnail>
<preview>
<type>exterior</type>
<path>thumb-exterior.png</path>
<url>http://foo.bar.com/thumb-exterior.png</url>
</thumbnail>
</preview>
<thumbnail>
<preview>
<type>panel</type>
<path>thumb-panel.png</path>
<url>http://foo.bar.com/thumb-panel.png</url>
</thumbnail>
</preview>
</package>

View File

@@ -20,6 +20,7 @@
<url>http://localhost:2000/catalogTest1/alpha.zip</url>
<dir>alpha</dir>
</package>
<package>
@@ -49,22 +50,22 @@
<revision>10</revision>
</depends>
<thumbnail>
<preview>
<type>exterior</type>
<path>thumb-exterior.png</path>
<url>http://foo.bar.com/thumb-exterior.png</url>
</thumbnail>
</preview>
<thumbnail>
<preview>
<type>panel</type>
<path>thumb-panel.png</path>
<url>http://foo.bar.com/thumb-panel.png</url>
</thumbnail>
</preview>
<thumbnail>
<preview>
<path>thumb-something.png</path>
<url>http://foo.bar.com/thumb-something.png</url>
</thumbnail>
</preview>
<variant>
<id>c172p-2d-panel</id>
@@ -77,17 +78,17 @@
<description>A plane with floats</description>
<author>Floats variant author</author>
<thumbnail>
<preview>
<type>exterior</type>
<path>thumb-exterior-floats.png</path>
<url>http://foo.bar.com/thumb-exterior-floats.png</url>
</thumbnail>
</preview>
<thumbnail>
<preview>
<type>panel</type>
<path>thumb-panel.png</path>
<url>http://foo.bar.com/thumb-panel.png</url>
</thumbnail>
</preview>
</variant>
<variant>
@@ -95,22 +96,25 @@
<name>C172 with skis</name>
<description>A plane with skis</description>
<thumbnail>
<preview>
<type>exterior</type>
<path>thumb-exterior-skis.png</path>
<url>http://foo.bar.com/thumb-exterior-skis.png</url>
</thumbnail>
</preview>
<thumbnail>
<preview>
<type>panel</type>
<path>thumb-panel.png</path>
<url>http://foo.bar.com/thumb-panel.png</url>
</thumbnail>
</preview>
</variant>
<md5>ec0e2ffdf98d6a5c05c77445e5447ff5</md5>
<url>http://localhost:2000/catalogTest1/c172p.zip</url>
<!-- legacy thumbnails also supported -->
<thumbnail>http://foo.bar.com/thumb-exterior.png</thumbnail>
<thumbnail-path>exterior.png</thumbnail-path>
</package>
<package>