1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #define private public
17 #define protected public
18
19 #include "cdma_sms_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 DelayedSingleton<SmsServiceManagerClient>::GetInstance()->ResetSmsServiceProxy();
118 DelayedSingleton<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 */
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_TRUE(true);
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 if (subscriberTest == nullptr) {
430 ASSERT_TRUE(false);
431 return;
432 }
433 bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberTest);
434 TELEPHONY_LOGI("subscribeResult is : %{public}d", subscribeResult);
435
436 if (!helper.Run(ReceiveWapPushTestFunc, helper)) {
437 TELEPHONY_LOGI("ReceiveWapPushTestFunc out of time");
438 ASSERT_TRUE(true);
439 return;
440 }
441 TELEPHONY_LOGI("TelSMSMMSTest::Receive_Wap_Push_0001 -->finished");
442 EXPECT_TRUE(helper.GetBoolResult());
443 }
444
445 /**
446 * @tc.number Telephony_SmsMmsGtest_Receive_Wap_Push_0002
447 * @tc.name Receive a Wap Push
448 * @tc.desc Function test
449 */
450 HWTEST_F(MmsGtest, Receive_Wap_Push_0002, Function | MediumTest | Level2)
451 {
452 TELEPHONY_LOGI("TelSMSMMSTest::Receive_Wap_Push_0002 -->");
453 int32_t slotId = DEFAULT_SIM_SLOT_ID_1;
454 if (!(MmsGtest::HasSimCard(slotId))) {
455 TELEPHONY_LOGI("TelephonyTestService has no sim card");
456 ASSERT_TRUE(true);
457 return;
458 }
459 SmsMmsTestHelper helper;
460 helper.slotId = slotId;
461
462 EventFwk::MatchingSkills matchingSkills;
463 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SMS_WAPPUSH_RECEIVE_COMPLETED);
464 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
465 std::shared_ptr<SmsBroadcastSubscriberGtest> subscriberTest =
466 std::make_shared<SmsBroadcastSubscriberGtest>(subscriberInfo, helper);
467 if (subscriberTest == nullptr) {
468 ASSERT_TRUE(false);
469 return;
470 }
471 bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberTest);
472 TELEPHONY_LOGI("subscribeResult is : %{public}d", subscribeResult);
473
474 if (!helper.Run(ReceiveWapPushTestFunc, helper)) {
475 TELEPHONY_LOGI("ReceiveWapPushTestFunc out of time");
476 ASSERT_TRUE(true);
477 return;
478 }
479 TELEPHONY_LOGI("TelSMSMMSTest::Receive_Wap_Push_0002 -->finished");
480 EXPECT_TRUE(helper.GetBoolResult());
481 }
482
483 /**
484 * @tc.number Telephony_SmsMmsGtest_MmsAddress_0001
485 * @tc.name Test MmsAddress
486 * @tc.desc Function test
487 */
488 HWTEST_F(MmsGtest, MmsAddress_0001, Function | MediumTest | Level1)
489 {
490 TELEPHONY_LOGI("TelSMSMMSTest::MmsAddress_0001 -->");
491 MmsAddress address;
492 address.SetMmsAddressString("12345678/TYPE=PLMN");
493 address.SetMmsAddressString("12345678/TYPE=IPv4");
494 address.SetMmsAddressString("12345678/TYPE=IPv6");
495 address.SetMmsAddressString("12345678/TYPE=UNKNOWN");
496 address.SetMmsAddressString("12345678/TYPE=EMAIL");
497 std::string ret = address.GetAddressString();
498 EXPECT_STREQ(ret.c_str(), "12345678/TYPE=EMAIL");
499 MmsAddress::MmsAddressType type = address.GetAddressType();
500 EXPECT_EQ(type, MmsAddress::MmsAddressType::ADDRESS_TYPE_PLMN);
501 MmsCharSets charset = address.GetAddressCharset();
502 EXPECT_EQ(charset, MmsCharSets::UTF_8);
503 }
504
505 /**
506 * @tc.number Telephony_SmsMmsGtest_MmsAttachment_0001
507 * @tc.name Test MmsAttachment
508 * @tc.desc Function test
509 */
510 HWTEST_F(MmsGtest, MmsAttachment_0001, Function | MediumTest | Level1)
511 {
512 TELEPHONY_LOGI("TelSMSMMSTest::MmsAttachment_0001 -->");
513 const std::string pathName = "/data/app/enSrc/618C0A89.smil";
514 std::size_t pos = pathName.find_last_of('/');
515 std::string fileName(pathName.substr(pos + 1));
516 MmsAttachment attachment;
517 bool retBool;
518 std::string retStr;
519 retBool = attachment.SetAttachmentFilePath("", false);
520 EXPECT_EQ(false, retBool);
521 retBool = attachment.SetAttachmentFilePath(pathName, true);
522 EXPECT_EQ(true, retBool);
523 retStr = attachment.GetAttachmentFilePath();
524 EXPECT_STREQ(retStr.c_str(), pathName.c_str());
525 retBool = attachment.SetContentId("");
526 EXPECT_EQ(false, retBool);
527 retBool = attachment.SetContentId("0000");
528 EXPECT_EQ(true, retBool);
529 retBool = attachment.SetContentId("<0000>");
530 EXPECT_EQ(true, retBool);
531 retStr = attachment.GetContentId();
532 EXPECT_STREQ(retStr.c_str(), "<0000>");
533 retBool = attachment.SetContentLocation("");
534 EXPECT_EQ(false, retBool);
535 retBool = attachment.SetContentLocation("SetContentLocation");
536 EXPECT_EQ(true, retBool);
537 retStr = attachment.GetContentLocation();
538 EXPECT_STREQ(retStr.c_str(), "SetContentLocation");
539 retBool = attachment.SetContentDisposition("");
540 EXPECT_EQ(false, retBool);
541 retBool = attachment.SetContentDisposition("attachment");
542 EXPECT_EQ(true, retBool);
543 retStr = attachment.GetContentDisposition();
544 EXPECT_STREQ(retStr.c_str(), "attachment");
545 retBool = attachment.SetContentTransferEncoding("");
546 EXPECT_EQ(false, retBool);
547 retBool = attachment.SetFileName(fileName);
548 EXPECT_EQ(true, retBool);
549 retStr = attachment.GetFileName();
550 EXPECT_STREQ(retStr.c_str(), fileName.c_str());
551 attachment.strFileName_ = "";
552 retStr = attachment.GetFileName();
553 EXPECT_STRNE(retStr.c_str(), fileName.c_str());
554 }
555
556 /**
557 * @tc.number Telephony_SmsMmsGtest_MmsAttachment_0002
558 * @tc.name Test MmsAttachment
559 * @tc.desc Function test
560 */
561 HWTEST_F(MmsGtest, MmsAttachment_0002, Function | MediumTest | Level1)
562 {
563 TELEPHONY_LOGI("TelSMSMMSTest::MmsAttachment_0002 -->");
564 MmsAttachment attachment;
565 bool retBool;
566 std::string retStr;
567 uint32_t retU32t;
568 uint32_t len = 10 * 1024 * 1024;
569 uint32_t charset = 0;
570 retBool = attachment.SetContentTransferEncoding("SetContentTransferEncoding");
571 EXPECT_EQ(true, retBool);
572 retStr = attachment.GetContentTransferEncoding();
573 EXPECT_STREQ(retStr.c_str(), "SetContentTransferEncoding");
574 retBool = attachment.SetContentType("");
575 EXPECT_EQ(false, retBool);
576 attachment.SetIsSmilFile(true);
577 retBool = attachment.IsSmilFile();
578 EXPECT_EQ(true, retBool);
579 attachment.SetCharSet(charset);
580 retU32t = attachment.GetCharSet();
581 EXPECT_EQ(charset, retU32t);
582 retBool = attachment.SetDataBuffer(nullptr, 0);
583 retBool = attachment.SetDataBuffer(nullptr, MAX_MMS_ATTACHMENT_LEN + 1);
584 EXPECT_EQ(false, retBool);
585 retBool = attachment.SetDataBuffer(std::make_unique<char[]>(len + 1), len + 1);
586 EXPECT_EQ(false, retBool);
587 retBool = attachment.SetDataBuffer(std::make_unique<char[]>(len - 1), len - 1);
588 EXPECT_EQ(true, retBool);
589 retBool = attachment.SetDataBuffer(std::make_unique<char[]>(len - 1), len + 1);
590 EXPECT_EQ(false, retBool);
591 EXPECT_FALSE(attachment.GetDataBuffer(len) == nullptr);
592 attachment.dataLength_ = MAX_MMS_ATTACHMENT_LEN + 1;
593 EXPECT_TRUE(attachment.GetDataBuffer(len) == nullptr);
594 MmsAttachment attachment1(attachment);
595 attachment1.SetContentType("application/smil");
596 retStr = attachment1.GetContentType();
597 EXPECT_STREQ(retStr.c_str(), "application/smil");
598 }
599
600 /**
601 * @tc.number Telephony_SmsMmsGtest_MmsBodyPartHeader_0001
602 * @tc.name Test MmsBodyPartHeader
603 * @tc.desc Function test
604 */
605 HWTEST_F(MmsGtest, MmsBodyPartHeader_0001, Function | MediumTest | Level1)
606 {
607 TELEPHONY_LOGI("TelSMSMMSTest::MmsBodyPartHeader_0001 -->");
608 MmsBodyPartHeader mmsBodyPartHeader;
609 MmsDecodeBuffer decodeBuffer;
610 std::string testStr;
611 uint32_t len = 0;
612 uint32_t lenErr = -1;
613 uint32_t lenMax = 300 * 1024;
614 mmsBodyPartHeader.DumpBodyPartHeader();
615 mmsBodyPartHeader.DecodeContentLocation(decodeBuffer, len);
616 mmsBodyPartHeader.DecodeContentId(decodeBuffer, len);
617 mmsBodyPartHeader.DecodeContentDisposition(decodeBuffer, len);
618 mmsBodyPartHeader.DecodeDispositionParameter(decodeBuffer, lenMax, len);
619 mmsBodyPartHeader.DecodeDispositionParameter(decodeBuffer, lenErr, len);
620 mmsBodyPartHeader.DecodeWellKnownHeader(decodeBuffer, len);
621 mmsBodyPartHeader.DecodeApplicationHeader(decodeBuffer, len);
622 mmsBodyPartHeader.SetContentId("contentId");
623 mmsBodyPartHeader.GetContentId(testStr);
624 EXPECT_STREQ(testStr.c_str(), "contentId");
625 mmsBodyPartHeader.SetContentTransferEncoding("contentTransferEncoding");
626 mmsBodyPartHeader.GetContentTransferEncoding(testStr);
627 EXPECT_STREQ(testStr.c_str(), "contentTransferEncoding");
628 mmsBodyPartHeader.SetContentLocation("contentLocation");
629 mmsBodyPartHeader.GetContentLocation(testStr);
630 EXPECT_STREQ(testStr.c_str(), "contentLocation");
631 MmsEncodeBuffer encodeBuffer;
632 mmsBodyPartHeader.EncodeContentLocation(encodeBuffer);
633 mmsBodyPartHeader.EncodeContentId(encodeBuffer);
634 mmsBodyPartHeader.EncodeContentDisposition(encodeBuffer);
635 mmsBodyPartHeader.EncodeContentTransferEncoding(encodeBuffer);
636 mmsBodyPartHeader.EncodeMmsBodyPartHeader(encodeBuffer);
637 MmsBodyPartHeader mmsBodyPartHeader2;
638 MmsBodyPartHeader mmsBodyPartHeader3 = MmsBodyPartHeader(mmsBodyPartHeader);
639 mmsBodyPartHeader2 = mmsBodyPartHeader;
640 mmsBodyPartHeader2.SetContentDisposition("contentDisposition");
641 mmsBodyPartHeader2.GetContentDisposition(testStr);
642 EXPECT_STREQ(testStr.c_str(), "contentDisposition");
643 }
644
645 /**
646 * @tc.number Telephony_SmsMmsGtest_MmsBuffer_0001
647 * @tc.name Test MmsBuffer
648 * @tc.desc Function test
649 */
650 HWTEST_F(MmsGtest, MmsBuffer_0001, Function | MediumTest | Level1)
651 {
652 TELEPHONY_LOGI("TelSMSMMSTest::MmsBuffer_0001 -->");
653 MmsBuffer mmsBuffer;
654 uint32_t len = 10;
655 bool retBool;
656 std::string strPathName = "/data/app/enSrc/618C0A89.smil";
657 mmsBuffer.ReadDataBuffer(len);
658 mmsBuffer.ReadDataBuffer(len, len);
659 retBool = mmsBuffer.WriteDataBuffer(std::make_unique<char[]>(len), 0);
660 EXPECT_EQ(false, retBool);
661 retBool = mmsBuffer.WriteDataBuffer(std::make_unique<char[]>(len), len);
662 EXPECT_EQ(true, retBool);
663 mmsBuffer.WriteBufferFromFile(strPathName);
664 mmsBuffer.GetCurPosition();
665 uint32_t ret = mmsBuffer.GetSize();
666 EXPECT_GE(ret, 0);
667 }
668
669 /**
670 * @tc.number Telephony_SmsMmsGtest_MmsContentParam_0001
671 * @tc.name Test MmsContentParam
672 * @tc.desc Function test
673 */
674 HWTEST_F(MmsGtest, MmsContentParam_0001, Function | MediumTest | Level1)
675 {
676 TELEPHONY_LOGI("TelSMSMMSTest::MmsContentParam_0001 -->");
677 MmsContentParam mmsContentParam;
678 MmsContentParam mmsContentParam2;
679 uint8_t field = 1;
680 uint32_t charset = 10;
681 std::string testStr;
682 uint32_t retU32t;
683 mmsContentParam.DumpContentParam();
684 mmsContentParam.SetCharSet(charset);
685 retU32t = mmsContentParam.GetCharSet();
686 EXPECT_EQ(charset, retU32t);
687 mmsContentParam.SetType("type");
688 testStr = mmsContentParam.GetType();
689 EXPECT_STREQ(testStr.c_str(), "type");
690 mmsContentParam.SetFileName("");
691 mmsContentParam.SetStart("");
692 mmsContentParam.SetStart("start");
693 mmsContentParam.GetStart(testStr);
694 EXPECT_STREQ(testStr.c_str(), "start");
695 mmsContentParam.AddNormalField(field, "value");
696 mmsContentParam.GetNormalField(field, testStr);
697 EXPECT_STREQ(testStr.c_str(), "value");
698 mmsContentParam.GetParamMap();
699 mmsContentParam2 = mmsContentParam;
700 mmsContentParam2.SetFileName("fileName");
701 mmsContentParam2.GetFileName(testStr);
702 EXPECT_STREQ(testStr.c_str(), "fileName");
703
704 mmsContentParam.textMap_.clear();
705 mmsContentParam.AddNormalField(field, "value");
706 mmsContentParam.textMap_.clear();
707 mmsContentParam.GetNormalField(field, testStr);
708 mmsContentParam.GetStart(testStr);
709 mmsContentParam2.GetFileName(testStr);
710 mmsContentParam.DumpContentParam();
711 EXPECT_STREQ(testStr.c_str(), "fileName");
712 }
713
714 /**
715 * @tc.number Telephony_SmsMmsGtest_MmsContentType_0001
716 * @tc.name Test MmsContentType
717 * @tc.desc Function test
718 */
719 HWTEST_F(MmsGtest, MmsContentType_0001, Function | MediumTest | Level1)
720 {
721 TELEPHONY_LOGI("TelSMSMMSTest::MmsContentType_0001 -->");
722 MmsContentType mmsContentType;
723 MmsDecodeBuffer decodeBuffer;
724 MmsContentParam contentParam;
725 int32_t len = 10;
726 uint8_t type = 10;
727 std::string testStr;
728 uint8_t count = 10;
729 uint8_t index = 0;
730 while (index < count) {
731 decodeBuffer.pduBuffer_[index] = '1';
732 index++;
733 }
734 mmsContentType.DumpMmsContentType();
735
736 decodeBuffer.curPosition_ = 0;
737 decodeBuffer.pduBuffer_[decodeBuffer.curPosition_++] = PDU_TEST_DATA;
738 decodeBuffer.pduBuffer_[decodeBuffer.curPosition_++] = PDU_TEST_DATA;
739 decodeBuffer.pduBuffer_[decodeBuffer.curPosition_] = PDU_TEST_DATA;
740 mmsContentType.DecodeMmsContentType(decodeBuffer, len);
741
742 decodeBuffer.curPosition_ = 0;
743 mmsContentType.DecodeMmsCTGeneralForm(decodeBuffer, len);
744 mmsContentType.GetContentTypeFromInt(type);
745 mmsContentType.GetContentTypeFromString("");
746
747 decodeBuffer.curPosition_ = 0;
748 mmsContentType.DecodeParameter(decodeBuffer, len);
749 mmsContentType.SetContentParam(contentParam);
750 mmsContentType.DecodeTextField(decodeBuffer, type, len);
751
752 decodeBuffer.curPosition_ = 0;
753 mmsContentType.DecodeCharsetField(decodeBuffer, len);
754 mmsContentType.DecodeTypeField(decodeBuffer, len);
755
756 MmsEncodeBuffer encodeBuffer;
757 mmsContentType.EncodeTextField(encodeBuffer);
758 mmsContentType.EncodeCharsetField(encodeBuffer);
759 mmsContentType.EncodeTypeField(encodeBuffer);
760 mmsContentType.EncodeMmsBodyPartContentParam(encodeBuffer);
761 mmsContentType.EncodeMmsBodyPartContentType(encodeBuffer);
762 mmsContentType.GetContentParam();
763 MmsContentType mmsContentType2(mmsContentType);
764 mmsContentType2 = mmsContentType;
765 mmsContentType2.SetContentType("contentType");
766 mmsContentType2.GetContentType(testStr);
767 EXPECT_STREQ(testStr.c_str(), "contentType");
768 }
769
770 /**
771 * @tc.number Telephony_SmsMmsGtest_MmsDecodeBuffer_0001
772 * @tc.name Test MmsDecodeBuffer
773 * @tc.desc Function test
774 */
775 HWTEST_F(MmsGtest, MmsDecodeBuffer_0001, Function | MediumTest | Level1)
776 {
777 TELEPHONY_LOGI("TelSMSMMSTest::MmsDecodeBuffer_0001 -->");
778 uint8_t byteVar = 1;
779 uint32_t intVar = PDU_COUNT;
780 std::string testStr;
781 MmsDecodeBuffer mmsDecodeBuffer;
782 uint8_t count = PDU_COUNT;
783 uint8_t index = 0;
784 while (index < count) {
785 mmsDecodeBuffer.pduBuffer_[index] = '1';
786 index++;
787 }
788
789 mmsDecodeBuffer.PeekOneByte(byteVar);
790 mmsDecodeBuffer.GetOneByte(byteVar);
791 mmsDecodeBuffer.IncreasePointer(intVar);
792 mmsDecodeBuffer.DecreasePointer(intVar);
793 mmsDecodeBuffer.curPosition_ = PDU_CUSITION;
794 mmsDecodeBuffer.totolLength_ = PDU_LENGTH;
795 mmsDecodeBuffer.PeekOneByte(byteVar);
796 mmsDecodeBuffer.GetOneByte(byteVar);
797 mmsDecodeBuffer.IncreasePointer(intVar);
798 mmsDecodeBuffer.DecreasePointer(intVar);
799
800 mmsDecodeBuffer.curPosition_ = 0;
801 mmsDecodeBuffer.DecodeUintvar(intVar, intVar);
802 mmsDecodeBuffer.DecodeShortLength(byteVar);
803
804 char testChar = MIN_SHORT_OCTET + 1;
805 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar;
806 mmsDecodeBuffer.DecodeShortLength(byteVar);
807 mmsDecodeBuffer.curPosition_ = 0;
808 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = MIN_SHORT_OCTET;
809 mmsDecodeBuffer.DecodeValueLengthReturnLen(intVar, intVar);
810 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar;
811 mmsDecodeBuffer.DecodeValueLengthReturnLen(intVar, intVar);
812 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar + 1;
813 mmsDecodeBuffer.DecodeValueLengthReturnLen(intVar, intVar);
814
815 uint8_t errVar = -1;
816 bool ret = mmsDecodeBuffer.CharIsToken(errVar);
817 EXPECT_EQ(false, ret);
818 }
819
820 /**
821 * @tc.number Telephony_SmsMmsGtest_MmsDecodeBuffer_0002
822 * @tc.name Test MmsDecodeBuffer
823 * @tc.desc Function test
824 */
825 HWTEST_F(MmsGtest, MmsDecodeBuffer_0002, Function | MediumTest | Level1)
826 {
827 TELEPHONY_LOGI("TelSMSMMSTest::MmsDecodeBuffer_0002 -->");
828 uint32_t intVar = 10;
829 std::string testStr;
830 MmsDecodeBuffer mmsDecodeBuffer;
831 uint8_t count = 10;
832 uint8_t index = 0;
833 while (index < count) {
834 mmsDecodeBuffer.pduBuffer_[index] = '1';
835 index++;
836 }
837 mmsDecodeBuffer.curPosition_ = 0;
838 char testChar = MIN_SHORT_OCTET + 1;
839 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = MIN_SHORT_OCTET;
840 mmsDecodeBuffer.DecodeValueLength(intVar);
841 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar;
842 mmsDecodeBuffer.DecodeValueLength(intVar);
843 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar + 1;
844 mmsDecodeBuffer.DecodeValueLength(intVar);
845
846 mmsDecodeBuffer.curPosition_ = 0;
847 testChar += 1;
848 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar;
849 mmsDecodeBuffer.DecodeTokenText(testStr, intVar);
850 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar + 1;
851 mmsDecodeBuffer.DecodeTokenText(testStr, intVar);
852 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = QUOTE_CHAR_LEN;
853 mmsDecodeBuffer.DecodeTokenText(testStr, intVar);
854
855 mmsDecodeBuffer.curPosition_ = 0;
856 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = QUOTE_CHAR_LEN - 1;
857 mmsDecodeBuffer.DecodeText(testStr, intVar);
858 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = QUOTE_CHAR_LEN;
859 mmsDecodeBuffer.DecodeText(testStr, intVar);
860
861 mmsDecodeBuffer.curPosition_ = 0;
862 testChar += 1;
863 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar;
864 mmsDecodeBuffer.DecodeQuotedText(testStr, intVar);
865 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar + 1;
866 mmsDecodeBuffer.DecodeQuotedText(testStr, intVar);
867
868 uint8_t errVar = -1;
869 bool ret = mmsDecodeBuffer.CharIsToken(errVar);
870 EXPECT_EQ(false, ret);
871 }
872
873 /**
874 * @tc.number Telephony_SmsMmsGtest_MmsDecodeBuffer_0003
875 * @tc.name Test MmsDecodeBuffer
876 * @tc.desc Function test
877 */
878 HWTEST_F(MmsGtest, MmsDecodeBuffer_0003, Function | MediumTest | Level1)
879 {
880 TELEPHONY_LOGI("TelSMSMMSTest::MmsDecodeBuffer_0003 -->");
881 uint8_t byteVar = 1;
882 uint64_t longVar = 10;
883 std::string testStr;
884 MmsDecodeBuffer mmsDecodeBuffer;
885 uint8_t count = 10;
886 uint8_t index = 0;
887 while (index < count) {
888 mmsDecodeBuffer.pduBuffer_[index] = '1';
889 index++;
890 }
891
892 mmsDecodeBuffer.curPosition_ = 0;
893 char testChar = QUOTE_CHAR_LEN + 1;
894 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar;
895 mmsDecodeBuffer.DecodeShortInteger(byteVar);
896 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar + 1;
897 mmsDecodeBuffer.DecodeShortInteger(byteVar);
898
899 mmsDecodeBuffer.curPosition_ = 0;
900 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = VALUE_CHAR;
901 mmsDecodeBuffer.DecodeLongInteger(longVar);
902 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = VALUE_CHAR + 1;
903 mmsDecodeBuffer.DecodeLongInteger(longVar);
904
905 mmsDecodeBuffer.curPosition_ = 0;
906 mmsDecodeBuffer.DecodeInteger(longVar);
907 mmsDecodeBuffer.curPosition_ = 0;
908 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar;
909 mmsDecodeBuffer.DecodeIsShortInt();
910 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar + 1;
911 mmsDecodeBuffer.DecodeIsShortInt();
912
913 mmsDecodeBuffer.curPosition_ = 0;
914 char srcChar = MIN_SHORT_OCTET + 1;
915 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = srcChar;
916 mmsDecodeBuffer.DecodeIsString();
917 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = srcChar + 1;
918 mmsDecodeBuffer.DecodeIsString();
919 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = testChar + 1;
920 mmsDecodeBuffer.DecodeIsString();
921
922 mmsDecodeBuffer.curPosition_ = 0;
923 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = srcChar;
924 mmsDecodeBuffer.DecodeIsValueLength();
925 mmsDecodeBuffer.pduBuffer_[mmsDecodeBuffer.curPosition_] = srcChar + 1;
926 mmsDecodeBuffer.DecodeIsValueLength();
927
928 mmsDecodeBuffer.MarkPosition();
929 mmsDecodeBuffer.UnMarkPosition();
930 uint8_t errVar = -1;
931 bool ret = mmsDecodeBuffer.CharIsToken(errVar);
932 EXPECT_EQ(false, ret);
933 }
934
935 /**
936 * @tc.number Telephony_SmsMmsGtest_MmsEncodeString_0001
937 * @tc.name Test MmsEncodeString
938 * @tc.desc Function test
939 */
940 HWTEST_F(MmsGtest, MmsEncodeString_0001, Function | MediumTest | Level1)
941 {
942 TELEPHONY_LOGI("TelSMSMMSTest::MmsEncodeString_0001 -->");
943 MmsEncodeString mmsEncodeString;
944 MmsDecodeBuffer decodeBuffer;
945 MmsEncodeBuffer encodeBuffer;
946 std::string testStr;
947 uint32_t charset = PDU_COUNT;
948 MmsAddress addrsss;
949 uint32_t len = PDU_COUNT;
950 std::unique_ptr<char[]> inBuff = std::make_unique<char[]>(len);
951 for (uint32_t i = 0; i < len; i++) {
952 inBuff[i] = 1;
953 }
954 decodeBuffer.WriteDataBuffer(std::move(inBuff), len);
955 mmsEncodeString.DecodeEncodeString(decodeBuffer);
956 decodeBuffer.curPosition_ = MAX_MMS_ATTACHMENT_LEN + 1;
957 mmsEncodeString.DecodeEncodeString(decodeBuffer);
958 mmsEncodeString.charset_ = ENCODE_CHARSET1;
959 mmsEncodeString.EncodeEncodeString(encodeBuffer);
960 mmsEncodeString.charset_ = ENCODE_CHARSET2;
961 mmsEncodeString.EncodeEncodeString(encodeBuffer);
962 mmsEncodeString.GetEncodeString(testStr);
963 EXPECT_GE(testStr.size(), 0);
964 mmsEncodeString.SetAddressString(addrsss);
965 mmsEncodeString.GetStrEncodeString();
966 MmsEncodeString mmsEncodeString1(mmsEncodeString);
967 charset = 0;
968 bool ret = mmsEncodeString1.SetEncodeString(charset, testStr);
969 EXPECT_EQ(true, ret);
970 ret = mmsEncodeString1.SetEncodeString(charset, testStr);
971 EXPECT_EQ(true, ret);
972 }
973
974 /**
975 * @tc.number Telephony_SmsMmsGtest_MmsHeaderCateg_0001
976 * @tc.name Test MmsHeaderCateg
977 * @tc.desc Function test
978 */
979 HWTEST_F(MmsGtest, MmsHeaderCateg_0001, Function | MediumTest | Level1)
980 {
981 TELEPHONY_LOGI("TelSMSMMSTest::MmsHeaderCateg_0001 -->");
982 MmsHeaderCateg mmsHeaderCateg;
983 uint8_t fieldId = 0;
984 mmsHeaderCateg.FindSendReqOptType(fieldId);
985 mmsHeaderCateg.FindSendConfOptType(fieldId);
986 mmsHeaderCateg.FindFieldDes(fieldId);
987 mmsHeaderCateg.CheckIsValueLen(fieldId);
988 bool ret = mmsHeaderCateg.CheckIsValueLen(fieldId);
989 EXPECT_EQ(false, ret);
990 }
991
992 /**
993 * @tc.number Telephony_SmsMmsGtest_MmsBase64_0001
994 * @tc.name Test MmsBase64
995 * @tc.desc Function test
996 */
997 HWTEST_F(MmsGtest, MmsBase64_0001, Function | MediumTest | Level1)
998 {
999 TELEPHONY_LOGI("TelSMSMMSTest::MmsBase64_0001 -->");
1000 MmsBase64 mmsBase64;
1001 std::string valueStr = "valueStr";
1002 mmsBase64.Encode(valueStr);
1003 std::string ret = mmsBase64.Decode(valueStr);
1004 EXPECT_STRNE(ret.c_str(), "test");
1005 }
1006
1007 /**
1008 * @tc.number Telephony_SmsMmsGtest_MmsCharSet_0001
1009 * @tc.name Test MmsCharSet
1010 * @tc.desc Function test
1011 */
1012 HWTEST_F(MmsGtest, MmsCharSet_0001, Function | MediumTest | Level1)
1013 {
1014 TELEPHONY_LOGI("TelSMSMMSTest::MmsCharSet_0001 -->");
1015 MmsCharSet mmsCharSet;
1016 uint32_t charSet = 10;
1017 std::string strCharSet = "US-ASCII";
1018 mmsCharSet.GetCharSetStrFromInt(strCharSet, charSet);
1019 bool ret = mmsCharSet.GetCharSetIntFromString(charSet, strCharSet);
1020 EXPECT_EQ(true, ret);
1021 }
1022
1023 /**
1024 * @tc.number Telephony_SmsMmsGtest_MmsQuotedPrintable_0001
1025 * @tc.name Test MmsQuotedPrintable
1026 * @tc.desc Function test
1027 */
1028 HWTEST_F(MmsGtest, MmsQuotedPrintable_0001, Function | MediumTest | Level1)
1029 {
1030 TELEPHONY_LOGI("TelSMSMMSTest::MmsQuotedPrintable_0001 -->");
1031 MmsQuotedPrintable mmsQuotedPrintable;
1032 std::string valueStr = "123";
1033 mmsQuotedPrintable.Encode(valueStr);
1034 std::string destStr = "";
1035 mmsQuotedPrintable.Decode(valueStr, destStr);
1036 bool ret = mmsQuotedPrintable.Decode("", valueStr);
1037 EXPECT_EQ(false, ret);
1038 }
1039
1040 /**
1041 * @tc.number Telephony_SmsServiceTest_0001
1042 * @tc.name Test MmsQuotedPrintable
1043 * @tc.desc Function test
1044 */
1045 HWTEST_F(MmsGtest, SmsServiceTest_0001, Function | MediumTest | Level1)
1046 {
1047 AccessMmsToken token;
1048 int32_t slotId = 0;
1049 std::string homeUrlVal;
1050 std::string dbUrl;
1051 GetPduToFile(slotId);
1052 dbUrl = GetFileToDb();
1053 homeUrlVal = GetMmsc(slotId);
1054 auto smsService = DelayedSingleton<SmsServiceManagerClient>::GetInstance();
1055 if (smsService == nullptr) {
1056 return;
1057 }
1058 std::u16string mmsc = StringUtils::ToUtf16(homeUrlVal);
1059 std::u16string data = StringUtils::ToUtf16(dbUrl);
1060 std::u16string ua = u"";
1061 std::u16string uaprof = u"";
1062 smsService->SendMms(slotId, mmsc, data, ua, uaprof);
1063 smsService->DownloadMms(slotId, mmsc, data, ua, uaprof);
1064 EXPECT_GE(dbUrl.length(), 0);
1065 EXPECT_GE(homeUrlVal.length(), 0);
1066 EXPECT_TRUE(smsService != nullptr);
1067 }
1068 #endif // TEL_TEST_UNSUPPORT
1069 } // namespace Telephony
1070 } // namespace OHOS