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
31 /*
32 * Test IRadio.disconnectReq() for the response returned
33 */
TEST_F(SapHidlTest,disconnectReq)34 TEST_F(SapHidlTest, disconnectReq) {
35 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 */
TEST_F(SapHidlTest,apduReq)45 TEST_F(SapHidlTest, apduReq) {
46 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(
55 CheckAnyOfErrors(sapCb->sapResultCode,
56 {SapResultCode::GENERIC_FAILURE, SapResultCode::CARD_ALREADY_POWERED_OFF,
57 SapResultCode::CARD_NOT_ACCESSSIBLE, SapResultCode::CARD_REMOVED}));
58 }
59
60 /*
61 * Test IRadio.transferAtrReq() for the response returned.
62 */
TEST_F(SapHidlTest,transferAtrReq)63 TEST_F(SapHidlTest, transferAtrReq) {
64 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(
71 CheckAnyOfErrors(sapCb->sapResultCode,
72 {SapResultCode::GENERIC_FAILURE, SapResultCode::DATA_NOT_AVAILABLE,
73 SapResultCode::CARD_ALREADY_POWERED_OFF, SapResultCode::CARD_REMOVED}));
74 }
75
76 /*
77 * Test IRadio.powerReq() for the response returned.
78 */
TEST_F(SapHidlTest,powerReq)79 TEST_F(SapHidlTest, powerReq) {
80 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(CheckAnyOfErrors(
88 sapCb->sapResultCode, {SapResultCode::GENERIC_FAILURE, SapResultCode::CARD_NOT_ACCESSSIBLE,
89 SapResultCode::CARD_ALREADY_POWERED_OFF, SapResultCode::CARD_REMOVED,
90 SapResultCode::CARD_ALREADY_POWERED_ON}));
91 }
92
93 /*
94 * Test IRadio.resetSimReq() for the response returned.
95 */
TEST_F(SapHidlTest,resetSimReq)96 TEST_F(SapHidlTest, resetSimReq) {
97 token = GetRandomSerialNumber();
98
99 sap->resetSimReq(token);
100 EXPECT_EQ(std::cv_status::no_timeout, wait());
101 EXPECT_EQ(sapCb->sapResponseToken, token);
102
103 ASSERT_TRUE(
104 CheckAnyOfErrors(sapCb->sapResultCode,
105 {SapResultCode::GENERIC_FAILURE, SapResultCode::CARD_NOT_ACCESSSIBLE,
106 SapResultCode::CARD_ALREADY_POWERED_OFF, SapResultCode::CARD_REMOVED}));
107 }
108
109 /*
110 * Test IRadio.transferCardReaderStatusReq() for the response returned.
111 */
TEST_F(SapHidlTest,transferCardReaderStatusReq)112 TEST_F(SapHidlTest, transferCardReaderStatusReq) {
113 token = GetRandomSerialNumber();
114
115 sap->transferCardReaderStatusReq(token);
116 EXPECT_EQ(std::cv_status::no_timeout, wait());
117 EXPECT_EQ(sapCb->sapResponseToken, token);
118
119 ASSERT_TRUE(CheckAnyOfErrors(
120 sapCb->sapResultCode, {SapResultCode::GENERIC_FAILURE, SapResultCode::DATA_NOT_AVAILABLE}));
121 }
122
123 /*
124 * Test IRadio.setTransferProtocolReq() for the response returned.
125 */
TEST_F(SapHidlTest,setTransferProtocolReq)126 TEST_F(SapHidlTest, setTransferProtocolReq) {
127 token = GetRandomSerialNumber();
128 SapTransferProtocol sapTransferProtocol = SapTransferProtocol::T0;
129
130 sap->setTransferProtocolReq(token, sapTransferProtocol);
131 EXPECT_EQ(std::cv_status::no_timeout, wait());
132 EXPECT_EQ(sapCb->sapResponseToken, token);
133
134 EXPECT_EQ(SapResultCode::NOT_SUPPORTED, sapCb->sapResultCode);
135 }
136