• 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 "sms_cb_message_test.h"
17 
18 #include <iostream>
19 #include <vector>
20 
21 #include "cdma_sms_message.h"
22 #include "gsm_cb_codec.h"
23 
24 namespace OHOS {
25 namespace Telephony {
ProcessInput(int inputCMD,bool & loopFlag) const26 void SmsCbMessageTest::ProcessInput(int inputCMD, bool &loopFlag) const
27 {
28     std::cout << "inputCMD is:" << inputCMD << std::endl;
29     switch (inputCMD) {
30         case 0x00:
31             TestMessageBody7Bit();
32             break;
33         case 0x01:
34             TestMessageBody7BitUmts();
35             break;
36         case 0x02:
37             TestMessageBody8Bit();
38             break;
39         case 0x03:
40             TestMessageBodyUcs2();
41             break;
42         case 0x04:
43             TestMessageBodyUcs2Umts();
44             break;
45         case 0x05:
46             TestEtwsWarningType0();
47             break;
48         case 0x06:
49             TestEtwsWarningType1();
50             break;
51         case 0x07:
52             TestEtwsWarningType2();
53             break;
54         case 0x08:
55             TestEtwsWarningType3();
56             break;
57         case 0x09:
58             TestEtwsWarningType4();
59             break;
60         case 0x0A:
61             TestMessageBody7BitGs2();
62             break;
63         case 0x0B:
64             TestCdmaUserData();
65             break;
66         case 0x0C:
67             TestCdmaCmasType1();
68             break;
69         default:
70             loopFlag = false;
71             break;
72     }
73 }
74 
ProcessTest() const75 void SmsCbMessageTest::ProcessTest() const
76 {
77     bool loopFlag = true;
78     while (loopFlag) {
79         std::cout << "\n-----------start test cbmessage api--------------\n"
80                      "usage:please input a cmd num:\n"
81                      "0:TestMessageBody7Bit\n"
82                      "1:TestMessageBody7BitUmts\n"
83                      "2:TestMessageBody8Bit\r\n"
84                      "3:TestMessageBodyUcs2\r\n"
85                      "4:TestMessageBodyUcs2Umts\r\n"
86                      "5:TestEtwsWarningType0\r\n"
87                      "6:TestEtwsWarningType1\r\n"
88                      "7:TestEtwsWarningType2\r\n"
89                      "8:TestEtwsWarningType3\r\n"
90                      "9:TestEtwsWarningType4\r\n"
91                      "10:TestMessageBody7BitGs2\r\n"
92                      "11:TestCdmaUserData\r\n"
93                      "12:TestCdmaCmasType1\r\n"
94                      "Other key:exit \n"
95                   << std::endl;
96 
97         int inputCMD = 0;
98         std::cin >> inputCMD;
99         while (std::cin.fail()) {
100             std::cin.clear();
101             std::cin.ignore();
102             std::cin >> inputCMD;
103         }
104         ProcessInput(inputCMD, loopFlag);
105     }
106 }
107 
TestMessageBody7Bit() const108 void SmsCbMessageTest::TestMessageBody7Bit() const
109 {
110     std::string data(
111         "C0000032401174747A0E4ACF41E8B0BCFD76E741EF39685C66B34162F93B4C1"
112         "E87E77410BD3CA7836EC2341D440ED3C321");
113 
114     std::shared_ptr<GsmCbCodec> msg = GsmCbCodec::CreateCbMessage(data);
115     if (msg == nullptr) {
116         std::cout << "CreateCbMessage fail." << std::endl;
117     } else {
118         std::cout << "msginfo: " << msg->ToString() << std::endl;
119     }
120 }
121 
TestMessageBody7BitUmts() const122 void SmsCbMessageTest::TestMessageBody7BitUmts() const
123 {
124     std::string data(
125         "010032C000400174747A0E4ACF41E8B0BCFD76E741EF39685C66B3C5F277983"
126         "C0ECFE9207A794E07DD84693AA8EC1EBFC96550B54D9F83C8617A9845479741"
127         "37719A0EAAB7E973D038EC060DC372791ED47ECBCB2072981E0652");
128 
129     std::shared_ptr<GsmCbCodec> msg = GsmCbCodec::CreateCbMessage(data);
130     if (msg == nullptr) {
131         std::cout << "CreateCbMessage fail." << std::endl;
132     } else {
133         std::cout << "msginfo: " << msg->ToString() << std::endl;
134     }
135 }
136 
TestMessageBody8Bit() const137 void SmsCbMessageTest::TestMessageBody8Bit() const
138 {
139     std::string data(
140         "C0000032441174686973206973206861726D6F6E79206F732063656C6C20627"
141         "26F6164636173742074657374203842697420656E636F64652064617461");
142 
143     std::shared_ptr<GsmCbCodec> msg = GsmCbCodec::CreateCbMessage(data);
144     if (msg == nullptr) {
145         std::cout << "CreateCbMessage fail." << std::endl;
146     } else {
147         std::cout << "msginfo: " << msg->ToString() << std::endl;
148     }
149 }
150 
TestMessageBodyUcs2() const151 void SmsCbMessageTest::TestMessageBodyUcs2() const
152 {
153     std::string data(
154         "C00000324811006800610072006D006F006E00790020006F00730020005500"
155         "630073003200200065006E0063006F0064006500200064006100740061");
156 
157     std::shared_ptr<GsmCbCodec> msg = GsmCbCodec::CreateCbMessage(data);
158     if (msg == nullptr) {
159         std::cout << "CreateCbMessage fail." << std::endl;
160     } else {
161         std::cout << "msginfo: " << msg->ToString() << std::endl;
162     }
163 }
164 
TestMessageBodyUcs2Umts() const165 void SmsCbMessageTest::TestMessageBodyUcs2Umts() const
166 {
167     std::string data(
168         "01a41f51101102ea3030a830ea30a230e130fc30eb914d4fe130c630b930c8000"
169         "d000a3053308c306f8a669a137528306e30e130c330bb30fc30b8306730593002"
170         "000d000aff080032003000310033002f00310031002f003252ea3000370020003"
171         "10035003a00340034ff09000d000aff0830a830ea30a25e02ff09000000000000"
172         "00000000000000000000000000000000000000000000000000000000000000000"
173         "000000000000000000022");
174 
175     std::shared_ptr<GsmCbCodec> msg = GsmCbCodec::CreateCbMessage(data);
176     if (msg == nullptr) {
177         std::cout << "CreateCbMessage fail." << std::endl;
178     } else {
179         std::cout << "msginfo: " << msg->ToString() << std::endl;
180     }
181 }
182 
TestEtwsWarningType0() const183 void SmsCbMessageTest::TestEtwsWarningType0() const
184 {
185     std::string data(
186       "0000110011010D0A004800610072006D006F006E00790020004F007300200045007400"
187       "770073005700610072006E0069006E00670020004D0065007300730061006700650055"
188       "00630073003200200045006D00740073");
189     std::shared_ptr<GsmCbCodec> msg = GsmCbCodec::CreateCbMessage(data);
190     if (msg == nullptr) {
191         std::cout << "CreateCbMessage fail." << std::endl;
192     } else {
193         std::cout << "msginfo: " << msg->ToString() << std::endl;
194     }
195 }
196 
TestEtwsWarningType1() const197 void SmsCbMessageTest::TestEtwsWarningType1() const
198 {
199     std::string data(
200       "0000110111010D0A004800610072006D006F006E00790020004F007300200045007400"
201       "770073005700610072006E0069006E00670020004D0065007300730061006700650055"
202       "00630073003200200045006D00740073");
203 
204     std::shared_ptr<GsmCbCodec> msg = GsmCbCodec::CreateCbMessage(data);
205     if (msg == nullptr) {
206         std::cout << "CreateCbMessage fail." << std::endl;
207     } else {
208         std::cout << "msginfo: " << msg->ToString() << std::endl;
209     }
210 }
211 
TestEtwsWarningType2() const212 void SmsCbMessageTest::TestEtwsWarningType2() const
213 {
214     std::string data(
215       "0000110211010D0A004800610072006D006F006E00790020004F007300200045007400"
216       "770073005700610072006E0069006E00670020004D0065007300730061006700650055"
217       "00630073003200200045006D00740073");
218 
219     std::shared_ptr<GsmCbCodec> msg = GsmCbCodec::CreateCbMessage(data);
220     if (msg == nullptr) {
221         std::cout << "CreateCbMessage fail." << std::endl;
222     } else {
223         std::cout << "msginfo: " << msg->ToString() << std::endl;
224     }
225 }
226 
TestEtwsWarningType3() const227 void SmsCbMessageTest::TestEtwsWarningType3() const
228 {
229     std::string data(
230         "0000110311010D0A5BAE57CE770C531790E85C716CBF3044573065B93067573097"
231         "07300263FA308C306B5099304830664E0B30553044FF086C178C615E81FF090000"
232         "0000000000000000000000000000000000000000");
233     std::shared_ptr<GsmCbCodec> msg = GsmCbCodec::CreateCbMessage(data);
234     if (msg == nullptr) {
235         std::cout << "CreateCbMessage fail." << std::endl;
236     } else {
237         std::cout << "msginfo: " << msg->ToString() << std::endl;
238     }
239 }
240 
TestEtwsWarningType4() const241 void SmsCbMessageTest::TestEtwsWarningType4() const
242 {
243     std::string data(
244       "0000110411010D0A004800610072006D006F006E00790020004F007300200045007400"
245       "770073005700610072006E0069006E00670020004D0065007300730061006700650055"
246       "00630073003200200045006D00740073");
247 
248     std::shared_ptr<GsmCbCodec> msg = GsmCbCodec::CreateCbMessage(data);
249     if (msg == nullptr) {
250         std::cout << "CreateCbMessage fail." << std::endl;
251     } else {
252         std::cout << "msginfo: " << msg->ToString() << std::endl;
253     }
254 }
255 
TestMessageBody7BitGs2() const256 void SmsCbMessageTest::TestMessageBody7BitGs2() const
257 {
258     std::string data(
259         "80000032401174747A0E4ACF41E8B0BCFD76E741EF39685C66B34162F93B4C1"
260         "E87E77410BD3CA7836EC2341D440ED3C321");
261 
262     std::shared_ptr<GsmCbCodec> msg = GsmCbCodec::CreateCbMessage(data);
263     if (msg == nullptr) {
264         std::cout << "CreateCbMessage fail." << std::endl;
265     } else {
266         std::cout << "msginfo: " << msg->ToString() << std::endl;
267     }
268 }
269 
TestCdmaUserData() const270 void SmsCbMessageTest::TestCdmaUserData() const
271 {
272     std::string pdu = "0101020004081300031008d00106102c2870e1420801c00c01c0";
273     std::shared_ptr<CdmaSmsMessage> message = CdmaSmsMessage::CreateMessage(pdu);
274     if (message == nullptr) {
275         std::cout << "message is nullptr!" << std::endl;
276         return;
277     }
278     std::cout << message->GetCbInfo() << std::endl;
279 }
280 
TestCdmaCmasType1() const281 void SmsCbMessageTest::TestCdmaCmasType1() const
282 {
283     std::string pdu = "0101021000081500031008d001080100000800c1E1000801c00c01c0";
284     std::shared_ptr<CdmaSmsMessage> message = CdmaSmsMessage::CreateMessage(pdu);
285     if (message == nullptr) {
286         std::cout << "message is nullptr!" << std::endl;
287         return;
288     }
289     std::cout << message->GetCbInfo() << std::endl;
290 }
291 } // namespace Telephony
292 } // namespace OHOS