Merge pull request #1225 from strawd/bug22307
[mono.git] / mcs / class / System / Test / System.Diagnostics / SwitchesTest.cs
index a5574b0275d9b110754eaa8a6797e4f6e77a4dd6..9d97fc8b53c615a8589e7fbea1a8cdc0d030038e 100644 (file)
@@ -11,6 +11,8 @@
 // (C) 2003 Martin Willemoes Hansen
 //
 
+#if !MOBILE
+
 using NUnit.Framework;
 using System;
 using System.Text;
@@ -25,7 +27,7 @@ namespace MonoTests.System.Diagnostics {
                private StringBuilder ops = new StringBuilder ();
                private const string expected = 
                        ".ctor\n" +
-                       "get_Value\n" +
+                       "get_TestValue\n" +
                        "OnSwitchSettingChanged\n" +
                        "GetSetting\n";
 
@@ -35,17 +37,22 @@ namespace MonoTests.System.Diagnostics {
                        ops.Append (".ctor\n");
                }
 
-               public string Value {
+               public string TestValue {
                        get {
-                               ops.Append ("get_Value\n");
+                               ops.Append ("get_TestValue\n");
                                // ensure that the .config file is read in
                                int n = base.SwitchSetting;
                                // remove warning about unused variable
-                               n = n;
+                               n = 5;
                                return v;
                        }
                }
 
+               public string [] ExposeSupportedAttributes ()
+               {
+                       return GetSupportedAttributes ();
+               }
+
                public bool Validate ()
                {
                        return expected == ops.ToString();
@@ -71,8 +78,14 @@ namespace MonoTests.System.Diagnostics {
                }
        }
 
+       class TestNullSwitch : Switch {
+               public TestNullSwitch () : base (null, null)
+               {
+               }
+       }
+
        [TestFixture]
-       public class SwitchesTest : Assertion {
+       public class SwitchesTest {
     
                private static BooleanSwitch bon = new BooleanSwitch ("bool-true", "");
                private static BooleanSwitch bon2 = new BooleanSwitch ("bool-true-2", "");
@@ -94,11 +107,11 @@ namespace MonoTests.System.Diagnostics {
                [Test]
                public void BooleanSwitches ()
                {
-                       Assert ("#BS:T:1", bon.Enabled);
-                       Assert ("#BS:T:2", bon2.Enabled);
-                       Assert ("#BS:T:3", bon3.Enabled);
-                       Assert ("#BS:F:1", !boff.Enabled);
-                       Assert ("#BS:F:2", !boff2.Enabled);
+                       Assert.IsTrue (bon.Enabled, "#BS:T:1");
+                       Assert.IsTrue (bon2.Enabled, "#BS:T:2");
+                       Assert.IsTrue (bon3.Enabled, "#BS:T:3");
+                       Assert.IsTrue (!boff.Enabled, "#BS:F:1");
+                       Assert.IsTrue (!boff2.Enabled, "#BS:F:2");
                }
 
                [Test]
@@ -124,21 +137,63 @@ namespace MonoTests.System.Diagnostics {
                private void CheckTraceSwitch (TraceSwitch ts, bool te, bool tw, bool ti, bool tv)
                {
                        string desc = string.Format ("#TS:{0}", ts.DisplayName);
-                       AssertEquals (desc + ":TraceError",   te, ts.TraceError);
-                       AssertEquals (desc + ":TraceWarning", tw, ts.TraceWarning);
-                       AssertEquals (desc + ":TraceInfo",    ti, ts.TraceInfo);
-                       AssertEquals (desc + ":TraceVerbose", tv, ts.TraceVerbose);
+                       Assert.AreEqual (te, ts.TraceError, desc + ":TraceError");
+                       Assert.AreEqual (tw, ts.TraceWarning, desc + ":TraceWarning");
+                       Assert.AreEqual (ti, ts.TraceInfo, desc + ":TraceInfo");
+                       Assert.AreEqual (tv, ts.TraceVerbose, desc + ":TraceVerbose");
                }
 
                [Test]
-#if NET_2_0
                [Ignore ("this test depends on 1.x configuration type")]
-#endif
                public void NewSwitch ()
                {
-                       AssertEquals ("#NS:Value", "42", tns.Value);
-                       Assert ("#NS:Validate", tns.Validate());
+                       Assert.AreEqual ("42", tns.TestValue, "#NS:TestValue");
+                       Assert.IsTrue (tns.Validate(), "#NS:Validate");
+               }
+
+               [Test]
+               public void GetSupportedAttributes ()
+               {
+                       Assert.IsNull (tns.ExposeSupportedAttributes ());
+               }
+
+               [Test] // no ArgumentNullException happens...
+               public void BooleanSwitchNullDefaultValue ()
+               {
+                       new BooleanSwitch ("test", "", null);
+               }
+
+               [Test]
+               public void BooleanSwitchValidDefaultValue ()
+               {
+                       BooleanSwitch s = new BooleanSwitch ("test", "", "2");
+                       Assert.IsTrue (s.Enabled, "#1");
+                       s = new BooleanSwitch ("test", "", "0");
+                       Assert.IsTrue (!s.Enabled, "#2");
+                       s = new BooleanSwitch ("test", "", "true");
+                       Assert.IsTrue (s.Enabled, "#3");
+                       s = new BooleanSwitch ("test", "", "True");
+                       Assert.IsTrue (s.Enabled, "#4");
+                       s = new BooleanSwitch ("test", "", "truE");
+                       Assert.IsTrue (s.Enabled, "#5");
+               }
+
+               [Test]
+               [ExpectedException (typeof (FormatException))]
+               public void BooleanSwitchInvalidDefaultValue ()
+               {
+                       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