Author: atsushi
Date: 2007-05-15 10:09:27 -0400 (Tue, 15 May 2007)
New Revision: 77408

Added:
   trunk/mcs/class/corlib/Test/System.Globalization/RegionInfoTest.cs
Modified:
   trunk/mcs/class/corlib/ChangeLog
   trunk/mcs/class/corlib/System.Globalization/ChangeLog
   trunk/mcs/class/corlib/System.Globalization/CultureInfo.cs
   trunk/mcs/class/corlib/System.Globalization/RegionInfo.cs
   trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog
   trunk/mcs/class/corlib/corlib_test.dll.sources
Log:
2007-05-15  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * RegionInfo.cs, CultureInfo.cs : in 2.0 RegionInfo could be created
          from locale name. To support that, retrieve CultureInfo from name
          and use its Territory name if exists.
          RegionInfo.Equals() still uses lcid, but hash code is based on
          region ID. Added GeoId, which represents unique region ID (which
          is returned in 1.x GetHashCode()).

        * RegionInfoTest.cs : new tests.

        * corlib_test.dll.sources : added RegionInfoTest.cs.



Modified: trunk/mcs/class/corlib/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/ChangeLog    2007-05-15 14:08:25 UTC (rev 77407)
+++ trunk/mcs/class/corlib/ChangeLog    2007-05-15 14:09:27 UTC (rev 77408)
@@ -1,3 +1,7 @@
+2007-05-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * corlib_test.dll.sources : added RegionInfoTest.cs.
+
 2007-05-11  Raja R Harinath  <[EMAIL PROTECTED]>
 
        * Makefile (cmp_makefrag, cmp_response): Depend on $(depsdir).
@@ -152,7 +156,7 @@
          System.Security.AccessControl/SecurityInfos.cs
          System.Security.AccessControl/SystemAcl.cs
 
-2006-07-03  Kornél Pál  <[EMAIL PROTECTED]>
+2006-07-03  Kornel Pal  <[EMAIL PROTECTED]>
 
        * corlib.dll.sources: Added
          System.Globalization/CodePageDataItem.cs
@@ -208,7 +212,7 @@
 
        * corlib.dll.sources: Added System.Resources/ResourceManagerTest.cs
 
-2006-01-05  Kornél Pál  <[EMAIL PROTECTED]>
+2006-01-05  Kornel Pal  <[EMAIL PROTECTED]>
 
        * corlib.dll.sources: Added DriveNotFoundException.cs in System.IO.
 
@@ -1122,7 +1126,7 @@
        * corlib.dll.sources: Added 
                System.Runtime.Serialization.Formatter.Binary.CodeGenerator.cs
 
-2004-02-10 Carlos Guzmán Álvarez  <[EMAIL PROTECTED]>
+2004-02-10 Carlos Guzman Alvarez  <[EMAIL PROTECTED]>
 
     * Mono.Security.Cryptography/PKCS1.cs:
 
@@ -1199,7 +1203,7 @@
        * corlib_test.dll.sources: Added unit tests PaddingMode and X509 
        using CryptoAPI.
 
-2003-12-14  Pedro Martínez Juliá <[EMAIL PROTECTED]>
+2003-12-14  Pedro Martinez Julia <[EMAIL PROTECTED]>
 
        * DateTime.cs: Be sure that the array access is not out of range
        when looking for ArgumentOutOfRangeException in the year value.
@@ -1290,7 +1294,7 @@
        * corlib.dll.sources: Added classes for Authenticode support.
        * corlib_test.dll.sources: Added unit test for SPC certificates.
 
-2003-09-26  Pedro Martínez Juliá <[EMAIL PROTECTED]>
+2003-09-26  Pedro Martinez Julia <[EMAIL PROTECTED]>
 
        * corlib_test.dll.sources: Remove tests that generate compile
        errors. The tests are still there but its name is rmoved here.
@@ -1448,7 +1452,7 @@
 
        * unix.args: Added 
System.Runtime.Remoting.Activation/AppDomainLevelActivator.cs
 
-2003-03-16  Pedro Martínez Juliá <[EMAIL PROTECTED]>
+2003-03-16  Pedro Martinez Julia <[EMAIL PROTECTED]>
 
        * unix.args: Added "System.FloatingPointFormatter.cs".
 
