[Mono-devel-list] CultureInfo

Lee Mallabone mono-docs at fonicmonkey.net
Tue Apr 15 17:31:49 EDT 2003


Hi all,

A diff is attached, along with a test case.

The patch is still unfinished, but it compiles and I thought it best to
post here in case others have any advice or criticism.

The test case succeeds on the MS runtime but still fails after applying
my patch - there is more work to be done.

However, the patch does implement methods that were TODO before - the
country code and Parent properties.

If I should commit this, let me know. I'll try and keep working on it -
the GetCultures() in particular will require some further changes to
implement.

If anyone has any insight on implementing the Calendar and
OptionalCalendars properties in particular, I'd love to hear it -
reading the API docs make the implementation sound non-trivial.

Regards,

Lee.

-------------- next part --------------
// CultureInfo.cs - NUnit Test Cases for ensuring culture correctness 
// between the Microsoft runtime and Mono.
//
// Lee Mallabone <gnome at fonicmonkey.net>
//

using NUnit.Framework;
using System;
using System.Globalization;

namespace MonoTests.System.Globalization
{

[TestFixture]
public class CultureInfoTest {
	
	// this method is run before each [Test] method is called. You can put
	// variable initialization, etc. here that is common to each test.
	[SetUp]
	public void GetReady() {}

	// this method is run after each Test* method is called. You can put
	// clean-up code, etc. here.  Whatever needs to be done after each test.
	[TearDown]
	public void Clean() {}

	/// Checks that the total, specific and neutral number of cultures we are returning is consistent
	/// with Microsoft's 1.0 .NET runtime.
	[Test]
	public void testNumberOfCultures() 
	{
		Assertion.AssertEquals ("Total # of cultures", 202, CultureInfo.GetCultures (CultureTypes.AllCultures).Length);
		Assertion.AssertEquals ("Neutral # of cultures", 68, CultureInfo.GetCultures (CultureTypes.NeutralCultures).Length);
		Assertion.AssertEquals ("Specific # of cultures", 134, CultureInfo.GetCultures (CultureTypes.SpecificCultures).Length);
	}

	// Tests that all cultures are parented as expected
	[Test]
	public void testParentCultures()
	{
		// Neutral cultures should have the InvariantCulture as their parent.
		// This includes the InvariantCulture having InvariantCulture as its parent.
		CultureInfo[] neutralCultures = CultureInfo.GetCultures (CultureTypes.NeutralCultures);
		foreach (CultureInfo info in neutralCultures)
		{
			Assertion.AssertEquals (CultureInfo.InvariantCulture, info.Parent);
		}
		CultureInfo[] specificCultures = CultureInfo.GetCultures (CultureTypes.SpecificCultures);
		foreach (CultureInfo info in specificCultures)
		{
			// Need to do two special cases for chinese cultures.
			switch (info.LCID)
			{
				case 0x0404:
					Assertion.AssertEquals(0x7c04, info.Parent.LCID);
					break;
				case 0x0c04:
					Assertion.AssertEquals(0x7c04, info.Parent.LCID);
					break;
				default:
					Assertion.AssertEquals (info+" Parent", new CultureInfo(info.LCID & 0xff), info.Parent);
					break;
			}
		}
	}

	// Ensures that all the cultures with alternative sort orders can
	// be created without exceptions getting thrown.
	[Test]
	public void testAlternateSortOrdersExist()
	{
		Assertion.AssertNotNull(new CultureInfo(0x0000040A)); // es-ES Spanish - Spain International: 0x00000C0A Traditional: 0x0000040A 
		Assertion.AssertNotNull(new CultureInfo(0x00030404)); // zh-TW Chinese - Taiwan Stroke Count: 0x00000404 Bopomofo: 0x00030404 
		Assertion.AssertNotNull(new CultureInfo(0x00020804)); // zh-CN  Chinese - China Pronunciation: 0x00000804 Stroke Count: 0x00020804 
		Assertion.AssertNotNull(new CultureInfo(0x00020c04)); // zh-HK Chinese - Hong Kong SAR Stroke Count: 0x00000c04 Stroke Count: 0x00020c04 
		Assertion.AssertNotNull(new CultureInfo(0x00021004)); // zh-SG Chinese - Singapore Pronunciation: 0x00001004 Stroke Count: 0x00021004 
		Assertion.AssertNotNull(new CultureInfo(0x00021404)); // zh-MO Chinese - Macau SAR Pronunciation: 0x00001404 Stroke Count: 0x00021404 
		Assertion.AssertNotNull(new CultureInfo(0x00010411)); // ja-JP Japanese - Japan Default: 0x00000411 Unicode: 0x00010411 
		Assertion.AssertNotNull(new CultureInfo(0x00010412)); // ko-KR Korean - Korea Default: 0x00000412 Korean Xwansung - Unicode: 0x00010412 
		Assertion.AssertNotNull(new CultureInfo(0x00010407)); // de-DE German - Germany Dictionary: 0x00000407 Phone Book Sort DIN: 0x00010407 
		Assertion.AssertNotNull(new CultureInfo(0x0001040e)); // hu-HU Hungarian - Hungary Default: 0x0000040e Technical Sort: 0x0001040e 
		Assertion.AssertNotNull(new CultureInfo(0x00010437)); // ka-GE Georgian - Georgia Traditional: 0x00000437 Modern Sort: 0x00010437 

	}

	// An nice way to test for exceptions the class under test should 
	// throw is:
// 	[ExpectedException(typeof(ArgumentNullException))]

}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CultureInfo.diff
Type: text/x-patch
Size: 41679 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20030415/ded10d38/attachment.bin 


More information about the Mono-devel-list mailing list