• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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<OHOS::NFC::NfcService> nfcService = std::make_shared<OHOS::NFC::NfcService>(nullptr);
114     OHOS::NFC::CeService *ceService = new OHOS::NFC::CeService(nfcService);
115     bool success = true;
116     bool initStaus = nfcService->Initialize();
117     ASSERT_TRUE(initStaus);
118 
119     ceService->PublishFieldOnOrOffCommonEvent(true);
120     ceService->PublishFieldOnOrOffCommonEvent(false);
121     ceService->HandleFieldActivated();
122     ceService->HandleFieldDeactivated();
123     delete ceService;
124     ASSERT_TRUE(success);
125 }
126 
127 /**
128  * @tc.name: CeService002
129  * @tc.desc: Test CeService002.
130  * @tc.type: FUNC
131  */
132 HWTEST_F(CardemulationTest, CeService002, TestSize.Level1)
133 {
134     std::shared_ptr<OHOS::NFC::NfcService> nfcService = std::make_shared<OHOS::NFC::NfcService>(nullptr);
135     OHOS::NFC::CeService *ceService = new OHOS::NFC::CeService(nfcService);
136     bool success = true;
137     nfcService = nullptr; // release the NfcService, let to be expired.
138     ceService->HandleFieldActivated();
139     ceService->HandleFieldDeactivated();
140     delete ceService;
141     ASSERT_TRUE(success);
142 }
143 }
144 }
145 }
146