diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-01-23 14:47:17 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-01-25 15:11:18 +0200 |
commit | 2f86467586706d254fcbcb1c88657992214aefcd (patch) | |
tree | 97c34a7c1589ba32cc981b47792983d057c3b996 /test | |
parent | cc47da5a15650c3f8ede9f7e253e4099dc61673f (diff) | |
download | qtlocation-mapboxgl-2f86467586706d254fcbcb1c88657992214aefcd.tar.gz |
Cleanup std::chrono usage
Use mbgl::Duration and mbgl::{,Milli}Seconds whenever possible.
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/mock_file_source.cpp | 3 | ||||
-rw-r--r-- | test/fixtures/util.cpp | 3 | ||||
-rw-r--r-- | test/fixtures/util.hpp | 4 | ||||
-rw-r--r-- | test/miscellaneous/timer.cpp | 32 | ||||
-rw-r--r-- | test/storage/cache_size.cpp | 3 | ||||
-rw-r--r-- | test/storage/http_retry_network_status.cpp | 6 |
6 files changed, 25 insertions, 26 deletions
diff --git a/test/fixtures/mock_file_source.cpp b/test/fixtures/mock_file_source.cpp index 791e5d314a..078271a422 100644 --- a/test/fixtures/mock_file_source.cpp +++ b/test/fixtures/mock_file_source.cpp @@ -1,5 +1,6 @@ #include "mock_file_source.hpp" #include <mbgl/util/io.hpp> +#include <mbgl/util/chrono.hpp> namespace mbgl { @@ -18,7 +19,7 @@ public: MockFileSource::MockFileSource(Type type_, const std::string& match_) : type(type_), match(match_) { - timer.start(std::chrono::milliseconds(10), std::chrono::milliseconds(10), [this] { + timer.start(Milliseconds(10), Milliseconds(10), [this] { // Explicit move to avoid iterator invalidation if ~MockFileRequest gets called within the loop. auto pending_ = std::move(pending); for (auto& pair : pending_) { diff --git a/test/fixtures/util.cpp b/test/fixtures/util.cpp index c2a5d83637..fcb6abed4e 100644 --- a/test/fixtures/util.cpp +++ b/test/fixtures/util.cpp @@ -4,6 +4,7 @@ #include <mbgl/platform/log.hpp> #include <mbgl/util/image.hpp> #include <mbgl/util/io.hpp> +#include <mbgl/util/chrono.hpp> #include <mapbox/pixelmatch.hpp> @@ -105,7 +106,7 @@ uint64_t crc64(const PremultipliedImage &image) { return crc64(reinterpret_cast<const char*>(image.data.get()), image.size()); } -PremultipliedImage render(Map& map, std::chrono::milliseconds timeout) { +PremultipliedImage render(Map& map, Milliseconds timeout) { std::promise<PremultipliedImage> promise; map.renderStill([&](std::exception_ptr, PremultipliedImage&& image) { promise.set_value(std::move(image)); diff --git a/test/fixtures/util.hpp b/test/fixtures/util.hpp index 7a240cb41f..b93d822a83 100644 --- a/test/fixtures/util.hpp +++ b/test/fixtures/util.hpp @@ -2,6 +2,7 @@ #define MBGL_TEST_UTIL #include <mbgl/util/image.hpp> +#include <mbgl/util/chrono.hpp> #include <chrono> #include <cstdint> @@ -35,8 +36,7 @@ uint64_t crc64(const char*, size_t); uint64_t crc64(const std::string&); uint64_t crc64(const PremultipliedImage&); -PremultipliedImage render(Map&, - std::chrono::milliseconds timeout = std::chrono::milliseconds(1000)); +PremultipliedImage render(Map&, Milliseconds timeout = Milliseconds(1000)); void checkImage(const std::string& base, const PremultipliedImage& actual, diff --git a/test/miscellaneous/timer.cpp b/test/miscellaneous/timer.cpp index 521d0e8cc4..1ac72d8068 100644 --- a/test/miscellaneous/timer.cpp +++ b/test/miscellaneous/timer.cpp @@ -1,6 +1,7 @@ #include <mbgl/util/chrono.hpp> #include <mbgl/util/timer.hpp> #include <mbgl/util/run_loop.hpp> +#include <mbgl/util/chrono.hpp> #include <memory> @@ -15,7 +16,7 @@ TEST(Timer, Basic) { auto callback = [&loop] { loop.stop(); }; - auto interval = std::chrono::milliseconds(300); + auto interval = mbgl::Milliseconds(300); auto expectedTotalTime = interval; auto first = mbgl::Clock::now(); @@ -23,8 +24,7 @@ TEST(Timer, Basic) { loop.run(); - using namespace std::chrono; - auto totalTime = duration_cast<milliseconds>(mbgl::Clock::now() - first); + auto totalTime = std::chrono::duration_cast<mbgl::Milliseconds>(mbgl::Clock::now() - first); // These are not high precision timers. Especially libuv uses // cached time from the beginning of of the main loop iteration @@ -45,7 +45,7 @@ TEST(Timer, Repeat) { } }; - auto interval = std::chrono::milliseconds(50); + auto interval = mbgl::Milliseconds(50); auto expectedTotalTime = interval * count; auto first = mbgl::Clock::now(); @@ -53,8 +53,7 @@ TEST(Timer, Repeat) { loop.run(); - using namespace std::chrono; - auto totalTime = duration_cast<milliseconds>(mbgl::Clock::now() - first); + auto totalTime = std::chrono::duration_cast<mbgl::Milliseconds>(mbgl::Clock::now() - first); EXPECT_GE(totalTime, expectedTotalTime * 0.8); EXPECT_LE(totalTime, expectedTotalTime * 1.2); @@ -66,8 +65,8 @@ TEST(Timer, Stop) { Timer timer1; Timer timer2; - auto interval1 = std::chrono::milliseconds(50); - auto interval2 = std::chrono::milliseconds(250); + auto interval1 = mbgl::Milliseconds(50); + auto interval2 = mbgl::Milliseconds(250); auto expectedTotalTime = interval2; int count = 0; @@ -88,8 +87,7 @@ TEST(Timer, Stop) { loop.run(); - using namespace std::chrono; - auto totalTime = duration_cast<milliseconds>(mbgl::Clock::now() - first); + auto totalTime = std::chrono::duration_cast<mbgl::Milliseconds>(mbgl::Clock::now() - first); EXPECT_EQ(count, 2); @@ -103,8 +101,8 @@ TEST(Timer, DestroyShouldStop) { auto timer1 = std::make_unique<Timer>(); Timer timer2; - auto interval1 = std::chrono::milliseconds(50); - auto interval2 = std::chrono::milliseconds(250); + auto interval1 = mbgl::Milliseconds(50); + auto interval2 = mbgl::Milliseconds(250); auto expectedTotalTime = interval2; int count = 0; @@ -125,8 +123,7 @@ TEST(Timer, DestroyShouldStop) { loop.run(); - using namespace std::chrono; - auto totalTime = duration_cast<milliseconds>(mbgl::Clock::now() - first); + auto totalTime = std::chrono::duration_cast<mbgl::Milliseconds>(mbgl::Clock::now() - first); EXPECT_EQ(count, 2); @@ -139,8 +136,8 @@ TEST(Timer, StartOverrides) { Timer timer; - auto interval1 = std::chrono::milliseconds(50); - auto interval2 = std::chrono::milliseconds(250); + auto interval1 = mbgl::Milliseconds(50); + auto interval2 = mbgl::Milliseconds(250); auto expectedTotalTime = interval1 + interval2; int count = 0; @@ -160,8 +157,7 @@ TEST(Timer, StartOverrides) { loop.run(); - using namespace std::chrono; - auto totalTime = duration_cast<milliseconds>(mbgl::Clock::now() - first); + auto totalTime = std::chrono::duration_cast<mbgl::Milliseconds>(mbgl::Clock::now() - first); EXPECT_EQ(count, 2); diff --git a/test/storage/cache_size.cpp b/test/storage/cache_size.cpp index 7a98e1c835..b0d59d5934 100644 --- a/test/storage/cache_size.cpp +++ b/test/storage/cache_size.cpp @@ -6,6 +6,7 @@ #include <mbgl/util/run_loop.hpp> #include <mbgl/util/string.hpp> #include <mbgl/util/timer.hpp> +#include <mbgl/util/chrono.hpp> #include <memory> #include <random> @@ -186,7 +187,7 @@ TEST_F(Storage, CacheSizePruneLeastAccessed) { bool done = false; util::Timer timer; - timer.start(std::chrono::milliseconds(1300), + timer.start(Milliseconds(1300), Duration::zero(), [&done] { done = true; }); diff --git a/test/storage/http_retry_network_status.cpp b/test/storage/http_retry_network_status.cpp index 4598b8e402..df9284f995 100644 --- a/test/storage/http_retry_network_status.cpp +++ b/test/storage/http_retry_network_status.cpp @@ -37,14 +37,14 @@ TEST_F(Storage, HTTPNetworkStatusChange) { // After 50 milliseconds, we're going to trigger a NetworkStatus change. util::Timer reachableTimer; - reachableTimer.start(std::chrono::milliseconds(50), Duration::zero(), [] () { + reachableTimer.start(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). util::Timer delayTimer; - delayTimer.start(std::chrono::milliseconds(300), Duration::zero(), [] () {}); + delayTimer.start(Milliseconds(300), Duration::zero(), [] () {}); loop.run(); } @@ -100,7 +100,7 @@ TEST_F(Storage, HTTPNetworkStatusChangePreempt) { // After 400 milliseconds, we're going to trigger a NetworkStatus change. util::Timer reachableTimer; - reachableTimer.start(std::chrono::milliseconds(400), Duration::zero(), [] () { + reachableTimer.start(Milliseconds(400), Duration::zero(), [] () { mbgl::NetworkStatus::Reachable(); }); |