execute the correct server path and use the exepath for application root rather than the cwd

This commit is contained in:
Konstantin Käfer
2015-01-23 02:54:20 -08:00
committed by Konstantin Käfer
parent 1c91f09fda
commit 6f349a796c
3 changed files with 18 additions and 6 deletions

View File

@@ -1,14 +1,28 @@
#include <mbgl/platform/platform.hpp>
#include <mbgl/util/uv.hpp>
#include <uv.h>
#include <libgen.h>
namespace mbgl {
namespace platform {
// Returns the path to the root folder of the application.
const std::string &applicationRoot() {
static const std::string root = uv::cwd();
static const std::string root = []() -> std::string {
size_t max = 0;
std::string dir;
do {
// Gradually increase the length of the string in case the path was truncated.
max += 256;
dir.resize(max);
uv_exepath(const_cast<char *>(dir.data()), &max);
} while (max == dir.size());
dir.resize(max - 1);
dir = dirname(const_cast<char *>(dir.c_str()));
return dir;
}();
return root;
}
}
}

View File

@@ -4,7 +4,6 @@
#include <mbgl/map/map.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/platform/platform.hpp>
#include <mbgl/util/io.hpp>
#include <rapidjson/document.h>
@@ -30,7 +29,7 @@ void rewriteLocalScheme(rapidjson::Value &value, rapidjson::Document::AllocatorT
class HeadlessTest : public ::testing::TestWithParam<std::string> {
public:
static void SetUpTestCase() {
const auto server = mbgl::platform::applicationRoot() + "/TEST_DATA/headless/server.js";
const auto server = mbgl::test::getBaseDirectory() + "/headless/server.js";
pid = mbgl::test::startServer(server.c_str());
display = std::make_shared<mbgl::HeadlessDisplay>();
}

View File

@@ -1,10 +1,9 @@
#include "storage.hpp"
#include <mbgl/platform/platform.hpp>
pid_t Storage::pid = 0;
void Storage::SetUpTestCase() {
const auto server = mbgl::platform::applicationRoot() + "/TEST_DATA/storage/server.js";
const auto server = mbgl::test::getBaseDirectory() + "/storage/server.js";
pid = mbgl::test::startServer(server.c_str());
}