Add clang-format (#1086)

Co-authored-by: mwilsnd <mwilsnd@gmail.com>
This commit is contained in:
Bart Louwers
2023-05-01 16:57:37 +02:00
committed by GitHub
parent 403a12bd1b
commit 71f6da2722
1018 changed files with 27876 additions and 25862 deletions

View File

@@ -8,13 +8,13 @@ namespace conversion {
class MockConvertible {
public:
MockConvertible() = default;
MockConvertible(int* counter_) : counter(counter_) {}
MockConvertible(int* counter_)
: counter(counter_) {}
MockConvertible(MockConvertible&& other) noexcept : counter(other.counter) {}
MockConvertible(MockConvertible&& other) noexcept
: counter(other.counter) {}
~MockConvertible() {
++*counter;
}
~MockConvertible() { ++*counter; }
int* counter = nullptr;
};
@@ -22,58 +22,34 @@ public:
template <>
class ConversionTraits<MockConvertible> {
public:
static bool isUndefined(const MockConvertible&) {
return false;
}
static bool isUndefined(const MockConvertible&) { return false; }
static bool isArray(const MockConvertible&) {
return false;
}
static bool isArray(const MockConvertible&) { return false; }
static bool isObject(const MockConvertible&) {
return false;
}
static bool isObject(const MockConvertible&) { return false; }
static std::size_t arrayLength(const MockConvertible&) {
return 0u;
}
static std::size_t arrayLength(const MockConvertible&) { return 0u; }
static MockConvertible arrayMember(const MockConvertible&, std::size_t) {
return {};
}
static MockConvertible arrayMember(const MockConvertible&, std::size_t) { return {}; }
static std::optional<MockConvertible> objectMember(const MockConvertible&, const char *) {
return std::nullopt;
}
static std::optional<MockConvertible> objectMember(const MockConvertible&, const char*) { return std::nullopt; }
template <class Fn>
static std::optional<Error> eachMember(const MockConvertible&, Fn&&) {
return std::nullopt;
}
static std::optional<bool> toBool(const MockConvertible&) {
return std::nullopt;
}
static std::optional<bool> toBool(const MockConvertible&) { return std::nullopt; }
static std::optional<float> toNumber(const MockConvertible&) {
return std::nullopt;
}
static std::optional<float> toNumber(const MockConvertible&) { return std::nullopt; }
static std::optional<double> toDouble(const MockConvertible&) {
return std::nullopt;
}
static std::optional<double> toDouble(const MockConvertible&) { return std::nullopt; }
static std::optional<std::string> toString(const MockConvertible&) {
return std::nullopt;
}
static std::optional<std::string> toString(const MockConvertible&) { return std::nullopt; }
static std::optional<mbgl::Value> toValue(const MockConvertible&) {
return std::nullopt;
}
static std::optional<mbgl::Value> toValue(const MockConvertible&) { return std::nullopt; }
static std::optional<GeoJSON> toGeoJSON(const MockConvertible&, Error&) {
return std::nullopt;
}
static std::optional<GeoJSON> toGeoJSON(const MockConvertible&, Error&) { return std::nullopt; }
};
} // namespace conversion

View File

@@ -62,18 +62,23 @@ TEST(StyleConversion, CompositeFunctionExpression) {
auto fn1 = parseFunction(R"(["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10])");
ASSERT_TRUE(fn1);
auto fn2 = parseFunction(R"(["coalesce", ["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10], 0])");
auto fn2 = parseFunction(
R"(["coalesce", ["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10], 0])");
ASSERT_TRUE(fn2);
auto fn3 = parseFunction(R"(["let", "a", 0, ["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10] ])");
auto fn3 = parseFunction(
R"(["let", "a", 0, ["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10] ])");
ASSERT_TRUE(fn3);
auto fn4 = parseFunction(R"(["coalesce", ["let", "a", 0, ["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10]], 0])");
auto fn4 = parseFunction(
R"(["coalesce", ["let", "a", 0, ["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10]], 0])");
ASSERT_TRUE(fn4);
auto fn5 = parseFunction(R"(["coalesce", ["interpolate", ["linear"], ["number", ["get", "x"]], 0, ["zoom"], 10, 10], 0])");
auto fn5 = parseFunction(
R"(["coalesce", ["interpolate", ["linear"], ["number", ["get", "x"]], 0, ["zoom"], 10, 10], 0])");
ASSERT_FALSE(fn5);
ASSERT_EQ(R"("zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.)", error.message);
ASSERT_EQ(R"("zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.)",
error.message);
}
TEST(StyleConversion, TokenStrings) {
@@ -88,12 +93,14 @@ TEST(StyleConversion, TokenStrings) {
ASSERT_EQ(*convertTokenStringToExpression("{token}"), *toString(get(literal("token"))));
ASSERT_EQ(*convertTokenStringToExpression("token {token}"), *concat(vec(literal("token "), get(literal("token")))));
ASSERT_EQ(*convertTokenStringToExpression("{token} token"), *concat(vec(get(literal("token")), literal(" token"))));
ASSERT_EQ(*convertTokenStringToExpression("{token} {token}"), *concat(vec(get(literal("token")), literal(" "), get(literal("token")))));
ASSERT_EQ(*convertTokenStringToExpression("{token} {token"), *concat(vec(get(literal("token")), literal(" "), literal("{token"))));
ASSERT_EQ(*convertTokenStringToExpression("{token {token}"), *concat(vec(literal("{token "), get(literal("token")))));
ASSERT_EQ(*convertTokenStringToExpression("{token} {token}"),
*concat(vec(get(literal("token")), literal(" "), get(literal("token")))));
ASSERT_EQ(*convertTokenStringToExpression("{token} {token"),
*concat(vec(get(literal("token")), literal(" "), literal("{token"))));
ASSERT_EQ(*convertTokenStringToExpression("{token {token}"),
*concat(vec(literal("{token "), get(literal("token")))));
}
TEST(StyleConversion, FormattedIdentityFunction) {
// See https://github.com/mapbox/mapbox-gl-js/issues/7311
// We never introduced this bug on gl-native, but we _almost_ did
@@ -102,7 +109,7 @@ TEST(StyleConversion, FormattedIdentityFunction) {
auto parseFunction = [&](const std::string& json) {
return convertJSON<PropertyValue<mbgl::style::expression::Formatted>>(json, error, true, false);
};
using namespace mbgl::style::expression::dsl;
auto fn1 = parseFunction(R"({ "property": "name", "type": "identity" })");

View File

@@ -11,15 +11,17 @@ using namespace mbgl::style::conversion;
TEST(GeoJSONOptions, Basic) {
Error error;
std::optional<GeoJSONOptions> converted = convertJSON<GeoJSONOptions>("{}", error);
ASSERT_TRUE((bool) converted);
ASSERT_TRUE((bool)converted);
}
TEST(GeoJSONOptions, ErrorHandling) {
Error error;
std::optional<GeoJSONOptions> converted = convertJSON<GeoJSONOptions>(R"JSON({
std::optional<GeoJSONOptions> converted = convertJSON<GeoJSONOptions>(
R"JSON({
"maxzoom": "should not be a string"
})JSON", error);
ASSERT_FALSE((bool) converted);
})JSON",
error);
ASSERT_FALSE((bool)converted);
}
TEST(GeoJSONOptions, RetainsDefaults) {
@@ -43,7 +45,8 @@ TEST(GeoJSONOptions, RetainsDefaults) {
TEST(GeoJSONOptions, FullConversion) {
Error error;
GeoJSONOptions converted = *convertJSON<GeoJSONOptions>(R"JSON({
GeoJSONOptions converted = *convertJSON<GeoJSONOptions>(
R"JSON({
"maxzoom": 1,
"buffer": 2,
"tolerance": 3,
@@ -56,7 +59,8 @@ TEST(GeoJSONOptions, FullConversion) {
"sum": [["+", ["accumulated"], ["get", "sum"]], ["get", "scalerank"]],
"has_island": ["any", ["==", ["get", "featureclass"], "island"]]
}
})JSON", error);
})JSON",
error);
// GeoJSON-VT
ASSERT_EQ(converted.minzoom, 0);

View File

