Esempio n. 1
0
        public void TestIndexer()
        {
            var b = new ByteStringBuilder();

              b.Append(new byte[] {0x61, 0x62, 0x63});

              Assert.AreEqual(0x61, b[0]);
              Assert.AreEqual(0x62, b[1]);
              Assert.AreEqual(0x63, b[2]);

              b[0] = (byte)0x63;
              b[1] = (byte)0x61;
              b[2] = (byte)0x62;

              Assert.AreEqual(0x63, b[0]);
              Assert.AreEqual(0x61, b[1]);
              Assert.AreEqual(0x62, b[2]);

              try {
            #pragma warning disable 168
            var val = b[3];
            #pragma warning restore 168
            Assert.Fail("IndexOutOfRangeException not thrown");
              }
              catch (IndexOutOfRangeException) {
              }

              try {
            b[3] = (byte)0x61;
            Assert.Fail("ArgumentOutOfRangeException not thrown");
              }
              catch (ArgumentOutOfRangeException) {
              }
        }
Esempio n. 2
0
        public void TestAppend()
        {
            var b = new ByteStringBuilder(16);

              Assert.AreEqual(16, b.Capacity);

              Assert.IsTrue(Object.ReferenceEquals(b, b.Append(new ByteString("0123456789"))));

              Assert.AreEqual(10, b.Length);
              Assert.AreEqual(16, b.Capacity);

              Assert.IsTrue(Object.ReferenceEquals(b, b.Append(new byte[] {0x61, 0x62, 0x63, 0x64, 0x65, 0x66})));

              Assert.AreEqual(16, b.Length);
              Assert.AreEqual(16, b.Capacity);

              Assert.IsTrue(Object.ReferenceEquals(b, b.Append((byte)0x67)));

              Assert.IsTrue(16 < b.Capacity);
              Assert.AreEqual(17, b.Length);

              Assert.IsTrue(Object.ReferenceEquals(b, b.Append("xyz")));

              Assert.AreEqual(20, b.Length);

              Assert.IsTrue(Object.ReferenceEquals(b, b.Append(new ByteString("0123456789"), 5, 3)));

              Assert.AreEqual(23, b.Length);

              Assert.AreEqual("0123456789abcdefgxyz567", b.ToString());
        }
Esempio n. 3
0
        public void TestConstruct()
        {
            var b = new ByteStringBuilder(16);

              Assert.AreEqual(0, b.Length);
              Assert.AreEqual(16, b.Capacity);
              Assert.IsTrue(b.ToByteString().IsEmpty);
        }
Esempio n. 4
0
        public void TestToByteArray()
        {
            var b = new ByteStringBuilder();

              b.Append(new byte[] {0x61, 0x62, 0x63, 0x64, 0x65, 0x66});

              var bytes1 = b.ToByteArray();

              Assert.AreEqual(6, bytes1.Length);
              Assert.AreEqual((new ByteString("abcdef")).ByteArray, bytes1);

              Assert.AreNotSame(bytes1, b.ToByteArray());

              b.Append((byte)0x67);

              var bytes2 = b.ToByteArray();

              Assert.AreNotSame(bytes1, bytes2);

              Assert.AreEqual(7, bytes2.Length);
              Assert.AreEqual((new ByteString("abcdefg")).ByteArray, bytes2);
        }
Esempio n. 5
0
        public void TestToString()
        {
            var b = new ByteStringBuilder();

              b.Append(new byte[] {0x61, 0x62, 0x63, 0x64, 0x65, 0x66});

              Assert.AreEqual("abcdef", b.ToString());

              b.Append((byte)0x67);

              Assert.AreEqual("abcdefg", b.ToString());
        }