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 "mc_motion_manager_test.h"
16
17 #include <thread>
18
19 #define private public
20 #define protected public
21 #include <stdexcept>
22 #include <iostream>
23
24 #include "mechbody_controller_log.h"
25 #include "mc_register_mech_position_info_cmd.h"
26 #include "mc_register_mech_camera_key_event_cmd.h"
27 #include "mechbody_controller_service.h"
28 #include "mc_register_mech_control_result_cmd.h"
29 #include "mc_command_base.h"
30 #undef private
31 #undef protected
32
33 using namespace testing;
34 using namespace testing::ext;
35 using namespace OHOS;
36
37 namespace OHOS {
38 namespace MechBodyController {
39 constexpr float DEFAULT_DURATION = 500;
40
SetUpTestCase()41 void MotionManagerTest::SetUpTestCase()
42 {
43 }
44
TearDownTestCase()45 void MotionManagerTest::TearDownTestCase()
46 {}
47
SetUp()48 void MotionManagerTest::SetUp()
49 {
50 }
51
TearDown()52 void MotionManagerTest::TearDown()
53 {}
54
55 static CameraKeyEvent keyEvent_ = CameraKeyEvent::INVALID;
56
MMIKeyEvent(CameraKeyEvent eventType)57 void MotionManager::MMIKeyEvent(CameraKeyEvent eventType)
58 {
59 keyEvent_ = eventType;
60 }
61
62 static bool g_mockMechState = false;
63
GetMechState(int32_t mechId)64 bool MechConnectManager::GetMechState(int32_t mechId)
65 {
66 return g_mockMechState;
67 }
68
69 /**
70 * @tc.name : MechAttitudeNotify_001
71 * @tc.number: MechAttitudeNotify_001
72 * @tc.desc : Test MechAttitudeNotify function.
73 */
74 HWTEST_F(MotionManagerTest, MechAttitudeNotify_001, TestSize.Level1)
75 {
76 int32_t mechId = 100;
77 std::shared_ptr<MotionManager> motionMgr =
78 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
79 motionMgr->RegisterEventListener();
80 EulerAngles eulerAngles;
81 eulerAngles.yaw = 100;
82 eulerAngles.roll = 100;
83 eulerAngles.pitch = 100;
84
85 std::shared_ptr<RegisterMechPositionInfoCmd> cmdNull = nullptr;
86 EXPECT_NO_FATAL_FAILURE(motionMgr->MechAttitudeNotify(cmdNull));
87
88 CommandFactory factory;
89 auto cmd = factory.CreateRegisterMechPositionInfoCmd();
90 motionMgr->deviceStatus_->eulerAngles = cmd->GetPosition();
91 EXPECT_NO_FATAL_FAILURE(motionMgr->MechAttitudeNotify(cmd));
92
93 motionMgr->deviceStatus_->eulerAngles = eulerAngles;
94 EXPECT_NO_FATAL_FAILURE(motionMgr->MechAttitudeNotify(cmd));
95 }
96
97 /**
98 * @tc.name : CreateKeyEvent_001
99 * @tc.number: CreateKeyEvent_001
100 * @tc.desc : Test CreateKeyEvent with valid parameters.
101 */
102 HWTEST_F(MotionManagerTest, CreateKeyEvent_001, TestSize.Level1)
103 {
104 int32_t keyCode = 10;
105 int32_t mechId = 100;
106 int32_t keyAction = MMI::KeyEvent::KEY_ACTION_DOWN;
107 std::shared_ptr<MotionManager> motionMgr =
108 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
109 motionMgr->RegisterEventListener();
110
111 std::shared_ptr<MMI::KeyEvent> keyEvent = motionMgr->CreateKeyEvent(keyCode, keyAction);
112
113 // 检查KeyEvent是否正确创建
114 EXPECT_NE(keyEvent, nullptr);
115 EXPECT_EQ(keyEvent->GetKeyCode(), keyCode);
116 EXPECT_EQ(keyEvent->GetKeyAction(), keyAction);
117 }
118
119 /**
120 * @tc.name : CreateKeyEvent_002
121 * @tc.number: CreateKeyEvent_002
122 * @tc.desc : Test CreateKeyEvent with invalid parameters.
123 */
124 HWTEST_F(MotionManagerTest, CreateKeyEvent_002, TestSize.Level1)
125 {
126 int32_t keyCode = -1;
127 int32_t mechId = 100;
128 int32_t keyAction = MMI::KeyEvent::KEY_ACTION_DOWN;
129 std::shared_ptr<MotionManager> motionMgr =
130 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
131 motionMgr->RegisterEventListener();
132
133 std::shared_ptr<MMI::KeyEvent> keyEvent = motionMgr->CreateKeyEvent(keyCode, keyAction);
134
135 EXPECT_NE(keyEvent, nullptr);
136 }
137
138 /**
139 * @tc.name : MechButtonEventNotify_001
140 * @tc.number: MechButtonEventNotify_001
141 * @tc.desc : Test MechButtonEventNotify with START_FILMING event.
142 */
143 HWTEST_F(MotionManagerTest, MechButtonEventNotify_001, TestSize.Level1)
144 {
145 int32_t mechId = 100;
146 std::shared_ptr<MotionManager> motionMgr =
147 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
148 motionMgr->RegisterEventListener();
149
150 std::shared_ptr<CameraInfo> cameraInfo = std::make_shared<CameraInfo>();
151 cameraInfo->isCameraOn = true;
152 McCameraTrackingController::GetInstance().currentCameraInfo_ = cameraInfo;
153
154 std::shared_ptr<RegisterMechCameraKeyEventCmd> cmd = std::make_shared<RegisterMechCameraKeyEventCmd>();
155 cmd->event_ = CameraKeyEvent::START_FILMING;
156 motionMgr->MechButtonEventNotify(cmd);
157
158 EXPECT_EQ(keyEvent_, CameraKeyEvent::START_FILMING);
159 }
160
161 /**
162 * @tc.name : MechButtonEventNotify_002
163 * @tc.number: MechButtonEventNotify_002
164 * @tc.desc : Test MechButtonEventNotify with SWITCH_TRACKING event.
165 */
166 HWTEST_F(MotionManagerTest, MechButtonEventNotify_002, TestSize.Level1)
167 {
168 int32_t mechId = 100;
169 std::shared_ptr<MotionManager> motionMgr =
170 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
171 motionMgr->RegisterEventListener();
172
173 std::shared_ptr<CameraInfo> cameraInfo = std::make_shared<CameraInfo>();
174 cameraInfo->isCameraOn = true;
175 McCameraTrackingController::GetInstance().currentCameraInfo_ = cameraInfo;
176
177 std::shared_ptr<RegisterMechCameraKeyEventCmd> cmd = std::make_shared<RegisterMechCameraKeyEventCmd>();
178 cmd->event_ = CameraKeyEvent::SWITCH_TRACKING;
179 motionMgr->MechButtonEventNotify(cmd);
180
181 EXPECT_NE(keyEvent_, CameraKeyEvent::SWITCH_TRACKING);
182 }
183
184 /**
185 * @tc.name : MechButtonEventNotify_003
186 * @tc.number: MechButtonEventNotify_003
187 * @tc.desc : Test MechButtonEventNotify with SWITCH_PHOTO_FILM event.
188 */
189 HWTEST_F(MotionManagerTest, MechButtonEventNotify_003, TestSize.Level1)
190 {
191 int32_t mechId = 100;
192 std::shared_ptr<MotionManager> motionMgr =
193 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
194 motionMgr->RegisterEventListener();
195
196 std::shared_ptr<CameraInfo> cameraInfo = std::make_shared<CameraInfo>();
197 cameraInfo->isCameraOn = true;
198 McCameraTrackingController::GetInstance().currentCameraInfo_ = cameraInfo;
199
200 std::shared_ptr<RegisterMechCameraKeyEventCmd> cmd = std::make_shared<RegisterMechCameraKeyEventCmd>();
201 cmd->event_ = CameraKeyEvent::SWITCH_PHOTO_FILM;
202 motionMgr->MechButtonEventNotify(cmd);
203
204 EXPECT_EQ(keyEvent_, CameraKeyEvent::SWITCH_PHOTO_FILM);
205 }
206
207 /**
208 * @tc.name : MechButtonEventNotify_004
209 * @tc.number: MechButtonEventNotify_004
210 * @tc.desc : Test MechButtonEventNotify with ZOOM_OUT event.
211 */
212 HWTEST_F(MotionManagerTest, MechButtonEventNotify_004, TestSize.Level1)
213 {
214 int32_t mechId = 100;
215 std::shared_ptr<MotionManager> motionMgr =
216 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
217 motionMgr->RegisterEventListener();
218
219 std::shared_ptr<CameraInfo> cameraInfo = std::make_shared<CameraInfo>();
220 cameraInfo->isCameraOn = true;
221 McCameraTrackingController::GetInstance().currentCameraInfo_ = cameraInfo;
222
223 std::shared_ptr<RegisterMechCameraKeyEventCmd> cmd = std::make_shared<RegisterMechCameraKeyEventCmd>();
224 cmd->event_ = CameraKeyEvent::ZOOM_OUT;
225 motionMgr->MechButtonEventNotify(cmd);
226
227 EXPECT_EQ(keyEvent_, CameraKeyEvent::ZOOM_OUT);
228 }
229
230 /**
231 * @tc.name : MechButtonEventNotify_005
232 * @tc.number: MechButtonEventNotify_005
233 * @tc.desc : Test MechButtonEventNotify with ZOOM_IN event.
234 */
235 HWTEST_F(MotionManagerTest, MechButtonEventNotify_005, TestSize.Level1)
236 {
237 int32_t mechId = 100;
238 std::shared_ptr<MotionManager> motionMgr =
239 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
240 motionMgr->RegisterEventListener();
241
242 std::shared_ptr<CameraInfo> cameraInfo = std::make_shared<CameraInfo>();
243 cameraInfo->isCameraOn = true;
244 McCameraTrackingController::GetInstance().currentCameraInfo_ = cameraInfo;
245
246 std::shared_ptr<RegisterMechCameraKeyEventCmd> cmd = std::make_shared<RegisterMechCameraKeyEventCmd>();
247 cmd->event_ = CameraKeyEvent::ZOOM_IN;
248 motionMgr->MechButtonEventNotify(cmd);
249
250 EXPECT_EQ(keyEvent_, CameraKeyEvent::ZOOM_IN);
251 }
252
253 /**
254 * @tc.name : MechButtonEventNotify_006
255 * @tc.number: MechButtonEventNotify_006
256 * @tc.desc : Test MechButtonEventNotify with SWITCH_CAMERA event.
257 */
258 HWTEST_F(MotionManagerTest, MechButtonEventNotify_006, TestSize.Level1)
259 {
260 int32_t mechId = 100;
261 std::shared_ptr<MotionManager> motionMgr =
262 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
263 motionMgr->RegisterEventListener();
264
265 std::shared_ptr<CameraInfo> cameraInfo = std::make_shared<CameraInfo>();
266 cameraInfo->isCameraOn = true;
267 McCameraTrackingController::GetInstance().currentCameraInfo_ = cameraInfo;
268
269 std::shared_ptr<RegisterMechCameraKeyEventCmd> cmd = std::make_shared<RegisterMechCameraKeyEventCmd>();
270 cmd->event_ = CameraKeyEvent::SWITCH_CAMERA;
271 motionMgr->MechButtonEventNotify(cmd);
272
273 EXPECT_EQ(keyEvent_, CameraKeyEvent::SWITCH_CAMERA);
274 }
275
276 /**
277 * @tc.name : MechButtonEventNotify_007
278 * @tc.number: MechButtonEventNotify_007
279 * @tc.desc : Test MechButtonEventNotify with Default event.
280 */
281 HWTEST_F(MotionManagerTest, MechButtonEventNotify_007, TestSize.Level1)
282 {
283 int32_t mechId = 100;
284 std::shared_ptr<MotionManager> motionMgr =
285 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
286 motionMgr->RegisterEventListener();
287
288 std::shared_ptr<CameraInfo> cameraInfo = std::make_shared<CameraInfo>();
289 cameraInfo->isCameraOn = true;
290 McCameraTrackingController::GetInstance().currentCameraInfo_ = cameraInfo;
291
292 std::shared_ptr<RegisterMechCameraKeyEventCmd> cmd = std::make_shared<RegisterMechCameraKeyEventCmd>();
293 cmd->event_ = CameraKeyEvent::INVALID;
294 motionMgr->MechButtonEventNotify(cmd);
295
296 EXPECT_NE(keyEvent_, CameraKeyEvent::INVALID);
297 }
298
299 /**
300 * @tc.name : MechParamNotify_001
301 * @tc.number: MechParamNotify_001
302 * @tc.desc : Test MechParamNotify with FOLLOW mode.
303 */
304 HWTEST_F(MotionManagerTest, MechParamNotify_001, TestSize.Level1)
305 {
306 int32_t mechId = 100;
307 std::shared_ptr<MotionManager> motionMgr =
308 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
309 motionMgr->RegisterEventListener();
310
311 std::shared_ptr<RegisterMechStateInfoCmd> cmd = std::make_shared<RegisterMechStateInfoCmd>();
312 MechStateInfo info;
313 info.mechMode = MechMode::FOLLOW;
314 cmd->info_ = info;
315 motionMgr->MechParamNotify(cmd);
316
317 motionMgr->deviceStatus_->stateInfo = cmd->GetInfo();
318 motionMgr->MechParamNotify(cmd);
319
320 EXPECT_TRUE(motionMgr->deviceStatus_->rotationAxesStatus.yawEnabled);
321 EXPECT_FALSE(motionMgr->deviceStatus_->rotationAxesStatus.rollEnabled);
322 EXPECT_TRUE(motionMgr->deviceStatus_->rotationAxesStatus.pitchEnabled);
323 }
324
325 /**
326 * @tc.name : MechParamNotify_002
327 * @tc.number: MechParamNotify_002
328 * @tc.desc : Test MechParamNotify with FREE mode.
329 */
330 HWTEST_F(MotionManagerTest, MechParamNotify_002, TestSize.Level1)
331 {
332 int32_t mechId = 100;
333 std::shared_ptr<MotionManager> motionMgr =
334 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
335 motionMgr->RegisterEventListener();
336
337 std::shared_ptr<RegisterMechStateInfoCmd> cmd = std::make_shared<RegisterMechStateInfoCmd>();
338 MechStateInfo info;
339 info.mechMode = MechMode::FREE;
340 cmd->info_ = info;
341 motionMgr->MechParamNotify(cmd);
342
343 EXPECT_FALSE(motionMgr->deviceStatus_->rotationAxesStatus.yawEnabled);
344 EXPECT_FALSE(motionMgr->deviceStatus_->rotationAxesStatus.rollEnabled);
345 EXPECT_FALSE(motionMgr->deviceStatus_->rotationAxesStatus.pitchEnabled);
346 }
347
348 /**
349 * @tc.name : MechParamNotify_003
350 * @tc.number: MechParamNotify_003
351 * @tc.desc : Test MechParamNotify with PITCH_FREE and FPV mode.
352 */
353 HWTEST_F(MotionManagerTest, MechParamNotify_003, TestSize.Level1)
354 {
355 int32_t mechId = 100;
356 std::shared_ptr<MotionManager> motionMgr =
357 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
358 motionMgr->RegisterEventListener();
359
360 std::shared_ptr<RegisterMechStateInfoCmd> cmd = std::make_shared<RegisterMechStateInfoCmd>();
361 MechStateInfo info;
362 info.mechMode = MechMode::PITCH_FREE;
363 cmd->info_ = info;
364 motionMgr->MechParamNotify(cmd);
365
366 info.mechMode = MechMode::FPV;
367 cmd->info_ = info;
368 motionMgr->MechParamNotify(cmd);
369
370 info.mechMode = MechMode::ROLL;
371 cmd->info_ = info;
372 motionMgr->MechParamNotify(cmd);
373
374 EXPECT_TRUE(motionMgr->deviceStatus_->rotationAxesStatus.yawEnabled);
375 EXPECT_FALSE(motionMgr->deviceStatus_->rotationAxesStatus.rollEnabled);
376 EXPECT_TRUE(motionMgr->deviceStatus_->rotationAxesStatus.pitchEnabled);
377 }
378
379 /**
380 * @tc.name : Rotate_001
381 * @tc.number: Rotate_001
382 * @tc.desc : Test Rotate when the phone is not placed on mech.
383 */
384 HWTEST_F(MotionManagerTest, Rotate_001, TestSize.Level1)
385 {
386 int32_t mechId = 100;
387 std::shared_ptr<MotionManager> motionMgr =
388 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
389 motionMgr->RegisterEventListener();
390 g_mockMechState = false;
391
392 std::shared_ptr<RotateParam> rotateParam = std::make_shared<RotateParam>();
393 rotateParam->degree.yaw = 0;
394 rotateParam->degree.pitch = 0;
395 rotateParam->degree.roll = 0;
396 rotateParam->duration = 1000;
397
398 sptr<IRemoteObject> callback = nullptr;
399 uint32_t tokenId = 1;
400 std::string napiCmdId = "1";
401
402 int32_t result = motionMgr->Rotate(rotateParam, tokenId, napiCmdId);
403 EXPECT_EQ(result, DEVICE_NOT_PLACED_ON_MECH);
404 }
405
406 /**
407 * @tc.name : Rotate_002
408 * @tc.number: Rotate_002
409 * @tc.desc : Test Rotate with invalid parameters and null callback.
410 */
411 HWTEST_F(MotionManagerTest, Rotate_002, TestSize.Level1)
412 {
413 int32_t mechId = 100;
414 std::shared_ptr<MotionManager> motionMgr =
415 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
416 motionMgr->RegisterEventListener();
417 g_mockMechState = true;
418
419 std::shared_ptr<RotateParam> rotateParam = std::make_shared<RotateParam>();
420 rotateParam->degree.yaw = 10;
421 rotateParam->degree.pitch = 0;
422 rotateParam->degree.roll = 0;
423 rotateParam->duration = 1000;
424
425 uint32_t tokenId = 1;
426 std::string napiCmdId = "1";
427
428 int32_t result = motionMgr->Rotate(rotateParam, tokenId, napiCmdId);
429 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
430 }
431
432 /**
433 * @tc.name : Rotate_003
434 * @tc.number: Rotate_003
435 * @tc.desc : Test Rotate with invalid parameters and non-null callback.
436 */
437 HWTEST_F(MotionManagerTest, Rotate_003, TestSize.Level1)
438 {
439 int32_t mechId = 100;
440 std::shared_ptr<MotionManager> motionMgr =
441 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
442 motionMgr->RegisterEventListener();
443 g_mockMechState = true;
444
445 std::shared_ptr<RotateParam> rotateParam = std::make_shared<RotateParam>();
446 rotateParam->degree.yaw = 361;
447 rotateParam->degree.pitch = 0;
448 rotateParam->degree.roll = 0;
449 rotateParam->duration = 1000;
450
451 uint32_t tokenId = 1;
452 std::string napiCmdId = "1";
453
454 int32_t result = motionMgr->Rotate(rotateParam, tokenId, napiCmdId);
455 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
456 }
457
458 /**
459 * @tc.name : Rotate_004
460 * @tc.number: Rotate_004
461 * @tc.desc : Test Rotate with valid parameters.
462 */
463 HWTEST_F(MotionManagerTest, Rotate_004, TestSize.Level1)
464 {
465 int32_t mechId = 100;
466 std::shared_ptr<MotionManager> motionMgr =
467 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
468 motionMgr->RegisterEventListener();
469 g_mockMechState = true;
470
471 std::shared_ptr<RotateParam> rotateParam = std::make_shared<RotateParam>();
472 rotateParam->degree.yaw = 1;
473 rotateParam->degree.pitch = 1;
474 rotateParam->degree.roll = 0;
475 rotateParam->duration = 100;
476
477 uint32_t tokenId = 1;
478 std::string napiCmdId = "1";
479
480 int32_t result = motionMgr->Rotate(rotateParam, tokenId, napiCmdId);
481 EXPECT_EQ(result, ERR_OK);
482
483 rotateParam->isRelative = true;
484 result = motionMgr->Rotate(rotateParam, tokenId, napiCmdId);
485 EXPECT_EQ(result, ERR_OK);
486 }
487
488 /**
489 * @tc.name : RotateBySpeed_001
490 * @tc.number: RotateBySpeed_001
491 * @tc.desc : Test RotateBySpeed when the phone is not placed on mech.
492 */
493 HWTEST_F(MotionManagerTest, RotateBySpeed_001, TestSize.Level1)
494 {
495 int32_t mechId = 100;
496 std::shared_ptr<MotionManager> motionMgr =
497 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
498 motionMgr->RegisterEventListener();
499 g_mockMechState = false;
500
501 std::shared_ptr<RotateBySpeedParam> rotateSpeedParam = std::make_shared<RotateBySpeedParam>();
502 rotateSpeedParam->speed.yawSpeed = 1;
503 rotateSpeedParam->speed.pitchSpeed = 1;
504 rotateSpeedParam->speed.rollSpeed = 1;
505 rotateSpeedParam->duration = 1000;
506
507 uint32_t tokenId = 1;
508 std::string napiCmdId = "1";
509
510 int32_t result = motionMgr->RotateBySpeed(rotateSpeedParam, tokenId, napiCmdId);
511 EXPECT_EQ(result, DEVICE_NOT_PLACED_ON_MECH);
512 }
513
514 /**
515 * @tc.name : RotateBySpeed_002
516 * @tc.number: RotateBySpeed_002
517 * @tc.desc : Test RotateBySpeed with null callback.
518 */
519 HWTEST_F(MotionManagerTest, RotateBySpeed_002, TestSize.Level1)
520 {
521 int32_t mechId = 100;
522 std::shared_ptr<MotionManager> motionMgr =
523 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
524 motionMgr->RegisterEventListener();
525 g_mockMechState = true;
526
527 std::shared_ptr<RotateBySpeedParam> rotateSpeedParam = std::make_shared<RotateBySpeedParam>();
528 rotateSpeedParam->speed.yawSpeed = 1;
529 rotateSpeedParam->speed.pitchSpeed = 1;
530 rotateSpeedParam->speed.rollSpeed = 1;
531 rotateSpeedParam->duration = 1000;
532
533 uint32_t tokenId = 1;
534 std::string napiCmdId = "1";
535
536 int32_t result = motionMgr->RotateBySpeed(rotateSpeedParam, tokenId, napiCmdId);
537 EXPECT_EQ(result, ERR_OK);
538 }
539
540 /**
541 * @tc.name : RotateBySpeed_003
542 * @tc.number: RotateBySpeed_003
543 * @tc.desc : Test RotateBySpeed with valid parameters.
544 */
545 HWTEST_F(MotionManagerTest, RotateBySpeed_003, TestSize.Level1)
546 {
547 int32_t mechId = 100;
548 std::shared_ptr<MotionManager> motionMgr =
549 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
550 motionMgr->RegisterEventListener();
551 g_mockMechState = true;
552
553 std::shared_ptr<RotateBySpeedParam> rotateSpeedParam = std::make_shared<RotateBySpeedParam>();
554 rotateSpeedParam->speed.yawSpeed = 1;
555 rotateSpeedParam->speed.pitchSpeed = 1;
556 rotateSpeedParam->speed.rollSpeed = 1;
557 rotateSpeedParam->duration = 100;
558
559 uint32_t tokenId = 1;
560 std::string napiCmdId = "1";
561
562 int32_t result = motionMgr->RotateBySpeed(rotateSpeedParam, tokenId, napiCmdId);
563 EXPECT_EQ(result, ERR_OK);
564 EXPECT_EQ(motionMgr->deviceStatus_->eulerAngles.yaw, 0);
565 EXPECT_EQ(motionMgr->deviceStatus_->eulerAngles.pitch, 0);
566 EXPECT_EQ(motionMgr->deviceStatus_->eulerAngles.roll, 0);
567 }
568
569 /**
570 * @tc.name : StopRotate_001
571 * @tc.number: StopRotate_001
572 * @tc.desc : Test StopRotate when the phone is not placed on mech.
573 */
574 HWTEST_F(MotionManagerTest, StopRotate_001, TestSize.Level1)
575 {
576 int32_t mechId = 100;
577 std::shared_ptr<MotionManager> motionMgr =
578 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
579 motionMgr->RegisterEventListener();
580 g_mockMechState = false;
581
582 uint32_t tokenId = 1;
583 std::string napiCmdId = "1";
584
585 int32_t result = motionMgr->StopRotate(tokenId, napiCmdId);
586 EXPECT_EQ(result, DEVICE_NOT_PLACED_ON_MECH);
587 }
588
589 /**
590 * @tc.name : StopRotate_002
591 * @tc.number: StopRotate_002
592 * @tc.desc : Test StopRotate with valid parameters.
593 */
594 HWTEST_F(MotionManagerTest, StopRotate_002, TestSize.Level1)
595 {
596 int32_t mechId = 100;
597 std::shared_ptr<MotionManager> motionMgr =
598 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
599 motionMgr->RegisterEventListener();
600 g_mockMechState = true;
601
602 uint32_t tokenId = 1;
603 std::string napiCmdId = "1";
604
605 int32_t result = motionMgr->StopRotate(tokenId, napiCmdId);
606 EXPECT_EQ(result, ERR_OK);
607 }
608
609 /**
610 * @tc.name : GetSpeedControlTimeLimit_001
611 * @tc.number: GetSpeedControlTimeLimit_001
612 * @tc.desc : Test GetSpeedControlTimeLimit when the phone is not placed on mech.
613 */
614 HWTEST_F(MotionManagerTest, GetSpeedControlTimeLimit_001, TestSize.Level1)
615 {
616 int32_t mechId = 100;
617 std::shared_ptr<MotionManager> motionMgr =
618 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
619 motionMgr->RegisterEventListener();
620 g_mockMechState = false;
621
622 std::shared_ptr<TimeLimit> timeLimit = nullptr;
623
624 int32_t result = motionMgr->GetSpeedControlTimeLimit(timeLimit);
625 EXPECT_EQ(result, DEVICE_NOT_PLACED_ON_MECH);
626 }
627
628 /**
629 * @tc.name : GetSpeedControlTimeLimit_002
630 * @tc.number: GetSpeedControlTimeLimit_002
631 * @tc.desc : Test GetSpeedControlTimeLimit with valid parameters.
632 */
633 HWTEST_F(MotionManagerTest, GetSpeedControlTimeLimit_002, TestSize.Level1)
634 {
635 int32_t mechId = 100;
636 std::shared_ptr<MotionManager> motionMgr =
637 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
638 motionMgr->RegisterEventListener();
639 g_mockMechState = true;
640
641 std::shared_ptr<TimeLimit> timeLimit = std::make_shared<TimeLimit>();
642 std::shared_ptr<TimeLimit> timeLimitNull = nullptr;
643
644 int32_t result = motionMgr->GetSpeedControlTimeLimit(timeLimit);
645 EXPECT_EQ(result, ERR_OK);
646 EXPECT_NE(timeLimit, nullptr);
647 EXPECT_EQ(timeLimit->min, 0);
648 EXPECT_EQ(timeLimit->max, DEFAULT_DURATION);
649
650 result = motionMgr->GetSpeedControlTimeLimit(timeLimitNull);
651 EXPECT_EQ(result, ERR_OK);
652 }
653
654 /**
655 * @tc.name : GetRotateSpeedLimit_001
656 * @tc.number: GetRotateSpeedLimit_001
657 * @tc.desc : Test GetRotateSpeedLimit when the phone is not placed on mech.
658 */
659 HWTEST_F(MotionManagerTest, GetRotateSpeedLimit_001, TestSize.Level1)
660 {
661 int32_t mechId = 100;
662 std::shared_ptr<MotionManager> motionMgr =
663 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
664 motionMgr->RegisterEventListener();
665 g_mockMechState = false;
666
667 RotateSpeedLimit speedLimit;
668
669 int32_t result = motionMgr->GetRotateSpeedLimit(speedLimit);
670 EXPECT_EQ(result, DEVICE_NOT_PLACED_ON_MECH);
671 }
672
673 /**
674 * @tc.name : GetRotateSpeedLimit_002
675 * @tc.number: GetRotateSpeedLimit_002
676 * @tc.desc : Test GetRotateSpeedLimit with valid parameters.
677 */
678 HWTEST_F(MotionManagerTest, GetRotateSpeedLimit_002, TestSize.Level1)
679 {
680 int32_t mechId = 100;
681 std::shared_ptr<MotionManager> motionMgr =
682 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
683 motionMgr->RegisterEventListener();
684 g_mockMechState = true;
685
686 RotateSpeedLimit speedLimit;
687
688 int32_t result = motionMgr->GetRotateSpeedLimit(speedLimit);
689 EXPECT_EQ(result, ERR_OK);
690 EXPECT_EQ(speedLimit.speedMin.pitchSpeed, motionMgr->deviceStatus_->rotateSpeedLimit.speedMin.pitchSpeed);
691 EXPECT_EQ(speedLimit.speedMin.rollSpeed, motionMgr->deviceStatus_->rotateSpeedLimit.speedMin.rollSpeed);
692 EXPECT_EQ(speedLimit.speedMin.yawSpeed, motionMgr->deviceStatus_->rotateSpeedLimit.speedMin.yawSpeed);
693 EXPECT_EQ(speedLimit.speedMax.pitchSpeed, motionMgr->deviceStatus_->rotateSpeedLimit.speedMax.pitchSpeed);
694 EXPECT_EQ(speedLimit.speedMax.rollSpeed, motionMgr->deviceStatus_->rotateSpeedLimit.speedMax.rollSpeed);
695 EXPECT_EQ(speedLimit.speedMax.yawSpeed, motionMgr->deviceStatus_->rotateSpeedLimit.speedMax.yawSpeed);
696 }
697
698 /**
699 * @tc.name : GetCurrentPosition_001
700 * @tc.number: GetCurrentPosition_001
701 * @tc.desc : Test GetCurrentPosition when the phone is not placed on mech.
702 */
703 HWTEST_F(MotionManagerTest, GetCurrentPosition_001, TestSize.Level1)
704 {
705 int32_t mechId = 100;
706 std::shared_ptr<MotionManager> motionMgr =
707 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
708 motionMgr->RegisterEventListener();
709 g_mockMechState = false;
710
711 std::shared_ptr<EulerAngles> eulerAngles = std::make_shared<EulerAngles>();
712
713 int32_t result = motionMgr->GetCurrentPosition(eulerAngles);
714 EXPECT_EQ(result, DEVICE_NOT_PLACED_ON_MECH);
715 }
716
717 /**
718 * @tc.name : GetCurrentPosition_002
719 * @tc.number: GetCurrentPosition_002
720 * @tc.desc : Test GetCurrentPosition with valid parameters.
721 */
722 HWTEST_F(MotionManagerTest, GetCurrentPosition_002, TestSize.Level1)
723 {
724 int32_t mechId = 100;
725 std::shared_ptr<MotionManager> motionMgr =
726 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
727 motionMgr->RegisterEventListener();
728 g_mockMechState = true;
729
730 std::shared_ptr<EulerAngles> eulerAngles = std::make_shared<EulerAngles>();
731
732 int32_t result = motionMgr->GetCurrentPosition(eulerAngles);
733 EXPECT_EQ(result, ERR_OK);
734 EXPECT_EQ(eulerAngles->yaw, motionMgr->deviceStatus_->eulerAngles.yaw);
735 EXPECT_EQ(eulerAngles->pitch, motionMgr->deviceStatus_->eulerAngles.pitch);
736 EXPECT_EQ(eulerAngles->roll, motionMgr->deviceStatus_->eulerAngles.roll);
737 }
738
739 /**
740 * @tc.name : GetRotationLimit_001
741 * @tc.number: GetRotationLimit_001
742 * @tc.desc : Test GetRotationLimit when the phone is not placed on mech.
743 */
744 HWTEST_F(MotionManagerTest, GetRotationLimit_001, TestSize.Level1)
745 {
746 int32_t mechId = 100;
747 std::shared_ptr<MotionManager> motionMgr =
748 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
749 motionMgr->RegisterEventListener();
750 g_mockMechState = false;
751
752 RotateDegreeLimit rotationLimit;
753
754 int32_t result = motionMgr->GetRotationLimit(rotationLimit);
755 EXPECT_EQ(result, DEVICE_NOT_PLACED_ON_MECH);
756 }
757
758 /**
759 * @tc.name : GetRotationLimit_002
760 * @tc.number: GetRotationLimit_002
761 * @tc.desc : Test GetRotationLimit with valid parameters.
762 */
763 HWTEST_F(MotionManagerTest, GetRotationLimit_002, TestSize.Level1)
764 {
765 int32_t mechId = 100;
766 std::shared_ptr<MotionManager> motionMgr =
767 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
768 motionMgr->RegisterEventListener();
769 g_mockMechState = true;
770
771 RotateDegreeLimit rotationLimit;
772
773 int32_t result = motionMgr->GetRotationLimit(rotationLimit);
774 EXPECT_EQ(result, ERR_OK);
775 // 检查旋转限制是否正确
776 EXPECT_EQ(rotationLimit.negMax.roll, motionMgr->deviceStatus_->rotationLimit.negMax.roll);
777 EXPECT_EQ(rotationLimit.negMax.pitch, motionMgr->deviceStatus_->rotationLimit.negMax.pitch);
778 EXPECT_EQ(rotationLimit.negMax.yaw, motionMgr->deviceStatus_->rotationLimit.negMax.yaw);
779 EXPECT_EQ(rotationLimit.posMax.roll, motionMgr->deviceStatus_->rotationLimit.posMax.roll);
780 EXPECT_EQ(rotationLimit.posMax.pitch, motionMgr->deviceStatus_->rotationLimit.posMax.pitch);
781 EXPECT_EQ(rotationLimit.posMax.yaw, motionMgr->deviceStatus_->rotationLimit.posMax.yaw);
782 }
783
784 /**
785 * @tc.name : SetMechCameraTrackingFrame_001
786 * @tc.number: SetMechCameraTrackingFrame_001
787 * @tc.desc : Test SetMechCameraTrackingFrame when the phone is not placed on mech.
788 */
789 HWTEST_F(MotionManagerTest, SetMechCameraTrackingFrame_001, TestSize.Level1)
790 {
791 int32_t mechId = 100;
792 std::shared_ptr<MotionManager> motionMgr =
793 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
794 motionMgr->RegisterEventListener();
795 g_mockMechState = false;
796
797 std::shared_ptr<TrackingFrameParams> trackingFrameParams = std::make_shared<TrackingFrameParams>();
798
799 int32_t result = motionMgr->SetMechCameraTrackingFrame(trackingFrameParams);
800 EXPECT_EQ(result, DEVICE_NOT_PLACED_ON_MECH);
801 }
802
803 /**
804 * @tc.name : SetMechCameraTrackingFrame_002
805 * @tc.number: SetMechCameraTrackingFrame_002
806 * @tc.desc : Test SetMechCameraTrackingFrame with valid parameters.
807 */
808 HWTEST_F(MotionManagerTest, SetMechCameraTrackingFrame_002, TestSize.Level1)
809 {
810 int32_t mechId = 100;
811 std::shared_ptr<MotionManager> motionMgr =
812 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
813 motionMgr->RegisterEventListener();
814 g_mockMechState = true;
815
816 std::shared_ptr<TrackingFrameParams> trackingFrameParams = std::make_shared<TrackingFrameParams>();
817 motionMgr->deviceStatus_->isEnabled = true;
818
819 int32_t result = motionMgr->SetMechCameraTrackingFrame(trackingFrameParams);
820 EXPECT_EQ(result, ERR_OK);
821 }
822
823 /**
824 * @tc.name : GetMechCameraTrackingEnabled_001
825 * @tc.number: GetMechCameraTrackingEnabled_001
826 * @tc.desc : Test GetMechCameraTrackingEnabled when the phone is not placed on mech.
827 */
828 HWTEST_F(MotionManagerTest, GetMechCameraTrackingEnabled_001, TestSize.Level1)
829 {
830 int32_t mechId = 100;
831 std::shared_ptr<MotionManager> motionMgr =
832 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
833 motionMgr->RegisterEventListener();
834 g_mockMechState = false;
835
836 bool isEnabled = false;
837
838 int32_t result = motionMgr->GetMechCameraTrackingEnabled(isEnabled);
839 EXPECT_EQ(result, ERR_OK);
840 }
841
842 /**
843 * @tc.name : GetMechCameraTrackingEnabled_002
844 * @tc.number: GetMechCameraTrackingEnabled_002
845 * @tc.desc : Test GetMechCameraTrackingEnabled with valid parameters.
846 */
847 HWTEST_F(MotionManagerTest, GetMechCameraTrackingEnabled_002, TestSize.Level1)
848 {
849 int32_t mechId = 100;
850 std::shared_ptr<MotionManager> motionMgr =
851 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
852 motionMgr->RegisterEventListener();
853 g_mockMechState = true;
854
855 bool isEnabled = false;
856
857 int32_t result = motionMgr->GetMechCameraTrackingEnabled(isEnabled);
858 EXPECT_EQ(result, ERR_OK);
859 // 检查是否正确获取了启用状态
860 EXPECT_EQ(isEnabled, motionMgr->deviceStatus_->isEnabled);
861 }
862
863 /**
864 * @tc.name : SetMechCameraTrackingLayout_001
865 * @tc.number: SetMechCameraTrackingLayout_001
866 * @tc.desc : Test SetMechCameraTrackingLayout when the phone is not placed on mech.
867 */
868 HWTEST_F(MotionManagerTest, SetMechCameraTrackingLayout_001, TestSize.Level1)
869 {
870 int32_t mechId = 100;
871 std::shared_ptr<MotionManager> motionMgr =
872 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
873 motionMgr->RegisterEventListener();
874 g_mockMechState = false;
875
876 std::shared_ptr<LayoutParams> layoutParams = std::make_shared<LayoutParams>();
877 layoutParams->isDefault = true;
878 layoutParams->offsetX = 10;
879 layoutParams->offsetY = 10;
880
881 int32_t result = motionMgr->SetMechCameraTrackingLayout(layoutParams);
882 EXPECT_EQ(result, DEVICE_NOT_PLACED_ON_MECH);
883 }
884
885 /**
886 * @tc.name : SetMechCameraTrackingLayout_002
887 * @tc.number: SetMechCameraTrackingLayout_002
888 * @tc.desc : Test SetMechCameraTrackingLayout with valid parameters.
889 */
890 HWTEST_F(MotionManagerTest, SetMechCameraTrackingLayout_002, TestSize.Level1)
891 {
892 int32_t mechId = 100;
893 std::shared_ptr<MotionManager> motionMgr =
894 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
895 motionMgr->RegisterEventListener();
896 g_mockMechState = true;
897
898 std::shared_ptr<LayoutParams> layoutParams = std::make_shared<LayoutParams>();
899 layoutParams->isDefault = true;
900 layoutParams->offsetX = 10;
901 layoutParams->offsetY = 10;
902
903 int32_t result = motionMgr->SetMechCameraTrackingLayout(layoutParams);
904 EXPECT_EQ(result, ERR_OK);
905
906 EXPECT_TRUE(motionMgr->deviceStatus_->layoutParams.isDefault);
907 EXPECT_EQ(motionMgr->deviceStatus_->layoutParams.offsetX, 10);
908 EXPECT_EQ(motionMgr->deviceStatus_->layoutParams.offsetY, 10);
909 }
910
911 /**
912 * @tc.name : GetMechCameraTrackingLayout_001
913 * @tc.number: GetMechCameraTrackingLayout_001
914 * @tc.desc : Test GetMechCameraTrackingLayout when the phone is not placed on mech.
915 */
916 HWTEST_F(MotionManagerTest, GetMechCameraTrackingLayout_001, TestSize.Level1)
917 {
918 int32_t mechId = 100;
919 std::shared_ptr<MotionManager> motionMgr =
920 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
921 motionMgr->RegisterEventListener();
922 g_mockMechState = false;
923
924 std::shared_ptr<LayoutParams> layoutParams = nullptr;
925
926 int32_t result = motionMgr->GetMechCameraTrackingLayout(layoutParams);
927 EXPECT_EQ(result, ERR_OK);
928 }
929
930 /**
931 * @tc.name : GetMechCameraTrackingLayout_002
932 * @tc.number: GetMechCameraTrackingLayout_002
933 * @tc.desc : Test GetMechCameraTrackingLayout with valid parameters.
934 */
935 HWTEST_F(MotionManagerTest, GetMechCameraTrackingLayout_002, TestSize.Level1)
936 {
937 int32_t mechId = 100;
938 std::shared_ptr<MotionManager> motionMgr =
939 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
940 motionMgr->RegisterEventListener();
941 g_mockMechState = true;
942
943 std::shared_ptr<LayoutParams> layoutParams = nullptr;
944
945 int32_t result = motionMgr->GetMechCameraTrackingLayout(layoutParams);
946 EXPECT_EQ(result, ERR_OK);
947 EXPECT_EQ(motionMgr->deviceStatus_->layoutParams.isDefault, layoutParams->isDefault);
948 EXPECT_EQ(motionMgr->deviceStatus_->layoutParams.offsetX, layoutParams->offsetX);
949 EXPECT_EQ(motionMgr->deviceStatus_->layoutParams.offsetY, layoutParams->offsetY);
950 }
951
952 /**
953 * @tc.name : GetMechBaseInfo_001
954 * @tc.number: GetMechBaseInfo_001
955 * @tc.desc : Test GetMechBaseInfo when the phone is not placed on mech.
956 */
957 HWTEST_F(MotionManagerTest, GetMechBaseInfo_001, TestSize.Level1)
958 {
959 int32_t mechId = 100;
960 std::shared_ptr<MotionManager> motionMgr =
961 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
962 motionMgr->RegisterEventListener();
963 g_mockMechState = false;
964
965 std::shared_ptr<MechBaseInfo> mechBaseInfo = nullptr;
966
967 int32_t result = motionMgr->GetMechBaseInfo(mechBaseInfo);
968 EXPECT_EQ(result, DEVICE_NOT_PLACED_ON_MECH);
969 }
970
971 /**
972 * @tc.name : GetMechBaseInfo_002
973 * @tc.number: GetMechBaseInfo_002
974 * @tc.desc : Test GetMechBaseInfo when base info is not obtainable.
975 */
976 HWTEST_F(MotionManagerTest, GetMechBaseInfo_002, TestSize.Level1)
977 {
978 int32_t mechId = 100;
979 std::shared_ptr<MotionManager> motionMgr =
980 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
981 motionMgr->RegisterEventListener();
982 g_mockMechState = true;
983 motionMgr->deviceStatus_->mechBaseInfo.obtainable = false;
984
985 std::shared_ptr<MechBaseInfo> mechBaseInfo = nullptr;
986
987 int32_t result = motionMgr->GetMechBaseInfo(mechBaseInfo);
988 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
989 }
990
991 /**
992 * @tc.name : GetMechBaseInfo_003
993 * @tc.number: GetMechBaseInfo_003
994 * @tc.desc : Test GetMechBaseInfo with valid parameters.
995 */
996 HWTEST_F(MotionManagerTest, GetMechBaseInfo_003, TestSize.Level1)
997 {
998 int32_t mechId = 100;
999 std::shared_ptr<MotionManager> motionMgr =
1000 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1001 motionMgr->RegisterEventListener();
1002 g_mockMechState = true;
1003 motionMgr->deviceStatus_->mechBaseInfo.obtainable = true;
1004
1005 std::shared_ptr<MechBaseInfo> mechBaseInfo = nullptr;
1006
1007 int32_t result = motionMgr->GetMechBaseInfo(mechBaseInfo);
1008 EXPECT_EQ(result, ERR_OK);
1009 EXPECT_NE(mechBaseInfo, nullptr);
1010 EXPECT_EQ(mechBaseInfo->mechType, motionMgr->deviceStatus_->mechBaseInfo.mechType);
1011 }
1012
1013 /**
1014 * @tc.name : GetMechCapabilityInfo_001
1015 * @tc.number: GetMechCapabilityInfo_001
1016 * @tc.desc : Test GetMechCapabilityInfo when the phone is not placed on mech.
1017 */
1018 HWTEST_F(MotionManagerTest, GetMechCapabilityInfo_001, TestSize.Level1)
1019 {
1020 int32_t mechId = 100;
1021 std::shared_ptr<MotionManager> motionMgr =
1022 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1023 motionMgr->RegisterEventListener();
1024 g_mockMechState = false;
1025
1026 std::shared_ptr<MechCapabilityInfo> mechCapabilityInfo = nullptr;
1027
1028 int32_t result = motionMgr->GetMechCapabilityInfo(mechCapabilityInfo);
1029 EXPECT_EQ(result, DEVICE_NOT_PLACED_ON_MECH);
1030 }
1031
1032 /**
1033 * @tc.name : GetMechCapabilityInfo_002
1034 * @tc.number: GetMechCapabilityInfo_002
1035 * @tc.desc : Test GetMechCapabilityInfo when capability info is not obtainable.
1036 */
1037 HWTEST_F(MotionManagerTest, GetMechCapabilityInfo_002, TestSize.Level1)
1038 {
1039 int32_t mechId = 100;
1040 std::shared_ptr<MotionManager> motionMgr =
1041 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1042 motionMgr->RegisterEventListener();
1043 g_mockMechState = true;
1044 motionMgr->deviceStatus_->mechCapabilityInfo.obtainable = false;
1045
1046 std::shared_ptr<MechCapabilityInfo> mechCapabilityInfo = nullptr;
1047
1048 int32_t result = motionMgr->GetMechCapabilityInfo(mechCapabilityInfo);
1049 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
1050 }
1051
1052 /**
1053 * @tc.name : GetMechCapabilityInfo_003
1054 * @tc.number: GetMechCapabilityInfo_003
1055 * @tc.desc : Test GetMechCapabilityInfo with valid parameters.
1056 */
1057 HWTEST_F(MotionManagerTest, GetMechCapabilityInfo_003, TestSize.Level1)
1058 {
1059 int32_t mechId = 100;
1060 std::shared_ptr<MotionManager> motionMgr =
1061 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1062 motionMgr->RegisterEventListener();
1063 g_mockMechState = true;
1064 motionMgr->deviceStatus_->mechCapabilityInfo.obtainable = true;
1065
1066 std::shared_ptr<MechCapabilityInfo> mechCapabilityInfo = nullptr;
1067
1068 int32_t result = motionMgr->GetMechCapabilityInfo(mechCapabilityInfo);
1069 EXPECT_EQ(result, ERR_OK);
1070 EXPECT_NE(mechCapabilityInfo, nullptr);
1071 EXPECT_EQ(mechCapabilityInfo->automaticReturn, motionMgr->deviceStatus_->mechCapabilityInfo.automaticReturn);
1072 }
1073
1074 /**
1075 * @tc.name : GetRotationAxesStatus_001
1076 * @tc.number: GetRotationAxesStatus_001
1077 * @tc.desc : Test GetRotationAxesStatus when the phone is not placed on mech.
1078 */
1079 HWTEST_F(MotionManagerTest, GetRotationAxesStatus_001, TestSize.Level1)
1080 {
1081 int32_t mechId = 100;
1082 std::shared_ptr<MotionManager> motionMgr =
1083 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1084 motionMgr->RegisterEventListener();
1085 g_mockMechState = false;
1086
1087 RotationAxesStatus axesStatus;
1088
1089 int32_t result = motionMgr->GetRotationAxesStatus(mechId, axesStatus);
1090 EXPECT_EQ(result, DEVICE_NOT_PLACED_ON_MECH);
1091 }
1092
1093 /**
1094 * @tc.name : GetRotationAxesStatus_002
1095 * @tc.number: GetRotationAxesStatus_002
1096 * @tc.desc : Test GetRotationAxesStatus with valid parameters.
1097 */
1098 HWTEST_F(MotionManagerTest, GetRotationAxesStatus_002, TestSize.Level1)
1099 {
1100 int32_t mechId = 100;
1101 std::shared_ptr<MotionManager> motionMgr =
1102 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1103 motionMgr->RegisterEventListener();
1104 g_mockMechState = true;
1105
1106 RotationAxesStatus axesStatus;
1107
1108 int32_t result = motionMgr->GetRotationAxesStatus(mechId, axesStatus);
1109 EXPECT_EQ(result, ERR_OK);
1110 EXPECT_EQ(axesStatus.rollEnabled, motionMgr->deviceStatus_->rotationAxesStatus.rollEnabled);
1111 EXPECT_EQ(axesStatus.pitchEnabled, motionMgr->deviceStatus_->rotationAxesStatus.pitchEnabled);
1112 EXPECT_EQ(axesStatus.yawEnabled, motionMgr->deviceStatus_->rotationAxesStatus.yawEnabled);
1113 EXPECT_EQ(axesStatus.rollLimited, motionMgr->deviceStatus_->rotationAxesStatus.rollLimited);
1114 EXPECT_EQ(axesStatus.pitchLimited, motionMgr->deviceStatus_->rotationAxesStatus.pitchLimited);
1115 EXPECT_EQ(axesStatus.yawLimited, motionMgr->deviceStatus_->rotationAxesStatus.yawLimited);
1116 }
1117
1118 /**
1119 * @tc.name : MechExecutionResultNotify_001
1120 * @tc.number: MechExecutionResultNotify_001
1121 * @tc.desc : Test MechExecutionResultNotify with invalid parameters.
1122 */
1123 HWTEST_F(MotionManagerTest, MechExecutionResultNotify_001, TestSize.Level1)
1124 {
1125 int32_t mechId = 100;
1126 std::shared_ptr<MotionManager> motionMgr =
1127 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1128 motionMgr->RegisterEventListener();
1129
1130 std::shared_ptr<RegisterMechControlResultCmd> cmd = nullptr;
1131
1132 EXPECT_NO_FATAL_FAILURE(motionMgr->MechExecutionResultNotify(cmd));
1133 }
1134
1135 /**
1136 * @tc.name : MechExecutionResultNotify_002
1137 * @tc.number: MechExecutionResultNotify_002
1138 * @tc.desc : Test MechExecutionResultNotify with valid parameters.
1139 */
1140 HWTEST_F(MotionManagerTest, MechExecutionResultNotify_002, TestSize.Level1)
1141 {
1142 int32_t mechId = 100;
1143 std::shared_ptr<MotionManager> motionMgr =
1144 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1145 motionMgr->RegisterEventListener();
1146
1147 uint32_t tokenId = 100;
1148 std::string napiCmdId = "napiCmdId";
1149 CommandFactory factory;
1150 auto cmd = factory.CreateRegisterMechControlResultCmd();
1151 uint16_t taskId = cmd->GetTaskId();
1152
1153 EXPECT_NO_FATAL_FAILURE(motionMgr->MechExecutionResultNotify(cmd));
1154
1155 MechNapiCommandCallbackInfo callbackInfo = {tokenId, napiCmdId};
1156 motionMgr->seqCallbacks_.insert(std::make_pair(tokenId, callbackInfo));
1157 EXPECT_NO_FATAL_FAILURE(motionMgr->MechExecutionResultNotify(cmd));
1158
1159 motionMgr->seqCallbacks_.insert(std::make_pair(taskId, callbackInfo));
1160 EXPECT_NO_FATAL_FAILURE(motionMgr->MechExecutionResultNotify(cmd));
1161
1162 cmd->controlResult_ = 2;
1163 EXPECT_NO_FATAL_FAILURE(motionMgr->MechExecutionResultNotify(cmd));
1164 }
1165
1166 /**
1167 * @tc.name : MechWheelZoomNotify_001
1168 * @tc.number: MechWheelZoomNotify_001
1169 * @tc.desc : Test MechWheelZoomNotify function.
1170 */
1171 HWTEST_F(MotionManagerTest, MechWheelZoomNotify_001, TestSize.Level1)
1172 {
1173 int32_t mechId = 100;
1174 std::shared_ptr<MotionManager> motionMgr =
1175 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1176 motionMgr->RegisterEventListener();
1177
1178 g_mockMechState = true;
1179 CommandFactory factory;
1180 auto cmd = factory.CreateRegisterMechWheelDataCmd();
1181
1182 EXPECT_NO_FATAL_FAILURE(motionMgr->MechWheelZoomNotify(cmd));
1183
1184 cmd->wheelData_.degree = 10;
1185 EXPECT_NO_FATAL_FAILURE(motionMgr->MechWheelZoomNotify(cmd));
1186 }
1187
1188 /**
1189 * @tc.name : IsLimited_001
1190 * @tc.number: IsLimited_001
1191 * @tc.desc : Test IsLimited function.
1192 */
1193 HWTEST_F(MotionManagerTest, IsLimited_001, TestSize.Level1)
1194 {
1195 int32_t mechId = 100;
1196 std::shared_ptr<MotionManager> motionMgr =
1197 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1198 motionMgr->RegisterEventListener();
1199
1200 EXPECT_EQ(motionMgr->IsLimited(), false);
1201
1202 motionMgr->deviceStatus_->rotationAxesStatus.pitchLimited = RotationAxisLimited::NEG_LIMITED;
1203 EXPECT_EQ(motionMgr->IsLimited(), true);
1204
1205 motionMgr->deviceStatus_->rotationAxesStatus.yawLimited = RotationAxisLimited::NEG_LIMITED;
1206 EXPECT_EQ(motionMgr->IsLimited(), true);
1207 }
1208
1209 /**
1210 * @tc.name : UnRegisterNotifyEvent_001
1211 * @tc.number: UnRegisterNotifyEvent_001
1212 * @tc.desc : Test UnRegisterNotifyEvent function.
1213 */
1214 HWTEST_F(MotionManagerTest, UnRegisterNotifyEvent_001, TestSize.Level1)
1215 {
1216 int32_t mechId = 100;
1217 std::shared_ptr<MotionManager> motionMgr =
1218 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1219 motionMgr->RegisterEventListener();
1220
1221 EXPECT_NO_FATAL_FAILURE(motionMgr->UnRegisterNotifyEvent());
1222 }
1223
1224 /**
1225 * @tc.name : SetMechCameraInfo_001
1226 * @tc.number: SetMechCameraInfo_001
1227 * @tc.desc : Test SetMechCameraInfo with valid parameters.
1228 */
1229 HWTEST_F(MotionManagerTest, SetMechCameraInfo_001, TestSize.Level1)
1230 {
1231 int32_t mechId = 100;
1232 std::shared_ptr<MotionManager> motionMgr =
1233 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1234 motionMgr->RegisterEventListener();
1235
1236 g_mockMechState = true;
1237 CameraInfoParams mechCameraInfo;
1238 mechCameraInfo.fovH = 1;
1239 mechCameraInfo.fovV = 1;
1240 mechCameraInfo.cameraType = CameraType::FRONT;
1241
1242 EXPECT_EQ(motionMgr->SetMechCameraInfo(mechCameraInfo), ERR_OK);
1243 }
1244
1245 /**
1246 * @tc.name : PerformPresetAction_001
1247 * @tc.number: PerformPresetAction_001
1248 * @tc.desc : Test PerformPresetAction with valid parameters.
1249 */
1250 HWTEST_F(MotionManagerTest, PerformPresetAction_001, TestSize.Level1)
1251 {
1252 int32_t mechId = 100;
1253 std::shared_ptr<MotionManager> motionMgr =
1254 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1255 motionMgr->RegisterEventListener();
1256
1257 PresetAction presetAction = PresetAction::NOD;
1258
1259 EXPECT_EQ(motionMgr->PerformPresetAction(presetAction, 0), ERR_OK);
1260 }
1261
1262 /**
1263 * @tc.name : JudgingYawLimit_001
1264 * @tc.number: JudgingYawLimit_001
1265 * @tc.desc : Test JudgingYawLimit with valid parameters.
1266 */
1267 HWTEST_F(MotionManagerTest, JudgingYawLimit_001, TestSize.Level1)
1268 {
1269 int32_t mechId = 100;
1270 std::shared_ptr<MotionManager> motionMgr =
1271 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1272 motionMgr->RegisterEventListener();
1273
1274 RotateDegreeLimit limit;
1275 limit.negMax.yaw = 1;
1276 limit.negMax.roll = 1;
1277 limit.negMax.pitch = 1;
1278 limit.posMax.yaw = 1;
1279 limit.posMax.roll = 1;
1280 limit.posMax.pitch = 1;
1281 EXPECT_NO_FATAL_FAILURE(motionMgr->JudgingYawLimit(limit));
1282
1283 limit.negMax.yaw = -3.14f;
1284 limit.negMax.roll = -3.14f;
1285 limit.negMax.pitch = -3.14f;
1286 EXPECT_NO_FATAL_FAILURE(motionMgr->JudgingYawLimit(limit));
1287
1288 limit.posMax.yaw = 3.14f;
1289 limit.posMax.roll = 3.14f;
1290 limit.posMax.pitch = 3.14f;
1291 limit.negMax.yaw = 1;
1292 limit.negMax.roll = 1;
1293 limit.negMax.pitch = 1;
1294 EXPECT_NO_FATAL_FAILURE(motionMgr->JudgingYawLimit(limit));
1295
1296 limit.negMax.yaw = -3.14f;
1297 limit.negMax.roll = -3.14f;
1298 limit.negMax.pitch = -3.14f;
1299 EXPECT_NO_FATAL_FAILURE(motionMgr->JudgingYawLimit(limit));
1300 }
1301
1302 /**
1303 * @tc.name : SetMechCameraTrackingEnabled_001
1304 * @tc.number: SetMechCameraTrackingEnabled_001
1305 * @tc.desc : Test SetMechCameraTrackingEnabled with valid parameters.
1306 */
1307 HWTEST_F(MotionManagerTest, SetMechCameraTrackingEnabled_001, TestSize.Level1)
1308 {
1309 int32_t mechId = 100;
1310 std::shared_ptr<MotionManager> motionMgr =
1311 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1312 motionMgr->RegisterEventListener();
1313
1314 bool isEnabled = true;
1315
1316 EXPECT_EQ(motionMgr->SetMechCameraTrackingEnabled(isEnabled), ERR_OK);
1317
1318 motionMgr->deviceStatus_ = nullptr;
1319 EXPECT_EQ(motionMgr->SetMechCameraTrackingEnabled(isEnabled), ERR_OK);
1320 }
1321
1322 /**
1323 * @tc.name : AbsolutelyEulerAnglesJudgingLimitLocked_001
1324 * @tc.number: AbsolutelyEulerAnglesJudgingLimitLocked_001
1325 * @tc.desc : Test AbsolutelyEulerAnglesJudgingLimitLocked with valid parameters.
1326 */
1327 HWTEST_F(MotionManagerTest, AbsolutelyEulerAnglesJudgingLimitLocked_001, TestSize.Level1)
1328 {
1329 int32_t mechId = 100;
1330 std::shared_ptr<MotionManager> motionMgr =
1331 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1332 motionMgr->RegisterEventListener();
1333
1334 motionMgr->deviceStatus_ = std::make_shared<DeviceStatus>();
1335 EulerAngles eulerAngles;
1336
1337 EXPECT_NO_FATAL_FAILURE(motionMgr->AbsolutelyEulerAnglesJudgingLimitLocked(eulerAngles));
1338 }
1339
1340 /**
1341 * @tc.name : AbsolutelyEulerAnglesJudgingLimitLocked_002
1342 * @tc.number: AbsolutelyEulerAnglesJudgingLimitLocked_002
1343 * @tc.desc : Test AbsolutelyEulerAnglesJudgingLimitLocked with invalid parameters.
1344 */
1345 HWTEST_F(MotionManagerTest, AbsolutelyEulerAnglesJudgingLimitLocked_002, TestSize.Level1)
1346 {
1347 int32_t mechId = 100;
1348 std::shared_ptr<MotionManager> motionMgr =
1349 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1350 motionMgr->RegisterEventListener();
1351
1352 motionMgr->deviceStatus_ = nullptr;
1353 EulerAngles eulerAngles;
1354
1355 EXPECT_NO_FATAL_FAILURE(motionMgr->AbsolutelyEulerAnglesJudgingLimitLocked(eulerAngles));
1356 }
1357
1358 /**
1359 * @tc.name : LimitCalculationLocked_001
1360 * @tc.number: LimitCalculationLocked_001
1361 * @tc.desc : Test LimitCalculationLocked with valid parameters.
1362 */
1363 HWTEST_F(MotionManagerTest, LimitCalculationLocked_001, TestSize.Level1)
1364 {
1365 int32_t mechId = 100;
1366 std::shared_ptr<MotionManager> motionMgr =
1367 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1368 motionMgr->RegisterEventListener();
1369
1370 motionMgr->deviceStatus_ = std::make_shared<DeviceStatus>();
1371 motionMgr->deviceStatus_->rollLimit = true;
1372 motionMgr->deviceStatus_->pitchLimit = true;
1373 motionMgr->deviceStatus_->yawLimit = true;
1374 EulerAngles eulerAngles;
1375 bool callback = true;
1376 EXPECT_NO_FATAL_FAILURE(
1377 motionMgr->LimitCalculationLocked(eulerAngles, motionMgr->deviceStatus_->rotationAxesStatus, callback));
1378
1379 motionMgr->deviceStatus_->rotationLimit.negMax.yaw = 1;
1380 motionMgr->deviceStatus_->rotationLimit.negMax.roll = 1;
1381 motionMgr->deviceStatus_->rotationLimit.negMax.pitch = 1;
1382 eulerAngles.yaw = 1;
1383 eulerAngles.roll = 1;
1384 eulerAngles.pitch = 1;
1385 EXPECT_NO_FATAL_FAILURE(
1386 motionMgr->LimitCalculationLocked(eulerAngles, motionMgr->deviceStatus_->rotationAxesStatus, callback));
1387
1388 motionMgr->deviceStatus_->rollLimit = false;
1389 motionMgr->deviceStatus_->pitchLimit = false;
1390 motionMgr->deviceStatus_->yawLimit = false;
1391 EXPECT_NO_FATAL_FAILURE(
1392 motionMgr->LimitCalculationLocked(eulerAngles, motionMgr->deviceStatus_->rotationAxesStatus, callback));
1393 }
1394
1395 /**
1396 * @tc.name : CreateResponseTaskId_001
1397 * @tc.number: CreateResponseTaskId_001
1398 * @tc.desc : Test CreateResponseTaskId with valid parameters.
1399 */
1400 HWTEST_F(MotionManagerTest, CreateResponseTaskId_001, TestSize.Level1)
1401 {
1402 int32_t mechId = 100;
1403 std::shared_ptr<MotionManager> motionMgr =
1404 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1405 motionMgr->RegisterEventListener();
1406
1407 motionMgr->lastTaskId_ = UINT8_MAX;
1408 uint8_t ret = motionMgr->CreateResponseTaskId();
1409
1410 EXPECT_EQ(ret, 0);
1411 }
1412
1413 /**
1414 * @tc.name : HandleMechPlacementChange_001
1415 * @tc.number: HandleMechPlacementChange_001
1416 * @tc.desc : Test HandleMechPlacementChange with valid parameters.
1417 */
1418 HWTEST_F(MotionManagerTest, HandleMechPlacementChange_001, TestSize.Level1)
1419 {
1420 int32_t mechId = 100;
1421 std::shared_ptr<MotionManager> motionMgr =
1422 std::make_shared<MotionManager>(std::make_shared<TransportSendAdapter>(), mechId);
1423 motionMgr->RegisterEventListener();
1424
1425 motionMgr->lastTaskId_ = UINT8_MAX;
1426 motionMgr->HandleMechPlacementChange(true);
1427
1428 EXPECT_NO_FATAL_FAILURE(motionMgr->HandleMechPlacementChange(false));
1429 }
1430 }
1431 }
1432