Home | History | Annotate | Download | only in functional
      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 "vibrator_hidl_hal_test"
     18 
     19 #include <VtsHalHidlTargetTestBase.h>
     20 #include <android-base/logging.h>
     21 #include <android/hardware/vibrator/1.1/IVibrator.h>
     22 #include <android/hardware/vibrator/1.1/types.h>
     23 #include <unistd.h>
     24 
     25 using ::android::hardware::vibrator::V1_0::Effect;
     26 using ::android::hardware::vibrator::V1_0::EffectStrength;
     27 using ::android::hardware::vibrator::V1_0::Status;
     28 using ::android::hardware::vibrator::V1_1::Effect_1_1;
     29 using ::android::hardware::vibrator::V1_1::IVibrator;
     30 using ::android::hardware::Return;
     31 using ::android::hardware::Void;
     32 using ::android::sp;
     33 
     34 // The main test class for VIBRATOR HIDL HAL 1.1.
     35 class VibratorHidlTest_1_1 : public ::testing::VtsHalHidlTargetTestBase {
     36    public:
     37     virtual void SetUp() override {
     38         vibrator = ::testing::VtsHalHidlTargetTestBase::getService<IVibrator>();
     39         ASSERT_NE(vibrator, nullptr);
     40     }
     41 
     42     virtual void TearDown() override {}
     43 
     44     sp<IVibrator> vibrator;
     45 };
     46 
     47 static void validatePerformEffect(Status status, uint32_t lengthMs) {
     48     ASSERT_TRUE(status == Status::OK || status == Status::UNSUPPORTED_OPERATION);
     49     if (status == Status::OK) {
     50         ASSERT_GT(lengthMs, static_cast<uint32_t>(0))
     51             << "Effects that return OK must return a non-zero duration";
     52     } else {
     53         ASSERT_EQ(lengthMs, static_cast<uint32_t>(0))
     54             << "Effects that return UNSUPPORTED_OPERATION must have a duration of zero";
     55     }
     56 }
     57 
     58 TEST_F(VibratorHidlTest_1_1, PerformEffect_1_1) {
     59     vibrator->perform_1_1(Effect_1_1::CLICK, EffectStrength::MEDIUM, validatePerformEffect);
     60     vibrator->perform_1_1(Effect_1_1::TICK, EffectStrength::STRONG, validatePerformEffect);
     61 }
     62 
     63 int main(int argc, char** argv) {
     64     ::testing::InitGoogleTest(&argc, argv);
     65     int status = RUN_ALL_TESTS();
     66     LOG(INFO) << "Test result = " << status;
     67     return status;
     68 }
     69