예제 #1
0
        public void ZeroHandleReturned()
        {
            var       listAllocs = new List <IntPtr>();
            var       stuff      = BluetopiaSdpParseTests.Create_BluetopiaSdpQuery();
            const int TheirRequestId_InvalidZero = 0;

            //
            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_InvalidZero));
            try {
                var ar = stuff.DutSdpQuery.BeginQuery(Addr2, SvcClass2, false,
                                                      null, null);
                Assert.Fail("should have thrown!");
            } catch (SocketException) {
            }
        }
예제 #2
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);
        }
예제 #3
0
        internal static StuffClientBluetopia DoOpen(StuffClientBluetopia stuff, Action beforeEndConnect)
        {
            var cli       = stuff.DutClient;
            var cli2      = (BluetopiaClient)cli;
            var conn      = (BluetopiaRfcommStream)cli2.Testing_GetConn();
            var behaviour = stuff.Behaviour;
            //
            BluetoothEndPoint remote;

            if (behaviour.ToPortNumber)
            {
                remote = new BluetoothEndPoint(Addr1, BluetoothService.Empty, Port5);
            }
            else
            {
                remote = new BluetoothEndPoint(Addr1, BluetoothService.VideoSource);
            }
            //
            bool ourCallbackCalled = false;
            var  ourCallback       = (AsyncCallback) delegate { ourCallbackCalled = true; };
            //
            var ar = cli.BeginConnect(remote, ourCallback, null);

            Assert_IsConnected(
                IsConnectedState.Closed,
                conn, cli, "BB");
            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
            //
            Assert_IsConnected(
                IsConnectedState.Closed,
                conn, cli, "CC0");
            if (behaviour.SdpQueryResultPort.HasValue)
            {
                var listAllocs = new List <IntPtr>();
                IntPtr /*"SDP_Response_Data *"*/ pSdp = BluetopiaSdpParseTests
                                                        .ProtoDListMake_InSDPResponse_Data(listAllocs, behaviour.SdpQueryResultPort.Value);
                var  sdpQuery          = cli2.Testing_GetSdpQuery();
                uint SDPRequestID      = 0;
                uint CallbackParameter = 0;
                //
                stuff.AddExpectOpenRemotePort(null, null);
                // TODO raise callback on thread pool
                sdpQuery.HandleSDP_Response_Callback(stuff.StackId, SDPRequestID,
                                                     pSdp, CallbackParameter);
                BluetopiaSdpParseTests.Free(listAllocs);
                Thread.Sleep(2000);//HACK
            }
            //
            Assert_IsConnected(
                IsConnectedState.Closed,
                conn, cli, "CC");
            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
            var openConfData = new Structs.SPP_Open_Port_Confirmation_Data(
                conn.Testing_GetPortId(), behaviour.ConnConfStatusCode);

            using (var ctor = new SppEventCreator()) {
                Structs.SPP_Event_Data eventData = ctor.CreateOpenConfirmation(
                    conn.Testing_GetPortId(), behaviour.ConnConfStatusCode);
                RaiseSppEvent(stuff, eventData);
            }
            SafeWait(ar); //NEW
            Assert_IsConnected(
                behaviour.EndConnectSuccess ? IsConnectedState.Connected : IsConnectedState.Closed,
                conn, cli, "DD");
            Assert.IsTrue(ar.IsCompleted, "ar.IsCompleted before");
            if (beforeEndConnect != null)
            {
                beforeEndConnect();
            }
            if (behaviour.EndConnectSuccess)
            {
                Debug.Assert(!behaviour.SocketError.HasValue, "Behaviour settings: Success BUT errorCode!!");
                cli.EndConnect(ar);
            }
            else
            {
                Debug.Assert(behaviour.SocketError.HasValue, "Behaviour settings: not Success BUT NO errorCode!!");
                try {
                    cli.EndConnect(ar);
                    Assert.Fail("should have thrown!");
                } catch (SocketException ex) {
                    //TODO Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode, "SocketErrorCode");
                    Assert.AreEqual(behaviour.SocketError ?? 0, ex.ErrorCode, "(Socket)ErrorCode");
                }
            }
            Thread.Sleep(200); // let the async async-callback run
            Assert.IsTrue(ourCallbackCalled, "ourCallbackCalled");
            //
            if (behaviour.EndConnectSuccess)
            {
                Assert_IsConnected(
                    IsConnectedState.Connected,
                    conn, cli, "DD2");
                BluetoothEndPoint expectedRemote = new BluetoothEndPoint(Addr1, BluetoothService.Empty, Port5);
                Assert.AreEqual(expectedRemote, cli.RemoteEndPoint, "cli.RemoteEndPoint");
            }
            //
            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
            return(stuff);
        }