public void StringGivenString() { ushort LangCodeEn = 0x656e; // "en" ushort LangCodeIs = 0x6973; // "is" ushort EncodingIdUtf8 = 106; ushort EncodingIdUtf16BE = 1013; ushort BaseA = 0x0100; ushort BaseB = 0x0100; // String str = "ambds\u2022nbdas\u00FEdlka\U00012004slkda"; ServiceElement element_ = new ServiceElement(ElementType.TextString, str); ServiceAttributeId id = ServiceRecord.CreateLanguageBasedAttributeId(UniversalAttributeId.ServiceName, (ServiceAttributeId)BaseA); ServiceAttribute attribute = new ServiceAttribute(id, element_); ServiceRecord record = CreateRecord(attribute); // LanguageBaseItem langBaseEn = new LanguageBaseItem(LangCodeEn, EncodingIdUtf8, BaseA); LanguageBaseItem langBaseIs = new LanguageBaseItem(LangCodeIs, EncodingIdUtf16BE, BaseB); Assert.AreEqual(str, record.GetMultiLanguageStringAttributeById( InTheHand.Net.Bluetooth.AttributeIds.UniversalAttributeId.ServiceName, langBaseEn)); Assert.AreEqual(str, record.GetMultiLanguageStringAttributeById( InTheHand.Net.Bluetooth.AttributeIds.UniversalAttributeId.ServiceName, langBaseIs)); // ServiceElement element = record.GetAttributeById(UniversalAttributeId.ServiceName, langBaseIs).Value; Assert.AreEqual(ElementTypeDescriptor.TextString, element.ElementTypeDescriptor); Assert.AreEqual(ElementType.TextString, element.ElementType); Assert.IsInstanceOfType(typeof(String), element.Value); Assert.AreEqual(str, element.GetValueAsStringUtf8()); Assert.AreEqual(str, element.GetValueAsString(Encoding.ASCII)); Assert.AreEqual(str, element.GetValueAsString(Encoding.Unicode)); }
public void NonExistingAttrById() { ServiceAttribute attr; ServiceRecord record = RecordAccess_Data.CreateRecordWithMultipleItems(); // attr = record.GetAttributeById(UniversalAttributeId.ServiceRecordState); }
public void AttrByIdAndLangNull() { ServiceAttribute attr; ServiceRecord record = RecordAccess_Data.CreateRecordWithZeroItems(); // attr = record.GetAttributeById(UniversalAttributeId.ServiceRecordHandle, null); }
public void AttrByIdAndLangFake() { ServiceAttribute attr; ServiceRecord record = RecordAccess_Data.CreateRecordWithZeroItems(); // LanguageBaseItem langFake = new LanguageBaseItem(1, 2, 3); attr = record.GetAttributeById(UniversalAttributeId.ServiceRecordHandle, langFake); }
public void AccessAttrById() { ServiceRecord record = RecordAccess_Data.CreateRecordWithMultipleItems(); // Assert.AreEqual(RecordAccess_Data.MultipleItemsCount, record.Count); // ServiceAttribute attr = record.GetAttributeById(UniversalAttributeId.ServiceRecordHandle); Assert.AreEqual(UniversalAttributeId.ServiceRecordHandle, attr.Id); Assert.AreEqual(ElementTypeDescriptor.UnsignedInteger, attr.Value.ElementTypeDescriptor); Assert.AreEqual(ElementType.UInt32, attr.Value.ElementType); Assert.AreEqual(66, attr.Value.Value); }
//---- public new void CreateServiceRecord(ServiceRecord record) { if (record == null) { throw new ArgumentNullException("record"); } if (_hSR.HasValue) { throw new InvalidOperationException("One at a time please."); } // ServiceElement svcIdListElement; var newList = new List <ServiceAttribute>(Math.Max(record.Count - 1, 0)); foreach (var cur in record) { if (cur.Id == UniversalAttributeId.ServiceClassIdList) { svcIdListElement = cur.Value; } else { newList.Add(cur); } } var newRecord = new ServiceRecord(newList); Debug.Assert(!newRecord.Contains(UniversalAttributeId.ServiceClassIdList), "DOES!! contain SvcIdList"); // Add the list of UUIDs var el = record.GetAttributeById(UniversalAttributeId.ServiceClassIdList).Value; var classList = el.GetValueAsElementList(); var svcIdListList = new Structs.SDP_UUID_Entry_Bytes[classList.Count]; for (int i = 0; i < svcIdListList.Length; ++i) { svcIdListList[i] = Structs.SDP_UUID_Entry_Bytes.Create(classList[i]); } Debug.Assert(svcIdListList.Length != 0, "Docs: 'the number of UUID Entries'...'CANNOT be zero'."); // int hSR = _fcty.Api.SDP_Create_Service_Record(_fcty.StackId, checked ((uint)svcIdListList.Length), svcIdListList); var ret = (BluetopiaError)hSR; BluetopiaUtils.CheckAndThrowZeroIsIllegal(ret, "SDP_Create_Service_Record"); _hSR = unchecked ((uint)hSR); // int count = base.CreateServiceRecord(newRecord, s_dummy); }
public void OneNoExtAttr() { var mocks = new Mockery(); var hackApi = mocks.NewMock <IBluesoleilApi>(); SetupNoSearchAppExtSPPService(hackApi); Expect.Never.On(hackApi).Method("Btsdk_FreeMemory"); // byte[] setSvcName = { (byte)'a', /* \u00E4 */ 0xC3, 0xA4, (byte)'b', (byte)'b', (byte)'c', (byte)'c', (byte)'d', (byte)'d' }; var attrs = new Structs.BtSdkRemoteServiceAttrStru(0, 0x1112, setSvcName, IntPtr.Zero); ServiceRecord sr = BluesoleilDeviceInfo.CreateServiceRecord(ref attrs, hackApi); // const string NewLine = "\r\n"; const string expectedDump = "AttrId: 0x0001 -- ServiceClassIdList" + NewLine + "ElementSequence" + NewLine + " Uuid16: 0x1112 -- HeadsetAudioGateway" + NewLine + NewLine + "AttrId: 0x0006 -- LanguageBaseAttributeIdList" + NewLine + "ElementSequence" + NewLine + " UInt16: 0x656E" + NewLine + " UInt16: 0x6A" + NewLine + " UInt16: 0x100" + NewLine + NewLine + "AttrId: 0x0100 -- ServiceName" + NewLine + "TextString: [en] 'a\u00E4bbccdd'" + NewLine + NewLine + "AttrId: 0xFFFF" + NewLine + "TextString (guessing UTF-8): '<partial BlueSoleil decode>'" + NewLine ; string dump = ServiceRecordUtilities.Dump(sr); Assert.AreEqual(expectedDump, dump, "dump"); // ServiceElement e; // e = sr.GetAttributeById(UniversalAttributeId.ServiceClassIdList).Value; ServiceElement eSvcClass = e.GetValueAsElementArray()[0]; UInt16 svcC = (UInt16)eSvcClass.Value; Assert.AreEqual(0x1112, svcC, "svcC"); // string sn = sr.GetPrimaryMultiLanguageStringAttributeById(UniversalAttributeId.ServiceName); Assert.AreEqual("a\u00E4bbccdd", sn, "sn"); //---- mocks.VerifyAllExpectationsHaveBeenMet(); }
public void OneNoExtAttr_ManualMock() { var hackApi = new TestSdBluesoleilApi(); byte[] setSvcName = Encoding.UTF8.GetBytes("aabbccdd"); var attrs = new Structs.BtSdkRemoteServiceAttrStru(0, 0x1112, setSvcName, IntPtr.Zero); ServiceRecord sr = BluesoleilDeviceInfo.CreateServiceRecord(ref attrs, hackApi); // const string NewLine = "\r\n"; const string expectedDump = "AttrId: 0x0001 -- ServiceClassIdList" + NewLine + "ElementSequence" + NewLine + " Uuid16: 0x1112 -- HeadsetAudioGateway" + NewLine + NewLine + "AttrId: 0x0006 -- LanguageBaseAttributeIdList" + NewLine + "ElementSequence" + NewLine + " UInt16: 0x656E" + NewLine + " UInt16: 0x6A" + NewLine + " UInt16: 0x100" + NewLine + NewLine + "AttrId: 0x0100 -- ServiceName" + NewLine + "TextString: [en] 'aabbccdd'" + NewLine + NewLine + "AttrId: 0xFFFF" + NewLine + "TextString (guessing UTF-8): '<partial BlueSoleil decode>'" + NewLine ; string dump = ServiceRecordUtilities.Dump(sr); Assert.AreEqual(expectedDump, dump, "dump"); // ServiceElement e; // e = sr.GetAttributeById(UniversalAttributeId.ServiceClassIdList).Value; ServiceElement eSvcClass = e.GetValueAsElementArray()[0]; UInt16 svcC = (UInt16)eSvcClass.Value; Assert.AreEqual(0x1112, svcC, "svcC"); // string sn = sr.GetPrimaryMultiLanguageStringAttributeById(UniversalAttributeId.ServiceName); Assert.AreEqual("aabbccdd", sn, "sn"); //---- hackApi.AssertActionsNoMore(); }
public static void RecordWithZeroItems_AssertIs(ServiceRecord record) { ServiceAttribute attr; Assert.AreEqual(0, record.Count); // IList_ServiceAttributeId ids = record.AttributeIds; Assert.AreEqual(0, ids.Count); // Assert.IsFalse(record.Contains(UniversalAttributeId.ServiceRecordHandle)); // //TODO ((((test disabled for TryGetAttributeById))) //bool found = record.TryGetAttributeById(UniversalAttributeId.ServiceRecordHandle, out attr); //Assert.IsFalse(found); try { attr = record.GetAttributeById(UniversalAttributeId.ServiceRecordHandle); Assert.Fail("Record should contain no attribute."); } catch (KeyNotFoundException) { } }
public void DeviceIdExtAttr_NoServiceName() { var mocks = new Mockery(); var hackApi = mocks.NewMock <IBluesoleilApi>(); SetupNoSearchAppExtSPPService(hackApi); // var ext = new Structs.BtSdkRmtDISvcExtAttrStru(1, 2, 3, 4, true, 6, 0); IntPtr pExt = Marshal.AllocHGlobal(Marshal.SizeOf(ext)); Marshal.StructureToPtr(ext, pExt, false); Expect.Once.On(hackApi).Method("Btsdk_FreeMemory").With(pExt); // byte[] setSvcName = new byte[0]; const int SvcClassPnp = 0x1200; var attrs = new Structs.BtSdkRemoteServiceAttrStru(0, SvcClassPnp, setSvcName, pExt); ServiceRecord sr = BluesoleilDeviceInfo.CreateServiceRecord(ref attrs, hackApi); // const string NewLine = "\r\n"; const string expectedDump = "AttrId: 0x0001 -- ServiceClassIdList" + NewLine + "ElementSequence" + NewLine + " Uuid16: 0x1200 -- PnPInformation" + NewLine + NewLine // + "AttrId: 0x0200 -- SpecificationId" + NewLine + "UInt16: 0x1" + NewLine + NewLine + "AttrId: 0x0201 -- VendorId" + NewLine + "UInt16: 0x2" + NewLine + NewLine + "AttrId: 0x0202 -- ProductId" + NewLine + "UInt16: 0x3" + NewLine + NewLine + "AttrId: 0x0203 -- Version" + NewLine + "UInt16: 0x4" + NewLine + NewLine + "AttrId: 0x0204 -- PrimaryRecord" + NewLine + "Boolean: True" + NewLine + NewLine + "AttrId: 0x0205 -- VendorIdSource" + NewLine + "UInt16: 0x6" + NewLine + NewLine // + "AttrId: 0xFFFF" + NewLine + "TextString (guessing UTF-8): '<partial BlueSoleil decode>'" + NewLine ; string dump = ServiceRecordUtilities.Dump(sr, typeof(DeviceIdProfileAttributeId)); Assert.AreEqual(expectedDump, dump, "dump"); // ServiceElement e; // e = sr.GetAttributeById(UniversalAttributeId.ServiceClassIdList).Value; ServiceElement eSvcClass = e.GetValueAsElementArray()[0]; UInt16 svcC = (UInt16)eSvcClass.Value; Assert.AreEqual(0x1200, svcC, "svcC"); // //---- mocks.VerifyAllExpectationsHaveBeenMet(); }
//Not supported! Can't tell between little-endian and big-endian Unicode! //[TestMethod] public void OneNoExtAttr_PanuBeUnicodeSvcName() { var mocks = new Mockery(); var hackApi = mocks.NewMock <IBluesoleilApi>(); SetupNoSearchAppExtSPPService(hackApi); Expect.Never.On(hackApi).Method("Btsdk_FreeMemory"); // byte[] setSvcName = { 0x00, 0x50, 0x00, 0x65, 0x00, 0x72, 0x00, 0x73, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x61, 0x00, 0x6C, 0x00, 0x20, 0x00, 0x41, 0x00, 0x64, 0x00, 0x2D, 0x00, 0x68, 0x00, 0x6F, 0x00, 0x63, 0x00, 0x20, 0x00, 0x55, 0x00, 0x73, 0x00, 0x65, 0x00, 0x72, 0x00, 0x20, 0x00, 0x53, 0x00, 0x65, 0x00, 0x72, 0x00, 0x76, 0x00, 0x69, 0x00, 0x63, 0x00, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; ushort SvcClassPanu = 0x1115; var attrs = new Structs.BtSdkRemoteServiceAttrStru(0, SvcClassPanu, setSvcName, IntPtr.Zero); ServiceRecord sr = BluesoleilDeviceInfo.CreateServiceRecord(ref attrs, hackApi); // const string NewLine = "\r\n"; const string expectedDump = "AttrId: 0x0001 -- ServiceClassIdList" + NewLine + "ElementSequence" + NewLine + " Uuid16: 0x1115 -- Panu" + NewLine + NewLine + "AttrId: 0x0006 -- LanguageBaseAttributeIdList" + NewLine + "ElementSequence" + NewLine + " UInt16: 0x656E" + NewLine + " UInt16: 0x6A" + NewLine + " UInt16: 0x100" + NewLine + NewLine + "AttrId: 0x0100 -- ServiceName" + NewLine + "TextString: [en] 'Personal Ad-hoc User Service'" + NewLine + NewLine + "AttrId: 0xFFFF" + NewLine + "TextString (guessing UTF-8): '<partial BlueSoleil decode>'" + NewLine ; string dump = ServiceRecordUtilities.Dump(sr); Assert.AreEqual(expectedDump, dump, "dump"); // ServiceElement e; // e = sr.GetAttributeById(UniversalAttributeId.ServiceClassIdList).Value; ServiceElement eSvcClass = e.GetValueAsElementArray()[0]; UInt16 svcC = (UInt16)eSvcClass.Value; Assert.AreEqual(0x1115, svcC, "svcC"); // string sn = sr.GetPrimaryMultiLanguageStringAttributeById(UniversalAttributeId.ServiceName); Assert.AreEqual("Personal Ad-hoc User Service", sn, "sn"); //---- mocks.VerifyAllExpectationsHaveBeenMet(); }
public void OneSppExtAttr_FullLenServiceName() { var mocks = new Mockery(); var hackApi = mocks.NewMock <IBluesoleilApi>(); SetupNoSearchAppExtSPPService(hackApi); // const byte Port = 23; var ext = new Structs.BtSdkRmtSPPSvcExtAttrStru(Port); IntPtr pExt = Marshal.AllocHGlobal(Marshal.SizeOf(ext)); Marshal.StructureToPtr(ext, pExt, false); Expect.Once.On(hackApi).Method("Btsdk_FreeMemory").With(pExt); // Debug.Assert(80 == StackConsts.BTSDK_SERVICENAME_MAXLENGTH, "BTSDK_SERVICENAME_MAXLENGTH: " + StackConsts.BTSDK_SERVICENAME_MAXLENGTH); byte[] setSvcName = new byte[StackConsts.BTSDK_SERVICENAME_MAXLENGTH]; for (int i = 0; i < (setSvcName.Length - 1); ++i) { setSvcName[i] = (byte)'a'; } setSvcName[setSvcName.Length - 1] = (byte)'b'; var attrs = new Structs.BtSdkRemoteServiceAttrStru(0, 0x1112, setSvcName, pExt); ServiceRecord sr = BluesoleilDeviceInfo.CreateServiceRecord(ref attrs, hackApi); // const string NewLine = "\r\n"; const string expectedDump = "AttrId: 0x0001 -- ServiceClassIdList" + NewLine + "ElementSequence" + NewLine + " Uuid16: 0x1112 -- HeadsetAudioGateway" + NewLine + NewLine + "AttrId: 0x0004 -- ProtocolDescriptorList" + NewLine + "ElementSequence" + NewLine + " ElementSequence" + NewLine + " Uuid16: 0x100 -- L2CapProtocol" + NewLine + " ElementSequence" + NewLine + " Uuid16: 0x3 -- RFCommProtocol" + NewLine + " UInt8: 0x17" + NewLine + "( ( L2Cap ), ( Rfcomm, ChannelNumber=23 ) )" + NewLine + NewLine + "AttrId: 0x0006 -- LanguageBaseAttributeIdList" + NewLine + "ElementSequence" + NewLine + " UInt16: 0x656E" + NewLine + " UInt16: 0x6A" + NewLine + " UInt16: 0x100" + NewLine + NewLine + "AttrId: 0x0100 -- ServiceName" + NewLine + "TextString: [en] 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab'" + NewLine + NewLine + "AttrId: 0xFFFF" + NewLine + "TextString (guessing UTF-8): '<partial BlueSoleil decode>'" + NewLine ; string dump = ServiceRecordUtilities.Dump(sr); Assert.AreEqual(expectedDump, dump, "dump"); // ServiceElement e; // e = sr.GetAttributeById(UniversalAttributeId.ServiceClassIdList).Value; ServiceElement eSvcClass = e.GetValueAsElementArray()[0]; UInt16 svcC = (UInt16)eSvcClass.Value; Assert.AreEqual(0x1112, svcC, "svcC"); // e = sr.GetAttributeById(UniversalAttributeId.ProtocolDescriptorList).Value; ServiceElement listRfcomm = e.GetValueAsElementArray()[1]; ServiceElement eScn = listRfcomm.GetValueAsElementArray()[1]; byte scn = (byte)eScn.Value; Assert.AreEqual(Port, scn, "scn"); // string sn = sr.GetPrimaryMultiLanguageStringAttributeById(UniversalAttributeId.ServiceName); Assert.AreEqual("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab", sn, "sn"); //---- mocks.VerifyAllExpectationsHaveBeenMet(); }
public void OneSppExtAttr_ManualMock() { var hackApi = new TestSdBluesoleilApi(); // const byte Port = 23; var ext = new Structs.BtSdkRmtSPPSvcExtAttrStru(Port); IntPtr pExt = Marshal.AllocHGlobal(Marshal.SizeOf(ext)); Marshal.StructureToPtr(ext, pExt, false); // byte[] setSvcName = Encoding.UTF8.GetBytes("aabbccdd"); var attrs = new Structs.BtSdkRemoteServiceAttrStru(0, 0x1112, setSvcName, pExt); ServiceRecord sr = BluesoleilDeviceInfo.CreateServiceRecord(ref attrs, hackApi); // const string NewLine = "\r\n"; const string expectedDump = "AttrId: 0x0001 -- ServiceClassIdList" + NewLine + "ElementSequence" + NewLine + " Uuid16: 0x1112 -- HeadsetAudioGateway" + NewLine + NewLine + "AttrId: 0x0004 -- ProtocolDescriptorList" + NewLine + "ElementSequence" + NewLine + " ElementSequence" + NewLine + " Uuid16: 0x100 -- L2CapProtocol" + NewLine + " ElementSequence" + NewLine + " Uuid16: 0x3 -- RFCommProtocol" + NewLine + " UInt8: 0x17" + NewLine + "( ( L2Cap ), ( Rfcomm, ChannelNumber=23 ) )" + NewLine + NewLine + "AttrId: 0x0006 -- LanguageBaseAttributeIdList" + NewLine + "ElementSequence" + NewLine + " UInt16: 0x656E" + NewLine + " UInt16: 0x6A" + NewLine + " UInt16: 0x100" + NewLine + NewLine + "AttrId: 0x0100 -- ServiceName" + NewLine + "TextString: [en] 'aabbccdd'" + NewLine + NewLine + "AttrId: 0xFFFF" + NewLine + "TextString (guessing UTF-8): '<partial BlueSoleil decode>'" + NewLine ; string dump = ServiceRecordUtilities.Dump(sr); Assert.AreEqual(expectedDump, dump, "dump"); // ServiceElement e; // e = sr.GetAttributeById(UniversalAttributeId.ServiceClassIdList).Value; ServiceElement eSvcClass = e.GetValueAsElementArray()[0]; UInt16 svcC = (UInt16)eSvcClass.Value; Assert.AreEqual(0x1112, svcC, "svcC"); // e = sr.GetAttributeById(UniversalAttributeId.ProtocolDescriptorList).Value; ServiceElement listRfcomm = e.GetValueAsElementArray()[1]; ServiceElement eScn = listRfcomm.GetValueAsElementArray()[1]; byte scn = (byte)eScn.Value; Assert.AreEqual(Port, scn, "scn"); // string sn = sr.GetPrimaryMultiLanguageStringAttributeById(UniversalAttributeId.ServiceName); Assert.AreEqual("aabbccdd", sn, "sn"); //---- hackApi.AssertActionsInOrder("Btsdk_FreeMemory", pExt); hackApi.AssertActionsNoMore(); }