• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "gtest/gtest.h"
17 #define private public
18 #define protected public
19 #include "cb_start_ability.h"
20 #include "os_account.h"
21 #include "ios_account.h"
22 #include "gsm_sms_param_codec.h"
23 #include "gsm_pdu_hex_value.h"
24 #include "gsm_sms_common_utils.h"
25 #include "gsm_sms_message.h"
26 #include "gsm_sms_receive_handler.h"
27 
28 namespace OHOS {
29 namespace Telephony {
30 using namespace testing::ext;
31 
32 static constexpr uint8_t MAX_GSM_7BIT_DATA_LEN = 160;
33 
34 class SmsGsmTest : public testing::Test {
35 public:
SetUpTestCase()36     static void SetUpTestCase()
37     {}
TearDownTestCase()38     static void TearDownTestCase()
39     {}
SetUp()40     void SetUp()
41     {}
TearDown()42     void TearDown()
43     {}
44 };
45 
46 /**
47  * @tc.number   Telephony_SmsMmsGtest_SmsGsmTest_001
48  * @tc.name     SmsGsmTest_001
49  * @tc.desc     Function test
50  */
51 HWTEST_F(SmsGsmTest, SmsGsmTest_001, Function | MediumTest | Level1)
52 {
53     std::shared_ptr<GsmSmsParamCodec> codec = std::make_shared<GsmSmsParamCodec>();
54 
55     string strBuff;
56     int32_t setType = 0;
57     int32_t indType = 0;
58     strBuff += HEX_VALUE_0D;
59     SmsReadBuffer smsReadBuff(strBuff);
60     EXPECT_FALSE(codec->CheckVoicemail(smsReadBuff, &setType, &indType));
61 }
62 
63 /**
64  * @tc.number   Telephony_SmsMmsGtest_SmsGsmTest_002
65  * @tc.name     SmsGsmTest_002
66  * @tc.desc     Function test
67  */
68 HWTEST_F(SmsGsmTest, SmsGsmTest_002, Function | MediumTest | Level1)
69 {
70     std::shared_ptr<GsmSmsParamCodec> codec = std::make_shared<GsmSmsParamCodec>();
71 
72     string strBuff;
73     int32_t setType = 0;
74     int32_t indType = 0;
75     strBuff += HEX_VALUE_04;
76     SmsReadBuffer smsReadBuff(strBuff);
77     EXPECT_FALSE(codec->CheckVoicemail(smsReadBuff, &setType, &indType));
78 }
79 
80 /**
81  * @tc.number   Telephony_SmsMmsGtest_SmsGsmTest_003
82  * @tc.name     SmsGsmTest_003
83  * @tc.desc     Function test
84  */
85 HWTEST_F(SmsGsmTest, SmsGsmTest_003, Function | MediumTest | Level1)
86 {
87     std::shared_ptr<GsmSmsParamCodec> codec = std::make_shared<GsmSmsParamCodec>();
88 
89     string strBuff;
90     int32_t setType = 0;
91     int32_t indType = 0;
92     strBuff += HEX_VALUE_04;
93     strBuff += HEX_VALUE_04;
94     SmsReadBuffer smsReadBuff(strBuff);
95     EXPECT_FALSE(codec->CheckVoicemail(smsReadBuff, &setType, &indType));
96 }
97 
98 /**
99  * @tc.number   Telephony_SmsMmsGtest_SmsGsmTest_004
100  * @tc.name     SmsGsmTest_004
101  * @tc.desc     Function test
102  */
103 HWTEST_F(SmsGsmTest, SmsGsmTest_004, Function | MediumTest | Level1)
104 {
105     std::shared_ptr<GsmSmsParamCodec> codec = std::make_shared<GsmSmsParamCodec>();
106 
107     string strBuff;
108     int32_t setType = 0;
109     int32_t indType = 0;
110     strBuff += HEX_VALUE_04;
111     strBuff += HEX_VALUE_D0;
112     SmsReadBuffer smsReadBuff(strBuff);
113     EXPECT_FALSE(codec->CheckVoicemail(smsReadBuff, &setType, &indType));
114 }
115 
116 
117 /**
118  * @tc.number   Telephony_SmsMmsGtest_SmsGsmTest_005
119  * @tc.name     SmsGsmTest_005
120  * @tc.desc     Function test
121  */
122 HWTEST_F(SmsGsmTest, SmsGsmTest_005, Function | MediumTest | Level1)
123 {
124     std::shared_ptr<GsmSmsParamCodec> codec = std::make_shared<GsmSmsParamCodec>();
125     string strBuff;
126     int32_t setType = 0;
127     int32_t indType = 0;
128     strBuff += HEX_VALUE_04;
129     strBuff += HEX_VALUE_D0;
130     strBuff += HEX_VALUE_D0;
131     SmsReadBuffer smsReadBuff(strBuff);
132     EXPECT_FALSE(codec->CheckVoicemail(smsReadBuff, &setType, &indType));
133 }
134 
135 /**
136  * @tc.number   Telephony_SmsMmsGtest_SmsGsmTest_006
137  * @tc.name     SmsGsmTest_006
138  * @tc.desc     Function test
139  */
140 HWTEST_F(SmsGsmTest, SmsGsmTest_006, Function | MediumTest | Level1)
141 {
142     std::shared_ptr<GsmSmsParamCodec> codec = std::make_shared<GsmSmsParamCodec>();
143 
144     string strBuff;
145     int32_t setType = 0;
146     int32_t indType = 0;
147     strBuff += HEX_VALUE_04;
148     strBuff += HEX_VALUE_D0;
149     strBuff += HEX_VALUE_11;
150     SmsReadBuffer smsReadBuff(strBuff);
151     EXPECT_FALSE(codec->CheckVoicemail(smsReadBuff, &setType, &indType));
152 }
153 
154 /**
155  * @tc.number   Telephony_SmsMmsGtest_SmsGsmTest_007
156  * @tc.name     SmsGsmTest_007
157  * @tc.desc     Function test
158  */
159 HWTEST_F(SmsGsmTest, SmsGsmTest_007, Function | MediumTest | Level1)
160 {
161     std::shared_ptr<GsmSmsParamCodec> codec = std::make_shared<GsmSmsParamCodec>();
162 
163     string strBuff;
164     int32_t setType = 0;
165     int32_t indType = 0;
166     strBuff += HEX_VALUE_04;
167     strBuff += HEX_VALUE_D0;
168     strBuff += HEX_VALUE_10;
169     strBuff += HEX_VALUE_10;
170     SmsReadBuffer smsReadBuff(strBuff);
171     EXPECT_TRUE(codec->CheckVoicemail(smsReadBuff, &setType, &indType));
172 }
173 
174 /**
175  * @tc.number   Telephony_SmsMmsGtest_SmsGsmTest_008
176  * @tc.name     SmsGsmTest_008
177  * @tc.desc     Function test
178  */
179 HWTEST_F(SmsGsmTest, SmsGsmTest_008, Function | MediumTest | Level1)
180 {
181     std::shared_ptr<GsmSmsCommonUtils> utils = std::make_shared<GsmSmsCommonUtils>();
182     SmsWriteBuffer buffer;
183     EXPECT_FALSE(utils->Pack7bitChar(buffer, nullptr, 0, 0));
184 }
185 
186 /**
187  * @tc.number   Telephony_SmsMmsGtest_SmsGsmTest_009
188  * @tc.name     SmsGsmTest_009
189  * @tc.desc     Function test
190  */
191 HWTEST_F(SmsGsmTest, SmsGsmTest_009, Function | MediumTest | Level1)
192 {
193     std::shared_ptr<GsmSmsCommonUtils> utils = std::make_shared<GsmSmsCommonUtils>();
194     std::vector<uint8_t> vectData;
195     uint8_t fillBits = 1;
196 
197     SmsWriteBuffer buffer;
198     EXPECT_FALSE(utils->Pack7bitChar(buffer, static_cast<const uint8_t*>(&vectData[0]), 0, fillBits));
199 }
200 
201 /**
202  * @tc.number   Telephony_SmsMmsGtest_SmsGsmTest_010
203  * @tc.name     SmsGsmTest_010
204  * @tc.desc     Function test
205  */
206 HWTEST_F(SmsGsmTest, SmsGsmTest_010, Function | MediumTest | Level1)
207 {
208     std::shared_ptr<GsmSmsCommonUtils> utils = std::make_shared<GsmSmsCommonUtils>();
209     std::vector<uint8_t> vectData;
210     uint8_t fillBits = 1;
211     vectData.push_back(1);
212     vectData.push_back(2);
213     vectData.push_back(3);
214     vectData.push_back(4);
215     SmsWriteBuffer buffer;
216     EXPECT_TRUE(utils->Pack7bitChar(buffer, static_cast<const uint8_t*>(&vectData[0]), vectData.size(), fillBits));
217 
218     vectData.clear();
219     vectData.assign(MAX_GSM_7BIT_DATA_LEN + 1, 1); // first branch
220     EXPECT_FALSE(utils->Pack7bitChar(buffer, static_cast<const uint8_t*>(&vectData[0]), vectData.size(), fillBits));
221     vectData.clear();
222     EXPECT_TRUE(utils->Pack7bitChar(buffer, static_cast<const uint8_t*>(&vectData[0]), vectData.size(), fillBits));
223 }
224 
225 /**
226  * @tc.number   Telephony_SmsMmsGtest_SmsGsmTest_011
227  * @tc.name     SmsGsmTest_011
228  * @tc.desc     Function test
229  */
230 HWTEST_F(SmsGsmTest, SmsGsmTest_011, Function | MediumTest | Level1)
231 {
232     std::shared_ptr<GsmSmsCommonUtils> utils = std::make_shared<GsmSmsCommonUtils>();
233     std::string strBuffer;
234     uint8_t fillBits = 0;
235     uint8_t dstIdx = 0;
236 
237     SmsReadBuffer buffer(strBuffer);
238     EXPECT_FALSE(utils->Unpack7bitChar(buffer, strBuffer.size(), fillBits,  nullptr, 0, dstIdx));
239     fillBits = 8;
240     EXPECT_FALSE(utils->Unpack7bitChar(buffer, strBuffer.size(), fillBits,  nullptr, 0, dstIdx));
241 }
242 
243 /**
244  * @tc.number   Telephony_SmsMmsGtest_SmsGsmTest_012
245  * @tc.name     SmsGsmTest_012
246  * @tc.desc     Function test
247  */
248 HWTEST_F(SmsGsmTest, SmsGsmTest_012, Function | MediumTest | Level1)
249 {
250     std::shared_ptr<GsmSmsCommonUtils> utils = std::make_shared<GsmSmsCommonUtils>();
251     std::string strBuffer;
252     std::vector<uint8_t> vectData;
253     uint8_t fillBits = 1;
254     uint8_t dstIdx = 0;
255 
256     SmsReadBuffer buffer(strBuffer);
257     EXPECT_FALSE(utils->Unpack7bitChar(buffer, strBuffer.size(), fillBits,
258         static_cast<uint8_t*>(&vectData[0]), vectData.size(), dstIdx));
259 }
260 
261 /**
262  * @tc.number   Telephony_SmsMmsGtest_SmsGsmTest_013
263  * @tc.name     SmsGsmTest_013
264  * @tc.desc     Function test Unpack7bitCharForMiddlePart
265  */
266 HWTEST_F(SmsGsmTest, SmsGsmTest_013, Function | MediumTest | Level1)
267 {
268     std::shared_ptr<GsmSmsCommonUtils> utils = std::make_shared<GsmSmsCommonUtils>();
269     std::string dataStr("1141515");
270     std::vector<uint8_t> vectData;
271 
272     const uint8_t *buffer = reinterpret_cast<const uint8_t *>(dataStr.c_str());
273     EXPECT_FALSE(utils->Unpack7bitCharForMiddlePart(nullptr, 0, static_cast<uint8_t*>(&vectData[0])));
274     EXPECT_FALSE(utils->Unpack7bitCharForMiddlePart(buffer, dataStr.size(), nullptr));
275     EXPECT_FALSE(utils->Unpack7bitCharForMiddlePart(buffer, 0, static_cast<uint8_t*>(&vectData[0])));
276 }
277 }
278 }