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

            using (var bb = new TestByteBuffer(data0))
                using (var ms = new MemoryStream(TestByteBuffer.CopyBytes(data1)))
                {
                    bb.CopyFrom(ms, 750000);
                    stats += bb.LastStatistics;

                    bb.CopyFrom(ms, 750000 + 1);
                    stats += bb.LastStatistics;

                    bb.CopyFrom(ms, 500000);
                    stats += bb.LastStatistics;

                    bb.CopyFrom(ms, 1000000 - 1);
                    stats += bb.LastStatistics;

                    bb.CopyFrom(ms, 1001101);
                    stats += bb.LastStatistics;
                }

            using (var bb = new TestByteBuffer(data0))
                using (var ms = new MemoryStream(TestByteBuffer.CopyBytes(data1)))
                {
                    bb.InitializeStream();
                    bb.CopyFrom(ms, 750000);
                    stats += bb.LastStatistics;

                    bb.CopyFrom(ms, 750000 + 1);
                    stats += bb.LastStatistics;

                    bb.CopyFrom(ms, 500000);
                    stats += bb.LastStatistics;

                    bb.CopyFrom(ms, 1000000 - 1);
                    stats += bb.LastStatistics;

                    bb.CopyFrom(ms, 1001101);
                    stats += bb.LastStatistics;
                }

            Console.WriteLine(stats);
        }
示例#2
0
        public void TestCopyFrom()
        {
            var data0 = RandomBytes(9432, -0x02F0B4EF);
            var data1 = RandomBytes(8472, -0x7BFC1702);

            using (var bb = new TestByteBuffer(data0))
                using (var ms = new MemoryStream(TestByteBuffer.CopyBytes(data1)))
                {
                    var result = bb.CopyFrom(ms, 4195);
                    Assert.AreEqual(4195, bb.Length, "CopyFrom - length");
                    Assert.AreEqual(0, bb.StreamPosition, "CopyFrom - StreamPosition");
                    Assert.AreEqual(4195, result, "CopyFrom - first batch return value");
                    AssertAreEqual(data1, 0, bb.DumpTestData(), 0, 4195, "CopyFrom - first batch data");

                    result = bb.CopyFrom(ms, 9000);
                    Assert.AreEqual(9000, bb.Length, "CopyFrom - length");             // apparently the length of the buffer after CopyFrom is the bytes requested, and not actual bytes read
                    Assert.AreEqual(0, bb.StreamPosition, "CopyFrom - StreamPosition");
                    Assert.AreEqual(4277, result, "CopyFrom - second batch return value");
                    AssertAreEqual(data1, 4195, bb.DumpTestData(), 0, 4277, "CopyFrom - second batch data");
                }

            using (var bb = new TestByteBuffer(data0))
                using (var ms = new MemoryStream(TestByteBuffer.CopyBytes(data1)))
                {
                    bb.InitializeStream(position: 42);

                    var result = bb.CopyFrom(ms, 4195);
                    Assert.AreEqual(4195, bb.Length, "CopyFrom - length - after Stream initialized");
                    Assert.AreEqual(0, bb.StreamPosition, "CopyFrom - StreamPosition - after Stream initialized");
                    Assert.AreEqual(4195, result, "CopyFrom - first batch return value - after Stream initialized");
                    AssertAreEqual(data1, 0, bb.DumpTestData(), 0, 4195, "CopyFrom - first batch data - after Stream initialized");

                    bb.InitializeStream(position: 42);

                    result = bb.CopyFrom(ms, 9000);
                    Assert.AreEqual(9000, bb.Length, "CopyFrom - length - after Stream initialized");             // apparently the length of the buffer after CopyFrom is the bytes requested, and not actual bytes read
                    Assert.AreEqual(0, bb.StreamPosition, "CopyFrom - StreamPosition - after Stream initialized");
                    Assert.AreEqual(4277, result, "CopyFrom - second batch return value - after Stream initialized");
                    AssertAreEqual(data1, 4195, bb.DumpTestData(), 0, 4277, "CopyFrom - second batch data - after Stream initialized");
                }
        }
		public void TestCopyFrom()
		{
			var data0 = RandomBytes(10000000, 0);
			var data1 = RandomBytes(10000000, 1);
			var stats = TestByteBufferStatistics.Empty;

			using (var bb = new TestByteBuffer(data0))
			using (var ms = new MemoryStream(TestByteBuffer.CopyBytes(data1)))
			{
				bb.CopyFrom(ms, 750000);
				stats += bb.LastStatistics;

				bb.CopyFrom(ms, 750000 + 1);
				stats += bb.LastStatistics;

				bb.CopyFrom(ms, 500000);
				stats += bb.LastStatistics;

				bb.CopyFrom(ms, 1000000 - 1);
				stats += bb.LastStatistics;

				bb.CopyFrom(ms, 1001101);
				stats += bb.LastStatistics;
			}

			using (var bb = new TestByteBuffer(data0))
			using (var ms = new MemoryStream(TestByteBuffer.CopyBytes(data1)))
			{
				bb.InitializeStream();
				bb.CopyFrom(ms, 750000);
				stats += bb.LastStatistics;

				bb.CopyFrom(ms, 750000 + 1);
				stats += bb.LastStatistics;

				bb.CopyFrom(ms, 500000);
				stats += bb.LastStatistics;

				bb.CopyFrom(ms, 1000000 - 1);
				stats += bb.LastStatistics;

				bb.CopyFrom(ms, 1001101);
				stats += bb.LastStatistics;
			}

			Console.WriteLine(stats);
		}