You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/02/26 23:37:36 UTC

[48/72] [abbrv] [partial] lucenenet git commit: Lucene.Net.Tests: Removed \core directory and put its contents in root directory

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/96822396/src/Lucene.Net.Tests/Codecs/Lucene3x/TestLucene3xStoredFieldsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Codecs/Lucene3x/TestLucene3xStoredFieldsFormat.cs b/src/Lucene.Net.Tests/Codecs/Lucene3x/TestLucene3xStoredFieldsFormat.cs
new file mode 100644
index 0000000..e78db47
--- /dev/null
+++ b/src/Lucene.Net.Tests/Codecs/Lucene3x/TestLucene3xStoredFieldsFormat.cs
@@ -0,0 +1,145 @@
+using Lucene.Net.Attributes;
+using NUnit.Framework;
+
+namespace Lucene.Net.Codecs.Lucene3x
+{
+    /*
+     * 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.
+     */
+
+    using BaseStoredFieldsFormatTestCase = Lucene.Net.Index.BaseStoredFieldsFormatTestCase;
+    using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+
+    [TestFixture]
+    public class TestLucene3xStoredFieldsFormat : BaseStoredFieldsFormatTestCase
+    {
+        /// <summary>
+        /// LUCENENET specific
+        /// Is non-static because OLD_FORMAT_IMPERSONATION_IS_ACTIVE is no longer static.
+        /// </summary>
+        [OneTimeSetUp]
+        public void BeforeClass()
+        {
+            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; // explicitly instantiates ancient codec
+        }
+
+        protected override Codec Codec
+        {
+            get
+            {
+                Assert.IsTrue(OLD_FORMAT_IMPERSONATION_IS_ACTIVE, "This should have been set up in the test fixture");
+                return new PreFlexRWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE);
+            }
+        }
+
+        [Test]
+        public override void TestWriteReadMerge()
+        {
+            AssumeFalse("impersonation isnt good enough", true);
+            // this test tries to switch up between the codec and another codec.
+            // for 3.x: we currently cannot take an index with existing 4.x segments
+            // and merge into newly formed 3.x segments.
+        }
+
+
+
+        #region BaseStoredFieldsFormatTestCase
+        // LUCENENET NOTE: Tests in an abstract base class are not pulled into the correct
+        // context in Visual Studio. This fixes that with the minimum amount of code necessary
+        // to run them in the correct context without duplicating all of the tests.
+
+        [Test]
+        public override void TestRandomStoredFields()
+        {
+            base.TestRandomStoredFields();
+        }
+
+        [Test]
+        // LUCENE-1727: make sure doc fields are stored in order
+        public override void TestStoredFieldsOrder()
+        {
+            base.TestStoredFieldsOrder();
+        }
+
+        [Test]
+        // LUCENE-1219
+        public override void TestBinaryFieldOffsetLength()
+        {
+            base.TestBinaryFieldOffsetLength();
+        }
+
+        [Test]
+        public override void TestNumericField()
+        {
+            base.TestNumericField();
+        }
+
+        [Test]
+        public override void TestIndexedBit()
+        {
+            base.TestIndexedBit();
+        }
+
+        [Test]
+        public override void TestReadSkip()
+        {
+            base.TestReadSkip();
+        }
+
+        [Test]
+        public override void TestEmptyDocs()
+        {
+            base.TestEmptyDocs();
+        }
+
+        [Test]
+        public override void TestConcurrentReads()
+        {
+            base.TestConcurrentReads();
+        }
+
+#if !NETSTANDARD
+        // LUCENENET: There is no Timeout on NUnit for .NET Core.
+        [Timeout(120000)]
+#endif
+        [Test, HasTimeout]
+        public override void TestBigDocuments()
+        {
+            base.TestBigDocuments();
+        }
+
+        [Test]
+        public override void TestBulkMergeWithDeletes()
+        {
+            base.TestBulkMergeWithDeletes();
+        }
+
+        #endregion
+
+        #region BaseIndexFileFormatTestCase
+        // LUCENENET NOTE: Tests in an abstract base class are not pulled into the correct
+        // context in Visual Studio. This fixes that with the minimum amount of code necessary
+        // to run them in the correct context without duplicating all of the tests.
+
+        [Test]
+        public override void TestMergeStability()
+        {
+            base.TestMergeStability();
+        }
+
+        #endregion
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/96822396/src/Lucene.Net.Tests/Codecs/Lucene3x/TestLucene3xTermVectorsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Codecs/Lucene3x/TestLucene3xTermVectorsFormat.cs b/src/Lucene.Net.Tests/Codecs/Lucene3x/TestLucene3xTermVectorsFormat.cs
new file mode 100644
index 0000000..cbd59ed
--- /dev/null
+++ b/src/Lucene.Net.Tests/Codecs/Lucene3x/TestLucene3xTermVectorsFormat.cs
@@ -0,0 +1,122 @@
+using NUnit.Framework;
+
+namespace Lucene.Net.Codecs.Lucene3x
+{
+    using System.Collections.Generic;
+    using Attributes;
+
+    /*
+         * 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.
+         */
+
+    using BaseTermVectorsFormatTestCase = Lucene.Net.Index.BaseTermVectorsFormatTestCase;
+    using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+
+    public class TestLucene3xTermVectorsFormat : BaseTermVectorsFormatTestCase
+    {
+        [SetUp]
+        public override void SetUp()
+        {
+            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
+            base.SetUp();
+        }
+
+        protected override Codec Codec
+        {
+            get
+            {
+                Assert.IsTrue(OLD_FORMAT_IMPERSONATION_IS_ACTIVE, "This should have been set up in the test fixture");
+                return new PreFlexRWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE);
+            }
+        }
+
+        protected override IEnumerable<Options> ValidOptions()
+        {
+            return ValidOptions(Options.NONE, Options.POSITIONS_AND_OFFSETS);
+        }
+
+
+        #region BaseTermVectorsFormatTestCase
+        // LUCENENET NOTE: Tests in an abstract base class are not pulled into the correct
+        // context in Visual Studio. This fixes that with the minimum amount of code necessary
+        // to run them in the correct context without duplicating all of the tests.
+
+        [Test]
+        // only one doc with vectors
+        public override void TestRareVectors()
+        {
+            base.TestRareVectors();
+        }
+
+        [Test]
+        public override void TestHighFreqs()
+        {
+            base.TestHighFreqs();
+        }
+
+        [Test]
+        public override void TestLotsOfFields()
+        {
+            base.TestLotsOfFields();
+        }
+
+#if !NETSTANDARD
+        // LUCENENET: There is no Timeout on NUnit for .NET Core.
+        [Timeout(300000)]
+#endif
+        [Test, HasTimeout]
+        // different options for the same field
+        public override void TestMixedOptions()
+        {
+            base.TestMixedOptions();
+        }
+
+        [Test]
+        public override void TestRandom()
+        {
+            base.TestRandom();
+        }
+
+        [Test]
+        public override void TestMerge()
+        {
+            base.TestMerge();
+        }
+
+        [Test]
+        // run random tests from different threads to make sure the per-thread clones
+        // don't share mutable data
+        public override void TestClone()
+        {
+            base.TestClone();
+        }
+
+        #endregion
+
+        #region BaseIndexFileFormatTestCase
+        // LUCENENET NOTE: Tests in an abstract base class are not pulled into the correct
+        // context in Visual Studio. This fixes that with the minimum amount of code necessary
+        // to run them in the correct context without duplicating all of the tests.
+
+        [Test]
+        public override void TestMergeStability()
+        {
+            base.TestMergeStability();
+        }
+
+        #endregion
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/96822396/src/Lucene.Net.Tests/Codecs/Lucene3x/TestSurrogates.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Codecs/Lucene3x/TestSurrogates.cs b/src/Lucene.Net.Tests/Codecs/Lucene3x/TestSurrogates.cs
new file mode 100644
index 0000000..d4b1b63
--- /dev/null
+++ b/src/Lucene.Net.Tests/Codecs/Lucene3x/TestSurrogates.cs
@@ -0,0 +1,424 @@
+using System;
+using System.Collections.Generic;
+using Lucene.Net.Documents;
+
+namespace Lucene.Net.Codecs.Lucene3x
+{
+    using Attributes;
+    using Lucene.Net.Analysis;
+    using Lucene.Net.Index;
+
+    /*
+         * 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.
+         */
+
+    using Lucene.Net.Store;
+    using Lucene.Net.Util;
+    using NUnit.Framework;
+
+    [TestFixture]
+    public class TestSurrogates : LuceneTestCase
+    {
+        /// <summary>
+        /// we will manually instantiate preflex-rw here
+        /// 
+        /// LUCENENET specific
+        /// Is non-static because OLD_FORMAT_IMPERSONATION_IS_ACTIVE is no longer static.
+        /// </summary>
+        [OneTimeSetUp]
+        public void BeforeClass()
+        {
+            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
+        }
+
+        private static string MakeDifficultRandomUnicodeString(Random r)
+        {
+            int end = r.Next(20);
+            if (end == 0)
+            {
+                // allow 0 length
+                return "";
+            }
+            char[] buffer = new char[end];
+            for (int i = 0; i < end; i++)
+            {
+                int t = r.Next(5);
+
+                if (0 == t && i < end - 1)
+                {
+                    // hi
+                    buffer[i++] = (char)(0xd800 + r.Next(2));
+                    // lo
+                    buffer[i] = (char)(0xdc00 + r.Next(2));
+                }
+                else if (t <= 3)
+                {
+                    buffer[i] = (char)('a' + r.Next(2));
+                }
+                else if (4 == t)
+                {
+                    buffer[i] = (char)(0xe000 + r.Next(2));
+                }
+            }
+
+            return new string(buffer, 0, end);
+        }
+
+        private static string ToHexString(Term t)
+        {
+            return t.Field + ":" + UnicodeUtil.ToHexString(t.Text());
+        }
+
+        private string GetRandomString(Random r)
+        {
+            string s;
+            if (r.Next(5) == 1)
+            {
+                if (r.Next(3) == 1)
+                {
+                    s = MakeDifficultRandomUnicodeString(r);
+                }
+                else
+                {
+                    s = TestUtil.RandomUnicodeString(r);
+                }
+            }
+            else
+            {
+                s = TestUtil.RandomRealisticUnicodeString(r);
+            }
+            return s;
+        }
+
+        private sealed class SortTermAsUTF16Comparer : IComparer<Term>
+        {
+#pragma warning disable 612, 618
+            private static readonly IComparer<BytesRef> LegacyComparer = BytesRef.UTF8SortedAsUTF16Comparer;
+#pragma warning restore 612, 618
+
+            public int Compare(Term term1, Term term2)
+            {
+                if (term1.Field.Equals(term2.Field))
+                {
+                    return LegacyComparer.Compare(term1.Bytes, term2.Bytes);
+                }
+                else
+                {
+                    return System.String.Compare(term1.Field, term2.Field, System.StringComparison.Ordinal);
+                }
+            }
+        }
+
+        private static readonly SortTermAsUTF16Comparer TermAsUTF16Comparer = new SortTermAsUTF16Comparer();
+
+        // single straight enum
+        private void DoTestStraightEnum(IList<Term> fieldTerms, IndexReader reader, int uniqueTermCount)
+        {
+            if (VERBOSE)
+            {
+                Console.WriteLine("\nTEST: top now enum reader=" + reader);
+            }
+            Fields fields = MultiFields.GetFields(reader);
+            {
+                // Test straight enum:
+                int termCount = 0;
+                foreach (string field in fields)
+                {
+                    Terms terms = fields.GetTerms(field);
+                    Assert.IsNotNull(terms);
+                    TermsEnum termsEnum = terms.GetIterator(null);
+                    BytesRef text;
+                    BytesRef lastText = null;
+                    while ((text = termsEnum.Next()) != null)
+                    {
+                        Term exp = fieldTerms[termCount];
+                        if (VERBOSE)
+                        {
+                            Console.WriteLine("  got term=" + field + ":" + UnicodeUtil.ToHexString(text.Utf8ToString()));
+                            Console.WriteLine("       exp=" + exp.Field + ":" + UnicodeUtil.ToHexString(exp.Text()));
+                            Console.WriteLine();
+                        }
+                        if (lastText == null)
+                        {
+                            lastText = BytesRef.DeepCopyOf(text);
+                        }
+                        else
+                        {
+                            Assert.IsTrue(lastText.CompareTo(text) < 0);
+                            lastText.CopyBytes(text);
+                        }
+                        Assert.AreEqual(exp.Field, field);
+                        Assert.AreEqual(exp.Bytes, text);
+                        termCount++;
+                    }
+                    if (VERBOSE)
+                    {
+                        Console.WriteLine("  no more terms for field=" + field);
+                    }
+                }
+                Assert.AreEqual(uniqueTermCount, termCount);
+            }
+        }
+
+        // randomly seeks to term that we know exists, then next's
+        // from there
+        private void DoTestSeekExists(Random r, IList<Term> fieldTerms, IndexReader reader)
+        {
+            IDictionary<string, TermsEnum> tes = new Dictionary<string, TermsEnum>();
+
+            // Test random seek to existing term, then enum:
+            if (VERBOSE)
+            {
+                Console.WriteLine("\nTEST: top now seek");
+            }
+
+            int num = AtLeast(100);
+            for (int iter = 0; iter < num; iter++)
+            {
+                // pick random field+term
+                int spot = r.Next(fieldTerms.Count);
+                Term term = fieldTerms[spot];
+                string field = term.Field;
+
+                if (VERBOSE)
+                {
+                    Console.WriteLine("TEST: exist seek field=" + field + " term=" + UnicodeUtil.ToHexString(term.Text()));
+                }
+
+                // seek to it
+                TermsEnum te;
+                if (!tes.TryGetValue(field, out te))
+                {
+                    te = MultiFields.GetTerms(reader, field).GetIterator(null);
+                    tes[field] = te;
+                }
+
+                if (VERBOSE)
+                {
+                    Console.WriteLine("  done get enum");
+                }
+
+                // seek should find the term
+                Assert.AreEqual(TermsEnum.SeekStatus.FOUND, te.SeekCeil(term.Bytes));
+
+                // now .next() this many times:
+                int ct = TestUtil.NextInt(r, 5, 100);
+                for (int i = 0; i < ct; i++)
+                {
+                    if (VERBOSE)
+                    {
+                        Console.WriteLine("TEST: now next()");
+                    }
+                    if (1 + spot + i >= fieldTerms.Count)
+                    {
+                        break;
+                    }
+                    term = fieldTerms[1 + spot + i];
+                    if (!term.Field.Equals(field))
+                    {
+                        Assert.IsNull(te.Next());
+                        break;
+                    }
+                    else
+                    {
+                        BytesRef t = te.Next();
+
+                        if (VERBOSE)
+                        {
+                            Console.WriteLine("  got term=" + (t == null ? null : UnicodeUtil.ToHexString(t.Utf8ToString())));
+                            Console.WriteLine("       exp=" + UnicodeUtil.ToHexString(term.Text().ToString()));
+                        }
+
+                        Assert.AreEqual(term.Bytes, t);
+                    }
+                }
+            }
+        }
+
+        private void DoTestSeekDoesNotExist(Random r, int numField, IList<Term> fieldTerms, Term[] fieldTermsArray, IndexReader reader)
+        {
+            IDictionary<string, TermsEnum> tes = new Dictionary<string, TermsEnum>();
+
+            if (VERBOSE)
+            {
+                Console.WriteLine("TEST: top random seeks");
+            }
+
+            {
+                int num = AtLeast(100);
+                for (int iter = 0; iter < num; iter++)
+                {
+                    // seek to random spot
+                    string field = StringHelper.Intern("f" + r.Next(numField));
+                    Term tx = new Term(field, GetRandomString(r));
+
+                    int spot = Array.BinarySearch(fieldTermsArray, tx);
+
+                    if (spot < 0)
+                    {
+                        if (VERBOSE)
+                        {
+                            Console.WriteLine("TEST: non-exist seek to " + field + ":" + UnicodeUtil.ToHexString(tx.Text()));
+                        }
+
+                        // term does not exist:
+                        TermsEnum te;
+                        if (!tes.TryGetValue(field, out te))
+                        {
+                            te = MultiFields.GetTerms(reader, field).GetIterator(null);
+                            tes[field] = te;
+                        }
+
+                        if (VERBOSE)
+                        {
+                            Console.WriteLine("  got enum");
+                        }
+
+                        spot = -spot - 1;
+
+                        if (spot == fieldTerms.Count || !fieldTerms[spot].Field.Equals(field))
+                        {
+                            Assert.AreEqual(TermsEnum.SeekStatus.END, te.SeekCeil(tx.Bytes));
+                        }
+                        else
+                        {
+                            Assert.AreEqual(TermsEnum.SeekStatus.NOT_FOUND, te.SeekCeil(tx.Bytes));
+
+                            if (VERBOSE)
+                            {
+                                Console.WriteLine("  got term=" + UnicodeUtil.ToHexString(te.Term.Utf8ToString()));
+                                Console.WriteLine("  exp term=" + UnicodeUtil.ToHexString(fieldTerms[spot].Text()));
+                            }
+
+                            Assert.AreEqual(fieldTerms[spot].Bytes, te.Term);
+
+                            // now .next() this many times:
+                            int ct = TestUtil.NextInt(r, 5, 100);
+                            for (int i = 0; i < ct; i++)
+                            {
+                                if (VERBOSE)
+                                {
+                                    Console.WriteLine("TEST: now next()");
+                                }
+                                if (1 + spot + i >= fieldTerms.Count)
+                                {
+                                    break;
+                                }
+                                Term term = fieldTerms[1 + spot + i];
+                                if (!term.Field.Equals(field))
+                                {
+                                    Assert.IsNull(te.Next());
+                                    break;
+                                }
+                                else
+                                {
+                                    BytesRef t = te.Next();
+
+                                    if (VERBOSE)
+                                    {
+                                        Console.WriteLine("  got term=" + (t == null ? null : UnicodeUtil.ToHexString(t.Utf8ToString())));
+                                        Console.WriteLine("       exp=" + UnicodeUtil.ToHexString(term.Text().ToString()));
+                                    }
+
+                                    Assert.AreEqual(term.Bytes, t);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+#if !NETSTANDARD
+        // LUCENENET: There is no Timeout on NUnit for .NET Core.
+        [Timeout(300000)]
+#endif
+        [Test, HasTimeout]
+        public virtual void TestSurrogatesOrder()
+        {
+            Directory dir = NewDirectory();
+            RandomIndexWriter w = new RandomIndexWriter(Random(), dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))
+                .SetCodec(new PreFlexRWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE)));
+
+            int numField = TestUtil.NextInt(Random(), 2, 5);
+
+            int uniqueTermCount = 0;
+
+            int tc = 0;
+
+            var fieldTerms = new List<Term>();
+
+            for (int f = 0; f < numField; f++)
+            {
+                string field = "f" + f;
+                int numTerms = AtLeast(200);
+
+                ISet<string> uniqueTerms = new HashSet<string>();
+
+                for (int i = 0; i < numTerms; i++)
+                {
+                    string term = GetRandomString(Random()) + "_ " + (tc++);
+                    uniqueTerms.Add(term);
+                    fieldTerms.Add(new Term(field, term));
+                    Documents.Document doc = new Documents.Document();
+                    doc.Add(NewStringField(field, term, Field.Store.NO));
+                    w.AddDocument(doc);
+                }
+                uniqueTermCount += uniqueTerms.Count;
+            }
+
+            IndexReader reader = w.Reader;
+
+            if (VERBOSE)
+            {
+                fieldTerms.Sort(TermAsUTF16Comparer);
+
+                Console.WriteLine("\nTEST: UTF16 order");
+                foreach (Term t in fieldTerms)
+                {
+                    Console.WriteLine("  " + ToHexString(t));
+                }
+            }
+
+            // sorts in code point order:
+            fieldTerms.Sort();
+
+            if (VERBOSE)
+            {
+                Console.WriteLine("\nTEST: codepoint order");
+                foreach (Term t in fieldTerms)
+                {
+                    Console.WriteLine("  " + ToHexString(t));
+                }
+            }
+
+            Term[] fieldTermsArray = fieldTerms.ToArray();
+
+            //SegmentInfo si = makePreFlexSegment(r, "_0", dir, fieldInfos, codec, fieldTerms);
+
+            //FieldsProducer fields = codec.fieldsProducer(new SegmentReadState(dir, si, fieldInfos, 1024, 1));
+            //Assert.IsNotNull(fields);
+
+            DoTestStraightEnum(fieldTerms, reader, uniqueTermCount);
+            DoTestSeekExists(Random(), fieldTerms, reader);
+            DoTestSeekDoesNotExist(Random(), numField, fieldTerms, fieldTermsArray, reader);
+
+            reader.Dispose();
+            w.Dispose();
+            dir.Dispose();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/96822396/src/Lucene.Net.Tests/Codecs/Lucene3x/TestTermInfosReaderIndex.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Codecs/Lucene3x/TestTermInfosReaderIndex.cs b/src/Lucene.Net.Tests/Codecs/Lucene3x/TestTermInfosReaderIndex.cs
new file mode 100644
index 0000000..2d9dd05
--- /dev/null
+++ b/src/Lucene.Net.Tests/Codecs/Lucene3x/TestTermInfosReaderIndex.cs
@@ -0,0 +1,235 @@
+using System;
+using System.Collections.Generic;
+using Lucene.Net.Documents;
+
+namespace Lucene.Net.Codecs.Lucene3x
+{
+    using Lucene.Net.Support;
+    using NUnit.Framework;
+    using Directory = Lucene.Net.Store.Directory;
+    using DirectoryReader = Lucene.Net.Index.DirectoryReader;
+    using Document = Documents.Document;
+    using Field = Field;
+    using FieldInfos = Lucene.Net.Index.FieldInfos;
+    using Fields = Lucene.Net.Index.Fields;
+    using IndexFileNames = Lucene.Net.Index.IndexFileNames;
+    using IndexInput = Lucene.Net.Store.IndexInput;
+    using IndexReader = Lucene.Net.Index.IndexReader;
+    using IndexSearcher = Lucene.Net.Search.IndexSearcher;
+    using IndexWriterConfig = Lucene.Net.Index.IndexWriterConfig;
+    using IOContext = Lucene.Net.Store.IOContext;
+    using LogMergePolicy = Lucene.Net.Index.LogMergePolicy;
+    using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+
+    /*
+         * 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.
+         */
+
+    using MockAnalyzer = Lucene.Net.Analysis.MockAnalyzer;
+    using MockTokenizer = Lucene.Net.Analysis.MockTokenizer;
+    using MultiFields = Lucene.Net.Index.MultiFields;
+    using RandomIndexWriter = Lucene.Net.Index.RandomIndexWriter;
+    using SegmentReader = Lucene.Net.Index.SegmentReader;
+    using Term = Lucene.Net.Index.Term;
+    using TermQuery = Lucene.Net.Search.TermQuery;
+    using Terms = Lucene.Net.Index.Terms;
+    using TermsEnum = Lucene.Net.Index.TermsEnum;
+    using TestUtil = Lucene.Net.Util.TestUtil;
+    using TopDocs = Lucene.Net.Search.TopDocs;
+
+#pragma warning disable 612, 618
+    [TestFixture]
+    public class TestTermInfosReaderIndex : LuceneTestCase
+    {
+        private static int NUMBER_OF_DOCUMENTS;
+        private static int NUMBER_OF_FIELDS;
+        private static TermInfosReaderIndex Index;
+        private static Directory Directory;
+        private static SegmentTermEnum TermEnum;
+        private static int IndexDivisor;
+        private static int TermIndexInterval;
+        private static IndexReader Reader;
+        private static IList<Term> SampleTerms;
+
+        /// <summary>
+        /// we will manually instantiate preflex-rw here
+        /// 
+        /// LUCENENET specific
+        /// Is non-static because OLD_FORMAT_IMPERSONATION_IS_ACTIVE is no longer static.
+        /// </summary>
+        [OneTimeSetUp]
+        public void BeforeClass()
+        {
+            // NOTE: turn off compound file, this test will open some index files directly.
+            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
+            IndexWriterConfig config = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.KEYWORD, false)).SetUseCompoundFile(false);
+
+            TermIndexInterval = config.TermIndexInterval;
+            IndexDivisor = TestUtil.NextInt(Random(), 1, 10);
+            NUMBER_OF_DOCUMENTS = AtLeast(100);
+            NUMBER_OF_FIELDS = AtLeast(Math.Max(10, 3 * TermIndexInterval * IndexDivisor / NUMBER_OF_DOCUMENTS));
+
+            Directory = NewDirectory();
+
+            config.SetCodec(new PreFlexRWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE));
+            LogMergePolicy mp = NewLogMergePolicy();
+            // NOTE: turn off compound file, this test will open some index files directly.
+            mp.NoCFSRatio = 0.0;
+            config.SetMergePolicy(mp);
+
+            Populate(Directory, config);
+
+            DirectoryReader r0 = IndexReader.Open(Directory);
+            SegmentReader r = LuceneTestCase.GetOnlySegmentReader(r0);
+            string segment = r.SegmentName;
+            r.Dispose();
+
+            FieldInfosReader infosReader = (new PreFlexRWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE)).FieldInfosFormat.FieldInfosReader;
+            FieldInfos fieldInfos = infosReader.Read(Directory, segment, "", IOContext.READ_ONCE);
+            string segmentFileName = IndexFileNames.SegmentFileName(segment, "", Lucene3xPostingsFormat.TERMS_INDEX_EXTENSION);
+            long tiiFileLength = Directory.FileLength(segmentFileName);
+            IndexInput input = Directory.OpenInput(segmentFileName, NewIOContext(Random()));
+            TermEnum = new SegmentTermEnum(Directory.OpenInput(IndexFileNames.SegmentFileName(segment, "", Lucene3xPostingsFormat.TERMS_EXTENSION), NewIOContext(Random())), fieldInfos, false);
+            int totalIndexInterval = TermEnum.indexInterval * IndexDivisor;
+
+            SegmentTermEnum indexEnum = new SegmentTermEnum(input, fieldInfos, true);
+            Index = new TermInfosReaderIndex(indexEnum, IndexDivisor, tiiFileLength, totalIndexInterval);
+            indexEnum.Dispose();
+            input.Dispose();
+
+            Reader = IndexReader.Open(Directory);
+            SampleTerms = Sample(Random(), Reader, 1000);
+        }
+
+        [OneTimeTearDown]
+        public static void AfterClass()
+        {
+            TermEnum.Dispose();
+            Reader.Dispose();
+            Directory.Dispose();
+            TermEnum = null;
+            Reader = null;
+            Directory = null;
+            Index = null;
+            SampleTerms = null;
+        }
+
+        [Test]
+        public virtual void TestSeekEnum()
+        {
+            int indexPosition = 3;
+            SegmentTermEnum clone = (SegmentTermEnum)TermEnum.Clone();
+            Term term = FindTermThatWouldBeAtIndex(clone, indexPosition);
+            SegmentTermEnum enumerator = clone;
+            Index.SeekEnum(enumerator, indexPosition);
+            Assert.AreEqual(term, enumerator.Term());
+            clone.Dispose();
+        }
+
+        [Test]
+        public virtual void TestCompareTo()
+        {
+            Term term = new Term("field" + Random().Next(NUMBER_OF_FIELDS), Text);
+            for (int i = 0; i < Index.Length; i++)
+            {
+                Term t = Index.GetTerm(i);
+                int compareTo = term.CompareTo(t);
+                Assert.AreEqual(compareTo, Index.CompareTo(term, i));
+            }
+        }
+
+        [Test]
+        public virtual void TestRandomSearchPerformance()
+        {
+            IndexSearcher searcher = new IndexSearcher(Reader);
+            foreach (Term t in SampleTerms)
+            {
+                TermQuery query = new TermQuery(t);
+                TopDocs topDocs = searcher.Search(query, 10);
+                Assert.IsTrue(topDocs.TotalHits > 0);
+            }
+        }
+
+        private static IList<Term> Sample(Random random, IndexReader reader, int size)
+        {
+            IList<Term> sample = new List<Term>();
+            Fields fields = MultiFields.GetFields(reader);
+            foreach (string field in fields)
+            {
+                Terms terms = fields.GetTerms(field);
+                Assert.IsNotNull(terms);
+                TermsEnum termsEnum = terms.GetIterator(null);
+                while (termsEnum.Next() != null)
+                {
+                    if (sample.Count >= size)
+                    {
+                        int pos = random.Next(size);
+                        sample[pos] = new Term(field, termsEnum.Term);
+                    }
+                    else
+                    {
+                        sample.Add(new Term(field, termsEnum.Term));
+                    }
+                }
+            }
+            Collections.Shuffle(sample);
+            return sample;
+        }
+
+        private Term FindTermThatWouldBeAtIndex(SegmentTermEnum termEnum, int index)
+        {
+            int termPosition = index * TermIndexInterval * IndexDivisor;
+            for (int i = 0; i < termPosition; i++)
+            {
+                // TODO: this test just uses random terms, so this is always possible
+                AssumeTrue("ran out of terms", termEnum.Next());
+            }
+            Term term = termEnum.Term();
+            // An indexed term is only written when the term after
+            // it exists, so, if the number of terms is 0 mod
+            // termIndexInterval, the last index term will not be
+            // written; so we require a term after this term
+            // as well:
+            AssumeTrue("ran out of terms", termEnum.Next());
+            return term;
+        }
+
+        private void Populate(Directory directory, IndexWriterConfig config)
+        {
+            RandomIndexWriter writer = new RandomIndexWriter(Random(), directory, config);
+            for (int i = 0; i < NUMBER_OF_DOCUMENTS; i++)
+            {
+                Document document = new Document();
+                for (int f = 0; f < NUMBER_OF_FIELDS; f++)
+                {
+                    document.Add(NewStringField("field" + f, Text, Field.Store.NO));
+                }
+                writer.AddDocument(document);
+            }
+            writer.ForceMerge(1);
+            writer.Dispose();
+        }
+
+        private static string Text
+        {
+            get
+            {
+                return Convert.ToString(Random().Next());
+            }
+        }
+    }
+#pragma warning restore 612, 618
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/96822396/src/Lucene.Net.Tests/Codecs/Lucene40/TestBitVector.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Codecs/Lucene40/TestBitVector.cs b/src/Lucene.Net.Tests/Codecs/Lucene40/TestBitVector.cs
new file mode 100644
index 0000000..3103129
--- /dev/null
+++ b/src/Lucene.Net.Tests/Codecs/Lucene40/TestBitVector.cs
@@ -0,0 +1,325 @@
+namespace Lucene.Net.Codecs.Lucene40
+{
+    using NUnit.Framework;
+
+    /*
+         * 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.
+         */
+
+    using Directory = Lucene.Net.Store.Directory;
+    using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+    using MockDirectoryWrapper = Lucene.Net.Store.MockDirectoryWrapper;
+    using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+    using TestUtil = Lucene.Net.Util.TestUtil;
+
+    /// <summary>
+    /// <code>TestBitVector</code> tests the <code>BitVector</code>, obviously.
+    /// </summary>
+    [TestFixture]
+    public class TestBitVector : LuceneTestCase
+    {
+        /// <summary>
+        /// Test the default constructor on BitVectors of various sizes.
+        /// </summary>
+        [Test]
+        public virtual void TestConstructSize()
+        {
+            DoTestConstructOfSize(8);
+            DoTestConstructOfSize(20);
+            DoTestConstructOfSize(100);
+            DoTestConstructOfSize(1000);
+        }
+
+        private void DoTestConstructOfSize(int n)
+        {
+            BitVector bv = new BitVector(n);
+            Assert.AreEqual(n, bv.Length); // LUCENENET NOTE: Length is the equivalent of size()
+        }
+
+        /// <summary>
+        /// Test the get() and set() methods on BitVectors of various sizes.
+        /// </summary>
+        [Test]
+        public virtual void TestGetSet()
+        {
+            DoTestGetSetVectorOfSize(8);
+            DoTestGetSetVectorOfSize(20);
+            DoTestGetSetVectorOfSize(100);
+            DoTestGetSetVectorOfSize(1000);
+        }
+
+        private void DoTestGetSetVectorOfSize(int n)
+        {
+            BitVector bv = new BitVector(n);
+            for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size()
+            {
+                // ensure a set bit can be git'
+                Assert.IsFalse(bv.Get(i));
+                bv.Set(i);
+                Assert.IsTrue(bv.Get(i));
+            }
+        }
+
+        /// <summary>
+        /// Test the clear() method on BitVectors of various sizes.
+        /// </summary>
+        [Test]
+        public virtual void TestClear()
+        {
+            DoTestClearVectorOfSize(8);
+            DoTestClearVectorOfSize(20);
+            DoTestClearVectorOfSize(100);
+            DoTestClearVectorOfSize(1000);
+        }
+
+        private void DoTestClearVectorOfSize(int n)
+        {
+            BitVector bv = new BitVector(n);
+            for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size()
+            {
+                // ensure a set bit is cleared
+                Assert.IsFalse(bv.Get(i));
+                bv.Set(i);
+                Assert.IsTrue(bv.Get(i));
+                bv.Clear(i);
+                Assert.IsFalse(bv.Get(i));
+            }
+        }
+
+        /// <summary>
+        /// Test the count() method on BitVectors of various sizes.
+        /// </summary>
+        [Test]
+        public virtual void TestCount()
+        {
+            DoTestCountVectorOfSize(8);
+            DoTestCountVectorOfSize(20);
+            DoTestCountVectorOfSize(100);
+            DoTestCountVectorOfSize(1000);
+        }
+
+        private void DoTestCountVectorOfSize(int n)
+        {
+            BitVector bv = new BitVector(n);
+            // test count when incrementally setting bits
+            for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size()
+            {
+                Assert.IsFalse(bv.Get(i));
+                Assert.AreEqual(i, bv.Count());
+                bv.Set(i);
+                Assert.IsTrue(bv.Get(i));
+                Assert.AreEqual(i + 1, bv.Count());
+            }
+
+            bv = new BitVector(n);
+            // test count when setting then clearing bits
+            for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size()
+            {
+                Assert.IsFalse(bv.Get(i));
+                Assert.AreEqual(0, bv.Count());
+                bv.Set(i);
+                Assert.IsTrue(bv.Get(i));
+                Assert.AreEqual(1, bv.Count());
+                bv.Clear(i);
+                Assert.IsFalse(bv.Get(i));
+                Assert.AreEqual(0, bv.Count());
+            }
+        }
+
+        /// <summary>
+        /// Test writing and construction to/from Directory.
+        /// </summary>
+        [Test]
+        public virtual void TestWriteRead()
+        {
+            DoTestWriteRead(8);
+            DoTestWriteRead(20);
+            DoTestWriteRead(100);
+            DoTestWriteRead(1000);
+        }
+
+        private void DoTestWriteRead(int n)
+        {
+            MockDirectoryWrapper d = new MockDirectoryWrapper(Random(), new RAMDirectory());
+            d.PreventDoubleWrite = false;
+            BitVector bv = new BitVector(n);
+            // test count when incrementally setting bits
+            for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size()
+            {
+                Assert.IsFalse(bv.Get(i));
+                Assert.AreEqual(i, bv.Count());
+                bv.Set(i);
+                Assert.IsTrue(bv.Get(i));
+                Assert.AreEqual(i + 1, bv.Count());
+                bv.Write(d, "TESTBV", NewIOContext(Random()));
+                BitVector compare = new BitVector(d, "TESTBV", NewIOContext(Random()));
+                // compare bit vectors with bits set incrementally
+                Assert.IsTrue(DoCompare(bv, compare));
+            }
+        }
+
+        /// <summary>
+        /// Test r/w when size/count cause switching between bit-set and d-gaps file formats.
+        /// </summary>
+        [Test]
+        public virtual void TestDgaps()
+        {
+            DoTestDgaps(1, 0, 1);
+            DoTestDgaps(10, 0, 1);
+            DoTestDgaps(100, 0, 1);
+            DoTestDgaps(1000, 4, 7);
+            DoTestDgaps(10000, 40, 43);
+            DoTestDgaps(100000, 415, 418);
+            DoTestDgaps(1000000, 3123, 3126);
+            // now exercise skipping of fully populated byte in the bitset (they are omitted if bitset is sparse)
+            MockDirectoryWrapper d = new MockDirectoryWrapper(Random(), new RAMDirectory());
+            d.PreventDoubleWrite = false;
+            BitVector bv = new BitVector(10000);
+            bv.Set(0);
+            for (int i = 8; i < 16; i++)
+            {
+                bv.Set(i);
+            } // make sure we have once byte full of set bits
+            for (int i = 32; i < 40; i++)
+            {
+                bv.Set(i);
+            } // get a second byte full of set bits
+            // add some more bits here
+            for (int i = 40; i < 10000; i++)
+            {
+                if (Random().Next(1000) == 0)
+                {
+                    bv.Set(i);
+                }
+            }
+            bv.Write(d, "TESTBV", NewIOContext(Random()));
+            BitVector compare = new BitVector(d, "TESTBV", NewIOContext(Random()));
+            Assert.IsTrue(DoCompare(bv, compare));
+        }
+
+        private void DoTestDgaps(int size, int count1, int count2)
+        {
+            MockDirectoryWrapper d = new MockDirectoryWrapper(Random(), new RAMDirectory());
+            d.PreventDoubleWrite = false;
+            BitVector bv = new BitVector(size);
+            bv.InvertAll();
+            for (int i = 0; i < count1; i++)
+            {
+                bv.Clear(i);
+                Assert.AreEqual(i + 1, size - bv.Count());
+            }
+            bv.Write(d, "TESTBV", NewIOContext(Random()));
+            // gradually increase number of set bits
+            for (int i = count1; i < count2; i++)
+            {
+                BitVector bv2 = new BitVector(d, "TESTBV", NewIOContext(Random()));
+                Assert.IsTrue(DoCompare(bv, bv2));
+                bv = bv2;
+                bv.Clear(i);
+                Assert.AreEqual(i + 1, size - bv.Count());
+                bv.Write(d, "TESTBV", NewIOContext(Random()));
+            }
+            // now start decreasing number of set bits
+            for (int i = count2 - 1; i >= count1; i--)
+            {
+                BitVector bv2 = new BitVector(d, "TESTBV", NewIOContext(Random()));
+                Assert.IsTrue(DoCompare(bv, bv2));
+                bv = bv2;
+                bv.Set(i);
+                Assert.AreEqual(i, size - bv.Count());
+                bv.Write(d, "TESTBV", NewIOContext(Random()));
+            }
+        }
+
+        [Test]
+        public virtual void TestSparseWrite()
+        {
+            Directory d = NewDirectory();
+            const int numBits = 10240;
+            BitVector bv = new BitVector(numBits);
+            bv.InvertAll();
+            int numToClear = Random().Next(5);
+            for (int i = 0; i < numToClear; i++)
+            {
+                bv.Clear(Random().Next(numBits));
+            }
+            bv.Write(d, "test", NewIOContext(Random()));
+            long size = d.FileLength("test");
+            Assert.IsTrue(size < 100, "size=" + size);
+            d.Dispose();
+        }
+
+        [Test]
+        public virtual void TestClearedBitNearEnd()
+        {
+            Directory d = NewDirectory();
+            int numBits = TestUtil.NextInt(Random(), 7, 1000);
+            BitVector bv = new BitVector(numBits);
+            bv.InvertAll();
+            bv.Clear(numBits - TestUtil.NextInt(Random(), 1, 7));
+            bv.Write(d, "test", NewIOContext(Random()));
+            Assert.AreEqual(numBits - 1, bv.Count());
+            d.Dispose();
+        }
+
+        [Test]
+        public virtual void TestMostlySet()
+        {
+            Directory d = NewDirectory();
+            int numBits = TestUtil.NextInt(Random(), 30, 1000);
+            for (int numClear = 0; numClear < 20; numClear++)
+            {
+                BitVector bv = new BitVector(numBits);
+                bv.InvertAll();
+                int count = 0;
+                while (count < numClear)
+                {
+                    int bit = Random().Next(numBits);
+                    // Don't use getAndClear, so that count is recomputed
+                    if (bv.Get(bit))
+                    {
+                        bv.Clear(bit);
+                        count++;
+                        Assert.AreEqual(numBits - count, bv.Count());
+                    }
+                }
+            }
+
+            d.Dispose();
+        }
+
+        /// <summary>
+        /// Compare two BitVectors.
+        /// this should really be an equals method on the BitVector itself. </summary>
+        /// <param name="bv"> One bit vector </param>
+        /// <param name="compare"> The second to compare </param>
+        private bool DoCompare(BitVector bv, BitVector compare)
+        {
+            bool equal = true;
+            for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size()
+            {
+                // bits must be equal
+                if (bv.Get(i) != compare.Get(i))
+                {
+                    equal = false;
+                    break;
+                }
+            }
+            Assert.AreEqual(bv.Count(), compare.Count());
+            return equal;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/96822396/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40DocValuesFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40DocValuesFormat.cs b/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40DocValuesFormat.cs
new file mode 100644
index 0000000..d63a6b3
--- /dev/null
+++ b/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40DocValuesFormat.cs
@@ -0,0 +1,555 @@
+namespace Lucene.Net.Codecs.Lucene40
+{
+    using NUnit.Framework;
+
+    /*
+         * 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.
+         */
+
+    using BaseDocValuesFormatTestCase = Lucene.Net.Index.BaseDocValuesFormatTestCase;
+
+    /// <summary>
+    /// Tests Lucene40DocValuesFormat
+    /// </summary>
+    public class TestLucene40DocValuesFormat : BaseDocValuesFormatTestCase
+    {
+        /// <summary>
+        /// LUCENENET specific
+        /// Is non-static because OLD_FORMAT_IMPERSONATION_IS_ACTIVE is no longer static.
+        /// </summary>
+        [OneTimeSetUp]
+        public void BeforeClass()
+        {
+            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; // explicitly instantiates ancient codec
+        }
+
+        protected override Codec Codec
+        {
+            get
+            {
+                Assert.True(OLD_FORMAT_IMPERSONATION_IS_ACTIVE, "Expecting that this is true");
+                return new Lucene40RWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE);
+            }
+        }
+
+        // LUCENE-4583: this codec should throw IAE on huge binary values:
+        protected internal override bool CodecAcceptsHugeBinaryValues(string field)
+        {
+            return false;
+        }
+
+
+        #region BaseDocValuesFormatTestCase
+        // LUCENENET NOTE: Tests in an abstract base class are not pulled into the correct
+        // context in Visual Studio. This fixes that with the minimum amount of code necessary
+        // to run them in the correct context without duplicating all of the tests.
+
+        [Test]
+        public override void TestOneNumber()
+        {
+            base.TestOneNumber();
+        }
+
+        [Test]
+        public override void TestOneFloat()
+        {
+            base.TestOneFloat();
+        }
+
+        [Test]
+        public override void TestTwoNumbers()
+        {
+            base.TestTwoNumbers();
+        }
+
+        [Test]
+        public override void TestTwoBinaryValues()
+        {
+            base.TestTwoBinaryValues();
+        }
+
+        [Test]
+        public override void TestTwoFieldsMixed()
+        {
+            base.TestTwoFieldsMixed();
+        }
+
+        [Test]
+        public override void TestThreeFieldsMixed()
+        {
+            base.TestThreeFieldsMixed();
+        }
+
+        [Test]
+        public override void TestThreeFieldsMixed2()
+        {
+            base.TestThreeFieldsMixed2();
+        }
+
+        [Test]
+        public override void TestTwoDocumentsNumeric()
+        {
+            base.TestTwoDocumentsNumeric();
+        }
+
+        [Test]
+        public override void TestTwoDocumentsMerged()
+        {
+            base.TestTwoDocumentsMerged();
+        }
+
+        [Test]
+        public override void TestBigNumericRange()
+        {
+            base.TestBigNumericRange();
+        }
+
+        [Test]
+        public override void TestBigNumericRange2()
+        {
+            base.TestBigNumericRange2();
+        }
+
+        [Test]
+        public override void TestBytes()
+        {
+            base.TestBytes();
+        }
+
+        [Test]
+        public override void TestBytesTwoDocumentsMerged()
+        {
+            base.TestBytesTwoDocumentsMerged();
+        }
+
+        [Test]
+        public override void TestSortedBytes()
+        {
+            base.TestSortedBytes();
+        }
+
+        [Test]
+        public override void TestSortedBytesTwoDocuments()
+        {
+            base.TestSortedBytesTwoDocuments();
+        }
+
+        [Test]
+        public override void TestSortedBytesThreeDocuments()
+        {
+            base.TestSortedBytesThreeDocuments();
+        }
+
+        [Test]
+        public override void TestSortedBytesTwoDocumentsMerged()
+        {
+            base.TestSortedBytesTwoDocumentsMerged();
+        }
+
+        [Test]
+        public override void TestSortedMergeAwayAllValues()
+        {
+            base.TestSortedMergeAwayAllValues();
+        }
+
+        [Test]
+        public override void TestBytesWithNewline()
+        {
+            base.TestBytesWithNewline();
+        }
+
+        [Test]
+        public override void TestMissingSortedBytes()
+        {
+            base.TestMissingSortedBytes();
+        }
+
+        [Test]
+        public override void TestSortedTermsEnum()
+        {
+            base.TestSortedTermsEnum();
+        }
+
+        [Test]
+        public override void TestEmptySortedBytes()
+        {
+            base.TestEmptySortedBytes();
+        }
+
+        [Test]
+        public override void TestEmptyBytes()
+        {
+            base.TestEmptyBytes();
+        }
+
+        [Test]
+        public override void TestVeryLargeButLegalBytes()
+        {
+            base.TestVeryLargeButLegalBytes();
+        }
+
+        [Test]
+        public override void TestVeryLargeButLegalSortedBytes()
+        {
+            base.TestVeryLargeButLegalSortedBytes();
+        }
+
+        [Test]
+        public override void TestCodecUsesOwnBytes()
+        {
+            base.TestCodecUsesOwnBytes();
+        }
+
+        [Test]
+        public override void TestCodecUsesOwnSortedBytes()
+        {
+            base.TestCodecUsesOwnSortedBytes();
+        }
+
+        [Test]
+        public override void TestCodecUsesOwnBytesEachTime()
+        {
+            base.TestCodecUsesOwnBytesEachTime();
+        }
+
+        [Test]
+        public override void TestCodecUsesOwnSortedBytesEachTime()
+        {
+            base.TestCodecUsesOwnSortedBytesEachTime();
+        }
+
+        /*
+         * Simple test case to show how to use the API
+         */
+        [Test]
+        public override void TestDocValuesSimple()
+        {
+            base.TestDocValuesSimple();
+        }
+
+        [Test]
+        public override void TestRandomSortedBytes()
+        {
+            base.TestRandomSortedBytes();
+        }
+
+        [Test]
+        public override void TestBooleanNumericsVsStoredFields()
+        {
+            base.TestBooleanNumericsVsStoredFields();
+        }
+
+        [Test]
+        public override void TestByteNumericsVsStoredFields()
+        {
+            base.TestByteNumericsVsStoredFields();
+        }
+
+        [Test]
+        public override void TestByteMissingVsFieldCache()
+        {
+            base.TestByteMissingVsFieldCache();
+        }
+
+        [Test]
+        public override void TestShortNumericsVsStoredFields()
+        {
+            base.TestShortNumericsVsStoredFields();
+        }
+
+        [Test]
+        public override void TestShortMissingVsFieldCache()
+        {
+            base.TestShortMissingVsFieldCache();
+        }
+
+        [Test]
+        public override void TestIntNumericsVsStoredFields()
+        {
+            base.TestIntNumericsVsStoredFields();
+        }
+
+        [Test]
+        public override void TestIntMissingVsFieldCache()
+        {
+            base.TestIntMissingVsFieldCache();
+        }
+
+        [Test]
+        public override void TestLongNumericsVsStoredFields()
+        {
+            base.TestLongNumericsVsStoredFields();
+        }
+
+        [Test]
+        public override void TestLongMissingVsFieldCache()
+        {
+            base.TestLongMissingVsFieldCache();
+        }
+
+        [Test]
+        public override void TestBinaryFixedLengthVsStoredFields()
+        {
+            base.TestBinaryFixedLengthVsStoredFields();
+        }
+
+        [Test]
+        public override void TestBinaryVariableLengthVsStoredFields()
+        {
+            base.TestBinaryVariableLengthVsStoredFields();
+        }
+
+        [Test]
+        public override void TestSortedFixedLengthVsStoredFields()
+        {
+            base.TestSortedFixedLengthVsStoredFields();
+        }
+
+        [Test]
+        public override void TestSortedFixedLengthVsFieldCache()
+        {
+            base.TestSortedFixedLengthVsFieldCache();
+        }
+
+        [Test]
+        public override void TestSortedVariableLengthVsFieldCache()
+        {
+            base.TestSortedVariableLengthVsFieldCache();
+        }
+
+        [Test]
+        public override void TestSortedVariableLengthVsStoredFields()
+        {
+            base.TestSortedVariableLengthVsStoredFields();
+        }
+
+        [Test]
+        public override void TestSortedSetOneValue()
+        {
+            base.TestSortedSetOneValue();
+        }
+
+        [Test]
+        public override void TestSortedSetTwoFields()
+        {
+            base.TestSortedSetTwoFields();
+        }
+
+        [Test]
+        public override void TestSortedSetTwoDocumentsMerged()
+        {
+            base.TestSortedSetTwoDocumentsMerged();
+        }
+
+        [Test]
+        public override void TestSortedSetTwoValues()
+        {
+            base.TestSortedSetTwoValues();
+        }
+
+        [Test]
+        public override void TestSortedSetTwoValuesUnordered()
+        {
+            base.TestSortedSetTwoValuesUnordered();
+        }
+
+        [Test]
+        public override void TestSortedSetThreeValuesTwoDocs()
+        {
+            base.TestSortedSetThreeValuesTwoDocs();
+        }
+
+        [Test]
+        public override void TestSortedSetTwoDocumentsLastMissing()
+        {
+            base.TestSortedSetTwoDocumentsLastMissing();
+        }
+
+        [Test]
+        public override void TestSortedSetTwoDocumentsLastMissingMerge()
+        {
+            base.TestSortedSetTwoDocumentsLastMissingMerge();
+        }
+
+        [Test]
+        public override void TestSortedSetTwoDocumentsFirstMissing()
+        {
+            base.TestSortedSetTwoDocumentsFirstMissing();
+        }
+
+        [Test]
+        public override void TestSortedSetTwoDocumentsFirstMissingMerge()
+        {
+            base.TestSortedSetTwoDocumentsFirstMissingMerge();
+        }
+
+        [Test]
+        public override void TestSortedSetMergeAwayAllValues()
+        {
+            base.TestSortedSetMergeAwayAllValues();
+        }
+
+        [Test]
+        public override void TestSortedSetTermsEnum()
+        {
+            base.TestSortedSetTermsEnum();
+        }
+
+        [Test]
+        public override void TestSortedSetFixedLengthVsStoredFields()
+        {
+            base.TestSortedSetFixedLengthVsStoredFields();
+        }
+
+        [Test]
+        public override void TestSortedSetVariableLengthVsStoredFields()
+        {
+            base.TestSortedSetVariableLengthVsStoredFields();
+        }
+
+        [Test]
+        public override void TestSortedSetFixedLengthSingleValuedVsStoredFields()
+        {
+            base.TestSortedSetFixedLengthSingleValuedVsStoredFields();
+        }
+
+        [Test]
+        public override void TestSortedSetVariableLengthSingleValuedVsStoredFields()
+        {
+            base.TestSortedSetVariableLengthSingleValuedVsStoredFields();
+        }
+
+        [Test]
+        public override void TestSortedSetFixedLengthVsUninvertedField()
+        {
+            base.TestSortedSetFixedLengthVsUninvertedField();
+        }
+
+        [Test]
+        public override void TestSortedSetVariableLengthVsUninvertedField()
+        {
+            base.TestSortedSetVariableLengthVsUninvertedField();
+        }
+
+        [Test]
+        public override void TestGCDCompression()
+        {
+            base.TestGCDCompression();
+        }
+
+        [Test]
+        public override void TestZeros()
+        {
+            base.TestZeros();
+        }
+
+        [Test]
+        public override void TestZeroOrMin()
+        {
+            base.TestZeroOrMin();
+        }
+
+        [Test]
+        public override void TestTwoNumbersOneMissing()
+        {
+            base.TestTwoNumbersOneMissing();
+        }
+
+        [Test]
+        public override void TestTwoNumbersOneMissingWithMerging()
+        {
+            base.TestTwoNumbersOneMissingWithMerging();
+        }
+
+        [Test]
+        public override void TestThreeNumbersOneMissingWithMerging()
+        {
+            base.TestThreeNumbersOneMissingWithMerging();
+        }
+
+        [Test]
+        public override void TestTwoBytesOneMissing()
+        {
+            base.TestTwoBytesOneMissing();
+        }
+
+        [Test]
+        public override void TestTwoBytesOneMissingWithMerging()
+        {
+            base.TestTwoBytesOneMissingWithMerging();
+        }
+
+        [Test]
+        public override void TestThreeBytesOneMissingWithMerging()
+        {
+            base.TestThreeBytesOneMissingWithMerging();
+        }
+
+        // LUCENE-4853
+        [Test]
+        public override void TestHugeBinaryValues()
+        {
+            base.TestHugeBinaryValues();
+        }
+
+        // TODO: get this out of here and into the deprecated codecs (4.0, 4.2)
+        [Test]
+        public override void TestHugeBinaryValueLimit()
+        {
+            base.TestHugeBinaryValueLimit();
+        }
+
+        /// <summary>
+        /// Tests dv against stored fields with threads (binary/numeric/sorted, no missing)
+        /// </summary>
+        [Test]
+        public override void TestThreads()
+        {
+            base.TestThreads();
+        }
+
+        /// <summary>
+        /// Tests dv against stored fields with threads (all types + missing)
+        /// </summary>
+        [Test]
+        public override void TestThreads2()
+        {
+            base.TestThreads2();
+        }
+
+        // LUCENE-5218
+        [Test]
+        public override void TestEmptyBinaryValueOnPageSizes()
+        {
+            base.TestEmptyBinaryValueOnPageSizes();
+        }
+
+        #endregion
+
+        #region BaseIndexFileFormatTestCase
+        // LUCENENET NOTE: Tests in an abstract base class are not pulled into the correct
+        // context in Visual Studio. This fixes that with the minimum amount of code necessary
+        // to run them in the correct context without duplicating all of the tests.
+
+        [Test]
+        public override void TestMergeStability()
+        {
+            base.TestMergeStability();
+        }
+
+        #endregion
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/96822396/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40PostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40PostingsFormat.cs b/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40PostingsFormat.cs
new file mode 100644
index 0000000..2d2b5f1
--- /dev/null
+++ b/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40PostingsFormat.cs
@@ -0,0 +1,111 @@
+namespace Lucene.Net.Codecs.Lucene40
+{
+    using NUnit.Framework;
+
+    /*
+         * 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.
+         */
+
+    using BasePostingsFormatTestCase = Lucene.Net.Index.BasePostingsFormatTestCase;
+
+    /// <summary>
+    /// Tests Lucene40PostingsFormat
+    /// </summary>
+    public class TestLucene40PostingsFormat : BasePostingsFormatTestCase
+    {
+        /// <summary>
+        /// LUCENENET specific
+        /// Is non-static because OLD_FORMAT_IMPERSONATION_IS_ACTIVE is no longer static.
+        /// </summary>
+        [OneTimeSetUp]
+        public void BeforeClass()
+        {
+            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; // explicitly instantiates ancient codec
+        }
+
+        protected override Codec Codec
+        {
+            get
+            {
+                Assert.True(OLD_FORMAT_IMPERSONATION_IS_ACTIVE, "Expecting this to be set already before creating codec");
+                return new Lucene40RWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE);
+            }
+        }
+
+
+        #region BasePostingsFormatTestCase
+        // LUCENENET NOTE: Tests in an abstract base class are not pulled into the correct
+        // context in Visual Studio. This fixes that with the minimum amount of code necessary
+        // to run them in the correct context without duplicating all of the tests.
+
+        [Test]
+        public override void TestDocsOnly()
+        {
+            base.TestDocsOnly();
+        }
+
+        [Test]
+        public override void TestDocsAndFreqs()
+        {
+            base.TestDocsAndFreqs();
+        }
+
+        [Test]
+        public override void TestDocsAndFreqsAndPositions()
+        {
+            base.TestDocsAndFreqsAndPositions();
+        }
+
+        [Test]
+        public override void TestDocsAndFreqsAndPositionsAndPayloads()
+        {
+            base.TestDocsAndFreqsAndPositionsAndPayloads();
+        }
+
+        [Test]
+        public override void TestDocsAndFreqsAndPositionsAndOffsets()
+        {
+            base.TestDocsAndFreqsAndPositionsAndOffsets();
+        }
+
+        [Test]
+        public override void TestDocsAndFreqsAndPositionsAndOffsetsAndPayloads()
+        {
+            base.TestDocsAndFreqsAndPositionsAndOffsetsAndPayloads();
+        }
+
+        [Test]
+        public override void TestRandom()
+        {
+            base.TestRandom();
+        }
+
+        #endregion
+
+        #region BaseIndexFileFormatTestCase
+        // LUCENENET NOTE: Tests in an abstract base class are not pulled into the correct
+        // context in Visual Studio. This fixes that with the minimum amount of code necessary
+        // to run them in the correct context without duplicating all of the tests.
+
+        [Test]
+        public override void TestMergeStability()
+        {
+            base.TestMergeStability();
+        }
+
+        #endregion
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/96822396/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40PostingsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40PostingsReader.cs b/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40PostingsReader.cs
new file mode 100644
index 0000000..aea5ce0
--- /dev/null
+++ b/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40PostingsReader.cs
@@ -0,0 +1,166 @@
+using Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Support;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Lucene.Net.Codecs.Lucene40
+{
+    using Lucene.Net.Randomized.Generators;
+    using NUnit.Framework;
+    using Directory = Lucene.Net.Store.Directory;
+    using Document = Documents.Document;
+    using Field = Field;
+    using FieldType = FieldType;
+    using IndexWriterConfig = Lucene.Net.Index.IndexWriterConfig;
+    using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+
+    /*
+         * 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.
+         */
+
+    using MockAnalyzer = Lucene.Net.Analysis.MockAnalyzer;
+    using RandomIndexWriter = Lucene.Net.Index.RandomIndexWriter;
+    using StringField = StringField;
+    using Term = Lucene.Net.Index.Term;
+    using TestUtil = Lucene.Net.Util.TestUtil;
+    using TextField = TextField;
+
+    [TestFixture]
+    public class TestLucene40PostingsReader : LuceneTestCase
+    {
+        internal static readonly string[] Terms = new string[100];
+
+        static TestLucene40PostingsReader()
+        {
+            for (int i = 0; i < Terms.Length; i++)
+            {
+                Terms[i] = Convert.ToString(i + 1);
+            }
+        }
+
+        /// <summary>
+        /// LUCENENET specific
+        /// Is non-static because OLD_FORMAT_IMPERSONATION_IS_ACTIVE is no longer static.
+        /// </summary>
+        [OneTimeSetUp]
+        public void BeforeClass()
+        {
+            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; // explicitly instantiates ancient codec
+        }
+
+        /// <summary>
+        /// tests terms with different probabilities of being in the document.
+        ///  depends heavily on term vectors cross-check at checkIndex
+        /// </summary>
+        [Test]
+        public virtual void TestPostings()
+        {
+            Directory dir = NewFSDirectory(CreateTempDir("postings"));
+            IndexWriterConfig iwc = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
+            iwc.SetCodec(Codec.ForName("Lucene40"));
+            RandomIndexWriter iw = new RandomIndexWriter(Random(), dir, iwc);
+
+            Document doc = new Document();
+
+            // id field
+            FieldType idType = new FieldType(StringField.TYPE_NOT_STORED);
+            idType.StoreTermVectors = true;
+            Field idField = new Field("id", "", idType);
+            doc.Add(idField);
+
+            // title field: short text field
+            FieldType titleType = new FieldType(TextField.TYPE_NOT_STORED);
+            titleType.StoreTermVectors = true;
+            titleType.StoreTermVectorPositions = true;
+            titleType.StoreTermVectorOffsets = true;
+            titleType.IndexOptions = IndexOptions();
+            Field titleField = new Field("title", "", titleType);
+            doc.Add(titleField);
+
+            // body field: long text field
+            FieldType bodyType = new FieldType(TextField.TYPE_NOT_STORED);
+            bodyType.StoreTermVectors = true;
+            bodyType.StoreTermVectorPositions = true;
+            bodyType.StoreTermVectorOffsets = true;
+            bodyType.IndexOptions = IndexOptions();
+            Field bodyField = new Field("body", "", bodyType);
+            doc.Add(bodyField);
+
+            int numDocs = AtLeast(1000);
+            for (int i = 0; i < numDocs; i++)
+            {
+                idField.SetStringValue(Convert.ToString(i));
+                titleField.SetStringValue(FieldValue(1));
+                bodyField.SetStringValue(FieldValue(3));
+                iw.AddDocument(doc);
+                if (Random().Next(20) == 0)
+                {
+                    iw.DeleteDocuments(new Term("id", Convert.ToString(i)));
+                }
+            }
+            if (Random().NextBoolean())
+            {
+                // delete 1-100% of docs
+                iw.DeleteDocuments(new Term("title", Terms[Random().Next(Terms.Length)]));
+            }
+            iw.Dispose();
+            dir.Dispose(); // checkindex
+        }
+
+        internal virtual IndexOptions IndexOptions()
+        {
+            switch (Random().Next(4))
+            {
+                case 0:
+                    return Index.IndexOptions.DOCS_ONLY;
+
+                case 1:
+                    return Index.IndexOptions.DOCS_AND_FREQS;
+
+                case 2:
+                    return Index.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
+
+                default:
+                    return Index.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
+            }
+        }
+
+        internal virtual string FieldValue(int maxTF)
+        {
+            IList<string> shuffled = new List<string>();
+            StringBuilder sb = new StringBuilder();
+            int i = Random().Next(Terms.Length);
+            while (i < Terms.Length)
+            {
+                int tf = TestUtil.NextInt(Random(), 1, maxTF);
+                for (int j = 0; j < tf; j++)
+                {
+                    shuffled.Add(Terms[i]);
+                }
+                i++;
+            }
+            Collections.Shuffle(shuffled);
+            foreach (string term in shuffled)
+            {
+                sb.Append(term);
+                sb.Append(' ');
+            }
+            return sb.ToString();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/96822396/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40StoredFieldsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40StoredFieldsFormat.cs b/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40StoredFieldsFormat.cs
new file mode 100644
index 0000000..c78b1b4
--- /dev/null
+++ b/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40StoredFieldsFormat.cs
@@ -0,0 +1,147 @@
+namespace Lucene.Net.Codecs.Lucene40
+{
+    using Attributes;
+    using NUnit.Framework;
+
+    /*
+         * 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.
+         */
+
+    using BaseStoredFieldsFormatTestCase = Lucene.Net.Index.BaseStoredFieldsFormatTestCase;
+
+    public class TestLucene40StoredFieldsFormat : BaseStoredFieldsFormatTestCase
+    {
+        /// <summary>
+        /// LUCENENET specific
+        /// Is non-static because OLD_FORMAT_IMPERSONATION_IS_ACTIVE is no longer static.
+        /// </summary>
+        [OneTimeSetUp]
+        public void BeforeClass()
+        {
+            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; // explicitly instantiates ancient codec
+        }
+
+        protected override Codec Codec
+        {
+            get
+            {
+                Assert.True(OLD_FORMAT_IMPERSONATION_IS_ACTIVE, "Expecting this to be set already");
+                return new Lucene40RWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE);
+            }
+        }
+
+
+        #region BaseStoredFieldsFormatTestCase
+        // LUCENENET NOTE: Tests in an abstract base class are not pulled into the correct
+        // context in Visual Studio. This fixes that with the minimum amount of code necessary
+        // to run them in the correct context without duplicating all of the tests.
+
+        [Test]
+        public override void TestRandomStoredFields()
+        {
+            base.TestRandomStoredFields();
+        }
+
+        [Test]
+        // LUCENE-1727: make sure doc fields are stored in order
+        public override void TestStoredFieldsOrder()
+        {
+            base.TestStoredFieldsOrder();
+        }
+
+        [Test]
+        // LUCENE-1219
+        public override void TestBinaryFieldOffsetLength()
+        {
+            base.TestBinaryFieldOffsetLength();
+        }
+
+        [Test]
+        public override void TestNumericField()
+        {
+            base.TestNumericField();
+        }
+
+        [Test]
+        public override void TestIndexedBit()
+        {
+            base.TestIndexedBit();
+        }
+
+        [Test]
+        public override void TestReadSkip()
+        {
+            base.TestReadSkip();
+        }
+
+#if !NETSTANDARD
+        // LUCENENET: There is no Timeout on NUnit for .NET Core.
+        [Timeout(300000)]
+#endif
+        [Test, HasTimeout]
+        public override void TestEmptyDocs()
+        {
+            base.TestEmptyDocs();
+        }
+
+#if !NETSTANDARD
+        // LUCENENET: There is no Timeout on NUnit for .NET Core.
+        [Timeout(300000)]
+#endif
+        [Test, HasTimeout]
+        public override void TestConcurrentReads()
+        {
+            base.TestConcurrentReads();
+        }
+
+        [Test]
+        public override void TestWriteReadMerge()
+        {
+            base.TestWriteReadMerge();
+        }
+
+#if !NETSTANDARD
+        // LUCENENET: There is no Timeout on NUnit for .NET Core.
+        [Timeout(80000)]
+#endif
+        [Test, HasTimeout]
+        public override void TestBigDocuments()
+        {
+            base.TestBigDocuments();
+        }
+
+        [Test]
+        public override void TestBulkMergeWithDeletes()
+        {
+            base.TestBulkMergeWithDeletes();
+        }
+
+        #endregion
+
+        #region BaseIndexFileFormatTestCase
+        // LUCENENET NOTE: Tests in an abstract base class are not pulled into the correct
+        // context in Visual Studio. This fixes that with the minimum amount of code necessary
+        // to run them in the correct context without duplicating all of the tests.
+
+        [Test]
+        public override void TestMergeStability()
+        {
+            base.TestMergeStability();
+        }
+
+        #endregion
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/96822396/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40TermVectorsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40TermVectorsFormat.cs b/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40TermVectorsFormat.cs
new file mode 100644
index 0000000..d7541eb
--- /dev/null
+++ b/src/Lucene.Net.Tests/Codecs/Lucene40/TestLucene40TermVectorsFormat.cs
@@ -0,0 +1,117 @@
+namespace Lucene.Net.Codecs.Lucene40
+{
+    using Attributes;
+    using NUnit.Framework;
+
+    /*
+         * 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.
+         */
+
+    using BaseTermVectorsFormatTestCase = Lucene.Net.Index.BaseTermVectorsFormatTestCase;
+
+    public class TestLucene40TermVectorsFormat : BaseTermVectorsFormatTestCase
+    {
+        /// <summary>
+        /// LUCENENET specific
+        /// Is non-static because OLD_FORMAT_IMPERSONATION_IS_ACTIVE is no longer static.
+        /// </summary>
+        [OneTimeSetUp]
+        public void BeforeClass()
+        {
+            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true; // explicitly instantiates ancient codec
+        }
+
+        protected override Codec Codec
+        {
+            get
+            {
+                Assert.True(OLD_FORMAT_IMPERSONATION_IS_ACTIVE, "Expecting this to be set already");
+                return new Lucene40RWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE);
+            }
+        }
+
+
+        #region BaseTermVectorsFormatTestCase
+        // LUCENENET NOTE: Tests in an abstract base class are not pulled into the correct
+        // context in Visual Studio. This fixes that with the minimum amount of code necessary
+        // to run them in the correct context without duplicating all of the tests.
+
+        [Test]
+        // only one doc with vectors
+        public override void TestRareVectors()
+        {
+            base.TestRareVectors();
+        }
+
+        [Test]
+        public override void TestHighFreqs()
+        {
+            base.TestHighFreqs();
+        }
+
+        [Test]
+        public override void TestLotsOfFields()
+        {
+            base.TestLotsOfFields();
+        }
+
+#if !NETSTANDARD
+        // LUCENENET: There is no Timeout on NUnit for .NET Core.
+        [Timeout(300000)]
+#endif
+        [Test, HasTimeout]
+        // different options for the same field
+        public override void TestMixedOptions()
+        {
+            base.TestMixedOptions();
+        }
+
+        [Test]
+        public override void TestRandom()
+        {
+            base.TestRandom();
+        }
+
+        [Test]
+        public override void TestMerge()
+        {
+            base.TestMerge();
+        }
+
+        [Test]
+        // run random tests from different threads to make sure the per-thread clones
+        // don't share mutable data
+        public override void TestClone()
+        {
+            base.TestClone();
+        }
+
+        #endregion
+
+        #region BaseIndexFileFormatTestCase
+        // LUCENENET NOTE: Tests in an abstract base class are not pulled into the correct
+        // context in Visual Studio. This fixes that with the minimum amount of code necessary
+        // to run them in the correct context without duplicating all of the tests.
+
+        [Test]
+        public override void TestMergeStability()
+        {
+            base.TestMergeStability();
+        }
+
+        #endregion
+    }
+}
\ No newline at end of file