Package com.ngt.jopenmetaverse.shared.structureddata

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


  /// but it should reveal basic nesting issues.
  /// </summary>
  @Test
  public void DeserializeNestedContainers()
  {
    OSD theSD = null;
    OSDArray array = null;
    OSDMap map = null;
    OSD tempSD = null;

    String testSD =  "[ \n" +
        "[ \n" +
          "{ \n" +
            "\"Map One\": \n" +
              "{ \n" +
                "\"Array One\": \n" +
                  "[ \n" +
                    "1.0, \n" +
                    "2.0 \n" +
                  "] \n" +
              "}\n" +
          "},\n" +
          "[ \n" +
            "\"A\", \n" +
            "\"B\", \n" +
            "[ \n" +
              "1.0, \n" +
              "4.0, \n" +
              "9.0 \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(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


          @Test
          public void DeserializeUndef() throws OSDException, IOException
          {
              String s = "!";
              OSD llsd = NotationalLLSDOSDParser.DeserializeLLSDNotation(s);
              Assert.assertEquals(OSDType.Unknown, llsd.getType());
          }
View Full Code Here

          }

          @Test
          public void SerializeUndef() throws IOException, OSDException
          {
              OSD llsd = new OSD();
              String s = NotationalLLSDOSDParser.SerializeLLSDNotation(llsd);

              OSD llsdDS = NotationalLLSDOSDParser.DeserializeLLSDNotation(s);
              Assert.assertEquals(OSDType.Unknown, llsdDS.getType());
          }
View Full Code Here

          @Test
          public void DeserializeBoolean() throws OSDException, IOException
          {
              String t = "true";
              OSD llsdT = NotationalLLSDOSDParser.DeserializeLLSDNotation(t);
              Assert.assertEquals(OSDType.Boolean, llsdT.getType());
              Assert.assertTrue(llsdT.asBoolean());

              String tTwo = "t";
              OSD llsdTTwo = NotationalLLSDOSDParser.DeserializeLLSDNotation(tTwo);
              Assert.assertEquals(OSDType.Boolean, llsdTTwo.getType());
              Assert.assertTrue(llsdTTwo.asBoolean());

              String tThree = "TRUE";
              OSD llsdTThree = NotationalLLSDOSDParser.DeserializeLLSDNotation(tThree);
              Assert.assertEquals(OSDType.Boolean, llsdTThree.getType());
              Assert.assertTrue(llsdTThree.asBoolean());

              String tFour = "T";
              OSD llsdTFour = NotationalLLSDOSDParser.DeserializeLLSDNotation(tFour);
              Assert.assertEquals(OSDType.Boolean, llsdTFour.getType());
              Assert.assertTrue(llsdTFour.asBoolean());

              String tFive = "1";
              OSD llsdTFive = NotationalLLSDOSDParser.DeserializeLLSDNotation(tFive);
              Assert.assertEquals(OSDType.Boolean, llsdTFive.getType());
              Assert.assertTrue(llsdTFive.asBoolean());

              String f = "false";
              OSD llsdF = NotationalLLSDOSDParser.DeserializeLLSDNotation(f);
              Assert.assertEquals(OSDType.Boolean, llsdF.getType());
              Assert.assertFalse(llsdF.asBoolean());

              String fTwo = "f";
              OSD llsdFTwo = NotationalLLSDOSDParser.DeserializeLLSDNotation(fTwo);
              Assert.assertEquals(OSDType.Boolean, llsdFTwo.getType());
              Assert.assertFalse(llsdFTwo.asBoolean());

              String fThree = "FALSE";
              OSD llsdFThree = NotationalLLSDOSDParser.DeserializeLLSDNotation(fThree);
              Assert.assertEquals(OSDType.Boolean, llsdFThree.getType());
              Assert.assertFalse(llsdFThree.asBoolean());

              String fFour = "F";
              OSD llsdFFour = NotationalLLSDOSDParser.DeserializeLLSDNotation(fFour);
              Assert.assertEquals(OSDType.Boolean, llsdFFour.getType());
              Assert.assertFalse(llsdFFour.asBoolean());

              String fFive = "0";
              OSD llsdFFive = NotationalLLSDOSDParser.DeserializeLLSDNotation(fFive);
              Assert.assertEquals(OSDType.Boolean, llsdFFive.getType());
              Assert.assertFalse(llsdFFive.asBoolean());
          }
