~aleteoryx/muditaos

ref: c19d38e5ba764b05f7f2e2ab5fe7d366c64982a0 muditaos/module-services/service-cellular/tests/unittest_volteCapabilityHandler.cpp -rw-r--r-- 4.4 KiB
c19d38e5 — Kuba Kleczkowski [MOS-816] Add parse and filter IMSI 3 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <catch2/catch.hpp>

#include <module-services/service-cellular/src/volte/VolteCapabilityHandler.hpp>
#include <module-services/service-cellular/src/volte/ImsiParserUS.hpp>
#include <module-services/service-cellular/src/volte/VolteAllowedUSList.hpp>
#include <module-services/service-cellular/src/volte/VolteCapabiltyHandlerCellularInterface.hpp>

TEST_CASE("VoLTE Capability handler")
{
    SECTION("ImsiParserUS success - US IMSI")
    {
        using namespace cellular::service;

        cellular::service::ImsiParserUS parser;
        std::string imsi("3111231234567890");

        auto result = parser.parse(imsi);

        REQUIRE(result.has_value() == true);
        REQUIRE(result.value().MCC == "311");
        REQUIRE(result.value().MNC == "123");
    }

    SECTION("ImsiParserUS failure - non US IMSI")
    {
        using namespace cellular::service;

        cellular::service::ImsiParserUS parser;
        std::string imsi("2601231234567890");

        auto result = parser.parse(imsi);

        REQUIRE(result.has_value() == false);
    }

    SECTION("ImsiParserUS failure -too short IMSI")
    {
        using namespace cellular::service;

        cellular::service::ImsiParserUS parser;
        std::string imsi("2601");

        auto result = parser.parse(imsi);

        REQUIRE(result.has_value() == false);
    }

    SECTION("VolteAllowedUSList success - TMobileUS IMSI")
    {
        using namespace cellular::service;

        VolteAllowedUSList list;
        OperatorInfo operatorInfo{"310", "120"};

        auto result = list.isVolteAllowed(operatorInfo);

        REQUIRE(result == true);
    }

    SECTION("VolteAllowedUSList failure - non TMobileUS MCC")
    {
        using namespace cellular::service;

        VolteAllowedUSList list;
        OperatorInfo operatorInfo{"210", "120"};

        auto result = list.isVolteAllowed(operatorInfo);

        REQUIRE(result == false);
    }

    SECTION("VolteAllowedUSList failure - non TMobileUS MNC")
    {
        using namespace cellular::service;

        VolteAllowedUSList list;
        OperatorInfo operatorInfo{"310", "999"};

        auto result = list.isVolteAllowed(operatorInfo);

        REQUIRE(result == false);
    }

    class MockTMobileUS : public cellular::service::VolteCapabilityCellularInterface
    {
        void setChannel(at::BaseChannel *channel)
        {}
        auto getImsi() -> std::optional<std::string>
        {
            return "310120123456789";
        }
    };

    SECTION("VolteCapabilityHandler succes = TMobileUS")
    {
        using namespace cellular::service;
        VolteCapabilityHandler handler{std::make_unique<ImsiParserUS>(),
                                       std::make_unique<VolteAllowedUSList>(),
                                       std::make_unique<MockTMobileUS>()};
        auto result = handler.isVolteAllowed();
        REQUIRE(result == true);
    }

    class MockNonTMobileUS : public cellular::service::VolteCapabilityCellularInterface
    {
        void setChannel(at::BaseChannel *channel)
        {}
        auto getImsi() -> std::optional<std::string>
        {
            return "310999123456789";
        }
    };

    SECTION("VolteCapabilityHandler failure = non TMobileUS")
    {
        using namespace cellular::service;
        VolteCapabilityHandler handler{std::make_unique<ImsiParserUS>(),
                                       std::make_unique<VolteAllowedUSList>(),
                                       std::make_unique<MockNonTMobileUS>()};
        auto result = handler.isVolteAllowed();
        REQUIRE(result == false);
    }

    class MockFailedToGetImsi : public cellular::service::VolteCapabilityCellularInterface
    {
        void setChannel(at::BaseChannel *channel)
        {}
        auto getImsi() -> std::optional<std::string>
        {
            return std::nullopt;
        }
    };

    SECTION("VolteCapabilityHandler failure = failed to get imsi")
    {
        using namespace cellular::service;
        VolteCapabilityHandler handler{std::make_unique<ImsiParserUS>(),
                                       std::make_unique<VolteAllowedUSList>(),
                                       std::make_unique<MockFailedToGetImsi>()};
        auto result = handler.isVolteAllowed();
        REQUIRE(result == false);
    }
}