• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Chipsea Technologies (Shenzhen) Corp., 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 <gtest/gtest.h>
17 #include <thread>
18 
19 #include "medical_native_impl.h"
20 #include "medical_errors.h"
21 #include "medical_log_domain.h"
22 
23 namespace OHOS {
24 namespace Sensors {
25 using namespace testing::ext;
26 using namespace OHOS::HiviewDFX;
27 
28 namespace {
29 constexpr HiLogLabel LABEL = { LOG_CORE, MedicalSensorLogDomain::MEDICAL_SENSOR_TEST, "MedicalNativeTest" };
30 }  // namespace
31 
32 class MedicalNativeTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp();
37     void TearDown();
38 };
39 
SetUpTestCase()40 void MedicalNativeTest::SetUpTestCase()
41 {}
42 
TearDownTestCase()43 void MedicalNativeTest::TearDownTestCase()
44 {}
45 
SetUp()46 void MedicalNativeTest::SetUp()
47 {}
48 
TearDown()49 void MedicalNativeTest::TearDown()
50 {}
51 
AfeDataCallbackImpl(SensorEvent * event)52 void AfeDataCallbackImpl(SensorEvent *event)
53 {
54     if (event == nullptr) {
55         HiLog::Error(LABEL, "AfeDataCallbackImpl event is null");
56         return;
57     }
58     uint32_t *sensorData = (uint32_t *)(event[0].data);
59     HiLog::Info(LABEL, "AfeDataCallbackImpl sensorTypeId: %{public}d, dataLen: %{public}d, data[0]: %{public}d\n",
60         event[0].sensorTypeId, event[0].dataLen, *(sensorData));
61 }
62 
63 /*
64  * @tc.name: AfeNativeApiTest_001
65  * @tc.desc: afe native api test
66  * @tc.type: FUNC
67  * @tc.author: wuzhihui
68  */
69 HWTEST_F(MedicalNativeTest, AfeNativeApiTest_001, TestSize.Level1)
70 {
71     HiLog::Info(LABEL, "%{public}s begin", __func__);
72 
73     int32_t sensorTypeId = 0;
74     MedicalSensorUser user;
75 
76     user.callback = AfeDataCallbackImpl;
77 
78     int32_t ret = SubscribeSensor(sensorTypeId, &user);
79     ASSERT_EQ(ret, 0);
80 
81     ret = SetBatch(sensorTypeId, &user, 100000000, 100000000);
82     ASSERT_EQ(ret, 0);
83 
84     ret = ActivateSensor(sensorTypeId, &user);
85     ASSERT_EQ(ret, 0);
86 
87     std::this_thread::sleep_for(std::chrono::milliseconds(10000));
88     ASSERT_EQ(ret, 0);
89 
90     ret = DeactivateSensor(sensorTypeId, &user);
91     ASSERT_EQ(ret, 0);
92 
93     ret = UnsubscribeSensor(sensorTypeId, &user);
94     ASSERT_EQ(ret, 0);
95 }
96 }  // namespace Sensors
97 }  // namespace OHOS
98