diff options
author | Anand Thakker <anandthakker@users.noreply.github.com> | 2017-06-09 06:28:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-09 06:28:14 -0400 |
commit | f59eb822e12b54f74e688a138dc8f4ede1feade8 (patch) | |
tree | 7d0d9039e96fd7ffef8ff89c85c7dcf639737da2 /test/programs/symbol_program.test.cpp | |
parent | 66c2a2a0b7c42e1947f57a412ece66fa8eaac149 (diff) | |
download | qtlocation-mapboxgl-f59eb822e12b54f74e688a138dc8f4ede1feade8.tar.gz |
Fix undefined memory access in getCoveringRanges() (#9227)
* Add simple unit tests for SymbolSizeBinder
* Fix bug in symbol size uniform value calculation
For camera functions we were setting the zoom levels in "covering ranges" to
`[(zoom stop <= tile zoom), (zoom stop >= 1 + tile zoom)]`, but then evaluating
the function at `[tile_zoom, tile_zoom + 1]`.
* Check for it != end() before accessing it->first
Diffstat (limited to 'test/programs/symbol_program.test.cpp')
-rw-r--r-- | test/programs/symbol_program.test.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/programs/symbol_program.test.cpp b/test/programs/symbol_program.test.cpp new file mode 100644 index 0000000000..ef1e71c269 --- /dev/null +++ b/test/programs/symbol_program.test.cpp @@ -0,0 +1,61 @@ +#include <mbgl/test/util.hpp> + +#include <mbgl/programs/symbol_program.hpp> + +using namespace mbgl; + +TEST(SymbolProgram, SymbolSizeBinder) { + auto binder = SymbolSizeBinder::create(5.0f, 12.0f, 0.0f); + auto uniformValues = binder->uniformValues(5.5f); + EXPECT_EQ(uniformValues.get<uniforms::u_is_size_zoom_constant>().t, true); + EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, true); + EXPECT_EQ(uniformValues.get<uniforms::u_size>().t, 12.0f); + EXPECT_EQ(uniformValues.get<uniforms::u_layout_size>().t, 12.0f); + + binder = SymbolSizeBinder::create(1.0f, style::CameraFunction<float>(style::ExponentialStops<float>({ + {0.0f, 8.0f}, + {10.0f, 18.0f} + }, 1.0f)), 0.0f); + uniformValues = binder->uniformValues(1.5f); + EXPECT_EQ(uniformValues.get<uniforms::u_is_size_zoom_constant>().t, false); + EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, true); + EXPECT_EQ(uniformValues.get<uniforms::u_size>().t, 9.5f); + EXPECT_EQ(uniformValues.get<uniforms::u_layout_size>().t, 10.0f); + + binder = SymbolSizeBinder::create(0.0f, style::CameraFunction<float>(style::ExponentialStops<float>({ + {1.0f, 8.0f}, + {11.0f, 18.0f} + }, 1.0f)), 0.0f); + uniformValues = binder->uniformValues(0.5f); + EXPECT_EQ(uniformValues.get<uniforms::u_is_size_zoom_constant>().t, false); + EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, true); + EXPECT_EQ(uniformValues.get<uniforms::u_size>().t, 8.0f); + EXPECT_EQ(uniformValues.get<uniforms::u_layout_size>().t, 8.0f); + + binder = SymbolSizeBinder::create(12.0f, style::CameraFunction<float>(style::ExponentialStops<float>({ + {1.0f, 8.0f}, + {11.0f, 18.0f} + }, 1.0f)), 0.0f); + uniformValues = binder->uniformValues(12.5f); + EXPECT_EQ(uniformValues.get<uniforms::u_is_size_zoom_constant>().t, false); + EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, true); + EXPECT_EQ(uniformValues.get<uniforms::u_size>().t, 18.0f); + EXPECT_EQ(uniformValues.get<uniforms::u_layout_size>().t, 18.0f); + + binder = SymbolSizeBinder::create(0.0f, style::SourceFunction<float>("x", style::ExponentialStops<float>({ + {1.0f, 8.0f}, + {11.0f, 18.0f} + }, 1.0f)), 0.0f); + uniformValues = binder->uniformValues(12.5f); + EXPECT_EQ(uniformValues.get<uniforms::u_is_size_zoom_constant>().t, true); + EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, false); + + binder = SymbolSizeBinder::create(5.0f, style::CompositeFunction<float>("x", style::CompositeExponentialStops<float>({ + {1.0f, {{0.0f, 8.0f}, {100.0f, 18.0f}}}, + {11.0f, {{0.0f, 12.0f}, {100.0f, 24.9f}}} + }, 1.0f)), 0.0f); + uniformValues = binder->uniformValues(5.5f); + EXPECT_EQ(uniformValues.get<uniforms::u_is_size_zoom_constant>().t, false); + EXPECT_EQ(uniformValues.get<uniforms::u_is_size_feature_constant>().t, false); + EXPECT_EQ(uniformValues.get<uniforms::u_size_t>().t, 0.45f); +} |