示例#1
0
        public void TestSocketReadWithBytesToSkipTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testReceive =
                "            SUBSCRIBE sip:[email protected] SIP/2.0" + CRLF +
                "Via: SIP/2.0/TCP 10.1.1.5:62647;branch=z9hG4bKa58b912c426f415daa887289efda50cd;rport" + CRLF +
                "To: <sip:[email protected]>" + CRLF +
                "From: <sip:[email protected]>;tag=1902440575" + CRLF +
                "Call-ID: 1b569032-d1e4-4869-be9f-67d4ba8a4e3a" + CRLF +
                "CSeq: 3 SUBSCRIBE" + CRLF +
                "Contact: <sip:10.1.1.5:62647;transport=tcp>" + CRLF +
                "Max-Forwards: 70" + CRLF +
                "Expires: 600" + CRLF +
                "Content-Length: 15" + CRLF +
                "Content-Type: text/text" + CRLF +
                "Event: dialog" +
                CRLF + CRLF +
                "includesdp=true";

            byte[] testReceiveBytes = UTF8Encoding.UTF8.GetBytes(testReceive);

            SIPConnection testConnection = new SIPConnection(null, null, (Stream)null, new IPEndPoint(IPAddress.Loopback, 0), SIPProtocolsEnum.tcp, SIPConnectionsEnum.Caller);
            int           sipMessages    = 0;

            testConnection.SIPMessageReceived += (chan, ep, buffer) => { sipMessages++; };
            Array.Copy(testReceiveBytes, testConnection.SocketBuffer, testReceiveBytes.Length);

            bool result = testConnection.SocketReadCompleted(testReceiveBytes.Length);

            Assert.IsTrue(result, "The result from processing the socket read should have been true.");
            Assert.IsTrue(sipMessages == 1, "The number of SIP messages parsed was incorrect, was " + sipMessages + ".");
            Assert.IsTrue(testConnection.SocketBufferEndPosition == 0, "The receive buffer end position was incorrect, was " + testConnection.SocketBufferEndPosition + ".");
        }
