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#define private public 17e5d0e473Sopenharmony_ci#define protected public 18e5d0e473Sopenharmony_ci 19e5d0e473Sopenharmony_ci#include <vector> 20e5d0e473Sopenharmony_ci 21e5d0e473Sopenharmony_ci#include "gsm_pdu_hex_value.h" 22e5d0e473Sopenharmony_ci#include "gsm_sms_common_utils.h" 23e5d0e473Sopenharmony_ci#include "gtest/gtest.h" 24e5d0e473Sopenharmony_ci#include "ims_sms_client.h" 25e5d0e473Sopenharmony_ci#include "sms_common_utils.h" 26e5d0e473Sopenharmony_ci#include "text_coder.h" 27e5d0e473Sopenharmony_ci 28e5d0e473Sopenharmony_cinamespace OHOS { 29e5d0e473Sopenharmony_cinamespace Telephony { 30e5d0e473Sopenharmony_ciusing namespace testing::ext; 31e5d0e473Sopenharmony_ci 32e5d0e473Sopenharmony_cinamespace { 33e5d0e473Sopenharmony_ciconst std::string TEXT_SMS_CONTENT = "hello world"; 34e5d0e473Sopenharmony_ciconst int BUF_SIZE = 2401; 35e5d0e473Sopenharmony_ciconst int TEXT_LENGTH = 2; 36e5d0e473Sopenharmony_ciconst int FILL_BITS = 2; 37e5d0e473Sopenharmony_ciconst int DIGIT_LEN = 3; 38e5d0e473Sopenharmony_ciconst int DIGIT_LEN2 = 6; 39e5d0e473Sopenharmony_ciconst unsigned char SRC_TEXT = 2; 40e5d0e473Sopenharmony_ci} // namespace 41e5d0e473Sopenharmony_ci 42e5d0e473Sopenharmony_ciclass BranchUtilsTest : public testing::Test { 43e5d0e473Sopenharmony_cipublic: 44e5d0e473Sopenharmony_ci static void SetUpTestCase(); 45e5d0e473Sopenharmony_ci static void TearDownTestCase(); 46e5d0e473Sopenharmony_ci void SetUp(); 47e5d0e473Sopenharmony_ci void TearDown(); 48e5d0e473Sopenharmony_ci}; 49e5d0e473Sopenharmony_civoid BranchUtilsTest::SetUpTestCase() {} 50e5d0e473Sopenharmony_ci 51e5d0e473Sopenharmony_civoid BranchUtilsTest::TearDownTestCase() 52e5d0e473Sopenharmony_ci{ 53e5d0e473Sopenharmony_ci DelayedSingleton<ImsSmsClient>::GetInstance()->UnInit(); 54e5d0e473Sopenharmony_ci} 55e5d0e473Sopenharmony_ci 56e5d0e473Sopenharmony_civoid BranchUtilsTest::SetUp() {} 57e5d0e473Sopenharmony_ci 58e5d0e473Sopenharmony_civoid BranchUtilsTest::TearDown() {} 59e5d0e473Sopenharmony_ci 60e5d0e473Sopenharmony_ci/** 61e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_TextCoder_0001 62e5d0e473Sopenharmony_ci * @tc.name Test TextCoder 63e5d0e473Sopenharmony_ci * @tc.desc Function test 64e5d0e473Sopenharmony_ci */ 65e5d0e473Sopenharmony_ciHWTEST_F(BranchUtilsTest, TextCoder_0001, Function | MediumTest | Level1) 66e5d0e473Sopenharmony_ci{ 67e5d0e473Sopenharmony_ci DataCodingScheme DataCodingScheme; 68e5d0e473Sopenharmony_ci MsgLangInfo msgLangInfo; 69e5d0e473Sopenharmony_ci unsigned char encodeData[BUF_SIZE]; 70e5d0e473Sopenharmony_ci MSG_LANGUAGE_ID_T langId = 0; 71e5d0e473Sopenharmony_ci bool unknown = false; 72e5d0e473Sopenharmony_ci unsigned short inText = 1; 73e5d0e473Sopenharmony_ci const uint8_t *pMsgText = (const uint8_t *)TEXT_SMS_CONTENT.c_str(); 74e5d0e473Sopenharmony_ci uint8_t *pDestText = encodeData; 75e5d0e473Sopenharmony_ci SmsCodingNationalType codingNational = SMS_CODING_NATIONAL_TYPE_DEFAULT; 76e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().Utf8ToGsm7bit(pDestText, BUF_SIZE, const_cast<uint8_t *>(pMsgText), 0, langId), 0); 77e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().CdmaUtf8ToAuto(pDestText, 1, pMsgText, 1, DataCodingScheme), -1); 78e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().GsmUtf8ToAuto(pDestText, 1, pMsgText, 1, 79e5d0e473Sopenharmony_ci DataCodingScheme, codingNational, langId), -1); 80e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().Utf8ToUcs2(pDestText, 1, pMsgText, -1), -1); 81e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().Utf8ToUcs2(pDestText, 0, pMsgText, -1), 0); 82e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().CdmaUtf8ToAuto(pDestText, 1, pMsgText, 0, DataCodingScheme), 0); 83e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().GsmUtf8ToAuto(pDestText, 1, pMsgText, 0, 84e5d0e473Sopenharmony_ci DataCodingScheme, codingNational, langId), 0); 85e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().Gsm7bitToUtf8(pDestText, 0, pMsgText, 0, msgLangInfo), 0); 86e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().ShiftjisToUtf8(pDestText, 1, pMsgText, -1), 0); 87e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().Ucs2ToUtf8(pDestText, 1, pMsgText, -1), 0); 88e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().EuckrToUtf8(pDestText, 1, pMsgText, -1), 0); 89e5d0e473Sopenharmony_ci EXPECT_FALSE(TextCoder::Instance().Ucs2ToUtf8(pDestText, 0, pMsgText, 0)); 90e5d0e473Sopenharmony_ci EXPECT_FALSE(TextCoder::Instance().EuckrToUtf8(pDestText, 0, pMsgText, 1)); 91e5d0e473Sopenharmony_ci EXPECT_FALSE(TextCoder::Instance().ShiftjisToUtf8(pDestText, 0, pMsgText, 1)); 92e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().Ucs2ToGsm7bit(pDestText, 0, pMsgText, 0, langId), -1); 93e5d0e473Sopenharmony_ci EXPECT_GT(TextCoder::Instance().Ucs2ToGsm7bit(pDestText, 1, pMsgText, TEXT_LENGTH, langId), 0); 94e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().Ucs2ToGsm7bitAuto(pDestText, 0, pMsgText, 0, unknown, codingNational), -1); 95e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().Ucs2ToGsm7bitAuto(pDestText, 1, pMsgText, 1, unknown, codingNational), 0); 96e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().Ucs2ToAscii(pDestText, 0, pMsgText, 0, unknown), -1); 97e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().Ucs2ToAscii(pDestText, 1, pMsgText, 1, unknown), 0); 98e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().GetLangType(pMsgText, 0), MSG_DEFAULT_CHAR); 99e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().GetLangType(pMsgText, 0), MSG_DEFAULT_CHAR); 100e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().FindGsm7bitExt(pDestText, 0, inText), 0); 101e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().FindGsm7bitExt(pDestText, 1, inText), 0); 102e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().FindTurkish(pDestText, 0, inText), 0); 103e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().FindTurkish(pDestText, 1, inText), 0); 104e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().FindSpanish(pDestText, 0, inText), 0); 105e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().FindSpanish(pDestText, 1, inText), 0); 106e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().FindPortu(pDestText, 0, inText), 0); 107e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().FindPortu(pDestText, 1, inText), 0); 108e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().FindReplaceChar(inText), MSG_DEFAULT_CHAR); 109e5d0e473Sopenharmony_ci auto extMap = TextCoder::Instance().Get7BitCodingExtMap(codingNational); 110e5d0e473Sopenharmony_ci EXPECT_GE(extMap.size(), 0); 111e5d0e473Sopenharmony_ci} 112e5d0e473Sopenharmony_ci 113e5d0e473Sopenharmony_ci/** 114e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_TextCoder_0002 115e5d0e473Sopenharmony_ci * @tc.name Test TextCoder 116e5d0e473Sopenharmony_ci * @tc.desc Function test 117e5d0e473Sopenharmony_ci */ 118e5d0e473Sopenharmony_ciHWTEST_F(BranchUtilsTest, TextCoder_0002, Function | MediumTest | Level1) 119e5d0e473Sopenharmony_ci{ 120e5d0e473Sopenharmony_ci MsgLangInfo pLangInfo; 121e5d0e473Sopenharmony_ci pLangInfo.bLockingShift = true; 122e5d0e473Sopenharmony_ci pLangInfo.bSingleShift = true; 123e5d0e473Sopenharmony_ci unsigned char encodeData[BUF_SIZE]; 124e5d0e473Sopenharmony_ci unsigned short result = 1; 125e5d0e473Sopenharmony_ci const uint8_t *pMsgText = (const uint8_t *)TEXT_SMS_CONTENT.c_str(); 126e5d0e473Sopenharmony_ci uint8_t *pDestText = encodeData; 127e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().Gsm7bitToUcs2(pDestText, 0, pMsgText, 0, pLangInfo), -1); 128e5d0e473Sopenharmony_ci pLangInfo.lockingLang = MSG_ID_TURKISH_LANG; 129e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().Gsm7bitToUcs2(pDestText, 1, pMsgText, 1, pLangInfo), 0); 130e5d0e473Sopenharmony_ci EXPECT_GT(TextCoder::Instance().EscapeToUcs2(SRC_TEXT, pLangInfo), 0); 131e5d0e473Sopenharmony_ci pLangInfo.lockingLang = MSG_ID_PORTUGUESE_LANG; 132e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().Gsm7bitToUcs2(pDestText, 1, pMsgText, 1, pLangInfo), 0); 133e5d0e473Sopenharmony_ci EXPECT_GT(TextCoder::Instance().EscapeToUcs2(SRC_TEXT, pLangInfo), 0); 134e5d0e473Sopenharmony_ci pLangInfo.bLockingShift = false; 135e5d0e473Sopenharmony_ci EXPECT_GE(TextCoder::Instance().Gsm7bitToUcs2(pDestText, 1, pMsgText, 1, pLangInfo), 0); 136e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().EscapeTurkishLockingToUcs2(pMsgText, 0, pLangInfo, result), 0); 137e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().EscapeTurkishLockingToUcs2(pMsgText, 1, pLangInfo, result), 0); 138e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().EscapePortuLockingToUcs2(pMsgText, 0, pLangInfo, result), 0); 139e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().EscapePortuLockingToUcs2(pMsgText, 1, pLangInfo, result), 0); 140e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().EscapeGsm7bitToUcs2(pMsgText, 0, pLangInfo, result), 0); 141e5d0e473Sopenharmony_ci EXPECT_EQ(TextCoder::Instance().EscapeGsm7bitToUcs2(pMsgText, 1, pLangInfo, result), 0); 142e5d0e473Sopenharmony_ci pLangInfo.singleLang = MSG_ID_SPANISH_LANG; 143e5d0e473Sopenharmony_ci EXPECT_GT(TextCoder::Instance().EscapeToUcs2(SRC_TEXT, pLangInfo), 0); 144e5d0e473Sopenharmony_ci pLangInfo.singleLang = MSG_ID_RESERVED_LANG; 145e5d0e473Sopenharmony_ci EXPECT_GT(TextCoder::Instance().EscapeToUcs2(SRC_TEXT, pLangInfo), 0); 146e5d0e473Sopenharmony_ci pLangInfo.bSingleShift = false; 147e5d0e473Sopenharmony_ci EXPECT_GT(TextCoder::Instance().EscapeToUcs2(SRC_TEXT, pLangInfo), 0); 148e5d0e473Sopenharmony_ci} 149e5d0e473Sopenharmony_ci 150e5d0e473Sopenharmony_ci/** 151e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsCommonUtils_0001 152e5d0e473Sopenharmony_ci * @tc.name Test SmsCommonUtils 153e5d0e473Sopenharmony_ci * @tc.desc Function test 154e5d0e473Sopenharmony_ci */ 155e5d0e473Sopenharmony_ciHWTEST_F(BranchUtilsTest, SmsCommonUtils_0001, Function | MediumTest | Level1) 156e5d0e473Sopenharmony_ci{ 157e5d0e473Sopenharmony_ci auto smsCommonUtils = std::make_shared<SmsCommonUtils>(); 158e5d0e473Sopenharmony_ci const unsigned char *userData = (const unsigned char *)TEXT_SMS_CONTENT.c_str(); 159e5d0e473Sopenharmony_ci const std::string str = "*#PPQQ"; 160e5d0e473Sopenharmony_ci const char *digit = (const char *)str.c_str(); 161e5d0e473Sopenharmony_ci unsigned char *packData = (unsigned char *)TEXT_SMS_CONTENT.c_str(); 162e5d0e473Sopenharmony_ci EXPECT_EQ(smsCommonUtils->Pack7bitChar(nullptr, 0, 0, nullptr, 0), 0); 163e5d0e473Sopenharmony_ci EXPECT_EQ(smsCommonUtils->Unpack7bitChar(nullptr, 1, 1, nullptr, 1), 0); 164e5d0e473Sopenharmony_ci EXPECT_EQ(smsCommonUtils->Pack7bitChar(userData, 1, 0, packData, 1), 1); 165e5d0e473Sopenharmony_ci EXPECT_EQ(smsCommonUtils->Pack7bitChar(userData, 1, 1, packData, 1), 1); 166e5d0e473Sopenharmony_ci EXPECT_EQ(smsCommonUtils->Pack7bitChar(userData, 1, FILL_BITS, packData, 1), 1); 167e5d0e473Sopenharmony_ci EXPECT_EQ(smsCommonUtils->Unpack7bitChar(userData, 1, 0, packData, 1), 0); 168e5d0e473Sopenharmony_ci EXPECT_EQ(smsCommonUtils->Unpack7bitChar(userData, 1, FILL_BITS, packData, 1), 0); 169e5d0e473Sopenharmony_ci EXPECT_EQ(smsCommonUtils->DigitToDtmfChar('*'), static_cast<char>(0x0B)); 170e5d0e473Sopenharmony_ci EXPECT_EQ(smsCommonUtils->DtmfCharToDigit(static_cast<char>(0x0B)), '*'); 171e5d0e473Sopenharmony_ci 172e5d0e473Sopenharmony_ci auto gsmUtils = std::make_shared<GsmSmsCommonUtils>(); 173e5d0e473Sopenharmony_ci uint8_t len; 174e5d0e473Sopenharmony_ci EXPECT_EQ(gsmUtils->DigitToBcd(digit, 1, nullptr, 0, len), 0); 175e5d0e473Sopenharmony_ci EXPECT_EQ(gsmUtils->DigitToBcd(nullptr, 1, packData, 1, len), 0); 176e5d0e473Sopenharmony_ci EXPECT_FALSE(gsmUtils->DigitToBcd(digit, DIGIT_LEN, packData, 1, len)); 177e5d0e473Sopenharmony_ci std::string digits; 178e5d0e473Sopenharmony_ci EXPECT_EQ(gsmUtils->BcdToDigit(userData, 1, digits, 1), 0); 179e5d0e473Sopenharmony_ci EXPECT_EQ(gsmUtils->BcdToDigit(nullptr, 1, digits, 1), 0); 180e5d0e473Sopenharmony_ci} 181e5d0e473Sopenharmony_ci 182e5d0e473Sopenharmony_ci/** 183e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsCommonUtils_0002 184e5d0e473Sopenharmony_ci * @tc.name Test SmsCommonUtils DigitToBcd support for +*# 185e5d0e473Sopenharmony_ci * @tc.desc Function test 186e5d0e473Sopenharmony_ci */ 187e5d0e473Sopenharmony_ciHWTEST_F(BranchUtilsTest, SmsCommonUtils_0002, Function | MediumTest | Level1) 188e5d0e473Sopenharmony_ci{ 189e5d0e473Sopenharmony_ci // input data with pure number 190e5d0e473Sopenharmony_ci const std::string packDataStr = "hello world"; 191e5d0e473Sopenharmony_ci const std::string digitTestStr = "17288424569"; 192e5d0e473Sopenharmony_ci const char *digit = (const char *)digitTestStr.c_str(); 193e5d0e473Sopenharmony_ci unsigned char *packData = (unsigned char *)packDataStr.c_str(); 194e5d0e473Sopenharmony_ci auto gsmUtils = std::make_shared<GsmSmsCommonUtils>(); 195e5d0e473Sopenharmony_ci EXPECT_NE(gsmUtils, nullptr); 196e5d0e473Sopenharmony_ci uint8_t len = static_cast<uint8_t>(DIGIT_LEN); 197e5d0e473Sopenharmony_ci EXPECT_FALSE(gsmUtils->DigitToBcd(digit, DIGIT_LEN, packData, DIGIT_LEN, len)); 198e5d0e473Sopenharmony_ci EXPECT_FALSE(gsmUtils->DigitToBcd(digit, DIGIT_LEN, packData, DIGIT_LEN - 1, len)); 199e5d0e473Sopenharmony_ci len = 0; 200e5d0e473Sopenharmony_ci EXPECT_TRUE(gsmUtils->DigitToBcd(digit, DIGIT_LEN2, packData, DIGIT_LEN2, len)); 201e5d0e473Sopenharmony_ci std::vector<uint8_t> userDataVec(packData, packData + DIGIT_LEN2); 202e5d0e473Sopenharmony_ci EXPECT_TRUE(std::find(userDataVec.begin(), userDataVec.end(), 0x71) != userDataVec.end()); 203e5d0e473Sopenharmony_ci EXPECT_TRUE(std::find(userDataVec.begin(), userDataVec.end(), 0x82) != userDataVec.end()); 204e5d0e473Sopenharmony_ci} 205e5d0e473Sopenharmony_ci 206e5d0e473Sopenharmony_ci/** 207e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsCommonUtils_0003 208e5d0e473Sopenharmony_ci * @tc.name Test SmsCommonUtils DigitToBcd 209e5d0e473Sopenharmony_ci * @tc.desc Function test 210e5d0e473Sopenharmony_ci */ 211e5d0e473Sopenharmony_ciHWTEST_F(BranchUtilsTest, SmsCommonUtils_0003, Function | MediumTest | Level1) 212e5d0e473Sopenharmony_ci{ 213e5d0e473Sopenharmony_ci // input data with number and + 214e5d0e473Sopenharmony_ci const std::string packDataStr = "hello world"; 215e5d0e473Sopenharmony_ci const std::string digitTestStr = "+17288424569"; 216e5d0e473Sopenharmony_ci const char *digit = (const char *)digitTestStr.c_str(); 217e5d0e473Sopenharmony_ci unsigned char *packData = (unsigned char *)packDataStr.c_str(); 218e5d0e473Sopenharmony_ci auto gsmUtils = std::make_shared<GsmSmsCommonUtils>(); 219e5d0e473Sopenharmony_ci EXPECT_NE(gsmUtils, nullptr); 220e5d0e473Sopenharmony_ci uint8_t len; 221e5d0e473Sopenharmony_ci EXPECT_TRUE(gsmUtils->DigitToBcd(digit, DIGIT_LEN2, packData, DIGIT_LEN2, len)); 222e5d0e473Sopenharmony_ci std::vector<uint8_t> userDataVec(packData, packData + DIGIT_LEN2); 223e5d0e473Sopenharmony_ci EXPECT_TRUE(std::find(userDataVec.begin(), userDataVec.end(), 0x78) != userDataVec.end()); 224e5d0e473Sopenharmony_ci EXPECT_TRUE(std::find(userDataVec.begin(), userDataVec.end(), 0x27) != userDataVec.end()); 225e5d0e473Sopenharmony_ci} 226e5d0e473Sopenharmony_ci 227e5d0e473Sopenharmony_ci/** 228e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsCommonUtils_0004 229e5d0e473Sopenharmony_ci * @tc.name Test SmsCommonUtils DigitToBcd 230e5d0e473Sopenharmony_ci * @tc.desc Function test 231e5d0e473Sopenharmony_ci */ 232e5d0e473Sopenharmony_ciHWTEST_F(BranchUtilsTest, SmsCommonUtils_0004, Function | MediumTest | Level1) 233e5d0e473Sopenharmony_ci{ 234e5d0e473Sopenharmony_ci // input data with number and # 235e5d0e473Sopenharmony_ci const std::string packDataStr = "hello world"; 236e5d0e473Sopenharmony_ci const std::string digitTestStr = "#17288424569"; 237e5d0e473Sopenharmony_ci const char *digit = (const char *)digitTestStr.c_str(); 238e5d0e473Sopenharmony_ci unsigned char *packData = (unsigned char *)packDataStr.c_str(); 239e5d0e473Sopenharmony_ci auto gsmUtils = std::make_shared<GsmSmsCommonUtils>(); 240e5d0e473Sopenharmony_ci EXPECT_NE(gsmUtils, nullptr); 241e5d0e473Sopenharmony_ci uint8_t len; 242e5d0e473Sopenharmony_ci EXPECT_TRUE(gsmUtils->DigitToBcd(digit, DIGIT_LEN2, packData, DIGIT_LEN2, len)); 243e5d0e473Sopenharmony_ci std::vector<uint8_t> userDataVec(packData, packData + DIGIT_LEN2); 244e5d0e473Sopenharmony_ci EXPECT_TRUE(std::find(userDataVec.begin(), userDataVec.end(), 0x1b) != userDataVec.end()); 245e5d0e473Sopenharmony_ci} 246e5d0e473Sopenharmony_ci 247e5d0e473Sopenharmony_ci/** 248e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsCommonUtils_0005 249e5d0e473Sopenharmony_ci * @tc.name Test SmsCommonUtils DigitToBcd 250e5d0e473Sopenharmony_ci * @tc.desc Function test 251e5d0e473Sopenharmony_ci */ 252e5d0e473Sopenharmony_ciHWTEST_F(BranchUtilsTest, SmsCommonUtils_0005, Function | MediumTest | Level1) 253e5d0e473Sopenharmony_ci{ 254e5d0e473Sopenharmony_ci // input data with # and * 255e5d0e473Sopenharmony_ci const std::string packDataStr = "hello world"; 256e5d0e473Sopenharmony_ci const std::string digitTestStr = "*0#0765"; 257e5d0e473Sopenharmony_ci const char *digit = (const char *)digitTestStr.c_str(); 258e5d0e473Sopenharmony_ci unsigned char *packData = (unsigned char *)packDataStr.c_str(); 259e5d0e473Sopenharmony_ci auto gsmUtils = std::make_shared<GsmSmsCommonUtils>(); 260e5d0e473Sopenharmony_ci EXPECT_NE(gsmUtils, nullptr); 261e5d0e473Sopenharmony_ci uint8_t len; 262e5d0e473Sopenharmony_ci EXPECT_TRUE(gsmUtils->DigitToBcd(digit, DIGIT_LEN2, packData, DIGIT_LEN2, len)); 263e5d0e473Sopenharmony_ci std::vector<uint8_t> userDataVec(packData, packData + DIGIT_LEN2); 264e5d0e473Sopenharmony_ci EXPECT_TRUE(std::find(userDataVec.begin(), userDataVec.end(), HEX_VALUE_0B) != userDataVec.end()); 265e5d0e473Sopenharmony_ci EXPECT_TRUE(std::find(userDataVec.begin(), userDataVec.end(), HEX_VALUE_0A) != userDataVec.end()); 266e5d0e473Sopenharmony_ci} 267e5d0e473Sopenharmony_ci 268e5d0e473Sopenharmony_ci/** 269e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsCommonUtils_0006 270e5d0e473Sopenharmony_ci * @tc.name Test SmsCommonUtils DigitToBcd 271e5d0e473Sopenharmony_ci * @tc.desc Function test 272e5d0e473Sopenharmony_ci */ 273e5d0e473Sopenharmony_ciHWTEST_F(BranchUtilsTest, SmsCommonUtils_0006, Function | MediumTest | Level1) 274e5d0e473Sopenharmony_ci{ 275e5d0e473Sopenharmony_ci // input data with # and * 276e5d0e473Sopenharmony_ci const std::string packDataStr = "hello world"; 277e5d0e473Sopenharmony_ci const std::string digitTestStr = "*21#13105550020#"; 278e5d0e473Sopenharmony_ci const char *digit = (const char *)digitTestStr.c_str(); 279e5d0e473Sopenharmony_ci unsigned char *packData = (unsigned char *)packDataStr.c_str(); 280e5d0e473Sopenharmony_ci auto gsmUtils = std::make_shared<GsmSmsCommonUtils>(); 281e5d0e473Sopenharmony_ci EXPECT_NE(gsmUtils, nullptr); 282e5d0e473Sopenharmony_ci uint8_t len; 283e5d0e473Sopenharmony_ci EXPECT_TRUE(gsmUtils->DigitToBcd(digit, DIGIT_LEN2, packData, DIGIT_LEN2, len)); 284e5d0e473Sopenharmony_ci std::vector<uint8_t> userDataVec(packData, packData + DIGIT_LEN2); 285e5d0e473Sopenharmony_ci EXPECT_TRUE(std::find(userDataVec.begin(), userDataVec.end(), 0x2a) != userDataVec.end()); 286e5d0e473Sopenharmony_ci EXPECT_TRUE(std::find(userDataVec.begin(), userDataVec.end(), 0xb1) != userDataVec.end()); 287e5d0e473Sopenharmony_ci EXPECT_TRUE(std::find(userDataVec.begin(), userDataVec.end(), 0x6f) != userDataVec.end()); 288e5d0e473Sopenharmony_ci} 289e5d0e473Sopenharmony_ci} // namespace Telephony 290e5d0e473Sopenharmony_ci} // namespace OHOS 291