Return-Path: X-Original-To: apmail-lucene-lucene-net-commits-archive@www.apache.org Delivered-To: apmail-lucene-lucene-net-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D75C9CEB5 for ; Fri, 22 Jun 2012 21:50:10 +0000 (UTC) Received: (qmail 89297 invoked by uid 500); 22 Jun 2012 21:50:10 -0000 Delivered-To: apmail-lucene-lucene-net-commits-archive@lucene.apache.org Received: (qmail 89233 invoked by uid 500); 22 Jun 2012 21:50:10 -0000 Mailing-List: contact lucene-net-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@lucene.apache.org Delivered-To: mailing list lucene-net-commits@lucene.apache.org Received: (qmail 89225 invoked by uid 99); 22 Jun 2012 21:50:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jun 2012 21:50:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jun 2012 21:50:06 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 359E923889D5; Fri, 22 Jun 2012 21:49:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1353041 - in /incubator/lucene.net/trunk: src/core/Document/ test/core/Document/ test/core/QueryParser/ test/core/Search/Function/ test/core/Util/ Date: Fri, 22 Jun 2012 21:49:43 -0000 To: lucene-net-commits@lucene.apache.org From: ccurrens@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120622214944.359E923889D5@eris.apache.org> Author: ccurrens Date: Fri Jun 22 21:49:41 2012 New Revision: 1353041 URL: http://svn.apache.org/viewvc?rev=1353041&view=rev Log: [LUCENENET-493] - Fixed issues with TestDateTools failing under arabic cultures. Added a test to the LocalizedTestCase base class, that will call all or some of the test methods under all installed cultures Modified: incubator/lucene.net/trunk/src/core/Document/DateTools.cs incubator/lucene.net/trunk/test/core/Document/TestDateTools.cs incubator/lucene.net/trunk/test/core/QueryParser/TestQueryParser.cs incubator/lucene.net/trunk/test/core/Search/Function/TestCustomScoreQuery.cs incubator/lucene.net/trunk/test/core/Util/LocalizedTestCase.cs incubator/lucene.net/trunk/test/core/Util/LuceneTestCase.cs Modified: incubator/lucene.net/trunk/src/core/Document/DateTools.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Document/DateTools.cs?rev=1353041&r1=1353040&r2=1353041&view=diff ============================================================================== --- incubator/lucene.net/trunk/src/core/Document/DateTools.cs (original) +++ incubator/lucene.net/trunk/src/core/Document/DateTools.cs Fri Jun 22 21:49:41 2012 @@ -95,31 +95,31 @@ namespace Lucene.Net.Documents if (resolution == Resolution.YEAR) { - return date.ToString(YEAR_FORMAT); + return date.ToString(YEAR_FORMAT, System.Globalization.CultureInfo.InvariantCulture); } else if (resolution == Resolution.MONTH) { - return date.ToString(MONTH_FORMAT); + return date.ToString(MONTH_FORMAT, System.Globalization.CultureInfo.InvariantCulture); } else if (resolution == Resolution.DAY) { - return date.ToString(DAY_FORMAT); + return date.ToString(DAY_FORMAT, System.Globalization.CultureInfo.InvariantCulture); } else if (resolution == Resolution.HOUR) { - return date.ToString(HOUR_FORMAT); + return date.ToString(HOUR_FORMAT, System.Globalization.CultureInfo.InvariantCulture); } else if (resolution == Resolution.MINUTE) { - return date.ToString(MINUTE_FORMAT); + return date.ToString(MINUTE_FORMAT, System.Globalization.CultureInfo.InvariantCulture); } else if (resolution == Resolution.SECOND) { - return date.ToString(SECOND_FORMAT); + return date.ToString(SECOND_FORMAT, System.Globalization.CultureInfo.InvariantCulture); } else if (resolution == Resolution.MILLISECOND) { - return date.ToString(MILLISECOND_FORMAT); + return date.ToString(MILLISECOND_FORMAT, System.Globalization.CultureInfo.InvariantCulture); } throw new System.ArgumentException("unknown resolution " + resolution); Modified: incubator/lucene.net/trunk/test/core/Document/TestDateTools.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Document/TestDateTools.cs?rev=1353041&r1=1353040&r2=1353041&view=diff ============================================================================== --- incubator/lucene.net/trunk/test/core/Document/TestDateTools.cs (original) +++ incubator/lucene.net/trunk/test/core/Document/TestDateTools.cs Fri Jun 22 21:49:41 2012 @@ -28,7 +28,6 @@ namespace Lucene.Net.Documents [TestFixture] public class TestDateTools:LocalizedTestCase { - [Test] public virtual void TestStringToDate() { @@ -172,7 +171,7 @@ namespace Lucene.Net.Documents private System.String IsoFormat(System.DateTime date) { - return date.ToString("yyyy-MM-dd HH:mm:ss:fff"); + return date.ToString("yyyy-MM-dd HH:mm:ss:fff", System.Globalization.CultureInfo.InvariantCulture); } [Test] Modified: incubator/lucene.net/trunk/test/core/QueryParser/TestQueryParser.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/QueryParser/TestQueryParser.cs?rev=1353041&r1=1353040&r2=1353041&view=diff ============================================================================== --- incubator/lucene.net/trunk/test/core/QueryParser/TestQueryParser.cs (original) +++ incubator/lucene.net/trunk/test/core/QueryParser/TestQueryParser.cs Fri Jun 22 21:49:41 2012 @@ -63,15 +63,15 @@ namespace Lucene.Net.QueryParsers [TestFixture] public class TestQueryParser:LocalizedTestCase { - static System.Collections.Hashtable dataTestWithDifferentLocals = new System.Collections.Hashtable(); - static TestQueryParser() - { - System.String[] data = new System.String[] {"TestLegacyDateRange", "TestDateRange", "TestCJK", "TestNumber", "TestFarsiRangeCollating", "TestLocalDateFormat"}; - for (int i = 0; i < data.Length; i++) - { - dataTestWithDifferentLocals.Add(data[i], data[i]); - } - } + private static readonly HashSet dataTestWithDifferentLocals = new HashSet + { + "TestLegacyDateRange", + "TestDateRange", + "TestCJK", + "TestNumber", + "TestFarsiRangeCollating", + "TestLocalDateFormat" + }; private class AnonymousClassQueryParser : QueryParser { Modified: incubator/lucene.net/trunk/test/core/Search/Function/TestCustomScoreQuery.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Search/Function/TestCustomScoreQuery.cs?rev=1353041&r1=1353040&r2=1353041&view=diff ============================================================================== --- incubator/lucene.net/trunk/test/core/Search/Function/TestCustomScoreQuery.cs (original) +++ incubator/lucene.net/trunk/test/core/Search/Function/TestCustomScoreQuery.cs Fri Jun 22 21:49:41 2012 @@ -104,12 +104,8 @@ namespace Lucene.Net.Search.Function class AnonymousCustomScoreProvider : CustomScoreProvider { - IndexReader reader; - public AnonymousCustomScoreProvider(IndexReader reader) : base(reader) - { - this.reader = reader; - } + { } public override float CustomScore(int doc, float subQueryScore, float valSrcScore) { @@ -151,12 +147,8 @@ namespace Lucene.Net.Search.Function class AnonymousCustomScoreProvider : CustomScoreProvider { - IndexReader reader; - public AnonymousCustomScoreProvider(IndexReader reader) : base(reader) - { - this.reader = reader; - } + { } public override float CustomScore(int doc, float subQueryScore, float[] valSrcScores) { @@ -205,12 +197,10 @@ namespace Lucene.Net.Search.Function class AnonymousCustomScoreProvider : CustomScoreProvider { - IndexReader reader; int[] values = null; public AnonymousCustomScoreProvider(IndexReader reader, int[] values) : base(reader) { - this.reader = reader; this.values = values; } Modified: incubator/lucene.net/trunk/test/core/Util/LocalizedTestCase.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Util/LocalizedTestCase.cs?rev=1353041&r1=1353040&r2=1353041&view=diff ============================================================================== --- incubator/lucene.net/trunk/test/core/Util/LocalizedTestCase.cs (original) +++ incubator/lucene.net/trunk/test/core/Util/LocalizedTestCase.cs Fri Jun 22 21:49:41 2012 @@ -16,100 +16,117 @@ */ using System; - +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Reflection; using NUnit.Framework; namespace Lucene.Net.Util { - - /// Base test class for Lucene test classes that test Locale-sensitive behavior. - ///

