summaryrefslogtreecommitdiff
path: root/test/style/glyph_store.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/style/glyph_store.cpp')
-rw-r--r--test/style/glyph_store.cpp81
1 files changed, 44 insertions, 37 deletions
diff --git a/test/style/glyph_store.cpp b/test/style/glyph_store.cpp
index 0215dff3ff..a4bc0e3135 100644
--- a/test/style/glyph_store.cpp
+++ b/test/style/glyph_store.cpp
@@ -1,22 +1,21 @@
#include "../fixtures/util.hpp"
-#include "../fixtures/mock_file_source.hpp"
+#include "../fixtures/stub_file_source.hpp"
#include "../fixtures/stub_style_observer.hpp"
#include <mbgl/text/font_stack.hpp>
#include <mbgl/text/glyph_store.hpp>
#include <mbgl/util/run_loop.hpp>
+#include <mbgl/util/string.hpp>
+#include <mbgl/util/io.hpp>
#include <mbgl/platform/log.hpp>
using namespace mbgl;
class GlyphStoreTest {
public:
- GlyphStoreTest(MockFileSource::Type type, const std::string& resource)
- : fileSource(type, resource) {}
-
util::ThreadContext context { "Map", util::ThreadType::Map, util::ThreadPriority::Regular };
util::RunLoop loop;
- MockFileSource fileSource;
+ StubFileSource fileSource;
StubStyleObserver observer;
GlyphStore glyphStore;
@@ -40,7 +39,14 @@ public:
};
TEST(GlyphStore, LoadingSuccess) {
- GlyphStoreTest test(MockFileSource::Success, "");
+ GlyphStoreTest test;
+
+ 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 std::string&, const GlyphRange&, std::exception_ptr) {
FAIL();
@@ -64,12 +70,22 @@ TEST(GlyphStore, LoadingSuccess) {
}
TEST(GlyphStore, LoadingFail) {
- GlyphStoreTest test(MockFileSource::RequestFail, "glyphs.pbf");
+ GlyphStoreTest test;
+
+ test.fileSource.glyphsResponse = [&] (const Resource&) {
+ Response response;
+ response.error = std::make_unique<Response::Error>(
+ Response::Error::Reason::Other,
+ "Failed by the test case");
+ return response;
+ };
test.observer.glyphsError = [&] (const std::string& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) {
- ASSERT_TRUE(error != nullptr);
- ASSERT_EQ(fontStack, "Test Stack");
- ASSERT_EQ(glyphRange, GlyphRange(0, 255));
+ EXPECT_EQ(fontStack, "Test Stack");
+ EXPECT_EQ(glyphRange, GlyphRange(0, 255));
+
+ EXPECT_TRUE(error != nullptr);
+ EXPECT_EQ(util::toString(error), "Failed by the test case");
auto stack = test.glyphStore.getFontStack("Test Stack");
ASSERT_TRUE(stack->getSDFs().empty());
@@ -85,12 +101,20 @@ TEST(GlyphStore, LoadingFail) {
}
TEST(GlyphStore, LoadingCorrupted) {
- GlyphStoreTest test(MockFileSource::RequestWithCorruptedData, "glyphs.pbf");
+ GlyphStoreTest test;
+
+ test.fileSource.glyphsResponse = [&] (const Resource&) {
+ Response response;
+ response.data = std::make_unique<std::string>("CORRUPTED");
+ return response;
+ };
test.observer.glyphsError = [&] (const std::string& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) {
- ASSERT_TRUE(error != nullptr);
- ASSERT_EQ(fontStack, "Test Stack");
- ASSERT_EQ(glyphRange, GlyphRange(0, 255));
+ EXPECT_EQ(fontStack, "Test Stack");
+ EXPECT_EQ(glyphRange, GlyphRange(0, 255));
+
+ EXPECT_TRUE(error != nullptr);
+ EXPECT_EQ(util::toString(error), "pbf unknown field type exception");
auto stack = test.glyphStore.getFontStack("Test Stack");
ASSERT_TRUE(stack->getSDFs().empty());
@@ -106,36 +130,19 @@ TEST(GlyphStore, LoadingCorrupted) {
}
TEST(GlyphStore, LoadingCancel) {
- GlyphStoreTest test(MockFileSource::Success, "glyphs.pbf");
+ GlyphStoreTest test;
- test.observer.glyphsLoaded = [&] (const std::string&, const GlyphRange&) {
- FAIL() << "Should never be called";
- };
-
- test.fileSource.requestEnqueuedCallback = [&]{
+ test.fileSource.glyphsResponse = [&] (const Resource&) {
test.end();
+ return Response();
};
- test.run(
- "test/fixtures/resources/glyphs.pbf",
- "Test Stack",
- {{0, 255}});
-}
-
-TEST(GlyphStore, InvalidURL) {
- GlyphStoreTest test(MockFileSource::Success, "");
-
- test.observer.glyphsError = [&] (const std::string&, const GlyphRange&, std::exception_ptr error) {
- ASSERT_TRUE(error != nullptr);
-
- auto stack = test.glyphStore.getFontStack("Test Stack");
- ASSERT_TRUE(stack->getSDFs().empty());
-
- test.end();
+ test.observer.glyphsLoaded = [&] (const std::string&, const GlyphRange&) {
+ FAIL() << "Should never be called";
};
test.run(
- "foo bar",
+ "test/fixtures/resources/glyphs.pbf",
"Test Stack",
{{0, 255}});
}