예제 #1
0
        public void testMakeMessage_string_BlockingSCTPStream()
        {
            Console.WriteLine("---->makeMessage string");

            StringBuilder      rightout = new StringBuilder();
            SCTPStreamListener rsl      = new ASCTPStreamListenerImpl(rightout);

            DatagramTransport[]     trans         = mkMockTransports();
            MockAssociationListener listenLeft    = new MockAssociationListener();
            MockAssociationListener listenRight   = new MockAssociationListenerImpl(rsl);
            ThreadedAssociation     instanceLeft  = new ThreadedAssociation(trans[0], listenLeft);
            ThreadedAssociation     instanceRight = new ThreadedAssociation(trans[1], listenRight);

            instanceLeft.associate();
            lock (listenLeft) {
                Monitor.Wait(listenLeft, 2000);
                Assert.IsTrue(listenLeft.associated);
                Assert.IsTrue(listenRight.associated);
            }
            int        id = 10;
            SCTPStream s  = instanceLeft.mkStream(id);

            Assert.IsTrue(typeof(BlockingSCTPStream).IsAssignableFrom(s.GetType()));
            string      test = "Test message";
            SCTPMessage m    = instanceLeft.makeMessage(test, (BlockingSCTPStream)s);

            instanceLeft.sendAndBlock(m);
            lock (rightout) {
                Monitor.Wait(rightout, 2000);
                Assert.AreEqual(rightout.ToString(), test);
            }
        }
예제 #2
0
        public void testDCEPStreamSend()
        {
            Console.WriteLine("---->testDCEPStreamSend string");

            StringBuilder      rightout   = new StringBuilder();
            StringBuilder      rightLabel = new StringBuilder();
            SCTPStreamListener rsl        = new ASCTPStreamListenerImpl(rightout);

            DatagramTransport[]     trans         = mkMockTransports();
            MockAssociationListener listenLeft    = new MockAssociationListenerImpl2();
            MockAssociationListener listenRight   = new MockAssociationListenerImpl3(rightLabel, rsl);
            ThreadedAssociation     instanceLeft  = new ThreadedAssociation(trans[0], listenLeft);
            ThreadedAssociation     instanceRight = new ThreadedAssociation(trans[1], listenRight);

            instanceLeft.associate();
            lock (listenLeft) {
                Monitor.Wait(listenLeft, 2000);
                Assert.IsTrue(listenLeft.associated);
                Assert.IsTrue(listenRight.associated);
            }
            int        id    = 10;
            string     label = "test Stream";
            SCTPStream s     = instanceLeft.mkStream(id, label);

            lock (rightLabel) {
                Monitor.Wait(rightLabel, 2000);
                Assert.AreEqual(rightLabel.ToString(), label);
            }
            Assert.IsTrue(typeof(BlockingSCTPStream).IsAssignableFrom(s.GetType()));
            BlockingSCTPStream bs = (BlockingSCTPStream)s;
            StringBuilder      longTestMessage = new StringBuilder();

            for (int i = 0; i < 10000; i++)
            {
                longTestMessage.Append(" " + i);
            }
            string teststring = longTestMessage.ToString();

            Console.WriteLine("-------> string length = " + teststring.Length);
            Thread st = new Thread(() => {
                try {
                    s.send(teststring);
                }
                catch (Exception ex) {
                    Console.WriteLine(ex.ToString());
                }
            });

            st.Name = "sender ";
            st.Start();

            lock (rightout) {
                Monitor.Wait(rightout, 10000);
                Assert.AreEqual(teststring, rightout.ToString());
            }
        }
예제 #3
0
        public void testAssociate()
        {
            Console.WriteLine("--> associate");

            DatagramTransport[]     trans         = mkMockTransports();
            MockAssociationListener listenLeft    = new MockAssociationListener();
            MockAssociationListener listenRight   = new MockAssociationListener();
            ThreadedAssociation     instanceLeft  = new ThreadedAssociation(trans[0], listenLeft);
            ThreadedAssociation     instanceRight = new ThreadedAssociation(trans[1], listenRight);

            instanceLeft.associate();
            lock (listenLeft) {
                Monitor.Wait(listenLeft, 1000);
                Assert.IsTrue(listenLeft.associated);
                Assert.IsTrue(listenRight.associated);
            }
        }
예제 #4
0
        public void testMkStream()
        {
            Console.WriteLine("--> mkStream");

            DatagramTransport[]     trans         = mkMockTransports();
            MockAssociationListener listenLeft    = new MockAssociationListener();
            MockAssociationListener listenRight   = new MockAssociationListener();
            ThreadedAssociation     instanceLeft  = new ThreadedAssociation(trans[0], listenLeft);
            ThreadedAssociation     instanceRight = new ThreadedAssociation(trans[1], listenRight);

            instanceLeft.associate();
            lock (listenLeft) {
                Monitor.Wait(listenLeft, 1000);
                Assert.IsTrue(listenLeft.associated);
                Assert.IsTrue(listenRight.associated);
            }
            int        id     = 10;
            SCTPStream result = instanceLeft.mkStream(id);

            Assert.IsTrue(typeof(BlockingSCTPStream).IsAssignableFrom(result.GetType()));
        }
예제 #5
0
        public void testMakeMessage_byteArr_BlockingSCTPStream()
        {
            Console.WriteLine("---->makeMessage bytes");

            ByteBuffer             rightout = new ByteBuffer(new byte[10000]);
            StringBuilder          empty    = new StringBuilder();
            SCTPByteStreamListener rsl      = new SCTPByteStreamListenerImpl(empty, rightout);

            DatagramTransport[]     trans         = mkMockTransports();
            MockAssociationListener listenLeft    = new MockAssociationListener();
            MockAssociationListener listenRight   = new MockAssociationListenerImpl(rsl);
            ThreadedAssociation     instanceLeft  = new ThreadedAssociation(trans[0], listenLeft);
            ThreadedAssociation     instanceRight = new ThreadedAssociation(trans[1], listenRight);

            instanceLeft.associate();
            lock (listenLeft) {
                Monitor.Wait(listenLeft, 2000);
                Assert.IsTrue(listenLeft.associated);
                Assert.IsTrue(listenRight.associated);
            }
            int        id = 10;
            SCTPStream s  = instanceLeft.mkStream(id);

            Assert.IsTrue(typeof(BlockingSCTPStream).IsAssignableFrom(s.GetType()));
            string      test = "Test message";
            SCTPMessage m    = instanceLeft.makeMessage(test.getBytes(), (BlockingSCTPStream)s);

            instanceLeft.sendAndBlock(m);
            lock (rightout) {
                Monitor.Wait(rightout, 2000);
                int    l   = rightout.Position;
                string res = rightout.Data.getString(0, l);
                Assert.AreEqual(res, test);
                Assert.AreEqual(empty.Length, 0);
            }
        }