Cleanup std::chrono usage

Use mbgl::Duration and mbgl::{,Milli}Seconds whenever possible.
This commit is contained in:
Bruno de Oliveira Abinader
2016-01-23 14:47:17 +02:00
parent cc47da5a15
commit 2f86467586
19 changed files with 65 additions and 68 deletions

View File

@@ -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_) {

View File

@@ -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));

View File

@@ -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,

View File

@@ -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);

View File

@@ -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; });

View File

@@ -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();
});