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
TEST(PDUParserTest,IsValidPDU_false)26 TEST(PDUParserTest, IsValidPDU_false) {
27 std::string pdu = "000100fD91688118109844F0000017AFD7903AB55A9BBA69D639D4ADCBF99E3DCCAE9701";
28 cuttlefish::PDUParser smspdu(pdu);
29 EXPECT_FALSE(smspdu.IsValidPDU());
30 }
31
TEST(PDUParserTest,CreatePDU)32 TEST(PDUParserTest, CreatePDU) {
33 std::string pdu = "0001000D91688118109844F0000017AFD7903AB55A9BBA69D639D4ADCBF99E3DCCAE9701";
34 cuttlefish::PDUParser smspdu(pdu);
35 EXPECT_TRUE(smspdu.IsValidPDU());
36 std::string new_pdu = smspdu.CreatePDU();
37 const char *expect = "";
38 ASSERT_STRNE(new_pdu.c_str(), expect);
39 }
40
TEST(PDUParserTest,GetPhoneNumberFromAddress)41 TEST(PDUParserTest, GetPhoneNumberFromAddress) {
42 std::string pdu = "0001000D91688118109844F0000017AFD7903AB55A9BBA69D639D4ADCBF99E3DCCAE9701";
43 cuttlefish::PDUParser smspdu(pdu);
44 EXPECT_TRUE(smspdu.IsValidPDU());
45 std::string phone_number = smspdu.GetPhoneNumberFromAddress();
46 const char *expect = "18810189440";
47 ASSERT_STREQ(phone_number.c_str(), expect);
48 }
49
TEST(PDUParserTest,BCDToString)50 TEST(PDUParserTest, BCDToString) {
51 std::string value = "12345678";
52 std::string process_value = cuttlefish::PDUParser::BCDToString(value);
53 const char *expect = "21436587";
54 ASSERT_STREQ(process_value.c_str(), expect);
55 }
56