Author: gert
Date: 2007-07-21 09:37:11 -0400 (Sat, 21 Jul 2007)
New Revision: 82414
Modified:
trunk/mcs/class/System/System.ComponentModel/ChangeLog
trunk/mcs/class/System/System.ComponentModel/DisplayNameAttribute.cs
trunk/mcs/class/System/Test/System.ComponentModel/ChangeLog
trunk/mcs/class/System/Test/System.ComponentModel/DisplayNameAttributeTests.cs
Log:
* DisplayNameAttribute.cs: To match MS, do not change null DisplayName
to a zero-length string. Modified IsDefaultAttribute to take into
account null DisplayName.
* DisplayNameAttribute.cs: Added ctor tests. Fixed tests to pass on
MS (now that our implementation matches that of MS). Added tests
for Default, GetHashCode and Equals.
Modified: trunk/mcs/class/System/System.ComponentModel/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.ComponentModel/ChangeLog 2007-07-21
12:47:05 UTC (rev 82413)
+++ trunk/mcs/class/System/System.ComponentModel/ChangeLog 2007-07-21
13:37:11 UTC (rev 82414)
@@ -1,3 +1,9 @@
+2007-07-21 Gert Driesen <[EMAIL PROTECTED]>
+
+ * DisplayNameAttribute.cs: To match MS, do not change null DisplayName
+ to a zero-length string. Modified IsDefaultAttribute to take into
+ account null DisplayName.
+
2007-07-16 Gert Driesen <[EMAIL PROTECTED]>
* ReflectionPropertyDescriptor.cs: For read-only properties,
Modified: trunk/mcs/class/System/System.ComponentModel/DisplayNameAttribute.cs
===================================================================
--- trunk/mcs/class/System/System.ComponentModel/DisplayNameAttribute.cs
2007-07-21 12:47:05 UTC (rev 82413)
+++ trunk/mcs/class/System/System.ComponentModel/DisplayNameAttribute.cs
2007-07-21 13:37:11 UTC (rev 82414)
@@ -29,7 +29,7 @@
#if NET_2_0
namespace System.ComponentModel
{
-
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Event)]
+ [AttributeUsageAttribute (AttributeTargets.Class |
AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event)]
public class DisplayNameAttribute : Attribute
{
public static readonly DisplayNameAttribute Default = new
DisplayNameAttribute ();
@@ -43,12 +43,14 @@
public DisplayNameAttribute (string displayName)
{
- this.attributeDisplayName = displayName != null ?
displayName : String.Empty;
+ this.attributeDisplayName = displayName;
}
public override bool IsDefaultAttribute ()
{
- return attributeDisplayName.Length == 0;
+ if (attributeDisplayName != null)
+ return attributeDisplayName.Length == 0;
+ return false;
}
public override int GetHashCode ()
@@ -74,7 +76,7 @@
protected string DisplayNameValue {
get { return attributeDisplayName; }
- set { attributeDisplayName = value != null ? value :
String.Empty; }
+ set { attributeDisplayName = value; }
}
}
}
Modified: trunk/mcs/class/System/Test/System.ComponentModel/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/System.ComponentModel/ChangeLog 2007-07-21
12:47:05 UTC (rev 82413)
+++ trunk/mcs/class/System/Test/System.ComponentModel/ChangeLog 2007-07-21
13:37:11 UTC (rev 82414)
@@ -1,3 +1,9 @@
+2007-07-21 Gert Driesen <[EMAIL PROTECTED]>
+
+ * DisplayNameAttribute.cs: Added ctor tests. Fixed tests to pass on
+ MS (now that our implementation matches that of MS). Added tests
+ for Default, GetHashCode and Equals.
+
2007-07-16 Gert Driesen <[EMAIL PROTECTED]>
* PropertyDescriptorTests.cs: Added test for ShouldSerializeValue
Modified:
trunk/mcs/class/System/Test/System.ComponentModel/DisplayNameAttributeTests.cs
===================================================================
---
trunk/mcs/class/System/Test/System.ComponentModel/DisplayNameAttributeTests.cs
2007-07-21 12:47:05 UTC (rev 82413)
+++
trunk/mcs/class/System/Test/System.ComponentModel/DisplayNameAttributeTests.cs
2007-07-21 13:37:11 UTC (rev 82414)
@@ -1,17 +1,20 @@
//
-// System.ComponentModel.DisplayNameAttributeTests test cases
+// System.ComponentModel.DisplayNameAttribute test cases
//
// Authors:
// Marek Habersack ([EMAIL PROTECTED])
+// Gert Driesen ([EMAIL PROTECTED]
//
// (c) 2006 Marek Habersack
//
+
#if NET_2_0
-using NUnit.Framework;
using System;
using System.ComponentModel;
using System.Reflection;
+using NUnit.Framework;
+
namespace MonoTests.System.ComponentModel
{
[DisplayName ()]
@@ -100,6 +103,81 @@
}
[Test]
+ public void Constructor0 ()
+ {
+ DisplayNameAttribute dn = new DisplayNameAttribute ();
+ Assert.IsNotNull (dn.DisplayName, "#1");
+ Assert.AreEqual (string.Empty, dn.DisplayName, "#2");
+ Assert.IsTrue (dn.IsDefaultAttribute (), "#3");
+ }
+
+ [Test]
+ public void Constructor1 ()
+ {
+ DisplayNameAttribute dn = new DisplayNameAttribute
(string.Empty);
+ Assert.IsNotNull (dn.DisplayName, "#A1");
+ Assert.AreEqual (string.Empty, dn.DisplayName, "#A2");
+ Assert.IsTrue (dn.IsDefaultAttribute (), "#A3");
+
+ dn = new DisplayNameAttribute (null);
+ Assert.IsNull (dn.DisplayName, "#B1");
+ Assert.IsFalse (dn.IsDefaultAttribute (), "#B2");
+
+ dn = new DisplayNameAttribute ("category");
+ Assert.IsNotNull (dn.DisplayName, "#C1");
+ Assert.AreEqual ("category", dn.DisplayName, "#C2");
+ Assert.IsFalse (dn.IsDefaultAttribute (), "#C3");
+ }
+
+ [Test]
+ public void Default ()
+ {
+ DisplayNameAttribute dn = DisplayNameAttribute.Default;
+ Assert.IsNotNull (dn.DisplayName, "#1");
+ Assert.AreEqual (string.Empty, dn.DisplayName, "#2");
+ Assert.IsTrue (dn.IsDefaultAttribute (), "#3");
+ }
+
+ [Test]
+ public void Equals ()
+ {
+ DisplayNameAttribute dn = new DisplayNameAttribute ();
+ Assert.IsTrue (dn.Equals
(DisplayNameAttribute.Default), "#A1");
+ Assert.IsTrue (dn.Equals (new DisplayNameAttribute
(string.Empty)), "#A2");
+ Assert.IsFalse (dn.Equals (new DisplayNameAttribute
("category")), "#A3");
+ Assert.IsFalse (dn.Equals (new DisplayNameAttribute
(null)), "#A4");
+ Assert.IsFalse (dn.Equals (null), "#A5");
+ Assert.IsTrue (dn.Equals (dn), "#A6");
+ Assert.IsFalse (dn.Equals (55), "#A7");
+
+ dn = new DisplayNameAttribute ("category");
+ Assert.IsFalse (dn.Equals
(DisplayNameAttribute.Default), "#B1");
+ Assert.IsFalse (dn.Equals (new DisplayNameAttribute
(string.Empty)), "#B2");
+ Assert.IsTrue (dn.Equals (new DisplayNameAttribute
("category")), "#B3");
+ Assert.IsFalse (dn.Equals (new DisplayNameAttribute
(null)), "#B4");
+ Assert.IsFalse (dn.Equals (null), "#B5");
+ Assert.IsTrue (dn.Equals (dn), "#B6");
+ Assert.IsFalse (dn.Equals (55), "#B7");
+ }
+
+ [Test]
+ public void GetHashCodeTest ()
+ {
+ DisplayNameAttribute dn = new DisplayNameAttribute ();
+ Assert.AreEqual (string.Empty.GetHashCode (),
dn.GetHashCode (), "#A1");
+ dn = new DisplayNameAttribute ("A");
+ Assert.AreEqual ("A".GetHashCode (), dn.GetHashCode (),
"#A2");
+
+ //
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=288534
+ dn = new DisplayNameAttribute (null);
+ try {
+ dn.GetHashCode ();
+ Assert.Fail ("#B1");
+ } catch (NullReferenceException) {
+ }
+ }
+
+ [Test]
public void TestEmptyName ()
{
Type tc1t = tc1.GetType ();
@@ -145,18 +223,15 @@
Type tc3t = tc3.GetType ();
DisplayNameAttribute dn = GetAttribute (tc3t);
Assert.IsNotNull (dn, "#1_1");
- Assert.IsFalse (dn.DisplayName == null, "#1_2");
- Assert.AreEqual (dn.DisplayName, "", "#1_3");
+ Assert.IsNull (dn.DisplayName, "#1_2");
dn = GetAttribute (tc3t, "Property3",
MemberTypes.Property);
Assert.IsNotNull (dn, "#2_1");
- Assert.IsFalse (dn.DisplayName == null, "#2_2");
- Assert.AreEqual (dn.DisplayName, "", "#2_3");
+ Assert.IsNull (dn.DisplayName, "#2_2");
dn = GetAttribute (tc3t, "Method3", MemberTypes.Method);
Assert.IsNotNull (dn, "#3_1");
- Assert.IsFalse (dn.DisplayName == null, "#3_2");
- Assert.AreEqual (dn.DisplayName, "", "#3_3");
+ Assert.IsNull (dn.DisplayName, "#3_2");
}
[Test]
@@ -191,17 +266,16 @@
Type tc3t = tc3.GetType ();
dn = GetAttribute (tc3t);
Assert.IsNotNull (dn, "#3_1");
- Assert.IsTrue (dn.IsDefaultAttribute (), "#3_2");
+ Assert.IsFalse (dn.IsDefaultAttribute (), "#3_2");
dn = GetAttribute (tc3t, "Property3",
MemberTypes.Property);
Assert.IsNotNull (dn, "#3_3");
- Assert.IsTrue (dn.IsDefaultAttribute (), "#3_4");
+ Assert.IsFalse (dn.IsDefaultAttribute (), "#3_4");
dn = GetAttribute (tc3t, "Method3", MemberTypes.Method);
Assert.IsNotNull (dn, "#3_5");
- Assert.IsTrue (dn.IsDefaultAttribute (), "#3_6");
+ Assert.IsFalse (dn.IsDefaultAttribute (), "#3_6");
}
}
}
#endif
-
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches