test_turn_customizer.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2017 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 P2P_BASE_TEST_TURN_CUSTOMIZER_H_
  11. #define P2P_BASE_TEST_TURN_CUSTOMIZER_H_
  12. #include <memory>
  13. #include "api/turn_customizer.h"
  14. #include "rtc_base/gunit.h"
  15. namespace cricket {
  16. class TestTurnCustomizer : public webrtc::TurnCustomizer {
  17. public:
  18. TestTurnCustomizer() {}
  19. virtual ~TestTurnCustomizer() {}
  20. enum TestTurnAttributeExtensions {
  21. // Test only attribute
  22. STUN_ATTR_COUNTER = 0xFF02 // Number
  23. };
  24. void MaybeModifyOutgoingStunMessage(cricket::PortInterface* port,
  25. cricket::StunMessage* message) override {
  26. modify_cnt_++;
  27. ASSERT_NE(0, message->type());
  28. if (add_counter_) {
  29. message->AddAttribute(std::make_unique<cricket::StunUInt32Attribute>(
  30. STUN_ATTR_COUNTER, modify_cnt_));
  31. }
  32. return;
  33. }
  34. bool AllowChannelData(cricket::PortInterface* port,
  35. const void* data,
  36. size_t size,
  37. bool payload) override {
  38. allow_channel_data_cnt_++;
  39. return allow_channel_data_;
  40. }
  41. bool add_counter_ = false;
  42. bool allow_channel_data_ = true;
  43. unsigned int modify_cnt_ = 0;
  44. unsigned int allow_channel_data_cnt_ = 0;
  45. };
  46. } // namespace cricket
  47. #endif // P2P_BASE_TEST_TURN_CUSTOMIZER_H_