summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2015-11-13 17:47:22 +0200
committerThiago Marcos P. Santos <thiago@mapbox.com>2015-12-01 11:49:02 +0200
commitcb06526b10d9ef44b3606c36aec498822884251e (patch)
tree822be48cb08a3cb51074689fbef4f92578a556ed
parentae3f1c79faa34337628d671d071a82ac97a66081 (diff)
downloadqtlocation-mapboxgl-cb06526b10d9ef44b3606c36aec498822884251e.tar.gz
[tests] Remove libuv dependency from the tests
-rw-r--r--test/fixtures/mock_file_source.cpp13
-rw-r--r--test/miscellaneous/thread.cpp21
-rw-r--r--test/miscellaneous/work_queue.cpp6
-rw-r--r--test/sprite/sprite_store.cpp9
-rw-r--r--test/storage/cache_response.cpp6
-rw-r--r--test/storage/cache_revalidate.cpp14
-rw-r--r--test/storage/directory_reading.cpp8
-rw-r--r--test/storage/file_reading.cpp20
-rw-r--r--test/storage/http_cancel.cpp10
-rw-r--r--test/storage/http_coalescing.cpp14
-rw-r--r--test/storage/http_error.cpp20
-rw-r--r--test/storage/http_header_parsing.cpp10
-rw-r--r--test/storage/http_issue_1369.cpp6
-rw-r--r--test/storage/http_load.cpp6
-rw-r--r--test/storage/http_other_loop.cpp6
-rw-r--r--test/storage/http_reading.cpp29
-rw-r--r--test/storage/http_retry_network_status.cpp27
-rw-r--r--test/storage/http_timeout.cpp6
-rw-r--r--test/storage/storage.cpp2
-rw-r--r--test/storage/storage.hpp1
-rw-r--r--test/style/glyph_store.cpp9
-rw-r--r--test/style/pending_resources.cpp8
-rw-r--r--test/style/resource_loading.cpp4
23 files changed, 110 insertions, 145 deletions
diff --git a/test/fixtures/mock_file_source.cpp b/test/fixtures/mock_file_source.cpp
index ea580276d6..021ddfa8df 100644
--- a/test/fixtures/mock_file_source.cpp
+++ b/test/fixtures/mock_file_source.cpp
@@ -3,16 +3,11 @@
#include <mbgl/util/io.hpp>
#include <mbgl/util/thread.hpp>
+#include <mbgl/util/timer.hpp>
#include <algorithm>
#include <unordered_map>
-namespace {
-
-const uint64_t timeout = 1000000;
-
-}
-
namespace mbgl {
class MockFileRequest : public FileRequest {
@@ -36,8 +31,8 @@ public:
class MockFileSource::Impl {
public:
Impl(Type type, const std::string& match)
- : type_(type), match_(match), timer_(util::RunLoop::getLoop()) {
- timer_.start(timeout, timeout, [this] { dispatchPendingRequests(); });
+ : type_(type), match_(match) {
+ timer_.start(std::chrono::milliseconds(1000), std::chrono::milliseconds(1000), [this] { dispatchPendingRequests(); });
timer_.unref();
}
@@ -63,7 +58,7 @@ private:
Type type_;
std::string match_;
std::unordered_map<FileRequest*, std::pair<Resource, Callback>> pendingRequests_;
- uv::timer timer_;
+ util::Timer timer_;
std::function<void(void)> requestEnqueuedCallback_;
};
diff --git a/test/miscellaneous/thread.cpp b/test/miscellaneous/thread.cpp
index 9d8f6b6327..f60d7d43dd 100644
--- a/test/miscellaneous/thread.cpp
+++ b/test/miscellaneous/thread.cpp
@@ -66,7 +66,7 @@ public:
TEST(Thread, invoke) {
const std::thread::id tid = std::this_thread::get_id();
- RunLoop loop(uv_default_loop());
+ RunLoop loop;
std::vector<std::unique_ptr<mbgl::WorkRequest>> requests;
loop.invoke([&] {
@@ -110,7 +110,7 @@ TEST(Thread, invoke) {
test.clear();
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
TEST(Thread, context) {
@@ -122,7 +122,7 @@ TEST(Thread, context) {
const std::thread::id tid = std::this_thread::get_id();
- RunLoop loop(uv_default_loop());
+ RunLoop loop;
std::vector<std::unique_ptr<mbgl::WorkRequest>> requests;
loop.invoke([&] {
@@ -134,7 +134,7 @@ TEST(Thread, context) {
}));
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
class TestWorker {
@@ -148,7 +148,7 @@ public:
};
TEST(Thread, ExecutesAfter) {
- RunLoop loop(uv_default_loop());
+ RunLoop loop;
Thread<TestWorker> thread({"Test", ThreadType::Map, ThreadPriority::Regular});
bool didWork = false;
@@ -161,14 +161,15 @@ TEST(Thread, ExecutesAfter) {
didWork = true;
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
EXPECT_TRUE(didWork);
EXPECT_TRUE(didAfter);
}
TEST(Thread, WorkRequestDeletionWaitsForWorkToComplete) {
- RunLoop loop(uv_default_loop());
+ RunLoop loop;
+
Thread<TestWorker> thread({"Test", ThreadType::Map, ThreadPriority::Regular});
std::promise<void> started;
@@ -186,7 +187,7 @@ TEST(Thread, WorkRequestDeletionWaitsForWorkToComplete) {
}
TEST(Thread, WorkRequestDeletionCancelsAfter) {
- RunLoop loop(uv_default_loop());
+ RunLoop loop;
Thread<TestWorker> thread({"Test", ThreadType::Map, ThreadPriority::Regular});
std::promise<void> started;
@@ -200,12 +201,12 @@ TEST(Thread, WorkRequestDeletionCancelsAfter) {
started.get_future().get();
request.reset();
- uv_run(uv_default_loop(), UV_RUN_ONCE);
+ loop.runOnce();
EXPECT_FALSE(didAfter);
}
TEST(Thread, WorkRequestDeletionCancelsImmediately) {
- RunLoop loop(uv_default_loop());
+ RunLoop loop;
Thread<TestWorker> thread({"Test", ThreadType::Map, ThreadPriority::Regular});
std::promise<void> started;
diff --git a/test/miscellaneous/work_queue.cpp b/test/miscellaneous/work_queue.cpp
index a5f616fe5b..a6cd6c3f88 100644
--- a/test/miscellaneous/work_queue.cpp
+++ b/test/miscellaneous/work_queue.cpp
@@ -23,7 +23,7 @@ private:
};
TEST(WorkQueue, push) {
- RunLoop loop(uv_default_loop());
+ RunLoop loop;
WorkQueue queue;
Thread<TestThread> thread({"Test", ThreadType::Map, ThreadPriority::Regular}, &queue);
@@ -43,11 +43,11 @@ TEST(WorkQueue, push) {
thread.invoke(&TestThread::send, endTest);
thread.invoke(&TestThread::send, endTest);
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
TEST(WorkQueue, cancel) {
- RunLoop loop(uv_default_loop());
+ RunLoop loop;
WorkQueue queue;
diff --git a/test/sprite/sprite_store.cpp b/test/sprite/sprite_store.cpp
index 14ea6c957b..fd8f3616f5 100644
--- a/test/sprite/sprite_store.cpp
+++ b/test/sprite/sprite_store.cpp
@@ -4,6 +4,7 @@
#include <mbgl/sprite/sprite_store.hpp>
+#include <mbgl/util/async_task.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/thread.hpp>
@@ -186,9 +187,9 @@ private:
class SpriteTest : public testing::Test {
protected:
void runTest(const SpriteParams& params, FileSource* fileSource, SpriteTestCallback callback) {
- util::RunLoop loop(uv_default_loop());
+ util::RunLoop loop;
- async_ = std::make_unique<uv::async>(loop.get(), [&] { loop.stop(); });
+ async_ = std::make_unique<util::AsyncTask>([&] { loop.stop(); });
async_->unref();
const util::ThreadContext context = {"Map", util::ThreadType::Map, util::ThreadPriority::Regular};
@@ -196,7 +197,7 @@ protected:
util::Thread<SpriteThread> tester(context, fileSource, callback);
tester.invoke(&SpriteThread::loadSprite, params);
- uv_run(loop.get(), UV_RUN_DEFAULT);
+ loop.run();
tester.invoke(&SpriteThread::unloadSprite);
}
@@ -206,7 +207,7 @@ protected:
}
private:
- std::unique_ptr<uv::async> async_;
+ std::unique_ptr<util::AsyncTask> async_;
};
TEST_F(SpriteTest, LoadingSuccess) {
diff --git a/test/storage/cache_response.cpp b/test/storage/cache_response.cpp
index 65a7208d94..8207460aa4 100644
--- a/test/storage/cache_response.cpp
+++ b/test/storage/cache_response.cpp
@@ -1,7 +1,5 @@
#include "storage.hpp"
-#include <uv.h>
-
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/sqlite_cache.hpp>
#include <mbgl/util/chrono.hpp>
@@ -12,9 +10,9 @@ TEST_F(Storage, CacheResponse) {
using namespace mbgl;
+ util::RunLoop loop;
SQLiteCache cache(":memory:");
DefaultFileSource fs(&cache);
- util::RunLoop loop(uv_default_loop());
const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/cache" };
Response response;
@@ -50,5 +48,5 @@ TEST_F(Storage, CacheResponse) {
});
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
diff --git a/test/storage/cache_revalidate.cpp b/test/storage/cache_revalidate.cpp
index 4a553997db..ab7fcd5d24 100644
--- a/test/storage/cache_revalidate.cpp
+++ b/test/storage/cache_revalidate.cpp
@@ -1,7 +1,5 @@
#include "storage.hpp"
-#include <uv.h>
-
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/sqlite_cache.hpp>
#include <mbgl/util/chrono.hpp>
@@ -12,9 +10,9 @@ TEST_F(Storage, CacheRevalidateSame) {
using namespace mbgl;
+ util::RunLoop loop;
SQLiteCache cache(":memory:");
DefaultFileSource fs(&cache);
- util::RunLoop loop(uv_default_loop());
const Resource revalidateSame { Resource::Unknown, "http://127.0.0.1:3000/revalidate-same" };
std::unique_ptr<FileRequest> req1;
@@ -64,7 +62,7 @@ TEST_F(Storage, CacheRevalidateSame) {
});
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
TEST_F(Storage, CacheRevalidateModified) {
@@ -72,9 +70,9 @@ TEST_F(Storage, CacheRevalidateModified) {
using namespace mbgl;
+ util::RunLoop loop;
SQLiteCache cache(":memory:");
DefaultFileSource fs(&cache);
- util::RunLoop loop(uv_default_loop());
const Resource revalidateModified{ Resource::Unknown,
"http://127.0.0.1:3000/revalidate-modified" };
@@ -124,7 +122,7 @@ TEST_F(Storage, CacheRevalidateModified) {
});
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
TEST_F(Storage, CacheRevalidateEtag) {
@@ -132,9 +130,9 @@ TEST_F(Storage, CacheRevalidateEtag) {
using namespace mbgl;
+ util::RunLoop loop;
SQLiteCache cache(":memory:");
DefaultFileSource fs(&cache);
- util::RunLoop loop(uv_default_loop());
const Resource revalidateEtag { Resource::Unknown, "http://127.0.0.1:3000/revalidate-etag" };
std::unique_ptr<FileRequest> req1;
@@ -182,5 +180,5 @@ TEST_F(Storage, CacheRevalidateEtag) {
});
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
diff --git a/test/storage/directory_reading.cpp b/test/storage/directory_reading.cpp
index 5754affe76..71ec761361 100644
--- a/test/storage/directory_reading.cpp
+++ b/test/storage/directory_reading.cpp
@@ -1,7 +1,5 @@
#include "storage.hpp"
-#include <uv.h>
-
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
@@ -11,14 +9,14 @@ TEST_F(Storage, AssetReadDirectory) {
using namespace mbgl;
+ util::RunLoop loop;
+
#ifdef MBGL_ASSET_ZIP
DefaultFileSource fs(nullptr, "test/fixtures/storage/assets.zip");
#else
DefaultFileSource fs(nullptr);
#endif
- util::RunLoop loop(uv_default_loop());
-
std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage" }, [&](Response res) {
req.reset();
ASSERT_NE(nullptr, res.error);
@@ -38,5 +36,5 @@ TEST_F(Storage, AssetReadDirectory) {
ReadDirectory.finish();
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
diff --git a/test/storage/file_reading.cpp b/test/storage/file_reading.cpp
index ceda7835f7..adae2ebf1f 100644
--- a/test/storage/file_reading.cpp
+++ b/test/storage/file_reading.cpp
@@ -1,7 +1,5 @@
#include "storage.hpp"
-#include <uv.h>
-
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/platform/platform.hpp>
#include <mbgl/util/chrono.hpp>
@@ -12,14 +10,14 @@ TEST_F(Storage, AssetEmptyFile) {
using namespace mbgl;
+ util::RunLoop loop;
+
#ifdef MBGL_ASSET_ZIP
DefaultFileSource fs(nullptr, "test/fixtures/storage/assets.zip");
#else
DefaultFileSource fs(nullptr);
#endif
- util::RunLoop loop(uv_default_loop());
-
std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/empty" }, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
@@ -33,7 +31,7 @@ TEST_F(Storage, AssetEmptyFile) {
EmptyFile.finish();
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
TEST_F(Storage, AssetNonEmptyFile) {
@@ -41,14 +39,14 @@ TEST_F(Storage, AssetNonEmptyFile) {
using namespace mbgl;
+ util::RunLoop loop;
+
#ifdef MBGL_ASSET_ZIP
DefaultFileSource fs(nullptr, "test/fixtures/storage/assets.zip");
#else
DefaultFileSource fs(nullptr);
#endif
- util::RunLoop loop(uv_default_loop());
-
std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/nonempty" }, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
@@ -64,7 +62,7 @@ TEST_F(Storage, AssetNonEmptyFile) {
NonEmptyFile.finish();
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
TEST_F(Storage, AssetNonExistentFile) {
@@ -72,14 +70,14 @@ TEST_F(Storage, AssetNonExistentFile) {
using namespace mbgl;
+ util::RunLoop loop;
+
#ifdef MBGL_ASSET_ZIP
DefaultFileSource fs(nullptr, "test/fixtures/storage/assets.zip");
#else
DefaultFileSource fs(nullptr);
#endif
- util::RunLoop loop(uv_default_loop());
-
std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/does_not_exist" }, [&](Response res) {
req.reset();
ASSERT_NE(nullptr, res.error);
@@ -98,5 +96,5 @@ TEST_F(Storage, AssetNonExistentFile) {
NonExistentFile.finish();
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
diff --git a/test/storage/http_cancel.cpp b/test/storage/http_cancel.cpp
index 52e23020be..442a159fe5 100644
--- a/test/storage/http_cancel.cpp
+++ b/test/storage/http_cancel.cpp
@@ -1,7 +1,5 @@
#include "storage.hpp"
-#include <uv.h>
-
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/util/chrono.hpp>
@@ -14,8 +12,8 @@ TEST_F(Storage, HTTPCancel) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
auto req =
fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" },
@@ -24,7 +22,7 @@ TEST_F(Storage, HTTPCancel) {
req.reset();
HTTPCancel.finish();
- uv_run(uv_default_loop(), UV_RUN_ONCE);
+ loop.runOnce();
}
TEST_F(Storage, HTTPCancelMultiple) {
@@ -32,8 +30,8 @@ TEST_F(Storage, HTTPCancelMultiple) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/test" };
@@ -54,5 +52,5 @@ TEST_F(Storage, HTTPCancelMultiple) {
});
req2.reset();
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
diff --git a/test/storage/http_coalescing.cpp b/test/storage/http_coalescing.cpp
index ab63260c1b..a9edf00839 100644
--- a/test/storage/http_coalescing.cpp
+++ b/test/storage/http_coalescing.cpp
@@ -1,7 +1,5 @@
#include "storage.hpp"
-#include <uv.h>
-
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
@@ -14,8 +12,8 @@ TEST_F(Storage, HTTPCoalescing) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
static const Response *reference = nullptr;
@@ -52,7 +50,7 @@ TEST_F(Storage, HTTPCoalescing) {
});
}
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
TEST_F(Storage, HTTPMultiple) {
@@ -60,8 +58,8 @@ TEST_F(Storage, HTTPMultiple) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/test?expires=2147483647" };
std::unique_ptr<FileRequest> req1;
@@ -96,7 +94,7 @@ TEST_F(Storage, HTTPMultiple) {
});
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
// Tests that we get stale responses from previous requests when requesting the same thing again.
@@ -105,8 +103,8 @@ TEST_F(Storage, HTTPStale) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
int updates = 0;
int stale = 0;
@@ -153,7 +151,7 @@ TEST_F(Storage, HTTPStale) {
});
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
EXPECT_EQ(1, stale);
EXPECT_EQ(1, updates);
diff --git a/test/storage/http_error.cpp b/test/storage/http_error.cpp
index 7c9c19eb62..1889d85e00 100644
--- a/test/storage/http_error.cpp
+++ b/test/storage/http_error.cpp
@@ -1,7 +1,5 @@
#include "storage.hpp"
-#include <uv.h>
-
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/util/chrono.hpp>
@@ -14,16 +12,16 @@ TEST_F(Storage, HTTPTemporaryError) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
- const auto start = uv_hrtime();
+ const auto start = Clock::now();
std::unique_ptr<FileRequest> 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 = double(uv_hrtime() - start) / 1e9;
+ 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);
@@ -37,7 +35,7 @@ TEST_F(Storage, HTTPTemporaryError) {
} break;
case 1: {
req1.reset();
- const auto duration = double(uv_hrtime() - start) / 1e9;
+ const auto duration = std::chrono::duration<const double>(Clock::now() - start).count();
EXPECT_LT(0.99, duration) << "Backoff timer didn't wait 1 second";
EXPECT_GT(1.2, duration) << "Backoff timer fired too late";
EXPECT_EQ(nullptr, res.error);
@@ -53,7 +51,7 @@ TEST_F(Storage, HTTPTemporaryError) {
}
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
TEST_F(Storage, HTTPConnectionError) {
@@ -61,15 +59,15 @@ TEST_F(Storage, HTTPConnectionError) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
- const auto start = uv_hrtime();
+ const auto start = Clock::now();
std::unique_ptr<FileRequest> req2 = fs.request({ Resource::Unknown, "http://127.0.0.1:3001/" }, [&](Response res) {
static int counter = 0;
static int wait = 0;
- const auto duration = double(uv_hrtime() - start) / 1e9;
+ const auto duration = std::chrono::duration<const double>(Clock::now() - start).count();
EXPECT_LT(wait - 0.01, duration) << "Backoff timer didn't wait 1 second";
EXPECT_GT(wait + 0.2, duration) << "Backoff timer fired too late";
ASSERT_NE(nullptr, res.error);
@@ -100,5 +98,5 @@ TEST_F(Storage, HTTPConnectionError) {
counter++;
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
diff --git a/test/storage/http_header_parsing.cpp b/test/storage/http_header_parsing.cpp
index bb2dccc6e7..9f48e995b5 100644
--- a/test/storage/http_header_parsing.cpp
+++ b/test/storage/http_header_parsing.cpp
@@ -1,7 +1,5 @@
#include "storage.hpp"
-#include <uv.h>
-
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
@@ -13,8 +11,8 @@ TEST_F(Storage, HTTPExpiresParsing) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
std::unique_ptr<FileRequest> req1 = fs.request({ Resource::Unknown,
"http://127.0.0.1:3000/test?modified=1420794326&expires=1420797926&etag=foo" },
@@ -31,7 +29,7 @@ TEST_F(Storage, HTTPExpiresParsing) {
HTTPExpiresTest.finish();
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
TEST_F(Storage, HTTPCacheControlParsing) {
@@ -39,8 +37,8 @@ TEST_F(Storage, HTTPCacheControlParsing) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
const Seconds now = toSeconds(SystemClock::now());
@@ -58,5 +56,5 @@ TEST_F(Storage, HTTPCacheControlParsing) {
HTTPCacheControlTest.finish();
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
diff --git a/test/storage/http_issue_1369.cpp b/test/storage/http_issue_1369.cpp
index 99b8fac16f..fff773de88 100644
--- a/test/storage/http_issue_1369.cpp
+++ b/test/storage/http_issue_1369.cpp
@@ -1,7 +1,5 @@
#include "storage.hpp"
-#include <uv.h>
-
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/sqlite_cache.hpp>
#include <mbgl/util/chrono.hpp>
@@ -23,9 +21,9 @@ TEST_F(Storage, HTTPIssue1369) {
using namespace mbgl;
+ util::RunLoop loop;
SQLiteCache cache;
DefaultFileSource fs(&cache);
- util::RunLoop loop(uv_default_loop());
const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/test" };
@@ -46,5 +44,5 @@ TEST_F(Storage, HTTPIssue1369) {
HTTPIssue1369.finish();
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
diff --git a/test/storage/http_load.cpp b/test/storage/http_load.cpp
index 1a494d24fa..947b850db6 100644
--- a/test/storage/http_load.cpp
+++ b/test/storage/http_load.cpp
@@ -1,7 +1,5 @@
#include "storage.hpp"
-#include <uv.h>
-
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
@@ -11,8 +9,8 @@ TEST_F(Storage, HTTPLoad) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
const int concurrency = 50;
const int max = 10000;
@@ -48,5 +46,5 @@ TEST_F(Storage, HTTPLoad) {
req(i);
}
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
diff --git a/test/storage/http_other_loop.cpp b/test/storage/http_other_loop.cpp
index ec373a7221..d9c90397ad 100644
--- a/test/storage/http_other_loop.cpp
+++ b/test/storage/http_other_loop.cpp
@@ -1,7 +1,5 @@
#include "storage.hpp"
-#include <uv.h>
-
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
@@ -12,8 +10,8 @@ TEST_F(Storage, HTTPOtherLoop) {
using namespace mbgl;
// This file source launches a separate thread to do the processing.
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" },
[&](Response res) {
@@ -29,5 +27,5 @@ TEST_F(Storage, HTTPOtherLoop) {
HTTPOtherLoop.finish();
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
diff --git a/test/storage/http_reading.cpp b/test/storage/http_reading.cpp
index 6c78878384..3d7f9926e1 100644
--- a/test/storage/http_reading.cpp
+++ b/test/storage/http_reading.cpp
@@ -1,11 +1,10 @@
#include "storage.hpp"
-#include <uv.h>
-
#include <mbgl/storage/default_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>
@@ -14,15 +13,13 @@ TEST_F(Storage, HTTPTest) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
-
- const auto mainThread = uv_thread_self();
std::unique_ptr<FileRequest> req1 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" },
[&](Response res) {
req1.reset();
- EXPECT_EQ(uv_thread_self(), mainThread);
+ EXPECT_TRUE(util::ThreadContext::currentlyOn(util::ThreadType::Main));
EXPECT_EQ(nullptr, res.error);
EXPECT_EQ(false, res.stale);
ASSERT_TRUE(res.data.get());
@@ -34,7 +31,7 @@ TEST_F(Storage, HTTPTest) {
HTTPTest.finish();
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
TEST_F(Storage, HTTP404) {
@@ -42,15 +39,13 @@ TEST_F(Storage, HTTP404) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
-
- const auto mainThread = uv_thread_self();
std::unique_ptr<FileRequest> req2 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/doesnotexist" },
[&](Response res) {
req2.reset();
- EXPECT_EQ(uv_thread_self(), mainThread);
+ EXPECT_TRUE(util::ThreadContext::currentlyOn(util::ThreadType::Main));
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::NotFound, res.error->reason);
EXPECT_EQ(false, res.stale);
@@ -64,7 +59,7 @@ TEST_F(Storage, HTTP404) {
HTTP404.finish();
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
TEST_F(Storage, HTTP500) {
@@ -72,15 +67,13 @@ TEST_F(Storage, HTTP500) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
-
- const auto mainThread = uv_thread_self();
std::unique_ptr<FileRequest> req3 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/permanent-error" },
[&](Response res) {
req3.reset();
- EXPECT_EQ(uv_thread_self(), mainThread);
+ EXPECT_TRUE(util::ThreadContext::currentlyOn(util::ThreadType::Main));
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::Server, res.error->reason);
EXPECT_EQ(false, res.stale);
@@ -94,7 +87,7 @@ TEST_F(Storage, HTTP500) {
HTTP500.finish();
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
TEST_F(Storage, HTTPNoCallback) {
@@ -102,8 +95,8 @@ TEST_F(Storage, HTTPNoCallback) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
try {
fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" },
diff --git a/test/storage/http_retry_network_status.cpp b/test/storage/http_retry_network_status.cpp
index 9f732b1859..41cbed3431 100644
--- a/test/storage/http_retry_network_status.cpp
+++ b/test/storage/http_retry_network_status.cpp
@@ -1,11 +1,10 @@
#include "storage.hpp"
-#include <mbgl/util/uv_detail.hpp>
-
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
+#include <mbgl/util/timer.hpp>
// Test for https://github.com/mapbox/mapbox-gl-native/issues/2123
//
@@ -18,8 +17,8 @@ TEST_F(Storage, HTTPNetworkStatusChange) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/delayed" };
@@ -38,17 +37,17 @@ TEST_F(Storage, HTTPNetworkStatusChange) {
});
// After 50 milliseconds, we're going to trigger a NetworkStatus change.
- uv::timer reachableTimer(uv_default_loop());
- reachableTimer.start(50, 0, [] () {
+ util::Timer reachableTimer;
+ reachableTimer.start(std::chrono::milliseconds(50), Duration::zero(), [] () {
mbgl::NetworkStatus::Reachable();
});
// This timer will keep the loop alive to make sure we would be getting a response in caes the
// network status change triggered another change (which it shouldn't).
- uv::timer delayTimer(uv_default_loop());
- delayTimer.start(300, 0, [] () {});
+ util::Timer delayTimer;
+ delayTimer.start(std::chrono::milliseconds(300), Duration::zero(), [] () {});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
// Tests that a change in network status preempts requests that failed due to connection or
@@ -58,15 +57,15 @@ TEST_F(Storage, HTTPNetworkStatusChangePreempt) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
- const auto start = uv_hrtime();
+ const auto start = Clock::now();
const Resource resource{ Resource::Unknown, "http://127.0.0.1:3001/test" };
std::unique_ptr<FileRequest> req = fs.request(resource, [&](Response res) {
static int counter = 0;
- const auto duration = double(uv_hrtime() - start) / 1e9;
+ const auto duration = std::chrono::duration<const double>(Clock::now() - start).count();
if (counter == 0) {
EXPECT_GT(0.2, duration) << "Response came in too late";
} else if (counter == 1) {
@@ -102,10 +101,10 @@ TEST_F(Storage, HTTPNetworkStatusChangePreempt) {
});
// After 400 milliseconds, we're going to trigger a NetworkStatus change.
- uv::timer reachableTimer(uv_default_loop());
- reachableTimer.start(400, 0, [] () {
+ util::Timer reachableTimer;
+ reachableTimer.start(std::chrono::milliseconds(400), Duration::zero(), [] () {
mbgl::NetworkStatus::Reachable();
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
}
diff --git a/test/storage/http_timeout.cpp b/test/storage/http_timeout.cpp
index 92c6fe4919..26ce0f5c3a 100644
--- a/test/storage/http_timeout.cpp
+++ b/test/storage/http_timeout.cpp
@@ -1,7 +1,5 @@
#include "storage.hpp"
-#include <uv.h>
-
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/util/chrono.hpp>
@@ -12,8 +10,8 @@ TEST_F(Storage, HTTPTimeout) {
using namespace mbgl;
+ util::RunLoop loop;
DefaultFileSource fs(nullptr);
- util::RunLoop loop(uv_default_loop());
int counter = 0;
@@ -34,7 +32,7 @@ TEST_F(Storage, HTTPTimeout) {
}
});
- uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ loop.run();
EXPECT_EQ(4, counter);
}
diff --git a/test/storage/storage.cpp b/test/storage/storage.cpp
index ddc6fef5fb..7fafe59e47 100644
--- a/test/storage/storage.cpp
+++ b/test/storage/storage.cpp
@@ -11,4 +11,4 @@ void Storage::SetUpTestCase() {
void Storage::TearDownTestCase() {
mbgl::test::stopServer(pid);
-} \ No newline at end of file
+}
diff --git a/test/storage/storage.hpp b/test/storage/storage.hpp
index 4c14746c6a..34fa69fbf9 100644
--- a/test/storage/storage.hpp
+++ b/test/storage/storage.hpp
@@ -3,7 +3,6 @@
#include "../fixtures/util.hpp"
#include <mbgl/storage/response.hpp>
-#include <uv.h>
#include <iostream>
class Storage : public testing::Test {
diff --git a/test/style/glyph_store.cpp b/test/style/glyph_store.cpp
index fe614e8c60..8d7c2aeefa 100644
--- a/test/style/glyph_store.cpp
+++ b/test/style/glyph_store.cpp
@@ -4,6 +4,7 @@
#include <mbgl/text/font_stack.hpp>
#include <mbgl/text/glyph_store.hpp>
+#include <mbgl/util/async_task.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/thread.hpp>
@@ -53,9 +54,9 @@ private:
class GlyphStoreTest : public testing::Test {
protected:
void runTest(const GlyphStoreParams& params, FileSource* fileSource, GlyphStoreTestCallback callback) {
- util::RunLoop loop(uv_default_loop());
+ util::RunLoop loop;
- async_ = std::make_unique<uv::async>(loop.get(), [&]{ loop.stop(); });
+ async_ = std::make_unique<util::AsyncTask>([&]{ loop.stop(); });
async_->unref();
const util::ThreadContext context = {"Map", util::ThreadType::Map, util::ThreadPriority::Regular};
@@ -63,7 +64,7 @@ protected:
util::Thread<GlyphStoreThread> tester(context, fileSource, callback);
tester.invoke(&GlyphStoreThread::loadGlyphStore, params);
- uv_run(loop.get(), UV_RUN_DEFAULT);
+ loop.run();
tester.invoke(&GlyphStoreThread::unloadGlyphStore);
}
@@ -80,7 +81,7 @@ protected:
private:
bool testDone = false;
- std::unique_ptr<uv::async> async_;
+ std::unique_ptr<util::AsyncTask> async_;
};
TEST_F(GlyphStoreTest, LoadingSuccess) {
diff --git a/test/style/pending_resources.cpp b/test/style/pending_resources.cpp
index 81452ffc7e..7f665e85e2 100644
--- a/test/style/pending_resources.cpp
+++ b/test/style/pending_resources.cpp
@@ -5,9 +5,9 @@
#include <mbgl/map/map.hpp>
#include <mbgl/platform/default/headless_display.hpp>
#include <mbgl/platform/default/headless_view.hpp>
+#include <mbgl/util/async_task.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
-#include <mbgl/util/uv_detail.hpp>
using namespace mbgl;
@@ -20,7 +20,7 @@ class PendingResources : public ::testing::TestWithParam<std::string> {
// the Map object after that. The idea here is to test if these pending requests
// are getting canceled correctly if on shutdown.
TEST_P(PendingResources, DeleteMapObjectWithPendingRequest) {
- util::RunLoop loop(uv_default_loop());
+ util::RunLoop loop;
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1, 1000, 1000);
@@ -28,7 +28,7 @@ TEST_P(PendingResources, DeleteMapObjectWithPendingRequest) {
std::unique_ptr<Map> map = std::make_unique<Map>(view, fileSource, MapMode::Still);
- uv::async endTest(loop.get(), [&map, &loop] {
+ util::AsyncTask endTest([&map, &loop] {
map.reset();
loop.stop();
});
@@ -43,7 +43,7 @@ TEST_P(PendingResources, DeleteMapObjectWithPendingRequest) {
EXPECT_TRUE(false) << "Should never happen.";
});
- uv_run(loop.get(), UV_RUN_DEFAULT);
+ loop.run();
}
// In the test data below, "sprite" will match both "sprite.json" and "sprite.png" and cause two
diff --git a/test/style/resource_loading.cpp b/test/style/resource_loading.cpp
index cdc84e96b2..f5019cfd82 100644
--- a/test/style/resource_loading.cpp
+++ b/test/style/resource_loading.cpp
@@ -80,7 +80,7 @@ private:
void runTestCase(MockFileSource::Type type,
const std::string& param,
const std::string& message) {
- util::RunLoop loop(uv_default_loop());
+ util::RunLoop loop;
MockView view;
MockFileSource fileSource(type, param);
@@ -118,7 +118,7 @@ void runTestCase(MockFileSource::Type type,
std::make_unique<util::Thread<MockMapContext>>(
util::ThreadContext{"Map", util::ThreadType::Map, util::ThreadPriority::Regular}, view, fileSource, callback));
- uv_run(loop.get(), UV_RUN_DEFAULT);
+ loop.run();
// Needed because it will make the Map thread
// join and cease logging after this point.