1 /*
2  * Copyright (c) 2023 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 #include "nfc_service.h"
18 #include "nfcc_nci_adapter.h"
19 
20 namespace OHOS {
21 namespace NFC {
22 namespace TEST {
23 using namespace testing::ext;
24 using namespace OHOS::NFC::NCI;
25 
26 class NfccNciAdapterTest : public testing::Test {
27 public:
SetUpTestCase()28     static void SetUpTestCase() {}
TearDownTestCase()29     static void TearDownTestCase() {}
30     void SetUp();
31     void TearDown();
32 
33     static const int ISO_DEP_MAX_TRANSEIVE_LENGTH = 0xFEFF;
34 };
35 
SetUp()36 void NfccNciAdapterTest::SetUp()
37 {
38 }
39 
TearDown()40 void NfccNciAdapterTest::TearDown()
41 {
42 }
43 
44 /**
45  * @tc.name: NfccNciAdapterTest001
46  * @tc.desc: Test Constructor
47  * @tc.type: FUNC
48  */
49 HWTEST_F(NfccNciAdapterTest, NfccNciAdapterTest001, TestSize.Level1)
50 {
51     NCI::NfccNciAdapter adapterObj = NCI::NfccNciAdapter::GetInstance();
52     EXPECT_TRUE(!adapterObj.IsTagActive());
53 }
54 
55 /**
56  * @tc.name: NfccNciAdapterTest002
57  * @tc.desc: Test Initialize or Deinitialize
58  * @tc.type: FUNC
59  */
60 HWTEST_F(NfccNciAdapterTest, NfccNciAdapterTest002, TestSize.Level1)
61 {
62     NCI::NfccNciAdapter adapterObj = NCI::NfccNciAdapter::GetInstance();
63     NCI::NfccNciAdapter::GetInstance().ClearT3tIdentifiersCache();
64     EXPECT_TRUE(NCI::NfccNciAdapter::GetInstance().GetLfT3tMax() == 0);
65     NCI::NfccNciAdapter::GetInstance().IsNfcActive();
66     adapterObj.Deinitialize();
67     std::string rawData = "00a40400";
68     adapterObj.SendRawFrame(rawData);
69     EXPECT_TRUE(NCI::NfccNciAdapter::GetInstance().GetLastError() == 0);
70 }
71 
72 /**
73  * @tc.name: NfccNciAdapterTest003
74  * @tc.desc: Test Connect or Disconnect
75  * @tc.type: FUNC
76  */
77 HWTEST_F(NfccNciAdapterTest, NfccNciAdapterTest003, TestSize.Level1)
78 {
79     NCI::NfccNciAdapter adapterObj = NCI::NfccNciAdapter::GetInstance();
80     adapterObj.SetScreenStatus(0xFF);
81     adapterObj.Initialize();
82     adapterObj.SetScreenStatus(0xFF);
83     adapterObj.SetScreenStatus(0xFF);
84     adapterObj.SetScreenStatus(0xF0);
85     adapterObj.SetScreenStatus(0xF2);
86     adapterObj.SetScreenStatus(0xF4);
87     adapterObj.SetScreenStatus(0xF8);
88     adapterObj.GetNciVersion();
89     std::string t3tIdentifier = "00a4";
90     EXPECT_TRUE(adapterObj.RegisterT3tIdentifier(t3tIdentifier));
91     adapterObj.DeregisterT3tIdentifier(0);
92     EXPECT_TRUE(adapterObj.CheckFirmware());
93     adapterObj.Dump(0);
94     adapterObj.FactoryReset();
95     adapterObj.Shutdown();
96     EXPECT_TRUE(!adapterObj.IsTagActive());
97 
98     EXPECT_TRUE(!adapterObj.IsRfEbabled());
99 }
100 }
101 }
102 }
103