2 // DiagnosticsConfigurationHandlerTest.cs:
3 // NUnit Test Cases for System.Diagnostics.DiagnosticsConfigurationHandler
6 // Jonathan Pryor (jonpryor@vt.edu)
7 // Martin Willemoes Hansen (mwh@sysrq.dk)
10 // (C) 2003 Martin Willemoes Hansen
13 using NUnit.Framework;
15 using System.Configuration;
16 using System.Diagnostics;
19 namespace MonoTests.System.Diagnostics {
22 public class DiagnosticsConfigurationHandlerTest : Assertion {
24 private const string XmlFormat =
27 "<system.diagnostics>" +
29 "</system.diagnostics>";
32 private DiagnosticsConfigurationHandler handler = new DiagnosticsConfigurationHandler ();
34 [Test, Category ("NotDotNet")]
35 public void SwitchesTag_Attributes ()
37 string[] attrs = {"invalid=\"yes\""};
38 ValidateExceptions ("#TST:A", "<switches {0}></switches>", attrs);
41 private void ValidateExceptions (string name, string format, string[] args)
43 foreach (string arg in args) {
44 string xml = string.Format (XmlFormat,
45 string.Format (format, arg));
48 Fail (string.Format ("{0}:{1}: no exception generated", name, arg));
50 catch (ConfigurationException) {
52 catch (AssertionException) {
53 // This is generated by the Assertion.Fail() statement in the try block.
57 Fail (string.Format ("{0}:{1}: wrong exception generated: {2} ({3}).",
58 // name, arg, e.Message,
59 name, arg, e.ToString(),
60 // e.InnerException == null ? "" : e.InnerException.Message));
61 e.InnerException == null ? "" : e.InnerException.ToString()));
66 private void ValidateSuccess (string name, string format, string[] args)
68 foreach (string arg in args) {
69 string xml = string.Format (XmlFormat,
70 string.Format (format, arg));
75 Fail (string.Format ("{0}:{1}: exception generated: {2} ({3}).",
76 // name, arg, e.Message,
77 name, arg, e.ToString(),
78 // e.InnerException == null ? "" : e.InnerException.Message));
79 e.InnerException == null ? "" : e.InnerException.ToString()));
84 private object CreateHandler (string xml)
86 XmlDocument d = new XmlDocument ();
88 return handler.Create (null, null, d);
91 [Test, Category ("NotDotNet")]
92 public void SwitchesTag_Elements ()
94 string[] badElements = {
95 // not enough arguments
100 "<add name=\"string-value\" value=\"string-value\"/>",
101 // too many arguments
102 "<add name=\"a\" value=\"b\" extra=\"c\"/>",
104 "<add Name=\"a\" value=\"b\"/>",
105 "<Add Name=\"a\" value=\"b\"/>",
108 "<remove value=\"b\"/>",
110 "<remove name=\"a\" value=\"b\"/>",
111 "<clear name=\"a\"/>",
113 "<invalid element=\"a\" here=\"b\"/>"
115 ValidateExceptions ("#TST:IE:Bad", "<switches>{0}</switches>", badElements);
117 string[] goodElements = {
118 "<add name=\"a\" value=\"4\"/>",
119 "<add name=\"a\" value=\"-2\"/>",
120 "<remove name=\"a\"/>",
123 ValidateSuccess ("#TST:IE:Good", "<switches>{0}</switches>", goodElements);
126 [Test, Category ("NotDotNet")]
127 public void AssertTag ()
129 string[] goodAttributes = {
131 "assertuienabled=\"true\"",
132 "assertuienabled=\"false\" logfilename=\"some file name\"",
133 "logfilename=\"some file name\""
135 ValidateSuccess ("#TAT:Good", "<assert {0}/>", goodAttributes);
137 string[] badAttributes = {
138 "AssertUiEnabled=\"true\"",
139 "LogFileName=\"foo\"",
140 "assertuienabled=\"\"",
141 "assertuienabled=\"non-boolean-value\""
143 ValidateExceptions ("#TAT:BadAttrs", "<assert {0}/>", badAttributes);
145 string[] badChildren = {
146 "<any element=\"here\"/>"
148 ValidateExceptions ("#TAT:BadChildren", "<assert>{0}</assert>", badChildren);
151 [Test, Category ("NotDotNet")]
152 public void TraceTag_Attributes ()
156 "autoflush=\"true\"",
158 "autoflush=\"false\" indentsize=\"10\""
160 ValidateSuccess ("#TTT:A:Good", "<trace {0}/>", good);
163 "AutoFlush=\"true\"",
164 "IndentSize=\"false\"",
165 "autoflush=\"non-boolean-value\"",
167 "indentsize=\"non-integral-value\"",
171 ValidateExceptions ("#TTT:A:Bad", "<trace {0}/>", bad);
174 [Test, Category ("NotDotNet")]
175 public void TraceTag_Children ()
178 // more about listeners in a different function...
181 ValidateSuccess ("#TTT:C:Good", "<trace>{0}</trace>", good);
184 "<listeners with=\"attribute\"/>",
185 "<invalid element=\"here\"/>"
187 ValidateExceptions ("#TTT:C:Bad", "<trace>{0}</trace>", bad);
190 [Test, Category ("NotDotNet")]
191 public void TraceTag_Listeners ()
193 const string format = "<trace><listeners>{0}</listeners></trace>";
196 "<add name=\"foo\" " +
197 "type=\"System.Diagnostics.TextWriterTraceListener, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\" " +
198 "initializeData=\"argument.txt\"/>",
199 "<remove name=\"foo\"/>",
200 "<add name=\"foo\" " +
201 "type=\"System.Diagnostics.TextWriterTraceListener, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\" />",
202 "<remove name=\"foo\"/>"
204 ValidateSuccess ("#TTT:L:Good", format, good);
207 "<invalid tag=\"here\"/>",
208 "<clear with=\"args\"/>",
211 "<remove name=\"foo\" extra=\"arg\"/>",
212 "<add name=\"foo\"/>",
213 "<add type=\"foo\"/>",
214 "<add name=\"foo\" type=\"invalid-type\"/>",
216 ValidateExceptions ("#TTT:L:Bad", format, bad);