public void TwoDiscosConcurrently_lattersGetFirstsInquiredList_basedOnTestOne()
        {
            TestInquiryBtIf btIf;
            BluetoothClient cli;

            //
            Create_BluetoothClient(out btIf, out cli);
            Assert.IsFalse(btIf.testDoCallbacksFromWithinStartInquiry, "tdcfwsi");
            ThreadStart dlgt = delegate {
                bool signalled = btIf.startInquiryCalled.WaitOne(10000, false);
                Assert.IsTrue(signalled, "!signalled!!!!!");
                btIf.InquiryEventsOne();
            };

            WidcommBluetoothClient.ReadKnownDeviceFromTheRegistry = false;
            // We really should test with two BtCli instances but that's a bit hard to set-up.
            IAsyncResult ar1         = cli.BeginDiscoverDevices(255, true, true, true, false, null, null);
            IAsyncResult ar2         = cli.BeginDiscoverDevices(255, true, true, true, false, null, null);
            IAsyncResult arDlgt      = Delegate2.BeginInvoke(dlgt, null, null);
            bool         signalledAr = _WaitAll(new WaitHandle[] { ar1.AsyncWaitHandle, ar2.AsyncWaitHandle }, 15000);

            Assert.IsTrue(signalledAr, "signalledAr");
            BluetoothDeviceInfo[] devices1 = cli.EndDiscoverDevices(ar1);
            BluetoothDeviceInfo[] devices2 = cli.EndDiscoverDevices(ar2);
            Delegate2.EndInvoke(dlgt, arDlgt); // any exceptions?
            VerifyDevicesOne(devices1);
            VerifyDevicesOne(devices2);
            Assert.AreEqual(1, btIf.stopInquiryCalled, "stopInquiryCalled");
        }
        public void One_CompletedEventLateOrNeverComes_ButHasTimeout()
        {
            TestInquiryBtIf btIf;
            BluetoothClient cli;

            //
            Create_BluetoothClient(out btIf, out cli);
            cli.InquiryLength = TimeSpan.FromMilliseconds(750);
            //
            Assert.IsFalse(btIf.testDoCallbacksFromWithinStartInquiry, "tdcfwsi");
            ThreadStart dlgt = delegate {
                bool signalled = btIf.startInquiryCalled.WaitOne(10000, false);
                Assert.IsTrue(signalled, "!signalled!!!!!");
                btIf.InquiryEventsOne_WithNoCompletedEvent();
            };
            IAsyncResult arDlgt = Delegate2.BeginInvoke(dlgt, null, null);

            //
            WidcommBluetoothClient.ReadKnownDeviceFromTheRegistry = false;
            Assert.IsTrue(cli.InquiryLength.CompareTo(TimeSpan.Zero) > 0, "blehhhhhhhhhhhhhhhhhhhhhh");
            IAsyncResult arDD = cli.BeginDiscoverDevices(255, true, true, true, false, null, null);
            // Timeout Killer occurs 1.5 times the InquiryLength, 1125ms
            bool completed = arDD.AsyncWaitHandle.WaitOne(1500, false);

            Assert.IsTrue(completed, "Unexpected DD time-out.");
            BluetoothDeviceInfo[] devices = cli.EndDiscoverDevices(arDD);
            Delegate2.EndInvoke(dlgt, arDlgt); // any exceptions?
            VerifyDevicesOne(devices);
            Assert.AreEqual(1, btIf.stopInquiryCalled, "stopInquiryCalled");
        }
        public void One_TimeoutSet_ButCompletesBeforeTimeout()
        {
            TestInquiryBtIf btIf;
            BluetoothClient cli;

            //
            Create_BluetoothClient(out btIf, out cli);
            cli.InquiryLength = TimeSpan.FromSeconds(1);
            //
            Assert.IsFalse(btIf.testDoCallbacksFromWithinStartInquiry, "tdcfwsi");
            ThreadStart dlgt = delegate {
                bool signalled = btIf.startInquiryCalled.WaitOne(10000, false);
                Assert.IsTrue(signalled, "!signalled!!!!!");
                btIf.InquiryEventsOne();
            };
            IAsyncResult arDlgt = Delegate2.BeginInvoke(dlgt, null, null);

            //
            WidcommBluetoothClient.ReadKnownDeviceFromTheRegistry = false;
            BluetoothDeviceInfo[] devices = cli.DiscoverDevices();
            Delegate2.EndInvoke(dlgt, arDlgt); // any exceptions?
            VerifyDevicesOne(devices);
            Assert.AreEqual(1, btIf.stopInquiryCalled, "stopInquiryCalled");
            // Wait around, trying to see any exception on the timeout thread.
            Thread.Sleep(1650);
        }
        // With default non-infinite InquiryLength, test now no correct.[Test]
        public void One_CompletedEventLateOrNeverComes()
        {
            TestInquiryBtIf btIf;
            BluetoothClient cli;

            //
            Create_BluetoothClient(out btIf, out cli);
            Assert.IsFalse(btIf.testDoCallbacksFromWithinStartInquiry, "tdcfwsi");
            ThreadStart dlgt = delegate {
                bool signalled = btIf.startInquiryCalled.WaitOne(10000, false);
                Assert.IsTrue(signalled, "!signalled!!!!!");
                btIf.InquiryEventsOne_WithNoCompletedEvent();
            };
            IAsyncResult arDlgt = Delegate2.BeginInvoke(dlgt, null, null);

            //
            WidcommBluetoothClient.ReadKnownDeviceFromTheRegistry = false;
            Assert.IsTrue(cli.InquiryLength.CompareTo(TimeSpan.Zero) < 0, "Excepted infinite InquiryLength, but was: " + cli.InquiryLength);
            IAsyncResult arDD      = cli.BeginDiscoverDevices(255, true, true, true, false, null, null);
            bool         completed = arDD.AsyncWaitHandle.WaitOne(1 * 1000, false);

            Assert.IsFalse(completed, "Expected DD to time-out.");
            // NON USEFUL/WOULD BLOCK
            //BluetoothDeviceInfo[] devices = cli.EndDiscoverDevices(arDD);
            Delegate2.EndInvoke(dlgt, arDlgt); // any exceptions?
            //VerifyDevicesOne(devices);
            //Assert.AreEqual(1, btIf.stopInquiryCalled, "stopInquiryCalled");
        }
        public void Ebap_TwoWithSecondNameEvent()
        {
            TestInquiryBtIf btIf;
            BluetoothClient cli;

            //
            Create_BluetoothClient(out btIf, out cli);
            Assert.IsFalse(btIf.testDoCallbacksFromWithinStartInquiry, "tdcfwsi");
            ThreadStart dlgt = delegate {
                bool signalled = btIf.startInquiryCalled.WaitOne(10000, false);
                Assert.IsTrue(signalled, "!signalled!!!!!");
                btIf.InquiryEventsTwoWithSecondNameEvent();
            };
            IAsyncResult arDlgt = Delegate2.BeginInvoke(dlgt, null, null);

            //
            WidcommBluetoothClient.ReadKnownDeviceFromTheRegistry = false;
            var bc           = new BluetoothComponent(cli);
            var devicesSteps = new List <BluetoothDeviceInfo[]>();

            BluetoothDeviceInfo[] devicesResult = null;
            var complete = new ManualResetEvent(false);

            bc.DiscoverDevicesProgress += delegate(object sender, DiscoverDevicesEventArgs e) {
                devicesSteps.Add(e.Devices);
            };
            bc.DiscoverDevicesComplete += delegate(object sender, DiscoverDevicesEventArgs e) {
                try {
                    devicesResult = e.Devices;
                } finally {
                    complete.Set();
                }
            };
            bc.DiscoverDevicesAsync(255, true, true, true, false, 999);
            bool signalled2 = complete.WaitOne(15000);

            Assert.IsTrue(signalled2, "signalled2");
            Delegate2.EndInvoke(dlgt, arDlgt); // any exceptions?
            VerifyDevicesOne(devicesResult);
            Assert.AreEqual(3, devicesSteps.Count);
            Assert.AreEqual(1, devicesSteps[0].Length, "[0].Len");
            Assert.AreEqual(AddressA, devicesSteps[0][0].DeviceAddress, "[0][0].Addr");
            Assert.AreEqual(AddressA.ToString("C"), devicesSteps[0][0].DeviceName, "[0][0].Name"); // no name
            Assert.AreEqual(1, devicesSteps[1].Length, "[1].Len");
            Assert.AreEqual(AddressB, devicesSteps[1][0].DeviceAddress, "[1][0].Addr");
            Assert.AreEqual(NameB, devicesSteps[1][0].DeviceName, "[1][0].Name");
            Assert.AreEqual(1, devicesSteps[2].Length, "[2].Len");
            Assert.AreEqual(AddressA, devicesSteps[2][0].DeviceAddress, "[2][0].Addr");
            Assert.AreEqual(NameA, devicesSteps[2][0].DeviceName, "[2][0].Name");
            Assert.AreEqual(1, btIf.stopInquiryCalled, "stopInquiryCalled");
        }
