lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [30/45] lucenenet git commit: Lucene.Net.Tests.Support.IO: Ported more ByteBuffer tests from Apache Harmony
Date Sun, 30 Apr 2017 21:56:09 GMT
Lucene.Net.Tests.Support.IO: Ported more ByteBuffer tests from Apache Harmony


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/6b3a8075
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/6b3a8075
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/6b3a8075

Branch: refs/heads/master
Commit: 6b3a807593585a86f5bbe877b2fa9e38e67b5299
Parents: d8f14b1
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sat Apr 29 15:57:21 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Mon May 1 04:48:34 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Tests/Lucene.Net.Tests.csproj    |    6 +-
 .../Support/IO/AbstractBufferTest.cs            |  368 ++
 .../Support/IO/TestByteBuffer.cs                | 3254 ++++++++++++++----
 .../Support/IO/TestByteBuffer2.cs               |  756 ++++
 .../Support/IO/TestDataInputStream.cs           |   39 +-
 .../Support/IO/TestDataOutputStream.cs          |   38 +-
 .../Support/IO/TestHeapByteBuffer.cs            |  533 +++
 .../Support/IO/TestLongBuffer.cs                |   38 +-
 .../Support/IO/TestReadOnlyHeapByteBuffer.cs    |  515 +++
 .../Support/IO/TestSafeTextWriterWrapper.cs     |   38 +-
 src/Lucene.Net/Support/IO/BufferExceptions.cs   |    4 +-
 src/Lucene.Net/Support/IO/ByteBuffer.cs         |    1 -
 12 files changed, 4916 insertions(+), 674 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6b3a8075/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj b/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj
index d75b5bf..df8cea4 100644
--- a/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj
+++ b/src/Lucene.Net.Tests/Lucene.Net.Tests.csproj
@@ -516,6 +516,10 @@
     <Compile Include="Support\Codecs\TestDefaultDocValuesFormatFactory.cs" />
     <Compile Include="Support\Codecs\TestDefaultPostingsFormatFactory.cs" />
     <Compile Include="Support\CollisionTester.cs" />
+    <Compile Include="Support\IO\AbstractBufferTest.cs" />
+    <Compile Include="Support\IO\TestByteBuffer.cs" />
+    <Compile Include="Support\IO\TestHeapByteBuffer.cs" />
+    <Compile Include="Support\IO\TestReadOnlyHeapByteBuffer.cs" />
     <Compile Include="Support\SmallObject.cs" />
     <Compile Include="Support\TestPriorityQueue.cs" />
     <Compile Include="Support\Threading\TestCloseableThreadLocal.cs" />
@@ -527,7 +531,7 @@
     <Compile Include="Support\TestIDisposable.cs" />
     <Compile Include="Support\TestLinkedHashMap.cs" />
     <Compile Include="Support\IO\TestLongBuffer.cs" />
-    <Compile Include="Support\IO\TestByteBuffer.cs" />
+    <Compile Include="Support\IO\TestByteBuffer2.cs" />
     <Compile Include="Support\TestLurchTable.cs" />
     <Compile Include="Support\TestLurchTableThreading.cs" />
     <Compile Include="Support\IO\TestDataInputStream.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6b3a8075/src/Lucene.Net.Tests/Support/IO/AbstractBufferTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Support/IO/AbstractBufferTest.cs b/src/Lucene.Net.Tests/Support/IO/AbstractBufferTest.cs
