Ejemplo n.º 1
0
 /// <exception cref="System.Exception"/>
 public virtual void TestFindAfterUpdatingContents()
 {
     Org.Apache.Hadoop.IO.Text text = new Org.Apache.Hadoop.IO.Text("abcd");
     text.Set(Runtime.GetBytesForString("a"));
     Assert.Equal(text.GetLength(), 1);
     Assert.Equal(text.Find("a"), 0);
     Assert.Equal(text.Find("b"), -1);
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 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());
        }