summaryrefslogtreecommitdiff
path: root/test/sprite
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-05-15 14:09:06 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-05-16 12:26:35 -0700
commitcc1ea759a681cadcfd06fd7bdda79ca6deb38c62 (patch)
tree97ece422b0516b11979c84b8136f95aeabb1aa91 /test/sprite
parentc0f6e5ccefc67dbdaa6ab7c7ea75a2a2d0c3f2ae (diff)
downloadqtlocation-mapboxgl-cc1ea759a681cadcfd06fd7bdda79ca6deb38c62.tar.gz
[core, node, darwin, android, qt] Make image ID part of Image
More like Source and Layer.
Diffstat (limited to 'test/sprite')
-rw-r--r--test/sprite/sprite_atlas.test.cpp22
-rw-r--r--test/sprite/sprite_image_collection.test.cpp10
-rw-r--r--test/sprite/sprite_loader.test.cpp10
-rw-r--r--test/sprite/sprite_parser.test.cpp38
4 files changed, 40 insertions, 40 deletions
diff --git a/test/sprite/sprite_atlas.test.cpp b/test/sprite/sprite_atlas.test.cpp
index 70cdfd9fa6..37a50ddddb 100644
--- a/test/sprite/sprite_atlas.test.cpp
+++ b/test/sprite/sprite_atlas.test.cpp
@@ -22,8 +22,8 @@ TEST(SpriteAtlas, Basic) {
auto images = parseSprite(util::read_file("test/fixtures/annotations/emerald.png"),
util::read_file("test/fixtures/annotations/emerald.json"));
- for (auto& pair : images) {
- atlas.addImage(pair.first, pair.second->impl);
+ for (auto& image : images) {
+ atlas.addImage(image->impl);
}
EXPECT_EQ(1.0f, atlas.getPixelRatio());
@@ -79,8 +79,8 @@ TEST(SpriteAtlas, Size) {
auto images = parseSprite(util::read_file("test/fixtures/annotations/emerald.png"),
util::read_file("test/fixtures/annotations/emerald.json"));
- for (auto& pair : images) {
- atlas.addImage(pair.first, pair.second->impl);
+ for (auto& image : images) {
+ atlas.addImage(image->impl);
}
EXPECT_DOUBLE_EQ(1.4f, atlas.getPixelRatio());
@@ -113,7 +113,7 @@ TEST(SpriteAtlas, Updates) {
EXPECT_EQ(32u, atlas.getSize().width);
EXPECT_EQ(32u, atlas.getSize().height);
- atlas.addImage("one", makeMutable<style::Image::Impl>(PremultipliedImage({ 16, 12 }), 1));
+ atlas.addImage(makeMutable<style::Image::Impl>("one", PremultipliedImage({ 16, 12 }), 1));
auto one = *atlas.getIcon("one");
float imagePixelRatio = one.relativePixelRatio * atlas.getPixelRatio();
EXPECT_EQ(0, one.pos.x);
@@ -137,7 +137,7 @@ TEST(SpriteAtlas, Updates) {
for (size_t i = 0; i < image2.bytes(); i++) {
image2.data.get()[i] = 255;
}
- atlas.addImage("one", makeMutable<style::Image::Impl>(std::move(image2), 1));
+ atlas.addImage(makeMutable<style::Image::Impl>("one", std::move(image2), 1));
test::checkImage("test/fixtures/sprite_atlas/updates_after", atlas.getAtlasImage());
}
@@ -146,9 +146,9 @@ TEST(SpriteAtlas, AddRemove) {
FixtureLog log;
SpriteAtlas atlas({ 32, 32 }, 1);
- atlas.addImage("one", makeMutable<style::Image::Impl>(PremultipliedImage({ 16, 16 }), 2));
- atlas.addImage("two", makeMutable<style::Image::Impl>(PremultipliedImage({ 16, 16 }), 2));
- atlas.addImage("three", makeMutable<style::Image::Impl>(PremultipliedImage({ 16, 16 }), 2));
+ atlas.addImage(makeMutable<style::Image::Impl>("one", PremultipliedImage({ 16, 16 }), 2));
+ atlas.addImage(makeMutable<style::Image::Impl>("two", PremultipliedImage({ 16, 16 }), 2));
+ atlas.addImage(makeMutable<style::Image::Impl>("three", PremultipliedImage({ 16, 16 }), 2));
atlas.removeImage("one");
atlas.removeImage("two");
@@ -176,12 +176,12 @@ TEST(SpriteAtlas, RemoveReleasesBinPackRect) {
SpriteAtlas atlas({ 36, 36 }, 1);
- atlas.addImage("big", makeMutable<style::Image::Impl>(PremultipliedImage({ 32, 32 }), 1));
+ atlas.addImage(makeMutable<style::Image::Impl>("big", PremultipliedImage({ 32, 32 }), 1));
EXPECT_TRUE(atlas.getIcon("big"));
atlas.removeImage("big");
- atlas.addImage("big", makeMutable<style::Image::Impl>(PremultipliedImage({ 32, 32 }), 1));
+ atlas.addImage(makeMutable<style::Image::Impl>("big", PremultipliedImage({ 32, 32 }), 1));
EXPECT_TRUE(atlas.getIcon("big"));
EXPECT_TRUE(log.empty());
}
diff --git a/test/sprite/sprite_image_collection.test.cpp b/test/sprite/sprite_image_collection.test.cpp
index 51ea20fdf3..788d7a59d5 100644
--- a/test/sprite/sprite_image_collection.test.cpp
+++ b/test/sprite/sprite_image_collection.test.cpp
@@ -14,16 +14,16 @@ TEST(SpriteImageCollection, OtherPixelRatio) {
Images images;
// Adding mismatched sprite image
- addSpriteImage(images, "one", std::make_unique<style::Image>(PremultipliedImage({ 8, 8 }), 2));
+ addSpriteImage(images, std::make_unique<style::Image>("one", PremultipliedImage({ 8, 8 }), 2));
}
TEST(SpriteImageCollection, Replace) {
FixtureLog log;
Images images;
- addSpriteImage(images, "sprite", std::make_unique<style::Image>(PremultipliedImage({ 16, 16 }), 2));
+ addSpriteImage(images, std::make_unique<style::Image>("sprite", PremultipliedImage({ 16, 16 }), 2));
auto image = images.find("sprite")->second.get();
- addSpriteImage(images, "sprite", std::make_unique<style::Image>(PremultipliedImage({ 16, 16 }), 2));
+ addSpriteImage(images, std::make_unique<style::Image>("sprite", PremultipliedImage({ 16, 16 }), 2));
EXPECT_NE(image, images.find("sprite")->second.get());
}
@@ -31,8 +31,8 @@ TEST(SpriteImageCollection, ReplaceWithDifferentDimensions) {
FixtureLog log;
Images images;
- addSpriteImage(images, "sprite", std::make_unique<style::Image>(PremultipliedImage({ 16, 16 }), 2));
- addSpriteImage(images, "sprite", std::make_unique<style::Image>(PremultipliedImage({ 18, 18 }), 2));
+ addSpriteImage(images, std::make_unique<style::Image>("sprite", PremultipliedImage({ 16, 16 }), 2));
+ addSpriteImage(images, std::make_unique<style::Image>("sprite", PremultipliedImage({ 18, 18 }), 2));
EXPECT_EQ(1u, log.count({
EventSeverity::Warning,
diff --git a/test/sprite/sprite_loader.test.cpp b/test/sprite/sprite_loader.test.cpp
index 99f44e57e4..3691572265 100644
--- a/test/sprite/sprite_loader.test.cpp
+++ b/test/sprite/sprite_loader.test.cpp
@@ -18,7 +18,7 @@ using namespace mbgl::style;
class StubSpriteLoaderObserver : public SpriteLoaderObserver {
public:
- void onSpriteLoaded(Images&& images) override {
+ void onSpriteLoaded(std::vector<std::unique_ptr<style::Image>>&& images) override {
if (spriteLoaded) spriteLoaded(std::move(images));
}
@@ -26,7 +26,7 @@ public:
if (spriteError) spriteError(error);
}
- std::function<void (Images&&)> spriteLoaded;
+ std::function<void (std::vector<std::unique_ptr<style::Image>>&&)> spriteLoaded;
std::function<void (std::exception_ptr)> spriteError;
};
@@ -94,8 +94,8 @@ TEST(SpriteLoader, LoadingSuccess) {
test.end();
};
- test.observer.spriteLoaded = [&] (SpriteLoaderObserver::Images&& images) {
- EXPECT_EQ(images.size(), Images::size_type(367));
+ test.observer.spriteLoaded = [&] (std::vector<std::unique_ptr<style::Image>>&& images) {
+ EXPECT_EQ(images.size(), 367u);
test.end();
};
@@ -171,7 +171,7 @@ TEST(SpriteLoader, LoadingCancel) {
return optional<Response>();
};
- test.observer.spriteLoaded = [&] (const SpriteLoaderObserver::Images&) {
+ test.observer.spriteLoaded = [&] (const std::vector<std::unique_ptr<style::Image>>&) {
FAIL() << "Should never be called";
};
diff --git a/test/sprite/sprite_parser.test.cpp b/test/sprite/sprite_parser.test.cpp
index 19c6b914a8..aad80b3d81 100644
--- a/test/sprite/sprite_parser.test.cpp
+++ b/test/sprite/sprite_parser.test.cpp
@@ -27,19 +27,19 @@ TEST(Sprite, SpriteImageCreationInvalid) {
ASSERT_EQ(200u, image_1x.size.width);
ASSERT_EQ(299u, image_1x.size.height);
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 0, 16, 1, false)); // width == 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 16, 0, 1, false)); // height == 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, -1, 16, 1, false)); // width < 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 16, -1, 1, false)); // height < 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 1, 1, 0, false)); // ratio == 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 1, 1, -1, false)); // ratio < 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 1, 1, 23, false)); // ratio too large
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 2048, 16, 1, false)); // too wide
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 16, 1025, 1, false)); // too tall
- ASSERT_EQ(nullptr, createStyleImage(image_1x, -1, 0, 16, 16, 1, false)); // srcX < 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, -1, 16, 16, 1, false)); // srcY < 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, image_1x.size.width + 1, 16, 1, false)); // right edge out of bounds
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 16, image_1x.size.height + 1, 1, false)); // bottom edge out of bounds
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 0, 16, 1, false)); // width == 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 16, 0, 1, false)); // height == 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, -1, 16, 1, false)); // width < 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 16, -1, 1, false)); // height < 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 1, 1, 0, false)); // ratio == 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 1, 1, -1, false)); // ratio < 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 1, 1, 23, false)); // ratio too large
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 2048, 16, 1, false)); // too wide
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 16, 1025, 1, false)); // too tall
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, -1, 0, 16, 16, 1, false)); // srcX < 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, -1, 16, 16, 1, false)); // srcY < 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, image_1x.size.width + 1, 16, 1, false)); // right edge out of bounds
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 16, image_1x.size.height + 1, 1, false)); // bottom edge out of bounds
EXPECT_EQ(1u, log.count({
EventSeverity::Error,
@@ -141,7 +141,7 @@ TEST(Sprite, SpriteImageCreation1x) {
ASSERT_EQ(299u, image_1x.size.height);
{ // "museum_icon":{"x":177,"y":187,"width":18,"height":18,"pixelRatio":1,"sdf":false}
- const auto sprite = createStyleImage(image_1x, 177, 187, 18, 18, 1, false);
+ const auto sprite = createStyleImage("test", image_1x, 177, 187, 18, 18, 1, false);
ASSERT_TRUE(sprite.get());
EXPECT_EQ(18, sprite->getWidth());
EXPECT_EQ(18, sprite->getHeight());
@@ -157,7 +157,7 @@ TEST(Sprite, SpriteImageCreation2x) {
const PremultipliedImage image_2x = decodeImage(util::read_file("test/fixtures/annotations/emerald@2x.png"));
// "museum_icon":{"x":354,"y":374,"width":36,"height":36,"pixelRatio":2,"sdf":false}
- const auto sprite = createStyleImage(image_2x, 354, 374, 36, 36, 2, false);
+ const auto sprite = createStyleImage("test", image_2x, 354, 374, 36, 36, 2, false);
ASSERT_TRUE(sprite.get());
EXPECT_EQ(18, sprite->getWidth());
EXPECT_EQ(18, sprite->getHeight());
@@ -172,7 +172,7 @@ TEST(Sprite, SpriteImageCreation1_5x) {
const PremultipliedImage image_2x = decodeImage(util::read_file("test/fixtures/annotations/emerald@2x.png"));
// "museum_icon":{"x":354,"y":374,"width":36,"height":36,"pixelRatio":2,"sdf":false}
- const auto sprite = createStyleImage(image_2x, 354, 374, 36, 36, 1.5, false);
+ const auto sprite = createStyleImage("test", image_2x, 354, 374, 36, 36, 1.5, false);
ASSERT_TRUE(sprite.get());
EXPECT_EQ(24, sprite->getWidth());
EXPECT_EQ(24, sprite->getHeight());
@@ -183,7 +183,7 @@ TEST(Sprite, SpriteImageCreation1_5x) {
sprite->getImage());
// "hospital_icon":{"x":314,"y":518,"width":36,"height":36,"pixelRatio":2,"sdf":false}
- const auto sprite2 = createStyleImage(image_2x, 314, 518, 35, 35, 1.5, false);
+ const auto sprite2 = createStyleImage("test", image_2x, 314, 518, 35, 35, 1.5, false);
ASSERT_TRUE(sprite2.get());
EXPECT_EQ(float(35 / 1.5), sprite2->getWidth());
EXPECT_EQ(float(35 / 1.5), sprite2->getHeight());
@@ -202,7 +202,7 @@ TEST(Sprite, SpriteParsing) {
std::set<std::string> names;
std::transform(images.begin(), images.end(), std::inserter(names, names.begin()),
- [](const auto& pair) { return pair.first; });
+ [](const auto& image) { return image->getID(); });
EXPECT_EQ(std::set<std::string>({ "airfield_icon",
"airport_icon",
@@ -280,7 +280,7 @@ TEST(Sprite, SpriteParsing) {
names);
{
- auto& sprite = images.find("generic-metro")->second;
+ auto& sprite = *std::find_if(images.begin(), images.end(), [] (const auto& image) { return image->getID() == "generic-metro"; });
EXPECT_EQ(18, sprite->getWidth());
EXPECT_EQ(18, sprite->getHeight());
EXPECT_EQ(18u, sprite->getImage().size.width);