View Full Code Here

          }

          @Test
          public void SerializeBoolean() throws IOException, OSDException
          {
              OSD llsdTrue = OSD.FromBoolean(true);
              String sTrue = NotationalLLSDOSDParser.SerializeLLSDNotation(llsdTrue);
              OSD llsdTrueDS = NotationalLLSDOSDParser.DeserializeLLSDNotation(sTrue);
              Assert.assertEquals(OSDType.Boolean, llsdTrueDS.getType());
              Assert.assertTrue(llsdTrueDS.asBoolean());

              OSD llsdFalse = OSD.FromBoolean(false);
              String sFalse = NotationalLLSDOSDParser.SerializeLLSDNotation(llsdFalse);
              OSD llsdFalseDS = NotationalLLSDOSDParser.DeserializeLLSDNotation(sFalse);
              Assert.assertEquals(OSDType.Boolean, llsdFalseDS.getType());
              Assert.assertFalse(llsdFalseDS.asBoolean());
          }
View Full Code Here

          @Test
          public void DeserializeInteger() throws OSDException, IOException
          {
              String integerOne = "i12319423";
              OSD llsdOne = NotationalLLSDOSDParser.DeserializeLLSDNotation(integerOne);
              Assert.assertEquals(OSDType.Integer, llsdOne.getType());
              Assert.assertEquals(12319423, llsdOne.asInteger());

              String integerTwo = "i-489234";
              OSD llsdTwo = NotationalLLSDOSDParser.DeserializeLLSDNotation(integerTwo);
              Assert.assertEquals(OSDType.Integer, llsdTwo.getType());
              Assert.assertEquals(-489234, llsdTwo.asInteger());
          }
View Full Code Here

          }

          @Test
          public void SerializeInteger() throws IOException, OSDException
          {
              OSD llsdOne = OSD.FromInteger(12319423);
              String sOne = NotationalLLSDOSDParser.SerializeLLSDNotation(llsdOne);
              OSD llsdOneDS = NotationalLLSDOSDParser.DeserializeLLSDNotation(sOne);
              Assert.assertEquals(OSDType.Integer, llsdOneDS.getType());
              Assert.assertEquals(12319423, llsdOne.asInteger());

              OSD llsdTwo = OSD.FromInteger(-71892034);
              String sTwo = NotationalLLSDOSDParser.SerializeLLSDNotation(llsdTwo);
              OSD llsdTwoDS = NotationalLLSDOSDParser.DeserializeLLSDNotation(sTwo);
              Assert.assertEquals(OSDType.Integer, llsdTwoDS.getType());
              Assert.assertEquals(-71892034, llsdTwoDS.asInteger());
          }
View Full Code Here

          @Test
          public void DeserializeReal() throws OSDException, IOException
          {
              String realOne = "r1123412345.465711";
              OSD llsdOne = NotationalLLSDOSDParser.DeserializeLLSDNotation(realOne);
              Assert.assertEquals(OSDType.Real, llsdOne.getType());
              Assert.assertEquals(1123412345.465711d, llsdOne.asReal(), 0);

              String realTwo = "r-11234684.923411";
              OSD llsdTwo = NotationalLLSDOSDParser.DeserializeLLSDNotation(realTwo);
              Assert.assertEquals(OSDType.Real, llsdTwo.getType());
              Assert.assertEquals(-11234684.923411d, llsdTwo.asReal(), 0);

              String realThree = "r1";
              OSD llsdThree = NotationalLLSDOSDParser.DeserializeLLSDNotation(realThree);
              Assert.assertEquals(OSDType.Real, llsdThree.getType());
              Assert.assertEquals(1d, llsdThree.asReal(), 0);

              String realFour = "r2.0193899999999998204e-06";
              OSD llsdFour = NotationalLLSDOSDParser.DeserializeLLSDNotation(realFour);
              Assert.assertEquals(OSDType.Real, llsdFour.getType());
              Assert.assertEquals(2.0193899999999998204e-06d, llsdFour.asReal(), 0);

              String realFive = "r0";
              OSD llsdFive = NotationalLLSDOSDParser.DeserializeLLSDNotation(realFive);
              Assert.assertEquals(OSDType.Real, llsdFive.getType());
              Assert.assertEquals(0d, llsdFive.asReal(), 0);
          }
