fake_bluetooth_socket.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_QUICK_PAIR_MESSAGE_STREAM_FAKE_BLUETOOTH_SOCKET_H_
  5. #define ASH_QUICK_PAIR_MESSAGE_STREAM_FAKE_BLUETOOTH_SOCKET_H_
  6. #include <memory>
  7. #include "base/callback.h"
  8. #include "device/bluetooth/test/mock_bluetooth_socket.h"
  9. #include "testing/gtest/include/gtest/gtest.h"
  10. namespace ash {
  11. namespace quick_pair {
  12. class FakeBluetoothSocket
  13. : public testing::NiceMock<device::MockBluetoothSocket> {
  14. public:
  15. FakeBluetoothSocket();
  16. // Move-only class
  17. FakeBluetoothSocket(const FakeBluetoothSocket&) = delete;
  18. FakeBluetoothSocket& operator=(const FakeBluetoothSocket&) = delete;
  19. void Receive(int buffer_size,
  20. ReceiveCompletionCallback success_callback,
  21. ReceiveErrorCompletionCallback error_callback) override;
  22. void Disconnect(base::OnceClosure success_callback) override;
  23. void SetIOBufferFromBytes(std::vector<uint8_t> bytes);
  24. void SetErrorReason(device::BluetoothSocket::ErrorReason error);
  25. void TriggerReceiveCallback();
  26. void SetEmptyBuffer();
  27. protected:
  28. ~FakeBluetoothSocket() override;
  29. private:
  30. device::BluetoothSocket::ErrorReason error_ =
  31. device::BluetoothSocket::ErrorReason::kIOPending;
  32. std::vector<uint8_t> bytes_;
  33. ReceiveCompletionCallback success_callback_;
  34. ReceiveErrorCompletionCallback error_callback_;
  35. bool empty_buffer_ = false;
  36. };
  37. } // namespace quick_pair
  38. } // namespace ash
  39. #endif // ASH_QUICK_PAIR_MESSAGE_STREAM_FAKE_BLUETOOTH_SOCKET_H_