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

@@ -15,7 +15,7 @@ using namespace mbgl;
Although they may look the same as input in your viewer, the
characters in the test results are "presentation forms" of
the characters.
To closely inspect the inputs and outputs, use a binary/hex editor.
*/
@@ -29,19 +29,21 @@ TEST(BiDi, Tashkeel) {
TEST(BiDi, MixedShaping) {
EXPECT_EQ(applyArabicShaping(u"مكتبة الإسكندرية‎‎ Maktabat al-Iskandarīyah"),
u"ﻣﻜﺘﺒﺔ ﺍﻹﺳﻜﻨﺪﺭﻳﺔ‎‎ Maktabat al-Iskandarīyah");
u"ﻣﻜﺘﺒﺔ ﺍﻹﺳﻜﻨﺪﺭﻳﺔ‎‎ Maktabat "
u"al-Iskandarīyah");
}
TEST(BiDi, ReverseArabic) {
BiDi bidi;
EXPECT_EQ(bidi.processText(applyArabicShaping(u"سلام۳۹"), {}),
std::vector<std::u16string>{ u"۳۹ﻡﻼﺳ" });
EXPECT_EQ(bidi.processText(applyArabicShaping(u"سلام۳۹"), {}), std::vector<std::u16string>{u"۳۹ﻡﻼﺳ"});
}
TEST(BiDi, ReverseMixed) {
BiDi bidi;
EXPECT_EQ(bidi.processText(applyArabicShaping(u"مكتبة الإسكندرية‎‎ Maktabat al-Iskandarīyah"), {}),
std::vector<std::u16string>{ u" Maktabat al-Iskandarīyahﺔﻳﺭﺪﻨﻜﺳﻹﺍ ﺔﺒﺘﻜﻣ" });
EXPECT_EQ(bidi.processText(applyArabicShaping(u"مكتبة الإسكندرية‎‎ Maktabat "
u"al-Iskandarīyah"),
{}),
std::vector<std::u16string>{u" Maktabat al-Iskandarīyahﺔﻳﺭﺪﻨﻜﺳﻹﺍ ﺔﺒﺘﻜﻣ"});
}
TEST(BiDi, WithLineBreaks) {
@@ -50,41 +52,30 @@ TEST(BiDi, WithLineBreaks) {
expected.emplace_back(u" ﺔﻳﺭﺪﻨﻜﺳﻹﺍ ﺔﺒﺘﻜﻣ");
expected.emplace_back(u"Maktabat al-");
expected.emplace_back(u"Iskandarīyah");
EXPECT_EQ(bidi.processText(applyArabicShaping(u"مكتبة الإسكندرية‎‎ Maktabat al-Iskandarīyah"), { 18, 30 }),
EXPECT_EQ(bidi.processText(applyArabicShaping(u"مكتبة الإسكندرية‎‎ Maktabat "
u"al-Iskandarīyah"),
{18, 30}),
expected);
}
TEST(BiDi, StyledText) {
// This test uses line breaks that intentionally split/reorder/interleave styled blocks
// that are contiguous in the input
// This test uses line breaks that intentionally split/reorder/interleave
// styled blocks that are contiguous in the input
BiDi bidi;
std::vector<StyledText> expected;
StyledText input(
applyArabicShaping(u"مكتبة الإسكندرية‎‎ Maktabat al-Iskandarīyah"),
std::vector<uint8_t>{ 0,0,0,0,0,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,4,5,5,5,5,6,6,6,6,6,6,6,6,6,6,7,7,7 }
);
StyledText input(applyArabicShaping(u"مكتبة الإسكندرية‎‎ Maktabat al-Iskandarīyah"),
std::vector<uint8_t>{0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3,
3, 3, 3, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7});
expected.emplace_back(StyledText(
u"ﺔﺒﺘﻜﻣ",
std::vector<uint8_t>{ 0,0,0,0,0 }
));
expected.emplace_back(StyledText(u"ﺔﺒﺘﻜﻣ", std::vector<uint8_t>{0, 0, 0, 0, 0}));
EXPECT_EQ(expected.rbegin()->first.size(), expected.rbegin()->second.size());
expected.emplace_back(StyledText(
u" ‎‎ﺔﻳﺭﺪﻨﻜﺳﻹﺍ ",
std::vector<uint8_t>{ 2,2,2,2,2,2,2,1,1,1,1,1,1 }
));
expected.emplace_back(StyledText(u" ‎‎ﺔﻳﺭﺪﻨﻜﺳﻹﺍ ",
std::vector<uint8_t>{2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1}));
EXPECT_EQ(expected.rbegin()->first.size(), expected.rbegin()->second.size());
expected.emplace_back(StyledText(
u"Maktabat al-",
std::vector<uint8_t>{ 2,3,3,3,3,3,4,5,5,5,5,6 }
));
expected.emplace_back(StyledText(u"Maktabat al-", std::vector<uint8_t>{2, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 6}));
EXPECT_EQ(expected.rbegin()->first.size(), expected.rbegin()->second.size());
expected.emplace_back(StyledText(
u"Iskandarīyah",
std::vector<uint8_t>{ 6,6,6,6,6,6,6,6,6,7,7,7 }
));
expected.emplace_back(StyledText(u"Iskandarīyah", std::vector<uint8_t>{6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7}));
EXPECT_EQ(expected.rbegin()->first.size(), expected.rbegin()->second.size());
EXPECT_EQ(bidi.processStyledText(input, { 5, 18, 30 }), expected);
EXPECT_EQ(bidi.processStyledText(input, {5, 18, 30}), expected);
}

View File

@@ -29,12 +29,30 @@ SymbolInstance makeSymbolInstance(float x, float y, std::u16string key) {
SymbolContent::IconSDF,
false,
false);
return SymbolInstance(anchor, std::move(sharedData), shaping, std::nullopt, std::nullopt, 0, 0, placementType, textOffset, 0, 0, iconOffset, subfeature, 0, 0, key, 0.0f, 0.0f, 0.0f, variableTextOffset, false);
return SymbolInstance(anchor,
std::move(sharedData),
shaping,
std::nullopt,
std::nullopt,
0,
0,
placementType,
textOffset,
0,
0,
iconOffset,
subfeature,
0,
0,
key,
0.0f,
0.0f,
0.0f,
variableTextOffset,
false);
}
TEST(CrossTileSymbolLayerIndex, addBucket) {
uint32_t maxCrossTileID = 0;
uint32_t maxBucketInstanceId = 0;
CrossTileSymbolLayerIndex index(maxCrossTileID);
@@ -71,7 +89,6 @@ TEST(CrossTileSymbolLayerIndex, addBucket) {
ASSERT_EQ(mainBucket.symbolInstances.at(0).crossTileID, 1u);
ASSERT_EQ(mainBucket.symbolInstances.at(1).crossTileID, 2u);
OverscaledTileID childID(7, 0, 7, 16, 16);
std::vector<SymbolInstance> childInstances;
std::vector<SortKeyRange> childRanges;
@@ -160,11 +177,9 @@ TEST(CrossTileSymbolLayerIndex, addBucket) {
ASSERT_EQ(grandchildBucket.symbolInstances.at(0).crossTileID, 1u);
// Does not match the previous value for Windsor because that tile was removed
ASSERT_EQ(grandchildBucket.symbolInstances.at(1).crossTileID, 5u);
}
TEST(CrossTileSymbolLayerIndex, resetIDs) {
uint32_t maxCrossTileID = 0;
uint32_t maxBucketInstanceId = 0;
CrossTileSymbolLayerIndex index(maxCrossTileID);
@@ -293,9 +308,12 @@ TEST(CrossTileSymbolLayerIndex, noDuplicatesWithinZoomLevel) {
// copies parent ids without duplicate ids in this tile
index.addBucket(childID, mat4{}, childBucket);
ASSERT_EQ(childBucket.symbolInstances.at(0).crossTileID, 1u); // A' copies from A
ASSERT_EQ(childBucket.symbolInstances.at(1).crossTileID, 2u); // B' copies from B
ASSERT_EQ(childBucket.symbolInstances.at(2).crossTileID, 3u); // C' gets new ID
ASSERT_EQ(childBucket.symbolInstances.at(0).crossTileID,
1u); // A' copies from A
ASSERT_EQ(childBucket.symbolInstances.at(1).crossTileID,
2u); // B' copies from B
ASSERT_EQ(childBucket.symbolInstances.at(2).crossTileID,
3u); // C' gets new ID
}
TEST(CrossTileSymbolLayerIndex, bucketReplacement) {
@@ -358,9 +376,12 @@ TEST(CrossTileSymbolLayerIndex, bucketReplacement) {
// copies parent ids without duplicate ids in this tile
index.addBucket(tileID, mat4{}, secondBucket);
ASSERT_EQ(secondBucket.symbolInstances.at(0).crossTileID, 1u); // A' copies from A
ASSERT_EQ(secondBucket.symbolInstances.at(1).crossTileID, 2u); // B' copies from B
ASSERT_EQ(secondBucket.symbolInstances.at(2).crossTileID, 3u); // C' gets new ID
ASSERT_EQ(secondBucket.symbolInstances.at(0).crossTileID,
1u); // A' copies from A
ASSERT_EQ(secondBucket.symbolInstances.at(1).crossTileID,
2u); // B' copies from B
ASSERT_EQ(secondBucket.symbolInstances.at(2).crossTileID,
3u); // C' gets new ID
}
namespace {

View File

@@ -34,8 +34,16 @@ const float overscaling = 1.0f;
} // namespace
TEST(getAnchors, NonContinuedLineShortLabels) {
const Anchors anchors = getAnchors(
nonContinuedLine, bigSpacing, static_cast<float>(M_PI), textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale, overscaling);
const Anchors anchors = getAnchors(nonContinuedLine,
bigSpacing,
static_cast<float>(M_PI),
textLeft,
textRight,
iconLeft,
iconRight,
glyphSize,
boxScale,
overscaling);
const Anchors expected_anchors = {Anchor(1.0f, 2.0f, 1.570796371f, 1u),
Anchor(1.0f, 5.0f, 1.570796371f, 4u),
Anchor(1.0f, 8.0f, 1.570796371f, 7u)};
@@ -62,8 +70,16 @@ TEST(getAnchors, NonContinuedLineLongLabels) {
}
TEST(getAnchors, ContinuedLineShortLabels) {
const Anchors anchors = getAnchors(
continuedLine, bigSpacing, static_cast<float>(M_PI), textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale, overscaling);
const Anchors anchors = getAnchors(continuedLine,
bigSpacing,
static_cast<float>(M_PI),
textLeft,
textRight,
iconLeft,
iconRight,
glyphSize,
boxScale,
overscaling);
const Anchors expected_anchors = {Anchor(1.0f, 2.0f, 1.570796371f, 1u),
Anchor(1.0f, 5.0f, 1.570796371f, 4u),
Anchor(1.0f, 8.0f, 1.570796371f, 7u)};
@@ -72,8 +88,16 @@ TEST(getAnchors, ContinuedLineShortLabels) {
}
TEST(getAnchors, ContinuedLineLongLabels) {
const Anchors anchors = getAnchors(
continuedLine, smallSpacing, static_cast<float>(M_PI), textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale, overscaling);
const Anchors anchors = getAnchors(continuedLine,
smallSpacing,
static_cast<float>(M_PI),
textLeft,
textRight,
iconLeft,
iconRight,
glyphSize,
boxScale,
overscaling);
const Anchors expected_anchors = {Anchor(1.0f, 1.0f, 1.570796371f, 1u),
Anchor(1.0f, 4.0f, 1.570796371f, 3u),
Anchor(1.0f, 6.0f, 1.570796371f, 6u)};
@@ -82,8 +106,16 @@ TEST(getAnchors, ContinuedLineLongLabels) {
}
TEST(getAnchors, OverscaledAnchorsInParent) {
const Anchors anchors = getAnchors(
nonContinuedLine, bigSpacing, static_cast<float>(M_PI), textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale, overscaling);
const Anchors anchors = getAnchors(nonContinuedLine,
bigSpacing,
static_cast<float>(M_PI),
textLeft,
textRight,
iconLeft,
iconRight,
glyphSize,
boxScale,
overscaling);
const Anchors childAnchors = getAnchors(nonContinuedLine,
bigSpacing / 2,
static_cast<float>(M_PI),
@@ -93,7 +125,8 @@ TEST(getAnchors, OverscaledAnchorsInParent) {
iconRight,
glyphSize,
0.5f /*boxScale*/,
2.0f /*overscaling*/);
2.0f /*overscaling*/
);
for (const auto& anchor : anchors) {
EXPECT_TRUE(std::find(childAnchors.begin(), childAnchors.end(), anchor) != childAnchors.end());
}
@@ -101,8 +134,16 @@ TEST(getAnchors, OverscaledAnchorsInParent) {
TEST(getAnchors, UseMidpointForShortLine) {
const GeometryCoordinates shortLine = {Point<int16_t>{1, 1}, Point<int16_t>{1, 3}};
const Anchors anchors = getAnchors(
shortLine, smallSpacing, static_cast<float>(M_PI), textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale, overscaling);
const Anchors anchors = getAnchors(shortLine,
smallSpacing,
static_cast<float>(M_PI),
textLeft,
textRight,
iconLeft,
iconRight,
glyphSize,
boxScale,
overscaling);
const Anchors expected_anchors = {Anchor(1.0f, 2.0f, 1.570796371f, 0u)};
EXPECT_EQ(anchors, expected_anchors);
@@ -111,20 +152,23 @@ TEST(getAnchors, UseMidpointForShortLine) {
TEST(getAnchors, GetCenterAnchor) {
const GeometryCoordinates line = {
Point<int16_t>{1, 1}, Point<int16_t>{1, 3}, Point<int16_t>{3, 6}, Point<int16_t>{4, 7}};
const auto anchor = getCenterAnchor(line, static_cast<float>(M_PI), textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale);
const auto anchor = getCenterAnchor(
line, static_cast<float>(M_PI), textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale);
EXPECT_TRUE(anchor);
EXPECT_EQ(*anchor, Anchor(2.0f, 4.0f, .982793748f, 1u));
}
TEST(getAnchors, GetCenterAnchorOutsideTileBounds) {
const GeometryCoordinates line = {Point<int16_t>{-10, -10}, Point<int16_t>{5, 5}};
const auto anchor = getCenterAnchor(line, static_cast<float>(M_PI), textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale);
const auto anchor = getCenterAnchor(
line, static_cast<float>(M_PI), textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale);
EXPECT_TRUE(anchor);
EXPECT_EQ(*anchor, Anchor(-3.0f, -3.0f, .785398185f, 0u));
}
TEST(getAnchors, GetCenterAnchorFailMaxAngle) {
const GeometryCoordinates line = {Point<int16_t>{1, 1}, Point<int16_t>{1, 3}, Point<int16_t>{3, 3}};
const auto anchor = getCenterAnchor(line, static_cast<float>(M_PI) / 4, textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale);
const auto anchor = getCenterAnchor(
line, static_cast<float>(M_PI) / 4, textLeft, textRight, iconLeft, iconRight, glyphSize, boxScale);
EXPECT_FALSE(anchor);
}

View File

@@ -11,9 +11,89 @@
using namespace mbgl;
// Alpha channel rendering of '中'
static constexpr const uint8_t stubBitmap[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 95, 82, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 255, 233, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 255, 227, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 22, 18, 18, 18, 18, 18, 15, 55, 255, 255, 42, 14, 18, 18, 18, 18, 18, 22, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 145, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 167, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 149, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 178, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90, 255, 120, 8, 15, 15, 15, 11, 51, 255, 233, 32, 11, 15, 15, 15, 8, 93, 255, 178, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84, 255, 100, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0, 0, 84, 255, 178, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84, 255, 107, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0, 0, 84, 255, 178, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84, 255, 107, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0, 0, 84, 255, 178, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84, 255, 100, 0, 0, 0, 0, 0, 32, 255, 227, 10, 0, 0, 0, 0, 0, 78, 255, 178, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84, 255, 170, 101, 101, 101, 101, 101, 129, 255, 255, 133, 100, 101, 101, 101, 96, 191, 255, 178, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 105, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 178, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 156, 255, 172, 110, 116, 116, 116, 115, 140, 255, 242, 127, 116, 116, 116, 116, 110, 163, 255, 169, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 145, 255, 108, 0, 0, 0, 0, 0, 32, 255, 227, 10, 0, 0, 0, 0, 0, 89, 255, 194, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 27, 16, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0, 0, 14, 27, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 73, 205, 167, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
static constexpr const uint8_t stubBitmap[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 50, 95, 82, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 255, 233, 17, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 36, 255, 227, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 6, 22, 18, 18, 18, 18, 18, 15, 55, 255, 255, 42, 14, 18, 18, 18, 18, 18, 22, 12, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 145, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 167, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 149, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 178, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90,
255, 120, 8, 15, 15, 15, 11, 51, 255, 233, 32, 11, 15, 15, 15, 8, 93, 255, 178, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0, 84, 255, 100, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0, 0,
84, 255, 178, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84, 255, 107, 0, 0, 0, 0, 0, 37, 255,
233, 17, 0, 0, 0, 0, 0, 84, 255, 178, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84, 255, 107,
0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0, 0, 84, 255, 178, 2, 0, 0, 0, 0, 0,
0, 0, 0, 0, 84, 255, 100, 0, 0, 0, 0, 0, 32, 255, 227, 10, 0, 0, 0, 0, 0, 78, 255,
178, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84, 255, 170, 101, 101, 101, 101, 101, 129, 255, 255, 133,
100, 101, 101, 101, 96, 191, 255, 178, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 105, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 178, 2, 0, 0, 0, 0, 0, 0, 0,
0, 1, 156, 255, 172, 110, 116, 116, 116, 115, 140, 255, 242, 127, 116, 116, 116, 116, 110, 163, 255, 169, 2,
0, 0, 0, 0, 0, 0, 0, 0, 0, 145, 255, 108, 0, 0, 0, 0, 0, 32, 255, 227, 10, 0, 0,
0, 0, 0, 89, 255, 194, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 27, 16, 0, 0, 0, 0,
0, 37, 255, 233, 17, 0, 0, 0, 0, 0, 14, 27, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37,
255, 233, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 255, 233, 17, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 73, 205, 167,
4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0};
// SDF transformation of '中'
static constexpr const uint8_t sdfBitmap[] = {0, 0, 0, 0, 0, 0, 0, 0, 19, 48, 76, 101, 119, 127, 127, 127, 126, 118, 100, 75, 48, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 19, 28, 31, 31, 31, 31, 59, 90, 119, 145, 158, 159, 159, 156, 144, 118, 89, 59, 31, 31, 31, 31, 28, 19, 5, 0, 0, 0, 10, 31, 48, 59, 63, 63, 63, 63, 63, 95, 127, 158, 182, 187, 186, 176, 156, 126, 94, 63, 63, 63, 63, 63, 59, 48, 31, 10, 0, 5, 31, 55, 75, 89, 94, 95, 95, 95, 95, 95, 127, 158, 181, 223, 204, 177, 157, 126, 95, 95, 95, 95, 95, 95, 89, 75, 55, 31, 10, 19, 48, 75, 100, 118, 126, 126, 126, 126, 126, 126, 127, 157, 180, 223, 204, 177, 157, 126, 126, 126, 126, 126, 126, 126, 119, 100, 75, 55, 31, 28, 59, 89, 118, 144, 156, 157, 157, 157, 157, 157, 157, 157, 180, 223, 204, 177, 156, 157, 157, 157, 157, 157, 157, 156, 144, 119, 100, 75, 48, 31, 63, 94, 126, 156, 176, 178, 178, 178, 178, 178, 178, 177, 182, 223, 223, 181, 177, 178, 178, 178, 178, 178, 178, 177, 156, 144, 118, 89, 59, 32, 64, 96, 128, 159, 193, 223, 223, 223, 223, 223, 223, 223, 223, 236, 236, 223, 223, 223, 223, 223, 223, 223, 223, 196, 176, 156, 126, 94, 63, 32, 64, 96, 128, 159, 194, 223, 223, 223, 223, 223, 223, 223, 223, 236, 226, 223, 223, 223, 223, 223, 223, 223, 224, 198, 176, 156, 126, 94, 63, 32, 64, 96, 127, 159, 187, 223, 190, 176, 177, 177, 177, 177, 182, 223, 204, 179, 177, 177, 177, 177, 176, 187, 223, 198, 176, 156, 126, 94, 63, 32, 64, 95, 127, 159, 186, 223, 188, 159, 156, 156, 156, 157, 180, 223, 204, 177, 157, 156, 156, 156, 159, 186, 223, 198, 176, 156, 126, 94, 63, 32, 64, 95, 127, 159, 186, 223, 189, 159, 127, 126, 127, 157, 180, 223, 204, 177, 157, 126, 126, 127, 159, 186, 223, 198, 176, 156, 126, 94, 63, 32, 64, 95, 127, 159, 186, 223, 189, 159, 127, 127, 127, 157, 180, 223, 204, 177, 157, 127, 127, 127, 159, 186, 223, 198, 176, 156, 126, 94, 63, 32, 64, 95, 127, 159, 186, 223, 188, 159, 159, 159, 159, 159, 179, 223, 204, 177, 159, 159, 159, 159, 159, 185, 223, 198, 176, 156, 126, 94, 63, 48, 75, 100, 127, 159, 186, 223, 197, 188, 188, 188, 188, 188, 191, 223, 223, 192, 188, 188, 188, 188, 187, 199, 224, 198, 176, 156, 126, 94, 63, 59, 89, 118, 143, 159, 188, 223, 224, 223, 223, 223, 223, 223, 223, 236, 226, 223, 223, 223, 223, 223, 223, 223, 224, 198, 176, 156, 126, 94, 63, 63, 94, 126, 156, 175, 195, 223, 197, 189, 190, 190, 190, 190, 193, 223, 206, 191, 190, 190, 190, 190, 189, 196, 223, 196, 176, 156, 126, 94, 63, 59, 89, 118, 143, 159, 193, 223, 189, 159, 159, 159, 159, 159, 179, 223, 204, 177, 159, 159, 159, 159, 159, 186, 223, 200, 176, 156, 126, 94, 63, 48, 75, 100, 126, 156, 176, 179, 177, 156, 127, 127, 127, 157, 180, 223, 204, 177, 157, 127, 127, 127, 156, 177, 179, 178, 157, 144, 118, 89, 59, 31, 59, 89, 118, 144, 156, 157, 156, 144, 119, 96, 127, 157, 180, 223, 204, 177, 157, 126, 96, 119, 144, 156, 157, 157, 144, 119, 100, 75, 48, 19, 48, 75, 100, 118, 126, 126, 126, 119, 100, 95, 127, 157, 180, 223, 204, 177, 157, 126, 95, 100, 119, 126, 126, 126, 119, 100, 76, 55, 31, 5, 31, 55, 75, 89, 94, 95, 95, 89, 75, 95, 127, 157, 180, 223, 204, 177, 157, 126, 95, 75, 89, 95, 95, 95, 90, 76, 55, 31, 10, 0, 10, 31, 48, 59, 63, 63, 63, 59, 63, 95, 127, 157, 180, 223, 204, 177, 157, 126, 95, 63, 59, 63, 63, 63, 59, 48, 31, 10, 0, 0, 0, 5, 19, 28, 31, 31, 31, 31, 63, 95, 127, 157, 180, 223, 204, 177, 157, 126, 95, 63, 31, 31, 31, 31, 28, 19, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 64, 95, 127, 159, 184, 201, 196, 176, 156, 126, 94, 63, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, 60, 90, 120, 146, 159, 159, 159, 156, 144, 118, 89, 59, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 49, 76, 101, 120, 127, 128, 128, 126, 118, 100, 75, 48, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 32, 56, 76, 90, 95, 96, 96, 94, 89, 75, 55, 31, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 32, 49, 60, 64, 64, 64, 63, 59, 48, 31, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 19, 29, 32, 32, 32, 31, 28, 19, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
static constexpr const uint8_t sdfBitmap[] = {
0, 0, 0, 0, 0, 0, 0, 0, 19, 48, 76, 101, 119, 127, 127, 127, 126, 118, 100, 75, 48, 19, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 19, 28, 31, 31, 31, 31, 59, 90, 119, 145, 158, 159, 159,
156, 144, 118, 89, 59, 31, 31, 31, 31, 28, 19, 5, 0, 0, 0, 10, 31, 48, 59, 63, 63, 63, 63,
63, 95, 127, 158, 182, 187, 186, 176, 156, 126, 94, 63, 63, 63, 63, 63, 59, 48, 31, 10, 0, 5, 31,
55, 75, 89, 94, 95, 95, 95, 95, 95, 127, 158, 181, 223, 204, 177, 157, 126, 95, 95, 95, 95, 95, 95,
89, 75, 55, 31, 10, 19, 48, 75, 100, 118, 126, 126, 126, 126, 126, 126, 127, 157, 180, 223, 204, 177, 157,
126, 126, 126, 126, 126, 126, 126, 119, 100, 75, 55, 31, 28, 59, 89, 118, 144, 156, 157, 157, 157, 157, 157,
157, 157, 180, 223, 204, 177, 156, 157, 157, 157, 157, 157, 157, 156, 144, 119, 100, 75, 48, 31, 63, 94, 126,
156, 176, 178, 178, 178, 178, 178, 178, 177, 182, 223, 223, 181, 177, 178, 178, 178, 178, 178, 178, 177, 156, 144,
118, 89, 59, 32, 64, 96, 128, 159, 193, 223, 223, 223, 223, 223, 223, 223, 223, 236, 236, 223, 223, 223, 223,
223, 223, 223, 223, 196, 176, 156, 126, 94, 63, 32, 64, 96, 128, 159, 194, 223, 223, 223, 223, 223, 223, 223,
223, 236, 226, 223, 223, 223, 223, 223, 223, 223, 224, 198, 176, 156, 126, 94, 63, 32, 64, 96, 127, 159, 187,
223, 190, 176, 177, 177, 177, 177, 182, 223, 204, 179, 177, 177, 177, 177, 176, 187, 223, 198, 176, 156, 126, 94,
63, 32, 64, 95, 127, 159, 186, 223, 188, 159, 156, 156, 156, 157, 180, 223, 204, 177, 157, 156, 156, 156, 159,
186, 223, 198, 176, 156, 126, 94, 63, 32, 64, 95, 127, 159, 186, 223, 189, 159, 127, 126, 127, 157, 180, 223,
204, 177, 157, 126, 126, 127, 159, 186, 223, 198, 176, 156, 126, 94, 63, 32, 64, 95, 127, 159, 186, 223, 189,
159, 127, 127, 127, 157, 180, 223, 204, 177, 157, 127, 127, 127, 159, 186, 223, 198, 176, 156, 126, 94, 63, 32,
64, 95, 127, 159, 186, 223, 188, 159, 159, 159, 159, 159, 179, 223, 204, 177, 159, 159, 159, 159, 159, 185, 223,
198, 176, 156, 126, 94, 63, 48, 75, 100, 127, 159, 186, 223, 197, 188, 188, 188, 188, 188, 191, 223, 223, 192,
188, 188, 188, 188, 187, 199, 224, 198, 176, 156, 126, 94, 63, 59, 89, 118, 143, 159, 188, 223, 224, 223, 223,
223, 223, 223, 223, 236, 226, 223, 223, 223, 223, 223, 223, 223, 224, 198, 176, 156, 126, 94, 63, 63, 94, 126,
156, 175, 195, 223, 197, 189, 190, 190, 190, 190, 193, 223, 206, 191, 190, 190, 190, 190, 189, 196, 223, 196, 176,
156, 126, 94, 63, 59, 89, 118, 143, 159, 193, 223, 189, 159, 159, 159, 159, 159, 179, 223, 204, 177, 159, 159,
159, 159, 159, 186, 223, 200, 176, 156, 126, 94, 63, 48, 75, 100, 126, 156, 176, 179, 177, 156, 127, 127, 127,
157, 180, 223, 204, 177, 157, 127, 127, 127, 156, 177, 179, 178, 157, 144, 118, 89, 59, 31, 59, 89, 118, 144,
156, 157, 156, 144, 119, 96, 127, 157, 180, 223, 204, 177, 157, 126, 96, 119, 144, 156, 157, 157, 144, 119, 100,
75, 48, 19, 48, 75, 100, 118, 126, 126, 126, 119, 100, 95, 127, 157, 180, 223, 204, 177, 157, 126, 95, 100,
119, 126, 126, 126, 119, 100, 76, 55, 31, 5, 31, 55, 75, 89, 94, 95, 95, 89, 75, 95, 127, 157, 180,
223, 204, 177, 157, 126, 95, 75, 89, 95, 95, 95, 90, 76, 55, 31, 10, 0, 10, 31, 48, 59, 63, 63,
63, 59, 63, 95, 127, 157, 180, 223, 204, 177, 157, 126, 95, 63, 59, 63, 63, 63, 59, 48, 31, 10, 0,
0, 0, 5, 19, 28, 31, 31, 31, 31, 63, 95, 127, 157, 180, 223, 204, 177, 157, 126, 95, 63, 31, 31,
31, 31, 28, 19, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 64, 95, 127, 159, 184, 201, 196,
176, 156, 126, 94, 63, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29,
60, 90, 120, 146, 159, 159, 159, 156, 144, 118, 89, 59, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 19, 49, 76, 101, 120, 127, 128, 128, 126, 118, 100, 75, 48, 19, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 32, 56, 76, 90, 95, 96, 96, 94, 89,
75, 55, 31, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 32,
49, 60, 64, 64, 64, 63, 59, 48, 31, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 5, 19, 29, 32, 32, 32, 31, 28, 19, 5, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0};
static constexpr const size_t stubBitmapLength = 900;
@@ -26,7 +106,7 @@ public:
Glyph rasterizeGlyph(const FontStack&, GlyphID glyphID) override {
Glyph stub;
stub.id = glyphID;
stub.metrics.width = 24;
stub.metrics.height = 24;
stub.metrics.left = 0;
@@ -49,8 +129,8 @@ public:
if (glyphsError) glyphsError(fontStack, glyphRange, error);
}
std::function<void (const FontStack&, const GlyphRange&)> glyphsLoaded;
std::function<void (const FontStack&, const GlyphRange&, std::exception_ptr)> glyphsError;
std::function<void(const FontStack&, const GlyphRange&)> glyphsLoaded;
std::function<void(const FontStack&, const GlyphRange&, std::exception_ptr)> glyphsError;
};
class StubGlyphRequestor : public GlyphRequestor {
@@ -59,7 +139,7 @@ public:
if (glyphsAvailable) glyphsAvailable(std::move(glyphs));
}
std::function<void (GlyphMap)> glyphsAvailable;
std::function<void(GlyphMap)> glyphsAvailable;
};
class GlyphManagerTest {
@@ -68,7 +148,7 @@ public:
StubFileSource fileSource;
StubGlyphManagerObserver observer;
StubGlyphRequestor requestor;
GlyphManager glyphManager{ std::make_unique<StubLocalGlyphRasterizer>() };
GlyphManager glyphManager{std::make_unique<StubLocalGlyphRasterizer>()};
void run(const std::string& url, GlyphDependencies dependencies) {
// Squelch logging.
@@ -81,32 +161,30 @@ public:
loop.run();
}
void end() {
loop.stop();
}
void end() { loop.stop(); }
};
TEST(GlyphManager, LoadingSuccess) {
GlyphManagerTest test;
test.fileSource.glyphsResponse = [&] (const Resource& resource) {
test.fileSource.glyphsResponse = [&](const Resource& resource) {
EXPECT_EQ(Resource::Kind::Glyphs, resource.kind);
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/glyphs.pbf"));
return response;
};
test.observer.glyphsError = [&] (const FontStack&, const GlyphRange&, std::exception_ptr) {
test.observer.glyphsError = [&](const FontStack&, const GlyphRange&, std::exception_ptr) {
FAIL();
test.end();
};
test.observer.glyphsLoaded = [&] (const FontStack& fontStack, const GlyphRange& range) {
ASSERT_EQ(fontStack, FontStack {{"Test Stack"}});
test.observer.glyphsLoaded = [&](const FontStack& fontStack, const GlyphRange& range) {
ASSERT_EQ(fontStack, FontStack{{"Test Stack"}});
ASSERT_EQ(range, GlyphRange(0, 255));
};
test.requestor.glyphsAvailable = [&] (GlyphMap glyphs) {
test.requestor.glyphsAvailable = [&](GlyphMap glyphs) {
const auto& testPositions = glyphs.at(FontStackHasher()({{"Test Stack"}}));
ASSERT_EQ(testPositions.size(), 3u);
@@ -118,112 +196,97 @@ TEST(GlyphManager, LoadingSuccess) {
test.end();
};
test.run(
"test/fixtures/resources/glyphs.pbf",
GlyphDependencies {
{{{"Test Stack"}}, {u'a', u'å', u' '}}
});
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{"Test Stack"}}, {u'a', u'å', u' '}}});
}
TEST(GlyphManager, LoadingFail) {
GlyphManagerTest test;
test.fileSource.glyphsResponse = [&] (const Resource&) {
test.fileSource.glyphsResponse = [&](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;
};
test.observer.glyphsError = [&] (const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) {
EXPECT_EQ(fontStack, FontStack({"Test Stack"}));
EXPECT_EQ(glyphRange, GlyphRange(0, 255));
test.observer.glyphsError =
[&](const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) {
EXPECT_EQ(fontStack, FontStack({"Test Stack"}));
EXPECT_EQ(glyphRange, GlyphRange(0, 255));
EXPECT_TRUE(error != nullptr);
EXPECT_EQ(util::toString(error), "Failed by the test case");
EXPECT_TRUE(error != nullptr);
EXPECT_EQ(util::toString(error), "Failed by the test case");
test.end();
};
test.end();
};
test.requestor.glyphsAvailable = [&] (GlyphMap) {
test.requestor.glyphsAvailable = [&](GlyphMap) {
FAIL();
test.end();
};
test.run(
"test/fixtures/resources/glyphs.pbf",
GlyphDependencies {
{{{"Test Stack"}}, {u'a', u'å'}}
});
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{"Test Stack"}}, {u'a', u'å'}}});
}
TEST(GlyphManager, LoadingCorrupted) {
GlyphManagerTest test;
test.fileSource.glyphsResponse = [&] (const Resource&) {
test.fileSource.glyphsResponse = [&](const Resource&) {
Response response;
response.data = std::make_unique<std::string>("CORRUPTED");
return response;
};
test.observer.glyphsError = [&] (const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) {
EXPECT_EQ(fontStack, FontStack({"Test Stack"}));
EXPECT_EQ(glyphRange, GlyphRange(0, 255));
test.observer.glyphsError =
[&](const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) {
EXPECT_EQ(fontStack, FontStack({"Test Stack"}));
EXPECT_EQ(glyphRange, GlyphRange(0, 255));
EXPECT_TRUE(error != nullptr);
EXPECT_EQ(util::toString(error), "unknown pbf field type exception");
EXPECT_TRUE(error != nullptr);
EXPECT_EQ(util::toString(error), "unknown pbf field type exception");
test.end();
};
test.end();
};
test.requestor.glyphsAvailable = [&] (GlyphMap) {
test.requestor.glyphsAvailable = [&](GlyphMap) {
FAIL();
test.end();
};
test.run(
"test/fixtures/resources/glyphs.pbf",
GlyphDependencies {
{{{"Test Stack"}}, {u'a', u'å'}}
});
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{"Test Stack"}}, {u'a', u'å'}}});
}
TEST(GlyphManager, LoadingCancel) {
GlyphManagerTest test;
test.fileSource.glyphsResponse = [&] (const Resource&) {
test.fileSource.glyphsResponse = [&](const Resource&) {
test.end();
return std::optional<Response>();
};
test.observer.glyphsLoaded = [&] (const FontStack&, const GlyphRange&) {
test.observer.glyphsLoaded = [&](const FontStack&, const GlyphRange&) {
FAIL() << "Should never be called";
};
test.run(
"test/fixtures/resources/glyphs.pbf",
GlyphDependencies {
{{{"Test Stack"}}, {u'a', u'å'}}
});
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{"Test Stack"}}, {u'a', u'å'}}});
}
TEST(GlyphManager, LoadLocalCJKGlyph) {
GlyphManagerTest test;
int glyphResponses = 0;
test.fileSource.glyphsResponse = [&] (const Resource&) {
test.fileSource.glyphsResponse = [&](const Resource&) {
glyphResponses++;
return std::optional<Response>();
};
test.observer.glyphsLoaded = [&] (const FontStack&, const GlyphRange&) {
test.observer.glyphsLoaded = [&](const FontStack&, const GlyphRange&) {
glyphResponses++;
};
test.requestor.glyphsAvailable = [&] (GlyphMap glyphs) {
EXPECT_EQ(glyphResponses, 0); // Local generation should prevent requesting any glyphs
test.requestor.glyphsAvailable = [&](GlyphMap glyphs) {
EXPECT_EQ(glyphResponses,
0); // Local generation should prevent requesting any glyphs
const auto& testPositions = glyphs.at(FontStackHasher()({{"Test Stack"}}));
ASSERT_EQ(testPositions.size(), 1u);
@@ -246,26 +309,22 @@ TEST(GlyphManager, LoadLocalCJKGlyph) {
test.end();
};
test.run(
"test/fixtures/resources/glyphs.pbf",
GlyphDependencies {
{{{"Test Stack"}}, {u'中'}}
});
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{"Test Stack"}}, {u'中'}}});
}
TEST(GlyphManager, LoadLocalCJKGlyphAfterLoadingRangeFromURL) {
GlyphManagerTest test;
bool firstGlyphResponse = false;
test.fileSource.glyphsResponse = [&] (const Resource&) {
test.fileSource.glyphsResponse = [&](const Resource&) {
firstGlyphResponse = true;
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/glyphs-12244-12543.pbf"));
response.data = std::make_shared<std::string>(
util::read_file("test/fixtures/resources/glyphs-12244-12543.pbf"));
return response;
};
test.requestor.glyphsAvailable = [&] (GlyphMap glyphs) {
test.requestor.glyphsAvailable = [&](GlyphMap glyphs) {
const auto& testPositions = glyphs.at(FontStackHasher()({{"Test Stack"}}));
if (firstGlyphResponse == true) {
@@ -273,14 +332,14 @@ TEST(GlyphManager, LoadLocalCJKGlyphAfterLoadingRangeFromURL) {
ASSERT_EQ(testPositions.size(), 1u);
ASSERT_EQ(testPositions.count(u'々'), 1u);
//Katakana letter te, should be locally rasterized
// instead of using the glyph recieved from the range
// for the ideagraphic mark
// Katakana letter te, should be locally rasterized
// instead of using the glyph recieved from the range
// for the ideagraphic mark
test.glyphManager.getGlyphs(test.requestor,
GlyphDependencies {
{{{"Test Stack"}}, {u'テ'}} // 0x30c6
},
test.fileSource);
GlyphDependencies{
{{{"Test Stack"}}, {u'テ'}} // 0x30c6
},
test.fileSource);
} else {
ASSERT_EQ(testPositions.size(), 1u);
ASSERT_EQ(testPositions.count(u'テ'), 1u);
@@ -298,34 +357,33 @@ TEST(GlyphManager, LoadLocalCJKGlyphAfterLoadingRangeFromURL) {
}
};
test.run(
"test/fixtures/resources/glyphs-12244-12543.pbf",
GlyphDependencies {
{{{"Test Stack"}}, {u'々'}} //0x3005
});
test.run("test/fixtures/resources/glyphs-12244-12543.pbf",
GlyphDependencies{
{{{"Test Stack"}}, {u'々'}} // 0x3005
});
}
TEST(GlyphManager, LoadingInvalid) {
GlyphManagerTest test;
test.fileSource.glyphsResponse = [&] (const Resource& resource) {
test.fileSource.glyphsResponse = [&](const Resource& resource) {
EXPECT_EQ(Resource::Kind::Glyphs, resource.kind);
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/fake_glyphs-0-255.pbf"));
return response;
};
test.observer.glyphsError = [&] (const FontStack&, const GlyphRange&, std::exception_ptr) {
test.observer.glyphsError = [&](const FontStack&, const GlyphRange&, std::exception_ptr) {
FAIL();
test.end();
};
test.observer.glyphsLoaded = [&] (const FontStack& fontStack, const GlyphRange& range) {
ASSERT_EQ(fontStack, FontStack {{"Test Stack"}});
test.observer.glyphsLoaded = [&](const FontStack& fontStack, const GlyphRange& range) {
ASSERT_EQ(fontStack, FontStack{{"Test Stack"}});
ASSERT_EQ(range, GlyphRange(0, 255));
};
test.requestor.glyphsAvailable = [&] (GlyphMap glyphs) {
test.requestor.glyphsAvailable = [&](GlyphMap glyphs) {
const auto& testPositions = glyphs.at(FontStackHasher()({{"Test Stack"}}));
ASSERT_EQ(testPositions.size(), 2u);
@@ -335,18 +393,14 @@ TEST(GlyphManager, LoadingInvalid) {
test.end();
};
test.run(
"test/fixtures/resources/glyphs.pbf",
GlyphDependencies {
{{{"Test Stack"}}, {u'A', u'E'}}
});
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{"Test Stack"}}, {u'A', u'E'}}});
}
TEST(GlyphManager, ImmediateFileSource) {
class GlyphManagerTestSynchronous {
public:
util::RunLoop loop;
StubFileSource fileSource = { StubFileSource::ResponseType::Synchronous };
StubFileSource fileSource = {StubFileSource::ResponseType::Synchronous};
StubGlyphManagerObserver observer;
StubGlyphRequestor requestor;
GlyphManager glyphManager;
@@ -362,31 +416,25 @@ TEST(GlyphManager, ImmediateFileSource) {
loop.run();
}
void end() {
loop.stop();
}
void end() { loop.stop(); }
};
GlyphManagerTestSynchronous test;
test.fileSource.glyphsResponse = [&] (const Resource&) {
test.fileSource.glyphsResponse = [&](const Resource&) {
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/glyphs.pbf"));
return response;
};
test.observer.glyphsError = [&] (const FontStack&, const GlyphRange&, std::exception_ptr) {
test.observer.glyphsError = [&](const FontStack&, const GlyphRange&, std::exception_ptr) {
FAIL();
test.end();
};
test.requestor.glyphsAvailable = [&] (GlyphMap) {
test.requestor.glyphsAvailable = [&](GlyphMap) {
test.end();
};
test.run(
"test/fixtures/resources/glyphs.pbf",
GlyphDependencies {
{{{"Test Stack"}}, {u'a', u'å', u' '}}
});
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{"Test Stack"}}, {u'a', u'å', u' '}}});
}

View File

@@ -7,7 +7,7 @@ using namespace mbgl;
TEST(GlyphPBF, Parsing) {
// The fake glyphs contain a number of invalid glyphs, which should be skipped by the parser.
auto sdfs = parseGlyphPBF(GlyphRange { 0, 255 }, util::read_file("test/fixtures/resources/fake_glyphs-0-255.pbf"));
auto sdfs = parseGlyphPBF(GlyphRange{0, 255}, util::read_file("test/fixtures/resources/fake_glyphs-0-255.pbf"));
EXPECT_TRUE(sdfs.size() == 1);
auto& sdf = sdfs[0];

View File

@@ -9,17 +9,17 @@ TEST(LanguageTag, Parsing) {
EXPECT_EQ(*(bareLanguage.language), "de");
EXPECT_FALSE(bareLanguage.script);
EXPECT_FALSE(bareLanguage.region);
LanguageTag languageAndScript = LanguageTag::fromBCP47("de-hans");
EXPECT_EQ(*(languageAndScript.language), "de");
EXPECT_EQ(*(languageAndScript.script), "hans");
EXPECT_FALSE(languageAndScript.region);
LanguageTag languageAndRegion = LanguageTag::fromBCP47("de-US");
EXPECT_EQ(*(languageAndRegion.language), "de");
EXPECT_FALSE(languageAndRegion.script);
EXPECT_EQ(*(languageAndRegion.region), "US");
LanguageTag kitchenSink = LanguageTag::fromBCP47("de-ext-two-Hans-US-variant-x-private");
EXPECT_EQ(*(kitchenSink.language), "de");
EXPECT_EQ(*(kitchenSink.script), "Hans");
@@ -29,17 +29,16 @@ TEST(LanguageTag, Parsing) {
TEST(LanguageTag, Generation) {
LanguageTag deHansUS({"de"}, {"hans"}, {"US"});
EXPECT_EQ(deHansUS.toBCP47(), "de-hans-US");
LanguageTag deUS({"de"}, {}, {"US"});
EXPECT_EQ(deUS.toBCP47(), "de-US");
LanguageTag noLanguage({}, {"hans"}, {"US"});
EXPECT_EQ(noLanguage.toBCP47(), "");
LanguageTag deHans({"de"}, {"hans"}, {});
EXPECT_EQ(deHans.toBCP47(), "de-hans");
LanguageTag de({"de"}, {}, {});
EXPECT_EQ(de.toBCP47(), "de");
}

View File

@@ -11,19 +11,19 @@
#include <mbgl/style/style.hpp>
/*
LoadLocalCJKGlyph in glyph_manager.test.cpp exercises the platform-independent
part of LocalGlyphRasterizer. This test actually exercises platform-dependent
font loading code for whatever platform it runs on. Different platforms have
different default fonts, so adding a new platform requires new "expected"
fixtures.
At the time of writing, we don't run `mbgl-test` on iOS or Android, so the only
supported test platform is macOS. Supporting Android would require adding a new
test case (probably using the "Droid" font family). iOS should theoretically
work -- the "PingFang" font family used below is expected to be available on
all iOS devices, and we use a relatively high image diff tolerance (0.05) to
account for small changes between the many possible variants of the PingFang
family.
LoadLocalCJKGlyph in glyph_manager.test.cpp exercises the
platform-independent part of LocalGlyphRasterizer. This test actually
exercises platform-dependent font loading code for whatever platform it runs
on. Different platforms have different default fonts, so adding a new
platform requires new "expected" fixtures.
At the time of writing, we don't run `mbgl-test` on iOS or Android, so the
only supported test platform is macOS. Supporting Android would require
adding a new test case (probably using the "Droid" font family). iOS should
theoretically work -- the "PingFang" font family used below is expected to be
available on all iOS devices, and we use a relatively high image diff
tolerance (0.05) to account for small changes between the many possible
variants of the PingFang family.
*/
using namespace mbgl;
@@ -38,10 +38,12 @@ public:
util::RunLoop loop;
std::shared_ptr<StubFileSource> fileSource = std::make_shared<StubFileSource>();
HeadlessFrontend frontend;
MapAdapter map { frontend, MapObserver::nullObserver(), fileSource,
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize())};
MapAdapter map{frontend,
MapObserver::nullObserver(),
fileSource,
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize())};
void checkRendering(const char * name, double imageMatchPixelsThreshold = 0.015, double pixelMatchThreshold = 0.1) {
void checkRendering(const char* name, double imageMatchPixelsThreshold = 0.015, double pixelMatchThreshold = 0.1) {
test::checkImage(std::string("test/fixtures/local_glyphs/") + name,
frontend.render(map).image,
imageMatchPixelsThreshold,
@@ -57,7 +59,7 @@ public:
TEST(LocalGlyphRasterizer, PingFang) {
LocalGlyphRasterizerTest test(std::string("PingFang TC"));
test.fileSource->glyphsResponse = [&] (const Resource& resource) {
test.fileSource->glyphsResponse = [&](const Resource& resource) {
EXPECT_EQ(Resource::Kind::Glyphs, resource.kind);
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/glyphs.pbf"));
@@ -92,7 +94,7 @@ TEST(LocalGlyphRasterizer, PingFangSemibold) {
TEST(LocalGlyphRasterizer, NotoSansCJK) {
LocalGlyphRasterizerTest test(std::string("Noto Sans CJK KR Regular"));
test.fileSource->glyphsResponse = [&] (const Resource& resource) {
test.fileSource->glyphsResponse = [&](const Resource& resource) {
EXPECT_EQ(Resource::Kind::Glyphs, resource.kind);
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/glyphs.pbf"));
@@ -105,11 +107,11 @@ TEST(LocalGlyphRasterizer, NotoSansCJK) {
#endif // defined(__linux__) && defined(__QT__)
TEST(LocalGlyphRasterizer, NoLocal) {
// Expectation: without any local fonts set, and without any CJK glyphs provided,
// the output should just contain basic latin characters.
// Expectation: without any local fonts set, and without any CJK glyphs
// provided, the output should just contain basic latin characters.
LocalGlyphRasterizerTest test({});
test.fileSource->glyphsResponse = [&] (const Resource& resource) {
test.fileSource->glyphsResponse = [&](const Resource& resource) {
EXPECT_EQ(Resource::Kind::Glyphs, resource.kind);
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/glyphs.pbf"));
@@ -120,12 +122,12 @@ TEST(LocalGlyphRasterizer, NoLocal) {
}
TEST(LocalGlyphRasterizer, NoLocalWithContentInsets) {
// Expectations: content insets imply rendering to offsetted viewport center.
// Rendered text should be on the same offset and keep the same size as
// with no offset.
// Expectations: content insets imply rendering to offsetted viewport
// center. Rendered text should be on the same offset and keep the same size
// as with no offset.
LocalGlyphRasterizerTest test({});
test.fileSource->glyphsResponse = [&] (const Resource& resource) {
test.fileSource->glyphsResponse = [&](const Resource& resource) {
EXPECT_EQ(Resource::Kind::Glyphs, resource.kind);
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/glyphs.pbf"));
@@ -138,17 +140,17 @@ TEST(LocalGlyphRasterizer, NoLocalWithContentInsets) {
// with no pitch defined, should produce the same output.
// test.map.moveBy({ viewSize.width * 0.25, 0 });
test.map.jumpTo(CameraOptions().withPadding(EdgeInsets { 0, viewSize.width * 0.25 * 2, 0, 0 }));
test.map.jumpTo(CameraOptions().withPadding(EdgeInsets{0, viewSize.width * 0.25 * 2, 0, 0}));
test.checkRendering("no_local_with_content_insets", 0.001, 0.1);
}
TEST(LocalGlyphRasterizer, NoLocalWithContentInsetsAndPitch) {
// Expectations: content insets imply rendering to offsetted viewport center.
// Rendered text should be on the same offset and keep the same size as
// with no offset.
// Expectations: content insets imply rendering to offsetted viewport
// center. Rendered text should be on the same offset and keep the same size
// as with no offset.
LocalGlyphRasterizerTest test({});
test.fileSource->glyphsResponse = [&] (const Resource& resource) {
test.fileSource->glyphsResponse = [&](const Resource& resource) {
EXPECT_EQ(Resource::Kind::Glyphs, resource.kind);
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/glyphs.pbf"));
@@ -160,6 +162,6 @@ TEST(LocalGlyphRasterizer, NoLocalWithContentInsetsAndPitch) {
// Expected image was verified using no-padding render, offsetted to right
// using bitmap editor.
test.map.jumpTo(CameraOptions().withPitch(45).withPadding(EdgeInsets { 0, viewSize.width * 0.4, 0, 0 }));
test.map.jumpTo(CameraOptions().withPitch(45).withPadding(EdgeInsets{0, viewSize.width * 0.4, 0, 0}));
test.checkRendering("no_local_with_content_insets_and_pitch", 0.001, 0.1);
}

View File

@@ -13,10 +13,8 @@ using namespace mbgl::style;
TEST(getIconQuads, normal) {
SymbolLayoutProperties::Evaluated layout;
Anchor anchor(2.0, 3.0, 0.0, 0);
ImagePosition image = {
mapbox::Bin(-1, 15, 11, 0, 0, 0, 0),
style::Image::Impl("test", PremultipliedImage({1,1}), 1.0f)
};
ImagePosition image = {mapbox::Bin(-1, 15, 11, 0, 0, 0, 0),
style::Image::Impl("test", PremultipliedImage({1, 1}), 1.0f)};
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-6.5f, -4.5f}}, SymbolAnchorType::Center);
@@ -49,8 +47,15 @@ TEST(getIconQuads, style) {
shapedText.right = 20.0f;
// shapedText.positionedGlyphs.emplace_back(PositionedGlyph(32, 0.0f, 0.0f, false, 0, 1.0));
shapedText.positionedLines.emplace_back();
shapedText.positionedLines.back().positionedGlyphs.emplace_back(
PositionedGlyph(32, 0.0f, 0.0f, false, 0, 1.0, /*texRect*/ {}, /*metrics*/ {}, /*imageID*/ std::nullopt));
shapedText.positionedLines.back().positionedGlyphs.emplace_back(PositionedGlyph(32,
0.0f,
0.0f,
false,
0,
1.0,
/*texRect*/ {},
/*metrics*/ {},
/*imageID*/ std::nullopt));
// none
{

View File

@@ -27,9 +27,7 @@ TEST(Shaping, ZWSP) {
const SectionOptions sectionOptions(1.0f, fontStack);
const float layoutTextSize = 16.0f;
const float layoutTextSizeAtBucketZoomLevel = 16.0f;
GlyphMap glyphs = {
{ FontStackHasher()(fontStack), {{u'中', std::move(immutableGlyph)}} }
};
GlyphMap glyphs = {{FontStackHasher()(fontStack), {{u'中', std::move(immutableGlyph)}}}};
GlyphPositions glyphPositions = {{FontStackHasher()(fontStack), {{u'中', std::move(glyphPosition)}}}};
ImagePositions imagePositions;

View File

@@ -9,18 +9,18 @@ TEST(TaggedString, Trim) {
TaggedString basic(u" \t\ntrim that and not this \n\t", SectionOptions(1.0f, {}));
basic.trim();
EXPECT_EQ(basic.rawText(), u"trim that and not this");
TaggedString twoSections;
twoSections.addTextSection(u" \t\ntrim that", 1.5f, {});
twoSections.addTextSection(u" and not this \n\t", 0.5f, {});
twoSections.trim();
EXPECT_EQ(twoSections.rawText(), u"trim that and not this");
TaggedString empty(u"\n\t\v \r \t\n", SectionOptions(1.0f, {}));
empty.trim();
EXPECT_EQ(empty.rawText(), u"");
TaggedString noTrim(u"no trim!", SectionOptions(1.0f, {}));
noTrim.trim();
EXPECT_EQ(noTrim.rawText(), u"no trim!");