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
, Ignore ("DiagnosticsConfigurationHandler is not meant to be used directly on Windows")]
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
, Ignore ("DiagnosticsConfigurationHandler is not meant to be used directly on Windows")]
92 public void SwitchesTag_Elements ()
94 string[] badElements
= {
95 // not enough arguments
99 "<add name=\"a\" value=\"b\" extra=\"c\"/>",
101 "<add Name=\"a\" value=\"b\"/>",
102 "<Add Name=\"a\" value=\"b\"/>",
105 "<remove value=\"b\"/>",
107 "<remove name=\"a\" value=\"b\"/>",
108 "<clear name=\"a\"/>",
110 "<invalid element=\"a\" here=\"b\"/>"
112 ValidateExceptions ("#TST:IE:Bad", "<switches>{0}</switches>", badElements
);
114 string[] goodElements
= {
115 "<add name=\"a\" value=\"b\"/>",
117 "<remove name=\"a\"/>",
120 ValidateSuccess ("#TST:IE:Good", "<switches>{0}</switches>", goodElements
);
123 [Test
, Ignore ("DiagnosticsConfigurationHandler is not meant to be used directly on Windows")]
124 public void AssertTag ()
126 string[] goodAttributes
= {
128 "assertuienabled=\"true\"",
129 "assertuienabled=\"false\" logfilename=\"some file name\"",
130 "logfilename=\"some file name\""
132 ValidateSuccess ("#TAT:Good", "<assert {0}/>", goodAttributes
);
134 string[] badAttributes
= {
135 "AssertUiEnabled=\"true\"",
136 "LogFileName=\"foo\"",
137 "assertuienabled=\"\"",
138 "assertuienabled=\"non-boolean-value\""
140 ValidateExceptions ("#TAT:BadAttrs", "<assert {0}/>", badAttributes
);
142 string[] badChildren
= {
143 "<any element=\"here\"/>"
145 ValidateExceptions ("#TAT:BadChildren", "<assert>{0}</assert>", badChildren
);
148 [Test
, Ignore ("DiagnosticsConfigurationHandler is not meant to be used directly on Windows")]
149 public void TraceTag_Attributes ()
153 "autoflush=\"true\"",
155 "autoflush=\"false\" indentsize=\"10\""
157 ValidateSuccess ("#TTT:A:Good", "<trace {0}/>", good
);
160 "AutoFlush=\"true\"",
161 "IndentSize=\"false\"",
162 "autoflush=\"non-boolean-value\"",
164 "indentsize=\"non-integral-value\"",
168 ValidateExceptions ("#TTT:A:Bad", "<trace {0}/>", bad
);
171 [Test
, Ignore ("DiagnosticsConfigurationHandler is not meant to be used directly on Windows")]
172 public void TraceTag_Children ()
175 // more about listeners in a different function...
178 ValidateSuccess ("#TTT:C:Good", "<trace>{0}</trace>", good
);
181 "<listeners with=\"attribute\"/>",
182 "<invalid element=\"here\"/>"
184 ValidateExceptions ("#TTT:C:Bad", "<trace>{0}</trace>", bad
);
187 [Test
, Ignore ("DiagnosticsConfigurationHandler is not meant to be used directly on Windows")]
188 public void TraceTag_Listeners ()
190 const string format
= "<trace><listeners>{0}</listeners></trace>";
193 "<add name=\"foo\" " +
194 "type=\"System.Diagnostics.TextWriterTraceListener, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\" " +
195 "initializeData=\"argument.txt\"/>",
196 "<remove name=\"foo\"/>",
197 "<add name=\"foo\"" +
198 "type=\"System.Diagnostics.TextWriterTraceListener, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\" />",
199 "<remove name=\"foo\"/>"
201 ValidateSuccess ("#TTT:L:Good", format
, good
);
204 "<invalid tag=\"here\"/>",
205 "<clear with=\"args\"/>",
208 "<remove name=\"foo\" extra=\"arg\"/>",
209 "<add name=\"foo\"/>",
210 "<add type=\"foo\"/>",
211 "<add name=\"foo\" type=\"invalid-type\"/>",
213 ValidateExceptions ("#TTT:L:Bad", format
, bad
);