Example #1
0
        public void EmptyListXmlTest()
        {
            // arrange
            NbtDocument reloaded;

            var fileName = GetWorkFile();
            var target   = new NbtDocument
            {
                Format = NbtFormat.Xml
            };

            target.DocumentRoot.Name = "Test";
            target.DocumentRoot.Value.Add("EmptyList", TagType.List, TagType.Compound);

            // act
            try
            {
                target.Save(fileName);
                reloaded = NbtDocument.LoadDocument(fileName);
            }
            finally
            {
                DeleteFile(fileName);
            }

            // assert
            // this test is essentially ensuring that an infinite loop when reloading an XML document is no longer present
            NbtAssert.Equal(target.DocumentRoot, reloaded.DocumentRoot);
        }
Example #2
0
        public void SaveTest()
        {
            // arrange
            NbtDocument target;

            var fileName = GetWorkFile();
            var expected = new NbtDocument(CreateComplexData())
            {
                FileName = fileName
            };

            // act
            try
            {
                expected.Save();
                target = NbtDocument.LoadDocument(fileName);
            }
            finally
            {
                DeleteFile(fileName);
            }

            // assert
            NbtAssert.Equal(expected, target);
        }
        public void SaveTest()
        {
            // arrange
            NbtDocument expected;
            NbtDocument target;
            string      fileName;

            fileName          = this.GetWorkFile();
            expected          = new NbtDocument(this.CreateComplexData());
            expected.FileName = fileName;

            // act
            try
            {
                expected.Save();
                target = NbtDocument.LoadDocument(fileName);
            }
            finally
            {
                this.DeleteFile(fileName);
            }

            // assert
            NbtAssert.AreEqual(expected, target);
        }
    public void EmptyListXmlTest()
    {
      // arrange
      NbtDocument target;
      NbtDocument reloaded;
      string fileName;

      fileName = this.GetWorkFile();
      target = new NbtDocument
               {
                 Format = NbtFormat.Xml
               };
      target.DocumentRoot.Name = "Test";
      target.DocumentRoot.Value.Add("EmptyList", TagType.List, TagType.Compound);

      // act
      try
      {
        target.Save(fileName);
        reloaded = NbtDocument.LoadDocument(fileName);
      }
      finally
      {
        this.DeleteFile(fileName);
      }

      // assert
      // this test is essentially ensuring that an infinite loop when reloading an XML document is no longer present
      this.CompareTags(target.DocumentRoot, reloaded.DocumentRoot);
    }
        public void Save_updates_filename_property()
        {
            // arrange
            NbtDocument target;
            string      expected;
            string      actual;

            expected = this.GetWorkFile();

            target = new NbtDocument(this.CreateComplexData());

            // act
            try
            {
                target.Save(expected);
            }
            finally
            {
                this.DeleteFile(expected);
            }

            // assert
            actual = target.FileName;
            Assert.AreEqual(expected, actual);
        }
Example #6
0
        public void Save_throws_exception_if_filename_is_null()
        {
            // arrange
            var target = new NbtDocument();

            // act
            var e = Assert.Throws <ArgumentNullException>(() => target.Save((string)null));

            Assert.Equal($"Value cannot be null.{Environment.NewLine}Parameter name: fileName", e.Message);
        }
        public void Save_throws_exception_if_stream_is_null()
        {
            // arrange
            NbtDocument target;

            target = new NbtDocument();

            // act
            target.Save((Stream)null);
        }
        public void Save_throws_exception_if_filename_is_null()
        {
            // arrange
            NbtDocument target;

            target = new NbtDocument();

            // act
            target.Save((string)null);
        }
        public void Save_throws_exception_if_filename_is_empty()
        {
            // arrange
            NbtDocument target;

            target = new NbtDocument();

            // act
            target.Save(string.Empty);
        }
        public void FormatTest()
        {
            // arrange
            NbtDocument source;
            NbtDocument expected;
            NbtDocument target;
            string      fileName1;
            string      fileName2;
            bool        file1IsBinary;
            bool        file2IsXml;

            fileName1 = this.GetWorkFile();
            fileName2 = this.GetWorkFile();
            source    = new NbtDocument(this.CreateComplexData());

            // act
            try
            {
                source.Format = NbtFormat.Binary;
                source.Save(fileName1);
                source.Format = NbtFormat.Xml;
                source.Save(fileName2);

                expected = NbtDocument.LoadDocument(fileName1);
                target   = NbtDocument.LoadDocument(fileName2);

                file1IsBinary = expected.Format == NbtFormat.Binary;
                file2IsXml    = target.Format == NbtFormat.Xml;
            }
            finally
            {
                this.DeleteFile(fileName1);
                this.DeleteFile(fileName2);
            }

            // assert
            Assert.IsTrue(file1IsBinary);
            Assert.IsTrue(file2IsXml);
            NbtAssert.AreEqual(expected, target);
        }
        public void WriteXmlDocumentViaNbtDocument()
        {
            NbtDocument document;
            TagCompound root;
            TagCompound compound;
            TagCompound child;
            TagList     list;

            document = new NbtDocument();

            root      = document.DocumentRoot;
            root.Name = "Level";
            root.Value.Add("longTest", 9223372036854775807);
            root.Value.Add("shortTest", (short)32767);
            root.Value.Add("stringTest", "HELLO WORLD THIS IS A TEST STRING ÅÄÖ!");
            root.Value.Add("floatTest", (float)0.498231471);
            root.Value.Add("intTest", 2147483647);

            compound = (TagCompound)root.Value.Add("nested compound test", TagType.Compound);
            child    = (TagCompound)compound.Value.Add("ham", TagType.Compound);
            child.Value.Add("name", "Hampus");
            child.Value.Add("value", (float)0.75);
            child = (TagCompound)compound.Value.Add("egg", TagType.Compound);
            child.Value.Add("name", "Eggbert");
            child.Value.Add("value", (float)0.5);

            list = (TagList)root.Value.Add("listTest (long)", TagType.List, TagType.Long);
            list.Value.Add((long)11);
            list.Value.Add((long)12);
            list.Value.Add((long)13);
            list.Value.Add((long)14);
            list.Value.Add((long)15);

            list  = (TagList)root.Value.Add("listTest (compound)", TagType.List, TagType.Compound);
            child = (TagCompound)list.Value.Add(TagType.Compound);
            child.Value.Add("name", "Compound tag #0");
            child.Value.Add("created-on", 1264099775885);
            child = (TagCompound)list.Value.Add(TagType.Compound);
            child.Value.Add("name", "Compound tag #1");
            child.Value.Add("created-on", 1264099775885);

            root.Value.Add("byteTest", (byte)127);
            root.Value.Add("byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...))", SampleByteArray);
            root.Value.Add("doubleTest", 0.49312871321823148);

            using (Stream stream = new MemoryStream())
            {
                document.Format = NbtFormat.Xml;
                document.Save(stream);
            }
        }
