1 /*
2 * Copyright (c) 2025 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 <vector>
17 #include <memory>
18
19 #include <unistd.h>
20
21 #include "device_manager.h"
22 #include <gtest/gtest.h>
23 #include "intention_dumper.h"
24
25 #include "devicestatus_define.h"
26 #include "devicestatus_errors.h"
27 #include "stationary_server.h"
28 #include "intention_service_test.h"
29 #include "ddm_adapter.h"
30 #include "dsoftbus_adapter.h"
31 #include "fi_log.h"
32 #include "input_adapter.h"
33 #include "intention_service.h"
34 #include "interaction_manager.h"
35 #include "ipc_skeleton.h"
36 #include "plugin_manager.h"
37
38 #undef LOG_TAG
39 #define LOG_TAG "IntentionDumperTest"
40
41 namespace OHOS {
42 namespace Msdp {
43 namespace DeviceStatus {
44 using namespace testing::ext;
45 namespace {
46 int32_t g_fd { 1 };
47 StationaryServer stationary;
48 constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
49 } // namespace
50
51 class IntentionDumperTest : public testing::Test {
52 public:
53 void SetUp();
54 void TearDown();
55 static void SetUpTestCase();
56 static void TearDownTestCase(void);
57 };
SetUpTestCase()58 void IntentionDumperTest::SetUpTestCase() {}
59
TearDownTestCase()60 void IntentionDumperTest::TearDownTestCase() {}
61
SetUp()62 void IntentionDumperTest::SetUp() {}
63
TearDown()64 void IntentionDumperTest::TearDown()
65 {
66 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
67 }
68
PostSyncTask(DTaskCallback callback)69 int32_t MockDelegateTasks::PostSyncTask(DTaskCallback callback)
70 {
71 return callback();
72 }
73
PostAsyncTask(DTaskCallback callback)74 int32_t MockDelegateTasks::PostAsyncTask(DTaskCallback callback)
75 {
76 return callback();
77 }
78
GetInstance()79 ContextService* ContextService::GetInstance()
80 {
81 static ContextService g_instance;
82 return &g_instance;
83 }
84
ContextService()85 ContextService::ContextService()
86 {
87 ddm_ = std::make_unique<DDMAdapter>();
88 input_ = std::make_unique<InputAdapter>();
89 pluginMgr_ = std::make_unique<PluginManager>(this);
90 dsoftbus_ = std::make_unique<DSoftbusAdapter>();
91 }
92
GetDelegateTasks()93 IDelegateTasks& ContextService::GetDelegateTasks()
94 {
95 return delegateTasks_;
96 }
97
GetDeviceManager()98 IDeviceManager& ContextService::GetDeviceManager()
99 {
100 return devMgr_;
101 }
102
GetTimerManager()103 ITimerManager& ContextService::GetTimerManager()
104 {
105 return timerMgr_;
106 }
107
GetDragManager()108 IDragManager& ContextService::GetDragManager()
109 {
110 return dragMgr_;
111 }
112
GetSocketSessionManager()113 ISocketSessionManager& ContextService::GetSocketSessionManager()
114 {
115 return socketSessionMgr_;
116 }
117
GetDDM()118 IDDMAdapter& ContextService::GetDDM()
119 {
120 return *ddm_;
121 }
122
GetPluginManager()123 IPluginManager& ContextService::GetPluginManager()
124 {
125 return *pluginMgr_;
126 }
127
GetInput()128 IInputAdapter& ContextService::GetInput()
129 {
130 return *input_;
131 }
132
GetDSoftbus()133 IDSoftbusAdapter& ContextService::GetDSoftbus()
134 {
135 return *dsoftbus_;
136 }
137
138 /**
139 * @tc.name: IntentionDumperTest001
140 * @tc.desc: test Intention Dumper
141 * @tc.type: FUNC
142 * @tc.require:
143 */
144 HWTEST_F(IntentionDumperTest, IntentionDumperTest001, TestSize.Level1)
145 {
146 CALL_TEST_DEBUG;
147 auto env1 = ContextService::GetInstance();
148 ASSERT_NE(env1, nullptr);
149 IntentionDumper dumper = IntentionDumper(env1, stationary);
150 std::vector<std::string> argList = {"s", "h", "l", "c", "d"};
151 ASSERT_NO_FATAL_FAILURE(dumper.Dump(g_fd, argList));
152 }
153
154 /**
155 * @tc.name: IntentionDumperTest002
156 * @tc.desc: test Intention Dumper
157 * @tc.type: FUNC
158 * @tc.require:
159 */
160 HWTEST_F(IntentionDumperTest, IntentionDumperTest002, TestSize.Level1)
161 {
162 CALL_TEST_DEBUG;
163 auto env = ContextService::GetInstance();
164 ASSERT_NE(env, nullptr);
165 IntentionDumper dumper = IntentionDumper(env, stationary);
166 int32_t value = 's';
167 ASSERT_NO_FATAL_FAILURE(dumper.DumpOnce(g_fd, value));
168 }
169
170 /**
171 * @tc.name: IntentionDumperTest003
172 * @tc.desc: test Intention Dumper
173 * @tc.type: FUNC
174 * @tc.require:
175 */
176 HWTEST_F(IntentionDumperTest, IntentionDumperTest003, TestSize.Level1)
177 {
178 CALL_TEST_DEBUG;
179 auto env = ContextService::GetInstance();
180 ASSERT_NE(env, nullptr);
181 IntentionDumper dumper = IntentionDumper(env, stationary);
182 int32_t value = 'l';
183 ASSERT_NO_FATAL_FAILURE(dumper.DumpOnce(g_fd, value));
184 }
185
186 /**
187 * @tc.name: IntentionDumperTest004
188 * @tc.desc: test Intention Dumper
189 * @tc.type: FUNC
190 * @tc.require:
191 */
192 HWTEST_F(IntentionDumperTest, IntentionDumperTest004, TestSize.Level1)
193 {
194 CALL_TEST_DEBUG;
195 auto env = ContextService::GetInstance();
196 ASSERT_NE(env, nullptr);
197 IntentionDumper dumper = IntentionDumper(env, stationary);
198 int32_t value = 'c';
199 ASSERT_NO_FATAL_FAILURE(dumper.DumpOnce(g_fd, value));
200 }
201
202 /**
203 * @tc.name: IntentionDumperTest005
204 * @tc.desc: test Intention Dumper
205 * @tc.type: FUNC
206 * @tc.require:
207 */
208 HWTEST_F(IntentionDumperTest, IntentionDumperTest005, TestSize.Level1)
209 {
210 CALL_TEST_DEBUG;
211 auto env = ContextService::GetInstance();
212 ASSERT_NE(env, nullptr);
213 IntentionDumper dumper = IntentionDumper(env, stationary);
214 int32_t value = 'd';
215 ASSERT_NO_FATAL_FAILURE(dumper.DumpOnce(g_fd, value));
216 }
217
218 /**
219 * @tc.name: IntentionDumperTest006
220 * @tc.desc: test Intention Dumper
221 * @tc.type: FUNC
222 * @tc.require:
223 */
224 HWTEST_F(IntentionDumperTest, IntentionDumperTest006, TestSize.Level1)
225 {
226 CALL_TEST_DEBUG;
227 auto env = ContextService::GetInstance();
228 ASSERT_NE(env, nullptr);
229 IntentionDumper dumper = IntentionDumper(env, stationary);
230 int32_t value = 'm';
231 ASSERT_NO_FATAL_FAILURE(dumper.DumpOnce(g_fd, value));
232 }
233
234 /**
235 * @tc.name: IntentionDumperTest007
236 * @tc.desc: test Intention Dumper
237 * @tc.type: FUNC
238 * @tc.require:
239 */
240 HWTEST_F(IntentionDumperTest, IntentionDumperTest007, TestSize.Level1)
241 {
242 CALL_TEST_DEBUG;
243 auto env = ContextService::GetInstance();
244 ASSERT_NE(env, nullptr);
245 IntentionDumper dumper = IntentionDumper(env, stationary);
246
247 int32_t value = 'y';
248 ASSERT_NO_FATAL_FAILURE(dumper.DumpOnce(g_fd, value));
249 }
250 } // namespace DeviceStatus
251 } // namespace Msdp
252 } // namespace OHOS