Ejemplo n.º 1
0
        internal static ITag ParseValue(BinaryReader reader, byte id)
        {
            switch (id)
            {
            case TagBoolean.TypeId: return(TagBoolean.Parse(reader));

            case TagByte.TypeId: return(TagByte.Parse(reader));

            case TagShort.TypeId: return(TagShort.Parse(reader));

            case TagInt.TypeId: return(TagInt.Parse(reader));

            case TagFloat.TypeId: return(TagFloat.Parse(reader));

            case TagLong.TypeId: return(TagLong.Parse(reader));

            case TagDouble.TypeId: return(TagDouble.Parse(reader));

            case TagString.TypeId: return(TagString.Parse(reader));

            case TagCompound.TypeId: return(TagCompound.Parse(reader));

            case TagList.TypeId: return(TagList.Parse(reader));

            default: throw new FormatException("Invalid type ID: " + id + ". At file position " + reader.BaseStream.Position);
            }
        }
Ejemplo n.º 2
0
        public override void WritePayload(Stream stream, INamedBinaryTag iTag)
        {
            TagLong tag = iTag as TagLong;

            byte[] data = BitConverter.GetBytes(tag.Value);
            data = data.ReverseIfLittleEndian();
            stream.Write(data, 0, 8);
        }
Ejemplo n.º 3
0
        public static TagCompound ParseCompound(JsonReader reader, string rootName = "")
        {
            TagCompound res     = new TagCompound(rootName);
            string      tagName = null;

            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.PropertyName)
                {
                    tagName = reader.Value as string;
                }

                if (reader.TokenType == JsonToken.Boolean)
                {
                    bool    b   = (bool)reader.Value;
                    TagByte tag = new TagByte(tagName, b);
                    res.Set(tag);
                }
                else if (reader.TokenType == JsonToken.Integer)
                {
                    long    l   = (long)reader.Value;
                    TagLong tag = new TagLong(tagName, l);
                    res.Set(tag);
                }
                else if (reader.TokenType == JsonToken.Float)
                {
                    double    d   = (double)reader.Value;
                    TagDouble tag = new TagDouble(tagName, d);
                    res.Set(tag);
                }
                else if (reader.TokenType == JsonToken.String)
                {
                    string    s   = reader.Value as string;
                    TagString tag = new TagString(tagName, s);
                    res.Set(tag);
                }
                else if (reader.TokenType == JsonToken.StartObject)
                {
                    TagCompound tag = ParseCompound(reader);
                    res.Set(tag);
                }
                else if (reader.TokenType == JsonToken.StartArray)
                {
                    TagList list = ParseList(reader, tagName);
                    res.Set(list);
                }
                else if (reader.TokenType == JsonToken.EndObject)
                {
                    return(res);
                }
            }

            return(res);
        }
Ejemplo n.º 4
0
        public static TagCompound ParseCompound(JsonReader reader, string rootName = "")
        {
            TagCompound res = new TagCompound(rootName);
            string tagName = null;
            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.PropertyName)
                {
                    tagName = reader.Value as string;
                }

                if (reader.TokenType == JsonToken.Boolean)
                {
                    bool b = (bool)reader.Value;
                    TagByte tag = new TagByte(tagName, b);
                    res.Set(tag);
                }
                else if (reader.TokenType == JsonToken.Integer)
                {
                    long l = (long)reader.Value;
                    TagLong tag = new TagLong(tagName, l);
                    res.Set(tag);
                }
                else if (reader.TokenType == JsonToken.Float)
                {
                    double d = (double)reader.Value;
                    TagDouble tag = new TagDouble(tagName, d);
                    res.Set(tag);
                }
                else if (reader.TokenType == JsonToken.String)
                {
                    string s = reader.Value as string;
                    TagString tag = new TagString(tagName, s);
                    res.Set(tag);
                }
                else if (reader.TokenType == JsonToken.StartObject)
                {
                    TagCompound tag = ParseCompound(reader);
                    res.Set(tag);
                }
                else if (reader.TokenType == JsonToken.StartArray)
                {
                    TagList list = ParseList(reader, tagName);
                    res.Set(list);
                }
                else if (reader.TokenType == JsonToken.EndObject)
                {
                    return res;
                }
            }

            return res;
        }
