Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: webrtc/api/sctputils_unittest.cc

Issue 2514883002: Create //webrtc/api:libjingle_peerconnection_api + refactorings. (Closed)
Patch Set: Rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/sctputils.cc ('k') | webrtc/api/stats/rtcstatscollectorcallback.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 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
11 #include "webrtc/api/sctputils.h"
12 #include "webrtc/base/bytebuffer.h"
13 #include "webrtc/base/copyonwritebuffer.h"
14 #include "webrtc/base/gunit.h"
15
16 class SctpUtilsTest : public testing::Test {
17 public:
18 void VerifyOpenMessageFormat(const rtc::CopyOnWriteBuffer& packet,
19 const std::string& label,
20 const webrtc::DataChannelInit& config) {
21 uint8_t message_type;
22 uint8_t channel_type;
23 uint32_t reliability;
24 uint16_t priority;
25 uint16_t label_length;
26 uint16_t protocol_length;
27
28 rtc::ByteBufferReader buffer(packet.data<char>(), packet.size());
29 ASSERT_TRUE(buffer.ReadUInt8(&message_type));
30 EXPECT_EQ(0x03, message_type);
31
32 ASSERT_TRUE(buffer.ReadUInt8(&channel_type));
33 if (config.ordered) {
34 EXPECT_EQ(config.maxRetransmits > -1 ?
35 0x01 : (config.maxRetransmitTime > -1 ? 0x02 : 0),
36 channel_type);
37 } else {
38 EXPECT_EQ(config.maxRetransmits > -1 ?
39 0x81 : (config.maxRetransmitTime > -1 ? 0x82 : 0x80),
40 channel_type);
41 }
42
43 ASSERT_TRUE(buffer.ReadUInt16(&priority));
44
45 ASSERT_TRUE(buffer.ReadUInt32(&reliability));
46 if (config.maxRetransmits > -1 || config.maxRetransmitTime > -1) {
47 EXPECT_EQ(config.maxRetransmits > -1 ?
48 config.maxRetransmits : config.maxRetransmitTime,
49 static_cast<int>(reliability));
50 }
51
52 ASSERT_TRUE(buffer.ReadUInt16(&label_length));
53 ASSERT_TRUE(buffer.ReadUInt16(&protocol_length));
54 EXPECT_EQ(label.size(), label_length);
55 EXPECT_EQ(config.protocol.size(), protocol_length);
56
57 std::string label_output;
58 ASSERT_TRUE(buffer.ReadString(&label_output, label_length));
59 EXPECT_EQ(label, label_output);
60 std::string protocol_output;
61 ASSERT_TRUE(buffer.ReadString(&protocol_output, protocol_length));
62 EXPECT_EQ(config.protocol, protocol_output);
63 }
64 };
65
66 TEST_F(SctpUtilsTest, WriteParseOpenMessageWithOrderedReliable) {
67 webrtc::DataChannelInit config;
68 std::string label = "abc";
69 config.protocol = "y";
70
71 rtc::CopyOnWriteBuffer packet;
72 ASSERT_TRUE(webrtc::WriteDataChannelOpenMessage(label, config, &packet));
73
74 VerifyOpenMessageFormat(packet, label, config);
75
76 std::string output_label;
77 webrtc::DataChannelInit output_config;
78 ASSERT_TRUE(webrtc::ParseDataChannelOpenMessage(
79 packet, &output_label, &output_config));
80
81 EXPECT_EQ(label, output_label);
82 EXPECT_EQ(config.protocol, output_config.protocol);
83 EXPECT_EQ(config.ordered, output_config.ordered);
84 EXPECT_EQ(config.maxRetransmitTime, output_config.maxRetransmitTime);
85 EXPECT_EQ(config.maxRetransmits, output_config.maxRetransmits);
86 }
87
88 TEST_F(SctpUtilsTest, WriteParseOpenMessageWithMaxRetransmitTime) {
89 webrtc::DataChannelInit config;
90 std::string label = "abc";
91 config.ordered = false;
92 config.maxRetransmitTime = 10;
93 config.protocol = "y";
94
95 rtc::CopyOnWriteBuffer packet;
96 ASSERT_TRUE(webrtc::WriteDataChannelOpenMessage(label, config, &packet));
97
98 VerifyOpenMessageFormat(packet, label, config);
99
100 std::string output_label;
101 webrtc::DataChannelInit output_config;
102 ASSERT_TRUE(webrtc::ParseDataChannelOpenMessage(
103 packet, &output_label, &output_config));
104
105 EXPECT_EQ(label, output_label);
106 EXPECT_EQ(config.protocol, output_config.protocol);
107 EXPECT_EQ(config.ordered, output_config.ordered);
108 EXPECT_EQ(config.maxRetransmitTime, output_config.maxRetransmitTime);
109 EXPECT_EQ(-1, output_config.maxRetransmits);
110 }
111
112 TEST_F(SctpUtilsTest, WriteParseOpenMessageWithMaxRetransmits) {
113 webrtc::DataChannelInit config;
114 std::string label = "abc";
115 config.maxRetransmits = 10;
116 config.protocol = "y";
117
118 rtc::CopyOnWriteBuffer packet;
119 ASSERT_TRUE(webrtc::WriteDataChannelOpenMessage(label, config, &packet));
120
121 VerifyOpenMessageFormat(packet, label, config);
122
123 std::string output_label;
124 webrtc::DataChannelInit output_config;
125 ASSERT_TRUE(webrtc::ParseDataChannelOpenMessage(
126 packet, &output_label, &output_config));
127
128 EXPECT_EQ(label, output_label);
129 EXPECT_EQ(config.protocol, output_config.protocol);
130 EXPECT_EQ(config.ordered, output_config.ordered);
131 EXPECT_EQ(config.maxRetransmits, output_config.maxRetransmits);
132 EXPECT_EQ(-1, output_config.maxRetransmitTime);
133 }
134
135 TEST_F(SctpUtilsTest, WriteParseAckMessage) {
136 rtc::CopyOnWriteBuffer packet;
137 webrtc::WriteDataChannelOpenAckMessage(&packet);
138
139 uint8_t message_type;
140 rtc::ByteBufferReader buffer(packet.data<char>(), packet.size());
141 ASSERT_TRUE(buffer.ReadUInt8(&message_type));
142 EXPECT_EQ(0x02, message_type);
143
144 EXPECT_TRUE(webrtc::ParseDataChannelOpenAckMessage(packet));
145 }
146
147 TEST_F(SctpUtilsTest, TestIsOpenMessage) {
148 rtc::CopyOnWriteBuffer open(1);
149 open[0] = 0x03;
150 EXPECT_TRUE(webrtc::IsOpenMessage(open));
151
152 rtc::CopyOnWriteBuffer openAck(1);
153 openAck[0] = 0x02;
154 EXPECT_FALSE(webrtc::IsOpenMessage(openAck));
155
156 rtc::CopyOnWriteBuffer invalid(1);
157 invalid[0] = 0x01;
158 EXPECT_FALSE(webrtc::IsOpenMessage(invalid));
159
160 rtc::CopyOnWriteBuffer empty;
161 EXPECT_FALSE(webrtc::IsOpenMessage(empty));
162 }
OLDNEW
« no previous file with comments | « webrtc/api/sctputils.cc ('k') | webrtc/api/stats/rtcstatscollectorcallback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698