new file mode 100644
index 0000000..efe2761
--- /dev/null
+++ b/src/Lucene.Net.Tests/Support/IO/AbstractBufferTest.cs
@@ -0,0 +1,368 @@
+// This class was sourced from the Apache Harmony project
+// https://svn.apache.org/repos/asf/harmony/enhanced/java/trunk/
+
+using Lucene.Net.Attributes;
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System;
+
+namespace Lucene.Net.Support.IO
+{
+    /*
+     * 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 abstract class AbstractBufferTest : LuceneTestCase
+    {
+        protected Buffer baseBuf;
+
+        public override void SetUp() 
+        {
+            base.SetUp();
+            baseBuf = ByteBuffer.Allocate(10);
+        }
+
+        public override void TearDown()
+        {
+            base.TearDown();
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestCapacity()
+        {
+            assertTrue(0 <= baseBuf.Position && baseBuf.Position <= baseBuf.Limit
+                    && baseBuf.Limit <= baseBuf.Capacity);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestClear()
+        {
+            // save state
+            int oldPosition = baseBuf.Position;
+            int oldLimit = baseBuf.Limit;
+
+            Buffer ret = baseBuf.Clear();
+            assertSame(ret, baseBuf);
+            assertEquals(baseBuf.Position, 0);
+            assertEquals(baseBuf.Limit, baseBuf.Capacity);
+            try
+            {
+                baseBuf.Reset();
+                fail("Should throw Exception"); //$NON-NLS-1$S
+            }
+            catch (InvalidMarkException e)
+            {
+                // expected
+            }
+
+            // restore state
+            baseBuf.SetLimit(oldLimit);
+            baseBuf.SetPosition(oldPosition);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestFlip()
+        {
+            // save state
+            int oldPosition = baseBuf.Position;
+            int oldLimit = baseBuf.Limit;
+
+            Buffer ret = baseBuf.Flip();
+            assertSame(ret, baseBuf);
+            assertEquals(baseBuf.Position, 0);
+            assertEquals(baseBuf.Limit, oldPosition);
+            try
+            {
+                baseBuf.Reset();
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (InvalidMarkException e)
+            {
+                // expected
+            }
+
+            // restore state
+            baseBuf.SetLimit(oldLimit);
+            baseBuf.SetPosition(oldPosition);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestHasRemaining()
+        {
+            // save state
+            int oldPosition = baseBuf.Position;
+            int oldLimit = baseBuf.Limit;
+
+            assertEquals(baseBuf.HasRemaining, baseBuf.Position < baseBuf.Limit);
+            baseBuf.SetPosition(baseBuf.Limit);
+            assertFalse(baseBuf.HasRemaining);
+
+            // restore state
+            baseBuf.SetLimit(oldLimit);
+            baseBuf.SetPosition(oldPosition);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestIsReadOnly()
+        {
+            var _ = baseBuf.IsReadOnly;
+        }
+
+        /*
+         * Class under test for int limit()
+         */
+        [Test, LuceneNetSpecific]
+        public virtual void TestLimit()
+        {
+            assertTrue(0 <= baseBuf.Position && baseBuf.Position <= baseBuf.Limit
+                    && baseBuf.Limit <= baseBuf.Capacity);
+        }
+
+        /*
+         * Class under test for Buffer limit(int)
+         */
+        [Test, LuceneNetSpecific]
+        public virtual void TestLimitint()
+        {
+            // save state
+            int oldPosition = baseBuf.Position;
+            int oldLimit = baseBuf.Limit;
+
+            Buffer ret = baseBuf.SetLimit(baseBuf.Limit);
+            assertSame(ret, baseBuf);
+
+            baseBuf.Mark();
+            baseBuf.SetLimit(baseBuf.Capacity);
+            assertEquals(baseBuf.Limit, baseBuf.Capacity);
+            // position should not change
+            assertEquals(baseBuf.Position, oldPosition);
+            // mark should be valid
+            baseBuf.Reset();
+
+            if (baseBuf.Capacity > 0)
+            {
+                baseBuf.SetLimit(baseBuf.Capacity);
+                baseBuf.SetPosition(baseBuf.Capacity);
+                baseBuf.Mark();
+                baseBuf.SetLimit(baseBuf.Capacity - 1);
+                // position should be the new limit
+                assertEquals(baseBuf.Position, baseBuf.Limit);
+                // mark should be invalid
+                try
+                {
+                    baseBuf.Reset();
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (InvalidMarkException e)
+                {
+                    // expected
+                }
+            }
+
+            try
+            {
+                baseBuf.SetLimit(-1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (ArgumentException e)
+            {
+                // expected
+            }
+            try
+            {
+                baseBuf.SetLimit(baseBuf.Capacity + 1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (ArgumentException e)
+            {
+                // expected
+            }
+
+            // restore state
+            baseBuf.SetLimit(oldLimit);
+            baseBuf.SetPosition(oldPosition);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestMark()
+        {
+            // save state
+            int oldPosition = baseBuf.Position;
+            int oldLimit = baseBuf.Limit;
+
+            Buffer ret = baseBuf.Mark();
+            assertSame(ret, baseBuf);
+
+            baseBuf.Mark();
+            baseBuf.SetPosition(baseBuf.Limit);
+            baseBuf.Reset();
+            assertEquals(baseBuf.Position, oldPosition);
+
+            baseBuf.Mark();
+            baseBuf.SetPosition(baseBuf.Limit);
+            baseBuf.Reset();
+            assertEquals(baseBuf.Position, oldPosition);
+
+            // restore state
+            baseBuf.SetLimit(oldLimit);
+            baseBuf.SetPosition(oldPosition);
+        }
+
+        /*
+         * Class under test for int position()
+         */
+        [Test, LuceneNetSpecific]
+        public virtual void TestPosition()
+        {
+            assertTrue(0 <= baseBuf.Position && baseBuf.Position <= baseBuf.Limit
+                    && baseBuf.Limit <= baseBuf.Capacity);
+        }
+
+        /*
+         * Class under test for Buffer position(int)
+         */
+        [Test, LuceneNetSpecific]
+        public virtual void TestPositionint()
+        {
+            // save state
+            int oldPosition = baseBuf.Position;
+            int oldLimit = baseBuf.Limit;
+
+            try
+            {
+                baseBuf.SetPosition(-1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (ArgumentException e)
+            {
+                // expected
+            }
+            try
+            {
+                baseBuf.SetPosition(baseBuf.Limit + 1);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (ArgumentException e)
+            {
+                // expected
+            }
+
+            baseBuf.Mark();
+            baseBuf.SetPosition(baseBuf.Position);
+            baseBuf.Reset();
+            assertEquals(baseBuf.Position, oldPosition);
+
+            baseBuf.SetPosition(0);
+            assertEquals(baseBuf.Position, 0);
+            baseBuf.SetPosition(baseBuf.Limit);
+            assertEquals(baseBuf.Position, baseBuf.Limit);
+
+            if (baseBuf.Capacity > 0)
+            {
+                baseBuf.SetLimit(baseBuf.Capacity);
+                baseBuf.SetPosition(baseBuf.Limit);
+                baseBuf.Mark();
+                baseBuf.SetPosition(baseBuf.Limit - 1);
+                assertEquals(baseBuf.Position, baseBuf.Limit - 1);
+                // mark should be invalid
+                try
+                {
+                    baseBuf.Reset();
+                    fail("Should throw Exception"); //$NON-NLS-1$
+                }
+                catch (InvalidMarkException e)
+                {
+                    // expected
+                }
+            }
+
+            Buffer ret = baseBuf.SetPosition(0);
+            assertSame(ret, baseBuf);
+
+            // restore state
+            baseBuf.SetLimit(oldLimit);
+            baseBuf.SetPosition(oldPosition);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestRemaining()
+        {
+            assertEquals(baseBuf.Remaining, baseBuf.Limit - baseBuf.Position);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestReset()
+        {
+            // save state
+            int oldPosition = baseBuf.Position;
+            int oldLimit = baseBuf.Limit;
+
+            baseBuf.Mark();
+            baseBuf.SetPosition(baseBuf.Limit);
+            baseBuf.Reset();
+            assertEquals(baseBuf.Position, oldPosition);
+
+            baseBuf.Mark();
+            baseBuf.SetPosition(baseBuf.Limit);
+            baseBuf.Reset();
+            assertEquals(baseBuf.Position, oldPosition);
+
+            Buffer ret = baseBuf.Reset();
+            assertSame(ret, baseBuf);
+
+            baseBuf.Clear();
+            try
+            {
+                baseBuf.Reset();
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (InvalidMarkException e)
+            {
+                // expected
+            }
+
+            // restore state
+            baseBuf.SetLimit(oldLimit);
+            baseBuf.SetPosition(oldPosition);
+        }
+
+        [Test, LuceneNetSpecific]
+        public virtual void TestRewind()
+        {
+            // save state
+            int oldPosition = baseBuf.Position;
+            int oldLimit = baseBuf.Limit;
+
+            Buffer ret = baseBuf.Rewind();
+            assertEquals(baseBuf.Position, 0);
+            assertSame(ret, baseBuf);
+            try
+            {
+                baseBuf.Reset();
+                fail("Should throw Exception"); //$NON-NLS-1$
+            }
+            catch (InvalidMarkException e)
+            {
+                // expected
+            }
+
+            // restore state
+            baseBuf.SetLimit(oldLimit);
+            baseBuf.SetPosition(oldPosition);
+        }
+    }
+}


Mime
View raw message