• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include <gtest/gtest.h>
17 
18 #define private public
19 #include "connection_observer_controller.h"
20 #undef private
21 #include "connection_observer_errors.h"
22 
23 using namespace testing::ext;
24 using namespace OHOS::AbilityRuntime;
25 
26 namespace OHOS {
27 namespace AAFwk {
28 class ConnectionObserverControllerTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34 };
35 
SetUpTestCase(void)36 void ConnectionObserverControllerTest::SetUpTestCase(void)
37 {}
TearDownTestCase(void)38 void ConnectionObserverControllerTest::TearDownTestCase(void)
39 {}
SetUp(void)40 void ConnectionObserverControllerTest::SetUp(void)
41 {}
TearDown(void)42 void ConnectionObserverControllerTest::TearDown(void)
43 {}
44 
45 /*
46  * Feature: ConnectionObserverController
47  * Function: AddObserver
48  * SubFunction: NA
49  * FunctionPoints: ConnectionObserverController AddObserver
50  * EnvConditions: NA
51  * CaseDescription: Verify AddObserver
52  */
53 HWTEST_F(ConnectionObserverControllerTest, AddObserver_001, TestSize.Level1)
54 {
55     auto connectionObserverController = std::make_shared<ConnectionObserverController>();
56     sptr<IConnectionObserver> observer = nullptr;
57     auto res = connectionObserverController->AddObserver(observer);
58     EXPECT_EQ(res, ERR_INVALID_OBSERVER);
59 }
60 
61 /*
62  * Feature: ConnectionObserverController
63  * Function: RemoveObserver
64  * SubFunction: NA
65  * FunctionPoints: ConnectionObserverController RemoveObserver
66  * EnvConditions: NA
67  * CaseDescription: Verify RemoveObserver
68  */
69 HWTEST_F(ConnectionObserverControllerTest, RemoveObserver_001, TestSize.Level1)
70 {
71     auto connectionObserverController = std::make_shared<ConnectionObserverController>();
72     sptr<IConnectionObserver> observer = nullptr;
73     connectionObserverController->RemoveObserver(observer);
74 }
75 
76 /*
77  * Feature: ConnectionObserverController
78  * Function: NotifyExtensionConnected
79  * SubFunction: NA
80  * FunctionPoints: ConnectionObserverController NotifyExtensionConnected
81  * EnvConditions: NA
82  * CaseDescription: Verify NotifyExtensionConnected
83  */
84 HWTEST_F(ConnectionObserverControllerTest, NotifyExtensionConnected_001, TestSize.Level1)
85 {
86     auto connectionObserverController = std::make_shared<ConnectionObserverController>();
87     ConnectionData data;
88     connectionObserverController->NotifyExtensionConnected(data);
89 }
90 
91 /*
92  * Feature: ConnectionObserverController
93  * Function: NotifyExtensionDisconnected
94  * SubFunction: NA
95  * FunctionPoints: ConnectionObserverController NotifyExtensionDisconnected
96  * EnvConditions: NA
97  * CaseDescription: Verify NotifyExtensionDisconnected
98  */
99 HWTEST_F(ConnectionObserverControllerTest, NotifyExtensionDisconnected_001, TestSize.Level1)
100 {
101     auto connectionObserverController = std::make_shared<ConnectionObserverController>();
102     ConnectionData data;
103     connectionObserverController->NotifyExtensionDisconnected(data);
104 }
105 
106 /*
107  * Feature: ConnectionObserverController
108  * Function: NotifyDlpAbilityOpened
109  * SubFunction: NA
110  * FunctionPoints: ConnectionObserverController NotifyDlpAbilityOpened
111  * EnvConditions: NA
112  * CaseDescription: Verify NotifyDlpAbilityOpened
113  */
114 HWTEST_F(ConnectionObserverControllerTest, NotifyDlpAbilityOpened_001, TestSize.Level1)
115 {
116     auto connectionObserverController = std::make_shared<ConnectionObserverController>();
117     DlpStateData data;
118     connectionObserverController->NotifyDlpAbilityOpened(data);
119 }
120 
121 /*
122  * Feature: ConnectionObserverController
123  * Function: NotifyDlpAbilityClosed
124  * SubFunction: NA
125  * FunctionPoints: ConnectionObserverController NotifyDlpAbilityClosed
126  * EnvConditions: NA
127  * CaseDescription: Verify NotifyDlpAbilityClosed
128  */
129 HWTEST_F(ConnectionObserverControllerTest, NotifyDlpAbilityClosed_001, TestSize.Level1)
130 {
131     auto connectionObserverController = std::make_shared<ConnectionObserverController>();
132     DlpStateData data;
133     connectionObserverController->NotifyDlpAbilityClosed(data);
134 }
135 
136 /*
137  * Feature: ConnectionObserverController
138  * Function: GetObservers
139  * SubFunction: NA
140  * FunctionPoints: ConnectionObserverController GetObservers
141  * EnvConditions: NA
142  * CaseDescription: Verify GetObservers
143  */
144 HWTEST_F(ConnectionObserverControllerTest, GetObservers_001, TestSize.Level1)
145 {
146     auto connectionObserverController = std::make_shared<ConnectionObserverController>();
147     std::vector<sptr<AbilityRuntime::IConnectionObserver>> observers;
148     auto res = connectionObserverController->GetObservers();
149     EXPECT_EQ(res, observers);
150 }
151 
152 /*
153  * Feature: ConnectionObserverController
154  * Function: HandleRemoteDied
155  * SubFunction: NA
156  * FunctionPoints: ConnectionObserverController HandleRemoteDied
157  * EnvConditions: NA
158  * CaseDescription: Verify HandleRemoteDied
159  */
160 HWTEST_F(ConnectionObserverControllerTest, HandleRemoteDied_001, TestSize.Level1)
161 {
162     auto connectionObserverController = std::make_shared<ConnectionObserverController>();
163     wptr<IRemoteObject> remote;
164     connectionObserverController->HandleRemoteDied(remote);
165 }
166 
167 /*
168  * Feature: ObserverDeathRecipient
169  * Function: OnRemoteDied
170  * SubFunction: NA
171  * FunctionPoints: ConnectionObserverController OnRemoteDied
172  * EnvConditions: NA
173  * CaseDescription: Verify OnRemoteDied
174  */
175 HWTEST_F(ConnectionObserverControllerTest, OnRemoteDied_001, TestSize.Level1)
176 {
177     auto connectionObserverController = std::make_shared<ConnectionObserverController>();
178     ConnectionObserverController::ObserverDeathRecipient::ObserverDeathHandler handler;
179     auto observerDeathRecipient = std::make_shared<ConnectionObserverController::ObserverDeathRecipient>(handler);
180     wptr<IRemoteObject> remote;
181     observerDeathRecipient->OnRemoteDied(remote);
182 }
183 }  // namespace AAFwk
184 }  // namespace OHOS
185