1e5d0e473Sopenharmony_ci/*
2e5d0e473Sopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd.
3e5d0e473Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e5d0e473Sopenharmony_ci * you may not use this file except in compliance with the License.
5e5d0e473Sopenharmony_ci * You may obtain a copy of the License at
6e5d0e473Sopenharmony_ci *
7e5d0e473Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e5d0e473Sopenharmony_ci *
9e5d0e473Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e5d0e473Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e5d0e473Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e5d0e473Sopenharmony_ci * See the License for the specific language governing permissions and
13e5d0e473Sopenharmony_ci * limitations under the License.
14e5d0e473Sopenharmony_ci */
15e5d0e473Sopenharmony_ci
16e5d0e473Sopenharmony_ci#include "cdma_sms_test.h"
17e5d0e473Sopenharmony_ci
18e5d0e473Sopenharmony_ci#include <chrono>
19e5d0e473Sopenharmony_ci#include <codecvt>
20e5d0e473Sopenharmony_ci#include <iostream>
21e5d0e473Sopenharmony_ci#include <locale>
22e5d0e473Sopenharmony_ci#include <sstream>
23e5d0e473Sopenharmony_ci
24e5d0e473Sopenharmony_ci#include "cdma_sms_sender.h"
25e5d0e473Sopenharmony_ci#include "cdma_sms_transport_message.h"
26e5d0e473Sopenharmony_ci#include "delivery_short_message_callback_stub.h"
27e5d0e473Sopenharmony_ci#include "send_short_message_callback_stub.h"
28e5d0e473Sopenharmony_ci#include "sms_sender.h"
29e5d0e473Sopenharmony_ci#include "string_utils.h"
30e5d0e473Sopenharmony_ci
31e5d0e473Sopenharmony_cinamespace OHOS {
32e5d0e473Sopenharmony_cinamespace Telephony {
33e5d0e473Sopenharmony_ciusing namespace std;
34e5d0e473Sopenharmony_ciusing namespace OHOS::Telephony;
35e5d0e473Sopenharmony_cistatic constexpr uint8_t TEST_MENU_TEXT_DELIVERY = 0;
36e5d0e473Sopenharmony_cistatic constexpr uint8_t TEST_MENU_ENCODE_SUBMIT = 1;
37e5d0e473Sopenharmony_cistatic constexpr uint8_t TEST_MENU_ENCODE_CANCEL = 2;
38e5d0e473Sopenharmony_cistatic constexpr uint8_t TEST_MENU_ENCODE_DELIVER_REPORT = 3;
39e5d0e473Sopenharmony_cistatic constexpr uint8_t TEST_MENU_ENCODE_ACK = 4;
40e5d0e473Sopenharmony_cistatic constexpr uint8_t TEST_MENU_DECODE_MSG = 5;
41e5d0e473Sopenharmony_cistatic constexpr uint8_t TEST_MENU_DECODE_BEARER_DATA = 6;
42e5d0e473Sopenharmony_cistatic constexpr uint8_t TEST_MENU_EXIT = 100;
43e5d0e473Sopenharmony_cistatic constexpr uint8_t BIT_8 = 8;
44e5d0e473Sopenharmony_cistatic constexpr uint8_t HEX_CHAR_LEN = 2;
45e5d0e473Sopenharmony_cistatic constexpr uint8_t VALUE_INDEX = 2;
46e5d0e473Sopenharmony_cistatic constexpr uint16_t MSG_ID = 100;
47e5d0e473Sopenharmony_cistatic constexpr uint8_t TP_FAIL_CAUSE = 0x81;
48e5d0e473Sopenharmony_cistatic constexpr uint8_t REPLY_SEQ = 10;
49e5d0e473Sopenharmony_ci
50e5d0e473Sopenharmony_civoid CdmaSmsTest::SetPduSeqInfo(const std::size_t size, const std::unique_ptr<CdmaTransportMsg> &transMsg,
51e5d0e473Sopenharmony_ci    const std::size_t index, const uint8_t msgRef8bit) const
52e5d0e473Sopenharmony_ci{
53e5d0e473Sopenharmony_ci    if (size > 1) {
54e5d0e473Sopenharmony_ci        transMsg->data.p2p.teleserviceId = static_cast<uint16_t>(SmsTransTelsvcId::WEMT);
55e5d0e473Sopenharmony_ci        transMsg->data.p2p.telesvcMsg.data.submit.msgId.headerInd = true;
56e5d0e473Sopenharmony_ci        transMsg->data.p2p.telesvcMsg.data.submit.userData.userData.headerCnt = 1;
57e5d0e473Sopenharmony_ci        transMsg->data.p2p.telesvcMsg.data.submit.userData.userData.header[0].udhType = UDH_CONCAT_8BIT;
58e5d0e473Sopenharmony_ci        transMsg->data.p2p.telesvcMsg.data.submit.userData.userData.header[0].udh.concat8bit.msgRef = msgRef8bit;
59e5d0e473Sopenharmony_ci        transMsg->data.p2p.telesvcMsg.data.submit.userData.userData.header[0].udh.concat8bit.totalSeg =
60e5d0e473Sopenharmony_ci            static_cast<uint8_t>(size);
61e5d0e473Sopenharmony_ci        transMsg->data.p2p.telesvcMsg.data.submit.userData.userData.header[0].udh.concat8bit.seqNum = index + 1;
62e5d0e473Sopenharmony_ci    }
63e5d0e473Sopenharmony_ci}
64e5d0e473Sopenharmony_ci
65e5d0e473Sopenharmony_cistd::string CdmaSmsTest::UnicodeToString(uint8_t *s, int len) const
66e5d0e473Sopenharmony_ci{
67e5d0e473Sopenharmony_ci    std::string u8str;
68e5d0e473Sopenharmony_ci    std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> converter;
69e5d0e473Sopenharmony_ci    for (int i = 0; i < len; i += HEX_CHAR_LEN) {
70e5d0e473Sopenharmony_ci        char32_t u8char = (s[i] << BIT_8) | s[i + 1];
71e5d0e473Sopenharmony_ci        u8str += converter.to_bytes(u8char);
72e5d0e473Sopenharmony_ci    }
73e5d0e473Sopenharmony_ci    return u8str;
74e5d0e473Sopenharmony_ci}
75e5d0e473Sopenharmony_ci
76e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintAddr(TransportAddr &addr, string s) const
77e5d0e473Sopenharmony_ci{
78e5d0e473Sopenharmony_ci    if (addr.addrLen == 0) {
79e5d0e473Sopenharmony_ci        return;
80e5d0e473Sopenharmony_ci    }
81e5d0e473Sopenharmony_ci    stringstream ss;
82e5d0e473Sopenharmony_ci    ss << s << "digitMode  : " << addr.digitMode << endl;
83e5d0e473Sopenharmony_ci    ss << s << "numberMode : " << addr.numberMode << endl;
84e5d0e473Sopenharmony_ci    ss << s << "numberType : " << static_cast<int>(addr.numberType) << endl;
85e5d0e473Sopenharmony_ci    ss << s << "numberPlan : " << static_cast<int>(addr.numberPlan) << endl;
86e5d0e473Sopenharmony_ci    ss << s << "addrLen    : " << addr.addrLen << endl;
87e5d0e473Sopenharmony_ci    ss << s << "szData     : ";
88e5d0e473Sopenharmony_ci    for (uint8_t i = 0; i < addr.addrLen; i++) {
89e5d0e473Sopenharmony_ci        ss << addr.szData[i];
90e5d0e473Sopenharmony_ci    }
91e5d0e473Sopenharmony_ci    ss << endl;
92e5d0e473Sopenharmony_ci    cout << ss.str() << flush;
93e5d0e473Sopenharmony_ci}
94e5d0e473Sopenharmony_ci
95e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintSubAddr(TransportSubAddr &addr, string s) const
96e5d0e473Sopenharmony_ci{
97e5d0e473Sopenharmony_ci    if (addr.addrLen == 0) {
98e5d0e473Sopenharmony_ci        return;
99e5d0e473Sopenharmony_ci    }
100e5d0e473Sopenharmony_ci    switch (addr.type) {
101e5d0e473Sopenharmony_ci        case TransportSubAddrType::NSAP:
102e5d0e473Sopenharmony_ci            cout << s << "type    : NSAP - " << static_cast<int>(addr.type) << endl;
103e5d0e473Sopenharmony_ci            break;
104e5d0e473Sopenharmony_ci        case TransportSubAddrType::USER:
105e5d0e473Sopenharmony_ci            cout << s << "type    : USER - " << static_cast<int>(addr.type) << endl;
106e5d0e473Sopenharmony_ci            break;
107e5d0e473Sopenharmony_ci        default:
108e5d0e473Sopenharmony_ci            cout << s << "type    : " << static_cast<int>(addr.type) << endl;
109e5d0e473Sopenharmony_ci            break;
110e5d0e473Sopenharmony_ci    }
111e5d0e473Sopenharmony_ci    cout << s << "odd     : " << addr.odd << endl;
112e5d0e473Sopenharmony_ci    cout << s << "addrLen : " << addr.addrLen << endl;
113e5d0e473Sopenharmony_ci    stringstream ss;
114e5d0e473Sopenharmony_ci    for (uint8_t i = 0; i < addr.addrLen; i++) {
115e5d0e473Sopenharmony_ci        ss << addr.szData[i];
116e5d0e473Sopenharmony_ci    }
117e5d0e473Sopenharmony_ci    cout << s << "szData  : " << ss.str() << endl << flush;
118e5d0e473Sopenharmony_ci}
119e5d0e473Sopenharmony_ci
120e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintSmsTeleSvcAddr(SmsTeleSvcAddr &addr, string s) const
121e5d0e473Sopenharmony_ci{
122e5d0e473Sopenharmony_ci    if (addr.addrLen == 0) {
123e5d0e473Sopenharmony_ci        return;
124e5d0e473Sopenharmony_ci    }
125e5d0e473Sopenharmony_ci    cout << s << "digitMode  : " << addr.digitMode << endl;
126e5d0e473Sopenharmony_ci    cout << s << "numberType : " << static_cast<int>(addr.numberType) << endl;
127e5d0e473Sopenharmony_ci    cout << s << "numberPlan : " << static_cast<int>(addr.numberPlan) << endl;
128e5d0e473Sopenharmony_ci    cout << s << "addrLen    : " << addr.addrLen << endl;
129e5d0e473Sopenharmony_ci    stringstream ss;
130e5d0e473Sopenharmony_ci    for (uint8_t i = 0; i < addr.addrLen; i++) {
131e5d0e473Sopenharmony_ci        ss << addr.szData[i];
132e5d0e473Sopenharmony_ci    }
133e5d0e473Sopenharmony_ci    cout << s << "szData     : " << ss.str() << endl << flush;
134e5d0e473Sopenharmony_ci}
135e5d0e473Sopenharmony_ci
136e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintHeader(const SmsUDH &header, string s) const
137e5d0e473Sopenharmony_ci{
138e5d0e473Sopenharmony_ci    switch (header.udhType) {
139e5d0e473Sopenharmony_ci        case UDH_CONCAT_8BIT: {
140e5d0e473Sopenharmony_ci            cout << s << "udhType : UDH_CONCAT_8BIT - " << static_cast<int>(header.udhType) << endl;
141e5d0e473Sopenharmony_ci            cout << s << "concat8bit: msgRef[" << static_cast<int>(header.udh.concat8bit.msgRef) << "] totalSeg["
142e5d0e473Sopenharmony_ci                 << static_cast<int>(header.udh.concat8bit.totalSeg) << "] seqNum["
143e5d0e473Sopenharmony_ci                 << static_cast<int>(header.udh.concat8bit.seqNum) << "]" << endl;
144e5d0e473Sopenharmony_ci            break;
145e5d0e473Sopenharmony_ci        }
146e5d0e473Sopenharmony_ci        case UDH_CONCAT_16BIT: {
147e5d0e473Sopenharmony_ci            cout << s << "udhType : UDH_CONCAT_16BIT - " << static_cast<int>(header.udhType) << endl;
148e5d0e473Sopenharmony_ci            cout << s << "concat16bit.seqNum [" << static_cast<int>(header.udh.concat16bit.seqNum) << "]" << endl;
149e5d0e473Sopenharmony_ci            break;
150e5d0e473Sopenharmony_ci        }
151e5d0e473Sopenharmony_ci        case UDH_APP_PORT_8BIT: {
152e5d0e473Sopenharmony_ci            cout << s << "udhType : UDH_APP_PORT_8BIT - " << static_cast<int>(header.udhType) << endl;
153e5d0e473Sopenharmony_ci            cout << s << "appPort8bit.destPort [" << static_cast<int>(header.udh.appPort8bit.destPort) << "]" << endl;
154e5d0e473Sopenharmony_ci            cout << s << "appPort8bit.originPort [" << static_cast<int>(header.udh.appPort8bit.originPort) << "]"
155e5d0e473Sopenharmony_ci                 << endl;
156e5d0e473Sopenharmony_ci            break;
157e5d0e473Sopenharmony_ci        }
158e5d0e473Sopenharmony_ci        case UDH_APP_PORT_16BIT: {
159e5d0e473Sopenharmony_ci            cout << s << "udhType : UDH_APP_PORT_16BIT - " << static_cast<int>(header.udhType) << endl;
160e5d0e473Sopenharmony_ci            cout << s << "appPort16bit.destPort [" << static_cast<int>(header.udh.appPort16bit.destPort) << "]" << endl;
161e5d0e473Sopenharmony_ci            cout << s << "appPort16bit.originPort [" << static_cast<int>(header.udh.appPort16bit.originPort) << "]"
162e5d0e473Sopenharmony_ci                 << endl;
163e5d0e473Sopenharmony_ci            break;
164e5d0e473Sopenharmony_ci        }
165e5d0e473Sopenharmony_ci        case UDH_SPECIAL_SMS: {
166e5d0e473Sopenharmony_ci            cout << s << "udhType : UDH_SPECIAL_SMS - " << static_cast<int>(header.udhType) << endl;
167e5d0e473Sopenharmony_ci            cout << s << "Decoding special sms udh." << endl;
168e5d0e473Sopenharmony_ci            break;
169e5d0e473Sopenharmony_ci        }
170e5d0e473Sopenharmony_ci        case UDH_SINGLE_SHIFT: {
171e5d0e473Sopenharmony_ci            cout << s << "udhType : UDH_SINGLE_SHIFT - " << static_cast<int>(header.udhType) << endl;
172e5d0e473Sopenharmony_ci            cout << s << "singleShift.langId [" << static_cast<int>(header.udh.singleShift.langId) << "]" << endl;
173e5d0e473Sopenharmony_ci            break;
174e5d0e473Sopenharmony_ci        }
175e5d0e473Sopenharmony_ci        case UDH_LOCKING_SHIFT: {
176e5d0e473Sopenharmony_ci            cout << s << "udhType : UDH_LOCKING_SHIFT - " << static_cast<int>(header.udhType) << endl;
177e5d0e473Sopenharmony_ci            cout << s << "lockingShift.langId [" << static_cast<int>(header.udh.lockingShift.langId) << "]" << endl;
178e5d0e473Sopenharmony_ci            break;
179e5d0e473Sopenharmony_ci        }
180e5d0e473Sopenharmony_ci        default:
181e5d0e473Sopenharmony_ci            cout << s << "udhType : " << static_cast<int>(header.udhType) << endl;
182e5d0e473Sopenharmony_ci            break;
183e5d0e473Sopenharmony_ci    }
184e5d0e473Sopenharmony_ci    cout << flush;
185e5d0e473Sopenharmony_ci}
186e5d0e473Sopenharmony_ci
187e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintTimeAbs(SmsTimeAbs &time, string s) const
188e5d0e473Sopenharmony_ci{
189e5d0e473Sopenharmony_ci    cout << dec << s << static_cast<int>(time.year) << "/" << static_cast<int>(time.month) << "/"
190e5d0e473Sopenharmony_ci         << static_cast<int>(time.day) << " " << static_cast<int>(time.hour) << ":" << static_cast<int>(time.minute)
191e5d0e473Sopenharmony_ci         << ":" << static_cast<int>(time.second) << endl;
192e5d0e473Sopenharmony_ci    cout << flush;
193e5d0e473Sopenharmony_ci}
194e5d0e473Sopenharmony_ci
195e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintEncodeType(SmsEncodingType encodeType, string s) const
196e5d0e473Sopenharmony_ci{
197e5d0e473Sopenharmony_ci    switch (encodeType) {
198e5d0e473Sopenharmony_ci        case SmsEncodingType::OCTET:
199e5d0e473Sopenharmony_ci            cout << s << "encodeType : OCTET - " << static_cast<int>(encodeType) << endl;
200e5d0e473Sopenharmony_ci            break;
201e5d0e473Sopenharmony_ci        case SmsEncodingType::EPM:
202e5d0e473Sopenharmony_ci            cout << s << "encodeType : EPM - " << static_cast<int>(encodeType) << endl;
203e5d0e473Sopenharmony_ci            break;
204e5d0e473Sopenharmony_ci        case SmsEncodingType::ASCII_7BIT:
205e5d0e473Sopenharmony_ci            cout << s << "encodeType : ASCII_7BIT - " << static_cast<int>(encodeType) << endl;
206e5d0e473Sopenharmony_ci            break;
207e5d0e473Sopenharmony_ci        case SmsEncodingType::IA5:
208e5d0e473Sopenharmony_ci            cout << s << "encodeType : IA5 - " << static_cast<int>(encodeType) << endl;
209e5d0e473Sopenharmony_ci            break;
210e5d0e473Sopenharmony_ci        case SmsEncodingType::UNICODE:
211e5d0e473Sopenharmony_ci            cout << s << "encodeType : UNICODE - " << static_cast<int>(encodeType) << endl;
212e5d0e473Sopenharmony_ci            break;
213e5d0e473Sopenharmony_ci        case SmsEncodingType::SHIFT_JIS:
214e5d0e473Sopenharmony_ci            cout << s << "encodeType : SHIFT_JIS - " << static_cast<int>(encodeType) << endl;
215e5d0e473Sopenharmony_ci            break;
216e5d0e473Sopenharmony_ci        case SmsEncodingType::KOREAN:
217e5d0e473Sopenharmony_ci            cout << s << "encodeType : KOREAN - " << static_cast<int>(encodeType) << endl;
218e5d0e473Sopenharmony_ci            break;
219e5d0e473Sopenharmony_ci        case SmsEncodingType::LATIN_HEBREW:
220e5d0e473Sopenharmony_ci            cout << s << "encodeType : LATIN_HEBREW - " << static_cast<int>(encodeType) << endl;
221e5d0e473Sopenharmony_ci            break;
222e5d0e473Sopenharmony_ci        case SmsEncodingType::LATIN:
223e5d0e473Sopenharmony_ci            cout << s << "encodeType : LATIN - " << static_cast<int>(encodeType) << endl;
224e5d0e473Sopenharmony_ci            break;
225e5d0e473Sopenharmony_ci        case SmsEncodingType::GSM7BIT:
226e5d0e473Sopenharmony_ci            cout << s << "encodeType : GSM7BIT - " << static_cast<int>(encodeType) << endl;
227e5d0e473Sopenharmony_ci            break;
228e5d0e473Sopenharmony_ci        case SmsEncodingType::GSMDCS:
229e5d0e473Sopenharmony_ci            cout << s << "encodeType : GSMDCS - " << static_cast<int>(encodeType) << endl;
230e5d0e473Sopenharmony_ci            break;
231e5d0e473Sopenharmony_ci        case SmsEncodingType::EUCKR:
232e5d0e473Sopenharmony_ci            cout << s << "encodeType : EUCKR - " << static_cast<int>(encodeType) << endl;
233e5d0e473Sopenharmony_ci            break;
234e5d0e473Sopenharmony_ci        case SmsEncodingType::RESERVED:
235e5d0e473Sopenharmony_ci            cout << s << "encodeType : RESERVED - " << static_cast<int>(encodeType) << endl;
236e5d0e473Sopenharmony_ci            break;
237e5d0e473Sopenharmony_ci        default:
238e5d0e473Sopenharmony_ci            cout << s << "encodeType : - " << static_cast<int>(encodeType) << endl;
239e5d0e473Sopenharmony_ci            break;
240e5d0e473Sopenharmony_ci    }
241e5d0e473Sopenharmony_ci    cout << flush;
242e5d0e473Sopenharmony_ci}
243e5d0e473Sopenharmony_ci
244e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintUserData(SmsTeleSvcUserData &userData, string s) const
245e5d0e473Sopenharmony_ci{
246e5d0e473Sopenharmony_ci    if (userData.userData.length == 0) {
247e5d0e473Sopenharmony_ci        return;
248e5d0e473Sopenharmony_ci    }
249e5d0e473Sopenharmony_ci    PrintEncodeType(userData.encodeType, s);
250e5d0e473Sopenharmony_ci    cout << s << "msgType    : " << static_cast<int>(userData.msgType) << endl;
251e5d0e473Sopenharmony_ci    cout << s << "headerCnt  : " << static_cast<int>(userData.userData.headerCnt) << endl;
252e5d0e473Sopenharmony_ci    for (int i = 0; i < userData.userData.headerCnt; i++) {
253e5d0e473Sopenharmony_ci        PrintHeader(userData.userData.header[i]);
254e5d0e473Sopenharmony_ci    }
255e5d0e473Sopenharmony_ci    cout << s << "length     : " << userData.userData.length << endl;
256e5d0e473Sopenharmony_ci    stringstream ss;
257e5d0e473Sopenharmony_ci    if (userData.encodeType == SmsEncodingType::UNICODE) {
258e5d0e473Sopenharmony_ci        unsigned char unicodeChar[userData.userData.length];
259e5d0e473Sopenharmony_ci        for (uint8_t i = 0; i < userData.userData.length; i++) {
260e5d0e473Sopenharmony_ci            unicodeChar[i] = userData.userData.data[i];
261e5d0e473Sopenharmony_ci        }
262e5d0e473Sopenharmony_ci        cout << s << "data       : " << UnicodeToString(unicodeChar, userData.userData.length) << endl;
263e5d0e473Sopenharmony_ci    } else {
264e5d0e473Sopenharmony_ci        for (uint8_t i = 0; i < userData.userData.length; i++) {
265e5d0e473Sopenharmony_ci            ss << userData.userData.data[i];
266e5d0e473Sopenharmony_ci        }
267e5d0e473Sopenharmony_ci        cout << s << "data       : " << ss.str() << endl;
268e5d0e473Sopenharmony_ci    }
269e5d0e473Sopenharmony_ci    cout << flush;
270e5d0e473Sopenharmony_ci}
271e5d0e473Sopenharmony_ci
272e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintCmasData(SmsTeleSvcCmasData cmasData, string s) const
273e5d0e473Sopenharmony_ci{
274e5d0e473Sopenharmony_ci    if (cmasData.dataLen == 0) {
275e5d0e473Sopenharmony_ci        return;
276e5d0e473Sopenharmony_ci    }
277e5d0e473Sopenharmony_ci    PrintEncodeType(cmasData.encodeType, s);
278e5d0e473Sopenharmony_ci    cout << s << "dataLen : " << cmasData.dataLen << endl;
279e5d0e473Sopenharmony_ci    stringstream ss;
280e5d0e473Sopenharmony_ci    if (cmasData.encodeType == SmsEncodingType::UNICODE) {
281e5d0e473Sopenharmony_ci        unsigned char unicodeChar[cmasData.dataLen];
282e5d0e473Sopenharmony_ci        for (uint8_t i = 0; i < cmasData.dataLen; i++) {
283e5d0e473Sopenharmony_ci            unicodeChar[i] = cmasData.alertText[i];
284e5d0e473Sopenharmony_ci        }
285e5d0e473Sopenharmony_ci        ss << UnicodeToString(unicodeChar, cmasData.dataLen);
286e5d0e473Sopenharmony_ci    } else {
287e5d0e473Sopenharmony_ci        for (uint8_t i = 0; i < cmasData.dataLen; i++) {
288e5d0e473Sopenharmony_ci            ss << static_cast<uint8_t>(cmasData.alertText[i]);
289e5d0e473Sopenharmony_ci        }
290e5d0e473Sopenharmony_ci    }
291e5d0e473Sopenharmony_ci    cout << s << "alertText         : " << ss.str() << endl;
292e5d0e473Sopenharmony_ci    cout << s << "category          :  " << static_cast<uint32_t>(cmasData.category) << endl;
293e5d0e473Sopenharmony_ci    cout << s << "responseType      :  " << static_cast<uint32_t>(cmasData.responseType) << endl;
294e5d0e473Sopenharmony_ci    cout << s << "severity          :  " << static_cast<uint32_t>(cmasData.severity) << endl;
295e5d0e473Sopenharmony_ci    cout << s << "urgency           :  " << static_cast<uint32_t>(cmasData.urgency) << endl;
296e5d0e473Sopenharmony_ci    cout << s << "certainty         :  " << static_cast<uint32_t>(cmasData.certainty) << endl;
297e5d0e473Sopenharmony_ci    cout << s << "id                :  " << static_cast<uint32_t>(cmasData.id) << endl;
298e5d0e473Sopenharmony_ci    cout << s << "alertHandle       :  " << static_cast<uint32_t>(cmasData.alertHandle) << endl;
299e5d0e473Sopenharmony_ci    cout << s << "language          :  " << static_cast<uint32_t>(cmasData.language) << endl;
300e5d0e473Sopenharmony_ci    cout << s << "isWrongRecodeType :  " << static_cast<uint32_t>(cmasData.isWrongRecodeType) << endl;
301e5d0e473Sopenharmony_ci    cout << s << "expires           : " << endl;
302e5d0e473Sopenharmony_ci    PrintTimeAbs(cmasData.expires, "             ");
303e5d0e473Sopenharmony_ci    cout << flush;
304e5d0e473Sopenharmony_ci}
305e5d0e473Sopenharmony_ci
306e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintSmsReplyOption(SmsReplyOption &replyOpt, string s) const
307e5d0e473Sopenharmony_ci{
308e5d0e473Sopenharmony_ci    cout << s << "userAck : " << replyOpt.userAck << endl;
309e5d0e473Sopenharmony_ci    cout << s << "dak     : " << replyOpt.dak << endl;
310e5d0e473Sopenharmony_ci    cout << s << "readAck : " << replyOpt.readAck << endl;
311e5d0e473Sopenharmony_ci    cout << s << "report  : " << replyOpt.report << endl;
312e5d0e473Sopenharmony_ci    cout << flush;
313e5d0e473Sopenharmony_ci}
314e5d0e473Sopenharmony_ci
315e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintSmsValPeriod(SmsValPeriod &valPeriod, string s) const
316e5d0e473Sopenharmony_ci{
317e5d0e473Sopenharmony_ci    switch (valPeriod.format) {
318e5d0e473Sopenharmony_ci        case SMS_TIME_RELATIVE:
319e5d0e473Sopenharmony_ci            cout << s << "RELATIVE : " << static_cast<uint32_t>(valPeriod.time.relTime.time) << endl;
320e5d0e473Sopenharmony_ci            break;
321e5d0e473Sopenharmony_ci        case SMS_TIME_ABSOLUTE:
322e5d0e473Sopenharmony_ci            cout << s << "ABSOLUTE : " << endl;
323e5d0e473Sopenharmony_ci            PrintTimeAbs(valPeriod.time.absTime);
324e5d0e473Sopenharmony_ci            break;
325e5d0e473Sopenharmony_ci        case SMS_TIME_EMPTY:
326e5d0e473Sopenharmony_ci            cout << s << "EMPTY" << endl;
327e5d0e473Sopenharmony_ci            break;
328e5d0e473Sopenharmony_ci        default:
329e5d0e473Sopenharmony_ci            cout << s << " " << static_cast<uint32_t>(valPeriod.format) << endl;
330e5d0e473Sopenharmony_ci            break;
331e5d0e473Sopenharmony_ci    }
332e5d0e473Sopenharmony_ci    cout << flush;
333e5d0e473Sopenharmony_ci}
334e5d0e473Sopenharmony_ci
335e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintSmsEnhancedVmn(SmsEnhancedVmn &vmn, string s) const
336e5d0e473Sopenharmony_ci{
337e5d0e473Sopenharmony_ci    cout << s << "priority : " << static_cast<int>(vmn.priority) << endl;
338e5d0e473Sopenharmony_ci    cout << s << "vmMsgId : " << static_cast<int>(vmn.vmMsgId) << endl;
339e5d0e473Sopenharmony_ci    cout << s << "anNumField : " << static_cast<int>(vmn.anNumField) << endl;
340e5d0e473Sopenharmony_ci    cout << s << "cliNumField : " << static_cast<int>(vmn.cliNumField) << endl;
341e5d0e473Sopenharmony_ci    cout << flush;
342e5d0e473Sopenharmony_ci}
343e5d0e473Sopenharmony_ci
344e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintTeleserviceDeliver(TeleserviceDeliver &deliver, bool isCMAS, string s) const
345e5d0e473Sopenharmony_ci{
346e5d0e473Sopenharmony_ci    cout << s << "  msgId          : " << static_cast<int>(deliver.msgId.msgId) << endl;
347e5d0e473Sopenharmony_ci    cout << s << "  headerInd      : " << static_cast<int>(deliver.msgId.headerInd) << endl;
348e5d0e473Sopenharmony_ci    if (isCMAS) {
349e5d0e473Sopenharmony_ci        cout << s << "  cmasData       : " << endl;
350e5d0e473Sopenharmony_ci        PrintCmasData(deliver.cmasData);
351e5d0e473Sopenharmony_ci    } else {
352e5d0e473Sopenharmony_ci        cout << s << "  userData       : " << endl;
353e5d0e473Sopenharmony_ci        PrintUserData(deliver.userData);
354e5d0e473Sopenharmony_ci    }
355e5d0e473Sopenharmony_ci    cout << s << "  timeStamp      : " << endl;
356e5d0e473Sopenharmony_ci    PrintTimeAbs(deliver.timeStamp);
357e5d0e473Sopenharmony_ci    cout << s << "  valPeriod      : " << endl;
358e5d0e473Sopenharmony_ci    PrintSmsValPeriod(deliver.valPeriod);
359e5d0e473Sopenharmony_ci    cout << s << "  deferValPeriod : " << endl;
360e5d0e473Sopenharmony_ci    PrintSmsValPeriod(deliver.deferValPeriod);
361e5d0e473Sopenharmony_ci    cout << s << "  replyOpt       : " << endl;
362e5d0e473Sopenharmony_ci    PrintSmsReplyOption(deliver.replyOpt);
363e5d0e473Sopenharmony_ci    cout << s << "  numMsg         : " << static_cast<int>(deliver.numMsg) << endl;
364e5d0e473Sopenharmony_ci    cout << s << "  language       : " << static_cast<int>(deliver.language) << endl;
365e5d0e473Sopenharmony_ci    cout << s << "  callbackNumber : " << endl;
366e5d0e473Sopenharmony_ci    PrintSmsTeleSvcAddr(deliver.callbackNumber);
367e5d0e473Sopenharmony_ci    cout << s << "  depositId      : " << static_cast<int>(deliver.depositId) << endl;
368e5d0e473Sopenharmony_ci    cout << s << "  vmn            : " << endl;
369e5d0e473Sopenharmony_ci    PrintSmsEnhancedVmn(deliver.vmn);
370e5d0e473Sopenharmony_ci}
371e5d0e473Sopenharmony_ci
372e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintTeleserviceSubmit(TeleserviceSubmit submit, string s) const
373e5d0e473Sopenharmony_ci{
374e5d0e473Sopenharmony_ci    cout << s << "  msgId          : " << static_cast<int>(submit.msgId.msgId) << endl;
375e5d0e473Sopenharmony_ci    cout << s << "  headerInd      : " << static_cast<int>(submit.msgId.headerInd) << endl;
376e5d0e473Sopenharmony_ci    cout << s << "  userData       : " << endl;
377e5d0e473Sopenharmony_ci    PrintUserData(submit.userData);
378e5d0e473Sopenharmony_ci    cout << s << "  valPeriod      : " << endl;
379e5d0e473Sopenharmony_ci    PrintSmsValPeriod(submit.valPeriod);
380e5d0e473Sopenharmony_ci    cout << s << "  deferValPeriod : " << endl;
381e5d0e473Sopenharmony_ci    PrintSmsValPeriod(submit.deferValPeriod);
382e5d0e473Sopenharmony_ci    cout << s << "  replyOpt       : " << endl;
383e5d0e473Sopenharmony_ci    PrintSmsReplyOption(submit.replyOpt);
384e5d0e473Sopenharmony_ci    cout << s << "  language       : " << static_cast<int>(submit.language) << endl;
385e5d0e473Sopenharmony_ci    cout << s << "  callbackNumber : " << endl;
386e5d0e473Sopenharmony_ci    PrintSmsTeleSvcAddr(submit.callbackNumber);
387e5d0e473Sopenharmony_ci    cout << s << "  depositId      : " << static_cast<int>(submit.depositId) << endl;
388e5d0e473Sopenharmony_ci}
389e5d0e473Sopenharmony_ci
390e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintTeleserviceDeliverAck(TeleserviceDeliverAck deliveryAck, string s) const
391e5d0e473Sopenharmony_ci{
392e5d0e473Sopenharmony_ci    cout << s << "  msgId     : " << static_cast<int>(deliveryAck.msgId.msgId) << endl;
393e5d0e473Sopenharmony_ci    cout << s << "  headerInd : " << static_cast<int>(deliveryAck.msgId.headerInd) << endl;
394e5d0e473Sopenharmony_ci    cout << s << "  userData  : " << endl;
395e5d0e473Sopenharmony_ci    PrintUserData(deliveryAck.userData);
396e5d0e473Sopenharmony_ci    cout << s << "  timeStamp : " << endl;
397e5d0e473Sopenharmony_ci    PrintTimeAbs(deliveryAck.timeStamp);
398e5d0e473Sopenharmony_ci    cout << s << "  msgStatus : " << static_cast<int>(deliveryAck.msgStatus) << endl;
399e5d0e473Sopenharmony_ci}
400e5d0e473Sopenharmony_ci
401e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintTelesvc(CdmaTeleserviceMsg &telesvcMsg, bool isCMAS, string s) const
402e5d0e473Sopenharmony_ci{
403e5d0e473Sopenharmony_ci    cout << s << "TeleserviceMsg >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << endl;
404e5d0e473Sopenharmony_ci    switch (telesvcMsg.type) {
405e5d0e473Sopenharmony_ci        case TeleserviceMsgType::RESERVED:
406e5d0e473Sopenharmony_ci            cout << s << "Type: RESERVED - " << static_cast<int>(telesvcMsg.type) << endl;
407e5d0e473Sopenharmony_ci            break;
408e5d0e473Sopenharmony_ci        case TeleserviceMsgType::DELIVER:
409e5d0e473Sopenharmony_ci            cout << s << "Type: DELIVER - " << static_cast<int>(telesvcMsg.type) << endl;
410e5d0e473Sopenharmony_ci            PrintTeleserviceDeliver(telesvcMsg.data.deliver, isCMAS, s);
411e5d0e473Sopenharmony_ci            break;
412e5d0e473Sopenharmony_ci        case TeleserviceMsgType::SUBMIT: {
413e5d0e473Sopenharmony_ci            cout << s << "Type: SUBMIT - " << static_cast<int>(telesvcMsg.type) << endl;
414e5d0e473Sopenharmony_ci            PrintTeleserviceSubmit(telesvcMsg.data.submit, s);
415e5d0e473Sopenharmony_ci            break;
416e5d0e473Sopenharmony_ci        }
417e5d0e473Sopenharmony_ci        case TeleserviceMsgType::CANCEL:
418e5d0e473Sopenharmony_ci            cout << s << "Type: CANCEL - " << static_cast<int>(telesvcMsg.type) << endl;
419e5d0e473Sopenharmony_ci            cout << s << "  msgId     : " << static_cast<int>(telesvcMsg.data.cancel.msgId.msgId) << endl;
420e5d0e473Sopenharmony_ci            cout << s << "  headerInd : " << static_cast<int>(telesvcMsg.data.cancel.msgId.headerInd) << endl;
421e5d0e473Sopenharmony_ci            break;
422e5d0e473Sopenharmony_ci        case TeleserviceMsgType::DELIVERY_ACK:
423e5d0e473Sopenharmony_ci            cout << s << "Type: DELIVERY_ACK - " << static_cast<int>(telesvcMsg.type) << endl;
424e5d0e473Sopenharmony_ci            PrintTeleserviceDeliverAck(telesvcMsg.data.deliveryAck, s);
425e5d0e473Sopenharmony_ci            break;
426e5d0e473Sopenharmony_ci        case TeleserviceMsgType::DELIVER_REPORT:
427e5d0e473Sopenharmony_ci            cout << s << "Type: DELIVER_REPORT - " << static_cast<int>(telesvcMsg.type) << endl;
428e5d0e473Sopenharmony_ci            cout << s << "  msgId           : " << static_cast<int>(telesvcMsg.data.report.msgId.msgId) << endl;
429e5d0e473Sopenharmony_ci            cout << s << "  headerInd       : " << static_cast<int>(telesvcMsg.data.report.msgId.headerInd) << endl;
430e5d0e473Sopenharmony_ci            cout << s << "  userData        : " << endl;
431e5d0e473Sopenharmony_ci            PrintUserData(telesvcMsg.data.report.userData);
432e5d0e473Sopenharmony_ci            cout << s << "  tpFailCause     : " << static_cast<int>(telesvcMsg.data.report.tpFailCause) << endl;
433e5d0e473Sopenharmony_ci            cout << s << "  language        : " << static_cast<int>(telesvcMsg.data.report.language) << endl;
434e5d0e473Sopenharmony_ci            cout << s << "  multiEncodeData : " << static_cast<int>(telesvcMsg.data.report.multiEncodeData) << endl;
435e5d0e473Sopenharmony_ci            break;
436e5d0e473Sopenharmony_ci        case TeleserviceMsgType::SUBMIT_REPORT:
437e5d0e473Sopenharmony_ci            cout << s << "Type: SUBMIT_REPORT - " << static_cast<int>(telesvcMsg.type) << endl;
438e5d0e473Sopenharmony_ci            break;
439e5d0e473Sopenharmony_ci        default:
440e5d0e473Sopenharmony_ci            cout << s << "Type: RESERVED - " << static_cast<int>(telesvcMsg.type) << endl;
441e5d0e473Sopenharmony_ci            break;
442e5d0e473Sopenharmony_ci    }
443e5d0e473Sopenharmony_ci    cout << s << "TeleserviceMsg <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << endl << flush;
444e5d0e473Sopenharmony_ci}
445e5d0e473Sopenharmony_ci
446e5d0e473Sopenharmony_civoid CdmaSmsTest::PrintMsg(CdmaTransportMsg &msg) const
447e5d0e473Sopenharmony_ci{
448e5d0e473Sopenharmony_ci    cout << "TransportMsg >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << endl;
449e5d0e473Sopenharmony_ci    if (msg.type == CdmaTransportMsgType::P2P) {
450e5d0e473Sopenharmony_ci        cout << "P2P" << endl;
451e5d0e473Sopenharmony_ci        cout << "  teleserviceId : " << hex << showbase << static_cast<int>(msg.data.p2p.teleserviceId) << dec << endl;
452e5d0e473Sopenharmony_ci        cout << "  serviceCtg    : " << hex << showbase << static_cast<int>(msg.data.p2p.serviceCtg) << dec << endl;
453e5d0e473Sopenharmony_ci        cout << "  address       : " << endl;
454e5d0e473Sopenharmony_ci        PrintAddr(msg.data.p2p.address);
455e5d0e473Sopenharmony_ci        cout << "  subAddress    : " << endl;
456e5d0e473Sopenharmony_ci        PrintSubAddr(msg.data.p2p.subAddress);
457e5d0e473Sopenharmony_ci        cout << "  replySeq      : " << static_cast<int>(msg.data.p2p.replySeq) << endl;
458e5d0e473Sopenharmony_ci        cout << "  telesvcMsg    : " << endl;
459e5d0e473Sopenharmony_ci        PrintTelesvc(msg.data.p2p.telesvcMsg);
460e5d0e473Sopenharmony_ci    } else if (msg.type == CdmaTransportMsgType::BROADCAST) {
461e5d0e473Sopenharmony_ci        cout << "BROADCAST" << endl;
462e5d0e473Sopenharmony_ci        cout << "  serviceCtg : " << msg.data.broadcast.serviceCtg << endl;
463e5d0e473Sopenharmony_ci        cout << "  telesvcMsg : " << endl;
464e5d0e473Sopenharmony_ci        if (msg.data.broadcast.serviceCtg >= static_cast<uint16_t>(SmsServiceCtg::CMAS_PRESIDENTIAL) &&
465e5d0e473Sopenharmony_ci            msg.data.broadcast.serviceCtg <= static_cast<uint16_t>(SmsServiceCtg::CMAS_TEST)) {
466e5d0e473Sopenharmony_ci            PrintTelesvc(msg.data.broadcast.telesvcMsg, true);
467e5d0e473Sopenharmony_ci        } else {
468e5d0e473Sopenharmony_ci            PrintTelesvc(msg.data.broadcast.telesvcMsg);
469e5d0e473Sopenharmony_ci        }
470e5d0e473Sopenharmony_ci    } else if (msg.type == CdmaTransportMsgType::ACK) {
471e5d0e473Sopenharmony_ci        cout << "ACK" << endl;
472e5d0e473Sopenharmony_ci        cout << "  address       : " << endl;
473e5d0e473Sopenharmony_ci        PrintAddr(msg.data.ack.address);
474e5d0e473Sopenharmony_ci        cout << "  subAddress    : " << endl;
475e5d0e473Sopenharmony_ci        cout << "  causeCode     : " << endl;
476e5d0e473Sopenharmony_ci        cout << "  transReplySeq : " << static_cast<int>(msg.data.ack.causeCode.transReplySeq) << endl;
477e5d0e473Sopenharmony_ci        cout << "  errorClass    : " << static_cast<int>(msg.data.ack.causeCode.errorClass) << endl;
478e5d0e473Sopenharmony_ci        cout << "  causeCode     : " << static_cast<int>(msg.data.ack.causeCode.causeCode) << endl;
479e5d0e473Sopenharmony_ci    } else {
480e5d0e473Sopenharmony_ci        cout << "Unknown type : " << static_cast<int>(msg.type) << endl;
481e5d0e473Sopenharmony_ci    }
482e5d0e473Sopenharmony_ci    cout << "TransportMsg <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << endl << flush;
483e5d0e473Sopenharmony_ci}
484e5d0e473Sopenharmony_ci
485e5d0e473Sopenharmony_civoid CdmaSmsTest::EncodeMsg(CdmaTransportMsg &msg) const
486e5d0e473Sopenharmony_ci{
487e5d0e473Sopenharmony_ci    std::unique_ptr<CdmaSmsTransportMessage> transportMessage = CdmaSmsTransportMessage::CreateTransportMessage(msg);
488e5d0e473Sopenharmony_ci    if (transportMessage == nullptr || transportMessage->IsEmpty()) {
489e5d0e473Sopenharmony_ci        std::cout << "create transport message error" << std::endl;
490e5d0e473Sopenharmony_ci        return;
491e5d0e473Sopenharmony_ci    }
492e5d0e473Sopenharmony_ci    SmsWriteBuffer pduBuffer;
493e5d0e473Sopenharmony_ci    if (!transportMessage->Encode(pduBuffer)) {
494e5d0e473Sopenharmony_ci        std::cout << "encode error" << std::endl;
495e5d0e473Sopenharmony_ci        return;
496e5d0e473Sopenharmony_ci    }
497e5d0e473Sopenharmony_ci    std::unique_ptr<std::vector<uint8_t>> pdu = pduBuffer.GetPduBuffer();
498e5d0e473Sopenharmony_ci    if (pdu == nullptr) {
499e5d0e473Sopenharmony_ci        std::cout << "get pdubuffer error" << std::endl;
500e5d0e473Sopenharmony_ci        return;
501e5d0e473Sopenharmony_ci    }
502e5d0e473Sopenharmony_ci    PrintMsg(msg);
503e5d0e473Sopenharmony_ci    std::cout << "TestEncodeSubmitMsg : " << StringUtils::StringToHex(*pdu) << std::endl;
504e5d0e473Sopenharmony_ci}
505e5d0e473Sopenharmony_ci
506e5d0e473Sopenharmony_civoid CdmaSmsTest::TestTextBasedSmsDelivery() const
507e5d0e473Sopenharmony_ci{
508e5d0e473Sopenharmony_ci    uint16_t dataBaseId = 0;
509e5d0e473Sopenharmony_ci    std::cout << "CdmaSmsTest::TestTextBasedSmsDelivery" << std::endl;
510e5d0e473Sopenharmony_ci    std::function<void(std::shared_ptr<SmsSendIndexer>)> fun = nullptr;
511e5d0e473Sopenharmony_ci    auto cdmaSmsSender = std::make_shared<CdmaSmsSender>(1, fun);
512e5d0e473Sopenharmony_ci    const sptr<ISendShortMessageCallback> sendCallback =
513e5d0e473Sopenharmony_ci        iface_cast<ISendShortMessageCallback>(new SendShortMessageCallbackStub());
514e5d0e473Sopenharmony_ci    if (sendCallback == nullptr) {
515e5d0e473Sopenharmony_ci        return;
516e5d0e473Sopenharmony_ci    }
517e5d0e473Sopenharmony_ci    const sptr<IDeliveryShortMessageCallback> deliveryCallback =
518e5d0e473Sopenharmony_ci        iface_cast<IDeliveryShortMessageCallback>(new DeliveryShortMessageCallbackStub());
519e5d0e473Sopenharmony_ci    if (deliveryCallback == nullptr) {
520e5d0e473Sopenharmony_ci        return;
521e5d0e473Sopenharmony_ci    }
522e5d0e473Sopenharmony_ci    const std::string desAddr = "qwe";
523e5d0e473Sopenharmony_ci    const std::string scAddr = "123";
524e5d0e473Sopenharmony_ci    const std::string text = "123";
525e5d0e473Sopenharmony_ci    cdmaSmsSender->TextBasedSmsDelivery(desAddr, scAddr, text, sendCallback, deliveryCallback, dataBaseId, true);
526e5d0e473Sopenharmony_ci    cdmaSmsSender->TextBasedSmsDelivery(desAddr, scAddr, text, sendCallback, deliveryCallback, dataBaseId, false);
527e5d0e473Sopenharmony_ci}
528e5d0e473Sopenharmony_ci
529e5d0e473Sopenharmony_civoid CdmaSmsTest::EncodeSubmitMsg(
530e5d0e473Sopenharmony_ci    std::string desAddr, std::string scAddr, std::string text, bool force7Bit, bool statusReport) const
531e5d0e473Sopenharmony_ci{
532e5d0e473Sopenharmony_ci    CdmaSmsMessage message;
533e5d0e473Sopenharmony_ci    DataCodingScheme codingType;
534e5d0e473Sopenharmony_ci    std::vector<struct SplitInfo> splits;
535e5d0e473Sopenharmony_ci    message.SplitMessage(splits, text, force7Bit, codingType, false, "");
536e5d0e473Sopenharmony_ci    std::cout << "codingType : " << codingType << std::endl;
537e5d0e473Sopenharmony_ci    if (splits.size() > MAX_SEGMENT_NUM) {
538e5d0e473Sopenharmony_ci        std::cout << "message exceed the limit." << std::endl;
539e5d0e473Sopenharmony_ci        return;
540e5d0e473Sopenharmony_ci    }
541e5d0e473Sopenharmony_ci    std::unique_ptr<CdmaTransportMsg> transMsg =
542e5d0e473Sopenharmony_ci        message.CreateSubmitTransMsg(desAddr, scAddr, text, statusReport, codingType);
543e5d0e473Sopenharmony_ci    if (transMsg == nullptr) {
544e5d0e473Sopenharmony_ci        std::cout << "CreateSubmitTransMsg nullptr fail." << std::endl;
545e5d0e473Sopenharmony_ci        return;
546e5d0e473Sopenharmony_ci    }
547e5d0e473Sopenharmony_ci    /* 1. Set Reply sequence number. */
548e5d0e473Sopenharmony_ci    uint8_t msgRef8bit = 1;
549e5d0e473Sopenharmony_ci    transMsg->data.p2p.replySeq = msgRef8bit;
550e5d0e473Sopenharmony_ci    /* 2. Set msg ID. */
551e5d0e473Sopenharmony_ci    transMsg->data.p2p.telesvcMsg.data.submit.msgId.msgId = MSG_ID;
552e5d0e473Sopenharmony_ci    for (std::size_t i = 0; i < splits.size(); i++) {
553e5d0e473Sopenharmony_ci        (void)memset_s(transMsg->data.p2p.telesvcMsg.data.submit.userData.userData.data,
554e5d0e473Sopenharmony_ci            sizeof(transMsg->data.p2p.telesvcMsg.data.submit.userData.userData.data), 0x00,
555e5d0e473Sopenharmony_ci            sizeof(transMsg->data.p2p.telesvcMsg.data.submit.userData.userData.data));
556e5d0e473Sopenharmony_ci        if (splits[i].encodeData.size() > sizeof(transMsg->data.p2p.telesvcMsg.data.submit.userData.userData.data)) {
557e5d0e473Sopenharmony_ci            TELEPHONY_LOGE("data length invalid");
558e5d0e473Sopenharmony_ci            return;
559e5d0e473Sopenharmony_ci        }
560e5d0e473Sopenharmony_ci        if (memcpy_s(transMsg->data.p2p.telesvcMsg.data.submit.userData.userData.data,
561e5d0e473Sopenharmony_ci            sizeof(transMsg->data.p2p.telesvcMsg.data.submit.userData.userData.data), splits[i].encodeData.data(),
562e5d0e473Sopenharmony_ci            splits[i].encodeData.size()) != EOK) {
563e5d0e473Sopenharmony_ci            return;
564e5d0e473Sopenharmony_ci        }
565e5d0e473Sopenharmony_ci        SetPduSeqInfo(splits.size(), transMsg, i, msgRef8bit);
566e5d0e473Sopenharmony_ci        transMsg->data.p2p.telesvcMsg.data.submit.userData.userData.length =
567e5d0e473Sopenharmony_ci            static_cast<int>(splits[i].encodeData.size());
568e5d0e473Sopenharmony_ci
569e5d0e473Sopenharmony_ci        /* encode msg data */
570e5d0e473Sopenharmony_ci        cout << "P2P SUBMIT" << endl;
571e5d0e473Sopenharmony_ci        EncodeMsg(*transMsg.get());
572e5d0e473Sopenharmony_ci    }
573e5d0e473Sopenharmony_ci}
574e5d0e473Sopenharmony_ci
575e5d0e473Sopenharmony_civoid CdmaSmsTest::TestEncodeSubmitMsg() const
576e5d0e473Sopenharmony_ci{
577e5d0e473Sopenharmony_ci    std::cout << "CdmaSmsTest::TestEncodeSubmitMsg" << std::endl;
578e5d0e473Sopenharmony_ci
579e5d0e473Sopenharmony_ci    std::cout << "Please enter the desAddr: " << std::endl;
580e5d0e473Sopenharmony_ci    std::string desAddr;
581e5d0e473Sopenharmony_ci    std::cin >> desAddr;
582e5d0e473Sopenharmony_ci
583e5d0e473Sopenharmony_ci    std::cout << "Please enter the scAddr: " << std::endl;
584e5d0e473Sopenharmony_ci    std::string scAddr;
585e5d0e473Sopenharmony_ci    std::cin >> scAddr;
586e5d0e473Sopenharmony_ci
587e5d0e473Sopenharmony_ci    std::cout << "Please enter the text: " << std::endl;
588e5d0e473Sopenharmony_ci    std::string text;
589e5d0e473Sopenharmony_ci    std::cin >> text;
590e5d0e473Sopenharmony_ci
591e5d0e473Sopenharmony_ci    std::cout << "Please enter the force7Bit: " << std::endl;
592e5d0e473Sopenharmony_ci    bool force7Bit = true;
593e5d0e473Sopenharmony_ci    std::cin >> force7Bit;
594e5d0e473Sopenharmony_ci
595e5d0e473Sopenharmony_ci    std::cout << "Please enter the statusReport: " << std::endl;
596e5d0e473Sopenharmony_ci    bool statusReport = true;
597e5d0e473Sopenharmony_ci    std::cin >> statusReport;
598e5d0e473Sopenharmony_ci
599e5d0e473Sopenharmony_ci    EncodeSubmitMsg(desAddr, scAddr, text, force7Bit, statusReport);
600e5d0e473Sopenharmony_ci}
601e5d0e473Sopenharmony_ci
602e5d0e473Sopenharmony_civoid CdmaSmsTest::TestEncodeCancelMsg() const
603e5d0e473Sopenharmony_ci{
604e5d0e473Sopenharmony_ci    std::cout << "CdmaSmsTest::TestEncodeCancelMsg" << std::endl;
605e5d0e473Sopenharmony_ci    std::cout << "Please enter the address: " << std::endl;
606e5d0e473Sopenharmony_ci    std::string address;
607e5d0e473Sopenharmony_ci    std::cin >> address;
608e5d0e473Sopenharmony_ci
609e5d0e473Sopenharmony_ci    CdmaTransportMsg msg;
610e5d0e473Sopenharmony_ci    memset_s(&msg, sizeof(msg), 0, sizeof(msg));
611e5d0e473Sopenharmony_ci    msg.type = CdmaTransportMsgType::P2P;
612e5d0e473Sopenharmony_ci    msg.data.p2p.teleserviceId = static_cast<uint16_t>(SmsTransTelsvcId::CMT_95);
613e5d0e473Sopenharmony_ci    msg.data.p2p.address.addrLen = address.length();
614e5d0e473Sopenharmony_ci    if (memcpy_s(msg.data.p2p.address.szData, msg.data.p2p.address.addrLen, address.c_str(),
615e5d0e473Sopenharmony_ci        msg.data.p2p.address.addrLen) != EOK) {
616e5d0e473Sopenharmony_ci        return;
617e5d0e473Sopenharmony_ci    }
618e5d0e473Sopenharmony_ci    msg.data.p2p.telesvcMsg.type = TeleserviceMsgType::CANCEL;
619e5d0e473Sopenharmony_ci    msg.data.p2p.telesvcMsg.data.cancel.msgId.msgId = MSG_ID;
620e5d0e473Sopenharmony_ci    msg.data.p2p.telesvcMsg.data.cancel.msgId.headerInd = 0;
621e5d0e473Sopenharmony_ci    cout << "P2P CANCEL" << endl;
622e5d0e473Sopenharmony_ci    EncodeMsg(msg);
623e5d0e473Sopenharmony_ci}
624e5d0e473Sopenharmony_ci
625e5d0e473Sopenharmony_civoid CdmaSmsTest::TestEncodeDeliverReportMsg() const
626e5d0e473Sopenharmony_ci{
627e5d0e473Sopenharmony_ci    std::cout << "CdmaSmsTest::TestEncodeDeliverReportMsg" << std::endl;
628e5d0e473Sopenharmony_ci    std::cout << "Please enter the address: " << std::endl;
629e5d0e473Sopenharmony_ci    std::string address;
630e5d0e473Sopenharmony_ci    std::cin >> address;
631e5d0e473Sopenharmony_ci
632e5d0e473Sopenharmony_ci    std::cout << "Please enter the text: " << std::endl;
633e5d0e473Sopenharmony_ci    std::string text;
634e5d0e473Sopenharmony_ci    std::cin >> text;
635e5d0e473Sopenharmony_ci
636e5d0e473Sopenharmony_ci    CdmaTransportMsg msg;
637e5d0e473Sopenharmony_ci    memset_s(&msg, sizeof(msg), 0, sizeof(msg));
638e5d0e473Sopenharmony_ci    msg.type = CdmaTransportMsgType::P2P;
639e5d0e473Sopenharmony_ci    msg.data.p2p.teleserviceId = static_cast<uint16_t>(SmsTransTelsvcId::CMT_95);
640e5d0e473Sopenharmony_ci    msg.data.p2p.address.addrLen = address.length();
641e5d0e473Sopenharmony_ci    if (memcpy_s(msg.data.p2p.address.szData, msg.data.p2p.address.addrLen, address.c_str(),
642e5d0e473Sopenharmony_ci        msg.data.p2p.address.addrLen) != EOK) {
643e5d0e473Sopenharmony_ci        return;
644e5d0e473Sopenharmony_ci    }
645e5d0e473Sopenharmony_ci    msg.data.p2p.telesvcMsg.type = TeleserviceMsgType::DELIVER_REPORT;
646e5d0e473Sopenharmony_ci    msg.data.p2p.telesvcMsg.data.report.msgId.msgId = MSG_ID;
647e5d0e473Sopenharmony_ci    msg.data.p2p.telesvcMsg.data.report.msgId.headerInd = 0;
648e5d0e473Sopenharmony_ci    msg.data.p2p.telesvcMsg.data.report.tpFailCause = TP_FAIL_CAUSE;
649e5d0e473Sopenharmony_ci    msg.data.p2p.telesvcMsg.data.report.userData.encodeType = SmsEncodingType::ASCII_7BIT;
650e5d0e473Sopenharmony_ci    msg.data.p2p.telesvcMsg.data.report.userData.userData.length = text.length();
651e5d0e473Sopenharmony_ci    if (memcpy_s(msg.data.p2p.telesvcMsg.data.report.userData.userData.data,
652e5d0e473Sopenharmony_ci        msg.data.p2p.telesvcMsg.data.report.userData.userData.length, text.c_str(),
653e5d0e473Sopenharmony_ci        msg.data.p2p.telesvcMsg.data.report.userData.userData.length) != EOK) {
654e5d0e473Sopenharmony_ci        return;
655e5d0e473Sopenharmony_ci    }
656e5d0e473Sopenharmony_ci    cout << "P2P DELIVER_REPORT" << endl;
657e5d0e473Sopenharmony_ci    EncodeMsg(msg);
658e5d0e473Sopenharmony_ci}
659e5d0e473Sopenharmony_ci
660e5d0e473Sopenharmony_civoid CdmaSmsTest::TestEncodeAckMsg() const
661e5d0e473Sopenharmony_ci{
662e5d0e473Sopenharmony_ci    std::cout << "CdmaSmsTest::TestEncodeAckMsg" << std::endl;
663e5d0e473Sopenharmony_ci    std::cout << "Please enter the address: " << std::endl;
664e5d0e473Sopenharmony_ci    std::string address;
665e5d0e473Sopenharmony_ci    std::cin >> address;
666e5d0e473Sopenharmony_ci
667e5d0e473Sopenharmony_ci    std::cout << "Please enter the errorClass(NONE = 0, TEMPORARY = 2, PERMANENT = 3): " << std::endl;
668e5d0e473Sopenharmony_ci    int errorClass;
669e5d0e473Sopenharmony_ci    std::cin >> errorClass;
670e5d0e473Sopenharmony_ci
671e5d0e473Sopenharmony_ci    std::cout << "Please enter the causeCode(INVAILD_TELESERVICE_ID = 4, SERVICE_TERMINATION_DENIED = 98): "
672e5d0e473Sopenharmony_ci              << std::endl;
673e5d0e473Sopenharmony_ci    int causeCode;
674e5d0e473Sopenharmony_ci    std::cin >> causeCode;
675e5d0e473Sopenharmony_ci
676e5d0e473Sopenharmony_ci    CdmaTransportMsg msg;
677e5d0e473Sopenharmony_ci    memset_s(&msg, sizeof(msg), 0, sizeof(msg));
678e5d0e473Sopenharmony_ci    msg.type = CdmaTransportMsgType::ACK;
679e5d0e473Sopenharmony_ci    msg.data.ack.address.addrLen = address.length();
680e5d0e473Sopenharmony_ci    if (memcpy_s(msg.data.ack.address.szData, msg.data.ack.address.addrLen, address.c_str(),
681e5d0e473Sopenharmony_ci        msg.data.ack.address.addrLen) != EOK) {
682e5d0e473Sopenharmony_ci        return;
683e5d0e473Sopenharmony_ci    }
684e5d0e473Sopenharmony_ci    msg.data.ack.causeCode.transReplySeq = REPLY_SEQ;
685e5d0e473Sopenharmony_ci    msg.data.ack.causeCode.errorClass = TransportErrClass(errorClass);
686e5d0e473Sopenharmony_ci    msg.data.ack.causeCode.causeCode = TransportCauseCodeType(causeCode);
687e5d0e473Sopenharmony_ci    cout << "ACK" << endl;
688e5d0e473Sopenharmony_ci    EncodeMsg(msg);
689e5d0e473Sopenharmony_ci}
690e5d0e473Sopenharmony_ci
691e5d0e473Sopenharmony_civoid CdmaSmsTest::TestDecodeMsg() const
692e5d0e473Sopenharmony_ci{
693e5d0e473Sopenharmony_ci    std::cout << "CdmaSmsTest::TestDecodeMsg" << std::endl;
694e5d0e473Sopenharmony_ci    std::cout << "Please enter the pdu: " << std::endl;
695e5d0e473Sopenharmony_ci    std::string pdu;
696e5d0e473Sopenharmony_ci    std::cin >> pdu;
697e5d0e473Sopenharmony_ci
698e5d0e473Sopenharmony_ci    CdmaTransportMsg msg;
699e5d0e473Sopenharmony_ci    memset_s(&msg, sizeof(msg), 0, sizeof(msg));
700e5d0e473Sopenharmony_ci    SmsReadBuffer pduBuffer(StringUtils::HexToString(pdu));
701e5d0e473Sopenharmony_ci    std::unique_ptr<CdmaSmsTransportMessage> message = CdmaSmsTransportMessage::CreateTransportMessage(msg, pduBuffer);
702e5d0e473Sopenharmony_ci    if (message == nullptr) {
703e5d0e473Sopenharmony_ci        std::cout << "create transport message error" << std::endl;
704e5d0e473Sopenharmony_ci        return;
705e5d0e473Sopenharmony_ci    }
706e5d0e473Sopenharmony_ci    if (!message->Decode(pduBuffer)) {
707e5d0e473Sopenharmony_ci        std::cout << "decode error" << std::endl;
708e5d0e473Sopenharmony_ci        return;
709e5d0e473Sopenharmony_ci    }
710e5d0e473Sopenharmony_ci    cout << "TestDecodeMsg : " << pdu << endl;
711e5d0e473Sopenharmony_ci    PrintMsg(msg);
712e5d0e473Sopenharmony_ci}
713e5d0e473Sopenharmony_ci
714e5d0e473Sopenharmony_civoid CdmaSmsTest::TestDecodeBearerData() const
715e5d0e473Sopenharmony_ci{
716e5d0e473Sopenharmony_ci    std::cout << "CdmaSmsTest::TestDecodeBearerData" << std::endl;
717e5d0e473Sopenharmony_ci    std::cout << "Please enter the pdu: " << std::endl;
718e5d0e473Sopenharmony_ci    std::string pdu;
719e5d0e473Sopenharmony_ci    std::cin >> pdu;
720e5d0e473Sopenharmony_ci
721e5d0e473Sopenharmony_ci    std::stringstream ss;
722e5d0e473Sopenharmony_ci    ss << static_cast<uint8_t>(CdmaSmsParameterRecord::BEARER_DATA);
723e5d0e473Sopenharmony_ci    ss << static_cast<uint8_t>(pdu.size() / HEX_CHAR_LEN);
724e5d0e473Sopenharmony_ci    ss << StringUtils::HexToString(pdu);
725e5d0e473Sopenharmony_ci
726e5d0e473Sopenharmony_ci    CdmaTeleserviceMsg v;
727e5d0e473Sopenharmony_ci    memset_s(&v, sizeof(CdmaTeleserviceMsg), 0x00, sizeof(CdmaTeleserviceMsg));
728e5d0e473Sopenharmony_ci    SmsReadBuffer rBuffer(ss.str());
729e5d0e473Sopenharmony_ci    rBuffer.SetIndex(VALUE_INDEX);
730e5d0e473Sopenharmony_ci    auto message = std::make_shared<CdmaSmsBearerData>(v, rBuffer);
731e5d0e473Sopenharmony_ci    if (message == nullptr) {
732e5d0e473Sopenharmony_ci        std::cout << "create bearer data error" << std::endl;
733e5d0e473Sopenharmony_ci        return;
734e5d0e473Sopenharmony_ci    }
735e5d0e473Sopenharmony_ci    rBuffer.SetIndex(0);
736e5d0e473Sopenharmony_ci    if (!message->Decode(rBuffer)) {
737e5d0e473Sopenharmony_ci        cout << "Decode error!!!!!!!!!!!!!!!!!!!" << endl;
738e5d0e473Sopenharmony_ci        return;
739e5d0e473Sopenharmony_ci    }
740e5d0e473Sopenharmony_ci
741e5d0e473Sopenharmony_ci    cout << "TestDecodeBearerData : " << pdu << endl;
742e5d0e473Sopenharmony_ci    PrintTelesvc(v);
743e5d0e473Sopenharmony_ci}
744e5d0e473Sopenharmony_ci
745e5d0e473Sopenharmony_civoid CdmaSmsTest::ProcessTest() const
746e5d0e473Sopenharmony_ci{
747e5d0e473Sopenharmony_ci    bool loopFlag = true;
748e5d0e473Sopenharmony_ci    while (loopFlag) {
749e5d0e473Sopenharmony_ci        std::cout << "\nusage:please input a cmd num:\n"
750e5d0e473Sopenharmony_ci                     "0:TestTextBasedSmsDelivery\n1:TestEncodeSubmitMsg\n2:TestEncodeCancelMsg\n"
751e5d0e473Sopenharmony_ci                     "3:TestEncodeDeliverReportMsg\n4:TestEncodeAckMsg\n5:TestDecodeMsg\n"
752e5d0e473Sopenharmony_ci                     "6:TestDecodeBearerData\n100:exit test cdma sms\n"
753e5d0e473Sopenharmony_ci                  << std::endl;
754e5d0e473Sopenharmony_ci
755e5d0e473Sopenharmony_ci        int inputCMD = 0;
756e5d0e473Sopenharmony_ci        std::cin >> inputCMD;
757e5d0e473Sopenharmony_ci        while (std::cin.fail()) {
758e5d0e473Sopenharmony_ci            std::cin.clear();
759e5d0e473Sopenharmony_ci            std::cin.ignore();
760e5d0e473Sopenharmony_ci            std::cin >> inputCMD;
761e5d0e473Sopenharmony_ci        }
762e5d0e473Sopenharmony_ci
763e5d0e473Sopenharmony_ci        std::cout << "inputCMD is:" << inputCMD << std::endl;
764e5d0e473Sopenharmony_ci
765e5d0e473Sopenharmony_ci        switch (inputCMD) {
766e5d0e473Sopenharmony_ci            case TEST_MENU_TEXT_DELIVERY:
767e5d0e473Sopenharmony_ci                TestTextBasedSmsDelivery();
768e5d0e473Sopenharmony_ci                break;
769e5d0e473Sopenharmony_ci            case TEST_MENU_ENCODE_SUBMIT:
770e5d0e473Sopenharmony_ci                TestEncodeSubmitMsg();
771e5d0e473Sopenharmony_ci                break;
772e5d0e473Sopenharmony_ci            case TEST_MENU_ENCODE_CANCEL:
773e5d0e473Sopenharmony_ci                TestEncodeCancelMsg();
774e5d0e473Sopenharmony_ci                break;
775e5d0e473Sopenharmony_ci            case TEST_MENU_ENCODE_DELIVER_REPORT:
776e5d0e473Sopenharmony_ci                TestEncodeDeliverReportMsg();
777e5d0e473Sopenharmony_ci                break;
778e5d0e473Sopenharmony_ci            case TEST_MENU_ENCODE_ACK:
779e5d0e473Sopenharmony_ci                TestEncodeAckMsg();
780e5d0e473Sopenharmony_ci                break;
781e5d0e473Sopenharmony_ci            case TEST_MENU_DECODE_MSG:
782e5d0e473Sopenharmony_ci                TestDecodeMsg();
783e5d0e473Sopenharmony_ci                break;
784e5d0e473Sopenharmony_ci            case TEST_MENU_DECODE_BEARER_DATA:
785e5d0e473Sopenharmony_ci                TestDecodeBearerData();
786e5d0e473Sopenharmony_ci                break;
787e5d0e473Sopenharmony_ci            case TEST_MENU_EXIT:
788e5d0e473Sopenharmony_ci                loopFlag = false;
789e5d0e473Sopenharmony_ci                break;
790e5d0e473Sopenharmony_ci            default:
791e5d0e473Sopenharmony_ci                break;
792e5d0e473Sopenharmony_ci        }
793e5d0e473Sopenharmony_ci    }
794e5d0e473Sopenharmony_ci}
795e5d0e473Sopenharmony_ci
796e5d0e473Sopenharmony_ci} // namespace Telephony
797e5d0e473Sopenharmony_ci} // namespace OHOS
798