- /// This class will run tests under the default Locale, but then will also run - /// tests under all available JVM locales. This is helpful to ensure tests will - /// not fail under a different environment. - ///

- public class LocalizedTestCase:LuceneTestCase - { - /// Before changing the default Locale, save the default Locale here so that it - /// can be restored. - /// - private System.Globalization.CultureInfo defaultLocale = System.Threading.Thread.CurrentThread.CurrentCulture; - - /// The locale being used as the system default Locale - private System.Globalization.CultureInfo locale = System.Globalization.CultureInfo.CurrentCulture; - - /// An optional limited set of testcases that will run under different Locales. - private System.Collections.Hashtable testWithDifferentLocales; - - public LocalizedTestCase():base() - { - testWithDifferentLocales = null; - } - - public LocalizedTestCase(System.String name):base(name) - { - testWithDifferentLocales = null; - } - - public LocalizedTestCase(System.Collections.Hashtable testWithDifferentLocales):base() - { - this.testWithDifferentLocales = testWithDifferentLocales; - } - - public LocalizedTestCase(System.String name, System.Collections.Hashtable testWithDifferentLocales):base(name) - { - this.testWithDifferentLocales = testWithDifferentLocales; - } - - // @Override - [SetUp] - public override void SetUp() - { - base.SetUp(); - System.Threading.Thread.CurrentThread.CurrentCulture = locale; - } - - // @Override - [TearDown] - public override void TearDown() - { - System.Threading.Thread.CurrentThread.CurrentCulture = defaultLocale; - base.TearDown(); - } - - // @Override - public override void RunBare() - { - // Do the test with the default Locale (default) - try - { - locale = defaultLocale; - base.RunBare(); - } - catch (System.Exception e) - { - System.Console.Out.WriteLine("Test failure of '" + Lucene.Net.TestCase.GetName() + "' occurred with the default Locale " + locale); - throw e; - } - - 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); - for (int i = 0; i < systemLocales.Length; i++) - { - try - { - locale = systemLocales[i]; - base.RunBare(); - } - catch (System.Exception e) - { - 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; - } - } - } - } - } + + /// Base test class for Lucene test classes that test Locale-sensitive behavior. + ///

+ /// This class will run tests under the default Locale, but then will also run + /// tests under all available JVM locales. This is helpful to ensure tests will + /// not fail under a different environment. + ///

+ public class LocalizedTestCase : LuceneTestCase + { + /// An optional limited set of testcases that will run under different Locales. + private readonly HashSet testWithDifferentLocales; + + public LocalizedTestCase() + { + testWithDifferentLocales = null; + } + + public LocalizedTestCase(System.String name) + : base(name) + { + testWithDifferentLocales = null; + } + + public LocalizedTestCase(HashSet testWithDifferentLocales) + { + this.testWithDifferentLocales = testWithDifferentLocales; + } + + public LocalizedTestCase(System.String name, HashSet testWithDifferentLocales) + : base(name) + { + this.testWithDifferentLocales = testWithDifferentLocales; + } + + // @Override + [SetUp] + public override void SetUp() + { + base.SetUp(); + } + + // @Override + [TearDown] + public override void TearDown() + { + base.TearDown(); + } + + [Test] + public void RunLocalizedTests() + { + // No need to test with default locale. Already done when actualy test was called by NUnit + var currentMethodName = MethodBase.GetCurrentMethod().Name; + + + // Get all the methods, and if there is a list of specific methods + // to test, only use those. + IEnumerable methodList = GetType().GetMethods(); + if(testWithDifferentLocales != null) + { + methodList = methodList.Where(mi => testWithDifferentLocales.Contains(mi.Name)); + } + + // Only get methods that have a TestAttribute on them...Ignore the rest + var methodsToTest = methodList.Where(mi => mi.Name != currentMethodName) + .Where(mi => mi.GetCustomAttributes(typeof (TestAttribute), true).Any()) + .ToList(); + + // Get a list of all locales to run the test against + var systemLocales = CultureInfo.GetCultures(CultureTypes.InstalledWin32Cultures); + + // Store the original cultures used, so they can be restored + var originalCulture = CultureInfo.CurrentCulture; + var originalUICulture = CultureInfo.CurrentUICulture; + try + { + // Do the test again under different Locales + foreach (CultureInfo t in systemLocales) + { + // Set the new test culture + System.Threading.Thread.CurrentThread.CurrentCulture = t; + System.Threading.Thread.CurrentThread.CurrentUICulture = t; + + foreach (var test in methodsToTest) + { + try + { + test.Invoke(this, null); + } + catch (Exception e) + { + Console.Out.WriteLine("Test failure of '" + test.Name + "' occurred under a different Locale " + t.Name); + throw; + } + } + } + } + finally + { + // Restore the cultures + System.Threading.Thread.CurrentThread.CurrentCulture = originalCulture; + System.Threading.Thread.CurrentThread.CurrentUICulture = originalUICulture; + } + } + } } \ No newline at end of file Modified: incubator/lucene.net/trunk/test/core/Util/LuceneTestCase.cs URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Util/LuceneTestCase.cs?rev=1353041&r1=1353040&r2=1353041&view=diff ============================================================================== --- incubator/lucene.net/trunk/test/core/Util/LuceneTestCase.cs (original) +++ incubator/lucene.net/trunk/test/core/Util/LuceneTestCase.cs Fri Jun 22 21:49:41 2012 @@ -233,25 +233,6 @@ namespace Lucene.Net.Util return new System.Random(seed); } - // @Override - public virtual void RunBare() - { - try - { - this.seed = null; - //base.RunBare(); // {{Aroush-2.9}} - System.Diagnostics.Debug.Fail("Port issue:", "base.RunBare()"); // {{Aroush-2.9}} - } - catch (System.Exception e) - { - if (this.seed != null) - { - System.Console.Out.WriteLine("NOTE: random seed of testcase '" + GetType() + "' was: " + seed); - } - throw e; - } - } - // recorded seed [NonSerialized] protected internal int? seed = null;