//
// DiagnosticsConfigurationHandlerTest.cs:
// NUnit Test Cases for System.Diagnostics.DiagnosticsConfigurationHandler
//
// Authors:
// Jonathan Pryor (jonpryor@vt.edu)
// Martin Willemoes Hansen (mwh@sysrq.dk)
//
// (C) Jonathan Pryor
// (C) 2003 Martin Willemoes Hansen
//
#if !MOBILE
using NUnit.Framework;
using System;
using System.Configuration;
using System.Diagnostics;
using System.Xml;
namespace MonoTests.System.Diagnostics
{
[TestFixture]
public class DiagnosticsConfigurationHandlerTest
{
private const string XmlFormat =
"{0}";
/*
"" +
"{0}" +
"";
*/
private DiagnosticsConfigurationHandler handler = new DiagnosticsConfigurationHandler ();
[Test]
[Category ("NotDotNet")]
public void SwitchesTag_Attributes ()
{
string[] attrs = {"invalid=\"yes\""};
ValidateExceptions ("#TST:A", "", attrs);
}
void ValidateExceptions (string name, string format, string[] args)
{
foreach (string arg in args) {
string xml = string.Format (XmlFormat,
string.Format (format, arg));
try {
CreateHandler (xml);
Assert.Fail (string.Format ("{0}:{1}: no exception generated", name, arg));
} catch (ConfigurationException) {
} catch (AssertionException) {
// This is generated by the Assertion.Fail() statement in the try block.
throw;
} catch (Exception e) {
Assert.Fail (string.Format ("{0}:{1}: wrong exception generated: {2} ({3}).",
name, arg, e.ToString(),
e.InnerException == null ? "" : e.InnerException.ToString()));
}
}
}
private void ValidateSuccess (string name, string format, string[] args)
{
foreach (string arg in args) {
string xml = string.Format (XmlFormat,
string.Format (format, arg));
try {
CreateHandler (xml);
} catch (Exception e) {
Assert.Fail (string.Format ("{0}:{1}: exception generated: {2} ({3}).",
name, arg, e.ToString(),
e.InnerException == null ? "" : e.InnerException.ToString()));
}
}
}
private object CreateHandler (string xml)
{
XmlDocument d = new XmlDocument ();
d.LoadXml (xml);
return handler.Create (null, null, d);
}
[Test]
[Category ("NotDotNet")]
public void SwitchesTag_Elements ()
{
string[] badElements = {
// not enough arguments
"",
"",
"",
// too many arguments
"",
// wrong casing
"",
"",
// missing args
"",
"",
// too many args
"",
"",
// invalid element
""
};
ValidateExceptions ("#TST:IE:Bad", "{0}", badElements);
string[] goodElements = {
"",
"",
"",
""
};
ValidateSuccess ("#TST:IE:Good", "{0}", goodElements);
}
[Test]
[Category ("NotDotNet")]
public void AssertTag ()
{
string[] goodAttributes = {
"",
"assertuienabled=\"true\"",
"assertuienabled=\"false\" logfilename=\"some file name\"",
"logfilename=\"some file name\""
};
ValidateSuccess ("#TAT:Good", "", goodAttributes);
string[] badAttributes = {
"AssertUiEnabled=\"true\"",
"LogFileName=\"foo\"",
"assertuienabled=\"\"",
"assertuienabled=\"non-boolean-value\""
};
ValidateExceptions ("#TAT:BadAttrs", "", badAttributes);
string[] badChildren = {
""
};
ValidateExceptions ("#TAT:BadChildren", "{0}", badChildren);
}
[Test]
[Category ("NotDotNet")]
public void PerformanceCountersTag ()
{
string[] goodAttributes = {
"",
"filemappingsize=\"1048576\"",
"filemappingsize=\"0\""
};
ValidateSuccess ("#PCT:Good", "", goodAttributes);
string[] badAttributes = {
"FileMappingSize=\"1048576\"",
"filemappingsize=\"\"",
"filemappingsize=\"non-int-value\""
};
ValidateExceptions ("#PCT:BadAttrs", "", badAttributes);
string[] badChildren = {
""
};
ValidateExceptions ("#PCT:BadChildren", "{0}", badChildren);
}
[Test]
[Category ("NotDotNet")]
public void TraceTag_Attributes ()
{
string[] good = {
"",
"autoflush=\"true\"",
"indentsize=\"4\"",
"autoflush=\"false\" indentsize=\"10\""
};
ValidateSuccess ("#TTT:A:Good", "", good);
string[] bad = {
"AutoFlush=\"true\"",
"IndentSize=\"false\"",
"autoflush=\"non-boolean-value\"",
"autoflush=\"\"",
"indentsize=\"non-integral-value\"",
"indentsize=\"\"",
"extra=\"invalid\""
};
ValidateExceptions ("#TTT:A:Bad", "", bad);
}
[Test]
[Category ("NotDotNet")]
public void TraceTag_Children ()
{
string[] good = {
// more about listeners in a different function...
""
};
ValidateSuccess ("#TTT:C:Good", "{0}", good);
string[] bad = {
"",
""
};
ValidateExceptions ("#TTT:C:Bad", "{0}", bad);
}
[Test]
[Category ("NotDotNet")]
public void TraceTag_Listeners ()
{
const string format = "{0}";
string[] good = {
"",
"",
"",
"",
""
};
ValidateSuccess ("#TTT:L:Good", format, good);
string[] bad = {
"",
"",
"",
"",
"",
"",
"",
};
ValidateExceptions ("#TTT:L:Bad", format, bad);
}
}
}
#endif