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 #include "aidl_test_client.h"
17 #include "gmock/gmock.h"
18 
19 using android::binder::Status;
20 
21 using android::aidl::tests::ITestService;
22 using android::aidl::tests::ITestServiceDefault;
23 
24 using testing::Eq;
25 
26 static constexpr int32_t kExpectedArgValue = 100;
27 static constexpr int32_t kExpectedReturnValue = 200;
28 
29 static int numCalled = 0;
30 static int32_t gotArgument = 0;
31 
32 struct Def : public ITestServiceDefault {
UnimplementedMethodDef33   Status UnimplementedMethod(int32_t arg, int32_t* _aidl_return) override {
34     numCalled++;
35     gotArgument = arg;
36     *_aidl_return = kExpectedReturnValue;
37     return android::binder::Status::ok();
38   }
39 };
40 
TEST_F(AidlTest,defaultImpl)41 TEST_F(AidlTest, defaultImpl) {
42   std::unique_ptr<ITestService> defImpl = std::make_unique<Def>();
43   auto ret = ITestService::setDefaultImpl(std::move(defImpl));
44   ASSERT_TRUE(ret);
45 
46   int32_t returned_value;
47   auto status = service->UnimplementedMethod(kExpectedArgValue, &returned_value);
48   ASSERT_TRUE(status.isOk());
49   ASSERT_THAT(numCalled, Eq(1));
50   ASSERT_THAT(gotArgument, Eq(kExpectedArgValue));
51   ASSERT_THAT(returned_value, Eq(kExpectedReturnValue));
52 }
53