From fa0bb8aa54c4b258b05452cc2e5edc3884fb07a1 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Mon, 5 Oct 2020 23:44:09 +0200 Subject: [PATCH] Added tests for SDP --- .gitignore | 3 +- test/zutil/parser/sdp/SDPParserTest.java | 109 ++++++++++++++++++ .../parser/sdp/SessionDescriptionTest.java | 101 ++++++++++++++++ 3 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 test/zutil/parser/sdp/SDPParserTest.java create mode 100644 test/zutil/parser/sdp/SessionDescriptionTest.java diff --git a/.gitignore b/.gitignore index 2860d98..41fec87 100755 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ /build/ /bin/ /target/ -/target/ +/gradle/ +/.gradle/ /.repository/ /.flattened-pom.xml diff --git a/test/zutil/parser/sdp/SDPParserTest.java b/test/zutil/parser/sdp/SDPParserTest.java new file mode 100644 index 0000000..68931a9 --- /dev/null +++ b/test/zutil/parser/sdp/SDPParserTest.java @@ -0,0 +1,109 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2020 Ziver Koc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package zutil.parser.sdp; + +import org.junit.Test; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class SDPParserTest { + +/* +"v=0\n" + +"o=mhandley 2890844526 2890842807 IN IP4 126.16.64.4\n" + +"s=SDP Seminar\n" + +"i=A Seminar on the session description protocol\n" + +"u=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps\n" + +"e=mjh@isi.edu (Mark Handley)\n" + +"c=IN IP4 224.2.17.12/127" + +"t=2873397496 2873404696\n" + +"a=recvonly\n" + +"m=audio 49170 RTP/AVP 0\n" + +"m=video 51372 RTP/AVP 31\n" + +"m=application 32416 udp wb\n" + +"a=orient:portrait"; +*/ + + @Test + public void basicSessionInfo() throws IOException { + String description = + "v=0\n" + + "o=mhandley 2890844526 2890842807 IN IP4 126.16.64.4\n" + + "s=SDP Seminar\n" + + "i=A Seminar on the session description protocol\n" + + "u=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps\n" + + "e=mjh@isi.edu (Mark Handley)\n" + + "c=IN IP4 224.2.17.12/127"; + + SDPParser parser = new SDPParser(description); + List sessions = parser.parse(); + + assertEquals(1, sessions.size()); + + SessionDescription session = sessions.get(0); + assertEquals(0, session.getProtocolVersion()); + assertEquals("SDP Seminar", session.getSessionTitle()); + assertEquals("A Seminar on the session description protocol", session.getSessionDescription()); + assertEquals("http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps", session.getSessionURI()); + assertEquals("mjh@isi.edu (Mark Handley)", session.getOrganizerEmail()); + } + + @Test + public void basicTimingInfo() throws IOException { + String description = "v=0\n" + + "s=SDP Seminar\n" + + "t=2873397496 2873404696"; + + SDPParser parser = new SDPParser(description); + List sessions = parser.parse(); + + assertEquals(1, sessions.get(0).getTimings().size()); + TimingDescription timing = sessions.get(0).getTimings().get(0); + + assertEquals(timing.getStartTime(), 2873397496l); + assertEquals(timing.getEndTime(), 2873404696l); + } + + @Test + public void basicMediaInfo() throws IOException { + String description = "v=0\n" + + "s=SDP Seminar\n" + + "m=video 51372 RTP/AVP 31\n" + + "i=main video feed"; + + SDPParser parser = new SDPParser(description); + List sessions = parser.parse(); + + assertEquals(1, sessions.get(0).getMedia().size()); + MediaDescription media = sessions.get(0).getMedia().get(0); + + assertEquals(media.getType(), "video"); + assertEquals(media.getTransportPort(), 51372); + assertEquals(media.getTransport(), "RTP/AVP"); + } +} \ No newline at end of file diff --git a/test/zutil/parser/sdp/SessionDescriptionTest.java b/test/zutil/parser/sdp/SessionDescriptionTest.java new file mode 100644 index 0000000..d38362e --- /dev/null +++ b/test/zutil/parser/sdp/SessionDescriptionTest.java @@ -0,0 +1,101 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2020 Ziver Koc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package zutil.parser.sdp; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class SessionDescriptionTest { + + // TODO: o=
+ // TODO: [optional] i= + // TODO: [optional] u= + // TODO: [optional] e= + // TODO: [optional] p= + // TODO: [optional] c=
// Session overall connection information + + // -------------------------------------- + // Time description + // -------------------------------------- + + // TODO: [optional] b=: + // TODO: [optional] z= .... // Time zone adjustments + // TODO: [optional] k=: // Encryption information + // TODO: [optional] a=: + + // -------------------------------------- + // Media description + // -------------------------------------- + + @Test + public void basicSession() { + SessionDescription session = new SessionDescription(); + session.protocolVersion = 0; + session.sessionTitle = "SDP Seminar"; + + assertEquals(session.toString(), "v=0\n" + + "s=SDP Seminar" + ); + } + + @Test + public void basicTiming() { + TimingDescription timing = new TimingDescription(); + timing.startTime = 2873397496l; + timing.endTime = 2873404696l; + + SessionDescription session = new SessionDescription(); + session.protocolVersion = 0; + session.sessionTitle = "SDP Seminar"; + session.timings.add(timing); + + assertEquals(session.toString(), "v=0\n" + + "s=SDP Seminar\n" + + "t=2873397496 2873404696" + ); + } + + @Test + public void basicMedia() { + MediaDescription media = new MediaDescription(); + media.type = "video"; + media.transportPort = 51372; + media.transport = "RTP/AVP"; + media.label = "main video feed"; + + SessionDescription session = new SessionDescription(); + session.protocolVersion = 0; + session.sessionTitle = "SDP Seminar"; + session.media.add(media); + + assertEquals(session.toString(), "v=0\n" + + "s=SDP Seminar\n" + + "m=video 51372 RTP/AVP\n" + + "i=main video feed" + ); + } + +} \ No newline at end of file