1bc2ed2b3Sopenharmony_ci/* 2bc2ed2b3Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3bc2ed2b3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4bc2ed2b3Sopenharmony_ci * you may not use this file except in compliance with the License. 5bc2ed2b3Sopenharmony_ci * You may obtain a copy of the License at 6bc2ed2b3Sopenharmony_ci * 7bc2ed2b3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bc2ed2b3Sopenharmony_ci * 9bc2ed2b3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bc2ed2b3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11bc2ed2b3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bc2ed2b3Sopenharmony_ci * See the License for the specific language governing permissions and 13bc2ed2b3Sopenharmony_ci * limitations under the License. 14bc2ed2b3Sopenharmony_ci */ 15bc2ed2b3Sopenharmony_ci#include <gtest/gtest.h> 16bc2ed2b3Sopenharmony_ci#include <thread> 17bc2ed2b3Sopenharmony_ci 18bc2ed2b3Sopenharmony_ci#include "cardEmulation.h" 19bc2ed2b3Sopenharmony_ci#include "nfc_sdk_common.h" 20bc2ed2b3Sopenharmony_ci#include "card_emulation/ce_service.h" 21bc2ed2b3Sopenharmony_ci 22bc2ed2b3Sopenharmony_cinamespace OHOS { 23bc2ed2b3Sopenharmony_cinamespace NFC { 24bc2ed2b3Sopenharmony_cinamespace TEST { 25bc2ed2b3Sopenharmony_ciusing namespace testing::ext; 26bc2ed2b3Sopenharmony_ciusing namespace OHOS::NFC::KITS; 27bc2ed2b3Sopenharmony_ciclass CardemulationTest : public testing::Test { 28bc2ed2b3Sopenharmony_cipublic: 29bc2ed2b3Sopenharmony_ci static void SetUpTestCase(); 30bc2ed2b3Sopenharmony_ci static void TearDownTestCase(); 31bc2ed2b3Sopenharmony_ci void SetUp(); 32bc2ed2b3Sopenharmony_ci void TearDown(); 33bc2ed2b3Sopenharmony_ci}; 34bc2ed2b3Sopenharmony_ci 35bc2ed2b3Sopenharmony_civoid CardemulationTest::SetUpTestCase() 36bc2ed2b3Sopenharmony_ci{ 37bc2ed2b3Sopenharmony_ci std::cout << " SetUpTestCase CardemulationTest." << std::endl; 38bc2ed2b3Sopenharmony_ci} 39bc2ed2b3Sopenharmony_ci 40bc2ed2b3Sopenharmony_civoid CardemulationTest::TearDownTestCase() 41bc2ed2b3Sopenharmony_ci{ 42bc2ed2b3Sopenharmony_ci std::cout << " TearDownTestCase CardemulationTest." << std::endl; 43bc2ed2b3Sopenharmony_ci} 44bc2ed2b3Sopenharmony_ci 45bc2ed2b3Sopenharmony_civoid CardemulationTest::SetUp() {} 46bc2ed2b3Sopenharmony_ci 47bc2ed2b3Sopenharmony_civoid CardemulationTest::TearDown() {} 48bc2ed2b3Sopenharmony_ci 49bc2ed2b3Sopenharmony_ci/** 50bc2ed2b3Sopenharmony_ci * @tc.name: IsSupported001 51bc2ed2b3Sopenharmony_ci * @tc.desc: Test CardemulationTest IsSupported. 52bc2ed2b3Sopenharmony_ci * @tc.type: FUNC 53bc2ed2b3Sopenharmony_ci */ 54bc2ed2b3Sopenharmony_ciHWTEST_F(CardemulationTest, IsSupported001, TestSize.Level1) 55bc2ed2b3Sopenharmony_ci{ 56bc2ed2b3Sopenharmony_ci bool isSupport = false; 57bc2ed2b3Sopenharmony_ci CardEmulation cardemulation = CardEmulation::GetInstance(); 58bc2ed2b3Sopenharmony_ci 59bc2ed2b3Sopenharmony_ci // Supports FeatureType { HCE = 0, UICC = 1, ESE = 2 } type card emulation 60bc2ed2b3Sopenharmony_ci isSupport = cardemulation.IsSupported(FeatureType::UICC); 61bc2ed2b3Sopenharmony_ci ASSERT_TRUE(isSupport == true); 62bc2ed2b3Sopenharmony_ci} 63bc2ed2b3Sopenharmony_ci/** 64bc2ed2b3Sopenharmony_ci * @tc.name: IsSupported002 65bc2ed2b3Sopenharmony_ci * @tc.desc: Test CardemulationTest IsSupported. 66bc2ed2b3Sopenharmony_ci * @tc.type: FUNC 67bc2ed2b3Sopenharmony_ci */ 68bc2ed2b3Sopenharmony_ciHWTEST_F(CardemulationTest, IsSupported002, TestSize.Level1) 69bc2ed2b3Sopenharmony_ci{ 70bc2ed2b3Sopenharmony_ci bool isSupport = false; 71bc2ed2b3Sopenharmony_ci CardEmulation cardemulation = CardEmulation::GetInstance(); 72bc2ed2b3Sopenharmony_ci 73bc2ed2b3Sopenharmony_ci // Supports FeatureType { HCE = 0, UICC = 1, ESE = 2 } type card emulation 74bc2ed2b3Sopenharmony_ci isSupport = cardemulation.IsSupported(FeatureType::HCE); 75bc2ed2b3Sopenharmony_ci ASSERT_TRUE(isSupport == true); 76bc2ed2b3Sopenharmony_ci} 77bc2ed2b3Sopenharmony_ci/** 78bc2ed2b3Sopenharmony_ci * @tc.name: IsSupported003 79bc2ed2b3Sopenharmony_ci * @tc.desc: Test CardemulationTest IsSupported. 80bc2ed2b3Sopenharmony_ci * @tc.type: FUNC 81bc2ed2b3Sopenharmony_ci */ 82bc2ed2b3Sopenharmony_ciHWTEST_F(CardemulationTest, IsSupported003, TestSize.Level1) 83bc2ed2b3Sopenharmony_ci{ 84bc2ed2b3Sopenharmony_ci bool isSupport = false; 85bc2ed2b3Sopenharmony_ci CardEmulation cardemulation = CardEmulation::GetInstance(); 86bc2ed2b3Sopenharmony_ci 87bc2ed2b3Sopenharmony_ci // Supports FeatureType { HCE = 0, UICC = 1, ESE = 2 } type card emulation 88bc2ed2b3Sopenharmony_ci isSupport = cardemulation.IsSupported(FeatureType::ESE); 89bc2ed2b3Sopenharmony_ci ASSERT_TRUE(isSupport == true); 90bc2ed2b3Sopenharmony_ci} 91bc2ed2b3Sopenharmony_ci/** 92bc2ed2b3Sopenharmony_ci * @tc.name: IsSupported004 93bc2ed2b3Sopenharmony_ci * @tc.desc: Test CardemulationTest IsSupported. 94bc2ed2b3Sopenharmony_ci * @tc.type: FUNC 95bc2ed2b3Sopenharmony_ci */ 96bc2ed2b3Sopenharmony_ciHWTEST_F(CardemulationTest, IsSupported004, TestSize.Level1) 97bc2ed2b3Sopenharmony_ci{ 98bc2ed2b3Sopenharmony_ci bool isSupport = true; 99bc2ed2b3Sopenharmony_ci CardEmulation cardemulation = CardEmulation::GetInstance(); 100bc2ed2b3Sopenharmony_ci 101bc2ed2b3Sopenharmony_ci // card emulation is not supported 102bc2ed2b3Sopenharmony_ci isSupport = cardemulation.IsSupported(static_cast<FeatureType>(ErrorCode::ERR_NFC_BASE)); 103bc2ed2b3Sopenharmony_ci ASSERT_TRUE(isSupport == false); 104bc2ed2b3Sopenharmony_ci} 105bc2ed2b3Sopenharmony_ci 106bc2ed2b3Sopenharmony_ci/** 107bc2ed2b3Sopenharmony_ci * @tc.name: CeService001 108bc2ed2b3Sopenharmony_ci * @tc.desc: Test CeService001. 109bc2ed2b3Sopenharmony_ci * @tc.type: FUNC 110bc2ed2b3Sopenharmony_ci */ 111bc2ed2b3Sopenharmony_ciHWTEST_F(CardemulationTest, CeService001, TestSize.Level1) 112bc2ed2b3Sopenharmony_ci{ 113bc2ed2b3Sopenharmony_ci std::shared_ptr<NfcService> nfcService = nullptr; 114bc2ed2b3Sopenharmony_ci std::shared_ptr<NCI::INciCeInterface> nciCeProxy = nullptr; 115bc2ed2b3Sopenharmony_ci std::shared_ptr<CeService> ceService = std::make_shared<CeService>(nfcService, nciCeProxy); 116bc2ed2b3Sopenharmony_ci ceService->PublishFieldOnOrOffCommonEvent(true); 117bc2ed2b3Sopenharmony_ci ceService->PublishFieldOnOrOffCommonEvent(false); 118bc2ed2b3Sopenharmony_ci ceService->HandleFieldActivated(); 119bc2ed2b3Sopenharmony_ci ceService->HandleFieldDeactivated(); 120bc2ed2b3Sopenharmony_ci} 121bc2ed2b3Sopenharmony_ci 122bc2ed2b3Sopenharmony_ci/** 123bc2ed2b3Sopenharmony_ci * @tc.name: CeService002 124bc2ed2b3Sopenharmony_ci * @tc.desc: Test CeService002. 125bc2ed2b3Sopenharmony_ci * @tc.type: FUNC 126bc2ed2b3Sopenharmony_ci */ 127bc2ed2b3Sopenharmony_ciHWTEST_F(CardemulationTest, CeService002, TestSize.Level1) 128bc2ed2b3Sopenharmony_ci{ 129bc2ed2b3Sopenharmony_ci std::shared_ptr<NfcService> nfcService = nullptr; 130bc2ed2b3Sopenharmony_ci std::shared_ptr<NCI::INciCeInterface> nciCeProxy = nullptr; 131bc2ed2b3Sopenharmony_ci std::shared_ptr<CeService> ceService = std::make_shared<CeService>(nfcService, nciCeProxy); 132bc2ed2b3Sopenharmony_ci ceService->HandleFieldActivated(); 133bc2ed2b3Sopenharmony_ci ceService->HandleFieldDeactivated(); 134bc2ed2b3Sopenharmony_ci} 135bc2ed2b3Sopenharmony_ci} 136bc2ed2b3Sopenharmony_ci} 137bc2ed2b3Sopenharmony_ci} 138