Пример #6
0
        int EndTimedRead(object ar)
        {
#if false
            IAsyncResult             ar2  = (IAsyncResult)ar;
            Func <Stream, bool, int> dlgt = (Func <Stream, bool, int>)ar2.AsyncState;
            int period = dlgt.EndInvoke(ar2);
            return(period);
#else
            IAsyncResult ar2 = (IAsyncResult)ar;
            //Func<Stream, bool, int> dlgt = (Func<Stream, bool, int>)ar2.AsyncState;
            //Func<int> dlgt0 = null;
            Func <int> dlgt0  = (Func <int>)ar2.AsyncState;
            int        period = Delegate2.EndInvoke(dlgt0, ar2);
            return(period);
#endif
        }
        void _EventsOccurWithNoPrecedingDiscoverDevicesCall_WithNoCompletedEvent(
            TestInquiryBtIf btIf, BluetoothClient cli)
        {
            Assert.IsFalse(btIf.testDoCallbacksFromWithinStartInquiry, "tdcfwsi");
            ThreadStart dlgt = delegate {
                bool signalled = btIf.startInquiryCalled.WaitOne(0, false);
                Assert.IsFalse(signalled, "!signalled_A!!!!!");
                btIf.InquiryEventsOne_WithNoCompletedEvent();
                signalled = btIf.startInquiryCalled.WaitOne(0, false);
                Assert.IsFalse(signalled, "!signalled_B!!!!!");
            };
            IAsyncResult arDlgt = Delegate2.BeginInvoke(dlgt, null, null);

            //
            WidcommBluetoothClient.ReadKnownDeviceFromTheRegistry = false;
            Delegate2.EndInvoke(dlgt, arDlgt); // any exceptions?
            Assert.AreEqual(0, btIf.stopInquiryCalled, "stopInquiryCalled");
        }
