lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [29/45] lucenenet git commit: Lucene.Net.Tests.Support.IO: Ported more ByteBuffer tests from Apache Harmony
Date Sun, 30 Apr 2017 21:56:08 GMT
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6b3a8075/src/Lucene.Net.Tests/Support/IO/TestByteBuffer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Support/IO/TestByteBuffer.cs b/src/Lucene.Net.Tests/Support/IO/TestByteBuffer.cs
index f0833c8..0ccb985 100644
--- a/src/Lucene.Net.Tests/Support/IO/TestByteBuffer.cs
+++ b/src/Lucene.Net.Tests/Support/IO/TestByteBuffer.cs
@@ -1,760 +1,2844 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
+// This class was sourced from the Apache Harmony project
+// https://svn.apache.org/repos/asf/harmony/enhanced/java/trunk/
 
 using Lucene.Net.Attributes;
 using NUnit.Framework;
 using System;
-using System.Reflection;
 
 namespace Lucene.Net.Support.IO
 {
-    /// <summary>
-    /// Tests from JDK/nio/BasicByte.java
-    /// </summary>
+    /*
+     * Licensed to the Apache Software Foundation (ASF) under one or more
+     * contributor license agreements.  See the NOTICE file distributed with
+     * this work for additional information regarding copyright ownership.
+     * The ASF licenses this file to You under the Apache License, Version 2.0
+     * (the "License"); you may not use this file except in compliance with
+     * the License.  You may obtain a copy of the License at
+     *
+     *     http://www.apache.org/licenses/LICENSE-2.0
+     *
+     * Unless required by applicable law or agreed to in writing, software
+     * distributed under the License is distributed on an "AS IS" BASIS,
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     * See the License for the specific language governing permissions and
+     * limitations under the License.
+     */
+
     [TestFixture]
-    public class TestByteBuffer : BaseBufferTestCase
+    public class TestByteBuffer : AbstractBufferTest
     {
-        private static readonly sbyte[] VALUES = {
-            sbyte.MinValue,
-            (sbyte) -1,
-            (sbyte) 0,
-            (sbyte) 1,
-            sbyte.MaxValue,
-        };
+        protected static readonly int SMALL_TEST_LENGTH = 5;
+        protected static readonly int BUFFER_LENGTH = 250;
 
+        protected ByteBuffer buf;
 
-        private static void relGet(ByteBuffer b)
+        public override void SetUp() 
         {
-            int n = b.Capacity;
-            //byte v; // LUCENENET: Not used
-            for (int i = 0; i < n; i++)
-                ck(b, (long)b.Get(), (long)((byte)Ic(i)));
-            b.Rewind();
+            buf = ByteBuffer.Allocate(10);
+            loadTestData1(buf);
+            baseBuf = buf;
         }
 
-        private static void relGet(ByteBuffer b, int start)
+        public override void TearDown() 
         {
-            int n = b.Remaining;
-            //byte v; // LUCENENET: Not used
-            for (int i = start; i < n; i++)
-                ck(b, (long)b.Get(), (long)((byte)Ic(i)));
-            b.Rewind();
+            base.TearDown();
         }
 
-        private static void absGet(ByteBuffer b)
+        [Test, LuceneNetSpecific]
+        public virtual void TestArray()
         {
-            int n = b.Capacity;
-            //byte v; // LUCENENET: Not used
-            for (int i = 0; i < n; i++)
-                ck(b, (long)b.Get(), (long)((byte)Ic(i)));
-            b.Rewind();
-        }
+            if (buf.HasArray)
+            {
+                byte[] array = buf.Array;
+                assertContentEquals(buf, array, buf.ArrayOffset, buf.Capacity);
 
-        private static void bulkGet(ByteBuffer b)
-        {
-            int n = b.Capacity;
-            byte[] a = new byte[n + 7];
-            b.Get(a, 7, n);
-            for (int i = 0; i < n; i++)
-                ck(b, (long)a[i + 7], (long)((byte)Ic(i)));
-        }
+                loadTestData1(array, buf.ArrayOffset, buf.Capacity);
+                assertContentEquals(buf, array, buf.ArrayOffset, buf.Capacity);
 
-        private static void relPut(ByteBuffer b)
-        {
-            int n = b.Capacity;
-            b.Clear();
-            for (int i = 0; i < n; i++)
-                b.Put((byte)Ic(i));
-            b.Flip();
-        }
+                loadTestData2(array, buf.ArrayOffset, buf.Capacity);
+                assertContentEquals(buf, array, buf.ArrayOffset, buf.Capacity);
 
-        private static void absPut(ByteBuffer b)
-        {
-            int n = b.Capacity;
-            b.Clear();
-            for (int i = 0; i < n; i++)
-                b.Put(i, (byte)Ic(i));
-            b.Limit = (n);
-            b.Position = (0);
-        }
+                loadTestData1(buf);
+                assertContentEquals(buf, array, buf.ArrayOffset, buf.Capacity);
 
-        private static void bulkPutArray(ByteBuffer b)
-        {
-            int n = b.Capacity;
-            b.Clear();
-            byte[] a = new byte[n + 7];
-            for (int i = 0; i < n; i++)
-                a[i + 7] = (byte)Ic(i);
-            b.Put(a, 7, n);
-            b.Flip();
+                loadTestData2(buf);
+                assertContentEquals(buf, array, buf.ArrayOffset, buf.Capacity);
+            }
+            else
+            {
+                if (buf.IsReadOnly)
+                {
+                    try
+                    {
+                        var _ = buf.Array;
+                        fail("Should throw Exception"); //$NON-NLS-1$
+                    }
+                    catch (NotSupportedException e)
+                    {
+                        // expected
+                        // Note:can not tell when to throw 
+                        // NotSupportedException
+                        // or ReadOnlyBufferException, so catch all.
+                    }
+                }
+                else
+                {
+                    try
+                    {
+                        var _ = buf.Array;
+                        fail("Should throw Exception"); //$NON-NLS-1$
+                    }
+                    catch (NotSupportedException e)
+                    {
+                        // expected
+                    }
+                }
+            }
         }
 
-        private static void bulkPutBuffer(ByteBuffer b)
+        [Test, LuceneNetSpecific]
+        public virtual void TestArrayOffset()
         {
-            int n = b.Capacity;
-            b.Clear();
-            ByteBuffer c = ByteBuffer.Allocate(n + 7);
-            c.Position = (7);
-            for (int i = 0; i < n; i++)
-                c.Put((byte)Ic(i));
-            c.Flip();
-            c.Position = (7);
-            b.Put(c);
-            b.Flip();
-        }
+            if (buf.HasArray)
+            {
+                byte[] array = buf.Array;
+                assertContentEquals(buf, array, buf.ArrayOffset, buf.Capacity);
 
-        //6231529
-        private static void callReset(ByteBuffer b)
-        {
-            b.Position = (0);
-            b.Mark();
+                loadTestData1(array, buf.ArrayOffset, buf.Capacity);
+                assertContentEquals(buf, array, buf.ArrayOffset, buf.Capacity);
 
-            b.Duplicate().Reset();
-            // LUCENENET: AsReadOnlyBuffer() not implemented
-            //b.AsReadOnlyBuffer().Reset();
+                loadTestData2(array, buf.ArrayOffset, buf.Capacity);
+                assertContentEquals(buf, array, buf.ArrayOffset, buf.Capacity);
+
+                loadTestData1(buf);
+                assertContentEquals(buf, array, buf.ArrayOffset, buf.Capacity);
+
+                loadTestData2(buf);
+                assertContentEquals(buf, array, buf.ArrayOffset, buf.Capacity);
+            }
+            else
+            {
+                if (buf.IsReadOnly)
+                {
+                    try
+                    {
+                        var _ = buf.ArrayOffset;
+                        fail("Should throw Exception"); //$NON-NLS-1$
+                    }
+                    catch (NotSupportedException e)
+                    {
+                        // expected
+                        // Note:can not tell when to throw 
+                        // NotSupportedException
+                        // or ReadOnlyBufferException, so catch all.
+                    }
+                }
+                else
+                {
+                    try
+                    {
+                        var _ = buf.ArrayOffset;
+                        fail("Should throw Exception"); //$NON-NLS-1$
+                    }
+                    catch (NotSupportedException e)
+                    {
+                        // expected
+                    }
+                }
+            }
         }
 
-        private static void checkSlice(ByteBuffer b, ByteBuffer slice)
+        [Test, LuceneNetSpecific]
+        public virtual void TestAsReadOnlyBuffer()
         {
-            ck(slice, 0, slice.Position);
-            ck(slice, b.Remaining, slice.Limit);
-            ck(slice, b.Remaining, slice.Capacity);
-            if (b.IsDirect != slice.IsDirect)
-                fail("Lost direction", slice);
-            if (b.IsReadOnly != slice.IsReadOnly)
-                fail("Lost read-only", slice);
+            buf.Clear();
+            buf.Mark();
+            buf.SetPosition(buf.Limit);
+
+            // readonly's contents should be the same as buf
+            ByteBuffer @readonly = buf.AsReadOnlyBuffer();
+            assertNotSame(buf, @readonly);
+            assertTrue(@readonly.IsReadOnly);
+            assertEquals(buf.Position, @readonly.Position);
+            assertEquals(buf.Limit, @readonly.Limit);
+            assertEquals(buf.IsDirect, @readonly.IsDirect);
+            assertEquals(buf.Order, @readonly.Order);
+            assertContentEquals(buf, @readonly);
+
+            // readonly's position, mark, and limit should be independent to buf
+            @readonly.Reset();
+            assertEquals(@readonly.Position, 0);
+            @readonly.Clear();
+            assertEquals(buf.Position, buf.Limit);
+            buf.Reset();
+            assertEquals(buf.Position, 0);
         }
 
-        private static void checkBytes(ByteBuffer b, byte[] bs)
+        [Test, LuceneNetSpecific]
+        public virtual void TestCompact()
         {
-            int n = bs.Length;
-            int p = b.Position;
-            //byte v; // LUCENENET: Not used
-            if (b.Order == ByteOrder.BIG_ENDIAN)
+            if (buf.IsReadOnly)
+            {
+                try
+                {
+                    buf.Compact();
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (ReadOnlyBufferException e)
+                {
+                    // expected
+                }
+                return;
+            }
+
+            // case: buffer is full
+            buf.Clear();
+            buf.Mark();
+            loadTestData1(buf);
+            ByteBuffer ret = buf.Compact();
+            assertSame(ret, buf);
+            assertEquals(buf.Position, buf.Capacity);
+            assertEquals(buf.Limit, buf.Capacity);
+            assertContentLikeTestData1(buf, 0, (byte)0, buf.Capacity);
+            try
             {
-                for (int i = 0; i < n; i++)
-                ck(b, b.Get(), bs[i]);
+                buf.Reset();
+                fail("Should throw Exception"); //$NON-NLS-1$
             }
-            else
+            catch (InvalidMarkException e)
             {
-                for (int i = n - 1; i >= 0; i--)
-                    ck(b, b.Get(), bs[i]);
+                // expected
             }
-            b.Position = (p);
-        }
 
-        private static void compact(IO.Buffer b)
-        {
+            // case: buffer is empty
+            buf.SetPosition(0);
+            buf.SetLimit(0);
+            buf.Mark();
+            ret = buf.Compact();
+            assertSame(ret, buf);
+            assertEquals(buf.Position, 0);
+            assertEquals(buf.Limit, buf.Capacity);
+            assertContentLikeTestData1(buf, 0, (byte)0, buf.Capacity);
             try
             {
-                Type cl = b.GetType();
-                MethodInfo m = cl.GetMethod("Compact", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
-                m.Invoke(b, new object[0]);
+                buf.Reset();
+                fail("Should throw Exception"); //$NON-NLS-1$
             }
-            catch (Exception e)
+            catch (InvalidMarkException e)
             {
-                fail(e.ToString(), b);
+                // expected
             }
-        }
 
-        private static void checkInvalidMarkException(IO.Buffer b)
-        {
-            tryCatch(b, typeof(InvalidMarkException), () =>
-                {
-                    b.Mark();
-                    compact(b);
-                    b.Reset();
-                });
+            // case: normal
+            assertTrue(buf.Capacity > SMALL_TEST_LENGTH);
+            buf.SetPosition(1);
+            buf.SetLimit(SMALL_TEST_LENGTH);
+            buf.Mark();
+            ret = buf.Compact();
+            assertSame(ret, buf);
+            assertEquals(buf.Position, 4);
+            assertEquals(buf.Limit, buf.Capacity);
+            assertContentLikeTestData1(buf, 0, (byte)1, 4);
+            try
+            {
+                buf.Reset();
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (InvalidMarkException e)
+            {
+                // expected
+            }
         }
 
-        private static void testViews(int level, ByteBuffer b, bool direct)
+        [Test, LuceneNetSpecific]
+        public virtual void TestCompareTo()
         {
-            //ShortBuffer sb = b.asShortBuffer();
-            //BasicShort.test(level, sb, direct);
-            //checkBytes(b, new byte[] { 0, (byte)ic(0) });
-            //checkInvalidMarkException(sb);
-
-            //CharBuffer cb = b.asCharBuffer();
-            //BasicChar.test(level, cb, direct);
-            //checkBytes(b, new byte[] { 0, (byte)ic(0) });
-            //checkInvalidMarkException(cb);
-
-            //IntBuffer ib = b.asIntBuffer();
-            //BasicInt.test(level, ib, direct);
-            //checkBytes(b, new byte[] { 0, 0, 0, (byte)ic(0) });
-            //checkInvalidMarkException(ib);
-
-            Int64Buffer lb = b.AsInt64Buffer();
-            TestLongBuffer.test(level, lb, direct);
-            checkBytes(b, new byte[] { 0, 0, 0, 0, 0, 0, 0, (byte)Ic(0) });
-            checkInvalidMarkException(lb);
+            // compare to self
+            assertEquals(0, buf.CompareTo(buf));
 
-            //FloatBuffer fb = b.asFloatBuffer();
-            //BasicFloat.test(level, fb, direct);
-            //checkBytes(b, new byte[] { 0x42, (byte)0xc2, 0, 0 });
-            //checkInvalidMarkException(fb);
+            // normal cases
+            if (!buf.IsReadOnly)
+            {
+                assertTrue(buf.Capacity > SMALL_TEST_LENGTH);
+                buf.Clear();
+                ByteBuffer other = ByteBuffer.Allocate(buf.Capacity);
+                loadTestData1(buf);
+                loadTestData1(other);
+                assertEquals(0, buf.CompareTo(other));
+                assertEquals(0, other.CompareTo(buf));
+                buf.SetPosition(1);
+                assertTrue(buf.CompareTo(other) > 0);
+                assertTrue(other.CompareTo(buf) < 0);
+                other.SetPosition(2);
+                assertTrue(buf.CompareTo(other) < 0);
+                assertTrue(other.CompareTo(buf) > 0);
+                buf.SetPosition(2);
+                other.SetLimit(SMALL_TEST_LENGTH);
+                assertTrue(buf.CompareTo(other) > 0);
+                assertTrue(other.CompareTo(buf) < 0);
+            }
 
-            //DoubleBuffer db = b.asDoubleBuffer();
-            //BasicDouble.test(level, db, direct);
-            //checkBytes(b, new byte[] { 0x40, 0x58, 0x40, 0, 0, 0, 0, 0 });
-            //checkInvalidMarkException(db);
+            // LUCENENET NOTE: AllocateDirect() not supported
+            //assertTrue(ByteBuffer.Wrap(new byte[21]).CompareTo(ByteBuffer.AllocateDirect(21)) == 0);
+            assertTrue(ByteBuffer.Wrap(new byte[21]).CompareTo(ByteBuffer.Allocate(21)) == 0);
         }
 
-        private static void testHet(int level, ByteBuffer b)
+        [Test, LuceneNetSpecific]
+        public virtual void TestDuplicate()
         {
+            buf.Clear();
+            buf.Mark();
+            buf.SetPosition(buf.Limit);
+
+            // duplicate's contents should be the same as buf
+            ByteBuffer duplicate = buf.Duplicate();
+            assertNotSame(buf, duplicate);
+            assertEquals(buf.Position, duplicate.Position);
+            assertEquals(buf.Limit, duplicate.Limit);
+            assertEquals(buf.IsReadOnly, duplicate.IsReadOnly);
+            assertEquals(buf.IsDirect, duplicate.IsDirect);
+            assertEquals(buf.Order, duplicate.Order);
+            assertContentEquals(buf, duplicate);
+
+            // duplicate's position, mark, and limit should be independent to buf
+            duplicate.Reset();
+            assertEquals(duplicate.Position, 0);
+            duplicate.Clear();
+            assertEquals(buf.Position, buf.Limit);
+            buf.Reset();
+            assertEquals(buf.Position, 0);
+
+            // duplicate share the same content with buf
+            if (!duplicate.IsReadOnly)
+            {
+                loadTestData1(buf);
+                assertContentEquals(buf, duplicate);
+                loadTestData2(duplicate);
+                assertContentEquals(buf, duplicate);
+            }
+        }
 
-            int p = b.Position;
-            b.Limit = (b.Capacity);
-            Show(level, b);
-            output.Write("    put:");
-
-            b.PutChar((char)1);
-            b.PutChar((char)char.MaxValue);
-            output.Write(" char");
-
-            b.PutInt16((short)1);
-            b.PutInt16((short)short.MaxValue);
-            output.Write(" short");
-
-            b.PutInt32(1);
-            b.PutInt32(int.MaxValue);
-            output.Write(" int");
-
-            b.PutInt64((long)1);
-            b.PutInt64((long)long.MaxValue);
-            output.Write(" long");
-
-            b.PutSingle((float)1);
-            b.PutSingle((float)float.MinValue);
-            b.PutSingle((float)float.MaxValue);
-            output.Write(" float");
-
-            b.PutDouble((double)1);
-            b.PutDouble((double)double.MinValue);
-            b.PutDouble((double)double.MaxValue);
-            output.Write(" double");
-
-            output.WriteLine();
-            b.Limit = (b.Position);
-            b.Position = (p);
-            Show(level, b);
-            output.Write("    get:");
-
-            ck(b, b.GetChar(), 1);
-            ck(b, b.GetChar(), char.MaxValue);
-            output.Write(" char");
-
-            ck(b, b.GetInt16(), 1);
-            ck(b, b.GetInt16(), short.MaxValue);
-            output.Write(" short");
-
-            ck(b, b.GetInt32(), 1);
-            ck(b, b.GetInt32(), int.MaxValue);
-            output.Write(" int");
-
-            ck(b, b.GetInt64(), 1);
-            ck(b, b.GetInt64(), long.MaxValue);
-            output.Write(" long");
+        [Test, LuceneNetSpecific]
+        public virtual void TestEquals()
+        {
+            // equal to self
+            assertTrue(buf.equals(buf));
+            ByteBuffer @readonly = buf.AsReadOnlyBuffer();
+            assertTrue(buf.equals(@readonly));
+            ByteBuffer duplicate = buf.Duplicate();
+            assertTrue(buf.equals(duplicate));
 
-            ck(b, (long)b.GetSingle(), 1);
-            ck(b, (long)b.GetSingle(), unchecked((long)float.MinValue));
-            ck(b, (long)b.GetSingle(), unchecked((long)float.MaxValue));
-            output.Write(" float");
+            // always false, if type mismatch
+            assertFalse(buf.equals(Boolean.TrueString));
 
-            ck(b, (long)b.GetDouble(), 1);
-            ck(b, (long)b.GetDouble(), unchecked((long)double.MinValue));
-            ck(b, (long)b.GetDouble(), unchecked((long)double.MaxValue));
-            output.Write(" double");
+            assertTrue(buf.Capacity > SMALL_TEST_LENGTH);
 
-            output.WriteLine();
-        }
+            buf.SetLimit(buf.Capacity).SetPosition(0);
+            @readonly.SetLimit(@readonly.Capacity).SetPosition(1);
+            assertFalse(buf.equals(@readonly));
 
-        private static void fail(string problem,
-                                 ByteBuffer xb, ByteBuffer yb,
-                                 byte x, byte y)
-        {
-            fail(problem + string.Format(": x={0} y={1}", x, y), xb, yb);
+            buf.SetLimit(buf.Capacity - 1).SetPosition(0);
+            duplicate.SetLimit(duplicate.Capacity).SetPosition(0);
+            assertFalse(buf.equals(duplicate));
         }
 
-        private static void tryCatch(IO.Buffer b, Type ex, Action thunk)
+        /*
+         * Class under test for byte get()
+         */
+        [Test, LuceneNetSpecific]
+        public virtual void TestGet()
         {
-            bool caught = false;
+            buf.Clear();
+            for (int i = 0; i < buf.Capacity; i++)
+            {
+                assertEquals(buf.Position, i);
+                assertEquals(buf.Get(), buf.Get(i));
+            }
             try
             {
-                thunk();
+                buf.Get();
+                fail("Should throw Exception"); //$NON-NLS-1$
             }
-            catch (Exception x)
+            catch (BufferUnderflowException e)
             {
-                if (ex.IsAssignableFrom(x.GetType()))
-                {
-                    caught = true;
-                }
-                else
-                {
-                    fail(x.Message + " not expected");
-                }
+                // expected
             }
-            if (!caught)
-                fail(ex.Name + " not thrown", b);
         }
 
-        private static void tryCatch(byte[] t, Type ex, Action thunk)
+        /*
+         * Class under test for java.nio.ByteBuffer get(byte[])
+         */
+        [Test, LuceneNetSpecific]
+        public virtual void TestGetbyteArray()
         {
-            tryCatch(ByteBuffer.Wrap(t), ex, thunk);
+            byte[] array = new byte[1];
+            buf.Clear();
+            for (int i = 0; i < buf.Capacity; i++)
+            {
+                assertEquals(buf.Position, i);
+                ByteBuffer ret = buf.Get(array);
+                assertEquals(array[0], buf.Get(i));
+                assertSame(ret, buf);
+            }
+            try
+            {
+                buf.Get(array);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (BufferUnderflowException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.Get((byte[])null);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (NullReferenceException e)
+            {
+                // expected
+            }
         }
 
-        public static void test(int level, ByteBuffer b, bool direct)
+        /*
+         * Class under test for java.nio.ByteBuffer get(byte[], int, int)
+         */
+        [Test, LuceneNetSpecific]
+        public virtual void TestGetbyteArrayintint()
         {
-            Show(level, b);
-
-            if (direct != b.IsDirect)
-                fail("Wrong direction", b);
-
-            // Gets and puts
-
-            relPut(b);
-            relGet(b);
-            absGet(b);
-            bulkGet(b);
-
-            absPut(b);
-            relGet(b);
-            absGet(b);
-            bulkGet(b);
-
-            bulkPutArray(b);
-            relGet(b);
-
-            bulkPutBuffer(b);
-            relGet(b);
-
-
-            // Compact
-
-            relPut(b);
-            b.Position = (13);
-            b.Compact();
-            b.Flip();
-            relGet(b, 13);
+            buf.Clear();
+            byte[] array = new byte[buf.Capacity];
 
-            // Exceptions
-
-            relPut(b);
-            b.Limit = (b.Capacity / 2);
-            b.Position = (b.Limit);
-
-            tryCatch(b, typeof(BufferUnderflowException), () =>
+            try
             {
-                b.Get();
-            });
-
-            tryCatch(b, typeof(BufferOverflowException), () =>
+                buf.Get(new byte[buf.Capacity + 1], 0, buf.Capacity + 1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (BufferUnderflowException e)
             {
-                b.Put((byte)42);
-            });
-
-            // The index must be non-negative and lesss than the buffer's limit.
-            tryCatch(b, typeof(IndexOutOfRangeException), () =>
+                // expected
+            }
+            assertEquals(buf.Position, 0);
+            try
             {
-                b.Get(b.Limit);
-            });
-            tryCatch(b, typeof(IndexOutOfRangeException), () =>
+                buf.Get(array, -1, array.Length);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
             {
-                b.Get(-1);
-            });
-
-            tryCatch(b, typeof(IndexOutOfRangeException), () =>
+                // expected
+            }
+            buf.Get(array, array.Length, 0);
+            try
             {
-                b.Put(b.Limit, (byte)42);
-            });
-
-            tryCatch(b, typeof(InvalidMarkException), () =>
+                buf.Get(array, array.Length + 1, 1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
             {
-                b.Position = (0);
-                b.Mark();
-                b.Compact();
-                b.Reset();
-            });
-
-            // Values
-
-            b.Clear();
-            b.Put((byte)0);
-            b.Put(unchecked((byte)-1));
-            b.Put((byte)1);
-            b.Put(unchecked((byte)sbyte.MaxValue));
-            b.Put(unchecked((byte)sbyte.MinValue));
-
-            //byte v; // LUCENENET: Not used
-            b.Flip();
-            ck(b, b.Get(), 0);
-            ck(b, b.Get(), unchecked((byte)-1));
-            ck(b, b.Get(), 1);
-            ck(b, b.Get(), unchecked((byte)sbyte.MaxValue));
-            ck(b, b.Get(), unchecked((byte)sbyte.MinValue));
-
-
-            // Comparison
-            b.Rewind();
-            ByteBuffer b2 = ByteBuffer.Allocate(b.Capacity);
-            b2.Put(b);
-            b2.Flip();
-            b.Position = (2);
-            b2.Position = (2);
-            if (!b.Equals(b2))
+                // expected
+            }
+            assertEquals(buf.Position, 0);
+            try
             {
-                for (int i = 2; i < b.Limit; i++)
-                {
-                    byte x = b.Get(i);
-                    byte y = b2.Get(i);
-                    if (x != y)
-                        output.WriteLine("[" + i + "] " + x + " != " + y);
-                }
-                fail("Identical buffers not equal", b, b2);
+                buf.Get(array, 2, -1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.Get(array, 2, array.Length);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.Get((byte[])null, -1, 0);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (NullReferenceException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.Get(array, 1, int.MaxValue);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
             }
-            if (b.CompareTo(b2) != 0)
-                fail("Comparison to identical buffer != 0", b, b2);
+            try
+            {
+                buf.Get(array, int.MaxValue, 1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            assertEquals(buf.Position, 0);
 
-            b.Limit = (b.Limit + 1);
-            b.Position = (b.Limit - 1);
-            b.Put((byte)99);
-            b.Rewind();
-            b2.Rewind();
-            if (b.Equals(b2))
-                fail("Non-identical buffers equal", b, b2);
-            if (b.CompareTo(b2) <= 0)
-                fail("Comparison to shorter buffer <= 0", b, b2);
-            b.Limit = (b.Limit - 1);
+            buf.Clear();
+            ByteBuffer ret = buf.Get(array, 0, array.Length);
+            assertEquals(buf.Position, buf.Capacity);
+            assertContentEquals(buf, array, 0, array.Length);
+            assertSame(ret, buf);
+        }
 
-            b.Put(2, (byte)42);
-            if (b.equals(b2))
-                fail("Non-identical buffers equal", b, b2);
-            if (b.CompareTo(b2) <= 0)
-                fail("Comparison to lesser buffer <= 0", b, b2);
+        /*
+         * Class under test for byte get(int)
+         */
+        [Test, LuceneNetSpecific]
+        public virtual void TestGetint()
+        {
+            buf.Clear();
+            for (int i = 0; i < buf.Capacity; i++)
+            {
+                assertEquals(buf.Position, i);
+                assertEquals(buf.Get(), buf.Get(i));
+            }
+            try
+            {
+                buf.Get(-1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.Get(buf.Limit);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+        }
 
-            // Check equals and compareTo with interesting values
-            foreach (byte x in VALUES)
+        [Test, LuceneNetSpecific]
+        public virtual void TestHasArray()
+        {
+            if (buf.HasArray)
             {
-                ByteBuffer xb = ByteBuffer.Wrap(new byte[] { x });
-                if (xb.CompareTo(xb) != 0)
-                {
-                    fail("compareTo not reflexive", xb, xb, x, x);
-                }
-                if (!xb.Equals(xb))
-                {
-                    fail("equals not reflexive", xb, xb, x, x);
-                }
-                foreach (byte y in VALUES)
+                assertNotNull(buf.Array);
+            }
+            else
+            {
+                if (buf.IsReadOnly)
                 {
-                    ByteBuffer yb = ByteBuffer.Wrap(new byte[] { y });
-                    if (xb.CompareTo(yb) != -yb.CompareTo(xb))
+                    try
                     {
-                        fail("compareTo not anti-symmetric",
-                             xb, yb, x, y);
+                        var _ = buf.Array;
+                        fail("Should throw Exception"); //$NON-NLS-1$
                     }
-                    if ((xb.CompareTo(yb) == 0) != xb.Equals(yb))
+                    catch (NotSupportedException e)
                     {
-                        fail("compareTo inconsistent with equals",
-                             xb, yb, x, y);
+                        // expected
+                        // Note:can not tell when to throw 
+                        // NotSupportedException
+                        // or ReadOnlyBufferException, so catch all.
                     }
-                    // from Byte.compare(x, y)
-                    //return x - y;
-                    if (xb.CompareTo(yb) != (x - y) /* Byte.Compare(x, y)*/)
+                }
+                else
+                {
+                    try
                     {
-                        fail("Incorrect results for ByteBuffer.compareTo",
-                             xb, yb, x, y);
+                        var _ = buf.Array;
+                        fail("Should throw Exception"); //$NON-NLS-1$
                     }
-                    if (xb.equals(yb) != ((x == y) /*|| ((x != x) && (y != y))*/))
+                    catch (NotSupportedException e)
                     {
-                        fail("Incorrect results for ByteBuffer.equals",
-                             xb, yb, x, y);
+                        // expected
                     }
                 }
             }
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestHashCode()
+        {
+            buf.Clear();
+            loadTestData1(buf);
+            ByteBuffer @readonly = buf.AsReadOnlyBuffer();
+            ByteBuffer duplicate = buf.Duplicate();
+            assertTrue(buf.GetHashCode() == @readonly.GetHashCode());
+            assertTrue(buf.Capacity > SMALL_TEST_LENGTH);
+            duplicate.SetPosition(buf.Capacity / 2);
+            assertTrue(buf.GetHashCode() != duplicate.GetHashCode());
+        }
 
-            // Sub, dup
+        //for the testHashCode() method of readonly subclasses
+        protected void readOnlyHashCode()
+        {
+            //create a new buffer initiated with some data 
+            ByteBuffer buf = ByteBuffer.Allocate(BUFFER_LENGTH);
+            loadTestData1(buf);
+            buf = buf.AsReadOnlyBuffer();
+            buf.Clear();
+            ByteBuffer @readonly = buf.AsReadOnlyBuffer();
+            ByteBuffer duplicate = buf.Duplicate();
+            assertEquals(buf.GetHashCode(),@readonly.GetHashCode());
+            duplicate.SetPosition(buf.Capacity / 2);
+            assertTrue(buf.GetHashCode() != duplicate.GetHashCode());
+        }
 
-            relPut(b);
-            relGet(b.Duplicate());
-            b.Position = (13);
-            relGet(b.Duplicate(), 13);
-            relGet(b.Duplicate().Slice(), 13);
-            relGet(b.Slice(), 13);
-            relGet(b.Slice().Duplicate(), 13);
+        [Test, LuceneNetSpecific]
+        public virtual void TestIsDirect()
+        {
+            var _ = buf.IsDirect;
+        }
 
-            // Slice
+        [Test, LuceneNetSpecific]
+        public virtual void TestOrder()
+        {
+            // BIG_ENDIAN is the default byte order
+            assertEquals(ByteOrder.BIG_ENDIAN, buf.Order);
 
-            b.Position = (5);
-            ByteBuffer sb = b.Slice();
-            checkSlice(b, sb);
-            b.Position = (0);
-            ByteBuffer sb2 = sb.Slice();
-            checkSlice(sb, sb2);
+            buf.SetOrder(ByteOrder.LITTLE_ENDIAN);
+            assertEquals(ByteOrder.LITTLE_ENDIAN, buf.Order);
 
-            if (!sb.Equals(sb2))
-                fail("Sliced slices do not match", sb, sb2);
-            if ((sb.HasArray) && (sb.ArrayOffset != sb2.ArrayOffset))
-                fail("Array offsets do not match: "
-                     + sb.ArrayOffset + " != " + sb2.ArrayOffset, sb, sb2);
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+            assertEquals(ByteOrder.BIG_ENDIAN, buf.Order);
 
-            // Views
+            // Regression test for HARMONY-798
+            buf.SetOrder((ByteOrder)null);
+            assertEquals(ByteOrder.LITTLE_ENDIAN, buf.Order);
 
-            b.Clear();
-            b.Order = (ByteOrder.BIG_ENDIAN);
-            testViews(level + 1, b, direct);
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        }
 
-            for (int i = 1; i <= 9; i++)
+        /*
+         * Class under test for java.nio.ByteBuffer put(byte)
+         */
+        [Test, LuceneNetSpecific]
+        public virtual void TestPutbyte()
+        {
+            if (buf.IsReadOnly)
             {
-                b.Position = (i);
-                Show(level + 1, b);
-                testViews(level + 2, b, direct);
+                try
+                {
+                    buf.Clear();
+                    buf.Put((byte)0);
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (ReadOnlyBufferException e)
+                {
+                    // expected
+                }
+                return;
             }
 
-            b.Position=(0);
-            b.Order=(ByteOrder.LITTLE_ENDIAN);
-            testViews(level + 1, b, direct);
-
-            // Heterogeneous accessors
-
-            b.Order = (ByteOrder.BIG_ENDIAN);
-            for (int i = 0; i <= 9; i++)
+            buf.Clear();
+            for (int i = 0; i < buf.Capacity; i++)
             {
-                b.Position = (i);
-                testHet(level + 1, b);
+                assertEquals(buf.Position, i);
+                ByteBuffer ret = buf.Put((byte)i);
+                assertEquals(buf.Get(i), (byte)i);
+                assertSame(ret, buf);
             }
-            b.Order = (ByteOrder.LITTLE_ENDIAN);
-            b.Position = (3);
-            testHet(level + 1, b);
-
-            // Read-only views
-
-            b.Rewind();
-            ByteBuffer rb = b.AsReadOnlyBuffer();
-            if (!b.equals(rb))
-                fail("Buffer not equal to read-only view", b, rb);
-            Show(level + 1, rb);
-
-            tryCatch(b, typeof(ReadOnlyBufferException), () =>
+            try
             {
-                relPut(rb);
-            });
-
-            tryCatch(b, typeof(ReadOnlyBufferException), () =>
+                buf.Put((byte)0);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (BufferOverflowException e)
             {
-                absPut(rb);
-            });
+                // expected
+            }
+        }
 
-            tryCatch(b, typeof(ReadOnlyBufferException), () =>
+        /*
+         * Class under test for java.nio.ByteBuffer put(byte[])
+         */
+        [Test, LuceneNetSpecific]
+        public virtual void TestPutbyteArray()
+        {
+            byte[] array = new byte[1];
+            if (buf.IsReadOnly)
             {
-                bulkPutArray(rb);
-            });
+                try
+                {
+                    buf.Put(array);
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (ReadOnlyBufferException e)
+                {
+                    // expected
+                }
+                return;
+            }
 
-            tryCatch(b, typeof(ReadOnlyBufferException), () =>
+            buf.Clear();
+            for (int i = 0; i < buf.Capacity; i++)
             {
-                bulkPutBuffer(rb);
-            });
-
-            // put(ByteBuffer) should not change source position
-            ByteBuffer src = ByteBuffer.Allocate(1);
-            tryCatch(b, typeof(ReadOnlyBufferException), () =>
+                assertEquals(buf.Position, i);
+                array[0] = (byte)i;
+                ByteBuffer ret = buf.Put(array);
+                assertEquals(buf.Get(i), (byte)i);
+                assertSame(ret, buf);
+            }
+            try
             {
-                rb.Put(src);
-            });
-            ck(src, src.Position, 0);
-
-            tryCatch(b, typeof(ReadOnlyBufferException), () =>
+                buf.Put(array);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (BufferOverflowException e)
             {
-                rb.Compact();
-            });
-
-            tryCatch(b, typeof(ReadOnlyBufferException), () =>
+                // expected
+            }
+            try
             {
-                rb.PutChar((char)1);
-            });
-            tryCatch(b, typeof(ReadOnlyBufferException), () =>
+                buf.Put((byte[])null);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (NullReferenceException e)
             {
-                rb.PutChar(0, (char)1);
-            });
+                // expected
+            }
+        }
 
-            tryCatch(b, typeof(ReadOnlyBufferException), () =>
-            {
-                rb.PutInt16((short)1);
-            });
-            tryCatch(b, typeof(ReadOnlyBufferException), () =>
+        /*
+         * Class under test for java.nio.ByteBuffer put(byte[], int, int)
+         */
+        [Test, LuceneNetSpecific]
+        public virtual void TestPutbyteArrayintint()
+        {
+            buf.Clear();
+            byte[] array = new byte[buf.Capacity];
+            if (buf.IsReadOnly)
             {
-                rb.PutInt16(0, (short)1);
-            });
+                try
+                {
+                    buf.Put(array, 0, array.Length);
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (ReadOnlyBufferException e)
+                {
+                    // expected
+                }
+                return;
+            }
 
-            tryCatch(b, typeof(ReadOnlyBufferException), () =>
+            try
+            {
+                buf.Put(new byte[buf.Capacity + 1], 0, buf.Capacity + 1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (BufferOverflowException e)
+            {
+                // expected
+            }
+            assertEquals(buf.Position, 0);
+            try
+            {
+                buf.Put(array, -1, array.Length);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.Put(array, array.Length + 1, 0);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            buf.Put(array, array.Length, 0);
+            assertEquals(buf.Position, 0);
+            try
+            {
+                buf.Put(array, 0, -1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.Put(array, 2, array.Length);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+
+            try
+            {
+                buf.Put(array, 2, int.MaxValue);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.Put(array, int.MaxValue, 1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.Put((byte[])null, 2, int.MaxValue);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (NullReferenceException e)
+            {
+                // expected
+            }
+
+            assertEquals(buf.Position, 0);
+
+            loadTestData2(array, 0, array.Length);
+            ByteBuffer ret = buf.Put(array, 0, array.Length);
+            assertEquals(buf.Position, buf.Capacity);
+            assertContentEquals(buf, array, 0, array.Length);
+            assertSame(ret, buf);
+        }
+
+        /*
+         * Class under test for java.nio.ByteBuffer put(java.nio.ByteBuffer)
+         */
+        [Test, LuceneNetSpecific]
+        public virtual void TestPutByteBuffer()
+        {
+            ByteBuffer other = ByteBuffer.Allocate(buf.Capacity);
+            if (buf.IsReadOnly)
+            {
+                try
+                {
+                    buf.Clear();
+                    buf.Put(other);
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (ReadOnlyBufferException e)
+                {
+                    // expected
+                }
+                try
+                {
+                    buf.Clear();
+                    buf.Put((ByteBuffer)null);
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (ReadOnlyBufferException e)
+                {
+                    // expected
+                }
+                return;
+            }
+
+            try
+            {
+                buf.Put(buf);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (ArgumentException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.Put(ByteBuffer.Allocate(buf.Capacity + 1));
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (BufferOverflowException e)
+            {
+                // expected
+            }
+
+            try
+            {
+                buf.Put((ByteBuffer)null);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (NullReferenceException e)
+            {
+                // expected
+            }
+            loadTestData2(other);
+            other.Clear();
+            buf.Clear();
+            ByteBuffer ret = buf.Put(other);
+            assertEquals(other.Position, other.Capacity);
+            assertEquals(buf.Position, buf.Capacity);
+            assertContentEquals(other, buf);
+            assertSame(ret, buf);
+        }
+
+        /*
+         * Class under test for java.nio.ByteBuffer put(int, byte)
+         */
+        [Test, LuceneNetSpecific]
+        public virtual void TestPutintbyte()
+        {
+            if (buf.IsReadOnly)
+            {
+                try
+                {
+                    buf.Put(0, (byte)0);
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (ReadOnlyBufferException e)
+                {
+                    // expected
+                }
+                return;
+            }
+
+            buf.Clear();
+            for (int i = 0; i < buf.Capacity; i++)
+            {
+                assertEquals(buf.Position, 0);
+                ByteBuffer ret = buf.Put(i, (byte)i);
+                assertEquals(buf.Get(i), (byte)i);
+                assertSame(ret, buf);
+            }
+            try
+            {
+                buf.Put(-1, (byte)0);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.Put(buf.Limit, (byte)0);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestSlice()
+        {
+            assertTrue(buf.Capacity > SMALL_TEST_LENGTH);
+            buf.SetPosition(1);
+            buf.SetLimit(buf.Capacity - 1);
+
+            ByteBuffer slice = buf.Slice();
+            assertEquals(buf.IsReadOnly, slice.IsReadOnly);
+            assertEquals(buf.IsDirect, slice.IsDirect);
+            assertEquals(buf.Order, slice.Order);
+            assertEquals(slice.Position, 0);
+            assertEquals(slice.Limit, buf.Remaining);
+            assertEquals(slice.Capacity, buf.Remaining);
+            try
+            {
+                slice.Reset();
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (InvalidMarkException e)
+            {
+                // expected
+            }
+
+            // slice share the same content with buf
+            if (!slice.IsReadOnly)
+            {
+                loadTestData1(slice);
+                assertContentLikeTestData1(buf, 1, (byte)0, slice.Capacity);
+                buf.Put(2, (byte)100);
+                assertEquals(slice.Get(1), 100);
+            }
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestToString()
+        {
+            String str = buf.toString();
+            assertTrue(str.IndexOf("Byte") >= 0 || str.IndexOf("byte") >= 0);
+            assertTrue(str.IndexOf("" + buf.Position) >= 0);
+            assertTrue(str.IndexOf("" + buf.Limit) >= 0);
+            assertTrue(str.IndexOf("" + buf.Capacity) >= 0);
+        }
+
+        // LUCENENET NOTE: Not supported
+        //[Test, LuceneNetSpecific]
+        //public virtual void TestAsCharBuffer()
+        //{
+        //    CharBuffer charBuffer;
+        //    byte[] bytes = new byte[2];
+        //    char value;
+
+        //    // test BIG_ENDIAN char buffer, read
+        //    buf.Clear();
+        //    buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        //    charBuffer = buf.asCharBuffer();
+        //    assertSame(ByteOrder.BIG_ENDIAN, charBuffer.Order);
+        //    while (charBuffer.Remaining > 0)
+        //    {
+        //        buf.Get(bytes);
+        //        value = charBuffer.Get();
+        //        assertEquals(bytes2char(bytes, buf.Order), value);
+        //    }
+
+        //    // test LITTLE_ENDIAN char buffer, read
+        //    buf.Clear();
+        //    buf.SetOrder(ByteOrder.LITTLE_ENDIAN);
+        //    charBuffer = buf.asCharBuffer();
+        //    assertSame(ByteOrder.LITTLE_ENDIAN, charBuffer.Order);
+        //    while (charBuffer.Remaining > 0)
+        //    {
+        //        buf.Get(bytes);
+        //        value = charBuffer.Get();
+        //        assertEquals(bytes2char(bytes, buf.Order), value);
+        //    }
+
+        //    if (!buf.IsReadOnly)
+        //    {
+        //        // test BIG_ENDIAN char buffer, write
+        //        buf.Clear();
+        //        buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        //        charBuffer = buf.asCharBuffer();
+        //        assertSame(ByteOrder.BIG_ENDIAN, charBuffer.Order);
+        //        while (charBuffer.Remaining > 0)
+        //        {
+        //            value = (char)charBuffer.Remaining;
+        //            charBuffer.Put(value);
+        //            buf.Get(bytes);
+        //            assertTrue(Arrays.Equals(bytes, char2bytes(value, buf.Order)));
+        //        }
+
+        //        // test LITTLE_ENDIAN char buffer, write
+        //        buf.Clear();
+        //        buf.SetOrder(ByteOrder.LITTLE_ENDIAN);
+        //        charBuffer = buf.asCharBuffer();
+        //        assertSame(ByteOrder.LITTLE_ENDIAN, charBuffer.Order);
+        //        while (charBuffer.Remaining > 0)
+        //        {
+        //            value = (char)charBuffer.Remaining;
+        //            charBuffer.Put(value);
+        //            buf.Get(bytes);
+        //            assertTrue(Arrays.Equals(bytes, char2bytes(value, buf.Order)));
+        //        }
+        //    }
+        //    buf.Clear();
+        //    buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        //}
+
+        // LUCENENET NOTE: Not supported
+        //[Test, LuceneNetSpecific]
+        //public virtual void TestAsDoubleBuffer()
+        //{
+        //    DoubleBuffer doubleBuffer;
+        //    byte[] bytes = new byte[8];
+        //    double value;
+
+        //    // test BIG_ENDIAN double buffer, read
+        //    buf.Clear();
+        //    buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        //    doubleBuffer = buf.AsDoubleBuffer();
+        //    assertSame(ByteOrder.BIG_ENDIAN, doubleBuffer.Order);
+        //    while (doubleBuffer.Remaining > 0)
+        //    {
+        //        buf.Get(bytes);
+        //        value = doubleBuffer.Get();
+        //        if (!(Double.IsNaN(bytes2double(bytes, buf.Order)) && Double
+        //                .IsNaN(value)))
+        //        {
+        //            assertEquals(bytes2double(bytes, buf.Order), value, 0.00);
+        //        }
+        //    }
+
+        //    // test LITTLE_ENDIAN double buffer, read
+        //    buf.Clear();
+        //    buf.SetOrder(ByteOrder.LITTLE_ENDIAN);
+        //    doubleBuffer = buf.AsDoubleBuffer();
+        //    assertSame(ByteOrder.LITTLE_ENDIAN, doubleBuffer.Order);
+        //    while (doubleBuffer.Remaining > 0)
+        //    {
+        //        buf.Get(bytes);
+        //        value = doubleBuffer.Get();
+        //        if (!(Double.IsNaN(bytes2double(bytes, buf.Order)) && Double
+        //                .IsNaN(value)))
+        //        {
+        //            assertEquals(bytes2double(bytes, buf.Order), value, 0.00);
+        //        }
+        //    }
+
+        //    if (!buf.IsReadOnly)
+        //    {
+        //        // test BIG_ENDIAN double buffer, write
+        //        buf.Clear();
+        //        buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        //        doubleBuffer = buf.AsDoubleBuffer();
+        //        assertSame(ByteOrder.BIG_ENDIAN, doubleBuffer.Order);
+        //        while (doubleBuffer.Remaining > 0)
+        //        {
+        //            value = (double)doubleBuffer.Remaining;
+        //            doubleBuffer.Put(value);
+        //            buf.Get(bytes);
+        //            assertTrue(Arrays.Equals(bytes, double2bytes(value, buf.Order)));
+        //        }
+
+        //        // test LITTLE_ENDIAN double buffer, write
+        //        buf.Clear();
+        //        buf.SetOrder(ByteOrder.LITTLE_ENDIAN);
+        //        doubleBuffer = buf.AsDoubleBuffer();
+        //        assertSame(ByteOrder.LITTLE_ENDIAN, doubleBuffer.Order);
+        //        while (doubleBuffer.Remaining > 0)
+        //        {
+        //            value = (double)doubleBuffer.Remaining;
+        //            doubleBuffer.Put(value);
+        //            buf.Get(bytes);
+        //            assertTrue(Arrays.Equals(bytes, double2bytes(value, buf.Order)));
+        //        }
+        //    }
+
+        //    buf.Clear();
+        //    buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        //}
+
+        // LUCENENET NOTE: Not supported
+        //[Test, LuceneNetSpecific]
+        //public virtual void TestAsFloatBuffer()
+        //{
+        //    SingleBuffer floatBuffer;
+        //    byte[] bytes = new byte[4];
+        //    float value;
+
+        //    // test BIG_ENDIAN float buffer, read
+        //    buf.Clear();
+        //    buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        //    floatBuffer = buf.AsSingleBuffer();
+        //    assertSame(ByteOrder.BIG_ENDIAN, floatBuffer.Order);
+        //    while (floatBuffer.Remaining > 0)
+        //    {
+        //        buf.Get(bytes);
+        //        value = floatBuffer.Get();
+        //        if (!(float.IsNaN(bytes2float(bytes, buf.Order)) && float
+        //                .IsNaN(value)))
+        //        {
+        //            assertEquals(bytes2float(bytes, buf.Order), value, 0.00);
+        //        }
+        //    }
+
+        //    // test LITTLE_ENDIAN float buffer, read
+        //    buf.Clear();
+        //    buf.SetOrder(ByteOrder.LITTLE_ENDIAN);
+        //    floatBuffer = buf.AsSingleBuffer();
+        //    assertSame(ByteOrder.LITTLE_ENDIAN, floatBuffer.Order);
+        //    while (floatBuffer.Remaining > 0)
+        //    {
+        //        buf.Get(bytes);
+        //        value = floatBuffer.Get();
+        //        if (!(float.IsNaN(bytes2float(bytes, buf.Order)) && float
+        //                .IsNaN(value)))
+        //        {
+        //            assertEquals(bytes2float(bytes, buf.Order), value, 0.00);
+        //        }
+        //    }
+
+        //    if (!buf.IsReadOnly)
+        //    {
+        //        // test BIG_ENDIAN float buffer, write
+        //        buf.Clear();
+        //        buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        //        floatBuffer = buf.AsSingleBuffer();
+        //        assertSame(ByteOrder.BIG_ENDIAN, floatBuffer.Order);
+        //        while (floatBuffer.Remaining > 0)
+        //        {
+        //            value = (float)floatBuffer.Remaining;
+        //            floatBuffer.Put(value);
+        //            buf.Get(bytes);
+        //            assertTrue(Arrays.Equals(bytes, float2bytes(value, buf.Order)));
+        //        }
+
+        //        // test LITTLE_ENDIAN float buffer, write
+        //        buf.Clear();
+        //        buf.SetOrder(ByteOrder.LITTLE_ENDIAN);
+        //        floatBuffer = buf.AsSingleBuffer();
+        //        assertSame(ByteOrder.LITTLE_ENDIAN, floatBuffer.Order);
+        //        while (floatBuffer.Remaining > 0)
+        //        {
+        //            value = (float)floatBuffer.Remaining;
+        //            floatBuffer.Put(value);
+        //            buf.Get(bytes);
+        //            assertTrue(Arrays.Equals(bytes, float2bytes(value, buf.Order)));
+        //        }
+        //    }
+
+        //    buf.Clear();
+        //    buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        //}
+
+        // LUCENENET NOTE: Not supported
+        //[Test, LuceneNetSpecific]
+        //public virtual void TestAsIntBuffer()
+        //{
+        //    Int32Buffer intBuffer;
+        //    byte[] bytes = new byte[4];
+        //    int value;
+
+        //    // test BIG_ENDIAN int buffer, read
+        //    buf.Clear();
+        //    buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        //    intBuffer = buf.AsInt32Buffer();
+        //    assertSame(ByteOrder.BIG_ENDIAN, intBuffer.Order);
+        //    while (intBuffer.Remaining > 0)
+        //    {
+        //        buf.Get(bytes);
+        //        value = intBuffer.Get();
+        //        assertEquals(bytes2int(bytes, buf.Order), value);
+        //    }
+
+        //    // test LITTLE_ENDIAN int buffer, read
+        //    buf.Clear();
+        //    buf.SetOrder(ByteOrder.LITTLE_ENDIAN);
+        //    intBuffer = buf.AsInt32Buffer();
+        //    assertSame(ByteOrder.LITTLE_ENDIAN, intBuffer.Order);
+        //    while (intBuffer.Remaining > 0)
+        //    {
+        //        buf.Get(bytes);
+        //        value = intBuffer.Get();
+        //        assertEquals(bytes2int(bytes, buf.Order), value);
+        //    }
+
+        //    if (!buf.IsReadOnly)
+        //    {
+        //        // test BIG_ENDIAN int buffer, write
+        //        buf.Clear();
+        //        buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        //        intBuffer = buf.AsInt32Buffer();
+        //        assertSame(ByteOrder.BIG_ENDIAN, intBuffer.Order);
+        //        while (intBuffer.Remaining > 0)
+        //        {
+        //            value = (int)intBuffer.Remaining;
+        //            intBuffer.Put(value);
+        //            buf.Get(bytes);
+        //            assertTrue(Arrays.Equals(bytes, int2bytes(value, buf.Order)));
+        //        }
+
+        //        // test LITTLE_ENDIAN int buffer, write
+        //        buf.Clear();
+        //        buf.SetOrder(ByteOrder.LITTLE_ENDIAN);
+        //        intBuffer = buf.AsInt32Buffer();
+        //        assertSame(ByteOrder.LITTLE_ENDIAN, intBuffer.Order);
+        //        while (intBuffer.Remaining > 0)
+        //        {
+        //            value = (int)intBuffer.Remaining;
+        //            intBuffer.Put(value);
+        //            buf.Get(bytes);
+        //            assertTrue(Arrays.Equals(bytes, int2bytes(value, buf.Order)));
+        //        }
+        //    }
+
+        //    buf.Clear();
+        //    buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        //}
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestAsLongBuffer()
+        {
+            Int64Buffer longBuffer;
+            byte[] bytes = new byte[8];
+            long value;
+
+            // test BIG_ENDIAN long buffer, read
+            buf.Clear();
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+            longBuffer = buf.AsInt64Buffer();
+            assertSame(ByteOrder.BIG_ENDIAN, longBuffer.Order);
+            while (longBuffer.Remaining > 0)
+            {
+                buf.Get(bytes);
+                value = longBuffer.Get();
+                assertEquals(bytes2long(bytes, buf.Order), value);
+            }
+
+            // test LITTLE_ENDIAN long buffer, read
+            buf.Clear();
+            buf.SetOrder(ByteOrder.LITTLE_ENDIAN);
+            longBuffer = buf.AsInt64Buffer();
+            assertSame(ByteOrder.LITTLE_ENDIAN, longBuffer.Order);
+            while (longBuffer.Remaining > 0)
+            {
+                buf.Get(bytes);
+                value = longBuffer.Get();
+                assertEquals(bytes2long(bytes, buf.Order), value);
+            }
+
+            if (!buf.IsReadOnly)
+            {
+                // test BIG_ENDIAN long buffer, write
+                buf.Clear();
+                buf.SetOrder(ByteOrder.BIG_ENDIAN);
+                longBuffer = buf.AsInt64Buffer();
+                assertSame(ByteOrder.BIG_ENDIAN, longBuffer.Order);
+                while (longBuffer.Remaining > 0)
+                {
+                    value = (long)longBuffer.Remaining;
+                    longBuffer.Put(value);
+                    buf.Get(bytes);
+                    assertTrue(Arrays.Equals(bytes, long2bytes(value, buf.Order)));
+                }
+
+                // test LITTLE_ENDIAN long buffer, write
+                buf.Clear();
+                buf.SetOrder(ByteOrder.LITTLE_ENDIAN);
+                longBuffer = buf.AsInt64Buffer();
+                assertSame(ByteOrder.LITTLE_ENDIAN, longBuffer.Order);
+                while (longBuffer.Remaining > 0)
+                {
+                    value = (long)longBuffer.Remaining;
+                    longBuffer.Put(value);
+                    buf.Get(bytes);
+                    assertTrue(Arrays.Equals(bytes, long2bytes(value, buf.Order)));
+                }
+            }
+
+            buf.Clear();
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        }
+
+        // LUCENENET NOTE: Not supported
+        //[Test, LuceneNetSpecific]
+        //public virtual void TestAsShortBuffer()
+        //{
+        //    Int16Buffer shortBuffer;
+        //    byte[] bytes = new byte[2];
+        //    short value;
+
+        //    // test BIG_ENDIAN short buffer, read
+        //    buf.Clear();
+        //    buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        //    shortBuffer = buf.AsInt16Buffer();
+        //    assertSame(ByteOrder.BIG_ENDIAN, shortBuffer.Order);
+        //    while (shortBuffer.Remaining > 0)
+        //    {
+        //        buf.Get(bytes);
+        //        value = shortBuffer.Get();
+        //        assertEquals(bytes2short(bytes, buf.Order), value);
+        //    }
+
+        //    // test LITTLE_ENDIAN short buffer, read
+        //    buf.Clear();
+        //    buf.SetOrder(ByteOrder.LITTLE_ENDIAN);
+        //    shortBuffer = buf.AsInt16Buffer();
+        //    assertSame(ByteOrder.LITTLE_ENDIAN, shortBuffer.Order);
+        //    while (shortBuffer.Remaining > 0)
+        //    {
+        //        buf.Get(bytes);
+        //        value = shortBuffer.Get();
+        //        assertEquals(bytes2short(bytes, buf.Order), value);
+        //    }
+
+        //    if (!buf.IsReadOnly)
+        //    {
+        //        // test BIG_ENDIAN short buffer, write
+        //        buf.Clear();
+        //        buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        //        shortBuffer = buf.AsInt16Buffer();
+        //        assertSame(ByteOrder.BIG_ENDIAN, shortBuffer.Order);
+        //        while (shortBuffer.Remaining > 0)
+        //        {
+        //            value = (short)shortBuffer.Remaining;
+        //            shortBuffer.Put(value);
+        //            buf.Get(bytes);
+        //            assertTrue(Arrays.Equals(bytes, short2bytes(value, buf.Order)));
+        //        }
+
+        //        // test LITTLE_ENDIAN short buffer, write
+        //        buf.Clear();
+        //        buf.SetOrder(ByteOrder.LITTLE_ENDIAN);
+        //        shortBuffer = buf.AsInt16Buffer();
+        //        assertSame(ByteOrder.LITTLE_ENDIAN, shortBuffer.Order);
+        //        while (shortBuffer.Remaining > 0)
+        //        {
+        //            value = (short)shortBuffer.Remaining;
+        //            shortBuffer.Put(value);
+        //            buf.Get(bytes);
+        //            assertTrue(Arrays.Equals(bytes, short2bytes(value, buf.Order)));
+        //        }
+        //    }
+
+        //    buf.Clear();
+        //    buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        //}
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestGetChar()
+        {
+            int nbytes = 2;
+            byte[] bytes = new byte[nbytes];
+            char value;
+            buf.Clear();
+            for (int i = 0; buf.Remaining >= nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                assertEquals(i * nbytes, buf.Position);
+                buf.Mark();
+                buf.Get(bytes);
+                buf.Reset();
+                value = buf.GetChar();
+                assertEquals(bytes2char(bytes, buf.Order), value);
+            }
+
+            try
+            {
+                buf.GetChar();
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (BufferUnderflowException e)
+            {
+                // expected
+            }
+
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestGetCharint()
+        {
+            int nbytes = 2;
+            byte[] bytes = new byte[nbytes];
+            char value;
+            buf.Clear();
+            for (int i = 0; i <= buf.Limit - nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                buf.SetPosition(i);
+                value = buf.GetChar(i);
+                assertEquals(i, buf.Position);
+                buf.Get(bytes);
+                assertEquals(bytes2char(bytes, buf.Order), value);
+            }
+
+            try
+            {
+                buf.GetChar(-1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.GetChar(buf.Limit - nbytes + 1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestPutChar()
+        {
+            if (buf.IsReadOnly)
+            {
+                try
+                {
+                    buf.Clear();
+                    buf.PutChar((char)1);
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (ReadOnlyBufferException e)
+                {
+                    // expected
+                }
+                return;
+            }
+
+            int nbytes = 2;
+            byte[] bytes = new byte[nbytes];
+            char value = (char)0;
+            buf.Clear();
+            for (int i = 0; buf.Remaining >= nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                value = (char)i;
+                buf.Mark();
+                buf.PutChar(value);
+                assertEquals((i + 1) * nbytes, buf.Position);
+                buf.Reset();
+                buf.Get(bytes);
+                assertTrue(Arrays.Equals(char2bytes(value, buf.Order), bytes));
+            }
+
+            try
+            {
+                buf.PutChar(value);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (BufferOverflowException e)
+            {
+                // expected
+            }
+
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestPutCharint()
+        {
+            if (buf.IsReadOnly)
+            {
+                try
+                {
+                    buf.PutChar(0, (char)1);
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (ReadOnlyBufferException e)
+                {
+                    // expected
+                }
+                return;
+            }
+
+            int nbytes = 2;
+            byte[] bytes = new byte[nbytes];
+            char value = (char)0;
+            buf.Clear();
+            for (int i = 0; i <= buf.Limit - nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                value = (char)i;
+                buf.SetPosition(i);
+                buf.PutChar(i, value);
+                assertEquals(i, buf.Position);
+                buf.Get(bytes);
+                assertTrue(Arrays.Equals(char2bytes(value, buf.Order), bytes));
+            }
+
+            try
+            {
+                buf.PutChar(-1, value);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.PutChar(buf.Limit - nbytes + 1, value);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+
+            try
+            {
+                // LUCENENET NOTE: AllocateDirect() not implemented
+                //ByteBuffer.AllocateDirect(16).PutChar(int.MaxValue, 'h');
+                ByteBuffer.Allocate(16).PutChar(int.MaxValue, 'h');
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                //expected 
+            }
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestGetDouble()
+        {
+            int nbytes = 8;
+            byte[] bytes = new byte[nbytes];
+            double value;
+            buf.Clear();
+            for (int i = 0; buf.Remaining >= nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                assertEquals(i * nbytes, buf.Position);
+                buf.Mark();
+                buf.Get(bytes);
+                buf.Reset();
+                value = buf.GetDouble();
+                if (!(Double.IsNaN(bytes2double(bytes, buf.Order)) && Double
+                        .IsNaN(value)))
+                {
+                    assertEquals(bytes2double(bytes, buf.Order), value, 0.00);
+                }
+            }
+
+            try
+            {
+                buf.GetDouble();
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (BufferUnderflowException e)
+            {
+                // expected
+            }
+
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestGetDoubleint()
+        {
+            int nbytes = 8;
+            byte[] bytes = new byte[nbytes];
+            double value;
+            buf.Clear();
+            for (int i = 0; i <= buf.Limit - nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                buf.SetPosition(i);
+                value = buf.GetDouble(i);
+                assertEquals(i, buf.Position);
+                buf.Get(bytes);
+                if (!(Double.IsNaN(bytes2double(bytes, buf.Order)) && Double
+                        .IsNaN(value)))
+                {
+                    assertEquals(bytes2double(bytes, buf.Order), value, 0.00);
+                }
+            }
+
+            try
+            {
+                buf.GetDouble(-1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.GetDouble(buf.Limit - nbytes + 1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+
+            try
+            {
+                // LUCENENET NOTE: AllocateDirect() not supported
+                //ByteBuffer.AllocateDirect(16).GetDouble(int.MaxValue);
+                ByteBuffer.Allocate(16).GetDouble(int.MaxValue);
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                //expected 
+            }
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestPutDouble()
+        {
+            if (buf.IsReadOnly)
+            {
+                try
+                {
+                    buf.Clear();
+                    buf.PutDouble((double)1);
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (ReadOnlyBufferException e)
+                {
+                    // expected
+                }
+                return;
+            }
+
+            int nbytes = 8;
+            byte[] bytes = new byte[nbytes];
+            double value = 0;
+            buf.Clear();
+            for (int i = 0; buf.Remaining >= nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                value = (double)i;
+                buf.Mark();
+                buf.PutDouble(value);
+                assertEquals((i + 1) * nbytes, buf.Position);
+                buf.Reset();
+                buf.Get(bytes);
+                assertTrue(Arrays.Equals(double2bytes(value, buf.Order), bytes));
+            }
+
+            try
+            {
+                buf.PutDouble(value);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (BufferOverflowException e)
+            {
+                // expected
+            }
+
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestPutDoubleint()
+        {
+            if (buf.IsReadOnly)
+            {
+                try
+                {
+                    buf.PutDouble(0, (double)1);
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (ReadOnlyBufferException e)
+                {
+                    // expected
+                }
+                return;
+            }
+
+            int nbytes = 8;
+            byte[] bytes = new byte[nbytes];
+            double value = 0;
+            buf.Clear();
+            for (int i = 0; i <= buf.Limit - nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                value = (double)i;
+                buf.SetPosition(i);
+                buf.PutDouble(i, value);
+                assertEquals(i, buf.Position);
+                buf.Get(bytes);
+                assertTrue(Arrays.Equals(double2bytes(value, buf.Order), bytes));
+            }
+
+            try
+            {
+                buf.PutDouble(-1, value);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.PutDouble(buf.Limit - nbytes + 1, value);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestGetFloat()
+        {
+            int nbytes = 4;
+            byte[] bytes = new byte[nbytes];
+            float value;
+            buf.Clear();
+            for (int i = 0; buf.Remaining >= nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                assertEquals(i * nbytes, buf.Position);
+                buf.Mark();
+                buf.Get(bytes);
+                buf.Reset();
+                value = buf.GetSingle();
+                if (!(float.IsNaN(bytes2float(bytes, buf.Order)) && float
+                        .IsNaN(value)))
+                {
+                    assertEquals(bytes2float(bytes, buf.Order), value, 0.00);
+                }
+            }
+
+            try
+            {
+                buf.GetSingle();
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (BufferUnderflowException e)
+            {
+                // expected
+            }
+
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestGetFloatint()
+        {
+            int nbytes = 4;
+            byte[] bytes = new byte[nbytes];
+            float value;
+            buf.Clear();
+            for (int i = 0; i <= buf.Limit - nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                buf.SetPosition(i);
+                value = buf.GetSingle(i);
+                assertEquals(i, buf.Position);
+                buf.Get(bytes);
+                if (!(float.IsNaN(bytes2float(bytes, buf.Order)) && float
+                        .IsNaN(value)))
+                {
+                    assertEquals(bytes2float(bytes, buf.Order), value, 0.00);
+                }
+            }
+
+            try
+            {
+                buf.GetSingle(-1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.GetSingle(buf.Limit - nbytes + 1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestPutFloat()
+        {
+            if (buf.IsReadOnly)
+            {
+                try
+                {
+                    buf.Clear();
+                    buf.PutSingle((float)1);
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (ReadOnlyBufferException e)
+                {
+                    // expected
+                }
+                return;
+            }
+
+            int nbytes = 4;
+            byte[] bytes = new byte[nbytes];
+            float value = 0;
+            buf.Clear();
+            for (int i = 0; buf.Remaining >= nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                value = (float)i;
+                buf.Mark();
+                buf.PutSingle(value);
+                assertEquals((i + 1) * nbytes, buf.Position);
+                buf.Reset();
+                buf.Get(bytes);
+                assertTrue(Arrays.Equals(float2bytes(value, buf.Order), bytes));
+            }
+
+            try
+            {
+                buf.PutSingle(value);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (BufferOverflowException e)
+            {
+                // expected
+            }
+
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestPutFloatint()
+        {
+            if (buf.IsReadOnly)
+            {
+                try
+                {
+                    buf.PutSingle(0, (float)1);
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (ReadOnlyBufferException e)
+                {
+                    // expected
+                }
+                return;
+            }
+
+            int nbytes = 4;
+            byte[] bytes = new byte[nbytes];
+            float value = 0;
+            buf.Clear();
+            for (int i = 0; i <= buf.Limit - nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                value = (float)i;
+                buf.SetPosition(i);
+                buf.PutSingle(i, value);
+                assertEquals(i, buf.Position);
+                buf.Get(bytes);
+                assertTrue(Arrays.Equals(float2bytes(value, buf.Order), bytes));
+            }
+
+            try
+            {
+                buf.PutSingle(-1, value);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.PutSingle(buf.Limit - nbytes + 1, value);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestGetInt()
+        {
+            int nbytes = 4;
+            byte[] bytes = new byte[nbytes];
+            int value;
+            buf.Clear();
+            for (int i = 0; buf.Remaining >= nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                assertEquals(i * nbytes, buf.Position);
+                buf.Mark();
+                buf.Get(bytes);
+                buf.Reset();
+                value = buf.GetInt32();
+                assertEquals(bytes2int(bytes, buf.Order), value);
+            }
+
+            try
+            {
+                buf.GetInt32();
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (BufferUnderflowException e)
+            {
+                // expected
+            }
+
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestGetIntint()
+        {
+            int nbytes = 4;
+            byte[] bytes = new byte[nbytes];
+            int value;
+            buf.Clear();
+            for (int i = 0; i <= buf.Limit - nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                buf.SetPosition(i);
+                value = buf.GetInt32(i);
+                assertEquals(i, buf.Position);
+                buf.Get(bytes);
+                assertEquals(bytes2int(bytes, buf.Order), value);
+            }
+
+            try
+            {
+                buf.GetInt32(-1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+            try
+            {
+                buf.GetInt32(buf.Limit - nbytes + 1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                // expected
+            }
+
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+            try
+            {
+                // LUCENENET NOTE: AllocateDirect() not implemented
+                //ByteBuffer.AllocateDirect(16).GetInt32(int.MaxValue);
+                ByteBuffer.Allocate(16).GetInt32(int.MaxValue);
+            }
+            catch (IndexOutOfRangeException e)
+            {
+                //expected 
+            }
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestPutInt()
+        {
+            if (buf.IsReadOnly)
+            {
+                try
+                {
+                    buf.Clear();
+                    buf.PutInt32((int)1);
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (ReadOnlyBufferException e)
+                {
+                    // expected
+                }
+                return;
+            }
+
+            int nbytes = 4;
+            byte[] bytes = new byte[nbytes];
+            int value = 0;
+            buf.Clear();
+            for (int i = 0; buf.Remaining >= nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                value = (int)i;
+                buf.Mark();
+                buf.PutInt32(value);
+                assertEquals((i + 1) * nbytes, buf.Position);
+                buf.Reset();
+                buf.Get(bytes);
+                assertTrue(Arrays.Equals(int2bytes(value, buf.Order), bytes));
+            }
+
+            try
+            {
+                buf.PutInt32(value);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (BufferOverflowException e)
+            {
+                // expected
+            }
+
+            buf.SetOrder(ByteOrder.BIG_ENDIAN);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestPutIntint()
+        {
+            if (buf.IsReadOnly)
+            {
+                try
+                {
+                    buf.PutInt32(0, (int)1);
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (ReadOnlyBufferException e)
+                {
+                    // expected
+                }
+                return;
+            }
+
+            int nbytes = 4;
+            byte[] bytes = new byte[nbytes];
+            int value = 0;
+            buf.Clear();
+            for (int i = 0; i <= buf.Limit - nbytes; i++)
+            {
+                buf.SetOrder(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
+                        : ByteOrder.LITTLE_ENDIAN);
+                value = (int)i;
+                buf.SetPosition(i);
+                buf.PutInt32(i, value);
+                assertEquals(i, buf.Position);
+                buf.Get(bytes);
+                assertTrue(Arrays.Equals(int2bytes(value, buf.Order), bytes));
+            }
+
+            try
+            {
+                buf.PutInt32(-1, value);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (IndexOutOfRangeException e)
+

<TRUNCATED>

Mime
View raw message