You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by cc...@apache.org on 2012/06/22 23:49:43 UTC

svn commit: r1353041 - in /incubator/lucene.net/trunk: src/core/Document/ test/core/Document/ test/core/QueryParser/ test/core/Search/Function/ test/core/Util/

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<string> dataTestWithDifferentLocals = new HashSet<string>
+	        {
+	            "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
 {
-	
-	/// <summary> Base test class for Lucene test classes that test Locale-sensitive behavior.
-	/// <p/>
-	/// 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.
-	/// </summary>
-	public class LocalizedTestCase:LuceneTestCase
-	{
-		/// <summary> Before changing the default Locale, save the default Locale here so that it
-		/// can be restored.
-		/// </summary>
-		private System.Globalization.CultureInfo defaultLocale = System.Threading.Thread.CurrentThread.CurrentCulture;
-		
-		/// <summary> The locale being used as the system default Locale</summary>
-        private System.Globalization.CultureInfo locale = System.Globalization.CultureInfo.CurrentCulture;
-		
-		/// <summary> An optional limited set of testcases that will run under different Locales.</summary>
-		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;
-					}
-				}
-			}
-		}
-	}
+
+    /// <summary> Base test class for Lucene test classes that test Locale-sensitive behavior.
+    /// <p/>
+    /// 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.
+    /// </summary>
+    public class LocalizedTestCase : LuceneTestCase
+    {
+        /// <summary> An optional limited set of testcases that will run under different Locales.</summary>
+        private readonly HashSet<string> testWithDifferentLocales;
+
+        public LocalizedTestCase()
+        {
+            testWithDifferentLocales = null;
+        }
+
+        public LocalizedTestCase(System.String name)
+            : base(name)
+        {
+            testWithDifferentLocales = null;
+        }
+
+        public LocalizedTestCase(HashSet<string> testWithDifferentLocales)
+        {
+            this.testWithDifferentLocales = testWithDifferentLocales;
+        }
+
+        public LocalizedTestCase(System.String name, HashSet<string> 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<MethodInfo> 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;