[System] Fixed Diagnostics.Switch ctor behavior for null parameters
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 10 Sep 2014 17:09:34 +0000 (19:09 +0200)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 10 Sep 2014 17:09:34 +0000 (19:09 +0200)
Passing null to the displayName or description ctor parameter on MS.NET makes them equal to an empty string.
Fixed the Mono behavior to match .NET.

mcs/class/System/System.Diagnostics/Switch.cs
mcs/class/System/Test/System.Diagnostics/SourceSwitchTest.cs
mcs/class/System/Test/System.Diagnostics/SwitchesTest.cs

index 216cde7fa24ed4a667d4090421e33527c12bd08f..94d1f4d19fe92bbe3bed4cb46f3d3526c341a611 100644 (file)
@@ -64,8 +64,8 @@ namespace System.Diagnostics
 
                protected Switch(string displayName, string description)
                {
-                       this.name = displayName;
-                       this.description = description;
+                       this.name = displayName ?? string.Empty;
+                       this.description = description ?? string.Empty;
                }
 
                protected Switch(string displayName, string description, string defaultSwitchValue)
index af0b6609d2727015ef390a99dd4352e36251019e..5cfcb1a6f7ba470c2eb2c01f99e433906a07c00a 100644 (file)
@@ -51,7 +51,7 @@ namespace MonoTests.System.Diagnostics
                public void ConstructorNullName ()
                {
                        SourceSwitch s = new SourceSwitch (null);
-                       Assert.IsNull (s.DisplayName);
+                       Assert.IsEmpty (s.DisplayName);
                }
 
                [Test]
index c21a1ca5248f07fea0f850c000611edc762079a7..4c52cb109af6ef70cf6e0a091042768642b0453e 100644 (file)
@@ -80,6 +80,12 @@ namespace MonoTests.System.Diagnostics {
                }
        }
 
+       class TestNullSwitch : Switch {
+               public TestNullSwitch () : base (null, null)
+               {
+               }
+       }
+
        [TestFixture]
        public class SwitchesTest {
     
@@ -184,8 +190,16 @@ namespace MonoTests.System.Diagnostics {
                        BooleanSwitch s = new BooleanSwitch ("test", "", "hoge");
                        Assert.IsTrue (!s.Enabled);
                }
+
+               [Test]
+               public void NullSwitchHasEmptyDisplayNameAndDescription ()
+               {
+                       var s = new TestNullSwitch ();
+                       Assert.IsEmpty (s.DisplayName);
+                       Assert.IsEmpty (s.Description);
+               }
 #endif
        }
 }
 
-#endif
\ No newline at end of file
+#endif