1 /* 2 * Copyright (C) 2018 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 "aidl_test_client_defaultimpl.h" 18 19 #include <iostream> 20 21 namespace android { 22 namespace aidl { 23 namespace tests { 24 namespace client { 25 26 static const int32_t kExpectedArgValue = 100; 27 static const int32_t kExpectedReturnValue = 200; 28 ConfirmDefaultImpl(const sp<ITestService> & s)29bool ConfirmDefaultImpl(const sp<ITestService>& s) { 30 class Def : public android::aidl::tests::ITestServiceDefault { 31 android::binder::Status UnimplementedMethod(int32_t arg, int32_t* _aidl_return) override { 32 if (arg != kExpectedArgValue) { 33 std::cerr << "Argument to UnimplementedMethod is expected to be " << kExpectedArgValue 34 << ", " 35 << "but got " << arg << std::endl; 36 return android::binder::Status::fromStatusT(android::FAILED_TRANSACTION); 37 } 38 *_aidl_return = kExpectedReturnValue; 39 return android::binder::Status::ok(); 40 } 41 }; 42 43 bool success = android::aidl::tests::ITestService::setDefaultImpl(std::make_unique<Def>()); 44 if (!success) { 45 std::cerr << "Failed to set default impl for ITestService" << std::endl; 46 return false; 47 } 48 49 int32_t ret; 50 android::binder::Status status = s->UnimplementedMethod(kExpectedArgValue, &ret); 51 if (!status.isOk()) { 52 std::cerr << "Call to UnimplementedMethod() has failed. status=" << status.toString8() 53 << std::endl; 54 return false; 55 } 56 57 if (ret != kExpectedReturnValue) { 58 std::cerr << "Return value from UnimplementedMethod is expected to be " << kExpectedReturnValue 59 << ", " 60 << "but got " << ret << std::endl; 61 return false; 62 } 63 64 return true; 65 } 66 67 } // namespace client 68 } // namespace tests 69 } // namespace aidl 70 } // namespace android 71