Merge branch 'master' of https://github.com/mapbox/mapbox-gl-native into android-mason

Conflicts:
	gyp/common.gypi
	include/mbgl/geometry/vao.hpp
	include/mbgl/platform/event.hpp
	include/mbgl/platform/gl.hpp
	platform/default/http_request_baton_curl.cpp
	src/storage/response.cpp
This commit is contained in:
Leith Bade
2014-11-09 00:35:52 +11:00
21 changed files with 396 additions and 231 deletions

View File

@@ -17,9 +17,21 @@
#include <dirent.h>
#include <signal.h>
#include <libgen.h>
#ifdef __linux__
#include <sys/prctl.h>
#endif
std::string base_directory;
namespace mbgl {
namespace platform {
std::string defaultCacheDatabase() {
// Disables the cache.
return "";
}
}
}
class ServerEnvironment : public ::testing::Environment {
public:
@@ -28,8 +40,13 @@ public:
if (pid < 0) {
throw std::runtime_error("Cannot create web server");
} else if (pid == 0) {
char *arg[] = { nullptr };
int ret = execv((base_directory + "bin/server.py").c_str(), arg);
#ifdef __linux__
prctl(PR_SET_PDEATHSIG, SIGHUP);
#endif
const auto executable = base_directory + "bin/server.py";
const char *port = "2900";
char *arg[] = { const_cast<char *>(executable.c_str()), const_cast<char *>(port), nullptr };
int ret = execv(executable.c_str(), arg);
// This call should not return. In case execve failed, we exit anyway.
if (ret < 0) {
fprintf(stderr, "Failed to start server: %s\n", strerror(errno));
@@ -56,9 +73,14 @@ ServerEnvironment* env = nullptr;
GTEST_API_ int main(int argc, char *argv[]) {
// Note: glibc's dirname() **modifies** the argument and can't handle static strings.
std::string argv0 { argv[0] }; argv0 = dirname(const_cast<char *>(argv0.c_str()));
std::string file { __FILE__ }; file = dirname(const_cast<char *>(file.c_str()));
base_directory = argv0 + "/" + file + "/suite/";
if (file[0] == '/') {
// If __FILE__ is an absolute path, we don't have to guess from the argv 0.
base_directory = file + "/suite/";
} else {
std::string argv0 { argv[0] }; argv0 = dirname(const_cast<char *>(argv0.c_str()));
base_directory = argv0 + "/" + file + "/suite/";
}
testing::InitGoogleTest(&argc, argv);
env = new ServerEnvironment();
@@ -66,6 +88,15 @@ GTEST_API_ int main(int argc, char *argv[]) {
return RUN_ALL_TESTS();
}
void rewriteLocalScheme(rapidjson::Value &value, rapidjson::Document::AllocatorType &allocator) {
ASSERT_TRUE(value.IsString());
auto string = std::string { value.GetString(),value.GetStringLength() };
if (string.compare(0, 8, "local://") == 0) {
string.replace(0, 8, "http://127.0.0.1:2900/");
value.SetString(string.data(), string.size(), allocator);
}
}
class HeadlessTest : public ::testing::TestWithParam<std::string> {};
TEST_P(HeadlessTest, render) {
@@ -76,17 +107,40 @@ TEST_P(HeadlessTest, render) {
std::string style = util::read_file(base_directory + "tests/" + base + "/style.json");
std::string info = util::read_file(base_directory + "tests/" + base + "/info.json");
std::size_t pos = 0;
while ((pos = style.find("local://", pos)) != std::string::npos) {
style.replace(pos, 8, "http://localhost:2900/");
}
// Parse style.
rapidjson::Document styleDoc;
styleDoc.Parse<0>((const char *const)style.c_str());
ASSERT_FALSE(styleDoc.HasParseError());
ASSERT_TRUE(styleDoc.IsObject());
// Rewrite "local://" to "http://127.0.0.1:2900/".
if (styleDoc.HasMember("sprite")) {
rewriteLocalScheme(styleDoc["sprite"], styleDoc.GetAllocator());
}
if (styleDoc.HasMember("glyphs")) {
rewriteLocalScheme(styleDoc["glyphs"], styleDoc.GetAllocator());
}
if (styleDoc.HasMember("sources")) {
auto &sources = styleDoc["sources"];
ASSERT_TRUE(sources.IsObject());
for (auto source = sources.MemberBegin(), end = sources.MemberEnd(); source != end; source++) {
if (source->value.HasMember("tiles")) {
auto &tiles = source->value["tiles"];
ASSERT_TRUE(tiles.IsArray());
for (rapidjson::SizeType i = 0; i < tiles.Size(); i++) {
rewriteLocalScheme(tiles[i], styleDoc.GetAllocator());
}
}
if (source->value.HasMember("url")) {
rewriteLocalScheme(source->value["url"], styleDoc.GetAllocator());
}
}
}
// Convert the JSON object back into a stringified version.
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
styleDoc.Accept(writer);

View File

@@ -198,9 +198,19 @@
'../mapboxgl.gyp:mbgl-standalone',
'<(platform_library)',
],
'variables': {
'cflags_cc': [
'-I<(boost_root)/include',
]
},
'conditions': [
['OS == "mac"', { 'xcode_settings': { 'OTHER_LDFLAGS': [ '<@(ldflags)', '-framework Foundation' ] }
['OS == "mac"', {
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS': [ '<@(cflags_cc)' ],
'OTHER_LDFLAGS': [ '<@(ldflags)', '-framework Foundation' ]
},
}, {
'cflags_cc': [ '<@(cflags_cc)' ],
'libraries': [ '<@(ldflags)'],
}]
]