Repository: lucenenet Updated Branches: refs/heads/master c99735650 -> 3f7e6cfe4
Lucene.Net.Tests.Analysis.Phonetic: Added TestApiConsistency and TestExceptionSerialization tests Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/3f7e6cfe Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/3f7e6cfe Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/3f7e6cfe Branch: refs/heads/master Commit: 3f7e6cfe4d929e0bdccea74c2c1cd348607129ab Parents: c997356 Author: Shad Storhaug <[email protected]> Authored: Wed Jun 28 15:18:29 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Wed Jun 28 15:18:29 2017 +0700 ---------------------------------------------------------------------- .../Language/Bm/Lang.cs | 6 +- .../Language/ColognePhonetic.cs | 36 ++--- .../Lucene.Net.Tests.Analysis.Phonetic.csproj | 2 + .../Support/TestApiConsistency.cs | 148 +++++++++++++++++++ .../Support/TestExceptionSerialization.cs | 54 +++++++ 5 files changed, 225 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/3f7e6cfe/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Lang.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Lang.cs b/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Lang.cs index 5889e8f..98119f8 100644 --- a/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Lang.cs +++ b/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Lang.cs @@ -108,7 +108,7 @@ namespace Lucene.Net.Analysis.Phonetic.Language.Bm } } - private static readonly IDictionary<NameType, Lang> Langs = new Dictionary<NameType, Lang>(); + private static readonly IDictionary<NameType, Lang> langs = new Dictionary<NameType, Lang>(); private static readonly string LANGUAGE_RULES_RN = "lang.txt"; @@ -116,7 +116,7 @@ namespace Lucene.Net.Analysis.Phonetic.Language.Bm { foreach (NameType s in Enum.GetValues(typeof(NameType))) { - Langs[s] = LoadFromResource(LANGUAGE_RULES_RN, Languages.GetInstance(s)); + langs[s] = LoadFromResource(LANGUAGE_RULES_RN, Languages.GetInstance(s)); } } @@ -128,7 +128,7 @@ namespace Lucene.Net.Analysis.Phonetic.Language.Bm public static Lang GetInstance(NameType nameType) { Lang result; - Langs.TryGetValue(nameType, out result); + langs.TryGetValue(nameType, out result); return result; } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/3f7e6cfe/src/Lucene.Net.Analysis.Phonetic/Language/ColognePhonetic.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Analysis.Phonetic/Language/ColognePhonetic.cs b/src/Lucene.Net.Analysis.Phonetic/Language/ColognePhonetic.cs index a4824b3..944267d 100644 --- a/src/Lucene.Net.Analysis.Phonetic/Language/ColognePhonetic.cs +++ b/src/Lucene.Net.Analysis.Phonetic/Language/ColognePhonetic.cs @@ -181,39 +181,39 @@ namespace Lucene.Net.Analysis.Phonetic.Language private static readonly char[] TDX = new char[] { 'T', 'D', 'X' }; /// <summary> - /// This class is not thread-safe; the field <see cref="length"/> is mutable. + /// This class is not thread-safe; the field <see cref="m_length"/> is mutable. /// However, it is not shared between threads, as it is constructed on demand /// by the method <see cref="ColognePhonetic.GetColognePhonetic(string)"/>. /// </summary> private abstract class CologneBuffer { - protected readonly char[] data; + protected readonly char[] m_data; - protected int length = 0; + protected int m_length = 0; public CologneBuffer(char[] data) { - this.data = data; - this.length = data.Length; + this.m_data = data; + this.m_length = data.Length; } public CologneBuffer(int buffSize) { - this.data = new char[buffSize]; - this.length = 0; + this.m_data = new char[buffSize]; + this.m_length = 0; } protected abstract char[] CopyData(int start, int length); public virtual int Length { - get { return length; } + get { return m_length; } } public override string ToString() { - return new string(CopyData(0, length)); + return new string(CopyData(0, m_length)); } } @@ -226,14 +226,14 @@ namespace Lucene.Net.Analysis.Phonetic.Language public void AddRight(char chr) { - data[length] = chr; - length++; + m_data[m_length] = chr; + m_length++; } protected override char[] CopyData(int start, int length) { char[] newData = new char[length]; - System.Array.Copy(data, start, newData, 0, length); + System.Array.Copy(m_data, start, newData, 0, length); return newData; } } @@ -247,31 +247,31 @@ namespace Lucene.Net.Analysis.Phonetic.Language public virtual void AddLeft(char ch) { - length++; - data[GetNextPos()] = ch; + m_length++; + m_data[GetNextPos()] = ch; } protected override char[] CopyData(int start, int length) { char[] newData = new char[length]; - System.Array.Copy(data, data.Length - this.length + start, newData, 0, length); + System.Array.Copy(m_data, m_data.Length - this.m_length + start, newData, 0, length); return newData; } public virtual char GetNextChar() { - return data[GetNextPos()]; + return m_data[GetNextPos()]; } protected virtual int GetNextPos() { - return data.Length - length; + return m_data.Length - m_length; } public virtual char RemoveNext() { char ch = GetNextChar(); - length--; + m_length--; return ch; } } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/3f7e6cfe/src/Lucene.Net.Tests.Analysis.Phonetic/Lucene.Net.Tests.Analysis.Phonetic.csproj ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests.Analysis.Phonetic/Lucene.Net.Tests.Analysis.Phonetic.csproj b/src/Lucene.Net.Tests.Analysis.Phonetic/Lucene.Net.Tests.Analysis.Phonetic.csproj index 5c38e1f..7fbb806 100644 --- a/src/Lucene.Net.Tests.Analysis.Phonetic/Lucene.Net.Tests.Analysis.Phonetic.csproj +++ b/src/Lucene.Net.Tests.Analysis.Phonetic/Lucene.Net.Tests.Analysis.Phonetic.csproj @@ -64,6 +64,8 @@ <Compile Include="Language\SoundexTest.cs" /> <Compile Include="Language\StringEncoderAbstractTest.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Support\TestApiConsistency.cs" /> + <Compile Include="Support\TestExceptionSerialization.cs" /> <Compile Include="TestBeiderMorseFilter.cs" /> <Compile Include="TestBeiderMorseFilterFactory.cs" /> <Compile Include="TestDoubleMetaphoneFilterFactory.cs" /> http://git-wip-us.apache.org/repos/asf/lucenenet/blob/3f7e6cfe/src/Lucene.Net.Tests.Analysis.Phonetic/Support/TestApiConsistency.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests.Analysis.Phonetic/Support/TestApiConsistency.cs b/src/Lucene.Net.Tests.Analysis.Phonetic/Support/TestApiConsistency.cs new file mode 100644 index 0000000..37e0f6b --- /dev/null +++ b/src/Lucene.Net.Tests.Analysis.Phonetic/Support/TestApiConsistency.cs @@ -0,0 +1,148 @@ +/* + * + * 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.Attributes; +using Lucene.Net.Support; +using NUnit.Framework; +using System; + +namespace Lucene.Net.Analysis.Phonetic +{ + /// <summary> + /// LUCENENET specific tests for ensuring API conventions are followed + /// </summary> + public class TestApiConsistency : ApiScanTestBase + { + [Test, LuceneNetSpecific] + [TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + public override void TestProtectedFieldNames(Type typeFromTargetAssembly) + { + base.TestProtectedFieldNames(typeFromTargetAssembly); + } + + [Test, LuceneNetSpecific] + [TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + public override void TestPrivateFieldNames(Type typeFromTargetAssembly) + { + base.TestPrivateFieldNames(typeFromTargetAssembly); + } + + [Test, LuceneNetSpecific] + [TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + public override void TestPublicFields(Type typeFromTargetAssembly) + { + base.TestPublicFields(typeFromTargetAssembly); + } + + [Test, LuceneNetSpecific] + [TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + public override void TestMethodParameterNames(Type typeFromTargetAssembly) + { + base.TestMethodParameterNames(typeFromTargetAssembly); + } + + [Test, LuceneNetSpecific] + [TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + public override void TestInterfaceNames(Type typeFromTargetAssembly) + { + base.TestInterfaceNames(typeFromTargetAssembly); + } + + [Test, LuceneNetSpecific] + [TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + public override void TestClassNames(Type typeFromTargetAssembly) + { + base.TestClassNames(typeFromTargetAssembly); + } + + [Test, LuceneNetSpecific] + [TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + public override void TestForPropertiesWithNoGetter(Type typeFromTargetAssembly) + { + base.TestForPropertiesWithNoGetter(typeFromTargetAssembly); + } + + [Test, LuceneNetSpecific] + [TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + public override void TestForPropertiesThatReturnArray(Type typeFromTargetAssembly) + { + base.TestForPropertiesThatReturnArray(typeFromTargetAssembly); + } + + [Test, LuceneNetSpecific] + [TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + public override void TestForMethodsThatReturnWritableArray(Type typeFromTargetAssembly) + { + base.TestForMethodsThatReturnWritableArray(typeFromTargetAssembly); + } + + [Test, LuceneNetSpecific] + [TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + public override void TestForPublicMembersContainingComparer(Type typeFromTargetAssembly) + { + base.TestForPublicMembersContainingComparer(typeFromTargetAssembly); + } + + [Test, LuceneNetSpecific] + [TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + public override void TestForPublicMembersNamedSize(Type typeFromTargetAssembly) + { + base.TestForPublicMembersNamedSize(typeFromTargetAssembly); + } + + [Test, LuceneNetSpecific] + [TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + public override void TestForPublicMembersContainingNonNetNumeric(Type typeFromTargetAssembly) + { + base.TestForPublicMembersContainingNonNetNumeric(typeFromTargetAssembly); + } + + [Test, LuceneNetSpecific] + [TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + public override void TestForTypesContainingNonNetNumeric(Type typeFromTargetAssembly) + { + base.TestForTypesContainingNonNetNumeric(typeFromTargetAssembly); + } + + [Test, LuceneNetSpecific] + [TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + public override void TestForPublicMembersWithNullableEnum(Type typeFromTargetAssembly) + { + base.TestForPublicMembersWithNullableEnum(typeFromTargetAssembly); + } + + // LUCENENET NOTE: This test is only for identifying members who were changed from + // ICollection, IList or ISet to IEnumerable during the port (that should be changed back) + //[Test, LuceneNetSpecific] + //[TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + //public override void TestForMembersAcceptingOrReturningIEnumerable(Type typeFromTargetAssembly) + //{ + // base.TestForMembersAcceptingOrReturningIEnumerable(typeFromTargetAssembly); + //} + + [Test, LuceneNetSpecific] + [TestCase(typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter))] + public override void TestForMembersAcceptingOrReturningListOrDictionary(Type typeFromTargetAssembly) + { + base.TestForMembersAcceptingOrReturningListOrDictionary(typeFromTargetAssembly); + } + } +} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/3f7e6cfe/src/Lucene.Net.Tests.Analysis.Phonetic/Support/TestExceptionSerialization.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests.Analysis.Phonetic/Support/TestExceptionSerialization.cs b/src/Lucene.Net.Tests.Analysis.Phonetic/Support/TestExceptionSerialization.cs new file mode 100644 index 0000000..ac85e1a --- /dev/null +++ b/src/Lucene.Net.Tests.Analysis.Phonetic/Support/TestExceptionSerialization.cs @@ -0,0 +1,54 @@ +#if FEATURE_SERIALIZABLE +using Lucene.Net.Attributes; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Lucene.Net.Support +{ + /* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + [TestFixture] + public class TestExceptionSerialization : ExceptionSerializationTestBase + { + public static IEnumerable<object> ExceptionTestData + { + get + { + var exceptionTypes = typeof(Lucene.Net.Analysis.Phonetic.BeiderMorseFilter).Assembly.GetTypes().Where(t => typeof(Exception).IsAssignableFrom(t)).Cast<object>(); + + // If the assembly has no exceptions, just provide Exception so the test will pass + if (!exceptionTypes.Any()) + { + return new Type[] { typeof(Exception) }; + } + + return exceptionTypes; + } + } + + [Test, LuceneNetSpecific] + public void AllExceptionsInLuceneNamespaceCanSerialize([ValueSource("ExceptionTestData")]Type luceneException) + { + var instance = TryInstantiate(luceneException); + Assert.That(TypeCanSerialize(instance), string.Format("Unable to serialize {0}", luceneException.FullName)); + } + } +} +#endif \ No newline at end of file