Пример #8
0
        private void DoTestStartStop(BluetoothListener lsnr)
        {
            Action <BluetoothListener> dlgt = Foo;
            ThreadStart dlgt0 = delegate { dlgt(lsnr); };

            //
            lsnr.Start();
            IAsyncResult ar0 = Delegate2.BeginInvoke(dlgt0, null, null);

            Assert.IsFalse(ar0.IsCompleted);
            //
            lsnr.Stop();
            System.Threading.Thread.Sleep(50);
            Assert.IsTrue(ar0.IsCompleted);
            try {
                Delegate2.EndInvoke(dlgt0, ar0);
            } catch (System.Reflection.TargetInvocationException tex) {
                Assert.IsInstanceOfType(typeof(System.Net.Sockets.SocketException), tex.InnerException, "InnerException");
            }
        }
        public void TwoWithSecondNameEvent()
        {
            TestInquiryBtIf btIf;
            BluetoothClient cli;

            //
            Create_BluetoothClient(out btIf, out cli);
            Assert.IsFalse(btIf.testDoCallbacksFromWithinStartInquiry, "tdcfwsi");
            ThreadStart dlgt = delegate {
                bool signalled = btIf.startInquiryCalled.WaitOne(10000, false);
                Assert.IsTrue(signalled, "!signalled!!!!!");
                btIf.InquiryEventsTwoWithSecondNameEvent();
            };
            IAsyncResult arDlgt = Delegate2.BeginInvoke(dlgt, null, null);

            //
            WidcommBluetoothClient.ReadKnownDeviceFromTheRegistry = false;
            BluetoothDeviceInfo[] devices = cli.DiscoverDevices();
            Delegate2.EndInvoke(dlgt, arDlgt); // any exceptions?
            VerifyDevicesOne(devices);
            Assert.AreEqual(1, btIf.stopInquiryCalled, "stopInquiryCalled");
        }
        public void StartInquiryFails_ThenTestOne()
        {
            TestInquiryBtIf btIf;
            BluetoothClient cli;

            //
            Create_BluetoothClient(out btIf, out cli);
            Assert.IsFalse(btIf.testDoCallbacksFromWithinStartInquiry, "tdcfwsi");
            //
            btIf.startInquiryFails = true;
            try {
                BluetoothDeviceInfo[] devicesX = cli.DiscoverDevices();
                Assert.Fail("should have thrown!");
            } catch (System.Net.Sockets.SocketException) {
            }
            bool signalled1 = btIf.startInquiryCalled.WaitOne(0, false);

            Assert.IsTrue(signalled1, "!signalled_a!!!!!");
            //
            btIf.startInquiryCalled.Reset();
            btIf.startInquiryFails = false;
            //
            ThreadStart dlgt = delegate {
                bool signalled = btIf.startInquiryCalled.WaitOne(10000, false);
                Assert.IsTrue(signalled, "!signalled!!!!!");
                btIf.InquiryEventsOne();
            };
            IAsyncResult arDlgt = Delegate2.BeginInvoke(dlgt, null, null);

            //
            WidcommBluetoothClient.ReadKnownDeviceFromTheRegistry = false;
            IAsyncResult arDD = cli.BeginDiscoverDevices(255, true, true, true, true, null, null);

            TestsApmUtils.SafeNoHangWait(arDD, "DiscoverDevices");
            BluetoothDeviceInfo[] devices = cli.EndDiscoverDevices(arDD);
            Delegate2.EndInvoke(dlgt, arDlgt); // any exceptions?
            VerifyDevicesOne(devices);
            Assert.AreEqual(1, btIf.stopInquiryCalled, "stopInquiryCalled");
        }
