Пример #1
0
        private static void Create_BluetoothClient_WritePartialsAcceptHalfB(WidcommBtInterface btIface,
                                                                            out TestRfcommPort port, out BluetoothClient cli, out Stream strm2)
        {
            WidcommFactoryGivenInstances fcty = new WidcommFactoryGivenInstances();

            port = new TestRfcommPort_WritePartials_AcceptHalf();
            TestRfCommIf            rfCommIf = new TestRfCommIf();
            WidcommRfcommStreamBase strm     = new WidcommRfcommStream(port, rfCommIf, fcty);

            fcty.AddRfcommStream(strm);
            fcty.SetBtInterface(btIface);
            WidcommBluetoothClient wcli = new WidcommBluetoothClient(fcty);

            cli   = new BluetoothClient(wcli);
            strm2 = strm;
        }
Пример #2
0
        private byte[][] SplitToLimits(params byte[][] dataArrayArray)
        {
            List <byte[]> list = new List <byte[]>();

            foreach (byte[] data in dataArrayArray)
            {
                int pos = 0;
                while (pos < data.Length)
                {
                    ushort curLen_ = TestRfcommPort_WritePartials_AcceptHalf.LimitValue(data.Length - pos);
                    byte[] chunk   = new byte[curLen_];
                    Array.Copy(data, pos, chunk, 0, chunk.Length);
                    list.Add(chunk);
                    pos += chunk.Length;
                }
            }
            return(list.ToArray());
        }
Пример #3
0
        public void WritePartials_BeginWrite()
        {
            // xxQueue the un-accepted data, and send one block per TXEMPTY event, we
            // xxshould really try sending until
            //
            TestRfcommPort  port = new TestRfcommPort_WritePartials_AcceptHalf();
            BluetoothClient cli;
            Stream          strm;

            Create_ConnectedBluetoothClient_WritePartialsAcceptHalf(out port, out cli, out strm);
            //
            // 'Long', zero offset.
            IAsyncResult ar = strm.BeginWrite(Data30, 0, Data30.Length, null, null);

            Assert.IsFalse(ar.IsCompleted, "IsComplete before empty event(s)");
            port.AssertWrittenContent("20 of 30", First(Data30, 20));
            Assert.IsFalse(ar.IsCompleted, "IsComplete before empty event(s)");
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite); // TODO remove duplicates
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite);
            Assert.IsTrue(ar.IsCompleted, "IsComplete after empty event(s)");
            byte[][] chunks = SplitToLimits(Data30);
            port.AssertWrittenContent("all of 30", chunks);
            Assert.IsFalse(ar.CompletedSynchronously, "CompletedSynchronously");
            strm.EndWrite(ar);
            port.ClearWrittenContent();
            ar = null;
            //
            // 'Long', zero offset. Twice! Whilst first un-transmitted
            IAsyncResult ar1 = strm.BeginWrite(Data30, 0, Data30.Length, null, null); //**

            Assert.IsFalse(ar1.IsCompleted, "Twice--IsComplete before #1");
            port.AssertWrittenContent("20 of 30", First(Data30, 20));
            Assert.IsFalse(ar1.IsCompleted, "Twice--IsComplete before #2");
            IAsyncResult ar2 = strm.BeginWrite(Data30, 0, Data30.Length, null, null); //**

            Assert.IsFalse(ar2.IsCompleted, "Twice--IsComplete before #3");
            port.AssertWrittenContent("20 of 30", First(Data30, 20)); // No change
            Assert.IsFalse(ar1.IsCompleted, "Twice--IsComplete before #4");
            Assert.IsFalse(ar2.IsCompleted, "Twice--IsComplete before #5");
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite); // TODO remove duplicates
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite);
            Assert.IsTrue(ar1.IsCompleted, "IsComplete after empty event(s)");
            chunks = SplitToLimits(Data30, Data30);
            port.AssertWrittenContent("all of 30", chunks);
            Assert.IsFalse(ar1.CompletedSynchronously, "CompletedSynchronously ar1");
            Assert.IsFalse(ar2.CompletedSynchronously, "CompletedSynchronously ar2");
            strm.EndWrite(ar1);
            strm.EndWrite(ar2);
            port.ClearWrittenContent();
            ar1 = ar2 = null;
            //==========================================================
            // 'Long', non-zero offset.
            ar = strm.BeginWrite(Data30_offset5, Data30_offset5_Offset, Data30.Length, null, null);
            Assert.IsFalse(ar.IsCompleted, "long/offset--IsComplete before #1");
            port.AssertWrittenContent("30_offset5", SplitToLimits(Data30)[0]);
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite); // TODO remove duplicates
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite);
            Assert.IsTrue(ar.IsCompleted, "30/offset--IsComplete after empty event(s)");
            port.AssertWrittenContent("30/offset", SplitToLimits(Data30));
            Assert.IsFalse(ar.CompletedSynchronously, "CompletedSynchronously ar");
            strm.EndWrite(ar);
            port.ClearWrittenContent();
            ar = null;
            //
            // 'Long', large non-zero offset.
            int newOffset = UInt16.MaxValue + 20;

            byte[] data30_OffsetOver16k = ShiftToOffset(Data30, newOffset);
            ar = strm.BeginWrite(data30_OffsetOver16k, newOffset, Data30.Length, null, null);
            Assert.IsFalse(ar.IsCompleted, "long/offset--IsComplete before #1");
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite); // TODO remove duplicates
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite);
            Assert.IsTrue(ar.IsCompleted, "long/offset--IsComplete after empty event(s)");
            port.AssertWrittenContent("long/offset", SplitToLimits(Data30));
            Assert.IsFalse(ar.CompletedSynchronously, "CompletedSynchronously ar");
            strm.EndWrite(ar);
            port.ClearWrittenContent();
            ar = null;
            //
            // Large (zero offset).
            byte[] dataOver16K        = CreateData(UInt16.MaxValue + 100);
            byte[] dataOver16K_writer = (byte[])dataOver16K.Clone();
            ar = strm.BeginWrite(dataOver16K_writer, 0, dataOver16K_writer.Length, null, null);
            Assert.IsFalse(ar.IsCompleted, "dataOver16K--IsComplete before #1");
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite); // TODO remove duplicates
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite);
            port.NewEvent(EventThatFreesPendingWrite);
            Assert.IsTrue(ar.IsCompleted, "dataOver16K--IsComplete after empty event(s)");
            strm.EndWrite(ar);
            // check data written
            List <byte[]> chunksList = new List <byte[]>();

            chunksList.AddRange(SplitToLimits(dataOver16K));
            chunks = chunksList.ToArray();
            port.AssertWrittenContentAndClear("Over16k", chunks);
        }