1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "test/core/transport/binder/mock_objects.h"
16
17 #include <memory>
18
19 #include "absl/memory/memory.h"
20
21 namespace grpc_binder {
22
23 using ::testing::Return;
24
MockReadableParcel()25 MockReadableParcel::MockReadableParcel() {
26 ON_CALL(*this, ReadBinder).WillByDefault([](std::unique_ptr<Binder>* binder) {
27 *binder = absl::make_unique<MockBinder>();
28 return absl::OkStatus();
29 });
30 ON_CALL(*this, ReadInt32).WillByDefault(Return(absl::OkStatus()));
31 ON_CALL(*this, ReadByteArray).WillByDefault(Return(absl::OkStatus()));
32 ON_CALL(*this, ReadString).WillByDefault(Return(absl::OkStatus()));
33 }
34
MockWritableParcel()35 MockWritableParcel::MockWritableParcel() {
36 ON_CALL(*this, WriteInt32).WillByDefault(Return(absl::OkStatus()));
37 ON_CALL(*this, WriteBinder).WillByDefault(Return(absl::OkStatus()));
38 ON_CALL(*this, WriteString).WillByDefault(Return(absl::OkStatus()));
39 ON_CALL(*this, WriteByteArray).WillByDefault(Return(absl::OkStatus()));
40 }
41
MockBinder()42 MockBinder::MockBinder() {
43 ON_CALL(*this, PrepareTransaction).WillByDefault(Return(absl::OkStatus()));
44 ON_CALL(*this, Transact).WillByDefault(Return(absl::OkStatus()));
45 ON_CALL(*this, GetWritableParcel).WillByDefault(Return(&mock_input_));
46 ON_CALL(*this, ConstructTxReceiver)
47 .WillByDefault(
48 [this](grpc_core::RefCountedPtr<WireReader> /*wire_reader_ref*/,
49 TransactionReceiver::OnTransactCb cb) {
50 return absl::make_unique<MockTransactionReceiver>(
51 cb, BinderTransportTxCode::SETUP_TRANSPORT, &mock_output_);
52 });
53 }
54
55 } // namespace grpc_binder
56