@@ -1460,7 +1464,7 @@
        * unix.args: Added
                System.Runtime.InteropServices/HandleRef.cs
 
-2003-03-04  Pedro Martínez Juliá <[EMAIL PROTECTED]>
+2003-03-04  Pedro Martinez Julia <[EMAIL PROTECTED]>
 
        * unix.args: Added "DoubleFormatter.cs" and "SingleFormatter.cs"
 

Modified: trunk/mcs/class/corlib/System.Globalization/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Globalization/ChangeLog       2007-05-15 
14:08:25 UTC (rev 77407)
+++ trunk/mcs/class/corlib/System.Globalization/ChangeLog       2007-05-15 
14:09:27 UTC (rev 77408)
@@ -1,3 +1,12 @@
+2007-05-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * RegionInfo.cs, CultureInfo.cs : in 2.0 RegionInfo could be created
+         from locale name. To support that, retrieve CultureInfo from name
+         and use its Territory name if exists.
+         RegionInfo.Equals() still uses lcid, but hash code is based on
+         region ID. Added GeoId, which represents unique region ID (which
+         is returned in 1.x GetHashCode()).
+
 2007-04-17  Alp Toker  <[EMAIL PROTECTED]>
 
        * DateTimeFormatInfo.cs: Provide set accessor for MonthNames.

Modified: trunk/mcs/class/corlib/System.Globalization/CultureInfo.cs
===================================================================
--- trunk/mcs/class/corlib/System.Globalization/CultureInfo.cs  2007-05-15 
14:08:25 UTC (rev 77407)
+++ trunk/mcs/class/corlib/System.Globalization/CultureInfo.cs  2007-05-15 
14:09:27 UTC (rev 77408)
@@ -78,6 +78,8 @@
                private string icu_name;
                [NonSerialized]
                private string win3lang;
+               [NonSerialized]
+               private string territory;
                volatile CompareInfo compareInfo;
                [NonSerialized]
                private unsafe readonly int *calendar_data;
@@ -156,6 +158,11 @@
                        return ConstructCurrentCulture ();
                }
 
+               // it is used for RegionInfo.
+               internal string Territory {
+                       get { return territory; }
+               }
+
                public virtual int LCID {
                        get {
                                return cultureID;

Modified: trunk/mcs/class/corlib/System.Globalization/RegionInfo.cs
===================================================================
--- trunk/mcs/class/corlib/System.Globalization/RegionInfo.cs   2007-05-15 
14:08:25 UTC (rev 77407)
+++ trunk/mcs/class/corlib/System.Globalization/RegionInfo.cs   2007-05-15 
14:09:27 UTC (rev 77408)
@@ -56,6 +56,7 @@
                        }
                }
 
+               int lcid; // it is used only for Equals() (not even used in 
GetHashCode()).
                int regionId;
                string iso2Name;
                string iso3Name;
