public void TestCopyToBytes()
        {
            var data0 = RandomBytes(10000000, 0);
            var stats = TestByteBufferStatistics.Empty;

            using (var bb = new TestByteBuffer(data0))
            {
                var dst = new byte[10000000];

                bb.CopyTo(dst, 0, 750000);
                stats += bb.LastStatistics;

                bb.CopyTo(dst, 750000, 750000 + 1);
                stats += bb.LastStatistics;

                bb.CopyTo(dst, 1500000 + 1, 500000);
                stats += bb.LastStatistics;

                bb.CopyTo(dst, 2000000 + 1, 1000000 - 1);
                stats += bb.LastStatistics;

                bb.CopyTo(dst, 3000000, 1001101);
                stats += bb.LastStatistics;
            }

            using (var bb = new TestByteBuffer(data0))
            {
                var dst = new byte[10000000];

                bb.InitializeStream();
                bb.CopyTo(dst, 0, 750000);
                stats += bb.LastStatistics;

                bb.CopyTo(dst, 750000, 750000 + 1);
                stats += bb.LastStatistics;

                bb.CopyTo(dst, 1500000 + 1, 500000);
                stats += bb.LastStatistics;

                bb.CopyTo(dst, 2000000 + 1, 1000000 - 1);
                stats += bb.LastStatistics;

                bb.CopyTo(dst, 3000000, 1001101);
                stats += bb.LastStatistics;
            }

            Console.WriteLine(stats);
        }
        public void TestCopyToBinaryWriterLargeMemoryStream()
        {
            var data0 = RandomBytes(10000000, 0);
            var stats = TestByteBufferStatistics.Empty;

            using (var bb = new TestByteBuffer(data0))
                using (var ms = new MemoryStream())
                    using (var bw = new BinaryWriter(ms))
                    {
                        bb.CopyTo(bw);
                        stats += bb.LastStatistics;

                        bb.CopyTo(bw);
                        stats += bb.LastStatistics;

                        bb.CopyTo(bw);
                        stats += bb.LastStatistics;

                        bb.CopyTo(bw);
                        stats += bb.LastStatistics;

                        bb.CopyTo(bw);
                        stats += bb.LastStatistics;
                    }

            using (var bb = new TestByteBuffer(data0))
                using (var ms = new MemoryStream())
                    using (var bw = new BinaryWriter(ms))
                    {
                        bb.InitializeStream();
                        bb.CopyTo(bw);
                        stats += bb.LastStatistics;

                        bb.CopyTo(bw);
                        stats += bb.LastStatistics;

                        bb.CopyTo(bw);
                        stats += bb.LastStatistics;

                        bb.CopyTo(bw);
                        stats += bb.LastStatistics;

                        bb.CopyTo(bw);
                        stats += bb.LastStatistics;
                    }

            Console.WriteLine(stats);
        }
Exemple #3
0
        public void TestCopyToBinaryWriterLargeMemoryStream()
        {
            var data0 = RandomBytes(6001001, -0x02F0B4EF);

            using (var bb = new TestByteBuffer(data0))
                using (var ms = new MemoryStream())
                    using (var bw = new BinaryWriter(ms))
                    {
                        bb.CopyTo(bw);

                        Assert.AreEqual(6001001, ms.Length, "CopyTo(BinaryWriter(MemoryStream)) - length");
                        Assert.AreEqual(0, bb.StreamPosition, "CopyTo(BinaryWriter(MemoryStream)) - StreamPosition - after Stream initialized");
                        AssertAreEqual(data0, ToArray(ms), "CopyTo(BinaryWriter(MemoryStream)) - destination data");
                        AssertAreEqual(data0, bb.DumpTestData(), "CopyTo(BinaryWriter(MemoryStream)) - source data");
                    }

            using (var bb = new TestByteBuffer(data0))
                using (var ms = new MemoryStream())
                    using (var bw = new BinaryWriter(ms))
                    {
                        bb.InitializeStream(position: 42);
                        bb.CopyTo(bw);

                        Assert.AreEqual(6001001, ms.Length, "CopyTo(BinaryWriter(MemoryStream)) - length - after Stream initialized");
                        Assert.AreEqual(42, bb.StreamPosition, "CopyTo(BinaryWriter(MemoryStream)) - StreamPosition - after Stream initialized");
                        AssertAreEqual(data0, ToArray(ms), "CopyTo(BinaryWriter(MemoryStream)) - destination data after Stream initialized");
                        AssertAreEqual(data0, bb.DumpTestData(), "CopyTo(BinaryWriter(MemoryStream)) - source data after Stream initialized");
                    }
        }
