Ejemplo n.º 1
0
        public void WritePartAaaa()
        {
            var stuff = ClientTestingBluetopia.Open();

            Assert.IsNotNull(stuff.DutClient, "DutClient");
            Assert.IsNotNull(stuff.DutConn, "DutConn");
            //
            byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xA };
            Expect.Once.On(stuff.MockedApi).Method("SPP_Data_Write")
            .With(stuff.StackId, stuff.DutConn.Testing_GetPortId(),
                  (ushort)buf.Length, buf)
            .Will(Return.Value(5));
            var ar = stuff.DutConn.BeginWrite(buf, 0, buf.Length, null, null);

            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
            Assert.IsFalse(ar.IsCompleted, "IsCompleted mid");
            //
            // Spp_Write is blocked
            Thread.Sleep(100);
            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
            //
            byte[] buf2 = { 6, 7, 8, 9, 0xA };
            ClientTestingBluetopia.ExpectWrite(stuff, buf2, buf2.Length);
            using (var ctor = new SppEventCreator()) {
                var eventData = ctor.CreateWriteEmpty(stuff.DutConn.Testing_GetPortId());
                ClientTestingBluetopia.RaiseSppEvent(stuff, eventData);
            }
            Thread.Sleep(100);
            Assert.IsTrue(ar.IsCompleted, "IsCompleted end");
            //
            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
            ClientTestingBluetopia.Close(stuff);
        }
Ejemplo n.º 2
0
        public void OpenToService_SdpMethodError()
        {
            bool doExplicitDispose = true;
            bool endConnectSuccess = false;
            int? socketError       = null;

            StackConsts.SPP_OPEN_PORT_STATUS connConfStatusCode = StackConsts.SPP_OPEN_PORT_STATUS.ConnectionTimeout;
            StuffClientBluetopia             stuff = null;

            try {
                stuff = ClientTestingBluetopia.Open(//false, endConnectSuccess, socketError, connConfStatusCode);
                    new ClientTestingBluetopia.Behaviour
                {
                    ToPortNumber       = false,
                    EndConnectSuccess  = endConnectSuccess,
                    SocketError        = socketError,
                    ConnConfStatusCode = connConfStatusCode,
                    SdpMethodResult    = (int)BluetopiaError.SDP_NOT_INITIALIZED
                });
                Assert.Fail("not implemented yey -- should have thrown!");
            } catch (SocketException) {
                // TODO SocketError check
            }
            if (stuff != null)
            {
                ClientTestingBluetopia.Close(stuff, doExplicitDispose, endConnectSuccess, connConfStatusCode);
            }
        }
Ejemplo n.º 3
0
        //--------
        internal static void OpenAndClose_(bool doExplicitDispose,
                                           bool endConnectSuccess, int?socketError, StackConsts.SPP_OPEN_PORT_STATUS connConfStatusCode)
        {
            StuffClientBluetopia stuff = ClientTestingBluetopia.Open(//true, endConnectSuccess, socketError, connConfStatusCode);
                new ClientTestingBluetopia.Behaviour
            {
                ToPortNumber       = true,
                EndConnectSuccess  = endConnectSuccess,
                SocketError        = socketError,
                ConnConfStatusCode = connConfStatusCode
            });

            ClientTestingBluetopia.Close(stuff, doExplicitDispose, endConnectSuccess, connConfStatusCode);
        }
Ejemplo n.º 4
0
        //--------
        private StuffClientBluetopia OpenAndRemoteClose_()
        {
            var stuff = ClientTestingBluetopia.Open(//true, true, null, StackConsts.SPP_OPEN_PORT_STATUS.Success);
                new ClientTestingBluetopia.Behaviour
            {
                ToPortNumber       = true,
                EndConnectSuccess  = true,
                SocketError        = null,
                ConnConfStatusCode = StackConsts.SPP_OPEN_PORT_STATUS.Success
            });

            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
            //
            ClientTestingBluetopia.RaiseRemoteClose(stuff);
            return(stuff);
        }