Ejemplo n.º 5
0
    public void ConstructorWithValueTest()
    {
      // arrange
      TagLong tag;
      long value;

      value = long.MaxValue;

      // act
      tag = new TagLong(value);

      // assert
      Assert.IsEmpty(tag.Name);
      Assert.AreEqual(value, tag.Value);
    }
Ejemplo n.º 6
0
    public void ConstructorTest()
    {
      // arrange
      TagLong tag;
      long expected;

      expected = 0;

      // act
      tag = new TagLong();

      // assert
      Assert.IsEmpty(tag.Name);
      Assert.AreEqual(expected, tag.Value);
    }
        public void Equals_returns_false_with_different_value()
        {
            // arrange
            TagLong target;
            TagLong other;
            bool    actual;

            target = new TagLong(string.Empty, 4611686018427387903);
            other  = new TagLong(string.Empty, 2305843009213693951);

            // act
            actual = target.Equals(other);

            // assert
            Assert.IsFalse(actual);
        }
        public void Constructor_sets_name()
        {
            // arrange
            TagLong target;
            string  expected;
            string  actual;

            expected = "Alphatag";

            // act
            target = new TagLong(expected);

            // assert
            actual = target.Name;
            Assert.AreEqual(expected, actual);
        }
        public void Equals_returns_true_for_matching_tag()
        {
            // arrange
            TagLong target;
            TagLong other;
            bool    actual;

            target = new TagLong("alpha", 4611686018427387903);
            other  = new TagLong("alpha", 4611686018427387903);

            // act
            actual = target.Equals(other);

            // assert
            Assert.IsTrue(actual);
        }
