//-------------------------------------------------------------- /// <summary> /// Obsolete, use <see cref="M:InTheHand.Net.Bluetooth.ServiceElement.#ctor(InTheHand.Net.Bluetooth.ElementType,System.Object)"/> instead. /// Initializes a new instance of the <see cref="T:InTheHand.Net.Bluetooth.ServiceElement"/> class. /// </summary> internal ServiceElement(ElementTypeDescriptor etd, ElementType type, Object value) { ServiceRecordParser.VerifyTypeMatchesEtd(etd, type); m_type = type; m_etd = etd; SetValue(value); }
public void EnIsSimple() { String expectedEn = "abcd"; String expectedIs = "abce"; byte[] buffer = RecordBytesEnIs; ServiceRecord record = new ServiceRecordParser().Parse(buffer); LanguageBaseItem[] langList = record.GetLanguageBaseList(); // LanguageBaseItem langIs = langList[0]; Assert.AreEqual("is", langIs.NaturalLanguage); LanguageBaseItem langEn = langList[1]; Assert.AreEqual("en", langEn.NaturalLanguage); // ServiceAttribute attrEn = record.GetAttributeByIndex(1); ServiceAttribute attrIs = record.GetAttributeByIndex(2); Assert.AreEqual((ServiceAttributeId)0x0100, attrEn.Id); Assert.AreEqual((ServiceAttributeId)0x0110, attrIs.Id); String resultEn = attrEn.Value.GetValueAsString(langEn); String resultIs = attrIs.Value.GetValueAsString(langIs); Assert.AreEqual(expectedEn, resultEn); Assert.AreEqual(expectedIs, resultIs); }
public Uri GetValueAsUri() { if (m_type != ElementType.Url) { throw new InvalidOperationException(ErrorMsgNotUrlType); } System.Diagnostics.Debug.Assert(m_rawValue != null); Uri asUri = m_rawValue as Uri; if (asUri == null) { var arr = m_rawValue as byte[]; string str; if (arr != null) { str = ServiceRecordParser.CreateUriStringFromBytes(arr); } else { str = (string)m_rawValue; } asUri = new Uri(str); } return(asUri); }
public void BadGetStringByIdAndLang_LangNull() { byte[] buffer = RecordBytesEnIsEncodings; ServiceRecord record = new ServiceRecordParser().Parse(buffer); record.GetMultiLanguageStringAttributeById(0, null); }
internal static Object FakeForArgExceptionCoverage_GetElementLength(byte[] buffer, int index, int length) { int contentOffset, contentLength; return(ServiceRecordParser.GetElementLength(buffer, index, length, out contentOffset, out contentLength)); }
public void EnIsEncodingsRecordGetStringByIdAndLang() { String expectedEn = "ab\u2020cd"; String expectedIs = "ab\u00D0c\u00DEe"; byte[] buffer = RecordBytesEnIsEncodings; ServiceRecord record = new ServiceRecordParser().Parse(buffer); LanguageBaseItem[] langList = record.GetLanguageBaseList(); // LanguageBaseItem langIs = langList[0]; Assert.AreEqual("is", langIs.NaturalLanguage); LanguageBaseItem langEn = langList[1]; Assert.AreEqual("en", langEn.NaturalLanguage); // // Here's the stuff really tested here!!!! String resultEn = record.GetMultiLanguageStringAttributeById(0, langEn); String resultIs = record.GetMultiLanguageStringAttributeById(0, langIs); Assert.AreEqual(expectedEn, resultEn); Assert.AreEqual(expectedIs, resultIs); String resultEnPrimary = record.GetPrimaryMultiLanguageStringAttributeById(0); Assert.AreEqual(expectedEn, resultEnPrimary); }
public BluetopiaSdpQuery(BluetopiaFactory factory) { Debug.Assert(factory != null); _fcty = factory; _callback = HandleSDP_Response_Callback; _parser = new ServiceRecordParser(); }
public ExpectedServiceElement(ElementType elementType, ElementTypeDescriptor etd, Object value) { if (!ServiceRecordParser.TypeMatchesEtd(etd, elementType)) { throw new ArgumentException(String.Format( "Test setup; ElementType does not match TypeDescriptor ({0}/{1}).", elementType, etd)); } this.ElementType = elementType; this.Etd = etd; // if (value != null) // Can't check types when the value is null. { if (etd == ElementTypeDescriptor.ElementSequence || etd == ElementTypeDescriptor.ElementAlternative) { if (typeof(ExpectedServiceElement[]) != value.GetType()) { throw new ArgumentException("DataElementSequence and DataElementAlternative need an array of ExpectedAttributeValue."); } this.Children = (ExpectedServiceElement[])value; } else { if (typeof(ExpectedServiceElement[]) == value.GetType()) { throw new ArgumentException("DataElementSequence and DataElementAlternative must be used for an array of ExpectedAttributeValue."); } this.Value = value; } } }
public void OneUnknownType_Strict() { byte[] recordBytes = OneUnknownTypeBytes; ServiceRecordParser parser = new ServiceRecordParser(); parser.SkipUnhandledElementTypes = false; parser.Parse(recordBytes); }
//-------------------------------------------------------------- public static ServiceRecord DoTest(ExpectedServiceAttribute[] expected, byte[] buffer) { ServiceRecord result = new ServiceRecordParser().Parse(buffer); // DoAreEqual(expected, result, 0); return(result); }
internal static void DoTestSmart(String expected, byte[] recordBytes, params Type[] attributeIdEnumDefiningTypes) { ServiceRecordParser parser = new ServiceRecordParser(); parser.SkipUnhandledElementTypes = true; ServiceRecord record = parser.Parse(recordBytes); DoTestSmart(expected, record, attributeIdEnumDefiningTypes); }
private static ServiceRecord ParseRaw(byte[] sdpRecord, int channelOffset) { ServiceRecordParser parser = new ServiceRecordParser(); Debug.Assert(!parser.SkipUnhandledElementTypes); ServiceRecord rcd = parser.Parse(sdpRecord); return(rcd); }
public void DoTest(byte[] bytes) { // Aim is simply to show an exception if not yet implemented so simply parse // and don't do any thorough checking of the result. ServiceRecord result = new ServiceRecordParser().Parse(bytes); Assert.IsNotNull(result); Assert.AreEqual(1, result.Count); }
private void DoTest(byte[] multiRecord, params byte[][] expectedRecords) { byte[][] records = ServiceRecordParser.SplitSearchAttributeResult(multiRecord); Assert.AreEqual(expectedRecords.Length, records.Length, "Record count"); for (int i = 0; i < expectedRecords.Length; ++i) { Assert.AreEqual(expectedRecords[i], records[i], String.Format("Record content -- record index {0}/{1}.", i, expectedRecords.Length)); } }
internal HeaderWriteState(ElementTypeDescriptor elementTypeDescriptor, byte[] buf, int offset, SizeIndex sizeIndex, int headerLength) { this.Etd = elementTypeDescriptor; this.HeaderOffset = offset; this.SizeIndex = sizeIndex; this.HeaderLength = headerLength; // VerifyWriteSpaceRemaining(HeaderLength, buf, offset); ServiceRecordParser.VerifyAllowedSizeIndex(Etd, SizeIndex, false); }
public void TwoItemsAsArrayToParse() { ServiceRecord record = new ServiceRecordParser().Parse(Data_LanguageBaseList.RecordTwoItemsAsBytes); LanguageBaseItem item = record.GetPrimaryLanguageBaseItem(); // Assert.AreEqual(Data_LanguageBaseList.LangStringEn, item.NaturalLanguage, "NaturalLanguage"); Assert.AreEqual(Data_LanguageBaseList.EncUtf8, item.EncodingId, "EncodingId"); Assert.AreEqual((ServiceAttributeId)0x0100, item.AttributeIdBase, "AttributeIdBase"); }
internal static void DoTestSmart_NotSkip(String expected, byte[] recordBytes, params Type[] attributeIdEnumDefiningTypes) { ServiceRecordParser parser = new ServiceRecordParser(); parser.SkipUnhandledElementTypes = false; ServiceRecord record = parser.Parse(recordBytes); // string result = ServiceRecordUtilities.Dump(record, attributeIdEnumDefiningTypes); Assert.AreEqual(expected, result); }
internal static void DoTestRaw(String expected, byte[] recordBytes) { ServiceRecordParser parser = new ServiceRecordParser(); parser.SkipUnhandledElementTypes = true; ServiceRecord record = parser.Parse(recordBytes); // string result = ServiceRecordUtilities.DumpRaw(record); Assert.AreEqual(expected, result); }
public void BadStringEncodingNotAscii() { byte[] buffer = RecordBytesEnIsEncodings; ServiceRecord record = new ServiceRecordParser().Parse(buffer); // ServiceAttribute attr = record.GetAttributeById((ServiceAttributeId)0x0100); const ushort langEn = 0x656e; const ushort ietfAscii = 3; LanguageBaseItem langBase = new LanguageBaseItem(langEn, ietfAscii, (ServiceAttributeId)0x0999); String x = attr.Value.GetValueAsString(langBase); }
public static ServiceRecord DoTestLazyUrlCreation(ExpectedServiceAttribute[] expected, byte[] buffer) { ServiceRecordParser parser = new ServiceRecordParser(); parser.LazyUrlCreation = true; ServiceRecord result = parser.Parse(buffer); // DoAreEqual(expected, result, 0); return(result); }
public void FromRecord() { ServiceRecord record = new ServiceRecordParser().Parse(Data_CompleteThirdPartyRecords.XpFsquirtOpp); MapServiceClassToAttributeIdList mapper = new MapServiceClassToAttributeIdList(); Type[] enums = mapper.GetAttributeIdEnumTypes(record); Assert.IsNotNull(enums); Assert.AreEqual(1, enums.Length); Assert.IsNotNull(enums[0]); Assert.AreEqual("ObexAttributeId", enums[0].Name); }
public static ServiceRecord DoTestSkippingUnhandledTypes(ExpectedServiceAttribute[] expected, byte[] buffer) { ServiceRecordParser parser = new ServiceRecordParser(); parser.SkipUnhandledElementTypes = true; ServiceRecord result = parser.Parse(buffer); // DoAreEqual(expected, result, 0); return(result); }
private void DoTest(int expectedContentLength, int expectedContentOffset, byte[] headerBytes, int offset, int length) { int expectedElementLength = checked (expectedContentLength + expectedContentOffset); ServiceRecordParser parser = new ServiceRecordParser(); Int32 contentOffset; Int32 contentLength; Int32 elementlength = TestableServiceRecordParser.GetElementLength(headerBytes, offset, length, out contentOffset, out contentLength); Assert.AreEqual(expectedElementLength, elementlength); Assert.AreEqual(expectedContentOffset, contentOffset); Assert.AreEqual(expectedContentLength, contentLength); }
static void Documentation_SRB_Simple() { ServiceRecord r = Documentation_SRB_Simple_(); ServiceRecordUtilities.Dump(Console.Out, r); ServiceRecordCreator ctr = new ServiceRecordCreator(); byte[] bs = ctr.CreateServiceRecord(r); ServiceRecordParser psr = new ServiceRecordParser(); ServiceRecord r2 = psr.Parse(bs); ServiceRecordUtilities.Dump(Console.Out, r2); }
/// <summary> /// Run an SDP query on the device’s Service Discovery Database, /// returning the raw byte rather than a parsed record. /// </summary> /// - /// <remarks> /// If the device isn’t accessible a <see cref="T:System.Net.Sockets.SocketException"/> /// with <see cref="P:System.Net.Sockets.SocketException.ErrorCode"/> /// 10108 (0x277C) occurs. /// </remarks> /// - /// <param name="service">The UUID to search for, as a <see cref="T:System.Guid"/>. /// </param> /// - /// <returns>An array of array of <see cref="T:System.Byte"/>.</returns> /// - /// <exception cref="T:System.Net.Sockets.SocketException"> /// The query failed. /// </exception> public byte[][] GetServiceRecordsUnparsed(Guid service) { byte[][] result = GetServiceRecordsUnparsedWindowsRaw(service); #if NETCF if (Environment.OSVersion.Platform == PlatformID.WinCE) { if (result.Length != 0) { System.Diagnostics.Debug.Assert(result.Length == 1, "Expect one multi-record item on CE."); result = ServiceRecordParser.SplitSearchAttributeResult(result[0]); } } #endif return result; }
public static ServiceRecord CreateServiceRecordFromBytes(byte[] recordBytes) { if (recordBytes == null) { throw new ArgumentNullException("recordBytes"); } ServiceRecord parsedRecord = new ServiceRecordParser().Parse(recordBytes); //// ...and copy the result to 'this'. //this.m_attributes = tmpRecord.m_attributes; //this.m_srcBytes = tmpRecord.m_srcBytes; //System.Diagnostics.Debug.Assert(this.m_srcBytes == recordBytes); return(parsedRecord); }
/// <summary> /// Run an SDP query on the device’s Service Discovery Database. /// </summary> /// - /// <remarks> /// <para> /// For instance to see whether the device has an an Serial Port services /// search for UUID <see cref="F:InTheHand.Net.Bluetooth.BluetoothService.SerialPort"/>, /// or too find all the services that use RFCOMM use /// <see cref="F:InTheHand.Net.Bluetooth.BluetoothService.RFCommProtocol"/>, /// or all the services use /// <see cref="F:InTheHand.Net.Bluetooth.BluetoothService.L2CapProtocol"/>. /// </para> /// <para> /// If the device isn’t accessible a <see cref="T:System.Net.Sockets.SocketException"/> /// with <see cref="P:System.Net.Sockets.SocketException.ErrorCode"/> /// 10108 (0x277C) occurs. /// </para> /// </remarks> /// - /// <param name="service">The UUID to search for, as a <see cref="T:System.Guid"/>. /// </param> /// - /// <returns>The parsed record as an /// <see cref="T:InTheHand.Net.Bluetooth.ServiceRecord"/>. /// </returns> /// - /// <example> /// <code lang="VB.NET"> /// Dim bdi As BluetoothDeviceInfo = ... /// Dim records As ServiceRecord() = bdi.GetServiceRecords(BluetoothService.RFCommProtocol) /// ' Dump each to console /// For Each curRecord As ServiceRecord In records /// ServiceRecordUtilities.Dump(Console.Out, curRecord) /// Next /// </code> /// </example> /// /// - /// <exception cref="T:System.Net.Sockets.SocketException"> /// The query failed. /// </exception> public ServiceRecord[] GetServiceRecords(Guid service) { byte[][] rawRecords = GetServiceRecordsUnparsed(service); ServiceRecord[] records = new ServiceRecord[rawRecords.Length]; ServiceRecordParser parser = new ServiceRecordParser(); int i = 0; foreach (byte[] rawBytes in rawRecords) { ServiceRecord record = parser.Parse(rawBytes); record.SetSourceBytes(rawBytes); records[i] = record; ++i; } return records; }
public void EnIsEncodingsRecordGetStringByIdAndLangNoLangBaseItems() { String expectedEn = "ab\u2020cd"; byte[] buffer = RecordBytesEnIsEncodingsNoLangBaseItems; ServiceRecord record = new ServiceRecordParser().Parse(buffer); // LanguageBaseItem[] langList = record.GetLanguageBaseList(); Assert.AreEqual(0, langList.Length, "#LangItems==0"); // String resultEnPrimary = record.GetPrimaryMultiLanguageStringAttributeById(0); Assert.AreEqual(expectedEn, resultEnPrimary); }
public void TwoItemsAsArrayToParse() { ServiceRecord record = new ServiceRecordParser().Parse(Data_LanguageBaseList.RecordTwoItemsAsBytes); LanguageBaseItem[] items = record.GetLanguageBaseList(); Assert.AreEqual(2, items.Length); // Assert.AreEqual(Data_LanguageBaseList.LangStringEn, items[0].NaturalLanguage, "NaturalLanguage"); Assert.AreEqual(Data_LanguageBaseList.EncUtf8, items[0].EncodingId, "EncodingId"); Assert.AreEqual((ServiceAttributeId)0x0100, items[0].AttributeIdBase, "AttributeIdBase"); // Assert.AreEqual(Data_LanguageBaseList.LangStringFr, items[1].NaturalLanguage, "NaturalLanguage"); Assert.AreEqual(Data_LanguageBaseList.EncWindows1252, items[1].EncodingId, "EncodingId"); Assert.AreEqual((ServiceAttributeId)0x0110, items[1].AttributeIdBase, "AttributeIdBase"); }
/// <summary> /// Add a custom attribute of simple type. /// </summary> /// - /// <remarks> /// <para>If the <paramref name="elementType"/> is a numerical type /// then this is equivalent to using /// <see cref="M:InTheHand.Net.Bluetooth.ServiceElement.CreateNumericalServiceElement(InTheHand.Net.Bluetooth.ElementType,System.Object)"/> /// otherwise the value is used directly in creating the /// <see cref="T:InTheHand.Net.Bluetooth.ServiceElement"/>. /// </para> /// </remarks> /// - /// <param name="id">The Attribute Id as a <see cref="T:InTheHand.Net.Bluetooth.ServiceAttributeId"/>.</param> /// <param name="elementType">The type of the element as an <see cref="T:InTheHand.Net.Bluetooth.ElementType"/>.</param> /// <param name="value">The value for the new element.</param> public void AddCustomAttribute(ServiceAttributeId id, ElementType elementType, object value) { ServiceElement e; ElementTypeDescriptor etd = ServiceRecordParser.GetEtdForType(elementType); if ((etd == ElementTypeDescriptor.UnsignedInteger || etd == ElementTypeDescriptor.TwosComplementInteger)) { e = ServiceElement.CreateNumericalServiceElement(elementType, value); } else { e = new ServiceElement(elementType, value); } this.AddCustomAttribute(new ServiceAttribute(id, e)); }