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 #include <chrono>
16 #include <thread>
17 #include <atomic>
18
19 #include "mechbody_controller_service_test.h"
20 #include "mc_motion_manager.h"
21 #include "bluetooth_errorcode.h"
22 #include "mechbody_controller_log.h"
23 #include "test_log.h"
24 #include "tokenid_kit.h"
25 #include "ipc_skeleton.h"
26 #include "securec.h"
27 #include "accesstoken_kit.h"
28 #include "token_setproc.h"
29 #include "tokenid_kit.h"
30 #include "system_ability.h"
31
32 using namespace testing;
33 using namespace testing::ext;
34 using namespace OHOS;
35
36 namespace {
37 constexpr int32_t MECHID = 1;
38 constexpr int32_t REVERTMECHID = -1;
39 constexpr int32_t DURATION = 1;
40 constexpr int32_t REVERTDURATION = -1;
41 constexpr float YAW = 1;
42 constexpr float ROLL = 1;
43 constexpr float PITCH = 1;
44 bool g_isSystemApp = true;
45 }
46
47 namespace OHOS {
48 namespace Security {
49 namespace AccessToken {
IsSystemAppByFullTokenID(uint64_t tokenId)50 bool TokenIdKit::IsSystemAppByFullTokenID(uint64_t tokenId)
51 {
52 return g_isSystemApp;
53 }
54 } // namespace AccessToken
55 } // namespace Security
56 } // namespace OHOS
57
58 namespace OHOS {
59 namespace MechBodyController {
SetUpTestCase()60 void MechBodyControllerServiceTest::SetUpTestCase()
61 {
62 DTEST_LOG << "MechBodyControllerServiceTest::SetUpTestCase" << std::endl;
63 }
64
TearDownTestCase()65 void MechBodyControllerServiceTest::TearDownTestCase()
66 {
67 DTEST_LOG << "MechBodyControllerServiceTest::TearDownTestCase" << std::endl;
68 }
69
TearDown()70 void MechBodyControllerServiceTest::TearDown()
71 {
72 DTEST_LOG << "MechBodyControllerServiceTest::TearDown" << std::endl;
73 }
74
SetUp()75 void MechBodyControllerServiceTest::SetUp()
76 {
77 DTEST_LOG << "MechBodyControllerServiceTest::SetUp" << std::endl;
78 }
79
80 /**
81 * @tc.name : OnStart_001
82 * @tc.number: OnStart_001
83 * @tc.desc : Test OnStart function.
84 */
85 HWTEST_F(MechBodyControllerServiceTest, OnStart_001, TestSize.Level1)
86 {
87 DTEST_LOG << "MechBodyControllerServiceTest OnStart_001 begin" << std::endl;
88
89 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
90 mechBodyControllerService.OnStart();
91 EXPECT_NE(mechBodyControllerService.sendAdapter_, nullptr);
92 DTEST_LOG << "MechBodyControllerServiceTest OnStart_001 end" << std::endl;
93 }
94
95 /**
96 * @tc.name : OnStop_001
97 * @tc.number: OnStop_001
98 * @tc.desc : Test OnStop function.
99 */
100 HWTEST_F(MechBodyControllerServiceTest, OnStop_001, TestSize.Level1)
101 {
102 DTEST_LOG << "MechBodyControllerServiceTest OnStop_001 begin" << std::endl;
103 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
104 EXPECT_NO_FATAL_FAILURE(mechBodyControllerService.OnStop());
105 DTEST_LOG << "MechBodyControllerServiceTest OnStop_001 end" << std::endl;
106 }
107
108 /**
109 * @tc.name : RegisterAttachStateChangeCallback_001
110 * @tc.number: RegisterAttachStateChangeCallback_001
111 * @tc.desc : Test RegisterAttachStateChangeCallback function when callback is nullptr.
112 */
113 HWTEST_F(MechBodyControllerServiceTest, RegisterAttachStateChangeCallback_001, TestSize.Level1)
114 {
115 DTEST_LOG << "MechBodyControllerServiceTest RegisterAttachStateChangeCallback_001 begin" << std::endl;
116
117 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
118 const sptr<IRemoteObject> listener;
119 int32_t ret = mechBodyControllerService.RegisterAttachStateChangeCallback(listener);
120 EXPECT_EQ(ret, INVALID_REMOTE_OBJECT);
121 DTEST_LOG << "MechBodyControllerServiceTest RegisterAttachStateChangeCallback_001 end" << std::endl;
122 }
123
124 /**
125 * @tc.name : UnRegisterAttachStateChangeCallback_001
126 * @tc.number: UnRegisterAttachStateChangeCallback_001
127 * @tc.desc : Test UnRegisterAttachStateChangeCallback function.
128 */
129 HWTEST_F(MechBodyControllerServiceTest, UnRegisterAttachStateChangeCallback_001, TestSize.Level1)
130 {
131 DTEST_LOG << "MechBodyControllerServiceTest UnRegisterAttachStateChangeCallback_001 begin" << std::endl;
132
133 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
134 sptr<IRemoteObject> listener;
135 mechBodyControllerService.deviceAttachCallback_[0] = listener;
136 int32_t ret = mechBodyControllerService.UnRegisterAttachStateChangeCallback();
137 EXPECT_EQ(ret, ERR_OK);
138 DTEST_LOG << "MechBodyControllerServiceTest UnRegisterAttachStateChangeCallback_001 end" << std::endl;
139 }
140
141 /**
142 * @tc.name : UnRegisterAttachStateChangeCallback_002
143 * @tc.number: UnRegisterAttachStateChangeCallback_002
144 * @tc.desc : Test UnRegisterAttachStateChangeCallback function.
145 */
146 HWTEST_F(MechBodyControllerServiceTest, UnRegisterAttachStateChangeCallback_002, TestSize.Level1)
147 {
148 DTEST_LOG << "MechBodyControllerServiceTest UnRegisterAttachStateChangeCallback_002 begin" << std::endl;
149
150 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
151 sptr<IRemoteObject> listener;
152 uint32_t tokenId = IPCSkeleton::GetCallingTokenID();
153 mechBodyControllerService.deviceAttachCallback_.clear();
154 mechBodyControllerService.deviceAttachCallback_[tokenId] = listener;
155 mechBodyControllerService.listener_ = nullptr;
156 int32_t ret = mechBodyControllerService.UnRegisterAttachStateChangeCallback();
157 EXPECT_EQ(ret, UNREGISTER_CALLBACK_FAILED);
158 DTEST_LOG << "MechBodyControllerServiceTest UnRegisterAttachStateChangeCallback_002 end" << std::endl;
159 }
160
161 /**
162 * @tc.name : OnAttachStateChange_001
163 * @tc.number: OnAttachStateChange_001
164 * @tc.desc : Test OnAttachStateChange function.
165 */
166 HWTEST_F(MechBodyControllerServiceTest, OnAttachStateChange_001, TestSize.Level1)
167 {
168 DTEST_LOG << "MechBodyControllerServiceTest OnAttachStateChange_001 begin" << std::endl;
169
170 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
171 AttachmentState attachmentState = AttachmentState::DETACHED;
172 MechInfo mechInfo;
173 mechInfo.mechName = "mechName";
174 mechInfo.state = AttachmentState::ATTACHED;
175 int32_t ret = mechBodyControllerService.OnAttachStateChange(attachmentState, mechInfo);
176 EXPECT_EQ(ret, SEND_CALLBACK_INFO_FAILED);
177 DTEST_LOG << "MechBodyControllerServiceTest OnAttachStateChange_001 end" << std::endl;
178 }
179
180 /**
181 * @tc.name : OnDeviceConnected_001
182 * @tc.number: OnDeviceConnected_001
183 * @tc.desc : Test OnDeviceConnected function.
184 */
185 HWTEST_F(MechBodyControllerServiceTest, OnDeviceConnected_001, TestSize.Level1)
186 {
187 DTEST_LOG << "MechBodyControllerServiceTest OnDeviceConnected_001 begin" << std::endl;
188
189 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
190 int32_t mechId = MECHID;
191 int32_t ret = mechBodyControllerService.OnDeviceConnected(mechId);
192 EXPECT_EQ(ret, ERR_OK);
193 DTEST_LOG << "MechBodyControllerServiceTest OnDeviceConnected_001 end" << std::endl;
194 }
195
196 /**
197 * @tc.name : OnDeviceDisconnected_001
198 * @tc.number: OnDeviceDisconnected_001
199 * @tc.desc : Test OnDeviceDisconnected function.
200 */
201 HWTEST_F(MechBodyControllerServiceTest, OnDeviceDisconnected_001, TestSize.Level1)
202 {
203 DTEST_LOG << "MechBodyControllerServiceTest OnDeviceDisconnected_001 begin" << std::endl;
204
205 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
206 int32_t mechId = MECHID;
207 int32_t ret = mechBodyControllerService.OnDeviceDisconnected(mechId);
208 EXPECT_EQ(ret, ERR_OK);
209 DTEST_LOG << "MechBodyControllerServiceTest OnDeviceDisconnected_001 end" << std::endl;
210 }
211
212 /**
213 * @tc.name : OnDeviceDisconnected_002
214 * @tc.number: OnDeviceDisconnected_002
215 * @tc.desc : Test OnDeviceDisconnected function.
216 */
217 HWTEST_F(MechBodyControllerServiceTest, OnDeviceDisconnected_002, TestSize.Level1)
218 {
219 DTEST_LOG << "MechBodyControllerServiceTest OnDeviceDisconnected_002 begin" << std::endl;
220
221 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
222 int32_t mechId = MECHID;
223 mechBodyControllerService.motionManagers_.clear();
224 int32_t ret = mechBodyControllerService.OnDeviceDisconnected(mechId);
225 EXPECT_EQ(ret, ERR_OK);
226 DTEST_LOG << "MechBodyControllerServiceTest OnDeviceDisconnected_002 end" << std::endl;
227 }
228
229 /**
230 * @tc.name : GetAttachedDevices_001
231 * @tc.number: GetAttachedDevices_001
232 * @tc.desc : Test GetAttachedDevices function.
233 */
234 HWTEST_F(MechBodyControllerServiceTest, GetAttachedDevices_001, TestSize.Level1)
235 {
236 DTEST_LOG << "MechBodyControllerServiceTest GetAttachedDevices_001 begin" << std::endl;
237
238 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
239 std::set<MechInfo> mechInfo;
240 int32_t ret = mechBodyControllerService.GetAttachedDevices(mechInfo);
241 EXPECT_EQ(ret, ERR_OK);
242 DTEST_LOG << "MechBodyControllerServiceTest GetAttachedDevices_001 end" << std::endl;
243 }
244
245 /**
246 * @tc.name : SetTrackingEnabled_001
247 * @tc.number: SetTrackingEnabled_001
248 * @tc.desc : Test SetTrackingEnabled function.
249 */
250 HWTEST_F(MechBodyControllerServiceTest, SetTrackingEnabled_001, TestSize.Level1)
251 {
252 DTEST_LOG << "MechBodyControllerServiceTest SetTrackingEnabled_001 begin" << std::endl;
253
254 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
255 bool isEnabled = true;
256 int32_t ret = mechBodyControllerService.SetTrackingEnabled(isEnabled);
257 EXPECT_EQ(ret, ERR_OK);
258 DTEST_LOG << "MechBodyControllerServiceTest SetTrackingEnabled_001 end" << std::endl;
259 }
260
261 /**
262 * @tc.name : GetTrackingEnabled_001
263 * @tc.number: GetTrackingEnabled_001
264 * @tc.desc : Test GetTrackingEnabled function.
265 */
266 HWTEST_F(MechBodyControllerServiceTest, GetTrackingEnabled_001, TestSize.Level1)
267 {
268 DTEST_LOG << "MechBodyControllerServiceTest GetTrackingEnabled_001 begin" << std::endl;
269
270 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
271 bool isEnabled = true;
272 int32_t ret = mechBodyControllerService.GetTrackingEnabled(isEnabled);
273 EXPECT_EQ(ret, ERR_OK);
274 DTEST_LOG << "MechBodyControllerServiceTest GetTrackingEnabled_001 end" << std::endl;
275 }
276
277 /**
278 * @tc.name : RegisterTrackingEventCallback_001
279 * @tc.number: RegisterTrackingEventCallback_001
280 * @tc.desc : Test RegisterTrackingEventCallback function when callback is nullptr.
281 */
282 HWTEST_F(MechBodyControllerServiceTest, RegisterTrackingEventCallback_001, TestSize.Level1)
283 {
284 DTEST_LOG << "MechBodyControllerServiceTest RegisterTrackingEventCallback_001 begin" << std::endl;
285
286 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
287 sptr<IRemoteObject> callback;
288 int32_t ret = mechBodyControllerService.RegisterTrackingEventCallback(callback);
289 EXPECT_EQ(ret, INVALID_REMOTE_OBJECT);
290 DTEST_LOG << "MechBodyControllerServiceTest RegisterTrackingEventCallback_001 end" << std::endl;
291 }
292
293 /**
294 * @tc.name : UnRegisterTrackingEventCallback_001
295 * @tc.number: UnRegisterTrackingEventCallback_001
296 * @tc.desc : Test UnRegisterTrackingEventCallback function.
297 */
298 HWTEST_F(MechBodyControllerServiceTest, UnRegisterTrackingEventCallback_001, TestSize.Level1)
299 {
300 DTEST_LOG << "MechBodyControllerServiceTest UnRegisterTrackingEventCallback_001 begin" << std::endl;
301
302 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
303 int32_t ret = mechBodyControllerService.UnRegisterTrackingEventCallback();
304 EXPECT_EQ(ret, ERR_OK);
305 DTEST_LOG << "MechBodyControllerServiceTest UnRegisterTrackingEventCallback_001 end" << std::endl;
306 }
307
308 /**
309 * @tc.name : SetTrackingLayout_001
310 * @tc.number: SetTrackingLayout_001
311 * @tc.desc : Test SetTrackingLayout function.
312 */
313 HWTEST_F(MechBodyControllerServiceTest, SetTrackingLayout_001, TestSize.Level1)
314 {
315 DTEST_LOG << "MechBodyControllerServiceTest SetTrackingLayout_001 begin" << std::endl;
316
317 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
318 CameraTrackingLayout cameraTrackingLayout = CameraTrackingLayout::DEFAULT;
319 g_isSystemApp = false;
320 int32_t ret = mechBodyControllerService.SetTrackingLayout(cameraTrackingLayout);
321 EXPECT_EQ(ret, PERMISSION_DENIED);
322
323 g_isSystemApp = true;
324 ret = mechBodyControllerService.SetTrackingLayout(cameraTrackingLayout);
325 EXPECT_EQ(ret, ERR_OK);
326 DTEST_LOG << "MechBodyControllerServiceTest SetTrackingLayout_001 end" << std::endl;
327 }
328
329 /**
330 * @tc.name : GetTrackingLayout_001
331 * @tc.number: GetTrackingLayout_001
332 * @tc.desc : Test GetTrackingLayout function.
333 */
334 HWTEST_F(MechBodyControllerServiceTest, GetTrackingLayout_001, TestSize.Level1)
335 {
336 DTEST_LOG << "MechBodyControllerServiceTest GetTrackingLayout_001 begin" << std::endl;
337
338 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
339 CameraTrackingLayout cameraTrackingLayout = CameraTrackingLayout::DEFAULT;
340 int32_t ret = mechBodyControllerService.GetTrackingLayout(cameraTrackingLayout);
341 EXPECT_EQ(ret, ERR_OK);
342 DTEST_LOG << "MechBodyControllerServiceTest GetTrackingLayout_001 end" << std::endl;
343 }
344
345 /**
346 * @tc.name : RotateByDegree_001
347 * @tc.number: RotateByDegree_001
348 * @tc.desc : Test RotateByDegree function.
349 */
350 HWTEST_F(MechBodyControllerServiceTest, RotateByDegree_001, TestSize.Level1)
351 {
352 DTEST_LOG << "MechBodyControllerServiceTest RotateByDegree_001 begin" << std::endl;
353
354 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
355 int32_t mechId = REVERTMECHID;
356 std::string cmdId = "cmdId";
357 RotateByDegreeParam rotateParam;
358 rotateParam.duration = REVERTDURATION;
359 rotateParam.degree.yaw = YAW;
360 rotateParam.degree.roll = ROLL;
361 rotateParam.degree.pitch = PITCH;
362 auto rotateByDegreeParam = std::make_shared<RotateByDegreeParam>(rotateParam);
363 g_isSystemApp = false;
364 int32_t ret = mechBodyControllerService.RotateByDegree(mechId, cmdId, rotateByDegreeParam);
365 EXPECT_EQ(ret, PERMISSION_DENIED);
366
367 g_isSystemApp = true;
368 ret = mechBodyControllerService.RotateByDegree(mechId, cmdId, rotateByDegreeParam);
369 EXPECT_EQ(ret, INVALID_MECH_ID);
370
371 mechId = MECHID;
372 ret = mechBodyControllerService.RotateByDegree(mechId, cmdId, nullptr);
373 EXPECT_EQ(ret, INVALID_ROTATE_PARAM);
374
375 ret = mechBodyControllerService.RotateByDegree(mechId, cmdId, rotateByDegreeParam);
376 EXPECT_EQ(ret, INVALID_ROTATE_PARAM);
377
378 rotateParam.duration = DURATION;
379 auto rotateByDegreeParamSecond = std::make_shared<RotateByDegreeParam>(rotateParam);
380
381 mechBodyControllerService.motionManagers_[mechId] = nullptr;
382 ret = mechBodyControllerService.RotateByDegree(mechId, cmdId, rotateByDegreeParamSecond);
383 EXPECT_EQ(ret, DEVICE_NOT_CONNECTED);
384
385 rotateParam.duration = 0;
386 auto rotateByDegreeParamThird = std::make_shared<RotateByDegreeParam>(rotateParam);
387 ret = mechBodyControllerService.RotateByDegree(mechId, cmdId, rotateByDegreeParamThird);
388 EXPECT_EQ(ret, ERR_OK);
389
390 rotateParam.duration = DURATION;
391 auto rotateByDegreeParamFourth = std::make_shared<RotateByDegreeParam>(rotateParam);
392 std::shared_ptr<MotionManager> motionMgr =
393 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
394 mechBodyControllerService.motionManagers_[mechId] = motionMgr;
395 ret = mechBodyControllerService.RotateByDegree(mechId, cmdId, rotateByDegreeParamFourth);
396 EXPECT_EQ(ret, DEVICE_NOT_PLACED_ON_MECH);
397 DTEST_LOG << "MechBodyControllerServiceTest RotateByDegree_001 end" << std::endl;
398 }
399
400 /**
401 * @tc.name : NotifyOperationResult_001
402 * @tc.number: NotifyOperationResult_001
403 * @tc.desc : Test NotifyOperationResult function.
404 */
405 HWTEST_F(MechBodyControllerServiceTest, NotifyOperationResult_001, TestSize.Level1)
406 {
407 DTEST_LOG << "MechBodyControllerServiceTest NotifyOperationResult_001 begin" << std::endl;
408
409 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
410 int32_t tokenId = MECHID;
411 std::string cmdId = "cmdId";
412 ExecResult result = ExecResult::COMPLETED;
413 int32_t ret = mechBodyControllerService.NotifyOperationResult(tokenId, cmdId, result);
414 EXPECT_EQ(ret, NAPI_SEND_DATA_FAIL);
415 DTEST_LOG << "MechBodyControllerServiceTest NotifyOperationResult_001 end" << std::endl;
416 }
417
418 /**
419 * @tc.name : RotateToEulerAngles_001
420 * @tc.number: RotateToEulerAngles_001
421 * @tc.desc : Test RotateToEulerAngles function when mechId < 0.
422 */
423 HWTEST_F(MechBodyControllerServiceTest, RotateToEulerAngles_001, TestSize.Level1)
424 {
425 DTEST_LOG << "MechBodyControllerServiceTest RotateToEulerAngles_001 begin" << std::endl;
426
427 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
428 g_isSystemApp = true;
429 int32_t mechId = REVERTMECHID;
430 std::string cmdId = "cmdId";
431 RotateToEulerAnglesParam rotateParam;
432 rotateParam.duration = DURATION;
433 rotateParam.angles.yaw = YAW;
434 rotateParam.angles.roll = ROLL;
435 rotateParam.angles.pitch = PITCH;
436 auto rotateToEulerAnglesParam = std::make_shared<RotateToEulerAnglesParam>(rotateParam);
437 int32_t ret = mechBodyControllerService.RotateToEulerAngles(mechId, cmdId, rotateToEulerAnglesParam);
438 EXPECT_EQ(ret, INVALID_MECH_ID);
439 DTEST_LOG << "MechBodyControllerServiceTest RotateToEulerAngles_001 end" << std::endl;
440 }
441
442 /**
443 * @tc.name : RotateToEulerAngles_002
444 * @tc.number: RotateToEulerAngles_002
445 * @tc.desc : Test RotateToEulerAngles function when duration < 0.
446 */
447 HWTEST_F(MechBodyControllerServiceTest, RotateToEulerAngles_002, TestSize.Level1)
448 {
449 DTEST_LOG << "MechBodyControllerServiceTest RotateToEulerAngles_002 begin" << std::endl;
450
451 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
452 g_isSystemApp = true;
453 int32_t mechId = MECHID;
454 std::string cmdId = "cmdId";
455 RotateToEulerAnglesParam rotateParam;
456 rotateParam.duration = REVERTDURATION;
457 rotateParam.angles.yaw = YAW;
458 rotateParam.angles.roll = ROLL;
459 rotateParam.angles.pitch = PITCH;
460 auto rotateToEulerAnglesParam = std::make_shared<RotateToEulerAnglesParam>(rotateParam);
461 int32_t ret = mechBodyControllerService.RotateToEulerAngles(mechId, cmdId, rotateToEulerAnglesParam);
462 EXPECT_EQ(ret, INVALID_ROTATE_PARAM);
463 DTEST_LOG << "MechBodyControllerServiceTest RotateToEulerAngles_002 end" << std::endl;
464 }
465
466 /**
467 * @tc.name : RotateToEulerAngles_003
468 * @tc.number: RotateToEulerAngles_003
469 * @tc.desc : Test RotateToEulerAngles function.
470 */
471 HWTEST_F(MechBodyControllerServiceTest, RotateToEulerAngles_003, TestSize.Level1)
472 {
473 DTEST_LOG << "MechBodyControllerServiceTest RotateToEulerAngles_003 begin" << std::endl;
474
475 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
476 g_isSystemApp = true;
477 int32_t mechId = MECHID;
478 std::string cmdId = "cmdId";
479 RotateToEulerAnglesParam rotateParam;
480 rotateParam.duration = DURATION;
481 rotateParam.angles.yaw = YAW;
482 rotateParam.angles.roll = ROLL;
483 rotateParam.angles.pitch = PITCH;
484 auto rotateToEulerAnglesParam = std::make_shared<RotateToEulerAnglesParam>(rotateParam);
485 mechBodyControllerService.motionManagers_[mechId] = nullptr;
486 int32_t ret = mechBodyControllerService.RotateToEulerAngles(mechId, cmdId, rotateToEulerAnglesParam);
487 EXPECT_EQ(ret, DEVICE_NOT_CONNECTED);
488
489 g_isSystemApp = false;
490 ret = mechBodyControllerService.RotateToEulerAngles(mechId, cmdId, rotateToEulerAnglesParam);
491 EXPECT_EQ(ret, PERMISSION_DENIED);
492
493 g_isSystemApp = true;
494 rotateParam.duration = 0;
495 auto rotateToEulerAnglesParamSecond = std::make_shared<RotateToEulerAnglesParam>(rotateParam);
496 ret = mechBodyControllerService.RotateToEulerAngles(mechId, cmdId, rotateToEulerAnglesParamSecond);
497 EXPECT_EQ(ret, ERR_OK);
498
499 rotateParam.duration = DURATION;
500 ret = mechBodyControllerService.RotateToEulerAngles(mechId, cmdId, nullptr);
501 EXPECT_EQ(ret, INVALID_ROTATE_PARAM);
502
503 std::shared_ptr<MotionManager> motionMgr =
504 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
505 mechBodyControllerService.motionManagers_[mechId] = motionMgr;
506 ret = mechBodyControllerService.RotateToEulerAngles(mechId, cmdId, rotateToEulerAnglesParam);
507 EXPECT_EQ(ret, DEVICE_NOT_PLACED_ON_MECH);
508 DTEST_LOG << "MechBodyControllerServiceTest RotateToEulerAngles_003 end" << std::endl;
509 }
510
511 /**
512 * @tc.name : GetMaxRotationTime_001
513 * @tc.number: GetMaxRotationTime_001
514 * @tc.desc : Test GetMaxRotationTime function when mechId < 0.
515 */
516 HWTEST_F(MechBodyControllerServiceTest, GetMaxRotationTime_001, TestSize.Level1)
517 {
518 DTEST_LOG << "MechBodyControllerServiceTest GetMaxRotationTime_001 begin" << std::endl;
519
520 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
521 g_isSystemApp = true;
522 int32_t mechId = REVERTMECHID;
523 auto timeLimit = std::shared_ptr<TimeLimit>();
524 int32_t ret = mechBodyControllerService.GetMaxRotationTime(mechId, timeLimit);
525 EXPECT_EQ(ret, INVALID_MECH_ID);
526 DTEST_LOG << "MechBodyControllerServiceTest GetMaxRotationTime_001 end" << std::endl;
527 }
528
529 /**
530 * @tc.name : GetMaxRotationTime_002
531 * @tc.number: GetMaxRotationTime_002
532 * @tc.desc : Test GetMaxRotationTime function.
533 */
534 HWTEST_F(MechBodyControllerServiceTest, GetMaxRotationTime_002, TestSize.Level1)
535 {
536 DTEST_LOG << "MechBodyControllerServiceTest GetMaxRotationTime_002 begin" << std::endl;
537
538 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
539 g_isSystemApp = false;
540 int32_t mechId = MECHID;
541 auto timeLimit = std::shared_ptr<TimeLimit>();
542 int32_t ret = mechBodyControllerService.GetMaxRotationTime(mechId, timeLimit);
543 EXPECT_EQ(ret, PERMISSION_DENIED);
544
545 g_isSystemApp = true;
546 mechBodyControllerService.motionManagers_[mechId] = nullptr;
547 ret = mechBodyControllerService.GetMaxRotationTime(mechId, timeLimit);
548 EXPECT_EQ(ret, DEVICE_NOT_CONNECTED);
549
550 std::shared_ptr<MotionManager> motionMgr =
551 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
552 mechBodyControllerService.motionManagers_[mechId] = motionMgr;
553 ret = mechBodyControllerService.GetMaxRotationTime(mechId, timeLimit);
554 EXPECT_EQ(ret, DEVICE_NOT_PLACED_ON_MECH);
555 DTEST_LOG << "MechBodyControllerServiceTest GetMaxRotationTime_002 end" << std::endl;
556 }
557
558 /**
559 * @tc.name : GetMaxRotationSpeed_001
560 * @tc.number: GetMaxRotationSpeed_001
561 * @tc.desc : Test GetMaxRotationSpeed function when mechId < 0.
562 */
563 HWTEST_F(MechBodyControllerServiceTest, GetMaxRotationSpeed_001, TestSize.Level1)
564 {
565 DTEST_LOG << "MechBodyControllerServiceTest GetMaxRotationSpeed_001 begin" << std::endl;
566
567 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
568 g_isSystemApp = true;
569 int32_t mechId = REVERTMECHID;
570 RotateSpeedLimit rotateSpeedLimit;
571 rotateSpeedLimit.speedMax.yawSpeed = YAW;
572 rotateSpeedLimit.speedMax.rollSpeed = ROLL;
573 rotateSpeedLimit.speedMax.pitchSpeed = PITCH;
574 rotateSpeedLimit.speedMin.yawSpeed = YAW;
575 rotateSpeedLimit.speedMin.rollSpeed = ROLL;
576 rotateSpeedLimit.speedMin.pitchSpeed = PITCH;
577 int32_t ret = mechBodyControllerService.GetMaxRotationSpeed(mechId, rotateSpeedLimit);
578 EXPECT_EQ(ret, INVALID_MECH_ID);
579 DTEST_LOG << "MechBodyControllerServiceTest GetMaxRotationSpeed_001 end" << std::endl;
580 }
581
582 /**
583 * @tc.name : GetMaxRotationSpeed_002
584 * @tc.number: GetMaxRotationSpeed_002
585 * @tc.desc : Test GetMaxRotationSpeed function.
586 */
587 HWTEST_F(MechBodyControllerServiceTest, GetMaxRotationSpeed_002, TestSize.Level1)
588 {
589 DTEST_LOG << "MechBodyControllerServiceTest GetMaxRotationSpeed_002 begin" << std::endl;
590
591 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
592 g_isSystemApp = false;
593 int32_t mechId = MECHID;
594 RotateSpeedLimit rotateSpeedLimit;
595 rotateSpeedLimit.speedMax.yawSpeed = YAW;
596 rotateSpeedLimit.speedMax.rollSpeed = ROLL;
597 rotateSpeedLimit.speedMax.pitchSpeed = PITCH;
598 rotateSpeedLimit.speedMin.yawSpeed = YAW;
599 rotateSpeedLimit.speedMin.rollSpeed = ROLL;
600 rotateSpeedLimit.speedMin.pitchSpeed = PITCH;
601 int32_t ret = mechBodyControllerService.GetMaxRotationSpeed(mechId, rotateSpeedLimit);
602 EXPECT_EQ(ret, PERMISSION_DENIED);
603
604 g_isSystemApp = true;
605 mechBodyControllerService.motionManagers_[mechId] = nullptr;
606 ret = mechBodyControllerService.GetMaxRotationSpeed(mechId, rotateSpeedLimit);
607 EXPECT_EQ(ret, DEVICE_NOT_CONNECTED);
608
609 std::shared_ptr<MotionManager> motionMgr =
610 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
611 mechBodyControllerService.motionManagers_[mechId] = motionMgr;
612 ret = mechBodyControllerService.GetMaxRotationSpeed(mechId, rotateSpeedLimit);
613 EXPECT_EQ(ret, DEVICE_NOT_PLACED_ON_MECH);
614 DTEST_LOG << "MechBodyControllerServiceTest GetMaxRotationSpeed_002 end" << std::endl;
615 }
616
617 /**
618 * @tc.name : RotateBySpeed_001
619 * @tc.number: RotateBySpeed_001
620 * @tc.desc : Test RotateBySpeed function when mechId < 0.
621 */
622 HWTEST_F(MechBodyControllerServiceTest, RotateBySpeed_001, TestSize.Level1)
623 {
624 DTEST_LOG << "MechBodyControllerServiceTest RotateBySpeed_001 begin" << std::endl;
625
626 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
627 g_isSystemApp = true;
628 int32_t mechId = REVERTMECHID;
629 std::string cmdId = "cmdId";
630 RotateBySpeedParam rotateParam;
631 rotateParam.duration = DURATION;
632 rotateParam.speed.yawSpeed = YAW;
633 rotateParam.speed.rollSpeed = ROLL;
634 rotateParam.speed.pitchSpeed = PITCH;
635 auto rotateBySpeedParam = std::make_shared<RotateBySpeedParam>(rotateParam);
636 int32_t ret = mechBodyControllerService.RotateBySpeed(mechId, cmdId, rotateBySpeedParam);
637 EXPECT_EQ(ret, INVALID_MECH_ID);
638 DTEST_LOG << "MechBodyControllerServiceTest RotateBySpeed_001 end" << std::endl;
639 }
640
641 /**
642 * @tc.name : RotateBySpeed_002
643 * @tc.number: RotateBySpeed_002
644 * @tc.desc : Test RotateBySpeed function.
645 */
646 HWTEST_F(MechBodyControllerServiceTest, RotateBySpeed_002, TestSize.Level1)
647 {
648 DTEST_LOG << "MechBodyControllerServiceTest RotateBySpeed_002 begin" << std::endl;
649
650 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
651 g_isSystemApp = false;
652 int32_t mechId = MECHID;
653 std::string cmdId = "cmdId";
654 RotateBySpeedParam rotateParam;
655 rotateParam.duration = DURATION;
656 rotateParam.speed.yawSpeed = YAW;
657 rotateParam.speed.rollSpeed = ROLL;
658 rotateParam.speed.pitchSpeed = PITCH;
659 auto rotateBySpeedParam = std::make_shared<RotateBySpeedParam>(rotateParam);
660 int32_t ret = mechBodyControllerService.RotateBySpeed(mechId, cmdId, rotateBySpeedParam);
661 EXPECT_EQ(ret, PERMISSION_DENIED);
662
663 g_isSystemApp = true;
664 ret = mechBodyControllerService.RotateBySpeed(mechId, cmdId, nullptr);
665 EXPECT_EQ(ret, INVALID_ROTATE_PARAM);
666
667
668 mechBodyControllerService.motionManagers_[mechId] = nullptr;
669 ret = mechBodyControllerService.RotateBySpeed(mechId, cmdId, rotateBySpeedParam);
670 EXPECT_EQ(ret, DEVICE_NOT_CONNECTED);
671
672 rotateParam.duration = 0;
673 auto rotateBySpeedParamSecond = std::make_shared<RotateBySpeedParam>(rotateParam);
674 ret = mechBodyControllerService.RotateBySpeed(mechId, cmdId, rotateBySpeedParamSecond);
675 EXPECT_EQ(ret, ERR_OK);
676
677 std::shared_ptr<MotionManager> motionMgr =
678 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
679 mechBodyControllerService.motionManagers_[mechId] = motionMgr;
680 ret = mechBodyControllerService.RotateBySpeed(mechId, cmdId, rotateBySpeedParam);
681 EXPECT_EQ(ret, DEVICE_NOT_PLACED_ON_MECH);
682 DTEST_LOG << "MechBodyControllerServiceTest RotateBySpeed_002 end" << std::endl;
683 }
684
685 /**
686 * @tc.name : StopMoving_001
687 * @tc.number: StopMoving_001
688 * @tc.desc : Test StopMoving function when mechId < 0.
689 */
690 HWTEST_F(MechBodyControllerServiceTest, StopMoving_001, TestSize.Level1)
691 {
692 DTEST_LOG << "MechBodyControllerServiceTest StopMoving_001 begin" << std::endl;
693
694 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
695 g_isSystemApp = true;
696 int32_t mechId = REVERTMECHID;
697 std::string cmdId = "cmdId";
698 int32_t ret = mechBodyControllerService.StopMoving(mechId, cmdId);
699 EXPECT_EQ(ret, INVALID_MECH_ID);
700 DTEST_LOG << "MechBodyControllerServiceTest StopMoving_001 end" << std::endl;
701 }
702
703 /**
704 * @tc.name : StopMoving_002
705 * @tc.number: StopMoving_002
706 * @tc.desc : Test StopMoving function.
707 */
708 HWTEST_F(MechBodyControllerServiceTest, StopMoving_002, TestSize.Level1)
709 {
710 DTEST_LOG << "MechBodyControllerServiceTest StopMoving_002 begin" << std::endl;
711
712 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
713 g_isSystemApp = false;
714 int32_t mechId = MECHID;
715 std::string cmdId = "cmdId";
716 int32_t ret = mechBodyControllerService.StopMoving(mechId, cmdId);
717 EXPECT_EQ(ret, PERMISSION_DENIED);
718
719 g_isSystemApp = true;
720 mechBodyControllerService.motionManagers_[mechId] = nullptr;
721 ret = mechBodyControllerService.StopMoving(mechId, cmdId);
722 EXPECT_EQ(ret, DEVICE_NOT_CONNECTED);
723
724 std::shared_ptr<MotionManager> motionMgr =
725 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
726 mechBodyControllerService.motionManagers_[mechId] = motionMgr;
727 ret = mechBodyControllerService.StopMoving(mechId, cmdId);
728 EXPECT_EQ(ret, DEVICE_NOT_PLACED_ON_MECH);
729 DTEST_LOG << "MechBodyControllerServiceTest StopMoving_002 end" << std::endl;
730 }
731
732 /**
733 * @tc.name : GetRotationAngles_001
734 * @tc.number: GetRotationAngles_001
735 * @tc.desc : Test GetRotationAngles function when mechId < 0.
736 */
737 HWTEST_F(MechBodyControllerServiceTest, GetRotationAngles_001, TestSize.Level1)
738 {
739 DTEST_LOG << "MechBodyControllerServiceTest GetRotationAngles_001 begin" << std::endl;
740
741 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
742 g_isSystemApp = true;
743 int32_t mechId = REVERTMECHID;
744 EulerAngles eulerAngles;
745 eulerAngles.yaw = YAW;
746 eulerAngles.roll = ROLL;
747 eulerAngles.pitch = PITCH;
748 auto eulerAnglesPtr = std::make_shared<EulerAngles>(eulerAngles);
749 int32_t ret = mechBodyControllerService.GetRotationAngles(mechId, eulerAnglesPtr);
750 EXPECT_EQ(ret, INVALID_MECH_ID);
751 DTEST_LOG << "MechBodyControllerServiceTest GetRotationAngles_001 end" << std::endl;
752 }
753
754 /**
755 * @tc.name : GetRotationAngles_002
756 * @tc.number: GetRotationAngles_002
757 * @tc.desc : Test GetRotationAngles function.
758 */
759 HWTEST_F(MechBodyControllerServiceTest, GetRotationAngles_002, TestSize.Level1)
760 {
761 DTEST_LOG << "MechBodyControllerServiceTest GetRotationAngles_002 begin" << std::endl;
762
763 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
764 g_isSystemApp = false;
765 int32_t mechId = MECHID;
766 EulerAngles eulerAngles;
767 eulerAngles.yaw = YAW;
768 eulerAngles.roll = ROLL;
769 eulerAngles.pitch = PITCH;
770 auto eulerAnglesPtr = std::make_shared<EulerAngles>(eulerAngles);
771 int32_t ret = mechBodyControllerService.GetRotationAngles(mechId, eulerAnglesPtr);
772 EXPECT_EQ(ret, PERMISSION_DENIED);
773
774 g_isSystemApp = true;
775 mechBodyControllerService.motionManagers_[mechId] = nullptr;
776 ret = mechBodyControllerService.GetRotationAngles(mechId, eulerAnglesPtr);
777 EXPECT_EQ(ret, DEVICE_NOT_CONNECTED);
778
779 std::shared_ptr<MotionManager> motionMgr =
780 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
781 mechBodyControllerService.motionManagers_[mechId] = motionMgr;
782 ret = mechBodyControllerService.GetRotationAngles(mechId, eulerAnglesPtr);
783 EXPECT_EQ(ret, DEVICE_NOT_PLACED_ON_MECH);
784 DTEST_LOG << "MechBodyControllerServiceTest GetRotationAngles_002 end" << std::endl;
785 }
786
787 /**
788 * @tc.name : GetRotationDegreeLimits_001
789 * @tc.number: GetRotationDegreeLimits_001
790 * @tc.desc : Test GetRotationDegreeLimits function when mechId < 0.
791 */
792 HWTEST_F(MechBodyControllerServiceTest, GetRotationDegreeLimits_001, TestSize.Level1)
793 {
794 DTEST_LOG << "MechBodyControllerServiceTest GetRotationDegreeLimits_001 begin" << std::endl;
795
796 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
797 g_isSystemApp = true;
798 int32_t mechId = REVERTMECHID;
799 RotateDegreeLimit rotationLimit;
800 rotationLimit.negMax.yaw = YAW;
801 rotationLimit.negMax.roll = ROLL;
802 rotationLimit.negMax.pitch = PITCH;
803 rotationLimit.posMax.yaw = YAW;
804 rotationLimit.posMax.roll = ROLL;
805 rotationLimit.posMax.pitch = PITCH;
806 int32_t ret = mechBodyControllerService.GetRotationDegreeLimits(mechId, rotationLimit);
807 EXPECT_EQ(ret, INVALID_MECH_ID);
808 DTEST_LOG << "MechBodyControllerServiceTest GetRotationDegreeLimits_001 end" << std::endl;
809 }
810
811 /**
812 * @tc.name : GetRotationDegreeLimits_002
813 * @tc.number: GetRotationDegreeLimits_002
814 * @tc.desc : Test GetRotationDegreeLimits function.
815 */
816 HWTEST_F(MechBodyControllerServiceTest, GetRotationDegreeLimits_002, TestSize.Level1)
817 {
818 DTEST_LOG << "MechBodyControllerServiceTest GetRotationDegreeLimits_002 begin" << std::endl;
819
820 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
821 g_isSystemApp = false;
822 int32_t mechId = MECHID;
823 RotateDegreeLimit rotationLimit;
824 rotationLimit.negMax.yaw = YAW;
825 rotationLimit.negMax.roll = ROLL;
826 rotationLimit.negMax.pitch = PITCH;
827 rotationLimit.posMax.yaw = YAW;
828 rotationLimit.posMax.roll = ROLL;
829 rotationLimit.posMax.pitch = PITCH;
830 int32_t ret = mechBodyControllerService.GetRotationDegreeLimits(mechId, rotationLimit);
831 EXPECT_EQ(ret, PERMISSION_DENIED);
832
833 g_isSystemApp = true;
834 mechBodyControllerService.motionManagers_[mechId] = nullptr;
835 ret = mechBodyControllerService.GetRotationDegreeLimits(mechId, rotationLimit);
836 EXPECT_EQ(ret, DEVICE_NOT_CONNECTED);
837
838 std::shared_ptr<MotionManager> motionMgr =
839 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
840 mechBodyControllerService.motionManagers_[mechId] = motionMgr;
841 ret = mechBodyControllerService.GetRotationDegreeLimits(mechId, rotationLimit);
842 EXPECT_EQ(ret, DEVICE_NOT_PLACED_ON_MECH);
843 DTEST_LOG << "MechBodyControllerServiceTest GetRotationDegreeLimits_002 end" << std::endl;
844 }
845
846 /**
847 * @tc.name : GetRotationAxesStatus_001
848 * @tc.number: GetRotationAxesStatus_001
849 * @tc.desc : Test GetRotationAxesStatus function when mechId < 0.
850 */
851 HWTEST_F(MechBodyControllerServiceTest, GetRotationAxesStatus_001, TestSize.Level1)
852 {
853 DTEST_LOG << "MechBodyControllerServiceTest GetRotationAxesStatus_001 begin" << std::endl;
854
855 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
856 g_isSystemApp = true;
857 int32_t mechId = REVERTMECHID;
858 RotationAxisLimited limited = RotationAxisLimited::NOT_LIMITED;
859 RotationAxesStatus axesStatus;
860 axesStatus.pitchEnabled = true;
861 axesStatus.rollEnabled = true;
862 axesStatus.yawEnabled = true;
863 axesStatus.pitchLimited = limited;
864 axesStatus.rollLimited = limited;
865 axesStatus.yawLimited = limited;
866 int32_t ret = mechBodyControllerService.GetRotationAxesStatus(mechId, axesStatus);
867 EXPECT_EQ(ret, INVALID_MECH_ID);
868 DTEST_LOG << "MechBodyControllerServiceTest GetRotationAxesStatus_001 end" << std::endl;
869 }
870
871 /**
872 * @tc.name : GetRotationAxesStatus_002
873 * @tc.number: GetRotationAxesStatus_002
874 * @tc.desc : Test GetRotationAxesStatus function.
875 */
876 HWTEST_F(MechBodyControllerServiceTest, GetRotationAxesStatus_002, TestSize.Level1)
877 {
878 DTEST_LOG << "MechBodyControllerServiceTest GetRotationAxesStatus_002 begin" << std::endl;
879
880 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
881 g_isSystemApp = false;
882 int32_t mechId = MECHID;
883 RotationAxisLimited limited = RotationAxisLimited::NOT_LIMITED;
884 RotationAxesStatus axesStatus;
885 axesStatus.pitchEnabled = true;
886 axesStatus.rollEnabled = true;
887 axesStatus.yawEnabled = true;
888 axesStatus.pitchLimited = limited;
889 axesStatus.rollLimited = limited;
890 axesStatus.yawLimited = limited;
891 int32_t ret = mechBodyControllerService.GetRotationAxesStatus(mechId, axesStatus);
892 EXPECT_EQ(ret, PERMISSION_DENIED);
893
894 g_isSystemApp = true;
895 mechBodyControllerService.motionManagers_[mechId] = nullptr;
896 ret = mechBodyControllerService.GetRotationAxesStatus(mechId, axesStatus);
897 EXPECT_EQ(ret, DEVICE_NOT_CONNECTED);
898
899 std::shared_ptr<MotionManager> motionMgr =
900 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
901 mechBodyControllerService.motionManagers_[mechId] = motionMgr;
902 ret = mechBodyControllerService.GetRotationAxesStatus(mechId, axesStatus);
903 EXPECT_EQ(ret, DEVICE_NOT_PLACED_ON_MECH);
904 DTEST_LOG << "MechBodyControllerServiceTest GetRotationAxesStatus_002 end" << std::endl;
905 }
906
907 /**
908 * @tc.name : RegisterRotationAxesStatusChangeCallback_001
909 * @tc.number: RegisterRotationAxesStatusChangeCallback_001
910 * @tc.desc : Test RegisterRotationAxesStatusChangeCallback function when callback is nullptr.
911 */
912 HWTEST_F(MechBodyControllerServiceTest, RegisterRotationAxesStatusChangeCallback_001, TestSize.Level1)
913 {
914 DTEST_LOG << "MechBodyControllerServiceTest RegisterRotationAxesStatusChangeCallback_001 begin" << std::endl;
915
916 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
917 g_isSystemApp = true;
918 auto callback = sptr<IRemoteObject>();
919 int32_t ret = mechBodyControllerService.RegisterRotationAxesStatusChangeCallback(callback);
920 EXPECT_EQ(ret, INVALID_REMOTE_OBJECT);
921
922 g_isSystemApp = false;
923 ret = mechBodyControllerService.RegisterRotationAxesStatusChangeCallback(callback);
924 EXPECT_EQ(ret, PERMISSION_DENIED);
925 DTEST_LOG << "MechBodyControllerServiceTest RegisterRotationAxesStatusChangeCallback_001 end" << std::endl;
926 }
927
928 /**
929 * @tc.name : UnRegisterRotationAxesStatusChangeCallback_001
930 * @tc.number: UnRegisterRotationAxesStatusChangeCallback_001
931 * @tc.desc : Test UnRegisterRotationAxesStatusChangeCallback function.
932 */
933 HWTEST_F(MechBodyControllerServiceTest, UnRegisterRotationAxesStatusChangeCallback_001, TestSize.Level1)
934 {
935 DTEST_LOG << "MechBodyControllerServiceTest UnRegisterRotationAxesStatusChangeCallback_001 begin" << std::endl;
936
937 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
938 g_isSystemApp = true;
939 int32_t ret = mechBodyControllerService.UnRegisterRotationAxesStatusChangeCallback();
940 EXPECT_EQ(ret, ERR_OK);
941
942 g_isSystemApp = false;
943 ret = mechBodyControllerService.UnRegisterRotationAxesStatusChangeCallback();
944 EXPECT_EQ(ret, PERMISSION_DENIED);
945 DTEST_LOG << "MechBodyControllerServiceTest UnRegisterRotationAxesStatusChangeCallback_001 end" << std::endl;
946 }
947
948 /**
949 * @tc.name : OnRotationAxesStatusChange_001
950 * @tc.number: OnRotationAxesStatusChange_001
951 * @tc.desc : Test OnRotationAxesStatusChange function.
952 */
953 HWTEST_F(MechBodyControllerServiceTest, OnRotationAxesStatusChange_001, TestSize.Level1)
954 {
955 DTEST_LOG << "MechBodyControllerServiceTest OnRotationAxesStatusChange_001 begin" << std::endl;
956
957 MechBodyControllerService& mechBodyControllerService = MechBodyControllerService::GetInstance();
958 int32_t mechId = MECHID;
959 RotationAxisLimited limited = RotationAxisLimited::NOT_LIMITED;
960 RotationAxesStatus axesStatus;
961 axesStatus.pitchEnabled = true;
962 axesStatus.rollEnabled = true;
963 axesStatus.yawEnabled = true;
964 axesStatus.pitchLimited = limited;
965 axesStatus.rollLimited = limited;
966 axesStatus.yawLimited = limited;
967 int32_t ret = mechBodyControllerService.OnRotationAxesStatusChange(mechId, axesStatus);
968 EXPECT_EQ(ret, ERR_OK);
969 DTEST_LOG << "MechBodyControllerServiceTest OnRotationAxesStatusChange_001 end" << std::endl;
970 }
971 }
972 }
973