Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/api/sctputils.h" | 11 #include "webrtc/api/sctputils.h" |
| 12 #include "webrtc/base/bytebuffer.h" | 12 #include "webrtc/base/bytebuffer.h" |
| 13 #include "webrtc/base/copyonwritebuffer.h" | |
| 13 #include "webrtc/base/gunit.h" | 14 #include "webrtc/base/gunit.h" |
| 14 | 15 |
| 15 class SctpUtilsTest : public testing::Test { | 16 class SctpUtilsTest : public testing::Test { |
| 16 public: | 17 public: |
| 17 void VerifyOpenMessageFormat(const rtc::Buffer& packet, | 18 void VerifyOpenMessageFormat(const rtc::CopyOnWriteBuffer& packet, |
| 18 const std::string& label, | 19 const std::string& label, |
| 19 const webrtc::DataChannelInit& config) { | 20 const webrtc::DataChannelInit& config) { |
| 20 uint8_t message_type; | 21 uint8_t message_type; |
| 21 uint8_t channel_type; | 22 uint8_t channel_type; |
| 22 uint32_t reliability; | 23 uint32_t reliability; |
| 23 uint16_t priority; | 24 uint16_t priority; |
| 24 uint16_t label_length; | 25 uint16_t label_length; |
| 25 uint16_t protocol_length; | 26 uint16_t protocol_length; |
| 26 | 27 |
| 27 rtc::ByteBuffer buffer(packet.data(), packet.length()); | 28 rtc::ByteBufferReader buffer(packet.data<char>(), packet.size()); |
| 28 ASSERT_TRUE(buffer.ReadUInt8(&message_type)); | 29 ASSERT_TRUE(buffer.ReadUInt8(&message_type)); |
| 29 EXPECT_EQ(0x03, message_type); | 30 EXPECT_EQ(0x03, message_type); |
| 30 | 31 |
| 31 ASSERT_TRUE(buffer.ReadUInt8(&channel_type)); | 32 ASSERT_TRUE(buffer.ReadUInt8(&channel_type)); |
| 32 if (config.ordered) { | 33 if (config.ordered) { |
| 33 EXPECT_EQ(config.maxRetransmits > -1 ? | 34 EXPECT_EQ(config.maxRetransmits > -1 ? |
| 34 0x01 : (config.maxRetransmitTime > -1 ? 0x02 : 0), | 35 0x01 : (config.maxRetransmitTime > -1 ? 0x02 : 0), |
| 35 channel_type); | 36 channel_type); |
| 36 } else { | 37 } else { |
| 37 EXPECT_EQ(config.maxRetransmits > -1 ? | 38 EXPECT_EQ(config.maxRetransmits > -1 ? |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 60 ASSERT_TRUE(buffer.ReadString(&protocol_output, protocol_length)); | 61 ASSERT_TRUE(buffer.ReadString(&protocol_output, protocol_length)); |
| 61 EXPECT_EQ(config.protocol, protocol_output); | 62 EXPECT_EQ(config.protocol, protocol_output); |
| 62 } | 63 } |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 TEST_F(SctpUtilsTest, WriteParseOpenMessageWithOrderedReliable) { | 66 TEST_F(SctpUtilsTest, WriteParseOpenMessageWithOrderedReliable) { |
| 66 webrtc::DataChannelInit config; | 67 webrtc::DataChannelInit config; |
| 67 std::string label = "abc"; | 68 std::string label = "abc"; |
| 68 config.protocol = "y"; | 69 config.protocol = "y"; |
| 69 | 70 |
| 70 rtc::Buffer packet; | 71 rtc::CopyOnWriteBuffer packet; |
| 71 ASSERT_TRUE(webrtc::WriteDataChannelOpenMessage(label, config, &packet)); | 72 ASSERT_TRUE(webrtc::WriteDataChannelOpenMessage(label, config, &packet)); |
| 72 | 73 |
| 73 VerifyOpenMessageFormat(packet, label, config); | 74 VerifyOpenMessageFormat(packet, label, config); |
| 74 | 75 |
| 75 std::string output_label; | 76 std::string output_label; |
| 76 webrtc::DataChannelInit output_config; | 77 webrtc::DataChannelInit output_config; |
| 77 ASSERT_TRUE(webrtc::ParseDataChannelOpenMessage( | 78 ASSERT_TRUE(webrtc::ParseDataChannelOpenMessage( |
| 78 packet, &output_label, &output_config)); | 79 packet, &output_label, &output_config)); |
| 79 | 80 |
| 80 EXPECT_EQ(label, output_label); | 81 EXPECT_EQ(label, output_label); |
| 81 EXPECT_EQ(config.protocol, output_config.protocol); | 82 EXPECT_EQ(config.protocol, output_config.protocol); |
| 82 EXPECT_EQ(config.ordered, output_config.ordered); | 83 EXPECT_EQ(config.ordered, output_config.ordered); |
| 83 EXPECT_EQ(config.maxRetransmitTime, output_config.maxRetransmitTime); | 84 EXPECT_EQ(config.maxRetransmitTime, output_config.maxRetransmitTime); |
| 84 EXPECT_EQ(config.maxRetransmits, output_config.maxRetransmits); | 85 EXPECT_EQ(config.maxRetransmits, output_config.maxRetransmits); |
| 85 } | 86 } |
| 86 | 87 |
| 87 TEST_F(SctpUtilsTest, WriteParseOpenMessageWithMaxRetransmitTime) { | 88 TEST_F(SctpUtilsTest, WriteParseOpenMessageWithMaxRetransmitTime) { |
| 88 webrtc::DataChannelInit config; | 89 webrtc::DataChannelInit config; |
| 89 std::string label = "abc"; | 90 std::string label = "abc"; |
| 90 config.ordered = false; | 91 config.ordered = false; |
| 91 config.maxRetransmitTime = 10; | 92 config.maxRetransmitTime = 10; |
| 92 config.protocol = "y"; | 93 config.protocol = "y"; |
| 93 | 94 |
| 94 rtc::Buffer packet; | 95 rtc::CopyOnWriteBuffer packet; |
| 95 ASSERT_TRUE(webrtc::WriteDataChannelOpenMessage(label, config, &packet)); | 96 ASSERT_TRUE(webrtc::WriteDataChannelOpenMessage(label, config, &packet)); |
| 96 | 97 |
| 97 VerifyOpenMessageFormat(packet, label, config); | 98 VerifyOpenMessageFormat(packet, label, config); |
| 98 | 99 |
| 99 std::string output_label; | 100 std::string output_label; |
| 100 webrtc::DataChannelInit output_config; | 101 webrtc::DataChannelInit output_config; |
| 101 ASSERT_TRUE(webrtc::ParseDataChannelOpenMessage( | 102 ASSERT_TRUE(webrtc::ParseDataChannelOpenMessage( |
| 102 packet, &output_label, &output_config)); | 103 packet, &output_label, &output_config)); |
| 103 | 104 |
| 104 EXPECT_EQ(label, output_label); | 105 EXPECT_EQ(label, output_label); |
| 105 EXPECT_EQ(config.protocol, output_config.protocol); | 106 EXPECT_EQ(config.protocol, output_config.protocol); |
| 106 EXPECT_EQ(config.ordered, output_config.ordered); | 107 EXPECT_EQ(config.ordered, output_config.ordered); |
| 107 EXPECT_EQ(config.maxRetransmitTime, output_config.maxRetransmitTime); | 108 EXPECT_EQ(config.maxRetransmitTime, output_config.maxRetransmitTime); |
| 108 EXPECT_EQ(-1, output_config.maxRetransmits); | 109 EXPECT_EQ(-1, output_config.maxRetransmits); |
| 109 } | 110 } |
| 110 | 111 |
| 111 TEST_F(SctpUtilsTest, WriteParseOpenMessageWithMaxRetransmits) { | 112 TEST_F(SctpUtilsTest, WriteParseOpenMessageWithMaxRetransmits) { |
| 112 webrtc::DataChannelInit config; | 113 webrtc::DataChannelInit config; |
| 113 std::string label = "abc"; | 114 std::string label = "abc"; |
| 114 config.maxRetransmits = 10; | 115 config.maxRetransmits = 10; |
| 115 config.protocol = "y"; | 116 config.protocol = "y"; |
| 116 | 117 |
| 117 rtc::Buffer packet; | 118 rtc::CopyOnWriteBuffer packet; |
| 118 ASSERT_TRUE(webrtc::WriteDataChannelOpenMessage(label, config, &packet)); | 119 ASSERT_TRUE(webrtc::WriteDataChannelOpenMessage(label, config, &packet)); |
| 119 | 120 |
| 120 VerifyOpenMessageFormat(packet, label, config); | 121 VerifyOpenMessageFormat(packet, label, config); |
| 121 | 122 |
| 122 std::string output_label; | 123 std::string output_label; |
| 123 webrtc::DataChannelInit output_config; | 124 webrtc::DataChannelInit output_config; |
| 124 ASSERT_TRUE(webrtc::ParseDataChannelOpenMessage( | 125 ASSERT_TRUE(webrtc::ParseDataChannelOpenMessage( |
| 125 packet, &output_label, &output_config)); | 126 packet, &output_label, &output_config)); |
| 126 | 127 |
| 127 EXPECT_EQ(label, output_label); | 128 EXPECT_EQ(label, output_label); |
| 128 EXPECT_EQ(config.protocol, output_config.protocol); | 129 EXPECT_EQ(config.protocol, output_config.protocol); |
| 129 EXPECT_EQ(config.ordered, output_config.ordered); | 130 EXPECT_EQ(config.ordered, output_config.ordered); |
| 130 EXPECT_EQ(config.maxRetransmits, output_config.maxRetransmits); | 131 EXPECT_EQ(config.maxRetransmits, output_config.maxRetransmits); |
| 131 EXPECT_EQ(-1, output_config.maxRetransmitTime); | 132 EXPECT_EQ(-1, output_config.maxRetransmitTime); |
| 132 } | 133 } |
| 133 | 134 |
| 134 TEST_F(SctpUtilsTest, WriteParseAckMessage) { | 135 TEST_F(SctpUtilsTest, WriteParseAckMessage) { |
| 135 rtc::Buffer packet; | 136 rtc::CopyOnWriteBuffer packet; |
| 136 webrtc::WriteDataChannelOpenAckMessage(&packet); | 137 webrtc::WriteDataChannelOpenAckMessage(&packet); |
| 137 | 138 |
| 138 uint8_t message_type; | 139 uint8_t message_type; |
| 139 rtc::ByteBuffer buffer(packet.data(), packet.length()); | 140 rtc::ByteBufferReader buffer(packet.data<char>(), packet.size()); |
| 140 ASSERT_TRUE(buffer.ReadUInt8(&message_type)); | 141 ASSERT_TRUE(buffer.ReadUInt8(&message_type)); |
| 141 EXPECT_EQ(0x02, message_type); | 142 EXPECT_EQ(0x02, message_type); |
| 142 | 143 |
| 143 EXPECT_TRUE(webrtc::ParseDataChannelOpenAckMessage(packet)); | 144 EXPECT_TRUE(webrtc::ParseDataChannelOpenAckMessage(packet)); |
| 144 } | 145 } |
| 145 | 146 |
| 146 TEST_F(SctpUtilsTest, TestIsOpenMessage) { | 147 TEST_F(SctpUtilsTest, TestIsOpenMessage) { |
| 147 rtc::ByteBuffer open; | 148 rtc::CopyOnWriteBuffer open(1); |
| 148 open.WriteUInt8(0x03); | 149 open[0] = 0x03; |
| 149 EXPECT_TRUE(webrtc::IsOpenMessage(open)); | 150 EXPECT_TRUE(webrtc::IsOpenMessage(open)); |
| 150 | 151 |
| 151 rtc::ByteBuffer openAck; | 152 rtc::CopyOnWriteBuffer openAck(1); |
| 152 openAck.WriteUInt8(0x02); | 153 openAck[0] = 0x02; |
| 153 EXPECT_FALSE(webrtc::IsOpenMessage(open)); | 154 EXPECT_FALSE(webrtc::IsOpenMessage(openAck)); |
|
Taylor Brandstetter
2016/11/07 20:06:20
Wait, how was this ever passing?
ossu
2016/11/08 09:55:56
Yeah, I'm not sure this was ever run, at least not
| |
| 154 | 155 |
| 155 rtc::ByteBuffer invalid; | 156 rtc::CopyOnWriteBuffer invalid(1); |
| 156 openAck.WriteUInt8(0x01); | 157 invalid[0] = 0x01; |
| 157 EXPECT_FALSE(webrtc::IsOpenMessage(invalid)); | 158 EXPECT_FALSE(webrtc::IsOpenMessage(invalid)); |
| 158 | 159 |
| 159 rtc::ByteBuffer empty; | 160 rtc::CopyOnWriteBuffer empty; |
| 160 EXPECT_FALSE(webrtc::IsOpenMessage(empty)); | 161 EXPECT_FALSE(webrtc::IsOpenMessage(empty)); |
| 161 } | 162 } |
| OLD | NEW |