Package com.ngt.jopenmetaverse.shared.structureddata

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


    String testThree = "{'region_handle':[r255232, r256512], 'position':[r33.6, r33.71, r43.13], 'look_at':[r34.6, r33.71, r43.13]}";

    OSD obj = NotationalLLSDOSDParser.DeserializeLLSDNotation(testOne);
   
    Assert.assertTrue("Expected SDArray, got " + obj.getType().toString(), obj instanceof OSDArray);
    OSDArray array = (OSDArray)obj;
    Assert.assertTrue("Expected three contained objects, got " + array.count(), array.count() == 3);
    Assert.assertTrue("Unexpected value for first real " + array.get(0).asReal(), array.get(0).asReal() > 0.9d && array.get(0).asReal() < 1.0d);
    Assert.assertTrue("Unexpected value for second real " + array.get(1).asReal(), array.get(1).asReal() < 0.0d && array.get(1).asReal() > -0.03d);
    Assert.assertTrue("Unexpected value for third real " + array.get(2).asReal(), array.get(2).asReal() == 0.0d);

    obj = NotationalLLSDOSDParser.DeserializeLLSDNotation(testTwo);
    Assert.assertTrue("Expected SDArray, got " + obj.getType().toString(), obj instanceof OSDArray);
    array = (OSDArray)obj;
    Assert.assertTrue("Expected two contained objects, got " + array.count(), array.count() == 2);
    Assert.assertTrue("Unexpected value for real " + array.get(1).asReal(), array.get(1).asReal() == 0.0d);
    obj = array.get(0);
    Assert.assertTrue("Expected ArrayList, got " + obj.getType().toString(), obj instanceof OSDArray);
    array = (OSDArray)obj;
    Assert.assertTrue("Unexpected value(s) for nested array: " + array.get(0).asReal() + ", " + array.get(1).asReal() + ", " +
        array.get(2).asReal(), array.get(0).asReal() == 1.0d && array.get(1).asReal() == 1.0d && array.get(2).asReal() == 1.0d);

    obj = NotationalLLSDOSDParser.DeserializeLLSDNotation(testThree);
    Assert.assertTrue("Expected LLSDMap, got " + obj.getType().toString(), obj instanceof OSDMap);
    OSDMap hashtable = (OSDMap)obj;
    Assert.assertTrue("Expected three contained objects, got " + hashtable.count(), hashtable.count() == 3);
View Full Code Here


      "]\n" +
    "}\n" +
  "]\n";
              // We dont do full testing here. We are fine if a few values are right
              // and the parser doesnt throw an exception
              OSDArray llsdArray = (OSDArray)NotationalLLSDOSDParser.DeserializeLLSDNotation(realWorldExample);
              Assert.assertEquals(OSDType.Array, llsdArray.getType());
              Assert.assertEquals(3, llsdArray.count());

              OSDMap llsdMapOne = (OSDMap)llsdArray.get(0);
              Assert.assertEquals(OSDType.Map, llsdMapOne.getType());
              Assert.assertEquals("http://secondlife.com", llsdMapOne.get("destination").asString());

              OSDMap llsdMapTwo = (OSDMap)llsdArray.get(1);
              Assert.assertEquals(OSDType.Map, llsdMapTwo.getType());
              Assert.assertEquals(OSDType.Integer, llsdMapTwo.get("version").getType());
              Assert.assertEquals(1, llsdMapTwo.get("version").asInteger());

              OSDMap llsdMapThree = (OSDMap)llsdArray.get(2);
              Assert.assertEquals(OSDType.UUID, llsdMapThree.get("session_id").getType());
              Assert.assertEquals("2c585cec-038c-40b0-b42e-a25ebab4d132", llsdMapThree.get("session_id").asString());
              Assert.assertEquals(OSDType.UUID, llsdMapThree.get("agent_id").getType());
              Assert.assertEquals("3c115e51-04f4-523c-9fa6-98aff1034730", llsdMapThree.get("agent_id").asString());
