summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/api/annotations.cpp32
-rw-r--r--test/api/repeated_render.cpp4
-rw-r--r--test/fixtures/annotations/assets.zipbin0 -> 481374 bytes
-rw-r--r--test/fixtures/api/assets.zipbin0 -> 328264 bytes
-rw-r--r--test/storage/directory_reading.cpp2
-rw-r--r--test/storage/file_reading.cpp105
6 files changed, 116 insertions, 27 deletions
diff --git a/test/api/annotations.cpp b/test/api/annotations.cpp
index 4c06b39e43..7514fc2dcc 100644
--- a/test/api/annotations.cpp
+++ b/test/api/annotations.cpp
@@ -14,6 +14,18 @@
using namespace mbgl;
+namespace {
+
+std::string getFileSourceRoot() {
+#ifdef MBGL_ASSET_ZIP
+ return "test/fixtures/annotations/assets.zip";
+#else
+ return "";
+#endif
+}
+
+}
+
std::shared_ptr<SpriteImage> defaultMarker() {
PremultipliedImage image = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
return std::make_shared<SpriteImage>(image.width, image.height, 1.0, std::string(reinterpret_cast<char*>(image.data.get()), image.size()));
@@ -36,7 +48,7 @@ void checkRendering(Map& map, const char * name) {
TEST(Annotations, PointAnnotation) {
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
- DefaultFileSource fileSource(nullptr);
+ DefaultFileSource fileSource(nullptr, getFileSourceRoot());
Map map(view, fileSource, MapMode::Still);
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
@@ -49,7 +61,7 @@ TEST(Annotations, PointAnnotation) {
TEST(Annotations, LineAnnotation) {
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
- DefaultFileSource fileSource(nullptr);
+ DefaultFileSource fileSource(nullptr, getFileSourceRoot());
Map map(view, fileSource, MapMode::Still);
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
@@ -68,7 +80,7 @@ TEST(Annotations, LineAnnotation) {
TEST(Annotations, FillAnnotation) {
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
- DefaultFileSource fileSource(nullptr);
+ DefaultFileSource fileSource(nullptr, getFileSourceRoot());
Map map(view, fileSource, MapMode::Still);
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
@@ -86,7 +98,7 @@ TEST(Annotations, FillAnnotation) {
TEST(Annotations, StyleSourcedShapeAnnotation) {
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
- DefaultFileSource fileSource(nullptr);
+ DefaultFileSource fileSource(nullptr, getFileSourceRoot());
Map map(view, fileSource, MapMode::Still);
map.setStyleJSON(util::read_file("test/fixtures/api/annotation.json"), "");
@@ -101,7 +113,7 @@ TEST(Annotations, StyleSourcedShapeAnnotation) {
TEST(Annotations, AddMultiple) {
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
- DefaultFileSource fileSource(nullptr);
+ DefaultFileSource fileSource(nullptr, getFileSourceRoot());
Map map(view, fileSource, MapMode::Still);
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
@@ -118,7 +130,7 @@ TEST(Annotations, AddMultiple) {
TEST(Annotations, NonImmediateAdd) {
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
- DefaultFileSource fileSource(nullptr);
+ DefaultFileSource fileSource(nullptr, getFileSourceRoot());
Map map(view, fileSource, MapMode::Still);
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
@@ -138,7 +150,7 @@ TEST(Annotations, NonImmediateAdd) {
TEST(Annotations, RemovePoint) {
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
- DefaultFileSource fileSource(nullptr);
+ DefaultFileSource fileSource(nullptr, getFileSourceRoot());
Map map(view, fileSource, MapMode::Still);
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
@@ -155,7 +167,7 @@ TEST(Annotations, RemovePoint) {
TEST(Annotations, RemoveShape) {
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
- DefaultFileSource fileSource(nullptr);
+ DefaultFileSource fileSource(nullptr, getFileSourceRoot());
AnnotationSegments segments = {{ {{ { 0, 0 }, { 45, 45 } }} }};
@@ -177,7 +189,7 @@ TEST(Annotations, RemoveShape) {
TEST(Annotations, ImmediateRemoveShape) {
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
- DefaultFileSource fileSource(nullptr);
+ DefaultFileSource fileSource(nullptr, getFileSourceRoot());
Map map(view, fileSource, MapMode::Still);
map.removeAnnotation(map.addShapeAnnotation(ShapeAnnotation({}, {})));
@@ -189,7 +201,7 @@ TEST(Annotations, ImmediateRemoveShape) {
TEST(Annotations, SwitchStyle) {
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
- DefaultFileSource fileSource(nullptr);
+ DefaultFileSource fileSource(nullptr, getFileSourceRoot());
Map map(view, fileSource, MapMode::Still);
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
diff --git a/test/api/repeated_render.cpp b/test/api/repeated_render.cpp
index 77e4569dbf..d92dcf2909 100644
--- a/test/api/repeated_render.cpp
+++ b/test/api/repeated_render.cpp
@@ -17,7 +17,11 @@ TEST(API, RepeatedRender) {
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1, 256, 512);
+#ifdef MBGL_ASSET_ZIP
+ DefaultFileSource fileSource(nullptr, "test/fixtures/api/assets.zip");
+#else
DefaultFileSource fileSource(nullptr);
+#endif
Log::setObserver(std::make_unique<FixtureLogObserver>());
diff --git a/test/fixtures/annotations/assets.zip b/test/fixtures/annotations/assets.zip
new file mode 100644
index 0000000000..869380034f
--- /dev/null
+++ b/test/fixtures/annotations/assets.zip
Binary files differ
diff --git a/test/fixtures/api/assets.zip b/test/fixtures/api/assets.zip
new file mode 100644
index 0000000000..42a30f1c2a
--- /dev/null
+++ b/test/fixtures/api/assets.zip
Binary files differ
diff --git a/test/storage/directory_reading.cpp b/test/storage/directory_reading.cpp
index 72aabe2eb3..5ef2983abf 100644
--- a/test/storage/directory_reading.cpp
+++ b/test/storage/directory_reading.cpp
@@ -27,7 +27,7 @@ TEST_F(Storage, AssetReadDirectory) {
EXPECT_EQ(Seconds::zero(), res.modified);
EXPECT_EQ("", res.etag);
#ifdef MBGL_ASSET_ZIP
- EXPECT_EQ("No such file", res.error->message);
+ EXPECT_EQ("Could not stat file in zip archive", res.error->message);
#elif MBGL_ASSET_FS
EXPECT_EQ("Is a directory", res.error->message);
#endif
diff --git a/test/storage/file_reading.cpp b/test/storage/file_reading.cpp
index 8d38303096..1b1b1b2888 100644
--- a/test/storage/file_reading.cpp
+++ b/test/storage/file_reading.cpp
@@ -4,6 +4,91 @@
#include <mbgl/platform/platform.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
+#include <mbgl/util/thread.hpp>
+
+namespace {
+
+std::string getFileSourceRoot() {
+#ifdef MBGL_ASSET_ZIP
+ return "test/fixtures/storage/assets.zip";
+#else
+ return "";
+#endif
+}
+
+class TestWorker {
+public:
+ TestWorker(mbgl::DefaultFileSource* fs_) : fs(fs_) {}
+
+ void run(std::function<void()> endCallback) {
+ const std::string asset("asset://TEST_DATA/fixtures/storage/nonempty");
+
+ requestCallback = [this, asset, endCallback](mbgl::Response res) {
+ EXPECT_EQ(nullptr, res.error);
+ ASSERT_TRUE(res.data.get());
+ EXPECT_EQ("content is here\n", *res.data);
+
+ if (res.stale) {
+ return;
+ }
+
+ if (!--numRequests) {
+ endCallback();
+ request.reset();
+ } else {
+ request = fs->request({ mbgl::Resource::Unknown, asset }, requestCallback);
+ }
+ };
+
+ request = fs->request({ mbgl::Resource::Unknown, asset }, requestCallback);
+ }
+
+private:
+ unsigned numRequests = 1000;
+
+ mbgl::DefaultFileSource* fs;
+ std::unique_ptr<mbgl::FileRequest> request;
+
+ std::function<void(mbgl::Response)> requestCallback;
+};
+
+}
+
+TEST_F(Storage, AssetStress) {
+ SCOPED_TEST(AssetStress)
+
+ using namespace mbgl;
+
+ util::RunLoop loop;
+
+ mbgl::DefaultFileSource fs(nullptr, getFileSourceRoot());
+
+ unsigned numThreads = 50;
+
+ auto callback = [&] {
+ if (!--numThreads) {
+ loop.stop();
+ }
+ };
+
+ std::vector<std::unique_ptr<util::Thread<TestWorker>>> threads;
+ std::vector<std::unique_ptr<mbgl::WorkRequest>> requests;
+ util::ThreadContext context = { "Test", util::ThreadType::Map, util::ThreadPriority::Regular };
+
+ for (unsigned i = 0; i < numThreads; ++i) {
+ std::unique_ptr<util::Thread<TestWorker>> thread =
+ std::make_unique<util::Thread<TestWorker>>(context, &fs);
+
+ requests.push_back(
+ thread->invokeWithCallback(&TestWorker::run, callback));
+
+ threads.push_back(std::move(thread));
+ }
+
+ loop.run();
+
+ AssetStress.finish();
+}
TEST_F(Storage, AssetEmptyFile) {
SCOPED_TEST(EmptyFile)
@@ -12,11 +97,7 @@ TEST_F(Storage, AssetEmptyFile) {
util::RunLoop loop;
-#ifdef MBGL_ASSET_ZIP
- DefaultFileSource fs(nullptr, "test/fixtures/storage/assets.zip");
-#else
- DefaultFileSource fs(nullptr);
-#endif
+ DefaultFileSource fs(nullptr, getFileSourceRoot());
std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/empty" }, [&](Response res) {
req.reset();
@@ -41,11 +122,7 @@ TEST_F(Storage, AssetNonEmptyFile) {
util::RunLoop loop;
-#ifdef MBGL_ASSET_ZIP
- DefaultFileSource fs(nullptr, "test/fixtures/storage/assets.zip");
-#else
- DefaultFileSource fs(nullptr);
-#endif
+ DefaultFileSource fs(nullptr, getFileSourceRoot());
std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/nonempty" }, [&](Response res) {
req.reset();
@@ -72,11 +149,7 @@ TEST_F(Storage, AssetNonExistentFile) {
util::RunLoop loop;
-#ifdef MBGL_ASSET_ZIP
- DefaultFileSource fs(nullptr, "test/fixtures/storage/assets.zip");
-#else
- DefaultFileSource fs(nullptr);
-#endif
+ DefaultFileSource fs(nullptr, getFileSourceRoot());
std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/does_not_exist" }, [&](Response res) {
req.reset();
@@ -88,7 +161,7 @@ TEST_F(Storage, AssetNonExistentFile) {
EXPECT_EQ(Seconds::zero(), res.modified);
EXPECT_EQ("", res.etag);
#ifdef MBGL_ASSET_ZIP
- EXPECT_EQ("No such file", res.error->message);
+ EXPECT_EQ("Could not stat file in zip archive", res.error->message);
#elif MBGL_ASSET_FS
EXPECT_EQ("No such file or directory", res.error->message);
#endif