From bdb1e5758174dc9a866b5698623b1c09b6b89d0c Mon Sep 17 00:00:00 2001 From: Sergey Yershov Date: Thu, 14 Nov 2019 19:28:39 +0300 Subject: [PATCH 1/2] [core] Fix incorrect resizing of TileCache --- src/mbgl/tile/tile_cache.cpp | 4 +- test/test-files.json | 1 + test/tile/tile_cache.test.cpp | 90 +++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 test/tile/tile_cache.test.cpp diff --git a/src/mbgl/tile/tile_cache.cpp b/src/mbgl/tile/tile_cache.cpp index d9363ead8fc..272ecdfee58 100644 --- a/src/mbgl/tile/tile_cache.cpp +++ b/src/mbgl/tile/tile_cache.cpp @@ -8,7 +8,7 @@ void TileCache::setSize(size_t size_) { while (orderedKeys.size() > size) { auto key = orderedKeys.front(); - orderedKeys.pop_front(); + orderedKeys.remove(key); tiles.erase(key); } @@ -21,7 +21,7 @@ void TileCache::add(const OverscaledTileID& key, std::unique_ptr tile) { } // insert new or query existing tile - if (tiles.emplace(key, std::move(tile)).second) { + if (!tiles.emplace(key, std::move(tile)).second) { // remove existing tile key orderedKeys.remove(key); } diff --git a/test/test-files.json b/test/test-files.json index a98e896e7e7..1d220f579d1 100644 --- a/test/test-files.json +++ b/test/test-files.json @@ -79,6 +79,7 @@ "test/tile/geometry_tile_data.test.cpp", "test/tile/raster_dem_tile.test.cpp", "test/tile/raster_tile.test.cpp", + "test/tile/tile_cache.test.cpp", "test/tile/tile_coordinate.test.cpp", "test/tile/tile_id.test.cpp", "test/tile/vector_tile.test.cpp", diff --git a/test/tile/tile_cache.test.cpp b/test/tile/tile_cache.test.cpp new file mode 100644 index 00000000000..521432e69a9 --- /dev/null +++ b/test/tile/tile_cache.test.cpp @@ -0,0 +1,90 @@ +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace mbgl; + +class VectorTileTest { +public: + std::shared_ptr fileSource = std::make_shared(); + TransformState transformState; + util::RunLoop loop; + style::Style style { *fileSource, 1 }; + AnnotationManager annotationManager { style }; + ImageManager imageManager; + GlyphManager glyphManager; + Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" }; + + TileParameters tileParameters { + 1.0, + MapDebugOptions(), + transformState, + fileSource, + MapMode::Continuous, + annotationManager, + imageManager, + glyphManager, + 0 + }; +}; + +class VectorTileMock : public VectorTile { + public: + VectorTileMock(const OverscaledTileID & id, + std::string sourceID, + const TileParameters & parameters, + const Tileset & tileset) : VectorTile(id, sourceID, parameters, tileset) + { renderable = true; } +}; + + +TEST(TileCache, Smoke) { + VectorTileTest test; + TileCache cache(1); + OverscaledTileID id(0,0,0); + std::unique_ptr tile = std::make_unique(id, "source", test.tileParameters, test.tileset); + + cache.add(id, std::move(tile)); + EXPECT_TRUE(cache.has(id)); + cache.clear(); + EXPECT_FALSE(cache.has(id)); +} + + +TEST(TileCache, Issue15926) { + VectorTileTest test; + TileCache cache(2); + OverscaledTileID id0(0,0,0); + OverscaledTileID id1(1,0,0); + std::unique_ptr tile1 = std::make_unique(id0, "source", test.tileParameters, test.tileset); + std::unique_ptr tile2 = std::make_unique(id0, "source", test.tileParameters, test.tileset); + std::unique_ptr tile3 = std::make_unique(id1, "source", test.tileParameters, test.tileset); + + cache.add(id0, std::move(tile1)); + EXPECT_TRUE(cache.has(id0)); + cache.add(id0, std::move(tile2)); + cache.setSize(1); + cache.add(id1, std::move(tile3)); + EXPECT_FALSE(cache.has(id0)); + EXPECT_TRUE(cache.has(id1)); +} + From 01292274cf080cf700fdd24d9527c93d79635c83 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Tue, 19 Nov 2019 14:20:59 +0200 Subject: [PATCH 2/2] [core] Identation and build fixes --- next/test/CMakeLists.txt | 1 + test/tile/tile_cache.test.cpp | 65 +++++++++++++++++------------------ 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/next/test/CMakeLists.txt b/next/test/CMakeLists.txt index 4995fa4e56b..12a6d8108cc 100644 --- a/next/test/CMakeLists.txt +++ b/next/test/CMakeLists.txt @@ -77,6 +77,7 @@ add_library( ${MBGL_ROOT}/test/tile/geometry_tile_data.test.cpp ${MBGL_ROOT}/test/tile/raster_dem_tile.test.cpp ${MBGL_ROOT}/test/tile/raster_tile.test.cpp + ${MBGL_ROOT}/test/tile/tile_cache.test.cpp ${MBGL_ROOT}/test/tile/tile_coordinate.test.cpp ${MBGL_ROOT}/test/tile/tile_id.test.cpp ${MBGL_ROOT}/test/tile/vector_tile.test.cpp diff --git a/test/tile/tile_cache.test.cpp b/test/tile/tile_cache.test.cpp index 521432e69a9..e64ad0bb79c 100644 --- a/test/tile/tile_cache.test.cpp +++ b/test/tile/tile_cache.test.cpp @@ -3,21 +3,21 @@ #include #include +#include #include #include -#include -#include +#include +#include #include -#include -#include -#include #include -#include -#include -#include #include +#include +#include +#include +#include #include +#include #include @@ -28,39 +28,38 @@ class VectorTileTest { std::shared_ptr fileSource = std::make_shared(); TransformState transformState; util::RunLoop loop; - style::Style style { *fileSource, 1 }; - AnnotationManager annotationManager { style }; + style::Style style{*fileSource, 1}; + AnnotationManager annotationManager{style}; ImageManager imageManager; GlyphManager glyphManager; - Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" }; + Tileset tileset{{"https://example.com"}, {0, 22}, "none"}; - TileParameters tileParameters { - 1.0, - MapDebugOptions(), - transformState, - fileSource, - MapMode::Continuous, - annotationManager, - imageManager, - glyphManager, - 0 - }; + TileParameters tileParameters{1.0, + MapDebugOptions(), + transformState, + fileSource, + MapMode::Continuous, + annotationManager, + imageManager, + glyphManager, + 0}; }; class VectorTileMock : public VectorTile { - public: - VectorTileMock(const OverscaledTileID & id, - std::string sourceID, - const TileParameters & parameters, - const Tileset & tileset) : VectorTile(id, sourceID, parameters, tileset) - { renderable = true; } +public: + VectorTileMock(const OverscaledTileID& id, + std::string sourceID, + const TileParameters& parameters, + const Tileset& tileset) + : VectorTile(id, sourceID, parameters, tileset) { + renderable = true; + } }; - TEST(TileCache, Smoke) { VectorTileTest test; TileCache cache(1); - OverscaledTileID id(0,0,0); + OverscaledTileID id(0, 0, 0); std::unique_ptr tile = std::make_unique(id, "source", test.tileParameters, test.tileset); cache.add(id, std::move(tile)); @@ -69,12 +68,11 @@ TEST(TileCache, Smoke) { EXPECT_FALSE(cache.has(id)); } - TEST(TileCache, Issue15926) { VectorTileTest test; TileCache cache(2); - OverscaledTileID id0(0,0,0); - OverscaledTileID id1(1,0,0); + OverscaledTileID id0(0, 0, 0); + OverscaledTileID id1(1, 0, 0); std::unique_ptr tile1 = std::make_unique(id0, "source", test.tileParameters, test.tileset); std::unique_ptr tile2 = std::make_unique(id0, "source", test.tileParameters, test.tileset); std::unique_ptr tile3 = std::make_unique(id1, "source", test.tileParameters, test.tileset); @@ -87,4 +85,3 @@ TEST(TileCache, Issue15926) { EXPECT_FALSE(cache.has(id0)); EXPECT_TRUE(cache.has(id1)); } -