1 /*
2 * Copyright (C) 2019 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 #include <android/hardware/tests/extension/vibrator/ICustomVibrator.h>
18 #include <android/hardware/vibrator/IVibrator.h>
19 #include <binder/IInterface.h>
20 #include <binder/IServiceManager.h>
21 #include <gtest/gtest.h>
22
23 using android::checked_interface_cast;
24 using android::IBinder;
25 using android::IInterface;
26 using android::OK;
27 using android::sp;
28 using android::waitForVintfService;
29 using android::hardware::tests::extension::vibrator::Directionality;
30 using android::hardware::tests::extension::vibrator::ICustomVibrator;
31 using android::hardware::vibrator::IVibrator;
32
TEST(Cpp,CallRootMethod)33 TEST(Cpp, CallRootMethod) {
34 sp<IVibrator> vib = waitForVintfService<IVibrator>();
35 ASSERT_NE(nullptr, vib.get());
36 ASSERT_TRUE(vib->off().isOk());
37 }
38
TEST(Cpp,CallExtMethod)39 TEST(Cpp, CallExtMethod) {
40 // normally you would want to cache this
41 sp<IVibrator> vib = waitForVintfService<IVibrator>();
42 ASSERT_NE(nullptr, vib.get());
43
44 // getting the extension
45 sp<IBinder> ext;
46 ASSERT_EQ(OK, IInterface::asBinder(vib)->getExtension(&ext));
47 sp<ICustomVibrator> cvib = checked_interface_cast<ICustomVibrator>(ext);
48 ASSERT_NE(nullptr, cvib.get());
49
50 // calling extension method
51 ASSERT_TRUE(cvib->setDirectionality(Directionality::TRANSVERSE).isOk());
52 }
53