1 /*
2 * Copyright (c) 2023 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
18 #include "host_card_emulation_manager.h"
19 #include "ce_service.h"
20
21 namespace OHOS {
22 namespace NFC {
23 namespace TEST {
24 using namespace testing::ext;
25 using namespace OHOS::NFC::KITS;
26 class HostCardEmulationManagerTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp();
31 void TearDown();
32 };
33
SetUpTestCase()34 void HostCardEmulationManagerTest::SetUpTestCase()
35 {
36 std::cout << " SetUpTestCase HostCardEmulationManagerTest." << std::endl;
37 }
38
TearDownTestCase()39 void HostCardEmulationManagerTest::TearDownTestCase()
40 {
41 std::cout << " TearDownTestCase HostCardEmulationManagerTest." << std::endl;
42 }
43
SetUp()44 void HostCardEmulationManagerTest::SetUp()
45 {
46 std::cout << " SetUp HostCardEmulationManagerTest." << std::endl;
47 }
48
TearDown()49 void HostCardEmulationManagerTest::TearDown()
50 {
51 std::cout << " TearDown HostCardEmulationManagerTest." << std::endl;
52 }
53
54 /**
55 * @tc.name: OnHostCardEmulationDataNfcA001
56 * @tc.desc: Test HostCardEmulationManagerTest OnHostCardEmulationDataNfcA.
57 * @tc.type: FUNC
58 */
59 HWTEST_F(HostCardEmulationManagerTest, OnHostCardEmulationDataNfcA001, TestSize.Level1)
60 {
61 std::shared_ptr<NfcService> nfcService = nullptr;
62 std::shared_ptr<CeService> ceService = nullptr;
63 std::shared_ptr<NCI::INciCeInterface> nciCeProxy = nullptr;
64 std::vector<uint8_t> data;
65 sptr<KITS::IHceCmdCallback> callback = nullptr;
66 std::string type = "";
67 std::shared_ptr<HostCardEmulationManager> hostCardEmulationManager =
68 std::make_shared<HostCardEmulationManager>(nfcService, nciCeProxy, ceService);
69 hostCardEmulationManager->OnHostCardEmulationDataNfcA(data);
70 Security::AccessToken::AccessTokenID callerToken = 0;
71 bool regHceCmdCallback = hostCardEmulationManager->RegHceCmdCallback(callback, type, callerToken);
72 ASSERT_TRUE(regHceCmdCallback == false);
73 }
74
75 /**
76 * @tc.name: OnHostCardEmulationDataNfcA002
77 * @tc.desc: Test HostCardEmulationManagerTest OnHostCardEmulationDataNfcA.
78 * @tc.type: FUNC
79 */
80 HWTEST_F(HostCardEmulationManagerTest, OnHostCardEmulationDataNfcA002, TestSize.Level1)
81 {
82 std::shared_ptr<NfcService> nfcService = nullptr;
83 std::shared_ptr<NCI::INciCeInterface> nciCeProxy = nullptr;
84 std::shared_ptr<CeService> ceService = nullptr;
85 std::vector<uint8_t> data = {1, 2, 3, 4, 5, 6};
86 sptr<KITS::IHceCmdCallback> callback = nullptr;
87 std::string type = "";
88 std::shared_ptr<HostCardEmulationManager> hostCardEmulationManager =
89 std::make_shared<HostCardEmulationManager>(nfcService, nciCeProxy, ceService);
90 hostCardEmulationManager->OnHostCardEmulationDataNfcA(data);
91 Security::AccessToken::AccessTokenID callerToken = 0;
92 bool regHceCmdCallback = hostCardEmulationManager->RegHceCmdCallback(callback, type, callerToken);
93 ASSERT_TRUE(regHceCmdCallback == false);
94 }
95
96 /**
97 * @tc.name: OnCardEmulationActivated001
98 * @tc.desc: Test HostCardEmulationManagerTest OnCardEmulationActivated.
99 * @tc.type: FUNC
100 */
101 HWTEST_F(HostCardEmulationManagerTest, OnCardEmulationActivated001, TestSize.Level1)
102 {
103 std::shared_ptr<NfcService> nfcService = nullptr;
104 std::shared_ptr<NCI::INciCeInterface> nciCeProxy = nullptr;
105 std::shared_ptr<CeService> ceService = nullptr;
106 sptr<KITS::IHceCmdCallback> callback = nullptr;
107 std::string type = "";
108 std::shared_ptr<HostCardEmulationManager> hostCardEmulationManager =
109 std::make_shared<HostCardEmulationManager>(nfcService, nciCeProxy, ceService);
110 hostCardEmulationManager->OnCardEmulationActivated();
111 Security::AccessToken::AccessTokenID callerToken = 0;
112 bool regHceCmdCallback = hostCardEmulationManager->RegHceCmdCallback(callback, type, callerToken);
113 ASSERT_TRUE(regHceCmdCallback == false);
114 }
115
116 /**
117 * @tc.name: OnCardEmulationDeactivated001
118 * @tc.desc: Test HostCardEmulationManagerTest OnCardEmulationDeactivated.
119 * @tc.type: FUNC
120 */
121 HWTEST_F(HostCardEmulationManagerTest, OnCardEmulationDeactivated001, TestSize.Level1)
122 {
123 std::shared_ptr<NfcService> nfcService = nullptr;
124 std::shared_ptr<NCI::INciCeInterface> nciCeProxy = nullptr;
125 std::shared_ptr<CeService> ceService = nullptr;
126 sptr<KITS::IHceCmdCallback> callback = nullptr;
127 std::string type = "";
128 std::shared_ptr<HostCardEmulationManager> hostCardEmulationManager =
129 std::make_shared<HostCardEmulationManager>(nfcService, nciCeProxy, ceService);
130 hostCardEmulationManager->OnCardEmulationDeactivated();
131 Security::AccessToken::AccessTokenID callerToken = 0;
132 bool regHceCmdCallback = hostCardEmulationManager->RegHceCmdCallback(callback, type, callerToken);
133 ASSERT_TRUE(regHceCmdCallback == false);
134 }
135
136 /**
137 * @tc.name: SendHostApduData001
138 * @tc.desc: Test HostCardEmulationManagerTest SendHostApduData.
139 * @tc.type: FUNC
140 */
141 HWTEST_F(HostCardEmulationManagerTest, SendHostApduData001, TestSize.Level1)
142 {
143 std::shared_ptr<NfcService> nfcService = nullptr;
144 std::shared_ptr<NCI::INciCeInterface> nciCeProxy = nullptr;
145 std::shared_ptr<CeService> ceService = nullptr;
146 std::string hexCmdData = "";
147 bool raw = false;
148 std::string hexRespData = "";
149 std::shared_ptr<HostCardEmulationManager> hostCardEmulationManager =
150 std::make_shared<HostCardEmulationManager>(nfcService, nciCeProxy, ceService);
151 Security::AccessToken::AccessTokenID callerToken = 0;
152 bool sendHostApduData = hostCardEmulationManager->SendHostApduData(hexCmdData, raw, hexRespData, callerToken);
153 ASSERT_TRUE(sendHostApduData == false);
154 }
155
156 /**
157 * @tc.name: SendHostApduData002
158 * @tc.desc: Test HostCardEmulationManagerTest SendHostApduData.
159 * @tc.type: FUNC
160 */
161 HWTEST_F(HostCardEmulationManagerTest, SendHostApduData002, TestSize.Level1)
162 {
163 std::shared_ptr<NfcService> nfcService = std::make_shared<NfcService>();
164 std::shared_ptr<NCI::INciCeInterface> nciCeProxy = nullptr;
165 std::shared_ptr<CeService> ceService = nullptr;
166 std::string hexCmdData = "";
167 bool raw = false;
168 std::string hexRespData = "";
169 std::shared_ptr<HostCardEmulationManager> hostCardEmulationManager =
170 std::make_shared<HostCardEmulationManager>(nfcService, nciCeProxy, ceService);
171 Security::AccessToken::AccessTokenID callerToken = 0;
172 bool sendHostApduData = hostCardEmulationManager->SendHostApduData(hexCmdData, raw, hexRespData, callerToken);
173 ASSERT_TRUE(sendHostApduData == false);
174 }
175
176 /**
177 * @tc.name: HandleQueueData001
178 * @tc.desc: Test HostCardEmulationManagerTest HandleQueueData.
179 * @tc.type: FUNC
180 */
181 HWTEST_F(HostCardEmulationManagerTest, HandleQueueData001, TestSize.Level1)
182 {
183 std::shared_ptr<NfcService> nfcService = std::make_shared<NfcService>();
184 std::shared_ptr<NCI::INciCeInterface> nciCeProxy = nullptr;
185 std::shared_ptr<CeService> ceService = nullptr;
186 std::shared_ptr<HostCardEmulationManager> hostCardEmulationManager =
187 std::make_shared<HostCardEmulationManager>(nfcService, nciCeProxy, ceService);
188 hostCardEmulationManager->HandleQueueData();
189 }
190
191 /**
192 * @tc.name: UnRegHceCmdCallback001
193 * @tc.desc: Test HostCardEmulationManagerTest UnRegHceCmdCallback.
194 * @tc.type: FUNC
195 */
196 HWTEST_F(HostCardEmulationManagerTest, UnRegHceCmdCallback001, TestSize.Level1)
197 {
198 std::shared_ptr<NfcService> nfcService = std::make_shared<NfcService>();
199 std::shared_ptr<NCI::INciCeInterface> nciCeProxy = nullptr;
200 std::shared_ptr<CeService> ceService = nullptr;
201 std::string type = "";
202 Security::AccessToken::AccessTokenID callerToken = 0;
203 std::shared_ptr<HostCardEmulationManager> hostCardEmulationManager =
204 std::make_shared<HostCardEmulationManager>(nfcService, nciCeProxy, ceService);
205 bool res = hostCardEmulationManager->UnRegHceCmdCallback(type, callerToken);
206 ASSERT_TRUE(!res);
207 }
208 } // namespace TEST
209 } // namespace NFC
210 } // namespace OHOS