blob: c5e95d01e9832e8facc4b1e7a8cb39710c2a3144 [file] [log] [blame]
Amit Hilbucha2012042018-12-03 11:35:05 -08001/*
2 * Copyright 2018 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
Amit Hilbuchc57d5732018-12-11 15:30:11 -080011#include <map>
Amit Hilbucha2012042018-12-03 11:35:05 -080012#include <string>
Amit Hilbuchc57d5732018-12-11 15:30:11 -080013#include <utility>
Amit Hilbucha2012042018-12-03 11:35:05 -080014#include <vector>
15
16#include "pc/sdpserializer.h"
17#include "rtc_base/gunit.h"
18
19using ::testing::ValuesIn;
Amit Hilbuchc57d5732018-12-11 15:30:11 -080020using ::testing::TestWithParam;
21using cricket::RidDescription;
22using cricket::RidDirection;
Amit Hilbucha2012042018-12-03 11:35:05 -080023using cricket::SimulcastDescription;
24using cricket::SimulcastLayer;
25using cricket::SimulcastLayerList;
26
27namespace webrtc {
28
Amit Hilbuchc57d5732018-12-11 15:30:11 -080029namespace {
30// Checks that two vectors have the same objects in the same order.
31template <typename TElement>
32void ExpectEqual(const std::vector<TElement>& expected,
33 const std::vector<TElement>& actual) {
34 ASSERT_EQ(expected.size(), actual.size());
35 for (size_t i = 0; i < expected.size(); i++) {
36 EXPECT_EQ(expected[i], actual[i]) << "Vectors differ at element " << i;
37 }
38}
39
40// Template specialization for vectors of SimulcastLayer objects.
41template <>
42void ExpectEqual(const std::vector<SimulcastLayer>& expected,
43 const std::vector<SimulcastLayer>& actual) {
44 EXPECT_EQ(expected.size(), actual.size());
45 for (size_t i = 0; i < expected.size(); i++) {
46 EXPECT_EQ(expected[i].rid, actual[i].rid);
47 EXPECT_EQ(expected[i].is_paused, actual[i].is_paused);
48 }
49}
50
51// Checks that two maps have the same key-value pairs.
52// Even though a map is technically ordered, the order semantics are not
53// tested because having the same key-set in both maps implies that they
54// are ordered the same because the template enforces that they have the
55// same Key-Comparer type.
56template <typename TKey, typename TValue>
57void ExpectEqual(const std::map<TKey, TValue>& expected,
58 const std::map<TKey, TValue>& actual) {
59 typedef typename std::map<TKey, TValue>::const_iterator const_iterator;
60 ASSERT_EQ(expected.size(), actual.size());
61 // Maps have unique keys, so if size is equal, it is enough to check
62 // that all the keys (and values) from one map exist in the other.
63 for (const std::pair<TKey, TValue>& pair : expected) {
64 const_iterator iter = actual.find(pair.first);
65 EXPECT_NE(iter, actual.end()) << "Key: " << pair.first << " not found";
66 EXPECT_EQ(pair.second, iter->second);
67 }
68}
69
70// Checks that the two SimulcastLayerLists are equal.
71void ExpectEqual(const SimulcastLayerList& expected,
72 const SimulcastLayerList& actual) {
73 EXPECT_EQ(expected.size(), actual.size());
74 for (size_t i = 0; i < expected.size(); i++) {
75 ExpectEqual(expected[i], actual[i]);
76 }
77}
78
79// Checks that the two SimulcastDescriptions are equal.
80void ExpectEqual(const SimulcastDescription& expected,
81 const SimulcastDescription& actual) {
82 ExpectEqual(expected.send_layers(), actual.send_layers());
83 ExpectEqual(expected.receive_layers(), actual.receive_layers());
84}
85
86// Checks that the two RidDescriptions are equal.
87void ExpectEqual(const RidDescription& expected, const RidDescription& actual) {
88 EXPECT_EQ(expected.rid, actual.rid);
89 EXPECT_EQ(expected.direction, actual.direction);
90 ExpectEqual(expected.payload_types, actual.payload_types);
91 ExpectEqual(expected.restrictions, actual.restrictions);
92}
93} // namespace
94
95class SimulcastSdpSerializerTest : public TestWithParam<const char*> {
Amit Hilbucha2012042018-12-03 11:35:05 -080096 public:
97 // Runs a test for deserializing Simulcast.
98 // |str| - The serialized Simulcast to parse.
99 // |expected| - The expected output Simulcast to compare to.
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800100 void TestDeserialization(const std::string& str,
101 const SimulcastDescription& expected) const {
Amit Hilbucha2012042018-12-03 11:35:05 -0800102 SdpSerializer deserializer;
103 auto result = deserializer.DeserializeSimulcastDescription(str);
104 EXPECT_TRUE(result.ok());
105 ExpectEqual(expected, result.value());
106 }
107
108 // Runs a test for serializing Simulcast.
109 // |simulcast| - The Simulcast to serialize.
110 // |expected| - The expected output string to compare to.
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800111 void TestSerialization(const SimulcastDescription& simulcast,
112 const std::string& expected) const {
Amit Hilbucha2012042018-12-03 11:35:05 -0800113 SdpSerializer serializer;
114 auto result = serializer.SerializeSimulcastDescription(simulcast);
115 EXPECT_EQ(expected, result);
116 }
Amit Hilbucha2012042018-12-03 11:35:05 -0800117};
118
119// Test Cases
120
121// Test simple deserialization with no alternative streams.
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800122TEST_F(SimulcastSdpSerializerTest, Deserialize_SimpleCaseNoAlternatives) {
Amit Hilbucha2012042018-12-03 11:35:05 -0800123 std::string simulcast_str = "send 1;2 recv 3;4";
124 SimulcastDescription expected;
125 expected.send_layers().AddLayer(SimulcastLayer("1", false));
126 expected.send_layers().AddLayer(SimulcastLayer("2", false));
127 expected.receive_layers().AddLayer(SimulcastLayer("3", false));
128 expected.receive_layers().AddLayer(SimulcastLayer("4", false));
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800129 TestDeserialization(simulcast_str, expected);
Amit Hilbucha2012042018-12-03 11:35:05 -0800130}
131
132// Test simulcast deserialization with alternative streams.
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800133TEST_F(SimulcastSdpSerializerTest, Deserialize_SimpleCaseWithAlternatives) {
Amit Hilbucha2012042018-12-03 11:35:05 -0800134 std::string simulcast_str = "send 1,5;2,6 recv 3,7;4,8";
135 SimulcastDescription expected;
136 expected.send_layers().AddLayerWithAlternatives(
137 {SimulcastLayer("1", false), SimulcastLayer("5", false)});
138 expected.send_layers().AddLayerWithAlternatives(
139 {SimulcastLayer("2", false), SimulcastLayer("6", false)});
140 expected.receive_layers().AddLayerWithAlternatives(
141 {SimulcastLayer("3", false), SimulcastLayer("7", false)});
142 expected.receive_layers().AddLayerWithAlternatives(
143 {SimulcastLayer("4", false), SimulcastLayer("8", false)});
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800144 TestDeserialization(simulcast_str, expected);
Amit Hilbucha2012042018-12-03 11:35:05 -0800145}
146
147// Test simulcast deserialization when only some streams have alternatives.
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800148TEST_F(SimulcastSdpSerializerTest, Deserialize_WithSomeAlternatives) {
Amit Hilbucha2012042018-12-03 11:35:05 -0800149 std::string simulcast_str = "send 1;2,6 recv 3,7;4";
150 SimulcastDescription expected;
151 expected.send_layers().AddLayer(SimulcastLayer("1", false));
152 expected.send_layers().AddLayerWithAlternatives(
153 {SimulcastLayer("2", false), SimulcastLayer("6", false)});
154 expected.receive_layers().AddLayerWithAlternatives(
155 {SimulcastLayer("3", false), SimulcastLayer("7", false)});
156 expected.receive_layers().AddLayer(SimulcastLayer("4", false));
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800157 TestDeserialization(simulcast_str, expected);
Amit Hilbucha2012042018-12-03 11:35:05 -0800158}
159
160// Test simulcast deserialization when only send streams are specified.
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800161TEST_F(SimulcastSdpSerializerTest, Deserialize_OnlySendStreams) {
Amit Hilbucha2012042018-12-03 11:35:05 -0800162 std::string simulcast_str = "send 1;2,6;3,7;4";
163 SimulcastDescription expected;
164 expected.send_layers().AddLayer(SimulcastLayer("1", false));
165 expected.send_layers().AddLayerWithAlternatives(
166 {SimulcastLayer("2", false), SimulcastLayer("6", false)});
167 expected.send_layers().AddLayerWithAlternatives(
168 {SimulcastLayer("3", false), SimulcastLayer("7", false)});
169 expected.send_layers().AddLayer(SimulcastLayer("4", false));
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800170 TestDeserialization(simulcast_str, expected);
Amit Hilbucha2012042018-12-03 11:35:05 -0800171}
172
173// Test simulcast deserialization when only receive streams are specified.
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800174TEST_F(SimulcastSdpSerializerTest, Deserialize_OnlyReceiveStreams) {
Amit Hilbucha2012042018-12-03 11:35:05 -0800175 std::string simulcast_str = "recv 1;2,6;3,7;4";
176 SimulcastDescription expected;
177 expected.receive_layers().AddLayer(SimulcastLayer("1", false));
178 expected.receive_layers().AddLayerWithAlternatives(
179 {SimulcastLayer("2", false), SimulcastLayer("6", false)});
180 expected.receive_layers().AddLayerWithAlternatives(
181 {SimulcastLayer("3", false), SimulcastLayer("7", false)});
182 expected.receive_layers().AddLayer(SimulcastLayer("4", false));
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800183 TestDeserialization(simulcast_str, expected);
Amit Hilbucha2012042018-12-03 11:35:05 -0800184}
185
186// Test simulcast deserialization with receive streams before send streams.
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800187TEST_F(SimulcastSdpSerializerTest, Deserialize_SendReceiveReversed) {
Amit Hilbucha2012042018-12-03 11:35:05 -0800188 std::string simulcast_str = "recv 1;2,6 send 3,7;4";
189 SimulcastDescription expected;
190 expected.receive_layers().AddLayer(SimulcastLayer("1", false));
191 expected.receive_layers().AddLayerWithAlternatives(
192 {SimulcastLayer("2", false), SimulcastLayer("6", false)});
193 expected.send_layers().AddLayerWithAlternatives(
194 {SimulcastLayer("3", false), SimulcastLayer("7", false)});
195 expected.send_layers().AddLayer(SimulcastLayer("4", false));
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800196 TestDeserialization(simulcast_str, expected);
Amit Hilbucha2012042018-12-03 11:35:05 -0800197}
198
199// Test simulcast deserialization with some streams set to paused state.
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800200TEST_F(SimulcastSdpSerializerTest, Deserialize_PausedStreams) {
Amit Hilbucha2012042018-12-03 11:35:05 -0800201 std::string simulcast_str = "recv 1;~2,6 send 3,7;~4";
202 SimulcastDescription expected;
203 expected.receive_layers().AddLayer(SimulcastLayer("1", false));
204 expected.receive_layers().AddLayerWithAlternatives(
205 {SimulcastLayer("2", true), SimulcastLayer("6", false)});
206 expected.send_layers().AddLayerWithAlternatives(
207 {SimulcastLayer("3", false), SimulcastLayer("7", false)});
208 expected.send_layers().AddLayer(SimulcastLayer("4", true));
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800209 TestDeserialization(simulcast_str, expected);
Amit Hilbucha2012042018-12-03 11:35:05 -0800210}
211
212// Parameterized negative test case for deserialization with invalid inputs.
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800213TEST_P(SimulcastSdpSerializerTest, SimulcastDeserializationFailed) {
Amit Hilbucha2012042018-12-03 11:35:05 -0800214 SdpSerializer deserializer;
215 auto result = deserializer.DeserializeSimulcastDescription(GetParam());
216 EXPECT_FALSE(result.ok());
217}
218
219// The malformed Simulcast inputs to use in the negative test case.
220const char* kSimulcastMalformedStrings[] = {
221 "send ",
222 "recv ",
223 "recv 1 send",
224 "receive 1",
225 "recv 1;~2,6 recv 3,7;~4",
226 "send 1;~2,6 send 3,7;~4",
227 "send ~;~2,6",
228 "send 1; ;~2,6",
229 "send 1,;~2,6",
230 "recv 1 send 2 3",
231 "",
232};
233
234INSTANTIATE_TEST_CASE_P(SimulcastDeserializationErrors,
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800235 SimulcastSdpSerializerTest,
Amit Hilbucha2012042018-12-03 11:35:05 -0800236 ValuesIn(kSimulcastMalformedStrings));
237
238// Test a simple serialization scenario.
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800239TEST_F(SimulcastSdpSerializerTest, Serialize_SimpleCase) {
Amit Hilbucha2012042018-12-03 11:35:05 -0800240 SimulcastDescription simulcast;
241 simulcast.send_layers().AddLayer(SimulcastLayer("1", false));
242 simulcast.receive_layers().AddLayer(SimulcastLayer("2", false));
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800243 TestSerialization(simulcast, "send 1 recv 2");
Amit Hilbucha2012042018-12-03 11:35:05 -0800244}
245
246// Test serialization with only send streams.
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800247TEST_F(SimulcastSdpSerializerTest, Serialize_OnlySend) {
Amit Hilbucha2012042018-12-03 11:35:05 -0800248 SimulcastDescription simulcast;
249 simulcast.send_layers().AddLayer(SimulcastLayer("1", false));
250 simulcast.send_layers().AddLayer(SimulcastLayer("2", false));
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800251 TestSerialization(simulcast, "send 1;2");
Amit Hilbucha2012042018-12-03 11:35:05 -0800252}
253
254// Test serialization with only receive streams
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800255TEST_F(SimulcastSdpSerializerTest, Serialize_OnlyReceive) {
Amit Hilbucha2012042018-12-03 11:35:05 -0800256 SimulcastDescription simulcast;
257 simulcast.receive_layers().AddLayer(SimulcastLayer("1", false));
258 simulcast.receive_layers().AddLayer(SimulcastLayer("2", false));
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800259 TestSerialization(simulcast, "recv 1;2");
Amit Hilbucha2012042018-12-03 11:35:05 -0800260}
261
262// Test a complex serialization with multiple streams, alternatives and states.
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800263TEST_F(SimulcastSdpSerializerTest, Serialize_ComplexSerialization) {
Amit Hilbucha2012042018-12-03 11:35:05 -0800264 SimulcastDescription simulcast;
265 simulcast.send_layers().AddLayerWithAlternatives(
266 {SimulcastLayer("2", false), SimulcastLayer("1", true)});
267 simulcast.send_layers().AddLayerWithAlternatives(
268 {SimulcastLayer("4", false), SimulcastLayer("3", false)});
269
270 simulcast.receive_layers().AddLayerWithAlternatives(
271 {SimulcastLayer("6", false), SimulcastLayer("7", false)});
272 simulcast.receive_layers().AddLayer(SimulcastLayer("8", true));
273 simulcast.receive_layers().AddLayerWithAlternatives(
274 {SimulcastLayer("9", false), SimulcastLayer("10", true),
275 SimulcastLayer("11", false)});
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800276 TestSerialization(simulcast, "send 2,~1;4,3 recv 6,7;~8;9,~10,11");
Amit Hilbucha2012042018-12-03 11:35:05 -0800277}
278
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800279class RidDescriptionSdpSerializerTest : public TestWithParam<const char*> {
280 public:
281 // Runs a test for deserializing Rid Descriptions.
282 // |str| - The serialized Rid Description to parse.
283 // |expected| - The expected output RidDescription to compare to.
284 void TestDeserialization(const std::string& str,
285 const RidDescription& expected) const {
286 SdpSerializer deserializer;
287 auto result = deserializer.DeserializeRidDescription(str);
288 EXPECT_TRUE(result.ok());
289 ExpectEqual(expected, result.value());
290 }
291
292 // Runs a test for serializing RidDescriptions.
293 // |rid_description| - The RidDescription to serialize.
294 // |expected| - The expected output string to compare to.
295 void TestSerialization(const RidDescription& rid_description,
296 const std::string& expected) const {
297 SdpSerializer serializer;
298 auto result = serializer.SerializeRidDescription(rid_description);
299 EXPECT_EQ(expected, result);
300 }
301};
302
303// Test serialization for RidDescription that only specifies send.
304TEST_F(RidDescriptionSdpSerializerTest, Serialize_OnlyDirectionSend) {
305 RidDescription rid_description("1", RidDirection::kSend);
306 TestSerialization(rid_description, "1 send");
307}
308
309// Test serialization for RidDescription that only specifies receive.
310TEST_F(RidDescriptionSdpSerializerTest, Serialize_OnlyDirectionReceive) {
311 RidDescription rid_description("2", RidDirection::kReceive);
312 TestSerialization(rid_description, "2 recv");
313}
314
315// Test serialization for RidDescription with format list.
316TEST_F(RidDescriptionSdpSerializerTest, Serialize_FormatList) {
317 RidDescription rid_description("3", RidDirection::kSend);
318 rid_description.payload_types = {102, 101};
319 TestSerialization(rid_description, "3 send pt=102,101");
320}
321
322// Test serialization for RidDescription with format list.
323TEST_F(RidDescriptionSdpSerializerTest, Serialize_FormatListSingleFormat) {
324 RidDescription rid_description("4", RidDirection::kReceive);
325 rid_description.payload_types = {100};
326 TestSerialization(rid_description, "4 recv pt=100");
327}
328
329// Test serialization for RidDescription with restriction list.
330// Note: restriction list will be sorted because it is stored in a map.
331TEST_F(RidDescriptionSdpSerializerTest, Serialize_AttributeList) {
332 RidDescription rid_description("5", RidDirection::kSend);
333 rid_description.restrictions["max-width"] = "1280";
334 rid_description.restrictions["max-height"] = "720";
335 TestSerialization(rid_description, "5 send max-height=720;max-width=1280");
336}
337
338// Test serialization for RidDescription with format list and attribute list.
339// Note: restriction list will be sorted because it is stored in a map.
340TEST_F(RidDescriptionSdpSerializerTest, Serialize_FormatAndAttributeList) {
341 RidDescription rid_description("6", RidDirection::kSend);
342 rid_description.payload_types = {103, 104};
343 rid_description.restrictions["max-mbps"] = "108000";
344 rid_description.restrictions["max-br"] = "64000";
345 TestSerialization(rid_description,
346 "6 send pt=103,104;max-br=64000;max-mbps=108000");
347}
348
349// Test serialization for attribute list that has key with no value.
350// Note: restriction list will be sorted because it is stored in a map.
351TEST_F(RidDescriptionSdpSerializerTest, Serialize_RestrictionWithoutValue) {
352 RidDescription rid_description("7", RidDirection::kReceive);
353 rid_description.payload_types = {103};
354 rid_description.restrictions["max-width"] = "1280";
355 rid_description.restrictions["max-height"] = "720";
356 rid_description.restrictions["max-myval"] = "";
357 TestSerialization(rid_description,
358 "7 recv pt=103;max-height=720;max-myval;max-width=1280");
359}
360
361// Test simulcast deserialization with simple send stream.
362TEST_F(RidDescriptionSdpSerializerTest, Deserialize_SimpleSendCase) {
363 RidDescription rid_description("1", RidDirection::kSend);
364 TestDeserialization("1 send", rid_description);
365}
366
367// Test simulcast deserialization with simple receive stream.
368TEST_F(RidDescriptionSdpSerializerTest, Deserialize_SimpleReceiveCase) {
369 RidDescription rid_description("2", RidDirection::kReceive);
370 TestDeserialization("2 recv", rid_description);
371}
372
373// Test simulcast deserialization with single format.
374TEST_F(RidDescriptionSdpSerializerTest, Deserialize_WithFormat) {
375 RidDescription rid_description("3", RidDirection::kSend);
376 rid_description.payload_types = {101};
377 TestDeserialization("3 send pt=101", rid_description);
378}
379
380// Test simulcast deserialization with multiple formats.
381TEST_F(RidDescriptionSdpSerializerTest, Deserialize_WithMultipleFormats) {
382 RidDescription rid_description("4", RidDirection::kSend);
383 rid_description.payload_types = {103, 104, 101, 102};
384 TestDeserialization("4 send pt=103,104,101,102", rid_description);
385}
386
387// Test simulcast deserialization with restriction.
388TEST_F(RidDescriptionSdpSerializerTest, Deserialize_WithRestriction) {
389 RidDescription rid_description("5", RidDirection::kReceive);
390 rid_description.restrictions["max-height"] = "720";
391 TestDeserialization("5 recv max-height=720", rid_description);
392}
393
394// Test simulcast deserialization with multiple restrictions.
395TEST_F(RidDescriptionSdpSerializerTest, Deserialize_WithMultipleRestrictions) {
396 RidDescription rid_description("6", RidDirection::kReceive);
397 rid_description.restrictions["max-height"] = "720";
398 rid_description.restrictions["max-width"] = "1920";
399 rid_description.restrictions["max-fr"] = "60";
400 rid_description.restrictions["max-bps"] = "14000";
401 TestDeserialization(
402 "6 recv max-height=720;max-width=1920;max-bps=14000;max-fr=60",
403 rid_description);
404}
405
406// Test simulcast deserialization with custom (non-standard) restriction.
407TEST_F(RidDescriptionSdpSerializerTest, Deserialize_WithCustomRestrictions) {
408 RidDescription rid_description("7", RidDirection::kSend);
409 rid_description.restrictions["foo"] = "bar";
410 rid_description.restrictions["max-height"] = "720";
411 TestDeserialization("7 send max-height=720;foo=bar", rid_description);
412}
413
414// Test simulcast deserialization with multiple formats and restrictions.
415TEST_F(RidDescriptionSdpSerializerTest, Deserialize_WithFormatAndRestrictions) {
416 RidDescription rid_description("8", RidDirection::kSend);
417 rid_description.payload_types = {104, 103};
418 rid_description.restrictions["max-height"] = "720";
419 rid_description.restrictions["max-width"] = "1920";
420 TestDeserialization("8 send pt=104,103;max-height=720;max-width=1920",
421 rid_description);
422}
423
424// Test simulcast deserialization with restriction that has no value.
425TEST_F(RidDescriptionSdpSerializerTest, Deserialize_RestrictionHasNoValue) {
426 RidDescription rid_description("9", RidDirection::kReceive);
427 rid_description.payload_types = {104};
428 rid_description.restrictions["max-height"];
429 rid_description.restrictions["max-width"] = "1920";
430 TestDeserialization("9 recv pt=104;max-height;max-width=1920",
431 rid_description);
432}
433
434// Add this test to explicitly indicate that this is not an error.
435// The following string "1 send recv" looks malformed because it specifies
436// two directions, but in fact, the recv can be interpreted as a parameter
437// without a value. While such a use case is dubious, the input string is
438// not malformed.
439TEST_F(RidDescriptionSdpSerializerTest, Deserialize_AmbiguousCase) {
440 RidDescription rid_description("1", RidDirection::kSend);
441 rid_description.restrictions["recv"]; // No value.
442 TestDeserialization("1 send recv", rid_description);
443}
444
445// Parameterized negative test case for deserialization with invalid inputs.
446TEST_P(RidDescriptionSdpSerializerTest, RidDescriptionDeserializationFailed) {
447 SdpSerializer deserializer;
448 auto result = deserializer.DeserializeRidDescription(GetParam());
449 EXPECT_FALSE(result.ok());
450}
451
452// The malformed Rid Description inputs to use in the negative test case.
453const char* kRidDescriptionMalformedStrings[] = {
454 "1",
455 "recv",
456 "send",
457 "recv 1",
458 "send 1",
459 "1 receive",
460 "one direction",
461 "1 send pt=1 max-width=720", // The ' ' should be ';' in restriction list.
462 "1 recv ;",
463 "1 recv =",
464 "1 recv a=b=c",
465 "1 send max-width=720;pt=101", // pt= should appear first.
466 "1 send pt=101;pt=102",
467 "1 send pt=101,101",
468 "1 recv max-width=720;max-width=720",
469 "1 send pt=",
470 "1 send pt=abc",
471 "1 recv ;;",
472};
473
474INSTANTIATE_TEST_CASE_P(RidDescriptionDeserializationErrors,
475 RidDescriptionSdpSerializerTest,
476 ValuesIn(kRidDescriptionMalformedStrings));
477
Amit Hilbucha2012042018-12-03 11:35:05 -0800478} // namespace webrtc