예제 #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestValidate()
        {
            Org.Apache.Hadoop.IO.Text text = new Org.Apache.Hadoop.IO.Text("abcd\u20acbdcd\u20ac"
                                                                           );
            byte[] utf8   = text.GetBytes();
            int    length = text.GetLength();

            Org.Apache.Hadoop.IO.Text.ValidateUTF8(utf8, 0, length);
        }
예제 #2
0
 /// <exception cref="CharacterCodingException"/>
 public virtual void TestTextText()
 {
     Org.Apache.Hadoop.IO.Text a = new Org.Apache.Hadoop.IO.Text("abc");
     Org.Apache.Hadoop.IO.Text b = new Org.Apache.Hadoop.IO.Text("a");
     b.Set(a);
     Assert.Equal("abc", b.ToString());
     a.Append(Runtime.GetBytesForString("xdefgxxx"), 1, 4);
     Assert.Equal("modified aliased string", "abc", b.ToString());
     Assert.Equal("appended string incorrectly", "abcdefg", a.ToString
                      ());
     // add an extra byte so that capacity = 14 and length = 8
     a.Append(new byte[] { (byte)('d') }, 0, 1);
     Assert.Equal(14, a.GetBytes().Length);
     Assert.Equal(8, a.CopyBytes().Length);
 }
예제 #3
0
        /// <exception cref="System.Exception"/>
        public virtual void TestClear()
        {
            // Test lengths on an empty text object
            Org.Apache.Hadoop.IO.Text text = new Org.Apache.Hadoop.IO.Text();
            Assert.Equal("Actual string on an empty text object must be an empty string"
                         , string.Empty, text.ToString());
            Assert.Equal("Underlying byte array length must be zero", 0, text
                         .GetBytes().Length);
            Assert.Equal("String's length must be zero", 0, text.GetLength
                             ());
            // Test if clear works as intended
            text = new Org.Apache.Hadoop.IO.Text("abcd\u20acbdcd\u20ac");
            int len = text.GetLength();

            text.Clear();
            Assert.Equal("String must be empty after clear()", string.Empty
                         , text.ToString());
            Assert.True("Length of the byte array must not decrease after clear()"
                        , text.GetBytes().Length >= len);
            Assert.Equal("Length of the string must be reset to 0 after clear()"
                         , 0, text.GetLength());
        }