コード例 #1
0
ファイル: ThreadedAssociationTest.cs プロジェクト: sgf/SCTP
        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
ファイル: ThreadedAssociationTest.cs プロジェクト: sgf/SCTP
        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);
            }
        }
コード例 #3
0
ファイル: ThreadedAssociationTest.cs プロジェクト: sgf/SCTP
        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()));
        }
コード例 #4
0
ファイル: ThreadedAssociationTest.cs プロジェクト: sgf/SCTP
        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);
            }
        }