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
15 using NUnit.Framework;
17 using System.Configuration;
18 using System.Diagnostics;
21 namespace MonoTests.System.Diagnostics
24 public class DiagnosticsConfigurationHandlerTest
26 private const string XmlFormat =
29 "<system.diagnostics>" +
31 "</system.diagnostics>";
34 private DiagnosticsConfigurationHandler handler = new DiagnosticsConfigurationHandler ();
37 [Category ("NotDotNet")]
38 public void SwitchesTag_Attributes ()
40 string[] attrs = {"invalid=\"yes\""};
41 ValidateExceptions ("#TST:A", "<switches {0}></switches>", attrs);
44 void ValidateExceptions (string name, string format, string[] args)
46 foreach (string arg in args) {
47 string xml = string.Format (XmlFormat,
48 string.Format (format, arg));
51 Assert.Fail (string.Format ("{0}:{1}: no exception generated", name, arg));
52 } catch (ConfigurationException) {
53 } catch (AssertionException) {
54 // This is generated by the Assertion.Fail() statement in the try block.
56 } catch (Exception e) {
57 Assert.Fail (string.Format ("{0}:{1}: wrong exception generated: {2} ({3}).",
58 name, arg, e.ToString(),
59 e.InnerException == null ? "" : e.InnerException.ToString()));
64 private void ValidateSuccess (string name, string format, string[] args)
66 foreach (string arg in args) {
67 string xml = string.Format (XmlFormat,
68 string.Format (format, arg));
71 } catch (Exception e) {
72 Assert.Fail (string.Format ("{0}:{1}: exception generated: {2} ({3}).",
73 name, arg, e.ToString(),
74 e.InnerException == null ? "" : e.InnerException.ToString()));
79 private object CreateHandler (string xml)
81 XmlDocument d = new XmlDocument ();
83 return handler.Create (null, null, d);
87 [Category ("NotDotNet")]
88 public void SwitchesTag_Elements ()
90 string[] badElements = {
91 // not enough arguments
96 "<add name=\"a\" value=\"b\" extra=\"c\"/>",
98 "<add Name=\"a\" value=\"b\"/>",
99 "<Add Name=\"a\" value=\"b\"/>",
102 "<remove value=\"b\"/>",
104 "<remove name=\"a\" value=\"b\"/>",
105 "<clear name=\"a\"/>",
107 "<invalid element=\"a\" here=\"b\"/>"
109 ValidateExceptions ("#TST:IE:Bad", "<switches>{0}</switches>", badElements);
111 string[] goodElements = {
112 "<add name=\"a\" value=\"4\"/>",
113 "<add name=\"a\" value=\"-2\"/>",
114 "<remove name=\"a\"/>",
117 ValidateSuccess ("#TST:IE:Good", "<switches>{0}</switches>", goodElements);
121 [Category ("NotDotNet")]
122 public void AssertTag ()
124 string[] goodAttributes = {
126 "assertuienabled=\"true\"",
127 "assertuienabled=\"false\" logfilename=\"some file name\"",
128 "logfilename=\"some file name\""
130 ValidateSuccess ("#TAT:Good", "<assert {0}/>", goodAttributes);
132 string[] badAttributes = {
133 "AssertUiEnabled=\"true\"",
134 "LogFileName=\"foo\"",
135 "assertuienabled=\"\"",
136 "assertuienabled=\"non-boolean-value\""
138 ValidateExceptions ("#TAT:BadAttrs", "<assert {0}/>", badAttributes);
140 string[] badChildren = {
141 "<any element=\"here\"/>"
143 ValidateExceptions ("#TAT:BadChildren", "<assert>{0}</assert>", badChildren);
147 [Category ("NotDotNet")]
148 public void PerformanceCountersTag ()
150 string[] goodAttributes = {
152 "filemappingsize=\"1048576\"",
153 "filemappingsize=\"0\""
155 ValidateSuccess ("#PCT:Good", "<performanceCounters {0}/>", goodAttributes);
157 string[] badAttributes = {
158 "FileMappingSize=\"1048576\"",
159 "filemappingsize=\"\"",
160 "filemappingsize=\"non-int-value\""
162 ValidateExceptions ("#PCT:BadAttrs", "<performanceCounters {0}/>", badAttributes);
164 string[] badChildren = {
165 "<any element=\"here\"/>"
167 ValidateExceptions ("#PCT:BadChildren", "<performanceCounters>{0}</performanceCounters>", badChildren);
171 [Category ("NotDotNet")]
172 public void TraceTag_Attributes ()
176 "autoflush=\"true\"",
178 "autoflush=\"false\" indentsize=\"10\""
180 ValidateSuccess ("#TTT:A:Good", "<trace {0}/>", good);
183 "AutoFlush=\"true\"",
184 "IndentSize=\"false\"",
185 "autoflush=\"non-boolean-value\"",
187 "indentsize=\"non-integral-value\"",
191 ValidateExceptions ("#TTT:A:Bad", "<trace {0}/>", bad);
195 [Category ("NotDotNet")]
196 public void TraceTag_Children ()
199 // more about listeners in a different function...
202 ValidateSuccess ("#TTT:C:Good", "<trace>{0}</trace>", good);
205 "<listeners with=\"attribute\"/>",
206 "<invalid element=\"here\"/>"
208 ValidateExceptions ("#TTT:C:Bad", "<trace>{0}</trace>", bad);
212 [Category ("NotDotNet")]
213 public void TraceTag_Listeners ()
215 const string format = "<trace><listeners>{0}</listeners></trace>";
218 "<add name=\"foo\" " +
219 "type=\"System.Diagnostics.TextWriterTraceListener, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\" " +
220 "initializeData=\"argument.txt\"/>",
221 "<remove name=\"foo\"/>",
222 "<add name=\"foo\" " +
223 "type=\"System.Diagnostics.TextWriterTraceListener, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\" />",
224 "<remove name=\"foo\"/>"
226 ValidateSuccess ("#TTT:L:Good", format, good);
229 "<invalid tag=\"here\"/>",
230 "<clear with=\"args\"/>",
233 "<remove name=\"foo\" extra=\"arg\"/>",
234 "<add type=\"foo\"/>",
235 "<add name=\"foo\" type=\"invalid-type\"/>",
237 ValidateExceptions ("#TTT:L:Bad", format, bad);