summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2018-02-20 15:06:26 +0100
committerKonstantin Käfer <mail@kkaefer.com>2018-02-21 14:50:13 +0100
commit021e1ae596440cfdee5ffe75907b76069ae44307 (patch)
treeebf15ff8a72e5f14291ba37b6f297ca9a738eea4 /test
parent06213d9145d3b20b63e235cc25678fd76dc296d0 (diff)
downloadqtlocation-mapboxgl-021e1ae596440cfdee5ffe75907b76069ae44307.tar.gz
[core] introduce Blob for compressed and uncompressed dataupstream/blob
- Blob is a wrapper type for a shared_ptr<const string> that has accessor functions for getting compressed and uncompressed data - Moved util::writeFile, util::readFile, util::compress, util::uncompress, decodeImage, and encodePNG to the Blob interface - Added Blob support to Request and file sources - Added Blob support to VectorTile objects - Added support for gzip decoding to util::uncompress - We're no longer compressing WebP, PNG, and JPEG data when storing in the OfflineDatabase - Android's HTTPRequest returns compressed Blobs by default One caveat is that our previous decompress function didn't support gzip, so once users upgrade to this version, their offline cache may contain both zlib-compressed data and gzip-compressed data, but older versions won't be able to decompress gzip data. On the other hand, we don't support downgrading SDKs anyway, so this shouldn't be a problem. To be on the safe side, we could bump the user_version of the SQLite DB.
Diffstat (limited to 'test')
-rw-r--r--test/api/annotations.test.cpp54
-rw-r--r--test/api/custom_geometry_source.test.cpp2
-rw-r--r--test/api/custom_layer.test.cpp2
-rw-r--r--test/api/query.test.cpp4
-rw-r--r--test/api/recycle_map.cpp4
-rw-r--r--test/api/zoom_history.cpp2
-rw-r--r--test/gl/context.test.cpp2
-rw-r--r--test/map/map.test.cpp54
-rw-r--r--test/map/prefetch.test.cpp10
-rw-r--r--test/programs/binary_program.test.cpp2
-rw-r--r--test/renderer/image_manager.test.cpp4
-rw-r--r--test/sprite/sprite_loader.test.cpp6
-rw-r--r--test/sprite/sprite_parser.test.cpp38
-rw-r--r--test/src/mbgl/test/util.cpp12
-rw-r--r--test/storage/asset_file_source.test.cpp22
-rw-r--r--test/storage/default_file_source.test.cpp100
-rw-r--r--test/storage/http_file_source.test.cpp27
-rw-r--r--test/storage/local_file_source.test.cpp20
-rw-r--r--test/storage/offline_database.test.cpp62
-rw-r--r--test/storage/offline_download.test.cpp10
-rw-r--r--test/storage/online_file_source.test.cpp28
-rw-r--r--test/style/expression/expression.test.cpp6
-rw-r--r--test/style/source.test.cpp26
-rw-r--r--test/style/style.test.cpp16
-rw-r--r--test/style/style_layer.test.cpp2
-rw-r--r--test/style/style_parser.test.cpp8
-rw-r--r--test/text/glyph_manager.test.cpp8
-rw-r--r--test/text/glyph_pbf.test.cpp2
-rw-r--r--test/text/local_glyph_rasterizer.test.cpp8
-rw-r--r--test/util/image.test.cpp14
-rw-r--r--test/util/memory.test.cpp6
31 files changed, 281 insertions, 280 deletions
diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp
index 07257851ac..8b25fa482d 100644
--- a/test/api/annotations.test.cpp
+++ b/test/api/annotations.test.cpp
@@ -17,7 +17,7 @@ using namespace mbgl;
namespace {
PremultipliedImage namedImage(const std::string& name) {
- return decodeImage(util::read_file("test/fixtures/sprites/" + name + ".png"));
+ return decodeImage(util::readFile("test/fixtures/sprites/" + name + ".png"));
}
std::unique_ptr<style::Image> namedMarker(const std::string& name) {
@@ -45,7 +45,7 @@ public:
TEST(Annotations, SymbolAnnotation) {
AnnotationTest test;
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double>(0, 0), "default_marker" });
test.checkRendering("point_annotation");
@@ -67,7 +67,7 @@ TEST(Annotations, LineAnnotation) {
annotation.color = Color::red();
annotation.width = { 5 };
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.addAnnotation(annotation);
test.checkRendering("line_annotation");
@@ -82,7 +82,7 @@ TEST(Annotations, FillAnnotation) {
FillAnnotation annotation { polygon };
annotation.color = Color::red();
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.addAnnotation(annotation);
test.checkRendering("fill_annotation");
@@ -95,7 +95,7 @@ TEST(Annotations, AntimeridianAnnotationSmall) {
double antimeridian = 180;
test.map.setLatLngZoom(mbgl::LatLng(0, antimeridian), 0);
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
LineString<double> line = {{ { antimeridian, 20 }, { antimeridian, -20 } }};
LineAnnotation lineAnnotation { line };
@@ -116,7 +116,7 @@ TEST(Annotations, AntimeridianAnnotationLarge) {
double antimeridian = 180;
test.map.setLatLngZoom(mbgl::LatLng(0, antimeridian), 0);
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
LineString<double> line = {{ { antimeridian, 20 }, { antimeridian, -20 } }};
LineAnnotation lineAnnotation { line };
@@ -141,7 +141,7 @@ TEST(Annotations, OverlappingFillAnnotation) {
FillAnnotation overlaidAnnotation { polygon };
overlaidAnnotation.color = Color::red();
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.addAnnotation(underlaidAnnotation);
test.map.addAnnotation(overlaidAnnotation);
test.checkRendering("overlapping_fill_annotation");
@@ -150,7 +150,7 @@ TEST(Annotations, OverlappingFillAnnotation) {
TEST(Annotations, AddMultiple) {
AnnotationTest test;
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double> { -10, 0 }, "default_marker" });
@@ -163,7 +163,7 @@ TEST(Annotations, AddMultiple) {
TEST(Annotations, NonImmediateAdd) {
AnnotationTest test;
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.frontend.render(test.map);
Polygon<double> polygon = { {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} };
@@ -177,7 +177,7 @@ TEST(Annotations, NonImmediateAdd) {
TEST(Annotations, UpdateSymbolAnnotationGeometry) {
AnnotationTest test;
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotationImage(namedMarker("flipped_marker"));
AnnotationID point = test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
@@ -191,7 +191,7 @@ TEST(Annotations, UpdateSymbolAnnotationGeometry) {
TEST(Annotations, UpdateSymbolAnnotationIcon) {
AnnotationTest test;
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotationImage(namedMarker("flipped_marker"));
AnnotationID point = test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
@@ -209,7 +209,7 @@ TEST(Annotations, UpdateLineAnnotationGeometry) {
annotation.color = Color::red();
annotation.width = { 5 };
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
AnnotationID line = test.map.addAnnotation(annotation);
test.frontend.render(test.map);
@@ -226,7 +226,7 @@ TEST(Annotations, UpdateLineAnnotationStyle) {
annotation.color = Color::red();
annotation.width = { 5 };
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
AnnotationID line = test.map.addAnnotation(annotation);
test.frontend.render(test.map);
@@ -243,7 +243,7 @@ TEST(Annotations, UpdateFillAnnotationGeometry) {
FillAnnotation annotation { Polygon<double> { {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} } };
annotation.color = Color::red();
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
AnnotationID fill = test.map.addAnnotation(annotation);
test.frontend.render(test.map);
@@ -260,7 +260,7 @@ TEST(Annotations, UpdateFillAnnotationStyle) {
FillAnnotation annotation { polygon };
annotation.color = Color::red();
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
AnnotationID fill = test.map.addAnnotation(annotation);
test.frontend.render(test.map);
@@ -273,7 +273,7 @@ TEST(Annotations, UpdateFillAnnotationStyle) {
TEST(Annotations, RemovePoint) {
AnnotationTest test;
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
AnnotationID point = test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
@@ -291,7 +291,7 @@ TEST(Annotations, RemoveShape) {
annotation.color = Color::red();
annotation.width = { 5 };
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
AnnotationID shape = test.map.addAnnotation(annotation);
test.frontend.render(test.map);
@@ -304,7 +304,7 @@ TEST(Annotations, ImmediateRemoveShape) {
AnnotationTest test;
test.map.removeAnnotation(test.map.addAnnotation(LineAnnotation { LineString<double>() }));
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.frontend.render(test.map);
}
@@ -312,20 +312,20 @@ TEST(Annotations, ImmediateRemoveShape) {
TEST(Annotations, SwitchStyle) {
AnnotationTest test;
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
test.frontend.render(test.map);
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.checkRendering("switch_style");
}
TEST(Annotations, ReaddImage) {
AnnotationTest test;
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
@@ -338,7 +338,7 @@ TEST(Annotations, ReaddImage) {
TEST(Annotations, QueryRenderedFeatures) {
AnnotationTest test;
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 50 }, "default_marker" });
@@ -362,7 +362,7 @@ TEST(Annotations, QueryFractionalZoomLevels) {
auto viewSize = test.frontend.getSize();
auto box = ScreenBox { {}, { double(viewSize.width), double(viewSize.height) } };
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
std::vector<mbgl::AnnotationID> ids;
@@ -394,7 +394,7 @@ TEST(Annotations, VisibleFeatures) {
auto viewSize = test.frontend.getSize();
auto box = ScreenBox { {}, { double(viewSize.width), double(viewSize.height) } };
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.setLatLngZoom({ 5, 5 }, 3);
@@ -438,7 +438,7 @@ TEST(Annotations, DebugEmpty) {
// should not render them.
AnnotationTest test;
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.setDebug(MapDebugOptions::TileBorders);
test.map.setZoom(1);
@@ -451,7 +451,7 @@ TEST(Annotations, DebugSparse) {
// tiles because they're all empty.
AnnotationTest test;
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.setDebug(MapDebugOptions::TileBorders);
test.map.setZoom(1);
test.map.addAnnotationImage(namedMarker("default_marker"));
@@ -469,7 +469,7 @@ TEST(Annotations, ChangeMaxZoom) {
annotation.width = { 5 };
test.map.setMaxZoom(6);
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.map.addAnnotation(annotation);
test.map.setMaxZoom(14);
test.map.setZoom(test.map.getMaxZoom());
diff --git a/test/api/custom_geometry_source.test.cpp b/test/api/custom_geometry_source.test.cpp
index 83d1543a0a..3397bef9ef 100644
--- a/test/api/custom_geometry_source.test.cpp
+++ b/test/api/custom_geometry_source.test.cpp
@@ -26,7 +26,7 @@ TEST(CustomGeometrySource, Grid) {
HeadlessFrontend frontend { pixelRatio, fileSource, *threadPool };
Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
*threadPool, MapMode::Static);
- map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
+ map.getStyle().loadJSON(util::readFile("test/fixtures/api/water.json"));
map.setLatLngZoom({ 37.8, -122.5 }, 10);
CustomGeometrySource::Options options;
diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp
index eb1d7e0d3a..5eaa73a37a 100644
--- a/test/api/custom_layer.test.cpp
+++ b/test/api/custom_layer.test.cpp
@@ -91,7 +91,7 @@ TEST(CustomLayer, Basic) {
HeadlessFrontend frontend { pixelRatio, fileSource, threadPool };
Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
threadPool, MapMode::Static);
- map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
+ map.getStyle().loadJSON(util::readFile("test/fixtures/api/water.json"));
map.setLatLngZoom({ 37.8, -122.5 }, 10);
map.getStyle().addLayer(std::make_unique<CustomLayer>(
"custom",
diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp
index c67ff9064c..43067dd57a 100644
--- a/test/api/query.test.cpp
+++ b/test/api/query.test.cpp
@@ -19,9 +19,9 @@ namespace {
class QueryTest {
public:
QueryTest() {
- map.getStyle().loadJSON(util::read_file("test/fixtures/api/query_style.json"));
+ map.getStyle().loadJSON(util::readFile("test/fixtures/api/query_style.json"));
map.getStyle().addImage(std::make_unique<style::Image>("test-icon",
- decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")), 1.0));
+ decodeImage(util::readFile("test/fixtures/sprites/default_marker.png")), 1.0));
frontend.render(map);
}
diff --git a/test/api/recycle_map.cpp b/test/api/recycle_map.cpp
index ca6abac8c1..1055eda5a9 100644
--- a/test/api/recycle_map.cpp
+++ b/test/api/recycle_map.cpp
@@ -40,10 +40,10 @@ TEST(API, RecycleMapUpdateImages) {
auto layer = std::make_unique<SymbolLayer>("geometry", "geometry");
layer->setIconImage({ markerName });
- map->getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ map->getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
map->getStyle().addSource(std::move(source));
map->getStyle().addLayer(std::move(layer));
- map->getStyle().addImage(std::make_unique<style::Image>(markerName, decodeImage(util::read_file(markerPath)), 1.0));
+ map->getStyle().addImage(std::make_unique<style::Image>(markerName, decodeImage(util::readFile(markerPath)), 1.0));
};
// default marker
diff --git a/test/api/zoom_history.cpp b/test/api/zoom_history.cpp
index df9b6ff2a3..a16d5322d7 100644
--- a/test/api/zoom_history.cpp
+++ b/test/api/zoom_history.cpp
@@ -34,7 +34,7 @@ TEST(API, ZoomHistory) {
EXPECT_TRUE(map);
- map->getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ map->getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
auto source = std::make_unique<GeoJSONSource>("source");
source->setGeoJSON({ LineString<double> { { 45, -45 }, { -45, 45 } } });
diff --git a/test/gl/context.test.cpp b/test/gl/context.test.cpp
index 179ce5de53..157732d723 100644
--- a/test/gl/context.test.cpp
+++ b/test/gl/context.test.cpp
@@ -90,7 +90,7 @@ TEST(GLContextMode, Shared) {
HeadlessFrontend frontend { pixelRatio, fileSource, threadPool, {}, GLContextMode::Shared };
Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource, threadPool, MapMode::Static);
- map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
+ map.getStyle().loadJSON(util::readFile("test/fixtures/api/water.json"));
map.setLatLngZoom({ 37.8, -122.5 }, 10);
// Set transparent background layer.
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index 9b34ea89b0..bb0ff2a201 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -21,7 +21,6 @@
using namespace mbgl;
using namespace mbgl::style;
-using namespace std::literals::string_literals;
class StubMapObserver : public MapObserver {
public:
@@ -162,7 +161,7 @@ TEST(Map, Offline) {
auto expiredItem = [] (const std::string& path) {
Response response;
- response.data = std::make_shared<std::string>(util::read_file("test/fixtures/map/offline/"s + path));
+ response.data = util::readFile("test/fixtures/map/offline/" + path);
response.expires = Timestamp{ Seconds(0) };
return response;
};
@@ -188,13 +187,13 @@ TEST(Map, Offline) {
TEST(Map, SetStyleDefaultCamera) {
MapTest<> test;
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
EXPECT_DOUBLE_EQ(test.map.getZoom(), 0.0);
EXPECT_DOUBLE_EQ(test.map.getPitch(), 0.0);
EXPECT_DOUBLE_EQ(test.map.getBearing(), 0.0);
EXPECT_EQ(test.map.getLatLng(), LatLng {});
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty-zoomed.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty-zoomed.json"));
EXPECT_DOUBLE_EQ(test.map.getZoom(), 0.0);
test.map.jumpTo(test.map.getStyle().getDefaultCamera());
@@ -211,7 +210,7 @@ TEST(Map, SetStyleInvalidJSON) {
test.observer.didFailLoadingMapCallback = [&]() {
fail = true;
};
- test.map.getStyle().loadJSON("invalid");
+ test.map.getStyle().loadJSON(Blob{ "invalid", false });
}
EXPECT_TRUE(fail);
@@ -247,8 +246,8 @@ TEST(Map, SetStyleInvalidURL) {
TEST(Map, DoubleStyleLoad) {
MapTest<> test;
- test.map.getStyle().loadJSON("");
- test.map.getStyle().loadJSON("");
+ test.map.getStyle().loadJSON(Blob{ "", false });
+ test.map.getStyle().loadJSON(Blob{ "", false });
}
TEST(Map, StyleFresh) {
@@ -260,7 +259,7 @@ TEST(Map, StyleFresh) {
EXPECT_EQ(1u, test.fileSource.requests.size());
Response response;
- response.data = std::make_shared<std::string>(util::read_file("test/fixtures/api/empty.json"));
+ response.data = util::readFile("test/fixtures/api/empty.json");
response.expires = Timestamp::max();
test.fileSource.respond(Resource::Style, response);
@@ -278,7 +277,7 @@ TEST(Map, StyleExpired) {
EXPECT_EQ(1u, test.fileSource.requests.size());
Response response;
- response.data = std::make_shared<std::string>(util::read_file("test/fixtures/api/empty.json"));
+ response.data = util::readFile("test/fixtures/api/empty.json");
response.expires = util::now() - 1h;
test.fileSource.respond(Resource::Style, response);
@@ -303,7 +302,7 @@ TEST(Map, StyleExpiredWithAnnotations) {
EXPECT_EQ(1u, test.fileSource.requests.size());
Response response;
- response.data = std::make_shared<std::string>(util::read_file("test/fixtures/api/empty.json"));
+ response.data = util::readFile("test/fixtures/api/empty.json");
response.expires = util::now() - 1h;
test.fileSource.respond(Resource::Style, response);
@@ -327,7 +326,7 @@ TEST(Map, StyleExpiredWithRender) {
EXPECT_EQ(1u, test.fileSource.requests.size());
Response response;
- response.data = std::make_shared<std::string>(util::read_file("test/fixtures/api/empty.json"));
+ response.data = util::readFile("test/fixtures/api/empty.json");
response.expires = util::now() - 1h;
test.fileSource.respond(Resource::Style, response);
@@ -349,7 +348,7 @@ TEST(Map, StyleEarlyMutation) {
test.map.getStyle().addLayer(std::make_unique<style::BackgroundLayer>("bg"));
Response response;
- response.data = std::make_shared<std::string>(util::read_file("test/fixtures/api/water.json"));
+ response.data = util::readFile("test/fixtures/api/water.json");
test.fileSource.respond(Resource::Style, response);
EXPECT_EQ(0u, test.fileSource.requests.size());
@@ -363,7 +362,7 @@ TEST(Map, MapLoadingSignal) {
test.observer.onWillStartLoadingMapCallback = [&]() {
emitted = true;
};
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
EXPECT_TRUE(emitted);
}
@@ -374,7 +373,7 @@ TEST(Map, MapLoadedSignal) {
test.runLoop.stop();
};
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
test.runLoop.run();
}
@@ -386,12 +385,12 @@ TEST(Map, StyleLoadedSignal) {
test.observer.didFinishLoadingStyleCallback = [&]() {
emitted = true;
};
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
EXPECT_TRUE(emitted);
// But not when the style couldn't be parsed
emitted = false;
- test.map.getStyle().loadJSON("invalid");
+ test.map.getStyle().loadJSON(Blob{ "invalid", false });
EXPECT_FALSE(emitted);
}
@@ -437,7 +436,7 @@ TEST(Map, TEST_REQUIRES_SERVER(StyleNotFound)) {
TEST(Map, AddLayer) {
MapTest<> test;
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
auto layer = std::make_unique<BackgroundLayer>("background");
layer->setBackgroundColor({ { 1, 0, 0, 1 } });
@@ -452,7 +451,7 @@ TEST(Map, WithoutVAOExtension) {
BackendScope scope { *test.frontend.getBackend() };
test.frontend.getBackend()->getContext().disableVAOExtension = true;
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/water.json"));
test::checkImage("test/fixtures/map/no_vao", test.frontend.render(test.map), 0.002);
}
@@ -460,7 +459,7 @@ TEST(Map, WithoutVAOExtension) {
TEST(Map, RemoveLayer) {
MapTest<> test;
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/api/empty.json"));
auto layer = std::make_unique<BackgroundLayer>("background");
layer->setBackgroundColor({{ 1, 0, 0, 1 }});
@@ -477,8 +476,7 @@ TEST(Map, DisabledSources) {
test.fileSource.response = [] (const Resource& res) -> optional<Response> {
if (res.url == "asset://tile.png") {
Response response;
- response.data = std::make_shared<std::string>(
- util::read_file("test/fixtures/map/disabled_layers/tile.png"));
+ response.data = util::readFile("test/fixtures/map/disabled_layers/tile.png");
return {std::move(response)};
}
return {};
@@ -491,7 +489,7 @@ TEST(Map, DisabledSources) {
// to an opacity of 0.5). Then, we are zooming back out to a zoom level of 0.5 and rerender.
// The "raster1" layer should not be visible anymore since it has minzoom 1, while "raster2"
// should still be there. Both layers have a distinct color through "raster-hue-rotate".
- test.map.getStyle().loadJSON(R"STYLE(
+ test.map.getStyle().loadJSON(Blob{ R"STYLE(
{
"version": 8,
"name": "Test",
@@ -523,7 +521,7 @@ TEST(Map, DisabledSources) {
}
}]
}
-)STYLE");
+)STYLE", false });
test::checkImage("test/fixtures/map/disabled_layers/first", test.frontend.render(test.map));
test.map.setZoom(0.5);
@@ -533,7 +531,7 @@ TEST(Map, DisabledSources) {
TEST(Map, DontLoadUnneededTiles) {
MapTest<> test;
- test.map.getStyle().loadJSON(R"STYLE({
+ test.map.getStyle().loadJSON(Blob{ R"STYLE({
"sources": {
"a": { "type": "vector", "tiles": [ "a/{z}/{x}/{y}" ] }
},
@@ -545,7 +543,7 @@ TEST(Map, DontLoadUnneededTiles) {
"minzoom": 0.3,
"maxzoom": 1.6
}]
-})STYLE");
+})STYLE", false });
using Tiles = std::unordered_set<std::string>;
Tiles tiles;
@@ -606,7 +604,7 @@ TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) {
};
Map map(frontend, observer, frontend.getSize(), pixelRatio, fileSource, threadPool, MapMode::Continuous);
- map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
+ map.getStyle().loadJSON(util::readFile("test/fixtures/api/water.json"));
runLoop.run();
}
@@ -624,7 +622,7 @@ TEST(Map, NoContentTiles) {
Tileset::Scheme::XYZ),
response);
- test.map.getStyle().loadJSON(R"STYLE({
+ test.map.getStyle().loadJSON(Blob{ R"STYLE({
"version": 8,
"name": "Water",
"sources": {
@@ -645,7 +643,7 @@ TEST(Map, NoContentTiles) {
"source": "mapbox",
"source-layer": "water"
}]
- })STYLE");
+ })STYLE", false });
test::checkImage("test/fixtures/map/nocontent",
test.frontend.render(test.map),
diff --git a/test/map/prefetch.test.cpp b/test/map/prefetch.test.cpp
index 4c82b2c965..7cb8ea1545 100644
--- a/test/map/prefetch.test.cpp
+++ b/test/map/prefetch.test.cpp
@@ -37,11 +37,9 @@ TEST(Map, PrefetchTiles) {
// The end rendering result should be all green because the map is only
// considered fully rendered when only ideal tiles are shown.
if (zoom == int(map.getZoom()) + 1) {
- response.data = std::make_shared<std::string>(
- util::read_file("test/fixtures/map/prefetch/tile_green.png"));
+ response.data = util::readFile("test/fixtures/map/prefetch/tile_green.png");
} else {
- response.data = std::make_shared<std::string>(
- util::read_file("test/fixtures/map/prefetch/tile_red.png"));
+ response.data = util::readFile("test/fixtures/map/prefetch/tile_red.png");
}
return { std::move(response) };
@@ -51,8 +49,8 @@ TEST(Map, PrefetchTiles) {
tiles.clear();
// Force tile reloading.
- map.getStyle().loadJSON(util::read_file("test/fixtures/map/prefetch/empty.json"));
- map.getStyle().loadJSON(util::read_file("test/fixtures/map/prefetch/style.json"));
+ map.getStyle().loadJSON(util::readFile("test/fixtures/map/prefetch/empty.json"));
+ map.getStyle().loadJSON(util::readFile("test/fixtures/map/prefetch/style.json"));
map.setLatLngZoom({ 40.726989, -73.992857 }, zoom); // Manhattan
diff --git a/test/programs/binary_program.test.cpp b/test/programs/binary_program.test.cpp
index a5cf7b6e39..7fc2acbf77 100644
--- a/test/programs/binary_program.test.cpp
+++ b/test/programs/binary_program.test.cpp
@@ -35,5 +35,5 @@ TEST(BinaryProgram, ObtainValues) {
EXPECT_EQ(3, binaryProgram2.uniformLocation("u_ratio"));
EXPECT_EQ(-1, binaryProgram2.uniformLocation("a_data"));
- EXPECT_THROW(BinaryProgram(""), std::runtime_error);
+ EXPECT_THROW(BinaryProgram(Blob{ "", false }), std::runtime_error);
}
diff --git a/test/renderer/image_manager.test.cpp b/test/renderer/image_manager.test.cpp
index ebe1bcd72f..e1d9030d4c 100644
--- a/test/renderer/image_manager.test.cpp
+++ b/test/renderer/image_manager.test.cpp
@@ -25,8 +25,8 @@ TEST(ImageManager, Basic) {
FixtureLog log;
ImageManager imageManager;
- auto images = parseSprite(util::read_file("test/fixtures/annotations/emerald.png"),
- util::read_file("test/fixtures/annotations/emerald.json"));
+ auto images = parseSprite(util::readFile("test/fixtures/annotations/emerald.png"),
+ util::readFile("test/fixtures/annotations/emerald.json"));
for (auto& image : images) {
imageManager.addImage(image->baseImpl);
}
diff --git a/test/sprite/sprite_loader.test.cpp b/test/sprite/sprite_loader.test.cpp
index 3691572265..d773afd539 100644
--- a/test/sprite/sprite_loader.test.cpp
+++ b/test/sprite/sprite_loader.test.cpp
@@ -58,14 +58,14 @@ public:
Response successfulSpriteImageResponse(const Resource& resource) {
EXPECT_EQ("test/fixtures/resources/sprite.png", resource.url);
Response response;
- response.data = std::make_unique<std::string>(util::read_file(resource.url));
+ response.data = util::readFile(resource.url);
return response;
}
Response successfulSpriteJSONResponse(const Resource& resource) {
EXPECT_EQ("test/fixtures/resources/sprite.json", resource.url);
Response response;
- response.data = std::make_unique<std::string>(util::read_file(resource.url));
+ response.data = util::readFile(resource.url);
return response;
}
@@ -79,7 +79,7 @@ Response failedSpriteResponse(const Resource&) {
Response corruptSpriteResponse(const Resource&) {
Response response;
- response.data = std::make_unique<std::string>("CORRUPT");
+ response.data = Blob{ "CORRUPT", false };
return response;
}
diff --git a/test/sprite/sprite_parser.test.cpp b/test/sprite/sprite_parser.test.cpp
index 529e4c75e8..14d5f65860 100644
--- a/test/sprite/sprite_parser.test.cpp
+++ b/test/sprite/sprite_parser.test.cpp
@@ -14,7 +14,7 @@ using namespace mbgl;
namespace {
auto readImage(const std::string& name) {
- return decodeImage(util::read_file(name));
+ return decodeImage(util::readFile(name));
}
} // namespace
@@ -22,7 +22,7 @@ auto readImage(const std::string& name) {
TEST(Sprite, SpriteImageCreationInvalid) {
FixtureLog log;
- const PremultipliedImage image_1x = decodeImage(util::read_file("test/fixtures/annotations/emerald.png"));
+ const PremultipliedImage image_1x = decodeImage(util::readFile("test/fixtures/annotations/emerald.png"));
ASSERT_EQ(200u, image_1x.size.width);
ASSERT_EQ(299u, image_1x.size.height);
@@ -135,7 +135,7 @@ TEST(Sprite, SpriteImageCreationInvalid) {
}
TEST(Sprite, SpriteImageCreation1x) {
- const PremultipliedImage image_1x = decodeImage(util::read_file("test/fixtures/annotations/emerald.png"));
+ const PremultipliedImage image_1x = decodeImage(util::readFile("test/fixtures/annotations/emerald.png"));
ASSERT_EQ(200u, image_1x.size.width);
ASSERT_EQ(299u, image_1x.size.height);
@@ -152,7 +152,7 @@ TEST(Sprite, SpriteImageCreation1x) {
}
TEST(Sprite, SpriteImageCreation2x) {
- const PremultipliedImage image_2x = decodeImage(util::read_file("test/fixtures/annotations/emerald@2x.png"));
+ const PremultipliedImage image_2x = decodeImage(util::readFile("test/fixtures/annotations/emerald@2x.png"));
// "museum_icon":{"x":354,"y":374,"width":36,"height":36,"pixelRatio":2,"sdf":false}
const auto sprite = createStyleImage("test", image_2x, 354, 374, 36, 36, 2, false);
@@ -165,7 +165,7 @@ TEST(Sprite, SpriteImageCreation2x) {
}
TEST(Sprite, SpriteImageCreation1_5x) {
- const PremultipliedImage image_2x = decodeImage(util::read_file("test/fixtures/annotations/emerald@2x.png"));
+ const PremultipliedImage image_2x = decodeImage(util::readFile("test/fixtures/annotations/emerald@2x.png"));
// "museum_icon":{"x":354,"y":374,"width":36,"height":36,"pixelRatio":2,"sdf":false}
const auto sprite = createStyleImage("test", image_2x, 354, 374, 36, 36, 1.5, false);
@@ -187,8 +187,8 @@ TEST(Sprite, SpriteImageCreation1_5x) {
}
TEST(Sprite, SpriteParsing) {
- const auto image_1x = util::read_file("test/fixtures/annotations/emerald.png");
- const auto json_1x = util::read_file("test/fixtures/annotations/emerald.json");
+ const auto image_1x = util::readFile("test/fixtures/annotations/emerald.png");
+ const auto json_1x = util::readFile("test/fixtures/annotations/emerald.json");
const auto images = parseSprite(image_1x, json_1x);
@@ -281,8 +281,8 @@ TEST(Sprite, SpriteParsing) {
}
TEST(Sprite, SpriteParsingInvalidJSON) {
- const auto image_1x = util::read_file("test/fixtures/annotations/emerald.png");
- const auto json_1x = R"JSON({ "image": " })JSON";
+ const auto image_1x = util::readFile("test/fixtures/annotations/emerald.png");
+ const auto json_1x = Blob{ R"JSON({ "image": " })JSON", false };
try {
parseSprite(image_1x, json_1x);
@@ -297,8 +297,8 @@ TEST(Sprite, SpriteParsingInvalidJSON) {
TEST(Sprite, SpriteParsingEmptyImage) {
FixtureLog log;
- const auto image_1x = util::read_file("test/fixtures/annotations/emerald.png");
- const auto json_1x = R"JSON({ "image": {} })JSON";
+ const auto image_1x = util::readFile("test/fixtures/annotations/emerald.png");
+ const auto json_1x = Blob{ R"JSON({ "image": {} })JSON", false };
const auto images = parseSprite(image_1x, json_1x);
EXPECT_EQ(0u, images.size());
@@ -314,8 +314,8 @@ TEST(Sprite, SpriteParsingEmptyImage) {
TEST(Sprite, SpriteParsingSimpleWidthHeight) {
FixtureLog log;
- const auto image_1x = util::read_file("test/fixtures/annotations/emerald.png");
- const auto json_1x = R"JSON({ "image": { "width": 32, "height": 32 } })JSON";
+ const auto image_1x = util::readFile("test/fixtures/annotations/emerald.png");
+ const auto json_1x = Blob{ R"JSON({ "image": { "width": 32, "height": 32 } })JSON", false };
const auto images = parseSprite(image_1x, json_1x);
EXPECT_EQ(1u, images.size());
@@ -324,8 +324,8 @@ TEST(Sprite, SpriteParsingSimpleWidthHeight) {
TEST(Sprite, SpriteParsingWidthTooBig) {
FixtureLog log;
- const auto image_1x = util::read_file("test/fixtures/annotations/emerald.png");
- const auto json_1x = R"JSON({ "image": { "width": 65536, "height": 32 } })JSON";
+ const auto image_1x = util::readFile("test/fixtures/annotations/emerald.png");
+ const auto json_1x = Blob{ R"JSON({ "image": { "width": 65536, "height": 32 } })JSON", false };
const auto images = parseSprite(image_1x, json_1x);
EXPECT_EQ(0u, images.size());
@@ -347,8 +347,8 @@ TEST(Sprite, SpriteParsingWidthTooBig) {
TEST(Sprite, SpriteParsingNegativeWidth) {
FixtureLog log;
- const auto image_1x = util::read_file("test/fixtures/annotations/emerald.png");
- const auto json_1x = R"JSON({ "image": { "width": -1, "height": 32 } })JSON";
+ const auto image_1x = util::readFile("test/fixtures/annotations/emerald.png");
+ const auto json_1x = Blob{ R"JSON({ "image": { "width": -1, "height": 32 } })JSON", false };
const auto images = parseSprite(image_1x, json_1x);
EXPECT_EQ(0u, images.size());
@@ -370,8 +370,8 @@ TEST(Sprite, SpriteParsingNegativeWidth) {
TEST(Sprite, SpriteParsingNullRatio) {
FixtureLog log;
- const auto image_1x = util::read_file("test/fixtures/annotations/emerald.png");
- const auto json_1x = R"JSON({ "image": { "width": 32, "height": 32, "pixelRatio": 0 } })JSON";
+ const auto image_1x = util::readFile("test/fixtures/annotations/emerald.png");
+ const auto json_1x = Blob{ R"JSON({ "image": { "width": 32, "height": 32, "pixelRatio": 0 } })JSON", false };
const auto images = parseSprite(image_1x, json_1x);
EXPECT_EQ(0u, images.size());
diff --git a/test/src/mbgl/test/util.cpp b/test/src/mbgl/test/util.cpp
index 028a0a9d51..82d2af6cd9 100644
--- a/test/src/mbgl/test/util.cpp
+++ b/test/src/mbgl/test/util.cpp
@@ -100,26 +100,26 @@ void checkImage(const std::string& base,
double pixelThreshold) {
#if !TEST_READ_ONLY
if (getenv("UPDATE")) {
- util::write_file(base + "/expected.png", encodePNG(actual));
+ util::writeFile(base + "/expected.png", encodePNG(actual));
return;
}
#endif
- std::string expected_image;
+ Blob expectedImage;
try {
- expected_image = util::read_file(base + "/expected.png");
+ expectedImage = util::readFile(base + "/expected.png");
} catch (std::exception& ex) {
Log::Error(Event::Setup, "Failed to load expected image %s: %s",
(base + "/expected.png").c_str(), ex.what());
throw;
}
- PremultipliedImage expected = decodeImage(expected_image);
+ PremultipliedImage expected = decodeImage(expectedImage);
PremultipliedImage diff { expected.size };
#if !TEST_READ_ONLY
- util::write_file(base + "/actual.png", encodePNG(actual));
+ util::writeFile(base + "/actual.png", encodePNG(actual));
#endif
ASSERT_EQ(expected.size, actual.size);
@@ -134,7 +134,7 @@ void checkImage(const std::string& base,
EXPECT_LE(pixels / (expected.size.width * expected.size.height), imageThreshold);
#if !TEST_READ_ONLY
- util::write_file(base + "/diff.png", encodePNG(diff));
+ util::writeFile(base + "/diff.png", encodePNG(diff));
#endif
}
diff --git a/test/storage/asset_file_source.test.cpp b/test/storage/asset_file_source.test.cpp
index 978a41a306..694d56be6d 100644
--- a/test/storage/asset_file_source.test.cpp
+++ b/test/storage/asset_file_source.test.cpp
@@ -33,8 +33,8 @@ TEST(AssetFileSource, Load) {
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);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("content is here\n", *res.data.uncompressedData());
if (!--numRequests) {
endCallback();
@@ -86,8 +86,8 @@ TEST(AssetFileSource, EmptyFile) {
std::unique_ptr<AsyncRequest> req = fs.request({ Resource::Unknown, "asset://empty" }, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("", *res.data.uncompressedData());
loop.stop();
});
@@ -102,8 +102,8 @@ TEST(AssetFileSource, NonEmptyFile) {
std::unique_ptr<AsyncRequest> req = fs.request({ Resource::Unknown, "asset://nonempty" }, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("content is here\n", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("content is here\n", *res.data.uncompressedData());
loop.stop();
});
@@ -119,7 +119,7 @@ TEST(AssetFileSource, NonExistentFile) {
req.reset();
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::NotFound, res.error->reason);
- ASSERT_FALSE(res.data.get());
+ ASSERT_FALSE(res.data);
// Do not assert on platform-specific error message.
loop.stop();
});
@@ -137,7 +137,7 @@ TEST(AssetFileSource, InvalidURL) {
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::Other, res.error->reason);
EXPECT_EQ("Invalid asset URL", res.error->message);
- ASSERT_FALSE(res.data.get());
+ ASSERT_FALSE(res.data);
loop.stop();
});
@@ -153,7 +153,7 @@ TEST(AssetFileSource, ReadDirectory) {
req.reset();
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::NotFound, res.error->reason);
- ASSERT_FALSE(res.data.get());
+ ASSERT_FALSE(res.data);
// Do not assert on platform-specific error message.
loop.stop();
});
@@ -169,8 +169,8 @@ TEST(AssetFileSource, URLEncoding) {
std::unique_ptr<AsyncRequest> req = fs.request({ Resource::Unknown, "asset://%6eonempty" }, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("content is here\n", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("content is here\n", *res.data.uncompressedData());
loop.stop();
});
diff --git a/test/storage/default_file_source.test.cpp b/test/storage/default_file_source.test.cpp
index c11d442270..f74a515d86 100644
--- a/test/storage/default_file_source.test.cpp
+++ b/test/storage/default_file_source.test.cpp
@@ -19,8 +19,8 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(CacheResponse)) {
req1 = fs.request(resource, [&](Response res) {
req1.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Response 1", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Response 1", *res.data.uncompressedData());
EXPECT_TRUE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -32,8 +32,8 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(CacheResponse)) {
req2 = fs.request(resource, [&](Response res2) {
req2.reset();
EXPECT_EQ(response.error, res2.error);
- ASSERT_TRUE(res2.data.get());
- EXPECT_EQ(*response.data, *res2.data);
+ ASSERT_TRUE(res2.data);
+ EXPECT_EQ(*response.data.uncompressedData(), *res2.data.uncompressedData());
EXPECT_EQ(response.expires, res2.expires);
EXPECT_EQ(response.mustRevalidate, res2.mustRevalidate);
EXPECT_EQ(response.modified, res2.modified);
@@ -61,8 +61,8 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(CacheRevalidateSame)) {
EXPECT_EQ(nullptr, res.error);
EXPECT_FALSE(res.notModified);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Response", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Response", *res.data.uncompressedData());
EXPECT_FALSE(bool(res.expires));
EXPECT_TRUE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -81,8 +81,8 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(CacheRevalidateSame)) {
gotResponse = true;
EXPECT_EQ(nullptr, res2.error);
EXPECT_FALSE(res2.notModified);
- ASSERT_TRUE(res2.data.get());
- EXPECT_EQ("Response", *res2.data);
+ ASSERT_TRUE(res2.data);
+ EXPECT_EQ("Response", *res2.data.uncompressedData());
EXPECT_TRUE(bool(res2.expires));
EXPECT_TRUE(res2.mustRevalidate);
EXPECT_FALSE(bool(res2.modified));
@@ -95,7 +95,7 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(CacheRevalidateSame)) {
req2.reset();
EXPECT_EQ(nullptr, res2.error);
EXPECT_TRUE(res2.notModified);
- EXPECT_FALSE(res2.data.get());
+ EXPECT_FALSE(res2.data);
EXPECT_TRUE(bool(res2.expires));
EXPECT_TRUE(res2.mustRevalidate);
EXPECT_FALSE(bool(res2.modified));
@@ -124,8 +124,8 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(CacheRevalidateModified)) {
EXPECT_EQ(nullptr, res.error);
EXPECT_FALSE(res.notModified);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Response", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Response", *res.data.uncompressedData());
EXPECT_FALSE(bool(res.expires));
EXPECT_TRUE(res.mustRevalidate);
EXPECT_EQ(Timestamp{ Seconds(1420070400) }, *res.modified);
@@ -144,8 +144,8 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(CacheRevalidateModified)) {
gotResponse = true;
EXPECT_EQ(nullptr, res2.error);
EXPECT_FALSE(res2.notModified);
- ASSERT_TRUE(res2.data.get());
- EXPECT_EQ("Response", *res2.data);
+ ASSERT_TRUE(res2.data);
+ EXPECT_EQ("Response", *res2.data.uncompressedData());
EXPECT_TRUE(bool(res2.expires));
EXPECT_TRUE(res2.mustRevalidate);
EXPECT_EQ(Timestamp{ Seconds(1420070400) }, *res2.modified);
@@ -158,7 +158,7 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(CacheRevalidateModified)) {
req2.reset();
EXPECT_EQ(nullptr, res2.error);
EXPECT_TRUE(res2.notModified);
- EXPECT_FALSE(res2.data.get());
+ EXPECT_FALSE(res2.data);
EXPECT_TRUE(bool(res2.expires));
EXPECT_TRUE(res2.mustRevalidate);
EXPECT_EQ(Timestamp{ Seconds(1420070400) }, *res2.modified);
@@ -184,8 +184,8 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(CacheRevalidateEtag)) {
req1.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Response 1", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Response 1", *res.data.uncompressedData());
EXPECT_FALSE(bool(res.expires));
EXPECT_TRUE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -196,9 +196,9 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(CacheRevalidateEtag)) {
req2.reset();
EXPECT_EQ(nullptr, res2.error);
- ASSERT_TRUE(res2.data.get());
- EXPECT_NE(res.data, res2.data);
- EXPECT_EQ("Response 2", *res2.data);
+ ASSERT_TRUE(res2.data);
+ EXPECT_FALSE(*res.data.uncompressedData() == *res2.data.uncompressedData());
+ EXPECT_EQ("Response 2", *res2.data.uncompressedData());
EXPECT_FALSE(bool(res2.expires));
EXPECT_TRUE(res2.mustRevalidate);
EXPECT_FALSE(bool(res2.modified));
@@ -235,8 +235,8 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(HTTPIssue1369)) {
req = fs.request(resource, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Hello World!", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Hello World!", *res.data.uncompressedData());
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -256,7 +256,7 @@ TEST(DefaultFileSource, OptionalNonExpired) {
using namespace std::chrono_literals;
Response response;
- response.data = std::make_shared<std::string>("Cached value");
+ response.data = Blob{ "Cached value", false };
response.expires = util::now() + 1h;
fs.put(optionalResource, response);
@@ -264,8 +264,8 @@ TEST(DefaultFileSource, OptionalNonExpired) {
req = fs.request(optionalResource, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Cached value", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Cached value", *res.data.uncompressedData());
ASSERT_TRUE(bool(res.expires));
EXPECT_EQ(*response.expires, *res.expires);
EXPECT_FALSE(res.mustRevalidate);
@@ -286,7 +286,7 @@ TEST(DefaultFileSource, OptionalExpired) {
using namespace std::chrono_literals;
Response response;
- response.data = std::make_shared<std::string>("Cached value");
+ response.data = Blob{ "Cached value", false };
response.expires = util::now() - 1h;
fs.put(optionalResource, response);
@@ -294,8 +294,8 @@ TEST(DefaultFileSource, OptionalExpired) {
req = fs.request(optionalResource, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Cached value", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Cached value", *res.data.uncompressedData());
ASSERT_TRUE(bool(res.expires));
EXPECT_EQ(*response.expires, *res.expires);
EXPECT_FALSE(res.mustRevalidate);
@@ -361,7 +361,7 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(NoCacheRefreshEtagNotModified)) {
// Put a fake value into the cache to make sure we're not retrieving anything from the cache.
Response response;
- response.data = std::make_shared<std::string>("Cached value");
+ response.data = Blob{ "Cached value", false };
response.expires = util::now() + 1h;
fs.put(resource, response);
@@ -370,7 +370,7 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(NoCacheRefreshEtagNotModified)) {
req.reset();
EXPECT_EQ(nullptr, res.error);
EXPECT_TRUE(res.notModified);
- EXPECT_FALSE(res.data.get());
+ EXPECT_FALSE(res.data);
ASSERT_TRUE(bool(res.expires));
EXPECT_LT(util::now(), *res.expires);
EXPECT_TRUE(res.mustRevalidate);
@@ -396,7 +396,7 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(NoCacheRefreshEtagModified)) {
// Put a fake value into the cache to make sure we're not retrieving anything from the cache.
Response response;
- response.data = std::make_shared<std::string>("Cached value");
+ response.data = Blob{ "Cached value", false };
response.expires = util::now() + 1h;
fs.put(resource, response);
@@ -405,8 +405,8 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(NoCacheRefreshEtagModified)) {
req.reset();
EXPECT_EQ(nullptr, res.error);
EXPECT_FALSE(res.notModified);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Response", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Response", *res.data.uncompressedData());
EXPECT_FALSE(bool(res.expires));
EXPECT_TRUE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -430,7 +430,7 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(NoCacheFull)) {
// Put a fake value into the cache to make sure we're not retrieving anything from the cache.
Response response;
- response.data = std::make_shared<std::string>("Cached value");
+ response.data = Blob{ "Cached value", false };
response.expires = util::now() + 1h;
fs.put(resource, response);
@@ -439,8 +439,8 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(NoCacheFull)) {
req.reset();
EXPECT_EQ(nullptr, res.error);
EXPECT_FALSE(res.notModified);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Response", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Response", *res.data.uncompressedData());
EXPECT_FALSE(bool(res.expires));
EXPECT_TRUE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -466,7 +466,7 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(NoCacheRefreshModifiedNotModified))
// Put a fake value into the cache to make sure we're not retrieving anything from the cache.
Response response;
- response.data = std::make_shared<std::string>("Cached value");
+ response.data = Blob{ "Cached value", false };
response.expires = util::now() + 1h;
fs.put(resource, response);
@@ -475,7 +475,7 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(NoCacheRefreshModifiedNotModified))
req.reset();
EXPECT_EQ(nullptr, res.error);
EXPECT_TRUE(res.notModified);
- EXPECT_FALSE(res.data.get());
+ EXPECT_FALSE(res.data);
ASSERT_TRUE(bool(res.expires));
EXPECT_LT(util::now(), *res.expires);
EXPECT_TRUE(res.mustRevalidate);
@@ -502,7 +502,7 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(NoCacheRefreshModifiedModified)) {
// Put a fake value into the cache to make sure we're not retrieving anything from the cache.
Response response;
- response.data = std::make_shared<std::string>("Cached value");
+ response.data = Blob{ "Cached value", false };
response.expires = util::now() + 1h;
fs.put(resource, response);
@@ -511,8 +511,8 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(NoCacheRefreshModifiedModified)) {
req.reset();
EXPECT_EQ(nullptr, res.error);
EXPECT_FALSE(res.notModified);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Response", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Response", *res.data.uncompressedData());
EXPECT_FALSE(bool(res.expires));
EXPECT_TRUE(res.mustRevalidate);
EXPECT_EQ(Timestamp{ Seconds(1420070400) }, *res.modified);
@@ -543,8 +543,8 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(SetResourceTransform)) {
req = fs.request(resource1, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Hello World!", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Hello World!", *res.data.uncompressedData());
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -560,8 +560,8 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(SetResourceTransform)) {
req = fs.request(resource2, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Hello World!", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Hello World!", *res.data.uncompressedData());
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -584,7 +584,7 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(RespondToStaleMustRevalidate)) {
// Put an existing value in the cache that has expired, and has must-revalidate set.
Response response;
- response.data = std::make_shared<std::string>("Cached value");
+ response.data = Blob{ "Cached value", false };
response.modified = Timestamp(Seconds(1417392000)); // December 1, 2014
response.expires = Timestamp(Seconds(1417392000));
response.mustRevalidate = true;
@@ -598,8 +598,8 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(RespondToStaleMustRevalidate)) {
EXPECT_EQ(Response::Error::Reason::NotFound, res.error->reason);
EXPECT_EQ("Cached resource is unusable", res.error->message);
EXPECT_FALSE(res.notModified);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Cached value", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Cached value", *res.data.uncompressedData());
ASSERT_TRUE(res.expires);
EXPECT_EQ(Timestamp{ Seconds(1417392000) }, *res.expires);
EXPECT_TRUE(res.mustRevalidate);
@@ -622,7 +622,7 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(RespondToStaleMustRevalidate)) {
// request. We're replacing the data so that we can check that the DefaultFileSource doesn't
// attempt another database access if we already have the value.
resource.loadingMethod = Resource::LoadingMethod::NetworkOnly;
- resource.priorData = std::make_shared<std::string>("Prior value");
+ resource.priorData = Blob{ "Prior value", false };
req = fs.request(resource, [&](Response res) {
req.reset();
@@ -632,11 +632,11 @@ TEST(DefaultFileSource, TEST_REQUIRES_SERVER(RespondToStaleMustRevalidate)) {
// OnlineFileSource to ensure that requestors know that this is the first time they're
// seeing this data.
EXPECT_FALSE(res.notModified);
- ASSERT_TRUE(res.data.get());
+ ASSERT_TRUE(res.data);
// Ensure that it's the value that we manually inserted into the cache rather than the value
// the server returns, since we should be executing a revalidation request which doesn't
// return new data, only a 304 Not Modified response.
- EXPECT_EQ("Prior value", *res.data);
+ EXPECT_EQ("Prior value", *res.data.uncompressedData());
ASSERT_TRUE(res.expires);
EXPECT_LE(util::now(), *res.expires);
EXPECT_TRUE(res.mustRevalidate);
diff --git a/test/storage/http_file_source.test.cpp b/test/storage/http_file_source.test.cpp
index 006b7a0fb3..093a5c1ced 100644
--- a/test/storage/http_file_source.test.cpp
+++ b/test/storage/http_file_source.test.cpp
@@ -23,8 +23,8 @@ TEST(HTTPFileSource, TEST_REQUIRES_SERVER(HTTP200)) {
auto req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" }, [&](Response res) {
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Hello World!", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Hello World!", *res.data.uncompressedData());
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -43,7 +43,7 @@ TEST(HTTPFileSource, TEST_REQUIRES_SERVER(HTTP404)) {
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::NotFound, res.error->reason);
EXPECT_EQ("HTTP status code 404", res.error->message);
- EXPECT_FALSE(bool(res.data));
+ EXPECT_FALSE(res.data);
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -61,7 +61,7 @@ TEST(HTTPFileSource, TEST_REQUIRES_SERVER(HTTPTile404)) {
auto req = fs.request({ Resource::Tile, "http://127.0.0.1:3000/doesnotexist" }, [&](Response res) {
EXPECT_TRUE(res.noContent);
EXPECT_FALSE(bool(res.error));
- EXPECT_FALSE(bool(res.data));
+ EXPECT_FALSE(res.data);
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -79,7 +79,8 @@ TEST(HTTPFileSource, TEST_REQUIRES_SERVER(HTTP200EmptyData)) {
auto req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/empty-data" }, [&](Response res) {
EXPECT_FALSE(res.noContent);
EXPECT_FALSE(bool(res.error));
- EXPECT_EQ(*res.data, std::string());
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ(0u, res.data.uncompressedData()->size());
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -97,7 +98,7 @@ TEST(HTTPFileSource, TEST_REQUIRES_SERVER(HTTP204)) {
auto req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/no-content" }, [&](Response res) {
EXPECT_TRUE(res.noContent);
EXPECT_FALSE(bool(res.error));
- EXPECT_FALSE(bool(res.data));
+ EXPECT_FALSE(res.data);
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -116,7 +117,7 @@ TEST(HTTPFileSource, TEST_REQUIRES_SERVER(HTTP500)) {
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::Server, res.error->reason);
EXPECT_EQ("HTTP status code 500", res.error->message);
- EXPECT_FALSE(bool(res.data));
+ EXPECT_FALSE(res.data);
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -134,8 +135,8 @@ TEST(HTTPFileSource, TEST_REQUIRES_SERVER(ExpiresParsing)) {
auto req = fs.request({ Resource::Unknown,
"http://127.0.0.1:3000/test?modified=1420794326&expires=1420797926&etag=foo" }, [&](Response res) {
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Hello World!", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Hello World!", *res.data.uncompressedData());
EXPECT_EQ(Timestamp{ Seconds(1420797926) }, res.expires);
EXPECT_FALSE(res.mustRevalidate);
EXPECT_EQ(Timestamp{ Seconds(1420794326) }, res.modified);
@@ -152,8 +153,8 @@ TEST(HTTPFileSource, TEST_REQUIRES_SERVER(CacheControlParsing)) {
auto req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test?cachecontrol=max-age=120" }, [&](Response res) {
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Hello World!", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Hello World!", *res.data.uncompressedData());
EXPECT_GT(Seconds(2), util::abs(*res.expires - util::now() - Seconds(120))) << "Expiration date isn't about 120 seconds in the future";
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -181,8 +182,8 @@ TEST(HTTPFileSource, TEST_REQUIRES_SERVER(Load)) {
[&, i, current](Response res) {
reqs[i].reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ(std::string("Request ") + std::to_string(current), *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ(std::string("Request ") + std::to_string(current), *res.data.uncompressedData());
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
diff --git a/test/storage/local_file_source.test.cpp b/test/storage/local_file_source.test.cpp
index e1756f8e7d..76848f6682 100644
--- a/test/storage/local_file_source.test.cpp
+++ b/test/storage/local_file_source.test.cpp
@@ -37,8 +37,8 @@ TEST(LocalFileSource, EmptyFile) {
std::unique_ptr<AsyncRequest> req = fs.request({ Resource::Unknown, toAbsoluteURL("empty") }, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("", *res.data.uncompressedData());
loop.stop();
});
@@ -53,8 +53,8 @@ TEST(LocalFileSource, NonEmptyFile) {
std::unique_ptr<AsyncRequest> req = fs.request({ Resource::Unknown, toAbsoluteURL("nonempty") }, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("content is here\n", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("content is here\n", *res.data.uncompressedData());
loop.stop();
});
@@ -70,7 +70,7 @@ TEST(LocalFileSource, NonExistentFile) {
req.reset();
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::NotFound, res.error->reason);
- ASSERT_FALSE(res.data.get());
+ ASSERT_FALSE(res.data);
// Do not assert on platform-specific error message.
loop.stop();
});
@@ -88,7 +88,7 @@ TEST(LocalFileSource, InvalidURL) {
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::Other, res.error->reason);
EXPECT_EQ("Invalid file URL", res.error->message);
- ASSERT_FALSE(res.data.get());
+ ASSERT_FALSE(res.data);
loop.stop();
});
@@ -104,7 +104,7 @@ TEST(LocalFileSource, ReadDirectory) {
req.reset();
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::NotFound, res.error->reason);
- ASSERT_FALSE(res.data.get());
+ ASSERT_FALSE(res.data);
// Do not assert on platform-specific error message.
loop.stop();
});
@@ -120,8 +120,8 @@ TEST(LocalFileSource, URLEncoding) {
std::unique_ptr<AsyncRequest> req = fs.request({ Resource::Unknown, toAbsoluteURL("%6eonempty") }, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("content is here\n", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("content is here\n", *res.data.uncompressedData());
loop.stop();
});
@@ -142,7 +142,7 @@ TEST(LocalFileSource, URLLimit) {
req.reset();
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::Other, res.error->reason);
- ASSERT_FALSE(res.data.get());
+ ASSERT_FALSE(res.data);
loop.stop();
});
diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp
index 94daf59c02..23e70448b0 100644
--- a/test/storage/offline_database.test.cpp
+++ b/test/storage/offline_database.test.cpp
@@ -34,8 +34,8 @@ void deleteFile(const char* name) {
}
}
-void writeFile(const char* name, const std::string& data) {
- mbgl::util::write_file(name, data);
+void writeFile(const char* name, mbgl::Blob&& data) {
+ mbgl::util::writeFile(name, data);
}
} // namespace
@@ -79,7 +79,7 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(Invalid)) {
createDir("test/fixtures/offline_database");
deleteFile("test/fixtures/offline_database/invalid.db");
- writeFile("test/fixtures/offline_database/invalid.db", "this is an invalid file");
+ writeFile("test/fixtures/offline_database/invalid.db", Blob{ "this is an invalid file", false });
Log::setObserver(std::make_unique<FixtureLogObserver>());
@@ -124,23 +124,23 @@ TEST(OfflineDatabase, PutResource) {
Resource resource { Resource::Style, "http://example.com/" };
Response response;
- response.data = std::make_shared<std::string>("first");
+ response.data = Blob{ "first", false };
auto insertPutResult = db.put(resource, response);
EXPECT_TRUE(insertPutResult.first);
EXPECT_EQ(5u, insertPutResult.second);
auto insertGetResult = db.get(resource);
EXPECT_EQ(nullptr, insertGetResult->error.get());
- EXPECT_EQ("first", *insertGetResult->data);
+ EXPECT_EQ("first", *insertGetResult->data.uncompressedData());
- response.data = std::make_shared<std::string>("second");
+ response.data = Blob{ "second", false };
auto updatePutResult = db.put(resource, response);
EXPECT_FALSE(updatePutResult.first);
EXPECT_EQ(6u, updatePutResult.second);
auto updateGetResult = db.get(resource);
EXPECT_EQ(nullptr, updateGetResult->error.get());
- EXPECT_EQ("second", *updateGetResult->data);
+ EXPECT_EQ("second", *updateGetResult->data.uncompressedData());
}
TEST(OfflineDatabase, PutTile) {
@@ -158,23 +158,23 @@ TEST(OfflineDatabase, PutTile) {
};
Response response;
- response.data = std::make_shared<std::string>("first");
+ response.data = Blob{ "first", false };
auto insertPutResult = db.put(resource, response);
EXPECT_TRUE(insertPutResult.first);
EXPECT_EQ(5u, insertPutResult.second);
auto insertGetResult = db.get(resource);
EXPECT_EQ(nullptr, insertGetResult->error.get());
- EXPECT_EQ("first", *insertGetResult->data);
+ EXPECT_EQ("first", *insertGetResult->data.uncompressedData());
- response.data = std::make_shared<std::string>("second");
+ response.data = Blob{ "second", false };
auto updatePutResult = db.put(resource, response);
EXPECT_FALSE(updatePutResult.first);
EXPECT_EQ(6u, updatePutResult.second);
auto updateGetResult = db.get(resource);
EXPECT_EQ(nullptr, updateGetResult->error.get());
- EXPECT_EQ("second", *updateGetResult->data);
+ EXPECT_EQ("second", *updateGetResult->data.uncompressedData());
}
TEST(OfflineDatabase, PutResourceNoContent) {
@@ -190,7 +190,7 @@ TEST(OfflineDatabase, PutResourceNoContent) {
auto res = db.get(resource);
EXPECT_EQ(nullptr, res->error);
EXPECT_TRUE(res->noContent);
- EXPECT_FALSE(res->data.get());
+ EXPECT_FALSE(res->data);
}
TEST(OfflineDatabase, PutTileNotFound) {
@@ -213,7 +213,7 @@ TEST(OfflineDatabase, PutTileNotFound) {
auto res = db.get(resource);
EXPECT_EQ(nullptr, res->error);
EXPECT_TRUE(res->noContent);
- EXPECT_FALSE(res->data.get());
+ EXPECT_FALSE(res->data);
}
TEST(OfflineDatabase, CreateRegion) {
@@ -344,15 +344,15 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(ConcurrentUse)) {
thread2.join();
}
-static std::shared_ptr<std::string> randomString(size_t size) {
- auto result = std::make_shared<std::string>(size, 0);
+static mbgl::Blob randomBlob(size_t size) {
+ auto result = std::string(size, char());
std::mt19937 random;
for (size_t i = 0; i < size; i++) {
- (*result)[i] = random();
+ result[i] = random();
}
- return result;
+ return { std::move(result), false };
}
TEST(OfflineDatabase, PutReturnsSize) {
@@ -361,11 +361,11 @@ TEST(OfflineDatabase, PutReturnsSize) {
OfflineDatabase db(":memory:");
Response compressible;
- compressible.data = std::make_shared<std::string>(1024, 0);
+ compressible.data = Blob{ std::string(1024, char()), false };
EXPECT_EQ(17u, db.put(Resource::style("http://example.com/compressible"), compressible).second);
Response incompressible;
- incompressible.data = randomString(1024);
+ incompressible.data = randomBlob(1024);
EXPECT_EQ(1024u, db.put(Resource::style("http://example.com/incompressible"), incompressible).second);
Response noContent;
@@ -379,7 +379,7 @@ TEST(OfflineDatabase, PutEvictsLeastRecentlyUsedResources) {
OfflineDatabase db(":memory:", 1024 * 100);
Response response;
- response.data = randomString(1024);
+ response.data = randomBlob(1024);
for (uint32_t i = 1; i <= 100; i++) {
Resource resource = Resource::style("http://example.com/"s + util::toString(i));
@@ -398,7 +398,7 @@ TEST(OfflineDatabase, PutRegionResourceDoesNotEvict) {
OfflineRegion region = db.createRegion(definition, OfflineRegionMetadata());
Response response;
- response.data = randomString(1024);
+ response.data = randomBlob(1024);
for (uint32_t i = 1; i <= 100; i++) {
db.putRegionResource(region.getID(), Resource::style("http://example.com/"s + util::toString(i)), response);
@@ -414,7 +414,7 @@ TEST(OfflineDatabase, PutFailsWhenEvictionInsuffices) {
OfflineDatabase db(":memory:", 1024 * 100);
Response big;
- big.data = randomString(1024 * 100);
+ big.data = randomBlob(1024 * 100);
EXPECT_FALSE(db.put(Resource::style("http://example.com/big"), big).first);
EXPECT_FALSE(bool(db.get(Resource::style("http://example.com/big"))));
@@ -435,7 +435,7 @@ TEST(OfflineDatabase, GetRegionCompletedStatus) {
EXPECT_EQ(0u, status1.completedTileSize);
Response response;
- response.data = std::make_shared<std::string>("data");
+ response.data = Blob{ "data", false };
uint64_t styleSize = db.putRegionResource(region.getID(), Resource::style("http://example.com/"), response);
@@ -465,7 +465,7 @@ TEST(OfflineDatabase, HasRegionResource) {
EXPECT_FALSE(bool(db.hasRegionResource(region.getID(), Resource::style("http://example.com/20"))));
Response response;
- response.data = randomString(1024);
+ response.data = randomBlob(1024);
for (uint32_t i = 1; i <= 100; i++) {
db.putRegionResource(region.getID(), Resource::style("http://example.com/"s + util::toString(i)), response);
@@ -493,7 +493,7 @@ TEST(OfflineDatabase, HasRegionResourceTile) {
};
Response response;
- response.data = std::make_shared<std::string>("first");
+ response.data = Blob{ "first", false };
EXPECT_FALSE(bool(db.hasRegionResource(region.getID(), resource)));
db.putRegionResource(region.getID(), resource, response);
@@ -522,7 +522,7 @@ TEST(OfflineDatabase, OfflineMapboxTileCount) {
Resource mapboxTile2 = Resource::tile("mapbox://tiles/2", 1.0, 0, 0, 1, Tileset::Scheme::XYZ);
Response response;
- response.data = std::make_shared<std::string>("data");
+ response.data = Blob{ "data", false };
// Count is initially zero.
EXPECT_EQ(0u, db.getOfflineMapboxTileCount());
@@ -609,7 +609,7 @@ TEST(OfflineDatabase, MigrateFromV2Schema) {
// v2.db is a v2 database containing a single offline region with a small number of resources.
deleteFile("test/fixtures/offline_database/migrated.db");
- writeFile("test/fixtures/offline_database/migrated.db", util::read_file("test/fixtures/offline_database/v2.db"));
+ writeFile("test/fixtures/offline_database/migrated.db", util::readFile("test/fixtures/offline_database/v2.db"));
{
OfflineDatabase db("test/fixtures/offline_database/migrated.db", 0);
@@ -630,7 +630,7 @@ TEST(OfflineDatabase, MigrateFromV3Schema) {
// v3.db is a v3 database, migrated from v2.
deleteFile("test/fixtures/offline_database/migrated.db");
- writeFile("test/fixtures/offline_database/migrated.db", util::read_file("test/fixtures/offline_database/v3.db"));
+ writeFile("test/fixtures/offline_database/migrated.db", util::readFile("test/fixtures/offline_database/v3.db"));
{
OfflineDatabase db("test/fixtures/offline_database/migrated.db", 0);
@@ -649,7 +649,7 @@ TEST(OfflineDatabase, MigrateFromV4Schema) {
// v4.db is a v4 database, migrated from v2 & v3. This database used `journal_mode = WAL` and `synchronous = NORMAL`.
deleteFile("test/fixtures/offline_database/migrated.db");
- writeFile("test/fixtures/offline_database/migrated.db", util::read_file("test/fixtures/offline_database/v4.db"));
+ writeFile("test/fixtures/offline_database/migrated.db", util::readFile("test/fixtures/offline_database/v4.db"));
{
OfflineDatabase db("test/fixtures/offline_database/migrated.db", 0);
@@ -675,7 +675,7 @@ TEST(OfflineDatabase, MigrateFromV5Schema) {
// v5.db is a v5 database, migrated from v2, v3 & v4.
deleteFile("test/fixtures/offline_database/migrated.db");
- writeFile("test/fixtures/offline_database/migrated.db", util::read_file("test/fixtures/offline_database/v5.db"));
+ writeFile("test/fixtures/offline_database/migrated.db", util::readFile("test/fixtures/offline_database/v5.db"));
{
OfflineDatabase db("test/fixtures/offline_database/migrated.db", 0);
@@ -703,7 +703,7 @@ TEST(OfflineDatabase, DowngradeSchema) {
// and recreated with the current schema.
deleteFile("test/fixtures/offline_database/migrated.db");
- writeFile("test/fixtures/offline_database/migrated.db", util::read_file("test/fixtures/offline_database/v999.db"));
+ writeFile("test/fixtures/offline_database/migrated.db", util::readFile("test/fixtures/offline_database/v999.db"));
{
OfflineDatabase db("test/fixtures/offline_database/migrated.db", 0);
diff --git a/test/storage/offline_download.test.cpp b/test/storage/offline_download.test.cpp
index 57780eba40..f7528fb024 100644
--- a/test/storage/offline_download.test.cpp
+++ b/test/storage/offline_download.test.cpp
@@ -14,7 +14,6 @@
#include <iostream>
using namespace mbgl;
-using namespace std::literals::string_literals;
class MockObserver : public OfflineRegionObserver {
public:
@@ -50,10 +49,11 @@ public:
Response response(const std::string& path) {
Response result;
- result.data = std::make_shared<std::string>(util::read_file("test/fixtures/offline_download/"s + path));
- size_t uncompressed = result.data->size();
- size_t compressed = util::compress(*result.data).size();
- size += std::min(uncompressed, compressed);
+ result.data = util::readFile("test/fixtures/offline_download/" + path);
+ const auto data = util::isCompressible(*result.data.uncompressedData())
+ ? result.data.compressedData()
+ : result.data.uncompressedData();
+ size += data->size();
return result;
}
};
diff --git a/test/storage/online_file_source.test.cpp b/test/storage/online_file_source.test.cpp
index 70bfe3ac95..9744c0a02e 100644
--- a/test/storage/online_file_source.test.cpp
+++ b/test/storage/online_file_source.test.cpp
@@ -33,8 +33,8 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(CancelMultiple)) {
std::unique_ptr<AsyncRequest> req = fs.request(resource, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Hello World!", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Hello World!", *res.data.uncompressedData());
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -61,7 +61,7 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(TemporaryError)) {
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::Server, res.error->reason);
EXPECT_EQ("HTTP status code 500", res.error->message);
- ASSERT_FALSE(bool(res.data));
+ ASSERT_FALSE(res.data);
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -72,8 +72,8 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(TemporaryError)) {
EXPECT_LT(0.99, duration) << "Backoff timer didn't wait 1 second";
EXPECT_GT(1.2, duration) << "Backoff timer fired too late";
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Hello World!", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Hello World!", *res.data.uncompressedData());
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -100,7 +100,7 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(ConnectionError)) {
EXPECT_GT(wait + 0.2, duration) << "Backoff timer fired too late";
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::Connection, res.error->reason);
- ASSERT_FALSE(res.data.get());
+ ASSERT_FALSE(res.data);
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -127,8 +127,8 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(Timeout)) {
std::unique_ptr<AsyncRequest> req = fs.request(resource, [&](Response res) {
counter++;
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Hello World!", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Hello World!", *res.data.uncompressedData());
EXPECT_TRUE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -244,8 +244,8 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(Load)) {
[&, i, current](Response res) {
reqs[i].reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ(std::string("Request ") + std::to_string(current), *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ(std::string("Request ") + std::to_string(current), *res.data.uncompressedData());
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -282,8 +282,8 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(NetworkStatusChange)) {
std::unique_ptr<AsyncRequest> req = fs.request(resource, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
- EXPECT_EQ("Response", *res.data);
+ ASSERT_TRUE(res.data);
+ EXPECT_EQ("Response", *res.data.uncompressedData());
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -322,7 +322,7 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(NetworkStatusChangePreempt)) {
}
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::Connection, res.error->reason);
- ASSERT_FALSE(res.data.get());
+ ASSERT_FALSE(res.data);
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(res.mustRevalidate);
EXPECT_FALSE(bool(res.modified));
@@ -361,7 +361,7 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(NetworkStatusOnlineOffline)) {
req.reset();
EXPECT_EQ(nullptr, res.error);
- ASSERT_TRUE(res.data.get());
+ ASSERT_TRUE(res.data);
EXPECT_EQ(NetworkStatus::Get(), NetworkStatus::Status::Online) << "Triggered before set back to Online";
diff --git a/test/style/expression/expression.test.cpp b/test/style/expression/expression.test.cpp
index 694569695c..c40f3fb863 100644
--- a/test/style/expression/expression.test.cpp
+++ b/test/style/expression/expression.test.cpp
@@ -16,8 +16,9 @@ using namespace mbgl;
using namespace mbgl::style;
TEST(Expression, IsExpression) {
+ const auto file = util::readFile("mapbox-gl-js/src/style-spec/reference/v8.json").uncompressedData();
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> spec;
- spec.Parse<0>(util::read_file("mapbox-gl-js/src/style-spec/reference/v8.json").c_str());
+ spec.Parse<0>(file->c_str());
ASSERT_FALSE(spec.HasParseError());
ASSERT_TRUE(spec.IsObject() &&
spec.HasMember("expression_name") &&
@@ -44,8 +45,9 @@ TEST_P(ExpressionEqualityTest, ExpressionEquality) {
std::string error;
auto parse = [&](std::string filename, std::string& error_) -> std::unique_ptr<expression::Expression> {
+ const auto file = util::readFile(filename).uncompressedData();
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> document;
- document.Parse<0>(util::read_file(filename).c_str());
+ document.Parse<0>(file->c_str());
assert(!document.HasParseError());
const JSValue* expression = &document;
expression::ParsingContext ctx;
diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp
index 6cb01146f6..94eb66a789 100644
--- a/test/style/source.test.cpp
+++ b/test/style/source.test.cpp
@@ -121,7 +121,7 @@ TEST(Source, LoadingCorrupt) {
test.fileSource.sourceResponse = [&] (const Resource& resource) {
EXPECT_EQ("url", resource.url);
Response response;
- response.data = std::make_unique<std::string>("CORRUPTED");
+ response.data = Blob{ "CORRUPTED", false };
return response;
};
@@ -375,7 +375,7 @@ TEST(Source, RasterTileCorrupt) {
test.fileSource.tileResponse = [&] (const Resource&) {
Response response;
- response.data = std::make_unique<std::string>("CORRUPTED");
+ response.data = Blob{ "CORRUPTED", false };
return response;
};
@@ -412,7 +412,7 @@ TEST(Source, RasterDEMTileCorrupt) {
test.fileSource.tileResponse = [&] (const Resource&) {
Response response;
- response.data = std::make_unique<std::string>("CORRUPTED");
+ response.data = Blob{ "CORRUPTED", false };
return response;
};
@@ -449,7 +449,7 @@ TEST(Source, VectorTileCorrupt) {
test.fileSource.tileResponse = [&] (const Resource&) {
Response response;
- response.data = std::make_unique<std::string>("CORRUPTED");
+ response.data = Blob{ "CORRUPTED", false };
return response;
};
@@ -610,9 +610,10 @@ TEST(Source, RasterTileAttribution) {
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");
+ response.data =
+ Blob{ R"TILEJSON({ "tilejson": "2.1.0", "attribution": ")TILEJSON" + mapboxOSM +
+ R"TILEJSON(", "tiles": [ "tiles" ] })TILEJSON",
+ false };
return response;
};
@@ -653,9 +654,10 @@ TEST(Source, RasterDEMTileAttribution) {
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");
+ response.data =
+ Blob{ R"TILEJSON({ "tilejson": "2.1.0", "attribution": ")TILEJSON" + mapbox +
+ R"TILEJSON(", "tiles": [ "tiles" ] })TILEJSON",
+ false };
return response;
};
@@ -684,7 +686,7 @@ TEST(Source, GeoJSonSourceUrlUpdate) {
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 = Blob{ R"({"geometry": {"type": "Point", "coordinates": [1.1, 1.1]}, "type": "Feature", "properties": {}})", false };
return response;
};
@@ -714,7 +716,7 @@ TEST(Source, ImageSourceImageUpdate) {
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"));
+ response.data = util::readFile("test/fixtures/image/no_profile.png");
return response;
};
test.styleObserver.sourceChanged = [&] (Source&) {
diff --git a/test/style/style.test.cpp b/test/style/style.test.cpp
index 9bdab37ac6..91ecbe8d22 100644
--- a/test/style/style.test.cpp
+++ b/test/style/style.test.cpp
@@ -23,27 +23,27 @@ TEST(Style, Properties) {
StubFileSource fileSource;
Style::Impl style { threadPool, fileSource, 1.0 };
- style.loadJSON(R"STYLE({"name": "Test"})STYLE");
+ style.loadJSON(Blob{ R"STYLE({"name": "Test"})STYLE", false });
ASSERT_EQ("Test", style.getName());
- style.loadJSON(R"STYLE({"center": [10, 20]})STYLE");
+ style.loadJSON(Blob{ R"STYLE({"center": [10, 20]})STYLE", false });
ASSERT_EQ("", style.getName());
ASSERT_EQ((LatLng{20, 10}), *style.getDefaultCamera().center);
- style.loadJSON(R"STYLE({"bearing": 24})STYLE");
+ style.loadJSON(Blob{ R"STYLE({"bearing": 24})STYLE", false });
ASSERT_EQ("", style.getName());
ASSERT_EQ(LatLng {}, *style.getDefaultCamera().center);
ASSERT_EQ(24, *style.getDefaultCamera().angle);
- style.loadJSON(R"STYLE({"zoom": 13.3})STYLE");
+ style.loadJSON(Blob{ R"STYLE({"zoom": 13.3})STYLE", false });
ASSERT_EQ("", style.getName());
ASSERT_EQ(13.3, *style.getDefaultCamera().zoom);
- style.loadJSON(R"STYLE({"pitch": 60})STYLE");
+ style.loadJSON(Blob{ R"STYLE({"pitch": 60})STYLE", false });
ASSERT_EQ("", style.getName());
ASSERT_EQ(60, *style.getDefaultCamera().pitch);
- style.loadJSON(R"STYLE({"name": 23, "center": {}, "bearing": "north", "zoom": null, "pitch": "wide"})STYLE");
+ style.loadJSON(Blob{ R"STYLE({"name": 23, "center": {}, "bearing": "north", "zoom": null, "pitch": "wide"})STYLE", false });
ASSERT_EQ("", style.getName());
ASSERT_EQ(LatLng {}, *style.getDefaultCamera().center);
ASSERT_EQ(0, *style.getDefaultCamera().zoom);
@@ -58,7 +58,7 @@ TEST(Style, DuplicateSource) {
StubFileSource fileSource;
Style::Impl style { threadPool, fileSource, 1.0 };
- style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
+ style.loadJSON(util::readFile("test/fixtures/resources/style-unused-sources.json"));
style.addSource(std::make_unique<VectorSource>("sourceId", "mapbox://mapbox.mapbox-terrain-v2"));
@@ -80,7 +80,7 @@ TEST(Style, RemoveSourceInUse) {
StubFileSource fileSource;
Style::Impl style { threadPool, fileSource, 1.0 };
- style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
+ style.loadJSON(util::readFile("test/fixtures/resources/style-unused-sources.json"));
style.addSource(std::make_unique<VectorSource>("sourceId", "mapbox://mapbox.mapbox-terrain-v2"));
style.addLayer(std::make_unique<LineLayer>("layerId", "sourceId"));
diff --git a/test/style/style_layer.test.cpp b/test/style/style_layer.test.cpp
index 77acca2868..36fd7de3f4 100644
--- a/test/style/style_layer.test.cpp
+++ b/test/style/style_layer.test.cpp
@@ -276,7 +276,7 @@ TEST(Layer, DuplicateLayer) {
ThreadPool threadPool{ 1 };
StubFileSource fileSource;
Style::Impl style { threadPool, fileSource, 1.0 };
- style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
+ style.loadJSON(util::readFile("test/fixtures/resources/style-unused-sources.json"));
// Add initial layer
style.addLayer(std::make_unique<LineLayer>("line", "unusedsource"));
diff --git a/test/style/style_parser.test.cpp b/test/style/style_parser.test.cpp
index 43b982c3b9..c6b78cf6d6 100644
--- a/test/style/style_parser.test.cpp
+++ b/test/style/style_parser.test.cpp
@@ -24,16 +24,18 @@ class StyleParserTest : public ::testing::TestWithParam<std::string> {};
TEST_P(StyleParserTest, ParseStyle) {
const std::string base = std::string("test/fixtures/style_parser/") + GetParam();
+ const auto infoFile = util::readFile(base + ".info.json").uncompressedData();
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> infoDoc;
- infoDoc.Parse<0>(util::read_file(base + ".info.json").c_str());
+ infoDoc.Parse<0>(infoFile->c_str());
ASSERT_FALSE(infoDoc.HasParseError());
ASSERT_TRUE(infoDoc.IsObject());
auto observer = new FixtureLogObserver();
Log::setObserver(std::unique_ptr<Log::Observer>(observer));
+ const auto styleFile = util::readFile(base + ".style.json").uncompressedData();
style::Parser parser;
- auto error = parser.parse(util::read_file(base + ".style.json"));
+ auto error = parser.parse(*styleFile);
if (error) {
Log::Error(Event::ParseStyle, "Failed to parse style: %s", util::toString(error).c_str());
@@ -95,7 +97,7 @@ INSTANTIATE_TEST_CASE_P(StyleParser, StyleParserTest, ::testing::ValuesIn([] {
TEST(StyleParser, FontStacks) {
style::Parser parser;
- parser.parse(util::read_file("test/fixtures/style_parser/font_stacks.json"));
+ parser.parse(*util::readFile("test/fixtures/style_parser/font_stacks.json").uncompressedData());
auto result = parser.fontStacks();
ASSERT_EQ(3u, result.size());
ASSERT_EQ(FontStack({"a"}), result[0]);
diff --git a/test/text/glyph_manager.test.cpp b/test/text/glyph_manager.test.cpp
index a96e1b970c..be1c13eefc 100644
--- a/test/text/glyph_manager.test.cpp
+++ b/test/text/glyph_manager.test.cpp
@@ -92,7 +92,7 @@ TEST(GlyphManager, LoadingSuccess) {
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"));
+ response.data = util::readFile("test/fixtures/resources/glyphs.pbf");
return response;
};
@@ -163,7 +163,7 @@ TEST(GlyphManager, LoadingCorrupted) {
test.fileSource.glyphsResponse = [&] (const Resource&) {
Response response;
- response.data = std::make_unique<std::string>("CORRUPTED");
+ response.data = Blob{ "CORRUPTED", false };
return response;
};
@@ -260,7 +260,7 @@ TEST(GlyphManager, LoadingInvalid) {
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"));
+ response.data = util::readFile("test/fixtures/resources/fake_glyphs-0-255.pbf");
return response;
};
@@ -320,7 +320,7 @@ TEST(GlyphManager, ImmediateFileSource) {
test.fileSource.glyphsResponse = [&] (const Resource&) {
Response response;
- response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/glyphs.pbf"));
+ response.data = util::readFile("test/fixtures/resources/glyphs.pbf");
return response;
};
diff --git a/test/text/glyph_pbf.test.cpp b/test/text/glyph_pbf.test.cpp
index c222ec1dd9..8c6b8a2028 100644
--- a/test/text/glyph_pbf.test.cpp
+++ b/test/text/glyph_pbf.test.cpp
@@ -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::readFile("test/fixtures/resources/fake_glyphs-0-255.pbf"));
EXPECT_TRUE(sdfs.size() == 1);
auto& sdf = sdfs[0];
diff --git a/test/text/local_glyph_rasterizer.test.cpp b/test/text/local_glyph_rasterizer.test.cpp
index 84c685d66f..49ef1e18ef 100644
--- a/test/text/local_glyph_rasterizer.test.cpp
+++ b/test/text/local_glyph_rasterizer.test.cpp
@@ -60,10 +60,10 @@ TEST(LocalGlyphRasterizer, PingFang) {
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"));
+ response.data = util::readFile("test/fixtures/resources/glyphs.pbf");
return response;
};
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/local_glyphs/mixed.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/local_glyphs/mixed.json"));
test.checkRendering("ping_fang");
}
@@ -77,10 +77,10 @@ TEST(LocalGlyphRasterizer, NoLocal) {
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"));
+ response.data = util::readFile("test/fixtures/resources/glyphs.pbf");
return response;
};
- test.map.getStyle().loadJSON(util::read_file("test/fixtures/local_glyphs/mixed.json"));
+ test.map.getStyle().loadJSON(util::readFile("test/fixtures/local_glyphs/mixed.json"));
test.checkRendering("no_local");
}
diff --git a/test/util/image.test.cpp b/test/util/image.test.cpp
index f4a6473040..f9389a694a 100644
--- a/test/util/image.test.cpp
+++ b/test/util/image.test.cpp
@@ -35,7 +35,7 @@ TEST(Image, PNGRoundTripAlpha) {
}
TEST(Image, PNGReadNoProfile) {
- PremultipliedImage image = decodeImage(util::read_file("test/fixtures/image/no_profile.png"));
+ PremultipliedImage image = decodeImage(util::readFile("test/fixtures/image/no_profile.png"));
EXPECT_EQ(128, image.data[0]);
EXPECT_EQ(0, image.data[1]);
EXPECT_EQ(0, image.data[2]);
@@ -43,7 +43,7 @@ TEST(Image, PNGReadNoProfile) {
}
TEST(Image, PNGReadNoProfileAlpha) {
- PremultipliedImage image = decodeImage(util::read_file("test/fixtures/image/no_profile_alpha.png"));
+ PremultipliedImage image = decodeImage(util::readFile("test/fixtures/image/no_profile_alpha.png"));
EXPECT_EQ(64, image.data[0]);
EXPECT_EQ(0, image.data[1]);
EXPECT_EQ(0, image.data[2]);
@@ -51,7 +51,7 @@ TEST(Image, PNGReadNoProfileAlpha) {
}
TEST(Image, PNGReadProfile) {
- PremultipliedImage image = decodeImage(util::read_file("test/fixtures/image/profile.png"));
+ PremultipliedImage image = decodeImage(util::readFile("test/fixtures/image/profile.png"));
EXPECT_EQ(128, image.data[0]);
EXPECT_EQ(0, image.data[1]);
EXPECT_EQ(0, image.data[2]);
@@ -59,7 +59,7 @@ TEST(Image, PNGReadProfile) {
}
TEST(Image, PNGReadProfileAlpha) {
- PremultipliedImage image = decodeImage(util::read_file("test/fixtures/image/profile_alpha.png"));
+ PremultipliedImage image = decodeImage(util::readFile("test/fixtures/image/profile_alpha.png"));
EXPECT_EQ(64, image.data[0]);
EXPECT_EQ(0, image.data[1]);
EXPECT_EQ(0, image.data[2]);
@@ -67,20 +67,20 @@ TEST(Image, PNGReadProfileAlpha) {
}
TEST(Image, PNGTile) {
- PremultipliedImage image = decodeImage(util::read_file("test/fixtures/image/tile.png"));
+ PremultipliedImage image = decodeImage(util::readFile("test/fixtures/image/tile.png"));
EXPECT_EQ(256u, image.size.width);
EXPECT_EQ(256u, image.size.height);
}
TEST(Image, JPEGTile) {
- PremultipliedImage image = decodeImage(util::read_file("test/fixtures/image/tile.jpeg"));
+ PremultipliedImage image = decodeImage(util::readFile("test/fixtures/image/tile.jpeg"));
EXPECT_EQ(256u, image.size.width);
EXPECT_EQ(256u, image.size.height);
}
#if !defined(__ANDROID__) && !defined(__APPLE__) && !defined(QT_IMAGE_DECODERS)
TEST(Image, WebPTile) {
- PremultipliedImage image = decodeImage(util::read_file("test/fixtures/image/tile.webp"));
+ PremultipliedImage image = decodeImage(util::readFile("test/fixtures/image/tile.webp"));
EXPECT_EQ(256u, image.size.width);
EXPECT_EQ(256u, image.size.height);
}
diff --git a/test/util/memory.test.cpp b/test/util/memory.test.cpp
index 6befb521f0..4f14c762b4 100644
--- a/test/util/memory.test.cpp
+++ b/test/util/memory.test.cpp
@@ -45,9 +45,7 @@ private:
if (it != cache.end()) {
result.data = it->second;
} else {
- auto data = std::make_shared<std::string>(
- util::read_file("test/fixtures/resources/"s + path));
-
+ auto data = util::readFile("test/fixtures/resources/" + path);
cache.insert(it, std::make_pair(path, data));
result.data = data;
}
@@ -63,7 +61,7 @@ private:
}
};
- std::unordered_map<std::string, std::shared_ptr<std::string>> cache;
+ std::unordered_map<std::string, Blob> cache;
};
TEST(Memory, Vector) {