Package com.ngt.jopenmetaverse.shared.structureddata

Examples of com.ngt.jopenmetaverse.shared.structureddata.OSDArray


    }

    @Test
    public void SerializeNestedComposite() throws Exception
    {
        OSDArray llsdNested = new OSDArray();
        OSDMap llsdMap = new OSDMap();
        OSDArray llsdArray = new OSDArray();
        llsdArray.add(OSD.FromInteger(1));
        llsdArray.add(OSD.FromInteger(2));
        llsdMap.put("t0st", llsdArray);
        llsdMap.put("test", OSD.FromString("what"));
        llsdNested.add(llsdMap);
        llsdNested.add(OSD.FromInteger(124));
        llsdNested.add(OSD.FromInteger(987));

        byte[] binaryNestedSerialized = BinaryLLSDOSDParser.SerializeLLSDBinary(llsdNested);
        // Because maps don't preserve order, we compare here to a deserialized value.
        OSDArray llsdNestedDeserialized = (OSDArray)BinaryLLSDOSDParser.DeserializeLLSDBinary(binaryNestedSerialized);
        Assert.assertEquals(OSDType.Array, llsdNestedDeserialized.getType());
        Assert.assertEquals(3, llsdNestedDeserialized.count());

        OSDMap llsdMapDeserialized = (OSDMap)llsdNestedDeserialized.get(0);
        Assert.assertEquals(OSDType.Map, llsdMapDeserialized.getType());
        Assert.assertEquals(2, llsdMapDeserialized.count());
        Assert.assertEquals(OSDType.Array, llsdMapDeserialized.get("t0st").getType());

        OSDArray llsdNestedArray = (OSDArray)llsdMapDeserialized.get("t0st");
        Assert.assertEquals(OSDType.Array, llsdNestedArray.getType());
        Assert.assertEquals(2, llsdNestedArray.count());
        Assert.assertEquals(OSDType.Integer, llsdNestedArray.get(0).getType());
        Assert.assertEquals(1, llsdNestedArray.get(0).asInteger());
        Assert.assertEquals(OSDType.Integer, llsdNestedArray.get(1).getType());
        Assert.assertEquals(2, llsdNestedArray.get(1).asInteger());

        Assert.assertEquals(OSDType.String, llsdMapDeserialized.get("test").getType());
        Assert.assertEquals("what", llsdMapDeserialized.get("test").asString());

        Assert.assertEquals(OSDType.Integer, llsdNestedDeserialized.get(1).getType());
View Full Code Here


  /// </summary>
  @Test
  public void DeserializeReals()
  {
    OSD theSD = null;
    OSDArray array = null;
    OSDReal tempReal = null;

    String testSD = "<?xml version='1.0' encoding='UTF-8'?> \n" +
        "<llsd> \n" +
        "<array> \n" +
        "<real>44.38898</real> \n" +
        "<real>nan</real> \n" +
        "<real>4</real> \n" +
        "<real>-13.333</real> \n" +
        "<real/> \n" +
        "</array> \n" +
        "</llsd>";
    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =XmlLLSDOSDParser.DeserializeLLSDXml(bytes);

    Assert.assertTrue(theSD instanceof OSDArray);
    array = (OSDArray)theSD;

    Assert.assertEquals(OSDType.Real, array.get(0).getType());
    tempReal = (OSDReal)array.get(0);
    Assert.assertEquals(44.38898d, tempReal.asReal(), 0);

    Assert.assertEquals(OSDType.Real, array.get(1).getType());
    tempReal = (OSDReal)array.get(1);
    Assert.assertEquals(Double.NaN, tempReal.asReal(), 0);

    Assert.assertEquals(OSDType.Real, array.get(2).getType());
    tempReal = (OSDReal)array.get(2);
    Assert.assertEquals(4.0d, tempReal.asReal(), 0);

    Assert.assertEquals(OSDType.Real, array.get(3).getType());
    tempReal = (OSDReal)array.get(3);
    Assert.assertEquals(-13.333d, tempReal.asReal(), 0);

    Assert.assertEquals(OSDType.Real, array.get(4).getType());
    tempReal = (OSDReal)array.get(4);
    Assert.assertEquals(0d, tempReal.asReal(), 0);
  }
View Full Code Here

  /// </summary>
  @Test
  public void DeserializeStrings()
  {
    OSD theSD = null;
    OSDArray array = null;
    OSDString tempStr = null;

    String testSD = "<?xml version='1.0' encoding='UTF-8'?> \n" +
        "<llsd> \n" +
        "<array> \n" +
        "<string>Kissling</string> \n" +
        "<string>Attack ships on fire off the shoulder of Orion</string> \n" +
        "<string>&lt; &gt; &amp; &apos; &quot;</string> \n" +
        "<string/> \n" +
        "</array> \n" +
        "</llsd>";
    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =XmlLLSDOSDParser.DeserializeLLSDXml(bytes);

    Assert.assertTrue(theSD instanceof OSDArray);
    array = (OSDArray)theSD;

    Assert.assertEquals(OSDType.String, array.get(0).getType());
    tempStr = (OSDString)array.get(0);
    Assert.assertEquals("Kissling", tempStr.asString());

    Assert.assertEquals(OSDType.String, array.get(1).getType());
    tempStr = (OSDString)array.get(1);
    Assert.assertEquals("Attack ships on fire off the shoulder of Orion", tempStr.asString());

    Assert.assertEquals(OSDType.String, array.get(2).getType());
    tempStr = (OSDString)array.get(2);
    Assert.assertEquals("< > & \' \"", tempStr.asString());

    Assert.assertEquals(OSDType.String, array.get(3).getType());
    tempStr = (OSDString)array.get(3);
    Assert.assertEquals("", tempStr.asString());

  }
View Full Code Here

  /// </summary>
  @Test
  public void DeserializeIntegers()
  {
    OSD theSD = null;
    OSDArray array = null;
    OSDInteger tempInt = null;

    String testSD = "<?xml version='1.0' encoding='UTF-8'?> \n" +
        "<llsd> \n" +
        "<array> \n" +
        "<integer>2147483647</integer> \n" +
        "<integer>-2147483648</integer> \n" +
        "<integer>0</integer> \n" +
        "<integer>013</integer> \n" +
        "<integer/> \n" +
        "</array> \n" +
        "</llsd>";
    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =XmlLLSDOSDParser.DeserializeLLSDXml(bytes);

    Assert.assertTrue(theSD instanceof OSDArray);
    array = (OSDArray)theSD;

    Assert.assertEquals(OSDType.Integer, array.get(0).getType());
    tempInt = (OSDInteger)array.get(0);
    Assert.assertEquals(2147483647, tempInt.asInteger());

    Assert.assertEquals(OSDType.Integer, array.get(1).getType());
    tempInt = (OSDInteger)array.get(1);
    Assert.assertEquals(-2147483648, tempInt.asInteger());

    Assert.assertEquals(OSDType.Integer, array.get(2).getType());
    tempInt = (OSDInteger)array.get(2);
    Assert.assertEquals(0, tempInt.asInteger());

    Assert.assertEquals(OSDType.Integer, array.get(3).getType());
    tempInt = (OSDInteger)array.get(3);
    Assert.assertEquals(13, tempInt.asInteger());

    Assert.assertEquals(OSDType.Integer, array.get(4).getType());
    tempInt = (OSDInteger)array.get(4);
    Assert.assertEquals(0, tempInt.asInteger());
  }
View Full Code Here

  /// </summary>
  @Test
  public void DeserializeUUID()
  {
    OSD theSD = null;
    OSDArray array = null;
    OSDUUID tempUUID = null;

    String testSD = "<?xml version='1.0' encoding='UTF-8'?> \n" +
        "<llsd> \n" +
        "<array> \n" +
        "<uuid>d7f4aeca-88f1-42a1-b385-b9db18abb255</uuid> \n" +
        "<uuid/> \n" +
        "</array> \n" +
        "</llsd>";
    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =XmlLLSDOSDParser.DeserializeLLSDXml(bytes);

    Assert.assertTrue(theSD instanceof OSDArray);
    array = (OSDArray)theSD;

    Assert.assertEquals(OSDType.UUID, array.get(0).getType());
    tempUUID = (OSDUUID)array.get(0);
    Assert.assertEquals(new UUID("d7f4aeca-88f1-42a1-b385-b9db18abb255"), tempUUID.asUUID());

    Assert.assertEquals(OSDType.UUID, array.get(1).getType());
    tempUUID = (OSDUUID)array.get(1);
    Assert.assertEquals(UUID.Zero, tempUUID.asUUID());
  }
View Full Code Here

  /// </summary>
  @Test
  public void DeserializeDates()
  {
    OSD theSD = null;
    OSDArray array = null;
    OSDDate tempDate = null;
    Date[] testDate = new Date[1];

    String testSD = "<?xml version='1.0' encoding='UTF-8'?> \n" +
        "<llsd> \n" +
        "<array> \n" +
        "<date>2006-02-01T14:29:53Z</date> \n" +
        "<date>1999-01-01T00:00:00Z</date> \n" +
        "<date/> \n" +
        "</array> \n" +
        "</llsd>";
    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =XmlLLSDOSDParser.DeserializeLLSDXml(bytes);

    Assert.assertTrue(theSD instanceof OSDArray);
    array = (OSDArray)theSD;

    Assert.assertEquals(OSDType.Date, array.get(0).getType());
    tempDate = (OSDDate)array.get(0);
    Utils.tryParseDate("2006-02-01T14:29:53Z", testDate);
    Assert.assertEquals(testDate[0], tempDate.asDate());

    Assert.assertEquals(OSDType.Date, array.get(1).getType());
    tempDate = (OSDDate)array.get(1);
    Utils.tryParseDate("1999-01-01T00:00:00Z", testDate);
    Assert.assertEquals(testDate[0], tempDate.asDate());

    Assert.assertEquals(OSDType.Date, array.get(2).getType());
    tempDate = (OSDDate)array.get(2);
    Assert.assertEquals(Utils.Epoch, tempDate.asDate());
  }
View Full Code Here

  /// </summary>
  @Test
  public void DeserializeBoolean()
  {
    OSD theSD = null;
    OSDArray array = null;
    OSDBoolean tempBool = null;

    String testSD = "<?xml version='1.0' encoding='UTF-8'?> \n" +
        "<llsd> \n" +
        "<array> \n" +
        "<boolean>1</boolean> \n" +
        "<boolean>true</boolean> \n" +
        "<boolean>0</boolean> \n" +
        "<boolean>false</boolean> \n" +
        "<boolean/> \n" +
        "</array> \n" +
        "</llsd>";
    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =XmlLLSDOSDParser.DeserializeLLSDXml(bytes);

    Assert.assertTrue(theSD instanceof OSDArray);
    array = (OSDArray)theSD;

    Assert.assertEquals(OSDType.Boolean, array.get(0).getType());
    tempBool = (OSDBoolean)array.get(0);
    Assert.assertEquals(true, tempBool.asBoolean());

    Assert.assertEquals(OSDType.Boolean, array.get(1).getType());
    tempBool = (OSDBoolean)array.get(1);
    Assert.assertEquals(true, tempBool.asBoolean());

    Assert.assertEquals(OSDType.Boolean, array.get(2).getType());
    tempBool = (OSDBoolean)array.get(2);
    Assert.assertEquals(false, tempBool.asBoolean());

    Assert.assertEquals(OSDType.Boolean, array.get(3).getType());
    tempBool = (OSDBoolean)array.get(3);
    Assert.assertEquals(false, tempBool.asBoolean());

    Assert.assertEquals(OSDType.Boolean, array.get(4).getType());
    tempBool = (OSDBoolean)array.get(4);
    Assert.assertEquals(false, tempBool.asBoolean());
  }
View Full Code Here

  /// </summary>
  @Test
  public void DeserializeBinary()
  {
    OSD theSD = null;
    OSDArray array = null;
    OSDBinary tempBinary = null;

    String testSD = "<?xml version='1.0' encoding='UTF-8'?> \n" +
        "<llsd> \n" +
        "<array> \n" +
        "<binary encoding='base64'>cmFuZG9t</binary> \n" +
        "<binary>dGhlIHF1aWNrIGJyb3duIGZveA==</binary> \n" +
        "<binary/> \n" +
        "</array> \n" +
        "</llsd>";

    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =XmlLLSDOSDParser.DeserializeLLSDXml(bytes);

    Assert.assertTrue(theSD instanceof OSDArray);
    array = (OSDArray)theSD;

    Assert.assertEquals(OSDType.Binary, array.get(0).getType());
    tempBinary = (OSDBinary)array.get(0);
    byte[] testData1 = {114, 97, 110, 100, 111, 109};
    TestHelper.TestBinary(tempBinary, testData1);

    Assert.assertEquals(OSDType.Binary, array.get(1).getType());
    tempBinary = (OSDBinary)array.get(1);
    byte[] testData2 = {116, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98,
        114, 111, 119, 110, 32, 102, 111, 120};
    TestHelper.TestBinary(tempBinary, testData2);

    Assert.assertEquals(OSDType.Binary, array.get(1).getType());
    tempBinary = (OSDBinary)array.get(2);
    Assert.assertEquals(0, tempBinary.asBinary().length);
  }
View Full Code Here

  /// </summary>
  @Test
  public void DeserializeURI() throws URISyntaxException
  {
    OSD theSD = null;
    OSDArray array = null;
    OSDUri tempURI = null;

    String testSD = "<?xml version='1.0' encoding='UTF-8'?> \n" +
        "<llsd> \n" +
        "<array> \n" +
        "  <uri>http://sim956.agni.lindenlab.com:12035/runtime/agents</uri> \n" +
        "   <uri/> \n" +
        "</array> \n" +
        "</llsd>";
    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =XmlLLSDOSDParser.DeserializeLLSDXml(bytes);

    Assert.assertTrue(theSD instanceof OSDArray);
    array = (OSDArray)theSD;

    Assert.assertEquals(OSDType.URI, array.get(0).getType());
    tempURI = (OSDUri)array.get(0);
    URI testURI = new URI("http://sim956.agni.lindenlab.com:12035/runtime/agents");
    Assert.assertEquals(testURI, tempURI.asUri());

    Assert.assertEquals(OSDType.URI, array.get(1).getType());
    tempURI = (OSDUri)array.get(1);
    Assert.assertEquals("", tempURI.asUri().toString());
  }
View Full Code Here

  /// </summary>
  @Test
  public void DeserializeNestedContainers()
  {
    OSD theSD = null;
    OSDArray array = null;
    OSDMap map = null;
    OSD tempSD = null;

    String testSD = "<?xml version='1.0' encoding='UTF-8'?> \n" +
        "<llsd> \n" +
        "<array> \n" +
        "<map> \n" +
        "<key>Map One</key> \n" +
        "<map> \n" +
        "<key>Array One</key> \n" +
        "<array> \n" +
        "<integer>1</integer> \n" +
        "<integer>2</integer> \n" +
        "</array> \n" +
        "</map> \n" +
        "</map> \n" +
        "<array> \n" +
        "<string>A</string> \n" +
        "<string>B</string> \n" +
        "<array> \n" +
        "<integer>1</integer> \n" +
        "<integer>4</integer> \n" +
        "<integer>9</integer> \n" +
        "</array> \n" +
        "</array> \n" +
        "</array> \n" +
        "</llsd>";
    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =XmlLLSDOSDParser.DeserializeLLSDXml(bytes);

    Assert.assertTrue(theSD instanceof OSDArray);
    array = (OSDArray)theSD;
    Assert.assertEquals(2, array.count());

    //The first element of top level array, a map
    Assert.assertEquals(OSDType.Map, array.get(0).getType());
    map = (OSDMap)array.get(0);
    //First nested map
    tempSD = map.get("Map One");
    Assert.assertNotNull(tempSD);
    Assert.assertEquals(OSDType.Map, tempSD.getType());
    map = (OSDMap)tempSD;
    //First nested array
    tempSD = map.get("Array One");
    Assert.assertNotNull(tempSD);
    Assert.assertEquals(OSDType.Array, tempSD.getType());
    array = (OSDArray)tempSD;
    Assert.assertEquals(2, array.count());

    array = (OSDArray)theSD;
    //Second element of top level array, an array
    tempSD = array.get(1);
    Assert.assertEquals(OSDType.Array, tempSD.getType());
    array = (OSDArray)tempSD;
    Assert.assertEquals(3, array.count());
    //Nested array
    tempSD = array.get(2);
    Assert.assertEquals(OSDType.Array, tempSD.getType());
    array = (OSDArray)tempSD;
    Assert.assertEquals(3, array.count());
  }
View Full Code Here

TOP

Related Classes of com.ngt.jopenmetaverse.shared.structureddata.OSDArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.