mock_objects.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include "test/core/transport/binder/mock_objects.h"
  15. #include <memory>
  16. #include "absl/memory/memory.h"
  17. namespace grpc_binder {
  18. using ::testing::Return;
  19. MockReadableParcel::MockReadableParcel() {
  20. ON_CALL(*this, ReadBinder).WillByDefault([](std::unique_ptr<Binder>* binder) {
  21. *binder = absl::make_unique<MockBinder>();
  22. return absl::OkStatus();
  23. });
  24. ON_CALL(*this, ReadInt32).WillByDefault(Return(absl::OkStatus()));
  25. ON_CALL(*this, ReadByteArray).WillByDefault(Return(absl::OkStatus()));
  26. ON_CALL(*this, ReadString).WillByDefault(Return(absl::OkStatus()));
  27. }
  28. MockWritableParcel::MockWritableParcel() {
  29. ON_CALL(*this, WriteInt32).WillByDefault(Return(absl::OkStatus()));
  30. ON_CALL(*this, WriteBinder).WillByDefault(Return(absl::OkStatus()));
  31. ON_CALL(*this, WriteString).WillByDefault(Return(absl::OkStatus()));
  32. ON_CALL(*this, WriteByteArray).WillByDefault(Return(absl::OkStatus()));
  33. }
  34. MockBinder::MockBinder() {
  35. ON_CALL(*this, PrepareTransaction).WillByDefault(Return(absl::OkStatus()));
  36. ON_CALL(*this, Transact).WillByDefault(Return(absl::OkStatus()));
  37. ON_CALL(*this, GetWritableParcel).WillByDefault(Return(&mock_input_));
  38. ON_CALL(*this, ConstructTxReceiver)
  39. .WillByDefault(
  40. [this](grpc_core::RefCountedPtr<WireReader> /*wire_reader_ref*/,
  41. TransactionReceiver::OnTransactCb cb) {
  42. return absl::make_unique<MockTransactionReceiver>(
  43. cb, BinderTransportTxCode::SETUP_TRANSPORT, &mock_output_);
  44. });
  45. }
  46. } // namespace grpc_binder