Ejemplo n.º 10
0
        public void Constructor_sets_value()
        {
            // arrange
            TagLong target;
            long    expected;
            long    actual;

            expected = 4611686018427387903;

            // act
            target = new TagLong(string.Empty, expected);

            // assert
            actual = target.Value;
            Assert.Equal(expected, actual);
        }
        public void Constructor_sets_value_without_name()
        {
            // arrange
            TagLong target;
            long    expected;
            long    actual;

            expected = 4611686018427387903;

            // act
            target = new TagLong(expected);

            // assert
            actual = target.Value;
            Assert.AreEqual(expected, actual);
        }
        public void Constructor_sets_default_name()
        {
            // arrange
            TagLong target;
            string  expected;
            string  actual;

            expected = string.Empty;

            // act
            target = new TagLong();

            // assert
            actual = target.Name;
            Assert.AreEqual(expected, actual);
        }
        public void Constructor_sets_default_value()
        {
            // arrange
            TagLong target;
            long    expected;
            long    actual;

            expected = 0;

            // act
            target = new TagLong();

            // assert
            actual = target.Value;
            Assert.AreEqual(expected, actual);
        }
        public void Equals_returns_false_with_different_name()
        {
            // arrange
            TagLong target;
            TagLong other;
            bool    actual;

            target = new TagLong("Alpha", 4611686018427387903);
            other  = new TagLong("Beta", 4611686018427387903);

            // act
            actual = target.Equals(other);

            // assert
            Assert.IsFalse(actual);
        }
        public void GetHashCode_returns_different_values_with_different_value()
        {
            // arrange
            TagLong target;
            int     actual;
            int     notExpected;

            target = new TagLong(string.Empty, 4611686018427387903);

            notExpected = new TagLong(string.Empty, 2305843009213693951).GetHashCode();

            // act
            actual = target.GetHashCode();

            // assert
            Assert.AreNotEqual(notExpected, actual);
        }
        public void Type_returns_correct_value()
        {
            // arrange
            TagLong target;
            TagType expected;
            TagType actual;

            target = new TagLong();

            expected = TagType.Long;

            // act
            actual = target.Type;

            // assert
            Assert.AreEqual(expected, actual);
        }
        public void ToString_returns_string_version_of_tag()
        {
            // arrange
            TagLong target;
            string  expected;
            string  actual;

            expected = "[Long: gamma=4611686018427387903]";

            target = new TagLong("gamma", 4611686018427387903);

            // act
            actual = target.ToString();

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 18
0
    public void ConstructorWithNameAndValueTest()
    {
      // arrange
      TagLong tag;
      string name;
      long value;

      name = "creationDate";
      value = long.MaxValue;

      // act
      tag = new TagLong(name, value);

      // assert
      Assert.AreEqual(name, tag.Name);
      Assert.AreEqual(value, tag.Value);
    }
        public void GetHashCode_returns_same_value_for_matching_tags()
        {
            // arrange
            TagLong target;
            int     actual;
            int     expected;

            target = new TagLong("beta", 4611686018427387903);

            expected = new TagLong("beta", 4611686018427387903).GetHashCode();

            // act
            actual = target.GetHashCode();

            // assert
            Assert.AreEqual(expected, actual);
        }
        public void GetHashCode_returns_different_values_with_different_name()
        {
            // arrange
            TagLong target;
            int     actual;
            int     notExpected;

            target = new TagLong("Alpha", 4611686018427387903);

            notExpected = new TagLong("Beta", 4611686018427387903).GetHashCode();

            // act
            actual = target.GetHashCode();

            // assert
            Assert.AreNotEqual(notExpected, actual);
        }
Ejemplo n.º 21
0
    public void ConstructorWithNameTest()
    {
      // arrange
      TagLong tag;
      string name;
      long expected;

      name = "creationDate";
      expected = 0;

      // act
      tag = new TagLong(name);

      // assert
      Assert.AreEqual(name, tag.Name);
      Assert.AreEqual(expected, tag.Value);
    }
        public void ToValueString_returns_string_version_of_value()
        {
            // arrange
            TagLong target;
            string  expected;
            string  actual;

            expected = "4611686018427387903";

            target = new TagLong(string.Empty, 4611686018427387903);

            // act
            actual = target.ToValueString();

            // assert
            Assert.AreEqual(expected, actual);
        }
        public void SetValue_updates_value()
        {
            // arrange
            Tag  target;
            long expected;
            long actual;

            target = new TagLong();

            expected = 4611686018427387903;

            // act
            target.SetValue(expected);

            // assert
            actual = ((TagLong)target).Value;
            Assert.AreEqual(expected, actual);
        }
        public void Value_can_be_set()
        {
            // arrange
            TagLong target;
            long    expected;
            long    actual;

            expected = 4611686018427387903;

            target = new TagLong();

            // act
            target.Value = expected;

            // assert
            actual = target.Value;
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 25
0
        public override object ParsePayload(Stream stream, INamedBinaryTag tagBase)
        {
            byte[] data = new byte[8];
            if (stream.Read(data, 0, 8) < 8)
            {
                throw new EndOfStreamException("End of stream reached inside of tag. Put those bytes back!");
            }

            data = data.ReverseIfLittleEndian();
            long val = BitConverter.ToInt64(data, 0);

            TagLong tag = tagBase as TagLong;

            if (tag == null)
            {
                throw new InvalidCastException("Wrong NBT type! Expected TagLong, found " + tagBase.GetType().Name);
            }
            tag.Value = val;
            return(val);
        }
Ejemplo n.º 26
0
        private TagBase GetArrayedTag()
        {
            CheckCharacter('[');
            char c0 = NextJsonAt();

            NextJsonAt();
            SkipWhiteSpace();

            if (!InTextLength())
            {
                throw GenerateException("Expected value");
            }
            else if (c0 == 'B')
            {
                return(new TagByteArray(CatchArrayItems <byte>(TagType.ByteArray, TagType.Byte, e =>
                {
                    TagByte tag = e as TagByte;
                    return e != null ? tag.Value : (byte)0;
                })));
            }
            else if (c0 == 'L')
            {
                return(new TagLongArray(CatchArrayItems <long>(TagType.LongArray, TagType.Long, e =>
                {
                    TagLong tag = e as TagLong;
                    return e != null ? tag.Value : 0;
                })));
            }
            else if (c0 == 'I')
            {
                return(new TagIntArray(CatchArrayItems <int>(TagType.IntArray, TagType.Int, e =>
                {
                    TagInt tag = e as TagInt;
                    return e != null ? tag.Value : 0;
                })));
            }
            else
            {
                throw GenerateException("Invalid array type '" + c0 + "' found");
            }
        }
Ejemplo n.º 27
0
        public void TestLoadComplexNbt()
        {
            Tag tag;

            tag = this.CreateComplexData();

            Assert.IsNotNull(tag);
            Assert.IsInstanceOf <TagCompound>(tag);
            TagCompound level = tag as TagCompound;

            Assert.AreEqual("Level", level.Name);

            TagShort shortTest = level.GetShort("shortTest");

            Assert.IsNotNull(shortTest);
            Assert.AreEqual("shortTest", shortTest.Name);
            Assert.AreEqual(32767, shortTest.Value);

            TagLong longTest = level.GetLong("longTest");

            Assert.IsNotNull(longTest);
            Assert.AreEqual("longTest", longTest.Name);
            Assert.AreEqual(9223372036854775807, longTest.Value);

            TagFloat floatTest = level.GetFloat("floatTest");

            Assert.IsNotNull(floatTest);
            Assert.AreEqual("floatTest", floatTest.Name);
            Assert.AreEqual(0.49823147f, floatTest.Value);

            TagString stringTest = level.GetString("stringTest");

            Assert.IsNotNull(stringTest);
            Assert.AreEqual("stringTest", stringTest.Name);
            Assert.AreEqual("HELLO WORLD THIS IS A TEST STRING едж!", stringTest.Value);

            TagInt intTest = level.GetInt("intTest");

            Assert.IsNotNull(intTest);
            Assert.AreEqual("intTest", intTest.Name);
            Assert.AreEqual(2147483647, intTest.Value);

            TagCompound nestedCompoundTest = level.GetCompound("nested compound test");

            Assert.IsNotNull(nestedCompoundTest);
            Assert.AreEqual("nested compound test", nestedCompoundTest.Name);

            TagCompound ham = nestedCompoundTest.GetCompound("ham");

            Assert.IsNotNull(ham);
            Assert.AreEqual("ham", ham.Name);

            TagString ham_name = ham.GetString("name");

            Assert.IsNotNull(ham_name);
            Assert.AreEqual("name", ham_name.Name);
            Assert.AreEqual("Hampus", ham_name.Value);

            TagFloat ham_value = ham.GetFloat("value");

            Assert.IsNotNull(ham_value);
            Assert.AreEqual("value", ham_value.Name);
            Assert.AreEqual(0.75f, ham_value.Value);

            TagCompound egg = nestedCompoundTest.GetCompound("egg");

            Assert.IsNotNull(egg);
            Assert.AreEqual("egg", egg.Name);

            TagString egg_name = egg.GetString("name");

            Assert.IsNotNull(egg_name);
            Assert.AreEqual("name", egg_name.Name);
            Assert.AreEqual("Eggbert", egg_name.Value);

            TagFloat egg_value = egg.GetFloat("value");

            Assert.IsNotNull(egg_value);
            Assert.AreEqual("value", egg_value.Name);
            Assert.AreEqual(0.5f, egg_value.Value);

            TagByte byteTest = level.GetByte("byteTest");

            Assert.IsNotNull(byteTest);
            Assert.AreEqual("byteTest", byteTest.Name);
            Assert.AreEqual(0x7f, byteTest.Value);

            TagDouble doubleTest = level.GetDouble("doubleTest");

            Assert.IsNotNull(doubleTest);
            Assert.AreEqual("doubleTest", doubleTest.Name);
            Assert.AreEqual(0.4931287132182315, doubleTest.Value);

            TagList listTest_long = level.GetList("listTest (long)");

            Assert.IsNotNull(listTest_long);
            Assert.AreEqual("listTest (long)", listTest_long.Name);
            Assert.IsNotNull(listTest_long.Value);
            Assert.AreEqual(5, listTest_long.Value.Count);
            Assert.AreEqual(11, (listTest_long.Value[0] as TagLong).Value);
            Assert.AreEqual(12, (listTest_long.Value[1] as TagLong).Value);
            Assert.AreEqual(13, (listTest_long.Value[2] as TagLong).Value);
            Assert.AreEqual(14, (listTest_long.Value[3] as TagLong).Value);
            Assert.AreEqual(15, (listTest_long.Value[4] as TagLong).Value);

            TagList listTest_compound = level.GetList("listTest (compound)");

            Assert.IsNotNull(listTest_compound);
            Assert.AreEqual("listTest (compound)", listTest_compound.Name);
            Assert.IsNotNull(listTest_compound.Value);
            Assert.AreEqual(2, listTest_compound.Value.Count);
            TagCompound listTest_compound_tag0 = listTest_compound.Value[0] as TagCompound;

            Assert.IsNotNull(listTest_compound_tag0);
            TagString listTest_compound_tag0_name = listTest_compound_tag0.GetString("name");

            Assert.IsNotNull(listTest_compound_tag0_name);
            Assert.AreEqual("name", listTest_compound_tag0_name.Name);
            Assert.AreEqual("Compound tag #0", listTest_compound_tag0_name.Value);
            TagLong listTest_compound_tag0_createdOn = listTest_compound_tag0.GetLong("created-on");

            Assert.IsNotNull(listTest_compound_tag0_createdOn);
            Assert.AreEqual("created-on", listTest_compound_tag0_createdOn.Name);
            Assert.AreEqual(1264099775885, listTest_compound_tag0_createdOn.Value);

            TagCompound listTest_compound_tag1 = listTest_compound.Value[1] as TagCompound;

            Assert.IsNotNull(listTest_compound_tag1);
            TagString listTest_compound_tag1_name = listTest_compound_tag1.GetString("name");

            Assert.IsNotNull(listTest_compound_tag1_name);
            Assert.AreEqual("name", listTest_compound_tag1_name.Name);
            Assert.AreEqual("Compound tag #1", listTest_compound_tag1_name.Value);
            TagLong listTest_compound_tag1_createdOn = listTest_compound_tag1.GetLong("created-on");

            Assert.IsNotNull(listTest_compound_tag1_createdOn);
            Assert.AreEqual("created-on", listTest_compound_tag1_createdOn.Name);
            Assert.AreEqual(1264099775885, listTest_compound_tag1_createdOn.Value);

            TagByteArray byteArrayTest = level.GetByteArray("byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...))");

            Assert.IsNotNull(byteArrayTest);
            Assert.AreEqual("byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...))", byteArrayTest.Name);
            Assert.IsNotNull(byteArrayTest.Value);
            Assert.AreEqual(1000, byteArrayTest.Value.Length);
        }
Ejemplo n.º 28
0
        public static TagList ParseList(JsonReader reader, string rootName)
        {
            TagList list = new TagList(rootName);
            bool foundGeneric = false;
            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.Boolean)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric = true;
                        list.GenericType = ETagType.Byte;
                    }

                    bool b = (bool)reader.Value;
                    TagByte tag = new TagByte(null, b);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.Integer)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric = true;
                        list.GenericType = ETagType.Long;
                    }

                    long l = (long)reader.Value;
                    TagLong tag = new TagLong(null, l);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.Float)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric = true;
                        list.GenericType = ETagType.Float;
                    }
                    else if (list.GenericType == ETagType.Long)
                    {
                        List<TagDouble> buf = new List<TagDouble>();
                        foreach (TagLong tl in list)
                        {
                            buf.Add(new TagDouble(tl.Name, tl.Value));
                        }
                        list.Clear();
                        list.GenericType = ETagType.Double;
                        foreach (TagDouble td in buf)
                        {
                            list.Add(td);
                        }
                    }

                    double d = (double)reader.Value;
                    TagDouble tag = new TagDouble(null, d);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.String)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric = true;
                        list.GenericType = ETagType.String;
                    }

                    string s = reader.Value as string;
                    TagString tag = new TagString(null, s);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.StartObject)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric = true;
                        list.GenericType = ETagType.Compound;
                    }

                    TagCompound tag = ParseCompound(reader, null);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.StartArray)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric = true;
                        list.GenericType = ETagType.List;
                    }

                    TagList inner = ParseList(reader, null);
                    list.Add(inner);
                }
                else if (reader.TokenType == JsonToken.EndArray)
                {
                    return list;
                }
                else
                {
                    throw new NotImplementedException("Currently no handling for this type of JSON token: " + reader.TokenType.ToString());
                }
            }

            return list;
        }
