File: date-utils-test.h

package info (click to toggle)
easyloggingpp 9.97.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,864 kB
  • sloc: cpp: 11,415; python: 2,336; sh: 337; makefile: 24
file content (59 lines) | stat: -rw-r--r-- 1,721 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

#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_