1 /*
2 * Copyright (C) 2021 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 #include "mms_msg_test.h"
16
17 #include <iostream>
18 #include <sstream>
19
20 #include "mms_codec_type.h"
21
22 namespace OHOS {
23 namespace Telephony {
24 static constexpr char HEX_TABLE[] = "0123456789ABCDEF";
25 static constexpr uint8_t HEX_OFFSET = 4;
26 static constexpr uint8_t MAX_LINE_NUM = 16;
27
MmsMsgTest()28 MmsMsgTest::MmsMsgTest() {}
29
~MmsMsgTest()30 MmsMsgTest::~MmsMsgTest() {}
31
ProcessDecodeInput(int inputCMD) const32 void MmsMsgTest::ProcessDecodeInput(int inputCMD) const
33 {
34 switch (inputCMD) {
35 case 0x00:
36 MmsDecodeTest("/data/telephony/deSrc/SendReq.mms");
37 break;
38 case 0x01:
39 MmsDecodeTest("/data/telephony/deSrc/SendConf.mms");
40 break;
41 case 0x02:
42 MmsDecodeTest("/data/telephony/deSrc/NotificationInd.mms");
43 break;
44 case 0x03:
45 MmsDecodeTest("/data/telephony/deSrc/NotifyRespInd.mms");
46 break;
47 case 0x04:
48 MmsDecodeTest("/data/telephony/deSrc/RetrieveConf.mms");
49 break;
50 case 0x05:
51 MmsDecodeTest("/data/telephony/deSrc/AcknowledgeInd.mms");
52 break;
53 case 0x06:
54 MmsDecodeTest("/data/telephony/deSrc/DeliveryInd.mms");
55 break;
56 case 0x07:
57 MmsDecodeTest("/data/telephony/deSrc/ReadRecInd.mms");
58 break;
59 case 0x08:
60 MmsDecodeTest("/data/telephony/deSrc/ReadOrigInd.mms");
61 break;
62 default:
63 break;
64 }
65 }
66
ProcessEncodeInput(int inputCMD) const67 void MmsMsgTest::ProcessEncodeInput(int inputCMD) const
68 {
69 switch (inputCMD) {
70 case 0x09:
71 MmsSendReqEncodeTest();
72 break;
73 case 0x0a:
74 MmsSendConfEncodeTest();
75 break;
76 case 0x0b:
77 MmsNotificationIndEncodeTest();
78 break;
79 case 0x0c:
80 MmsNotifyRespIndEncodeTest();
81 break;
82 case 0x0d:
83 MmsRetrieveConfEncodeTest();
84 break;
85 case 0x0e:
86 MmsAcknowledgeIndEncodeTest();
87 break;
88 case 0x0f:
89 MmsDeliveryIndEncodeTest();
90 break;
91 case 0x10:
92 MmsReadRecIndEncodeTest();
93 break;
94 case 0x11:
95 MmsReadOrigIndEncodeTest();
96 break;
97 default:
98 break;
99 }
100 }
101
ProcessTest() const102 void MmsMsgTest::ProcessTest() const
103 {
104 bool loopFlag = true;
105 const int exitKey = 100;
106 while (loopFlag) {
107 std::cout << "\nusage:please input a cmd num:\n"
108 "0:TestDecodeMmsSendReq\n"
109 "1:TestDecodeMmsSendConf\n"
110 "2:TestDecodeMmsNotificationInd\r\n"
111 "3:TestDecodeMmsNotifyRespInd\r\n"
112 "4:TestDecodeMmsRetrieveConf\r\n"
113 "5:TestDecodeMmsAcknowledgeInd\r\n"
114 "6:TestDecodeMmsDeliveryInd\r\n"
115 "7:TestDecodeMmsReadRecInd\r\n"
116 "8:TestDecodeMmsReadOrigInd\r\n"
117 "9:TestEncodeMmsSendReq\r\n"
118 "10:TestEncodeMmsSendConf\r\n"
119 "11:TestEncodeMmsNotificationInd\r\n"
120 "12:TestEncodeMmsNotifyRespInd\r\n"
121 "13:TestEncodeMmsRetrieveConf\r\n"
122 "14:TestEncodeMmsAcknowledgeInd\r\n"
123 "15:TestEncodeMmsDeliveryInd\r\n"
124 "16:TestEncodeMmsReadRecInd\r\n"
125 "17:TestEncodeMmsReadOrigInd\r\n"
126 "100:exit test mms msg\n"
127 << std::endl;
128
129 int inputCMD = 0;
130 std::cin >> inputCMD;
131 while (std::cin.fail()) {
132 std::cin.clear();
133 std::cin.ignore();
134 std::cin >> inputCMD;
135 }
136 if (inputCMD == exitKey) {
137 return;
138 }
139 std::cout << "inputCMD is:" << inputCMD << std::endl;
140 ProcessDecodeInput(inputCMD);
141 ProcessEncodeInput(inputCMD);
142 }
143 }
144
MmsDecodeTest(std::string strPath) const145 void MmsMsgTest::MmsDecodeTest(std::string strPath) const
146 {
147 MmsMsg decodeMsg;
148 if (!decodeMsg.DecodeMsg(strPath)) {
149 std::cout << "mms decode message fail." << std::endl;
150 std::cout << "mms file path name:" << strPath << std::endl;
151 return;
152 }
153 decodeMsg.DumpMms();
154 uint8_t messageType = decodeMsg.GetMmsMessageType();
155 switch (messageType) {
156 case MMS_MSGTYPE_SEND_REQ:
157 MmsSendReqDecodeTest(decodeMsg);
158 break;
159 case MMS_MSGTYPE_SEND_CONF:
160 MmsSendConfDecodeTest(decodeMsg);
161 break;
162 case MMS_MSGTYPE_NOTIFICATION_IND:
163 MmsNotificationIndDecodeTest(decodeMsg);
164 break;
165 case MMS_MSGTYPE_NOTIFYRESP_IND:
166 MmsNotifyRespIndDecodeTest(decodeMsg);
167 break;
168 case MMS_MSGTYPE_RETRIEVE_CONF:
169 MmsRetrieveConfDecodeTest(decodeMsg);
170 break;
171 case MMS_MSGTYPE_ACKNOWLEDGE_IND:
172 MmsAcknowledgeIndDecodeTest(decodeMsg);
173 break;
174 case MMS_MSGTYPE_DELIVERY_IND:
175 MmsDeliveryIndDecodeTest(decodeMsg);
176 break;
177 case MMS_MSGTYPE_READ_REC_IND:
178 MmsReadRecIndDecodeTest(decodeMsg);
179 break;
180 case MMS_MSGTYPE_READ_ORIG_IND:
181 MmsReadOrigIndDecodeTest(decodeMsg);
182 break;
183 default:
184 break;
185 }
186 }
187
MmsSendReqEncodeTest() const188 void MmsMsgTest::MmsSendReqEncodeTest() const
189 {
190 std::cout << "Start MmsSendReqEncodeTest" << std::endl;
191 MmsMsg encodeMsg;
192 // Mandatory
193 if (!encodeMsg.SetMmsMessageType(MMS_MSGTYPE_SEND_REQ)) {
194 std::cout << "SetMmsMessageType fail" << std::endl;
195 return;
196 }
197 if (!encodeMsg.SetMmsTransactionId("2077.1427358451410")) {
198 std::cout << "SetMmsTransactionId fail" << std::endl;
199 return;
200 }
201 if (!encodeMsg.SetMmsVersion(static_cast<uint16_t>(MmsVersionType::MMS_VERSION_1_2))) {
202 std::cout << "SetMmsVersion fail" << std::endl;
203 return;
204 }
205 MmsAddress address;
206 address.SetMmsAddressString("+8613812345678/TYPE=PLMN");
207 if (!encodeMsg.SetMmsFrom(address)) {
208 std::cout << "SetMmsFrom fail" << std::endl;
209 return;
210 }
211 if (!encodeMsg.SetHeaderContentType("application/vnd.wap.multipart.related")) {
212 std::cout << "SetHeaderContentType fail" << std::endl;
213 return;
214 }
215 // Optional
216 if (!encodeMsg.SetMmsSubject("Test mms")) {
217 std::cout << "SetMmsSubject fail" << std::endl;
218 return;
219 }
220 if (!encodeMsg.SetHeaderOctetValue(MMS_CONTENT_CLASS, static_cast<uint8_t>(MmsContentClass::MMS_TEXT))) {
221 std::cout << "SetHeaderOctetValue MMS_CONTENT_CLASS fail" << std::endl;
222 return;
223 }
224 std::vector<MmsAddress> vecAddrs;
225 MmsAddress toAddrs("+8613888888888/TYPE=PLMN");
226 vecAddrs.push_back(toAddrs);
227 MmsAddress toAddrs2("+8613812345678/TYPE=PLMN");
228 vecAddrs.push_back(toAddrs2);
229 if (!encodeMsg.SetMmsTo(vecAddrs)) {
230 std::cout << "SetMmsTo fail" << std::endl;
231 return;
232 }
233 // add smil file
234 const std::string filePathNameSmil = "/data/telephony/enSrc/618C0A89.smil";
235 if (!MmsAddAttachment(encodeMsg, filePathNameSmil, "<0000>", "application/smil", true)) {
236 std::cout << "MmsAddAttachment smil fail" << std::endl;
237 return;
238 }
239 // add text file
240 const std::string filePathNameText = "/data/telephony/enSrc/content.text";
241 if (!MmsAddAttachment(encodeMsg, filePathNameText, "<content.text>", "text/plain", false)) {
242 std::cout << "MmsAddAttachment text fail" << std::endl;
243 return;
244 }
245 // add image file
246 const std::string filePathNameGif = "/data/telephony/enSrc/picture.gif";
247 if (!MmsAddAttachment(encodeMsg, filePathNameGif, "<picture.gif>", "image/gif", false)) {
248 std::cout << "MmsAddAttachment gif fail" << std::endl;
249 return;
250 }
251 uint32_t len = 0;
252 std::unique_ptr<char[]> result = encodeMsg.EncodeMsg(len);
253 if (result == nullptr) {
254 std::cout << "encode fail result nullptr error." << std::endl;
255 return;
256 }
257 if (!WriteBufferToFile(std::move(result), len, "/data/telephony/deSrc/SendReq.mms")) {
258 std::cout << "Encode write to file error." << std::endl;
259 return;
260 }
261 std::cout << "MmsSendReqEncodeTest encode success, data len = " << len << std::endl;
262 }
263
MmsSendConfEncodeTest() const264 void MmsMsgTest::MmsSendConfEncodeTest() const
265 {
266 std::cout << "Start MmsSendConfEncodeTest" << std::endl;
267 MmsMsg encodeMsg;
268 // Mandatory
269 if (!encodeMsg.SetMmsMessageType(MMS_MSGTYPE_SEND_CONF)) {
270 std::cout << "SetMmsMessageType fail" << std::endl;
271 return;
272 }
273 if (!encodeMsg.SetMmsTransactionId("2077.1427358451410")) {
274 std::cout << "SetMmsTransactionId fail" << std::endl;
275 return;
276 }
277 if (!encodeMsg.SetMmsVersion(static_cast<uint16_t>(MmsVersionType::MMS_VERSION_1_2))) {
278 std::cout << "SetMmsVersion fail" << std::endl;
279 return;
280 }
281 if (!encodeMsg.SetHeaderOctetValue(MMS_RESPONSE_STATUS, static_cast<uint8_t>(MmsResponseStatus::MMS_OK))) {
282 std::cout << "SetHeaderOctetValue MMS_RESPONSE_STATUS fail" << std::endl;
283 return;
284 }
285 uint32_t len = 0;
286 std::unique_ptr<char[]> result = encodeMsg.EncodeMsg(len);
287 if (result == nullptr) {
288 std::cout << "encode fail result nullptr error." << std::endl;
289 return;
290 }
291 if (!WriteBufferToFile(std::move(result), len, "/data/telephony/deSrc/SendConf.mms")) {
292 std::cout << "Encode write to file error." << std::endl;
293 return;
294 }
295 std::cout << "MmsSendConfEncodeTest encode success, data len =" << len << std::endl;
296 }
297
MmsNotificationIndEncodeTest() const298 void MmsMsgTest::MmsNotificationIndEncodeTest() const
299 {
300 std::cout << "Start MmsNotificationIndEncodeTest" << std::endl;
301 const long expiryTemp = 1637141707;
302 const long messageSize = 12345678;
303 MmsMsg encodeMsg;
304 // Mandatory
305 if (!encodeMsg.SetMmsMessageType(MMS_MSGTYPE_NOTIFICATION_IND)) {
306 std::cout << "SetMmsMessageType fail" << std::endl;
307 return;
308 }
309 if (!encodeMsg.SetMmsTransactionId("2077.1427358451410")) {
310 std::cout << "SetMmsTransactionId fail" << std::endl;
311 return;
312 }
313 if (!encodeMsg.SetMmsVersion(static_cast<uint16_t>(MmsVersionType::MMS_VERSION_1_2))) {
314 std::cout << "SetMmsVersion fail" << std::endl;
315 return;
316 }
317 if (!encodeMsg.SetHeaderOctetValue(MMS_MESSAGE_CLASS, static_cast<uint8_t>(MmsMessageClass::PERSONAL))) {
318 std::cout << "SetHeaderOctetValue fail" << std::endl;
319 return;
320 }
321 if (!encodeMsg.SetHeaderLongValue(MMS_EXPIRY, expiryTemp)) {
322 std::cout << "SetHeaderLongValue MMS_EXPIRY fail" << std::endl;
323 return;
324 }
325 if (!encodeMsg.SetHeaderLongValue(MMS_MESSAGE_SIZE, messageSize)) {
326 std::cout << "SetHeaderLongValue MMS_MESSAGE_SIZE fail" << std::endl;
327 return;
328 }
329 std::string strContentLocation = "Test";
330 if (!encodeMsg.SetHeaderStringValue(MMS_CONTENT_LOCATION, strContentLocation)) {
331 std::cout << "SetHeaderStringValue fail" << std::endl;
332 return;
333 } // need to confirmation
334 // Optional
335 MmsAddress address;
336 address.SetMmsAddressString("+8613812345678/TYPE=PLMN");
337 if (!encodeMsg.SetMmsFrom(address)) {
338 std::cout << "SetMmsFrom fail" << std::endl;
339 return;
340 }
341 if (!encodeMsg.SetMmsSubject("Test mms")) {
342 std::cout << "SetMmsSubject fail" << std::endl;
343 return;
344 }
345 uint32_t len = 0;
346 std::unique_ptr<char[]> result = encodeMsg.EncodeMsg(len);
347 if (result == nullptr) {
348 std::cout << "encode fail result nullptr error." << std::endl;
349 return;
350 }
351 if (!WriteBufferToFile(std::move(result), len, "/data/telephony/deSrc/NotificationInd.mms")) {
352 std::cout << "Encode write to file error." << std::endl;
353 return;
354 }
355 std::cout << "MmsNotificationIndEncodeTest encode success, data len =" << len << std::endl;
356 }
357
MmsNotifyRespIndEncodeTest() const358 void MmsMsgTest::MmsNotifyRespIndEncodeTest() const
359 {
360 std::cout << "Start MmsNotifyRespIndEncodeTest" << std::endl;
361 MmsMsg encodeMsg;
362 // Mandatory
363 if (!encodeMsg.SetMmsMessageType(MMS_MSGTYPE_NOTIFYRESP_IND)) {
364 std::cout << "SetMmsMessageType fail" << std::endl;
365 return;
366 }
367 if (!encodeMsg.SetMmsTransactionId("2077.1427358451410")) {
368 std::cout << "SetMmsTransactionId fail" << std::endl;
369 return;
370 }
371 if (!encodeMsg.SetMmsVersion(static_cast<uint16_t>(MmsVersionType::MMS_VERSION_1_2))) {
372 std::cout << "SetMmsVersion fail" << std::endl;
373 return;
374 }
375 if (!encodeMsg.SetHeaderOctetValue(MMS_STATUS, static_cast<uint8_t>(MmsStatus::MMS_EXPIRED))) {
376 std::cout << "SetHeaderOctetValue MMS_STATUS fail" << std::endl;
377 return;
378 }
379 uint32_t len = 0;
380 std::unique_ptr<char[]> result = encodeMsg.EncodeMsg(len);
381 if (result == nullptr) {
382 std::cout << "encode fail result nullptr error." << std::endl;
383 return;
384 }
385 if (!WriteBufferToFile(std::move(result), len, "/data/telephony/deSrc/NotifyRespInd.mms")) {
386 std::cout << "Encode write to file error." << std::endl;
387 return;
388 }
389 std::cout << "MmsNotifyRespIndEncodeTest encode success, data len =" << len << std::endl;
390 }
391
MmsRetrieveConfEncodeTest() const392 void MmsMsgTest::MmsRetrieveConfEncodeTest() const
393 {
394 std::cout << "Start MmsRetrieveConfEncodeTest" << std::endl;
395 MmsMsg encodeMsg;
396 // Mandatory
397 if (!encodeMsg.SetMmsMessageType(MMS_MSGTYPE_RETRIEVE_CONF)) {
398 std::cout << "SetMmsMessageType fail" << std::endl;
399 return;
400 }
401 if (!encodeMsg.SetMmsTransactionId("2077.1427358451410")) {
402 std::cout << "SetMmsTransactionId fail" << std::endl;
403 return;
404 }
405 if (!encodeMsg.SetMmsVersion(static_cast<uint16_t>(MmsVersionType::MMS_VERSION_1_2))) {
406 std::cout << "SetMmsVersion fail" << std::endl;
407 return;
408 }
409 const long dateTemp = 1637141707;
410 if (!encodeMsg.SetMmsDate(dateTemp)) {
411 std::cout << "SetMmsDate fail" << std::endl;
412 return;
413 }
414 if (!encodeMsg.SetHeaderContentType("application/vnd.wap.multipart.related")) {
415 std::cout << "SetHeaderContentType fail" << std::endl;
416 return;
417 }
418
419 // Optional
420 MmsAddress address;
421 address.SetMmsAddressString("+8613812345678/TYPE=PLMN");
422 if (!encodeMsg.SetMmsFrom(address)) {
423 std::cout << "SetMmsFrom fail" << std::endl;
424 return;
425 }
426 if (!encodeMsg.SetMmsSubject("Test mms")) {
427 std::cout << "SetMmsSubject fail" << std::endl;
428 return;
429 }
430 // add smil file
431 const std::string filePathNameSmil = "/data/telephony/enSrc/618C0A89.smil";
432 if (!MmsAddAttachment(encodeMsg, filePathNameSmil, "<0000>", "application/smil", true)) {
433 std::cout << "MmsAddAttachment smil fail" << std::endl;
434 return;
435 }
436 // add text file
437 const std::string filePathNameText = "/data/telephony/enSrc/content.text";
438 if (!MmsAddAttachment(encodeMsg, filePathNameText, "<content.text>", "text/plain", false)) {
439 std::cout << "MmsAddAttachment text fail" << std::endl;
440 return;
441 }
442 // add image file
443 const std::string filePathNameGif("/data/telephony/enSrc/picture.gif");
444 if (!MmsAddAttachment(encodeMsg, filePathNameGif, "picture.gif", "image/gif", false)) {
445 std::cout << "MmsAddAttachment gif fail" << std::endl;
446 return;
447 }
448 uint32_t len = 0;
449 std::unique_ptr<char[]> result = encodeMsg.EncodeMsg(len);
450 if (result == nullptr) {
451 std::cout << "encode fail result nullptr error." << std::endl;
452 return;
453 }
454 if (!WriteBufferToFile(std::move(result), len, "/data/telephony/deSrc/RetrieveConf.mms")) {
455 std::cout << "Encode write to file error." << std::endl;
456 return;
457 }
458 std::cout << "MmsRetrieveConfEncodeTest encode success, data len =" << len << std::endl;
459 }
460
MmsAcknowledgeIndEncodeTest() const461 void MmsMsgTest::MmsAcknowledgeIndEncodeTest() const
462 {
463 std::cout << "Start MmsAcknowledgeIndEncodeTest" << std::endl;
464 MmsMsg encodeMsg;
465 // Mandatory
466 if (!encodeMsg.SetMmsMessageType(MMS_MSGTYPE_ACKNOWLEDGE_IND)) {
467 std::cout << "SetMmsMessageType fail" << std::endl;
468 return;
469 }
470 if (!encodeMsg.SetMmsTransactionId("2077.1427358451410")) {
471 std::cout << "SetMmsTransactionId fail" << std::endl;
472 return;
473 }
474 if (!encodeMsg.SetMmsVersion(static_cast<uint16_t>(MmsVersionType::MMS_VERSION_1_2))) {
475 std::cout << "SetMmsVersion fail" << std::endl;
476 return;
477 }
478 uint32_t len = 0;
479 std::unique_ptr<char[]> result = encodeMsg.EncodeMsg(len);
480 if (result == nullptr) {
481 std::cout << "encode fail result nullptr error." << std::endl;
482 return;
483 }
484 if (!WriteBufferToFile(std::move(result), len, "/data/telephony/deSrc/AcknowledgeInd.mms")) {
485 std::cout << "Encode write to file error." << std::endl;
486 return;
487 }
488 std::cout << "MmsAcknowledgeIndEncodeTest encode success, data len =" << len << std::endl;
489 }
490
MmsDeliveryIndEncodeTest() const491 void MmsMsgTest::MmsDeliveryIndEncodeTest() const
492 {
493 std::cout << "Start MmsDeliveryIndEncodeTest" << std::endl;
494 MmsMsg encodeMsg;
495 // Mandatory
496 if (!encodeMsg.SetMmsMessageType(MMS_MSGTYPE_DELIVERY_IND)) {
497 std::cout << "SetMmsMessageType fail" << std::endl;
498 return;
499 }
500 if (!encodeMsg.SetMmsTransactionId("2077.1427358451410")) {
501 std::cout << "SetMmsTransactionId fail" << std::endl;
502 return;
503 }
504 if (!encodeMsg.SetMmsVersion(static_cast<uint16_t>(MmsVersionType::MMS_VERSION_1_2))) {
505 std::cout << "SetMmsVersion fail" << std::endl;
506 return;
507 }
508 std::string strMessageID = "0001";
509 if (!encodeMsg.SetHeaderStringValue(MMS_MESSAGE_ID, strMessageID)) {
510 std::cout << "SetHeaderStringValue fail" << std::endl;
511 return;
512 }
513 const long dateTemp = 1637141707;
514 if (!encodeMsg.SetMmsDate(dateTemp)) {
515 std::cout << "SetMmsDate fail" << std::endl;
516 return;
517 }
518 std::vector<MmsAddress> vecAddrs;
519 MmsAddress toAddrs("+8613888888888/TYPE=PLMN");
520 vecAddrs.push_back(toAddrs);
521 if (!encodeMsg.SetMmsTo(vecAddrs)) {
522 std::cout << "SetMmsTo fail" << std::endl;
523 return;
524 }
525 if (!encodeMsg.SetHeaderOctetValue(MMS_STATUS, static_cast<uint8_t>(MmsStatus::MMS_EXPIRED))) {
526 std::cout << "SetHeaderOctetValue MMS_STATUS fail" << std::endl;
527 return;
528 }
529 uint32_t len = 0;
530 std::unique_ptr<char[]> result = encodeMsg.EncodeMsg(len);
531 if (result == nullptr) {
532 std::cout << "encode fail result nullptr error." << std::endl;
533 return;
534 }
535 if (!WriteBufferToFile(std::move(result), len, "/data/telephony/deSrc/DeliveryInd.mms")) {
536 std::cout << "Encode write to file error." << std::endl;
537 return;
538 }
539 std::cout << "MmsDeliveryIndEncodeTest encode success, data len =" << len << std::endl;
540 }
541
MmsReadRecIndEncodeTest() const542 void MmsMsgTest::MmsReadRecIndEncodeTest() const
543 {
544 std::cout << "Start MmsReadRecIndEncodeTest" << std::endl;
545 MmsMsg encodeMsg;
546 // Mandatory
547 if (!encodeMsg.SetMmsMessageType(MMS_MSGTYPE_READ_REC_IND)) {
548 std::cout << "SetMmsMessageType fail" << std::endl;
549 return;
550 }
551 if (!encodeMsg.SetMmsVersion(static_cast<uint16_t>(MmsVersionType::MMS_VERSION_1_2))) {
552 std::cout << "SetMmsVersion fail" << std::endl;
553 return;
554 }
555 std::string strMessageID = "0001";
556 if (!encodeMsg.SetHeaderStringValue(MMS_MESSAGE_ID, strMessageID)) {
557 std::cout << "SetHeaderStringValue fail" << std::endl;
558 return;
559 }
560 std::vector<MmsAddress> vecAddrs;
561 MmsAddress toAddrs("+8613888888888/TYPE=PLMN");
562 vecAddrs.push_back(toAddrs);
563 if (!encodeMsg.SetMmsTo(vecAddrs)) {
564 std::cout << "SetMmsTo fail" << std::endl;
565 return;
566 }
567 MmsAddress address;
568 address.SetMmsAddressString("+8613812345678/TYPE=PLMN");
569 if (!encodeMsg.SetMmsFrom(address)) {
570 std::cout << "SetMmsFrom fail" << std::endl;
571 return;
572 }
573 if (!encodeMsg.SetHeaderOctetValue(MMS_READ_STATUS, static_cast<uint8_t>(MmsReadStatus::MMS_READ))) {
574 std::cout << "SetHeaderOctetValue MMS_READ_STATUS fail" << std::endl;
575 return;
576 }
577 // Optional
578 const long dateTemp = 1637141707;
579 encodeMsg.SetMmsDate(dateTemp);
580 uint32_t len = 0;
581 std::unique_ptr<char[]> result = encodeMsg.EncodeMsg(len);
582 if (result == nullptr) {
583 std::cout << "encode fail result nullptr error." << std::endl;
584 return;
585 }
586 if (!WriteBufferToFile(std::move(result), len, "/data/telephony/deSrc/ReadRecInd.mms")) {
587 std::cout << "Encode write to file error." << std::endl;
588 return;
589 }
590 std::cout << "MmsReadRecIndEncodeTest encode success data len =" << len << std::endl;
591 }
592
MmsReadOrigIndEncodeTest() const593 void MmsMsgTest::MmsReadOrigIndEncodeTest() const
594 {
595 std::cout << "Start MmsReadOrigIndEncodeTest" << std::endl;
596 MmsMsg encodeMsg;
597 // Mandatory
598 if (!encodeMsg.SetMmsMessageType(MMS_MSGTYPE_READ_ORIG_IND)) {
599 std::cout << "SetMmsMessageType fail" << std::endl;
600 return;
601 }
602 if (!encodeMsg.SetMmsVersion(static_cast<uint16_t>(MmsVersionType::MMS_VERSION_1_2))) {
603 std::cout << "SetMmsVersion fail" << std::endl;
604 return;
605 }
606 std::string strMessageID = "0001";
607 if (!encodeMsg.SetHeaderStringValue(MMS_MESSAGE_ID, strMessageID)) {
608 std::cout << "SetHeaderStringValue fail" << std::endl;
609 return;
610 }
611 std::vector<MmsAddress> vecAddrs;
612 MmsAddress toAddrs("+8613888888888/TYPE=PLMN");
613 vecAddrs.push_back(toAddrs);
614 if (!encodeMsg.SetMmsTo(vecAddrs)) {
615 std::cout << "SetMmsTo fail" << std::endl;
616 return;
617 }
618 MmsAddress address;
619 address.SetMmsAddressString("+8613812345678/TYPE=PLMN");
620 if (!encodeMsg.SetMmsFrom(address)) {
621 std::cout << "SetMmsFrom fail" << std::endl;
622 return;
623 }
624 const long dateTemp = 1637141707;
625 if (!encodeMsg.SetMmsDate(dateTemp)) {
626 std::cout << "SetMmsDate fail" << std::endl;
627 return;
628 }
629 if (!encodeMsg.SetHeaderOctetValue(MMS_READ_STATUS, static_cast<uint8_t>(MmsReadStatus::MMS_READ))) {
630 std::cout << "SetHeaderOctetValue MMS_READ_STATUS fail" << std::endl;
631 return;
632 }
633 // Optional
634 uint32_t len = 0;
635 std::unique_ptr<char[]> result = encodeMsg.EncodeMsg(len);
636 if (result == nullptr) {
637 std::cout << "encode fail result nullptr error." << std::endl;
638 return;
639 }
640 if (!WriteBufferToFile(std::move(result), len, "/data/telephony/deSrc/ReadOrigInd.mms")) {
641 std::cout << "Encode write to file error." << std::endl;
642 return;
643 }
644 std::cout << "MmsReadOrigIndEncodeTest encode success, data len =" << len << std::endl;
645 }
646
MmsAddAttachment(MmsMsg & msg,std::string pathName,std::string contentId,std::string contenType,bool isSmil) const647 bool MmsMsgTest::MmsAddAttachment(
648 MmsMsg &msg, std::string pathName, std::string contentId, std::string contenType, bool isSmil) const
649 {
650 MmsAttachment imageAttachment;
651 std::size_t pos = pathName.find_last_of('/');
652 std::string fileName(pathName.substr(pos + 1));
653
654 if (!imageAttachment.SetAttachmentFilePath(pathName, isSmil)) {
655 std::cout << "MmsAddAttachment SetAttachmentFilePath fail" << std::endl;
656 return false;
657 }
658 if (!imageAttachment.SetFileName(fileName)) {
659 std::cout << "MmsAddAttachment SetFileName fail" << std::endl;
660 return false;
661 }
662 if (!imageAttachment.SetContentId(contentId)) {
663 std::cout << "MmsAddAttachment SetContentId fail" << std::endl;
664 return false;
665 }
666 if (!imageAttachment.SetContentLocation(fileName)) {
667 std::cout << "MmsAddAttachment SetContentLocation fail" << std::endl;
668 return false;
669 }
670 if (!imageAttachment.SetContentType(contenType)) {
671 std::cout << "MmsAddAttachment SetContentType fail" << std::endl;
672 return false;
673 }
674 imageAttachment.SetContentDisposition("attachment");
675 if (!msg.AddAttachment(imageAttachment)) {
676 std::cout << "MmsAddAttachment AddAttachment fail" << std::endl;
677 return false;
678 }
679 return true;
680 }
681
MmsSendReqDecodeTest(MmsMsg & decodeMsg) const682 void MmsMsgTest::MmsSendReqDecodeTest(MmsMsg &decodeMsg) const
683 {
684 std::cout << "======= Start SendReqDecodeTest ===========" << std::endl;
685 // Mandatory
686 std::cout << "TransactionId: " << decodeMsg.GetMmsTransactionId() << std::endl;
687 std::cout << "Version: " << decodeMsg.GetMmsVersion() << std::endl;
688 std::cout << "Date: " << decodeMsg.GetMmsDate() << std::endl;
689 std::cout << "From: " << decodeMsg.GetMmsFrom().GetAddressString() << std::endl;
690 std::vector<MmsAddress> toAddress;
691 decodeMsg.GetMmsTo(toAddress);
692 for (auto itTo : toAddress) {
693 std::cout << "To: " << itTo.GetAddressString() << std::endl;
694 }
695 std::string deliverReport = std::to_string(decodeMsg.GetHeaderOctetValue(MMS_DELIVERY_REPORT));
696 std::string sendVisbility = std::to_string(decodeMsg.GetHeaderOctetValue(MMS_SENDER_VISIBILITY));
697 std::string readResport = std::to_string(decodeMsg.GetHeaderOctetValue(MMS_READ_REPORT));
698 std::string messageClass = std::to_string(decodeMsg.GetHeaderOctetValue(MMS_MESSAGE_CLASS));
699 std::string priority = std::to_string(decodeMsg.GetHeaderOctetValue(MMS_PRIORITY));
700
701 std::cout << "Subject: " << decodeMsg.GetMmsSubject() << std::endl;
702 std::cout << "DeliveryReport: " << deliverReport << std::endl;
703 std::cout << "SenderVisibility: " << sendVisbility << std::endl;
704 std::cout << "ReadReport: " << readResport << std::endl;
705 std::cout << "MessageClass: " << messageClass << std::endl;
706 std::cout << "Prioity: " << priority << std::endl;
707
708 std::vector<MmsAttachment> attachments;
709 decodeMsg.GetAllAttachment(attachments);
710 int attachmentCnt = 0;
711 for (auto it : attachments) {
712 std::cout << "=======part:" << attachmentCnt << " attachments infos ======" << std::endl;
713 std::cout << "ContentDisposition: " << it.GetContentDisposition() << std::endl;
714 std::cout << "ContentLocation: " << it.GetContentLocation() << std::endl;
715 std::cout << "ContentId: " << it.GetContentId() << std::endl;
716 std::cout << "FileName: " << it.GetFileName() << std::endl;
717 uint32_t len = 0;
718 std::unique_ptr<char[]> buff = it.GetDataBuffer(len);
719 if (buff != nullptr) {
720 std::cout << "attachments buffer size = " << len << std::endl;
721 }
722 std::cout << "=======part:" << attachmentCnt << " attachments infos ======" << std::endl;
723 attachmentCnt++;
724 }
725 std::cout << "======= End SendReqDecodeTest ===========" << std::endl;
726 }
727
MmsSendConfDecodeTest(MmsMsg & decodeMsg) const728 void MmsMsgTest::MmsSendConfDecodeTest(MmsMsg &decodeMsg) const
729 {
730 std::cout << "======== Start SendConfEncodeTest =============" << std::endl;
731 // Mandatory
732 std::cout << "TransactionId: " << decodeMsg.GetMmsTransactionId() << std::endl;
733 std::cout << "Version: " << decodeMsg.GetMmsVersion() << std::endl;
734 std::string responseStatus = std::to_string(decodeMsg.GetHeaderOctetValue(MMS_RESPONSE_STATUS));
735 std::cout << "ResponseStatus: " << responseStatus << std::endl;
736 std::cout << "======== End SendConfEncodeTest =============" << std::endl;
737 }
738
MmsNotificationIndDecodeTest(MmsMsg & decodeMsg) const739 void MmsMsgTest::MmsNotificationIndDecodeTest(MmsMsg &decodeMsg) const
740 {
741 std::cout << "========== Start NotificationIndDecodeTest ========" << std::endl;
742 // Mandatory
743 std::cout << "TransactionId: " << decodeMsg.GetMmsTransactionId() << std::endl;
744 std::cout << "Version: " << decodeMsg.GetMmsVersion() << std::endl;
745 std::cout << "MessageSize: " << decodeMsg.GetHeaderLongValue(MMS_MESSAGE_SIZE) << std::endl;
746 std::cout << "Expiry: " << decodeMsg.GetHeaderLongValue(MMS_EXPIRY) << std::endl;
747 std::cout << "ContentLocation: " << decodeMsg.GetHeaderStringValue(MMS_CONTENT_LOCATION) << std::endl;
748 std::cout << "========== End NotificationIndDecodeTest ========" << std::endl;
749 }
750
MmsNotifyRespIndDecodeTest(MmsMsg & decodeMsg) const751 void MmsMsgTest::MmsNotifyRespIndDecodeTest(MmsMsg &decodeMsg) const
752 {
753 std::cout << "========= Start NotifyRespIndDecodeTest ======" << std::endl;
754 // Mandatory
755 std::cout << "TransactionId: " << decodeMsg.GetMmsTransactionId() << std::endl;
756 std::cout << "Version: " << decodeMsg.GetMmsVersion() << std::endl;
757 std::string status = std::to_string(decodeMsg.GetHeaderOctetValue(MMS_STATUS));
758 std::cout << "Status: " << status << std::endl;
759 std::cout << "========= End NotifyRespIndDecodeTest ======" << std::endl;
760 }
761
MmsRetrieveConfDecodeTest(MmsMsg & decodeMsg) const762 void MmsMsgTest::MmsRetrieveConfDecodeTest(MmsMsg &decodeMsg) const
763 {
764 std::cout << "======== Start RetrieveConfDecodeTest =========" << std::endl;
765 // Mandatory
766 std::cout << "TransactionId: " << decodeMsg.GetMmsTransactionId() << std::endl;
767 std::cout << "Version: " << decodeMsg.GetMmsVersion() << std::endl;
768 std::cout << "Date: " << decodeMsg.GetMmsDate() << std::endl;
769
770 std::vector<MmsAttachment> attachments;
771 decodeMsg.GetAllAttachment(attachments);
772 int attachmentCnt = 0;
773 for (auto it : attachments) {
774 std::cout << "======= part:" << attachmentCnt << " attachments infos ======" << std::endl;
775 std::cout << "ContentDisposition: " << it.GetContentDisposition() << std::endl;
776 std::cout << "ContentLocation: " << it.GetContentLocation() << std::endl;
777 std::cout << "ContentId: " << it.GetContentId() << std::endl;
778 std::cout << "FileName: " << it.GetFileName() << std::endl;
779 uint32_t len = 0;
780 std::unique_ptr<char[]> buff = it.GetDataBuffer(len);
781 if (buff != nullptr) {
782 std::cout << "attachments buffer size = " << len << std::endl;
783 }
784 std::cout << "======= part:" << attachmentCnt << " attachments infos ======" << std::endl;
785 attachmentCnt++;
786 }
787 std::cout << "======== End RetrieveConfDecodeTest =========" << std::endl;
788 }
789
MmsAcknowledgeIndDecodeTest(MmsMsg & decodeMsg) const790 void MmsMsgTest::MmsAcknowledgeIndDecodeTest(MmsMsg &decodeMsg) const
791 {
792 std::cout << "======= Start AcknowledgeIndDecodeTest ========" << std::endl;
793 // Mandatory
794 std::cout << "TransactionId: " << decodeMsg.GetMmsTransactionId() << std::endl;
795 std::cout << "Version: " << decodeMsg.GetMmsVersion() << std::endl;
796 std::cout << "======= End AcknowledgeIndDecodeTest ========" << std::endl;
797 }
798
MmsDeliveryIndDecodeTest(MmsMsg & decodeMsg) const799 void MmsMsgTest::MmsDeliveryIndDecodeTest(MmsMsg &decodeMsg) const
800 {
801 std::cout << "======== Start DeliveryIndDecodeTest ==========" << std::endl;
802 // Mandatory
803 std::cout << "Version: " << decodeMsg.GetMmsVersion() << std::endl;
804 std::cout << "MessageID: " << decodeMsg.GetHeaderStringValue(MMS_MESSAGE_ID) << std::endl;
805 std::vector<MmsAddress> toAddress;
806 decodeMsg.GetMmsTo(toAddress);
807 for (auto itTo : toAddress) {
808 std::cout << "To: " << itTo.GetAddressString() << std::endl;
809 }
810 std::cout << "Date: " << decodeMsg.GetMmsDate() << std::endl;
811 std::string status = std::to_string(decodeMsg.GetHeaderOctetValue(MMS_STATUS));
812 std::cout << "Status: " << status << std::endl;
813 std::cout << "======== End DeliveryIndDecodeTest ==========" << std::endl;
814 }
815
MmsReadRecIndDecodeTest(MmsMsg & decodeMsg) const816 void MmsMsgTest::MmsReadRecIndDecodeTest(MmsMsg &decodeMsg) const
817 {
818 std::cout << "======= Start ReadRecIndDecodeTest =========" << std::endl;
819 // Mandatory
820 std::cout << "Version: " << decodeMsg.GetMmsVersion() << std::endl;
821 std::cout << "MessageID: " << decodeMsg.GetHeaderStringValue(MMS_MESSAGE_ID) << std::endl;
822 std::vector<MmsAddress> toAddress;
823 decodeMsg.GetMmsTo(toAddress);
824 for (auto itTo : toAddress) {
825 std::cout << "To: " << itTo.GetAddressString() << std::endl;
826 }
827 MmsAddress fromAddress = decodeMsg.GetMmsFrom();
828 std::cout << "From: " << fromAddress.GetAddressString() << std::endl;
829 std::cout << "Date: " << decodeMsg.GetMmsDate() << std::endl;
830 std::string status = std::to_string(decodeMsg.GetHeaderOctetValue(MMS_STATUS));
831 std::cout << "Status: " << status << std::endl;
832 std::cout << "======= End ReadRecIndDecodeTest =========" << std::endl;
833 }
834
MmsReadOrigIndDecodeTest(MmsMsg & decodeMsg) const835 void MmsMsgTest::MmsReadOrigIndDecodeTest(MmsMsg &decodeMsg) const
836 {
837 std::cout << "======== Start MmsReadOrigIndDecodeTest ========" << std::endl;
838 // Mandatory
839 std::cout << "Version: " << decodeMsg.GetMmsVersion() << std::endl;
840 std::cout << "MessageID: " << decodeMsg.GetHeaderStringValue(MMS_MESSAGE_ID) << std::endl;
841 std::vector<MmsAddress> toAddress;
842 decodeMsg.GetMmsTo(toAddress);
843 for (auto itTo : toAddress) {
844 std::cout << "To: " << itTo.GetAddressString() << std::endl;
845 }
846 MmsAddress fromAddress = decodeMsg.GetMmsFrom();
847 std::cout << "From: " << fromAddress.GetAddressString() << std::endl;
848 std::cout << "Date: " << decodeMsg.GetMmsDate() << std::endl;
849 std::string readStatus = std::to_string(decodeMsg.GetHeaderOctetValue(MMS_READ_STATUS));
850 std::cout << "ReadStatus: " << readStatus << std::endl;
851 std::cout << "======== End MmsReadOrigIndDecodeTest ========" << std::endl;
852 }
853
BuffToHex(const std::unique_ptr<char[]> & buff,uint32_t len) const854 std::string MmsMsgTest::BuffToHex(const std::unique_ptr<char[]> &buff, uint32_t len) const
855 {
856 std::stringstream ss;
857 for (std::size_t i = 0; i < len; ++i) {
858 unsigned char temp = static_cast<unsigned char>(buff[i]) >> HEX_OFFSET;
859 ss << "0x" << HEX_TABLE[temp] << HEX_TABLE[buff[i] & 0xf] << " ";
860 if ((i % MAX_LINE_NUM == 0) && (i != 0)) {
861 ss << "\r\n";
862 }
863 }
864 return ss.str();
865 }
866
WriteBufferToFile(const std::unique_ptr<char[]> & buff,uint32_t len,const std::string & strPathName) const867 bool MmsMsgTest::WriteBufferToFile(
868 const std::unique_ptr<char[]> &buff, uint32_t len, const std::string &strPathName) const
869 {
870 FILE *pFile = nullptr;
871 pFile = fopen(strPathName.c_str(), "wb");
872 if (!pFile || buff == nullptr) {
873 std::cout << "open file: " << strPathName << "fail!" << std::endl;
874 return false;
875 }
876 uint32_t fileLen = fwrite(buff.get(), len, 1, pFile);
877 if (fileLen > 0) {
878 std::cout << "write mms buffer to file success name:" << strPathName << std::endl;
879 } else {
880 std::cout << "write mms buffer to file error name:" << strPathName << std::endl;
881 }
882 (void)fclose(pFile);
883 return true;
884 }
885 } // namespace Telephony
886 } // namespace OHOS
887