public void TestMethod2()
        {
            TagIntArray a     = new TagIntArray(new int[] { 1, 2 });
            var         clone = a.Clone();

            return;
        }
Exemple #2
0
 public static void Serialize(JsonWriter writer, TagIntArray array)
 {
     writer.WriteStartArray();
     foreach (int n in array)
     {
         writer.WriteValue(n);
     }
     writer.WriteEndArray();
 }
    public void ConstructorTest()
    {
      // arrange
      TagIntArray tag;
      int[] expected;

      expected = new int[0];

      // act
      tag = new TagIntArray();

      // assert
      Assert.IsEmpty(tag.Name);
      CollectionAssert.AreEqual(expected, tag.Value);
    }
    public void ConstructorWithValueTest()
    {
      // arrange
      TagIntArray tag;
      int[] value;

      value = new[] { int.MinValue, int.MaxValue };

      // act
      tag = new TagIntArray(value);

      // assert
      Assert.IsEmpty(tag.Name);
      CollectionAssert.AreEqual(value, tag.Value);
    }
Exemple #5
0
        public override void WritePayload(Stream stream, INamedBinaryTag iTag)
        {
            TagIntArray tag = iTag as TagIntArray;

            byte[] count_bin = BitConverter.GetBytes(tag.Count);
            count_bin = count_bin.ReverseIfLittleEndian();
            stream.Write(count_bin, 0, 4);

            foreach (int n in tag)
            {
                byte[] num_bin = BitConverter.GetBytes(n);
                num_bin = num_bin.ReverseIfLittleEndian();
                stream.Write(num_bin, 0, 4);
            }
        }
        public void Constructor_sets_name()
        {
            // arrange
            TagIntArray target;
            string      expected;
            string      actual;

            expected = "Alphatag";

            // act
            target = new TagIntArray(expected);

            // assert
            actual = target.Name;
            Assert.Equal(expected, actual);
        }
        public void Equals_returns_false_with_different_value()
        {
            // arrange
            TagIntArray target;
            TagIntArray other;
            bool        actual;

            target = new TagIntArray(string.Empty, new[] { 2190, 2994, 3248, 4294394 });
            other  = new TagIntArray(string.Empty, new[] { 2190, 2994, 3248, 294394 });

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

            // assert
            Assert.False(actual);
        }
        public void Constructor_sets_default_name()
        {
            // arrange
            TagIntArray target;
            string      expected;
            string      actual;

            expected = string.Empty;

            // act
            target = new TagIntArray();

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

            target = new TagIntArray("alpha", new[] { 2190, 2994, 3248, 4294394 });
            other  = new TagIntArray("alpha", new[] { 2190, 2994, 3248, 4294394 });

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

            // assert
            Assert.True(actual);
        }
Exemple #10
0
        public void Equals_returns_false_with_different_name()
        {
            // arrange
            TagIntArray target;
            TagIntArray other;
            bool        actual;

            target = new TagIntArray("Alpha", new[] { 2190, 2994, 3248, 4294394 });
            other  = new TagIntArray("Beta", new[] { 2190, 2994, 3248, 4294394 });

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

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

            target = new TagIntArray(string.Empty, new[] { 2190, 2994, 3248, 4294394 });

            notExpected = new TagIntArray(string.Empty, new[] { 2190, 2994, 3248, 294394 }).GetHashCode();

            // act
            actual = target.GetHashCode();

            // assert
            Assert.NotEqual(notExpected, actual);
        }
    public void ConstructorWithNameTest()
    {
      // arrange
      TagIntArray tag;
      string name;
      int[] expected;

      name = "creationDate";
      expected = new int[0];

      // act
      tag = new TagIntArray(name);

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

            expected = "2190, 2994, 3248, 4294394";

            target = new TagIntArray(string.Empty, new[] { 2190, 2994, 3248, 4294394 });

            // act
            actual = target.ToValueString();

            // assert
            Assert.Equal(expected, actual);
        }
        public void GetHashCode_returns_same_value_for_matching_tags()
        {
            // arrange
            TagIntArray target;
            int         actual;
            int         expected;

            target = new TagIntArray("beta", new[] { 2190, 2994, 3248, 4294394 });

            expected = new TagIntArray("beta", new[] { 2190, 2994, 3248, 4294394 }).GetHashCode();

            // act
            actual = target.GetHashCode();

            // assert
            Assert.Equal(expected, actual);
        }
        public void Constructor_sets_default_value()
        {
            // arrange
            TagIntArray target;

            int[] expected;
            int[] actual;

            expected = new int[0];

            // act
            target = new TagIntArray();

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

            int[] expected;
            int[] actual;

            expected = new[] { 2190, 2994, 3248, 4294394 };

            // act
            target = new TagIntArray(expected);

            // assert
            actual = target.Value;
            Assert.Equal(expected, actual);
        }
    public void ConstructorWithNameAndValueTest()
    {
      // arrange
      TagIntArray tag;
      string name;
      int[] value;

      name = "creationDate";
      value = new[] { int.MinValue, int.MaxValue };

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

      // assert
      Assert.AreEqual(name, tag.Name);
      CollectionAssert.AreEqual(value, tag.Value);
    }
        public void Type_returns_correct_value()
        {
            // arrange
            TagIntArray target;
            TagType     expected;
            TagType     actual;

            target = new TagIntArray();

            expected = TagType.IntArray;

            // act
            actual = target.Type;

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

            expected = "[IntArray: gamma] (4 items)";

            target = new TagIntArray("gamma", new[] { 2190, 2994, 3248, 4294394 });

            // act
            actual = target.ToString();

            // assert
            Assert.Equal(expected, actual);
        }
        public void Value_can_be_set()
        {
            // arrange
            TagIntArray target;

            int[] expected;
            int[] actual;

            expected = new[] { 2190, 2994, 3248, 4294394 };

            target = new TagIntArray();

            // act
            target.Value = expected;

            // assert
            actual = target.Value;
            Assert.Equal(expected, actual);
        }
        public void SetValue_updates_value()
        {
            // arrange
            Tag target;

            int[] expected;
            int[] actual;

            target = new TagIntArray();

            expected = new[] { 2190, 2994, 3248, 4294394 };

            // act
            target.SetValue(expected);

            // assert
            actual = ((TagIntArray)target).Value;
            Assert.Equal(expected, actual);
        }
