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 <phancke@microsoft.com>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38864}
This commit is contained in:
Philipp Hancke 2022-12-08 12:46:20 +01:00 committed by WebRTC LUCI CQ
parent 2bfa767245
commit b493db9b4d

View File

@ -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"