Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 1 | /* |
| 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 Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 11 | #include <map> |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 12 | #include <string> |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 13 | #include <utility> |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
| 16 | #include "pc/sdpserializer.h" |
| 17 | #include "rtc_base/gunit.h" |
| 18 | |
| 19 | using ::testing::ValuesIn; |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 20 | using ::testing::TestWithParam; |
| 21 | using cricket::RidDescription; |
| 22 | using cricket::RidDirection; |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 23 | using cricket::SimulcastDescription; |
| 24 | using cricket::SimulcastLayer; |
| 25 | using cricket::SimulcastLayerList; |
| 26 | |
| 27 | namespace webrtc { |
| 28 | |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 29 | namespace { |
| 30 | // Checks that two vectors have the same objects in the same order. |
| 31 | template <typename TElement> |
| 32 | void 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. |
| 41 | template <> |
| 42 | void 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. |
| 56 | template <typename TKey, typename TValue> |
| 57 | void 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. |
| 71 | void 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. |
| 80 | void 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. |
| 87 | void 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 | |
| 95 | class SimulcastSdpSerializerTest : public TestWithParam<const char*> { |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 96 | 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 Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 100 | void TestDeserialization(const std::string& str, |
| 101 | const SimulcastDescription& expected) const { |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 102 | 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 Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 111 | void TestSerialization(const SimulcastDescription& simulcast, |
| 112 | const std::string& expected) const { |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 113 | SdpSerializer serializer; |
| 114 | auto result = serializer.SerializeSimulcastDescription(simulcast); |
| 115 | EXPECT_EQ(expected, result); |
| 116 | } |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | // Test Cases |
| 120 | |
| 121 | // Test simple deserialization with no alternative streams. |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 122 | TEST_F(SimulcastSdpSerializerTest, Deserialize_SimpleCaseNoAlternatives) { |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 123 | 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 Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 129 | TestDeserialization(simulcast_str, expected); |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | // Test simulcast deserialization with alternative streams. |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 133 | TEST_F(SimulcastSdpSerializerTest, Deserialize_SimpleCaseWithAlternatives) { |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 134 | 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 Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 144 | TestDeserialization(simulcast_str, expected); |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | // Test simulcast deserialization when only some streams have alternatives. |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 148 | TEST_F(SimulcastSdpSerializerTest, Deserialize_WithSomeAlternatives) { |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 149 | 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 Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 157 | TestDeserialization(simulcast_str, expected); |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | // Test simulcast deserialization when only send streams are specified. |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 161 | TEST_F(SimulcastSdpSerializerTest, Deserialize_OnlySendStreams) { |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 162 | 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 Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 170 | TestDeserialization(simulcast_str, expected); |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | // Test simulcast deserialization when only receive streams are specified. |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 174 | TEST_F(SimulcastSdpSerializerTest, Deserialize_OnlyReceiveStreams) { |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 175 | 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 Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 183 | TestDeserialization(simulcast_str, expected); |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | // Test simulcast deserialization with receive streams before send streams. |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 187 | TEST_F(SimulcastSdpSerializerTest, Deserialize_SendReceiveReversed) { |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 188 | 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 Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 196 | TestDeserialization(simulcast_str, expected); |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | // Test simulcast deserialization with some streams set to paused state. |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 200 | TEST_F(SimulcastSdpSerializerTest, Deserialize_PausedStreams) { |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 201 | 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 Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 209 | TestDeserialization(simulcast_str, expected); |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | // Parameterized negative test case for deserialization with invalid inputs. |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 213 | TEST_P(SimulcastSdpSerializerTest, SimulcastDeserializationFailed) { |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 214 | 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. |
| 220 | const 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 | |
| 234 | INSTANTIATE_TEST_CASE_P(SimulcastDeserializationErrors, |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 235 | SimulcastSdpSerializerTest, |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 236 | ValuesIn(kSimulcastMalformedStrings)); |
| 237 | |
| 238 | // Test a simple serialization scenario. |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 239 | TEST_F(SimulcastSdpSerializerTest, Serialize_SimpleCase) { |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 240 | SimulcastDescription simulcast; |
| 241 | simulcast.send_layers().AddLayer(SimulcastLayer("1", false)); |
| 242 | simulcast.receive_layers().AddLayer(SimulcastLayer("2", false)); |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 243 | TestSerialization(simulcast, "send 1 recv 2"); |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | // Test serialization with only send streams. |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 247 | TEST_F(SimulcastSdpSerializerTest, Serialize_OnlySend) { |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 248 | SimulcastDescription simulcast; |
| 249 | simulcast.send_layers().AddLayer(SimulcastLayer("1", false)); |
| 250 | simulcast.send_layers().AddLayer(SimulcastLayer("2", false)); |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 251 | TestSerialization(simulcast, "send 1;2"); |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | // Test serialization with only receive streams |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 255 | TEST_F(SimulcastSdpSerializerTest, Serialize_OnlyReceive) { |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 256 | SimulcastDescription simulcast; |
| 257 | simulcast.receive_layers().AddLayer(SimulcastLayer("1", false)); |
| 258 | simulcast.receive_layers().AddLayer(SimulcastLayer("2", false)); |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 259 | TestSerialization(simulcast, "recv 1;2"); |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | // Test a complex serialization with multiple streams, alternatives and states. |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 263 | TEST_F(SimulcastSdpSerializerTest, Serialize_ComplexSerialization) { |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 264 | 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 Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 276 | TestSerialization(simulcast, "send 2,~1;4,3 recv 6,7;~8;9,~10,11"); |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame^] | 279 | class 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. |
| 304 | TEST_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. |
| 310 | TEST_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. |
| 316 | TEST_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. |
| 323 | TEST_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. |
| 331 | TEST_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. |
| 340 | TEST_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. |
| 351 | TEST_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. |
| 362 | TEST_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. |
| 368 | TEST_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. |
| 374 | TEST_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. |
| 381 | TEST_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. |
| 388 | TEST_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. |
| 395 | TEST_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. |
| 407 | TEST_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. |
| 415 | TEST_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. |
| 425 | TEST_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. |
| 439 | TEST_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. |
| 446 | TEST_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. |
| 453 | const 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 | |
| 474 | INSTANTIATE_TEST_CASE_P(RidDescriptionDeserializationErrors, |
| 475 | RidDescriptionSdpSerializerTest, |
| 476 | ValuesIn(kRidDescriptionMalformedStrings)); |
| 477 | |
Amit Hilbuch | a201204 | 2018-12-03 11:35:05 -0800 | [diff] [blame] | 478 | } // namespace webrtc |