You've already forked linux-packaging-mono
Imported Upstream version 3.12.0
Former-commit-id: cf92446697332992ec36726e78eb8703e1f259d7
This commit is contained in:
@@ -159,6 +159,30 @@ namespace MonoTests.System.Diagnostics
|
||||
ValidateExceptions ("#TAT:BadChildren", "<assert>{0}</assert>", badChildren);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category ("NotDotNet")]
|
||||
public void PerformanceCountersTag ()
|
||||
{
|
||||
string[] goodAttributes = {
|
||||
"",
|
||||
"filemappingsize=\"1048576\"",
|
||||
"filemappingsize=\"0\""
|
||||
};
|
||||
ValidateSuccess ("#PCT:Good", "<performanceCounters {0}/>", goodAttributes);
|
||||
|
||||
string[] badAttributes = {
|
||||
"FileMappingSize=\"1048576\"",
|
||||
"filemappingsize=\"\"",
|
||||
"filemappingsize=\"non-int-value\""
|
||||
};
|
||||
ValidateExceptions ("#PCT:BadAttrs", "<performanceCounters {0}/>", badAttributes);
|
||||
|
||||
string[] badChildren = {
|
||||
"<any element=\"here\"/>"
|
||||
};
|
||||
ValidateExceptions ("#PCT:BadChildren", "<performanceCounters>{0}</performanceCounters>", badChildren);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category ("NotDotNet")]
|
||||
public void TraceTag_Attributes ()
|
||||
|
@@ -722,7 +722,7 @@ namespace MonoTests.System.Diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
int bytesRead = -1;
|
||||
public int bytesRead = -1;
|
||||
|
||||
#if NET_2_0
|
||||
// Not technically a 2.0 only test, but I use lambdas, so I need gmcs
|
||||
@@ -836,7 +836,7 @@ namespace MonoTests.System.Diagnostics
|
||||
try {
|
||||
var x = p.Handle;
|
||||
Assert.Fail ("Handle should throw for unstated procs, but returned " + x);
|
||||
} catch (InvalidOperationException ex) {
|
||||
} catch (InvalidOperationException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -31,6 +31,8 @@
|
||||
|
||||
#if !MOBILE
|
||||
|
||||
#define TRACE
|
||||
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Text;
|
||||
@@ -43,11 +45,15 @@ namespace MonoTests.System.Diagnostics
|
||||
[TestFixture]
|
||||
public class SourceSwitchTest
|
||||
{
|
||||
internal TraceSource traceSource { get; set; }
|
||||
internal TestTextWriterTraceListener txtTraceListener;
|
||||
|
||||
|
||||
[Test]
|
||||
public void ConstructorNullName ()
|
||||
{
|
||||
SourceSwitch s = new SourceSwitch (null);
|
||||
Assert.IsNull (s.DisplayName);
|
||||
Assert.IsEmpty (s.DisplayName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -98,6 +104,80 @@ namespace MonoTests.System.Diagnostics
|
||||
Assert.IsTrue (s.ShouldTrace (TraceEventType.Resume), "#9");
|
||||
Assert.IsTrue (s.ShouldTrace (TraceEventType.Transfer), "#10");
|
||||
}
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void InitalizeSourceSwitchTest()
|
||||
{
|
||||
// Initializing the TraceSource instance
|
||||
traceSource = new TraceSource ("LoggingTraceSource");
|
||||
traceSource.Listeners.Remove("Default");
|
||||
traceSource.Switch = new SourceSwitch ("MySwitch");
|
||||
|
||||
// Initializing the TraceListener instance
|
||||
txtTraceListener = new TestTextWriterTraceListener (Console.Out);
|
||||
traceSource.Listeners.Add (txtTraceListener);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void setSwitchToCritical()
|
||||
{
|
||||
traceSource.Switch.Level = SourceLevels.Critical;
|
||||
LogAllTraceLevels ();
|
||||
// Switch.Level is Critical so it should log Critical
|
||||
Assert.AreEqual (1, txtTraceListener.TotalMessageCount);
|
||||
Assert.AreEqual (1, txtTraceListener.CritialMessageCount);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void setSwitchToError()
|
||||
{
|
||||
traceSource.Switch.Level = SourceLevels.Error;
|
||||
LogAllTraceLevels ();
|
||||
// Switch.Level is Error so it should log Critical, Error
|
||||
Assert.AreEqual (2, txtTraceListener.TotalMessageCount);
|
||||
Assert.AreEqual (1, txtTraceListener.ErrorMessageCount);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void setSwitchToWarning()
|
||||
{
|
||||
traceSource.Switch.Level = SourceLevels.Warning;
|
||||
LogAllTraceLevels ();
|
||||
// Switch.Level is Warning so it should log Critical, Error, Warning
|
||||
Assert.AreEqual (3, txtTraceListener.TotalMessageCount);
|
||||
Assert.AreEqual (1, txtTraceListener.WarningMessageCount);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void setSwitchToInfo()
|
||||
{
|
||||
traceSource.Switch.Level = SourceLevels.Information;
|
||||
LogAllTraceLevels ();
|
||||
// Switch.Level is Information so it should log Critical, Error, Warning, Information
|
||||
Assert.AreEqual (4, txtTraceListener.TotalMessageCount);
|
||||
Assert.AreEqual (1, txtTraceListener.InfoMessageCount);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void setSwitchToVerbose()
|
||||
{
|
||||
traceSource.Switch.Level = SourceLevels.Verbose;
|
||||
LogAllTraceLevels ();
|
||||
// Switch.Level is Verbose so it should log Critical, Error, Warning, Information, Verbose
|
||||
Assert.AreEqual (5, txtTraceListener.TotalMessageCount);
|
||||
Assert.AreEqual (1, txtTraceListener.VerboseMessageCount);
|
||||
}
|
||||
|
||||
void LogAllTraceLevels ()
|
||||
{
|
||||
traceSource.TraceEvent (TraceEventType.Critical, 123, "Critical Level message.");
|
||||
traceSource.TraceEvent (TraceEventType.Error, 123, "Error Level message.");
|
||||
traceSource.TraceEvent (TraceEventType.Warning, 123, "Warning Level message.");
|
||||
traceSource.TraceEvent (TraceEventType.Information, 123, "Information Level message.");
|
||||
traceSource.TraceEvent (TraceEventType.Verbose, 123, "Verbose Level message.");
|
||||
traceSource.Flush ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -80,6 +80,12 @@ namespace MonoTests.System.Diagnostics {
|
||||
}
|
||||
}
|
||||
|
||||
class TestNullSwitch : Switch {
|
||||
public TestNullSwitch () : base (null, null)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class SwitchesTest {
|
||||
|
||||
@@ -184,8 +190,16 @@ namespace MonoTests.System.Diagnostics {
|
||||
BooleanSwitch s = new BooleanSwitch ("test", "", "hoge");
|
||||
Assert.IsTrue (!s.Enabled);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NullSwitchHasEmptyDisplayNameAndDescription ()
|
||||
{
|
||||
var s = new TestNullSwitch ();
|
||||
Assert.IsEmpty (s.DisplayName);
|
||||
Assert.IsEmpty (s.Description);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@@ -0,0 +1,88 @@
|
||||
// TextWriterTraceListenerHelper.cs -
|
||||
// Test Helper for System.Diagnostics/SourceSwitchTest.cs
|
||||
|
||||
//
|
||||
// Author:
|
||||
// Ramtin Raji Kermani
|
||||
//
|
||||
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if !MOBILE
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace MonoTests.System.Diagnostics
|
||||
{
|
||||
public class TestTextWriterTraceListener: TextWriterTraceListener
|
||||
{
|
||||
public int TotalMessageCount { set; get;}
|
||||
public int CritialMessageCount { get; set;}
|
||||
public int ErrorMessageCount { get; set;}
|
||||
public int WarningMessageCount { get; set;}
|
||||
public int InfoMessageCount { get; set;}
|
||||
public int VerboseMessageCount { set; get;}
|
||||
|
||||
public TestTextWriterTraceListener(TextWriter textWriter): base(textWriter)
|
||||
{
|
||||
Console.WriteLine ("TextWriterTraceListener is instantiated.");
|
||||
}
|
||||
|
||||
|
||||
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
|
||||
{
|
||||
base.TraceEvent (eventCache, source, eventType, id, message);
|
||||
TotalMessageCount++;
|
||||
|
||||
switch (eventType) {
|
||||
case TraceEventType.Critical:
|
||||
CritialMessageCount++; break;
|
||||
case TraceEventType.Error:
|
||||
ErrorMessageCount++; break;
|
||||
case TraceEventType.Warning:
|
||||
WarningMessageCount++; break;
|
||||
case TraceEventType.Information:
|
||||
InfoMessageCount++; break;
|
||||
case TraceEventType.Verbose:
|
||||
VerboseMessageCount++; break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void clearMessageCounters()
|
||||
{
|
||||
TotalMessageCount = 0;
|
||||
CritialMessageCount = 0;
|
||||
WarningMessageCount = 0;
|
||||
ErrorMessageCount = 0;
|
||||
InfoMessageCount = 0;
|
||||
VerboseMessageCount = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user