diff options
author | Langston Smith <langston.smith@mapbox.com> | 2018-01-04 11:15:50 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-04 11:15:50 -0800 |
commit | 2ea955d2751ba6459f99a0695e53505c0a11702b (patch) | |
tree | f54450918b634a2eea1bd2c4ebc671bf1bb06106 /test/renderer/backend_scope.test.cpp | |
parent | f2ec6ae326bad79fea2b06a21151a2835522572a (diff) | |
parent | c62b0af24fc76b4bb2eb34100611dd3ee9ee5536 (diff) | |
download | qtlocation-mapboxgl-upstream/ls-android-readme-tweaks.tar.gz |
Merge branch 'master' into ls-android-readme-tweaksupstream/ls-android-readme-tweaks
Diffstat (limited to 'test/renderer/backend_scope.test.cpp')
-rw-r--r-- | test/renderer/backend_scope.test.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/test/renderer/backend_scope.test.cpp b/test/renderer/backend_scope.test.cpp new file mode 100644 index 0000000000..05b82695b2 --- /dev/null +++ b/test/renderer/backend_scope.test.cpp @@ -0,0 +1,112 @@ +#include <mbgl/test/util.hpp> + +#include <mbgl/renderer/renderer_backend.hpp> +#include <mbgl/renderer/backend_scope.hpp> + +#include <functional> + +using namespace mbgl; + +class StubRendererBackend: public RendererBackend { +public: + void bind() override { + } + + mbgl::Size getFramebufferSize() const override { + return mbgl::Size{}; + } + + void activate() override { + if (activateFunction) activateFunction(); + } + + void deactivate() override { + if (deactivateFunction) deactivateFunction(); + } + + void updateAssumedState() override { + if (updateAssumedStateFunction) updateAssumedStateFunction(); + } + + gl::ProcAddress getExtensionFunctionPointer(const char*) override { + return {}; + } + + std::function<void ()> activateFunction; + std::function<void ()> deactivateFunction; + std::function<void ()> updateAssumedStateFunction; +}; + +// A scope should activate on construction +// and deactivate on descruction (going out +// of scope) +TEST(BackendScope, SingleScope) { + bool activated; + bool deactivated; + + StubRendererBackend backend; + backend.activateFunction = [&] { activated = true; }; + backend.deactivateFunction = [&] { deactivated = true; }; + + { + BackendScope test { backend }; + } + + ASSERT_TRUE(activated); + ASSERT_TRUE(deactivated); +} + +// With nested scopes, only the outer scope +// should activate/deactivate +TEST(BackendScope, NestedScopes) { + int activated = 0; + int deactivated = 0; + + StubRendererBackend backend; + backend.activateFunction = [&] { activated++; }; + backend.deactivateFunction = [&] { deactivated++; }; + + { + BackendScope outer { backend }; + ASSERT_EQ(1, activated); + { + BackendScope inner { backend }; + ASSERT_EQ(1, activated); + } + ASSERT_EQ(0, deactivated); + } + + ASSERT_EQ(1, deactivated); +} + +// With chained scopes, where scopes have +// different backends, the scopes should each +// activate the scope on entering and de-activating +// on leaving the scope +TEST(BackendScope, ChainedScopes) { + bool activatedA = false; + bool activatedB = false; + + StubRendererBackend backendA; + backendA.activateFunction = [&] { activatedA = true; }; + backendA.deactivateFunction = [&] { activatedA = false; }; + + StubRendererBackend backendB; + backendB.activateFunction = [&] { activatedB = true; }; + backendB.deactivateFunction = [&] { activatedB = false; }; + + { + BackendScope scopeA { backendA }; + ASSERT_TRUE(activatedA); + { + BackendScope scopeB { backendB }; + ASSERT_FALSE(activatedA); + ASSERT_TRUE(activatedB); + } + ASSERT_FALSE(activatedB); + ASSERT_TRUE(activatedA); + } + + ASSERT_FALSE(activatedA); + ASSERT_FALSE(activatedB); +} |