@@ -44,10 +44,8 @@ TEST(StyleConversion, LayerTransition) {
}
})JSON");
ASSERT_STREQ("background", layer->getTypeInfo()->type);
ASSERT_EQ(400ms, *static_cast<BackgroundLayer*>(layer.get())->impl().paint
.get<BackgroundColor>().options.duration);
ASSERT_EQ(500ms, *static_cast<BackgroundLayer*>(layer.get())->impl().paint
.get<BackgroundColor>().options.delay);
ASSERT_EQ(400ms, *static_cast<BackgroundLayer*>(layer.get())->impl().paint.get<BackgroundColor>().options.duration);
ASSERT_EQ(500ms, *static_cast<BackgroundLayer*>(layer.get())->impl().paint.get<BackgroundColor>().options.delay);
}
TEST(StyleConversion, SerializeDefaults) {

View File

@@ -25,7 +25,7 @@ TEST(StyleConversion, Light) {
{
auto light = parseLight("{}");
ASSERT_TRUE((bool) light);
ASSERT_TRUE((bool)light);
const mbgl::JSValue colorValue("blue");
light->setProperty("color", &colorValue);
@@ -41,17 +41,21 @@ TEST(StyleConversion, Light) {
ASSERT_EQ(light->getIntensity().asConstant(), 0.5);
mbgl::JSValue::AllocatorType allocator;
const mbgl::JSValue positionValue(std::move(mbgl::JSValue(rapidjson::kArrayType).PushBack(1.f, allocator).PushBack(2.f, allocator).PushBack(3.f, allocator).Move()));
const mbgl::JSValue positionValue(std::move(mbgl::JSValue(rapidjson::kArrayType)
.PushBack(1.f, allocator)
.PushBack(2.f, allocator)
.PushBack(3.f, allocator)
.Move()));
light->setProperty("position", &positionValue);
ASSERT_FALSE(light->getPosition().isUndefined());
ASSERT_TRUE(light->getPosition().isConstant());
std::array<float, 3> expected{{ 1.f, 2.f, 3.f }};
ASSERT_EQ(light->getPosition().asConstant(), mbgl::style::Position({ expected }));
std::array<float, 3> expected{{1.f, 2.f, 3.f}};
ASSERT_EQ(light->getPosition().asConstant(), mbgl::style::Position({expected}));
}
{
auto light = parseLight(R"({"color":{"stops":[[14,"blue"],[16,"red"]]},"intensity":0.3,"position":[3,90,90]})");
ASSERT_TRUE((bool) light);
ASSERT_TRUE((bool)light);
ASSERT_TRUE(light->getAnchor().isUndefined());
ASSERT_FALSE(light->getAnchor().isConstant());
@@ -69,54 +73,54 @@ TEST(StyleConversion, Light) {
ASSERT_FALSE(light->getPosition().isUndefined());
ASSERT_TRUE(light->getPosition().isConstant());
std::array<float, 3> expected{{ 3, 90, 90 }};
ASSERT_EQ(light->getPosition().asConstant(), mbgl::style::Position({ expected }));
std::array<float, 3> expected{{3, 90, 90}};
ASSERT_EQ(light->getPosition().asConstant(), mbgl::style::Position({expected}));
ASSERT_FALSE(light->getPosition().isExpression());
}
{
auto light = parseLight(R"({"color":"blue","intensity":0.3,"color-transition":{"duration":1000}})");
ASSERT_TRUE((bool) light);
ASSERT_TRUE((bool)light);
ASSERT_FALSE(light->getColor().isUndefined());
ASSERT_TRUE(light->getColor().isConstant());
ASSERT_FALSE(light->getColor().isExpression());
ASSERT_EQ(light->getColorTransition().duration, mbgl::Duration(mbgl::Milliseconds(1000)));
ASSERT_FALSE((bool) light->getColorTransition().delay);
ASSERT_FALSE((bool)light->getColorTransition().delay);
}
{
auto light = parseLight(R"({"intensity":false})");
ASSERT_FALSE((bool) light);
ASSERT_FALSE((bool)light);
ASSERT_EQ("value must be a number", error.message);
}
{
auto light = parseLight(R"({"intensity":{"stops":[[15,"red"],[17,"blue"]]}})");
ASSERT_FALSE((bool) light);
ASSERT_FALSE((bool)light);
ASSERT_EQ("value must be a number", error.message);
}
{
auto light = parseLight(R"({"color":5})");
ASSERT_FALSE((bool) light);
ASSERT_FALSE((bool)light);
ASSERT_EQ("value must be a string", error.message);
}
{
auto light = parseLight(R"({"position":[0,5]})");
ASSERT_FALSE((bool) light);
ASSERT_FALSE((bool)light);
ASSERT_EQ("value must be an array of 3 numbers", error.message);
}
{
auto light = parseLight(R"({"anchor":"something"})");
ASSERT_FALSE((bool) light);
ASSERT_FALSE((bool)light);
ASSERT_EQ("value must be a valid enumeration value", error.message);
}
}

View File

@@ -9,7 +9,8 @@ using namespace mbgl::style;
using namespace mbgl::style::conversion;
TEST(StyleConversion, PropertyValue) {
// PropertyValue<T> accepts a constant expression: https://github.com/mapbox/mapbox-gl-native/issues/11940
// PropertyValue<T> accepts a constant expression:
// https://github.com/mapbox/mapbox-gl-native/issues/11940
Error error;
JSDocument doc;
doc.Parse<0>(R"(["literal", [1, 2]])");

View File

@@ -59,15 +59,15 @@ TEST(Stringify, Color) {
}
TEST(Stringify, Array) {
ASSERT_EQ(stringify(std::array<float, 2> {{ 1, 2 }}), "[1.0,2.0]");
ASSERT_EQ(stringify(std::array<float, 2>{{1, 2}}), "[1.0,2.0]");
}
TEST(Stringify, Vector) {
ASSERT_EQ(stringify(std::vector<float> {{ 1, 2 }}), "[1.0,2.0]");
ASSERT_EQ(stringify(std::vector<float>{{1, 2}}), "[1.0,2.0]");
}
TEST(Stringify, Map) {
ASSERT_EQ(stringify(std::unordered_map<std::string, float> {{ "a", 1.0f }}), "{\"a\":1.0}");
ASSERT_EQ(stringify(std::unordered_map<std::string, float>{{"a", 1.0f}}), "{\"a\":1.0}");
}
TEST(Stringify, Value) {
@@ -84,53 +84,40 @@ TEST(Stringify, Filter) {
TEST(Stringify, PropertyExpression) {
using namespace mbgl::style::expression::dsl;
ASSERT_EQ(stringify(PropertyExpression<float>(
interpolate(
linear(),
zoom(),
0.0, literal(1.0),
1.0, literal(2.0)
))),
"[\"interpolate\",[\"linear\"],[\"zoom\"],0.0,1.0,1.0,2.0]");
ASSERT_EQ(stringify(PropertyExpression<float>(interpolate(linear(), zoom(), 0.0, literal(1.0), 1.0, literal(2.0)))),
"[\"interpolate\",[\"linear\"],[\"zoom\"],0.0,1.0,1.0,2.0]");
ASSERT_EQ(stringify(PropertyExpression<float>(
interpolate(
exponential(2.0),
number(get("property")),
0.0, literal(1.0),
1.0, literal(2.0)
))),
"[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0,1.0,2.0]");
interpolate(exponential(2.0), number(get("property")), 0.0, literal(1.0), 1.0, literal(2.0)))),
"[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\","
"\"property\"]],0.0,1.0,1.0,2.0]");
ASSERT_EQ(stringify(PropertyExpression<float>(
interpolate(
linear(),
zoom(),
0.0, interpolate(exponential(2.0), number(get("property")), 0.0, literal(1.0), 1.0, literal(2.0)),
1.0, interpolate(exponential(2.0), number(get("property")), 0.0, literal(1.0), 1.0, literal(2.0))
))),
"[\"interpolate\","
"[\"linear\"],"
"[\"zoom\"],"
"0.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0,1.0,2.0],"
"1.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0,1.0,2.0]]");
ASSERT_EQ(stringify(PropertyExpression<float>(interpolate(
linear(),
zoom(),
0.0,
interpolate(exponential(2.0), number(get("property")), 0.0, literal(1.0), 1.0, literal(2.0)),
1.0,
interpolate(exponential(2.0), number(get("property")), 0.0, literal(1.0), 1.0, literal(2.0))))),
"[\"interpolate\","
"[\"linear\"],"
"[\"zoom\"],"
"0.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\","
"\"property\"]],0.0,1.0,1.0,2.0],"
"1.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\","
"\"property\"]],0.0,1.0,1.0,2.0]]");
}
TEST(Stringify, PropertyValue) {
using namespace mbgl::style::expression::dsl;
ASSERT_EQ(stringify(PropertyValue<float>(1)), "1.0");
ASSERT_EQ(stringify(PropertyValue<float>(PropertyExpression<float>(
interpolate(
exponential(2.0),
zoom(),
0.0, literal(1.0),
1.0, literal(2.0)
)))),
"[\"interpolate\",[\"exponential\",2.0],[\"zoom\"],0.0,1.0,1.0,2.0]");
interpolate(exponential(2.0), zoom(), 0.0, literal(1.0), 1.0, literal(2.0))))),
"[\"interpolate\",[\"exponential\",2.0],[\"zoom\"],0.0,1.0,1.0,2.0]");
}
TEST(Stringify, Layout) {
auto stringify = [] (const SymbolLayoutProperties::Unevaluated& layout) {
auto stringify = [](const SymbolLayoutProperties::Unevaluated& layout) {
rapidjson::StringBuffer s;
rapidjson::Writer<rapidjson::StringBuffer> writer(s);
layout.stringify(writer);

View File

@@ -11,87 +11,103 @@ using namespace mbgl::style::conversion;
TEST(Tileset, Empty) {
Error error;
std::optional<Tileset> converted = convertJSON<Tileset>("{}", error);
EXPECT_FALSE((bool) converted);
EXPECT_FALSE((bool)converted);
}
TEST(Tileset, ErrorHandling) {
Error error;
std::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
std::optional<Tileset> converted = convertJSON<Tileset>(
R"JSON({
"tiles": "should not be a string"
})JSON", error);
EXPECT_FALSE((bool) converted);
})JSON",
error);
EXPECT_FALSE((bool)converted);
}
TEST(Tileset, InvalidBounds) {
{
Error error;
std::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
std::optional<Tileset> converted = convertJSON<Tileset>(
R"JSON({
"tiles": ["http://mytiles"],
"bounds": [73, -180, -73, -120]
})JSON", error);
})JSON",
error);
EXPECT_FALSE((bool) converted);
EXPECT_FALSE((bool)converted);
}
{
Error error;
std::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
std::optional<Tileset> converted = convertJSON<Tileset>(
R"JSON({
"tiles": ["http://mytiles"],
"bounds": [-120]
})JSON", error);
})JSON",
error);
EXPECT_FALSE((bool) converted);
EXPECT_FALSE((bool)converted);
}
{
Error error;
std::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
std::optional<Tileset> converted = convertJSON<Tileset>(
R"JSON({
"tiles": ["http://mytiles"],
"bounds": "should not be a string"
})JSON", error);
})JSON",
error);
EXPECT_FALSE((bool) converted);
EXPECT_FALSE((bool)converted);
}
}
TEST(Tileset, ValidWorldBounds) {
Error error;
std::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
std::optional<Tileset> converted = convertJSON<Tileset>(
R"JSON({
"tiles": ["http://mytiles"],
"bounds": [-180, -90, 180, 90]
})JSON", error);
EXPECT_TRUE((bool) converted);
})JSON",
error);
EXPECT_TRUE((bool)converted);
EXPECT_EQ(converted->bounds, LatLngBounds::hull({90, -180}, {-90, 180}));
}
TEST(Tileset, PointBounds) {
Error error;
std::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
std::optional<Tileset> converted = convertJSON<Tileset>(
R"JSON({
"tiles": ["http://mytiles"],
"bounds": [0, 0, 0, 0]
})JSON", error);
EXPECT_TRUE((bool) converted);
})JSON",
error);
EXPECT_TRUE((bool)converted);
EXPECT_EQ(converted->bounds, LatLngBounds::hull({0, 0}, {0, 0}));
}
TEST(Tileset, BoundsAreClamped) {
Error error;
std::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
std::optional<Tileset> converted = convertJSON<Tileset>(
R"JSON({
"tiles": ["http://mytiles"],
"bounds": [-181.0000005,-90.000000006,180.00000000000006,91]
})JSON", error);
EXPECT_TRUE((bool) converted);
})JSON",
error);
EXPECT_TRUE((bool)converted);
EXPECT_EQ(converted->bounds, LatLngBounds::hull({90, -180}, {-90, 180}));
}
TEST(Tileset, FullConversion) {
Error error;
Tileset converted = *convertJSON<Tileset>(R"JSON({
Tileset converted = *convertJSON<Tileset>(
R"JSON({
"tiles": ["http://mytiles"],
"scheme": "xyz",
"minzoom": 1,
"maxzoom": 2,
"attribution": "mapbox",
"bounds": [-180, -73, -120, 73]
})JSON", error);
})JSON",
error);
EXPECT_EQ(converted.tiles[0], "http://mytiles");
EXPECT_EQ(converted.scheme, Tileset::Scheme::XYZ);

View File

