summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Morris <michael.patrick.morris@gmail.com>2014-10-10 12:24:45 -0400
committerMike Morris <michael.patrick.morris@gmail.com>2014-10-10 12:24:45 -0400
commit2d1219fa5154c489cd856bedd04b84573d45ac04 (patch)
treea8e42e6acd79f73aac228e0fe6876917067db8c4 /test
parent8f6e8eead12c6b2c2de0ce76fa7df39ca2445006 (diff)
parentf390dab0ea7d449bdd89855c84e47f4a07606fe4 (diff)
downloadqtlocation-mapboxgl-2d1219fa5154c489cd856bedd04b84573d45ac04.tar.gz
Merge branch 'master' into libuv-0.10-headless-display
Conflicts: common/curl_request.cpp common/glfw_view.cpp common/glfw_view.hpp include/mbgl/platform/request.hpp ios/mapbox-gl-cocoa setup-libraries.sh src/map/map.cpp src/platform/request.cpp test/fixtures/fixture_request.cpp
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/fixture_request.cpp130
1 files changed, 37 insertions, 93 deletions
diff --git a/test/fixtures/fixture_request.cpp b/test/fixtures/fixture_request.cpp
index 417958a33d..b37cd92bee 100644
--- a/test/fixtures/fixture_request.cpp
+++ b/test/fixtures/fixture_request.cpp
@@ -1,10 +1,16 @@
-#include <mbgl/platform/platform.hpp>
-#include <mbgl/platform/request.hpp>
-#include <mbgl/util/uv_detail.hpp>
+#include <mbgl/storage/http_request_baton.hpp>
+#include <mbgl/storage/file_request_baton.hpp>
+#include <mbgl/storage/response.hpp>
#include <mbgl/util/url.hpp>
+#include <mbgl/util/std.hpp>
#include <mbgl/platform/log.hpp>
#include <iostream>
+#include <uv.h>
+
+#include <cassert>
+
+
const std::string base_directory = []{
std::string fn = __FILE__;
fn.erase(fn.find_last_of("/"));
@@ -13,110 +19,48 @@ const std::string base_directory = []{
return fn + "/node_modules/mapbox-gl-test-suite/";
}();
-
namespace mbgl {
-std::shared_ptr<platform::Request>
-platform::request_http(const std::string &url,
- std::function<void(Response *)> callback,
- std::shared_ptr<uv::loop> loop) {
- uv_loop_t *l = nullptr;
- if (loop) {
- l = **loop;
- } else {
- l = uv_default_loop();
- }
+void HTTPRequestBaton::start(const util::ptr<HTTPRequestBaton> &baton) {
+ assert(uv_thread_self() == baton->thread_id);
- std::string clean_url = util::percentDecode(url);
+ std::string clean_url = util::percentDecode(baton->path);
if (clean_url.find("local://") == 0) {
clean_url = base_directory + clean_url.substr(8);
}
- std::shared_ptr<Request> req = std::make_shared<Request>(url, callback, loop);
-
- int err;
-
- std::string body;
- FILE *file = std::fopen(clean_url.c_str(),"rb");
-
- if (file != NULL)
- {
- std::fseek(file, 0, SEEK_END);
- std::size_t file_size = std::ftell(file);
- std::fseek(file, 0, SEEK_SET);
- body.resize(file_size);
- std::fread(&body[0], file_size, 1, file);
- std::fclose(file);
- }
-
- /*
- uv_fs_t open_req;
- err = uv_fs_open(l, &open_req, clean_url.c_str(), O_RDONLY, S_IRUSR, nullptr);
- uv_fs_req_cleanup(&open_req);
- if (err < 0) {
- req->res->code = err;
- req->res->error_message = uv_strerror(uv_last_error(l));
- Log::Warning(Event::HttpRequest, err, url + ": " + uv_strerror(uv_last_error(l)));
- req->complete();
- return req;
- }
- uv_file fd = err;
-
- uv_fs_t stat_req;
- uv_fs_fstat(l, &stat_req, fd, nullptr);
- uv_fs_req_cleanup(&stat_req);
- err = uv_fs_fstat(l, &stat_req, fd, nullptr);
- if (err < 0) {
- req->res->code = err;
- req->res->error_message = uv_strerror(uv_last_error(l));
- Log::Warning(Event::HttpRequest, err, url + ": " + uv_strerror(uv_last_error(l)));
- req->complete();
- return req;
- }
-
- const uint64_t size = static_cast<const uv_statbuf_t*>(stat_req.ptr)->st_size;
-
-
- std::string body;
- body.resize(size);
- uv_buf_t uvbuf = uv_buf_init(const_cast<char *>(body.data()), body.size());
-
- uv_fs_t read_req;
- err = uv_fs_read(l, &read_req, fd, &uvbuf, 1, 0, nullptr);
- uv_fs_req_cleanup(&read_req);
- if (err < 0) {
- req->res->code = err;
- req->res->error_message = uv_strerror(uv_last_error(l));
- Log::Warning(Event::HttpRequest, err, url + ": " + uv_strerror(uv_last_error(l)));
- req->complete();
- return req;
+ baton->response = std::make_unique<Response>();
+ FILE *file = fopen(clean_url.c_str(),"rb");
+ if (file != NULL) {
+ fseek(file, 0, SEEK_END);
+ const size_t size = ftell(file);
+ fseek(file, 0, SEEK_SET);
+ baton->response->data.resize(size);
+ fread(&baton->response->data[0], size, 1, file);
+ fclose(file);
+
+ baton->response->code = 200;
+ baton->type = HTTPResponseType::Successful;
+ } else {
+ baton->type = HTTPResponseType::PermanentError;
+ baton->response->code = 404;
}
+ uv_async_send(baton->async);
+}
- uv_fs_t close_req;
- err = uv_fs_close(l, &close_req, fd, nullptr);
- uv_fs_req_cleanup(&close_req);
- if (err < 0) {
- req->res->code = err;
- req->res->error_message = uv_strerror(uv_last_error(l));
- Log::Warning(Event::HttpRequest, err, url + ": " + uv_strerror(uv_last_error(l)));
- req->complete();
- return req;
- }
- */
+void HTTPRequestBaton::stop(const util::ptr<HTTPRequestBaton> &baton) {
+ fprintf(stderr, "HTTP request cannot be canceled because it is answered immediately");
+ abort();
+}
- req->res->body.swap(body);
- req->res->code = 200;
- Log::Info(Event::HttpRequest, 200, url);
- req->complete();
+namespace platform {
- return req;
+std::string defaultCacheDatabase() {
+ // Disables the cache.
+ return "";
}
-void platform::cancel_request_http(const std::shared_ptr<Request> &req) {
- if (req) {
- req->cancelled = true;
- }
}
}