Exemple #4
0
        public void TestCopyToStream()
        {
            var data0 = RandomBytes(7101, -0x02F0B4EF);

            using (var bb = new TestByteBuffer(data0))
                using (var ms = new MemoryStream())
                {
                    bb.CopyTo(ms, 1237, 4193);

                    Assert.AreEqual(4193, ms.Length, "CopyTo(Stream,int,int) - length");
                    Assert.AreEqual(0, bb.StreamPosition, "CopyTo(Stream,int,int) - StreamPosition");
                    AssertAreEqual(data0, 1237, ToArray(ms), 0, 4193, "CopyTo(Stream,int,int)");

                    bb.CopyTo(ms, 642, 942);

                    Assert.AreEqual(4193 + 942, ms.Length, "CopyTo(Stream,int,int) - length after append");
                    Assert.AreEqual(0, bb.StreamPosition, "CopyTo(Stream,int,int) - StreamPosition after append");
                    AssertAreEqual(data0, 1237, ToArray(ms), 0, 4193, "CopyTo(Stream,int,int) - existing data");
                    AssertAreEqual(data0, 642, ToArray(ms), 4193, 942, "CopyTo(Stream,int,int) - new appended data");
                }

            using (var bb = new TestByteBuffer(data0))
                using (var ms = new MemoryStream())
                {
                    bb.InitializeStream(position: 42);
                    bb.CopyTo(ms, 1237, 4193);

                    Assert.AreEqual(4193, ms.Length, "CopyTo(Stream,int,int) - length - after Stream initialized");
                    Assert.AreEqual(42, bb.StreamPosition, "CopyTo(Stream,int,int) - StreamPosition - after Stream initialized");
                    AssertAreEqual(data0, 1237, ToArray(ms), 0, 4193, "CopyTo(Stream,int,int) - after Stream initialized");

                    bb.CopyTo(ms, 642, 942);

                    Assert.AreEqual(4193 + 942, ms.Length, "CopyTo(Stream,int,int) - length after append - after Stream initialized");
                    Assert.AreEqual(42, bb.StreamPosition, "CopyTo(Stream,int,int) - StreamPosition after append - after Stream initialized");
                    AssertAreEqual(data0, 1237, ToArray(ms), 0, 4193, "CopyTo(Stream,int,int) - existing data - after Stream initialized");
                    AssertAreEqual(data0, 642, ToArray(ms), 4193, 942, "CopyTo(Stream,int,int) - new appended data - after Stream initialized");
                }
        }
