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
18 #include "hce_cmd_callback_stub.h"
19 #include "nfc_sdk_common.h"
20 #include "nfc_service_ipc_interface_code.h"
21
22 namespace OHOS {
23 namespace NFC {
24 namespace TEST {
25 using namespace testing::ext;
26 using namespace OHOS::NFC::KITS;
27 class HceCmdCallbackStubTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp();
32 void TearDown();
33 };
34
SetUpTestCase()35 void HceCmdCallbackStubTest::SetUpTestCase()
36 {
37 std::cout << " SetUpTestCase HceCmdCallbackStubTest." << std::endl;
38 }
39
TearDownTestCase()40 void HceCmdCallbackStubTest::TearDownTestCase()
41 {
42 std::cout << " TearDownTestCase HceCmdCallbackStubTest." << std::endl;
43 }
44
SetUp()45 void HceCmdCallbackStubTest::SetUp()
46 {
47 std::cout << " SetUp HceCmdCallbackStubTest." << std::endl;
48 }
49
TearDown()50 void HceCmdCallbackStubTest::TearDown()
51 {
52 std::cout << " TearDown HceCmdCallbackStubTest." << std::endl;
53 }
54
55 /**
56 * @tc.name: RegHceCmdCallback001
57 * @tc.desc: Test HceCmdCallbackStubTest RegHceCmdCallback.
58 * @tc.type: FUNC
59 */
60 HWTEST_F(HceCmdCallbackStubTest, RegHceCmdCallback001, TestSize.Level1)
61 {
62 const sptr<IHceCmdCallback> callback = nullptr;
63 HCE::HceCmdCallbackStub& hceCmdCallbackStub = HCE::HceCmdCallbackStub::GetInstance();
64 KITS::ErrorCode regHceCmdCallback = hceCmdCallbackStub.RegHceCmdCallback(callback);
65 ASSERT_TRUE(regHceCmdCallback == KITS::ERR_NFC_PARAMETERS);
66 }
67
68 /**
69 * @tc.name: UnRegHceCmdCallback001
70 * @tc.desc: Test HceCmdCallbackStubTest UnRegHceCmdCallback.
71 * @tc.type: FUNC
72 */
73 HWTEST_F(HceCmdCallbackStubTest, UnRegHceCmdCallback001, TestSize.Level1)
74 {
75 const sptr<IHceCmdCallback> callback = nullptr;
76 HCE::HceCmdCallbackStub& hceCmdCallbackStub = HCE::HceCmdCallbackStub::GetInstance();
77 KITS::ErrorCode regHceCmdCallback = hceCmdCallbackStub.UnRegHceCmdCallback(callback);
78 ASSERT_TRUE(regHceCmdCallback == KITS::ERR_NFC_PARAMETERS);
79 }
80
81 /**
82 * @tc.name: OnRemoteRequest001
83 * @tc.desc: Test HceCmdCallbackStubTest OnRemoteRequest.
84 * @tc.type: FUNC
85 */
86 HWTEST_F(HceCmdCallbackStubTest, OnRemoteRequest001, TestSize.Level1)
87 {
88 uint32_t code = static_cast<uint32_t>(NfcServiceIpcInterfaceCode::COMMAND_ON_NOTIFY);
89 MessageParcel data;
90 MessageParcel reply;
91 MessageOption option;
92 HCE::HceCmdCallbackStub& hceCmdCallbackStub = HCE::HceCmdCallbackStub::GetInstance();
93 int onRemoteRequest = hceCmdCallbackStub.OnRemoteRequest(code, data, reply, option);
94 ASSERT_TRUE(onRemoteRequest == ERR_NFC_PARAMETERS);
95 }
96 }
97 }
98 }