1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <gtest/gtest.h>
16 #include <thread>
17 #include <string>
18 #include <vector>
19 #include <securec.h>
20 #include <sstream>
21 #include <hdf_log.h>
22
23 #include "se_impl.h"
24 #include "se_vendor_adaptions.h"
25
26 namespace OHOS {
27 namespace HDI {
28 namespace SecureElement {
29 namespace TEST {
30 using namespace testing;
31 using namespace testing::ext;
32
33 class SeVendorAdaptionsTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp();
38 void TearDown();
39 };
40
SetUpTestCase()41 void SeVendorAdaptionsTest::SetUpTestCase()
42 {
43 HDF_LOGD("SetUpTestCase SeVendorAdaptionsTest");
44 }
45
TearDownTestCase()46 void SeVendorAdaptionsTest::TearDownTestCase()
47 {
48 HDF_LOGD("TearDownTestCase SeVendorAdaptionsTest");
49 }
50
SetUp()51 void SeVendorAdaptionsTest::SetUp()
52 {
53 HDF_LOGD("SetUp SeVendorAdaptionsTest");
54 }
55
TearDown()56 void SeVendorAdaptionsTest::TearDown()
57 {
58 HDF_LOGD("TearDown SeVendorAdaptionsTest");
59 }
60
61 /**
62 * @tc.name: getAtr001
63 * @tc.desc: Test SeVendorAdaptionsTest getAtr.
64 * @tc.type: FUNC
65 */
66 HWTEST_F(SeVendorAdaptionsTest, getAtr001, TestSize.Level1)
67 {
68 std::vector<uint8_t> response;
69 std::shared_ptr<SeVendorAdaptions> seVendorAdaptions = std::make_shared<SeVendorAdaptions>();
70 int ret = seVendorAdaptions->getAtr(response);
71 ASSERT_TRUE(ret == HDF_SUCCESS);
72 }
73
74 /**
75 * @tc.name: openLogicalChannel002
76 * @tc.desc: Test SeVendorAdaptionsTest openLogicalChannel.
77 * @tc.type: FUNC
78 */
79 HWTEST_F(SeVendorAdaptionsTest, openLogicalChannel002, TestSize.Level1)
80 {
81 std::vector<uint8_t> aid = {0x001, 0x002, 0x003};
82 uint8_t p2 = 0;
83 std::vector<uint8_t> response;
84 uint8_t channelNumber = 0;
85 SecureElementStatus status;
86 std::shared_ptr<SeVendorAdaptions> seVendorAdaptions = std::make_shared<SeVendorAdaptions>();
87 int ret = seVendorAdaptions->openLogicalChannel(aid, p2, response, channelNumber, status);
88 ASSERT_TRUE(ret == HDF_SUCCESS);
89 }
90
91 /**
92 * @tc.name: openBasicChannel002
93 * @tc.desc: Test SeVendorAdaptionsTest openBasicChannel.
94 * @tc.type: FUNC
95 */
96 HWTEST_F(SeVendorAdaptionsTest, openBasicChannel002, TestSize.Level1)
97 {
98 const std::vector<uint8_t> aid = {0x001, 0x002, 0x003};
99 uint8_t p2 = 0;
100 std::vector<uint8_t> response;
101 SecureElementStatus status;
102 std::shared_ptr<SeVendorAdaptions> seVendorAdaptions = std::make_shared<SeVendorAdaptions>();
103 int ret = seVendorAdaptions->openBasicChannel(aid, p2, response, status);
104 ASSERT_TRUE(ret == HDF_SUCCESS);
105 }
106
107 /**
108 * @tc.name: closeChannel001
109 * @tc.desc: Test SeVendorAdaptionsTest closeChannel.
110 * @tc.type: FUNC
111 */
112 HWTEST_F(SeVendorAdaptionsTest, closeChannel001, TestSize.Level1)
113 {
114 uint8_t channelNumber = 0;
115 SecureElementStatus status;
116 std::shared_ptr<SeVendorAdaptions> seVendorAdaptions = std::make_shared<SeVendorAdaptions>();
117 int ret = seVendorAdaptions->closeChannel(channelNumber, status);
118 ASSERT_TRUE(ret == HDF_SUCCESS);
119 }
120
121 /**
122 * @tc.name: transmit001
123 * @tc.desc: Test SeVendorAdaptionsTest transmit.
124 * @tc.type: FUNC
125 */
126 HWTEST_F(SeVendorAdaptionsTest, transmit001, TestSize.Level1)
127 {
128 const std::vector<uint8_t> command;
129 std::vector<uint8_t> response;
130 SecureElementStatus status;
131 std::shared_ptr<SeVendorAdaptions> seVendorAdaptions = std::make_shared<SeVendorAdaptions>();
132 int ret = seVendorAdaptions->transmit(command, response, status);
133 ASSERT_TRUE(ret == HDF_SUCCESS);
134 }
135
136 /**
137 * @tc.name: reset001
138 * @tc.desc: Test SeVendorAdaptionsTest reset.
139 * @tc.type: FUNC
140 */
141 HWTEST_F(SeVendorAdaptionsTest, reset001, TestSize.Level1)
142 {
143 SecureElementStatus status;
144 std::shared_ptr<SeVendorAdaptions> seVendorAdaptions = std::make_shared<SeVendorAdaptions>();
145 int ret = seVendorAdaptions->reset(status);
146 ASSERT_TRUE(ret == HDF_SUCCESS);
147 }
148
149 /**
150 * @tc.name: getStatusBySW001
151 * @tc.desc: Test SeVendorAdaptionsTest getStatusBySW.
152 * @tc.type: FUNC
153 */
154 HWTEST_F(SeVendorAdaptionsTest, getStatusBySW001, TestSize.Level1)
155 {
156 uint8_t sw1 = 0x62;
157 uint8_t sw2 = 0;
158 std::shared_ptr<SeVendorAdaptions> seVendorAdaptions = std::make_shared<SeVendorAdaptions>();
159 SecureElementStatus ret = seVendorAdaptions->getStatusBySW(sw1, sw2);
160 ASSERT_TRUE(ret == SecureElementStatus::SE_SUCCESS);
161 }
162
163 /**
164 * @tc.name: getStatusBySW002
165 * @tc.desc: Test SeVendorAdaptionsTest getStatusBySW.
166 * @tc.type: FUNC
167 */
168 HWTEST_F(SeVendorAdaptionsTest, getStatusBySW002, TestSize.Level1)
169 {
170 uint8_t sw1 = 0x63;
171 uint8_t sw2 = 0;
172 std::shared_ptr<SeVendorAdaptions> seVendorAdaptions = std::make_shared<SeVendorAdaptions>();
173 SecureElementStatus ret = seVendorAdaptions->getStatusBySW(sw1, sw2);
174 ASSERT_TRUE(ret == SecureElementStatus::SE_SUCCESS);
175 }
176
177 /**
178 * @tc.name: getStatusBySW003
179 * @tc.desc: Test SeVendorAdaptionsTest getStatusBySW.
180 * @tc.type: FUNC
181 */
182 HWTEST_F(SeVendorAdaptionsTest, getStatusBySW003, TestSize.Level1)
183 {
184 uint8_t sw1 = 0x90;
185 uint8_t sw2 = 0x00;
186 std::shared_ptr<SeVendorAdaptions> seVendorAdaptions = std::make_shared<SeVendorAdaptions>();
187 SecureElementStatus ret = seVendorAdaptions->getStatusBySW(sw1, sw2);
188 ASSERT_TRUE(ret == SecureElementStatus::SE_SUCCESS);
189 }
190
191 /**
192 * @tc.name: getStatusBySW004
193 * @tc.desc: Test SeVendorAdaptionsTest getStatusBySW.
194 * @tc.type: FUNC
195 */
196 HWTEST_F(SeVendorAdaptionsTest, getStatusBySW004, TestSize.Level1)
197 {
198 uint8_t sw1 = 0x6A;
199 uint8_t sw2 = 0x82;
200 std::shared_ptr<SeVendorAdaptions> seVendorAdaptions = std::make_shared<SeVendorAdaptions>();
201 SecureElementStatus ret = seVendorAdaptions->getStatusBySW(sw1, sw2);
202 ASSERT_TRUE(ret == SecureElementStatus::SE_NO_SUCH_ELEMENT_ERROR);
203 }
204
205 /**
206 * @tc.name: getStatusBySW005
207 * @tc.desc: Test SeVendorAdaptionsTest getStatusBySW.
208 * @tc.type: FUNC
209 */
210 HWTEST_F(SeVendorAdaptionsTest, getStatusBySW005, TestSize.Level1)
211 {
212 uint8_t sw1 = 0x69;
213 uint8_t sw2 = 0x99;
214 std::shared_ptr<SeVendorAdaptions> seVendorAdaptions = std::make_shared<SeVendorAdaptions>();
215 SecureElementStatus ret = seVendorAdaptions->getStatusBySW(sw1, sw2);
216 ASSERT_TRUE(ret == SecureElementStatus::SE_NO_SUCH_ELEMENT_ERROR);
217 }
218
219 /**
220 * @tc.name: getStatusBySW006
221 * @tc.desc: Test SeVendorAdaptionsTest getStatusBySW.
222 * @tc.type: FUNC
223 */
224 HWTEST_F(SeVendorAdaptionsTest, getStatusBySW006, TestSize.Level1)
225 {
226 uint8_t sw1 = 0x69;
227 uint8_t sw2 = 0x85;
228 std::shared_ptr<SeVendorAdaptions> seVendorAdaptions = std::make_shared<SeVendorAdaptions>();
229 SecureElementStatus ret = seVendorAdaptions->getStatusBySW(sw1, sw2);
230 ASSERT_TRUE(ret == SecureElementStatus::SE_NO_SUCH_ELEMENT_ERROR);
231 }
232
233 /**
234 * @tc.name: getStatusBySW007
235 * @tc.desc: Test SeVendorAdaptionsTest getStatusBySW.
236 * @tc.type: FUNC
237 */
238 HWTEST_F(SeVendorAdaptionsTest, getStatusBySW007, TestSize.Level1)
239 {
240 uint8_t sw1 = 0x6A;
241 uint8_t sw2 = 0x86;
242 std::shared_ptr<SeVendorAdaptions> seVendorAdaptions = std::make_shared<SeVendorAdaptions>();
243 SecureElementStatus ret = seVendorAdaptions->getStatusBySW(sw1, sw2);
244 ASSERT_TRUE(ret == SecureElementStatus::SE_OPERATION_NOT_SUPPORTED_ERROR);
245 }
246
247 /**
248 * @tc.name: getStatusBySW008
249 * @tc.desc: Test SeVendorAdaptionsTest getStatusBySW.
250 * @tc.type: FUNC
251 */
252 HWTEST_F(SeVendorAdaptionsTest, getStatusBySW008, TestSize.Level1)
253 {
254 uint8_t sw1 = 0;
255 uint8_t sw2 = 0;
256 std::shared_ptr<SeVendorAdaptions> seVendorAdaptions = std::make_shared<SeVendorAdaptions>();
257 SecureElementStatus ret = seVendorAdaptions->getStatusBySW(sw1, sw2);
258 ASSERT_TRUE(ret == SecureElementStatus::SE_GENERAL_ERROR);
259 }
260 }
261 }
262 }
263 }