private static void DoAreEqual(ExpectedServiceElement expected, ServiceElement value, int depth) { if (expected.Etd != value.ElementTypeDescriptor) { } Assert.AreEqual(expected.Etd, value.ElementTypeDescriptor, "ElementTypeDescriptor."); if (expected.ElementType != value.ElementType) { } Assert.AreEqual(expected.ElementType, value.ElementType, "ElementType."); if (expected.Etd == ElementTypeDescriptor.ElementSequence || expected.Etd == ElementTypeDescriptor.ElementAlternative) { ExpectedServiceElement[] expectedChildAttributes = expected.Children; ServiceElement[] children = value.GetValueAsElementArray(); DoAreEqual(expectedChildAttributes, children, depth + 1); } else { Assert.AreEqual(expected.Value, value.Value, "Element Value"); } }
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(); }