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 "nfc_sdk_common.h"
19 #include "on_card_emulation_notify_cb_stub.h"
20
21 namespace OHOS {
22 namespace NFC {
23 namespace TEST {
24 using namespace testing::ext;
25 using namespace OHOS::NFC::KITS;
26 class OnCardEmulationNotifyCbStubTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp();
31 void TearDown();
32 };
33
MyCallback(uint32_t,std::string)34 bool MyCallback(uint32_t, std::string)
35 {
36 return false;
37 }
38
SetUpTestCase()39 void OnCardEmulationNotifyCbStubTest::SetUpTestCase()
40 {
41 std::cout << " SetUpTestCase OnCardEmulationNotifyCbStubTest." << std::endl;
42 }
43
TearDownTestCase()44 void OnCardEmulationNotifyCbStubTest::TearDownTestCase()
45 {
46 std::cout << " TearDownTestCase OnCardEmulationNotifyCbStubTest." << std::endl;
47 }
48
SetUp()49 void OnCardEmulationNotifyCbStubTest::SetUp() {}
50
TearDown()51 void OnCardEmulationNotifyCbStubTest::TearDown() {}
52
53 /**
54 * @tc.name: RegisterCallback001
55 * @tc.desc: Test OnCardEmulationNotifyCbStubTest RegisterCallback.
56 * @tc.type: FUNC
57 */
58 HWTEST_F(OnCardEmulationNotifyCbStubTest, RegisterCallback001, TestSize.Level1)
59 {
60 ASSERT_TRUE(OnCardEmulationNotifyCbStub::GetInstance().RegisterCallback(nullptr));
61 }
62
63 /**
64 * @tc.name: RegisterCallback002
65 * @tc.desc: Test OnCardEmulationNotifyCbStubTest RegisterCallback.
66 * @tc.type: FUNC
67 */
68 HWTEST_F(OnCardEmulationNotifyCbStubTest, RegisterCallback002, TestSize.Level1)
69 {
70 OnCardEmulationNotifyCb callback = MyCallback;
71 ASSERT_TRUE(!(OnCardEmulationNotifyCbStub::GetInstance().RegisterCallback(callback)));
72 }
73
74 /**
75 * @tc.name: RegisterCallback003
76 * @tc.desc: Test OnCardEmulationNotifyCbStubTest RegisterCallback.
77 * @tc.type: FUNC
78 */
79 HWTEST_F(OnCardEmulationNotifyCbStubTest, RegisterCallback003, TestSize.Level1)
80 {
81 OnCardEmulationNotifyCb callback = MyCallback;
82 OnCardEmulationNotifyCbStub::GetInstance().RegisterCallback(callback);
83 ASSERT_TRUE(OnCardEmulationNotifyCbStub::GetInstance().RegisterCallback(callback));
84 }
85
86 /**
87 * @tc.name: OnRemoteRequest001
88 * @tc.desc: Test OnCardEmulationNotifyCbStubTest OnRemoteRequest.
89 * @tc.type: FUNC
90 */
91 HWTEST_F(OnCardEmulationNotifyCbStubTest, OnRemoteRequest001, TestSize.Level1)
92 {
93 MessageParcel data;
94 MessageParcel reply;
95 MessageOption option;
96 int ret = OnCardEmulationNotifyCbStub::GetInstance().OnRemoteRequest(0, data, reply, option);
97 ASSERT_TRUE(ret == KITS::ERR_NFC_PARAMETERS);
98 }
99
100 /**
101 * @tc.name: OnRemoteRequest002
102 * @tc.desc: Test OnCardEmulationNotifyCbStubTest OnRemoteRequest.
103 * @tc.type: FUNC
104 */
105 HWTEST_F(OnCardEmulationNotifyCbStubTest, OnRemoteRequest002, TestSize.Level1)
106 {
107 MessageParcel data;
108 MessageParcel reply;
109 MessageOption option;
110 std::u16string descriptor = u"ohos.nfc.IOnCardEmulationNotifyCb";
111 data.WriteInterfaceToken(descriptor);
112 data.WriteInt32(1);
113 int ret = OnCardEmulationNotifyCbStub::GetInstance().OnRemoteRequest(0, data, reply, option);
114 ASSERT_TRUE(ret == 1);
115 }
116
117 /**
118 * @tc.name: OnRemoteRequest004
119 * @tc.desc: Test OnCardEmulationNotifyCbStubTest OnRemoteRequest.
120 * @tc.type: FUNC
121 */
122 HWTEST_F(OnCardEmulationNotifyCbStubTest, OnRemoteRequest004, TestSize.Level1)
123 {
124 MessageParcel data;
125 MessageParcel reply;
126 MessageOption option;
127 std::u16string descriptor = u"ohos.nfc.IOnCardEmulationNotifyCb";
128 data.WriteInterfaceToken(descriptor);
129 data.WriteInt32(0);
130 int ret = OnCardEmulationNotifyCbStub::GetInstance().OnRemoteRequest(0, data, reply, option);
131 ASSERT_TRUE(ret);
132 }
133 }
134 }
135 }
136