From 9af5172f98a4319ba4d8d9d4cb7a24ac8bd9ea12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Mon, 11 Jun 2018 14:02:15 +0200 Subject: [core] fix undefined behavior in LineAtlas::addDash --- test/geometry/line_atlas.test.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/geometry/line_atlas.test.cpp (limited to 'test') 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 + +#include + +#include + +using namespace mbgl; + +TEST(LineAtlas, Random) { + std::mt19937 generator(42); // Use the same seed for reproducible tests. + std::uniform_int_distribution countDistribution(0, 12); + std::uniform_int_distribution capStyleDistribution(0, 1); + std::normal_distribution lengthDistribution(3, 5); + + for (size_t it = 0; it < 100; it++) { + LineAtlas atlas{ Size{ 128, 1024 } }; + std::vector 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); + } + } +} -- cgit v1.2.1