• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cmath>
17 #include <cstdio>
18 #include <unistd.h>
19 #include <gtest/gtest.h>
20 #include <securec.h>
21 #include "hdf_base.h"
22 #include "osal_time.h"
23 #include "v3_0/isensor_interface.h"
24 #include "sensor_type.h"
25 #include "sensor_plug_callback_impl.h"
26 using namespace OHOS::HDI::Sensor::V3_0;
27 using namespace testing::ext;
28 
29 namespace {
30     sptr<ISensorInterface>  g_sensorInterface = nullptr;
31     sptr<SensorPlugCallbackImpl> g_sensorPlugCallback = new SensorPlugCallbackImpl();
32 }
33 
34 class HatsHdfSensorPlugCallbackTest : public testing::Test {
35 public:
36     static void SetUpTestCase();
37     static void TearDownTestCase();
38     void SetUp();
39     void TearDown();
40 };
41 
SetUpTestCase()42 void HatsHdfSensorPlugCallbackTest::SetUpTestCase()
43 {
44     g_sensorInterface = ISensorInterface::Get();
45 }
46 
TearDownTestCase()47 void HatsHdfSensorPlugCallbackTest::TearDownTestCase()
48 {
49 }
50 
SetUp()51 void HatsHdfSensorPlugCallbackTest::SetUp()
52 {
53     if (g_sensorInterface == nullptr) {
54         printf("Sensor list is empty");
55         GTEST_SKIP() << "Device not exist" << std::endl;
56         return;
57     }
58 }
59 
TearDown()60 void HatsHdfSensorPlugCallbackTest::TearDown()
61 {
62 }
63 
64 /**
65   * @tc.name: SUB_Driver_Sensor_HdiSensor_0100
66   * @tc.number : SUB_Driver_Sensor_HdiSensor_0100
67   * @tc.desc: Get a client and check whether the client is empty.
68   * @tc.type: FUNC
69   */
70 HWTEST_F(HatsHdfSensorPlugCallbackTest, SUB_Driver_Sensor_HdiSensor_0100, TestSize.Level1)
71 {
72     ASSERT_NE(nullptr, g_sensorInterface);
73 }
74 
75 /**
76  * @tc.name: testHdiSensorRegSensorPlugCallBack
77  * @tc.number: testHdiSensorRegSensorPlugCallBack
78  * @tc.desc: Read event data for the specified sensor.
79  * @tc.type: FUNC
80  */
81 HWTEST_F(HatsHdfSensorPlugCallbackTest, testHdiSensorRegSensorPlugCallBack, TestSize.Level1)
82 {
83     if (g_sensorInterface == nullptr) {
84         ASSERT_NE(nullptr, g_sensorInterface);
85         return;
86     }
87     int32_t ret = g_sensorInterface->RegSensorPlugCallBack(g_sensorPlugCallback);
88     EXPECT_EQ(0, ret);
89     printf("RegSensorPlugCallBack\n");
90 
91     OsalMSleep(3000);
92 
93     ret = g_sensorInterface->UnRegSensorPlugCallBack(g_sensorPlugCallback);
94     EXPECT_EQ(0, ret);
95     printf("RegSensorPlugCallBack\n");
96 }