From 06a0c4ad15a335e1fe8c66886d8b9f75d6e3bdbe Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Wed, 5 Jul 2017 16:31:16 +0300 Subject: [test] Added bucket feature insertion tests --- test/gl/bucket.test.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'test') diff --git a/test/gl/bucket.test.cpp b/test/gl/bucket.test.cpp index feca82998f..fdff0e990a 100644 --- a/test/gl/bucket.test.cpp +++ b/test/gl/bucket.test.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -14,21 +15,54 @@ using namespace mbgl; TEST(Buckets, CircleBucket) { + gl::Context context; CircleBucket bucket { { {0, 0, 0}, MapMode::Still, 1.0 }, {} }; ASSERT_FALSE(bucket.hasData()); ASSERT_FALSE(bucket.needsUpload()); + + GeometryCollection point { { { 0, 0 } } }; + bucket.addFeature(StubGeometryTileFeature { {}, FeatureType::Point, point, {} }, point); + ASSERT_TRUE(bucket.hasData()); + ASSERT_TRUE(bucket.needsUpload()); + + bucket.upload(context); + ASSERT_TRUE(bucket.hasData()); + ASSERT_FALSE(bucket.needsUpload()); } TEST(Buckets, FillBucket) { + gl::Context context; FillBucket bucket { { {0, 0, 0}, MapMode::Still, 1.0 }, {} }; ASSERT_FALSE(bucket.hasData()); ASSERT_FALSE(bucket.needsUpload()); + + GeometryCollection polygon { { { 0, 0 }, { 0, 1 }, { 1, 1 } } }; + bucket.addFeature(StubGeometryTileFeature { {}, FeatureType::Polygon, polygon, {} }, polygon); + ASSERT_TRUE(bucket.hasData()); + ASSERT_TRUE(bucket.needsUpload()); + + bucket.upload(context); + ASSERT_FALSE(bucket.needsUpload()); } TEST(Buckets, LineBucket) { + gl::Context context; LineBucket bucket { { {0, 0, 0}, MapMode::Still, 1.0 }, {}, {} }; ASSERT_FALSE(bucket.hasData()); ASSERT_FALSE(bucket.needsUpload()); + + // Ignore invalid feature type. + GeometryCollection point { { { 0, 0 } } }; + bucket.addFeature(StubGeometryTileFeature { {}, FeatureType::Point, point, {} }, point); + ASSERT_FALSE(bucket.hasData()); + + GeometryCollection line { { { 0, 0 }, { 1, 1 } } }; + bucket.addFeature(StubGeometryTileFeature { {}, FeatureType::LineString, line, {} }, line); + ASSERT_TRUE(bucket.hasData()); + ASSERT_TRUE(bucket.needsUpload()); + + bucket.upload(context); + ASSERT_FALSE(bucket.needsUpload()); } TEST(Buckets, SymbolBucket) { @@ -36,18 +70,34 @@ TEST(Buckets, SymbolBucket) { bool sdfIcons = false; bool iconsNeedLinear = false; + gl::Context context; SymbolBucket bucket { layout, {}, 16.0f, 1.0f, 0, sdfIcons, iconsNeedLinear }; ASSERT_FALSE(bucket.hasIconData()); ASSERT_FALSE(bucket.hasTextData()); ASSERT_FALSE(bucket.hasCollisionBoxData()); ASSERT_FALSE(bucket.hasData()); ASSERT_FALSE(bucket.needsUpload()); + + // SymbolBucket::addFeature() is a no-op. + GeometryCollection point { { { 0, 0 } } }; + bucket.addFeature(StubGeometryTileFeature { {}, FeatureType::Point, point, {} }, point); + ASSERT_FALSE(bucket.hasData()); + ASSERT_FALSE(bucket.needsUpload()); + + bucket.text.segments.emplace_back(0, 0); + ASSERT_TRUE(bucket.hasTextData()); + ASSERT_TRUE(bucket.hasData()); + ASSERT_TRUE(bucket.needsUpload()); + + bucket.upload(context); + ASSERT_FALSE(bucket.needsUpload()); } TEST(Buckets, RasterBucket) { gl::Context context; UnassociatedImage rgba({ 1, 1 }); + // RasterBucket::hasData() is always true. RasterBucket bucket = { std::move(rgba) }; ASSERT_TRUE(bucket.hasData()); ASSERT_TRUE(bucket.needsUpload()); -- cgit v1.2.1