Example #12
0
        public void FormatTest()
        {
            // arrange
            NbtDocument expected;
            NbtDocument target;
            bool        file1IsBinary;
            bool        file2IsXml;

            var fileName1 = GetWorkFile();
            var fileName2 = GetWorkFile();
            var source    = new NbtDocument(CreateComplexData());

            // act
            try
            {
                source.Format = NbtFormat.Binary;
                source.Save(fileName1);
                source.Format = NbtFormat.Xml;
                source.Save(fileName2);

                expected = NbtDocument.LoadDocument(fileName1);
                target   = NbtDocument.LoadDocument(fileName2);

                file1IsBinary = expected.Format == NbtFormat.Binary;
                file2IsXml    = target.Format == NbtFormat.Xml;
            }
            finally
            {
                DeleteFile(fileName1);
                DeleteFile(fileName2);
            }

            // assert
            Assert.True(file1IsBinary);
            Assert.True(file2IsXml);
            NbtAssert.Equal(expected, target);
        }
Example #13
0
        public void Save_updates_filename_property()
        {
            // arrange
            var expected = GetWorkFile();
            var target   = new NbtDocument(CreateComplexData());

            // act
            try
            {
                target.Save(expected);
            }
            finally
            {
                DeleteFile(expected);
            }

            // assert
            var actual = target.FileName;

            Assert.Equal(expected, actual);
        }
    public void FormatTest()
    {
      // arrange
      NbtDocument source;
      NbtDocument target1;
      NbtDocument target2;
      string fileName1;
      string fileName2;
      bool file1IsBinary;
      bool file2IsXml;

      fileName1 = this.GetWorkFile();
      fileName2 = this.GetWorkFile();
      source = new NbtDocument(this.CreateComplexData());

      // act
      try
      {
        source.Format = NbtFormat.Binary;
        source.Save(fileName1);
        source.Format = NbtFormat.Xml;
        source.Save(fileName2);

        target1 = NbtDocument.LoadDocument(fileName1);
        target2 = NbtDocument.LoadDocument(fileName2);

        file1IsBinary = (target1.Format == NbtFormat.Binary);
        file2IsXml = (target2.Format == NbtFormat.Xml);
      }
      finally
      {
        this.DeleteFile(fileName1);
        this.DeleteFile(fileName2);
      }

      // assert
      Assert.IsTrue(file1IsBinary);
      Assert.IsTrue(file2IsXml);
      this.CompareTags(target1.DocumentRoot, target2.DocumentRoot);
    }
    public void SaveWithFileTest()
    {
      // arrange
      NbtDocument target1;
      NbtDocument target2;
      string fileName;

      fileName = this.GetWorkFile();
      target1 = new NbtDocument(this.CreateComplexData());

      // act
      try
      {
        target1.Save(fileName);
        target2 = NbtDocument.LoadDocument(fileName);
      }
      finally
      {
        this.DeleteFile(fileName);
      }

      // assert
      this.CompareTags(target1.DocumentRoot, target2.DocumentRoot);
    }