encfs/vendor/github.com/muflihun/easyloggingpp/test/date-utils-test.h
Valient Gough 5f0806c5cc Add "easylogging" from "https://github.com/muflihun/easyloggingpp@master"
git-vendor-name: easylogging
git-vendor-dir: vendor/github.com/muflihun/easyloggingpp
git-vendor-repository: https://github.com/muflihun/easyloggingpp
git-vendor-ref: master
2017-08-05 23:23:41 -07:00

60 lines
1.7 KiB
C++

#ifndef DATE_UTILS_TEST_H_
#define DATE_UTILS_TEST_H_
#include "test.h"
#include <thread>
#include <chrono>
TEST(DateUtilsTest, TimeFormatTest) {
auto f = [](unsigned long long v) {
return DateTime::formatTime(v, base::TimestampUnit::Millisecond);
};
ASSERT_EQ("2 ms", f(2));
ASSERT_EQ("999 ms", f(999));
ASSERT_EQ("1007 ms", f(1007));
ASSERT_EQ("1899 ms", f(1899));
ASSERT_EQ("1 seconds", f(1999));
ASSERT_EQ("16 minutes", f(999000));
ASSERT_EQ("24 hours", f(1 * 24 * 60 * 60 * 1000));
ASSERT_EQ("2 days", f(2 * 24 * 60 * 60 * 1000));
ASSERT_EQ("7 days", f(7 * 24 * 60 * 60 * 1000));
ASSERT_EQ("15 days", f(15 * 24 * 60 * 60 * 1000));
}
TEST(DateUtilsTest, PerformanceTrackerTest) {
{
TIMED_SCOPE(timer, "1200 milliseconds wait");
std::this_thread::sleep_for(std::chrono::milliseconds(1200));
}
{
TIMED_SCOPE(timer, "20 milliseconds wait");
std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
{
TIMED_SCOPE(timer, "20 microseconds wait");
std::this_thread::sleep_for(std::chrono::microseconds(20));
}
{
TIMED_SCOPE(timer, "886 milliseconds wait");
std::this_thread::sleep_for(std::chrono::milliseconds(886));
}
{
TIMED_SCOPE(timer, "1500 milliseconds wait");
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
}
{
TIMED_SCOPE(timer, "1400 milliseconds wait");
std::this_thread::sleep_for(std::chrono::milliseconds(1400));
}
{
TIMED_SCOPE(timer, "1600 milliseconds wait");
std::this_thread::sleep_for(std::chrono::milliseconds(1600));
}
}
#endif // DATE_UTILS_TEST_H_