(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System / Test / System.Diagnostics / DiagnosticsConfigurationHandlerTest.cs
blobd3cd929559440bf8244ac5c32e3959a0a4437087
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 using NUnit.Framework;
14 using System;
15 using System.Configuration;
16 using System.Diagnostics;
17 using System.Xml;
19 namespace MonoTests.System.Diagnostics {
21 [TestFixture]
22 public class DiagnosticsConfigurationHandlerTest : Assertion {
24 private const string XmlFormat =
25 "{0}";
27 "<system.diagnostics>" +
28 "{0}" +
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));
46 try {
47 CreateHandler (xml);
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.
54 throw;
56 catch (Exception e) {
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));
71 try {
72 CreateHandler (xml);
74 catch (Exception e) {
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 ();
87 d.LoadXml (xml);
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
96 "<add />",
97 "<add value=\"b\"/>",
98 // too many arguments
99 "<add name=\"a\" value=\"b\" extra=\"c\"/>",
100 // wrong casing
101 "<add Name=\"a\" value=\"b\"/>",
102 "<Add Name=\"a\" value=\"b\"/>",
103 // missing args
104 "<remove />",
105 "<remove value=\"b\"/>",
106 // too many args
107 "<remove name=\"a\" value=\"b\"/>",
108 "<clear name=\"a\"/>",
109 // invalid element
110 "<invalid element=\"a\" here=\"b\"/>"
112 ValidateExceptions ("#TST:IE:Bad", "<switches>{0}</switches>", badElements);
114 string[] goodElements = {
115 "<add name=\"a\" value=\"b\"/>",
116 "<add name=\"a\"/>",
117 "<remove name=\"a\"/>",
118 "<clear/>"
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 ()
151 string[] good = {
153 "autoflush=\"true\"",
154 "indentsize=\"4\"",
155 "autoflush=\"false\" indentsize=\"10\""
157 ValidateSuccess ("#TTT:A:Good", "<trace {0}/>", good);
159 string[] bad = {
160 "AutoFlush=\"true\"",
161 "IndentSize=\"false\"",
162 "autoflush=\"non-boolean-value\"",
163 "autoflush=\"\"",
164 "indentsize=\"non-integral-value\"",
165 "indentsize=\"\"",
166 "extra=\"invalid\""
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 ()
174 string[] good = {
175 // more about listeners in a different function...
176 "<listeners />"
178 ValidateSuccess ("#TTT:C:Good", "<trace>{0}</trace>", good);
180 string[] bad = {
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>";
191 string[] good = {
192 "<clear/>",
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);
203 string[] bad = {
204 "<invalid tag=\"here\"/>",
205 "<clear with=\"args\"/>",
206 "<remove/>",
207 "<add/>",
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);