1 //
2 // Copyright (C) 2020 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 #include "host/commands/modem_simulator/pdu_parser.h"
17
18 #include <gtest/gtest.h>
19
TEST(PDUParserTest,IsValidPDU_true)20 TEST(PDUParserTest, IsValidPDU_true) {
21 std::string pdu = "0001000D91688118109844F0000017AFD7903AB55A9BBA69D639D4ADCBF99E3DCCAE9701";
22 cuttlefish::PDUParser smspdu(pdu);
23 EXPECT_TRUE(smspdu.IsValidPDU());
24
25 std::string pdu_unicode = "000100048145540008024F60";
26 cuttlefish::PDUParser pduUnicode(pdu_unicode);
27 EXPECT_TRUE(pduUnicode.IsValidPDU());
28 }
29
TEST(PDUParserTest,IsValidPDU_false)30 TEST(PDUParserTest, IsValidPDU_false) {
31 std::string pdu = "000100fD91688118109844F0000017AFD7903AB55A9BBA69D639D4ADCBF99E3DCCAE9701";
32 cuttlefish::PDUParser smspdu(pdu);
33 EXPECT_FALSE(smspdu.IsValidPDU());
34 }
35
TEST(PDUParserTest,CreatePDU)36 TEST(PDUParserTest, CreatePDU) {
37 std::string pdu = "0001000D91688118109844F0000017AFD7903AB55A9BBA69D639D4ADCBF99E3DCCAE9701";
38 cuttlefish::PDUParser smspdu(pdu);
39 EXPECT_TRUE(smspdu.IsValidPDU());
40 std::string new_pdu = smspdu.CreatePDU();
41 const char *expect = "";
42 ASSERT_STRNE(new_pdu.c_str(), expect);
43 }
44
TEST(PDUParserTest,GetPhoneNumberFromAddress)45 TEST(PDUParserTest, GetPhoneNumberFromAddress) {
46 std::string pdu = "0001000D91688118109844F0000017AFD7903AB55A9BBA69D639D4ADCBF99E3DCCAE9701";
47 cuttlefish::PDUParser smspdu(pdu);
48 EXPECT_TRUE(smspdu.IsValidPDU());
49 std::string phone_number = smspdu.GetPhoneNumberFromAddress();
50 const char *expect = "18810189440";
51 ASSERT_STREQ(phone_number.c_str(), expect);
52 }
53
TEST(PDUParserTest,BCDToString)54 TEST(PDUParserTest, BCDToString) {
55 std::string value = "12345678";
56 std::string process_value = cuttlefish::PDUParser::BCDToString(value);
57 const char *expect = "21436587";
58 ASSERT_STREQ(process_value.c_str(), expect);
59 }
60