Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,299 @@
2009-06-26 Robert Jordan <robertj@gmx.net>
* SwitchesTest.cs, TraceTest.cs: Upgrade to new NUnit style.
2009-02-24 Andrés G. Aragoneses <aaragoneses@novell.com>
* Process.cs: New tests for bug 477943.
2008-12-30 Raja R Harinath <harinath@hurrynot.org>
* ProcessTest.cs: Import System.Threading namespace.
2008-12-25 Miguel de Icaza <miguel@novell.com>
* ProcessTest.cs: Created a test case from bug 459450.
2008-10-18 Gert Driesen <drieseng@users.sourceforge.net>
* EventLogTest.cs: Fixed compiler warning.
2008-08-02 Gert Driesen <drieseng@users.sourceforge.net>
* TraceListenerTest.cs: Added test for GetSupportedAttributes.
2008-06-21 Robert Jordan <robertj@gmx.net>
* ProcessTest.cs (Start_UseShellExecuteWithEmptyUserName):
add test for bug #350543.
2008-06-11 Atsushi Enomoto <atsushi@ximian.com>
* FileVersionInfoTest.cs : disabled all English-Windows-dependent
tests. They all fail on Windows whose language is not English.
In general, be careful to compare language-dependent strings.
2008-05-02 Zoltan Varga <vargaz@gmail.com>
* TraceTest.cs: Add a test for #385666.
2008-04-18 Gert Driesen <drieseng@users.sourceforge.net>
* FileVerionInfoTest.cs: Enabled test for bug #374600.
2008-03-29 Gert Driesen <drieseng@users.sourceforge.net>
* FileVersionInfoTest.cs: Enabled tests that previously failed.
Increase code coverage.
2008-01-23 Gert Driesen <drieseng@users.sourceforge.net>
* FileVersionInfoTest.cs: Added set of (mostly notworking) tests for
FileVersionInfo, and indirectly also for AssemblyBuilder.
2007-12-22 Gert Driesen <drieseng@users.sourceforge.net>
* ProcessTest.cs: Added tests for PriorityClass.
2007-12-04 Gert Driesen <drieseng@users.sourceforge.net>
* ProcessTest.cs: Added tests for Start overloads.
2007-11-02 Robert Jordan <robertj@gmx.net>
* ProcessTest.cs (TestRedirectedOutputIsAsync):
Comment out the failing asserts until I've found out why they are
failing.
2007-11-02 Robert Jordan <robertj@gmx.net>
* ProcessTest.cs (TestRedirectedOutputIsAsync):
Wait for the pending async operation.
2007-11-02 Robert Jordan <robertj@gmx.net>
* ProcessTest.cs (TestRedirectedOutputIsAsync):
Instrument to see why the build bots are failing.
2007-11-01 Robert Jordan <robertj@gmx.net>
* ProcessTest.cs (TestRedirectedOutputIsAsync):
Replace the generated script with a simple one (command line based).
Add additional assert for Process.ExitCode == 0.
2007-10-30 Robert Jordan <robertj@gmx.net>
* ProcessTest.cs: Add tests for bug #319829.
2007-10-21 Gert Driesen <drieseng@users.sourceforge.net>
* SwitchesTest.cs: Fixed compiler warning.
2007-09-22 Gert Driesen <drieseng@users.sourceforge.net>
* DiagnosticsConfigurationHandlerTest.cs: No longer derive from
deprecated Assertion class. Code formatting. On 2.0 profile, allow
non-integral values for switches.
2007-08-14 Gert Driesen <drieseng@users.sourceforge.net>
* EventLogTest.cs: Added tests for validity of machine name. Added
tests for case-insensitivity of Source, Log and MachineName.
2007-08-06 Atsushi Enomoto <atsushi@ximian.com>
* ProcessStartInfoTest.cs: tests for Standard[Output|Error]Encoding.
2007-07-11 Ankit Jain <jankit@novell.com>
* ProcessStartInfoTest.cs: New.
2007-05-19 Atsushi Enomoto <atsushi@ximian.com>
* DelimitedListTraceListenerTest.cs : new test.
2007-05-17 Atsushi Enomoto <atsushi@ximian.com>
* SwitchesTest.cs : added tests for BooleanSwitch Value.
* TraceListenerTest.cs : added test for TraceOutputOptions.
2007-05-14 Atsushi Enomoto <atsushi@ximian.com>
* DiagnosticsConfigurationHandlerTest.cs : in 2.0 configuration item
listeners/add/@type is optional (for named shared listener support).
2007-04-19 Atsushi Enomoto <atsushi@ximian.com>
* TraceListenerTest.cs : new test.
* XmlWriterTraceListenerTest.cs : new test (but disabled since they
are too instance dependent).
2007-01-18 Atsushi Enomoto <atsushi@ximian.com>
* TraceSourceTest.cs, SourceSwitchTest.cs : new tests.
* SwitchesTest.cs : added test for GetSupportedAttributes().
2007-01-02 Gert Driesen <drieseng@users.sourceforge.net>
* ProcessTest.cs: Added null check tests.
2006-08-27 Gert Driesen <drieseng@users.sourceforge.net>
* EventLogTest.cs: Added tests for log name validation in
CreateEventSource.
2006-08-26 Gert Driesen <drieseng@users.sourceforge.net>
* EventLogTest.cs: Use a dedicated temp directory for testing the
local file implementation (2.0 only).
2006-08-20 Gert Driesen <drieseng@users.sourceforge.net>
* EventInstanceTest.cs: Added tests for EventInstance.
2006-08-20 Gert Driesen <drieseng@users.sourceforge.net>
* EventLogTest.cs: Enable tests. On 2.0 profile, set MONO_EVENTLOG_TYPE
environment variable to force local file implementation to be used for
unit tests. This avoids permission issues for the unit tests, and
allows us to clean up the files/directory that are created during the
test run. Skip tests that cannot pass when the null implementation is
active (on 1.0 profile). Added tests for all WriteEntry and WriteEvent
(2.0 only) overloads, Clear, Entries, Exists and LogNameFromSourceName.
2006-08-11 Gert Driesen <drieseng@users.sourceforge.net>
* EventLogTest.cs: new test, currently not enabled due to UnixRegistry
bug which still needs to be tracked, and which would cause temporary
registry entries to be left behind by running tests.
2006-08-09 Gert Driesen <drieseng@users.sourceforge.net>
* EventSourceCreationDataTest.cs: new test.
2006-05-17 Atsushi Enomoto <atsushi@ximian.com>
* SwitchesTest.cs : Ignore NewSwitch under 2.0 as it fails under
.NET.
2006-04-04 Atsushi Enomoto <atsushi@ximian.com>
* StopwatchTest.cs : new test.
2005-09-22 Sebastien Pouliot <sebastien@ximian.com>
* EventLogPermissionAttributeTest.cs: Removed *Choice security actions
* PerformanceCounterPermissionAttributeTest.cs: Removed *Choice
security actions.
2005-06-10 Gert Driesen <drieseng@users.sourceforge.net>
* TraceTest.cs: Fixed test failure.
2005-05-31 Sebastien Pouliot <sebastien@ximian.com>
* EventLogPermissionAttributeTest.cs: Character #133 is refused into
machine names for 2.0.
* EventLogPermissionTest.csFx 2.0 now has better arguments checking
(i.e. FDBK15131 was fixed).
* PerformanceCounterPermissionAttributeTest.cs
* PerformanceCounterPermissionTest.cs: Fx 2.0 now has better arguments
checking (i.e. FDBK15131 was fixed).
2005-02-22 Jonathan Pryor <jonpryor@vt.edu>
* TraceTest.cs: Add multi-thread test for #69964.
2005-01-19 Sebastien Pouliot <sebastien@ximian.com>
* EventLogPermissionTest.cs: Now works on both Fx 1.1 / 2.0.
* PerformanceCounterPermissionTest.cs: Now works on both Fx 1.1 / 2.0.
2005-01-18 Jonathan Pryor <jonpryor@vt.edu>
* DiagnosticsConfigurationHandlerTest.cs: .NET 1.1 requires that the value
attribute be a numeric value; check for that and update the success test
so that they'll actually pass.
* SwitchesTest.cs: TestNewSwitch reads "custom-switch" now, and the switches
value is now "42", not "0". Remove warning about unused variable.
2005-01-17 Jonathan Pryor <jonpryor@vt.edu>
* DiagnosticsConfigurationHandlerTest.cs: .NET 1.1 doesn't permit <add/>
elements without a value attribute. Assert the same under Mono.
2005-01-17 Jonathan Pryor <jonpryor@vt.edu>
* DiagnosticsConfigurationHandlerTest.cs: Don't ignore tests, instead mark
them as [Category ("NotDotNet")]; Fix the TraceTag_Listeners example (it
was passing invalid XML in a "valid" test).
2005-01-08 Nick Drochak <ndrochak@ieee.org>
* EventLogPermissionTest.cs
* PerformanceCounterPermissionTest.cs: Make tests pass on MS.NET.
2004-09-11 Sebastien Pouliot <sebastien@ximian.com>
* EventLogPermissionTest.cs: New. Unit tests for EventLogPermission.
* PerformanceCounterPermissionTest.cs: New. Unit tests for
PerformanceCounterPermission.
2004-09-10 Sebastien Pouliot <sebastien@ximian.com>
* EventLogPermissionAttributeTest.cs: New. Unit tests for
EventLogPermissionAttribute.
* PerformanceCounterPermissionAttributeTest.cs: New. Unit tests for
PerformanceCounterPermissionAttribute.
2004-02-05 Nick Drochak <ndrochak@gol.com>
* DiagnosticsConfigurationHandlerTest.cs: Ignore tests using classes not
meant to be used directly.
2003-12-30 Nick Drochak <ndrochak@gol.com>
* DiagnosticsConfigurationHandlerTest.cs: Inherit from Assertion to
make it a bit simpler.
* SwitchesTest.cs: Make the tests pass on .NET 1.1
2003-03-25 Nick Drochak <ndrochak@gol.com>
* DiagnosticsConfigurationHandlerTest.cs: Fix compiler warnings
2002-12-20 Jonathan Pryor <jonpryor@vt.edu>
* AllTests.cs: Add new tests
* SwitchesTest.cs: new file to test switches
* DiagnosticsConfigurationHandlerTest.cs: new file to test
DiagnosticsConfigurationHandler
* TraceTest.cs: Make sure that IndentLevel and IndentSize are set
appropriately before testing output.
2002-09-23 Nick Drochak <ndrochak@gol.com>
* TraceTest.cs: Default level and size are 0 & 4, respectively.
2002-09-19 Nick Drochak <ndrochak@gol.com>
* TraceTest.cs: Clear list of listeners before each test.
2002-09-17 Nick Drochak <ndrochak@gol.com>
* TraceTest.cs: Remove extraneous Console.WriteLine().
2002-06-16 Jonathan Pryor <jonpryor@vt.edu>
* TraceTest.cs: Added additional test cases.
2002-04-07 Jonathan Pryor <jonpryor@vt.edu>
* TraceTest.cs: Removed extraneous output; renamed test case so that NUnit
would find it.
2002-03-10 Jonathan Pryor <jonpryor@vt.edu>
* Initial creation of System.Diagnostics test directory
* AllTests.cs: file added
* TraceTest.cs: Test System.Diagnostics.Trace class

View File

@@ -0,0 +1,50 @@
//
// CounterCreationDataTest.cs -
// NUnit Test Cases for CounterCreationData
//
// Author:
// Christian Hergert <christian.hergert@gmail.com>
//
// Copyright (C) 2008 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 NUnit.Framework;
using System;
using System.Diagnostics;
namespace MonoTests.System.Diagnostics {
[TestFixture]
public class CounterCreationDataTest {
[Test]
public void CounterHelp_Empty () {
CounterCreationData dc = new CounterCreationData();
dc.CounterType = PerformanceCounterType.NumberOfItems32;
dc.CounterName = "Foo";
Assert.AreEqual (dc.CounterHelp, String.Empty);
}
}
}
#endif

View File

