From b493db9b4d0456de62c0b7d8636661fc25224cba Mon Sep 17 00:00:00 2001 From: Philipp Hancke Date: Thu, 8 Dec 2022 12:46:20 +0100 Subject: [PATCH] sdp: add tests for ParseMsidAttribute increasing the line coverage to 100%. Note that code coverage is still a very basic metric and the tests still do not enforce the length of the attributes nor their token-char-ness defined in https://www.rfc-editor.org/rfc/rfc8830.html#section-2 BUG=webrtc:14745 Change-Id: If5de5e1f8c32f7dae029916c6cd0a4f2b094f672 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/286900 Commit-Queue: Philipp Hancke Reviewed-by: Harald Alvestrand Reviewed-by: Florent Castelli Cr-Commit-Position: refs/heads/main@{#38864} --- pc/webrtc_sdp_unittest.cc | 89 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/pc/webrtc_sdp_unittest.cc b/pc/webrtc_sdp_unittest.cc index b176c008ab..9f1cfc9c96 100644 --- a/pc/webrtc_sdp_unittest.cc +++ b/pc/webrtc_sdp_unittest.cc @@ -4116,6 +4116,67 @@ TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithMissingTrackId) { EXPECT_FALSE(SdpDeserialize(sdp, &jdesc_output)); } +TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithoutColon) { + std::string sdp = + "v=0\r\n" + "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" + "s=-\r\n" + "t=0 0\r\n" + "m=audio 9 RTP/SAVPF 111\r\n" + "c=IN IP4 0.0.0.0\r\n" + "a=rtpmap:111 opus/48000/2\r\n" + "a=msid\r\n"; + + JsepSessionDescription jdesc_output(kDummyType); + EXPECT_FALSE(SdpDeserialize(sdp, &jdesc_output)); +} + +TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithoutAttributes) { + std::string sdp = + "v=0\r\n" + "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" + "s=-\r\n" + "t=0 0\r\n" + "m=audio 9 RTP/SAVPF 111\r\n" + "c=IN IP4 0.0.0.0\r\n" + "a=rtpmap:111 opus/48000/2\r\n" + "a=msid:\r\n"; + + JsepSessionDescription jdesc_output(kDummyType); + EXPECT_FALSE(SdpDeserialize(sdp, &jdesc_output)); +} + +TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithTooManySpaces) { + std::string sdp = + "v=0\r\n" + "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" + "s=-\r\n" + "t=0 0\r\n" + "m=audio 9 RTP/SAVPF 111\r\n" + "c=IN IP4 0.0.0.0\r\n" + "a=rtpmap:111 opus/48000/2\r\n" + "a=msid:stream_id track_id bogus\r\n"; + + JsepSessionDescription jdesc_output(kDummyType); + EXPECT_FALSE(SdpDeserialize(sdp, &jdesc_output)); +} + +TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithDifferentTrackIds) { + std::string sdp = + "v=0\r\n" + "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" + "s=-\r\n" + "t=0 0\r\n" + "m=audio 9 RTP/SAVPF 111\r\n" + "c=IN IP4 0.0.0.0\r\n" + "a=rtpmap:111 opus/48000/2\r\n" + "a=msid:stream_id track_id\r\n" + "a=msid:stream_id2 track_id2\r\n"; + + JsepSessionDescription jdesc_output(kDummyType); + EXPECT_FALSE(SdpDeserialize(sdp, &jdesc_output)); +} + TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithoutAppData) { std::string sdp = "v=0\r\n" @@ -4217,6 +4278,34 @@ TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithoutAppDataMixed) { EXPECT_EQ(stream.id, "track_id"); } +TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithoutAppDataMixed2) { + std::string sdp = + "v=0\r\n" + "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" + "s=-\r\n" + "t=0 0\r\n" + "m=audio 9 RTP/SAVPF 111\r\n" + "c=IN IP4 0.0.0.0\r\n" + "a=rtpmap:111 opus/48000/2\r\n" + "a=msid:stream_id track_id\r\n" + "a=msid:stream_id2\r\n"; + + JsepSessionDescription jdesc_output(kDummyType); + // Mixing the syntax like this is not a good idea but we accept it + // and the result is the second track_id. + EXPECT_TRUE(SdpDeserialize(sdp, &jdesc_output)); + auto stream = jdesc_output.description() + ->contents()[0] + .media_description() + ->streams()[0]; + ASSERT_EQ(stream.stream_ids().size(), 2u); + EXPECT_EQ(stream.stream_ids()[0], "stream_id"); + EXPECT_EQ(stream.stream_ids()[1], "stream_id2"); + + // Track id is taken from first line. + EXPECT_EQ(stream.id, "track_id"); +} + TEST_F(WebRtcSdpTest, DeserializeMsidAttributeWithoutAppDataMixedNoStream) { std::string sdp = "v=0\r\n"