1 /*
2 * Copyright (C) 2023-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #define private public
17 #define protected public
18
19 #include "cdma_sms_transport_message.h"
20 #include "core_manager_inner.h"
21 #include "core_service_client.h"
22 #include "gtest/gtest.h"
23 #include "i_sms_service_interface.h"
24 #include "if_system_ability_manager.h"
25 #include "iservice_registry.h"
26 #include "mms_address.h"
27 #include "mms_apn_info.h"
28 #include "mms_attachment.h"
29 #include "mms_base64.h"
30 #include "mms_body.h"
31 #include "mms_body_part.h"
32 #include "mms_body_part_header.h"
33 #include "mms_charset.h"
34 #include "mms_codec_type.h"
35 #include "mms_decode_buffer.h"
36 #include "mms_header.h"
37 #include "mms_msg.h"
38 #include "mms_persist_helper.h"
39 #include "mms_quoted_printable.h"
40 #include "pdp_profile_data.h"
41 #include "radio_event.h"
42 #include "sms_broadcast_subscriber_gtest.h"
43 #include "sms_mms_gtest.h"
44 #include "sms_mms_test_helper.h"
45 #include "sms_service.h"
46 #include "sms_service_manager_client.h"
47 #include "string_utils.h"
48 #include "telephony_log_wrapper.h"
49 #include "telephony_types.h"
50 #include "uri.h"
51
52 namespace OHOS {
53 namespace Telephony {
54 namespace {
55 sptr<ISmsServiceInterface> g_telephonyService = nullptr;
56 } // namespace
57 using namespace testing::ext;
58
59 class MmsGtest : public testing::Test {
60 public:
61 static void SetUpTestCase();
62 static void TearDownTestCase();
63 void SetUp();
64 void TearDown();
65 static sptr<ISmsServiceInterface> GetProxy();
HasSimCard(int32_t slotId)66 static bool HasSimCard(int32_t slotId)
67 {
68 bool hasSimCard = false;
69 if (CoreServiceClient::GetInstance().GetProxy() == nullptr) {
70 return hasSimCard;
71 }
72 CoreServiceClient::GetInstance().HasSimCard(slotId, hasSimCard);
73 return hasSimCard;
74 }
75 };
76
TearDownTestCase()77 void MmsGtest::TearDownTestCase() {}
78
SetUp()79 void MmsGtest::SetUp() {}
80
TearDown()81 void MmsGtest::TearDown() {}
82
83 const int32_t DEFAULT_SIM_SLOT_ID_1 = 1;
84 const uint16_t MESSAGE_TYPE = 4;
85 const uint16_t WAPPUSH_PDU_LEN = 164;
86 const uint32_t MAX_MMS_ATTACHMENT_LEN = 10 * 1024 * 1024;
87 const char PDU_TEST_DATA = 35;
88 const char MIN_SHORT_OCTET = 30;
89 const char QUOTE_CHAR_LEN = 0X7F - 1;
90 const char VALUE_CHAR = 8;
91 const char PDU_COUNT = 10;
92 const char PDU_CUSITION = 5;
93 const char PDU_LENGTH = 4;
94 const char *ENCODE_CHARSET = "01010101";
95 const uint32_t ENCODE_CHARSET1 = 0x0100;
96 const uint32_t ENCODE_CHARSET2 = 0x0001;
97 const uint32_t MMS_PDU_MAX_SIZE = 300 * 1024;
98 static constexpr const char *PDU = "pdu";
99 static constexpr uint32_t MAX_PDU_PAGES = 4;
100 static constexpr uint8_t HEX_VALUE_0F = 0x0F;
101 static constexpr uint8_t HEX_VALUE_F0 = 0xF0;
102 static constexpr uint32_t SPLIT_PDU_LENGTH = 195 * 1024;
103 static constexpr const char *PDU_CONTENT = "pdu_content";
104 const std::string PDP_PROFILE_NET_URI = "datashare:///com.ohos.pdpprofileability/net/pdp_profile?simId=";
105 const std::string MMS_APN_TYPE = "mms";
106 const std::string ALL_APN_TYPE = "*";
107 const std::string MMS_FILE_ADDRESS = "/data/app/test.mms";
108 const std::string SMS_PROFILE_MMS_PDU_URI = "datashare:///com.ohos.smsmmsability/sms_mms/mms_pdu";
109
SetUpTestCase()110 void MmsGtest::SetUpTestCase()
111 {
112 TELEPHONY_LOGI("SetUpTestCase slotId%{public}d", DEFAULT_SIM_SLOT_ID_1);
113 g_telephonyService = GetProxy();
114 if (g_telephonyService == nullptr) {
115 return;
116 }
117 Singleton<SmsServiceManagerClient>::GetInstance().ResetSmsServiceProxy();
118 Singleton<SmsServiceManagerClient>::GetInstance().InitSmsServiceProxy();
119 }
120
GetProxy()121 sptr<ISmsServiceInterface> MmsGtest::GetProxy()
122 {
123 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
124 if (systemAbilityMgr == nullptr) {
125 return nullptr;
126 }
127 sptr<IRemoteObject> remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_SMS_MMS_SYS_ABILITY_ID);
128 if (remote) {
129 sptr<ISmsServiceInterface> smsService = iface_cast<ISmsServiceInterface>(remote);
130 return smsService;
131 }
132 return nullptr;
133 }
134
135 #ifndef TEL_TEST_UNSUPPORT
ReceiveWapPushTestFunc(SmsMmsTestHelper &helper)136 void ReceiveWapPushTestFunc(SmsMmsTestHelper &helper)
137 {
138 AccessMmsToken token;
139 auto smsReceiveHandler = std::make_shared<GsmSmsReceiveHandler>(helper.slotId);
140 auto message = std::make_shared<SmsMessageInfo>();
141 message->indicationType = MESSAGE_TYPE;
142 message->size = WAPPUSH_PDU_LEN;
143 message->pdu = StringUtils::HexToByteVector(
144 "0891683110205005F0640BA10156455102F1000432109261715023880605040B8423F04C06246170706C69636174696F6E2F766E642E77"
145 "61702E6D6D732D6D65737361676500B487AF848C829850765030303031365A645430008D9089178031363630373532313930382F545950"
146 "453D504C4D4E008A808E040001298D"
147 "8805810303F47B83687474703A2F2F31302E3132332E31382E38303A3138302F76564F455F3000");
148
149 AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GSM_SMS, message);
150 smsReceiveHandler->ProcessEvent(event);
151 }
152
GetSendReqDataTest(MmsMsg &encodeMsg, std::string number)153 void GetSendReqDataTest(MmsMsg &encodeMsg, std::string number)
154 {
155 if (!encodeMsg.SetMmsMessageType(MMS_MSGTYPE_SEND_REQ)) {
156 TELEPHONY_LOGE("SetMmsMessageType fail");
157 }
158 if (!encodeMsg.SetMmsTransactionId("2077.1427358451410")) {
159 TELEPHONY_LOGE("SetMmsTransactionId fail");
160 }
161 if (!encodeMsg.SetMmsVersion(static_cast<uint16_t>(MmsVersionType::MMS_VERSION_1_2))) {
162 TELEPHONY_LOGE("SetMmsVersion fail");
163 }
164 MmsAddress address;
165 address.SetMmsAddressString(number);
166 if (!encodeMsg.SetMmsFrom(address)) {
167 TELEPHONY_LOGE("SetMmsFrom fail");
168 }
169 if (!encodeMsg.SetHeaderContentType("application/vnd.wap.multipart.related")) {
170 TELEPHONY_LOGE("SetHeaderContentType fail");
171 }
172 if (!encodeMsg.SetMmsSubject("mms")) {
173 TELEPHONY_LOGE("SetMmsSubject fail");
174 }
175 if (!encodeMsg.SetHeaderOctetValue(MMS_CONTENT_CLASS, static_cast<uint8_t>(MmsContentClass::MMS_TEXT))) {
176 TELEPHONY_LOGE("SetHeaderOctetValue MMS_CONTENT_CLASS fail");
177 }
178 }
179
MmsAddAttachment(MmsMsg &msg, std::string pathName, std::string contentId, std::string contenType, bool isSmil)180 bool MmsAddAttachment(MmsMsg &msg, std::string pathName, std::string contentId, std::string contenType, bool isSmil)
181 {
182 MmsAttachment imageAttachment;
183 std::size_t pos = pathName.find_last_of('/');
184 std::string fileName(pathName.substr(pos + 1));
185 if (!imageAttachment.SetAttachmentFilePath(pathName, isSmil)) {
186 TELEPHONY_LOGE("MmsAddAttachment SetAttachmentFilePath fail");
187 return false;
188 }
189 if (!imageAttachment.SetFileName(fileName)) {
190 TELEPHONY_LOGE("MmsAddAttachment SetFileName fail");
191 return false;
192 }
193 if (!imageAttachment.SetContentId(contentId)) {
194 TELEPHONY_LOGE("MmsAddAttachment SetContentId fail");
195 return false;
196 }
197 if (!imageAttachment.SetContentLocation(fileName)) {
198 TELEPHONY_LOGE("MmsAddAttachment SetContentLocation fail");
199 return false;
200 }
201 if (!imageAttachment.SetContentType(contenType)) {
202 TELEPHONY_LOGE("MmsAddAttachment SetContentType fail");
203 return false;
204 }
205 imageAttachment.SetContentDisposition("attachment");
206 if (!msg.AddAttachment(imageAttachment)) {
207 TELEPHONY_LOGE("MmsAddAttachment AddAttachment fail");
208 return false;
209 }
210 return true;
211 }
212
WriteBufferToFile(const std::unique_ptr<char[]> &buff, uint32_t len, const std::string &strPathName)213 bool WriteBufferToFile(const std::unique_ptr<char[]> &buff, uint32_t len, const std::string &strPathName)
214 {
215 FILE *pFile = nullptr;
216 pFile = fopen(strPathName.c_str(), "wb");
217 if (!pFile || buff == nullptr) {
218 return false;
219 }
220 uint32_t fileLen = fwrite(buff.get(), len, 1, pFile);
221 if (fileLen > 0) {
222 TELEPHONY_LOGD("write mms buffer to file success");
223 } else {
224 TELEPHONY_LOGE("write mms buffer to file error");
225 }
226 (void)fclose(pFile);
227 return true;
228 }
229
GetMmsPduFromFile(const std::string &fileName, std::string &mmsPdu)230 bool GetMmsPduFromFile(const std::string &fileName, std::string &mmsPdu)
231 {
232 char realPath[PATH_MAX] = { 0 };
233 if (fileName.empty() || realpath(fileName.c_str(), realPath) == nullptr) {
234 TELEPHONY_LOGE("path or realPath is nullptr");
235 return false;
236 }
237 FILE *pFile = fopen(realPath, "rb");
238 if (pFile == nullptr) {
239 TELEPHONY_LOGE("openFile Error");
240 return false;
241 }
242 (void)fseek(pFile, 0, SEEK_END);
243 long fileLen = ftell(pFile);
244 if (fileLen <= 0 || fileLen > static_cast<long>(MMS_PDU_MAX_SIZE)) {
245 (void)fclose(pFile);
246 TELEPHONY_LOGE("fileLen Over Max Error");
247 return false;
248 }
249 std::unique_ptr<char[]> pduBuffer = std::make_unique<char[]>(fileLen);
250 if (!pduBuffer) {
251 (void)fclose(pFile);
252 TELEPHONY_LOGE("make unique pduBuffer nullptr Error");
253 return false;
254 }
255 (void)fseek(pFile, 0, SEEK_SET);
256 int32_t totolLength = static_cast<int32_t>(fread(pduBuffer.get(), 1, MMS_PDU_MAX_SIZE, pFile));
257 TELEPHONY_LOGI("fread totolLength%{public}d", totolLength);
258 long i = 0;
259 while (i < fileLen) {
260 mmsPdu += pduBuffer[i];
261 i++;
262 }
263 (void)fclose(pFile);
264 return true;
265 }
266
SplitPdu(const std::string &mmsPdu)267 std::vector<std::string> SplitPdu(const std::string &mmsPdu)
268 {
269 std::vector<std::string> mmsPdus;
270 if (mmsPdu.compare(PDU) == 0) {
271 for (uint32_t locate = 0; locate < MAX_PDU_PAGES; locate++) {
272 mmsPdus.push_back(PDU);
273 }
274 return mmsPdus;
275 }
276 std::string targetMmsPdu;
277 for (size_t i = 0; i < mmsPdu.size(); i++) {
278 targetMmsPdu += static_cast<char>((mmsPdu[i] & HEX_VALUE_0F) | HEX_VALUE_F0);
279 targetMmsPdu += static_cast<char>((mmsPdu[i] & HEX_VALUE_F0) | HEX_VALUE_0F);
280 }
281 std::string mmsPduData;
282 for (uint32_t locate = 0; locate * SPLIT_PDU_LENGTH < targetMmsPdu.size(); locate++) {
283 if ((locate + 1) * SPLIT_PDU_LENGTH < targetMmsPdu.size()) {
284 mmsPduData = targetMmsPdu.substr(locate * SPLIT_PDU_LENGTH, SPLIT_PDU_LENGTH);
285 mmsPdus.push_back(mmsPduData);
286 } else {
287 mmsPduData = targetMmsPdu.substr(locate * SPLIT_PDU_LENGTH);
288 mmsPdus.push_back(mmsPduData);
289 break;
290 }
291 }
292 TELEPHONY_LOGI("pduLen:%{public}zu,targetPduLen:%{public}zu", mmsPdu.size(), targetMmsPdu.size());
293 return mmsPdus;
294 }
295
GetPduToFile(int32_t slotId)296 void GetPduToFile(int32_t slotId)
297 {
298 SmsMmsTestHelper smsMmsTestHelper;
299 smsMmsTestHelper.slotId = slotId;
300 std::string dest = "10086";
301 std::u16string simcardNumber;
302 if (!CoreServiceClient::GetInstance().GetSimTelephoneNumber(smsMmsTestHelper.slotId, simcardNumber) &&
303 !simcardNumber.empty()) {
304 dest = StringUtils::ToUtf8(simcardNumber);
305 }
306 MmsMsg encodeMsg;
307 std::vector<MmsAddress> vecAddrs;
308 std::string toAddr = dest + "/TYPE=PLMN";
309 MmsAddress toAddrs(toAddr);
310 GetSendReqDataTest(encodeMsg, toAddr);
311 vecAddrs.push_back(toAddrs);
312 if (!encodeMsg.SetMmsTo(vecAddrs)) {
313 TELEPHONY_LOGE("SetMmsTo fail");
314 }
315 const std::string filePathNameText = "/data/app/mms.text";
316 const char *source = "mms";
317 size_t sourceLen = std::strlen(source);
318 std::unique_ptr<char[]> text = std::make_unique<char[]>(sourceLen + 1);
319 if (snprintf_s(text.get(), sourceLen + 1, sourceLen + 1, "%s", source) < 0) {
320 TELEPHONY_LOGE("snprintf_s failed");
321 return;
322 }
323 if (!WriteBufferToFile(std::move(text), std::strlen(source) + 1, filePathNameText)) {
324 TELEPHONY_LOGE("file error.");
325 }
326 if (!MmsAddAttachment(encodeMsg, filePathNameText, "<content.text>", "text/plain", false)) {
327 TELEPHONY_LOGE("MmsAddAttachment text fail");
328 }
329 uint32_t len = 0;
330 std::unique_ptr<char[]> results = encodeMsg.EncodeMsg(len);
331 if (results == nullptr) {
332 TELEPHONY_LOGE("encode fail result nullptr !!!!");
333 }
334 if (!WriteBufferToFile(std::move(results), len, MMS_FILE_ADDRESS)) {
335 TELEPHONY_LOGE("Encode write to file error.");
336 }
337 }
338
GetFileToDb()339 std::string GetFileToDb()
340 {
341 std::string mmsPdu;
342 GetMmsPduFromFile(MMS_FILE_ADDRESS, mmsPdu);
343 Uri uri(SMS_PROFILE_MMS_PDU_URI);
344 std::shared_ptr<MmsPersistHelper> mmsPersistHelper = std::make_shared<MmsPersistHelper>();
345 if (mmsPersistHelper == nullptr) {
346 return "";
347 }
348 std::shared_ptr<DataShare::DataShareHelper> helper = mmsPersistHelper->CreateSmsHelper();
349 if (helper == nullptr) {
350 return "";
351 }
352 std::vector<std::string> mmsPdus = SplitPdu(mmsPdu);
353 std::string dbUrl;
354 for (std::string mmsPdu : mmsPdus) {
355 DataShare::DataShareValuesBucket bucket;
356 bucket.Put(PDU_CONTENT, mmsPdu);
357 int32_t result = helper->Insert(uri, bucket);
358 if (result < 0) {
359 TELEPHONY_LOGE("mms pdu insert fail");
360 }
361 dbUrl += std::to_string(result) + ',';
362 }
363 helper->Release();
364 return dbUrl;
365 }
366
GetMmsc(int32_t slotId)367 std::string GetMmsc(int32_t slotId)
368 {
369 int32_t simId = CoreManagerInner::GetInstance().GetSimId(slotId);
370 Uri pdpUri(PDP_PROFILE_NET_URI + std::to_string(simId));
371 std::vector<std::string> colume;
372 DataShare::DataSharePredicates predicates;
373 std::u16string operatorNumeric;
374 CoreServiceClient::GetInstance().GetSimOperatorNumeric(slotId, operatorNumeric);
375 std::string mccmnc = StringUtils::ToUtf8(operatorNumeric);
376 predicates.EqualTo(PdpProfileData::MCCMNC, mccmnc);
377 std::shared_ptr<MmsApnInfo> mmsApnInfo = std::make_shared<MmsApnInfo>(slotId);
378 auto pdpHelper = mmsApnInfo->CreatePdpProfileHelper();
379 if (pdpHelper == nullptr) {
380 return "";
381 }
382 auto resultSet = pdpHelper->Query(pdpUri, predicates, colume);
383 if (resultSet == nullptr) {
384 pdpHelper->Release();
385 return "";
386 }
387 int count;
388 resultSet->GetRowCount(count);
389 if (count <= 0) {
390 resultSet->Close();
391 pdpHelper->Release();
392 return "";
393 }
394 std::string homeUrlVal;
395 std::string mmsIPAddressVal;
396 if (!mmsApnInfo->GetMmsApnValue(resultSet, count, homeUrlVal, mmsIPAddressVal)) {
397 TELEPHONY_LOGI("homeUrlVal and mmsIPAddressVal not matched");
398 resultSet->Close();
399 pdpHelper->Release();
400 return "";
401 }
402 resultSet->Close();
403 pdpHelper->Release();
404 return homeUrlVal;
405 }
406
407 /**
408 * @tc.number Telephony_SmsMmsGtest_Receive_Wap_Push_0001
409 * @tc.name Receive a Wap Push
410 * @tc.desc Function test
411 */
HWTEST_F(MmsGtest, Receive_Wap_Push_0001, Function | MediumTest | Level2)412 HWTEST_F(MmsGtest, Receive_Wap_Push_0001, Function | MediumTest | Level2)
413 {
414 TELEPHONY_LOGI("TelSMSMMSTest::Receive_Wap_Push_0001 -->");
415 int32_t slotId = DEFAULT_SIM_SLOT_ID;
416 if (!(MmsGtest::HasSimCard(slotId))) {
417 TELEPHONY_LOGI("TelephonyTestService has no sim card");
418 ASSERT_FALSE(MmsGtest::HasSimCard(slotId));
419 return;
420 }
421 SmsMmsTestHelper helper;
422 helper.slotId = slotId;
423
424 EventFwk::MatchingSkills matchingSkills;
425 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SMS_WAPPUSH_RECEIVE_COMPLETED);
426 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
427 std::shared_ptr<SmsBroadcastSubscriberGtest> subscriberTest =
428 std::make_shared<SmsBroadcastSubscriberGtest>(subscriberInfo, helper);
429 ASSERT_NE(subscriberTest, nullptr);
430 bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberTest);
431 TELEPHONY_LOGI("subscribeResult is : %{public}d", subscribeResult);
432
433 if (!helper.Run(ReceiveWapPushTestFunc, helper)) {
434 TELEPHONY_LOGI("ReceiveWapPushTestFunc out of time");
435 ASSERT_TRUE(helper.Run(ReceiveWapPushTestFunc, helper));
436 return;
437 }
438 TELEPHONY_LOGI("TelSMSMMSTest::Receive_Wap_Push_0001 -->finished");
439 EXPECT_TRUE(helper.GetBoolResult());
440 }
441
442 /**
443 * @tc.number Telephony_SmsMmsGtest_Receive_Wap_Push_0002
444 * @tc.name Receive a Wap Push
445 * @tc.desc Function test
446 */
HWTEST_F(MmsGtest, Receive_Wap_Push_0002, Function | MediumTest | Level2)447 HWTEST_F(MmsGtest, Receive_Wap_Push_0002, Function | MediumTest | Level2)
448 {
449 TELEPHONY_LOGI("TelSMSMMSTest::Receive_Wap_Push_0002 -->");
450 int32_t slotId = DEFAULT_SIM_SLOT_ID_1;
451 if (!(MmsGtest::HasSimCard(slotId))) {
452 TELEPHONY_LOGI("TelephonyTestService has no sim card");
453 ASSERT_FALSE(MmsGtest::HasSimCard(slotId));
454 return;
455 }
456 SmsMmsTestHelper helper;
457 helper.slotId = slotId;
458
459 EventFwk::MatchingSkills matchingSkills;
460 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SMS_WAPPUSH_RECEIVE_COMPLETED);
461 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
462 std::shared_ptr<SmsBroadcastSubscriberGtest> subscriberTest =
463 std::make_shared<SmsBroadcastSubscriberGtest>(subscriberInfo, helper);
464 ASSERT_NE(subscriberTest, nullptr);
465 bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberTest);
466 TELEPHONY_LOGI("subscribeResult is : %{public}d", subscribeResult);
467
468 if (!helper.Run(ReceiveWapPushTestFunc, helper)) {
469 TELEPHONY_LOGI("ReceiveWapPushTestFunc out of time");
470 ASSERT_FALSE(helper.Run(ReceiveWapPushTestFunc, helper));
471 return;
472 }
473 TELEPHONY_LOGI("TelSMSMMSTest::Receive_Wap_Push_0002 -->finished");
474 EXPECT_TRUE(helper.GetBoolResult());
475 }
476
477 /**
478 * @tc.number Telephony_SmsMmsGtest_MmsAddress_0001
479 * @tc.name Test MmsAddress
480 * @tc.desc Function test
481 */
HWTEST_F(MmsGtest, MmsAddress_0001, Function | MediumTest | Level1)482 HWTEST_F(MmsGtest, MmsAddress_0001, Function | MediumTest | Level1)
483 {
484 TELEPHONY_LOGI("TelSMSMMSTest::MmsAddress_0001 -->");
485 MmsAddress address;
486 address.SetMmsAddressString("12345678/TYPE=PLMN");
487 address.SetMmsAddressString("12345678/TYPE=IPv4");
488 address.SetMmsAddressString("12345678/TYPE=IPv6");
489 address.SetMmsAddressString("12345678/TYPE=UNKNOWN");
490 address.SetMmsAddressString("12345678/TYPE=EMAIL");
491 std::string ret = address.GetAddressString();
492 EXPECT_STREQ(ret.c_str(), "12345678/TYPE=EMAIL");
493 MmsAddress::MmsAddressType type = address.GetAddressType();
494 EXPECT_EQ(type, MmsAddress::MmsAddressType::ADDRESS_TYPE_PLMN);
495 MmsCharSets charset = address.GetAddressCharset();
496 EXPECT_EQ(charset, MmsCharSets::UTF_8);
497 }
498
499 /**
500 * @tc.number Telephony_SmsMmsGtest_MmsAttachment_0001
501 * @tc.name Test MmsAttachment
502 * @tc.desc Function test
503 */
HWTEST_F(MmsGtest, MmsAttachment_0001, Function | MediumTest | Level1)504 HWTEST_F(MmsGtest, MmsAttachment_0001, Function | MediumTest | Level1)
505 {
506 TELEPHONY_LOGI("TelSMSMMSTest::MmsAttachment_0001 -->");
507 const std::string pathName = "/data/app/enSrc/618C0A89.smil";
508 std::size_t pos = pathName.find_last_of('/');
509 std::string fileName(pathName.substr(pos + 1));
510 MmsAttachment attachment;
511 bool retBool;
512 std::string retStr;
513 retBool = attachment.SetAttachmentFilePath("", false);
514 EXPECT_EQ(false, retBool);
515 retBool = attachment.SetAttachmentFilePath(pathName, true);
516 EXPECT_EQ(true, retBool);
517 retStr = attachment.GetAttachmentFilePath();
518 EXPECT_STREQ(retStr.c_str(), pathName.c_str());
519 retBool = attachment.SetContentId("");
520 EXPECT_EQ(false, retBool);
521 retBool = attachment.SetContentId("0000");
522 EXPECT_EQ(true, retBool);
523 retBool = attachment.SetContentId("<0000>");
524 EXPECT_EQ(true, retBool);
525 retStr = attachment.GetContentId();
526 EXPECT_STREQ(retStr.c_str(), "<0000>");
527 retBool = attachment.SetContentLocation("");
528 EXPECT_EQ(false, retBool);
529 retBool = attachment.SetContentLocation("SetContentLocation");
530 EXPECT_EQ(true, retBool);
531 retStr = attachment.GetContentLocation();
532 EXPECT_STREQ(retStr.c_str(), "SetContentLocation");
533 retBool = attachment.SetContentDisposition("");
534 EXPECT_EQ(false, retBool);
535 retBool = attachment.SetContentDisposition("attachment");
536 EXPECT_EQ(true, retBool);
537 retStr = attachment.GetContentDisposition();
538 EXPECT_STREQ(retStr.c_str(), "attachment");
539 retBool = attachment.SetContentTransferEncoding("");
540 EXPECT_EQ(false, retBool);
541 retBool = attachment.SetFileName(fileName);
542 EXPECT_EQ(true, retBool);
543 retStr = attachment.GetFileName();
544 EXPECT_STREQ(retStr.c_str(), fileName.c_str());
545 attachment.strFileName_ = "";
546 retStr = attachment.GetFileName();
547 EXPECT_STRNE(retStr.c_str(), fileName.c_str());
548 }
549
550 /**
551 * @tc.number Telephony_SmsMmsGtest_MmsAttachment_0002
552 * @tc.name Test MmsAttachment
553 * @tc.desc Function test
554 */
HWTEST_F(MmsGtest, MmsAttachment_0002, Function | MediumTest | Level1)555 HWTEST_F(MmsGtest, MmsAttachment_0002, Function | MediumTest | Level1)
556 {
557 TELEPHONY_LOGI("TelSMSMMSTest::MmsAttachment_0002 -->");
558 MmsAttachment attachment;
559 bool retBool;
560 std::string retStr;
561 uint32_t retU32t;
562 uint32_t len = 10 * 1024 * 1024;
563 uint32_t charset = 0;
564 retBool = attachment.SetContentTransferEncoding("SetContentTransferEncoding");
565 EXPECT_EQ(true, retBool);
566 retStr = attachment.GetContentTransferEncoding();
567 EXPECT_STREQ(retStr.c_str(), "SetContentTransferEncoding");
568 retBool = attachment.SetContentType("");
569 EXPECT_EQ(false, retBool);
570 attachment.SetIsSmilFile(true);
571 retBool = attachment.IsSmilFile();
572 EXPECT_EQ(true, retBool);
573 attachment.SetCharSet(charset);
574 retU32t = attachment.GetCharSet();
575 EXPECT_EQ(charset, retU32t);
576 retBool = attachment.SetDataBuffer(nullptr, 0);
577 retBool = attachment.SetDataBuffer(nullptr, MAX_MMS_ATTACHMENT_LEN + 1);
578 EXPECT_EQ(false, retBool);
579 retBool = attachment.SetDataBuffer(std::make_unique<char[]>(len + 1), len + 1);
580 EXPECT_EQ(false, retBool);
581 retBool = attachment.SetDataBuffer(std::make_unique<char[]>(len - 1), len - 1);
582 EXPECT_EQ(true, retBool);
583 retBool = attachment.SetDataBuffer(std::make_unique<char[]>(len - 1), len + 1);
584 EXPECT_EQ(false, retBool);
585 EXPECT_FALSE(attachment.GetDataBuffer(len) == nullptr);
586 attachment.dataLength_ = MAX_MMS_ATTACHMENT_LEN + 1;
587 EXPECT_TRUE(attachment.GetDataBuffer(len) == nullptr);
588 MmsAttachment attachment1(attachment);
589 attachment1.SetContentType("application/smil");
590 retStr = attachment1.GetContentType();
591 EXPECT_STREQ(retStr.c_str(), "application/smil");
592 }
593
594 /**
595 * @tc.number Telephony_SmsMmsGtest_MmsBodyPartHeader_0001
596 * @tc.name Test MmsBodyPartHeader
597 * @tc.desc Function test
598 */
HWTEST_F(MmsGtest, MmsBodyPartHeader_0001, Function | MediumTest | Level1)599 HWTEST_F(MmsGtest, MmsBodyPartHeader_0001, Function | MediumTest | Level1)
600 {
601 TELEPHONY_LOGI("TelSMSMMSTest::MmsBodyPartHeader_0001 -->");
602 MmsBodyPartHeader mmsBodyPartHeader;
603 MmsDecodeBuffer decodeBuffer;
604 std::string testStr;
605 uint32_t len = 0;
606 uint32_t lenErr = -1;
607 uint32_t lenMax = 300 * 1024;
608 mmsBodyPartHeader.DumpBodyPartHeader();
609 mmsBodyPartHeader.DecodeContentLocation(decodeBuffer, len);
610 mmsBodyPartHeader.DecodeContentId(decodeBuffer, len);
611 mmsBodyPartHeader.DecodeContentDisposition(decodeBuffer, len);
612 mmsBodyPartHeader.DecodeDispositionParameter(decodeBuffer, lenMax, len);
613 mmsBodyPartHeader.DecodeDispositionParameter(decodeBuffer, lenErr, len);
614 mmsBodyPartHeader.DecodeWellKnownHeader(decodeBuffer, len);
615 mmsBodyPartHeader.DecodeApplicationHeader(decodeBuffer, len);
616 mmsBodyPartHeader.SetContentId("contentId");
617 mmsBodyPartHeader.GetContentId(testStr);
618 EXPECT_STREQ(testStr.c_str(), "contentId");
619 mmsBodyPartHeader.SetContentTransferEncoding("contentTransferEncoding");
620 mmsBodyPartHeader.GetContentTransferEncoding(testStr);
621 EXPECT_STREQ(testStr.c_str(), "contentTransferEncoding");
622 mmsBodyPartHeader.SetContentLocation("contentLocation");
623 mmsBodyPartHeader.GetContentLocation(testStr);
624 EXPECT_STREQ(testStr.c_str(), "contentLocation");
625 MmsEncodeBuffer encodeBuffer;
626 mmsBodyPartHeader.EncodeContentLocation(encodeBuffer);
627 mmsBodyPartHeader.EncodeContentId(encodeBuffer);
628 mmsBodyPartHeader.EncodeContentDisposition(encodeBuffer);
629 mmsBodyPartHeader.EncodeContentTransferEncoding(encodeBuffer);
630 mmsBodyPartHeader.EncodeMmsBodyPartHeader(encodeBuffer);
631 MmsBodyPartHeader mmsBodyPartHeader2;
632 MmsBodyPartHeader mmsBodyPartHeader3 = MmsBodyPartHeader(mmsBodyPartHeader);
633 mmsBodyPartHeader2 = mmsBodyPartHeader;
634 mmsBodyPartHeader2.SetContentDisposition("contentDisposition");
635 mmsBodyPartHeader2.GetContentDisposition(testStr);
636 EXPECT_STREQ(testStr.c_str(), "contentDisposition");
637 }
638
639 /**
640 * @tc.number Telephony_SmsMmsGtest_MmsBuffer_0001
641 * @tc.name Test MmsBuffer
642 * @tc.desc Function test
643 */
HWTEST_F(MmsGtest, MmsBuffer_0001, Function | MediumTest | Level1)644 HWTEST_F(MmsGtest, MmsBuffer_0001, Function | MediumTest | Level1)
645 {
646 TELEPHONY_LOGI("TelSMSMMSTest::MmsBuffer_0001 -->");
647 MmsBuffer mmsBuffer;
648 uint32_t len = 10;
649 bool retBool;
650 std::string strPathName = "/data/app/enSrc/618C0A89.smil";
651 mmsBuffer.ReadDataBuffer(len);
652 mmsBuffer.ReadDataBuffer(len, len);
653 retBool = mmsBuffer.WriteDataBuffer(std::make_unique<char[]>(len), 0);
654 EXPECT_EQ(false, retBool);
655 retBool = mmsBuffer.WriteDataBuffer(std::make_unique<char[]>(len), len);
656 EXPECT_EQ(true, retBool);
657 mmsBuffer.WriteBufferFromFile(strPathName);
658 mmsBuffer.GetCurPosition();
659 uint32_t ret = mmsBuffer.GetSize();
660 EXPECT_GE(ret, 0);
661 }
662
663 /**
664 * @tc.number Telephony_SmsMmsGtest_MmsContentParam_0001
665 * @tc.name Test MmsContentParam
666 * @tc.desc Function test
667 */
HWTEST_F(MmsGtest, MmsContentParam_0001, Function | MediumTest | Level1)668 HWTEST_F(MmsGtest, MmsContentParam_0001, Function | MediumTest | Level1)
669 {
670 TELEPHONY_LOGI("TelSMSMMSTest::MmsContentParam_0001 -->");
671 MmsContentParam mmsContentParam;
672 MmsContentParam mmsContentParam2;
673 uint8_t field = 1;
674 uint32_t charset = 10;
675 std::string testStr;
676 uint32_t retU32t;
677 mmsContentParam.DumpContentParam();
678 mmsContentParam.SetCharSet(charset);
679 retU32t = mmsContentParam.GetCharSet();
680 EXPECT_EQ(charset, retU32t);
681 mmsContentParam.SetType("type");
682 testStr = mmsContentParam.GetType();
683 EXPECT_STREQ(testStr.c_str(), "type");
684 mmsContentParam.SetFileName("");
685 mmsContentParam.SetStart("");
686 mmsContentParam.SetStart("start");
687 mmsContentParam.GetStart(testStr);
688 EXPECT_STREQ(testStr.c_str(), "start");
689 mmsContentParam.AddNormalField(field, "value");
690 mmsContentParam.GetNormalField(field, testStr);
691 EXPECT_STREQ(testStr.c_str(), "value");
692 mmsContentParam.GetParamMap();
693 mmsContentParam2 = mmsContentParam;
694 mmsContentParam2.SetFileName("fileName");
695 mmsContentParam2.GetFileName(testStr);
696 EXPECT_STREQ(testStr.c_str(), "fileName");
697
698 mmsContentParam.textMap_.clear();
699 mmsContentParam.AddNormalField(field, "value");
700 mmsContentParam.textMap_.clear();
701 mmsContentParam.GetNormalField(field, testStr);
702 mmsContentParam.GetStart(testStr);
703 mmsContentParam2.GetFileName(testStr);
704 mmsContentParam.DumpContentParam();
705 EXPECT_STREQ(testStr.c_str(), "fileName");
706 }
707
708 /**
709 * @tc.number Telephony_SmsMmsGtest_MmsContentType_0001
710 * @tc.name Test MmsContentType
711 * @tc.desc Function test
712 */
HWTEST_F(MmsGtest, MmsContentType_0001, Function | MediumTest | Level1)713 HWTEST_F(MmsGtest, MmsContentType_0001, Function | MediumTest | Level1)
714 {
715 TELEPHONY_LOGI("TelSMSMMSTest::MmsContentType_0001 -->");
716 MmsContentType mmsContentType;
717 MmsDecodeBuffer decodeBuffer;
718 MmsContentParam contentParam;
719 int32_t len = 10;
720 uint8_t type = 10;
721 std::string testStr;
722 uint8_t count = 10;
723 uint8_t index = 0;
724 while (index < count) {
725 decodeBuffer.pduBuffer_[index] = '1';
726 index++;
727 }
728 mmsContentType.DumpMmsContentType();
729
730 decodeBuffer.curPosition_ = 0;
731 decodeBuffer.pduBuffer_[decodeBuffer.curPosition_++] = PDU_TEST_DATA;
732 decodeBuffer.pduBuffer_[decodeBuffer.curPosition_++] = PDU_TEST_DATA;
733 decodeBuffer.pduBuffer_[decodeBuffer.curPosition_] = PDU_TEST_DATA;
734 mmsContentType.DecodeMmsContentType(decodeBuffer, len);
735
736 decodeBuffer.curPosition_ = 0;
737 mmsContentType.DecodeMmsCTGeneralForm(decodeBuffer, len);
738 mmsContentType.GetContentTypeFromInt(type);
739 mmsContentType.GetContentTypeFromString("");
740
741 decodeBuffer.curPosition_ = 0;
742 mmsContentType.DecodeParameter(decodeBuffer, len);
743 mmsContentType.SetContentParam(contentParam);
744 mmsContentType.DecodeTextField(decodeBuffer, type, len);
745
746 decodeBuffer.curPosition_ = 0;
747 mmsContentType.DecodeCharsetField(decodeBuffer, len);
748 mmsContentType.DecodeTypeField(decodeBuffer, len);
749
750 MmsEncodeBuffer encodeBuffer;
751 mmsContentType.EncodeTextField(encodeBuffer);
752 mmsContentType.EncodeCharsetField(encodeBuffer);
753 mmsContentType.EncodeTypeField(encodeBuffer);
754 mmsContentType.EncodeMmsBodyPartContentParam(encodeBuffer);
755 mmsContentType.EncodeMmsBodyPartContentType(encodeBuffer);
756 mmsContentType.GetContentParam();
757 MmsContentType mmsContentType2(mmsContentType);
758 mmsContentType2 = mmsContentType;
759 mmsContentType2.SetContentType("contentType");
760 mmsContentType2.GetContentType(testStr);
761 EXPECT_STREQ(testStr.c_str(), "contentType");
762 }
763
764 /**
765 * @tc.number Telephony_SmsMmsGtest_MmsDecodeBuffer_0001
766 * @tc.name Test MmsDecodeBuffer
767 * @tc.desc Function test
768 */
HWTEST_F(MmsGtest, MmsDecodeBuffer_0001, Function | MediumTest | Level1)769 HWTEST_F(MmsGtest, MmsDecodeBuffer_0001, Function | MediumTest | Level1)
770 {
771 TELEPHONY_LOGI("TelSMSMMSTest::MmsDecodeBuffer_0001 -->");
772 uint8_t byteVar = 1;
773 uint32_t intVar = PDU_COUNT;
774 std::string testStr;
775 MmsDecodeBuffer mmsDecodeBuffer;
776 uint8_t count = PDU_COUNT;
777 uint8_t index = 0;
778 while (index < count) {
779 mmsDecodeBuffer.pduBuffer_[index] = '1';
780 index++;
781 }
782
783 mmsDecodeBuffer.PeekOneByte(byteVar);
784 mmsDecodeBuffer.GetOneByte(byteVar);
785 mmsDecodeBuffer.IncreasePointer(intVar);
786 mmsDecodeBuffer.DecreasePointer(intVar);
787 mmsDecodeBuffer.curPosition_ = PDU_CUSITION;
788 mmsDecodeBuffer.totolLength_ = PDU_LENGTH;
789 mmsDecodeBuffer.PeekOneByte(byteVar);
790 mmsDecodeBuffer.GetOneByte(byteVar);
791 mmsDecodeBuffer.IncreasePointer(intVar);
792 mmsDecodeBuffer.DecreasePointer(intVar);
793
794 mmsDecodeBuffer.curPosition_ = 0;
795 mmsDecodeBuffer.DecodeUintvar(intVar, intVar);
796 mmsDecodeBuffer.DecodeShortLength(byteVar);
797
798 char testChar = MIN_SHORT_OCTET + 1;
799 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar;
800 mmsDecodeBuffer.DecodeShortLength(byteVar);
801 mmsDecodeBuffer.curPosition_ = 0;
802 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = MIN_SHORT_OCTET;
803 mmsDecodeBuffer.DecodeValueLengthReturnLen(intVar, intVar);
804 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar;
805 mmsDecodeBuffer.DecodeValueLengthReturnLen(intVar, intVar);
806 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar + 1;
807 mmsDecodeBuffer.DecodeValueLengthReturnLen(intVar, intVar);
808
809 uint8_t errVar = -1;
810 bool ret = mmsDecodeBuffer.CharIsToken(errVar);
811 EXPECT_EQ(false, ret);
812 }
813
814 /**
815 * @tc.number Telephony_SmsMmsGtest_MmsDecodeBuffer_0002
816 * @tc.name Test MmsDecodeBuffer
817 * @tc.desc Function test
818 */
HWTEST_F(MmsGtest, MmsDecodeBuffer_0002, Function | MediumTest | Level1)819 HWTEST_F(MmsGtest, MmsDecodeBuffer_0002, Function | MediumTest | Level1)
820 {
821 TELEPHONY_LOGI("TelSMSMMSTest::MmsDecodeBuffer_0002 -->");
822 uint32_t intVar = 10;
823 std::string testStr;
824 MmsDecodeBuffer mmsDecodeBuffer;
825 uint8_t count = 10;
826 uint8_t index = 0;
827 while (index < count) {
828 mmsDecodeBuffer.pduBuffer_[index] = '1';
829 index++;
830 }
831 mmsDecodeBuffer.curPosition_ = 0;
832 char testChar = MIN_SHORT_OCTET + 1;
833 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = MIN_SHORT_OCTET;
834 mmsDecodeBuffer.DecodeValueLength(intVar);
835 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar;
836 mmsDecodeBuffer.DecodeValueLength(intVar);
837 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar + 1;
838 mmsDecodeBuffer.DecodeValueLength(intVar);
839
840 mmsDecodeBuffer.curPosition_ = 0;
841 testChar += 1;
842 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar;
843 mmsDecodeBuffer.DecodeTokenText(testStr, intVar);
844 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar + 1;
845 mmsDecodeBuffer.DecodeTokenText(testStr, intVar);
846 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = QUOTE_CHAR_LEN;
847 mmsDecodeBuffer.DecodeTokenText(testStr, intVar);
848
849 mmsDecodeBuffer.curPosition_ = 0;
850 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = QUOTE_CHAR_LEN - 1;
851 mmsDecodeBuffer.DecodeText(testStr, intVar);
852 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = QUOTE_CHAR_LEN;
853 mmsDecodeBuffer.DecodeText(testStr, intVar);
854
855 mmsDecodeBuffer.curPosition_ = 0;
856 testChar += 1;
857 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar;
858 mmsDecodeBuffer.DecodeQuotedText(testStr, intVar);
859 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar + 1;
860 mmsDecodeBuffer.DecodeQuotedText(testStr, intVar);
861
862 uint8_t errVar = -1;
863 bool ret = mmsDecodeBuffer.CharIsToken(errVar);
864 EXPECT_EQ(false, ret);
865 }
866
867 /**
868 * @tc.number Telephony_SmsMmsGtest_MmsDecodeBuffer_0003
869 * @tc.name Test MmsDecodeBuffer
870 * @tc.desc Function test
871 */
HWTEST_F(MmsGtest, MmsDecodeBuffer_0003, Function | MediumTest | Level1)872 HWTEST_F(MmsGtest, MmsDecodeBuffer_0003, Function | MediumTest | Level1)
873 {
874 TELEPHONY_LOGI("TelSMSMMSTest::MmsDecodeBuffer_0003 -->");
875 uint8_t byteVar = 1;
876 uint64_t longVar = 10;
877 std::string testStr;
878 MmsDecodeBuffer mmsDecodeBuffer;
879 uint8_t count = 10;
880 uint8_t index = 0;
881 while (index < count) {
882 mmsDecodeBuffer.pduBuffer_[index] = '1';
883 index++;
884 }
885
886 mmsDecodeBuffer.curPosition_ = 0;
887 char testChar = QUOTE_CHAR_LEN + 1;
888 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar;
889 mmsDecodeBuffer.DecodeShortInteger(byteVar);
890 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar + 1;
891 mmsDecodeBuffer.DecodeShortInteger(byteVar);
892
893 mmsDecodeBuffer.curPosition_ = 0;
894 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = VALUE_CHAR;
895 mmsDecodeBuffer.DecodeLongInteger(longVar);
896 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = VALUE_CHAR + 1;
897 mmsDecodeBuffer.DecodeLongInteger(longVar);
898
899 mmsDecodeBuffer.curPosition_ = 0;
900 mmsDecodeBuffer.DecodeInteger(longVar);
901 mmsDecodeBuffer.curPosition_ = 0;
902 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar;
903 mmsDecodeBuffer.DecodeIsShortInt();
904 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar + 1;
905 mmsDecodeBuffer.DecodeIsShortInt();
906
907 mmsDecodeBuffer.curPosition_ = 0;
908 char srcChar = MIN_SHORT_OCTET + 1;
909 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = srcChar;
910 mmsDecodeBuffer.DecodeIsString();
911 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = srcChar + 1;
912 mmsDecodeBuffer.DecodeIsString();
913 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar + 1;
914 mmsDecodeBuffer.DecodeIsString();
915
916 mmsDecodeBuffer.curPosition_ = 0;
917 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = srcChar;
918 mmsDecodeBuffer.DecodeIsValueLength();
919 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = srcChar + 1;
920 mmsDecodeBuffer.DecodeIsValueLength();
921
922 mmsDecodeBuffer.MarkPosition();
923 mmsDecodeBuffer.UnMarkPosition();
924 uint8_t errVar = -1;
925 bool ret = mmsDecodeBuffer.CharIsToken(errVar);
926 EXPECT_EQ(false, ret);
927 }
928
929 /**
930 * @tc.number Telephony_SmsMmsGtest_MmsEncodeString_0001
931 * @tc.name Test MmsEncodeString
932 * @tc.desc Function test
933 */
HWTEST_F(MmsGtest, MmsEncodeString_0001, Function | MediumTest | Level1)934 HWTEST_F(MmsGtest, MmsEncodeString_0001, Function | MediumTest | Level1)
935 {
936 TELEPHONY_LOGI("TelSMSMMSTest::MmsEncodeString_0001 -->");
937 MmsEncodeString mmsEncodeString;
938 MmsDecodeBuffer decodeBuffer;
939 MmsEncodeBuffer encodeBuffer;
940 std::string testStr;
941 uint32_t charset = PDU_COUNT;
942 MmsAddress addrsss;
943 uint32_t len = PDU_COUNT;
944 std::unique_ptr<char[]> inBuff = std::make_unique<char[]>(len);
945 for (uint32_t i = 0; i < len; i++) {
946 inBuff[i] = 1;
947 }
948 decodeBuffer.WriteDataBuffer(std::move(inBuff), len);
949 mmsEncodeString.DecodeEncodeString(decodeBuffer);
950 decodeBuffer.curPosition_ = MAX_MMS_ATTACHMENT_LEN + 1;
951 mmsEncodeString.DecodeEncodeString(decodeBuffer);
952 mmsEncodeString.charset_ = ENCODE_CHARSET1;
953 mmsEncodeString.EncodeEncodeString(encodeBuffer);
954 mmsEncodeString.charset_ = ENCODE_CHARSET2;
955 mmsEncodeString.EncodeEncodeString(encodeBuffer);
956 mmsEncodeString.GetEncodeString(testStr);
957 EXPECT_GE(testStr.size(), 0);
958 mmsEncodeString.SetAddressString(addrsss);
959 mmsEncodeString.GetStrEncodeString();
960 MmsEncodeString mmsEncodeString1(mmsEncodeString);
961 charset = 0;
962 bool ret = mmsEncodeString1.SetEncodeString(charset, testStr);
963 EXPECT_EQ(true, ret);
964 ret = mmsEncodeString1.SetEncodeString(charset, testStr);
965 EXPECT_EQ(true, ret);
966 }
967
968 /**
969 * @tc.number Telephony_SmsMmsGtest_MmsHeaderCateg_0001
970 * @tc.name Test MmsHeaderCateg
971 * @tc.desc Function test
972 */
HWTEST_F(MmsGtest, MmsHeaderCateg_0001, Function | MediumTest | Level1)973 HWTEST_F(MmsGtest, MmsHeaderCateg_0001, Function | MediumTest | Level1)
974 {
975 TELEPHONY_LOGI("TelSMSMMSTest::MmsHeaderCateg_0001 -->");
976 MmsHeaderCateg mmsHeaderCateg;
977 uint8_t fieldId = 0;
978 mmsHeaderCateg.FindSendReqOptType(fieldId);
979 mmsHeaderCateg.FindSendConfOptType(fieldId);
980 mmsHeaderCateg.FindFieldDes(fieldId);
981 mmsHeaderCateg.CheckIsValueLen(fieldId);
982 bool ret = mmsHeaderCateg.CheckIsValueLen(fieldId);
983 EXPECT_EQ(false, ret);
984 }
985
986 /**
987 * @tc.number Telephony_SmsMmsGtest_MmsBase64_0001
988 * @tc.name Test MmsBase64
989 * @tc.desc Function test
990 */
HWTEST_F(MmsGtest, MmsBase64_0001, Function | MediumTest | Level1)991 HWTEST_F(MmsGtest, MmsBase64_0001, Function | MediumTest | Level1)
992 {
993 TELEPHONY_LOGI("TelSMSMMSTest::MmsBase64_0001 -->");
994 MmsBase64 mmsBase64;
995 std::string valueStr = "valueStr";
996 mmsBase64.Encode(valueStr);
997 std::string ret = mmsBase64.Decode(valueStr);
998 EXPECT_STRNE(ret.c_str(), "test");
999 }
1000
1001 /**
1002 * @tc.number Telephony_SmsMmsGtest_MmsCharSet_0001
1003 * @tc.name Test MmsCharSet
1004 * @tc.desc Function test
1005 */
HWTEST_F(MmsGtest, MmsCharSet_0001, Function | MediumTest | Level1)1006 HWTEST_F(MmsGtest, MmsCharSet_0001, Function | MediumTest | Level1)
1007 {
1008 TELEPHONY_LOGI("TelSMSMMSTest::MmsCharSet_0001 -->");
1009 MmsCharSet mmsCharSet;
1010 uint32_t charSet = 10;
1011 std::string strCharSet = "US-ASCII";
1012 mmsCharSet.GetCharSetStrFromInt(strCharSet, charSet);
1013 bool ret = mmsCharSet.GetCharSetIntFromString(charSet, strCharSet);
1014 EXPECT_EQ(true, ret);
1015 }
1016
1017 /**
1018 * @tc.number Telephony_SmsMmsGtest_MmsQuotedPrintable_0001
1019 * @tc.name Test MmsQuotedPrintable
1020 * @tc.desc Function test
1021 */
HWTEST_F(MmsGtest, MmsQuotedPrintable_0001, Function | MediumTest | Level1)1022 HWTEST_F(MmsGtest, MmsQuotedPrintable_0001, Function | MediumTest | Level1)
1023 {
1024 TELEPHONY_LOGI("TelSMSMMSTest::MmsQuotedPrintable_0001 -->");
1025 MmsQuotedPrintable mmsQuotedPrintable;
1026 std::string valueStr = "123";
1027 mmsQuotedPrintable.Encode(valueStr);
1028 std::string destStr = "";
1029 mmsQuotedPrintable.Decode(valueStr, destStr);
1030 bool ret = mmsQuotedPrintable.Decode("", valueStr);
1031 EXPECT_EQ(false, ret);
1032 }
1033
1034 /**
1035 * @tc.number Telephony_SmsServiceTest_0001
1036 * @tc.name Test MmsQuotedPrintable
1037 * @tc.desc Function test
1038 */
HWTEST_F(MmsGtest, SmsServiceTest_0001, Function | MediumTest | Level1)1039 HWTEST_F(MmsGtest, SmsServiceTest_0001, Function | MediumTest | Level1)
1040 {
1041 AccessMmsToken token;
1042 int32_t slotId = 0;
1043 int64_t timeStamp = 0;
1044 std::string homeUrlVal;
1045 std::string dbUrl;
1046 GetPduToFile(slotId);
1047 dbUrl = GetFileToDb();
1048 homeUrlVal = GetMmsc(slotId);
1049 std::u16string mmsc = StringUtils::ToUtf16(homeUrlVal);
1050 std::u16string data = StringUtils::ToUtf16(dbUrl);
1051 std::u16string ua = u"";
1052 std::u16string uaprof = u"";
1053 Singleton<SmsServiceManagerClient>::GetInstance().SendMms(slotId, mmsc, data, ua, uaprof, timeStamp);
1054 Singleton<SmsServiceManagerClient>::GetInstance().DownloadMms(slotId, mmsc, data, ua, uaprof);
1055 EXPECT_GE(dbUrl.length(), 0);
1056 EXPECT_GE(homeUrlVal.length(), 0);
1057 }
1058 #endif // TEL_TEST_UNSUPPORT
1059 } // namespace Telephony
1060 } // namespace OHOS