Exemple #22
0
        public override object ParsePayload(Stream stream, INamedBinaryTag iTag)
        {
            TagIntArray tag = iTag as TagIntArray;

            byte[] count_bin = new byte[4];
            stream.Read(count_bin, 0, 4);
            count_bin = count_bin.ReverseIfLittleEndian();
            int num_count  = BitConverter.ToInt32(count_bin, 0);
            int byte_count = num_count * 4;

            for (int i = 0; i < num_count; i++)
            {
                byte[] num_bin = new byte[4];
                stream.Read(num_bin, 0, 4);
                num_bin = num_bin.ReverseIfLittleEndian();
                int num = BitConverter.ToInt32(num_bin, 0);
                tag.Add(num);
            }

            return(tag.Values);
        }
Exemple #23
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);
        }
Exemple #24
0
 public static void Serialize(JsonWriter writer, TagIntArray array)
 {
     writer.WriteStartArray();
     foreach (int n in array)
     {
         writer.WriteValue(n);
     }
     writer.WriteEndArray();
 }
Exemple #25
0
            private void _read()
            {
                _type = ((MinecraftNbt.Tag)m_io.ReadU1());
                if (!(IsTagEnd))
                {
                    _name = new TagString(m_io, this, m_root);
                }
                if (!(IsTagEnd))
                {
                    switch (Type)
                    {
                    case MinecraftNbt.Tag.LongArray: {
                        _payload = new TagLongArray(m_io, this, m_root);
                        break;
                    }

                    case MinecraftNbt.Tag.Compound: {
                        _payload = new TagCompound(m_io, this, m_root);
                        break;
                    }

                    case MinecraftNbt.Tag.Double: {
                        _payload = m_io.ReadF8be();
                        break;
                    }

                    case MinecraftNbt.Tag.List: {
                        _payload = new TagList(m_io, this, m_root);
                        break;
                    }

                    case MinecraftNbt.Tag.Float: {
                        _payload = m_io.ReadF4be();
                        break;
                    }

                    case MinecraftNbt.Tag.Short: {
                        _payload = m_io.ReadS2be();
                        break;
                    }

                    case MinecraftNbt.Tag.Int: {
                        _payload = m_io.ReadS4be();
                        break;
                    }

                    case MinecraftNbt.Tag.ByteArray: {
                        _payload = new TagByteArray(m_io, this, m_root);
                        break;
                    }

                    case MinecraftNbt.Tag.Byte: {
                        _payload = m_io.ReadS1();
                        break;
                    }

                    case MinecraftNbt.Tag.IntArray: {
                        _payload = new TagIntArray(m_io, this, m_root);
                        break;
                    }

                    case MinecraftNbt.Tag.String: {
                        _payload = new TagString(m_io, this, m_root);
                        break;
                    }

                    case MinecraftNbt.Tag.Long: {
                        _payload = m_io.ReadS8be();
                        break;
                    }
                    }
                }
            }
    public void ToStringWithIndentTest()
    {
      // arrange
      TagIntArray target;
      string expected;
      string actual;
      string name;
      int[] value;
      string prefix;

      prefix = "test";
      name = "tagname";
      value = new[]
              {
                int.MinValue,
                int.MaxValue
              };
      expected = string.Format("{2}[IntArray: {0}={1} values]", name, value.Length, prefix);
      target = new TagIntArray(name, value);

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

      // assert
      Assert.AreEqual(expected, actual);
    }
    public void ToValueStringTest()
    {
      // arrange
      ITag target;
      string expected;
      string actual;
      int[] value;

      value = new[]
              {
                int.MinValue,
                int.MaxValue
              };
      expected = "-2147483648, 2147483647";
      target = new TagIntArray(value);

      // act
      actual = target.ToValueString();

      // assert
      Assert.AreEqual(expected, actual);
    }
    public void TypeTest()
    {
      // arrange
      TagType expected;
      TagType actual;

      expected = TagType.IntArray;

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

      // assert
      Assert.AreEqual(expected, actual);
    }
    public void ValueTest()
    {
      // arrange
      TagIntArray target;
      int[] expected;

      target = new TagIntArray();
      expected = new[]
                 {
                   int.MinValue,
                   int.MaxValue
                 };

      // act
      target.Value = expected;

      // assert
      CollectionAssert.AreEqual(expected, target.Value);
    }
    public void NameTest()
    {
      // arrange
      TagIntArray target;
      string expected;

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

      // act
      target.Name = expected;

      // assert
      Assert.AreEqual(expected, target.Name);
    }