Home | History | Annotate | Download | only in functional
      1 /*
      2  * Copyright (C) 2017 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 
     17 #include <radio_hidl_hal_utils_v1_0.h>
     18 
     19 using namespace ::android::hardware::radio::V1_0;
     20 
     21 /*
     22  * Test IRadio.sendSms() for the response returned.
     23  */
     24 TEST_F(RadioHidlTest, sendSms) {
     25     serial = GetRandomSerialNumber();
     26     GsmSmsMessage msg;
     27     msg.smscPdu = "";
     28     msg.pdu = "01000b916105770203f3000006d4f29c3e9b01";
     29 
     30     radio->sendSms(serial, msg);
     31 
     32     EXPECT_EQ(std::cv_status::no_timeout, wait(300));
     33     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
     34     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
     35 
     36     if (cardStatus.cardState == CardState::ABSENT) {
     37         ASSERT_TRUE(CheckAnyOfErrors(
     38             radioRsp->rspInfo.error,
     39             {RadioError::INVALID_ARGUMENTS, RadioError::INVALID_STATE, RadioError::SIM_ABSENT},
     40             CHECK_GENERAL_ERROR));
     41         EXPECT_EQ(0, radioRsp->sendSmsResult.errorCode);
     42     }
     43 }
     44 
     45 /*
     46  * Test IRadio.sendSMSExpectMore() for the response returned.
     47  */
     48 TEST_F(RadioHidlTest, sendSMSExpectMore) {
     49     serial = GetRandomSerialNumber();
     50     GsmSmsMessage msg;
     51     msg.smscPdu = "";
     52     msg.pdu = "01000b916105770203f3000006d4f29c3e9b01";
     53 
     54     radio->sendSMSExpectMore(serial, msg);
     55 
     56     // TODO(shuoq): add more test for this API when inserted sim card is
     57     // considered
     58 
     59     EXPECT_EQ(std::cv_status::no_timeout, wait(300));
     60     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
     61     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
     62 
     63     if (cardStatus.cardState == CardState::ABSENT) {
     64         ASSERT_TRUE(CheckAnyOfErrors(
     65             radioRsp->rspInfo.error,
     66             {RadioError::INVALID_ARGUMENTS, RadioError::INVALID_STATE, RadioError::SIM_ABSENT},
     67             CHECK_GENERAL_ERROR));
     68     }
     69 }
     70 
     71 /*
     72  * Test IRadio.acknowledgeLastIncomingGsmSms() for the response returned.
     73  */
     74 TEST_F(RadioHidlTest, acknowledgeLastIncomingGsmSms) {
     75     serial = GetRandomSerialNumber();
     76     bool success = true;
     77 
     78     radio->acknowledgeLastIncomingGsmSms(serial, success,
     79                                          SmsAcknowledgeFailCause::MEMORY_CAPACITY_EXCEEDED);
     80 
     81     EXPECT_EQ(std::cv_status::no_timeout, wait());
     82     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
     83     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
     84 
     85     if (cardStatus.cardState == CardState::ABSENT) {
     86         ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error,
     87                                      {RadioError::INVALID_ARGUMENTS, RadioError::INVALID_STATE},
     88                                      CHECK_GENERAL_ERROR));
     89     }
     90 }
     91 
     92 /*
     93  * Test IRadio.acknowledgeIncomingGsmSmsWithPdu() for the response returned.
     94  */
     95 TEST_F(RadioHidlTest, acknowledgeIncomingGsmSmsWithPdu) {
     96     serial = GetRandomSerialNumber();
     97     bool success = true;
     98     std::string ackPdu = "";
     99 
    100     radio->acknowledgeIncomingGsmSmsWithPdu(serial, success, ackPdu);
    101 
    102     EXPECT_EQ(std::cv_status::no_timeout, wait());
    103     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    104     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
    105 
    106     if (cardStatus.cardState == CardState::ABSENT) {
    107         // TODO(shuoq): Will add error check when we know the expected error from QC
    108     }
    109 }
    110 
    111 /*
    112  * Test IRadio.sendCdmaSms() for the response returned.
    113  */
    114 TEST_F(RadioHidlTest, sendCdmaSms) {
    115     serial = GetRandomSerialNumber();
    116 
    117     // Create a CdmaSmsAddress
    118     CdmaSmsAddress cdmaSmsAddress;
    119     cdmaSmsAddress.digitMode = CdmaSmsDigitMode::FOUR_BIT;
    120     cdmaSmsAddress.numberMode = CdmaSmsNumberMode::NOT_DATA_NETWORK;
    121     cdmaSmsAddress.numberType = CdmaSmsNumberType::UNKNOWN;
    122     cdmaSmsAddress.numberPlan = CdmaSmsNumberPlan::UNKNOWN;
    123     cdmaSmsAddress.digits = (std::vector<uint8_t>){11, 1, 6, 5, 10, 7, 7, 2, 10, 3, 10, 3};
    124 
    125     // Create a CdmaSmsSubAddress
    126     CdmaSmsSubaddress cdmaSmsSubaddress;
    127     cdmaSmsSubaddress.subaddressType = CdmaSmsSubaddressType::NSAP;
    128     cdmaSmsSubaddress.odd = false;
    129     cdmaSmsSubaddress.digits = (std::vector<uint8_t>){};
    130 
    131     // Create a CdmaSmsMessage
    132     android::hardware::radio::V1_0::CdmaSmsMessage cdmaSmsMessage;
    133     cdmaSmsMessage.teleserviceId = 4098;
    134     cdmaSmsMessage.isServicePresent = false;
    135     cdmaSmsMessage.serviceCategory = 0;
    136     cdmaSmsMessage.address = cdmaSmsAddress;
    137     cdmaSmsMessage.subAddress = cdmaSmsSubaddress;
    138     cdmaSmsMessage.bearerData =
    139         (std::vector<uint8_t>){15, 0, 3, 32, 3, 16, 1, 8, 16, 53, 76, 68, 6, 51, 106, 0};
    140 
    141     radio->sendCdmaSms(serial, cdmaSmsMessage);
    142 
    143     EXPECT_EQ(std::cv_status::no_timeout, wait());
    144     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    145     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
    146 
    147     if (cardStatus.cardState == CardState::ABSENT) {
    148         ASSERT_TRUE(CheckAnyOfErrors(
    149             radioRsp->rspInfo.error,
    150             {RadioError::INVALID_ARGUMENTS, RadioError::INVALID_STATE, RadioError::SIM_ABSENT},
    151             CHECK_GENERAL_ERROR));
    152     }
    153 }
    154 
    155 /*
    156  * Test IRadio.acknowledgeLastIncomingCdmaSms() for the response returned.
    157  */
    158 TEST_F(RadioHidlTest, acknowledgeLastIncomingCdmaSms) {
    159     serial = GetRandomSerialNumber();
    160 
    161     // Create a CdmaSmsAck
    162     CdmaSmsAck cdmaSmsAck;
    163     cdmaSmsAck.errorClass = CdmaSmsErrorClass::NO_ERROR;
    164     cdmaSmsAck.smsCauseCode = 1;
    165 
    166     radio->acknowledgeLastIncomingCdmaSms(serial, cdmaSmsAck);
    167 
    168     EXPECT_EQ(std::cv_status::no_timeout, wait());
    169     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    170     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
    171 
    172     if (cardStatus.cardState == CardState::ABSENT) {
    173         ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error,
    174                                      {RadioError::INVALID_ARGUMENTS, RadioError::NO_SMS_TO_ACK},
    175                                      CHECK_GENERAL_ERROR));
    176     }
    177 }
    178 
    179 /*
    180  * Test IRadio.sendImsSms() for the response returned.
    181  */
    182 TEST_F(RadioHidlTest, sendImsSms) {
    183     serial = GetRandomSerialNumber();
    184 
    185     // Create a CdmaSmsAddress
    186     CdmaSmsAddress cdmaSmsAddress;
    187     cdmaSmsAddress.digitMode = CdmaSmsDigitMode::FOUR_BIT;
    188     cdmaSmsAddress.numberMode = CdmaSmsNumberMode::NOT_DATA_NETWORK;
    189     cdmaSmsAddress.numberType = CdmaSmsNumberType::UNKNOWN;
    190     cdmaSmsAddress.numberPlan = CdmaSmsNumberPlan::UNKNOWN;
    191     cdmaSmsAddress.digits = (std::vector<uint8_t>){11, 1, 6, 5, 10, 7, 7, 2, 10, 3, 10, 3};
    192 
    193     // Create a CdmaSmsSubAddress
    194     CdmaSmsSubaddress cdmaSmsSubaddress;
    195     cdmaSmsSubaddress.subaddressType = CdmaSmsSubaddressType::NSAP;
    196     cdmaSmsSubaddress.odd = false;
    197     cdmaSmsSubaddress.digits = (std::vector<uint8_t>){};
    198 
    199     // Create a CdmaSmsMessage
    200     CdmaSmsMessage cdmaSmsMessage;
    201     cdmaSmsMessage.teleserviceId = 4098;
    202     cdmaSmsMessage.isServicePresent = false;
    203     cdmaSmsMessage.serviceCategory = 0;
    204     cdmaSmsMessage.address = cdmaSmsAddress;
    205     cdmaSmsMessage.subAddress = cdmaSmsSubaddress;
    206     cdmaSmsMessage.bearerData =
    207         (std::vector<uint8_t>){15, 0, 3, 32, 3, 16, 1, 8, 16, 53, 76, 68, 6, 51, 106, 0};
    208 
    209     // Creata an ImsSmsMessage
    210     ImsSmsMessage msg;
    211     msg.tech = RadioTechnologyFamily::THREE_GPP2;
    212     msg.retry = false;
    213     msg.messageRef = 0;
    214     msg.cdmaMessage = (std::vector<CdmaSmsMessage>){cdmaSmsMessage};
    215     msg.gsmMessage = (std::vector<GsmSmsMessage>){};
    216 
    217     radio->sendImsSms(serial, msg);
    218 
    219     EXPECT_EQ(std::cv_status::no_timeout, wait());
    220     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    221     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
    222 
    223     if (cardStatus.cardState == CardState::ABSENT) {
    224         ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error, {RadioError::INVALID_ARGUMENTS},
    225                                      CHECK_GENERAL_ERROR));
    226     }
    227 }
    228 
    229 /*
    230  * Test IRadio.getSmscAddress() for the response returned.
    231  */
    232 TEST_F(RadioHidlTest, getSmscAddress) {
    233     serial = GetRandomSerialNumber();
    234 
    235     radio->getSmscAddress(serial);
    236 
    237     EXPECT_EQ(std::cv_status::no_timeout, wait());
    238     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    239     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
    240 
    241     if (cardStatus.cardState == CardState::ABSENT) {
    242         ASSERT_TRUE(CheckAnyOfErrors(
    243             radioRsp->rspInfo.error,
    244             {RadioError::INVALID_MODEM_STATE, RadioError::INVALID_STATE, RadioError::SIM_ABSENT},
    245             CHECK_GENERAL_ERROR));
    246     }
    247 }
    248 
    249 /*
    250  * Test IRadio.setSmscAddress() for the response returned.
    251  */
    252 TEST_F(RadioHidlTest, setSmscAddress) {
    253     serial = GetRandomSerialNumber();
    254     hidl_string address = hidl_string("smscAddress");
    255 
    256     radio->setSmscAddress(serial, address);
    257 
    258     EXPECT_EQ(std::cv_status::no_timeout, wait());
    259     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    260     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
    261 
    262     if (cardStatus.cardState == CardState::ABSENT) {
    263         ASSERT_TRUE(CheckAnyOfErrors(
    264             radioRsp->rspInfo.error,
    265             {RadioError::INVALID_ARGUMENTS, RadioError::INVALID_SMS_FORMAT, RadioError::SIM_ABSENT},
    266             CHECK_GENERAL_ERROR));
    267     }
    268 }
    269 
    270 /*
    271  * Test IRadio.writeSmsToSim() for the response returned.
    272  */
    273 TEST_F(RadioHidlTest, writeSmsToSim) {
    274     serial = GetRandomSerialNumber();
    275     SmsWriteArgs smsWriteArgs;
    276     smsWriteArgs.status = SmsWriteArgsStatus::REC_UNREAD;
    277     smsWriteArgs.smsc = "";
    278     smsWriteArgs.pdu = "01000b916105770203f3000006d4f29c3e9b01";
    279 
    280     radio->writeSmsToSim(serial, smsWriteArgs);
    281 
    282     EXPECT_EQ(std::cv_status::no_timeout, wait());
    283     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    284     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
    285 
    286     if (cardStatus.cardState == CardState::ABSENT) {
    287         ASSERT_TRUE(CheckAnyOfErrors(
    288             radioRsp->rspInfo.error,
    289             {RadioError::NONE, RadioError::ENCODING_ERR, RadioError::INVALID_ARGUMENTS,
    290              RadioError::INVALID_SMSC_ADDRESS, RadioError::MODEM_ERR, RadioError::NETWORK_NOT_READY,
    291              RadioError::NO_RESOURCES, RadioError::SIM_ABSENT},
    292             CHECK_GENERAL_ERROR));
    293     }
    294 }
    295 
    296 /*
    297  * Test IRadio.deleteSmsOnSim() for the response returned.
    298  */
    299 TEST_F(RadioHidlTest, deleteSmsOnSim) {
    300     serial = GetRandomSerialNumber();
    301     int index = 1;
    302 
    303     radio->deleteSmsOnSim(serial, index);
    304 
    305     EXPECT_EQ(std::cv_status::no_timeout, wait());
    306     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    307     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
    308 
    309     if (cardStatus.cardState == CardState::ABSENT) {
    310         ASSERT_TRUE(CheckAnyOfErrors(
    311             radioRsp->rspInfo.error,
    312             {RadioError::NONE, RadioError::ENCODING_ERR, RadioError::INVALID_ARGUMENTS,
    313              RadioError::INVALID_MODEM_STATE, RadioError::NO_SUCH_ENTRY, RadioError::MODEM_ERR,
    314              RadioError::SIM_ABSENT},
    315             CHECK_GENERAL_ERROR));
    316     }
    317 }
    318 
    319 /*
    320  * Test IRadio.writeSmsToRuim() for the response returned.
    321  */
    322 TEST_F(RadioHidlTest, writeSmsToRuim) {
    323     serial = GetRandomSerialNumber();
    324 
    325     // Create a CdmaSmsAddress
    326     CdmaSmsAddress cdmaSmsAddress;
    327     cdmaSmsAddress.digitMode = CdmaSmsDigitMode::FOUR_BIT;
    328     cdmaSmsAddress.numberMode = CdmaSmsNumberMode::NOT_DATA_NETWORK;
    329     cdmaSmsAddress.numberType = CdmaSmsNumberType::UNKNOWN;
    330     cdmaSmsAddress.numberPlan = CdmaSmsNumberPlan::UNKNOWN;
    331     cdmaSmsAddress.digits = (std::vector<uint8_t>){11, 1, 6, 5, 10, 7, 7, 2, 10, 3, 10, 3};
    332 
    333     // Create a CdmaSmsSubAddress
    334     CdmaSmsSubaddress cdmaSmsSubaddress;
    335     cdmaSmsSubaddress.subaddressType = CdmaSmsSubaddressType::NSAP;
    336     cdmaSmsSubaddress.odd = false;
    337     cdmaSmsSubaddress.digits = (std::vector<uint8_t>){};
    338 
    339     // Create a CdmaSmsMessage
    340     CdmaSmsMessage cdmaSmsMessage;
    341     cdmaSmsMessage.teleserviceId = 4098;
    342     cdmaSmsMessage.isServicePresent = false;
    343     cdmaSmsMessage.serviceCategory = 0;
    344     cdmaSmsMessage.address = cdmaSmsAddress;
    345     cdmaSmsMessage.subAddress = cdmaSmsSubaddress;
    346     cdmaSmsMessage.bearerData =
    347         (std::vector<uint8_t>){15, 0, 3, 32, 3, 16, 1, 8, 16, 53, 76, 68, 6, 51, 106, 0};
    348 
    349     // Create a CdmaSmsWriteArgs
    350     CdmaSmsWriteArgs cdmaSmsWriteArgs;
    351     cdmaSmsWriteArgs.status = CdmaSmsWriteArgsStatus::REC_UNREAD;
    352     cdmaSmsWriteArgs.message = cdmaSmsMessage;
    353 
    354     radio->writeSmsToRuim(serial, cdmaSmsWriteArgs);
    355 
    356     EXPECT_EQ(std::cv_status::no_timeout, wait());
    357     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    358     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
    359 
    360     if (cardStatus.cardState == CardState::ABSENT) {
    361         ASSERT_TRUE(CheckAnyOfErrors(
    362             radioRsp->rspInfo.error,
    363             {RadioError::NONE, RadioError::INVALID_ARGUMENTS, RadioError::INVALID_SMS_FORMAT,
    364              RadioError::INVALID_SMSC_ADDRESS, RadioError::INVALID_STATE, RadioError::MODEM_ERR,
    365              RadioError::NO_SUCH_ENTRY, RadioError::SIM_ABSENT},
    366             CHECK_GENERAL_ERROR));
    367     }
    368 }
    369 
    370 /*
    371  * Test IRadio.deleteSmsOnRuim() for the response returned.
    372  */
    373 TEST_F(RadioHidlTest, deleteSmsOnRuim) {
    374     serial = GetRandomSerialNumber();
    375     int index = 1;
    376 
    377     // Create a CdmaSmsAddress
    378     CdmaSmsAddress cdmaSmsAddress;
    379     cdmaSmsAddress.digitMode = CdmaSmsDigitMode::FOUR_BIT;
    380     cdmaSmsAddress.numberMode = CdmaSmsNumberMode::NOT_DATA_NETWORK;
    381     cdmaSmsAddress.numberType = CdmaSmsNumberType::UNKNOWN;
    382     cdmaSmsAddress.numberPlan = CdmaSmsNumberPlan::UNKNOWN;
    383     cdmaSmsAddress.digits = (std::vector<uint8_t>){11, 1, 6, 5, 10, 7, 7, 2, 10, 3, 10, 3};
    384 
    385     // Create a CdmaSmsSubAddress
    386     CdmaSmsSubaddress cdmaSmsSubaddress;
    387     cdmaSmsSubaddress.subaddressType = CdmaSmsSubaddressType::NSAP;
    388     cdmaSmsSubaddress.odd = false;
    389     cdmaSmsSubaddress.digits = (std::vector<uint8_t>){};
    390 
    391     // Create a CdmaSmsMessage
    392     CdmaSmsMessage cdmaSmsMessage;
    393     cdmaSmsMessage.teleserviceId = 4098;
    394     cdmaSmsMessage.isServicePresent = false;
    395     cdmaSmsMessage.serviceCategory = 0;
    396     cdmaSmsMessage.address = cdmaSmsAddress;
    397     cdmaSmsMessage.subAddress = cdmaSmsSubaddress;
    398     cdmaSmsMessage.bearerData =
    399         (std::vector<uint8_t>){15, 0, 3, 32, 3, 16, 1, 8, 16, 53, 76, 68, 6, 51, 106, 0};
    400 
    401     // Create a CdmaSmsWriteArgs
    402     CdmaSmsWriteArgs cdmaSmsWriteArgs;
    403     cdmaSmsWriteArgs.status = CdmaSmsWriteArgsStatus::REC_UNREAD;
    404     cdmaSmsWriteArgs.message = cdmaSmsMessage;
    405 
    406     radio->deleteSmsOnRuim(serial, index);
    407 
    408     EXPECT_EQ(std::cv_status::no_timeout, wait());
    409     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    410     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
    411 
    412     if (cardStatus.cardState == CardState::ABSENT) {
    413         ASSERT_TRUE(CheckAnyOfErrors(
    414             radioRsp->rspInfo.error,
    415             {RadioError::NONE, RadioError::INVALID_ARGUMENTS, RadioError::INVALID_MODEM_STATE,
    416              RadioError::MODEM_ERR, RadioError::NO_SUCH_ENTRY, RadioError::SIM_ABSENT},
    417             CHECK_GENERAL_ERROR));
    418     }
    419 }
    420 
    421 /*
    422  * Test IRadio.reportSmsMemoryStatus() for the response returned.
    423  */
    424 TEST_F(RadioHidlTest, reportSmsMemoryStatus) {
    425     serial = GetRandomSerialNumber();
    426     bool available = true;
    427 
    428     radio->reportSmsMemoryStatus(serial, available);
    429 
    430     EXPECT_EQ(std::cv_status::no_timeout, wait());
    431     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    432     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
    433 
    434     if (cardStatus.cardState == CardState::ABSENT) {
    435         ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error,
    436                                      {RadioError::INVALID_ARGUMENTS, RadioError::INVALID_STATE,
    437                                       RadioError::MODEM_ERR, RadioError::SIM_ABSENT},
    438                                      CHECK_GENERAL_ERROR));
    439     }
    440 }
    441