Author: digy Date: Mon Dec 21 13:42:45 2009 New Revision: 892820 URL: http://svn.apache.org/viewvc?rev=892820&view=rev Log: LUCENENET-329 Support for junit.framework.TestCase.getName() Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestFieldScoreQuery.cs incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestOrdValues.cs incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanMinShouldMatch.cs incubator/lucene.net/trunk/C#/src/Test/Search/TestSort.cs incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs incubator/lucene.net/trunk/C#/src/Test/Util/LocalizedTestCase.cs incubator/lucene.net/trunk/C#/src/Test/Util/LuceneTestCase.cs Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestFieldScoreQuery.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Function/TestFieldScoreQuery.cs?rev=892820&r1=892819&r2=892820&view=diff ============================================================================== --- incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestFieldScoreQuery.cs (original) +++ incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestFieldScoreQuery.cs Mon Dec 21 13:42:45 2009 @@ -264,7 +264,7 @@ private System.String TestName() { - return GetType().Name + "." + "getName()"; // {{Aroush-2.9}} String junit.framework.TestCase.getName() + return Lucene.Net.TestCase.GetFullName(); } } } \ No newline at end of file Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestOrdValues.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Function/TestOrdValues.cs?rev=892820&r1=892819&r2=892820&view=diff ============================================================================== --- incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestOrdValues.cs (original) +++ incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestOrdValues.cs Mon Dec 21 13:42:45 2009 @@ -287,7 +287,7 @@ private System.String TestName() { - return GetType().Name + "." + "getName()"; // {{Aroush-2.9}} String junit.framework.TestCase.getName() + return Lucene.Net.TestCase.GetFullName(); } } } \ No newline at end of file Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanMinShouldMatch.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestBooleanMinShouldMatch.cs?rev=892820&r1=892819&r2=892820&view=diff ============================================================================== --- incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanMinShouldMatch.cs (original) +++ incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanMinShouldMatch.cs Mon Dec 21 13:42:45 2009 @@ -112,7 +112,7 @@ ScoreDoc[] h = s.Search(q, null, 1000).scoreDocs; if (expected != h.Length) { - PrintHits("getName()", h, s); // {{Aroush-2.9}} String junit.framework.TestCase.getName() + PrintHits(Lucene.Net.TestCase.GetName(), h, s); } Assert.AreEqual(expected, h.Length, "result count"); QueryUtils.Check(q, s); Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestSort.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestSort.cs?rev=892820&r1=892819&r2=892820&view=diff ============================================================================== --- incubator/lucene.net/trunk/C#/src/Test/Search/TestSort.cs (original) +++ incubator/lucene.net/trunk/C#/src/Test/Search/TestSort.cs Mon Dec 21 13:42:45 2009 @@ -549,32 +549,32 @@ sort.SetSort(new SortField[]{new SortField("parser", new AnonymousClassIntParser(this)), SortField.FIELD_DOC}); AssertMatches(full, queryA, sort, "JIHGFEDCBA"); - AssertSaneFieldCaches("getName()" + " IntParser"); // {{Aroush-2.9}} String junit.framework.TestCase.getName() + AssertSaneFieldCaches(Lucene.Net.TestCase.GetName() + " IntParser"); fc.PurgeAllCaches(); sort.SetSort(new SortField[]{new SortField("parser", new AnonymousClassFloatParser(this)), SortField.FIELD_DOC}); AssertMatches(full, queryA, sort, "JIHGFEDCBA"); - AssertSaneFieldCaches("getName()" + " FloatParser"); // {{Aroush-2.9}} String junit.framework.TestCase.getName() + AssertSaneFieldCaches(Lucene.Net.TestCase.GetName() + " FloatParser"); fc.PurgeAllCaches(); sort.SetSort(new SortField[]{new SortField("parser", new AnonymousClassLongParser(this)), SortField.FIELD_DOC}); AssertMatches(full, queryA, sort, "JIHGFEDCBA"); - AssertSaneFieldCaches("getName()" + " LongParser"); // {{Aroush-2.9}} String junit.framework.TestCase.getName() + AssertSaneFieldCaches(Lucene.Net.TestCase.GetName() + " LongParser"); fc.PurgeAllCaches(); sort.SetSort(new SortField[]{new SortField("parser", new AnonymousClassDoubleParser(this)), SortField.FIELD_DOC}); AssertMatches(full, queryA, sort, "JIHGFEDCBA"); - AssertSaneFieldCaches("getName()" + " DoubleParser"); // {{Aroush-2.9}} String junit.framework.TestCase.getName() + AssertSaneFieldCaches(Lucene.Net.TestCase.GetName() + " DoubleParser"); fc.PurgeAllCaches(); sort.SetSort(new SortField[]{new SortField("parser", new AnonymousClassByteParser(this)), SortField.FIELD_DOC}); AssertMatches(full, queryA, sort, "JIHGFEDCBA"); - AssertSaneFieldCaches("getName()" + " ByteParser"); // {{Aroush-2.9}} String junit.framework.TestCase.getName() + AssertSaneFieldCaches(Lucene.Net.TestCase.GetName() + " ByteParser"); fc.PurgeAllCaches(); sort.SetSort(new SortField[]{new SortField("parser", new AnonymousClassShortParser(this)), SortField.FIELD_DOC}); AssertMatches(full, queryA, sort, "JIHGFEDCBA"); - AssertSaneFieldCaches("getName()" + " ShortParser"); // {{Aroush-2.9}} String junit.framework.TestCase.getName() + AssertSaneFieldCaches(Lucene.Net.TestCase.GetName() + " ShortParser"); fc.PurgeAllCaches(); } @@ -1205,7 +1205,7 @@ // up to this point, all of the searches should have "sane" // FieldCache behavior, and should have reused hte cache in several cases - AssertSaneFieldCaches("getName()" + " various"); // {{Aroush-2.9}} String junit.framework.TestCase.getName() + AssertSaneFieldCaches(Lucene.Net.TestCase.GetName() + " various"); // next we'll check Locale based (String[]) for 'string', so purge first Lucene.Net.Search.FieldCache_Fields.DEFAULT.PurgeAllCaches(); @@ -1217,8 +1217,8 @@ sort.SetSort(new SortField[]{new SortField("string", new System.Globalization.CultureInfo("en-GB"))}); AssertMatches(multi, queryA, sort, "DJAIHGFEBC"); - - AssertSaneFieldCaches("getName()" + " Locale.US + Locale.UK"); // {{Aroush-2.9}} String junit.framework.TestCase.getName() + + AssertSaneFieldCaches(Lucene.Net.TestCase.GetName() + " Locale.US + Locale.UK"); Lucene.Net.Search.FieldCache_Fields.DEFAULT.PurgeAllCaches(); } Modified: incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/TestSupportClass.cs?rev=892820&r1=892819&r2=892820&view=diff ============================================================================== --- incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs (original) +++ incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs Mon Dec 21 13:42:45 2009 @@ -934,7 +934,41 @@ } //------------------------------------------- + } + +} +namespace Lucene.Net +{ + /// + /// Support for junit.framework.TestCase.getName(). + /// {{Lucene.Net-2.9.1}} Move to another location after LUCENENET-266 + /// + public class TestCase + { + public static string GetName() + { + return GetTestCaseName(false); + } + + public static string GetFullName() + { + return GetTestCaseName(true); + } + + static string GetTestCaseName(bool fullName) + { + System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(); + for (int i = 0; i < stackTrace.FrameCount; i++) + { + System.Reflection.MethodBase method = stackTrace.GetFrame(i).GetMethod(); + object[] testAttrs = method.GetCustomAttributes(typeof(NUnit.Framework.TestAttribute), false); + if (testAttrs != null && testAttrs.Length > 0) + if (fullName) return method.DeclaringType.FullName + "." + method.Name; + else return method.Name; + } + return "GetTestCaseName[UnknownTestMethod]"; + } } } \ No newline at end of file Modified: incubator/lucene.net/trunk/C#/src/Test/Util/LocalizedTestCase.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Util/LocalizedTestCase.cs?rev=892820&r1=892819&r2=892820&view=diff ============================================================================== --- incubator/lucene.net/trunk/C#/src/Test/Util/LocalizedTestCase.cs (original) +++ incubator/lucene.net/trunk/C#/src/Test/Util/LocalizedTestCase.cs Mon Dec 21 13:42:45 2009 @@ -89,11 +89,11 @@ } catch (System.Exception e) { - System.Console.Out.WriteLine("Test failure of '" + "getName()" + "' occurred with the default Locale " + locale); // {{Aroush-2.9}} String junit.framework.TestCase.getName() + System.Console.Out.WriteLine("Test failure of '" + Lucene.Net.TestCase.GetName() + "' occurred with the default Locale " + locale); throw e; } - - if (testWithDifferentLocales == null || testWithDifferentLocales.Contains("getName()")) // {{Aroush-2.9}} String junit.framework.TestCase.getName() + + if (testWithDifferentLocales == null || testWithDifferentLocales.Contains(Lucene.Net.TestCase.GetName())) { // Do the test again under different Locales System.Globalization.CultureInfo[] systemLocales = System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.InstalledWin32Cultures); @@ -106,7 +106,7 @@ } catch (System.Exception e) { - System.Console.Out.WriteLine("Test failure of '" + "getName()" + "' occurred under a different Locale " + locale); // {{Aroush-2.9}} String junit.framework.TestCase.getName() + System.Console.Out.WriteLine("Test failure of '" + Lucene.Net.TestCase.GetName() + "' occurred under a different Locale " + locale); // {{Aroush-2.9}} String junit.framework.TestCase.getName() throw e; } } Modified: incubator/lucene.net/trunk/C#/src/Test/Util/LuceneTestCase.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Util/LuceneTestCase.cs?rev=892820&r1=892819&r2=892820&view=diff ============================================================================== --- incubator/lucene.net/trunk/C#/src/Test/Util/LuceneTestCase.cs (original) +++ incubator/lucene.net/trunk/C#/src/Test/Util/LuceneTestCase.cs Mon Dec 21 13:42:45 2009 @@ -92,7 +92,7 @@ protected internal virtual System.String GetTestLabel() { - return GetType().Name + "." + "getName()"; // {{Aroush-2.9}} String junit.framework.TestCase.getName() + return Lucene.Net.TestCase.GetFullName(); } [TearDown]