public void ErrorOpenNoCallback() { var stuff = BluetopiaTesting.InitMockery_Client(new ClientTestingBluetopia.Behaviour()); // const int hConn = 99; // var cli = stuff.CreateBluetoothClient(); var cli2 = (BluetopiaClient)cli; var conn = (BluetopiaRfcommStream)cli2.Testing_GetConn(); // Expect.Once.On(stuff.MockedApi).Method("SPP_Open_Remote_Port") .With(stuff.StackId, ClientTesting.Addr1Long, ClientTesting.Port5Uint, (InTheHand.Net.Bluetooth.StonestreetOne.NativeMethods.SPP_Event_Callback) conn.HandleSPP_Event_Callback, (uint)0) .Will(Return.Value(hConn)); // var remote = new BluetoothEndPoint(ClientTesting.Addr1, BluetoothService.Empty, ClientTesting.Port5); var ar = cli.BeginConnect(remote, null, null); stuff.Mockery_VerifyAllExpectationsHaveBeenMet(); ClientTesting.Assert_IsConnected( ClientTesting.IsConnectedState.Closed, conn, cli, "after"); Assert.IsFalse(ar.IsCompleted, "ar.IsCompleted after"); // Expect.Once.On(stuff.MockedApi).Method("SPP_Close_Port") .With(stuff.StackId, conn.Testing_GetPortId()) .Will(Return.Value(BluetopiaError.OK)); cli.Dispose(); stuff.Mockery_VerifyAllExpectationsHaveBeenMet(); }
//[Obsolete] //internal static StuffClient Open(bool toPortNumber, // bool endConnectSuccess, int? socketError, // StackConsts.SPP_OPEN_PORT_STATUS connConfStatusCode) //{ // return Open(new Behaviour // { // //toPortNumber = toPortNumber, // EndConnectSuccess = endConnectSuccess, // SocketError = socketError, // ConnConfStatusCode = connConfStatusCode, // }); //} internal static StuffClientBluetopia CreateClient(Behaviour behaviour) { var stuff = BluetopiaTesting.InitMockery_Client(behaviour); // var cli = stuff.CreateBluetoothClient(); var cli2 = (BluetopiaClient)cli; var conn = (BluetopiaRfcommStream)cli2.Testing_GetConn(); stuff.SetDut(cli, conn); return(stuff); }
public void Properties() { var stuff = BluetopiaTesting.InitMockery_Client(new ClientTestingBluetopia.Behaviour()); var cli = stuff.CreateBluetoothClient(); // //Assert.IsFalse(cli.Authenticate, "Authenticate"); //try { // cli.Authenticate = true; // Assert.Fail("should have thrown!"); //} catch (NotSupportedException) { } //// //Assert.IsFalse(cli.Encrypt, "Encrypt"); //try { // cli.Encrypt = true; // Assert.Fail("should have thrown!"); //} catch (NotSupportedException) { } // try { var s = cli.Client; Assert.Fail("should have thrown!"); } catch (NotSupportedException) { } var sock = new System.Net.Sockets.Socket( System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Unspecified); try { cli.Client = sock; Assert.Fail("should have thrown!"); } catch (NotSupportedException) { } finally { sock.Close(); } // stuff.Mockery_VerifyAllExpectationsHaveBeenMet(); }
public void ErrorOnCallOpenRemotePort() { var stuff = BluetopiaTesting.InitMockery_Client(new ClientTestingBluetopia.Behaviour()); // Expect.Once.On(stuff.MockedApi).Method("SPP_Open_Remote_Port") .WithAnyArguments() .Will(Return.Value((int)BluetopiaError.INTERNAL_ERROR)); // var cli = stuff.CreateBluetoothClient(); var remote = new BluetoothEndPoint(ClientTesting.Addr1, BluetoothService.Empty, ClientTesting.Port5); try { var ar = cli.BeginConnect(remote, null, null); cli.EndConnect(ar); // NEW Assert.Fail("should have thrown!"); } catch (BluetopiaSocketException) { // TODO SocketError check } stuff.Mockery_VerifyAllExpectationsHaveBeenMet(); // cli.Dispose(); stuff.Mockery_VerifyAllExpectationsHaveBeenMet(); }
public void One() { var stuff = BluetopiaTesting.InitMockery_Client(new ClientTestingBluetopia.Behaviour()); // const uint NullPeriodLengths = 0; const uint InquiryLen = 12; const uint CallbackParameter = 0; const uint MaximumResponses = 255; var callback = stuff.GetFactory()._inquiryEventCallback; Expect.Once.On(stuff.MockedApi).Method("GAP_Perform_Inquiry") .With(stuff.StackId, StackConsts.GAP_Inquiry_Type.GeneralInquiry, NullPeriodLengths, NullPeriodLengths, InquiryLen, MaximumResponses, callback, CallbackParameter) .Will(Return.Value(BluetopiaError.OK)); // IBluetoothClient cli = stuff.CreateBluetoothClient(); var ar = cli.BeginDiscoverDevices(255, false, false, false, true, null, null); Assert.IsFalse(ar.IsCompleted, "IsCompleted 0"); // IntPtr pItemData = IntPtr.Zero; IntPtr pCompleteData = IntPtr.Zero; try { Structs.GAP_Inquiry_Entry_Event_Data itemData = new Structs.GAP_Inquiry_Entry_Event_Data( Addr1Bytes, new byte[] { 0x03, 0x02, 0x01 } ); pItemData = Marshal.AllocHGlobal(Marshal.SizeOf(itemData)); Marshal.StructureToPtr(itemData, pItemData, false); Structs.GAP_Event_Data item1 = new Structs.GAP_Event_Data( StackConsts.GAP_Event_Type.Inquiry_Entry_Result, pItemData); // const ushort NumDevices = 1; Structs.GAP_Inquiry_Event_Data completeData = new Structs.GAP_Inquiry_Event_Data( NumDevices /*, pCompleteDeviceData*/); pCompleteData = Marshal.AllocHGlobal(Marshal.SizeOf(completeData)); Marshal.StructureToPtr(completeData, pCompleteData, false); Structs.GAP_Event_Data complete = new Structs.GAP_Event_Data( StackConsts.GAP_Event_Type.Inquiry_Result, pCompleteData); // // using (var done = new ManualResetEvent(false)) { ThreadPool.QueueUserWorkItem(delegate { try { callback(stuff.StackId, ref item1, CallbackParameter); callback(stuff.StackId, ref complete, CallbackParameter); } finally { done.Set(); } }); bool signalled = done.WaitOne(30000); Debug.Assert(signalled, "NOT signalled"); } } finally { if (pItemData != IntPtr.Zero) { Marshal.FreeHGlobal(pItemData); } if (pCompleteData != IntPtr.Zero) { Marshal.FreeHGlobal(pCompleteData); } } // Thread.Sleep(200); Assert.IsFalse(ar.IsCompleted, "notIsCompleted2 before rnr"); Thread.Sleep(2500); // Space for (possible!) name queries Thread.Sleep(200); Assert.IsTrue(ar.IsCompleted, "IsCompleted3"); var deviceList = cli.EndDiscoverDevices(ar); Assert.AreEqual(1, deviceList.Length, "deviceList.Length"); var dev = deviceList[0]; Assert.AreEqual(BluetoothAddress.Parse("001122334455"), dev.DeviceAddress, "dev.DeviceAddress"); Assert.AreEqual(new ClassOfDevice(0x010203), dev.ClassOfDevice, "dev.ClassOfDevice"); // stuff.Mockery_VerifyAllExpectationsHaveBeenMet(); }