@@ -19,7 +19,6 @@
#include <dirent.h>
#endif
using namespace mbgl;
using namespace mbgl::style;
@@ -27,16 +26,13 @@ TEST(Expression, IsExpression) {
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> spec;
spec.Parse<0>(util::read_file("scripts/style-spec-reference/v8.json").c_str());
ASSERT_FALSE(spec.HasParseError());
ASSERT_TRUE(spec.IsObject() &&
spec.HasMember("expression_name") &&
spec["expression_name"].IsObject() &&
spec["expression_name"].HasMember("values") &&
spec["expression_name"]["values"].IsObject());
ASSERT_TRUE(spec.IsObject() && spec.HasMember("expression_name") && spec["expression_name"].IsObject() &&
spec["expression_name"].HasMember("values") && spec["expression_name"]["values"].IsObject());
const auto& allExpressions = spec["expression_name"]["values"];
for(auto& entry : allExpressions.GetObject()) {
const std::string name { entry.name.GetString(), entry.name.GetStringLength() };
for (auto& entry : allExpressions.GetObject()) {
const std::string name{entry.name.GetString(), entry.name.GetStringLength()};
JSDocument document;
document.Parse<0>(R"([")" + name + R"("])");
const JSValue* expression = &document;
@@ -45,7 +41,8 @@ TEST(Expression, IsExpression) {
// TODO: "interpolate-lab": https://github.com/mapbox/mapbox-gl-native/issues/8720
if (name == "interpolate-hcl" || name == "interpolate-lab") {
if (expression::isExpression(conversion::Convertible(expression))) {
ASSERT_TRUE(false) << "Expression name" << name << "is implemented - please update Expression.IsExpression test.";
ASSERT_TRUE(false) << "Expression name" << name
<< "is implemented - please update Expression.IsExpression test.";
}
continue;
}
@@ -82,7 +79,6 @@ TEST_P(ExpressionEqualityTest, ExpressionEquality) {
std::unique_ptr<expression::Expression> expression_b = parse(base + ".b.json", error);
ASSERT_TRUE(expression_b) << GetParam() << ": " << error;
EXPECT_TRUE(*expression_a1 == *expression_a2);
EXPECT_TRUE(*expression_a1 != *expression_b);
}

View File

@@ -19,7 +19,7 @@
using namespace mbgl;
using namespace mbgl::style;
bool filter(const char * json,
bool filter(const char* json,
const PropertyMap& featureProperties = {{}},
FeatureIdentifier featureId = {},
FeatureType featureType = FeatureType::Point,
@@ -29,14 +29,14 @@ bool filter(const char * json,
std::optional<Filter> filter = conversion::convertJSON<Filter>(json, error);
EXPECT_TRUE(bool(filter));
EXPECT_EQ(error.message, "");
StubGeometryTileFeature feature { featureId, featureType, featureGeometry, featureProperties };
expression::EvaluationContext context = { zoom, &feature };
StubGeometryTileFeature feature{featureId, featureType, featureGeometry, featureProperties};
expression::EvaluationContext context = {zoom, &feature};
return (*filter)(context);
}
void invalidFilter(const char * json) {
void invalidFilter(const char* json) {
conversion::Error error;
std::optional<Filter> filter = conversion::convertJSON<Filter>(json, error);
EXPECT_FALSE(bool(filter));
@@ -44,28 +44,26 @@ void invalidFilter(const char * json) {
}
void writeJSON(rapidjson::Writer<rapidjson::StringBuffer>& writer, const Value& value) {
value.match(
[&] (const NullValue&) { writer.Null(); },
[&] (bool b) { writer.Bool(b); },
[&] (uint64_t t) { writer.Uint64(t); },
[&] (int64_t t) { writer.Int64(t); },
[&] (double f) {
// make sure integer values are stringified without trailing ".0".
f == std::floor(f) ? writer.Int(static_cast<int>(f)) : writer.Double(f);
},
[&] (const std::string& s) { writer.String(s); },
[&] (const std::vector<Value>& arr) {
writer.StartArray();
for(const auto& item : arr) {
writeJSON(writer, item);
}
writer.EndArray();
},
[](const auto&) {
});
value.match([&](const NullValue&) { writer.Null(); },
[&](bool b) { writer.Bool(b); },
[&](uint64_t t) { writer.Uint64(t); },
[&](int64_t t) { writer.Int64(t); },
[&](double f) {
// make sure integer values are stringified without trailing ".0".
f == std::floor(f) ? writer.Int(static_cast<int>(f)) : writer.Double(f);
},
[&](const std::string& s) { writer.String(s); },
[&](const std::vector<Value>& arr) {
writer.StartArray();
for (const auto& item : arr) {
writeJSON(writer, item);
}
writer.EndArray();
},
[](const auto&) {});
}
std::string stringifyFilter(const char * json) {
std::string stringifyFilter(const char* json) {
conversion::Error error;
std::optional<Filter> filter = conversion::convertJSON<Filter>(json, error);
EXPECT_TRUE(bool(filter));
@@ -81,33 +79,33 @@ std::string stringifyFilter(const char * json) {
TEST(Filter, EqualsNull) {
auto f = R"(["==", "foo", null])";
ASSERT_TRUE(filter(f, {{ "foo", mapbox::feature::null_value }}));
ASSERT_TRUE(filter(f, {{"foo", mapbox::feature::null_value}}));
ASSERT_FALSE(filter(f, {{ "foo", int64_t(0) }}));
ASSERT_FALSE(filter(f, {{ "foo", int64_t(1) }}));
ASSERT_FALSE(filter(f, {{ "foo", std::string("0") }}));
ASSERT_FALSE(filter(f, {{ "foo", true }}));
ASSERT_FALSE(filter(f, {{ "foo", false }}));
ASSERT_FALSE(filter(f, {{ }}));
ASSERT_FALSE(filter(f, {{"foo", int64_t(0)}}));
ASSERT_FALSE(filter(f, {{"foo", int64_t(1)}}));
ASSERT_FALSE(filter(f, {{"foo", std::string("0")}}));
ASSERT_FALSE(filter(f, {{"foo", true}}));
ASSERT_FALSE(filter(f, {{"foo", false}}));
ASSERT_FALSE(filter(f, {{}}));
}
TEST(Filter, EqualsString) {
auto f = R"(["==", "foo", "bar"])";
ASSERT_TRUE(filter(f, {{ "foo", std::string("bar") }}));
ASSERT_FALSE(filter(f, {{ "foo", std::string("baz") }}));
ASSERT_TRUE(filter(f, {{"foo", std::string("bar")}}));
ASSERT_FALSE(filter(f, {{"foo", std::string("baz")}}));
}
TEST(Filter, EqualsNumber) {
auto f = R"(["==", "foo", 0])";
ASSERT_TRUE(filter(f, {{ "foo", int64_t(0) }}));
ASSERT_TRUE(filter(f, {{ "foo", uint64_t(0) }}));
ASSERT_TRUE(filter(f, {{ "foo", double(0) }}));
ASSERT_FALSE(filter(f, {{ "foo", int64_t(1) }}));
ASSERT_FALSE(filter(f, {{ "foo", uint64_t(1) }}));
ASSERT_FALSE(filter(f, {{ "foo", double(1) }}));
ASSERT_FALSE(filter(f, {{ "foo", std::string("0") }}));
ASSERT_FALSE(filter(f, {{ "foo", false }}));
ASSERT_FALSE(filter(f, {{ "foo", true }}));
ASSERT_FALSE(filter(f, {{ "foo", mapbox::feature::null_value }}));
ASSERT_TRUE(filter(f, {{"foo", int64_t(0)}}));
ASSERT_TRUE(filter(f, {{"foo", uint64_t(0)}}));
ASSERT_TRUE(filter(f, {{"foo", double(0)}}));
ASSERT_FALSE(filter(f, {{"foo", int64_t(1)}}));
ASSERT_FALSE(filter(f, {{"foo", uint64_t(1)}}));
ASSERT_FALSE(filter(f, {{"foo", double(1)}}));
ASSERT_FALSE(filter(f, {{"foo", std::string("0")}}));
ASSERT_FALSE(filter(f, {{"foo", false}}));
ASSERT_FALSE(filter(f, {{"foo", true}}));
ASSERT_FALSE(filter(f, {{"foo", mapbox::feature::null_value}}));
ASSERT_FALSE(filter(f, {{}}));
}
@@ -133,70 +131,76 @@ TEST(Filter, InType) {
TEST(Filter, InID) {
auto f = R"(["in", "$id", "123", "1234", 1234])";
ASSERT_FALSE(filter(f));
ASSERT_TRUE(filter(f, {{}}, { uint64_t(1234) }));
ASSERT_TRUE(filter(f, {{}}, { std::string("1234") }));
ASSERT_FALSE(filter(f, {{}}, { std::string("4321") }));
ASSERT_TRUE(filter(f, {{}}, {uint64_t(1234)}));
ASSERT_TRUE(filter(f, {{}}, {std::string("1234")}));
ASSERT_FALSE(filter(f, {{}}, {std::string("4321")}));
}
TEST(Filter, Any) {
ASSERT_FALSE(filter("[\"any\"]"));
ASSERT_TRUE(filter("[\"any\", [\"==\", \"foo\", 1]]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_FALSE(filter("[\"any\", [\"==\", \"foo\", 0]]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_TRUE(filter("[\"any\", [\"==\", \"foo\", 0], [\"==\", \"foo\", 1]]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_TRUE(filter("[\"any\", [\"==\", \"foo\", 1]]", {{std::string("foo"), int64_t(1)}}));
ASSERT_FALSE(filter("[\"any\", [\"==\", \"foo\", 0]]", {{std::string("foo"), int64_t(1)}}));
ASSERT_TRUE(filter("[\"any\", [\"==\", \"foo\", 0], [\"==\", \"foo\", 1]]", {{std::string("foo"), int64_t(1)}}));
}
TEST(Filter, AnyExpression) {
ASSERT_FALSE(filter("[\"any\"]"));
ASSERT_TRUE(filter("[\"any\", [\"==\", [\"get\", \"foo\"], 1]]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_FALSE(filter("[\"any\", [\"==\", [\"get\", \"foo\"], 0]]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_TRUE(filter("[\"any\", [\"==\", [\"get\", \"foo\"], 0], [\"==\", [\"get\", \"foo\"], 1]]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_TRUE(filter("[\"any\", [\"==\", [\"get\", \"foo\"], 1]]", {{std::string("foo"), int64_t(1)}}));
ASSERT_FALSE(filter("[\"any\", [\"==\", [\"get\", \"foo\"], 0]]", {{std::string("foo"), int64_t(1)}}));
ASSERT_TRUE(
filter("[\"any\", [\"==\", [\"get\", \"foo\"], 0], [\"==\", [\"get\", "
"\"foo\"], 1]]",
{{std::string("foo"), int64_t(1)}}));
}
TEST(Filter, All) {
ASSERT_TRUE(filter("[\"all\"]", {{}}));
ASSERT_TRUE(filter("[\"all\", [\"==\", \"foo\", 1]]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_FALSE(filter("[\"all\", [\"==\", \"foo\", 0]]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_FALSE(filter("[\"all\", [\"==\", \"foo\", 0], [\"==\", \"foo\", 1]]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_TRUE(filter("[\"all\", [\"==\", \"foo\", 1]]", {{std::string("foo"), int64_t(1)}}));
ASSERT_FALSE(filter("[\"all\", [\"==\", \"foo\", 0]]", {{std::string("foo"), int64_t(1)}}));
ASSERT_FALSE(filter("[\"all\", [\"==\", \"foo\", 0], [\"==\", \"foo\", 1]]", {{std::string("foo"), int64_t(1)}}));
}
TEST(Filter, AllExpression) {
ASSERT_TRUE(filter("[\"all\", [\"==\", [\"get\", \"foo\"], 1]]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_FALSE(filter("[\"all\", [\"==\", [\"get\", \"foo\"], 0]]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_FALSE(filter("[\"all\", [\"==\", [\"get\", \"foo\"], 0], [\"==\", [\"get\", \"foo\"], 1]]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_TRUE(filter("[\"all\", [\"==\", [\"get\", \"foo\"], 1]]", {{std::string("foo"), int64_t(1)}}));
ASSERT_FALSE(filter("[\"all\", [\"==\", [\"get\", \"foo\"], 0]]", {{std::string("foo"), int64_t(1)}}));
ASSERT_FALSE(
filter("[\"all\", [\"==\", [\"get\", \"foo\"], 0], [\"==\", [\"get\", "
"\"foo\"], 1]]",
{{std::string("foo"), int64_t(1)}}));
}
TEST(Filter, None) {
ASSERT_TRUE(filter("[\"none\"]"));
ASSERT_FALSE(filter("[\"none\", [\"==\", \"foo\", 1]]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_TRUE(filter("[\"none\", [\"==\", \"foo\", 0]]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_FALSE(filter("[\"none\", [\"==\", \"foo\", 0], [\"==\", \"foo\", 1]]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_FALSE(filter("[\"none\", [\"==\", \"foo\", 1]]", {{std::string("foo"), int64_t(1)}}));
ASSERT_TRUE(filter("[\"none\", [\"==\", \"foo\", 0]]", {{std::string("foo"), int64_t(1)}}));
ASSERT_FALSE(filter("[\"none\", [\"==\", \"foo\", 0], [\"==\", \"foo\", 1]]", {{std::string("foo"), int64_t(1)}}));
}
TEST(Filter, Has) {
ASSERT_TRUE(filter("[\"has\", \"foo\"]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_TRUE(filter("[\"has\", \"foo\"]", {{ std::string("foo"), int64_t(0) }}));
ASSERT_TRUE(filter("[\"has\", \"foo\"]", {{ std::string("foo"), false }}));
ASSERT_TRUE(filter("[\"has\", \"foo\"]", {{std::string("foo"), int64_t(1)}}));
ASSERT_TRUE(filter("[\"has\", \"foo\"]", {{std::string("foo"), int64_t(0)}}));
ASSERT_TRUE(filter("[\"has\", \"foo\"]", {{std::string("foo"), false}}));
ASSERT_FALSE(filter("[\"has\", \"foo\"]"));
ASSERT_FALSE(filter("[\"has\", \"$id\"]"));
}
TEST(Filter, NotHas) {
ASSERT_FALSE(filter("[\"!has\", \"foo\"]", {{ std::string("foo"), int64_t(1) }}));
ASSERT_FALSE(filter("[\"!has\", \"foo\"]", {{ std::string("foo"), int64_t(0) }}));
ASSERT_FALSE(filter("[\"!has\", \"foo\"]", {{ std::string("foo"), false }}));
ASSERT_FALSE(filter("[\"!has\", \"foo\"]", {{std::string("foo"), int64_t(1)}}));
ASSERT_FALSE(filter("[\"!has\", \"foo\"]", {{std::string("foo"), int64_t(0)}}));
ASSERT_FALSE(filter("[\"!has\", \"foo\"]", {{std::string("foo"), false}}));
ASSERT_TRUE(filter("[\"!has\", \"foo\"]"));
}
TEST(Filter, ID) {
FeatureIdentifier id1 { uint64_t{ 1234 } };
FeatureIdentifier id1{uint64_t{1234}};
ASSERT_TRUE(filter("[\"==\", \"$id\", 1234]", {{}}, id1));
ASSERT_FALSE(filter("[\"==\", \"$id\", \"1234\"]", {{}}, id1));
FeatureIdentifier id2 { std::string{ "1" } };
FeatureIdentifier id2{std::string{"1"}};
ASSERT_FALSE(filter("[\"<\", \"$id\", \"0\"]", {{}}, id2));
ASSERT_TRUE(filter("[\"<\", \"$id\", \"1234\"]", {{}}, id2));
ASSERT_FALSE(filter("[\"==\", \"$id\", 1234]", {{ "id", uint64_t(1234) }}));
ASSERT_FALSE(filter("[\"==\", \"$id\", 1234]", {{"id", uint64_t(1234)}}));
}
TEST(Filter, Expression) {
@@ -224,11 +228,11 @@ TEST(Filter, LegacyProperty) {
TEST(Filter, Serialize) {
std::string json = R"(["any",["==","foo",0],["==","foo",1]])";
EXPECT_EQ(stringifyFilter(json.c_str()), std::string(json));
json = R"(["<=","two",2])";
EXPECT_EQ(stringifyFilter(json.c_str()), std::string(json));
//Constant folding for Expression filters
// Constant folding for Expression filters
json = R"(["==",["+",1,1],2])";
EXPECT_EQ(stringifyFilter(json.c_str()), std::string("true"));
@@ -238,14 +242,16 @@ TEST(Filter, Serialize) {
TEST(Filter, ExpressionLegacyMix) {
conversion::Error error;
std::optional<Filter> filter = conversion::convertJSON<Filter>(R"(["any", ["all", ["==", ["geometry-type"], "LineString"]], ["==", "x", 1]])", error);
std::optional<Filter> filter = conversion::convertJSON<Filter>(
R"(["any", ["all", ["==", ["geometry-type"], "LineString"]], ["==", "x", 1]])", error);
EXPECT_FALSE(bool(filter));
EXPECT_TRUE(error.message.size() > 0);
}
TEST(Filter, ZoomExpressionNested) {
ASSERT_TRUE(filter(R"(["==", ["get", "two"], ["zoom"]])", {{"two", int64_t(2)}}, {}, FeatureType::Point, {}, 2.0f));
ASSERT_FALSE(filter(R"(["==", ["get", "two"], ["+", ["zoom"], 1]])", {{"two", int64_t(2)}}, {}, FeatureType::Point, {}, 2.0f));
ASSERT_FALSE(filter(
R"(["==", ["get", "two"], ["+", ["zoom"], 1]])", {{"two", int64_t(2)}}, {}, FeatureType::Point, {}, 2.0f));
}
TEST(Filter, Internal) {

View File

@@ -13,34 +13,21 @@ float evaluate(Transitioning<PropertyValue<float>>& property, Duration delta = D
ZoomHistory zoomHistory;
zoomHistory.update(0, TimePoint::min() + delta);
PropertyEvaluationParameters parameters {
zoomHistory,
TimePoint::min() + delta,
Duration::zero()
};
PropertyEvaluationParameters parameters{zoomHistory, TimePoint::min() + delta, Duration::zero()};
PropertyEvaluator<float> evaluator {
parameters,
0.0f
};
PropertyEvaluator<float> evaluator{parameters, 0.0f};
return property.evaluate(evaluator, parameters.now);
}
PossiblyEvaluatedPropertyValue<float> evaluateDataExpression(Transitioning<PropertyValue<float>>& property, Duration delta = Duration::zero()) {
PossiblyEvaluatedPropertyValue<float> evaluateDataExpression(Transitioning<PropertyValue<float>>& property,
Duration delta = Duration::zero()) {
ZoomHistory zoomHistory;
zoomHistory.update(0, TimePoint::min() + delta);
PropertyEvaluationParameters parameters {
zoomHistory,
TimePoint::min() + delta,
Duration::zero()
};
PropertyEvaluationParameters parameters{zoomHistory, TimePoint::min() + delta, Duration::zero()};
DataDrivenPropertyEvaluator<float> evaluator {
parameters,
0.0f
};
DataDrivenPropertyEvaluator<float> evaluator{parameters, 0.0f};
return property.evaluate(evaluator, parameters.now);
}
@@ -51,33 +38,20 @@ TEST(TransitioningPropertyValue, EvaluateDefaultValue) {
}
TEST(TransitioningPropertyValue, EvaluateUntransitionedConstant) {
Transitioning<PropertyValue<float>> property {
PropertyValue<float>(1.0f),
Transitioning<PropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
Transitioning<PropertyValue<float>> property{
PropertyValue<float>(1.0f), Transitioning<PropertyValue<float>>(), TransitionOptions(), TimePoint::min()};
ASSERT_EQ(1.0f, evaluate(property));
}
TEST(TransitioningPropertyValue, EvaluateTransitionedConstantWithoutDelay) {
TransitionOptions transition;
transition.duration = { 1000ms };
transition.duration = {1000ms};
Transitioning<PropertyValue<float>> t0 {
PropertyValue<float>(0.0f),
Transitioning<PropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
Transitioning<PropertyValue<float>> t0{
PropertyValue<float>(0.0f), Transitioning<PropertyValue<float>>(), TransitionOptions(), TimePoint::min()};
Transitioning<PropertyValue<float>> t1 {
PropertyValue<float>(1.0f),
t0,
transition,
TimePoint::min()
};
Transitioning<PropertyValue<float>> t1{PropertyValue<float>(1.0f), t0, transition, TimePoint::min()};
ASSERT_FLOAT_EQ(0.0f, evaluate(t1, 0ms));
ASSERT_FLOAT_EQ(0.823099f, evaluate(t1, 500ms));
@@ -86,22 +60,13 @@ TEST(TransitioningPropertyValue, EvaluateTransitionedConstantWithoutDelay) {
TEST(TransitioningPropertyValue, EvaluateTransitionedConstantWithDelay) {
TransitionOptions transition;
transition.delay = { 1000ms };
transition.duration = { 1000ms };
transition.delay = {1000ms};
transition.duration = {1000ms};
Transitioning<PropertyValue<float>> t0 {
PropertyValue<float>(0.0f),
Transitioning<PropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
Transitioning<PropertyValue<float>> t0{
PropertyValue<float>(0.0f), Transitioning<PropertyValue<float>>(), TransitionOptions(), TimePoint::min()};
Transitioning<PropertyValue<float>> t1 {
PropertyValue<float>(1.0f),
t0,
transition,
TimePoint::min()
};
Transitioning<PropertyValue<float>> t1{PropertyValue<float>(1.0f), t0, transition, TimePoint::min()};
ASSERT_FLOAT_EQ(0.0f, evaluate(t1, 0ms));
ASSERT_FLOAT_EQ(0.0f, evaluate(t1, 500ms));
@@ -112,27 +77,20 @@ TEST(TransitioningPropertyValue, EvaluateTransitionedConstantWithDelay) {
TEST(TransitioningDataDrivenPropertyValue, Evaluate) {
TransitionOptions transition;
transition.delay = { 1000ms };
transition.duration = { 1000ms };
transition.delay = {1000ms};
transition.duration = {1000ms};
Transitioning<PropertyValue<float>> t0 {
PropertyValue<float>(0.0f),
Transitioning<PropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
Transitioning<PropertyValue<float>> t0{
PropertyValue<float>(0.0f), Transitioning<PropertyValue<float>>(), TransitionOptions(), TimePoint::min()};
using namespace mbgl::style::expression::dsl;
PropertyExpression<float> expression(number(get("property_name")));
Transitioning<PropertyValue<float>> t1 {
PropertyValue<float>(expression),
t0,
transition,
TimePoint::min()
};
Transitioning<PropertyValue<float>> t1{PropertyValue<float>(expression), t0, transition, TimePoint::min()};
ASSERT_TRUE(evaluateDataExpression(t0, 0ms).isConstant());
ASSERT_FALSE(evaluateDataExpression(t1, 0ms).isConstant()) <<
"A paint property transition to a data-driven evaluates immediately to the final value (see https://github.com/mapbox/mapbox-gl-native/issues/8237).";
ASSERT_FALSE(evaluateDataExpression(t1, 0ms).isConstant())
<< "A paint property transition to a data-driven evaluates immediately "
"to the final value (see "
"https://github.com/mapbox/mapbox-gl-native/issues/8237).";
}

View File

@@ -35,13 +35,11 @@ float evaluate(PropertyValue<float> value, float zoom) {
return value.evaluate(PropertyEvaluator<float>(PropertyEvaluationParameters(zoom), 0));
}
template<typename T>
template <typename T>
auto createOverride(expression::type::Type exprType,
PossiblyEvaluatedPropertyValue<T> propValue,
std::string propName) {
return std::make_unique<FormatSectionOverride<T>>(std::move(exprType),
std::move(propValue),
std::move(propName));
return std::make_unique<FormatSectionOverride<T>>(std::move(exprType), std::move(propValue), std::move(propName));
}
TEST(PropertyExpression, Constant) {
@@ -63,74 +61,96 @@ TEST(PropertyExpression, Expression) {
}
TEST(PropertyExpression, Defaults) {
EXPECT_EQ(1.0f, PropertyExpression<float>(number(get("property")), 0.0f)
.evaluate(oneInteger, 2.0f));
EXPECT_EQ(1.0f, PropertyExpression<float>(number(get("property")), 0.0f)
.evaluate(oneDouble, 2.0f));
EXPECT_EQ(0.0f, PropertyExpression<float>(number(get("property")), 0.0f)
.evaluate(oneString, 2.0f));
EXPECT_EQ(2.0f, PropertyExpression<float>(number(get("property")))
.evaluate(oneString, 2.0f));
EXPECT_EQ(1.0f, PropertyExpression<float>(number(get("property")), 0.0f).evaluate(oneInteger, 2.0f));
EXPECT_EQ(1.0f, PropertyExpression<float>(number(get("property")), 0.0f).evaluate(oneDouble, 2.0f));
EXPECT_EQ(0.0f, PropertyExpression<float>(number(get("property")), 0.0f).evaluate(oneString, 2.0f));
EXPECT_EQ(2.0f, PropertyExpression<float>(number(get("property"))).evaluate(oneString, 2.0f));
}
TEST(PropertyExpression, ZoomInterpolation) {
EXPECT_EQ(40.0f, PropertyExpression<float>(
interpolate(linear(), zoom(),
0.0, interpolate(linear(), number(get("property")), 1.0, literal(24.0)),
1.5, interpolate(linear(), number(get("property")), 1.0, literal(36.0)),
3.0, interpolate(linear(), number(get("property")), 1.0, literal(48.0))
), 0.0f)
.evaluate(2.0f, oneInteger, -1.0f)) << "Should interpolate between stops";
EXPECT_EQ(33.0, PropertyExpression<float>(
interpolate(linear(), zoom(),
5.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0))
), 0.0f)
.evaluate(0.0f, oneInteger, -1.0f)) << "Use first stop output for input values from -inf to first stop";
EXPECT_EQ(66.0, PropertyExpression<float>(
interpolate(linear(), zoom(),
0.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0))
), 0.0f)
.evaluate(20.0f, oneInteger, -1.0f)) << "Use last stop output for input values from last stop to +inf";
EXPECT_EQ(40.0f,
PropertyExpression<float>(interpolate(linear(),
zoom(),
0.0,
interpolate(linear(), number(get("property")), 1.0, literal(24.0)),
1.5,
interpolate(linear(), number(get("property")), 1.0, literal(36.0)),
3.0,
interpolate(linear(), number(get("property")), 1.0, literal(48.0))),
0.0f)
.evaluate(2.0f, oneInteger, -1.0f))
<< "Should interpolate between stops";
EXPECT_EQ(66.0f, PropertyExpression<float>(
interpolate(linear(), zoom(),
0.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0))
), 0.0f)
.evaluate(10.0f, oneInteger, -1.0f)) << "Should interpolate TO the last stop.";
EXPECT_EQ(33.0f, PropertyExpression<float>(
interpolate(linear(), zoom(),
0.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0))
), 0.0f)
.evaluate(0.0f, oneInteger, -1.0f)) << "Should interpolate TO the first stop";
EXPECT_EQ(33.0,
PropertyExpression<float>(interpolate(linear(),
zoom(),
5.0,
interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
10.0,
interpolate(linear(), number(get("property")), 1.0, literal(66.0))),
0.0f)
.evaluate(0.0f, oneInteger, -1.0f))
<< "Use first stop output for input values from -inf to first stop";
EXPECT_EQ(66.0,
PropertyExpression<float>(interpolate(linear(),
zoom(),
0.0,
interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
10.0,
interpolate(linear(), number(get("property")), 1.0, literal(66.0))),
0.0f)
.evaluate(20.0f, oneInteger, -1.0f))
<< "Use last stop output for input values from last stop to +inf";
EXPECT_EQ(66.0f,
PropertyExpression<float>(interpolate(linear(),
zoom(),
0.0,
interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
10.0,
interpolate(linear(), number(get("property")), 1.0, literal(66.0))),
0.0f)
.evaluate(10.0f, oneInteger, -1.0f))
<< "Should interpolate TO the last stop.";
EXPECT_EQ(33.0f,
PropertyExpression<float>(interpolate(linear(),
zoom(),
0.0,
interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
10.0,
interpolate(linear(), number(get("property")), 1.0, literal(66.0))),
0.0f)
.evaluate(0.0f, oneInteger, -1.0f))
<< "Should interpolate TO the first stop";
}
TEST(PropertyExpression, Issue8460) {
PropertyExpression<float> fn1(
interpolate(linear(), zoom(),
15.0, interpolate(linear(), number(get("property")), 1.0, literal(0.0)),
15.2, interpolate(linear(), number(get("property")), 1.0, literal(600.0))
), 0.0f);
PropertyExpression<float> fn1(interpolate(linear(),
zoom(),
15.0,
interpolate(linear(), number(get("property")), 1.0, literal(0.0)),
15.2,
interpolate(linear(), number(get("property")), 1.0, literal(600.0))),
0.0f);
EXPECT_NEAR( 0.0f, fn1.evaluate(15.0f, oneInteger, -1.0f), 0.00);
EXPECT_NEAR(0.0f, fn1.evaluate(15.0f, oneInteger, -1.0f), 0.00);
EXPECT_NEAR(300.0f, fn1.evaluate(15.1f, oneInteger, -1.0f), 0.01);
EXPECT_NEAR(600.0f, fn1.evaluate(15.2f, oneInteger, -1.0f), 0.00);
EXPECT_NEAR(600.0f, fn1.evaluate(16.0f, oneInteger, -1.0f), 0.00);
PropertyExpression<float> fn2(
interpolate(linear(), zoom(),
15.0, interpolate(linear(), number(get("property")), 1.0, literal(0.0)),
15.2, interpolate(linear(), number(get("property")), 1.0, literal(300.0)),
18.0, interpolate(linear(), number(get("property")), 1.0, literal(600.0))
), 0.0f);
PropertyExpression<float> fn2(interpolate(linear(),
zoom(),
15.0,
interpolate(linear(), number(get("property")), 1.0, literal(0.0)),
15.2,
interpolate(linear(), number(get("property")), 1.0, literal(300.0)),
18.0,
interpolate(linear(), number(get("property")), 1.0, literal(600.0))),
0.0f);
EXPECT_NEAR( 0.0f, fn2.evaluate(15.0f, oneInteger, -1.0f), 0.00);
EXPECT_NEAR(0.0f, fn2.evaluate(15.0f, oneInteger, -1.0f), 0.00);
EXPECT_NEAR(150.0f, fn2.evaluate(15.1f, oneInteger, -1.0f), 0.01);
EXPECT_NEAR(300.0f, fn2.evaluate(15.2f, oneInteger, -1.0f), 0.00);
EXPECT_NEAR(385.71f, fn2.evaluate(16.0f, oneInteger, -1.0f), 0.01);
@@ -140,8 +160,7 @@ TEST(PropertyExpression, Issue8460) {
TEST(PropertyExpression, FormatSectionOverride) {
using Value = expression::Value;
Value formattedSection =
std::unordered_map<std::string, Value>{ {"text-color", Value{Color::blue()}} };
Value formattedSection = std::unordered_map<std::string, Value>{{"text-color", Value{Color::blue()}}};
auto ctx = expression::EvaluationContext(&oneDouble).withFormattedSection(&formattedSection);
PossiblyEvaluatedPropertyValue<Color> constantValueRed(Color::red());
PossiblyEvaluatedPropertyValue<Color> constantValueGreen(Color::green());
@@ -268,8 +287,8 @@ TEST(PropertyExpression, WithinExpression) {
ASSERT_TRUE(expression);
PropertyExpression<bool> propExpr(std::move(expression));
// evaluation test with valid geojson source but FeatureType is not Point/LineString (currently only support
// FeatureType::Point and FeatureType::LineString)
// evaluation test with valid geojson source but FeatureType is not Point/LineString
// (currently only support FeatureType::Point and FeatureType::LineString)
{
// testPoly is inside polygon, but will return false
Polygon<double> testRing{{{-9.228515625, -17.560246503294888},
@@ -293,8 +312,8 @@ TEST(PropertyExpression, WithinExpression) {
auto geoLine1 = convertGeometry(testLine1, canonicalTileID);
StubGeometryTileFeature lineFeature1(FeatureType::LineString, geoLine1);
auto evaluatedResult =
propExpr.evaluate(EvaluationContext(&lineFeature0).withCanonicalTileID(&canonicalTileID));
auto evaluatedResult = propExpr.evaluate(
EvaluationContext(&lineFeature0).withCanonicalTileID(&canonicalTileID));
EXPECT_TRUE(evaluatedResult);
evaluatedResult = propExpr.evaluate(EvaluationContext(&lineFeature1).withCanonicalTileID(&canonicalTileID));
EXPECT_FALSE(evaluatedResult);
@@ -302,7 +321,7 @@ TEST(PropertyExpression, WithinExpression) {
// evaluation test with valid geojson source and valid point features
{
auto getPointFeature = [&canonicalTileID](const Point<double>& testPoint) -> StubGeometryTileFeature {
auto getPointFeature = [&canonicalTileID](const Point<double> &testPoint) -> StubGeometryTileFeature {
auto geoPoint = convertGeometry(testPoint, canonicalTileID);
StubGeometryTileFeature pointFeature(FeatureType::Point, geoPoint);
return pointFeature;
@@ -310,8 +329,8 @@ TEST(PropertyExpression, WithinExpression) {
// check `within` algorithm
auto pointFeature = getPointFeature(Point<double>(-10.72265625, -7.27529233637217));
auto evaluatedResult =
propExpr.evaluate(EvaluationContext(&pointFeature).withCanonicalTileID(&canonicalTileID));
auto evaluatedResult = propExpr.evaluate(
EvaluationContext(&pointFeature).withCanonicalTileID(&canonicalTileID));
EXPECT_FALSE(evaluatedResult);
pointFeature = getPointFeature(Point<double>(-7.646484374999999, -12.382928338487396));
@@ -418,8 +437,8 @@ TEST(PropertyExpression, WithinExpressionAntiMeridian) {
auto geoLine1 = convertGeometry(testLine1, canonicalTileID);
StubGeometryTileFeature lineFeature1(FeatureType::LineString, geoLine1);
auto evaluatedResult =
propExpr.evaluate(EvaluationContext(&lineFeature0).withCanonicalTileID(&canonicalTileID));
auto evaluatedResult = propExpr.evaluate(
EvaluationContext(&lineFeature0).withCanonicalTileID(&canonicalTileID));
EXPECT_TRUE(evaluatedResult);
evaluatedResult = propExpr.evaluate(EvaluationContext(&lineFeature1).withCanonicalTileID(&canonicalTileID));
EXPECT_FALSE(evaluatedResult);
@@ -439,7 +458,7 @@ TEST(PropertyExpression, WithinExpressionAntiMeridian) {
ASSERT_TRUE(expression);
PropertyExpression<bool> propExpr(std::move(expression));
auto getPointFeature = [&canonicalTileID](const Point<double>& testPoint) -> StubGeometryTileFeature {
auto getPointFeature = [&canonicalTileID](const Point<double> &testPoint) -> StubGeometryTileFeature {
auto geoPoint = convertGeometry(testPoint, canonicalTileID);
StubGeometryTileFeature pointFeature(FeatureType::Point, geoPoint);
return pointFeature;
@@ -447,8 +466,8 @@ TEST(PropertyExpression, WithinExpressionAntiMeridian) {
// check `within` algorithm
auto pointFeature = getPointFeature(Point<double>(177, 62.5));
auto evaluatedResult =
propExpr.evaluate(EvaluationContext(&pointFeature).withCanonicalTileID(&canonicalTileID));
auto evaluatedResult = propExpr.evaluate(
EvaluationContext(&pointFeature).withCanonicalTileID(&canonicalTileID));
EXPECT_TRUE(evaluatedResult);
pointFeature = getPointFeature(Point<double>(180, 62.5));
@@ -517,10 +536,9 @@ TEST(PropertyExpression, DistanceExpression) {
ASSERT_TRUE(expression);
PropertyExpression<double> propExpr(std::move(expression));
auto evaluatedResult =
propExpr.evaluate(EvaluationContext(&pointFeature).withCanonicalTileID(&canonicalTileID), invalidResult);
auto evaluatedResult = propExpr.evaluate(EvaluationContext(&pointFeature).withCanonicalTileID(&canonicalTileID),
invalidResult);
EXPECT_NEAR(491.307, evaluatedResult, 0.01);
}
// Evaluation test with Point to MultiPoint distance
@@ -544,8 +562,8 @@ TEST(PropertyExpression, DistanceExpression) {
auto geoPoint = convertGeometry(featurePoint, canonicalTileID);
StubGeometryTileFeature feature(FeatureType::Point, geoPoint);
auto evaluatedResult =
propExpr.evaluate(EvaluationContext(&feature).withCanonicalTileID(&canonicalTileID), invalidResult);
auto evaluatedResult = propExpr.evaluate(EvaluationContext(&feature).withCanonicalTileID(&canonicalTileID),
invalidResult);
EXPECT_NEAR(158.541, evaluatedResult, 0.01);
}
@@ -571,8 +589,8 @@ TEST(PropertyExpression, DistanceExpression) {
auto geoLine = convertGeometry(line, canonicalTileID);
StubGeometryTileFeature lineFeature(FeatureType::LineString, geoLine);
auto evaluatedResult =
propExpr.evaluate(EvaluationContext(&lineFeature).withCanonicalTileID(&canonicalTileID), invalidResult);
auto evaluatedResult = propExpr.evaluate(EvaluationContext(&lineFeature).withCanonicalTileID(&canonicalTileID),
invalidResult);
EXPECT_NEAR(107.211, evaluatedResult, 0.01);
}
@@ -600,8 +618,8 @@ TEST(PropertyExpression, DistanceExpression) {
auto geoLine = convertGeometry(lines, canonicalTileID);
StubGeometryTileFeature lineFeature(FeatureType::LineString, geoLine);
auto evaluatedResult =
propExpr.evaluate(EvaluationContext(&lineFeature).withCanonicalTileID(&canonicalTileID), invalidResult);
auto evaluatedResult = propExpr.evaluate(EvaluationContext(&lineFeature).withCanonicalTileID(&canonicalTileID),
invalidResult);
EXPECT_NEAR(59.845, evaluatedResult, 0.01);
}
@@ -671,16 +689,16 @@ TEST(PropertyExpression, DistanceExpression) {
ASSERT_TRUE(expression);
PropertyExpression<double> propExpr(std::move(expression));
auto evaluatedResult =
propExpr.evaluate(EvaluationContext(&lineFeature).withCanonicalTileID(&canonicalTileID), invalidResult);
auto evaluatedResult = propExpr.evaluate(EvaluationContext(&lineFeature).withCanonicalTileID(&canonicalTileID),
invalidResult);
EXPECT_NEAR(180.408, evaluatedResult, 0.01);
}
// Evaluation test with MultiPoints to MutltiLineString distance
{
const auto multiPoints = mbgl::util::read_file("test/fixtures/geometry_data/multi_point_2.geojson");
const auto multiLineFeature =
getFeature("multi_line_string_1.geojson", FeatureType::LineString, canonicalTileID);
const auto multiLineFeature = getFeature(
"multi_line_string_1.geojson", FeatureType::LineString, canonicalTileID);
std::stringstream ss;
ss << std::string(R"(["distance", )") << multiPoints << std::string(R"( ])");
auto expression = createExpression(ss.str().c_str());
@@ -695,8 +713,8 @@ TEST(PropertyExpression, DistanceExpression) {
// Evaluation test with LineString to MutltiLineString distance
{
const auto LineString1 = mbgl::util::read_file("test/fixtures/geometry_data/line_string_1.geojson");
const auto multiLineFeature =
getFeature("multi_line_string_2.geojson", FeatureType::LineString, canonicalTileID);
const auto multiLineFeature = getFeature(
"multi_line_string_2.geojson", FeatureType::LineString, canonicalTileID);
std::stringstream ss;
ss << std::string(R"(["distance", )") << LineString1 << std::string(R"( ])");
auto expression = createExpression(ss.str().c_str());
@@ -711,8 +729,8 @@ TEST(PropertyExpression, DistanceExpression) {
// Evaluation test with MultiLineString to MutltiLineString distance
{
const auto multiLineString1 = mbgl::util::read_file("test/fixtures/geometry_data/multi_line_string_1.geojson");
const auto multiLineFeature =
getFeature("multi_line_string_2.geojson", FeatureType::LineString, canonicalTileID);
const auto multiLineFeature = getFeature(
"multi_line_string_2.geojson", FeatureType::LineString, canonicalTileID);
std::stringstream ss;
ss << std::string(R"(["distance", )") << multiLineString1 << std::string(R"( ])");
auto expression = createExpression(ss.str().c_str());
@@ -753,14 +771,14 @@ TEST(PropertyExpression, DistanceExpression) {
ASSERT_TRUE(expression);
PropertyExpression<double> propExpr(std::move(expression));
const auto multiLineFeature1 =
getFeature("multi_line_string_1.geojson", FeatureType::LineString, canonicalTileID);
const auto multiLineFeature1 = getFeature(
"multi_line_string_1.geojson", FeatureType::LineString, canonicalTileID);
auto evaluatedResult = propExpr.evaluate(
EvaluationContext(&multiLineFeature1).withCanonicalTileID(&canonicalTileID), invalidResult);
EXPECT_NEAR(193.450, evaluatedResult, 0.01);
const auto multiLineFeature2 =
getFeature("multi_line_string_2.geojson", FeatureType::LineString, canonicalTileID);
const auto multiLineFeature2 = getFeature(
"multi_line_string_2.geojson", FeatureType::LineString, canonicalTileID);
evaluatedResult = propExpr.evaluate(EvaluationContext(&multiLineFeature2).withCanonicalTileID(&canonicalTileID),
invalidResult);
EXPECT_NEAR(0.0, evaluatedResult, 0.01);
@@ -783,8 +801,8 @@ TEST(PropertyExpression, DistanceExpression) {
auto geoPolygon = convertGeometry(polygon, canonicalTileID);
StubGeometryTileFeature polygonFeature(FeatureType::Polygon, geoPolygon);
auto evaluatedResult =
propExpr.evaluate(EvaluationContext(&polygonFeature).withCanonicalTileID(&canonicalTileID), invalidResult);
auto evaluatedResult = propExpr.evaluate(
EvaluationContext(&polygonFeature).withCanonicalTileID(&canonicalTileID), invalidResult);
EXPECT_NEAR(203.876, evaluatedResult, 0.01);
}
@@ -827,8 +845,8 @@ TEST(PropertyExpression, DistanceExpression) {
auto geoPolygon1 = convertGeometry(polygon1, canonicalTileID);
StubGeometryTileFeature polygonFeature1(FeatureType::Polygon, geoPolygon1);
auto evaluatedResult =
propExpr.evaluate(EvaluationContext(&polygonFeature1).withCanonicalTileID(&canonicalTileID), invalidResult);
auto evaluatedResult = propExpr.evaluate(
EvaluationContext(&polygonFeature1).withCanonicalTileID(&canonicalTileID), invalidResult);
EXPECT_NEAR(0.0, evaluatedResult, 0.01);
// polygon2's line is intersecting polygon, but no point is inside polygon
@@ -840,8 +858,8 @@ TEST(PropertyExpression, DistanceExpression) {
auto geoPolygon2 = convertGeometry(polygon2, canonicalTileID);
StubGeometryTileFeature polygonFeature2(FeatureType::Polygon, geoPolygon2);
evaluatedResult =
propExpr.evaluate(EvaluationContext(&polygonFeature2).withCanonicalTileID(&canonicalTileID), invalidResult);
evaluatedResult = propExpr.evaluate(EvaluationContext(&polygonFeature2).withCanonicalTileID(&canonicalTileID),
invalidResult);
EXPECT_NEAR(0.0, evaluatedResult, 0.01);
// one of polygon3's point is inside polygon
@@ -853,8 +871,8 @@ TEST(PropertyExpression, DistanceExpression) {
auto geoPolygon3 = convertGeometry(polygon3, canonicalTileID);
StubGeometryTileFeature polygonFeature3(FeatureType::Polygon, geoPolygon3);
evaluatedResult =
propExpr.evaluate(EvaluationContext(&polygonFeature3).withCanonicalTileID(&canonicalTileID), invalidResult);
evaluatedResult = propExpr.evaluate(EvaluationContext(&polygonFeature3).withCanonicalTileID(&canonicalTileID),
invalidResult);
EXPECT_NEAR(0.0, evaluatedResult, 0.01);
// lineString1 is within polygon
@@ -862,8 +880,8 @@ TEST(PropertyExpression, DistanceExpression) {
auto geoLineString1 = convertGeometry(lineString1, canonicalTileID);
StubGeometryTileFeature lineFeature1(FeatureType::LineString, geoLineString1);
evaluatedResult =
propExpr.evaluate(EvaluationContext(&lineFeature1).withCanonicalTileID(&canonicalTileID), invalidResult);
evaluatedResult = propExpr.evaluate(EvaluationContext(&lineFeature1).withCanonicalTileID(&canonicalTileID),
invalidResult);
EXPECT_NEAR(0.0, evaluatedResult, 0.01);
// lineString2 is intersecting the polygon but its points are outside the polygon
@@ -871,8 +889,8 @@ TEST(PropertyExpression, DistanceExpression) {
auto geoLineString2 = convertGeometry(lineString2, canonicalTileID);
StubGeometryTileFeature lineFeature2(FeatureType::LineString, geoLineString2);
evaluatedResult =
propExpr.evaluate(EvaluationContext(&lineFeature2).withCanonicalTileID(&canonicalTileID), invalidResult);
evaluatedResult = propExpr.evaluate(EvaluationContext(&lineFeature2).withCanonicalTileID(&canonicalTileID),
invalidResult);
EXPECT_NEAR(0.0, evaluatedResult, 0.01);
}
}

View File

@@ -61,7 +61,7 @@ public:
Transform transform;
TransformState transformState;
Style style{fileSource, 1};
AnnotationManager annotationManager { style };
AnnotationManager annotationManager{style};
ImageManager imageManager;
GlyphManager glyphManager;
@@ -81,34 +81,28 @@ public:
// Squelch logging.
Log::setObserver(std::make_unique<Log::NullObserver>());
transform.resize({ 512, 512 });
transform.resize({512, 512});
transform.jumpTo(CameraOptions().withCenter(LatLng()).withZoom(0.0));
transformState = transform.getState();
}
void run() {
loop.run();
}
void run() { loop.run(); }
void end() {
loop.stop();
}
void end() { loop.stop(); }
};
TEST(Source, LoadingFail) {
SourceTest test;
test.fileSource->sourceResponse = [&] (const Resource& resource) {
test.fileSource->sourceResponse = [&](const Resource& resource) {
EXPECT_EQ("url", resource.url);
Response response;
response.error = std::make_unique<Response::Error>(
Response::Error::Reason::Other,
"Failed by the test case");
response.error = std::make_unique<Response::Error>(Response::Error::Reason::Other, "Failed by the test case");
return response;
};
test.styleObserver.sourceError = [&] (Source& source, std::exception_ptr error) {
test.styleObserver.sourceError = [&](Source& source, std::exception_ptr error) {
EXPECT_EQ("source", source.getID());
EXPECT_EQ("Failed by the test case", util::toString(error));
test.end();
@@ -124,14 +118,14 @@ TEST(Source, LoadingFail) {
TEST(Source, LoadingCorrupt) {
SourceTest test;
test.fileSource->sourceResponse = [&] (const Resource& resource) {
test.fileSource->sourceResponse = [&](const Resource& resource) {
EXPECT_EQ("url", resource.url);
Response response;
response.data = std::make_unique<std::string>("CORRUPTED");
return response;
};
test.styleObserver.sourceError = [&] (Source& source, std::exception_ptr error) {
test.styleObserver.sourceError = [&](Source& source, std::exception_ptr error) {
EXPECT_EQ("source", source.getID());
EXPECT_EQ("Invalid value. at offset 0", util::toString(error));
test.end();
@@ -147,28 +141,29 @@ TEST(Source, LoadingCorrupt) {
TEST(Source, RasterTileEmpty) {
SourceTest test;
test.fileSource->tileResponse = [&] (const Resource&) {
test.fileSource->tileResponse = [&](const Resource&) {
Response response;
response.noContent = true;
return response;
};
RasterLayer layer("id", "source");
Immutable<LayerProperties> layerProperties = makeMutable<RasterLayerProperties>(staticImmutableCast<RasterLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };
Immutable<LayerProperties> layerProperties = makeMutable<RasterLayerProperties>(
staticImmutableCast<RasterLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
Tileset tileset;
tileset.tiles = { "tiles" };
tileset.tiles = {"tiles"};
RasterSource source("source", tileset, 512);
source.loadDescription(*test.fileSource);
test.renderSourceObserver.tileChanged = [&] (RenderSource& source_, const OverscaledTileID&) {
test.renderSourceObserver.tileChanged = [&](RenderSource& source_, const OverscaledTileID&) {
EXPECT_EQ("source", source_.baseImpl->id);
test.end();
};
test.renderSourceObserver.tileError = [&] (RenderSource&, const OverscaledTileID&, std::exception_ptr) {
test.renderSourceObserver.tileError = [&](RenderSource&, const OverscaledTileID&, std::exception_ptr) {
FAIL() << "Should never be called";
};
@@ -182,28 +177,29 @@ TEST(Source, RasterTileEmpty) {
TEST(Source, RasterDEMTileEmpty) {
SourceTest test;
test.fileSource->tileResponse = [&] (const Resource&) {
test.fileSource->tileResponse = [&](const Resource&) {
Response response;
response.noContent = true;
return response;
};
HillshadeLayer layer("id", "source");
Immutable<LayerProperties> layerProperties = makeMutable<HillshadeLayerProperties>(staticImmutableCast<HillshadeLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };
Immutable<LayerProperties> layerProperties = makeMutable<HillshadeLayerProperties>(
staticImmutableCast<HillshadeLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
Tileset tileset;
tileset.tiles = { "tiles" };
tileset.tiles = {"tiles"};
RasterDEMSource source("source", tileset, 512);
source.loadDescription(*test.fileSource);
test.renderSourceObserver.tileChanged = [&] (RenderSource& source_, const OverscaledTileID&) {
test.renderSourceObserver.tileChanged = [&](RenderSource& source_, const OverscaledTileID&) {
EXPECT_EQ("source", source_.baseImpl->id);
test.end();
};
test.renderSourceObserver.tileError = [&] (RenderSource&, const OverscaledTileID&, std::exception_ptr) {
test.renderSourceObserver.tileError = [&](RenderSource&, const OverscaledTileID&, std::exception_ptr) {
FAIL() << "Should never be called";
};
@@ -217,7 +213,7 @@ TEST(Source, RasterDEMTileEmpty) {
TEST(Source, VectorTileEmpty) {
SourceTest test;
test.fileSource->tileResponse = [&] (const Resource&) {
test.fileSource->tileResponse = [&](const Resource&) {
Response response;
response.noContent = true;
return response;
@@ -226,21 +222,22 @@ TEST(Source, VectorTileEmpty) {
LineLayer layer("id", "source");
layer.setSourceLayer("water");
Immutable<LayerProperties> layerProperties = makeMutable<LineLayerProperties>(staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };
Immutable<LayerProperties> layerProperties = makeMutable<LineLayerProperties>(
staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
Tileset tileset;
tileset.tiles = { "tiles" };
tileset.tiles = {"tiles"};
VectorSource source("source", tileset);
source.loadDescription(*test.fileSource);
test.renderSourceObserver.tileChanged = [&] (RenderSource& source_, const OverscaledTileID&) {
test.renderSourceObserver.tileChanged = [&](RenderSource& source_, const OverscaledTileID&) {
EXPECT_EQ("source", source_.baseImpl->id);
test.end();
};
test.renderSourceObserver.tileError = [&] (RenderSource&, const OverscaledTileID&, std::exception_ptr) {
test.renderSourceObserver.tileError = [&](RenderSource&, const OverscaledTileID&, std::exception_ptr) {
FAIL() << "Should never be called";
};
@@ -254,30 +251,30 @@ TEST(Source, VectorTileEmpty) {
TEST(Source, RasterTileFail) {
SourceTest test;
test.fileSource->tileResponse = [&] (const Resource&) {
test.fileSource->tileResponse = [&](const Resource&) {
Response response;
response.error = std::make_unique<Response::Error>(
Response::Error::Reason::Other,
"Failed by the test case");
response.error = std::make_unique<Response::Error>(Response::Error::Reason::Other, "Failed by the test case");
return response;
};
RasterLayer layer("id", "source");
Immutable<LayerProperties> layerProperties = makeMutable<RasterLayerProperties>(staticImmutableCast<RasterLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };
Immutable<LayerProperties> layerProperties = makeMutable<RasterLayerProperties>(
staticImmutableCast<RasterLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
Tileset tileset;
tileset.tiles = { "tiles" };
tileset.tiles = {"tiles"};
RasterSource source("source", tileset, 512);
source.loadDescription(*test.fileSource);
test.renderSourceObserver.tileError = [&] (RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
EXPECT_EQ(SourceType::Raster, source_.baseImpl->type);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_EQ("Failed by the test case", util::toString(error));
test.end();
};
test.renderSourceObserver.tileError =
[&](RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
EXPECT_EQ(SourceType::Raster, source_.baseImpl->type);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_EQ("Failed by the test case", util::toString(error));
test.end();
};
auto renderSource = RenderSource::create(source.baseImpl);
renderSource->setObserver(&test.renderSourceObserver);
@@ -289,30 +286,30 @@ TEST(Source, RasterTileFail) {
TEST(Source, RasterDEMTileFail) {
SourceTest test;
test.fileSource->tileResponse = [&] (const Resource&) {
test.fileSource->tileResponse = [&](const Resource&) {
Response response;
response.error = std::make_unique<Response::Error>(
Response::Error::Reason::Other,
"Failed by the test case");
response.error = std::make_unique<Response::Error>(Response::Error::Reason::Other, "Failed by the test case");
return response;
};
HillshadeLayer layer("id", "source");
Immutable<LayerProperties> layerProperties = makeMutable<HillshadeLayerProperties>(staticImmutableCast<HillshadeLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };
Immutable<LayerProperties> layerProperties = makeMutable<HillshadeLayerProperties>(
staticImmutableCast<HillshadeLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
Tileset tileset;
tileset.tiles = { "tiles" };
tileset.tiles = {"tiles"};
RasterDEMSource source("source", tileset, 512);
source.loadDescription(*test.fileSource);
test.renderSourceObserver.tileError = [&] (RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
EXPECT_EQ(SourceType::RasterDEM, source_.baseImpl->type);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_EQ("Failed by the test case", util::toString(error));
test.end();
};
test.renderSourceObserver.tileError =
[&](RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
EXPECT_EQ(SourceType::RasterDEM, source_.baseImpl->type);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_EQ("Failed by the test case", util::toString(error));
test.end();
};
auto renderSource = RenderSource::create(source.baseImpl);
renderSource->setObserver(&test.renderSourceObserver);
@@ -324,32 +321,32 @@ TEST(Source, RasterDEMTileFail) {
TEST(Source, VectorTileFail) {
SourceTest test;
test.fileSource->tileResponse = [&] (const Resource&) {
test.fileSource->tileResponse = [&](const Resource&) {
Response response;
response.error = std::make_unique<Response::Error>(
Response::Error::Reason::Other,
"Failed by the test case");
response.error = std::make_unique<Response::Error>(Response::Error::Reason::Other, "Failed by the test case");
return response;
};
LineLayer layer("id", "source");
layer.setSourceLayer("water");
Immutable<LayerProperties> layerProperties = makeMutable<LineLayerProperties>(staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };
Immutable<LayerProperties> layerProperties = makeMutable<LineLayerProperties>(
staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
Tileset tileset;
tileset.tiles = { "tiles" };
tileset.tiles = {"tiles"};
VectorSource source("source", tileset);
source.loadDescription(*test.fileSource);
test.renderSourceObserver.tileError = [&] (RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
EXPECT_EQ(SourceType::Vector, source_.baseImpl->type);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_EQ("Failed by the test case", util::toString(error));
test.end();
};
test.renderSourceObserver.tileError =
[&](RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
EXPECT_EQ(SourceType::Vector, source_.baseImpl->type);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_EQ("Failed by the test case", util::toString(error));
test.end();
};
auto renderSource = RenderSource::create(source.baseImpl);
renderSource->setObserver(&test.renderSourceObserver);
@@ -361,29 +358,31 @@ TEST(Source, VectorTileFail) {
TEST(Source, RasterTileCorrupt) {
SourceTest test;
test.fileSource->tileResponse = [&] (const Resource&) {
test.fileSource->tileResponse = [&](const Resource&) {
Response response;
response.data = std::make_unique<std::string>("CORRUPTED");
return response;
};
RasterLayer layer("id", "source");
Immutable<LayerProperties> layerProperties = makeMutable<RasterLayerProperties>(staticImmutableCast<RasterLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };
Immutable<LayerProperties> layerProperties = makeMutable<RasterLayerProperties>(
staticImmutableCast<RasterLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
Tileset tileset;
tileset.tiles = { "tiles" };
tileset.tiles = {"tiles"};
RasterSource source("source", tileset, 512);
source.loadDescription(*test.fileSource);
test.renderSourceObserver.tileError = [&] (RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
EXPECT_EQ(source_.baseImpl->type, SourceType::Raster);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_TRUE(bool(error));
// Not asserting on platform-specific error text.
test.end();
};
test.renderSourceObserver.tileError =
[&](RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
EXPECT_EQ(source_.baseImpl->type, SourceType::Raster);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_TRUE(bool(error));
// Not asserting on platform-specific error text.
test.end();
};
auto renderSource = RenderSource::create(source.baseImpl);
renderSource->setObserver(&test.renderSourceObserver);
@@ -395,29 +394,32 @@ TEST(Source, RasterTileCorrupt) {
TEST(Source, RasterDEMTileCorrupt) {
SourceTest test;
test.fileSource->tileResponse = [&] (const Resource&) {
test.fileSource->tileResponse = [&](const Resource&) {
Response response;
response.data = std::make_unique<std::string>("CORRUPTED");
return response;
};
HillshadeLayer layer("id", "source");
Immutable<LayerProperties> layerProperties = makeMutable<HillshadeLayerProperties>(staticImmutableCast<HillshadeLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };;
Immutable<LayerProperties> layerProperties = makeMutable<HillshadeLayerProperties>(
staticImmutableCast<HillshadeLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
;
Tileset tileset;
tileset.tiles = { "tiles" };
tileset.tiles = {"tiles"};
RasterDEMSource source("source", tileset, 512);
source.loadDescription(*test.fileSource);
test.renderSourceObserver.tileError = [&] (RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
EXPECT_EQ(source_.baseImpl->type, SourceType::RasterDEM);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_TRUE(bool(error));
// Not asserting on platform-specific error text.
test.end();
};
test.renderSourceObserver.tileError =
[&](RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
EXPECT_EQ(source_.baseImpl->type, SourceType::RasterDEM);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_TRUE(bool(error));
// Not asserting on platform-specific error text.
test.end();
};
auto renderSource = RenderSource::create(source.baseImpl);
renderSource->setObserver(&test.renderSourceObserver);
@@ -429,7 +431,7 @@ TEST(Source, RasterDEMTileCorrupt) {
TEST(Source, VectorTileCorrupt) {
SourceTest test;
test.fileSource->tileResponse = [&] (const Resource&) {
test.fileSource->tileResponse = [&](const Resource&) {
Response response;
response.data = std::make_unique<std::string>("CORRUPTED");
return response;
@@ -438,21 +440,23 @@ TEST(Source, VectorTileCorrupt) {
LineLayer layer("id", "source");
layer.setSourceLayer("water");
Immutable<LayerProperties> layerProperties = makeMutable<LineLayerProperties>(staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };
Immutable<LayerProperties> layerProperties = makeMutable<LineLayerProperties>(
staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
Tileset tileset;
tileset.tiles = { "tiles" };
tileset.tiles = {"tiles"};
VectorSource source("source", tileset);
source.loadDescription(*test.fileSource);
test.renderSourceObserver.tileError = [&] (RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
EXPECT_EQ(source_.baseImpl->type, SourceType::Vector);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_EQ(util::toString(error), "unknown pbf field type exception");
test.end();
};
test.renderSourceObserver.tileError =
[&](RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) {
EXPECT_EQ(source_.baseImpl->type, SourceType::Vector);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_EQ(util::toString(error), "unknown pbf field type exception");
test.end();
};
auto renderSource = RenderSource::create(source.baseImpl);
renderSource->setObserver(&test.renderSourceObserver);
@@ -464,26 +468,27 @@ TEST(Source, VectorTileCorrupt) {
TEST(Source, RasterTileCancel) {
SourceTest test;
test.fileSource->tileResponse = [&] (const Resource&) {
test.fileSource->tileResponse = [&](const Resource&) {
test.end();
return std::optional<Response>();
};
RasterLayer layer("id", "source");
Immutable<LayerProperties> layerProperties = makeMutable<RasterLayerProperties>(staticImmutableCast<RasterLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };
Immutable<LayerProperties> layerProperties = makeMutable<RasterLayerProperties>(
staticImmutableCast<RasterLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
Tileset tileset;
tileset.tiles = { "tiles" };
tileset.tiles = {"tiles"};
RasterSource source("source", tileset, 512);
source.loadDescription(*test.fileSource);
test.renderSourceObserver.tileChanged = [&] (RenderSource&, const OverscaledTileID&) {
test.renderSourceObserver.tileChanged = [&](RenderSource&, const OverscaledTileID&) {
FAIL() << "Should never be called";
};
test.renderSourceObserver.tileError = [&] (RenderSource&, const OverscaledTileID&, std::exception_ptr) {
test.renderSourceObserver.tileError = [&](RenderSource&, const OverscaledTileID&, std::exception_ptr) {
FAIL() << "Should never be called";
};
@@ -497,26 +502,27 @@ TEST(Source, RasterTileCancel) {
TEST(Source, RasterDEMTileCancel) {
SourceTest test;
test.fileSource->tileResponse = [&] (const Resource&) {
test.fileSource->tileResponse = [&](const Resource&) {
test.end();
return std::optional<Response>();
};
HillshadeLayer layer("id", "source");
Immutable<LayerProperties> layerProperties = makeMutable<HillshadeLayerProperties>(staticImmutableCast<HillshadeLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };
Immutable<LayerProperties> layerProperties = makeMutable<HillshadeLayerProperties>(
staticImmutableCast<HillshadeLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
Tileset tileset;
tileset.tiles = { "tiles" };
tileset.tiles = {"tiles"};
RasterDEMSource source("source", tileset, 512);
source.loadDescription(*test.fileSource);
test.renderSourceObserver.tileChanged = [&] (RenderSource&, const OverscaledTileID&) {
test.renderSourceObserver.tileChanged = [&](RenderSource&, const OverscaledTileID&) {
FAIL() << "Should never be called";
};
test.renderSourceObserver.tileError = [&] (RenderSource&, const OverscaledTileID&, std::exception_ptr) {
test.renderSourceObserver.tileError = [&](RenderSource&, const OverscaledTileID&, std::exception_ptr) {
FAIL() << "Should never be called";
};
@@ -530,7 +536,7 @@ TEST(Source, RasterDEMTileCancel) {
TEST(Source, VectorTileCancel) {
SourceTest test;
test.fileSource->tileResponse = [&] (const Resource&) {
test.fileSource->tileResponse = [&](const Resource&) {
test.end();
return std::optional<Response>();
};
@@ -538,20 +544,21 @@ TEST(Source, VectorTileCancel) {
LineLayer layer("id", "source");
layer.setSourceLayer("water");
Immutable<LayerProperties> layerProperties = makeMutable<LineLayerProperties>(staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };
Immutable<LayerProperties> layerProperties = makeMutable<LineLayerProperties>(
staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
Tileset tileset;
tileset.tiles = { "tiles" };
tileset.tiles = {"tiles"};
VectorSource source("source", tileset);
source.loadDescription(*test.fileSource);
test.renderSourceObserver.tileChanged = [&] (RenderSource&, const OverscaledTileID&) {
test.renderSourceObserver.tileChanged = [&](RenderSource&, const OverscaledTileID&) {
FAIL() << "Should never be called";
};
test.renderSourceObserver.tileError = [&] (RenderSource&, const OverscaledTileID&, std::exception_ptr) {
test.renderSourceObserver.tileError = [&](RenderSource&, const OverscaledTileID&, std::exception_ptr) {
FAIL() << "Should never be called";
};
@@ -566,28 +573,31 @@ TEST(Source, RasterTileAttribution) {
SourceTest test;
RasterLayer layer("id", "source");
Immutable<LayerProperties> layerProperties = makeMutable<RasterLayerProperties>(staticImmutableCast<RasterLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };
Immutable<LayerProperties> layerProperties = makeMutable<RasterLayerProperties>(
staticImmutableCast<RasterLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
std::string mapboxOSM = ("<a href='https://www.mapbox.com/about/maps/' target='_blank'>&copy; Mapbox</a> "
"<a href='http://www.openstreetmap.org/about/' target='_blank'>©️ OpenStreetMap</a>");
std::string mapboxOSM =
("<a href='https://www.mapbox.com/about/maps/' target='_blank'>&copy; "
"Mapbox</a> "
"<a href='http://www.openstreetmap.org/about/' target='_blank'>©️ "
"OpenStreetMap</a>");
test.fileSource->tileResponse = [&] (const Resource&) {
test.fileSource->tileResponse = [&](const Resource&) {
Response response;
response.noContent = true;
return response;
};
test.fileSource->sourceResponse = [&] (const Resource& resource) {
test.fileSource->sourceResponse = [&](const Resource& resource) {
EXPECT_EQ("url", resource.url);
Response response;
response.data = std::make_unique<std::string>(R"TILEJSON({ "tilejson": "2.1.0", "attribution": ")TILEJSON" +
mapboxOSM +
R"TILEJSON(", "tiles": [ "tiles" ] })TILEJSON");
mapboxOSM + R"TILEJSON(", "tiles": [ "tiles" ] })TILEJSON");
return response;
};
test.styleObserver.sourceChanged = [&] (Source& source) {
test.styleObserver.sourceChanged = [&](Source& source) {
EXPECT_EQ(mapboxOSM, source.getAttribution());
EXPECT_FALSE(mapboxOSM.find("©️ OpenStreetMap") == std::string::npos);
test.end();
@@ -607,27 +617,29 @@ TEST(Source, RasterDEMTileAttribution) {
SourceTest test;
HillshadeLayer layer("id", "source");
Immutable<LayerProperties> layerProperties = makeMutable<HillshadeLayerProperties>(staticImmutableCast<HillshadeLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };
Immutable<LayerProperties> layerProperties = makeMutable<HillshadeLayerProperties>(
staticImmutableCast<HillshadeLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
std::string mapbox = ("<a href='https://www.mapbox.com/about/maps/' target='_blank'>&copy; Mapbox</a> ");
std::string mapbox =
("<a href='https://www.mapbox.com/about/maps/' target='_blank'>&copy; "
"Mapbox</a> ");
test.fileSource->tileResponse = [&] (const Resource&) {
test.fileSource->tileResponse = [&](const Resource&) {
Response response;
response.noContent = true;
return response;
};
test.fileSource->sourceResponse = [&] (const Resource& resource) {
test.fileSource->sourceResponse = [&](const Resource& resource) {
EXPECT_EQ("url", resource.url);
Response response;
response.data = std::make_unique<std::string>(R"TILEJSON({ "tilejson": "2.1.0", "attribution": ")TILEJSON" +
mapbox +
R"TILEJSON(", "tiles": [ "tiles" ] })TILEJSON");
mapbox + R"TILEJSON(", "tiles": [ "tiles" ] })TILEJSON");
return response;
};
test.styleObserver.sourceChanged = [&] (Source& source) {
test.styleObserver.sourceChanged = [&](Source& source) {
EXPECT_EQ(mapbox, source.getAttribution());
test.end();
};
@@ -645,14 +657,15 @@ TEST(Source, RasterDEMTileAttribution) {
TEST(Source, GeoJSonSourceUrlUpdate) {
SourceTest test;
test.fileSource->sourceResponse = [&] (const Resource& resource) {
test.fileSource->sourceResponse = [&](const Resource& resource) {
EXPECT_EQ("url", resource.url);
Response response;
response.data = std::make_unique<std::string>(R"({"geometry": {"type": "Point", "coordinates": [1.1, 1.1]}, "type": "Feature", "properties": {}})");
response.data = std::make_unique<std::string>(
R"({"geometry": {"type": "Point", "coordinates": [1.1, 1.1]}, "type": "Feature", "properties": {}})");
return response;
};
test.styleObserver.sourceDescriptionChanged = [&] (Source&) {
test.styleObserver.sourceDescriptionChanged = [&](Source&) {
// Should be called (test will hang if it doesn't)
test.end();
};
@@ -664,7 +677,7 @@ TEST(Source, GeoJSonSourceUrlUpdate) {
source.loadDescription(*test.fileSource);
// Schedule an update
test.loop.invoke([&] () {
test.loop.invoke([&]() {
// Update the url
source.setURL(std::string("http://source-url.ext"));
});
@@ -675,13 +688,13 @@ TEST(Source, GeoJSonSourceUrlUpdate) {
TEST(Source, ImageSourceImageUpdate) {
SourceTest test;
test.fileSource->response = [&] (const Resource& resource) {
test.fileSource->response = [&](const Resource& resource) {
EXPECT_EQ("http://url", resource.url);
Response response;
response.data = std::make_unique<std::string>(util::read_file("test/fixtures/image/no_profile.png"));
return response;
};
test.styleObserver.sourceChanged = [&] (Source&) {
test.styleObserver.sourceChanged = [&](Source&) {
// Should be called (test will hang if it doesn't)
test.end();
};
@@ -693,14 +706,14 @@ TEST(Source, ImageSourceImageUpdate) {
// Load initial, so the source state will be loaded=true
source.loadDescription(*test.fileSource);
PremultipliedImage rgba({ 1, 1 });
PremultipliedImage rgba({1, 1});
rgba.data[0] = 255;
rgba.data[1] = 254;
rgba.data[2] = 253;
rgba.data[3] = 0;
// Schedule an update
test.loop.invoke([&] () {
test.loop.invoke([&]() {
// Update the url
source.setImage(std::move(rgba));
});
@@ -715,15 +728,16 @@ TEST(Source, CustomGeometrySourceSetTileData) {
LineLayer layer("id", "source");
layer.setSourceLayer("water");
Immutable<LayerProperties> layerProperties = makeMutable<LineLayerProperties>(staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };
Immutable<LayerProperties> layerProperties = makeMutable<LineLayerProperties>(
staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
test.renderSourceObserver.tileChanged = [&] (RenderSource& source_, const OverscaledTileID&) {
test.renderSourceObserver.tileChanged = [&](RenderSource& source_, const OverscaledTileID&) {
EXPECT_EQ("source", source_.baseImpl->id);
test.end();
};
test.renderSourceObserver.tileError = [&] (RenderSource&, const OverscaledTileID&, std::exception_ptr) {
test.renderSourceObserver.tileError = [&](RenderSource&, const OverscaledTileID&, std::exception_ptr) {
FAIL() << "Should never be called";
};
@@ -731,9 +745,9 @@ TEST(Source, CustomGeometrySourceSetTileData) {
renderSource->setObserver(&test.renderSourceObserver);
renderSource->update(source.baseImpl, layers, true, true, test.tileParameters());
test.loop.invoke([&] () {
test.loop.invoke([&]() {
// Set Tile Data
source.setTileData(CanonicalTileID(0, 0, 0), GeoJSON{ FeatureCollection{} });
source.setTileData(CanonicalTileID(0, 0, 0), GeoJSON{FeatureCollection{}});
});
test.run();
@@ -745,7 +759,8 @@ class FakeTileSource;
class FakeTile : public Tile {
public:
FakeTile(FakeTileSource& source_, const OverscaledTileID& tileID)
: Tile(Tile::Kind::Geometry, tileID), source(source_) {
: Tile(Tile::Kind::Geometry, tileID),
source(source_) {
renderable = true;
}
void setNecessity(TileNecessity necessity) override;
@@ -763,7 +778,8 @@ public:
MOCK_METHOD1(tileSetNecessity, void(TileNecessity));
MOCK_METHOD1(tileSetMinimumUpdateInterval, void(Duration));
explicit FakeTileSource(Immutable<style::Source::Impl> impl_) : RenderTileSetSource(std::move(impl_)) {}
explicit FakeTileSource(Immutable<style::Source::Impl> impl_)
: RenderTileSetSource(std::move(impl_)) {}
void updateInternal(const Tileset& tileset,
const std::vector<Immutable<style::LayerProperties>>& layers,
const bool needsRendering,
@@ -803,8 +819,8 @@ TEST(Source, InvisibleSourcesTileNecessity) {
FakeTileSource renderTilesetSource{initialized.baseImpl};
RenderSource* renderSource = &renderTilesetSource;
LineLayer layer("id", "source");
Immutable<LayerProperties> layerProperties =
makeMutable<LineLayerProperties>(staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
Immutable<LayerProperties> layerProperties = makeMutable<LineLayerProperties>(
staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
EXPECT_CALL(renderTilesetSource, tileSetNecessity(TileNecessity::Required)).Times(1);
renderSource->update(initialized.baseImpl, layers, true, true, test.tileParameters());
@@ -826,8 +842,8 @@ TEST(Source, SourceMinimumUpdateInterval) {
FakeTileSource renderTilesetSource{initialized.baseImpl};
RenderSource* renderSource = &renderTilesetSource;
LineLayer layer("id", "source");
Immutable<LayerProperties> layerProperties =
makeMutable<LineLayerProperties>(staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
Immutable<LayerProperties> layerProperties = makeMutable<LineLayerProperties>(
staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
Duration minimumTileUpdateInterval = initialized.getMinimumTileUpdateInterval();
@@ -873,7 +889,9 @@ TEST(Source, RenderTileSetSourceUpdate) {
void updateInternal(const Tileset&,
const std::vector<Immutable<style::LayerProperties>>&,
const bool, const bool, const TileParameters&) override {
const bool,
const bool,
const TileParameters&) override {
mockedUpdateInternal();
}
@@ -882,14 +900,15 @@ TEST(Source, RenderTileSetSourceUpdate) {
}
};
VectorSource initialized("source", Tileset{ {"tiles"} });
VectorSource initialized("source", Tileset{{"tiles"}});
initialized.loadDescription(*test.fileSource);
FakeRenderTileSetSource renderTilesetSource { initialized.baseImpl };
FakeRenderTileSetSource renderTilesetSource{initialized.baseImpl};
LineLayer layer("id", "source");
Immutable<LayerProperties> layerProperties = makeMutable<LineLayerProperties>(staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers { layerProperties };
Immutable<LayerProperties> layerProperties = makeMutable<LineLayerProperties>(
staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
// Check that `updateInternal()` is called even if the updated source has not yet loaded description.
EXPECT_CALL(renderTilesetSource, mockedUpdateInternal()).Times(2);
@@ -909,12 +928,13 @@ TEST(Source, GeoJSONSourceTilesAfterDataReset) {
RenderGeoJSONSource renderSource{staticImmutableCast<GeoJSONSource::Impl>(source.baseImpl)};
CircleLayer layer("id", "source");
Immutable<LayerProperties> layerProperties =
makeMutable<CircleLayerProperties>(staticImmutableCast<CircleLayer::Impl>(layer.baseImpl));
Immutable<LayerProperties> layerProperties = makeMutable<CircleLayerProperties>(
staticImmutableCast<CircleLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
static_cast<RenderSource&>(renderSource).update(source.baseImpl, layers, true, true, test.tileParameters());
EXPECT_FALSE(renderSource.isLoaded()); // loaded == false, means that the source contains pending tiles.
EXPECT_FALSE(renderSource.isLoaded()); // loaded == false, means that the
// source contains pending tiles.
source.setGeoJSONData(nullptr);
static_cast<RenderSource&>(renderSource).update(source.baseImpl, layers, true, true, test.tileParameters());
@@ -949,8 +969,8 @@ TEST(Source, SetMaxParentOverscaleFactor) {
};
RasterLayer layer("id", "source");
Immutable<LayerProperties> layerProperties =
makeMutable<RasterLayerProperties>(staticImmutableCast<RasterLayer::Impl>(layer.baseImpl));
Immutable<LayerProperties> layerProperties = makeMutable<RasterLayerProperties>(
staticImmutableCast<RasterLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
Tileset tileset;

View File

@@ -23,7 +23,7 @@ TEST(Style, Properties) {
util::RunLoop loop;
auto fileSource = std::make_shared<StubFileSource>();
Style::Impl style { fileSource, 1.0 };
Style::Impl style{fileSource, 1.0};
style.loadJSON(R"STYLE({"name": "Test"})STYLE");
ASSERT_EQ("Test", style.getName());
@@ -34,7 +34,7 @@ TEST(Style, Properties) {
style.loadJSON(R"STYLE({"bearing": 24})STYLE");
ASSERT_EQ("", style.getName());
ASSERT_EQ(LatLng {}, *style.getDefaultCamera().center);
ASSERT_EQ(LatLng{}, *style.getDefaultCamera().center);
ASSERT_EQ(24, *style.getDefaultCamera().bearing);
style.loadJSON(R"STYLE({"zoom": 13.3})STYLE");
@@ -55,7 +55,7 @@ TEST(Style, Properties) {
style.loadJSON(R"STYLE({"name": 23, "center": {}, "bearing": "north", "zoom": null, "pitch": "wide"})STYLE");
ASSERT_EQ("", style.getName());
ASSERT_EQ(LatLng {}, *style.getDefaultCamera().center);
ASSERT_EQ(LatLng{}, *style.getDefaultCamera().center);
ASSERT_EQ(0, *style.getDefaultCamera().zoom);
ASSERT_EQ(0, *style.getDefaultCamera().bearing);
ASSERT_EQ(0, *style.getDefaultCamera().pitch);
@@ -65,12 +65,12 @@ TEST(Style, DuplicateSource) {
util::RunLoop loop;
auto fileSource = std::make_shared<StubFileSource>();
Style::Impl style { fileSource, 1.0 };
Style::Impl style{fileSource, 1.0};
style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
style.addSource(std::make_unique<VectorSource>("sourceId", "mptiler://tiles/contours"));
try {
style.addSource(std::make_unique<VectorSource>("sourceId", "mptiler://tiles/contours"));
FAIL() << "Should not have been allowed to add a duplicate source id";
@@ -86,7 +86,7 @@ TEST(Style, RemoveSourceInUse) {
Log::setObserver(std::unique_ptr<Log::Observer>(log));
auto fileSource = std::make_shared<StubFileSource>();
Style::Impl style { fileSource, 1.0 };
Style::Impl style{fileSource, 1.0};
style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
@@ -98,11 +98,11 @@ TEST(Style, RemoveSourceInUse) {
ASSERT_EQ(nullptr, removed);
ASSERT_NE(nullptr, style.getSource("sourceId"));
const FixtureLogObserver::LogMessage logMessage {
EventSeverity::Warning,
Event::General,
int64_t(-1),
"Source 'sourceId' is in use, cannot remove",
const FixtureLogObserver::LogMessage logMessage{
EventSeverity::Warning,
Event::General,
int64_t(-1),
"Source 'sourceId' is in use, cannot remove",
};
#if defined(WIN32)

View File

@@ -8,7 +8,7 @@ using namespace mbgl;
TEST(StyleImage, ZeroWidth) {
try {
style::Image("test", PremultipliedImage({ 0, 16 }), 2.0f);
style::Image("test", PremultipliedImage({0, 16}), 2.0f);
FAIL() << "Expected exception";
} catch (util::StyleImageException& ex) {
EXPECT_STREQ("dimensions may not be zero", ex.what());
@@ -17,7 +17,7 @@ TEST(StyleImage, ZeroWidth) {
TEST(StyleImage, ZeroHeight) {
try {
style::Image("test", PremultipliedImage({ 16, 0 }), 2.0f);
style::Image("test", PremultipliedImage({16, 0}), 2.0f);
FAIL() << "Expected exception";
} catch (util::StyleImageException& ex) {
EXPECT_STREQ("dimensions may not be zero", ex.what());
@@ -26,7 +26,7 @@ TEST(StyleImage, ZeroHeight) {
TEST(StyleImage, ZeroRatio) {
try {
style::Image("test", PremultipliedImage({ 16, 16 }), 0.0f);
style::Image("test", PremultipliedImage({16, 16}), 0.0f);
FAIL() << "Expected exception";
} catch (util::StyleImageException& ex) {
EXPECT_STREQ("pixelRatio may not be <= 0", ex.what());
@@ -34,14 +34,14 @@ TEST(StyleImage, ZeroRatio) {
}
TEST(StyleImage, Retina) {
style::Image image("test", PremultipliedImage({ 32, 24 }), 2.0f);
style::Image image("test", PremultipliedImage({32, 24}), 2.0f);
EXPECT_EQ(32u, image.getImage().size.width);
EXPECT_EQ(24u, image.getImage().size.height);
EXPECT_EQ(2, image.getPixelRatio());
}
TEST(StyleImage, FractionalRatio) {
style::Image image("test", PremultipliedImage({ 20, 12 }), 1.5f);
style::Image image("test", PremultipliedImage({20, 12}), 1.5f);
EXPECT_EQ(20u, image.getImage().size.width);
EXPECT_EQ(12u, image.getImage().size.height);
EXPECT_EQ(1.5, image.getPixelRatio());
@@ -110,8 +110,12 @@ TEST(StyleImage, InvalidContent) {
}
TEST(StyleImage, StretchContent) {
style::Image image(
"test", PremultipliedImage({16, 16}), 1, {{2.0f, 14.0f}}, {{0.0f, 4.0f}, {12.0f, 16.0f}}, style::ImageContent{2, 2, 14, 14});
style::Image image("test",
PremultipliedImage({16, 16}),
1,
{{2.0f, 14.0f}},
{{0.0f, 4.0f}, {12.0f, 16.0f}},
style::ImageContent{2, 2, 14, 14});
EXPECT_EQ(16u, image.getImage().size.width);
EXPECT_EQ(16u, image.getImage().size.height);
EXPECT_EQ(1.0, image.getPixelRatio());

View File

@@ -37,13 +37,13 @@ using namespace std::literals::string_literals;
namespace {
const auto color = Color { 1, 0, 0, 1 };
const auto color = Color{1, 0, 0, 1};
const auto opacity = 1.0f;
const auto radius = 1.0f;
const auto blur = 1.0f;
const auto pattern = PropertyValue<expression::Image>{"foo"};
const auto antialias = false;
const auto translate = std::array<float, 2> {{ 0, 0 }};
const auto translate = std::array<float, 2>{{0, 0}};
const auto translateAnchor = TranslateAnchorType::Map;
const auto lineCap = LineCapType::Round;
const auto lineJoin = LineJoinType::Miter;
@@ -52,7 +52,7 @@ const auto roundLimit = 1.0f;
const auto width = 1.0f;
const auto gapWidth = 1.0f;
const auto offset = 1.0f;
const auto dashArray = std::vector<float> {};
const auto dashArray = std::vector<float>{};
const auto hueRotate = 1.0f;
const auto brightness = 1.0f;
const auto saturation = 1.0f;
@@ -225,7 +225,7 @@ TEST(Layer, Observer) {
// Notifies observer on filter change.
bool filterChanged = false;
observer.layerChanged = [&] (Layer& layer_) {
observer.layerChanged = [&](Layer& layer_) {
EXPECT_EQ(layer.get(), &layer_);
filterChanged = true;
};
@@ -234,7 +234,7 @@ TEST(Layer, Observer) {
// Notifies observer on visibility change.
bool visibilityChanged = false;
observer.layerChanged = [&] (Layer& layer_) {
observer.layerChanged = [&](Layer& layer_) {
EXPECT_EQ(layer.get(), &layer_);
visibilityChanged = true;
};
@@ -243,7 +243,7 @@ TEST(Layer, Observer) {
// Notifies observer on paint property change.
bool paintPropertyChanged = false;
observer.layerChanged = [&] (Layer& layer_) {
observer.layerChanged = [&](Layer& layer_) {
EXPECT_EQ(layer.get(), &layer_);
paintPropertyChanged = true;
};
@@ -252,7 +252,7 @@ TEST(Layer, Observer) {
// Notifies observer on layout property change.
bool layoutPropertyChanged = false;
observer.layerChanged = [&] (Layer& layer_) {
observer.layerChanged = [&](Layer& layer_) {
EXPECT_EQ(layer.get(), &layer_);
layoutPropertyChanged = true;
};
@@ -261,7 +261,7 @@ TEST(Layer, Observer) {
// Does not notify observer on no-op visibility change.
visibilityChanged = false;
observer.layerChanged = [&] (Layer& layer_) {
observer.layerChanged = [&](Layer& layer_) {
EXPECT_EQ(layer.get(), &layer_);
visibilityChanged = true;
};
@@ -270,7 +270,7 @@ TEST(Layer, Observer) {
// Does not notify observer on no-op paint property change.
paintPropertyChanged = false;
observer.layerChanged = [&] (Layer& layer_) {
observer.layerChanged = [&](Layer& layer_) {
EXPECT_EQ(layer.get(), &layer_);
paintPropertyChanged = true;
};
@@ -279,7 +279,7 @@ TEST(Layer, Observer) {
// Does not notify observer on no-op layout property change.
layoutPropertyChanged = false;
observer.layerChanged = [&] (Layer& layer_) {
observer.layerChanged = [&](Layer& layer_) {
EXPECT_EQ(layer.get(), &layer_);
layoutPropertyChanged = true;
};
@@ -292,7 +292,7 @@ TEST(Layer, DuplicateLayer) {
// Setup style
auto fileSource = std::make_shared<StubFileSource>();
Style::Impl style { fileSource, 1.0 };
Style::Impl style{fileSource, 1.0};
style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
// Add initial layer
@@ -319,7 +319,8 @@ TEST(Layer, IncompatibleLayer) {
// Try to add duplicate
try {
style.addLayer(std::make_unique<RasterLayer>("raster", "unusedsource"));
FAIL() << "Should not have been allowed to add an incompatible layer to the source";
FAIL() << "Should not have been allowed to add an incompatible layer "
"to the source";
} catch (const std::runtime_error& e) {
// Expected
ASSERT_STREQ("Layer 'raster' is not compatible with source 'unusedsource'", e.what());
@@ -328,7 +329,7 @@ TEST(Layer, IncompatibleLayer) {
namespace {
template<template<typename> class PropertyValueType, typename LayoutType>
template <template <typename> class PropertyValueType, typename LayoutType>
void testHasOverrides(LayoutType& layout) {
// Undefined
layout.template get<TextField>() = PropertyValueType<Formatted>();
@@ -364,9 +365,10 @@ void testHasOverrides(LayoutType& layout) {
secondParagraph.setTextSectionOptions(std::nullopt, std::nullopt, toColor(literal("blue")));
std::vector<FormatExpressionSection> sections{{std::move(secondParagraph)}};
auto formattedExpr2 = std::make_unique<FormatExpression>(std::move(sections));
std::unordered_map<std::string, std::shared_ptr<Expression>> branches{ { "1st", std::move(formattedExpr1) },
{ "2nd", std::move(formattedExpr2) } };
auto match = std::make_unique<Match<std::string>>(type::Formatted, literal("input"), std::move(branches), format("otherwise"));
std::unordered_map<std::string, std::shared_ptr<Expression>> branches{{"1st", std::move(formattedExpr1)},
{"2nd", std::move(formattedExpr2)}};
auto match = std::make_unique<Match<std::string>>(
type::Formatted, literal("input"), std::move(branches), format("otherwise"));
PropertyExpression<Formatted> nestedPropExpr(std::move(match));
layout.template get<TextField>() = PropertyValueType<Formatted>(std::move(nestedPropExpr));
EXPECT_TRUE(MockOverrides::hasOverrides(layout.template get<TextField>()));
@@ -375,7 +377,6 @@ void testHasOverrides(LayoutType& layout) {
} // namespace
TEST(Layer, SymbolLayerOverrides) {
// Unevaluated / transitionable.
{
MockLayoutProperties::Unevaluated layout;

View File

@@ -49,24 +49,23 @@ TEST_P(StyleParserTest, ParseStyle) {
ASSERT_TRUE(infoDoc.IsObject());
for (const auto& property : infoDoc.GetObject()) {
const std::string name { property.name.GetString(), property.name.GetStringLength() };
const JSValue &value = property.value;
const std::string name{property.name.GetString(), property.name.GetStringLength()};
const JSValue& value = property.value;
ASSERT_EQ(true, value.IsObject());
if (value.HasMember("log")) {
const JSValue &js_log = value["log"];
const JSValue& js_log = value["log"];
ASSERT_EQ(true, js_log.IsArray());
for (auto& js_entry : js_log.GetArray()) {
ASSERT_EQ(true, js_entry.IsArray());
ASSERT_GE(4u, js_entry.Size());
const uint32_t count = js_entry[rapidjson::SizeType(0)].GetUint();
const FixtureLogObserver::LogMessage message {
const FixtureLogObserver::LogMessage message{
*Enum<EventSeverity>::toEnum(js_entry[rapidjson::SizeType(1)].GetString()),
*Enum<Event>::toEnum(js_entry[rapidjson::SizeType(2)].GetString()),
int64_t(-1),
js_entry[rapidjson::SizeType(3)].GetString()
};
js_entry[rapidjson::SizeType(3)].GetString()};
#if defined(WIN32)
Sleep(10);
@@ -76,7 +75,7 @@ TEST_P(StyleParserTest, ParseStyle) {
}
}
const auto &unchecked = observer->unchecked();
const auto& unchecked = observer->unchecked();
if (unchecked.size()) {
std::cerr << "Unchecked Log Messages (" << base << "/" << name << "): " << std::endl << unchecked;
}
@@ -109,9 +108,9 @@ static void populateNames(std::vector<std::string>& names) {
FindClose(hFind);
}
#else
DIR *dir = opendir(style_directory.c_str());
DIR* dir = opendir(style_directory.c_str());
if (dir != nullptr) {
for (dirent *dp = nullptr; (dp = readdir(dir)) != nullptr;) {
for (dirent* dp = nullptr; (dp = readdir(dir)) != nullptr;) {
const std::string name = dp->d_name;
testName(name);
}