コード例 #1
0
ファイル: BlobTests.cs プロジェクト: mauriciolsrj/corefx
        public void Link()
        {
            var builder1 = new BlobBuilder(16);

            builder1.WriteByte(1);

            var builder2 = new BlobBuilder(16);

            builder2.WriteByte(2);

            var builder3 = new BlobBuilder(16);

            builder3.WriteByte(3);

            var builder4 = new BlobBuilder(16);

            builder4.WriteByte(4);

            var builder5 = new BlobBuilder(16);

            builder5.WriteByte(5);

            builder2.LinkPrefix(builder1);
            AssertEx.Equal(new byte[] { 1, 2 }, builder2.ToArray());
            Assert.Throws <InvalidOperationException>(() => builder1.ToArray());
            Assert.Throws <InvalidOperationException>(() => builder2.LinkPrefix(builder1));
            Assert.Throws <InvalidOperationException>(() => builder1.WriteByte(0xff));
            Assert.Throws <InvalidOperationException>(() => builder1.WriteBytes(1, 10));
            Assert.Throws <InvalidOperationException>(() => builder1.WriteBytes(new byte[] { 1 }));
            Assert.Throws <InvalidOperationException>(() => builder1.ReserveBytes(1));
            Assert.Throws <InvalidOperationException>(() => builder1.GetBlobs());
            Assert.Throws <InvalidOperationException>(() => builder1.ContentEquals(builder1));
            Assert.Throws <InvalidOperationException>(() => builder1.WriteUTF16("str"));
            Assert.Throws <InvalidOperationException>(() => builder1.WriteUTF8("str", allowUnpairedSurrogates: false));

            builder2.LinkSuffix(builder3);
            AssertEx.Equal(new byte[] { 1, 2, 3 }, builder2.ToArray());
            Assert.Throws <InvalidOperationException>(() => builder3.LinkPrefix(builder5));

            builder2.LinkPrefix(builder4);
            AssertEx.Equal(new byte[] { 4, 1, 2, 3 }, builder2.ToArray());
            Assert.Throws <InvalidOperationException>(() => builder4.LinkPrefix(builder5));

            builder2.LinkSuffix(builder5);
            AssertEx.Equal(new byte[] { 4, 1, 2, 3, 5 }, builder2.ToArray());
        }
コード例 #2
0
ファイル: BlobTests.cs プロジェクト: mauriciolsrj/corefx
        public void LinkPrefix1()
        {
            var builder1 = new BlobBuilder(16);

            builder1.WriteByte(1);
            builder1.WriteByte(2);
            builder1.WriteByte(3);

            var builder2 = new BlobBuilder(16);

            builder2.WriteByte(4);

            builder1.LinkPrefix(builder2);

            AssertEx.Equal(new byte[] { 4, 1, 2, 3 }, builder1.ToArray());
        }
コード例 #3
0
ファイル: BlobTests.cs プロジェクト: ESgarbi/corefx
        public void Link()
        {
            var builder1 = new BlobBuilder(16);
            builder1.WriteByte(1);

            var builder2 = new BlobBuilder(16);
            builder2.WriteByte(2);

            var builder3 = new BlobBuilder(16);
            builder3.WriteByte(3);

            var builder4 = new BlobBuilder(16);
            builder4.WriteByte(4);

            var builder5 = new BlobBuilder(16);
            builder5.WriteByte(5);

            builder2.LinkPrefix(builder1);
            AssertEx.Equal(new byte[] { 1, 2 }, builder2.ToArray());
            Assert.Throws<InvalidOperationException>(() => builder1.ToArray());
            Assert.Throws<InvalidOperationException>(() => builder2.LinkPrefix(builder1));
            Assert.Throws<InvalidOperationException>(() => builder1.WriteByte(0xff));
            Assert.Throws<InvalidOperationException>(() => builder1.WriteBytes(1, 10));
            Assert.Throws<InvalidOperationException>(() => builder1.WriteBytes(new byte[] { 1 }));
            Assert.Throws<InvalidOperationException>(() => builder1.ReserveBytes(1));
            Assert.Throws<InvalidOperationException>(() => builder1.GetBlobs());
            Assert.Throws<InvalidOperationException>(() => builder1.ContentEquals(builder1));
            Assert.Throws<InvalidOperationException>(() => builder1.WriteUTF16("str"));
            Assert.Throws<InvalidOperationException>(() => builder1.WriteUTF8("str", allowUnpairedSurrogates: false));

            builder2.LinkSuffix(builder3);
            AssertEx.Equal(new byte[] { 1, 2, 3 }, builder2.ToArray());
            Assert.Throws<InvalidOperationException>(() => builder3.LinkPrefix(builder5));

            builder2.LinkPrefix(builder4);
            AssertEx.Equal(new byte[] { 4, 1, 2, 3 }, builder2.ToArray());
            Assert.Throws<InvalidOperationException>(() => builder4.LinkPrefix(builder5));

            builder2.LinkSuffix(builder5);
            AssertEx.Equal(new byte[] { 4, 1, 2, 3, 5 }, builder2.ToArray());
        }
コード例 #4
0
ファイル: BlobTests.cs プロジェクト: ESgarbi/corefx
        public void LinkPrefix1()
        {
            var builder1 = new BlobBuilder(16);
            builder1.WriteByte(1);
            builder1.WriteByte(2);
            builder1.WriteByte(3);

            var builder2 = new BlobBuilder(16);
            builder2.WriteByte(4);

            builder1.LinkPrefix(builder2);

            AssertEx.Equal(new byte[] { 4, 1, 2, 3 }, builder1.ToArray());

            Assert.Equal(4, builder1.Count);
            Assert.Equal(1, builder2.Count);
        }