示例#2
0
        public void TestSocketReadSingleMessageTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testReceive =
                @"SUBSCRIBE sip:[email protected] SIP/2.0" + CRLF +
                "Via: SIP/2.0/TCP 10.1.1.5:62647;branch=z9hG4bKa58b912c426f415daa887289efda50cd;rport" + CRLF +
                "To: <sip:[email protected]>" + CRLF +
                "From: <sip:[email protected]>;tag=1902440575" + CRLF +
                "Call-ID: 1b569032-d1e4-4869-be9f-67d4ba8a4e3a" + CRLF +
                "CSeq: 3 SUBSCRIBE" + CRLF +
                "Contact: <sip:10.1.1.5:62647;transport=tcp>" + CRLF +
                "Max-Forwards: 70" + CRLF +
                "Expires: 600" + CRLF +
                "Content-Length: 15" + CRLF +
                "Content-Type: text/text" + CRLF +
                "Event: dialog" + CRLF +
                CRLF +
                "includesdp=true";

            byte[] testReceiveBytes = UTF8Encoding.UTF8.GetBytes(testReceive);

            SIPConnection testConnection = new SIPConnection(null, null, (Stream)null, null, SIPProtocolsEnum.tcp, SIPConnectionsEnum.Caller);

            Array.Copy(testReceiveBytes, testConnection.SocketBuffer, testReceiveBytes.Length);

            bool result = testConnection.SocketReadCompleted(testReceiveBytes.Length);

            Assert.IsTrue(result, "The result of processing the receive should have been true.");
            Assert.IsTrue(testConnection.SocketBufferEndPosition == 0, "The receive buffer end position should have been 0.");
        }
        public void TestSocketReadWithTwoMessagesAndBytesToSkipTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testReceive =
            @"            SUBSCRIBE sip:[email protected] SIP/2.0" + CRLF +
            "Via: SIP/2.0/TCP 10.1.1.5:62647;branch=z9hG4bKa58b912c426f415daa887289efda50cd;rport" + CRLF +
            "To: <sip:[email protected]>" + CRLF +
            "From: <sip:[email protected]>;tag=1902440575" + CRLF +
            "Call-ID: 1b569032-d1e4-4869-be9f-67d4ba8a4e3a" + CRLF +
            "CSeq: 3 SUBSCRIBE" + CRLF +
            "Contact: <sip:10.1.1.5:62647;transport=tcp>" + CRLF +
            "Max-Forwards: 70" + CRLF +
            "Expires: 600" + CRLF +
            "Content-Length: 15" + CRLF +
            "Content-Type: text/text" + CRLF +
            "Event: dialog" +
            CRLF + CRLF +
            "includesdp=true       " +
            CRLF +
            " SUBSCRIBE sip:[email protected] SIP/2.0" + CRLF +
            "Via: SIP/2.0/TCP 10.1.1.5:62647;branch=z9hG4bKa58b912c426f415daa887289efda50cd;rport" + CRLF +
            "To: <sip:[email protected]>" + CRLF +
            "From: <sip:[email protected]>;tag=1902440575" + CRLF +
            "Call-ID: 1b569032-d1e4-4869-be9f-67d4ba8a4e3a" + CRLF +
            "CSeq: 3 SUBSCRIBE" + CRLF
            + CRLF +
            "SUBSCRIBE sip:[email protected]";

            byte[] testReceiveBytes = UTF8Encoding.UTF8.GetBytes(testReceive);

            SIPConnection testConnection = new SIPConnection(null, null, (Stream)null, new IPEndPoint(IPAddress.Loopback, 0), SIPProtocolsEnum.tcp, SIPConnectionsEnum.Caller);
            int sipMessages = 0;
            testConnection.SIPMessageReceived += (chan, ep, buffer) => { sipMessages++; };
            Array.Copy(testReceiveBytes, testConnection.SocketBuffer, testReceiveBytes.Length);

            bool result = testConnection.SocketReadCompleted(testReceiveBytes.Length);
            string remainingBytes = Encoding.UTF8.GetString(testConnection.SocketBuffer, 0, testConnection.SocketBufferEndPosition);

            Console.WriteLine("SocketBufferEndPosition=" + testConnection.SocketBufferEndPosition + ".");
            Console.WriteLine("SocketBuffer=" + remainingBytes + ".");

            Assert.IsTrue(result, "The result from processing the socket read should have been true.");
            Assert.IsTrue(sipMessages == 2, "The number of SIP messages parsed was incorrect.");
            Assert.AreEqual(26, testConnection.SocketBufferEndPosition, "The receive buffer end position was incorrect.");
            Assert.IsTrue(remainingBytes == "SUBSCRIBE sip:[email protected]", "The leftover bytes in the socket buffer were incorrect.");
        }
        public void TestSocketReadSingleMessageTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testReceive =
            @"SUBSCRIBE sip:[email protected] SIP/2.0" + CRLF +
            "Via: SIP/2.0/TCP 10.1.1.5:62647;branch=z9hG4bKa58b912c426f415daa887289efda50cd;rport" + CRLF +
            "To: <sip:[email protected]>" + CRLF +
            "From: <sip:[email protected]>;tag=1902440575" + CRLF +
            "Call-ID: 1b569032-d1e4-4869-be9f-67d4ba8a4e3a" + CRLF +
            "CSeq: 3 SUBSCRIBE" + CRLF +
            "Contact: <sip:10.1.1.5:62647;transport=tcp>" + CRLF +
            "Max-Forwards: 70" + CRLF +
            "Expires: 600" + CRLF +
            "Content-Length: 15" + CRLF +
            "Content-Type: text/text" + CRLF +
            "Event: dialog" + CRLF +
            CRLF +
            "includesdp=true";

            byte[] testReceiveBytes = UTF8Encoding.UTF8.GetBytes(testReceive);

            SIPConnection testConnection = new SIPConnection(null, null, (Stream)null, null, SIPProtocolsEnum.tcp, SIPConnectionsEnum.Caller);
            Array.Copy(testReceiveBytes, testConnection.SocketBuffer, testReceiveBytes.Length);

            bool result = testConnection.SocketReadCompleted(testReceiveBytes.Length);

            Assert.IsTrue(result, "The result of processing the receive should have been true.");
            Assert.IsTrue(testConnection.SocketBufferEndPosition == 0, "The receive buffer end position should have been 0.");
        }