• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
TEST_F(SapHidlTest,connectReq)22 TEST_F(SapHidlTest, connectReq) {
23     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     // Modem side need time for connect to finish. Adding a waiting time to prevent
31     // disconnect being requested right after connect request.
32     sleep(1);
33 }
34 
35 /*
36  * Test IRadio.disconnectReq() for the response returned
37  */
TEST_F(SapHidlTest,disconnectReq)38 TEST_F(SapHidlTest, disconnectReq) {
39     token = GetRandomSerialNumber();
40 
41     sap->disconnectReq(token);
42     EXPECT_EQ(std::cv_status::no_timeout, wait());
43     EXPECT_EQ(sapCb->sapResponseToken, token);
44 }
45 
46 /*
47  * Test IRadio.apduReq() for the response returned.
48  */
TEST_F(SapHidlTest,apduReq)49 TEST_F(SapHidlTest, apduReq) {
50     token = GetRandomSerialNumber();
51     SapApduType sapApduType = SapApduType::APDU;
52     android::hardware::hidl_vec<uint8_t> command = {};
53 
54     sap->apduReq(token, sapApduType, command);
55     EXPECT_EQ(std::cv_status::no_timeout, wait());
56     EXPECT_EQ(sapCb->sapResponseToken, token);
57 
58     ASSERT_TRUE(
59         CheckAnyOfErrors(sapCb->sapResultCode,
60                          {SapResultCode::GENERIC_FAILURE, SapResultCode::CARD_ALREADY_POWERED_OFF,
61                           SapResultCode::CARD_NOT_ACCESSSIBLE, SapResultCode::CARD_REMOVED}));
62 }
63 
64 /*
65  * Test IRadio.transferAtrReq() for the response returned.
66  */
TEST_F(SapHidlTest,transferAtrReq)67 TEST_F(SapHidlTest, transferAtrReq) {
68     token = GetRandomSerialNumber();
69 
70     sap->transferAtrReq(token);
71     EXPECT_EQ(std::cv_status::no_timeout, wait());
72     EXPECT_EQ(sapCb->sapResponseToken, token);
73 
74     ASSERT_TRUE(
75         CheckAnyOfErrors(sapCb->sapResultCode,
76                          {SapResultCode::GENERIC_FAILURE, SapResultCode::DATA_NOT_AVAILABLE,
77                           SapResultCode::CARD_ALREADY_POWERED_OFF, SapResultCode::CARD_REMOVED}));
78 }
79 
80 /*
81  * Test IRadio.powerReq() for the response returned.
82  */
TEST_F(SapHidlTest,powerReq)83 TEST_F(SapHidlTest, powerReq) {
84     token = GetRandomSerialNumber();
85     bool state = true;
86 
87     sap->powerReq(token, state);
88     EXPECT_EQ(std::cv_status::no_timeout, wait());
89     EXPECT_EQ(sapCb->sapResponseToken, token);
90 
91     ASSERT_TRUE(CheckAnyOfErrors(
92         sapCb->sapResultCode, {SapResultCode::GENERIC_FAILURE, SapResultCode::CARD_NOT_ACCESSSIBLE,
93                                SapResultCode::CARD_ALREADY_POWERED_OFF, SapResultCode::CARD_REMOVED,
94                                SapResultCode::CARD_ALREADY_POWERED_ON}));
95 }
96 
97 /*
98  * Test IRadio.resetSimReq() for the response returned.
99  */
TEST_F(SapHidlTest,resetSimReq)100 TEST_F(SapHidlTest, resetSimReq) {
101     token = GetRandomSerialNumber();
102 
103     sap->resetSimReq(token);
104     EXPECT_EQ(std::cv_status::no_timeout, wait());
105     EXPECT_EQ(sapCb->sapResponseToken, token);
106 
107     ASSERT_TRUE(
108         CheckAnyOfErrors(sapCb->sapResultCode,
109                          {SapResultCode::GENERIC_FAILURE, SapResultCode::CARD_NOT_ACCESSSIBLE,
110                           SapResultCode::CARD_ALREADY_POWERED_OFF, SapResultCode::CARD_REMOVED}));
111 }
112 
113 /*
114  * Test IRadio.transferCardReaderStatusReq() for the response returned.
115  */
TEST_F(SapHidlTest,transferCardReaderStatusReq)116 TEST_F(SapHidlTest, transferCardReaderStatusReq) {
117     token = GetRandomSerialNumber();
118 
119     sap->transferCardReaderStatusReq(token);
120     EXPECT_EQ(std::cv_status::no_timeout, wait());
121     EXPECT_EQ(sapCb->sapResponseToken, token);
122 
123     ASSERT_TRUE(CheckAnyOfErrors(
124         sapCb->sapResultCode, {SapResultCode::GENERIC_FAILURE, SapResultCode::DATA_NOT_AVAILABLE}));
125 }
126 
127 /*
128  * Test IRadio.setTransferProtocolReq() for the response returned.
129  */
TEST_F(SapHidlTest,setTransferProtocolReq)130 TEST_F(SapHidlTest, setTransferProtocolReq) {
131     token = GetRandomSerialNumber();
132     SapTransferProtocol sapTransferProtocol = SapTransferProtocol::T0;
133 
134     sap->setTransferProtocolReq(token, sapTransferProtocol);
135     EXPECT_EQ(std::cv_status::no_timeout, wait());
136     EXPECT_EQ(sapCb->sapResponseToken, token);
137 
138     EXPECT_EQ(SapResultCode::NOT_SUPPORTED, sapCb->sapResultCode);
139 }
140