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 std::cout << "OnCeApduData." << std::endl;
64 }
65
AsObject()66 OHOS::sptr<OHOS::IRemoteObject> AsObject() override {
67 return nullptr;
68 }
69 };
70
71 /**
72 * @tc.name: RegHceCmdCallback001
73 * @tc.desc: Test HceServiceTest RegHceCmdCallback.
74 * @tc.type: FUNC
75 */
76 HWTEST_F(HceServiceTest, RegHceCmdCallback001, TestSize.Level1)
77 {
78 sptr<HceCmdListener> callback = sptr<HceCmdListener>(new (std::nothrow) HceCmdListener());
79 int ret = HceService::GetInstance().RegHceCmdCallback(callback, "hceCmd");
80 ASSERT_TRUE(ret == NFC::KITS::ErrorCode::ERR_HCE_STATE_UNBIND);
81 }
82
83 /**
84 * @tc.name: SendRawFrame001
85 * @tc.desc: Test HceServiceTest SendRawFrame001.
86 * @tc.type: FUNC
87 */
88 HWTEST_F(HceServiceTest, SendRawFrame001, TestSize.Level1)
89 {
90 std::string hexCmdData = "010203";
91 std::string hexRespData = "";
92 int ret = HceService::GetInstance().SendRawFrame(hexCmdData, true, hexRespData);
93 ASSERT_TRUE(ret == NFC::KITS::ErrorCode::ERR_HCE_STATE_UNBIND);
94 }
95
96 /**
97 * @tc.name: GetPaymentServices001
98 * @tc.desc: Test HceServiceTest GetPaymentServices001.
99 * @tc.type: FUNC
100 */
101 HWTEST_F(HceServiceTest, GetPaymentServices001, TestSize.Level1)
102 {
103 std::vector<AbilityInfo> paymentAbilityInfos;
104 int ret = HceService::GetInstance().GetPaymentServices(paymentAbilityInfos);
105 ASSERT_TRUE(ret == NFC::KITS::ErrorCode::ERR_HCE_STATE_UNBIND);
106 }
107
108 /**
109 * @tc.name: IsDefaultService001
110 * @tc.desc: Test HceServiceTest IsDefaultService001.
111 * @tc.type: FUNC
112 */
113 HWTEST_F(HceServiceTest, IsDefaultService001, TestSize.Level1)
114 {
115 ElementName element;
116 std::string type = "";
117 bool isDefaultService = true;
118 int ret = HceService::GetInstance().IsDefaultService(element, type, isDefaultService);
119 ASSERT_TRUE(ret == NFC::KITS::ErrorCode::ERR_HCE_STATE_UNBIND);
120 }
121
122 /**
123 * @tc.name: StopHce001
124 * @tc.desc: Test HceServiceTest StopHce001.
125 * @tc.type: FUNC
126 */
127 HWTEST_F(HceServiceTest, StopHce001, TestSize.Level1)
128 {
129 ElementName element;
130 int ret = HceService::GetInstance().StopHce(element);
131 ASSERT_TRUE(ret == NFC::KITS::ErrorCode::ERR_HCE_STATE_UNBIND);
132 }
133
134 }
135 }
136 }