~aleteoryx/muditaos

ref: 25a5d90f4e12ee5d33f4202170f18b59e16a9564 muditaos/module-services/service-cellular/tests/unittest_smssendhandler.cpp -rw-r--r-- 3.8 KiB
25a5d90f — rrandomsky [CP-2156] Fixed no response when editing a contact to have the same number as another 2 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
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <catch2/catch.hpp>
#include <service-cellular/src/SMSSendHandler.hpp>

static SMSRecord buildValidSMSRecord()
{
    SMSRecord rec;
    rec.ID = DB_ID_NONE + 1;
    return rec;
}

TEST_CASE("SMSSendHandler functionality")
{
    using namespace cellular::internal::sms;
    SMSSendHandler outSMS;

    uint32_t wasOnSendQueryInvoked{};
    uint32_t wasOnSendInvoked{};
    outSMS.onSendQuery = [&wasOnSendQueryInvoked](db::Interface::Name database,
                                                  std::unique_ptr<db::Query> query) -> bool {
        wasOnSendQueryInvoked++;
        return true;
    };
    outSMS.onSend = [&wasOnSendInvoked](SMSRecord &record) -> bool {
        wasOnSendInvoked++;
        return true;
    };

    outSMS.onGetOfflineMode = []() -> bool { return false; };

    outSMS.onSIMNotInitialized = []() -> bool { return false; };

    outSMS.onGetModemResetInProgress = []() -> bool { return false; };

    SECTION("Schedule standard send SMS procedure")
    {
        auto record                = buildValidSMSRecord();
        constexpr auto sendOnDelay = false;

        outSMS.handleDBNotification();
        outSMS.handleIncomingDbRecord(record, sendOnDelay);
        outSMS.handleNoMoreDbRecords();

        CHECK(wasOnSendInvoked == 1);
        CHECK(wasOnSendQueryInvoked == 2);
    }

    SECTION("Schedule non-standard send SMS procedure")
    {
        auto record                = buildValidSMSRecord();
        constexpr auto sendOnDelay = false;

        outSMS.handleDBNotification();
        outSMS.handleDBNotification();
        outSMS.handleIncomingDbRecord(record, sendOnDelay);
        outSMS.handleDBNotification();
        outSMS.handleNoMoreDbRecords();

        CHECK(wasOnSendInvoked == 1);
        CHECK(wasOnSendQueryInvoked == 2);
    }
    SECTION("Schedule queued send SMS procedure")
    {
        auto record                = buildValidSMSRecord();
        constexpr auto sendOnDelay = false;

        outSMS.handleDBNotification();
        outSMS.handleDBNotification();
        outSMS.handleIncomingDbRecord(record, sendOnDelay);
        outSMS.handleDBNotification();
        outSMS.handleIncomingDbRecord(record, sendOnDelay);
        outSMS.handleDBNotification();
        outSMS.handleDBNotification();
        outSMS.handleNoMoreDbRecords();

        CHECK(wasOnSendInvoked == 2);
        CHECK(wasOnSendQueryInvoked == 3);
    }

    SECTION("Check offline mode")
    {
        outSMS.onGetOfflineMode    = []() -> bool { return true; };
        auto record                = buildValidSMSRecord();
        constexpr auto sendOnDelay = false;

        outSMS.handleDBNotification();
        outSMS.handleIncomingDbRecord(record, sendOnDelay);

        CHECK(wasOnSendInvoked == 0);
        CHECK(wasOnSendQueryInvoked == 2);
    }

    SECTION("Delayed send - positive flow")
    {
        auto record                = buildValidSMSRecord();
        constexpr auto sendOnDelay = true;

        outSMS.handleDBNotification();
        outSMS.handleIncomingDbRecord(record, sendOnDelay);
        CHECK(wasOnSendInvoked == 0);
        CHECK(wasOnSendQueryInvoked == 1);
        outSMS.sendMessageIfDelayed();
        CHECK(wasOnSendInvoked == 1);
        CHECK(wasOnSendQueryInvoked == 2);
    }

    SECTION("Delayed send - negative flow")
    {
        auto record                = buildValidSMSRecord();
        constexpr auto sendOnDelay = false;

        outSMS.handleDBNotification();
        outSMS.handleIncomingDbRecord(record, sendOnDelay);
        CHECK(wasOnSendInvoked == 1);
        CHECK(wasOnSendQueryInvoked == 2);
        outSMS.sendMessageIfDelayed();
        CHECK(wasOnSendInvoked == 1);
        CHECK(wasOnSendQueryInvoked == 2);
    }
}