~aleteoryx/muditaos

ref: 25a5d90f4e12ee5d33f4202170f18b59e16a9564 muditaos/module-services/service-cellular/tests/unittest_smsPartsHandler.cpp -rw-r--r-- 6.4 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// 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 <service-cellular/src/SMSPartsHandler.hpp>

namespace
{
    constexpr auto singleSMSLimit            = 67;
    constexpr auto singleUCS2CharacterLength = 4;
    constexpr auto singleSMSLimitUCS2        = singleUCS2CharacterLength * singleSMSLimit;
    const std::string smileEmojiUTF          = "\U0001f601";
    const std::string winkEmojiUTF           = "\U0001f609";
} // namespace

TEST_CASE("SMS Parts handler")
{
    using namespace cellular::internal::sms;

    SECTION("Fit to SMS limit")
    {
        std::string smsAt67SignsLimit = "qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm12345";
        SMSPartsHandler parts{smsAt67SignsLimit};
        CHECK(parts.isSinglePartSMS());
        CHECK(parts.getNextSmsPart().length() <= singleSMSLimitUCS2);
        CHECK(parts.getNextSmsPart().length() == 0);
    }

    SECTION("Fit to SMS limit with emoji")
    {
        std::string smsAt67SignsLimit =
            "qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm1" + smileEmojiUTF;
        CHECK(smsAt67SignsLimit.length() == singleSMSLimit);
        SMSPartsHandler parts{smsAt67SignsLimit};
        CHECK(parts.isSinglePartSMS());
        CHECK(parts.getNextSmsPart().length() <= singleSMSLimitUCS2);
        CHECK(parts.getNextSmsPart().length() == 0);
    }

    SECTION("Above single SMS limit")
    {
        std::string smsAbove67SignsLimit = "qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm123456";
        SMSPartsHandler parts{smsAbove67SignsLimit};
        CHECK(!parts.isSinglePartSMS());
        CHECK(parts.getNextSmsPart().length() <= singleSMSLimitUCS2);
        CHECK(parts.getNextSmsPart().length() == singleUCS2CharacterLength);
        CHECK(parts.getNextSmsPart().length() == 0);
    }

    SECTION("Above single SMS limit with emoji")
    {
        std::string smsAbove67SignsLimit =
            "qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm1234" + smileEmojiUTF + "abcd";
        CHECK(smsAbove67SignsLimit.length() > singleSMSLimit);
        SMSPartsHandler parts{smsAbove67SignsLimit};
        CHECK(!parts.isSinglePartSMS());
        CHECK(parts.getNextSmsPart().length() <= singleSMSLimitUCS2);
        CHECK(parts.getNextSmsPart().length() > 0);
    }

    SECTION("3-part SMS limit")
    {
        std::string smsAt67SignsLimit = "qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm12345";
        SMSPartsHandler parts{smsAt67SignsLimit + smsAt67SignsLimit + smsAt67SignsLimit};
        CHECK(!parts.isSinglePartSMS());
        CHECK(parts.getPartsCount() == 3);
        CHECK(parts.getNextSmsPart().length() == singleSMSLimitUCS2);
        CHECK(parts.getNextSmsPart().length() == singleSMSLimitUCS2);
        CHECK(parts.getNextSmsPart().length() == singleSMSLimitUCS2);
        CHECK(parts.getNextSmsPart().length() == 0);
    }

    SECTION("Multi-part SMS with emojis")
    {
        std::string multiPartSMS =
            "qwertyuiopasdf" + smileEmojiUTF + "ghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm12345" + smileEmojiUTF +
            smileEmojiUTF + smileEmojiUTF + "ghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm12345" + smileEmojiUTF +
            "teststringteststring" + smileEmojiUTF;
        SMSPartsHandler parts{multiPartSMS};
        UTF8 multiPartSMSUTF8{multiPartSMS};
        unsigned numOfParts = (multiPartSMSUTF8.length() / singleSMSLimit);
        numOfParts += (multiPartSMSUTF8.length() % singleSMSLimit) ? 1 : 0;
        CHECK(!parts.isSinglePartSMS());
        CHECK(parts.getPartsCount() == numOfParts);

        for (unsigned i = 0; i < numOfParts; ++i) {
            CHECK(parts.getNextSmsPart().length() <= singleSMSLimitUCS2);
        }
    }

    SECTION("7-part SMS limit")
    {
        std::string smsAbove7PartLimit =
            std::string{"qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm12345"} +
            std::string{"qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm12345"} +
            std::string{"qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm12345"} +
            std::string{"qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm12345"} +
            std::string{"qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm12345"} +
            std::string{"qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm12345"} +
            std::string{"qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm12345"} + std::string{"qwerty"};
        SMSPartsHandler parts{smsAbove7PartLimit};
        CHECK(parts.isPartsCountAboveLimit());
        CHECK(parts.getPartsCount() == 8);
    }
}

TEST_CASE("EGD-7372 cases")
{
    using namespace cellular::internal::sms;

    SECTION("First")
    {
        std::string testString =
            "Hello everyone! Mudita Pure test today? I propose a meeting at 3:30PM " + winkEmojiUTF + ".";
        SMSPartsHandler parts{testString};
        CHECK(parts.getPartsCount() == 2);
        CHECK(parts.getNextSmsPart().length() <= singleSMSLimitUCS2);
        CHECK(parts.getNextSmsPart().length() <= singleSMSLimitUCS2);
    }

    SECTION("Second")
    {
        std::string testString =
            "Hello everyone! Mudita Pure test today? " + winkEmojiUTF + " I propose a meeting at 3:30PM.";
        SMSPartsHandler parts{testString};
        CHECK(parts.getPartsCount() == 2);
        CHECK(parts.getNextSmsPart().length() <= singleSMSLimitUCS2);
        CHECK(parts.getNextSmsPart().length() <= singleSMSLimitUCS2);
    }

    SECTION("Third")
    {
        std::string testString = "Hello everyone! Mudita Pure test today? I propose a meeting at 3:30PM " +
                                 winkEmojiUTF + ". Extra random text.";
        SMSPartsHandler parts{testString};
        CHECK(parts.getPartsCount() == 2);
        CHECK(parts.getNextSmsPart().length() <= singleSMSLimitUCS2);
        CHECK(parts.getNextSmsPart().length() <= singleSMSLimitUCS2);
    }

    SECTION("Fourth")
    {
        std::string testString =
            "Hello! Mudita Pure test today? I propose a meeting at 3:30PM " + winkEmojiUTF + ". Extra random text.";
        SMSPartsHandler parts{testString};
        CHECK(parts.getPartsCount() == 2);
        CHECK(parts.getNextSmsPart().length() <= singleSMSLimitUCS2);
        CHECK(parts.getNextSmsPart().length() <= singleSMSLimitUCS2);
    }
}