Ejemplo n.º 29
0
    public void ToStringTest()
    {
      // arrange
      TagLong target;
      string expected;
      string actual;
      string name;
      long value;

      name = "tagname";
      value = long.MaxValue;
      expected = string.Format("[Long: {0}={1}]", name, value);
      target = new TagLong(name, value);

      // act
      actual = target.ToString();

      // assert
      Assert.AreEqual(expected, actual);
    }
Ejemplo n.º 30
0
        public static TagList ParseList(JsonReader reader, string rootName)
        {
            TagList list         = new TagList(rootName);
            bool    foundGeneric = false;

            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.Boolean)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric     = true;
                        list.GenericType = ETagType.Byte;
                    }

                    bool    b   = (bool)reader.Value;
                    TagByte tag = new TagByte(null, b);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.Integer)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric     = true;
                        list.GenericType = ETagType.Long;
                    }

                    long    l   = (long)reader.Value;
                    TagLong tag = new TagLong(null, l);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.Float)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric     = true;
                        list.GenericType = ETagType.Float;
                    }
                    else if (list.GenericType == ETagType.Long)
                    {
                        List <TagDouble> buf = new List <TagDouble>();
                        foreach (TagLong tl in list)
                        {
                            buf.Add(new TagDouble(tl.Name, tl.Value));
                        }
                        list.Clear();
                        list.GenericType = ETagType.Double;
                        foreach (TagDouble td in buf)
                        {
                            list.Add(td);
                        }
                    }

                    double    d   = (double)reader.Value;
                    TagDouble tag = new TagDouble(null, d);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.String)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric     = true;
                        list.GenericType = ETagType.String;
                    }

                    string    s   = reader.Value as string;
                    TagString tag = new TagString(null, s);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.StartObject)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric     = true;
                        list.GenericType = ETagType.Compound;
                    }

                    TagCompound tag = ParseCompound(reader, null);
                    list.Add(tag);
                }
                else if (reader.TokenType == JsonToken.StartArray)
                {
                    if (!foundGeneric)
                    {
                        foundGeneric     = true;
                        list.GenericType = ETagType.List;
                    }

                    TagList inner = ParseList(reader, null);
                    list.Add(inner);
                }
                else if (reader.TokenType == JsonToken.EndArray)
                {
                    return(list);
                }
                else
                {
                    throw new NotImplementedException("Currently no handling for this type of JSON token: " + reader.TokenType.ToString());
                }
            }

            return(list);
        }
