aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/tests.chrono.cpp
blob: 269cdca5804dd7aa1bcd4c2c857947d6b3831eee (plain)
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
#include "tests.pch.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace Chrono = vcpkg::Chrono;

namespace UnitTest1
{
    class ChronoTests : public TestClass<ChronoTests>
    {
        TEST_METHOD(parse_time)
        {
            auto timestring = "1990-02-03T04:05:06.0Z";
            auto maybe_time = Chrono::CTime::parse(timestring);

            Assert::IsTrue(maybe_time.has_value());

            Assert::AreEqual(timestring, maybe_time.get()->to_string().c_str());
        }

        TEST_METHOD(parse_time_blank)
        {
            auto maybe_time = Chrono::CTime::parse("");

            Assert::IsFalse(maybe_time.has_value());
        }

        TEST_METHOD(time_difference)
        {
            auto maybe_time1 = Chrono::CTime::parse("1990-02-03T04:05:06.0Z");
            auto maybe_time2 = Chrono::CTime::parse("1990-02-10T04:05:06.0Z");

            Assert::IsTrue(maybe_time1.has_value());
            Assert::IsTrue(maybe_time2.has_value());

            auto delta = maybe_time2.get()->to_time_point() - maybe_time1.get()->to_time_point();

            Assert::AreEqual(24 * 7, std::chrono::duration_cast<std::chrono::hours>(delta).count());
        }
    };
}