1e5d0e473Sopenharmony_ci/* 2e5d0e473Sopenharmony_ci * Copyright (C) 2024 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 "gtest/gtest.h" 17e5d0e473Sopenharmony_ci#define private public 18e5d0e473Sopenharmony_ci#define protected public 19e5d0e473Sopenharmony_ci#include "cb_start_ability.h" 20e5d0e473Sopenharmony_ci#include "os_account.h" 21e5d0e473Sopenharmony_ci#include "ios_account.h" 22e5d0e473Sopenharmony_ci#include "gsm_sms_param_codec.h" 23e5d0e473Sopenharmony_ci#include "gsm_pdu_hex_value.h" 24e5d0e473Sopenharmony_ci#include "gsm_sms_common_utils.h" 25e5d0e473Sopenharmony_ci#include "gsm_sms_message.h" 26e5d0e473Sopenharmony_ci#include "gsm_sms_receive_handler.h" 27e5d0e473Sopenharmony_ci 28e5d0e473Sopenharmony_cinamespace OHOS { 29e5d0e473Sopenharmony_cinamespace Telephony { 30e5d0e473Sopenharmony_ciusing namespace testing::ext; 31e5d0e473Sopenharmony_ci 32e5d0e473Sopenharmony_cistatic constexpr uint8_t MAX_GSM_7BIT_DATA_LEN = 160; 33e5d0e473Sopenharmony_ci 34e5d0e473Sopenharmony_ciclass SmsGsmTest : public testing::Test { 35e5d0e473Sopenharmony_cipublic: 36e5d0e473Sopenharmony_ci static void SetUpTestCase() 37e5d0e473Sopenharmony_ci {} 38e5d0e473Sopenharmony_ci static void TearDownTestCase() 39e5d0e473Sopenharmony_ci {} 40e5d0e473Sopenharmony_ci void SetUp() 41e5d0e473Sopenharmony_ci {} 42e5d0e473Sopenharmony_ci void TearDown() 43e5d0e473Sopenharmony_ci {} 44e5d0e473Sopenharmony_ci}; 45e5d0e473Sopenharmony_ci 46e5d0e473Sopenharmony_ci/** 47e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsGsmTest_001 48e5d0e473Sopenharmony_ci * @tc.name SmsGsmTest_001 49e5d0e473Sopenharmony_ci * @tc.desc Function test 50e5d0e473Sopenharmony_ci */ 51e5d0e473Sopenharmony_ciHWTEST_F(SmsGsmTest, SmsGsmTest_001, Function | MediumTest | Level1) 52e5d0e473Sopenharmony_ci{ 53e5d0e473Sopenharmony_ci AAFwk::Want want; 54e5d0e473Sopenharmony_ci DelayedSingleton<CbStartAbility>::GetInstance()->StartAbility(want); 55e5d0e473Sopenharmony_ci EXPECT_EQ(want.GetModuleName(), "entry"); 56e5d0e473Sopenharmony_ci} 57e5d0e473Sopenharmony_ci 58e5d0e473Sopenharmony_ci/** 59e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsGsmTest_002 60e5d0e473Sopenharmony_ci * @tc.name SmsGsmTest_002 61e5d0e473Sopenharmony_ci * @tc.desc Function test 62e5d0e473Sopenharmony_ci */ 63e5d0e473Sopenharmony_ciHWTEST_F(SmsGsmTest, SmsGsmTest_002, Function | MediumTest | Level1) 64e5d0e473Sopenharmony_ci{ 65e5d0e473Sopenharmony_ci std::shared_ptr<GsmSmsParamCodec> codec = std::make_shared<GsmSmsParamCodec>(); 66e5d0e473Sopenharmony_ci 67e5d0e473Sopenharmony_ci string strBuff; 68e5d0e473Sopenharmony_ci int32_t setType = 0; 69e5d0e473Sopenharmony_ci int32_t indType = 0; 70e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_0D; 71e5d0e473Sopenharmony_ci SmsReadBuffer smsReadBuff(strBuff); 72e5d0e473Sopenharmony_ci EXPECT_FALSE(codec->CheckVoicemail(smsReadBuff, &setType, &indType)); 73e5d0e473Sopenharmony_ci} 74e5d0e473Sopenharmony_ci 75e5d0e473Sopenharmony_ci/** 76e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsGsmTest_003 77e5d0e473Sopenharmony_ci * @tc.name SmsGsmTest_003 78e5d0e473Sopenharmony_ci * @tc.desc Function test 79e5d0e473Sopenharmony_ci */ 80e5d0e473Sopenharmony_ciHWTEST_F(SmsGsmTest, SmsGsmTest_003, Function | MediumTest | Level1) 81e5d0e473Sopenharmony_ci{ 82e5d0e473Sopenharmony_ci std::shared_ptr<GsmSmsParamCodec> codec = std::make_shared<GsmSmsParamCodec>(); 83e5d0e473Sopenharmony_ci 84e5d0e473Sopenharmony_ci string strBuff; 85e5d0e473Sopenharmony_ci int32_t setType = 0; 86e5d0e473Sopenharmony_ci int32_t indType = 0; 87e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_04; 88e5d0e473Sopenharmony_ci SmsReadBuffer smsReadBuff(strBuff); 89e5d0e473Sopenharmony_ci EXPECT_FALSE(codec->CheckVoicemail(smsReadBuff, &setType, &indType)); 90e5d0e473Sopenharmony_ci} 91e5d0e473Sopenharmony_ci 92e5d0e473Sopenharmony_ci/** 93e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsGsmTest_004 94e5d0e473Sopenharmony_ci * @tc.name SmsGsmTest_004 95e5d0e473Sopenharmony_ci * @tc.desc Function test 96e5d0e473Sopenharmony_ci */ 97e5d0e473Sopenharmony_ciHWTEST_F(SmsGsmTest, SmsGsmTest_004, Function | MediumTest | Level1) 98e5d0e473Sopenharmony_ci{ 99e5d0e473Sopenharmony_ci std::shared_ptr<GsmSmsParamCodec> codec = std::make_shared<GsmSmsParamCodec>(); 100e5d0e473Sopenharmony_ci 101e5d0e473Sopenharmony_ci string strBuff; 102e5d0e473Sopenharmony_ci int32_t setType = 0; 103e5d0e473Sopenharmony_ci int32_t indType = 0; 104e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_04; 105e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_04; 106e5d0e473Sopenharmony_ci SmsReadBuffer smsReadBuff(strBuff); 107e5d0e473Sopenharmony_ci EXPECT_FALSE(codec->CheckVoicemail(smsReadBuff, &setType, &indType)); 108e5d0e473Sopenharmony_ci} 109e5d0e473Sopenharmony_ci 110e5d0e473Sopenharmony_ci/** 111e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsGsmTest_005 112e5d0e473Sopenharmony_ci * @tc.name SmsGsmTest_005 113e5d0e473Sopenharmony_ci * @tc.desc Function test 114e5d0e473Sopenharmony_ci */ 115e5d0e473Sopenharmony_ciHWTEST_F(SmsGsmTest, SmsGsmTest_005, Function | MediumTest | Level1) 116e5d0e473Sopenharmony_ci{ 117e5d0e473Sopenharmony_ci std::shared_ptr<GsmSmsParamCodec> codec = std::make_shared<GsmSmsParamCodec>(); 118e5d0e473Sopenharmony_ci 119e5d0e473Sopenharmony_ci string strBuff; 120e5d0e473Sopenharmony_ci int32_t setType = 0; 121e5d0e473Sopenharmony_ci int32_t indType = 0; 122e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_04; 123e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_D0; 124e5d0e473Sopenharmony_ci SmsReadBuffer smsReadBuff(strBuff); 125e5d0e473Sopenharmony_ci EXPECT_FALSE(codec->CheckVoicemail(smsReadBuff, &setType, &indType)); 126e5d0e473Sopenharmony_ci} 127e5d0e473Sopenharmony_ci 128e5d0e473Sopenharmony_ci 129e5d0e473Sopenharmony_ci/** 130e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsGsmTest_006 131e5d0e473Sopenharmony_ci * @tc.name SmsGsmTest_006 132e5d0e473Sopenharmony_ci * @tc.desc Function test 133e5d0e473Sopenharmony_ci */ 134e5d0e473Sopenharmony_ciHWTEST_F(SmsGsmTest, SmsGsmTest_006, Function | MediumTest | Level1) 135e5d0e473Sopenharmony_ci{ 136e5d0e473Sopenharmony_ci std::shared_ptr<GsmSmsParamCodec> codec = std::make_shared<GsmSmsParamCodec>(); 137e5d0e473Sopenharmony_ci string strBuff; 138e5d0e473Sopenharmony_ci int32_t setType = 0; 139e5d0e473Sopenharmony_ci int32_t indType = 0; 140e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_04; 141e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_D0; 142e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_D0; 143e5d0e473Sopenharmony_ci SmsReadBuffer smsReadBuff(strBuff); 144e5d0e473Sopenharmony_ci EXPECT_FALSE(codec->CheckVoicemail(smsReadBuff, &setType, &indType)); 145e5d0e473Sopenharmony_ci} 146e5d0e473Sopenharmony_ci 147e5d0e473Sopenharmony_ci/** 148e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsGsmTest_007 149e5d0e473Sopenharmony_ci * @tc.name SmsGsmTest_007 150e5d0e473Sopenharmony_ci * @tc.desc Function test 151e5d0e473Sopenharmony_ci */ 152e5d0e473Sopenharmony_ciHWTEST_F(SmsGsmTest, SmsGsmTest_007, Function | MediumTest | Level1) 153e5d0e473Sopenharmony_ci{ 154e5d0e473Sopenharmony_ci std::shared_ptr<GsmSmsParamCodec> codec = std::make_shared<GsmSmsParamCodec>(); 155e5d0e473Sopenharmony_ci 156e5d0e473Sopenharmony_ci string strBuff; 157e5d0e473Sopenharmony_ci int32_t setType = 0; 158e5d0e473Sopenharmony_ci int32_t indType = 0; 159e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_04; 160e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_D0; 161e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_11; 162e5d0e473Sopenharmony_ci SmsReadBuffer smsReadBuff(strBuff); 163e5d0e473Sopenharmony_ci EXPECT_FALSE(codec->CheckVoicemail(smsReadBuff, &setType, &indType)); 164e5d0e473Sopenharmony_ci} 165e5d0e473Sopenharmony_ci 166e5d0e473Sopenharmony_ci/** 167e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsGsmTest_008 168e5d0e473Sopenharmony_ci * @tc.name SmsGsmTest_008 169e5d0e473Sopenharmony_ci * @tc.desc Function test 170e5d0e473Sopenharmony_ci */ 171e5d0e473Sopenharmony_ciHWTEST_F(SmsGsmTest, SmsGsmTest_008, Function | MediumTest | Level1) 172e5d0e473Sopenharmony_ci{ 173e5d0e473Sopenharmony_ci std::shared_ptr<GsmSmsParamCodec> codec = std::make_shared<GsmSmsParamCodec>(); 174e5d0e473Sopenharmony_ci 175e5d0e473Sopenharmony_ci string strBuff; 176e5d0e473Sopenharmony_ci int32_t setType = 0; 177e5d0e473Sopenharmony_ci int32_t indType = 0; 178e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_04; 179e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_D0; 180e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_10; 181e5d0e473Sopenharmony_ci strBuff += HEX_VALUE_10; 182e5d0e473Sopenharmony_ci SmsReadBuffer smsReadBuff(strBuff); 183e5d0e473Sopenharmony_ci EXPECT_TRUE(codec->CheckVoicemail(smsReadBuff, &setType, &indType)); 184e5d0e473Sopenharmony_ci} 185e5d0e473Sopenharmony_ci 186e5d0e473Sopenharmony_ci/** 187e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsGsmTest_009 188e5d0e473Sopenharmony_ci * @tc.name SmsGsmTest_009 189e5d0e473Sopenharmony_ci * @tc.desc Function test 190e5d0e473Sopenharmony_ci */ 191e5d0e473Sopenharmony_ciHWTEST_F(SmsGsmTest, SmsGsmTest_009, Function | MediumTest | Level1) 192e5d0e473Sopenharmony_ci{ 193e5d0e473Sopenharmony_ci std::shared_ptr<GsmSmsCommonUtils> utils = std::make_shared<GsmSmsCommonUtils>(); 194e5d0e473Sopenharmony_ci SmsWriteBuffer buffer; 195e5d0e473Sopenharmony_ci EXPECT_FALSE(utils->Pack7bitChar(buffer, nullptr, 0, 0)); 196e5d0e473Sopenharmony_ci} 197e5d0e473Sopenharmony_ci 198e5d0e473Sopenharmony_ci/** 199e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsGsmTest_010 200e5d0e473Sopenharmony_ci * @tc.name SmsGsmTest_010 201e5d0e473Sopenharmony_ci * @tc.desc Function test 202e5d0e473Sopenharmony_ci */ 203e5d0e473Sopenharmony_ciHWTEST_F(SmsGsmTest, SmsGsmTest_010, Function | MediumTest | Level1) 204e5d0e473Sopenharmony_ci{ 205e5d0e473Sopenharmony_ci std::shared_ptr<GsmSmsCommonUtils> utils = std::make_shared<GsmSmsCommonUtils>(); 206e5d0e473Sopenharmony_ci std::vector<uint8_t> vectData; 207e5d0e473Sopenharmony_ci uint8_t fillBits = 1; 208e5d0e473Sopenharmony_ci 209e5d0e473Sopenharmony_ci SmsWriteBuffer buffer; 210e5d0e473Sopenharmony_ci EXPECT_FALSE(utils->Pack7bitChar(buffer, static_cast<const uint8_t*>(&vectData[0]), 0, fillBits)); 211e5d0e473Sopenharmony_ci} 212e5d0e473Sopenharmony_ci 213e5d0e473Sopenharmony_ci/** 214e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsGsmTest_011 215e5d0e473Sopenharmony_ci * @tc.name SmsGsmTest_011 216e5d0e473Sopenharmony_ci * @tc.desc Function test 217e5d0e473Sopenharmony_ci */ 218e5d0e473Sopenharmony_ciHWTEST_F(SmsGsmTest, SmsGsmTest_011, Function | MediumTest | Level1) 219e5d0e473Sopenharmony_ci{ 220e5d0e473Sopenharmony_ci std::shared_ptr<GsmSmsCommonUtils> utils = std::make_shared<GsmSmsCommonUtils>(); 221e5d0e473Sopenharmony_ci std::vector<uint8_t> vectData; 222e5d0e473Sopenharmony_ci uint8_t fillBits = 1; 223e5d0e473Sopenharmony_ci vectData.push_back(1); 224e5d0e473Sopenharmony_ci vectData.push_back(2); 225e5d0e473Sopenharmony_ci vectData.push_back(3); 226e5d0e473Sopenharmony_ci vectData.push_back(4); 227e5d0e473Sopenharmony_ci SmsWriteBuffer buffer; 228e5d0e473Sopenharmony_ci EXPECT_TRUE(utils->Pack7bitChar(buffer, static_cast<const uint8_t*>(&vectData[0]), vectData.size(), fillBits)); 229e5d0e473Sopenharmony_ci 230e5d0e473Sopenharmony_ci vectData.clear(); 231e5d0e473Sopenharmony_ci vectData.assign(MAX_GSM_7BIT_DATA_LEN + 1, 1); // first branch 232e5d0e473Sopenharmony_ci EXPECT_FALSE(utils->Pack7bitChar(buffer, static_cast<const uint8_t*>(&vectData[0]), vectData.size(), fillBits)); 233e5d0e473Sopenharmony_ci vectData.clear(); 234e5d0e473Sopenharmony_ci EXPECT_TRUE(utils->Pack7bitChar(buffer, static_cast<const uint8_t*>(&vectData[0]), vectData.size(), fillBits)); 235e5d0e473Sopenharmony_ci} 236e5d0e473Sopenharmony_ci 237e5d0e473Sopenharmony_ci/** 238e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsGsmTest_012 239e5d0e473Sopenharmony_ci * @tc.name SmsGsmTest_012 240e5d0e473Sopenharmony_ci * @tc.desc Function test 241e5d0e473Sopenharmony_ci */ 242e5d0e473Sopenharmony_ciHWTEST_F(SmsGsmTest, SmsGsmTest_012, Function | MediumTest | Level1) 243e5d0e473Sopenharmony_ci{ 244e5d0e473Sopenharmony_ci std::shared_ptr<GsmSmsCommonUtils> utils = std::make_shared<GsmSmsCommonUtils>(); 245e5d0e473Sopenharmony_ci std::string strBuffer; 246e5d0e473Sopenharmony_ci uint8_t fillBits = 0; 247e5d0e473Sopenharmony_ci uint8_t dstIdx = 0; 248e5d0e473Sopenharmony_ci 249e5d0e473Sopenharmony_ci SmsReadBuffer buffer(strBuffer); 250e5d0e473Sopenharmony_ci EXPECT_FALSE(utils->Unpack7bitChar(buffer, strBuffer.size(), fillBits, nullptr, 0, dstIdx)); 251e5d0e473Sopenharmony_ci fillBits = 8; 252e5d0e473Sopenharmony_ci EXPECT_FALSE(utils->Unpack7bitChar(buffer, strBuffer.size(), fillBits, nullptr, 0, dstIdx)); 253e5d0e473Sopenharmony_ci} 254e5d0e473Sopenharmony_ci 255e5d0e473Sopenharmony_ci/** 256e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsGsmTest_013 257e5d0e473Sopenharmony_ci * @tc.name SmsGsmTest_013 258e5d0e473Sopenharmony_ci * @tc.desc Function test 259e5d0e473Sopenharmony_ci */ 260e5d0e473Sopenharmony_ciHWTEST_F(SmsGsmTest, SmsGsmTest_013, Function | MediumTest | Level1) 261e5d0e473Sopenharmony_ci{ 262e5d0e473Sopenharmony_ci std::shared_ptr<GsmSmsCommonUtils> utils = std::make_shared<GsmSmsCommonUtils>(); 263e5d0e473Sopenharmony_ci std::string strBuffer; 264e5d0e473Sopenharmony_ci std::vector<uint8_t> vectData; 265e5d0e473Sopenharmony_ci uint8_t fillBits = 1; 266e5d0e473Sopenharmony_ci uint8_t dstIdx = 0; 267e5d0e473Sopenharmony_ci 268e5d0e473Sopenharmony_ci SmsReadBuffer buffer(strBuffer); 269e5d0e473Sopenharmony_ci EXPECT_FALSE(utils->Unpack7bitChar(buffer, strBuffer.size(), fillBits, 270e5d0e473Sopenharmony_ci static_cast<uint8_t*>(&vectData[0]), vectData.size(), dstIdx)); 271e5d0e473Sopenharmony_ci} 272e5d0e473Sopenharmony_ci 273e5d0e473Sopenharmony_ci/** 274e5d0e473Sopenharmony_ci * @tc.number Telephony_SmsMmsGtest_SmsGsmTest_014 275e5d0e473Sopenharmony_ci * @tc.name SmsGsmTest_014 276e5d0e473Sopenharmony_ci * @tc.desc Function test Unpack7bitCharForMiddlePart 277e5d0e473Sopenharmony_ci */ 278e5d0e473Sopenharmony_ciHWTEST_F(SmsGsmTest, SmsGsmTest_014, Function | MediumTest | Level1) 279e5d0e473Sopenharmony_ci{ 280e5d0e473Sopenharmony_ci std::shared_ptr<GsmSmsCommonUtils> utils = std::make_shared<GsmSmsCommonUtils>(); 281e5d0e473Sopenharmony_ci std::string dataStr("1141515"); 282e5d0e473Sopenharmony_ci std::vector<uint8_t> vectData; 283e5d0e473Sopenharmony_ci 284e5d0e473Sopenharmony_ci const uint8_t *buffer = reinterpret_cast<const uint8_t *>(dataStr.c_str()); 285e5d0e473Sopenharmony_ci EXPECT_FALSE(utils->Unpack7bitCharForMiddlePart(nullptr, 0, static_cast<uint8_t*>(&vectData[0]))); 286e5d0e473Sopenharmony_ci EXPECT_FALSE(utils->Unpack7bitCharForMiddlePart(buffer, dataStr.size(), nullptr)); 287e5d0e473Sopenharmony_ci EXPECT_FALSE(utils->Unpack7bitCharForMiddlePart(buffer, 0, static_cast<uint8_t*>(&vectData[0]))); 288e5d0e473Sopenharmony_ci} 289e5d0e473Sopenharmony_ci} 290e5d0e473Sopenharmony_ci}