From 7332ae00735a7cb1a0a4528d48e5956aa593b8b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 10 May 2016 11:48:22 +0200 Subject: [core] retain tiles differently and remove old TileID class --- test/algorithm/mock.hpp | 60 ++++++ test/algorithm/update_renderables.cpp | 367 ++++++++++++++++++++++++++++++++++ test/map/tile.cpp | 50 ----- test/storage/offline.cpp | 49 ++--- test/test.gypi | 3 +- test/util/tile_cover.cpp | 145 ++++++-------- 6 files changed, 504 insertions(+), 170 deletions(-) create mode 100644 test/algorithm/mock.hpp create mode 100644 test/algorithm/update_renderables.cpp delete mode 100644 test/map/tile.cpp (limited to 'test') diff --git a/test/algorithm/mock.hpp b/test/algorithm/mock.hpp new file mode 100644 index 0000000000..89f51b15b8 --- /dev/null +++ b/test/algorithm/mock.hpp @@ -0,0 +1,60 @@ +#ifndef MBGL_TEST_MOCK +#define MBGL_TEST_MOCK + +#include +#include +#include +#include +#include + +#include + +struct MockSourceInfo { + uint8_t maxZoom = 16; + uint8_t minZoom = 0; +}; + +struct MockTileData; + +struct MockRenderable { + MockRenderable(mbgl::UnwrappedTileID id_, MockTileData& data_) : id(id_), data(data_) {} + + const mbgl::UnwrappedTileID id; + MockTileData& data; + + bool operator==(const MockRenderable& rhs) const { + return &data == &rhs.data; + } +}; + +::std::ostream& operator<<(::std::ostream& os, const MockRenderable&) { + return os << "Renderable{}"; +} + +struct MockSource { + MockSourceInfo info; + std::map> dataTiles; + std::set idealTiles; + std::map renderables; + + // Test API + inline MockTileData* createTileData(const mbgl::OverscaledTileID& tileID); +}; + +struct MockBucket {}; + + +struct MockTileData { + bool isReady() { + return ready; + } + + bool ready = false; +}; + +MockTileData* MockSource::createTileData(const mbgl::OverscaledTileID& tileID) { + // Replace the existing MockTileData object, if any. + return (dataTiles[tileID] = std::make_unique()).get(); +} + +#endif diff --git a/test/algorithm/update_renderables.cpp b/test/algorithm/update_renderables.cpp new file mode 100644 index 0000000000..860381bdfa --- /dev/null +++ b/test/algorithm/update_renderables.cpp @@ -0,0 +1,367 @@ +#include +#include "mock.hpp" + +#include + +using namespace mbgl; + +TEST(UpdateRenderables, SingleTile) { + MockSource source; + source.idealTiles.emplace(UnwrappedTileID{ 1, 1, 1 }); + + // Make sure that we're getting the tile back. + auto tile_1_1_1 = source.createTileData(OverscaledTileID{ 1, 1, 1 }); + tile_1_1_1->ready = true; + + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 1, 1, 1 }, MockRenderable{ { 1, 1, 1 }, *tile_1_1_1 } }, + }), + source.renderables); + + // Check a repeated render with the same data. + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 1, 1, 1 }, MockRenderable{ { 1, 1, 1 }, *tile_1_1_1 } }, + }), + source.renderables); + + // Insert a tile we don't have data for. + source.idealTiles.emplace(UnwrappedTileID{ 1, 0, 1 }); + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 1, 1, 1 }, MockRenderable{ { 1, 1, 1 }, *tile_1_1_1 } }, + }), + source.renderables); + + // Now insert the missing tile and check that we're rendering it. + auto tile_1_0_1 = source.createTileData(OverscaledTileID{ 1, 0, 1 }); + tile_1_0_1->ready = true; + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 1, 0, 1 }, MockRenderable{ { 1, 0, 1 }, *tile_1_0_1 } }, + { { 1, 1, 1 }, MockRenderable{ { 1, 1, 1 }, *tile_1_1_1 } }, + }), + source.renderables); + + // Insert another tile, and another bucket that has a different name and check that we're not + // using it. + source.idealTiles.emplace(UnwrappedTileID{ 1, 0, 0 }); + auto tile_1_0_0 = source.createTileData(OverscaledTileID{ 1, 0, 0 }); + + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 1, 0, 1 }, MockRenderable{ { 1, 0, 1 }, *tile_1_0_1 } }, + { { 1, 1, 1 }, MockRenderable{ { 1, 1, 1 }, *tile_1_1_1 } }, + }), + source.renderables); + + // Then, add the bucket and check that it's getting used. + tile_1_0_0->ready = true; + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 1, 0, 0 }, MockRenderable{ { 1, 0, 0 }, *tile_1_0_0 } }, + { { 1, 0, 1 }, MockRenderable{ { 1, 0, 1 }, *tile_1_0_1 } }, + { { 1, 1, 1 }, MockRenderable{ { 1, 1, 1 }, *tile_1_1_1 } }, + }), + source.renderables); +} + +TEST(UpdateRenderables, UseParentTile) { + MockSource source; + source.idealTiles.emplace(UnwrappedTileID{ 1, 0, 1 }); + source.idealTiles.emplace(UnwrappedTileID{ 1, 1, 0 }); + source.idealTiles.emplace(UnwrappedTileID{ 1, 1, 1 }); + + // Make sure that we're getting the tile back. + auto tile_0_0_0 = source.createTileData(OverscaledTileID{ 0, 0, 0 }); + tile_0_0_0->ready = true; + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 0, 0, 0 }, MockRenderable{ { 0, 0, 0 }, *tile_0_0_0 } }, + }), + source.renderables); +} + +TEST(UpdateRenderables, DontUseWrongParentTile) { + MockSource source; + source.idealTiles.emplace(UnwrappedTileID{ 2, 0, 0 }); + + auto tile_1_1_0 = source.createTileData(OverscaledTileID{ 1, 1, 0 }); + tile_1_1_0->ready = true; + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 2); + EXPECT_EQ(decltype(source.renderables)({}), source.renderables); + + // Add a new child tile and check that it is now used. + source.idealTiles.emplace(UnwrappedTileID{ 2, 2, 0 }); + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 2); + EXPECT_EQ(decltype(source.renderables)({ + { { 1, 1, 0 }, MockRenderable{ { 1, 1, 0 }, *tile_1_1_0 } }, + }), + source.renderables); +} + +TEST(UpdateRenderables, UseParentTileWhenChildNotReady) { + MockSource source; + source.idealTiles.emplace(UnwrappedTileID{ 1, 0, 1 }); + + auto tile_0_0_0 = source.createTileData(OverscaledTileID{ 0, 0, 0 }); + tile_0_0_0->ready = true; + + auto tile_1_0_1 = source.createTileData(OverscaledTileID{ 1, 0, 1 }); + // Don't create bucket. + + // Make sure that it renders the parent tile. + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 0, 0, 0 }, MockRenderable{ { 0, 0, 0 }, *tile_0_0_0 } }, + }), + source.renderables); + + // Now insert the bucket and make sure we're now using the matching tile + tile_1_0_1->ready = true; + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 1, 0, 1 }, MockRenderable{ { 1, 0, 1 }, *tile_1_0_1 } }, + }), + source.renderables); +} + +TEST(UpdateRenderables, UseOverlappingParentTile) { + MockSource source; + source.idealTiles.emplace(UnwrappedTileID{ 1, 0, 0 }); + source.idealTiles.emplace(UnwrappedTileID{ 1, 0, 1 }); + + auto tile_0_0_0 = source.createTileData(OverscaledTileID{ 0, 0, 0 }); + tile_0_0_0->ready = true; + + auto tile_1_0_1 = source.createTileData(OverscaledTileID{ 1, 0, 1 }); + tile_1_0_1->ready = true; + + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 0, 0, 0 }, MockRenderable{ { 0, 0, 0 }, *tile_0_0_0 } }, + { { 1, 0, 1 }, MockRenderable{ { 1, 0, 1 }, *tile_1_0_1 } }, + }), + source.renderables); +} + +TEST(UpdateRenderables, UseChildTiles) { + MockSource source; + source.idealTiles.emplace(UnwrappedTileID{ 0, 0, 0 }); + + auto tile_1_0_0 = source.createTileData(OverscaledTileID{ 1, 0, 0 }); + tile_1_0_0->ready = true; + auto tile_1_1_0 = source.createTileData(OverscaledTileID{ 1, 1, 0 }); + tile_1_1_0->ready = true; + + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 0); + EXPECT_EQ(decltype(source.renderables)({ + { { 1, 0, 0 }, MockRenderable{ { 1, 0, 0 }, *tile_1_0_0 } }, + { { 1, 1, 0 }, MockRenderable{ { 1, 1, 0 }, *tile_1_1_0 } }, + }), + source.renderables); +} + +TEST(UpdateRenderables, PreferChildTiles) { + MockSource source; + source.idealTiles.emplace(UnwrappedTileID{ 1, 0, 0 }); + + auto tile_0_0_0 = source.createTileData(OverscaledTileID{ 0, 0, 0 }); + tile_0_0_0->ready = true; + auto tile_2_0_0 = source.createTileData(OverscaledTileID{ 2, 0, 0 }); + tile_2_0_0->ready = true; + + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 0, 0, 0 }, MockRenderable{ { 0, 0, 0 }, *tile_0_0_0 } }, + { { 2, 0, 0 }, MockRenderable{ { 2, 0, 0 }, *tile_2_0_0 } }, + }), + source.renderables); + + // Now add more children to cover the ideal tile fully, until it is covered fully, and verify + // that the parent doesn't get rendered. + auto tile_2_0_1 = source.createTileData(OverscaledTileID{ 2, 0, 1 }); + tile_2_0_1->ready = true; + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 0, 0, 0 }, MockRenderable{ { 0, 0, 0 }, *tile_0_0_0 } }, + { { 2, 0, 0 }, MockRenderable{ { 2, 0, 0 }, *tile_2_0_0 } }, + { { 2, 0, 1 }, MockRenderable{ { 2, 0, 1 }, *tile_2_0_1 } }, + }), + source.renderables); + + auto tile_2_1_0 = source.createTileData(OverscaledTileID{ 2, 1, 0 }); + tile_2_1_0->ready = true; + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 0, 0, 0 }, MockRenderable{ { 0, 0, 0 }, *tile_0_0_0 } }, + { { 2, 0, 0 }, MockRenderable{ { 2, 0, 0 }, *tile_2_0_0 } }, + { { 2, 0, 1 }, MockRenderable{ { 2, 0, 1 }, *tile_2_0_1 } }, + { { 2, 1, 0 }, MockRenderable{ { 2, 1, 0 }, *tile_2_1_0 } }, + }), + source.renderables); + + // Adding the last child tile covers 1/0/0 fully, so we don't need 0/0/0 anymore. + auto tile_2_1_1 = source.createTileData(OverscaledTileID{ 2, 1, 1 }); + tile_2_1_1->ready = true; + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 2, 0, 0 }, MockRenderable{ { 2, 0, 0 }, *tile_2_0_0 } }, + { { 2, 0, 1 }, MockRenderable{ { 2, 0, 1 }, *tile_2_0_1 } }, + { { 2, 1, 0 }, MockRenderable{ { 2, 1, 0 }, *tile_2_1_0 } }, + { { 2, 1, 1 }, MockRenderable{ { 2, 1, 1 }, *tile_2_1_1 } }, + }), + source.renderables); +} + +TEST(UpdateRenderables, UseParentAndChildTiles) { + MockSource source; + source.idealTiles.emplace(UnwrappedTileID{ 1, 0, 0 }); + + auto tile_0_0_0 = source.createTileData(OverscaledTileID{ 0, 0, 0 }); + tile_0_0_0->ready = true; + auto tile_2_0_0 = source.createTileData(OverscaledTileID{ 2, 0, 0 }); + tile_2_0_0->ready = true; + + // Check that it uses the child tile, but not the parent tile. + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 0, 0, 0 }, MockRenderable{ { 0, 0, 0 }, *tile_0_0_0 } }, + { { 2, 0, 0 }, MockRenderable{ { 2, 0, 0 }, *tile_2_0_0 } }, + }), + source.renderables); + + // Then, remove the child tile and check that it now uses the parent tile. + source.dataTiles.erase(OverscaledTileID{ 2, 0, 0 }); + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 1); + EXPECT_EQ(decltype(source.renderables)({ + { { 0, 0, 0 }, MockRenderable{ { 0, 0, 0 }, *tile_0_0_0 } }, + }), + source.renderables); +} + +TEST(UpdateRenderables, DontUseTilesLowerThanMinzoom) { + MockSource source; + source.info.minZoom = 2; + source.idealTiles.emplace(UnwrappedTileID{ 2, 0, 0 }); + + auto tile_1_0_0 = source.createTileData(OverscaledTileID{ 1, 0, 0 }); + tile_1_0_0->ready = true; + + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 2); + EXPECT_EQ(decltype(source.renderables)({}), source.renderables); +} + +TEST(UpdateRenderables, UseOverzoomedTileAfterMaxzoom) { + MockSource source; + source.info.maxZoom = 2; + source.idealTiles.emplace(UnwrappedTileID{ 2, 0, 0 }); + + // Add a child tile (that should never occur in practice) and make sure it's not selected. + auto tile_3_3_0_0 = source.createTileData(OverscaledTileID{ 3, 0, 0 }); + tile_3_3_0_0->ready = true; + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 2); + EXPECT_EQ(decltype(source.renderables)({}), source.renderables); + + // Only add a non-overzoomed ("parent") tile at first. + auto tile_2_2_0_0 = source.createTileData(OverscaledTileID{ 2, { 2, 0, 0 } }); + tile_2_2_0_0->ready = true; + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 3); + EXPECT_EQ(decltype(source.renderables)({ + { { 2, 0, 0 }, MockRenderable{ { 2, 0, 0 }, *tile_2_2_0_0 } }, + }), + source.renderables); + + // Then add the overzoomed tile matching the zoom level we're rendering. + auto tile_3_2_0_0 = source.createTileData(OverscaledTileID{ 3, { 2, 0, 0 } }); + tile_3_2_0_0->ready = true; + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 3); + EXPECT_EQ(decltype(source.renderables)({ + { { 2, 0, 0 }, MockRenderable{ { 2, 0, 0 }, *tile_3_2_0_0 } }, + }), + source.renderables); + + // Check that it's switching back to the tile that has the matching overzoom value. + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 2); + EXPECT_EQ(decltype(source.renderables)({ + { { 2, 0, 0 }, MockRenderable{ { 2, 0, 0 }, *tile_2_2_0_0 } }, + }), + source.renderables); + + // Now remove the best match. + source.dataTiles.erase(OverscaledTileID{ 2, { 2, 0, 0 } }); + tile_2_2_0_0 = nullptr; + + // Use the overzoomed tile even though it doesn't match the zoom level. + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 2); + EXPECT_EQ(decltype(source.renderables)({ + { { 2, 0, 0 }, MockRenderable{ { 2, 0, 0 }, *tile_3_2_0_0 } }, + }), + source.renderables); +} + +TEST(UpdateRenderables, AscendToNonOverzoomedTiles) { + MockSource source; + source.info.maxZoom = 2; + source.idealTiles.emplace(UnwrappedTileID{ 2, 0, 0 }); + + // Add a matching overzoomed tile and make sure it gets selected. + auto tile_3_2_0_0 = source.createTileData(OverscaledTileID{ 3, { 2, 0, 0 } }); + tile_3_2_0_0->ready = true; + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 3); + EXPECT_EQ(decltype(source.renderables)({ + { { 2, 0, 0 }, MockRenderable{ { 2, 0, 0 }, *tile_3_2_0_0 } }, + }), + source.renderables); + + // Then, swap it with a non-overzoomed tile. + source.dataTiles.erase(OverscaledTileID{ 3, { 2, 0, 0 } }); + tile_3_2_0_0 = nullptr; + auto tile_2_2_0_0 = source.createTileData(OverscaledTileID{ 2, { 2, 0, 0 } }); + tile_2_2_0_0->ready = true; + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 3); + EXPECT_EQ(decltype(source.renderables)({ + { { 2, 0, 0 }, MockRenderable{ { 2, 0, 0 }, *tile_2_2_0_0 } }, + }), + source.renderables); + + // Then, swap it with a parent tile. + source.dataTiles.erase(OverscaledTileID{ 2, { 2, 0, 0 } }); + tile_2_2_0_0 = nullptr; + auto tile_1_1_0_0 = source.createTileData(OverscaledTileID{ 1, { 1, 0, 0 } }); + tile_1_1_0_0->ready = true; + source.renderables = algorithm::updateRenderables( + source.dataTiles, source.idealTiles, source.info, 3); + EXPECT_EQ(decltype(source.renderables)({ + { { 1, 0, 0 }, MockRenderable{ { 1, 0, 0 }, *tile_1_1_0_0 } }, + }), + source.renderables); +} diff --git a/test/map/tile.cpp b/test/map/tile.cpp deleted file mode 100644 index ad703595ad..0000000000 --- a/test/map/tile.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -#include - -using namespace mbgl; - - -TEST(Variant, isChild) { - ASSERT_TRUE(TileID(1, 0, 0, 1).isChildOf(TileID(0, 0, 0, 0))); - ASSERT_TRUE(TileID(1, 1, 0, 1).isChildOf(TileID(0, 0, 0, 0))); - ASSERT_TRUE(TileID(1, 2, 0, 1).isChildOf(TileID(0, 1, 0, 0))); - ASSERT_TRUE(TileID(1, 3, 0, 1).isChildOf(TileID(0, 1, 0, 0))); - ASSERT_TRUE(TileID(1, 4, 0, 1).isChildOf(TileID(0, 2, 0, 0))); - ASSERT_TRUE(TileID(1, 5, 0, 1).isChildOf(TileID(0, 2, 0, 0))); - ASSERT_TRUE(TileID(2, 0, 0, 2).isChildOf(TileID(0, 0, 0, 0))); - - ASSERT_TRUE(TileID(2, 8, 0, 2).isChildOf(TileID(0, 2, 0, 0))); - ASSERT_TRUE(TileID(2, 9, 0, 2).isChildOf(TileID(0, 2, 0, 0))); - ASSERT_TRUE(TileID(2, 10, 0, 2).isChildOf(TileID(0, 2, 0, 0))); - ASSERT_TRUE(TileID(2, 11, 0, 2).isChildOf(TileID(0, 2, 0, 0))); - ASSERT_TRUE(TileID(2, 12, 0, 2).isChildOf(TileID(0, 3, 0, 0))); - ASSERT_TRUE(TileID(2, 13, 0, 2).isChildOf(TileID(0, 3, 0, 0))); - - ASSERT_TRUE(TileID(1, -1, 0, 1).isChildOf(TileID(0, -1, 0, 0))); - ASSERT_TRUE(TileID(1, -2, 0, 1).isChildOf(TileID(0, -1, 0, 0))); - ASSERT_TRUE(TileID(1, -3, 0, 1).isChildOf(TileID(0, -2, 0, 0))); - ASSERT_TRUE(TileID(1, -4, 0, 1).isChildOf(TileID(0, -2, 0, 0))); - ASSERT_TRUE(TileID(2, -1, 0, 2).isChildOf(TileID(0, -1, 0, 0))); - ASSERT_TRUE(TileID(2, -2, 0, 2).isChildOf(TileID(0, -1, 0, 0))); - ASSERT_TRUE(TileID(2, -3, 0, 2).isChildOf(TileID(0, -1, 0, 0))); - ASSERT_TRUE(TileID(2, -4, 0, 2).isChildOf(TileID(0, -1, 0, 0))); - ASSERT_TRUE(TileID(2, -5, 0, 2).isChildOf(TileID(0, -2, 0, 0))); - ASSERT_TRUE(TileID(2, -6, 0, 2).isChildOf(TileID(0, -2, 0, 0))); - ASSERT_TRUE(TileID(2, -7, 0, 2).isChildOf(TileID(0, -2, 0, 0))); - ASSERT_TRUE(TileID(2, -8, 0, 2).isChildOf(TileID(0, -2, 0, 0))); - - ASSERT_FALSE(TileID(4, -16, 0, 4).isChildOf(TileID(0, -2, 0, 0))); - ASSERT_TRUE(TileID(4, -17, 0, 4).isChildOf(TileID(0, -2, 0, 0))); - - ASSERT_TRUE(TileID(2, -1, 0, 2).isChildOf(TileID(1, -1, 0, 1))); - ASSERT_TRUE(TileID(2, -2, 0, 2).isChildOf(TileID(1, -1, 0, 1))); - ASSERT_TRUE(TileID(2, -3, 0, 2).isChildOf(TileID(1, -2, 0, 1))); - ASSERT_TRUE(TileID(2, -4, 0, 2).isChildOf(TileID(1, -2, 0, 1))); - ASSERT_TRUE(TileID(3, -1, 0, 3).isChildOf(TileID(1, -1, 0, 1))); - ASSERT_TRUE(TileID(3, -2, 0, 3).isChildOf(TileID(1, -1, 0, 1))); - ASSERT_TRUE(TileID(3, -3, 0, 3).isChildOf(TileID(1, -1, 0, 1))); - ASSERT_TRUE(TileID(3, -4, 0, 3).isChildOf(TileID(1, -1, 0, 1))); - ASSERT_TRUE(TileID(3, -5, 0, 3).isChildOf(TileID(1, -2, 0, 1))); -} diff --git a/test/storage/offline.cpp b/test/storage/offline.cpp index e8f78425f5..3b64c0f50e 100644 --- a/test/storage/offline.cpp +++ b/test/storage/offline.cpp @@ -1,25 +1,22 @@ #include #include -#include +#include #include using namespace mbgl; -static const LatLngBounds sanFrancisco = LatLngBounds::hull( - { 37.6609, -122.5744 }, - { 37.8271, -122.3204 }); +static const LatLngBounds sanFrancisco = + LatLngBounds::hull({ 37.6609, -122.5744 }, { 37.8271, -122.3204 }); -static const LatLngBounds sanFranciscoWrapped = LatLngBounds::hull( - { 37.6609, 238.5744 }, - { 37.8271, 238.3204 }); +static const LatLngBounds sanFranciscoWrapped = + LatLngBounds::hull({ 37.6609, 238.5744 }, { 37.8271, 238.3204 }); TEST(OfflineTilePyramidRegionDefinition, TileCoverEmpty) { OfflineTilePyramidRegionDefinition region("", LatLngBounds::empty(), 0, 20, 1.0); SourceInfo info; - auto result = region.tileCover(SourceType::Vector, 512, info); - ASSERT_TRUE(result.empty()); + EXPECT_EQ((std::vector{}), region.tileCover(SourceType::Vector, 512, info)); } TEST(OfflineTilePyramidRegionDefinition, TileCoverZoomIntersection) { @@ -27,47 +24,39 @@ TEST(OfflineTilePyramidRegionDefinition, TileCoverZoomIntersection) { SourceInfo info; info.minZoom = 0; - auto resultIntersection = region.tileCover(SourceType::Vector, 512, info); - ASSERT_EQ(1, resultIntersection.size()); + EXPECT_EQ((std::vector{ { 2, 0, 1 } }), + region.tileCover(SourceType::Vector, 512, info)); info.minZoom = 3; - auto resultNoIntersection = region.tileCover(SourceType::Vector, 512, info); - ASSERT_TRUE(resultNoIntersection.empty()); + EXPECT_EQ((std::vector{}), region.tileCover(SourceType::Vector, 512, info)); } TEST(OfflineTilePyramidRegionDefinition, TileCoverTileSize) { OfflineTilePyramidRegionDefinition region("", LatLngBounds::world(), 0, 0, 1.0); SourceInfo info; - auto result512 = region.tileCover(SourceType::Vector, 512, info); - ASSERT_EQ(1, result512.size()); - ASSERT_EQ(0, result512[0].z); + EXPECT_EQ((std::vector{ { 0, 0, 0 } }), + region.tileCover(SourceType::Vector, 512, info)); - auto result256 = region.tileCover(SourceType::Vector, 256, info); - ASSERT_EQ(4, result256.size()); - ASSERT_EQ(1, result256[0].z); + EXPECT_EQ((std::vector{ { 1, 0, 0 }, { 1, 0, 1 }, { 1, 1, 0 }, { 1, 1, 1 } }), + region.tileCover(SourceType::Vector, 256, info)); } TEST(OfflineTilePyramidRegionDefinition, TileCoverZoomRounding) { OfflineTilePyramidRegionDefinition region("", sanFrancisco, 0.6, 0.7, 1.0); SourceInfo info; - auto resultVector = region.tileCover(SourceType::Vector, 512, info); - ASSERT_EQ(1, resultVector.size()); - ASSERT_EQ(0, resultVector[0].z); + EXPECT_EQ((std::vector{ { 0, 0, 0 } }), + region.tileCover(SourceType::Vector, 512, info)); - auto resultRaster = region.tileCover(SourceType::Raster, 512, info); - ASSERT_EQ(1, resultRaster.size()); - ASSERT_EQ(1, resultRaster[0].z); + EXPECT_EQ((std::vector{ { 1, 0, 0 } }), + region.tileCover(SourceType::Raster, 512, info)); } TEST(OfflineTilePyramidRegionDefinition, TileCoverWrapped) { OfflineTilePyramidRegionDefinition region("", sanFranciscoWrapped, 0, 0, 1.0); SourceInfo info; - auto result = region.tileCover(SourceType::Vector, 512, info); - ASSERT_EQ(1, result.size()); - ASSERT_EQ(0, result[0].z); - ASSERT_EQ(0, result[0].x); - ASSERT_EQ(0, result[0].y); + EXPECT_EQ((std::vector{ { 0, 0, 0 } }), + region.tileCover(SourceType::Vector, 512, info)); } diff --git a/test/test.gypi b/test/test.gypi index 2cb98df654..1db886e097 100644 --- a/test/test.gypi +++ b/test/test.gypi @@ -35,6 +35,8 @@ 'algorithm/covered_by_children.cpp', 'algorithm/generate_clip_ids.cpp', + 'algorithm/mock.hpp', + 'algorithm/update_renderables.cpp', 'api/annotations.cpp', 'api/api_misuse.cpp', @@ -46,7 +48,6 @@ 'geometry/binpack.cpp', 'map/map.cpp', - 'map/tile.cpp', 'map/transform.cpp', 'math/minmax.cpp', diff --git a/test/util/tile_cover.cpp b/test/util/tile_cover.cpp index d003653fd8..2fde6da54b 100644 --- a/test/util/tile_cover.cpp +++ b/test/util/tile_cover.cpp @@ -1,118 +1,85 @@ #include #include -#include +#include +#include #include -#include - using namespace mbgl; -using set = std::unordered_set; TEST(TileCover, Empty) { - auto result = tileCover(LatLngBounds::empty(), 0, 0); - ASSERT_TRUE(result.empty()); + EXPECT_EQ((std::vector{}), util::tileCover(LatLngBounds::empty(), 0)); } TEST(TileCover, Arctic) { - auto result = tileCover(LatLngBounds::hull({ 86, -180 }, { 90, 180 }), 0, 0); - ASSERT_TRUE(result.empty()); + EXPECT_EQ((std::vector{}), + util::tileCover(LatLngBounds::hull({ 86, -180 }, { 90, 180 }), 0)); } TEST(TileCover, Antarctic) { - auto result = tileCover(LatLngBounds::hull({ -86, -180 }, { -90, 180 }), 0, 0); - ASSERT_TRUE(result.empty()); + EXPECT_EQ((std::vector{}), + util::tileCover(LatLngBounds::hull({ -86, -180 }, { -90, 180 }), 0)); } TEST(TileCover, WorldZ0) { - auto result = tileCover(LatLngBounds::world(), 0, 0); - ASSERT_EQ(1, result.size()); - ASSERT_EQ(0, result[0].z); - ASSERT_EQ(0, result[0].x); - ASSERT_EQ(0, result[0].y); + EXPECT_EQ((std::vector{ + { 0, 0, 0 }, + }), + util::tileCover(LatLngBounds::world(), 0)); +} + +TEST(TileCover, Pitch) { + MockView view; + Transform transform(view, ConstrainMode::HeightOnly); + transform.resize({ { 512, 512 } }); + transform.setZoom(2); + transform.setPitch(40.0 * M_PI / 180.0); + + EXPECT_EQ((std::vector{ + { 2, 1, 1 }, { 2, 1, 2 }, { 2, 2, 1 }, { 2, 2, 2 }, + }), + util::tileCover(transform.getState(), 2)); } TEST(TileCover, WorldZ1) { - auto result = tileCover(LatLngBounds::world(), 1, 1); - ASSERT_EQ(4, result.size()); - ASSERT_EQ( - (set {{ - TileID(1, 1, 1, 1), - TileID(1, 0, 1, 1), - TileID(1, 1, 0, 1), - TileID(1, 0, 0, 1) - }}), - (set { - result.begin(), - result.end() - })); + EXPECT_EQ((std::vector{ + { 1, 0, 0 }, { 1, 0, 1 }, { 1, 1, 0 }, { 1, 1, 1 }, + }), + util::tileCover(LatLngBounds::world(), 1)); } -//TEST(TileCover, SingletonZ0) { -// auto result = tileCover(LatLngBounds::singleton({0, 0}), 0, 0); -// ASSERT_EQ(1, result.size()); -// ASSERT_EQ(0, result[0].z); -// ASSERT_EQ(0, result[0].x); -// ASSERT_EQ(0, result[0].y); -//} -// -//TEST(TileCover, SingletonZ1) { -// auto result = tileCover(LatLngBounds::singleton({0, 0}), 1, 1); -// ASSERT_EQ(1, result.size()); -// ASSERT_EQ(0, result[0].z); -// ASSERT_EQ(0, result[0].x); -// ASSERT_EQ(0, result[0].y); -//} - -static const LatLngBounds sanFrancisco = LatLngBounds::hull( - { 37.6609, -122.5744 }, - { 37.8271, -122.3204 }); +TEST(TileCover, SingletonZ0) { + EXPECT_EQ((std::vector{}), + util::tileCover(LatLngBounds::singleton({ 0, 0 }), 0)); +} + +TEST(TileCover, SingletonZ1) { + EXPECT_EQ((std::vector{}), + util::tileCover(LatLngBounds::singleton({ 0, 0 }), 1)); +} + +static const LatLngBounds sanFrancisco = + LatLngBounds::hull({ 37.6609, -122.5744 }, { 37.8271, -122.3204 }); TEST(TileCover, SanFranciscoZ0) { - auto result = tileCover(sanFrancisco, 0, 0); - ASSERT_EQ(1, result.size()); - ASSERT_EQ(0, result[0].w); - ASSERT_EQ(0, result[0].z); - ASSERT_EQ(0, result[0].x); - ASSERT_EQ(0, result[0].y); + EXPECT_EQ((std::vector{ + { 0, 0, 0 }, + }), + util::tileCover(sanFrancisco, 0)); } TEST(TileCover, SanFranciscoZ10) { - auto result = tileCover(sanFrancisco, 10, 10); - ASSERT_EQ(4, result.size()); - ASSERT_EQ( - (set {{ - TileID(10, 163, 395, 10), - TileID(10, 164, 395, 10), - TileID(10, 163, 396, 10), - TileID(10, 164, 396, 10) - }}), - (set { - result.begin(), - result.end() - })); + EXPECT_EQ((std::vector{ + { 10, 163, 395 }, { 10, 163, 396 }, { 10, 164, 395 }, { 10, 164, 396 }, + + }), + util::tileCover(sanFrancisco, 10)); } -//TEST(TileCover, OrderedByDistanceToCenter) { -// auto result = tileCover(sanFrancisco, 12, 12); -// ASSERT_EQ(12, result.size()); -// ASSERT_EQ( 12, result[0].z); -// ASSERT_EQ( 654, result[0].x); -// ASSERT_EQ(1583, result[0].y); -// ASSERT_EQ( 12, result[1].z); -// ASSERT_EQ( 655, result[1].x); -// ASSERT_EQ(1583, result[1].y); -//} -// -//static const LatLngBounds sanFranciscoWrapped = LatLngBounds::hull( -// { 37.6609, 238.5744 }, -// { 37.8271, 238.3204 }); -// -//TEST(TileCover, SanFranciscoZ0Wrapped) { -// auto result = tileCover(sanFranciscoWrapped, 0, 0); -// ASSERT_EQ(1, result.size()); -// ASSERT_EQ(1, result[0].w); -// ASSERT_EQ(0, result[0].z); -// ASSERT_EQ(0, result[0].x); -// ASSERT_EQ(0, result[0].y); -//} +static const LatLngBounds sanFranciscoWrapped = + LatLngBounds::hull({ 37.6609, 238.5744 }, { 37.8271, 238.3204 }); + +TEST(TileCover, SanFranciscoZ0Wrapped) { + EXPECT_EQ((std::vector{ { 0, 1, 0 } }), + util::tileCover(sanFranciscoWrapped, 0)); +} -- cgit v1.2.1