• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "short_message_test.h"
17 
18 #include <iostream>
19 
20 #include "string_utils.h"
21 
22 namespace OHOS {
23 namespace Telephony {
24 using namespace OHOS::Telephony;
25 std::unique_ptr<ShortMessage> ShortMessageTest::shortMessage_ = nullptr;
26 
TestCreateMessage() const27 void ShortMessageTest::TestCreateMessage() const
28 {
29     std::vector<unsigned char> pdu =
30         StringUtils::HexToByteVector("0891683108200075F4240D91688129562983F600001240800102142302C130");
31 
32     ShortMessage *message = new ShortMessage();
33     if (message == nullptr) {
34         std::cout << "message is nullptr!" << std::endl;
35         return;
36     }
37     ShortMessage::CreateMessage(pdu, u"3gpp", *message);
38     shortMessage_ = std::unique_ptr<ShortMessage>(message);
39     if (shortMessage_ == nullptr) {
40         std::cout << "TestCreateMessage fail!!!" << std::endl;
41     } else {
42         std::cout << "TestCreateMessage success!!!" << std::endl;
43     }
44 }
45 
Test3Gpp2CreateMessage() const46 void ShortMessageTest::Test3Gpp2CreateMessage() const
47 {
48     std::vector<unsigned char> pdu = StringUtils::HexToByteVector(
49         "0000021002020702c6049064c4d40601fc081b00031000200106102e8cbb366f03061409011126310a01400d0101");
50     ShortMessage *message = new ShortMessage();
51     if (message == nullptr) {
52         std::cout << "message is nullptr!" << std::endl;
53         return;
54     }
55     ShortMessage::CreateMessage(pdu, u"3gpp2", *message);
56     shortMessage_ = std::unique_ptr<ShortMessage>(message);
57     if (shortMessage_ == nullptr) {
58         std::cout << "TestCreateMessage Cdma fail!!!" << std::endl;
59     } else {
60         std::cout << "TestCreateMessage Cdma success!!!" << std::endl;
61     }
62 }
63 
TestGetVisibleMessageBody() const64 void ShortMessageTest::TestGetVisibleMessageBody() const
65 {
66     if (shortMessage_ == nullptr) {
67         std::cout << "please create a short message!" << std::endl;
68         return;
69     }
70     std::cout << "GetVisibleMessageBody = " << StringUtils::ToUtf8(shortMessage_->GetVisibleMessageBody())
71               << std::endl;
72 }
73 
TestShowShortMessage() const74 void ShortMessageTest::TestShowShortMessage() const
75 {
76     if (shortMessage_ == nullptr) {
77         std::cout << "please create a short message!" << std::endl;
78         return;
79     }
80     std::u16string smscAddress;
81     shortMessage_->GetScAddress(smscAddress);
82     std::cout << "GetSmscAddr = " << StringUtils::ToUtf8(smscAddress) << std::endl;
83     std::cout << "GetVisibleMessageBody = " << StringUtils::ToUtf8(shortMessage_->GetVisibleMessageBody())
84               << std::endl;
85     std::cout << "GetVisibleRawAddress = " << StringUtils::ToUtf8(shortMessage_->GetVisibleRawAddress())
86               << std::endl;
87     int64_t time = shortMessage_->GetScTimestamp();
88     std::cout << "GetScTimestamp = " << ctime(static_cast<time_t *>(&(time)));
89     std::cout << "GetProtocolId = " << shortMessage_->GetProtocolId() << std::endl;
90     std::cout << "GetStatus = " << shortMessage_->GetStatus() << std::endl;
91     std::cout << "GetMessageClass = " << shortMessage_->GetMessageClass() << std::endl;
92     std::cout << "HasReplyPath = " << shortMessage_->HasReplyPath() << std::endl;
93     std::cout << "IsSmsStatusReportMessage = " << shortMessage_->IsSmsStatusReportMessage() << std::endl;
94     std::cout << "IsReplaceMessage = " << shortMessage_->IsReplaceMessage() << std::endl;
95     std::cout << "HasReplyPath = " << shortMessage_->HasReplyPath() << std::endl;
96     std::cout << "raw pdu = " << StringUtils::StringToHex(shortMessage_->GetPdu()) << std::endl;
97 }
98 } // namespace Telephony
99 } // namespace OHOS