update readme (#21797)
[mono-project.git] / mcs / class / System / Test / System.Diagnostics / DiagnosticsConfigurationHandlerTest.cs
blob1a4f138306ca602cd5339f10834132562cb4adc2
1 //
2 // DiagnosticsConfigurationHandlerTest.cs:
3 // NUnit Test Cases for System.Diagnostics.DiagnosticsConfigurationHandler
4 //
5 // Authors:
6 // Jonathan Pryor (jonpryor@vt.edu)
7 // Martin Willemoes Hansen (mwh@sysrq.dk)
8 //
9 // (C) Jonathan Pryor
10 // (C) 2003 Martin Willemoes Hansen
11 //
13 #if !MOBILE
15 using NUnit.Framework;
16 using System;
17 using System.Configuration;
18 using System.Diagnostics;
19 using System.Xml;
21 namespace MonoTests.System.Diagnostics
23 [TestFixture]
24 public class DiagnosticsConfigurationHandlerTest
26 private const string XmlFormat =
27 "{0}";
29 "<system.diagnostics>" +
30 "{0}" +
31 "</system.diagnostics>";
34 private DiagnosticsConfigurationHandler handler = new DiagnosticsConfigurationHandler ();
36 [Test]
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));
49 try {
50 CreateHandler (xml);
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.
55 throw;
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));
69 try {
70 CreateHandler (xml);
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 ();
82 d.LoadXml (xml);
83 return handler.Create (null, null, d);
86 [Test]
87 [Category ("NotDotNet")]
88 public void SwitchesTag_Elements ()
90 string[] badElements = {
91 // not enough arguments
92 "<add />",
93 "<add name=\"a\"/>",
94 "<add value=\"b\"/>",
95 // too many arguments
96 "<add name=\"a\" value=\"b\" extra=\"c\"/>",
97 // wrong casing
98 "<add Name=\"a\" value=\"b\"/>",
99 "<Add Name=\"a\" value=\"b\"/>",
100 // missing args
101 "<remove />",
102 "<remove value=\"b\"/>",
103 // too many args
104 "<remove name=\"a\" value=\"b\"/>",
105 "<clear name=\"a\"/>",
106 // invalid element
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\"/>",
115 "<clear/>"
117 ValidateSuccess ("#TST:IE:Good", "<switches>{0}</switches>", goodElements);
120 [Test]
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);
146 [Test]
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);
170 [Test]
171 [Category ("NotDotNet")]
172 public void TraceTag_Attributes ()
174 string[] good = {
176 "autoflush=\"true\"",
177 "indentsize=\"4\"",
178 "autoflush=\"false\" indentsize=\"10\""
180 ValidateSuccess ("#TTT:A:Good", "<trace {0}/>", good);
182 string[] bad = {
183 "AutoFlush=\"true\"",
184 "IndentSize=\"false\"",
185 "autoflush=\"non-boolean-value\"",
186 "autoflush=\"\"",
187 "indentsize=\"non-integral-value\"",
188 "indentsize=\"\"",
189 "extra=\"invalid\""
191 ValidateExceptions ("#TTT:A:Bad", "<trace {0}/>", bad);
194 [Test]
195 [Category ("NotDotNet")]
196 public void TraceTag_Children ()
198 string[] good = {
199 // more about listeners in a different function...
200 "<listeners />"
202 ValidateSuccess ("#TTT:C:Good", "<trace>{0}</trace>", good);
204 string[] bad = {
205 "<listeners with=\"attribute\"/>",
206 "<invalid element=\"here\"/>"
208 ValidateExceptions ("#TTT:C:Bad", "<trace>{0}</trace>", bad);
211 [Test]
212 [Category ("NotDotNet")]
213 public void TraceTag_Listeners ()
215 const string format = "<trace><listeners>{0}</listeners></trace>";
216 string[] good = {
217 "<clear/>",
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);
228 string[] bad = {
229 "<invalid tag=\"here\"/>",
230 "<clear with=\"args\"/>",
231 "<remove/>",
232 "<add/>",
233 "<remove name=\"foo\" extra=\"arg\"/>",
234 "<add type=\"foo\"/>",
235 "<add name=\"foo\" type=\"invalid-type\"/>",
237 ValidateExceptions ("#TTT:L:Bad", format, bad);
242 #endif