1 /*
2  * Copyright (c) 2022 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 "cardEmulation.h"
19 #include "nfc_sdk_common.h"
20 #include "card_emulation/ce_service.h"
21 
22 namespace OHOS {
23 namespace NFC {
24 namespace TEST {
25 using namespace testing::ext;
26 using namespace OHOS::NFC::KITS;
27 class CardemulationTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase()35 void CardemulationTest::SetUpTestCase()
36 {
37     std::cout << " SetUpTestCase CardemulationTest." << std::endl;
38 }
39 
TearDownTestCase()40 void CardemulationTest::TearDownTestCase()
41 {
42     std::cout << " TearDownTestCase CardemulationTest." << std::endl;
43 }
44 
SetUp()45 void CardemulationTest::SetUp() {}
46 
TearDown()47 void CardemulationTest::TearDown() {}
48 
49 /**
50  * @tc.name: IsSupported001
51  * @tc.desc: Test CardemulationTest IsSupported.
52  * @tc.type: FUNC
53  */
54 HWTEST_F(CardemulationTest, IsSupported001, TestSize.Level1)
55 {
56     bool isSupport = false;
57     CardEmulation cardemulation = CardEmulation::GetInstance();
58 
59     // Supports FeatureType { HCE = 0, UICC = 1, ESE = 2 } type card emulation
60     isSupport = cardemulation.IsSupported(FeatureType::UICC);
61     ASSERT_TRUE(isSupport == true);
62 }
63 /**
64  * @tc.name: IsSupported002
65  * @tc.desc: Test CardemulationTest IsSupported.
66  * @tc.type: FUNC
67  */
68 HWTEST_F(CardemulationTest, IsSupported002, TestSize.Level1)
69 {
70     bool isSupport = false;
71     CardEmulation cardemulation = CardEmulation::GetInstance();
72 
73     // Supports FeatureType { HCE = 0, UICC = 1, ESE = 2 } type card emulation
74     isSupport = cardemulation.IsSupported(FeatureType::HCE);
75     ASSERT_TRUE(isSupport == true);
76 }
77 /**
78  * @tc.name: IsSupported003
79  * @tc.desc: Test CardemulationTest IsSupported.
80  * @tc.type: FUNC
81  */
82 HWTEST_F(CardemulationTest, IsSupported003, TestSize.Level1)
83 {
84     bool isSupport = false;
85     CardEmulation cardemulation = CardEmulation::GetInstance();
86 
87     // Supports FeatureType { HCE = 0, UICC = 1, ESE = 2 } type card emulation
88     isSupport = cardemulation.IsSupported(FeatureType::ESE);
89     ASSERT_TRUE(isSupport == true);
90 }
91 /**
92  * @tc.name: IsSupported004
93  * @tc.desc: Test CardemulationTest IsSupported.
94  * @tc.type: FUNC
95  */
96 HWTEST_F(CardemulationTest, IsSupported004, TestSize.Level1)
97 {
98     bool isSupport = true;
99     CardEmulation cardemulation = CardEmulation::GetInstance();
100 
101     // card emulation is not supported
102     isSupport = cardemulation.IsSupported(static_cast<FeatureType>(ErrorCode::ERR_NFC_BASE));
103     ASSERT_TRUE(isSupport == false);
104 }
105 
106 /**
107  * @tc.name: CeService001
108  * @tc.desc: Test CeService001.
109  * @tc.type: FUNC
110  */
111 HWTEST_F(CardemulationTest, CeService001, TestSize.Level1)
112 {
113     std::shared_ptr<NfcService> nfcService = nullptr;
114     std::shared_ptr<NCI::INciCeInterface> nciCeProxy = nullptr;
115     std::shared_ptr<CeService> ceService = std::make_shared<CeService>(nfcService, nciCeProxy);
116     ceService->PublishFieldOnOrOffCommonEvent(true);
117     ceService->PublishFieldOnOrOffCommonEvent(false);
118     ceService->HandleFieldActivated();
119     ceService->HandleFieldDeactivated();
120 }
121 
122 /**
123  * @tc.name: CeService002
124  * @tc.desc: Test CeService002.
125  * @tc.type: FUNC
126  */
127 HWTEST_F(CardemulationTest, CeService002, TestSize.Level1)
128 {
129     std::shared_ptr<NfcService> nfcService = nullptr;
130     std::shared_ptr<NCI::INciCeInterface> nciCeProxy = nullptr;
131     std::shared_ptr<CeService> ceService = std::make_shared<CeService>(nfcService, nciCeProxy);
132     ceService->HandleFieldActivated();
133     ceService->HandleFieldDeactivated();
134 }
135 }
136 }
137 }
138