1 /*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifdef DEVICE_STATUS_SENSOR_ENABLE
17 #include <memory>
18 #include <dlfcn.h>
19
20 #include <gtest/gtest.h>
21
22 #include "accesstoken_kit.h"
23
24 #define private public
25 #include "devicestatus_algorithm_manager.h"
26 #include "sensor_agent_type.h"
27 #include "sensor_data_callback.h"
28 #undef private
29 #include "devicestatus_dumper.h"
30 #include "devicestatus_manager.h"
31
32 #undef LOG_TAG
33 #define LOG_TAG "DeviceStatusAlgorithmTest"
34
35 namespace OHOS {
36 namespace Msdp {
37 namespace DeviceStatus {
38 using namespace testing::ext;
39 namespace {
40 std::shared_ptr<AlgoMgr> g_manager { nullptr };
41 #ifdef __aarch64__
42 const std::string DEVICESTATUS_ALGO_LIB_PATH { "/system/lib64/libdevicestatus_algo.z.so" };
43 #else
44 const std::string DEVICESTATUS_ALGO_LIB_PATH { "/system/lib/libdevicestatus_algo.z.so" };
45 #endif
46 } // namespace
47
48 class DeviceStatusAlgorithmTest : public testing::Test {
49 public:
50 static void SetUpTestCase();
51 static void TearDownTestCase();
52 void SetUp();
53 void TearDown();
54 class DeviceStatusMock : public IMsdp::MsdpAlgoCallback {
55 public:
56 DeviceStatusMock() = default;
57 virtual ~DeviceStatusMock() = default;
OnResult(const Data & data)58 void OnResult(const Data& data) {};
59 };
60 int32_t LoadAlgoLibrary(const std::shared_ptr<MsdpAlgoHandle> &algoHandler);
61 int32_t UnloadAlgoLibrary(const std::shared_ptr<MsdpAlgoHandle> &algoHandler);
62 };
63
SetUpTestCase()64 void DeviceStatusAlgorithmTest::SetUpTestCase()
65 {
66 g_manager = std::make_shared<AlgoMgr>();
67 }
68
TearDownTestCase()69 void DeviceStatusAlgorithmTest::TearDownTestCase()
70 {
71 g_manager = nullptr;
72 }
73
SetUp()74 void DeviceStatusAlgorithmTest::SetUp() {}
75
TearDown()76 void DeviceStatusAlgorithmTest::DeviceStatusAlgorithmTest::TearDown() {}
77
LoadAlgoLibrary(const std::shared_ptr<MsdpAlgoHandle> & algoHandler)78 int32_t DeviceStatusAlgorithmTest::LoadAlgoLibrary(const std::shared_ptr<MsdpAlgoHandle> &algoHandler)
79 {
80 FI_HILOGI("Enter");
81 if (algoHandler == nullptr) {
82 FI_HILOGE("algoHandler is nullptr");
83 return RET_ERR;
84 }
85 if (algoHandler->handle != nullptr) {
86 FI_HILOGE("handle already exists");
87 return RET_OK;
88 }
89
90 std::string dlName = DEVICESTATUS_ALGO_LIB_PATH;
91 char libRealPath[PATH_MAX] = { 0 };
92 if (realpath(dlName.c_str(), libRealPath) == nullptr) {
93 FI_HILOGE("Get absolute algoPath is error, errno:%{public}d", errno);
94 return RET_ERR;
95 }
96
97 algoHandler->handle = dlopen(libRealPath, RTLD_LAZY);
98 if (algoHandler->handle == nullptr) {
99 FI_HILOGE("Cannot load library error:%{public}s", dlerror());
100 return RET_ERR;
101 }
102
103 algoHandler->create = reinterpret_cast<IMsdp* (*)()>(dlsym(algoHandler->handle, "Create"));
104 algoHandler->destroy = reinterpret_cast<void *(*)(IMsdp*)>(dlsym(algoHandler->handle, "Destroy"));
105 if (algoHandler->create == nullptr || algoHandler->destroy == nullptr) {
106 FI_HILOGE("%{public}s dlsym create or destroy failed", dlName.c_str());
107 dlclose(algoHandler->handle);
108 algoHandler->Clear();
109 return RET_ERR;
110 }
111 return RET_OK;
112 }
113
UnloadAlgoLibrary(const std::shared_ptr<MsdpAlgoHandle> & algoHandler)114 int32_t DeviceStatusAlgorithmTest::UnloadAlgoLibrary(const std::shared_ptr<MsdpAlgoHandle> &algoHandler)
115 {
116 FI_HILOGI("Enter");
117 if (algoHandler == nullptr) {
118 FI_HILOGE("algoHandler is nullptr");
119 return RET_ERR;
120 }
121 if (algoHandler->handle == nullptr) {
122 FI_HILOGE("handle is nullptr");
123 return RET_ERR;
124 }
125
126 if (algoHandler->pAlgorithm != nullptr) {
127 algoHandler->destroy(algoHandler->pAlgorithm);
128 algoHandler->pAlgorithm = nullptr;
129 }
130 dlclose(algoHandler->handle);
131 algoHandler->Clear();
132 return RET_OK;
133 }
134
135 /**
136 * @tc.name: DeviceStatusAlgoAbsoluteStillTest
137 * @tc.desc: test devicestatus Absolute Still Algorithm
138 * @tc.type: FUNC
139 */
140 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest001, TestSize.Level1)
141 {
142 CALL_TEST_DEBUG;
143 bool result = g_manager->StartSensor(Type::TYPE_ABSOLUTE_STILL);
144 EXPECT_TRUE(result);
145 int32_t ret = g_manager->Enable(Type::TYPE_ABSOLUTE_STILL);
146 ASSERT_EQ(ret, RET_OK);
147 result = g_manager->UnregisterSensor(Type::TYPE_ABSOLUTE_STILL);
148 EXPECT_TRUE(result);
149 ret = g_manager->Disable(Type::TYPE_ABSOLUTE_STILL);
150 ASSERT_EQ(ret, RET_OK);
151 }
152
153 /**
154 * @tc.name: DeviceStatusAlgoHorizontalTest
155 * @tc.desc: test devicestatus AlgoHorizontal Algorithm
156 * @tc.type: FUNC
157 */
158 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest002, TestSize.Level1)
159 {
160 CALL_TEST_DEBUG;
161 bool result = g_manager->StartSensor(Type::TYPE_HORIZONTAL_POSITION);
162 EXPECT_TRUE(result);
163 int32_t ret = g_manager->Enable(Type::TYPE_HORIZONTAL_POSITION);
164 ASSERT_EQ(ret, RET_OK);
165 result = g_manager->UnregisterSensor(Type::TYPE_HORIZONTAL_POSITION);
166 EXPECT_TRUE(result);
167 ret = g_manager->Disable(Type::TYPE_HORIZONTAL_POSITION);
168 ASSERT_EQ(ret, RET_OK);
169 }
170
171 /**
172 * @tc.name: DeviceStatusVeriticalTest
173 * @tc.desc: test devicestatus Veritical Algorithm
174 * @tc.type: FUNC
175 */
176 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest003, TestSize.Level1)
177 {
178 CALL_TEST_DEBUG;
179 bool result = g_manager->StartSensor(Type::TYPE_INVALID);
180 EXPECT_FALSE(result);
181 int32_t ret = g_manager->Enable(Type::TYPE_INVALID);
182 ASSERT_EQ(ret, RET_ERR);
183 result = g_manager->UnregisterSensor(Type::TYPE_INVALID);
184 EXPECT_FALSE(result);
185 ret = g_manager->Disable(Type::TYPE_INVALID);
186 ASSERT_EQ(ret, RET_ERR);
187 }
188
189 /**
190 * @tc.name: DeviceStatusAlgorithmManagerTest
191 * @tc.desc: test devicestatus Algorithm g_manager
192 * @tc.type: FUNC
193 */
194 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest004, TestSize.Level1)
195 {
196 CALL_TEST_DEBUG;
197 std::shared_ptr<AlgoMgr> g_manager = std::make_shared<AlgoMgr>();
198 int32_t ret = g_manager->UnregisterCallback();
199 EXPECT_EQ(ret, ERR_OK);
200 bool result = g_manager->StartSensor(Type::TYPE_LID_OPEN);
201 EXPECT_FALSE(result);
202 ret = g_manager->UnregisterCallback();
203 EXPECT_EQ(ret, ERR_OK);
204 int32_t sensorTypeId = SENSOR_TYPE_ID_ACCELEROMETER;
205 ret = g_manager->CheckSensorTypeId(sensorTypeId);
206 ASSERT_TRUE(ret);
207 g_manager->GetSensorTypeId(Type::TYPE_ABSOLUTE_STILL);
208 g_manager->GetSensorTypeId(Type::TYPE_HORIZONTAL_POSITION);
209 g_manager->GetSensorTypeId(Type::TYPE_VERTICAL_POSITION);
210 }
211
212 /**
213 * @tc.name: DeviceStatusAlgorithmManagerTest
214 * @tc.desc: test Enable Disable
215 * @tc.type: FUNC
216 */
217 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest005, TestSize.Level1)
218 {
219 CALL_TEST_DEBUG;
220 int32_t ret = g_manager->Enable(Type::TYPE_LID_OPEN);
221 ASSERT_TRUE(ret);
222 }
223
224 /**
225 * @tc.name: DeviceStatusAlgorithmManagerTest
226 * @tc.desc: test Enable Disable
227 * @tc.type: FUNC
228 */
229 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest006, TestSize.Level1)
230 {
231 CALL_TEST_DEBUG;
232 bool result = g_manager->StartSensor(Type::TYPE_ABSOLUTE_STILL);
233 EXPECT_TRUE(result);
234 int32_t ret = g_manager->Enable(Type::TYPE_ABSOLUTE_STILL);
235 ASSERT_EQ(ret, RET_OK);
236 AlgoAbsoluteStill still;
237 std::shared_ptr<DeviceStatusMsdpClientImpl> callback = std::make_shared<DeviceStatusMsdpClientImpl>();
238 still.RegisterCallback(callback);
239 ret = g_manager->Disable(Type::TYPE_ABSOLUTE_STILL);
240 ASSERT_EQ(ret, RET_OK);
241 }
242
243 /**
244 * @tc.name: DeviceStatusAlgorithmManagerTest
245 * @tc.desc: test Enable Disable
246 * @tc.type: FUNC
247 */
248 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest007, TestSize.Level1)
249 {
250 CALL_TEST_DEBUG;
251 bool result = g_manager->StartSensor(Type::TYPE_ABSOLUTE_STILL);
252 EXPECT_TRUE(result);
253 int32_t ret = g_manager->Enable(Type::TYPE_HORIZONTAL_POSITION);
254 ASSERT_EQ(ret, RET_OK);
255 AlgoHorizontal horizontal;
256 std::shared_ptr<DeviceStatusMsdpClientImpl> callback = std::make_shared<DeviceStatusMsdpClientImpl>();
257 horizontal.RegisterCallback(callback);
258 ret = g_manager->Disable(Type::TYPE_HORIZONTAL_POSITION);
259 ASSERT_EQ(ret, RET_OK);
260 }
261
262 /**
263 * @tc.name: DeviceStatusAlgorithmManagerTest
264 * @tc.desc: test Enable Disable
265 * @tc.type: FUNC
266 */
267 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest008, TestSize.Level1)
268 {
269 CALL_TEST_DEBUG;
270 bool result = g_manager->StartSensor(Type::TYPE_ABSOLUTE_STILL);
271 EXPECT_TRUE(result);
272 int32_t ret = g_manager->Enable(Type::TYPE_VERTICAL_POSITION);
273 ASSERT_EQ(ret, RET_OK);
274 AlgoVertical vertical;
275 std::shared_ptr<DeviceStatusMsdpClientImpl> callback = std::make_shared<DeviceStatusMsdpClientImpl>();
276 vertical.RegisterCallback(callback);
277 ret = g_manager->Disable(Type::TYPE_VERTICAL_POSITION);
278 ASSERT_EQ(ret, RET_OK);
279 }
280
281 /**
282 * @tc.name: DeviceStatusAlgorithmManagerTest
283 * @tc.desc: test DisableCount
284 * @tc.type: FUNC
285 */
286 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest009, TestSize.Level1)
287 {
288 CALL_TEST_DEBUG;
289 bool result = g_manager->StartSensor(Type::TYPE_ABSOLUTE_STILL);
290 EXPECT_TRUE(result);
291 int32_t ret = g_manager->Enable(Type::TYPE_HORIZONTAL_POSITION);
292 ASSERT_EQ(ret, RET_OK);
293 AlgoVertical vertical;
294 std::shared_ptr<DeviceStatusMsdpClientImpl> callback = std::make_shared<DeviceStatusMsdpClientImpl>();
295 vertical.RegisterCallback(callback);
296 ret = g_manager->Disable(Type::TYPE_HORIZONTAL_POSITION);
297 ASSERT_EQ(ret, RET_OK);
298 ret = g_manager->DisableCount(Type::TYPE_HORIZONTAL_POSITION);
299 ASSERT_EQ(ret, RET_OK);
300 }
301
302 /**
303 * @tc.name: DeviceStatusAlgorithmManagerTest
304 * @tc.desc: test Enable Disable
305 * @tc.type: FUNC
306 */
307 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest010, TestSize.Level1)
308 {
309 CALL_TEST_DEBUG;
310 int32_t typeError = 5;
311 int32_t ret = g_manager->Enable(static_cast<Type>(typeError));
312 ASSERT_EQ(ret, RET_ERR);
313 bool result = g_manager->StartSensor(Type::TYPE_ABSOLUTE_STILL);
314 EXPECT_TRUE(result);
315 ret = g_manager->Enable(static_cast<Type>(typeError));
316 ASSERT_EQ(ret, RET_ERR);
317 }
318
319 /**
320 * @tc.name: DeviceStatusAlgorithmManagerTest
321 * @tc.desc: test StartSensor and UnregisterSensor
322 * @tc.type: FUNC
323 */
324 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest011, TestSize.Level1)
325 {
326 CALL_TEST_DEBUG;
327 bool result = g_manager->StartSensor(Type::TYPE_ABSOLUTE_STILL);
328 EXPECT_TRUE(result);
329 int32_t ret = g_manager->UnregisterSensor(Type::TYPE_ABSOLUTE_STILL);
330 ASSERT_TRUE(ret);
331 }
332
333 /**
334 * @tc.name: DeviceStatusAlgorithmManagerTest
335 * @tc.desc: test StartSensor and UnregisterSensor
336 * @tc.type: FUNC
337 */
338 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest012, TestSize.Level1)
339 {
340 CALL_TEST_DEBUG;
341 bool result = g_manager->StartSensor(Type::TYPE_INVALID);
342 EXPECT_FALSE(result);
343 }
344
345 /**
346 * @tc.name: DeviceStatusAlgorithmManagerTest
347 * @tc.desc: test StartSensor and UnregisterSensor
348 * @tc.type: FUNC
349 */
350 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest013, TestSize.Level1)
351 {
352 CALL_TEST_DEBUG;
353 bool result = g_manager->StartSensor(Type::TYPE_HORIZONTAL_POSITION);
354 EXPECT_TRUE(result);
355 int32_t ret = g_manager->UnregisterSensor(Type::TYPE_HORIZONTAL_POSITION);
356 ASSERT_TRUE(ret);
357 }
358
359 /**
360 * @tc.name: DeviceStatusAlgorithmManagerTest
361 * @tc.desc: test StartSensor and UnregisterSensor
362 * @tc.type: FUNC
363 */
364 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest014, TestSize.Level1)
365 {
366 CALL_TEST_DEBUG;
367 bool result = g_manager->StartSensor(Type::TYPE_VERTICAL_POSITION);
368 EXPECT_TRUE(result);
369 int32_t ret = g_manager->UnregisterSensor(Type::TYPE_VERTICAL_POSITION);
370 ASSERT_TRUE(ret);
371 }
372
373 /**
374 * @tc.name: DeviceStatusAlgorithmManagerTest
375 * @tc.desc: test StartSensor and UnregisterSensor
376 * @tc.type: FUNC
377 */
378 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest015, TestSize.Level1)
379 {
380 CALL_TEST_DEBUG;
381 int32_t typeError = 5;
382 bool result = g_manager->StartSensor(static_cast<Type>(typeError));
383 EXPECT_FALSE(result);
384 }
385
386 /**
387 * @tc.name: DeviceStatusAlgorithmManagerTest
388 * @tc.desc: test CheckSensorTypeId001
389 * @tc.type: FUNC
390 */
391 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest016, TestSize.Level1)
392 {
393 CALL_TEST_DEBUG;
394 bool result = g_manager->StartSensor(Type::TYPE_INVALID);
395 EXPECT_FALSE(result);
396 g_manager->GetSensorTypeId(Type::TYPE_INVALID);
397 int32_t sensorTypeId = SENSOR_TYPE_ID_ACCELEROMETER;
398 int32_t ret = g_manager->CheckSensorTypeId(sensorTypeId);
399 ASSERT_TRUE(ret);
400 }
401
402 /**
403 * @tc.name: DeviceStatusAlgorithmManagerTest
404 * @tc.desc: test CheckSensorTypeId002
405 * @tc.type: FUNC
406 */
407 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest017, TestSize.Level1)
408 {
409 CALL_TEST_DEBUG;
410 bool result = g_manager->StartSensor(Type::TYPE_ABSOLUTE_STILL);
411 EXPECT_TRUE(result);
412 g_manager->GetSensorTypeId(Type::TYPE_ABSOLUTE_STILL);
413 int32_t sensorTypeId = SENSOR_TYPE_ID_NONE;
414 int32_t ret = g_manager->CheckSensorTypeId(sensorTypeId);
415 ASSERT_TRUE(ret);
416 ret = g_manager->UnregisterSensor(Type::TYPE_ABSOLUTE_STILL);
417 ASSERT_TRUE(ret);
418 }
419
420 /**
421 * @tc.name: DeviceStatusAlgorithmManagerTest
422 * @tc.desc: test CheckSensorTypeId003
423 * @tc.type: FUNC
424 */
425 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest018, TestSize.Level1)
426 {
427 CALL_TEST_DEBUG;
428 bool state = g_manager->StartSensor(Type::TYPE_ABSOLUTE_STILL);
429 EXPECT_TRUE(state);
430 g_manager->GetSensorTypeId(Type::TYPE_ABSOLUTE_STILL);
431 int32_t sensorTypeId = SENSOR_TYPE_ID_MAX;
432 int32_t ret = g_manager->CheckSensorTypeId(sensorTypeId);
433 EXPECT_FALSE(ret);
434 ret = g_manager->UnregisterSensor(Type::TYPE_ABSOLUTE_STILL);
435 ASSERT_TRUE(ret);
436 }
437
438 /**
439 * @tc.name: DeviceStatusAlgorithmManagerTest
440 * @tc.desc: test CheckSensorTypeId004
441 * @tc.type: FUNC
442 */
443 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest019, TestSize.Level1)
444 {
445 CALL_TEST_DEBUG;
446 bool result = g_manager->StartSensor(Type::TYPE_ABSOLUTE_STILL);
447 EXPECT_TRUE(result);
448 g_manager->GetSensorTypeId(Type::TYPE_ABSOLUTE_STILL);
449 int32_t sensorTypeId = SENSOR_TYPE_ID_MAX;
450 int32_t ret = g_manager->CheckSensorTypeId(sensorTypeId);
451 EXPECT_FALSE(ret);
452 ret = g_manager->UnregisterSensor(Type::TYPE_ABSOLUTE_STILL);
453 ASSERT_TRUE(ret);
454 }
455
456 /**
457 * @tc.name: DeviceStatusAlgorithmManagerTest
458 * @tc.desc: test CheckSensorTypeId005
459 * @tc.type: FUNC
460 */
461 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest020, TestSize.Level1)
462 {
463 CALL_TEST_DEBUG;
464 bool result = g_manager->StartSensor(Type::TYPE_ABSOLUTE_STILL);
465 EXPECT_TRUE(result);
466 g_manager->GetSensorTypeId(Type::TYPE_ABSOLUTE_STILL);
467 int32_t typeError = -100;
468 int32_t ret = g_manager->CheckSensorTypeId(static_cast<SensorTypeId>(typeError));
469 EXPECT_FALSE(ret);
470 ret = g_manager->UnregisterSensor(Type::TYPE_ABSOLUTE_STILL);
471 ASSERT_TRUE(ret);
472 }
473
474 /**
475 * @tc.name: DeviceStatusAlgorithmManagerTest
476 * @tc.desc: test GetSensorTypeId001
477 * @tc.type: FUNC
478 */
479 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest021, TestSize.Level1)
480 {
481 CALL_TEST_DEBUG;
482 bool result = g_manager->StartSensor(Type::TYPE_HORIZONTAL_POSITION);
483 EXPECT_TRUE(result);
484 g_manager->GetSensorTypeId(Type::TYPE_HORIZONTAL_POSITION);
485 int32_t ret = g_manager->UnregisterSensor(Type::TYPE_HORIZONTAL_POSITION);
486 ASSERT_TRUE(ret);
487 }
488
489 /**
490 * @tc.name: DeviceStatusAlgorithmManagerTest
491 * @tc.desc: test GetSensorTypeId002
492 * @tc.type: FUNC
493 */
494 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest022, TestSize.Level1)
495 {
496 CALL_TEST_DEBUG;
497 bool result = g_manager->StartSensor(Type::TYPE_VERTICAL_POSITION);
498 EXPECT_TRUE(result);
499 g_manager->GetSensorTypeId(Type::TYPE_VERTICAL_POSITION);
500 int32_t ret = g_manager->UnregisterSensor(Type::TYPE_VERTICAL_POSITION);
501 ASSERT_TRUE(ret);
502 }
503
504 /**
505 * @tc.name: DeviceStatusAlgorithmManagerTest
506 * @tc.desc: test GetSensorTypeId003
507 * @tc.type: FUNC
508 */
509 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest023, TestSize.Level1)
510 {
511 CALL_TEST_DEBUG;
512 bool result = g_manager->StartSensor(Type::TYPE_VERTICAL_POSITION);
513 EXPECT_TRUE(result);
514 g_manager->GetSensorTypeId(Type::TYPE_MAX);
515 int32_t ret = g_manager->UnregisterSensor(Type::TYPE_VERTICAL_POSITION);
516 ASSERT_TRUE(ret);
517 }
518
519 /**
520 * @tc.name: DeviceStatusAlgorithmManagerTest
521 * @tc.desc: test Enable
522 * @tc.type: FUNC
523 */
524 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest024, TestSize.Level1)
525 {
526 CALL_TEST_DEBUG;
527 int32_t ret = g_manager->Enable(Type::TYPE_MAX);
528 EXPECT_EQ(ret, RET_ERR);
529 }
530
531 /**
532 * @tc.name: DeviceStatusAlgorithmManagerTest
533 * @tc.desc: test Disable
534 * @tc.type: FUNC
535 */
536 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest025, TestSize.Level1)
537 {
538 CALL_TEST_DEBUG;
539 g_manager->callAlgoNums_[Type::TYPE_ABSOLUTE_STILL] = 2;
540 int32_t ret = g_manager->Disable(Type::TYPE_ABSOLUTE_STILL);
541 EXPECT_EQ(ret, RET_ERR);
542 }
543
544 /**
545 * @tc.name: DeviceStatusAlgorithmManagerTest
546 * @tc.desc: test Disable
547 * @tc.type: FUNC
548 */
549 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest026, TestSize.Level1)
550 {
551 CALL_TEST_DEBUG;
552 int32_t ret = g_manager->Enable(Type::TYPE_MAX);
553 ASSERT_TRUE(ret);
554 g_manager->callAlgoNums_[Type::TYPE_MAX] = 1;
555 ret = g_manager->Disable(Type::TYPE_MAX);
556 EXPECT_EQ(ret, RET_OK);
557 }
558
559 /**
560 * @tc.name: DeviceStatusAlgorithmManagerTest
561 * @tc.desc: test UnregisterSensor
562 * @tc.type: FUNC
563 */
564 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest027, TestSize.Level1)
565 {
566 CALL_TEST_DEBUG;
567 int32_t ret = g_manager->UnregisterSensor(Type::TYPE_MAX);
568 EXPECT_EQ(ret, false);
569 }
570
571 /**
572 * @tc.name: DeviceStatusAlgorithmManagerTest
573 * @tc.desc: test UnregisterSensor
574 * @tc.type: FUNC
575 */
576 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest028, TestSize.Level1)
577 {
578 CALL_TEST_DEBUG;
579 SENSOR_DATA_CB.user_.callback = nullptr;
580 bool result = g_manager->UnregisterSensor(Type::TYPE_ABSOLUTE_STILL);
581 EXPECT_FALSE(result);
582 }
583
584 /**
585 * @tc.name: DeviceStatusAlgorithmManagerTest
586 * @tc.desc: test Enable
587 * @tc.type: FUNC
588 */
589 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest029, TestSize.Level1)
590 {
591 CALL_TEST_DEBUG;
592 std::shared_ptr<MsdpAlgoHandle> algo = std::make_shared<MsdpAlgoHandle>();
593 int32_t ret = LoadAlgoLibrary(algo);
594 ASSERT_EQ(ret, RET_OK);
595 ASSERT_NE(algo->handle, nullptr);
596 algo->pAlgorithm = algo->create();
597
598 ret = algo->pAlgorithm->Enable(Type::TYPE_LID_OPEN);
599 ASSERT_TRUE(ret);
600
601 ret = UnloadAlgoLibrary(algo);
602 ASSERT_EQ(ret, RET_OK);
603 }
604
605 /**
606 * @tc.name: DeviceStatusAlgorithmManagerTest
607 * @tc.desc: test RegisterCallback
608 * @tc.type: FUNC
609 */
610 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest030, TestSize.Level1)
611 {
612 CALL_TEST_DEBUG;
613 int32_t ret = g_manager->Enable(Type::TYPE_ABSOLUTE_STILL);
614 EXPECT_EQ(ret, RET_OK);
615
616 std::shared_ptr<DeviceStatusMock> callback = std::make_shared<DeviceStatusMock>();
617 ret = g_manager->RegisterCallback(callback);
618 EXPECT_EQ(ret, RET_OK);
619
620 ret = g_manager->Disable(Type::TYPE_ABSOLUTE_STILL);
621 EXPECT_EQ(ret, RET_OK);
622 }
623
624 /**
625 * @tc.name: DeviceStatusAlgorithmManagerTest
626 * @tc.desc: test RegisterCallback
627 * @tc.type: FUNC
628 */
629 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest031, TestSize.Level1)
630 {
631 CALL_TEST_DEBUG;
632 int32_t ret = g_manager->Enable(Type::TYPE_HORIZONTAL_POSITION);
633 EXPECT_EQ(ret, RET_OK);
634
635 std::shared_ptr<DeviceStatusMock> callback = std::make_shared<DeviceStatusMock>();
636 ret = g_manager->RegisterCallback(callback);
637 EXPECT_EQ(ret, RET_OK);
638
639 ret = g_manager->Disable(Type::TYPE_HORIZONTAL_POSITION);
640 EXPECT_EQ(ret, RET_OK);
641 }
642
643 /**
644 * @tc.name: DeviceStatusAlgorithmManagerTest
645 * @tc.desc: test RegisterCallback
646 * @tc.type: FUNC
647 */
648 HWTEST_F(DeviceStatusAlgorithmTest, DeviceStatusAlgorithmTest032, TestSize.Level1)
649 {
650 CALL_TEST_DEBUG;
651 int32_t ret = g_manager->Enable(Type::TYPE_VERTICAL_POSITION);
652 EXPECT_EQ(ret, RET_OK);
653
654 std::shared_ptr<DeviceStatusMock> callback = std::make_shared<DeviceStatusMock>();
655 ret = g_manager->RegisterCallback(callback);
656 EXPECT_EQ(ret, RET_OK);
657
658 ret = g_manager->Disable(Type::TYPE_VERTICAL_POSITION);
659 EXPECT_EQ(ret, RET_OK);
660 }
661 } // namespace DeviceStatus
662 } // namespace Msdp
663 } // namespace OHOS
664 #endif // DEVICE_STATUS_SENSOR_ENABLE
665