Ejemplo n.º 31
0
    public void NameTest()
    {
      // arrange
      TagLong target;
      string expected;

      target = new TagLong();
      expected = "newvalue";

      // act
      target.Name = expected;

      // assert
      Assert.AreEqual(expected, target.Name);
    }
Ejemplo n.º 32
0
    public void ToValueStringTest()
    {
      // arrange
      ITag target;
      string expected;
      string actual;
      long value;

      value = long.MaxValue;
      expected = value.ToString(CultureInfo.InvariantCulture);
      target = new TagLong(value);

      // act
      actual = target.ToValueString();

      // assert
      Assert.AreEqual(expected, actual);
    }
Ejemplo n.º 33
0
    public void ToStringWithIndentTest()
    {
      // arrange
      TagLong target;
      string expected;
      string actual;
      string name;
      long value;
      string prefix;

      prefix = "test";
      name = "tagname";
      value = long.MaxValue;
      expected = string.Format("{2}[Long: {0}={1}]", name, value, prefix);
      target = new TagLong(name, value);

      // act
      actual = target.ToString(prefix);

      // assert
      Assert.AreEqual(expected, actual);
    }
Ejemplo n.º 34
0
    public void TypeTest()
    {
      // arrange
      TagType expected;
      TagType actual;

      expected = TagType.Long;

      // act
      actual = new TagLong().Type;

      // assert
      Assert.AreEqual(expected, actual);
    }
