本文整理汇总了C++中OnlineFileSource类的典型用法代码示例。如果您正苦于以下问题:C++ OnlineFileSource类的具体用法?C++ OnlineFileSource怎么用?C++ OnlineFileSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OnlineFileSource类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST
TEST(OnlineFileSource, TEST_REQUIRES_SERVER(RespectPriorExpires)) {
util::RunLoop loop;
OnlineFileSource fs;
// Very long expiration time, should never arrive.
Resource resource1{ Resource::Unknown, "http://127.0.0.1:3000/test" };
resource1.priorExpires = util::now() + Seconds(100000);
std::unique_ptr<AsyncRequest> req1 = fs.request(resource1, [&](Response) {
FAIL() << "Should never be called";
});
// No expiration time, should be requested immediately.
Resource resource2{ Resource::Unknown, "http://127.0.0.1:3000/test" };
std::unique_ptr<AsyncRequest> req2 = fs.request(resource2, [&](Response) {
loop.stop();
});
// Very long expiration time, should never arrive.
Resource resource3{ Resource::Unknown, "http://127.0.0.1:3000/test" };
resource3.priorExpires = util::now() + Seconds(100000);
std::unique_ptr<AsyncRequest> req3 = fs.request(resource3, [&](Response) {
FAIL() << "Should never be called";
});
loop.run();
}
示例2: TEST_F
#include "storage.hpp"
#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
#include <cmath>
TEST_F(Storage, HTTPExpiresParsing) {
SCOPED_TEST(HTTPExpiresTest)
using namespace mbgl;
util::RunLoop loop;
OnlineFileSource fs(nullptr);
std::unique_ptr<FileRequest> req1 = fs.request({ Resource::Unknown,
"http://127.0.0.1:3000/test?modified=1420794326&expires=1420797926&etag=foo" },
[&](Response res) {
req1.reset();
EXPECT_EQ(nullptr, res.error);
EXPECT_EQ(false, res.stale);
ASSERT_TRUE(res.data.get());
EXPECT_EQ("Hello World!", *res.data);
EXPECT_EQ(1420797926, res.expires.count());
EXPECT_EQ(1420794326, res.modified.count());
EXPECT_EQ("foo", res.etag);
loop.stop();
HTTPExpiresTest.finish();
});
示例3: TEST_F
#include "storage.hpp"
#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
TEST_F(Storage, HTTPLoad) {
SCOPED_TEST(HTTPLoad)
using namespace mbgl;
util::RunLoop loop;
OnlineFileSource fs(nullptr);
const int concurrency = 50;
const int max = 10000;
int number = 1;
std::unique_ptr<FileRequest> reqs[concurrency];
std::function<void(int)> req = [&](int i) {
const auto current = number++;
reqs[i] = fs.request({ Resource::Unknown,
std::string("http://127.0.0.1:3000/load/") + std::to_string(current) },
[&, i, current](Response res) {
reqs[i].reset();
EXPECT_EQ(nullptr, res.error);
EXPECT_EQ(false, res.stale);
ASSERT_TRUE(res.data.get());
EXPECT_EQ(std::string("Request ") + std::to_string(current), *res.data);
EXPECT_EQ(Seconds::zero(), res.expires);
示例4: TEST_F
#include "storage.hpp"
#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
#include <cmath>
TEST_F(Storage, HTTPCancel) {
SCOPED_TEST(HTTPCancel)
using namespace mbgl;
util::RunLoop loop;
OnlineFileSource fs(nullptr);
auto req =
fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" },
[&](Response) { ADD_FAILURE() << "Callback should not be called"; });
req.reset();
HTTPCancel.finish();
loop.runOnce();
}
TEST_F(Storage, HTTPCancelMultiple) {
SCOPED_TEST(HTTPCancelMultiple)
using namespace mbgl;
示例5: TEST_F
#include "storage.hpp"
#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
#include <cmath>
TEST_F(Storage, TEST_REQUIRES_SERVER(HTTPTemporaryError)) {
SCOPED_TEST(HTTPTemporaryError)
using namespace mbgl;
util::RunLoop loop;
OnlineFileSource fs;
const auto start = Clock::now();
std::unique_ptr<AsyncRequest> req1 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/temporary-error" }, [&](Response res) {
static int counter = 0;
switch (counter++) {
case 0: {
const auto duration = std::chrono::duration<const double>(Clock::now() - start).count();
EXPECT_GT(0.2, duration) << "Initial error request took too long";
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));
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(bool(res.modified));
示例6: TEST_F
#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/util/exception.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/thread_context.hpp>
#include <future>
TEST_F(Storage, HTTPTest) {
SCOPED_TEST(HTTPTest)
using namespace mbgl;
util::RunLoop loop;
OnlineFileSource fs(nullptr);
std::unique_ptr<FileRequest> req1 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" },
[&](Response res) {
req1.reset();
EXPECT_TRUE(util::ThreadContext::currentlyOn(util::ThreadType::Main));
EXPECT_EQ(nullptr, res.error);
ASSERT_TRUE(res.data.get());
EXPECT_EQ("Hello World!", *res.data);
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(bool(res.modified));
EXPECT_FALSE(bool(res.etag));
loop.stop();
HTTPTest.finish();
});
示例7: TEST_F
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/timer.hpp>
// Test for https://github.com/mapbox/mapbox-gl-native/issues/2123
//
// A request is made. While the request is in progress, the network status changes. This should
// trigger an immediate retry of all requests that are not in progress. This test makes sure that
// we don't accidentally double-trigger the request.
TEST_F(Storage, HTTPNetworkStatusChange) {
SCOPED_TEST(HTTPNetworkStatusChange)
using namespace mbgl;
util::RunLoop loop;
OnlineFileSource fs(nullptr);
const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/delayed" };
// This request takes 200 milliseconds to answer.
std::unique_ptr<FileRequest> req = fs.request(resource, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
ASSERT_TRUE(res.data.get());
EXPECT_EQ("Response", *res.data);
EXPECT_FALSE(bool(res.expires));
EXPECT_FALSE(bool(res.modified));
EXPECT_FALSE(bool(res.etag));
loop.stop();
HTTPNetworkStatusChange.finish();
});