Merge pull request #453 from mapbox/fix-headless-basepath

Fix basepath for headless tests and correctly load %20 encoded paths
This commit is contained in:
Konstantin Käfer
2014-08-27 14:52:16 +02:00
6 changed files with 63 additions and 58 deletions

View File

@@ -7,6 +7,7 @@ namespace mbgl {
namespace util {
std::string percentEncode(const std::string&);
std::string percentDecode(const std::string&);
}
}

View File

@@ -56,45 +56,38 @@ void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> lay
const timestamp currentTime = util::now();
std::deque<FrameSnapshot> &history = frameHistory.history;
if (history.size() >= 2) {
// Remove frames until only one is outside the duration, or until there are only three
while (history.size() > 3 && history[1].t + duration < currentTime) {
history.pop_front();
}
// Remove frames until only one is outside the duration, or until there are only three
while (history.size() > 3 && history[1].t + duration < currentTime) {
history.pop_front();
if (history[1].t + duration < currentTime) {
history[0].z = history[1].z;
}
// Find the range of zoom levels we want to fade between
float startingZ = history.front().z;
const FrameSnapshot lastFrame = history.back();
float endingZ = lastFrame.z;
float lowZ = std::fmin(startingZ, endingZ);
float highZ = std::fmax(startingZ, endingZ);
// Calculate the speed of zooming, and how far it would zoom in terms of zoom levels in one
// duration
float zoomDiff = endingZ - history[1].z, timeDiff = lastFrame.t - history[1].t;
float fadedist = zoomDiff / (timeDiff / duration);
// At end of a zoom when the zoom stops changing continue pretending to zoom at that speed
// bump is how much farther it would have been if it had continued zooming at the same rate
float bump = (currentTime - lastFrame.t) / duration * fadedist;
textShader->setFadeDist(fadedist * 10);
textShader->setMinFadeZoom(std::floor(lowZ * 10));
textShader->setMaxFadeZoom(std::floor(highZ * 10));
textShader->setFadeZoom((map.getState().getNormalizedZoom() + bump) * 10);
}
if (history[1].t + duration < currentTime) {
history[0].z = history[1].z;
}
assert("there should never be less than three frames in the history" &&
(history.size() >= 3));
// Find the range of zoom levels we want to fade between
float startingZ = history.front().z;
const FrameSnapshot lastFrame = history.back();
float endingZ = lastFrame.z;
float lowZ = std::fmin(startingZ, endingZ);
float highZ = std::fmax(startingZ, endingZ);
// Calculate the speed of zooming, and how far it would zoom in terms of zoom levels in one
// duration
float zoomDiff = endingZ - history[1].z, timeDiff = lastFrame.t - history[1].t;
float fadedist = zoomDiff / (timeDiff / duration);
#if defined(DEBUG)
// if (std::isnan(fadedist))
// fprintf(stderr, "fadedist should never be NaN\n");
#endif
// At end of a zoom when the zoom stops changing continue pretending to zoom at that speed
// bump is how much farther it would have been if it had continued zooming at the same rate
float bump = (currentTime - lastFrame.t) / duration * fadedist;
textShader->setFadeDist(fadedist * 10);
textShader->setMinFadeZoom(std::floor(lowZ * 10));
textShader->setMaxFadeZoom(std::floor(highZ * 10));
textShader->setFadeZoom((map.getState().getNormalizedZoom() + bump) * 10);
// This defines the gamma around the SDF cutoff value.
const float sdfGamma = 1.0f / 10.0f;

View File

@@ -80,7 +80,7 @@ void getSegmentGlyphs(std::back_insert_iterator<GlyphInstances> glyphs, Anchor &
// skip duplicate nodes
while (newAnchor == end) {
segment += direction;
if ((int)line.size() <= segment) {
if ((int)line.size() <= segment || segment < 0) {
anchor.scale = scale;
return;
}

View File

@@ -4,6 +4,8 @@
#include <iomanip>
#include <sstream>
#include <string>
#include <cstdlib>
#include <algorithm>
namespace mbgl {
namespace util {
@@ -25,5 +27,25 @@ std::string percentEncode(const std::string& input) {
return encoded.str();
}
std::string percentDecode(const std::string& input) {
std::string decoded;
auto it = input.begin();
const auto end = input.end();
char hex[3] = "00";
while (it != end) {
auto cur = std::find(it, end, '%');
decoded.append(it, cur);
it = cur;
if (cur != end) {
it += input.copy(hex, 2, cur - input.begin() + 1) + 1;
decoded += static_cast<char>(std::strtoul(hex, nullptr, 16));
}
}
return decoded;
}
}
}

View File

@@ -1,12 +1,15 @@
#include <mbgl/platform/platform.hpp>
#include <mbgl/platform/request.hpp>
#include <mbgl/util/uv_detail.hpp>
#include <mbgl/util/url.hpp>
#include <mbgl/platform/log.hpp>
const std::string base_directory = []{
std::string fn = __FILE__;
fn.erase(fn.find_last_of("/"));
return fn;
fn.erase(fn.find_last_of("/"));
fn.erase(fn.find_last_of("/"));
return fn + "/node_modules/mapbox-gl-test-suite/";
}();
@@ -23,14 +26,11 @@ platform::request_http(const std::string &url,
l = uv_default_loop();
}
std::string clean_url = base_directory + "/" + url;
auto pos = clean_url.find("://");
if (pos != std::string::npos) {
clean_url.replace(pos, 3, "/");
std::string clean_url = util::percentDecode(url);
if (clean_url.find("local://") == 0) {
clean_url = base_directory + clean_url.substr(8);
}
std::replace(clean_url.begin(), clean_url.end(), '+', ' ');
std::shared_ptr<Request> req = std::make_shared<Request>(url, callback, loop);
int err;

View File

@@ -18,17 +18,12 @@
const std::string base_directory = []{
std::string fn = __FILE__;
fn.erase(fn.find_last_of("/"));
return fn + "/../node_modules/mapbox-gl-test-suite/";
fn.erase(fn.find_last_of("/"));
return fn + "/node_modules/mapbox-gl-test-suite/";
}();
class HeadlessTest : public ::testing::TestWithParam<std::string> {};
void ResolveLocalURL(rapidjson::Value& value, rapidjson::Document& doc) {
std::string str { value.GetString(), value.GetStringLength() };
str.replace(0, 8, base_directory); // local://
value.SetString(str.c_str(), str.length(), doc.GetAllocator());
}
TEST_P(HeadlessTest, render) {
using namespace mbgl;
@@ -43,12 +38,6 @@ TEST_P(HeadlessTest, render) {
ASSERT_EQ(false, styleDoc.HasParseError());
ASSERT_EQ(true, styleDoc.IsObject());
if (styleDoc.HasMember("sprite")) {
ResolveLocalURL(styleDoc["sprite"], styleDoc);
}
ResolveLocalURL(styleDoc["sources"]["mapbox"]["tiles"][rapidjson::SizeType(0)], styleDoc);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
styleDoc.Accept(writer);
@@ -91,7 +80,7 @@ TEST_P(HeadlessTest, render) {
}
}
map.setStyleJSON(style);
map.setStyleJSON(style, base_directory);
map.setAppliedClasses(classes);
view.resize(width, height);