Ejemplo n.º 35
0
    public void ValueTest()
    {
      // arrange
      TagLong target;
      long expected;

      target = new TagLong();
      expected = long.MaxValue;

      // act
      target.Value = expected;

      // assert
      Assert.AreEqual(expected, target.Value);
    }
Ejemplo n.º 36
0
        public void TestAnvilRegion()
        {
            string     filename = this.AnvilRegionFileName;
            FileStream input    = File.OpenRead(filename);

            int[]  locations = new int[1024];
            byte[] buffer    = new byte[4096];
            input.Read(buffer, 0, 4096);
            for (int i = 0; i < 1024; i++)
            {
                locations[i] = BitConverter.ToInt32(buffer, i * 4);
            }

            int[] timestamps = new int[1024];
            input.Read(buffer, 0, 4096);
            for (int i = 0; i < 1024; i++)
            {
                timestamps[i] = BitConverter.ToInt32(buffer, i * 4);
            }

            input.Read(buffer, 0, 4);
            if (BitConverter.IsLittleEndian)
            {
                BitHelper.SwapBytes(buffer, 0, 4);
            }
            int sizeOfChunkData = BitConverter.ToInt32(buffer, 0) - 1;

            int compressionType = input.ReadByte();

            buffer = new byte[sizeOfChunkData];
            input.Read(buffer, 0, sizeOfChunkData);

            Stream inputStream = null;

            if (compressionType == 1)
            {
                inputStream = new GZipStream(new MemoryStream(buffer), CompressionMode.Decompress);
            }
            else if (compressionType == 2)
            {
                inputStream = new DeflateStream(new MemoryStream(buffer, 2, buffer.Length - 6), CompressionMode.Decompress);
            }

            TagReader reader;

            reader = new BinaryTagReader(inputStream);
            TagCompound tag    = (TagCompound)reader.ReadTag();
            string      strTag = tag.ToString();

            Assert.IsNotNull(tag);

            Assert.AreEqual(TagType.Compound, tag.GetTag("Level").Type);
            TagCompound levelTag = tag.GetCompound("Level");

            Tag aTag = levelTag.GetTag("Entities");

            Assert.AreEqual(TagType.List, aTag.Type);
            TagList entitiesTag = aTag as TagList;

            Assert.AreEqual(0, entitiesTag.Value.Count);

            aTag = levelTag.GetTag("Biomes");
            Assert.AreEqual(TagType.ByteArray, aTag.Type);
            TagByteArray biomesTag = aTag as TagByteArray;

            Assert.AreEqual(256, biomesTag.Value.Length);

            aTag = levelTag.GetTag("LastUpdate");
            Assert.AreEqual(TagType.Long, aTag.Type);
            TagLong lastUpdateTag = aTag as TagLong;

            Assert.AreEqual(2861877, lastUpdateTag.Value);

            aTag = levelTag.GetTag("xPos");
            Assert.AreEqual(TagType.Int, aTag.Type);
            TagInt xPosTag = aTag as TagInt;

            Assert.AreEqual(10, xPosTag.Value);

            aTag = levelTag.GetTag("zPos");
            Assert.AreEqual(TagType.Int, aTag.Type);
            TagInt zPosTag = aTag as TagInt;

            Assert.AreEqual(0, zPosTag.Value);

            aTag = levelTag.GetTag("TileEntities");
            Assert.AreEqual(TagType.List, aTag.Type);
            TagList tileEntitiesTag = aTag as TagList;

            Assert.AreEqual(0, tileEntitiesTag.Value.Count);

            aTag = levelTag.GetTag("TerrainPopulated");
            Assert.AreEqual(TagType.Byte, aTag.Type);
            TagByte terrainPopulatedTag = aTag as TagByte;

            Assert.AreEqual(1, terrainPopulatedTag.Value);

            aTag = levelTag.GetTag("HeightMap");
            Assert.AreEqual(TagType.IntArray, aTag.Type);
            TagIntArray heightmapTag = aTag as TagIntArray;

            Assert.AreEqual(256, heightmapTag.Value.Length);

            aTag = levelTag.GetTag("Sections");
            Assert.AreEqual(TagType.List, aTag.Type);
            TagList sectionsTag = aTag as TagList;

            Assert.AreEqual(4, sectionsTag.Value.Count);

            TagCompound section_0 = sectionsTag.Value[0] as TagCompound;

            Assert.IsNotNull(section_0);
            TagByteArray section_0_data = section_0.GetByteArray("Data");

            Assert.IsNotNull(section_0_data);
            Assert.AreEqual(2048, section_0_data.Value.Length);
            TagByteArray section_0_skyLight = section_0.GetByteArray("SkyLight");

            Assert.IsNotNull(section_0_skyLight);
            Assert.AreEqual(2048, section_0_skyLight.Value.Length);
            TagByteArray section_0_blockLight = section_0.GetByteArray("BlockLight");

            Assert.IsNotNull(section_0_blockLight);
            Assert.AreEqual(2048, section_0_blockLight.Value.Length);
            TagByte section_0_y = section_0.GetByte("Y");

            Assert.IsNotNull(section_0_y);
            Assert.AreEqual(0, section_0_y.Value);
            TagByteArray section_0_blocks = section_0.GetByteArray("Blocks");

            Assert.IsNotNull(section_0_blocks);
            Assert.AreEqual(4096, section_0_blocks.Value.Length);

            TagCompound section_1 = sectionsTag.Value[1] as TagCompound;

            Assert.IsNotNull(section_1);
            TagByteArray section_1_data = section_1.GetByteArray("Data");

            Assert.IsNotNull(section_1_data);
            Assert.AreEqual(2048, section_1_data.Value.Length);
            TagByteArray section_1_skyLight = section_1.GetByteArray("SkyLight");

            Assert.IsNotNull(section_1_skyLight);
            Assert.AreEqual(2048, section_1_skyLight.Value.Length);
            TagByteArray section_1_blockLight = section_1.GetByteArray("BlockLight");

            Assert.IsNotNull(section_1_blockLight);
            Assert.AreEqual(2048, section_1_blockLight.Value.Length);
            TagByte section_1_y = section_1.GetByte("Y");

            Assert.IsNotNull(section_1_y);
            Assert.AreEqual(1, section_1_y.Value);
            TagByteArray section_1_blocks = section_1.GetByteArray("Blocks");

            Assert.IsNotNull(section_1_blocks);
            Assert.AreEqual(4096, section_1_blocks.Value.Length);

            TagCompound section_2 = sectionsTag.Value[2] as TagCompound;

            Assert.IsNotNull(section_2);
            TagByteArray section_2_data = section_2.GetByteArray("Data");

            Assert.IsNotNull(section_2_data);
            Assert.AreEqual(2048, section_2_data.Value.Length);
            TagByteArray section_2_skyLight = section_2.GetByteArray("SkyLight");

            Assert.IsNotNull(section_2_skyLight);
            Assert.AreEqual(2048, section_2_skyLight.Value.Length);
            TagByteArray section_2_blockLight = section_2.GetByteArray("BlockLight");

            Assert.IsNotNull(section_2_blockLight);
            Assert.AreEqual(2048, section_2_blockLight.Value.Length);
            TagByte section_2_y = section_2.GetByte("Y");

            Assert.IsNotNull(section_2_y);
            Assert.AreEqual(2, section_2_y.Value);
            TagByteArray section_2_blocks = section_2.GetByteArray("Blocks");

            Assert.IsNotNull(section_2_blocks);
            Assert.AreEqual(4096, section_2_blocks.Value.Length);

            TagCompound section_3 = sectionsTag.Value[3] as TagCompound;

            Assert.IsNotNull(section_3);
            TagByteArray section_3_data = section_3.GetByteArray("Data");

            Assert.IsNotNull(section_3_data);
            Assert.AreEqual(2048, section_3_data.Value.Length);
            TagByteArray section_3_skyLight = section_3.GetByteArray("SkyLight");

            Assert.IsNotNull(section_3_skyLight);
            Assert.AreEqual(2048, section_3_skyLight.Value.Length);
            TagByteArray section_3_blockLight = section_3.GetByteArray("BlockLight");

            Assert.IsNotNull(section_3_blockLight);
            Assert.AreEqual(2048, section_3_blockLight.Value.Length);
            TagByte section_3_y = section_3.GetByte("Y");

            Assert.IsNotNull(section_3_y);
            Assert.AreEqual(3, section_3_y.Value);
            TagByteArray section_3_blocks = section_3.GetByteArray("Blocks");

            Assert.IsNotNull(section_3_blocks);
            Assert.AreEqual(4096, section_3_blocks.Value.Length);
        }
Ejemplo n.º 37
0
 public static DateTime ToDateTime(this TagLong tag)
 {
     return(UnixDateTimeHelpers.ToDateTime(tag.Value));
 }