@@ -0,0 +1,69 @@
//
// MonoTests.System.Diagnostics.DebugTest.cs
//
// Author:
// John R. Hicks (angryjohn69@nc.rr.com)
//
// (C) 2002
using System;
using System.Diagnostics;
using NUnit.Framework;
namespace MonoTests.System.Diagnostics
{
[TestFixture]
public class DebugTest2
{
DefaultTraceListener listener = new DefaultTraceListener ();
[SetUp]
protected void SetUp()
{
Debug.Listeners.Add(listener);
}
[TearDown]
protected void TearDown()
{
Debug.Listeners.Remove (listener);
}
[Test]
public void TestAssert()
{
Debug.Assert(false, "Testing Assertions");
}
[Test]
public void TestFail ()
{
Debug.Fail("Testing Fail method");
}
[Test]
public void TestWrite()
{
Debug.Write("Testing Write", "Testing the output of the Write method");
}
[Test]
public void TestWriteIf()
{
Debug.WriteIf(true, "Testing WriteIf");
Debug.WriteIf(false, "Testing WriteIf", "Passed false");
}
[Test]
public void TestWriteLine()
{
Debug.WriteLine("Testing WriteLine method");
}
[Test]
public void TestWriteLineIf()
{
Debug.WriteLineIf(true, "Testing WriteLineIf");
Debug.WriteLineIf(false, "Testing WriteLineIf", "Passed false");
}
}
}

View File

@@ -0,0 +1,141 @@
//
// DelimitedListTraceListenerTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2007 Novell, Inc.
//
//
// 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 NUnit.Framework;
using System;
using System.IO;
using System.Diagnostics;
using System.Threading;
namespace MonoTests.System.Diagnostics
{
[TestFixture]
public class DelimitedListTraceListenerTest
{
#if NET_2_0
string sample1 = "sample\n";
string sample2 = ";Error;4;;;;;;;;\n";
string sample3 = "\"bulldog\";Error;5;;;;;;;;\n\"bulldog\";Error;3;\"test event arg:arg1\";;;;;;;\n";
string sample4 = ";Error;2;;;;;;;;\n;Error;3;;;;;;;;\n";
string sample5 = ";Error;7;;\"XYZ\";;;;;;\n;Error;7;;\"ABC\",\"DEF\",\"123\";;;;;;\n";
string sample6 = "\"my name is \"\"tricky\"\"\";Transfer;0;\"hoge;hoge, relatedActivityId=00000000-0000-0000-0000-000000000000\";;;;;;;\n";
string sample7 = "Fail: error summary error details\n";
[Test]
public void WriteLine1 ()
{
StringWriter sw = new StringWriter ();
DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
x.WriteLine ("sample");
x.Close ();
Assert.AreEqual (sample1, sw.ToString ().Replace ("\r\n", "\n"));
}
[Test]
public void TraceEvent1 ()
{
StringWriter sw = new StringWriter ();
DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
x.TraceEvent (null, null, TraceEventType.Error, 4, null);
x.Close ();
Assert.AreEqual (sample2, sw.ToString ().Replace ("\r\n", "\n"));
}
[Test]
public void TraceEvent2 ()
{
StringWriter sw = new StringWriter ();
DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
x.TraceEvent (null, "bulldog", TraceEventType.Error, 5);
x.TraceEvent (null, "bulldog", TraceEventType.Error, 3, "test event arg:{0}", "arg1");
x.Close ();
Assert.AreEqual (sample3, sw.ToString ().Replace ("\r\n", "\n"));
}
[Test]
public void TraceDataWithCache1 ()
{
StringWriter sw = new StringWriter ();
DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
Trace.CorrelationManager.StartLogicalOperation ("op1"); // ... irrelevant?
TraceEventCache cc = new TraceEventCache ();
x.TraceData (cc, null, TraceEventType.Error, 2);
x.TraceData (cc, null, TraceEventType.Error, 3);
Trace.CorrelationManager.StopLogicalOperation ();
x.Close ();
Assert.AreEqual (sample4, sw.ToString ().Replace ("\r\n", "\n"));
}
[Test]
public void TraceDataWithCache2 ()
{
StringWriter sw = new StringWriter ();
DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
TraceEventCache cc = new TraceEventCache ();
x.TraceData (cc, null, TraceEventType.Error, 7, "XYZ");
x.TraceData (cc, null, TraceEventType.Error, 7, "ABC", "DEF", 123);
x.Close ();
Assert.AreEqual (sample5, sw.ToString ().Replace ("\r\n", "\n"));
}
[Test]
public void TraceTransfer1 ()
{
StringWriter sw = new StringWriter ();
DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
x.TraceTransfer (null, "my name is \"tricky\"", 0, "hoge;hoge", Guid.Empty);
x.Close ();
Assert.AreEqual (sample6, sw.ToString ().Replace ("\r\n", "\n"));
}
[Test]
[Category ("NotWorking")]
public void Fail1 ()
{
StringWriter sw = new StringWriter ();
DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
TraceEventCache cc = new TraceEventCache ();
x.Fail ("error summary", "error details");
x.Close ();
Assert.AreEqual (sample7, sw.ToString ().Replace ("\r\n", "\n"));
}
#endif
}
}
#endif

View File

@@ -0,0 +1,238 @@
//
// 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}";
/*
"<system.diagnostics>" +
"{0}" +
"</system.diagnostics>";
*/
private DiagnosticsConfigurationHandler handler = new DiagnosticsConfigurationHandler ();
[Test]
[Category ("NotDotNet")]
public void SwitchesTag_Attributes ()
{
string[] attrs = {"invalid=\"yes\""};
ValidateExceptions ("#TST:A", "<switches {0}></switches>", 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
"<add />",
"<add name=\"a\"/>",
"<add value=\"b\"/>",
#if !NET_2_0
// in the 2.0 profile, we currently allow non-integral
// values
//
// MS actually introduced new configuration classes
// for the 2.0 profile and did not modify the original
// classes
//
// Once we add 2.0 configuration classes for
// system.diagnostics, the origina behavior should
// be restored and this test should be enabled again
// for the 2.0 profile
// non-integral value
"<add name=\"string-value\" value=\"string-value\"/>",
#endif
// too many arguments
"<add name=\"a\" value=\"b\" extra=\"c\"/>",
// wrong casing
"<add Name=\"a\" value=\"b\"/>",
"<Add Name=\"a\" value=\"b\"/>",
// missing args
"<remove />",
"<remove value=\"b\"/>",
// too many args
"<remove name=\"a\" value=\"b\"/>",
"<clear name=\"a\"/>",
// invalid element
"<invalid element=\"a\" here=\"b\"/>"
};
ValidateExceptions ("#TST:IE:Bad", "<switches>{0}</switches>", badElements);
string[] goodElements = {
"<add name=\"a\" value=\"4\"/>",
"<add name=\"a\" value=\"-2\"/>",
"<remove name=\"a\"/>",
"<clear/>"
};
ValidateSuccess ("#TST:IE:Good", "<switches>{0}</switches>", goodElements);
}
[Test]
[Category ("NotDotNet")]
public void AssertTag ()
{
string[] goodAttributes = {
"",
"assertuienabled=\"true\"",
"assertuienabled=\"false\" logfilename=\"some file name\"",
"logfilename=\"some file name\""
};
ValidateSuccess ("#TAT:Good", "<assert {0}/>", goodAttributes);
string[] badAttributes = {
"AssertUiEnabled=\"true\"",
"LogFileName=\"foo\"",
"assertuienabled=\"\"",
"assertuienabled=\"non-boolean-value\""
};
ValidateExceptions ("#TAT:BadAttrs", "<assert {0}/>", badAttributes);
string[] badChildren = {
"<any element=\"here\"/>"
};
ValidateExceptions ("#TAT:BadChildren", "<assert>{0}</assert>", badChildren);
}
[Test]
[Category ("NotDotNet")]
public void TraceTag_Attributes ()
{
string[] good = {
"",
"autoflush=\"true\"",
"indentsize=\"4\"",
"autoflush=\"false\" indentsize=\"10\""
};
ValidateSuccess ("#TTT:A:Good", "<trace {0}/>", good);
string[] bad = {
"AutoFlush=\"true\"",
"IndentSize=\"false\"",
"autoflush=\"non-boolean-value\"",
"autoflush=\"\"",
"indentsize=\"non-integral-value\"",
"indentsize=\"\"",
"extra=\"invalid\""
};
ValidateExceptions ("#TTT:A:Bad", "<trace {0}/>", bad);
}
[Test]
[Category ("NotDotNet")]
public void TraceTag_Children ()
{
string[] good = {
// more about listeners in a different function...
"<listeners />"
};
ValidateSuccess ("#TTT:C:Good", "<trace>{0}</trace>", good);
string[] bad = {
"<listeners with=\"attribute\"/>",
"<invalid element=\"here\"/>"
};
ValidateExceptions ("#TTT:C:Bad", "<trace>{0}</trace>", bad);
}
[Test]
[Category ("NotDotNet")]
public void TraceTag_Listeners ()
{
const string format = "<trace><listeners>{0}</listeners></trace>";
string[] good = {
"<clear/>",
"<add name=\"foo\" " +
"type=\"System.Diagnostics.TextWriterTraceListener, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\" " +
"initializeData=\"argument.txt\"/>",
"<remove name=\"foo\"/>",
"<add name=\"foo\" " +
"type=\"System.Diagnostics.TextWriterTraceListener, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\" />",
"<remove name=\"foo\"/>"
};
ValidateSuccess ("#TTT:L:Good", format, good);
string[] bad = {
"<invalid tag=\"here\"/>",
"<clear with=\"args\"/>",
"<remove/>",
"<add/>",
"<remove name=\"foo\" extra=\"arg\"/>",
#if NET_2_0 // type is optional (it could indicate a named listener)
#else
"<add name=\"foo\"/>",
#endif
"<add type=\"foo\"/>",
"<add name=\"foo\" type=\"invalid-type\"/>",
};
ValidateExceptions ("#TTT:L:Bad", format, bad);
}
}
}
#endif

View File