View Full Code Here

          }

          @Test
          public void SerializeReal() throws IOException, OSDException
          {
              OSD llsdOne = OSD.FromReal(12987234.723847d);
              String sOne = NotationalLLSDOSDParser.SerializeLLSDNotation(llsdOne);
              OSD llsdOneDS = NotationalLLSDOSDParser.DeserializeLLSDNotation(sOne);
              Assert.assertEquals(OSDType.Real, llsdOneDS.getType());
              Assert.assertEquals(12987234.723847d, llsdOneDS.asReal(), 0);

              OSD llsdTwo = OSD.FromReal(-32347892.234234d);
              String sTwo = NotationalLLSDOSDParser.SerializeLLSDNotation(llsdTwo);
              OSD llsdTwoDS = NotationalLLSDOSDParser.DeserializeLLSDNotation(sTwo);
              Assert.assertEquals(OSDType.Real, llsdTwoDS.getType());
              Assert.assertEquals(-32347892.234234d, llsdTwoDS.asReal(), 0);

              OSD llsdThree = OSD.FromReal( Double.MAX_VALUE );
              String sThree = NotationalLLSDOSDParser.SerializeLLSDNotation( llsdThree );
              OSD llsdThreeDS = NotationalLLSDOSDParser.DeserializeLLSDNotation( sThree );
              Assert.assertEquals( OSDType.Real, llsdThreeDS.getType() );
              Assert.assertEquals( Double.MAX_VALUE, llsdThreeDS.asReal(), 0);
         
              OSD llsdFour = OSD.FromReal(Double.MIN_VALUE);
              String sFour = NotationalLLSDOSDParser.SerializeLLSDNotation(llsdFour);
              OSD llsdFourDS = NotationalLLSDOSDParser.DeserializeLLSDNotation(sFour);
              Assert.assertEquals(OSDType.Real, llsdFourDS.getType());
              Assert.assertEquals(Double.MIN_VALUE, llsdFourDS.asReal(), 0);

              OSD llsdFive = OSD.FromReal(-1.1123123E+50d);
              String sFive = NotationalLLSDOSDParser.SerializeLLSDNotation(llsdFive);
              OSD llsdFiveDS = NotationalLLSDOSDParser.DeserializeLLSDNotation(sFive);
              Assert.assertEquals(OSDType.Real, llsdFiveDS.getType());
              Assert.assertEquals(-1.1123123E+50d, llsdFiveDS.asReal(), 0);

              OSD llsdSix = OSD.FromReal(2.0193899999999998204e-06);
              String sSix = NotationalLLSDOSDParser.SerializeLLSDNotation(llsdSix);
              OSD llsdSixDS = NotationalLLSDOSDParser.DeserializeLLSDNotation(sSix);
              Assert.assertEquals(OSDType.Real, llsdSixDS.getType());
              Assert.assertEquals(2.0193899999999998204e-06, llsdSixDS.asReal(), 0);
          }
View Full Code Here

          @Test
          public void DeserializeUUID() throws OSDException, IOException
          {
              String uuidOne = "u97f4aeca-88a1-42a1-b385-b97b18abb255";
              OSD llsdOne = NotationalLLSDOSDParser.DeserializeLLSDNotation(uuidOne);
              Assert.assertEquals(OSDType.UUID, llsdOne.getType());
              Assert.assertEquals("97f4aeca-88a1-42a1-b385-b97b18abb255", llsdOne.asString());

              String uuidTwo = "u00000000-0000-0000-0000-000000000000";
              OSD llsdTwo = NotationalLLSDOSDParser.DeserializeLLSDNotation(uuidTwo);
              Assert.assertEquals(OSDType.UUID, llsdTwo.getType());
              Assert.assertEquals("00000000-0000-0000-0000-000000000000", llsdTwo.asString());
          }
View Full Code Here

TOP

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

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.