~aleteoryx/muditaos

ref: 39a760bad6d6dd28300bad334c7902d7e46fa6e2 muditaos/module-utils/time/test/unittest_TimeZone.cpp -rw-r--r-- 2.0 KiB
39a760ba — Maciej Gibowicz [EGD-6702] Add time zone library 4 years ago
                                                                                
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
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <time/TimeZone.hpp>

TEST_CASE("TimeZone parser")
{
    SECTION("Checking the time zone rules for Warsaw")
    {
        std::string zone{"Warsaw"};
        auto rules  = utils::time::getTimeZoneRules(zone);
        auto offset = utils::time::getTimeZoneOffset(zone);

        REQUIRE(offset == 4);
        REQUIRE(rules.size() != 0);
    }

    SECTION("Checking the time zone rules for London")
    {
        std::string zone{"London"};
        auto rules  = utils::time::getTimeZoneRules(zone);
        auto offset = utils::time::getTimeZoneOffset(zone);

        REQUIRE(offset == 0);
        REQUIRE(rules.size() != 0);
    }

    SECTION("Checking the time zone rules for New York")
    {
        std::string zone{"New York"};
        auto rules  = utils::time::getTimeZoneRules(zone);
        auto offset = utils::time::getTimeZoneOffset(zone);

        REQUIRE(offset == -20);
        REQUIRE(rules.size() != 0);
    }

    SECTION("Checking the time zone rules for Tehran")
    {
        std::string zone{"Tehran"};
        auto rules  = utils::time::getTimeZoneRules(zone);
        auto offset = utils::time::getTimeZoneOffset(zone);

        REQUIRE(offset == 14);
        REQUIRE(rules.size() != 0);
    }

    SECTION("Checking the time zone rules for Auckland")
    {
        std::string zone{"Auckland"};
        auto rules  = utils::time::getTimeZoneRules(zone);
        auto offset = utils::time::getTimeZoneOffset(zone);

        REQUIRE(offset == 48);
        REQUIRE(rules.size() != 0);
    }

    SECTION("Checking the time zone rules for unknown zone")
    {
        std::string zone{"unknown"};
        auto rules  = utils::time::getTimeZoneRules(zone);
        auto offset = utils::time::getTimeZoneOffset(zone);

        REQUIRE(offset == 0);
        REQUIRE(rules.size() == 0);
    }
}