@@ -0,0 +1,322 @@
//
// EventInstanceTest.cs -
// NUnit Test Cases for System.Diagnostics.EvenInstance
//
// Author:
// Gert Driesen <driesen@users.sourceforge.net>
//
// 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.ComponentModel;
using System.Diagnostics;
using NUnit.Framework;
namespace MonoTests.System.Diagnostics
{
[TestFixture]
public class EventInstanceTest
{
[Test]
public void Constructor1 ()
{
EventInstance ei = null;
ei = new EventInstance (5, 10);
Assert.AreEqual (10, ei.CategoryId, "#A1");
Assert.AreEqual (5, ei.InstanceId, "#A2");
Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#A3");
ei = new EventInstance (0, 0);
Assert.AreEqual (0, ei.CategoryId, "#B1");
Assert.AreEqual (0, ei.InstanceId, "#B2");
Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#B3");
ei = new EventInstance (uint.MaxValue, ushort.MaxValue);
Assert.AreEqual (ushort.MaxValue, ei.CategoryId, "#C1");
Assert.AreEqual (uint.MaxValue, ei.InstanceId, "#C2");
Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#C3");
}
[Test]
public void Constructor1_InstanceId_Invalid ()
{
try {
new EventInstance (-1, 10);
Assert.Fail ("#A1");
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNotNull (ex.Message, "#A3");
Assert.IsNull (ex.InnerException, "#A4");
}
try {
new EventInstance ((long) uint.MaxValue + 1, 10);
Assert.Fail ("#B1");
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
Assert.IsNotNull (ex.Message, "#B3");
Assert.IsNull (ex.InnerException, "#B4");
}
}
[Test]
public void Constructor1_CategoryId_Invalid ()
{
try {
new EventInstance (5, -1);
Assert.Fail ("#A1");
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNotNull (ex.Message, "#A3");
Assert.IsNull (ex.InnerException, "#A4");
}
try {
new EventInstance (5, ushort.MaxValue + 1);
Assert.Fail ("#A1");
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNotNull (ex.Message, "#A3");
Assert.IsNull (ex.InnerException, "#A4");
}
}
[Test]
public void Constructor2 ()
{
EventInstance ei = null;
ei = new EventInstance (5, 10, EventLogEntryType.Information);
Assert.AreEqual (10, ei.CategoryId, "#A1");
Assert.AreEqual (5, ei.InstanceId, "#A2");
Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#A3");
ei = new EventInstance (0, 0, EventLogEntryType.Error);
Assert.AreEqual (0, ei.CategoryId, "#B1");
Assert.AreEqual (0, ei.InstanceId, "#B2");
Assert.AreEqual (EventLogEntryType.Error, ei.EntryType, "#B3");
ei = new EventInstance (uint.MaxValue, ushort.MaxValue,
EventLogEntryType.Warning);
Assert.AreEqual (ushort.MaxValue, ei.CategoryId, "#C1");
Assert.AreEqual (uint.MaxValue, ei.InstanceId, "#C2");
Assert.AreEqual (EventLogEntryType.Warning, ei.EntryType, "#C3");
}
[Test]
public void Constructor2_InstanceId_Invalid ()
{
try {
new EventInstance (-1, 10, EventLogEntryType.Error);
Assert.Fail ("#A1");
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNotNull (ex.Message, "#A3");
Assert.IsNull (ex.InnerException, "#A4");
}
try {
new EventInstance ((long) uint.MaxValue + 1, 10,
EventLogEntryType.Error);
Assert.Fail ("#B1");
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
Assert.IsNotNull (ex.Message, "#B3");
Assert.IsNull (ex.InnerException, "#B4");
}
}
[Test]
public void Constructor2_CategoryId_Invalid ()
{
try {
new EventInstance (5, -1, EventLogEntryType.Error);
Assert.Fail ("#A1");
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNotNull (ex.Message, "#A3");
Assert.IsNull (ex.InnerException, "#A4");
}
try {
new EventInstance (5, (int) ushort.MaxValue + 1, EventLogEntryType.Error);
Assert.Fail ("#A1");
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNotNull (ex.Message, "#A3");
Assert.IsNull (ex.InnerException, "#A4");
}
}
[Test]
[ExpectedException (typeof (InvalidEnumArgumentException))] // Enum argument value 666 is not valid for type. type should be a value from EventLogEntryType.
public void Constructor2_EntryType_Invalid ()
{
new EventInstance (5, 5, (EventLogEntryType) 666);
}
[Test]
public void CategoryId ()
{
EventInstance ei = new EventInstance (5, 10);
ei.CategoryId = 0;
Assert.AreEqual (0, ei.CategoryId, "#1");
ei.CategoryId = 5;
Assert.AreEqual (5, ei.CategoryId, "#2");
ei.CategoryId = ushort.MaxValue;
Assert.AreEqual (ushort.MaxValue, ei.CategoryId, "#3");
ei.CategoryId = 0;
Assert.AreEqual (0, ei.CategoryId, "#4");
Assert.AreEqual (5, ei.InstanceId, "#5");
}
[Test]
public void CategoryId_Invalid ()
{
EventInstance ei = new EventInstance (5, 10, EventLogEntryType.Error);
try {
ei.CategoryId = -1;
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNotNull (ex.Message, "#A3");
Assert.IsNull (ex.InnerException, "#A4");
}
try {
ei.CategoryId = (int) ushort.MaxValue + 1;
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNotNull (ex.Message, "#A3");
Assert.IsNull (ex.InnerException, "#A4");
}
Assert.AreEqual (10, ei.CategoryId, "#C1");
Assert.AreEqual (EventLogEntryType.Error, ei.EntryType, "#C2");
Assert.AreEqual (5, ei.InstanceId, "#C2");
}
[Test]
public void InstanceId ()
{
EventInstance ei = new EventInstance (5, 10);
ei.InstanceId = 0;
Assert.AreEqual (0, ei.InstanceId, "#1");
ei.InstanceId = 5;
Assert.AreEqual (5, ei.InstanceId, "#2");
ei.InstanceId = uint.MaxValue;
Assert.AreEqual (uint.MaxValue, ei.InstanceId, "#3");
ei.InstanceId = 0;
Assert.AreEqual (0, ei.InstanceId, "#4");
Assert.AreEqual (10, ei.CategoryId, "#5");
}
[Test]
public void InstanceId_Invalid ()
{
EventInstance ei = new EventInstance (5, 10, EventLogEntryType.Error);
try {
ei.InstanceId = -1;
Assert.Fail ("#A1");
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNotNull (ex.Message, "#A3");
Assert.IsNull (ex.InnerException, "#A4");
}
try {
ei.InstanceId = (long) uint.MaxValue + 1;
Assert.Fail ("#B1");
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
Assert.IsNotNull (ex.Message, "#B3");
Assert.IsNull (ex.InnerException, "#B4");
}
Assert.AreEqual (10, ei.CategoryId, "#C1");
Assert.AreEqual (EventLogEntryType.Error, ei.EntryType, "#C2");
Assert.AreEqual (5, ei.InstanceId, "#C3");
}
[Test]
public void EntryType ()
{
EventInstance ei = new EventInstance (5, 10, EventLogEntryType.Error);
ei.EntryType = EventLogEntryType.Warning;
Assert.AreEqual (EventLogEntryType.Warning, ei.EntryType, "#1");
ei.EntryType = EventLogEntryType.FailureAudit;
Assert.AreEqual (EventLogEntryType.FailureAudit, ei.EntryType, "#2");
ei.EntryType = EventLogEntryType.SuccessAudit;
Assert.AreEqual (EventLogEntryType.SuccessAudit, ei.EntryType, "#3");
ei.EntryType = EventLogEntryType.Information;
Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#4");
Assert.AreEqual (5, ei.InstanceId, "#5");
Assert.AreEqual (10, ei.CategoryId, "#6");
}
[Test]
public void EntryType_Invalid ()
{
EventInstance ei = new EventInstance (5, 10, EventLogEntryType.Error);
try {
ei.EntryType = (EventLogEntryType) 666;
Assert.Fail ("#A1");
} catch (InvalidEnumArgumentException ex) {
// The value of argument 'value' (666) is invalid for Enum type
// 'EventLogEntryType'
Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#A2");
Assert.IsNotNull (ex.Message, "#A3");
Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#A4");
Assert.IsTrue (ex.Message.IndexOf ("value") != -1, "#A5");
Assert.IsTrue (ex.Message.IndexOf ("EventLogEntryType") != -1, "#A6");
Assert.IsNull (ex.InnerException, "#A7");
}
try {
ei.EntryType = new EventLogEntryType ();
Assert.Fail ("#B1");
} catch (InvalidEnumArgumentException ex) {
// The value of argument 'value' (0) is invalid for Enum type
// 'EventLogEntryType'
Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#B2");
Assert.IsNotNull (ex.Message, "#B3");
Assert.IsTrue (ex.Message.IndexOf ("0") != -1, "#B4");
Assert.IsTrue (ex.Message.IndexOf ("value") != -1, "#B5");
Assert.IsTrue (ex.Message.IndexOf ("EventLogEntryType") != -1, "#B6");
Assert.IsNull (ex.InnerException, "#B7");
}
Assert.AreEqual (10, ei.CategoryId, "#C1");
Assert.AreEqual (EventLogEntryType.Error, ei.EntryType, "#C2");
Assert.AreEqual (5, ei.InstanceId, "#C3");
}
}
}
#endif

View File

