1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #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 #include "devicestatus_define.h"
24 #include "devicestatus_algorithm_manager.h"
25 #include "sensor_agent_type.h"
26 #include "sensor_data_callback.h"
27 #include "stationary_data.h"
28 #include "devicestatus_dumper.h"
29 #include "devicestatus_manager.h"
30
31 #undef LOG_TAG
32 #define LOG_TAG "DeviceStatusAlgoMgrTest"
33
34 namespace OHOS {
35 namespace Msdp {
36 namespace DeviceStatus {
37 using namespace testing::ext;
38 namespace {
39 std::shared_ptr<AlgoMgr> g_algoManager { nullptr };
40 } // namespace
41
42 class DeviceStatusAlgoMgrTest : public testing::Test {
43 public:
44 static void SetUpTestCase();
45 static void TearDownTestCase();
46 void SetUp();
47 void TearDown();
48 };
49
SetUpTestCase()50 void DeviceStatusAlgoMgrTest::SetUpTestCase()
51 {
52 g_algoManager = std::make_shared<AlgoMgr>();
53 }
54
TearDownTestCase()55 void DeviceStatusAlgoMgrTest::TearDownTestCase()
56 {
57 g_algoManager = nullptr;
58 }
59
SetUp()60 void DeviceStatusAlgoMgrTest::SetUp() {}
61
TearDown()62 void DeviceStatusAlgoMgrTest::DeviceStatusAlgoMgrTest::TearDown() {}
63
64
65 /**
66 * @tc.name: DeviceStatusAlgoMgrTest001
67 * @tc.desc: test GetSensorTypeId
68 * @tc.type: FUNC
69 */
70 HWTEST_F(DeviceStatusAlgoMgrTest, DeviceStatusAlgoMgrTest001, TestSize.Level1)
71 {
72 CALL_TEST_DEBUG;
73 Type type = Type::TYPE_HORIZONTAL_POSITION;
74 int32_t result = g_algoManager->GetSensorTypeId(type);
75 EXPECT_TRUE(result);
76 type = (Type)-1;
77 result = g_algoManager->GetSensorTypeId(type);
78 EXPECT_TRUE(result == RET_ERR);
79 }
80
81 /**
82 * @tc.name: DeviceStatusAlgoMgrTest002
83 * @tc.desc: test DisableCount
84 * @tc.type: FUNC
85 */
86 HWTEST_F(DeviceStatusAlgoMgrTest, DeviceStatusAlgoMgrTest002, TestSize.Level1)
87 {
88 CALL_TEST_DEBUG;
89 Type type = (Type)1;
90 bool result = g_algoManager->DisableCount(type);
91 EXPECT_TRUE(result == RET_OK);
92 }
93
94 /**
95 * @tc.name: DeviceStatusAlgoMgrTest003
96 * @tc.desc: test UnregisterCallback
97 * @tc.type: FUNC
98 */
99 HWTEST_F(DeviceStatusAlgoMgrTest, DeviceStatusAlgoMgrTest003, TestSize.Level1)
100 {
101 CALL_TEST_DEBUG;
102 bool result = g_algoManager->UnregisterCallback();
103 EXPECT_TRUE(result == RET_OK);
104 }
105
106 /**
107 * @tc.name: DeviceStatusAlgoMgrTest004
108 * @tc.desc: test CheckSensorTypeId
109 * @tc.type: FUNC
110 */
111 HWTEST_F(DeviceStatusAlgoMgrTest, DeviceStatusAlgoMgrTest004, TestSize.Level1)
112 {
113 CALL_TEST_DEBUG;
114 int32_t sensorTypeId = SENSOR_TYPE_ID_MAX;
115 int32_t ret = g_algoManager->CheckSensorTypeId(sensorTypeId);
116 EXPECT_FALSE(ret);
117 }
118
119 /**
120 * @tc.name: DeviceStatusAlgoMgrTest005
121 * @tc.desc: test CheckSensorTypeId
122 * @tc.type: FUNC
123 */
124 HWTEST_F(DeviceStatusAlgoMgrTest, DeviceStatusAlgoMgrTest005, TestSize.Level1)
125 {
126 CALL_TEST_DEBUG;
127 int32_t sensorTypeId = SENSOR_TYPE_ID_MAX;
128 int32_t ret = g_algoManager->CheckSensorTypeId(sensorTypeId);
129 EXPECT_FALSE(ret);
130 }
131
132 /**
133 * @tc.name: DeviceStatusAlgoMgrTest006
134 * @tc.desc: test Enable
135 * @tc.type: FUNC
136 */
137 HWTEST_F(DeviceStatusAlgoMgrTest, DeviceStatusAlgoMgrTest006, TestSize.Level1)
138 {
139 CALL_TEST_DEBUG;
140 Type type = Type::TYPE_VERTICAL_POSITION;
141 int32_t ret = g_algoManager->Enable(type);
142 EXPECT_FALSE(ret);
143 }
144 } // namespace DeviceStatus
145 } // namespace Msdp
146 } // namespace OHOS
147 #endif // DEVICE_STATUS_SENSOR_ENABLE
148