summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2018-06-11 14:02:15 +0200
committerKonstantin Käfer <mail@kkaefer.com>2018-06-12 17:18:22 +0200
commit5170b4689bcd677e45bea91725a825904658bc84 (patch)
tree1fb21e3bd6d0770d172ed4291c1b33539e2c6c17 /test
parent5429b035d8549dd18ae2c62a4499ebc6f575aa71 (diff)
downloadqtlocation-mapboxgl-5170b4689bcd677e45bea91725a825904658bc84.tar.gz
fix undefined behavior in LineAtlas::addDash
Diffstat (limited to 'test')
-rw-r--r--test/geometry/line_atlas.test.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/geometry/line_atlas.test.cpp b/test/geometry/line_atlas.test.cpp
new file mode 100644
index 0000000000..960e4ad7ad
--- /dev/null
+++ b/test/geometry/line_atlas.test.cpp
@@ -0,0 +1,31 @@
+#include <mbgl/test/util.hpp>
+
+#include <mbgl/geometry/line_atlas.hpp>
+
+#include <random>
+
+using namespace mbgl;
+
+TEST(LineAtlas, Random) {
+ std::mt19937 generator(42); // Use the same seed for reproducible tests.
+ std::uniform_int_distribution<size_t> countDistribution(0, 12);
+ std::uniform_int_distribution<size_t> capStyleDistribution(0, 1);
+ std::normal_distribution<float> lengthDistribution(3, 5);
+
+ for (size_t it = 0; it < 100; it++) {
+ LineAtlas atlas{ Size{ 128, 1024 } };
+ std::vector<float> dasharray;
+ dasharray.reserve(8);
+ for (size_t j = 0; j < 100; j++) {
+ dasharray.resize(0);
+ const size_t count = countDistribution(generator);
+ for (size_t i = 0; i < count; i++) {
+ dasharray.push_back(lengthDistribution(generator));
+ }
+ const LinePatternCap patternCap =
+ capStyleDistribution(generator) > 0 ? LinePatternCap::Round : LinePatternCap::Square;
+
+ atlas.addDash(dasharray, patternCap);
+ }
+ }
+}