View Full Code Here

          @Test
          public void SerializeFormattedTest() throws IOException, OSDException
          {
              // This is not a real test. Instead look at the console.out tab for how formatted notation looks like.
              OSDArray llsdArray = new OSDArray();
              OSD llsdOne = OSD.FromInteger(1);
              OSD llsdTwo = OSD.FromInteger(1);
              llsdArray.add(llsdOne);
              llsdArray.add(llsdTwo);
                         
              OSDMap llsdMap = new OSDMap();
              OSD llsdThree = OSD.FromInteger(2);
              llsdMap.put("test1", llsdThree);
              OSD llsdFour = OSD.FromInteger(2);
              llsdMap.put("test2", llsdFour);

              llsdArray.add(llsdMap);
             
              OSDArray llsdArrayTwo = new OSDArray();
              OSD llsdFive = OSD.FromString("asdflkhjasdhj");
              OSD llsdSix = OSD.FromString("asdkfhasjkldfghsd");
              llsdArrayTwo.add(llsdFive);
              llsdArrayTwo.add(llsdSix);

              llsdMap.put("test3",  llsdArrayTwo);

              String sThree = NotationalLLSDOSDParser.SerializeLLSDNotationFormatted(llsdArray);

              // we also try to parse this... and look a little at the results
              OSDArray llsdSeven = (OSDArray)NotationalLLSDOSDParser.DeserializeLLSDNotation(sThree);
              Assert.assertEquals(OSDType.Array, llsdSeven.getType());
              Assert.assertEquals(3, llsdSeven.count());
              Assert.assertEquals(OSDType.Integer, llsdSeven.get(0).getType());
              Assert.assertEquals(1, llsdSeven.get(0).asInteger());
              Assert.assertEquals(OSDType.Integer, llsdSeven.get(1).getType());
              Assert.assertEquals(1, llsdSeven.get(1).asInteger());

              Assert.assertEquals(OSDType.Map, llsdSeven.get(2).getType());
              // thats enough for now.           
          }
View Full Code Here

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

    String testSD ="[ \n" +
        "[ \n" +
        "44.38898, \n" +
//        "<real>nan</real> \n" +
        "4.0, \n" +
        "-13.333, \n" +
        "0.0 \n" +
        "], \n" +
        "]";
    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =JsonLLSDOSDParser.DeserializeLLSDJson(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(1).getType());
    tempReal = (OSDReal)array.get(1);
    Assert.assertEquals(4.0d, tempReal.asReal(), 0);

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

    Assert.assertEquals(OSDType.Real, array.get(3).getType());
    tempReal = (OSDReal)array.get(3);
    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 = "[ \n" +
        "[ \n" +
        "\"Kissling\", \n" +
        "\"Attack ships on fire off the shoulder of Orion\", \n" +
        "\"&lt; &gt; &amp; &apos; &quot;\", \n" +
        "\"\", \n" +
        "\"    \" \n" +
        "] \n" +
        "]";
    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =JsonLLSDOSDParser.DeserializeLLSDJson(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("&lt; &gt; &amp; &apos; &quot;", tempStr.asString());

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

    Assert.assertEquals(OSDType.String, array.get(4).getType());
    tempStr = (OSDString)array.get(4);
    Assert.assertEquals("    ", tempStr.asString());
   
  }
View Full Code Here

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

    String testSD ="[ \n" +
        "[ \n" +
        "2147483647, \n" +
        "-2147483648, \n" +
        "0, \n" +
        "013, \n" +
        "0 \n" +
        "] \n" +
        "]";
    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =JsonLLSDOSDParser.DeserializeLLSDJson(bytes);

    System.out.println("=========" + theSD.getType().toString());
   
    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 = "[ \n" +
        "[ \n" +
        "\"d7f4aeca-88f1-42a1-b385-b9db18abb255\",\n" +
        "\"00000000-0000-0000-0000-000000000000\" \n" +
        "] \n" +
        "]";
    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =JsonLLSDOSDParser.DeserializeLLSDJson(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 = "[ \n" +
        "[ \n" +
        "\"2006-02-01T14:29:53Z\", \n" +
        "\"1999-01-01T00:00:00Z\" \n" +
        "] \n" +
        "]";
    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =JsonLLSDOSDParser.DeserializeLLSDJson(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);
View Full Code Here

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

    String testSD = "[ \n" +
        "[ \n" +
        "true, \n" +
        "false \n" +
        "] \n" +
        "]";
    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =JsonLLSDOSDParser.DeserializeLLSDJson(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(false, tempBool.asBoolean());
  }
View Full Code Here

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

    String str1 = "This is test String 1";
    byte[] bytes1 = Utils.stringToBytes(str1);
    String str2 = "This is test String 2";
    byte[] bytes2 = Utils.stringToBytes(str2);
   
   
    String testSD = "[ \n" +
        "[ \n" +
        bytesToJsonArrayString(bytes1) + ", \n" +
        bytesToJsonArrayString(bytes2) + "\n" +
        "] \n" +
        "]";

    System.out.println(testSD);
   
    //Deserialize the string
    byte[] bytes = Utils.stringToBytes(testSD);
    theSD =JsonLLSDOSDParser.DeserializeLLSDJson(bytes);

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

    Assert.assertEquals(OSDType.Binary, array.get(0).getType());
    tempBinary = (OSDBinary)array.get(0);
    byte[] testData1 = bytes1;
    TestHelper.TestBinary(tempBinary, testData1);

    Assert.assertEquals(OSDType.Binary, array.get(1).getType());
    tempBinary = (OSDBinary)array.get(1);
    byte[] testData2 = bytes2;
    TestHelper.TestBinary(tempBinary, testData2);
  }
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.