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";
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 auto smsReceiveHandler = std::make_shared<GsmSmsReceiveHandler>(helper.slotId);
139 auto message = std::make_shared<SmsMessageInfo>();
140 message->indicationType = MESSAGE_TYPE;
141 message->size = WAPPUSH_PDU_LEN;
142 message->pdu = StringUtils::HexToByteVector(
143 "0891683110205005F0640BA10156455102F1000432109261715023880605040B8423F04C06246170706C69636174696F6E2F766E642E77"
144 "61702E6D6D732D6D65737361676500B487AF848C829850765030303031365A645430008D9089178031363630373532313930382F545950"
145 "453D504C4D4E008A808E040001298D"
146 "8805810303F47B83687474703A2F2F31302E3132332E31382E38303A3138302F76564F455F3000");
147
148 AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GSM_SMS, message);
149 smsReceiveHandler->ProcessEvent(event);
150 }
151
GetSendReqDataTest(MmsMsg & encodeMsg,std::string number)152 void GetSendReqDataTest(MmsMsg &encodeMsg, std::string number)
153 {
154 if (!encodeMsg.SetMmsMessageType(MMS_MSGTYPE_SEND_REQ)) {
155 TELEPHONY_LOGE("SetMmsMessageType fail");
156 }
157 if (!encodeMsg.SetMmsTransactionId("2077.1427358451410")) {
158 TELEPHONY_LOGE("SetMmsTransactionId fail");
159 }
160 if (!encodeMsg.SetMmsVersion(static_cast<uint16_t>(MmsVersionType::MMS_VERSION_1_2))) {
161 TELEPHONY_LOGE("SetMmsVersion fail");
162 }
163 MmsAddress address;
164 address.SetMmsAddressString(number);
165 if (!encodeMsg.SetMmsFrom(address)) {
166 TELEPHONY_LOGE("SetMmsFrom fail");
167 }
168 if (!encodeMsg.SetHeaderContentType("application/vnd.wap.multipart.related")) {
169 TELEPHONY_LOGE("SetHeaderContentType fail");
170 }
171 if (!encodeMsg.SetMmsSubject("mms")) {
172 TELEPHONY_LOGE("SetMmsSubject fail");
173 }
174 if (!encodeMsg.SetHeaderOctetValue(MMS_CONTENT_CLASS, static_cast<uint8_t>(MmsContentClass::MMS_TEXT))) {
175 TELEPHONY_LOGE("SetHeaderOctetValue MMS_CONTENT_CLASS fail");
176 }
177 }
178
MmsAddAttachment(MmsMsg & msg,std::string pathName,std::string contentId,std::string contenType,bool isSmil)179 bool MmsAddAttachment(MmsMsg &msg, std::string pathName, std::string contentId, std::string contenType, bool isSmil)
180 {
181 MmsAttachment imageAttachment;
182 std::size_t pos = pathName.find_last_of('/');
183 std::string fileName(pathName.substr(pos + 1));
184 if (!imageAttachment.SetAttachmentFilePath(pathName, isSmil)) {
185 TELEPHONY_LOGE("MmsAddAttachment SetAttachmentFilePath fail");
186 return false;
187 }
188 if (!imageAttachment.SetFileName(fileName)) {
189 TELEPHONY_LOGE("MmsAddAttachment SetFileName fail");
190 return false;
191 }
192 if (!imageAttachment.SetContentId(contentId)) {
193 TELEPHONY_LOGE("MmsAddAttachment SetContentId fail");
194 return false;
195 }
196 if (!imageAttachment.SetContentLocation(fileName)) {
197 TELEPHONY_LOGE("MmsAddAttachment SetContentLocation fail");
198 return false;
199 }
200 if (!imageAttachment.SetContentType(contenType)) {
201 TELEPHONY_LOGE("MmsAddAttachment SetContentType fail");
202 return false;
203 }
204 imageAttachment.SetContentDisposition("attachment");
205 if (!msg.AddAttachment(imageAttachment)) {
206 TELEPHONY_LOGE("MmsAddAttachment AddAttachment fail");
207 return false;
208 }
209 return true;
210 }
211
WriteBufferToFile(const std::unique_ptr<char[]> & buff,uint32_t len,const std::string & strPathName)212 bool WriteBufferToFile(const std::unique_ptr<char[]> &buff, uint32_t len, const std::string &strPathName)
213 {
214 FILE *pFile = nullptr;
215 pFile = fopen(strPathName.c_str(), "wb");
216 if (!pFile || buff == nullptr) {
217 return false;
218 }
219 uint32_t fileLen = fwrite(buff.get(), len, 1, pFile);
220 if (fileLen > 0) {
221 TELEPHONY_LOGD("write mms buffer to file success");
222 } else {
223 TELEPHONY_LOGE("write mms buffer to file error");
224 }
225 (void)fclose(pFile);
226 return true;
227 }
228
GetMmsPduFromFile(const std::string & fileName,std::string & mmsPdu)229 bool GetMmsPduFromFile(const std::string &fileName, std::string &mmsPdu)
230 {
231 char realPath[PATH_MAX] = { 0 };
232 if (fileName.empty() || realpath(fileName.c_str(), realPath) == nullptr) {
233 TELEPHONY_LOGE("path or realPath is nullptr");
234 return false;
235 }
236 FILE *pFile = fopen(realPath, "rb");
237 if (pFile == nullptr) {
238 TELEPHONY_LOGE("openFile Error");
239 return false;
240 }
241 (void)fseek(pFile, 0, SEEK_END);
242 long fileLen = ftell(pFile);
243 if (fileLen <= 0 || fileLen > static_cast<long>(MMS_PDU_MAX_SIZE)) {
244 (void)fclose(pFile);
245 TELEPHONY_LOGE("fileLen Over Max Error");
246 return false;
247 }
248 std::unique_ptr<char[]> pduBuffer = std::make_unique<char[]>(fileLen);
249 if (!pduBuffer) {
250 (void)fclose(pFile);
251 TELEPHONY_LOGE("make unique pduBuffer nullptr Error");
252 return false;
253 }
254 (void)fseek(pFile, 0, SEEK_SET);
255 int32_t totolLength = static_cast<int32_t>(fread(pduBuffer.get(), 1, MMS_PDU_MAX_SIZE, pFile));
256 TELEPHONY_LOGI("fread totolLength%{public}d", totolLength);
257 long i = 0;
258 while (i < fileLen) {
259 mmsPdu += pduBuffer[i];
260 i++;
261 }
262 (void)fclose(pFile);
263 return true;
264 }
265
SplitPdu(const std::string & mmsPdu)266 std::vector<std::string> SplitPdu(const std::string &mmsPdu)
267 {
268 std::vector<std::string> mmsPdus;
269 if (mmsPdu.compare(PDU) == 0) {
270 for (uint32_t locate = 0; locate < MAX_PDU_PAGES; locate++) {
271 mmsPdus.push_back(PDU);
272 }
273 return mmsPdus;
274 }
275 std::string targetMmsPdu;
276 for (size_t i = 0; i < mmsPdu.size(); i++) {
277 targetMmsPdu += static_cast<char>((mmsPdu[i] & HEX_VALUE_0F) | HEX_VALUE_F0);
278 targetMmsPdu += static_cast<char>((mmsPdu[i] & HEX_VALUE_F0) | HEX_VALUE_0F);
279 }
280 std::string mmsPduData;
281 for (uint32_t locate = 0; locate * SPLIT_PDU_LENGTH < targetMmsPdu.size(); locate++) {
282 if ((locate + 1) * SPLIT_PDU_LENGTH < targetMmsPdu.size()) {
283 mmsPduData = targetMmsPdu.substr(locate * SPLIT_PDU_LENGTH, SPLIT_PDU_LENGTH);
284 mmsPdus.push_back(mmsPduData);
285 } else {
286 mmsPduData = targetMmsPdu.substr(locate * SPLIT_PDU_LENGTH);
287 mmsPdus.push_back(mmsPduData);
288 break;
289 }
290 }
291 TELEPHONY_LOGI("pduLen:%{public}zu,targetPduLen:%{public}zu", mmsPdu.size(), targetMmsPdu.size());
292 return mmsPdus;
293 }
294
GetPduToFile(int32_t slotId)295 void GetPduToFile(int32_t slotId)
296 {
297 SmsMmsTestHelper smsMmsTestHelper;
298 smsMmsTestHelper.slotId = slotId;
299 std::string dest = "10086";
300 std::u16string simcardNumber;
301 if (!CoreServiceClient::GetInstance().GetSimTelephoneNumber(smsMmsTestHelper.slotId, simcardNumber) &&
302 !simcardNumber.empty()) {
303 dest = StringUtils::ToUtf8(simcardNumber);
304 }
305 MmsMsg encodeMsg;
306 std::vector<MmsAddress> vecAddrs;
307 std::string toAddr = dest + "/TYPE=PLMN";
308 MmsAddress toAddrs(toAddr);
309 GetSendReqDataTest(encodeMsg, toAddr);
310 vecAddrs.push_back(toAddrs);
311 if (!encodeMsg.SetMmsTo(vecAddrs)) {
312 TELEPHONY_LOGE("SetMmsTo fail");
313 }
314 const std::string filePathNameText = "/data/app/mms.text";
315 const char *source = "mms";
316 size_t sourceLen = std::strlen(source);
317 std::unique_ptr<char[]> text = std::make_unique<char[]>(sourceLen + 1);
318 if (snprintf_s(text.get(), sourceLen + 1, sourceLen + 1, "%s", source) < 0) {
319 TELEPHONY_LOGE("snprintf_s failed");
320 return;
321 }
322 if (!WriteBufferToFile(std::move(text), std::strlen(source) + 1, filePathNameText)) {
323 TELEPHONY_LOGE("file error.");
324 }
325 if (!MmsAddAttachment(encodeMsg, filePathNameText, "<content.text>", "text/plain", false)) {
326 TELEPHONY_LOGE("MmsAddAttachment text fail");
327 }
328 uint32_t len = 0;
329 std::unique_ptr<char[]> results = encodeMsg.EncodeMsg(len);
330 if (results == nullptr) {
331 TELEPHONY_LOGE("encode fail result nullptr !!!!");
332 }
333 if (!WriteBufferToFile(std::move(results), len, MMS_FILE_ADDRESS)) {
334 TELEPHONY_LOGE("Encode write to file error.");
335 }
336 }
337
GetFileToDb()338 std::string GetFileToDb()
339 {
340 std::string mmsPdu;
341 GetMmsPduFromFile(MMS_FILE_ADDRESS, mmsPdu);
342 Uri uri(SMS_PROFILE_MMS_PDU_URI);
343 std::shared_ptr<MmsPersistHelper> mmsPersistHelper = std::make_shared<MmsPersistHelper>();
344 if (mmsPersistHelper == nullptr) {
345 return "";
346 }
347 std::shared_ptr<DataShare::DataShareHelper> helper = mmsPersistHelper->CreateSmsHelper();
348 if (helper == nullptr) {
349 return "";
350 }
351 std::vector<std::string> mmsPdus = SplitPdu(mmsPdu);
352 std::string dbUrl;
353 for (std::string mmsPdu : mmsPdus) {
354 DataShare::DataShareValuesBucket bucket;
355 bucket.Put(PDU_CONTENT, mmsPdu);
356 int32_t result = helper->Insert(uri, bucket);
357 if (result < 0) {
358 TELEPHONY_LOGE("mms pdu insert fail");
359 }
360 dbUrl += std::to_string(result) + ',';
361 }
362 helper->Release();
363 return dbUrl;
364 }
365
GetMmsc(int32_t slotId)366 std::string GetMmsc(int32_t slotId)
367 {
368 Uri pdpUri(PDP_PROFILE_NET_URI);
369 std::vector<std::string> colume;
370 DataShare::DataSharePredicates predicates;
371 std::u16string operatorNumeric;
372 CoreServiceClient::GetInstance().GetSimOperatorNumeric(slotId, operatorNumeric);
373 std::string mccmnc = StringUtils::ToUtf8(operatorNumeric);
374 predicates.EqualTo(PdpProfileData::MCCMNC, mccmnc);
375 std::shared_ptr<MmsApnInfo> mmsApnInfo = std::make_shared<MmsApnInfo>(slotId);
376 auto pdpHelper = mmsApnInfo->CreatePdpProfileHelper();
377 if (pdpHelper == nullptr) {
378 return "";
379 }
380 auto resultSet = pdpHelper->Query(pdpUri, predicates, colume);
381 if (resultSet == nullptr) {
382 pdpHelper->Release();
383 return "";
384 }
385 int count;
386 resultSet->GetRowCount(count);
387 if (count <= 0) {
388 resultSet->Close();
389 pdpHelper->Release();
390 return "";
391 }
392 std::string homeUrlVal;
393 std::string mmsIPAddressVal;
394 if (!mmsApnInfo->GetMmsApnValue(resultSet, count, homeUrlVal, mmsIPAddressVal)) {
395 TELEPHONY_LOGI("homeUrlVal and mmsIPAddressVal not matched");
396 resultSet->Close();
397 pdpHelper->Release();
398 return "";
399 }
400 resultSet->Close();
401 pdpHelper->Release();
402 return homeUrlVal;
403 }
404
405 /**
406 * @tc.number Telephony_SmsMmsGtest_Receive_Wap_Push_0001
407 * @tc.name Receive a Wap Push
408 * @tc.desc Function test
409 */
410 HWTEST_F(MmsGtest, Receive_Wap_Push_0001, Function | MediumTest | Level2)
411 {
412 AccessMmsToken token;
413 TELEPHONY_LOGI("TelSMSMMSTest::Receive_Wap_Push_0001 -->");
414 int32_t slotId = DEFAULT_SIM_SLOT_ID;
415 if (!(MmsGtest::HasSimCard(slotId))) {
416 TELEPHONY_LOGI("TelephonyTestService has no sim card");
417 ASSERT_TRUE(true);
418 return;
419 }
420 SmsMmsTestHelper helper;
421 helper.slotId = slotId;
422
423 EventFwk::MatchingSkills matchingSkills;
424 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SMS_WAPPUSH_RECEIVE_COMPLETED);
425 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
426 std::shared_ptr<SmsBroadcastSubscriberGtest> subscriberTest =
427 std::make_shared<SmsBroadcastSubscriberGtest>(subscriberInfo, helper);
428 if (subscriberTest == nullptr) {
429 ASSERT_TRUE(false);
430 return;
431 }
432 bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberTest);
433 TELEPHONY_LOGI("subscribeResult is : %{public}d", subscribeResult);
434
435 if (!helper.Run(ReceiveWapPushTestFunc, helper)) {
436 TELEPHONY_LOGI("ReceiveWapPushTestFunc out of time");
437 ASSERT_TRUE(true);
438 return;
439 }
440 TELEPHONY_LOGI("TelSMSMMSTest::Receive_Wap_Push_0001 -->finished");
441 EXPECT_TRUE(helper.GetBoolResult());
442 }
443
444 /**
445 * @tc.number Telephony_SmsMmsGtest_Receive_Wap_Push_0002
446 * @tc.name Receive a Wap Push
447 * @tc.desc Function test
448 */
449 HWTEST_F(MmsGtest, Receive_Wap_Push_0002, Function | MediumTest | Level2)
450 {
451 AccessMmsToken token;
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