Exemple #5
0
        public void TestCopyToBytes()
        {
            var data0 = RandomBytes(7101, -0x02F0B4EF);

            using (var bb = new TestByteBuffer(data0))
            {
                var dst = new byte[6731];
                bb.CopyTo(dst, 1007, 4361);
                Assert.AreEqual(0, bb.StreamPosition, "CopyTo(byte[],int,int) - StreamPosition");
                AssertAreEqual(data0, 1007, dst, 0, 4361, "CopyTo(byte[],int,int) - actual data");
                AssertAreEqual(new byte[6731 - 4361], 0, dst, 4361, 6731 - 4361, "CopyTo(byte[],int,int) - zero data");

                dst = new byte[6731];
                bb.InitializeStream(position: 42);
                bb.CopyTo(dst, 1007, 4361);
                Assert.AreEqual(42, bb.StreamPosition, "CopyTo(byte[],int,int) - StreamPosition after Stream initialized");
                AssertAreEqual(data0, 1007, dst, 0, 4361, "CopyTo(byte[],int,int) - actual data after Stream initialized");
                AssertAreEqual(new byte[6731 - 4361], 0, dst, 4361, 6731 - 4361, "CopyTo(byte[],int,int) - zero data after Stream initialized");
            }

            using (var bb = new TestByteBuffer(data0))
            {
                var dst = new byte[6731];
                bb.CopyTo(dst, 1007, 723, 4361);
                Assert.AreEqual(0, bb.StreamPosition, "CopyTo(byte[],int,int,int) - StreamPosition");
                AssertAreEqual(data0, 1007, dst, 723, 4361, "CopyTo(byte[],int,int,int) - actual data");
                AssertAreEqual(new byte[723], 0, dst, 0, 723, "CopyTo(byte[],int,int,int) - zero data before actual");
                AssertAreEqual(new byte[6731 - (4361 + 723)], 0, dst, 723 + 4361, 6731 - (4361 + 723), "CopyTo(byte[],int,int,int) - zero data after actual");

                dst = new byte[6731];
                bb.InitializeStream(position: 42);
                bb.CopyTo(dst, 1007, 723, 4361);
                Assert.AreEqual(42, bb.StreamPosition, "CopyTo(byte[],int,int,int) - StreamPosition after Stream initialized");
                AssertAreEqual(data0, 1007, dst, 723, 4361, "CopyTo(byte[],int,int,int) - actual data after Stream initialized");
                AssertAreEqual(new byte[723], 0, dst, 0, 723, "CopyTo(byte[],int,int,int) - zero data before actual after Stream initialized");
                AssertAreEqual(new byte[6731 - (4361 + 723)], 0, dst, 723 + 4361, 6731 - (4361 + 723), "CopyTo(byte[],int,int,int) - zero data after actual after Stream initialized");
            }
        }
		public void TestCopyToBytes()
		{
			var data0 = RandomBytes(10000000, 0);
			var stats = TestByteBufferStatistics.Empty;

			using (var bb = new TestByteBuffer(data0))
			{
				var dst = new byte[10000000];

				bb.CopyTo(dst, 0, 750000);
				stats += bb.LastStatistics;

				bb.CopyTo(dst, 750000, 750000 + 1);
				stats += bb.LastStatistics;

				bb.CopyTo(dst, 1500000 + 1, 500000);
				stats += bb.LastStatistics;

				bb.CopyTo(dst, 2000000 + 1, 1000000 - 1);
				stats += bb.LastStatistics;

				bb.CopyTo(dst, 3000000, 1001101);
				stats += bb.LastStatistics;
			}

			using (var bb = new TestByteBuffer(data0))
			{
				var dst = new byte[10000000];

				bb.InitializeStream();
				bb.CopyTo(dst, 0, 750000);
				stats += bb.LastStatistics;

				bb.CopyTo(dst, 750000, 750000 + 1);
				stats += bb.LastStatistics;

				bb.CopyTo(dst, 1500000 + 1, 500000);
				stats += bb.LastStatistics;

				bb.CopyTo(dst, 2000000 + 1, 1000000 - 1);
				stats += bb.LastStatistics;

				bb.CopyTo(dst, 3000000, 1001101);
				stats += bb.LastStatistics;
			}

			Console.WriteLine(stats);
		}
		public void TestCopyToBinaryWriterLargeMemoryStream()
		{
			var data0 = RandomBytes(10000000, 0);
			var stats = TestByteBufferStatistics.Empty;

			using (var bb = new TestByteBuffer(data0))
			using (var ms = new MemoryStream())
			using (var bw = new BinaryWriter(ms))
			{
				bb.CopyTo(bw);
				stats += bb.LastStatistics;

				bb.CopyTo(bw);
				stats += bb.LastStatistics;

				bb.CopyTo(bw);
				stats += bb.LastStatistics;

				bb.CopyTo(bw);
				stats += bb.LastStatistics;

				bb.CopyTo(bw);
				stats += bb.LastStatistics;
			}

			using (var bb = new TestByteBuffer(data0))
			using (var ms = new MemoryStream())
			using (var bw = new BinaryWriter(ms))
			{
				bb.InitializeStream();
				bb.CopyTo(bw);
				stats += bb.LastStatistics;

				bb.CopyTo(bw);
				stats += bb.LastStatistics;

				bb.CopyTo(bw);
				stats += bb.LastStatistics;

				bb.CopyTo(bw);
				stats += bb.LastStatistics;

				bb.CopyTo(bw);
				stats += bb.LastStatistics;
			}

			Console.WriteLine(stats);
		}