Пример #11
0
        public void WritePartials_Write()
        {
            TestRfcommPort  port;
            BluetoothClient cli;
            Stream          strm;

            Create_ConnectedBluetoothClient_WritePartialsAcceptHalf_WriteEventAfterEachWrite(out port, out cli, out strm);
            //
            // 'Long', zero offset.
            strm.Write(Data30, 0, Data30.Length);
            port.AssertWrittenContentAndClear("30", SplitToLimits(Data30));
            port.ClearWrittenContent();
            //

            /*            // 'Long', non-zero offset.
             *          strm.Write(Data50_offset5, Data50_offset5_Offset, dataA.Length);
             *          port.AssertWrittenContentAndClear("50_offset5", dataA);
             *          port.ClearWrittenContent();     */
            // TODO 'Long', large non-zero offset.
            //int newOffset = UInt16.MaxValue + 20;
            //byte[] data30_OffsetOver16k = ShiftToOffset(dataA, newOffset);
            //strm.Write(data30_OffsetOver16k, newOffset, dataA.Length);
            //port.AssertWrittenContentAndClear("30_offsetOver16k", dataA);
            //// Large (zero offset).
            //byte[] dataOver16K = CreateData(UInt16.MaxValue + 100);
            //strm.Write(dataOver16K, 0, dataOver16K.Length);
            //byte[] b1 = new byte[UInt16.MaxValue];
            //byte[] b2 = new byte[dataOver16K.Length - UInt16.MaxValue];
            //Array.Copy(dataOver16K, 0, b1, 0, UInt16.MaxValue);
            //Array.Copy(dataOver16K, UInt16.MaxValue, b2, 0, dataOver16K.Length - UInt16.MaxValue);
            //port.AssertWrittenContentAndClear("Over16k", b1, b2);
            //
            byte[][] chunks;
            //
            // Large (zero offset).
            byte[]      dataOver16K        = CreateData(UInt16.MaxValue + 100);
            byte[]      dataOver16K_writer = (byte[])dataOver16K.Clone();
            ThreadStart action             = delegate {
                strm.Write(dataOver16K_writer, 0, dataOver16K_writer.Length);
            };
            IAsyncResult ar = Delegate2.BeginInvoke(action, null, null);

            Assert.IsFalse(ar.IsCompleted, "dataOver16K--IsComplete before #1");
            Thread.Sleep(200);                         // do we have to wrry that the Write thread not been called yet
            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)");
            Delegate2.EndInvoke(action, ar);
            // check data written
            // TO CHECK assert checks data correctly:: dataOver16K[5] = 0;
            List <byte[]> chunksList = new List <byte[]>();

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