@@ -67,10 +68,16 @@
 
                public RegionInfo (int lcid)
                {
+#if NET_2_0
+                       if (!GetByTerritory (CultureInfo.GetCultureInfo (lcid)))
+                               throw new ArgumentException (
+                                       String.Format ("Region ID {0} 
(0x{0:X4}) is not a supported region.", lcid), "lcid");
+#else
                        if (!construct_internal_region_from_lcid (lcid))
                                throw new ArgumentException (
                                        String.Format ("Region ID {0} 
(0x{0:X4}) is not a " +
                                                        "supported region.", 
lcid), "lcid");
+#endif
                }
 
                public RegionInfo (string name)
@@ -78,11 +85,30 @@
                        if (name == null)
                                throw new ArgumentNullException ();
 
+#if NET_2_0
+                       if (construct_internal_region_from_name 
(name.ToUpperInvariant ())) {
+                               lcid = name.GetHashCode (); // random-ish
+                               return;
+                       }
+                       if (!GetByTerritory (CultureInfo.GetCultureInfo (name)))
+                               throw new ArgumentException (String.Format 
("Region name {0} is not supported.", name), "name");
+#else
                        if (!construct_internal_region_from_name 
(name.ToUpperInvariant ()))
                                throw new ArgumentException ("Region name " + 
name +
                                                " is not supported.", "name");
+#endif
                }
 
+               bool GetByTerritory (CultureInfo ci)
+               {
+                       if (ci == null)
+                               throw new Exception ("INTERNAL ERROR: should 
not happen.");
+                       if (ci.IsNeutralCulture || ci.Territory == null)
+                               return false;
+                       this.lcid = ci.LCID;
+                       return construct_internal_region_from_name 
(ci.Territory.ToUpperInvariant ());
+               }
+
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                private extern bool construct_internal_region_from_lcid (int 
lcid);
 
@@ -109,6 +135,12 @@
                        get { return englishName; }
                }
 
+#if NET_2_0
+               public virtual int GeoId {
+                       get { return regionId; }
+               }
+#endif
+
                public virtual bool IsMetric {
                        get {
                                switch (iso2Name) {
@@ -157,6 +189,16 @@
                // methods
 
 #if NET_2_0
+               public override bool Equals (object value)
+               {
+                       RegionInfo other = value as RegionInfo;
+                       return other != null && lcid == other.lcid;
+               }
+
+               public override int GetHashCode ()
+               {
+                       return (int) (0x80000000 + (regionId << 3) + regionId); 
// it i still based on regionId
+               }
 #else
                public override bool Equals (object value)
                {

Modified: trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog  2007-05-15 
14:08:25 UTC (rev 77407)
+++ trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog  2007-05-15 
14:09:27 UTC (rev 77408)
@@ -1,3 +1,7 @@
+2007-05-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * RegionInfoTest.cs : new tests.
+
 2007-03-06  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * CompareInfoTest.cs : added test for bug #79714.

Added: trunk/mcs/class/corlib/Test/System.Globalization/RegionInfoTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Globalization/RegionInfoTest.cs  
2007-05-15 14:08:25 UTC (rev 77407)
+++ trunk/mcs/class/corlib/Test/System.Globalization/RegionInfoTest.cs  
2007-05-15 14:09:27 UTC (rev 77408)
@@ -0,0 +1,62 @@
+//
+// System.Globalization.RegionInfoTest.cs
+//
+// Author:
+//     Atsushi Enomoto  <[EMAIL PROTECTED]>
+//
+// (c) 2007 Novell, Inc. (http://www.novell.com)
+//
+
+using NUnit.Framework;
+using System.IO;
+using System;
+using System.Globalization;
+using System.Threading;
+
+namespace MonoTests.System.Globalization
+{
+       [TestFixture]
+       public class RegionInfoTest
+       {
+               [Test]
+               public void RegionByName ()
+               {
+                       string [] names = new string [] {
+                               "AR", "ES", "HK", "TW", "US"};
+
+                       foreach (string name in names)
+                               new RegionInfo (name);
+
+               }
+
+               [Test]
+               public void RegionByWrongName ()
+               {
+                       string [] names = new string [] {
+                               "en", "EN"};
+
+                       foreach (string name in names) {
+                               try {
+                                       new RegionInfo (name);
+                                       Assert.Fail ("should be invalid: " + 
name);
+                               } catch (ArgumentException) {
+                               }
+                       }
+               }
+
+               [Test]
+#if NET_2_0
+#else
+               [ExpectedException (typeof (ArgumentException))]
+#endif
+               public void RegionByLocaleName ()
+               {
+                       string [] names = new string [] {
+                               "en-US", "zh-TW"};
+
+                       foreach (string name in names)
+                               new RegionInfo (name);
+               }
+       }
+}
+

Modified: trunk/mcs/class/corlib/corlib_test.dll.sources
===================================================================
--- trunk/mcs/class/corlib/corlib_test.dll.sources      2007-05-15 14:08:25 UTC 
(rev 77407)
+++ trunk/mcs/class/corlib/corlib_test.dll.sources      2007-05-15 14:09:27 UTC 
(rev 77408)
@@ -58,6 +58,7 @@
 System.Globalization/CompareInfoTest.cs
 System.Globalization/CultureInfoTest.cs
 System.Globalization/DaylightTimeTest.cs
+System.Globalization/RegionInfoTest.cs
 System.Globalization/TextInfoTest.cs
 System/GuidTest.cs
 System/Int16Test.cs

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to