1 /*
2  * Copyright (c) 2023-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 
18 #include "nfc_controller_callback_stub.h"
19 #include "nfc_service_ipc_interface_code.h"
20 
21 namespace OHOS {
22 namespace NFC {
23 namespace TEST {
24 using namespace testing::ext;
25 using namespace OHOS::NFC::KITS;
26 class NfcControllerCallBackStubTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp();
31     void TearDown();
32 };
33 
34 class INfcControllerCallbackImpl : public INfcControllerCallback {
35 public:
INfcControllerCallbackImpl()36     INfcControllerCallbackImpl() {}
37 
~INfcControllerCallbackImpl()38     virtual ~INfcControllerCallbackImpl() {}
39 
40 public:
OnNfcStateChanged(int nfcState)41     void OnNfcStateChanged(int nfcState) override
42     {
43     }
44 
AsObject()45     OHOS::sptr<OHOS::IRemoteObject> AsObject() override
46     {
47         return nullptr;
48     }
49 };
50 
SetUpTestCase()51 void NfcControllerCallBackStubTest::SetUpTestCase()
52 {
53     std::cout << " SetUpTestCase NfcControllerCallBackStubTest." << std::endl;
54 }
55 
TearDownTestCase()56 void NfcControllerCallBackStubTest::TearDownTestCase()
57 {
58     std::cout << " TearDownTestCase NfcControllerCallBackStubTest." << std::endl;
59 }
60 
SetUp()61 void NfcControllerCallBackStubTest::SetUp()
62 {
63     std::cout << " SetUp NfcControllerCallBackStubTest." << std::endl;
64 }
65 
TearDown()66 void NfcControllerCallBackStubTest::TearDown()
67 {
68     std::cout << " TearDown NfcControllerCallBackStubTest." << std::endl;
69 }
70 
71 /**
72  * @tc.name: RegisterCallBack001
73  * @tc.desc: Test NfcControllerCallBackStub RegisterCallBack.
74  * @tc.type: FUNC
75  */
76 HWTEST_F(NfcControllerCallBackStubTest, RegisterCallBack001, TestSize.Level1)
77 {
78     const sptr<INfcControllerCallback> callBack = nullptr;
79     NfcControllerCallBackStub& ctrl = NfcControllerCallBackStub::GetInstance();
80     KITS::ErrorCode registerCallBack = ctrl.RegisterCallBack(callBack);
81     ASSERT_TRUE(registerCallBack == KITS::ERR_NFC_PARAMETERS);
82 }
83 /**
84  * @tc.name: RegisterCallBack002
85  * @tc.desc: Test NfcControllerCallBackStub RegisterCallBack.
86  * @tc.type: FUNC
87  */
88 HWTEST_F(NfcControllerCallBackStubTest, RegisterCallBack002, TestSize.Level1)
89 {
90     NfcControllerCallBackStub& ctrl = NfcControllerCallBackStub::GetInstance();
91     const sptr<NfcControllerCallBackStub> g_nfcControllerCallbackStub =
92         sptr<NfcControllerCallBackStub>(new (std::nothrow) NfcControllerCallBackStub());
93     KITS::ErrorCode registerCallBack = ctrl.RegisterCallBack(g_nfcControllerCallbackStub);
94     ASSERT_TRUE(registerCallBack == KITS::ERR_NONE);
95 }
96 /**
97  * @tc.name: OnRemoteRequest001
98  * @tc.desc: Test NfcControllerCallBackStub OnRemoteRequest.
99  * @tc.type: FUNC
100  */
101 HWTEST_F(NfcControllerCallBackStubTest, OnRemoteRequest001, TestSize.Level1)
102 {
103     uint32_t code = static_cast<uint32_t>(NfcServiceIpcInterfaceCode::COMMAND_ON_NOTIFY);
104     MessageParcel data;
105     MessageParcel reply;
106     MessageOption option;
107     NfcControllerCallBackStub& ctrl = NfcControllerCallBackStub::GetInstance();
108     int onRemoteRequest = ctrl.OnRemoteRequest(code, data, reply, option);
109     ASSERT_TRUE(onRemoteRequest == KITS::ERR_NFC_PARAMETERS);
110 }
111 }
112 }
113 }
114