@@ -0,0 +1,199 @@
//
// EventLogPermissionAttributeTest.cs -
// NUnit Test Cases for EventLogPermissionAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004-2005 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 NUnit.Framework;
using System;
using System.Diagnostics;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
namespace MonoTests.System.Diagnostics {
[TestFixture]
public class EventLogPermissionAttributeTest {
[Test]
public void Default ()
{
EventLogPermissionAttribute a = new EventLogPermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
Assert.IsFalse (a.Unrestricted, "Unrestricted");
Assert.AreEqual (".", a.MachineName, "MachineName");
#if NET_2_0
Assert.AreEqual (EventLogPermissionAccess.Write, a.PermissionAccess, "PermissionAccess");
#else
Assert.AreEqual (EventLogPermissionAccess.Browse, a.PermissionAccess, "PermissionAccess");
#endif
EventLogPermission sp = (EventLogPermission)a.CreatePermission ();
Assert.IsFalse (sp.IsUnrestricted (), "IsUnrestricted");
}
[Test]
public void Action ()
{
EventLogPermissionAttribute a = new EventLogPermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
a.Action = SecurityAction.Demand;
Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
a.Action = SecurityAction.Deny;
Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
a.Action = SecurityAction.InheritanceDemand;
Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
a.Action = SecurityAction.LinkDemand;
Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
a.Action = SecurityAction.PermitOnly;
Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
a.Action = SecurityAction.RequestMinimum;
Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
a.Action = SecurityAction.RequestOptional;
Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
a.Action = SecurityAction.RequestRefuse;
Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
}
[Test]
public void Action_Invalid ()
{
EventLogPermissionAttribute a = new EventLogPermissionAttribute ((SecurityAction)Int32.MinValue);
// no validation in attribute
}
[Test]
public void Unrestricted ()
{
EventLogPermissionAttribute a = new EventLogPermissionAttribute (SecurityAction.Assert);
a.Unrestricted = true;
EventLogPermission wp = (EventLogPermission)a.CreatePermission ();
Assert.IsTrue (wp.IsUnrestricted (), "IsUnrestricted");
a.Unrestricted = false;
wp = (EventLogPermission)a.CreatePermission ();
Assert.IsFalse (wp.IsUnrestricted (), "!IsUnrestricted");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void MachineName_Null ()
{
EventLogPermissionAttribute a = new EventLogPermissionAttribute (SecurityAction.Assert);
a.MachineName = null;
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void MachineName_Empty ()
{
EventLogPermissionAttribute a = new EventLogPermissionAttribute (SecurityAction.Assert);
a.MachineName = String.Empty;
}
[Test]
public void MachineName ()
{
EventLogPermissionAttribute a = new EventLogPermissionAttribute (SecurityAction.Assert);
for (int i=0; i < 256; i++) {
try {
a.MachineName = Convert.ToChar (i).ToString ();
Assert.AreEqual (i, (int)a.MachineName [0], i.ToString ());
}
catch {
switch (i) {
case 9:
case 10:
case 11:
case 12:
case 13:
case 32:
case 92:
#if NET_2_0
case 133:
#endif
case 160:
// known invalid chars
break;
default:
Assert.Fail (i.ToString());
break;
}
}
}
// all first 256 characters seems to be valid
// is there other rules ?
}
[Test]
public void PermissionAccess ()
{
EventLogPermissionAttribute a = new EventLogPermissionAttribute (SecurityAction.Assert);
a.PermissionAccess = EventLogPermissionAccess.Audit;
Assert.AreEqual (EventLogPermissionAccess.Audit, a.PermissionAccess, "Audit");
a.PermissionAccess = EventLogPermissionAccess.Browse;
Assert.AreEqual (EventLogPermissionAccess.Browse, a.PermissionAccess, "Browse");
a.PermissionAccess = EventLogPermissionAccess.Instrument;
Assert.AreEqual (EventLogPermissionAccess.Instrument, a.PermissionAccess, "Instrument");
a.PermissionAccess = EventLogPermissionAccess.None;
Assert.AreEqual (EventLogPermissionAccess.None, a.PermissionAccess, "None");
#if NET_2_0
a.PermissionAccess = EventLogPermissionAccess.Administer;
Assert.AreEqual (EventLogPermissionAccess.Administer, a.PermissionAccess, "Administer");
a.PermissionAccess = EventLogPermissionAccess.Write;
Assert.AreEqual (EventLogPermissionAccess.Write, a.PermissionAccess, "Write");
#endif
}
[Test]
public void PermissionAccess_Invalid ()
{
EventLogPermissionAttribute a = new EventLogPermissionAttribute (SecurityAction.Assert);
a.PermissionAccess = (EventLogPermissionAccess) Int32.MinValue;
Assert.AreEqual ((EventLogPermissionAccess)Int32.MinValue, a.PermissionAccess, "None");
// no exception thrown
}
[Test]
public void Attributes ()
{
Type t = typeof (EventLogPermissionAttribute);
Assert.IsTrue (t.IsSerializable, "IsSerializable");
object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Event);
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}
#endif

View File

@@ -0,0 +1,452 @@
//
// EventLogPermissionTest.cs -
// NUnit Test Cases for EventLogPermission
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004-2005 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 NUnit.Framework;
using System;
using System.Diagnostics;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Diagnostics {
[TestFixture]
public class EventLogPermissionTest {
static EventLogPermissionAccess[] AllAccess = {
EventLogPermissionAccess.None,
EventLogPermissionAccess.Browse,
EventLogPermissionAccess.Instrument,
EventLogPermissionAccess.Audit,
#if NET_2_0
EventLogPermissionAccess.Write,
EventLogPermissionAccess.Administer,
#endif
};
[Test]
public void PermissionState_None ()
{
PermissionState ps = PermissionState.None;
EventLogPermission elp = new EventLogPermission (ps);
Assert.AreEqual (0, elp.PermissionEntries.Count, "PermissionEntries");
Assert.IsFalse (elp.IsUnrestricted (), "IsUnrestricted");
SecurityElement se = elp.ToXml ();
// only class and version are present
Assert.AreEqual (2, se.Attributes.Count, "Xml-Attributes");
Assert.IsNull (se.Children, "Xml-Children");
EventLogPermission copy = (EventLogPermission)elp.Copy ();
Assert.IsFalse (Object.ReferenceEquals (elp, copy), "ReferenceEquals");
Assert.AreEqual (elp.PermissionEntries.Count, copy.PermissionEntries.Count, "copy-PermissionEntries");
Assert.AreEqual (elp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
}
[Test]
public void PermissionState_Unrestricted ()
{
PermissionState ps = PermissionState.Unrestricted;
EventLogPermission elp = new EventLogPermission (ps);
Assert.AreEqual (0, elp.PermissionEntries.Count, "PermissionEntries");
Assert.IsTrue (elp.IsUnrestricted (), "IsUnrestricted");
SecurityElement se = elp.ToXml ();
// only class and version are present
Assert.AreEqual ("true", se.Attribute ("Unrestricted"), "Xml-Unrestricted");
Assert.IsNull (se.Children, "Xml-Children");
EventLogPermission copy = (EventLogPermission)elp.Copy ();
Assert.IsFalse (Object.ReferenceEquals (elp, copy), "ReferenceEquals");
Assert.AreEqual (elp.PermissionEntries.Count, copy.PermissionEntries.Count, "copy-PermissionEntries");
Assert.AreEqual (elp.IsUnrestricted (), copy.IsUnrestricted (), "copy-IsUnrestricted ()");
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentException))]
#endif
public void PermissionState_Bad ()
{
PermissionState ps = (PermissionState)77;
EventLogPermission elp = new EventLogPermission (ps);
Assert.IsFalse (elp.IsUnrestricted (), "IsUnrestricted");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_PermissionEntries_Null ()
{
EventLogPermission elp = new EventLogPermission (null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Constructor_MachineName_Null ()
{
EventLogPermission elp = new EventLogPermission (EventLogPermissionAccess.None, null);
}
[Test]
public void EventLogPermissionAccesss_Bad ()
{
EventLogPermissionAccess elpa = (EventLogPermissionAccess)Int32.MinValue;
EventLogPermission elp = new EventLogPermission (elpa, "localhost");
Assert.AreEqual (1, elp.PermissionEntries.Count, "Count");
Assert.AreEqual ((EventLogPermissionAccess)Int32.MinValue, elp.PermissionEntries [0].PermissionAccess, "PermissionAccess");
}
[Test]
public void PermissionEntries ()
{
EventLogPermissionAccess elpa = EventLogPermissionAccess.None;
EventLogPermission elp = new EventLogPermission (elpa, "localhost");
EventLogPermissionEntryCollection elpec = elp.PermissionEntries;
Assert.AreEqual (1, elpec.Count, "Count==1");
EventLogPermissionEntry elpe = new EventLogPermissionEntry (EventLogPermissionAccess.Browse, "*");
elp.PermissionEntries.Add (elpe);
Assert.AreEqual (2, elpec.Count, "Count==2");
// remove (same instance)
elp.PermissionEntries.Remove (elpe);
Assert.AreEqual (1, elpec.Count, "Count==1 (b)");
// remove different instance (doesn't work)
elpe = new EventLogPermissionEntry (EventLogPermissionAccess.None, "localhost");
Assert.AreEqual (1, elpec.Count, "Count==1");
}
[Test]
public void Copy ()
{
foreach (EventLogPermissionAccess elpa in AllAccess) {
EventLogPermission elp = new EventLogPermission (PermissionState.None);
EventLogPermissionEntry elpe = new EventLogPermissionEntry (elpa, elpa.ToString ());
elp.PermissionEntries.Add (elpe);
EventLogPermission copy = (EventLogPermission)elp.Copy ();
Assert.AreEqual (1, copy.PermissionEntries.Count, "Count==1");
Assert.AreEqual (elpa, elp.PermissionEntries [0].PermissionAccess, elpa.ToString ());
}
}
[Test]
public void Intersect_Null ()
{
EventLogPermission elp = new EventLogPermission (PermissionState.None);
// No intersection with null
Assert.IsNull (elp.Intersect (null), "None N null");
}
[Test]
public void Intersect_None ()
{
EventLogPermission elp1 = new EventLogPermission (PermissionState.None);
EventLogPermission elp2 = new EventLogPermission (PermissionState.None);
// 1. None N None
EventLogPermission result = (EventLogPermission)elp1.Intersect (elp2);
Assert.IsNull (result, "Empty N Empty");
// 2. None N Entry
elp2.PermissionEntries.Add (new EventLogPermissionEntry (EventLogPermissionAccess.None, "localhost"));
result = (EventLogPermission)elp1.Intersect (elp2);
Assert.IsNull (result, "Empty N Entry");
// 3. Entry N None
result = (EventLogPermission)elp2.Intersect (elp1);
Assert.IsNull (result, "Entry N Empty");
}
[Test]
public void Intersect_Unrestricted ()
{
// Intersection with unrestricted == Copy
// a. source (this) is unrestricted
EventLogPermission elp1 = new EventLogPermission (PermissionState.Unrestricted);
EventLogPermission elp2 = new EventLogPermission (PermissionState.None);
// 1. Unrestricted N None
EventLogPermission result = (EventLogPermission)elp1.Intersect (elp2);
Assert.IsFalse (result.IsUnrestricted (), "(Unrestricted N None).IsUnrestricted");
Assert.AreEqual (0, result.PermissionEntries.Count, "(Unrestricted N None).Count");
// 2. None N Unrestricted
result = (EventLogPermission)elp2.Intersect (elp1);
Assert.IsFalse (result.IsUnrestricted (), "(None N Unrestricted).IsUnrestricted");
Assert.AreEqual (0, result.PermissionEntries.Count, "(None N Unrestricted).Count");
// 3. Unrestricted N Unrestricted
result = (EventLogPermission)elp1.Intersect (elp1);
Assert.IsTrue (result.IsUnrestricted (), "(Unrestricted N Unrestricted).IsUnrestricted");
Assert.AreEqual (0, result.PermissionEntries.Count, "(Unrestricted N Unrestricted).Count");
// 4. Unrestricted N Entry
elp2.PermissionEntries.Add (new EventLogPermissionEntry (EventLogPermissionAccess.None, "localhost"));
result = (EventLogPermission)elp1.Intersect (elp2);
Assert.IsFalse (result.IsUnrestricted (), "(Unrestricted N Entry).IsUnrestricted");
Assert.AreEqual (1, result.PermissionEntries.Count, "(Unrestricted N Entry).Count");
// 5. Entry N Unrestricted
result = (EventLogPermission)elp2.Intersect (elp1);
Assert.IsFalse (result.IsUnrestricted (), "(Entry N Unrestricted).IsUnrestricted");
Assert.AreEqual (1, result.PermissionEntries.Count, "(Entry N Unrestricted).Count");
// 6. Unrestricted N Unrestricted
elp1.PermissionEntries.Add (new EventLogPermissionEntry (EventLogPermissionAccess.None, "localhost"));
result = (EventLogPermission)elp1.Intersect (elp1);
Assert.IsTrue (result.IsUnrestricted (), "(Unrestricted N Unrestricted).IsUnrestricted");
Assert.AreEqual (1, result.PermissionEntries.Count, "(Unrestricted N Unrestricted).Count");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Intersect_BadPermission ()
{
EventLogPermission elp1 = new EventLogPermission (PermissionState.Unrestricted);
elp1.Intersect (new SecurityPermission (SecurityPermissionFlag.Assertion));
}
[Test]
public void IsSubset_Null ()
{
EventLogPermission elp = new EventLogPermission (PermissionState.None);
#if NET_2_0
Assert.IsTrue (elp.IsSubsetOf (null), "null");
#else
Assert.IsFalse (elp.IsSubsetOf (null), "null");
#endif
}
[Test]
public void IsSubset_None ()
{
// IsSubset with none
// a. source (this) is none -> target is never a subset
// b. destination (target) is none -> target is always a subset
EventLogPermission elp1 = new EventLogPermission (PermissionState.None);
foreach (EventLogPermissionAccess elpa in AllAccess) {
EventLogPermission elp2 = new EventLogPermission (PermissionState.None);
elp2.PermissionEntries.Add (new EventLogPermissionEntry (elpa, elpa.ToString ()));
Assert.IsTrue (elp1.IsSubsetOf (elp2), "target " + elpa.ToString ());
Assert.IsFalse (elp2.IsSubsetOf (elp1), "source " + elpa.ToString ());
}
}
[Test]
public void IsSubset_Self ()
{
foreach (EventLogPermissionAccess elpa in AllAccess) {
EventLogPermission elp = new EventLogPermission (PermissionState.None);
elp.PermissionEntries.Add (new EventLogPermissionEntry (elpa, elpa.ToString ()));
Assert.IsTrue (elp.IsSubsetOf (elp), elpa.ToString ());
}
}
[Test]
public void IsSubset_Unrestricted ()
{
// IsSubset with unrestricted
// a. source (this) is unrestricted -> target is never a subset
// b. destination (target) is unrestricted -> source is always a subset
EventLogPermission elp1 = new EventLogPermission (PermissionState.Unrestricted);
foreach (EventLogPermissionAccess elpa in AllAccess) {
EventLogPermission elp2 = new EventLogPermission (PermissionState.None);
elp2.PermissionEntries.Add (new EventLogPermissionEntry (elpa, elpa.ToString ()));
Assert.IsFalse (elp1.IsSubsetOf (elp2), "target " + elpa.ToString ());
Assert.IsTrue (elp2.IsSubsetOf (elp1), "source " + elpa.ToString ());
}
Assert.IsTrue (elp1.IsSubsetOf (elp1), "Unrestricted.IsSubsetOf(Unrestricted)");
}
[Test]
// "special" behavior inherited from ResourceBasePermission
// [ExpectedException (typeof (ArgumentException))]
public void IsSubsetOf_BadPermission ()
{
EventLogPermission elp1 = new EventLogPermission (PermissionState.Unrestricted);
Assert.IsFalse (elp1.IsSubsetOf (new SecurityPermission (SecurityPermissionFlag.Assertion)));
}
[Test]
public void Union_Null ()
{
EventLogPermission elp = new EventLogPermission (PermissionState.None);
elp.PermissionEntries.Add (new EventLogPermissionEntry (EventLogPermissionAccess.None, "localhost"));
// Union with null is a simple copy
EventLogPermission union = (EventLogPermission)elp.Union (null);
Assert.IsNotNull (elp.PermissionEntries.Count, "Count");
}
[Test]
public void Union_None ()
{
EventLogPermission elp1 = new EventLogPermission (PermissionState.None);
foreach (EventLogPermissionAccess elpa in AllAccess) {
EventLogPermission elp2 = new EventLogPermission (PermissionState.None);
elp2.PermissionEntries.Add (new EventLogPermissionEntry (elpa, elpa.ToString ()));
EventLogPermission union = (EventLogPermission)elp1.Union (elp2);
Assert.IsFalse (union.IsUnrestricted (), "target.IsUnrestricted " + elpa.ToString ());
Assert.AreEqual (1, union.PermissionEntries.Count, "target.Count " + elpa.ToString ());
union = (EventLogPermission)elp2.Union (elp1);
Assert.IsFalse (union.IsUnrestricted (), "source.IsUnrestricted " + elpa.ToString ());
Assert.AreEqual (1, union.PermissionEntries.Count, "source.Count " + elpa.ToString ());
}
}
[Test]
public void Union_Self ()
{
foreach (EventLogPermissionAccess elpa in AllAccess)
{
EventLogPermission elp = new EventLogPermission (PermissionState.None);
elp.PermissionEntries.Add (new EventLogPermissionEntry (elpa, elpa.ToString ()));
EventLogPermission union = (EventLogPermission)elp.Union (elp);
Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted " + elpa.ToString ());
Assert.AreEqual (1, union.PermissionEntries.Count, "Count " + elpa.ToString ());
}
}
[Test]
public void Union_Unrestricted ()
{
// Union with unrestricted is unrestricted
EventLogPermission elp1 = new EventLogPermission (PermissionState.Unrestricted);
foreach (EventLogPermissionAccess elpa in AllAccess) {
EventLogPermission elp2 = new EventLogPermission (PermissionState.None);
elp2.PermissionEntries.Add (new EventLogPermissionEntry (elpa, elpa.ToString ()));
EventLogPermission union = (EventLogPermission)elp1.Union (elp2);
Assert.IsTrue (union.IsUnrestricted (), "target.IsUnrestricted " + elpa.ToString ());
Assert.AreEqual (0, union.PermissionEntries.Count, "target.Count " + elpa.ToString ());
union = (EventLogPermission)elp2.Union (elp1);
Assert.IsTrue (union.IsUnrestricted (), "source.IsUnrestricted " + elpa.ToString ());
Assert.AreEqual (0, union.PermissionEntries.Count, "source.Count " + elpa.ToString ());
}
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Union_BadPermission ()
{
EventLogPermission elp1 = new EventLogPermission (PermissionState.Unrestricted);
elp1.Union (new SecurityPermission (SecurityPermissionFlag.Assertion));
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#else
// Problem inherited from ResourcePermissionBase
[ExpectedException (typeof (NullReferenceException))]
#endif
public void FromXml_Null ()
{
EventLogPermission elp = new EventLogPermission (PermissionState.None);
elp.FromXml (null);
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentException))]
#endif
public void FromXml_WrongTag ()
{
EventLogPermission elp = new EventLogPermission (PermissionState.None);
SecurityElement se = elp.ToXml ();
se.Tag = "IMono";
elp.FromXml (se);
// note: normally IPermission classes (in corlib) DO care about the
// IPermission tag
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentException))]
#endif
public void FromXml_WrongTagCase ()
{
EventLogPermission elp = new EventLogPermission (PermissionState.None);
SecurityElement se = elp.ToXml ();
se.Tag = "IPERMISSION"; // instead of IPermission
elp.FromXml (se);
// note: normally IPermission classes (in corlib) DO care about the
// IPermission tag
}
[Test]
public void FromXml_WrongClass ()
{
EventLogPermission elp = new EventLogPermission (PermissionState.None);
SecurityElement se = elp.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", "Wrong" + se.Attribute ("class"));
w.AddAttribute ("version", se.Attribute ("version"));
elp.FromXml (w);
// doesn't care of the class name at that stage
// anyway the class has already be created so...
}
[Test]
public void FromXml_NoClass ()
{
EventLogPermission elp = new EventLogPermission (PermissionState.None);
SecurityElement se = elp.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("version", se.Attribute ("version"));
elp.FromXml (w);
// doesn't even care of the class attribute presence
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_WrongVersion ()
{
EventLogPermission elp = new EventLogPermission (PermissionState.None);
SecurityElement se = elp.ToXml ();
se.Attributes.Remove ("version");
se.Attributes.Add ("version", "2");
elp.FromXml (se);
}
[Test]
public void FromXml_NoVersion ()
{
EventLogPermission elp = new EventLogPermission (PermissionState.None);
SecurityElement se = elp.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
elp.FromXml (w);
}
}
}
#endif

View File

@@ -0,0 +1 @@
5c3d08bf5c4684c4f2c90c048c1fef8512a7d147

View File

@@ -0,0 +1,189 @@
//
// EventSourceCreationDataTest.cs -
// NUnit Test Cases for System.Diagnostics.EventSourceCreationData
//
// Author:
// Gert Driesen <driesen@users.sourceforge.net>
//
// 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.Diagnostics;
using NUnit.Framework;
namespace MonoTests.System.Diagnostics
{
[TestFixture]
public class EventLogCreationDataTest
{
[Test]
public void Constructor1 ()
{
EventSourceCreationData crd;
crd = new EventSourceCreationData (null, null);
Assert.AreEqual (0, crd.CategoryCount, "#A1");
Assert.IsNull (crd.CategoryResourceFile, "#A2");
Assert.IsNull (crd.LogName, "#A3");
Assert.IsNotNull (crd.MachineName, "#A4");
Assert.AreEqual (".", crd.MachineName, "#A5");
Assert.IsNull (crd.MessageResourceFile, "#A6");
Assert.IsNull (crd.ParameterResourceFile, "#A7");
Assert.IsNull (crd.Source, "#A8");
crd = new EventSourceCreationData ("src", null);
Assert.AreEqual (0, crd.CategoryCount, "#B1");
Assert.IsNull (crd.CategoryResourceFile, "#B2");
Assert.IsNull (crd.LogName, "#B3");
Assert.IsNotNull (crd.MachineName, "#B4");
Assert.AreEqual (".", crd.MachineName, "#B5");
Assert.IsNull (crd.MessageResourceFile, "#B6");
Assert.IsNull (crd.ParameterResourceFile, "#B7");
Assert.IsNotNull (crd.Source, "#B8");
Assert.AreEqual ("src", crd.Source, "#B9");
crd = new EventSourceCreationData (null, "log");
Assert.AreEqual (0, crd.CategoryCount, "#C1");
Assert.IsNull (crd.CategoryResourceFile, "#C2");
Assert.IsNotNull (crd.LogName, "#C3");
Assert.AreEqual ("log", crd.LogName, "#C4");
Assert.IsNotNull (crd.MachineName, "#C5");
Assert.AreEqual (".", crd.MachineName, "#C6");
Assert.IsNull (crd.MessageResourceFile, "#C7");
Assert.IsNull (crd.ParameterResourceFile, "#C8");
Assert.IsNull (crd.Source, "#C9");
crd = new EventSourceCreationData ("src", "log");
Assert.AreEqual (0, crd.CategoryCount, "#C1");
Assert.IsNull (crd.CategoryResourceFile, "#C2");
Assert.IsNotNull (crd.LogName, "#C3");
Assert.AreEqual ("log", crd.LogName, "#C4");
Assert.IsNotNull (crd.MachineName, "#C5");
Assert.AreEqual (".", crd.MachineName, "#C6");
Assert.IsNull (crd.MessageResourceFile, "#C7");
Assert.IsNull (crd.ParameterResourceFile, "#C8");
Assert.IsNotNull (crd.Source, "#C9");
Assert.AreEqual ("src", crd.Source, "#C10");
}
[Test]
public void CategoryCount ()
{
EventSourceCreationData crd = new EventSourceCreationData ("src", "log");
crd.CategoryCount = 15;
Assert.AreEqual (15, crd.CategoryCount, "#1");
crd.CategoryCount = 0;
Assert.AreEqual (0, crd.CategoryCount, "#2");
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void CategoryCount_Negative ()
{
EventSourceCreationData crd = new EventSourceCreationData ("src", "log");
crd.CategoryCount = -1;
Assert.AreEqual (-1, crd.CategoryCount);
}
[Test]
public void CategoryResourceFile ()
{
EventSourceCreationData crd = new EventSourceCreationData ("src", "log");
crd.CategoryResourceFile = "catRes";
Assert.AreEqual ("catRes", crd.CategoryResourceFile, "#1");
crd.CategoryResourceFile = null;
Assert.IsNull (crd.CategoryResourceFile, "#2");
crd.CategoryResourceFile = string.Empty;
Assert.AreEqual (string.Empty, crd.CategoryResourceFile, "#3");
}
[Test]
public void LogName ()
{
EventSourceCreationData crd = new EventSourceCreationData ("src", "log");
Assert.AreEqual ("log", crd.LogName, "#1");
crd.LogName = "newLog";
Assert.AreEqual ("newLog", crd.LogName, "#2");
crd.LogName = null;
Assert.IsNull (crd.LogName, "#3");
crd.LogName = string.Empty;
Assert.AreEqual (string.Empty, crd.LogName, "#4");
}
[Test]
public void MachineName ()
{
EventSourceCreationData crd = new EventSourceCreationData ("src", "log");
Assert.AreEqual (".", crd.MachineName, "#1");
crd.MachineName = "go-mono";
Assert.AreEqual ("go-mono", crd.MachineName, "#2");
crd.MachineName = null;
Assert.IsNull (crd.MachineName, "#3");
crd.MachineName = string.Empty;
Assert.AreEqual (string.Empty, crd.MachineName, "#4");
}
[Test]
public void MessageResourceFile ()
{
EventSourceCreationData crd = new EventSourceCreationData ("src", "log");
Assert.IsNull (crd.MessageResourceFile, "#1");
crd.MessageResourceFile = "msgRes";
Assert.AreEqual ("msgRes", crd.MessageResourceFile, "#2");
crd.MessageResourceFile = null;
Assert.IsNull (crd.MessageResourceFile, "#3");
crd.MessageResourceFile = string.Empty;
Assert.AreEqual (string.Empty, crd.MessageResourceFile, "#4");
}
[Test]
public void ParameterResourceFile ()
{
EventSourceCreationData crd = new EventSourceCreationData ("src", "log");
Assert.IsNull (crd.ParameterResourceFile, "#1");
crd.ParameterResourceFile = "paramRes";
Assert.AreEqual ("paramRes", crd.ParameterResourceFile, "#2");
crd.ParameterResourceFile = null;
Assert.IsNull (crd.ParameterResourceFile, "#3");
crd.ParameterResourceFile = string.Empty;
Assert.AreEqual (string.Empty, crd.ParameterResourceFile, "#4");
}
[Test]
public void Source ()
{
EventSourceCreationData crd = new EventSourceCreationData ("src", "log");
Assert.AreEqual ("src", crd.Source, "#1");
crd.Source = "newSrc";
Assert.AreEqual ("newSrc", crd.Source, "#2");
crd.Source = null;
Assert.IsNull (crd.Source, "#3");
crd.Source = string.Empty;
Assert.AreEqual (string.Empty, crd.Source, "#4");
}
}
}
#endif

View File

@@ -0,0 +1 @@
ac3d3bc555ee25f2f10f85c3e5c729682a4173b2

View File

@@ -0,0 +1,216 @@
//
// PerformanceCounterPermissionAttributeTest.cs -
// NUnit Test Cases for PerformanceCounterPermissionAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004-2005 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 NUnit.Framework;
using System;
using System.Diagnostics;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
namespace MonoTests.System.Diagnostics {
[TestFixture]
public class PerformanceCounterPermissionAttributeTest {
[Test]
public void Default ()
{
PerformanceCounterPermissionAttribute a = new PerformanceCounterPermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
Assert.IsFalse (a.Unrestricted, "Unrestricted");
Assert.AreEqual (".", a.MachineName, "MachineName");
Assert.AreEqual ("*", a.CategoryName, "CategoryName");
#if NET_2_0
Assert.AreEqual (PerformanceCounterPermissionAccess.Write, a.PermissionAccess, "PermissionAccess");
#else
Assert.AreEqual (PerformanceCounterPermissionAccess.Browse, a.PermissionAccess, "PermissionAccess");
#endif
PerformanceCounterPermission sp = (PerformanceCounterPermission)a.CreatePermission ();
Assert.IsFalse (sp.IsUnrestricted (), "IsUnrestricted");
}
[Test]
public void Action ()
{
PerformanceCounterPermissionAttribute a = new PerformanceCounterPermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
a.Action = SecurityAction.Demand;
Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
a.Action = SecurityAction.Deny;
Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
a.Action = SecurityAction.InheritanceDemand;
Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
a.Action = SecurityAction.LinkDemand;
Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
a.Action = SecurityAction.PermitOnly;
Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
a.Action = SecurityAction.RequestMinimum;
Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
a.Action = SecurityAction.RequestOptional;
Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
a.Action = SecurityAction.RequestRefuse;
Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
}
[Test]
public void Action_Invalid ()
{
PerformanceCounterPermissionAttribute a = new PerformanceCounterPermissionAttribute ((SecurityAction)Int32.MinValue);
// no validation in attribute
}
[Test]
public void Unrestricted ()
{
PerformanceCounterPermissionAttribute a = new PerformanceCounterPermissionAttribute (SecurityAction.Assert);
a.Unrestricted = true;
PerformanceCounterPermission wp = (PerformanceCounterPermission)a.CreatePermission ();
Assert.IsTrue (wp.IsUnrestricted (), "IsUnrestricted");
a.Unrestricted = false;
wp = (PerformanceCounterPermission)a.CreatePermission ();
Assert.IsFalse (wp.IsUnrestricted (), "!IsUnrestricted");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CategoryName_Null ()
{
PerformanceCounterPermissionAttribute a = new PerformanceCounterPermissionAttribute (SecurityAction.Assert);
a.CategoryName = null;
}
[Test]
public void CategoryName ()
{
PerformanceCounterPermissionAttribute a = new PerformanceCounterPermissionAttribute (SecurityAction.Assert);
a.CategoryName = String.Empty;
Assert.AreEqual (String.Empty, a.CategoryName, "Empty");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void MachineName_Null ()
{
PerformanceCounterPermissionAttribute a = new PerformanceCounterPermissionAttribute (SecurityAction.Assert);
a.MachineName = null;
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void MachineName_Empty ()
{
PerformanceCounterPermissionAttribute a = new PerformanceCounterPermissionAttribute (SecurityAction.Assert);
a.MachineName = String.Empty;
}
[Test]
public void MachineName ()
{
PerformanceCounterPermissionAttribute a = new PerformanceCounterPermissionAttribute (SecurityAction.Assert);
for (int i = 0; i < 256; i++) {
try {
a.MachineName = Convert.ToChar (i).ToString ();
Assert.AreEqual (i, (int)a.MachineName [0], i.ToString ());
}
catch {
switch (i) {
case 9:
case 10:
case 11:
case 12:
case 13:
case 32:
case 92:
#if NET_2_0
case 133:
#endif
case 160:
// known invalid chars
break;
default:
Assert.Fail (i.ToString ());
break;
}
}
}
// all first 256 characters seems to be valid
// is there other rules ?
}
[Test]
public void PermissionAccess ()
{
PerformanceCounterPermissionAttribute a = new PerformanceCounterPermissionAttribute (SecurityAction.Assert);
a.PermissionAccess = PerformanceCounterPermissionAccess.Administer;
Assert.AreEqual (PerformanceCounterPermissionAccess.Administer, a.PermissionAccess, "Administer");
a.PermissionAccess = PerformanceCounterPermissionAccess.Browse;
Assert.AreEqual (PerformanceCounterPermissionAccess.Browse, a.PermissionAccess, "Browse");
a.PermissionAccess = PerformanceCounterPermissionAccess.Instrument;
Assert.AreEqual (PerformanceCounterPermissionAccess.Instrument, a.PermissionAccess, "Instrument");
a.PermissionAccess = PerformanceCounterPermissionAccess.None;
Assert.AreEqual (PerformanceCounterPermissionAccess.None, a.PermissionAccess, "None");
#if NET_2_0
a.PermissionAccess = PerformanceCounterPermissionAccess.Read;
Assert.AreEqual (PerformanceCounterPermissionAccess.Read, a.PermissionAccess, "Read");
a.PermissionAccess = PerformanceCounterPermissionAccess.Write;
Assert.AreEqual (PerformanceCounterPermissionAccess.Write, a.PermissionAccess, "Write");
#endif
}
[Test]
public void PermissionAccess_Invalid ()
{
PerformanceCounterPermissionAttribute a = new PerformanceCounterPermissionAttribute (SecurityAction.Assert);
a.PermissionAccess = (PerformanceCounterPermissionAccess)Int32.MinValue;
Assert.AreEqual ((PerformanceCounterPermissionAccess)Int32.MinValue, a.PermissionAccess, "None");
// no exception thrown
}
[Test]
public void Attributes ()
{
Type t = typeof (PerformanceCounterPermissionAttribute);
Assert.IsTrue (t.IsSerializable, "IsSerializable");
object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Event);
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}
#endif

View File

@@ -0,0 +1,465 @@
//
// PerformanceCounterPermissionTest.cs -
// NUnit Test Cases for PerformanceCounterPermission
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004-2005 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 NUnit.Framework;
using System;
using System.Diagnostics;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Diagnostics {
[TestFixture]
public class PerformanceCounterPermissionTest {
static PerformanceCounterPermissionAccess[] AllAccess = {
PerformanceCounterPermissionAccess.None,
PerformanceCounterPermissionAccess.Browse,
#if NET_2_0
PerformanceCounterPermissionAccess.Read,
PerformanceCounterPermissionAccess.Write,
#endif
PerformanceCounterPermissionAccess.Instrument,
PerformanceCounterPermissionAccess.Administer,
};
[Test]
public void PermissionState_None ()
{
PermissionState ps = PermissionState.None;
PerformanceCounterPermission pcp = new PerformanceCounterPermission (ps);
Assert.AreEqual (0, pcp.PermissionEntries.Count, "PermissionEntries");
Assert.IsFalse (pcp.IsUnrestricted (), "IsUnrestricted");
SecurityElement se = pcp.ToXml ();
// only class and version are present
Assert.AreEqual (2, se.Attributes.Count, "Xml-Attributes");
Assert.IsNull (se.Children, "Xml-Children");
PerformanceCounterPermission copy = (PerformanceCounterPermission)pcp.Copy ();
Assert.IsFalse (Object.ReferenceEquals (pcp, copy), "ReferenceEquals");
Assert.AreEqual (pcp.PermissionEntries.Count, copy.PermissionEntries.Count, "copy-PermissionEntries");
Assert.AreEqual (pcp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
}
[Test]
public void PermissionState_Unrestricted ()
{
PermissionState ps = PermissionState.Unrestricted;
PerformanceCounterPermission pcp = new PerformanceCounterPermission (ps);
Assert.AreEqual (0, pcp.PermissionEntries.Count, "PermissionEntries");
Assert.IsTrue (pcp.IsUnrestricted (), "IsUnrestricted");
SecurityElement se = pcp.ToXml ();
// only class and version are present
Assert.AreEqual ("true", se.Attribute ("Unrestricted"), "Xml-Unrestricted");
Assert.IsNull (se.Children, "Xml-Children");
PerformanceCounterPermission copy = (PerformanceCounterPermission)pcp.Copy ();
Assert.IsFalse (Object.ReferenceEquals (pcp, copy), "ReferenceEquals");
Assert.AreEqual (pcp.PermissionEntries.Count, copy.PermissionEntries.Count, "copy-PermissionEntries");
Assert.AreEqual (pcp.IsUnrestricted (), copy.IsUnrestricted (), "copy-IsUnrestricted ()");
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentException))]
#endif
public void PermissionState_Bad ()
{
PermissionState ps = (PermissionState)77;
PerformanceCounterPermission pcp = new PerformanceCounterPermission (ps);
Assert.IsFalse (pcp.IsUnrestricted (), "IsUnrestricted");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_PermissionEntries_Null ()
{
PerformanceCounterPermission pcp = new PerformanceCounterPermission (null);
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#else
[ExpectedException (typeof (ArgumentException))]
#endif
public void Constructor_MachineName_Null ()
{
PerformanceCounterPermission pcp = new PerformanceCounterPermission (PerformanceCounterPermissionAccess.None, null, String.Empty);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_CategoryName_Null ()
{
PerformanceCounterPermission pcp = new PerformanceCounterPermission (PerformanceCounterPermissionAccess.None, "localhost", null);
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentException))]
#endif
public void PerformanceCounterPermissionAccesss_Bad ()
{
PerformanceCounterPermissionAccess pcpa = (PerformanceCounterPermissionAccess)Int32.MinValue;
PerformanceCounterPermission pcp = new PerformanceCounterPermission (pcpa, "localhost", String.Empty);
Assert.AreEqual (1, pcp.PermissionEntries.Count, "Count");
Assert.AreEqual ((PerformanceCounterPermissionAccess)Int32.MinValue, pcp.PermissionEntries [0].PermissionAccess, "PermissionAccess");
}
[Test]
public void PermissionEntries ()
{
PerformanceCounterPermissionAccess pcpa = PerformanceCounterPermissionAccess.None;
PerformanceCounterPermission pcp = new PerformanceCounterPermission (pcpa, "localhost", String.Empty);
PerformanceCounterPermissionEntryCollection pcpec = pcp.PermissionEntries;
Assert.AreEqual (1, pcpec.Count, "Count==1");
PerformanceCounterPermissionEntry pcpe = new PerformanceCounterPermissionEntry (PerformanceCounterPermissionAccess.Browse, "*", String.Empty);
pcp.PermissionEntries.Add (pcpe);
Assert.AreEqual (2, pcpec.Count, "Count==2");
// remove (same instance)
pcp.PermissionEntries.Remove (pcpe);
Assert.AreEqual (1, pcpec.Count, "Count==1 (b)");
// remove different instance (doesn't work)
pcpe = new PerformanceCounterPermissionEntry (PerformanceCounterPermissionAccess.None, "localhost", String.Empty);
Assert.AreEqual (1, pcpec.Count, "Count==1");
}
[Test]
public void Copy ()
{
foreach (PerformanceCounterPermissionAccess pcpa in AllAccess) {
PerformanceCounterPermission pcp = new PerformanceCounterPermission (PermissionState.None);
PerformanceCounterPermissionEntry pcpe = new PerformanceCounterPermissionEntry (pcpa, pcpa.ToString (), String.Empty);
pcp.PermissionEntries.Add (pcpe);
PerformanceCounterPermission copy = (PerformanceCounterPermission)pcp.Copy ();
Assert.AreEqual (1, copy.PermissionEntries.Count, "Count==1");
Assert.AreEqual (pcpa, pcp.PermissionEntries [0].PermissionAccess, pcpa.ToString ());
}
}
[Test]
public void Intersect_Null ()
{
PerformanceCounterPermission pcp = new PerformanceCounterPermission (PermissionState.None);
// No intersection with null
Assert.IsNull (pcp.Intersect (null), "None N null");
}
[Test]
public void Intersect_None ()
{
PerformanceCounterPermission pcp1 = new PerformanceCounterPermission (PermissionState.None);
PerformanceCounterPermission pcp2 = new PerformanceCounterPermission (PermissionState.None);
// 1. None N None
PerformanceCounterPermission result = (PerformanceCounterPermission)pcp1.Intersect (pcp2);
Assert.IsNull (result, "Empty N Empty");
// 2. None N Entry
pcp2.PermissionEntries.Add (new PerformanceCounterPermissionEntry (PerformanceCounterPermissionAccess.None, "localhost", String.Empty));
result = (PerformanceCounterPermission)pcp1.Intersect (pcp2);
Assert.IsNull (result, "Empty N Entry");
// 3. Entry N None
result = (PerformanceCounterPermission)pcp2.Intersect (pcp1);
Assert.IsNull (result, "Entry N Empty");
}
[Test]
public void Intersect_Unrestricted ()
{
// Intersection with unrestricted == Copy
// a. source (this) is unrestricted
PerformanceCounterPermission pcp1 = new PerformanceCounterPermission (PermissionState.Unrestricted);
PerformanceCounterPermission pcp2 = new PerformanceCounterPermission (PermissionState.None);
// 1. Unrestricted N None
PerformanceCounterPermission result = (PerformanceCounterPermission)pcp1.Intersect (pcp2);
Assert.IsFalse (result.IsUnrestricted (), "(Unrestricted N None).IsUnrestricted");
Assert.AreEqual (0, result.PermissionEntries.Count, "(Unrestricted N None).Count");
// 2. None N Unrestricted
result = (PerformanceCounterPermission)pcp2.Intersect (pcp1);
Assert.IsFalse (result.IsUnrestricted (), "(None N Unrestricted).IsUnrestricted");
Assert.AreEqual (0, result.PermissionEntries.Count, "(None N Unrestricted).Count");
// 3. Unrestricted N Unrestricted
result = (PerformanceCounterPermission)pcp1.Intersect (pcp1);
Assert.IsTrue (result.IsUnrestricted (), "(Unrestricted N Unrestricted).IsUnrestricted");
Assert.AreEqual (0, result.PermissionEntries.Count, "(Unrestricted N Unrestricted).Count");
// 4. Unrestricted N Entry
pcp2.PermissionEntries.Add (new PerformanceCounterPermissionEntry (PerformanceCounterPermissionAccess.None, "localhost", String.Empty));
result = (PerformanceCounterPermission)pcp1.Intersect (pcp2);
Assert.IsFalse (result.IsUnrestricted (), "(Unrestricted N Entry).IsUnrestricted");
Assert.AreEqual (1, result.PermissionEntries.Count, "(Unrestricted N Entry).Count");
// 5. Entry N Unrestricted
result = (PerformanceCounterPermission)pcp2.Intersect (pcp1);
Assert.IsFalse (result.IsUnrestricted (), "(Entry N Unrestricted).IsUnrestricted");
Assert.AreEqual (1, result.PermissionEntries.Count, "(Entry N Unrestricted).Count");
// 6. Unrestricted N Unrestricted
pcp1.PermissionEntries.Add (new PerformanceCounterPermissionEntry (PerformanceCounterPermissionAccess.None, "localhost", String.Empty));
result = (PerformanceCounterPermission)pcp1.Intersect (pcp1);
Assert.IsTrue (result.IsUnrestricted (), "(Unrestricted N Unrestricted).IsUnrestricted");
Assert.AreEqual (1, result.PermissionEntries.Count, "(Unrestricted N Unrestricted).Count");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Intersect_BadPermission ()
{
PerformanceCounterPermission pcp1 = new PerformanceCounterPermission (PermissionState.Unrestricted);
pcp1.Intersect (new SecurityPermission (SecurityPermissionFlag.Assertion));
}
[Test]
public void IsSubset_Null ()
{
PerformanceCounterPermission pcp = new PerformanceCounterPermission (PermissionState.None);
#if NET_2_0
Assert.IsTrue (pcp.IsSubsetOf (null), "null");
#else
Assert.IsFalse (pcp.IsSubsetOf (null), "null");
#endif
}
[Test]
public void IsSubset_None ()
{
// IsSubset with none
// a. source (this) is none -> target is never a subset
// b. destination (target) is none -> target is always a subset
PerformanceCounterPermission pcp1 = new PerformanceCounterPermission (PermissionState.None);
foreach (PerformanceCounterPermissionAccess pcpa in AllAccess) {
PerformanceCounterPermission pcp2 = new PerformanceCounterPermission (PermissionState.None);
pcp2.PermissionEntries.Add (new PerformanceCounterPermissionEntry (pcpa, pcpa.ToString (), String.Empty));
Assert.IsTrue (pcp1.IsSubsetOf (pcp2), "target " + pcpa.ToString ());
Assert.IsFalse (pcp2.IsSubsetOf (pcp1), "source " + pcpa.ToString ());
}
}
[Test]
public void IsSubset_Self ()
{
foreach (PerformanceCounterPermissionAccess pcpa in AllAccess) {
PerformanceCounterPermission pcp = new PerformanceCounterPermission (PermissionState.None);
pcp.PermissionEntries.Add (new PerformanceCounterPermissionEntry (pcpa, pcpa.ToString (), String.Empty));
Assert.IsTrue (pcp.IsSubsetOf (pcp), pcpa.ToString ());
}
}
[Test]
public void IsSubset_Unrestricted ()
{
// IsSubset with unrestricted
// a. source (this) is unrestricted -> target is never a subset
// b. destination (target) is unrestricted -> source is always a subset
PerformanceCounterPermission pcp1 = new PerformanceCounterPermission (PermissionState.Unrestricted);
foreach (PerformanceCounterPermissionAccess pcpa in AllAccess) {
PerformanceCounterPermission pcp2 = new PerformanceCounterPermission (PermissionState.None);
pcp2.PermissionEntries.Add (new PerformanceCounterPermissionEntry (pcpa, pcpa.ToString (), String.Empty));
Assert.IsFalse (pcp1.IsSubsetOf (pcp2), "target " + pcpa.ToString ());
Assert.IsTrue (pcp2.IsSubsetOf (pcp1), "source " + pcpa.ToString ());
}
Assert.IsTrue (pcp1.IsSubsetOf (pcp1), "Unrestricted.IsSubsetOf(Unrestricted)");
}
[Test]
// "special" behavior inherited from ResourceBasePermission
// [ExpectedException (typeof (ArgumentException))]
public void IsSubsetOf_BadPermission ()
{
PerformanceCounterPermission pcp1 = new PerformanceCounterPermission (PermissionState.Unrestricted);
Assert.IsFalse (pcp1.IsSubsetOf (new SecurityPermission (SecurityPermissionFlag.Assertion)));
}
[Test]
public void Union_Null ()
{
PerformanceCounterPermission pcp = new PerformanceCounterPermission (PermissionState.None);
pcp.PermissionEntries.Add (new PerformanceCounterPermissionEntry (PerformanceCounterPermissionAccess.None, "localhost", String.Empty));
// Union with null is a simple copy
PerformanceCounterPermission union = (PerformanceCounterPermission)pcp.Union (null);
Assert.IsNotNull (pcp.PermissionEntries.Count, "Count");
}
[Test]
public void Union_None ()
{
PerformanceCounterPermission pcp1 = new PerformanceCounterPermission (PermissionState.None);
foreach (PerformanceCounterPermissionAccess pcpa in AllAccess) {
PerformanceCounterPermission pcp2 = new PerformanceCounterPermission (PermissionState.None);
pcp2.PermissionEntries.Add (new PerformanceCounterPermissionEntry (pcpa, pcpa.ToString (), String.Empty));
PerformanceCounterPermission union = (PerformanceCounterPermission)pcp1.Union (pcp2);
Assert.IsFalse (union.IsUnrestricted (), "target.IsUnrestricted " + pcpa.ToString ());
Assert.AreEqual (1, union.PermissionEntries.Count, "target.Count " + pcpa.ToString ());
union = (PerformanceCounterPermission)pcp2.Union (pcp1);
Assert.IsFalse (union.IsUnrestricted (), "source.IsUnrestricted " + pcpa.ToString ());
Assert.AreEqual (1, union.PermissionEntries.Count, "source.Count " + pcpa.ToString ());
}
}
[Test]
public void Union_Self ()
{
foreach (PerformanceCounterPermissionAccess pcpa in AllAccess) {
PerformanceCounterPermission pcp = new PerformanceCounterPermission (PermissionState.None);
pcp.PermissionEntries.Add (new PerformanceCounterPermissionEntry (pcpa, pcpa.ToString (), String.Empty));
PerformanceCounterPermission union = (PerformanceCounterPermission)pcp.Union (pcp);
Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted " + pcpa.ToString ());
Assert.AreEqual (1, union.PermissionEntries.Count, "Count " + pcpa.ToString ());
}
}
[Test]
public void Union_Unrestricted ()
{
// Union with unrestricted is unrestricted
PerformanceCounterPermission pcp1 = new PerformanceCounterPermission (PermissionState.Unrestricted);
foreach (PerformanceCounterPermissionAccess pcpa in AllAccess) {
PerformanceCounterPermission pcp2 = new PerformanceCounterPermission (PermissionState.None);
pcp2.PermissionEntries.Add (new PerformanceCounterPermissionEntry (pcpa, pcpa.ToString (), String.Empty));
PerformanceCounterPermission union = (PerformanceCounterPermission)pcp1.Union (pcp2);
Assert.IsTrue (union.IsUnrestricted (), "target.IsUnrestricted " + pcpa.ToString ());
Assert.AreEqual (0, union.PermissionEntries.Count, "target.Count " + pcpa.ToString ());
union = (PerformanceCounterPermission)pcp2.Union (pcp1);
Assert.IsTrue (union.IsUnrestricted (), "source.IsUnrestricted " + pcpa.ToString ());
Assert.AreEqual (0, union.PermissionEntries.Count, "source.Count " + pcpa.ToString ());
}
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Union_BadPermission ()
{
PerformanceCounterPermission pcp1 = new PerformanceCounterPermission (PermissionState.Unrestricted);
pcp1.Union (new SecurityPermission (SecurityPermissionFlag.Assertion));
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#else
// Problem inherited from ResourcePermissionBase
[ExpectedException (typeof (NullReferenceException))]
#endif
public void FromXml_Null ()
{
PerformanceCounterPermission pcp = new PerformanceCounterPermission (PermissionState.None);
pcp.FromXml (null);
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentException))]
#endif
public void FromXml_WrongTag ()
{
PerformanceCounterPermission pcp = new PerformanceCounterPermission (PermissionState.None);
SecurityElement se = pcp.ToXml ();
se.Tag = "IMono";
pcp.FromXml (se);
// note: normally IPermission classes (in corlib) DO care about the
// IPermission tag
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentException))]
#endif
public void FromXml_WrongTagCase ()
{
PerformanceCounterPermission pcp = new PerformanceCounterPermission (PermissionState.None);
SecurityElement se = pcp.ToXml ();
se.Tag = "IPERMISSION"; // instead of IPermission
pcp.FromXml (se);
// note: normally IPermission classes (in corlib) DO care about the
// IPermission tag
}
[Test]
public void FromXml_WrongClass ()
{
PerformanceCounterPermission pcp = new PerformanceCounterPermission (PermissionState.None);
SecurityElement se = pcp.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", "Wrong" + se.Attribute ("class"));
w.AddAttribute ("version", se.Attribute ("version"));
pcp.FromXml (w);
// doesn't care of the class name at that stage
// anyway the class has already be created so...
}
[Test]
public void FromXml_NoClass ()
{
PerformanceCounterPermission pcp = new PerformanceCounterPermission (PermissionState.None);
SecurityElement se = pcp.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("version", se.Attribute ("version"));
pcp.FromXml (w);
// doesn't even care of the class attribute presence
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_WrongVersion ()
{
PerformanceCounterPermission pcp = new PerformanceCounterPermission (PermissionState.None);
SecurityElement se = pcp.ToXml ();
se.Attributes.Remove ("version");
se.Attributes.Add ("version", "2");
pcp.FromXml (se);
}
[Test]
public void FromXml_NoVersion ()
{
PerformanceCounterPermission pcp = new PerformanceCounterPermission (PermissionState.None);
SecurityElement se = pcp.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
pcp.FromXml (w);
}
}
}
#endif

View File

@@ -0,0 +1,60 @@
//
// ProcessStartInfoTest.cs - NUnit Test Cases for System.Diagnostics.ProcessStartInfo
//
// Authors:
// Ankit Jain <jankit@novell.com>
// Atsushi Enomoto <atsushi@ximian.com>
//
// (c) 2007 Novell, Inc. (http://www.novell.com)
//
using System;
using System.Diagnostics;
using System.Text;
using NUnit.Framework;
namespace MonoTests.System.Diagnostics
{
[TestFixture]
public class ProcessStartInfoTest
{
[Test]
public void NullWorkingDirectory ()
{
ProcessStartInfo info = new ProcessStartInfo ();
info.WorkingDirectory = null;
Assert.AreEqual (info.WorkingDirectory, String.Empty, "#1");
}
#if NET_2_0
[Test]
public void StandardErrorOutputEncoding ()
{
ProcessStartInfo info = new ProcessStartInfo ();
Assert.IsNull (info.StandardErrorEncoding, "#1");
Assert.IsNull (info.StandardOutputEncoding, "#2");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void StandardErrorEncodingWithoutRedirect ()
{
ProcessStartInfo info = new ProcessStartInfo ();
info.FileName = "mono";
info.StandardErrorEncoding = Encoding.UTF8;
Process.Start (info);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void StandardOutputEncodingWithoutRedirect ()
{
ProcessStartInfo info = new ProcessStartInfo ();
info.FileName = "mono";
info.StandardOutputEncoding = Encoding.UTF8;
Process.Start (info);
}
#endif
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,104 @@
//
// SourceSwitchTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2007 Novell, Inc.
//
//
// 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 NUnit.Framework;
using System;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Diagnostics;
namespace MonoTests.System.Diagnostics
{
[TestFixture]
public class SourceSwitchTest
{
[Test]
public void ConstructorNullName ()
{
SourceSwitch s = new SourceSwitch (null);
Assert.IsNull (s.DisplayName);
}
[Test]
public void ConstructorNullDefaultValue ()
{
SourceSwitch s = new SourceSwitch ("foo", null);
}
[Test]
public void ConstructorDefault ()
{
SourceSwitch s = new SourceSwitch ("foo");
Assert.AreEqual ("foo", s.DisplayName, "#1");
Assert.AreEqual (SourceLevels.Off, s.Level, "#2");
Assert.AreEqual (0, s.Attributes.Count, "#3");
}
[Test]
public void ShouldTrace ()
{
SourceSwitch s = new SourceSwitch ("foo");
s.Level = SourceLevels.Verbose;
Assert.IsTrue (s.ShouldTrace (TraceEventType.Critical), "#1");
Assert.IsTrue (s.ShouldTrace (TraceEventType.Error), "#2");
Assert.IsTrue (s.ShouldTrace (TraceEventType.Warning), "#3");
Assert.IsTrue (s.ShouldTrace (TraceEventType.Information), "#4");
Assert.IsTrue (s.ShouldTrace (TraceEventType.Verbose), "#5");
Assert.IsFalse (s.ShouldTrace (TraceEventType.Start), "#6");
Assert.IsFalse (s.ShouldTrace (TraceEventType.Stop), "#7");
Assert.IsFalse (s.ShouldTrace (TraceEventType.Suspend), "#8");
Assert.IsFalse (s.ShouldTrace (TraceEventType.Resume), "#9");
Assert.IsFalse (s.ShouldTrace (TraceEventType.Transfer), "#10");
}
[Test]
public void ShouldTrace2 ()
{
SourceSwitch s = new SourceSwitch ("foo");
s.Level = SourceLevels.ActivityTracing;
Assert.IsFalse (s.ShouldTrace (TraceEventType.Critical), "#1");
Assert.IsFalse (s.ShouldTrace (TraceEventType.Error), "#2");
Assert.IsFalse (s.ShouldTrace (TraceEventType.Warning), "#3");
Assert.IsFalse (s.ShouldTrace (TraceEventType.Information), "#4");
Assert.IsFalse (s.ShouldTrace (TraceEventType.Verbose), "#5");
Assert.IsTrue (s.ShouldTrace (TraceEventType.Start), "#6");
Assert.IsTrue (s.ShouldTrace (TraceEventType.Stop), "#7");
Assert.IsTrue (s.ShouldTrace (TraceEventType.Suspend), "#8");
Assert.IsTrue (s.ShouldTrace (TraceEventType.Resume), "#9");
Assert.IsTrue (s.ShouldTrace (TraceEventType.Transfer), "#10");
}
}
}
#endif

View File

@@ -0,0 +1,50 @@
//
// StopwatchTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc.
//
#if NET_2_0
using System;
using System.Diagnostics;
using System.Threading;
using NUnit.Framework;
namespace MonoTests.System.Diagnostics
{
[TestFixture]
public class StopwatchTest
{
[Test]
public void TestSimple ()
{
// It starts at started state.
Stopwatch sw = Stopwatch.StartNew ();
Thread.Sleep (1000);
sw.Stop ();
long ticks = sw.ElapsedTicks;
Assert.IsTrue (sw.ElapsedMilliseconds > 100, "#1");
Thread.Sleep (1000);
// do not increment resuts
Assert.AreEqual (ticks, sw.ElapsedTicks, "#2");
sw.Start ();
Thread.Sleep (1000);
// increment results
Assert.IsTrue (sw.ElapsedTicks > ticks, "#3");
ticks = sw.ElapsedTicks;
sw.Stop ();
Assert.IsTrue (sw.ElapsedTicks >= ticks, "#4");
sw.Reset ();
Assert.AreEqual (0, sw.ElapsedTicks, "#5");
sw.Start ();
Thread.Sleep (1000);
Assert.IsTrue (sw.ElapsedTicks > 100, "#5");
// This test is not strict but would mostly work.
Assert.IsTrue (ticks > sw.ElapsedTicks, "#6");
sw.Stop ();
}
}
}
#endif

View File

@@ -0,0 +1,191 @@
//
// SwitchesTest.cs:
// NUnit Test Cases for System.Diagnostics.BooleanSwitch and
// System.Diagnostics.TraceSwitch
//
// Authors:
// Jonathan Pryor (jonpryor@vt.edu)
// Martin Willemoes Hansen (mwh@sysrq.dk)
//
// (C) 2002 Jonathan Pryor
// (C) 2003 Martin Willemoes Hansen
//
#if !MOBILE
using NUnit.Framework;
using System;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Diagnostics;
namespace MonoTests.System.Diagnostics {
class TestNewSwitch : Switch {
private string v;
private StringBuilder ops = new StringBuilder ();
private const string expected =
".ctor\n" +
"get_TestValue\n" +
"OnSwitchSettingChanged\n" +
"GetSetting\n";
public TestNewSwitch (string name, string desc)
: base (name, desc)
{
ops.Append (".ctor\n");
}
public string TestValue {
get {
ops.Append ("get_TestValue\n");
// ensure that the .config file is read in
int n = base.SwitchSetting;
// remove warning about unused variable
n = 5;
return v;
}
}
#if NET_2_0
public string [] ExposeSupportedAttributes ()
{
return GetSupportedAttributes ();
}
#endif
public bool Validate ()
{
return expected == ops.ToString();
}
private void GetSetting ()
{
ops.Append ("GetSetting\n");
IDictionary d = (IDictionary) ConfigurationSettings.GetConfig ("system.diagnostics");
if (d != null) {
d = (IDictionary) d ["switches"];
if (d != null) {
v = d [DisplayName].ToString();
}
}
}
protected override void OnSwitchSettingChanged ()
{
ops.Append ("OnSwitchSettingChanged\n");
GetSetting ();
}
}
[TestFixture]
public class SwitchesTest {
private static BooleanSwitch bon = new BooleanSwitch ("bool-true", "");
private static BooleanSwitch bon2 = new BooleanSwitch ("bool-true-2", "");
private static BooleanSwitch bon3 = new BooleanSwitch ("bool-true-3", "");
private static BooleanSwitch boff = new BooleanSwitch ("bool-false", "");
private static BooleanSwitch boff2 = new BooleanSwitch ("bool-default", "");
private static TraceSwitch toff = new TraceSwitch ("trace-off", "");
private static TraceSwitch terror = new TraceSwitch ("trace-error", "");
private static TraceSwitch twarning = new TraceSwitch ("trace-warning", "");
private static TraceSwitch tinfo = new TraceSwitch ("trace-info", "");
private static TraceSwitch tverbose = new TraceSwitch ("trace-verbose", "");
private static TraceSwitch tdefault = new TraceSwitch ("no-value", "");
private static TraceSwitch tsv = new TraceSwitch ("string-value", "");
private static TraceSwitch tnegative = new TraceSwitch ("trace-negative", "");
private static TestNewSwitch tns = new TestNewSwitch ("custom-switch", "");
[Test]
public void BooleanSwitches ()
{
Assert.IsTrue (bon.Enabled, "#BS:T:1");
Assert.IsTrue (bon2.Enabled, "#BS:T:2");
Assert.IsTrue (bon3.Enabled, "#BS:T:3");
Assert.IsTrue (!boff.Enabled, "#BS:F:1");
Assert.IsTrue (!boff2.Enabled, "#BS:F:2");
}
[Test]
public void TraceSwitches ()
{
// The levels 0..4:
CheckTraceSwitch (toff, false, false, false, false);
CheckTraceSwitch (terror, true, false, false, false);
CheckTraceSwitch (twarning, true, true, false, false);
CheckTraceSwitch (tinfo, true, true, true, false);
CheckTraceSwitch (tverbose, true, true, true, true);
// Default value is 0
CheckTraceSwitch (tdefault, false, false, false, false);
// string value can't be converted to int, so default is 0
CheckTraceSwitch (tsv, false, false, false, false);
// negative number is < 0, so all off
CheckTraceSwitch (tnegative, false, false, false, false);
}
private void CheckTraceSwitch (TraceSwitch ts, bool te, bool tw, bool ti, bool tv)
{
string desc = string.Format ("#TS:{0}", ts.DisplayName);
Assert.AreEqual (te, ts.TraceError, desc + ":TraceError");
Assert.AreEqual (tw, ts.TraceWarning, desc + ":TraceWarning");
Assert.AreEqual (ti, ts.TraceInfo, desc + ":TraceInfo");
Assert.AreEqual (tv, ts.TraceVerbose, desc + ":TraceVerbose");
}
[Test]
#if NET_2_0
[Ignore ("this test depends on 1.x configuration type")]
#endif
public void NewSwitch ()
{
Assert.AreEqual ("42", tns.TestValue, "#NS:TestValue");
Assert.IsTrue (tns.Validate(), "#NS:Validate");
}
#if NET_2_0
[Test]
public void GetSupportedAttributes ()
{
Assert.IsNull (tns.ExposeSupportedAttributes ());
}
[Test] // no ArgumentNullException happens...
public void BooleanSwitchNullDefaultValue ()
{
new BooleanSwitch ("test", "", null);
}
[Test]
public void BooleanSwitchValidDefaultValue ()
{
BooleanSwitch s = new BooleanSwitch ("test", "", "2");
Assert.IsTrue (s.Enabled, "#1");
s = new BooleanSwitch ("test", "", "0");
Assert.IsTrue (!s.Enabled, "#2");
s = new BooleanSwitch ("test", "", "true");
Assert.IsTrue (s.Enabled, "#3");
s = new BooleanSwitch ("test", "", "True");
Assert.IsTrue (s.Enabled, "#4");
s = new BooleanSwitch ("test", "", "truE");
Assert.IsTrue (s.Enabled, "#5");
}
[Test]
[ExpectedException (typeof (FormatException))]
public void BooleanSwitchInvalidDefaultValue ()
{
BooleanSwitch s = new BooleanSwitch ("test", "", "hoge");
Assert.IsTrue (!s.Enabled);
}
#endif
}
}
#endif

View File

@@ -0,0 +1,62 @@
//
// MonoTests.System.Diagnostics.TextWriterTraceListenerTest.cs
//
// Author:
// John R. Hicks (angryjohn69@nc.rr.com)
//
// (C) 2001
#if !MOBILE
using System;
using System.IO;
using System.Text;
using System.Diagnostics;
using NUnit.Framework;
namespace MonoTests.System.Diagnostics
{
[TestFixture]
public class TextWriterTraceListenerTest
{
private TextWriterTraceListener listener;
[SetUp]
public void SetUp()
{
listener = new TextWriterTraceListener();
listener.Writer = Console.Out;
}
[TearDown]
public void TearDown()
{
listener = null;
}
[Test]
public void TestWrite()
{
Assert.IsTrue(!(listener == null), "Null Listener");
Assert.IsTrue(!(listener.Writer == null), "Null Writer");
listener.Write("Test Message\n");
}
[Test]
public void TestWriteLine()
{
Assert.IsTrue(!(listener == null), "Null Listener");
Assert.IsTrue(!(listener.Writer == null), "Null Writer");
listener.WriteLine("Test WriteLine Message");
}
[Test]
public void TestFlush()
{
listener.Flush();
}
}
}
#endif

View File

@@ -0,0 +1,143 @@
//
// TraceListenerTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2007 Novell, Inc.
//
//
// 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 NUnit.Framework;
using System;
using System.IO;
using System.Diagnostics;
using System.Threading;
namespace MonoTests.System.Diagnostics
{
[TestFixture]
public class TraceListenerTest
{
#if NET_2_0
[Test]
public void GetSupportedAttributes ()
{
MyTraceListener t = new MyTraceListener ();
string [] attributes = t.SupportedAttributes;
Assert.IsNull (attributes);
}
[Test]
public void TraceEventAndTraceData ()
{
StringWriter sw = new StringWriter ();
TextWriterTraceListener t = new TextWriterTraceListener (sw);
t.TraceEvent (null, null, TraceEventType.Error, 0, null);
t.TraceEvent (null, "bulldog", TraceEventType.Error, 0);
TraceEventCache cc = new TraceEventCache ();
t.TraceData (cc, null, TraceEventType.Error, 0);
t.TraceData (cc, null, TraceEventType.Error, 0);
t.TraceTransfer (null, "bulldog", 0, "hoge", Guid.Empty);
t.Close ();
string expected = @" Error: 0 :
bulldog Error: 0 :
Error: 0 :
Error: 0 :
bulldog Transfer: 0 : hoge, relatedActivityId=00000000-0000-0000-0000-000000000000
";
Assert.AreEqual (expected, sw.ToString ().Replace ("\r\n", "\n"));
}
[Test]
public void TraceOptionValues ()
{
Assert.AreEqual (TraceOptions.None,
new TextWriterTraceListener (TextWriter.Null).TraceOutputOptions, "#1");
Assert.AreEqual (TraceOptions.None,
new XmlWriterTraceListener (TextWriter.Null).TraceOutputOptions, "#2");
StringWriter sw = new StringWriter ();
TextWriterTraceListener t = new TextWriterTraceListener (sw);
Trace.CorrelationManager.StartLogicalOperation ("foo");
Trace.CorrelationManager.StartLogicalOperation ("bar");
t.TraceOutputOptions = TraceOptions.LogicalOperationStack | TraceOptions.DateTime | TraceOptions.Timestamp;// | TraceOptions.ProcessId | TraceOptions.ThreadId | TraceOptions.Callstack;
t.TraceEvent (null, null, TraceEventType.Error, 0, null);
t.TraceEvent (null, "bulldog", TraceEventType.Error, 0);
TraceEventCache cc = new TraceEventCache ();
DateTime date = cc.DateTime;
long time = cc.Timestamp;
t.TraceData (cc, null, TraceEventType.Error, 0);
t.TraceData (cc, null, TraceEventType.Error, 0);
t.TraceTransfer (null, "bulldog", 0, "hoge", Guid.Empty);
Trace.CorrelationManager.StopLogicalOperation ();
Trace.CorrelationManager.StopLogicalOperation ();
t.Close ();
string expected = String.Format (@" Error: 0 :
bulldog Error: 0 :
Error: 0 :
LogicalOperationStack=bar, foo
DateTime={0}
Timestamp={1}" +
/*
Callstack= at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at System.Diagnostics.TraceEventCache.get_Callstack()
at System.Diagnostics.TraceListener.WriteFooter(TraceEventCache eventCache)
at System.Diagnostics.TraceListener.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object[] data)
at MonoTests.System.Diagnostics.TraceListenerTest.TraceOptionValues()
...
*/
@"
Error: 0 :
LogicalOperationStack=bar, foo
DateTime={0}
Timestamp={1}
bulldog Transfer: 0 : hoge, relatedActivityId=00000000-0000-0000-0000-000000000000
", date.ToString ("o"), time); // date and time are in current culture
Assert.AreEqual (expected, sw.ToString ().Replace ("\r\n", "\n"));
}
#endif
class MyTraceListener : TraceListener
{
#if NET_2_0
public string [] SupportedAttributes {
get { return base.GetSupportedAttributes (); }
}
#endif
public override void Write (string message)
{
}
public override void WriteLine (string message)
{
}
}
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More