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 
16 #include <gtest/gtest.h>
17 #include <thread>
18 
19 #include "hce_service.h"
20 #include "nfc_controller.h"
21 
22 namespace OHOS {
23 namespace NFC {
24 namespace TEST {
25 using namespace testing::ext;
26 using namespace OHOS::NFC::KITS;
27 class HceServiceTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase()35 void HceServiceTest::SetUpTestCase()
36 {
37     std::cout << " SetUpTestCase HceServiceTest." << std::endl;
38 }
39 
TearDownTestCase()40 void HceServiceTest::TearDownTestCase()
41 {
42     std::cout << " TearDownTestCase HceServiceTest." << std::endl;
43 }
44 
SetUp()45 void HceServiceTest::SetUp()
46 {
47     std::cout << " SetUp HceServiceTest." << std::endl;
48 }
49 
TearDown()50 void HceServiceTest::TearDown()
51 {
52     std::cout << " TearDown HceServiceTest." << std::endl;
53 }
54 
55 class HceCmdListener : public IHceCmdCallback {
56 public:
HceCmdListener()57     HceCmdListener() {}
58 
~HceCmdListener()59     virtual ~HceCmdListener() {}
60 
61 public:
OnCeApduData(const std::vector<uint8_t> & data)62     void OnCeApduData(const std::vector<uint8_t>& data) override
63     {
64         std::cout << "OnCeApduData" << std::endl;
65     }
66 
AsObject()67     OHOS::sptr<OHOS::IRemoteObject> AsObject() override
68     {
69         return nullptr;
70     }
71 };
72 
73 /**
74  * @tc.name: RegHceCmdCallback001
75  * @tc.desc: Test HceServiceTest RegHceCmdCallback.
76  * @tc.type: FUNC
77  */
78 HWTEST_F(HceServiceTest, RegHceCmdCallback001, TestSize.Level1)
79 {
80     sptr<HceCmdListener> callback = sptr<HceCmdListener>(new (std::nothrow) HceCmdListener());
81     int ret = HceService::GetInstance().RegHceCmdCallback(callback, "hceCmd");
82     ASSERT_TRUE(ret == NFC::KITS::ErrorCode::ERR_NONE);
83 }
84 
85 /**
86  * @tc.name: SendRawFrame001
87  * @tc.desc: Test HceServiceTest SendRawFrame001.
88  * @tc.type: FUNC
89  */
90 HWTEST_F(HceServiceTest, SendRawFrame001, TestSize.Level1)
91 {
92     std::string hexCmdData = "010203";
93     std::string hexRespData = "";
94     int ret = HceService::GetInstance().SendRawFrame(hexCmdData, true, hexRespData);
95     ASSERT_TRUE(ret == NFC::KITS::ErrorCode::ERR_NONE);
96 }
97 
98 /**
99  * @tc.name: GetPaymentServices001
100  * @tc.desc: Test HceServiceTest GetPaymentServices001.
101  * @tc.type: FUNC
102  */
103 HWTEST_F(HceServiceTest, GetPaymentServices001, TestSize.Level1)
104 {
105     std::vector<AbilityInfo> abilityInfos;
106     int ret = HceService::GetInstance().GetPaymentServices(abilityInfos);
107     ASSERT_TRUE(ret == NFC::KITS::ErrorCode::ERR_NONE);
108 }
109 
110 /**
111  * @tc.name: IsDefaultService001
112  * @tc.desc: Test HceServiceTest IsDefaultService001.
113  * @tc.type: FUNC
114  */
115 HWTEST_F(HceServiceTest, IsDefaultService001, TestSize.Level1)
116 {
117     ElementName element;
118     const std::string type = "";
119     bool isDefaultService = true;
120     int ret = HceService::GetInstance().IsDefaultService(element, type, isDefaultService);
121     ASSERT_TRUE(ret == NFC::KITS::ErrorCode::ERR_NONE);
122 }
123 
124 /**
125  * @tc.name: StopHce001
126  * @tc.desc: Test HceServiceTest StopHce001.
127  * @tc.type: FUNC
128  */
129 HWTEST_F(HceServiceTest, StopHce001, TestSize.Level1)
130 {
131     ElementName element;
132     int ret = HceService::GetInstance().StopHce(element);
133     ASSERT_TRUE(ret == NFC::KITS::ErrorCode::ERR_NONE);
134 }
135 }
136 }
137 }