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 "nfc_ability_connection_callback.h"
19
20 namespace OHOS {
21 namespace NFC {
22 namespace TEST {
23 using namespace testing::ext;
24 using namespace OHOS::NFC;
25 class NfcAbilityConnectionCallbackTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 void SetUp();
30 void TearDown();
31 };
32
SetUpTestCase()33 void NfcAbilityConnectionCallbackTest::SetUpTestCase()
34 {
35 std::cout << " SetUpTestCase NfcAbilityConnectionCallbackTest." << std::endl;
36 }
37
TearDownTestCase()38 void NfcAbilityConnectionCallbackTest::TearDownTestCase()
39 {
40 std::cout << " TearDownTestCase NfcAbilityConnectionCallbackTest." << std::endl;
41 }
42
SetUp()43 void NfcAbilityConnectionCallbackTest::SetUp()
44 {
45 std::cout << " SetUp NfcAbilityConnectionCallbackTest." << std::endl;
46 }
47
TearDown()48 void NfcAbilityConnectionCallbackTest::TearDown()
49 {
50 std::cout << " TearDown NfcAbilityConnectionCallbackTest." << std::endl;
51 }
52
53 /**
54 * @tc.name: OnAbilityConnectDone001
55 * @tc.desc: Test NfcAbilityConnectionCallbackTest OnAbilityConnectDone.
56 * @tc.type: FUNC
57 */
58 HWTEST_F(NfcAbilityConnectionCallbackTest, OnAbilityConnectDone001, TestSize.Level1)
59 {
60 AppExecFwk::ElementName element;
61 sptr<IRemoteObject> remoteObject = nullptr;
62 int resultCode = 0;
63 std::shared_ptr<NfcAbilityConnectionCallback> nfcAbilityConnectionCallback =
64 std::make_shared<NfcAbilityConnectionCallback>();
65 nfcAbilityConnectionCallback->OnAbilityConnectDone(element, remoteObject, resultCode);
66 bool serviceConnected = nfcAbilityConnectionCallback->ServiceConnected();
67 ASSERT_TRUE(serviceConnected);
68 }
69
70 /**
71 * @tc.name: OnAbilityDisconnectDone001
72 * @tc.desc: Test NfcAbilityConnectionCallbackTest OnAbilityDisconnectDone.
73 * @tc.type: FUNC
74 */
75 HWTEST_F(NfcAbilityConnectionCallbackTest, OnAbilityDisconnectDone001, TestSize.Level1)
76 {
77 AppExecFwk::ElementName element;
78 int resultCode = 0;
79 std::shared_ptr<NfcAbilityConnectionCallback> nfcAbilityConnectionCallback =
80 std::make_shared<NfcAbilityConnectionCallback>();
81 nfcAbilityConnectionCallback->OnAbilityDisconnectDone(element, resultCode);
82 bool serviceConnected = nfcAbilityConnectionCallback->ServiceConnected();
83 ASSERT_TRUE(!serviceConnected);
84 }
85
86 /**
87 * @tc.name: ServiceConnected001
88 * @tc.desc: Test NfcAbilityConnectionCallbackTest ServiceConnected.
89 * @tc.type: FUNC
90 */
91 HWTEST_F(NfcAbilityConnectionCallbackTest, ServiceConnected001, TestSize.Level1)
92 {
93 std::shared_ptr<NfcAbilityConnectionCallback> nfcAbilityConnectionCallback =
94 std::make_shared<NfcAbilityConnectionCallback>();
95 bool serviceConnected = nfcAbilityConnectionCallback->ServiceConnected();
96 ASSERT_TRUE(!serviceConnected);
97 }
98
99 /**
100 * @tc.name: SetHceManager001
101 * @tc.desc: Test NfcAbilityConnectionCallbackTest SetHceManager.
102 * @tc.type: FUNC
103 */
104 HWTEST_F(NfcAbilityConnectionCallbackTest, SetHceManager001, TestSize.Level1)
105 {
106 std::shared_ptr<HostCardEmulationManager> hceManager = nullptr;
107 std::shared_ptr<NfcAbilityConnectionCallback> nfcAbilityConnectionCallback =
108 std::make_shared<NfcAbilityConnectionCallback>();
109 nfcAbilityConnectionCallback->SetHceManager(hceManager);
110 bool serviceConnected = nfcAbilityConnectionCallback->ServiceConnected();
111 ASSERT_TRUE(!serviceConnected);
112 }
113
114 /**
115 * @tc.name: GetConnectedElement001
116 * @tc.desc: Test NfcAbilityConnectionCallbackTest GetConnectedElement.
117 * @tc.type: FUNC
118 */
119 HWTEST_F(NfcAbilityConnectionCallbackTest, GetConnectedElement001, TestSize.Level1)
120 {
121 std::shared_ptr<NfcAbilityConnectionCallback> nfcAbilityConnectionCallback =
122 std::make_shared<NfcAbilityConnectionCallback>();
123 nfcAbilityConnectionCallback->GetConnectedElement();
124 bool serviceConnected = nfcAbilityConnectionCallback->ServiceConnected();
125 ASSERT_TRUE(!serviceConnected);
126 }
127 }
128 }
129 }