示例#1
0
        public void InitError()
        {
            var mocks = new Mockery();
            var api   = mocks.NewMock <IBluetopiaApi>();

            // Second time after try-kill BTExplorer.exe
            Expect.Exactly(2).On(api).Method("BSC_Initialize")
            .WithAnyArguments()      // TO-DO
            .Will(Return.Value((int)BluetopiaError.UNSUPPORTED_PLATFORM_ERROR));
            //----
            try {
                BluetopiaTesting.HackAllowShutdownCall(api);
                BluetopiaFactory fcty = new BluetopiaFactory(api);
                Assert.Fail("should have thrown!");
            } catch (BluetopiaSocketException ex) {
                Assert.AreEqual((int)BluetopiaError.UNSUPPORTED_PLATFORM_ERROR, ex.BluetopiaErrorCode, "BluetopiaErrorCode");
                Assert.AreEqual(BluetopiaError.UNSUPPORTED_PLATFORM_ERROR.ToString(), ex.BluetopiaError, "BluetopiaError");
                Assert.AreEqual(
                    // was: "An operation was attempted on something that is not a socket"
                    "The attempted operation is not supported for the type of object referenced"
                    + " (Bluetopia: UNSUPPORTED_PLATFORM_ERROR (-101)).",
                    ex.Message, "Message");
            }
            //
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
示例#2
0
 public BluetopiaFactory GetFactory(IBluetopiaSecurity optionalSecurityInstance)
 {
     if (_fcty == null)
     {
         _fcty = new BluetopiaFactory(this.MockedApi, optionalSecurityInstance);
     }
     BluetopiaTesting.HackAllowShutdownCall(this.MockedApi);
     return(_fcty);
 }
示例#3
0
        static StuffRadio Create_Radio_A(Params p)
        {
            var stuff = new StuffRadio();
            //.
            const uint StackId         = 1;
            var        addrBytes       = new byte[] { 0xA4, 0x24, 0x4C, 0x98, 0x24, 0x08 };
            var        ExpectedAddress = BluetoothAddress.Parse("08:24:98:4C:24:A4");
            var        nameBytes       = new byte[] { (byte)'A', (byte)'b', (byte)'c', 0 };
            var        ExpectedName    = "Abc";
            var        codStruct       = (uint)0x20104;
            var        ExpectedCod     = new ClassOfDevice(0x20104);

            //
            BluetopiaTesting.InitMockery(stuff, StackId);
            Expect.Once.On(stuff.MockedApi).Method("GAP_Query_Local_BD_ADDR")
            .With(StackId, new byte[6])
            .Will(
                FillArrayIndexedParameterAction.Fill(1, addrBytes, true),
                Return.Value(BluetopiaError.OK));
            Expect.Once.On(stuff.MockedApi).Method("GAP_Query_Local_Device_Name")
            .With(StackId, 248, new byte[248])
            .Will(
                FillArrayIndexedParameterAction.Fill(2, nameBytes, false),
                Return.Value(BluetopiaError.OK));
            Expect.Once.On(stuff.MockedApi).Method("GAP_Query_Class_Of_Device")
            .With(StackId, Is.Out)
            .Will(
                new SetIndexedParameterAction(1, codStruct),
                Return.Value(BluetopiaError.OK));
            if (p.AccessesVersionsOrManufacturer)
            {
                Expect.Once.On(stuff.MockedApi).Method("HCI_Read_Local_Version_Information")
                .With(StackId,
                      Is.Out, Is.Out, Is.Out, Is.Out, Is.Out, Is.Out)
                .Will(
                    new SetIndexedParameterAction(1, (StackConsts.HCI_ERROR_CODE) 0),
                    new SetIndexedParameterAction(2, (HciVersion)0),
                    new SetIndexedParameterAction(3, (UInt16)0),
                    new SetIndexedParameterAction(4, (LmpVersion)0),
                    new SetIndexedParameterAction(5, Manufacturer.Zeevo),
                    new SetIndexedParameterAction(6, (UInt16)0),
                    Return.Value(BluetopiaError.OK));
            }
            //--
            BluetopiaTesting.HackAllowShutdownCall(stuff.MockedApi);
            BluetopiaFactory fcty = new BluetopiaFactory(stuff.MockedApi);
            IBluetoothRadio  r    = stuff.Radio = fcty.DoGetPrimaryRadio();

            Assert.AreEqual(Manufacturer.StonestreetOne, r.SoftwareManufacturer, "SoftwareManufacturer");
            Assert.AreEqual(ExpectedAddress, r.LocalAddress, "LocalAddress");
            Assert.AreEqual(ExpectedName, r.Name, "Name");
            Assert.AreEqual(ExpectedCod, r.ClassOfDevice, "ClassOfDevice");
            //
            return(stuff);
        }
示例#4
0
        //[Explicit("Causes Debug.Assert")]
        public void InitZeroHandle()
        {
            const uint BadZeroStackId = 0;
            var        mocks          = new Mockery();
            var        api            = mocks.NewMock <IBluetopiaApi>();

            Expect.Exactly(2).On(api).Method("BSC_Initialize")
            .WithAnyArguments()      // TO-DO
            .Will(Return.Value((int)BadZeroStackId));
            //----
            try {
                BluetopiaTesting.HackAllowShutdownCall(api);
                BluetopiaFactory fcty = new BluetopiaFactory(api);
                Assert.Fail("should have thrown!");
            } catch (BluetopiaSocketException ex) {
                Assert.AreEqual((int)BluetopiaError.OK, ex.BluetopiaErrorCode, "BluetopiaErrorCode");
                Assert.AreEqual(BluetopiaError.OK.ToString(), ex.BluetopiaError, "BluetopiaError");
            }
            //
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
示例#5
0
 public TestBluetopiaSdpCreator(BluetopiaFactory fcty)
     : base(fcty)
 {
     _fcty = fcty;
 }