Files
MapLibreParticleLab/test/style/style.test.cpp
Petr Pokorny d62ff400c6 Replacing hardcoded configuration with configurable API and removing Mapbox assets (#90)
* Refactoring online file source so that tile server configuration is not hardcoded - part 1

* Added default templates

* Update from master

* Renaming MGLAccountManager to MGLSettings. Passing ResourceOptions and TileServerOptions to relevant classes and method in order to remove mapbox hardocded configuration

* Fixing build

* Addedm missing theme

* Unit tests fixes

* Fixing unit tests, adding factory methods for creating predefined configuration.

* Fixing mapbox unit tests

* Additional unit test fixes

* Making MapboxConfiguration default

* Making get/set resource options available in all classes that inherits from FileSource

* Making get/set resource options available in all classes that inherits from FileSource - part 2

* Fixes for Android

* Disable test coverage reports

* Disable test coverage reports

* Disable test coverage reports

* Disable test coverage reports

* Removing hardcoded configuration in iOS project - part 1

* Fixing wrong file extension, making use of tile server options.

* Use apiKey and MGL_API_KEY everywhere

* Just a rename

* Re-enabling tests and improving MGLSettings init

* Removing mapbox hardcoded configuration, using api key everywhere, implementing JNI conversion for TileServerOptions

* Lint issues.

* Integrating configurable tile server properties into Android SDK - part 2

* Removing mabox accounts

* Exposing multiple configurations to Android SDK - bug fixes

* Removing TileServerOptions from public interface - native methods dont work before mapbox-gl library is loaded

* Adding support for configurable predefined styles

* Migrating predefined styles in test app + cleanup

* Parameter fix

* Bug fixes

* Fixing render test build

* Fixing offline tester

* Fixing benchmark tool

* Fix: typo in method name

* Adding code for public access to TileServerOptions

* Bug fixes and debug code removal

* Fixes for macOS, adding unit tests from MapLibre, removing redundant members from OnlineFileSource

* Unit test fixes

* MacOS test app - migrating to configurable tile server options, part 1

* Fixing offline maps

* Migrating macOS test app to MapTiler

* Minor improvements

* Putting back apiKey test

* Added unit tests for MapTiler configuration

* Migrating test resources to MapTiler

* minor fix

* A few fixes

* Fixing macOS tests, removing feedback functionality

* Migrating ios test app to MapTiler

* Migrating ui tests

* UI tests fix

* Benchmarking app fix

* Cleanup and strings updates

* Migrating benchmark app to maptiler

* API key injection in benchmark app

* Putting back release configuration

* Additional tests and fixing issues identified by thread sanitizer.

* Removing test filters

* Fixes and addressing lint issues

* More Maptiler tests + minro fix

* Android instrumentation test migration to MapTiler. Exposing missing TileServerOptions in Android SDK. Minor fixes.

* No requirements on API key format.

* Fixing offline cache test tool

* Adding configurable domain name for sources, adding source domain int MapTiler configuration, cleanup

* Migrating tests to MapTiler, adding code for canonicalizing URLs, removing mapbox stuff from comments, cleanup

* More tests

* Updated database size

* Lint issues

* Fixed test

* Updating developer config API key

* Fixes for Android, propagaing updated tileServerOptions to native file sources, more tests

* Just a few more fixes

* Propagating updated settings to file sources + additional unit test

* Lint issues

* Removing test filter and fixing incorrect uri

* Release preparation

* macos release notes
2021-06-29 12:44:51 +02:00

162 lines
5.7 KiB
C++

#include <mbgl/test/util.hpp>
#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/test/fixture_log_observer.hpp>
#include <mbgl/style/style_impl.hpp>
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/sources/vector_source.hpp>
#include <mbgl/style/layer.hpp>
#include <mbgl/style/layers/line_layer.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
#include <memory>
using namespace mbgl;
using namespace mbgl::style;
TEST(Style, Properties) {
util::RunLoop loop;
auto fileSource = std::make_shared<StubFileSource>();
Style::Impl style { fileSource, 1.0 };
style.loadJSON(R"STYLE({"name": "Test"})STYLE");
ASSERT_EQ("Test", style.getName());
style.loadJSON(R"STYLE({"center": [10, 20]})STYLE");
ASSERT_EQ("", style.getName());
ASSERT_EQ((LatLng{20, 10}), *style.getDefaultCamera().center);
style.loadJSON(R"STYLE({"bearing": 24})STYLE");
ASSERT_EQ("", style.getName());
ASSERT_EQ(LatLng {}, *style.getDefaultCamera().center);
ASSERT_EQ(24, *style.getDefaultCamera().bearing);
style.loadJSON(R"STYLE({"zoom": 13.3})STYLE");
ASSERT_EQ("", style.getName());
ASSERT_EQ(13.3, *style.getDefaultCamera().zoom);
style.loadJSON(R"STYLE({"pitch": 60})STYLE");
ASSERT_EQ("", style.getName());
ASSERT_EQ(60, *style.getDefaultCamera().pitch);
style.loadJSON(R"STYLE({})STYLE");
ASSERT_EQ(Milliseconds(300), *style.getTransitionOptions().duration);
ASSERT_EQ(optional<Duration> {}, style.getTransitionOptions().delay);
style.loadJSON(R"STYLE({"transition": { "duration": 500, "delay": 50 }})STYLE");
ASSERT_EQ(Milliseconds(500), *style.getTransitionOptions().duration);
ASSERT_EQ(Milliseconds(50), *style.getTransitionOptions().delay);
style.loadJSON(R"STYLE({"name": 23, "center": {}, "bearing": "north", "zoom": null, "pitch": "wide"})STYLE");
ASSERT_EQ("", style.getName());
ASSERT_EQ(LatLng {}, *style.getDefaultCamera().center);
ASSERT_EQ(0, *style.getDefaultCamera().zoom);
ASSERT_EQ(0, *style.getDefaultCamera().bearing);
ASSERT_EQ(0, *style.getDefaultCamera().pitch);
}
TEST(Style, DuplicateSource) {
util::RunLoop loop;
auto fileSource = std::make_shared<StubFileSource>();
Style::Impl style { fileSource, 1.0 };
style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
style.addSource(std::make_unique<VectorSource>("sourceId", "mptiler://tiles/contours"));
try {
style.addSource(std::make_unique<VectorSource>("sourceId", "mptiler://tiles/contours"));
FAIL() << "Should not have been allowed to add a duplicate source id";
} catch (const std::runtime_error&) {
// Expected
}
}
TEST(Style, RemoveSourceInUse) {
util::RunLoop loop;
auto log = new FixtureLogObserver();
Log::setObserver(std::unique_ptr<Log::Observer>(log));
auto fileSource = std::make_shared<StubFileSource>();
Style::Impl style { fileSource, 1.0 };
style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
style.addSource(std::make_unique<VectorSource>("sourceId", "mptiler://tiles/contours"));
style.addLayer(std::make_unique<LineLayer>("layerId", "sourceId"));
// Should not remove the source
auto removed = style.removeSource("sourceId");
ASSERT_EQ(nullptr, removed);
ASSERT_NE(nullptr, style.getSource("sourceId"));
const FixtureLogObserver::LogMessage logMessage {
EventSeverity::Warning,
Event::General,
int64_t(-1),
"Source 'sourceId' is in use, cannot remove",
};
EXPECT_EQ(log->count(logMessage), 1u);
}
TEST(Style, SourceImplsOrder) {
util::RunLoop loop;
auto fileSource = std::make_shared<StubFileSource>();
Style::Impl style{fileSource, 1.0};
style.addSource(std::make_unique<VectorSource>("c", "mptiler://tiles/contours"));
style.addSource(std::make_unique<VectorSource>("b", "mptiler://tiles/contours"));
style.addSource(std::make_unique<VectorSource>("a", "mptiler://tiles/contours"));
auto sources = style.getSources();
ASSERT_EQ(3u, sources.size());
EXPECT_EQ("c", sources[0]->getID());
EXPECT_EQ("b", sources[1]->getID());
EXPECT_EQ("a", sources[2]->getID());
const auto& sourceImpls = *style.getSourceImpls();
ASSERT_EQ(3u, sourceImpls.size());
EXPECT_EQ("a", sourceImpls[0]->id);
EXPECT_EQ("b", sourceImpls[1]->id);
EXPECT_EQ("c", sourceImpls[2]->id);
}
TEST(Style, AddRemoveImage) {
util::RunLoop loop;
auto fileSource = std::make_shared<StubFileSource>();
Style::Impl style{fileSource, 1.0};
style.addImage(std::make_unique<style::Image>("one", PremultipliedImage({16, 16}), 2));
style.addImage(std::make_unique<style::Image>("two", PremultipliedImage({16, 16}), 2));
style.addImage(std::make_unique<style::Image>("three", PremultipliedImage({16, 16}), 2));
style.removeImage("one");
style.removeImage("two");
EXPECT_TRUE(!!style.getImage("three"));
EXPECT_FALSE(!!style.getImage("two"));
EXPECT_FALSE(!!style.getImage("four"));
}
TEST(Style, AddRemoveRemoveImage) {
// regression test for https://github.com/mapbox/mapbox-gl-native/pull/16391
util::RunLoop loop;
auto fileSource = std::make_shared<StubFileSource>();
Style::Impl style{fileSource, 1.0};
style.addImage(std::make_unique<style::Image>("one", PremultipliedImage({16, 16}), 2));
style.addImage(std::make_unique<style::Image>("two", PremultipliedImage({16, 16}), 2));
style.addImage(std::make_unique<style::Image>("three", PremultipliedImage({16, 16}), 2));
style.removeImage("one");
style.removeImage("two");
style.removeImage("two");
EXPECT_TRUE(!!style.getImage("three"));
EXPECT_FALSE(!!style.getImage("two"));
EXPECT_FALSE(!!style.getImage("four"));
}