mock_data_channel.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 2016 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef PC_TEST_MOCK_DATA_CHANNEL_H_
  11. #define PC_TEST_MOCK_DATA_CHANNEL_H_
  12. #include <string>
  13. #include "pc/data_channel.h"
  14. #include "test/gmock.h"
  15. namespace webrtc {
  16. class MockDataChannel : public rtc::RefCountedObject<DataChannel> {
  17. public:
  18. MockDataChannel(int id, DataState state)
  19. : MockDataChannel(id, "MockDataChannel", state, "udp", 0, 0, 0, 0) {}
  20. MockDataChannel(
  21. int id,
  22. const std::string& label,
  23. DataState state,
  24. const std::string& protocol,
  25. uint32_t messages_sent,
  26. uint64_t bytes_sent,
  27. uint32_t messages_received,
  28. uint64_t bytes_received,
  29. const InternalDataChannelInit& config = InternalDataChannelInit(),
  30. rtc::Thread* signaling_thread = rtc::Thread::Current(),
  31. rtc::Thread* network_thread = rtc::Thread::Current())
  32. : rtc::RefCountedObject<DataChannel>(config,
  33. nullptr,
  34. cricket::DCT_NONE,
  35. label,
  36. signaling_thread,
  37. network_thread) {
  38. EXPECT_CALL(*this, id()).WillRepeatedly(::testing::Return(id));
  39. EXPECT_CALL(*this, state()).WillRepeatedly(::testing::Return(state));
  40. EXPECT_CALL(*this, protocol()).WillRepeatedly(::testing::Return(protocol));
  41. EXPECT_CALL(*this, messages_sent())
  42. .WillRepeatedly(::testing::Return(messages_sent));
  43. EXPECT_CALL(*this, bytes_sent())
  44. .WillRepeatedly(::testing::Return(bytes_sent));
  45. EXPECT_CALL(*this, messages_received())
  46. .WillRepeatedly(::testing::Return(messages_received));
  47. EXPECT_CALL(*this, bytes_received())
  48. .WillRepeatedly(::testing::Return(bytes_received));
  49. }
  50. MOCK_METHOD(int, id, (), (const, override));
  51. MOCK_METHOD(DataState, state, (), (const, override));
  52. MOCK_METHOD(std::string, protocol, (), (const, override));
  53. MOCK_METHOD(uint32_t, messages_sent, (), (const, override));
  54. MOCK_METHOD(uint64_t, bytes_sent, (), (const, override));
  55. MOCK_METHOD(uint32_t, messages_received, (), (const, override));
  56. MOCK_METHOD(uint64_t, bytes_received, (), (const, override));
  57. };
  58. } // namespace webrtc
  59. #endif // PC_TEST_MOCK_DATA_CHANNEL_H_