1 /* 2 * Copyright (c) 2024 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 "gtest/gtest.h" 17 #include "sensor_impl.h" 18 #include "SharedData.h" 19 20 namespace { 21 uint32_t g_pressureVal = 1000; 22 uint32_t g_sumStepVal = 2000; 23 uint8_t g_heartBeatVal = 90; 24 bool g_wearingStateVal = true; 25 26 class SensorModuleImplTest : public ::testing::Test { 27 public: SensorModuleImplTest()28 SensorModuleImplTest() {} ~SensorModuleImplTest()29 ~SensorModuleImplTest() {} 30 protected: SetUpTestCase()31 static void SetUpTestCase() 32 { 33 SharedData<uint32_t>(SharedDataType::PRESSURE_VALUE, g_pressureVal, 0, 999900); // 999900 is max value 34 SharedData<uint32_t>(SharedDataType::SUMSTEP_VALUE, g_sumStepVal, 0, 999999); // 999999 is max value 35 SharedData<uint8_t>(SharedDataType::HEARTBEAT_VALUE, g_heartBeatVal, 0, 255); // 255 is max value 36 SharedData<bool>(SharedDataType::WEARING_STATE, g_wearingStateVal); 37 } 38 }; 39 TEST_F(SensorModuleImplTest,GetBarometerTest)40 TEST_F(SensorModuleImplTest, GetBarometerTest) 41 { 42 uint32_t ret = OHOS::ACELite::SensorImpl::GetBarometer(); 43 EXPECT_EQ(ret, g_pressureVal); 44 } 45 TEST_F(SensorModuleImplTest,GetStepsTest)46 TEST_F(SensorModuleImplTest, GetStepsTest) 47 { 48 uint32_t ret = OHOS::ACELite::SensorImpl::GetSteps(); 49 EXPECT_EQ(ret, g_sumStepVal); 50 } 51 TEST_F(SensorModuleImplTest,GetHeartRateTest)52 TEST_F(SensorModuleImplTest, GetHeartRateTest) 53 { 54 uint32_t ret = OHOS::ACELite::SensorImpl::GetHeartRate(); 55 EXPECT_EQ(ret, g_heartBeatVal); 56 } 57 TEST_F(SensorModuleImplTest,GetOnBodyStateTest)58 TEST_F(SensorModuleImplTest, GetOnBodyStateTest) 59 { 60 bool ret = OHOS::ACELite::SensorImpl::GetOnBodyState(); 61 EXPECT_EQ(ret, g_wearingStateVal); 62 } 63 }