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 <sap_hidl_hal_utils.h>
     18 
     19 /*
     20  * Test ISap.connectReq() for the response returned.
     21  */
     22 TEST_F(SapHidlTest, connectReq) {
     23     int32_t token = GetRandomSerialNumber();
     24     int32_t maxMsgSize = 100;
     25 
     26     sap->connectReq(token, maxMsgSize);
     27     EXPECT_EQ(std::cv_status::no_timeout, wait());
     28     EXPECT_EQ(sapCb->sapResponseToken, token);
     29 }
     30 
     31 /*
     32  * Test IRadio.disconnectReq() for the response returned
     33  */
     34 TEST_F(SapHidlTest, disconnectReq) {
     35     int32_t token = GetRandomSerialNumber();
     36 
     37     sap->disconnectReq(token);
     38     EXPECT_EQ(std::cv_status::no_timeout, wait());
     39     EXPECT_EQ(sapCb->sapResponseToken, token);
     40 }
     41 
     42 /*
     43  * Test IRadio.apduReq() for the response returned.
     44  */
     45 TEST_F(SapHidlTest, apduReq) {
     46     int32_t token = GetRandomSerialNumber();
     47     SapApduType sapApduType = SapApduType::APDU;
     48     android::hardware::hidl_vec<uint8_t> command = {};
     49 
     50     sap->apduReq(token, sapApduType, command);
     51     EXPECT_EQ(std::cv_status::no_timeout, wait());
     52     EXPECT_EQ(sapCb->sapResponseToken, token);
     53 
     54     ASSERT_TRUE(SapResultCode::GENERIC_FAILURE == sapCb->sapResultCode ||
     55                 SapResultCode::CARD_NOT_ACCESSSIBLE == sapCb->sapResultCode ||
     56                 SapResultCode::CARD_ALREADY_POWERED_OFF == sapCb->sapResultCode ||
     57                 SapResultCode::CARD_REMOVED == sapCb->sapResultCode);
     58 }
     59 
     60 /*
     61  * Test IRadio.transferAtrReq() for the response returned.
     62  */
     63 TEST_F(SapHidlTest, transferAtrReq) {
     64     int32_t token = GetRandomSerialNumber();
     65 
     66     sap->transferAtrReq(token);
     67     EXPECT_EQ(std::cv_status::no_timeout, wait());
     68     EXPECT_EQ(sapCb->sapResponseToken, token);
     69 
     70     ASSERT_TRUE(SapResultCode::GENERIC_FAILURE == sapCb->sapResultCode ||
     71                 SapResultCode::DATA_NOT_AVAILABLE == sapCb->sapResultCode ||
     72                 SapResultCode::CARD_ALREADY_POWERED_OFF == sapCb->sapResultCode ||
     73                 SapResultCode::CARD_REMOVED == sapCb->sapResultCode);
     74 }
     75 
     76 /*
     77  * Test IRadio.powerReq() for the response returned.
     78  */
     79 TEST_F(SapHidlTest, powerReq) {
     80     int32_t token = GetRandomSerialNumber();
     81     bool state = true;
     82 
     83     sap->powerReq(token, state);
     84     EXPECT_EQ(std::cv_status::no_timeout, wait());
     85     EXPECT_EQ(sapCb->sapResponseToken, token);
     86 
     87     ASSERT_TRUE(SapResultCode::GENERIC_FAILURE == sapCb->sapResultCode ||
     88                 SapResultCode::CARD_NOT_ACCESSSIBLE == sapCb->sapResultCode ||
     89                 SapResultCode::CARD_ALREADY_POWERED_OFF == sapCb->sapResultCode ||
     90                 SapResultCode::CARD_REMOVED == sapCb->sapResultCode ||
     91                 SapResultCode::CARD_ALREADY_POWERED_ON == sapCb->sapResultCode);
     92 }
     93 
     94 /*
     95  * Test IRadio.resetSimReq() for the response returned.
     96  */
     97 TEST_F(SapHidlTest, resetSimReq) {
     98     int32_t token = GetRandomSerialNumber();
     99 
    100     sap->resetSimReq(token);
    101     EXPECT_EQ(std::cv_status::no_timeout, wait());
    102     EXPECT_EQ(sapCb->sapResponseToken, token);
    103 
    104     ASSERT_TRUE(SapResultCode::GENERIC_FAILURE == sapCb->sapResultCode ||
    105                 SapResultCode::CARD_NOT_ACCESSSIBLE == sapCb->sapResultCode ||
    106                 SapResultCode::CARD_ALREADY_POWERED_OFF == sapCb->sapResultCode ||
    107                 SapResultCode::CARD_REMOVED == sapCb->sapResultCode);
    108 }
    109 
    110 /*
    111  * Test IRadio.transferCardReaderStatusReq() for the response returned.
    112  */
    113 TEST_F(SapHidlTest, transferCardReaderStatusReq) {
    114     int32_t token = GetRandomSerialNumber();
    115 
    116     sap->transferCardReaderStatusReq(token);
    117     EXPECT_EQ(std::cv_status::no_timeout, wait());
    118     EXPECT_EQ(sapCb->sapResponseToken, token);
    119 
    120     ASSERT_TRUE(SapResultCode::GENERIC_FAILURE == sapCb->sapResultCode ||
    121                 SapResultCode::DATA_NOT_AVAILABLE == sapCb->sapResultCode);
    122 }
    123 
    124 /*
    125  * Test IRadio.setTransferProtocolReq() for the response returned.
    126  */
    127 TEST_F(SapHidlTest, setTransferProtocolReq) {
    128     int32_t token = GetRandomSerialNumber();
    129     SapTransferProtocol sapTransferProtocol = SapTransferProtocol::T0;
    130 
    131     sap->setTransferProtocolReq(token, sapTransferProtocol);
    132     EXPECT_EQ(std::cv_status::no_timeout, wait());
    133     EXPECT_EQ(sapCb->sapResponseToken, token);
    134 
    135     EXPECT_EQ(SapResultCode::NOT_SUPPORTED, sapCb->sapResultCode);
    136 }
    137