Ejemplo n.º 5
0
        public void OpenAndRemoteClose_AndWrite()
        {
            var stuff = OpenAndRemoteClose_();

            byte[] buf  = new byte[10];
            var    peer = stuff.DutClient.GetStream();

            try {
                peer.Write(buf, 0, buf.Length);
            } catch (IOException) {
                // TODO IOException check
            }
            ClientTestingBluetopia.Assert_IsConnected(ClientTestingBluetopia.IsConnectedState.Closed,
                                                      stuff.DutConn, stuff.DutClient, "after remote close");
            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 6
0
        public void RealGsrOne()
        {
            var listAllocs = new List <IntPtr>();
            var stuff      = BluetopiaSdpParseTests.Create_BluetopiaSdpQuery();
            var dutBdi     = (BluetopiaDeviceInfo)stuff.GetFactory().DoGetBluetoothDeviceInfo(Addr2);

            stuff.SetDut(dutBdi.Testing_GetSdpQuery());
            Debug.Assert(stuff.DutSdpQuery != null, "NULL stuff.DutSdpQuery");
            //const uint OurRequestId = 0 + 1;
            const byte Port           = 17;
            const int  TheirRequestId = 100;

            //
            Expect.Once.On(stuff.MockedApi).Method("SDP_Service_Search_Attribute_Request")
            //TODO With(...Is.Anything,...)*/
            /**/.With(stuff.StackId,
                      Addr2Long,
                                   //Is.Anything,//new byte[6],
                                   //--
                      (uint)1,
                      Is.Anything, //new Structs.SDP_UUID_Entry[1],
                                   //--
                      (uint)1,
                      Is.Anything, //new Structs.SDP_Attribute_ID_List_Entry[1],
                                   //--
                      new InTheHand.Net.Bluetooth.StonestreetOne.NativeMethods
                      .SDP_Response_Callback(stuff.DutSdpQuery.HandleSDP_Response_Callback),
                      Is.Anything //OurRequestId
                      )           /**/
            .Will(Return.Value(TheirRequestId));
            var ar = dutBdi.BeginGetServiceRecords(SvcClass2,
                                                   null, null);

            //
            Assert.IsFalse(ar.IsCompleted, "IsCompleted before event");
            ClientTestingBluetopia.RaiseSdpEvent(stuff,
                                                 BluetopiaSdpParseTests.ProtoDListMake_InSDPResponse_Data(listAllocs, Port), TheirRequestId);
            //
            ClientTestingBluetopia.SafeWait(ar);
            Assert.IsTrue(ar.IsCompleted, "IsCompleted after event");
            ServiceRecord[] rList = dutBdi.EndGetServiceRecords(ar);
            BluetopiaSdpParseTests.Free(listAllocs);
            //
            BluetopiaSdpParseTests.ProtoDList_Assert(rList[0][0], Port);
        }
Ejemplo n.º 7
0
        private static byte[] SendReceiveTen(StuffClientBluetopia stuff)
        {
            byte[] srcBuf             = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xA };
            bool   isMustBeSameLength = false;
            int    sizeOfReaderBuffer = 10;

            Expect.Once.On(stuff.MockedApi).Method("SPP_Data_Read")
            .With(stuff.StackId, stuff.DutConn.Testing_GetPortId(),
                  (ushort)sizeOfReaderBuffer, new byte[sizeOfReaderBuffer])
            .Will(Return.Value(srcBuf.Length),
                  FillArrayIndexedParameterAction.Fill(3, srcBuf, isMustBeSameLength));
            using (var ctor = new SppEventCreator()) {
                var eventData = ctor.CreateDataIndication(stuff.DutConn.Testing_GetPortId(), srcBuf.Length);
                ClientTestingBluetopia.RaiseSppEvent(stuff, eventData);
            }
            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
            return(srcBuf);
        }
Ejemplo n.º 8
0
        public void WriteAllAaaa()
        {
            var stuff = ClientTestingBluetopia.Open();

            Assert.IsNotNull(stuff.DutClient, "DutClient");
            Assert.IsNotNull(stuff.DutConn, "DutConn");
            //
            Expect.Once.On(stuff.MockedApi).Method("SPP_Data_Write")
            .With(stuff.StackId, stuff.DutConn.Testing_GetPortId(),
                  (ushort)10, new byte[10])
            .Will(Return.Value(10));
            byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xA };
            buf = new byte[10];
            stuff.DutConn.Write(buf, 0, buf.Length);
            //
            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
            ClientTestingBluetopia.Close(stuff);
        }
Ejemplo n.º 9
0
        public void ReadAfter()
        {
            var stuff = ClientTestingBluetopia.Open();

            Assert.IsNotNull(stuff.DutClient, "DutClient");
            Assert.IsNotNull(stuff.DutConn, "DutConn");
            //
            byte[] srcBuf = SendReceiveTen(stuff);
            //
            byte[] buf     = new byte[100];
            int    readLen = stuff.DutConn.Read(buf, 0, buf.Length);

            Assert.AreEqual(10, readLen, "readLen");
            Assert2.AreEqual_Buffers(srcBuf, buf, 0, readLen, "buf content");
            //
            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
            ClientTestingBluetopia.Close(stuff);
        }
