• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 #define private public
17 #define protected public
18 
19 #include "cdma_sms_message.h"
20 #include "cdma_sms_receive_handler.h"
21 #include "cdma_sms_transport_message.h"
22 #include "gtest/gtest.h"
23 
24 namespace OHOS {
25 namespace Telephony {
26 using namespace testing::ext;
27 
28 namespace {
29 const uint16_t PDU_BUFFER_MAX_SIZE = 0xFF;
30 const size_t DATA_LENGTH = 162;
31 const int32_t HEADER_LENGTH = 7;
32 } // namespace
33 
34 class BranchCdmaSmsTest : public testing::Test {
35 public:
36     static void SetUpTestCase();
37     static void TearDownTestCase();
38     void SetUp();
39     void TearDown();
40 };
SetUpTestCase()41 void BranchCdmaSmsTest::SetUpTestCase() {}
42 
TearDownTestCase()43 void BranchCdmaSmsTest::TearDownTestCase() {}
44 
SetUp()45 void BranchCdmaSmsTest::SetUp() {}
46 
TearDown()47 void BranchCdmaSmsTest::TearDown() {}
48 
49 /**
50  * @tc.number   Telephony_BranchCdmaSmsTest_CdmaSmsMessage_0001
51  * @tc.name     Test CdmaSmsMessage
52  * @tc.desc     Function test
53  */
54 HWTEST_F(BranchCdmaSmsTest, CdmaSmsMessage_0001, Function | MediumTest | Level1)
55 {
56     std::shared_ptr<CdmaSmsMessage> cdmaSmsMessage = std::make_shared<CdmaSmsMessage>();
57     string pduHex = "";
58     DataCodingScheme codingType;
59     CdmaP2PMsg p2pMsg;
60     p2pMsg.telesvcMsg.type = TeleserviceMsgType::DELIVER;
61     cdmaSmsMessage->AnalysisP2pMsg(p2pMsg);
62     p2pMsg.telesvcMsg.type = TeleserviceMsgType::DELIVERY_ACK;
63     cdmaSmsMessage->AnalysisP2pMsg(p2pMsg);
64     p2pMsg.telesvcMsg.type = TeleserviceMsgType::USER_ACK;
65     cdmaSmsMessage->AnalysisP2pMsg(p2pMsg);
66     p2pMsg.telesvcMsg.type = TeleserviceMsgType::READ_ACK;
67     cdmaSmsMessage->AnalysisP2pMsg(p2pMsg);
68     p2pMsg.telesvcMsg.type = TeleserviceMsgType::SUBMIT_REPORT;
69     cdmaSmsMessage->AnalysisP2pMsg(p2pMsg);
70     p2pMsg.telesvcMsg.type = TeleserviceMsgType::SUBMIT;
71     cdmaSmsMessage->AnalysisP2pMsg(p2pMsg);
72     p2pMsg.telesvcMsg.type = TeleserviceMsgType::MAX_VALUE;
73     cdmaSmsMessage->AnalysisP2pMsg(p2pMsg);
74     p2pMsg.teleserviceId = static_cast<uint16_t>(SmsTransTelsvcId::RESERVED);
75     cdmaSmsMessage->AnalysisP2pMsg(p2pMsg);
76     EXPECT_FALSE(cdmaSmsMessage->IsWapPushMsg());
77     EXPECT_EQ(cdmaSmsMessage->GetTransMsgType(), CdmaTransportMsgType::RESERVED);
78     EXPECT_EQ(cdmaSmsMessage->GetTransTeleService(), static_cast<uint16_t>(SmsTransTelsvcId::RESERVED));
79     EXPECT_FALSE(cdmaSmsMessage->PduAnalysis(pduHex));
80     cdmaSmsMessage->transMsg_ = std::make_unique<struct CdmaTransportMsg>();
81     cdmaSmsMessage->transMsg_->type = CdmaTransportMsgType::BROADCAST;
82     EXPECT_EQ(cdmaSmsMessage->GetTransTeleService(), static_cast<uint16_t>(SmsTransTelsvcId::RESERVED));
83     cdmaSmsMessage->transMsg_->type = CdmaTransportMsgType::P2P;
84     cdmaSmsMessage->transMsg_->data.p2p.teleserviceId = static_cast<uint16_t>(SmsTransTelsvcId::WAP);
85     EXPECT_TRUE(cdmaSmsMessage->IsWapPushMsg());
86     codingType = DataCodingScheme::DATA_CODING_7BIT;
87     EXPECT_EQ(cdmaSmsMessage->CovertEncodingType(codingType), SmsEncodingType::GSM7BIT);
88     codingType = DataCodingScheme::DATA_CODING_ASCII7BIT;
89     EXPECT_EQ(cdmaSmsMessage->CovertEncodingType(codingType), SmsEncodingType::ASCII_7BIT);
90     codingType = DataCodingScheme::DATA_CODING_8BIT;
91     EXPECT_EQ(cdmaSmsMessage->CovertEncodingType(codingType), SmsEncodingType::OCTET);
92     codingType = DataCodingScheme::DATA_CODING_UCS2;
93     EXPECT_EQ(cdmaSmsMessage->CovertEncodingType(codingType), SmsEncodingType::UNICODE);
94     codingType = DataCodingScheme::DATA_CODING_EUCKR;
95     EXPECT_EQ(cdmaSmsMessage->CovertEncodingType(codingType), SmsEncodingType::UNICODE);
96     EXPECT_FALSE(cdmaSmsMessage->PduAnalysis(pduHex));
97     pduHex = "12";
98     EXPECT_FALSE(cdmaSmsMessage->PduAnalysis(pduHex));
99 }
100 
101 /**
102  * @tc.number   Telephony_BranchCdmaSmsTest_CdmaSmsMessage_0002
103  * @tc.name     Test CdmaSmsMessage
104  * @tc.desc     Function test
105  */
106 HWTEST_F(BranchCdmaSmsTest, CdmaSmsMessage_0002, Function | MediumTest | Level1)
107 {
108     std::shared_ptr<CdmaSmsMessage> cdmaSmsMessage = std::make_shared<CdmaSmsMessage>();
109     CdmaP2PMsg p2pMsg;
110     TeleserviceDeliver deliver;
111     SmsTeleSvcUserData userData;
112     CdmaBroadCastMsg cbMsg;
113     SmsUDH header;
114     p2pMsg.teleserviceId = static_cast<uint16_t>(SmsTransTelsvcId::VMN_95);
115     p2pMsg.telesvcMsg.data.deliver.vmn.faxIncluded = true;
116     p2pMsg.telesvcMsg.data.deliver.userData.userData.length = 0;
117     deliver.displayMode = SmsDisplayMode::IMMEDIATE;
118     cdmaSmsMessage->AnalsisDeliverMwi(p2pMsg);
119     cdmaSmsMessage->AnalsisDeliverMsg(deliver);
120     userData.encodeType = SmsEncodingType::GSM7BIT;
121     cdmaSmsMessage->AnalsisUserData(userData);
122     userData.encodeType = SmsEncodingType::KOREAN;
123     cdmaSmsMessage->AnalsisUserData(userData);
124     userData.encodeType = SmsEncodingType::EUCKR;
125     cdmaSmsMessage->AnalsisUserData(userData);
126     userData.encodeType = SmsEncodingType::IA5;
127     cdmaSmsMessage->AnalsisUserData(userData);
128     userData.encodeType = SmsEncodingType::ASCII_7BIT;
129     cdmaSmsMessage->AnalsisUserData(userData);
130     userData.encodeType = SmsEncodingType::LATIN_HEBREW;
131     cdmaSmsMessage->AnalsisUserData(userData);
132     userData.encodeType = SmsEncodingType::LATIN;
133     cdmaSmsMessage->AnalsisUserData(userData);
134     userData.encodeType = SmsEncodingType::OCTET;
135     cdmaSmsMessage->AnalsisUserData(userData);
136     userData.encodeType = SmsEncodingType::SHIFT_JIS;
137     cdmaSmsMessage->AnalsisUserData(userData);
138     userData.encodeType = SmsEncodingType::RESERVED;
139     cdmaSmsMessage->AnalsisUserData(userData);
140     deliver.cmasData.dataLen = DATA_LENGTH;
141     cdmaSmsMessage->AnalsisCMASMsg(deliver);
142     cbMsg.telesvcMsg.type = TeleserviceMsgType::RESERVED;
143     cdmaSmsMessage->AnalysisCbMsg(cbMsg);
144     cbMsg.telesvcMsg.type = TeleserviceMsgType::DELIVER;
145     cdmaSmsMessage->AnalysisCbMsg(cbMsg);
146     cbMsg.serviceCtg = static_cast<uint16_t>(SmsServiceCtg::CMAS_AMBER);
147     cdmaSmsMessage->AnalysisCbMsg(cbMsg);
148     userData.userData.headerCnt = HEADER_LENGTH;
149     cdmaSmsMessage->bHeaderInd_ = true;
150     cdmaSmsMessage->AnalsisHeader(userData);
151     EXPECT_FALSE(cdmaSmsMessage->AddUserDataHeader(header));
152 }
153 
154 /**
155  * @tc.number   Telephony_SmsMmsGtest_SmsPduBuffer_0001
156  * @tc.name     Test SmsPduBuffer
157  * @tc.desc     Function test
158  */
159 HWTEST_F(BranchCdmaSmsTest, SmsPduBuffer_0001, Function | MediumTest | Level1)
160 {
161     auto buffer = std::make_shared<SmsPduBuffer>();
162     EXPECT_TRUE(buffer->IsEmpty());
163     EXPECT_EQ(buffer->GetIndex(), 0);
164     EXPECT_FALSE(buffer->SetIndex(1));
165     EXPECT_EQ(buffer->GetIndex(), 0);
166     EXPECT_TRUE(buffer->SetIndex(0));
167     EXPECT_EQ(buffer->GetIndex(), 0);
168     EXPECT_EQ(buffer->MoveForward(), 0);
169     EXPECT_EQ(buffer->MoveForward(1), 0);
170     EXPECT_EQ(buffer->MoveBack(), 0);
171     EXPECT_EQ(buffer->MoveBack(1), 0);
172     EXPECT_EQ(buffer->MoveBack(2), 0);
173     EXPECT_EQ(buffer->MoveForward(0), 0);
174     EXPECT_EQ(buffer->SkipBits(), 0);
175 }
176 
177 /**
178  * @tc.number   Telephony_SmsMmsGtest_SmsReadBuffer_0001
179  * @tc.name     Test SmsReadBuffer
180  * @tc.desc     Function test
181  */
182 HWTEST_F(BranchCdmaSmsTest, SmsReadBuffer_0001, Function | MediumTest | Level1)
183 {
184     std::string pduHex = "0000021002";
185     std::string pdu = StringUtils::HexToString(pduHex);
186     uint16_t pduLen = pdu.length();
187 
188     auto buffer = std::make_shared<SmsReadBuffer>(pdu);
189     EXPECT_FALSE(buffer->IsEmpty());
190     EXPECT_EQ(buffer->GetIndex(), 0);
191     EXPECT_TRUE(buffer->SetIndex(1));
192     EXPECT_EQ(buffer->GetIndex(), 1);
193     EXPECT_TRUE(buffer->SetIndex(0));
194     EXPECT_EQ(buffer->GetIndex(), 0);
195     EXPECT_TRUE(buffer->SetIndex(pduLen));
196     EXPECT_EQ(buffer->GetIndex(), pduLen);
197     EXPECT_FALSE(buffer->SetIndex(pduLen + 1));
198     EXPECT_EQ(buffer->GetIndex(), pduLen);
199 
200     EXPECT_TRUE(buffer->SetIndex(0));
201     EXPECT_EQ(buffer->GetIndex(), 0);
202     EXPECT_EQ(buffer->MoveForward(), 0);
203     EXPECT_EQ(buffer->MoveForward(1), 1);
204     EXPECT_EQ(buffer->MoveBack(1), 2);
205     EXPECT_EQ(buffer->MoveForward(0), 1);
206     EXPECT_EQ(buffer->MoveBack(2), 1);
207     EXPECT_EQ(buffer->MoveBack(1), 1);
208     EXPECT_EQ(buffer->GetIndex(), 0);
209 
210     EXPECT_TRUE(buffer->SetIndex(pduLen));
211     EXPECT_EQ(buffer->GetIndex(), pduLen);
212     EXPECT_EQ(buffer->MoveForward(), pduLen);
213     EXPECT_EQ(buffer->MoveForward(), pduLen);
214     EXPECT_EQ(buffer->MoveBack(1), pduLen);
215     EXPECT_EQ(buffer->GetIndex(), pduLen - 1);
216 
217     uint16_t index = buffer->GetIndex();
218     EXPECT_EQ(buffer->SkipBits(), index);
219 }
220 
221 /**
222  * @tc.number   Telephony_SmsMmsGtest_SmsReadBuffer_0002
223  * @tc.name     Test SmsReadBuffer
224  * @tc.desc     Function test
225  */
226 HWTEST_F(BranchCdmaSmsTest, SmsReadBuffer_0002, Function | MediumTest | Level1)
227 {
228     std::string pduHex = "00000210020000021002";
229     std::string pdu = StringUtils::HexToString(pduHex);
230     uint16_t pduLen = pdu.length();
231 
232     auto buffer = std::make_shared<SmsReadBuffer>(pdu);
233     EXPECT_FALSE(buffer->IsEmpty());
234 
235     buffer->SetIndex(0);
236     uint8_t v = 0;
237     for (uint16_t i = 0; i < pduLen; i++) {
238         EXPECT_TRUE(buffer->ReadByte(v));
239     }
240     EXPECT_FALSE(buffer->ReadByte(v));
241 
242     buffer->SetIndex(0);
243     uint16_t v2 = 0;
244     uint16_t index = buffer->GetIndex();
245     do {
246         EXPECT_TRUE(buffer->ReadWord(v2));
247         index += 2;
248         EXPECT_EQ(buffer->GetIndex(), index);
249     } while (index < pduLen);
250     index = buffer->GetIndex();
251     EXPECT_FALSE(buffer->ReadWord(v2));
252     EXPECT_EQ(buffer->GetIndex(), index);
253 }
254 
255 /**
256  * @tc.number   Telephony_SmsMmsGtest_SmsReadBuffer_0003
257  * @tc.name     Test SmsReadBuffer
258  * @tc.desc     Function test
259  */
260 HWTEST_F(BranchCdmaSmsTest, SmsReadBuffer_0003, Function | MediumTest | Level1)
261 {
262     std::string pduHex = "00000210020000021002";
263     std::string pdu = StringUtils::HexToString(pduHex);
264     uint16_t pduLen = pdu.length();
265 
266     auto buffer = std::make_shared<SmsReadBuffer>(pdu);
267     EXPECT_FALSE(buffer->IsEmpty());
268 
269     buffer->SetIndex(0);
270     uint32_t bitLen = pduLen * BIT8;
271     uint8_t v = 0;
272     for (uint32_t i = 0; i < bitLen; i++) {
273         EXPECT_TRUE(buffer->ReadBits(v));
274     }
275     EXPECT_FALSE(buffer->ReadBits(v));
276     uint16_t index = buffer->GetIndex();
277     EXPECT_EQ(buffer->SkipBits(), index);
278 
279     buffer->SetIndex(0);
280     uint8_t bits = BIT0;
281     uint32_t bitIndex = 0;
282     do {
283         bits++;
284         if (bits > BIT8) {
285             EXPECT_FALSE(buffer->ReadBits(v, bits));
286             if (bits == 10) {
287                 bits = BIT0;
288             }
289         } else {
290             if (bitIndex + bits <= bitLen) {
291                 bitIndex += bits;
292                 EXPECT_TRUE(buffer->ReadBits(v, bits));
293             } else {
294                 EXPECT_FALSE(buffer->ReadBits(v, bits));
295             }
296         }
297     } while (bitIndex < bitLen);
298 
299     buffer->SetIndex(0);
300     index = buffer->GetIndex();
301     EXPECT_EQ(buffer->SkipBits(), index);
302     EXPECT_TRUE(buffer->ReadBits(v));
303     EXPECT_FALSE(buffer->SetIndex(0));
304     EXPECT_EQ(buffer->SkipBits(), index + 1);
305     EXPECT_TRUE(buffer->SetIndex(0));
306 }
307 
308 /**
309  * @tc.number   Telephony_SmsMmsGtest_SmsReadBuffer_0004
310  * @tc.name     Test SmsReadBuffer
311  * @tc.desc     Function test
312  */
313 HWTEST_F(BranchCdmaSmsTest, SmsReadBuffer_0004, Function | MediumTest | Level1)
314 {
315     auto buffer = std::make_shared<SmsReadBuffer>(StringUtils::HexToString("00"));
316     EXPECT_TRUE(buffer->IsEmpty());
317     buffer = std::make_shared<SmsReadBuffer>(StringUtils::HexToString("0000"));
318     EXPECT_FALSE(buffer->IsEmpty());
319     buffer = std::make_shared<SmsReadBuffer>(StringUtils::HexToString("000002"));
320     EXPECT_FALSE(buffer->IsEmpty());
321     buffer = std::make_shared<SmsReadBuffer>(StringUtils::HexToString("0000021002"));
322     EXPECT_FALSE(buffer->IsEmpty());
323     std::string s1(PDU_BUFFER_MAX_SIZE * 2, '0');
324     buffer = std::make_shared<SmsReadBuffer>(StringUtils::HexToString(s1));
325     EXPECT_FALSE(buffer->IsEmpty());
326     std::string s2((PDU_BUFFER_MAX_SIZE + 1) * 2, '0');
327     buffer = std::make_shared<SmsReadBuffer>(StringUtils::HexToString(s2));
328     EXPECT_FALSE(buffer->IsEmpty());
329     std::string s3((PDU_BUFFER_MAX_SIZE + 2) * 2, '0');
330     buffer = std::make_shared<SmsReadBuffer>(StringUtils::HexToString(s3));
331     EXPECT_TRUE(buffer->IsEmpty());
332 }
333 
334 /**
335  * @tc.number   Telephony_SmsMmsGtest_SmsWriteBuffer_0001
336  * @tc.name     Test SmsWriteBuffer
337  * @tc.desc     Function test
338  */
339 HWTEST_F(BranchCdmaSmsTest, SmsWriteBuffer_0001, Function | MediumTest | Level1)
340 {
341     uint16_t pduLen = PDU_BUFFER_MAX_SIZE + 1;
342     auto buffer = std::make_shared<SmsWriteBuffer>();
343     EXPECT_FALSE(buffer->IsEmpty());
344     EXPECT_EQ(buffer->GetIndex(), 0);
345     EXPECT_TRUE(buffer->SetIndex(1));
346     EXPECT_EQ(buffer->GetIndex(), 1);
347     EXPECT_TRUE(buffer->SetIndex(0));
348     EXPECT_EQ(buffer->GetIndex(), 0);
349     EXPECT_TRUE(buffer->SetIndex(pduLen));
350     EXPECT_EQ(buffer->GetIndex(), pduLen);
351     EXPECT_FALSE(buffer->SetIndex(pduLen + 1));
352     EXPECT_EQ(buffer->GetIndex(), pduLen);
353 
354     EXPECT_TRUE(buffer->SetIndex(0));
355     EXPECT_EQ(buffer->GetIndex(), 0);
356     EXPECT_EQ(buffer->MoveForward(), 0);
357     EXPECT_EQ(buffer->MoveForward(1), 1);
358     EXPECT_EQ(buffer->MoveBack(1), 2);
359     EXPECT_EQ(buffer->MoveForward(0), 1);
360     EXPECT_EQ(buffer->MoveBack(2), 1);
361     EXPECT_EQ(buffer->MoveBack(1), 1);
362     EXPECT_EQ(buffer->GetIndex(), 0);
363 
364     EXPECT_TRUE(buffer->SetIndex(pduLen));
365     EXPECT_EQ(buffer->GetIndex(), pduLen);
366     EXPECT_EQ(buffer->MoveForward(), pduLen);
367     EXPECT_EQ(buffer->MoveForward(), pduLen);
368     EXPECT_EQ(buffer->MoveBack(1), pduLen);
369     EXPECT_EQ(buffer->GetIndex(), pduLen - 1);
370 
371     uint16_t index = buffer->GetIndex();
372     EXPECT_EQ(buffer->SkipBits(), index);
373 }
374 
375 /**
376  * @tc.number   Telephony_SmsMmsGtest_SmsWriteBuffer_0002
377  * @tc.name     Test SmsWriteBuffer
378  * @tc.desc     Function test
379  */
380 HWTEST_F(BranchCdmaSmsTest, SmsWriteBuffer_0002, Function | MediumTest | Level1)
381 {
382     uint16_t pduLen = PDU_BUFFER_MAX_SIZE + 1;
383     auto buffer = std::make_shared<SmsWriteBuffer>();
384     EXPECT_FALSE(buffer->IsEmpty());
385 
386     EXPECT_EQ(buffer->GetPduBuffer(), nullptr);
387 
388     buffer->SetIndex(0);
389     uint8_t v = 0;
390     for (uint16_t i = 0; i < pduLen; i++) {
391         v++;
392         if (v == 0xff) {
393             v = 0;
394         }
395         EXPECT_TRUE(buffer->InsertByte(v, i));
396     }
397     EXPECT_FALSE(buffer->InsertByte(v, pduLen));
398 
399     buffer->SetIndex(0);
400     for (uint16_t i = 0; i < pduLen; i++) {
401         v++;
402         if (v == 0xff) {
403             v = 0;
404         }
405         EXPECT_TRUE(buffer->WriteByte(v));
406         EXPECT_EQ(buffer->GetIndex(), i + 1);
407     }
408     uint16_t index = buffer->GetIndex();
409     EXPECT_FALSE(buffer->WriteByte(v));
410     EXPECT_EQ(buffer->GetIndex(), index);
411 
412     buffer->SetIndex(1);
413     std::unique_ptr<std::vector<uint8_t>> data = buffer->GetPduBuffer();
414     EXPECT_NE(data, nullptr);
415     EXPECT_EQ(data->size(), 1);
416 
417     buffer->SetIndex(0);
418     uint16_t v2 = 0;
419     index = buffer->GetIndex();
420     do {
421         v2++;
422         if (v2 == 0xffff) {
423             v = 0;
424         }
425         EXPECT_TRUE(buffer->WriteWord(v2));
426         index += 2;
427         EXPECT_EQ(buffer->GetIndex(), index);
428     } while (index < pduLen);
429     index = buffer->GetIndex();
430     EXPECT_FALSE(buffer->WriteByte(v));
431     EXPECT_EQ(buffer->GetIndex(), index);
432 }
433 
434 /**
435  * @tc.number   Telephony_SmsMmsGtest_SmsWriteBuffer_0003
436  * @tc.name     Test SmsWriteBuffer
437  * @tc.desc     Function test
438  */
439 HWTEST_F(BranchCdmaSmsTest, SmsWriteBuffer_0003, Function | MediumTest | Level1)
440 {
441     uint16_t pduLen = PDU_BUFFER_MAX_SIZE + 1;
442     auto buffer = std::make_shared<SmsWriteBuffer>();
443     EXPECT_FALSE(buffer->IsEmpty());
444 
445     buffer->SetIndex(0);
446     uint32_t bitLen = pduLen * BIT8;
447     uint8_t v = 0;
448     for (uint32_t i = 0; i < bitLen; i++) {
449         EXPECT_TRUE(buffer->WriteBits(v));
450     }
451     EXPECT_FALSE(buffer->WriteBits(v));
452     uint16_t index = buffer->GetIndex();
453     EXPECT_EQ(buffer->SkipBits(), index);
454 
455     buffer->SetIndex(0);
456     uint8_t bits = BIT0;
457     uint32_t bitIndex = 0;
458     do {
459         bits++;
460         if (bits > BIT8) {
461             EXPECT_FALSE(buffer->WriteBits(v, bits));
462             if (bits == 10) {
463                 bits = BIT0;
464             }
465         } else {
466             if (bitIndex + bits <= bitLen) {
467                 bitIndex += bits;
468                 EXPECT_TRUE(buffer->WriteBits(v, bits));
469             } else {
470                 EXPECT_FALSE(buffer->WriteBits(v, bits));
471             }
472         }
473     } while (bitIndex < bitLen);
474 
475     buffer->SetIndex(0);
476     index = buffer->GetIndex();
477     EXPECT_EQ(buffer->SkipBits(), index);
478     EXPECT_TRUE(buffer->WriteBits(v));
479     EXPECT_FALSE(buffer->SetIndex(0));
480     EXPECT_EQ(buffer->SkipBits(), index + 1);
481     EXPECT_TRUE(buffer->SetIndex(0));
482 
483     buffer->SetIndex(0);
484     EXPECT_EQ(buffer->GetPduBuffer(), nullptr);
485     buffer->SetIndex(1);
486     index = buffer->GetIndex();
487     EXPECT_EQ(buffer->GetPduBuffer()->size(), index);
488     EXPECT_TRUE(buffer->WriteBits(v));
489     EXPECT_EQ(buffer->GetPduBuffer(), nullptr);
490     EXPECT_EQ(buffer->SkipBits(), index + 1);
491     EXPECT_EQ(buffer->GetPduBuffer()->size(), static_cast<unsigned long>(index + 1));
492 }
493 
494 /**
495  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsTransportMessage_0001
496  * @tc.name     Test CdmaSmsTransportMessage
497  * @tc.desc     Function test
498  */
499 HWTEST_F(BranchCdmaSmsTest, CdmaSmsTransportMessage_0001, Function | MediumTest | Level1)
500 {
501     auto message = std::make_shared<CdmaSmsTransportMessage>();
502     EXPECT_TRUE(message->IsEmpty());
503 
504     auto buffer1 = std::make_shared<SmsWriteBuffer>();
505     EXPECT_FALSE(buffer1->IsEmpty());
506     EXPECT_FALSE(message->Encode(*buffer1));
507 
508     std::stringstream ss;
509     ss.clear();
510     ss << static_cast<uint8_t>(CdmaTransportMsgType::P2P);
511     auto buffer2 = std::make_shared<SmsReadBuffer>(ss.str());
512     EXPECT_TRUE(buffer2->IsEmpty());
513     EXPECT_FALSE(message->Decode(*buffer2));
514 
515     ss << CdmaSmsParameterRecord::TELESERVICE_ID;
516     auto buffer3 = std::make_shared<SmsReadBuffer>(ss.str());
517     EXPECT_FALSE(buffer3->IsEmpty());
518     EXPECT_FALSE(message->Decode(*buffer3));
519 }
520 
521 /**
522  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsTransportMessage_0002
523  * @tc.name     Test CdmaSmsTransportMessage
524  * @tc.desc     Function test
525  */
526 HWTEST_F(BranchCdmaSmsTest, CdmaSmsTransportMessage_0002, Function | MediumTest | Level1)
527 {
528     do {
529         CdmaTransportMsg msg;
530         msg.type = CdmaTransportMsgType::RESERVED;
531         auto message = CdmaSmsTransportMessage::CreateTransportMessage(msg);
532         EXPECT_EQ(message, nullptr);
533     } while (0);
534 
535     uint8_t type = 0;
536     for (type = 0; type < static_cast<uint8_t>(CdmaTransportMsgType::RESERVED); type++) {
537         CdmaTransportMsg msg;
538         msg.type = CdmaTransportMsgType(type);
539         auto message = CdmaSmsTransportMessage::CreateTransportMessage(msg);
540         EXPECT_NE(message, nullptr);
541         auto buffer = std::make_shared<SmsWriteBuffer>();
542         EXPECT_FALSE(buffer->IsEmpty());
543         message->Encode(*buffer);
544         SmsReadBuffer rBuffer(StringUtils::HexToString("000000"));
545         EXPECT_FALSE(message->Decode(rBuffer));
546     }
547 
548     CdmaTransportMsg msg;
549     std::vector<std::string> pduHex;
550     pduHex.clear();
551     pduHex.push_back("00");
552     pduHex.push_back("0300");
553     for (uint8_t i = 0; i < pduHex.size(); i++) {
554         SmsReadBuffer buffer(StringUtils::HexToString(pduHex[i]));
555         auto message = CdmaSmsTransportMessage::CreateTransportMessage(msg, buffer);
556         EXPECT_EQ(message, nullptr);
557     }
558 
559     pduHex.clear();
560     pduHex.push_back("0000");
561     pduHex.push_back("0100");
562     pduHex.push_back("0200");
563     for (uint8_t i = 0; i < pduHex.size(); i++) {
564         SmsReadBuffer buffer(StringUtils::HexToString(pduHex[i]));
565         auto message = CdmaSmsTransportMessage::CreateTransportMessage(msg, buffer);
566         EXPECT_NE(message, nullptr);
567         EXPECT_FALSE(message->Decode(buffer));
568     }
569 
570     pduHex.clear();
571     pduHex.push_back("0000021002");
572     pduHex.push_back("0101020000");
573     pduHex.push_back("0207020000");
574     for (uint8_t i = 0; i < pduHex.size(); i++) {
575         SmsReadBuffer buffer(StringUtils::HexToString(pduHex[i]));
576         auto message = CdmaSmsTransportMessage::CreateTransportMessage(msg, buffer);
577         EXPECT_NE(message, nullptr);
578         EXPECT_TRUE(message->Decode(buffer));
579     }
580 }
581 
582 /**
583  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsTransportMessage_0003
584  * @tc.name     Test CdmaSmsTransportMessage
585  * @tc.desc     Function test
586  */
587 HWTEST_F(BranchCdmaSmsTest, CdmaSmsTransportMessage_0003, Function | MediumTest | Level1)
588 {
589     auto message = std::make_shared<CdmaSmsTransportMessage>();
590     EXPECT_TRUE(message->IsEmpty());
591 
592     auto buffer1 = std::make_shared<SmsWriteBuffer>();
593     EXPECT_FALSE(buffer1->IsEmpty());
594     EXPECT_FALSE(message->Encode(*buffer1));
595 
596     std::stringstream ss;
597     ss.clear();
598     ss << static_cast<uint8_t>(CdmaTransportMsgType::P2P);
599     ss << CdmaSmsParameterRecord::TELESERVICE_ID;
600     auto buffer2 = std::make_shared<SmsReadBuffer>(ss.str());
601     EXPECT_FALSE(buffer2->IsEmpty());
602     EXPECT_FALSE(message->Decode(*buffer2));
603 
604     CdmaTransportMsg msg;
605     msg.type = CdmaTransportMsgType::P2P;
606     auto message2 = CdmaSmsTransportMessage::CreateTransportMessage(msg);
607     EXPECT_NE(message2, nullptr);
608     auto message3 = CdmaSmsTransportMessage::CreateTransportMessage(msg, *buffer2);
609     EXPECT_NE(message3, nullptr);
610     auto message4 = std::make_shared<CdmaSmsP2pMessage>(msg.data.p2p);
611     EXPECT_NE(message4, nullptr);
612     auto message5 = std::make_shared<CdmaSmsP2pMessage>(msg.data.p2p, *buffer2);
613     EXPECT_NE(message5, nullptr);
614     auto message6 = std::make_shared<CdmaSmsBroadcastMessage>(msg.data.broadcast);
615     EXPECT_NE(message6, nullptr);
616     auto message7 = std::make_shared<CdmaSmsBroadcastMessage>(msg.data.broadcast, *buffer2);
617     EXPECT_NE(message7, nullptr);
618     auto message8 = std::make_shared<CdmaSmsAckMessage>(msg.data.ack);
619     EXPECT_NE(message8, nullptr);
620     auto message9 = std::make_shared<CdmaSmsAckMessage>(msg.data.ack, *buffer2);
621     EXPECT_NE(message9, nullptr);
622 }
623 
624 /**
625  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsTeleserviceMessage_0001
626  * @tc.name     Test CdmaSmsTeleserviceMessage
627  * @tc.desc     Function test
628  */
629 HWTEST_F(BranchCdmaSmsTest, CdmaSmsTeleserviceMessage_0001, Function | MediumTest | Level1)
630 {
631     SmsWriteBuffer wBuffer;
632     SmsReadBuffer rBuffer(StringUtils::HexToString("0003200640"));
633     auto message = std::make_shared<CdmaSmsTeleserviceMessage>();
634     EXPECT_NE(message, nullptr);
635     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
636     EXPECT_FALSE(message->Encode(wBuffer));
637     EXPECT_FALSE(message->Decode(rBuffer));
638     EXPECT_EQ(CdmaSmsTeleserviceMessage::GetMessageType(rBuffer), CdmaSmsTeleserviceMessage::SUBMIT);
639 
640     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
641     CdmaTransportMsg msg;
642     auto message1 = std::make_shared<CdmaSmsSubmitMessage>(msg.data.p2p.telesvcMsg.data.submit);
643     EXPECT_NE(message1, nullptr);
644     EXPECT_FALSE(message1->Encode(wBuffer));
645     EXPECT_FALSE(message1->Decode(rBuffer));
646     auto message2 = std::make_shared<CdmaSmsSubmitMessage>(msg.data.p2p.telesvcMsg.data.submit, rBuffer);
647     EXPECT_NE(message2, nullptr);
648     EXPECT_FALSE(message2->Encode(wBuffer));
649     EXPECT_FALSE(message2->Decode(rBuffer));
650     auto message3 = std::make_shared<CdmaSmsCancelMessage>(msg.data.p2p.telesvcMsg.data.cancel);
651     EXPECT_NE(message3, nullptr);
652     EXPECT_FALSE(message3->Encode(wBuffer));
653     EXPECT_FALSE(message3->Decode(rBuffer));
654     auto message4 = std::make_shared<CdmaSmsDeliverReport>(msg.data.p2p.telesvcMsg.data.report);
655     EXPECT_NE(message4, nullptr);
656     EXPECT_FALSE(message4->Encode(wBuffer));
657     EXPECT_FALSE(message4->Decode(rBuffer));
658     auto message5 = std::make_shared<CdmaSmsDeliverMessage>(msg.data.p2p.telesvcMsg.data.deliver, rBuffer);
659     EXPECT_NE(message5, nullptr);
660     EXPECT_FALSE(message5->Encode(wBuffer));
661     EXPECT_FALSE(message5->Decode(rBuffer));
662     auto message6 = std::make_shared<CdmaSmsDeliveryAck>(msg.data.p2p.telesvcMsg.data.deliveryAck, rBuffer);
663     EXPECT_NE(message6, nullptr);
664     EXPECT_FALSE(message6->Encode(wBuffer));
665     EXPECT_FALSE(message6->Decode(rBuffer));
666     auto message7 = std::make_shared<CdmaSmsUserAck>(msg.data.p2p.telesvcMsg.data.userAck, rBuffer);
667     EXPECT_NE(message7, nullptr);
668     EXPECT_FALSE(message7->Encode(wBuffer));
669     EXPECT_FALSE(message7->Decode(rBuffer));
670     auto message8 = std::make_shared<CdmaSmsReadAck>(msg.data.p2p.telesvcMsg.data.readAck, rBuffer);
671     EXPECT_NE(message8, nullptr);
672     EXPECT_FALSE(message8->Encode(wBuffer));
673     EXPECT_FALSE(message8->Decode(rBuffer));
674 }
675 
676 /**
677  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsParameterRecord_0001
678  * @tc.name     Test CdmaSmsParameterRecord
679  * @tc.desc     Function test
680  */
681 HWTEST_F(BranchCdmaSmsTest, CdmaSmsParameterRecord_0001, Function | MediumTest | Level1)
682 {
683     auto initValue = static_cast<uint16_t>(SmsTransTelsvcId::RESERVED);
684     auto testValue = static_cast<uint16_t>(SmsTransTelsvcId::CMT_95);
685     uint16_t v1 = testValue;
686     uint16_t v2 = initValue;
687 
688     auto message1 = std::make_shared<CdmaSmsTeleserviceId>(v1);
689     SmsWriteBuffer wBuffer;
690     EXPECT_TRUE(message1->Encode(wBuffer));
691     auto buffer = wBuffer.GetPduBuffer();
692     EXPECT_GT(buffer->size(), static_cast<uint32_t>(0));
693     std::stringstream ss;
694     ss.clear();
695     for (uint16_t i = 0; i < buffer->size(); i++) {
696         ss << (*buffer)[i];
697     }
698     SmsReadBuffer rBuffer(ss.str());
699     auto message2 = std::make_shared<CdmaSmsTeleserviceId>(v2);
700     EXPECT_TRUE(message2->Decode(rBuffer));
701     EXPECT_EQ(v2, testValue);
702 
703     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
704     EXPECT_FALSE(message1->Encode(wBuffer));
705     rBuffer.SetIndex(1);
706     EXPECT_FALSE(message1->Decode(rBuffer));
707 }
708 
709 /**
710  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsParameterRecord_0002
711  * @tc.name     Test CdmaSmsParameterRecord
712  * @tc.desc     Function test
713  */
714 HWTEST_F(BranchCdmaSmsTest, CdmaSmsParameterRecord_0002, Function | MediumTest | Level1)
715 {
716     auto initValue = static_cast<uint16_t>(SmsServiceCtg::RESERVED);
717     auto testValue = static_cast<uint16_t>(SmsServiceCtg::CMAS_TEST);
718     uint16_t v1 = testValue;
719     uint16_t v2 = initValue;
720 
721     auto message1 = std::make_shared<CdmaSmsServiceCategory>(v1);
722     SmsWriteBuffer wBuffer;
723     EXPECT_TRUE(message1->Encode(wBuffer));
724     auto buffer = wBuffer.GetPduBuffer();
725     EXPECT_GT(buffer->size(), 0);
726     std::stringstream ss;
727     ss.clear();
728     for (uint16_t i = 0; i < buffer->size(); i++) {
729         ss << (*buffer)[i];
730     }
731     SmsReadBuffer rBuffer(ss.str());
732     auto message2 = std::make_shared<CdmaSmsServiceCategory>(v2);
733     EXPECT_TRUE(message2->Decode(rBuffer));
734     EXPECT_EQ(v2, testValue);
735 
736     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
737     EXPECT_FALSE(message1->Encode(wBuffer));
738     rBuffer.SetIndex(1);
739     EXPECT_FALSE(message1->Decode(rBuffer));
740 }
741 
742 /**
743  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsParameterRecord_0003
744  * @tc.name     Test CdmaSmsParameterRecord
745  * @tc.desc     Function test
746  */
747 HWTEST_F(BranchCdmaSmsTest, CdmaSmsParameterRecord_0003, Function | MediumTest | Level1)
748 {
749     auto initValue = static_cast<uint32_t>(0);
750     auto testValue = static_cast<uint32_t>(5);
751     TransportAddr v1;
752     memset_s(&v1, sizeof(TransportAddr), 0x00, sizeof(TransportAddr));
753     v1.addrLen = testValue;
754     TransportAddr v2;
755     v2.addrLen = initValue;
756 
757     auto message1 = std::make_shared<CdmaSmsAddressParameter>(v1, CdmaSmsParameterRecord::DEST_ADDRESS);
758     SmsWriteBuffer wBuffer;
759     EXPECT_TRUE(message1->Encode(wBuffer));
760     auto buffer = wBuffer.GetPduBuffer();
761     EXPECT_GT(buffer->size(), 0);
762     std::stringstream ss;
763     ss.clear();
764     for (uint16_t i = 0; i < buffer->size(); i++) {
765         ss << (*buffer)[i];
766     }
767     SmsReadBuffer rBuffer(ss.str());
768     auto message2 = std::make_shared<CdmaSmsAddressParameter>(v2, CdmaSmsParameterRecord::DEST_ADDRESS);
769     EXPECT_TRUE(message2->Decode(rBuffer));
770     EXPECT_EQ(v2.addrLen, testValue);
771 
772     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
773     EXPECT_FALSE(message1->Encode(wBuffer));
774     rBuffer.SetIndex(1);
775     EXPECT_FALSE(message1->Decode(rBuffer));
776 }
777 
778 /**
779  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsParameterRecord_0004
780  * @tc.name     Test CdmaSmsParameterRecord
781  * @tc.desc     Function test
782  */
783 HWTEST_F(BranchCdmaSmsTest, CdmaSmsParameterRecord_0004, Function | MediumTest | Level1)
784 {
785     auto initValue = static_cast<uint32_t>(0);
786     auto testValue = static_cast<uint32_t>(5);
787     TransportSubAddr v1;
788     memset_s(&v1, sizeof(TransportSubAddr), 0x00, sizeof(TransportSubAddr));
789     v1.addrLen = testValue;
790     TransportSubAddr v2;
791     v2.addrLen = initValue;
792 
793     auto message1 = std::make_shared<CdmaSmsSubaddress>(v1, CdmaSmsParameterRecord::DEST_SUB_ADDRESS);
794     SmsWriteBuffer wBuffer;
795     EXPECT_TRUE(message1->Encode(wBuffer));
796     auto buffer = wBuffer.GetPduBuffer();
797     EXPECT_GT(buffer->size(), 0);
798     std::stringstream ss;
799     ss.clear();
800     for (uint16_t i = 0; i < buffer->size(); i++) {
801         ss << (*buffer)[i];
802     }
803     SmsReadBuffer rBuffer(ss.str());
804     auto message2 = std::make_shared<CdmaSmsSubaddress>(v2, CdmaSmsParameterRecord::DEST_SUB_ADDRESS);
805     EXPECT_TRUE(message2->Decode(rBuffer));
806     EXPECT_EQ(v2.addrLen, testValue);
807 
808     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
809     EXPECT_FALSE(message1->Encode(wBuffer));
810     rBuffer.SetIndex(1);
811     EXPECT_FALSE(message1->Decode(rBuffer));
812 }
813 
814 /**
815  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsParameterRecord_0005
816  * @tc.name     Test CdmaSmsParameterRecord
817  * @tc.desc     Function test
818  */
819 HWTEST_F(BranchCdmaSmsTest, CdmaSmsParameterRecord_0005, Function | MediumTest | Level1)
820 {
821     auto initValue = static_cast<uint8_t>(0);
822     auto testValue = static_cast<uint8_t>(5);
823     uint8_t v1 = testValue;
824     uint8_t v2 = initValue;
825 
826     auto message1 = std::make_shared<CdmaSmsBearerReply>(v1);
827     SmsWriteBuffer wBuffer;
828     EXPECT_TRUE(message1->Encode(wBuffer));
829     auto buffer = wBuffer.GetPduBuffer();
830     EXPECT_GT(buffer->size(), 0);
831     std::stringstream ss;
832     ss.clear();
833     for (uint16_t i = 0; i < buffer->size(); i++) {
834         ss << (*buffer)[i];
835     }
836     SmsReadBuffer rBuffer(ss.str());
837     auto message2 = std::make_shared<CdmaSmsBearerReply>(v2);
838     EXPECT_TRUE(message2->Decode(rBuffer));
839     EXPECT_EQ(v2, testValue);
840 
841     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
842     EXPECT_FALSE(message1->Encode(wBuffer));
843     rBuffer.SetIndex(1);
844     EXPECT_FALSE(message1->Decode(rBuffer));
845 }
846 
847 /**
848  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsParameterRecord_0006
849  * @tc.name     Test CdmaSmsParameterRecord
850  * @tc.desc     Function test
851  */
852 HWTEST_F(BranchCdmaSmsTest, CdmaSmsParameterRecord_0006, Function | MediumTest | Level1)
853 {
854     auto initValue = TeleserviceMsgType::RESERVED;
855     auto testValue = TeleserviceMsgType::SUBMIT;
856     CdmaTeleserviceMsg v1;
857     memset_s(&v1, sizeof(CdmaTeleserviceMsg), 0x00, sizeof(CdmaTeleserviceMsg));
858     v1.type = testValue;
859     CdmaTeleserviceMsg v2;
860     v2.type = initValue;
861 
862     auto message1 = std::make_shared<CdmaSmsBearerData>(v1);
863     SmsWriteBuffer wBuffer;
864     EXPECT_TRUE(message1->Encode(wBuffer));
865     auto buffer = wBuffer.GetPduBuffer();
866     EXPECT_GT(buffer->size(), 0);
867     std::stringstream ss;
868     ss.clear();
869     for (uint16_t i = 0; i < buffer->size(); i++) {
870         ss << (*buffer)[i];
871     }
872     SmsReadBuffer rBuffer(ss.str());
873     rBuffer.SetIndex(2);
874     auto message2 = std::make_shared<CdmaSmsBearerData>(v2, rBuffer);
875     rBuffer.SetIndex(0);
876     EXPECT_TRUE(message2->Decode(rBuffer));
877     EXPECT_EQ(v2.type, testValue);
878 
879     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
880     EXPECT_FALSE(message1->Encode(wBuffer));
881     rBuffer.SetIndex(1);
882     EXPECT_FALSE(message1->Decode(rBuffer));
883 }
884 
885 /**
886  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsParameterRecord_0007
887  * @tc.name     Test CdmaSmsParameterRecord
888  * @tc.desc     Function test
889  */
890 HWTEST_F(BranchCdmaSmsTest, CdmaSmsParameterRecord_0007, Function | MediumTest | Level1)
891 {
892     auto initValue = TransportErrClass::NONE;
893     auto testValue = TransportErrClass::TEMPORARY;
894     TransportCauseCode v1;
895     memset_s(&v1, sizeof(TransportCauseCode), 0x00, sizeof(TransportCauseCode));
896     v1.errorClass = testValue;
897     TransportCauseCode v2;
898     v2.errorClass = initValue;
899 
900     auto message1 = std::make_shared<CdmaSmsCauseCodes>(v1);
901     SmsWriteBuffer wBuffer;
902     EXPECT_TRUE(message1->Encode(wBuffer));
903     auto buffer = wBuffer.GetPduBuffer();
904     EXPECT_GT(buffer->size(), 0);
905     std::stringstream ss;
906     ss.clear();
907     for (uint16_t i = 0; i < buffer->size(); i++) {
908         ss << (*buffer)[i];
909     }
910     SmsReadBuffer rBuffer(ss.str());
911     auto message2 = std::make_shared<CdmaSmsCauseCodes>(v2);
912     EXPECT_TRUE(message2->Decode(rBuffer));
913     EXPECT_EQ(v2.errorClass, testValue);
914 
915     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
916     EXPECT_FALSE(message1->Encode(wBuffer));
917     rBuffer.SetIndex(1);
918     EXPECT_FALSE(message1->Decode(rBuffer));
919 }
920 
921 /**
922  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0001
923  * @tc.name     Test CdmaSmsSubParameter
924  * @tc.desc     Function test
925  */
926 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0001, Function | MediumTest | Level1)
927 {
928     auto initValue = static_cast<uint8_t>(0);
929     auto testValue = static_cast<uint8_t>(5);
930     uint8_t v1 = testValue;
931     uint8_t v2 = initValue;
932 
933     auto message1 = std::make_shared<CdmaSmsBaseParameter>(CdmaSmsSubParameter::USER_RESPONSE_CODE, v1);
934     SmsWriteBuffer wBuffer;
935     EXPECT_TRUE(message1->Encode(wBuffer));
936     auto buffer = wBuffer.GetPduBuffer();
937     EXPECT_GT(buffer->size(), 0);
938     std::stringstream ss;
939     ss.clear();
940     for (uint16_t i = 0; i < buffer->size(); i++) {
941         ss << (*buffer)[i];
942     }
943     SmsReadBuffer rBuffer(ss.str());
944     auto message2 = std::make_shared<CdmaSmsBaseParameter>(CdmaSmsSubParameter::USER_RESPONSE_CODE, v2);
945     EXPECT_TRUE(message2->Decode(rBuffer));
946     EXPECT_EQ(v2, testValue);
947 
948     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
949     EXPECT_FALSE(message1->Encode(wBuffer));
950     rBuffer.SetIndex(1);
951     EXPECT_FALSE(message1->Decode(rBuffer));
952 }
953 
954 /**
955  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0002
956  * @tc.name     Test CdmaSmsSubParameter
957  * @tc.desc     Function test
958  */
959 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0002, Function | MediumTest | Level1)
960 {
961     auto message1 = std::make_shared<CdmaSmsReservedParameter>(CdmaSmsSubParameter::USER_RESPONSE_CODE);
962     SmsWriteBuffer wBuffer;
963     EXPECT_TRUE(message1->Encode(wBuffer));
964     std::stringstream ss;
965     ss.clear();
966     ss << static_cast<uint8_t>(CdmaSmsSubParameter::USER_RESPONSE_CODE);
967     ss << static_cast<uint8_t>(0x01);
968     ss << static_cast<uint8_t>(0x00);
969     SmsReadBuffer rBuffer(ss.str());
970     auto message2 = std::make_shared<CdmaSmsReservedParameter>(CdmaSmsSubParameter::USER_RESPONSE_CODE);
971     EXPECT_TRUE(message2->Decode(rBuffer));
972 
973     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
974     EXPECT_TRUE(message1->Encode(wBuffer));
975     rBuffer.SetIndex(1);
976     EXPECT_FALSE(message1->Decode(rBuffer));
977 }
978 
979 /**
980  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0003
981  * @tc.name     Test CdmaSmsSubParameter
982  * @tc.desc     Function test
983  */
984 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0003, Function | MediumTest | Level1)
985 {
986     auto initValue = static_cast<uint16_t>(0x0);
987     auto testValue = static_cast<uint16_t>(0x10);
988     SmsTeleSvcMsgId v1;
989     memset_s(&v1, sizeof(SmsTeleSvcMsgId), 0x00, sizeof(SmsTeleSvcMsgId));
990     v1.msgId = testValue;
991     SmsTeleSvcMsgId v2;
992     v2.msgId = initValue;
993     uint8_t type = static_cast<uint8_t>(TeleserviceMsgType::SUBMIT);
994 
995     auto message1 = std::make_shared<CdmaSmsMessageId>(v1, type);
996     SmsWriteBuffer wBuffer;
997     EXPECT_TRUE(message1->Encode(wBuffer));
998     auto buffer = wBuffer.GetPduBuffer();
999     EXPECT_GT(buffer->size(), 0);
1000     std::stringstream ss;
1001     ss.clear();
1002     for (uint16_t i = 0; i < buffer->size(); i++) {
1003         ss << (*buffer)[i];
1004     }
1005     SmsReadBuffer rBuffer(ss.str());
1006     auto message2 = std::make_shared<CdmaSmsMessageId>(v2, type);
1007     EXPECT_TRUE(message2->Decode(rBuffer));
1008     EXPECT_EQ(message2->GetMessageType(), type);
1009     EXPECT_EQ(v2.msgId, testValue);
1010 
1011     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1012     EXPECT_FALSE(message1->Encode(wBuffer));
1013     rBuffer.SetIndex(1);
1014     EXPECT_FALSE(message1->Decode(rBuffer));
1015 }
1016 
1017 /**
1018  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0004
1019  * @tc.name     Test CdmaSmsSubParameter
1020  * @tc.desc     Function test
1021  */
1022 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0004, Function | MediumTest | Level1)
1023 {
1024     auto initValue = SmsEncodingType::RESERVED;
1025     auto testValue = SmsEncodingType::ASCII_7BIT;
1026     SmsTeleSvcUserData v1;
1027     memset_s(&v1, sizeof(SmsTeleSvcUserData), 0x00, sizeof(SmsTeleSvcUserData));
1028     v1.encodeType = testValue;
1029     SmsTeleSvcUserData v2;
1030     v2.encodeType = initValue;
1031     bool headerInd = false;
1032 
1033     auto message1 = std::make_shared<CdmaSmsUserData>(v1, headerInd);
1034     SmsWriteBuffer wBuffer;
1035     EXPECT_TRUE(message1->Encode(wBuffer));
1036     auto buffer = wBuffer.GetPduBuffer();
1037     EXPECT_GT(buffer->size(), 0);
1038     std::stringstream ss;
1039     ss.clear();
1040     for (uint16_t i = 0; i < buffer->size(); i++) {
1041         ss << (*buffer)[i];
1042     }
1043     SmsReadBuffer rBuffer(ss.str());
1044     auto message2 = std::make_shared<CdmaSmsUserData>(v2, headerInd);
1045     EXPECT_TRUE(message2->Decode(rBuffer));
1046 
1047     EXPECT_EQ(v2.encodeType, testValue);
1048 
1049     wBuffer.SetIndex(0);
1050     EXPECT_TRUE(message1->EncodeHeader7Bit(wBuffer));
1051     EXPECT_TRUE(message1->EncodeAscii7Bit(wBuffer));
1052     EXPECT_TRUE(message1->EncodeGsm7Bit(wBuffer));
1053     EXPECT_TRUE(message1->EncodeUnicode(wBuffer));
1054 
1055     rBuffer.SetIndex(0);
1056     EXPECT_EQ(message2->DecodeHeader7Bit(rBuffer), 0);
1057     EXPECT_TRUE(message2->DecodeAscii7Bit(rBuffer, 0, 0));
1058     EXPECT_TRUE(message2->DecodeGsm7Bit(rBuffer, 0, 0));
1059 
1060     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1061     EXPECT_FALSE(message1->Encode(wBuffer));
1062     rBuffer.SetIndex(1);
1063     EXPECT_FALSE(message1->Decode(rBuffer));
1064 }
1065 
1066 /**
1067  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0005
1068  * @tc.name     Test CdmaSmsSubParameter
1069  * @tc.desc     Function test
1070  */
1071 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0005, Function | MediumTest | Level1)
1072 {
1073     SmsTeleSvcCmasData v1;
1074     memset_s(&v1, sizeof(SmsTeleSvcCmasData), 0x00, sizeof(SmsTeleSvcCmasData));
1075     SmsTeleSvcCmasData v2;
1076 
1077     auto message1 = std::make_shared<CdmaSmsCmasData>(v1);
1078     SmsWriteBuffer wBuffer;
1079     EXPECT_FALSE(message1->Encode(wBuffer));
1080 
1081     std::stringstream ss;
1082     ss.clear();
1083     ss << static_cast<uint8_t>(CdmaSmsSubParameter::USER_DATA);
1084     uint8_t len = 100;
1085     ss << static_cast<uint8_t>(len);
1086     for (uint8_t i = 0; i < len; i++) {
1087         ss << static_cast<uint8_t>(0x00);
1088     }
1089     SmsReadBuffer rBuffer(ss.str());
1090     auto message2 = std::make_shared<CdmaSmsCmasData>(v2);
1091     EXPECT_TRUE(message2->Decode(rBuffer));
1092 
1093     rBuffer.SetIndex(0);
1094     EXPECT_TRUE(message2->DecodeType0Data(rBuffer));
1095     EXPECT_TRUE(message2->DecodeType1Data(rBuffer));
1096     EXPECT_TRUE(message2->DecodeType2Data(rBuffer));
1097     EXPECT_TRUE(message2->DecodeAbsTime(rBuffer));
1098 
1099     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1100     EXPECT_FALSE(message1->Encode(wBuffer));
1101     rBuffer.SetIndex(1);
1102     EXPECT_FALSE(message1->Decode(rBuffer));
1103 }
1104 
1105 /**
1106  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0006
1107  * @tc.name     Test CdmaSmsSubParameter
1108  * @tc.desc     Function test
1109  */
1110 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0006, Function | MediumTest | Level1)
1111 {
1112     auto initValue = static_cast<unsigned char>(0);
1113     auto testValue = static_cast<unsigned char>(5);
1114     SmsTimeAbs v1;
1115     memset_s(&v1, sizeof(SmsTimeAbs), 0x00, sizeof(SmsTimeAbs));
1116     v1.month = testValue;
1117     SmsTimeAbs v2;
1118     v2.month = initValue;
1119 
1120     auto message1 = std::make_shared<CdmaSmsAbsoluteTime>(CdmaSmsSubParameter::VALIDITY_PERIOD_ABSOLUTE, v1);
1121     SmsWriteBuffer wBuffer;
1122     EXPECT_TRUE(message1->Encode(wBuffer));
1123     auto buffer = wBuffer.GetPduBuffer();
1124     EXPECT_GT(buffer->size(), 0);
1125     std::stringstream ss;
1126     ss.clear();
1127     for (uint16_t i = 0; i < buffer->size(); i++) {
1128         ss << (*buffer)[i];
1129     }
1130     SmsReadBuffer rBuffer(ss.str());
1131     auto message2 = std::make_shared<CdmaSmsAbsoluteTime>(CdmaSmsSubParameter::VALIDITY_PERIOD_ABSOLUTE, v2);
1132     EXPECT_TRUE(message2->Decode(rBuffer));
1133     EXPECT_EQ(v2.month, testValue);
1134 
1135     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1136     EXPECT_FALSE(message1->Encode(wBuffer));
1137     rBuffer.SetIndex(1);
1138     EXPECT_FALSE(message1->Decode(rBuffer));
1139 }
1140 
1141 /**
1142  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0007
1143  * @tc.name     Test CdmaSmsSubParameter
1144  * @tc.desc     Function test
1145  */
1146 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0007, Function | MediumTest | Level1)
1147 {
1148     auto initValue = SmsPriorityIndicator::RESERVED;
1149     auto testValue = SmsPriorityIndicator::NORMAL;
1150     SmsPriorityIndicator v1 = testValue;
1151     SmsPriorityIndicator v2 = initValue;
1152 
1153     auto message1 = std::make_shared<CdmaSmsPriorityInd>(v1);
1154     SmsWriteBuffer wBuffer;
1155     EXPECT_TRUE(message1->Encode(wBuffer));
1156     auto buffer = wBuffer.GetPduBuffer();
1157     EXPECT_GT(buffer->size(), 0);
1158     std::stringstream ss;
1159     ss.clear();
1160     for (uint16_t i = 0; i < buffer->size(); i++) {
1161         ss << (*buffer)[i];
1162     }
1163     SmsReadBuffer rBuffer(ss.str());
1164     auto message2 = std::make_shared<CdmaSmsPriorityInd>(v2);
1165     EXPECT_TRUE(message2->Decode(rBuffer));
1166     EXPECT_EQ(v2, testValue);
1167 
1168     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1169     EXPECT_FALSE(message1->Encode(wBuffer));
1170     rBuffer.SetIndex(1);
1171     EXPECT_FALSE(message1->Decode(rBuffer));
1172 }
1173 
1174 /**
1175  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0008
1176  * @tc.name     Test CdmaSmsSubParameter
1177  * @tc.desc     Function test
1178  */
1179 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0008, Function | MediumTest | Level1)
1180 {
1181     auto initValue = SmsPrivacyIndicator::NOT_RESTRICTED;
1182     auto testValue = SmsPrivacyIndicator::RESTRICTED;
1183     SmsPrivacyIndicator v1 = testValue;
1184     SmsPrivacyIndicator v2 = initValue;
1185 
1186     auto message1 = std::make_shared<CdmaSmsPrivacyInd>(v1);
1187     SmsWriteBuffer wBuffer;
1188     EXPECT_TRUE(message1->Encode(wBuffer));
1189     auto buffer = wBuffer.GetPduBuffer();
1190     EXPECT_GT(buffer->size(), 0);
1191     std::stringstream ss;
1192     ss.clear();
1193     for (uint16_t i = 0; i < buffer->size(); i++) {
1194         ss << (*buffer)[i];
1195     }
1196     SmsReadBuffer rBuffer(ss.str());
1197     auto message2 = std::make_shared<CdmaSmsPrivacyInd>(v2);
1198     EXPECT_TRUE(message2->Decode(rBuffer));
1199     EXPECT_EQ(v2, testValue);
1200 
1201     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1202     EXPECT_FALSE(message1->Encode(wBuffer));
1203     rBuffer.SetIndex(1);
1204     EXPECT_FALSE(message1->Decode(rBuffer));
1205 }
1206 
1207 /**
1208  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0009
1209  * @tc.name     Test CdmaSmsSubParameter
1210  * @tc.desc     Function test
1211  */
1212 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0009, Function | MediumTest | Level1)
1213 {
1214     auto initValue = false;
1215     auto testValue = true;
1216     SmsReplyOption v1;
1217     memset_s(&v1, sizeof(SmsReplyOption), 0x00, sizeof(SmsReplyOption));
1218     v1.dak = testValue;
1219     SmsReplyOption v2;
1220     v2.dak = initValue;
1221 
1222     auto message1 = std::make_shared<CdmaSmsReplyOption>(v1);
1223     SmsWriteBuffer wBuffer;
1224     EXPECT_TRUE(message1->Encode(wBuffer));
1225     auto buffer = wBuffer.GetPduBuffer();
1226     EXPECT_GT(buffer->size(), 0);
1227     std::stringstream ss;
1228     ss.clear();
1229     for (uint16_t i = 0; i < buffer->size(); i++) {
1230         ss << (*buffer)[i];
1231     }
1232     SmsReadBuffer rBuffer(ss.str());
1233     auto message2 = std::make_shared<CdmaSmsReplyOption>(v2);
1234     EXPECT_TRUE(message2->Decode(rBuffer));
1235     EXPECT_EQ(v2.dak, testValue);
1236 
1237     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1238     EXPECT_FALSE(message1->Encode(wBuffer));
1239     rBuffer.SetIndex(1);
1240     EXPECT_FALSE(message1->Decode(rBuffer));
1241 }
1242 
1243 /**
1244  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0010
1245  * @tc.name     Test CdmaSmsSubParameter
1246  * @tc.desc     Function test
1247  */
1248 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0010, Function | MediumTest | Level1)
1249 {
1250     auto initValue = SmsAlertPriority::DEFAULT;
1251     auto testValue = SmsAlertPriority::HIGH;
1252     SmsAlertPriority v1 = testValue;
1253     SmsAlertPriority v2 = initValue;
1254 
1255     auto message1 = std::make_shared<CdmaSmsAlertPriority>(v1);
1256     SmsWriteBuffer wBuffer;
1257     EXPECT_TRUE(message1->Encode(wBuffer));
1258     auto buffer = wBuffer.GetPduBuffer();
1259     EXPECT_GT(buffer->size(), 0);
1260     std::stringstream ss;
1261     ss.clear();
1262     for (uint16_t i = 0; i < buffer->size(); i++) {
1263         ss << (*buffer)[i];
1264     }
1265     SmsReadBuffer rBuffer(ss.str());
1266     auto message2 = std::make_shared<CdmaSmsAlertPriority>(v2);
1267     EXPECT_TRUE(message2->Decode(rBuffer));
1268     EXPECT_EQ(v2, testValue);
1269 
1270     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1271     EXPECT_FALSE(message1->Encode(wBuffer));
1272     rBuffer.SetIndex(1);
1273     EXPECT_FALSE(message1->Decode(rBuffer));
1274 }
1275 
1276 /**
1277  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0011
1278  * @tc.name     Test CdmaSmsSubParameter
1279  * @tc.desc     Function test
1280  */
1281 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0011, Function | MediumTest | Level1)
1282 {
1283     auto initValue = SmsLanguageType::UNKNOWN;
1284     auto testValue = SmsLanguageType::CHINESE;
1285     SmsLanguageType v1 = testValue;
1286     SmsLanguageType v2 = initValue;
1287 
1288     auto message1 = std::make_shared<CdmaSmsLanguageInd>(v1);
1289     SmsWriteBuffer wBuffer;
1290     EXPECT_TRUE(message1->Encode(wBuffer));
1291     auto buffer = wBuffer.GetPduBuffer();
1292     EXPECT_GT(buffer->size(), 0);
1293     std::stringstream ss;
1294     ss.clear();
1295     for (uint16_t i = 0; i < buffer->size(); i++) {
1296         ss << (*buffer)[i];
1297     }
1298     SmsReadBuffer rBuffer(ss.str());
1299     auto message2 = std::make_shared<CdmaSmsLanguageInd>(v2);
1300     EXPECT_TRUE(message2->Decode(rBuffer));
1301     EXPECT_EQ(v2, testValue);
1302 
1303     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1304     EXPECT_FALSE(message1->Encode(wBuffer));
1305     rBuffer.SetIndex(1);
1306     EXPECT_FALSE(message1->Decode(rBuffer));
1307 }
1308 
1309 /**
1310  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0012
1311  * @tc.name     Test CdmaSmsSubParameter
1312  * @tc.desc     Function test
1313  */
1314 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0012, Function | MediumTest | Level1)
1315 {
1316     auto initValue = static_cast<uint32_t>(0);
1317     auto testValue = static_cast<uint32_t>(5);
1318     SmsTeleSvcAddr v1;
1319     memset_s(&v1, sizeof(SmsTeleSvcAddr), 0x00, sizeof(SmsTeleSvcAddr));
1320     v1.addrLen = testValue;
1321     SmsTeleSvcAddr v2;
1322     v2.addrLen = initValue;
1323 
1324     auto message1 = std::make_shared<CdmaSmsCallbackNumber>(v1);
1325     SmsWriteBuffer wBuffer;
1326     EXPECT_TRUE(message1->Encode(wBuffer));
1327     auto buffer = wBuffer.GetPduBuffer();
1328     EXPECT_GT(buffer->size(), 0);
1329     std::stringstream ss;
1330     ss.clear();
1331     for (uint16_t i = 0; i < buffer->size(); i++) {
1332         ss << (*buffer)[i];
1333     }
1334     SmsReadBuffer rBuffer(ss.str());
1335     auto message2 = std::make_shared<CdmaSmsCallbackNumber>(v2);
1336     EXPECT_TRUE(message2->Decode(rBuffer));
1337     EXPECT_EQ(v2.addrLen, testValue);
1338 
1339     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1340     EXPECT_FALSE(message1->Encode(wBuffer));
1341     rBuffer.SetIndex(1);
1342     EXPECT_FALSE(message1->Decode(rBuffer));
1343 }
1344 
1345 /**
1346  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0013
1347  * @tc.name     Test CdmaSmsSubParameter
1348  * @tc.desc     Function test
1349  */
1350 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0013, Function | MediumTest | Level1)
1351 {
1352     uint16_t initValue = 0;
1353     uint16_t testValue = 5;
1354     uint16_t v1 = testValue;
1355     uint16_t v2 = initValue;
1356 
1357     auto message1 = std::make_shared<CdmaSmsDepositIndex>(v1);
1358     SmsWriteBuffer wBuffer;
1359     EXPECT_TRUE(message1->Encode(wBuffer));
1360     auto buffer = wBuffer.GetPduBuffer();
1361     EXPECT_GT(buffer->size(), 0);
1362     std::stringstream ss;
1363     ss.clear();
1364     for (uint16_t i = 0; i < buffer->size(); i++) {
1365         ss << (*buffer)[i];
1366     }
1367     SmsReadBuffer rBuffer(ss.str());
1368     auto message2 = std::make_shared<CdmaSmsDepositIndex>(v2);
1369     EXPECT_TRUE(message2->Decode(rBuffer));
1370     EXPECT_EQ(v2, testValue);
1371 
1372     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1373     EXPECT_FALSE(message1->Encode(wBuffer));
1374     rBuffer.SetIndex(1);
1375     EXPECT_FALSE(message1->Decode(rBuffer));
1376 }
1377 
1378 /**
1379  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0014
1380  * @tc.name     Test CdmaSmsSubParameter
1381  * @tc.desc     Function test
1382  */
1383 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0014, Function | MediumTest | Level1)
1384 {
1385     auto initValue = SmsDisplayMode::RESERVED;
1386     auto testValue = SmsDisplayMode::DEFAULT_SETTING;
1387     SmsDisplayMode v1 = testValue;
1388     SmsDisplayMode v2 = initValue;
1389 
1390     auto message1 = std::make_shared<CdmaSmsDisplayMode>(v1);
1391     SmsWriteBuffer wBuffer;
1392     EXPECT_TRUE(message1->Encode(wBuffer));
1393     auto buffer = wBuffer.GetPduBuffer();
1394     EXPECT_GT(buffer->size(), 0);
1395     std::stringstream ss;
1396     ss.clear();
1397     for (uint16_t i = 0; i < buffer->size(); i++) {
1398         ss << (*buffer)[i];
1399     }
1400     SmsReadBuffer rBuffer(ss.str());
1401     auto message2 = std::make_shared<CdmaSmsDisplayMode>(v2);
1402     EXPECT_TRUE(message2->Decode(rBuffer));
1403     EXPECT_EQ(v2, testValue);
1404 
1405     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1406     EXPECT_FALSE(message1->Encode(wBuffer));
1407     rBuffer.SetIndex(1);
1408     EXPECT_FALSE(message1->Decode(rBuffer));
1409 }
1410 
1411 /**
1412  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0015
1413  * @tc.name     Test CdmaSmsSubParameter
1414  * @tc.desc     Function test
1415  */
1416 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0015, Function | MediumTest | Level1)
1417 {
1418     SmsEnhancedVmn v1;
1419     SmsEnhancedVmn v2;
1420 
1421     auto message1 = std::make_shared<CdmaSmsEnhancedVmn>(v1);
1422     SmsWriteBuffer wBuffer;
1423     EXPECT_FALSE(message1->Encode(wBuffer));
1424     std::stringstream ss;
1425     ss.clear();
1426     ss << static_cast<uint8_t>(CdmaSmsSubParameter::ENHANCED_VMN);
1427     uint8_t len = 20;
1428     ss << static_cast<uint8_t>(len);
1429     for (uint8_t i = 0; i < len; i++) {
1430         ss << static_cast<uint8_t>(0x00);
1431     }
1432     SmsReadBuffer rBuffer(ss.str());
1433     auto message2 = std::make_shared<CdmaSmsEnhancedVmn>(v2);
1434     EXPECT_TRUE(message2->Decode(rBuffer));
1435 
1436     rBuffer.SetIndex(0);
1437     EXPECT_TRUE(message2->DecodeHeader(rBuffer));
1438     EXPECT_TRUE(message2->DecodeAccessNumber(rBuffer));
1439     EXPECT_TRUE(message2->DecodeCallingPartyNumber(rBuffer));
1440 
1441     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1442     EXPECT_FALSE(message1->Encode(wBuffer));
1443     rBuffer.SetIndex(1);
1444     EXPECT_FALSE(message1->Decode(rBuffer));
1445 }
1446 
1447 /**
1448  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0016
1449  * @tc.name     Test CdmaSmsSubParameter
1450  * @tc.desc     Function test
1451  */
1452 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0016, Function | MediumTest | Level1)
1453 {
1454     SmsEnhancedVmnAck v1;
1455     SmsEnhancedVmnAck v2;
1456 
1457     auto message1 = std::make_shared<CdmaSmsEnhancedVmnAck>(v1);
1458     SmsWriteBuffer wBuffer;
1459     EXPECT_FALSE(message1->Encode(wBuffer));
1460     std::stringstream ss;
1461     ss.clear();
1462     ss << static_cast<uint8_t>(CdmaSmsSubParameter::ENHANCED_VMN_ACK);
1463     ss << static_cast<uint8_t>(0x05);
1464     ss << static_cast<uint8_t>(0x00);
1465     ss << static_cast<uint8_t>(0x00);
1466     ss << static_cast<uint8_t>(0x00);
1467     ss << static_cast<uint8_t>(0x00);
1468     ss << static_cast<uint8_t>(0x00);
1469     SmsReadBuffer rBuffer(ss.str());
1470     auto message2 = std::make_shared<CdmaSmsEnhancedVmnAck>(v2);
1471     EXPECT_TRUE(message2->Decode(rBuffer));
1472 
1473     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1474     EXPECT_FALSE(message1->Encode(wBuffer));
1475     rBuffer.SetIndex(1);
1476     EXPECT_FALSE(message1->Decode(rBuffer));
1477 }
1478 
1479 /**
1480  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0017
1481  * @tc.name     Test CdmaSmsSubParameter
1482  * @tc.desc     Function test
1483  */
1484 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0017, Function | MediumTest | Level1)
1485 {
1486     SmsStatusCode v1;
1487     SmsStatusCode v2;
1488 
1489     auto message1 = std::make_shared<CdmaSmsMessageStatus>(v1);
1490     SmsWriteBuffer wBuffer;
1491     EXPECT_FALSE(message1->Encode(wBuffer));
1492     std::stringstream ss;
1493     ss.clear();
1494     ss << static_cast<uint8_t>(CdmaSmsSubParameter::MESSAGE_STATUS);
1495     ss << static_cast<uint8_t>(0x01);
1496     ss << static_cast<uint8_t>(0x00);
1497     SmsReadBuffer rBuffer(ss.str());
1498     auto message2 = std::make_shared<CdmaSmsMessageStatus>(v2);
1499     EXPECT_TRUE(message2->Decode(rBuffer));
1500 
1501     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1502     EXPECT_FALSE(message1->Encode(wBuffer));
1503     rBuffer.SetIndex(1);
1504     EXPECT_FALSE(message1->Decode(rBuffer));
1505 }
1506 
1507 /**
1508  * @tc.number   Telephony_SmsMmsGtest_CdmaSmsSubParameter_0018
1509  * @tc.name     Test CdmaSmsSubParameter
1510  * @tc.desc     Function test
1511  */
1512 HWTEST_F(BranchCdmaSmsTest, CdmaSmsSubParameter_0018, Function | MediumTest | Level1)
1513 {
1514     uint32_t v1;
1515     uint32_t v2;
1516 
1517     auto message1 = std::make_shared<CdmaSmsNumberMessages>(v1);
1518     SmsWriteBuffer wBuffer;
1519     EXPECT_FALSE(message1->Encode(wBuffer));
1520     std::stringstream ss;
1521     ss.clear();
1522     ss << static_cast<uint8_t>(CdmaSmsSubParameter::NUMBER_OF_MESSAGES);
1523     ss << static_cast<uint8_t>(0x01);
1524     ss << static_cast<uint8_t>(0x00);
1525     SmsReadBuffer rBuffer(ss.str());
1526     auto message2 = std::make_shared<CdmaSmsNumberMessages>(v2);
1527     EXPECT_TRUE(message2->Decode(rBuffer));
1528 
1529     wBuffer.SetIndex(PDU_BUFFER_MAX_SIZE);
1530     EXPECT_FALSE(message1->Encode(wBuffer));
1531     rBuffer.SetIndex(1);
1532     EXPECT_FALSE(message1->Decode(rBuffer));
1533 }
1534 } // namespace Telephony
1535 } // namespace OHOS
1536