Ejemplo n.º 1
0
 /// <summary>
 /// Asserts that the contents of the LLSDBinary match the values and length
 /// of the supplied byte array
 /// </summary>
 /// <param name="inBinary"></param>
 /// <param name="inExpected"></param>
 private void TestBinary(LLSDBinary inBinary, byte[] inExpected)
 {
     byte[] binary = inBinary.AsBinary();
     Assert.AreEqual(inExpected.Length, binary.Length);
     for (int i = 0; i < inExpected.Length; i++)
     {
         if (inExpected[i] != binary[i])
         {
             Assert.Fail("Expected " + inExpected[i].ToString() + " at position " + i.ToString() +
                         " but saw " + binary[i].ToString());
         }
     }
 }
Ejemplo n.º 2
0
        public void DeserializeBinary()
        {
            LLSD       theLLSD    = null;
            LLSDArray  array      = null;
            LLSDBinary tempBinary = null;

            String testLLSD = @"<?xml version='1.0' encoding='UTF-8'?>
            <llsd>
                <array>
                    <binary encoding='base64'>cmFuZG9t</binary>
                    <binary>dGhlIHF1aWNrIGJyb3duIGZveA==</binary>
                    <binary/>
                </array>
            </llsd>";

            //Deserialize the string
            byte[] bytes = Encoding.UTF8.GetBytes(testLLSD);
            theLLSD = LLSDParser.DeserializeXml(bytes);

            Assert.IsTrue(theLLSD is LLSDArray);
            array = (LLSDArray)theLLSD;

            Assert.AreEqual(LLSDType.Binary, array[0].Type);
            tempBinary = (LLSDBinary)array[0];
            byte[] testData1 = { 114, 97, 110, 100, 111, 109 };
            TestBinary(tempBinary, testData1);

            Assert.AreEqual(LLSDType.Binary, array[1].Type);
            tempBinary = (LLSDBinary)array[1];
            byte[] testData2 = { 116, 104, 101,  32, 113, 117, 105, 99, 107, 32, 98,
                                 114, 111, 119, 110,  32, 102, 111, 120 };
            TestBinary(tempBinary, testData2);

            Assert.AreEqual(LLSDType.Binary, array[1].Type);
            tempBinary = (LLSDBinary)array[2];
            Assert.AreEqual(0, tempBinary.AsBinary().Length);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Asserts that the contents of the LLSDBinary match the values and length
 /// of the supplied byte array
 /// </summary>
 /// <param name="inBinary"></param>
 /// <param name="inExpected"></param>
 private void TestBinary(LLSDBinary inBinary, byte[] inExpected)
 {
     byte[] binary = inBinary.AsBinary();
     Assert.AreEqual(inExpected.Length, binary.Length);
     for (int i = 0; i < inExpected.Length; i++)
     {
         if (inExpected[i] != binary[i])
         {
             Assert.Fail("Expected " + inExpected[i].ToString() + " at position " + i.ToString() +
                 " but saw " + binary[i].ToString());
         }
     }
 }