TraceSourceTest.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // TraceSourceTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2007 Novell, Inc.
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if !MOBILE
  30. using NUnit.Framework;
  31. using System;
  32. using System.Text;
  33. using System.Collections;
  34. using System.Configuration;
  35. using System.Diagnostics;
  36. namespace MonoTests.System.Diagnostics
  37. {
  38. [TestFixture]
  39. public class TraceSourceTest
  40. {
  41. [Test]
  42. [ExpectedException (typeof (ArgumentNullException))]
  43. public void ConstructorNullName ()
  44. {
  45. new TraceSource (null);
  46. }
  47. [Test]
  48. [ExpectedException (typeof (ArgumentException))]
  49. public void ConstructorEmpty ()
  50. {
  51. new TraceSource ("");
  52. }
  53. [Test]
  54. public void DefaultValues ()
  55. {
  56. TraceSource ts = new TraceSource ("foo");
  57. Assert.AreEqual ("foo", ts.Name, "#1");
  58. Assert.IsNotNull (ts.Switch, "#2");
  59. Assert.AreEqual (SourceLevels.Off, ts.Switch.Level, "#3");
  60. Assert.IsNotNull (ts.Listeners, "#4");
  61. Assert.AreEqual (1, ts.Listeners.Count, "#5");
  62. Assert.IsNotNull (ts.Attributes, "#6");
  63. Assert.AreEqual (0, ts.Attributes.Count, "#7");
  64. }
  65. [Test]
  66. [ExpectedException (typeof (ArgumentNullException))]
  67. public void SetSourceSwitchNull ()
  68. {
  69. TraceSource ts = new TraceSource ("foo");
  70. ts.Switch = null;
  71. }
  72. [Test]
  73. public void SwitchLevel ()
  74. {
  75. TraceSource s = new TraceSource ("Source1");
  76. Assert.AreEqual (SourceLevels.Off, s.Switch.Level, "#1");
  77. s = new TraceSource("Source2", SourceLevels.All);
  78. Assert.AreEqual (SourceLevels.All, s.Switch.Level, "#2");
  79. s = new TraceSource("Source3");
  80. s.Switch.Level = SourceLevels.All;
  81. Assert.AreEqual (SourceLevels.All, s.Switch.Level, "#3");
  82. }
  83. }
  84. }
  85. #endif