Ejemplo n.º 10
0
        public void OpenAndRemoteClose_AndBeginReadOverClose()
        {
            var stuff = ClientTestingBluetopia.Open();

            byte[] buf  = new byte[10];
            var    peer = stuff.DutClient.GetStream();
            var    ar   = peer.BeginRead(buf, 0, buf.Length, null, null);

            ClientTestingBluetopia.RaiseRemoteClose(stuff);
            int readLen = peer.EndRead(ar);

            Assert.AreEqual(0, readLen);
            //Assert.Ignore("Apparently we don't go Closed in this case......");
            //Assert_IsConnected(IsConnectedState.Closed, stuff.DutConn, stuff.DutClient, "after remote close");
            ClientTestingBluetopia.Assert_IsConnected(ClientTestingBluetopia.IsConnectedState.RemoteCloseAndBeforeAnyIOMethod,
                                                      stuff.DutConn, stuff.DutClient, "after remote close");
            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 11
0
        public void OpenToService()
        {
            bool doExplicitDispose = true;

            StackConsts.SPP_OPEN_PORT_STATUS connConfStatusCode = StackConsts.SPP_OPEN_PORT_STATUS.Success;
            StuffClientBluetopia             stuff = null;

            stuff = ClientTestingBluetopia.Open(
                new ClientTestingBluetopia.Behaviour
            {
                ToPortNumber       = false,
                EndConnectSuccess  = true,
                ConnConfStatusCode = connConfStatusCode,
                SdpMethodResult    = 543,
                SdpQueryResultPort = 5
            });
            ClientTestingBluetopia.Close(stuff, doExplicitDispose, true, connConfStatusCode);
        }
Ejemplo n.º 12
0
        public void OpenAndRemoteClose_AndBeginWriteOverClose()
        {
            var stuff = ClientTestingBluetopia.Open();

            byte[] buf  = new byte[10];
            var    peer = stuff.DutClient.GetStream();

            ClientTestingBluetopia.ExpectWrite(stuff, buf, buf.Length);
            var ar = peer.BeginWrite(buf, 0, buf.Length, null, null);

            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
            //
            ClientTestingBluetopia.RaiseRemoteClose(stuff);
            try {
                peer.EndWrite(ar);
            } catch (IOException) {
                // TODO IOException check
            }
            ClientTestingBluetopia.Assert_IsConnected(ClientTestingBluetopia.IsConnectedState.RemoteCloseAndBeforeAnyIOMethod,
                                                      stuff.DutConn, stuff.DutClient, "after remote close");
            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 13
0
        public void ReadBeginBefore()
        {
            var stuff = ClientTestingBluetopia.Open();

            Assert.IsNotNull(stuff.DutClient, "DutClient");
            Assert.IsNotNull(stuff.DutConn, "DutConn");
            //
            byte[] buf = new byte[100];
            var    ar  = stuff.DutConn.BeginRead(buf, 0, buf.Length, null, null);

            Assert.IsFalse(ar.IsCompleted);
            //
            byte[] srcBuf = SendReceiveTen(stuff);
            //
            Assert.IsTrue(ar.IsCompleted);
            int readLen = stuff.DutConn.EndRead(ar);

            Assert.AreEqual(10, readLen, "readLen");
            Assert2.AreEqual_Buffers(srcBuf, buf, 0, readLen, "buf content");
            //
            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
            ClientTestingBluetopia.Close(stuff);
        }
Ejemplo n.º 14
0
        public void ReadBeginBeforeTwoParts()
        {
            var stuff = ClientTestingBluetopia.Open();

            Assert.IsNotNull(stuff.DutClient, "DutClient");
            Assert.IsNotNull(stuff.DutConn, "DutConn");
            //
            byte[] buf  = new byte[100];
            byte[] buf2 = new byte[100];
            var    ar   = stuff.DutConn.BeginRead(buf, 0, 5, null, null);
            var    ar2  = stuff.DutConn.BeginRead(buf2, 0, buf2.Length, null, null);

            Assert.IsFalse(ar.IsCompleted);
            Assert.IsFalse(ar2.IsCompleted);
            //
            byte[] srcBuf = SendReceiveTen(stuff);
            //
            byte[] srcBufPart1 = new byte[5];
            Array.Copy(srcBuf, 0, srcBufPart1, 0, srcBufPart1.Length);
            byte[] srcBufPart2 = new byte[5];
            Array.Copy(srcBuf, srcBufPart1.Length, srcBufPart2, 0, srcBufPart2.Length);
            //
            Assert.IsTrue(ar.IsCompleted);
            Assert.IsTrue(ar2.IsCompleted);
            int readLen = stuff.DutConn.EndRead(ar);

            Assert.AreEqual(5, readLen, "readLen");
            Assert2.AreEqual_Buffers(srcBufPart1, buf, 0, readLen, "buf content Part1");
            int readLen2 = stuff.DutConn.EndRead(ar);

            Assert.AreEqual(5, readLen, "readLen");
            Assert2.AreEqual_Buffers(srcBufPart2, buf2, 0, readLen2, "buf content Part2");
            //
            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
            ClientTestingBluetopia.Close(stuff);
        }