1 /*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define LOG_TAG "health_hidl_hal_test"
18
19 #include <android/hardware/health/1.0/IHealth.h>
20 #include <android/hardware/health/1.0/types.h>
21 #include <log/log.h>
22 #include <VtsHalHidlTargetTestBase.h>
23
24 using HealthConfig = ::android::hardware::health::V1_0::HealthConfig;
25 using HealthInfo = ::android::hardware::health::V1_0::HealthInfo;
26 using IHealth = ::android::hardware::health::V1_0::IHealth;
27 using Result = ::android::hardware::health::V1_0::Result;
28
29 using ::android::sp;
30
31 class HealthHidlTest : public ::testing::VtsHalHidlTargetTestBase {
32 public:
SetUp()33 virtual void SetUp() override {
34 health = ::testing::VtsHalHidlTargetTestBase::getService<IHealth>();
35 ASSERT_NE(health, nullptr);
36 health->init(config,
37 [&](const auto& halConfigOut) { config = halConfigOut; });
38 }
39
40 sp<IHealth> health;
41 HealthConfig config;
42 };
43
44 /**
45 * Ensure EnergyCounter call returns positive energy counter or NOT_SUPPORTED
46 */
TEST_F(HealthHidlTest,TestEnergyCounter)47 TEST_F(HealthHidlTest, TestEnergyCounter) {
48 Result result;
49 int64_t energy = 0;
50 health->energyCounter([&](Result ret, int64_t energyOut) {
51 result = ret;
52 energy = energyOut;
53 });
54
55 ASSERT_TRUE(result == Result::SUCCESS || result == Result::NOT_SUPPORTED);
56 ASSERT_TRUE(result != Result::SUCCESS || energy > 0);
57 }
58
main(int argc,char ** argv)59 int main(int argc, char **argv) {
60 ::testing::InitGoogleTest(&argc, argv);
61 int status = RUN_ALL_TESTS();
62 ALOGI("Test result = %d", status);
63 return status;
64 }
65