Example #1
0
        public void StringUtf8Empty()
        {
            byte[]         bytes   = new byte[0];
            ServiceElement element = new ServiceElement(ElementType.TextString, bytes);

            Assert.AreEqual(ElementTypeDescriptor.TextString, element.ElementTypeDescriptor);
            Assert.AreEqual(ElementType.TextString, element.ElementType);
            Assert.IsInstanceOfType(typeof(byte[]), element.Value);
            Assert.AreEqual(String.Empty, element.GetValueAsStringUtf8());
            Assert.AreEqual(0, element.GetValueAsStringUtf8().Length);
        }
        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));
        }
Example #3
0
        public void StringUtf8WithVariousHighChars()
        {
            String str = "ambds\u2022nbdas\u00FEdlka\U00012004slkda";

            byte[]         bytes   = Encoding.UTF8.GetBytes(str);
            ServiceElement element = new ServiceElement(ElementType.TextString, bytes);

            Assert.AreEqual(ElementTypeDescriptor.TextString, element.ElementTypeDescriptor);
            Assert.AreEqual(ElementType.TextString, element.ElementType);
            Assert.IsInstanceOfType(typeof(byte[]), element.Value);
            Assert.AreEqual(str, element.GetValueAsStringUtf8());
        }
Example #4
0
        public void StringUtf8AllAscii()
        {
            String str = "ambdsanbdasdlkaslkda";

            byte[]         bytes   = Encoding.UTF8.GetBytes(str);
            ServiceElement element = new ServiceElement(ElementType.TextString, bytes);

            Assert.AreEqual(ElementTypeDescriptor.TextString, element.ElementTypeDescriptor);
            Assert.AreEqual(ElementType.TextString, element.ElementType);
            Assert.IsInstanceOfType(typeof(byte[]), element.Value);
            Assert.AreEqual(str, element.GetValueAsStringUtf8());
        }
Example #5
0
        public void StringGivenString()
        {
            String         str     = "ambds\u2022nbdas\u00FEdlka\U00012004slkda";
            ServiceElement element = new ServiceElement(ElementType.TextString, str);

            //
            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 WidcommMiscOpp()
        {
            ServiceRecord result =
                TestRecordParsing.DoTestSkippingUnhandledTypes(Data_CompleteThirdPartyRecords.WidcommMiscOpp_Expected,
                                                               Data_CompleteThirdPartyRecords.WidcommMiscOpp);
            //----
            ServiceElement elmnt = result.GetAttributeByIndex(7).Value;

            Assert.AreEqual(ElementType.TextString, elmnt.ElementType);
            String str1 = elmnt.GetValueAsStringUtf8();

            Assert.AreEqual(Data_CompleteThirdPartyRecords.WidcommMiscOppString1, str1);
        }
Example #7
0
        public void StringUtf8AllAsciiWithANullTerminationByte()
        {
            String str = "ambdsanbdasdlkaslkda";

            byte[] bytes_ = Encoding.UTF8.GetBytes(str);
            // Add a null-termination byte
            byte[] bytes = new byte[bytes_.Length + 1];
            bytes_.CopyTo(bytes, 0);
            ServiceElement element = new ServiceElement(ElementType.TextString, bytes);

            Assert.AreEqual(ElementTypeDescriptor.TextString, element.ElementTypeDescriptor);
            Assert.AreEqual(ElementType.TextString, element.ElementType);
            Assert.IsInstanceOfType(typeof(byte[]), element.Value);
            Assert.AreEqual(str, element.GetValueAsStringUtf8());
        }