Author: rolf
Date: 2007-01-15 04:14:21 -0500 (Mon, 15 Jan 2007)
New Revision: 71009

Added:
   trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/
   trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/AspLogTest.cs
   trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/ChangeLog
   
trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/FileLogTraceListener.cs
   trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/LogTest.cs
Log:
2007-01-15  Rolf Bjarne Kvinge  <[EMAIL PROTECTED]>

        * AspLogTest.cs, FileLogTraceListener.cs, LogTest.cs


Added: 
trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/AspLogTest.cs
===================================================================
--- trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/AspLogTest.cs 
2007-01-15 09:13:19 UTC (rev 71008)
+++ trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/AspLogTest.cs 
2007-01-15 09:14:21 UTC (rev 71009)
@@ -0,0 +1,54 @@
+// AspLogTest.cs - NUnit Test Cases for Microsoft.VisualBasic.Logging.AspLog
+//
+// Rolf Bjarne Kvinge  ([EMAIL PROTECTED])
+//
+// 
+// Copyright (C) 2007 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 NET_2_0
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NUnit.Framework;
+using Microsoft.VisualBasic.Logging;
+
+namespace MonoTests.Microsoft_VisualBasic.Logging
+{
+       [TestFixture]
+       public class AspLogTest
+       {
+               [Test]
+               public void TestDefaults ()
+               {
+                       AspLog log = new AspLog ();
+                       Assert.IsNull (log.DefaultFileLogWriter, "#01");
+                       Assert.AreEqual ("DefaultSource", log.TraceSource.Name, 
"#02");
+                       Assert.AreEqual (2, log.TraceSource.Listeners.Count, 
"#03");
+                       Assert.AreEqual ("Default", 
Helper.getObjects<System.Diagnostics.TraceListener> (log.TraceSource.Listeners) 
[0].Name, "#04");
+                       Assert.AreEqual ("", 
Helper.getObjects<System.Diagnostics.TraceListener> (log.TraceSource.Listeners) 
[1].Name, "#05");
+                       Assert.AreEqual ("DefaultTraceListener", 
Helper.getObjects<System.Diagnostics.TraceListener> (log.TraceSource.Listeners) 
[0].GetType ().Name, "#06");
+                       Assert.AreEqual ("WebPageTraceListener", 
Helper.getObjects<System.Diagnostics.TraceListener> (log.TraceSource.Listeners) 
[1].GetType ().Name, "#07");
+                       Assert.AreEqual 
(System.Diagnostics.SourceLevels.Information, log.TraceSource.Switch.Level, 
"#08");
+               }
+       }
+}
+#endif
\ No newline at end of file

Added: trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/ChangeLog
===================================================================
--- trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/ChangeLog     
2007-01-15 09:13:19 UTC (rev 71008)
+++ trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/ChangeLog     
2007-01-15 09:14:21 UTC (rev 71009)
@@ -0,0 +1,3 @@
+2007-01-15  Rolf Bjarne Kvinge  <[EMAIL PROTECTED]>
+
+       * AspLogTest.cs, FileLogTraceListener.cs, LogTest.cs
\ No newline at end of file

Added: 
trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/FileLogTraceListener.cs
===================================================================
--- 
trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/FileLogTraceListener.cs
       2007-01-15 09:13:19 UTC (rev 71008)
+++ 
trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/FileLogTraceListener.cs
       2007-01-15 09:14:21 UTC (rev 71009)
@@ -0,0 +1,346 @@
+// FileLogTraceListenerTest.cs - NUnit Test Cases for 
Microsoft.VisualBasic.Logging.FileLogTraceListener
+//
+// Rolf Bjarne Kvinge  ([EMAIL PROTECTED])
+//
+// 
+// Copyright (C) 2007 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 NET_2_0
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NUnit.Framework;
+using Microsoft.VisualBasic.Logging;
+using System.Globalization;
+
+namespace MonoTests.Microsoft_VisualBasic.Logging
+{
+       [TestFixture]
+       public class FileLogTraceListenerTest
+       {
+               [Test]
+               public void SupportedAttributesTest ()
+               {
+                       Derived derived = new Derived ();
+                       Assert.AreEqual (Microsoft.VisualBasic.Strings.Join 
(derived.GetAttribs (), ";"), 
"append;Append;autoflush;AutoFlush;autoFlush;basefilename;BaseFilename;baseFilename;BaseFileName;baseFileName;customlocation;CustomLocation;customLocation;delimiter;Delimiter;diskspaceexhaustedbehavior;DiskSpaceExhaustedBehavior;diskSpaceExhaustedBehavior;encoding;Encoding;includehostname;IncludeHostName;includeHostName;location;Location;logfilecreationschedule;LogFileCreationSchedule;logFileCreationSchedule;maxfilesize;MaxFileSize;maxFileSize;reservediskspace;ReserveDiskSpace;reserveDiskSpace",
 "#01");
+               }
+               
+               [Test]
+               public void DefaultPropertiesTest ()
+               {
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               Assert.AreEqual (true, log.Append, "A1");
+                               Assert.AreEqual (false, log.AutoFlush, "A2");
+                               Assert.AreEqual 
(System.IO.Path.GetFileNameWithoutExtension(System.Windows.Forms.Application.ExecutablePath),
 log.BaseFileName, "B1");
+                               Assert.AreEqual 
(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, 
log.CustomLocation, "C1");
+                               Assert.AreEqual ("\t", log.Delimiter, "D1");
+                               Assert.AreEqual 
(DiskSpaceExhaustedOption.DiscardMessages, log.DiskSpaceExhaustedBehavior, 
"D2");
+                               Assert.AreEqual 
(System.Text.Encoding.UTF8.EncodingName, log.Encoding.EncodingName, "E1");
+                               Assert.AreEqual 
(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData,
 log.BaseFileName) + ".log", log.FullLogFileName, "F1");
+                               Assert.IsNull   (log.Filter, "F2");
+                               Assert.AreEqual (false, log.IncludeHostName, 
"I1");
+                               Assert.AreEqual 
(LogFileLocation.LocalUserApplicationDirectory, log.Location, "L1");
+                               Assert.AreEqual 
(LogFileCreationScheduleOption.None, log.LogFileCreationSchedule, "L2");
+                               Assert.AreEqual (5000000, log.MaxFileSize, 
"M1");
+                               Assert.AreEqual ("FileLogTraceListener", 
log.Name, "N1");
+                               Assert.AreEqual (10000000, 
log.ReserveDiskSpace, "R1");
+                       }
+               }
+               
+               [Test]
+               public void FilenameTest ()
+               {
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               log.LogFileCreationSchedule = 
LogFileCreationScheduleOption.None;
+                               log.Location = 
LogFileLocation.CommonApplicationDirectory;
+                               Assert.AreEqual 
(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.AllUsersApplicationData,
 log.BaseFileName) + ".log", log.FullLogFileName, "#A1");
+
+                               log.Location = 
LogFileLocation.ExecutableDirectory;
+                               Assert.AreEqual (System.IO.Path.Combine 
(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath),
 log.BaseFileName) + ".log", log.FullLogFileName, "#A2");
+
+                               log.Location = 
LogFileLocation.LocalUserApplicationDirectory;
+                               Assert.AreEqual (System.IO.Path.Combine 
(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, 
log.BaseFileName) + ".log", log.FullLogFileName, "#A3");
+
+                               log.Location = LogFileLocation.TempDirectory;
+                               Assert.AreEqual (System.IO.Path.Combine 
(Microsoft.VisualBasic.FileIO.SpecialDirectories.Temp, log.BaseFileName) + 
".log", log.FullLogFileName, "#A4");
+
+                               log.Location = LogFileLocation.Custom;
+                               Assert.AreEqual (System.IO.Path.Combine 
(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, 
log.BaseFileName) + ".log", log.FullLogFileName, "#A5");
+                               
+                               log.CustomLocation = 
Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments;
+                               Assert.AreEqual (System.IO.Path.Combine 
(Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments, log.BaseFileName) 
+ ".log", log.FullLogFileName, "#A6");
+                       }
+
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               log.LogFileCreationSchedule = 
LogFileCreationScheduleOption.Daily;
+                               log.Location = 
LogFileLocation.CommonApplicationDirectory;
+                               Assert.AreEqual (System.IO.Path.Combine 
(Microsoft.VisualBasic.FileIO.SpecialDirectories.AllUsersApplicationData, 
log.BaseFileName) + DateTime.Now.ToString("-yyyy-MM-dd") + ".log", 
log.FullLogFileName, "#B1");
+
+                               log.Location = 
LogFileLocation.ExecutableDirectory;
+                               Assert.AreEqual (System.IO.Path.Combine 
(System.IO.Path.GetDirectoryName 
(System.Windows.Forms.Application.ExecutablePath), log.BaseFileName) + 
DateTime.Now.ToString ("-yyyy-MM-dd") + ".log", log.FullLogFileName, "#B2");
+
+                               log.Location = 
LogFileLocation.LocalUserApplicationDirectory;
+                               Assert.AreEqual (System.IO.Path.Combine 
(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, 
log.BaseFileName) + DateTime.Now.ToString ("-yyyy-MM-dd") + ".log", 
log.FullLogFileName, "#B3");
+
+                               log.Location = LogFileLocation.TempDirectory;
+                               Assert.AreEqual (System.IO.Path.Combine 
(Microsoft.VisualBasic.FileIO.SpecialDirectories.Temp, log.BaseFileName) + 
DateTime.Now.ToString ("-yyyy-MM-dd") + ".log", log.FullLogFileName, "#B4");
+
+                               log.Location = LogFileLocation.Custom;
+                               Assert.AreEqual (System.IO.Path.Combine 
(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, 
log.BaseFileName) + DateTime.Now.ToString ("-yyyy-MM-dd") + ".log", 
log.FullLogFileName, "#B5");
+
+                               log.CustomLocation = 
Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments;
+                               Assert.AreEqual (System.IO.Path.Combine 
(Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments, log.BaseFileName) 
+ DateTime.Now.ToString ("-yyyy-MM-dd") + ".log", log.FullLogFileName, "#B6");
+                       }
+
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               DateTime dt = DateTime.Today.AddDays 
(-(int)DateTime.Today.DayOfWeek);
+                               string format = dt.ToString ("-yyyy-MM-dd");
+                               log.LogFileCreationSchedule = 
LogFileCreationScheduleOption.Weekly;
+                               log.Location = 
LogFileLocation.CommonApplicationDirectory;
+                               Assert.AreEqual (System.IO.Path.Combine 
(Microsoft.VisualBasic.FileIO.SpecialDirectories.AllUsersApplicationData, 
log.BaseFileName) + format + ".log", log.FullLogFileName, "#C1");
+
+                               log.Location = 
LogFileLocation.ExecutableDirectory;
+                               Assert.AreEqual (System.IO.Path.Combine 
(System.IO.Path.GetDirectoryName 
(System.Windows.Forms.Application.ExecutablePath), log.BaseFileName) + format + 
".log", log.FullLogFileName, "#C2");
+
+                               log.Location = 
LogFileLocation.LocalUserApplicationDirectory;
+                               Assert.AreEqual (System.IO.Path.Combine 
(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, 
log.BaseFileName) + format + ".log", log.FullLogFileName, "#C3");
+
+                               log.Location = LogFileLocation.TempDirectory;
+                               Assert.AreEqual (System.IO.Path.Combine 
(Microsoft.VisualBasic.FileIO.SpecialDirectories.Temp, log.BaseFileName) + 
format + ".log", log.FullLogFileName, "#C4");
+
+                               log.Location = LogFileLocation.Custom;
+                               Assert.AreEqual (System.IO.Path.Combine 
(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, 
log.BaseFileName) + format + ".log", log.FullLogFileName, "#C5");
+
+                               log.CustomLocation = 
Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments;
+                               Assert.AreEqual (System.IO.Path.Combine 
(Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments, log.BaseFileName) 
+ format + ".log", log.FullLogFileName, "#C6");
+                       }
+               }
+               
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void DiskSpaceTest1 ()
+               {
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               log.Location = LogFileLocation.TempDirectory;
+                               log.ReserveDiskSpace = new System.IO.DriveInfo 
(log.FullLogFileName [0].ToString ()).TotalFreeSpace;
+                               log.DiskSpaceExhaustedBehavior = 
DiskSpaceExhaustedOption.ThrowException;
+                               log.WriteLine ("TestLine");     
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void DiskSpaceTest2 ()
+               {
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               log.MaxFileSize = 0;
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void DiskSpaceTest3 ()
+               {
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               log.Location = LogFileLocation.TempDirectory;
+                               log.MaxFileSize = 1000;
+                               log.DiskSpaceExhaustedBehavior = 
DiskSpaceExhaustedOption.ThrowException;
+                               log.Write (new string('z', 1001));
+                       }
+               }
+               
+               [Test]
+               public void WriteTest ()
+               {
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               log.Filter = new 
System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All);
+                               string filename = log.FullLogFileName;
+                               string data;
+                               System.Diagnostics.TraceEventCache cache = new 
System.Diagnostics.TraceEventCache ();
+                               
+                               log.TraceData (cache, "nunit", 
System.Diagnostics.TraceEventType.Critical, 0, null);
+                               log.Close ();
+                               data = 
Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename);
+                               
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename);
+                               
+                               Assert.AreEqual ("nunit\tCritical\t0\t\r\n", 
data, "#01");
+                       }
+
+
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               log.Filter = new 
System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All);
+                               string filename = log.FullLogFileName;
+                               string data;
+                               System.Diagnostics.TraceEventCache cache = new 
System.Diagnostics.TraceEventCache ();
+
+                               log.TraceData (cache, "nunit", 
System.Diagnostics.TraceEventType.Critical, 0, "data");
+                               log.Close ();
+                               data = 
Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename);
+                               
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename);
+
+                               Assert.AreEqual 
("nunit\tCritical\t0\tdata\r\n", data, "#02");
+                       }
+
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               log.Filter = new 
System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All);
+                               string filename = log.FullLogFileName;
+                               string data;
+                               System.Diagnostics.TraceEventCache cache = new 
System.Diagnostics.TraceEventCache ();
+
+                               log.TraceData (cache, "nunit", 
System.Diagnostics.TraceEventType.Critical, 0, "data", "data2");
+                               log.Close ();
+                               data = 
Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename);
+                               
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename);
+
+                               Assert.AreEqual 
("nunit\tCritical\t0\tdata\tdata2\r\n", data, "#03");
+                       }
+
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               log.Filter = new 
System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All);
+                               string filename = log.FullLogFileName;
+                               string data;
+                               System.Diagnostics.TraceEventCache cache = new 
System.Diagnostics.TraceEventCache ();
+
+                               log.TraceEvent (cache, "nunit", 
System.Diagnostics.TraceEventType.Critical, 0, "msg");
+                               log.Close ();
+                               data = 
Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename);
+                               
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename);
+
+                               Assert.AreEqual ("nunit\tCritical\t0\tmsg\r\n", 
data, "#04");
+                       }
+
+
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               log.Filter = new 
System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All);
+                               string filename = log.FullLogFileName;
+                               string data;
+                               System.Diagnostics.TraceEventCache cache = new 
System.Diagnostics.TraceEventCache ();
+
+                               log.TraceEvent (cache, "nunit", 
System.Diagnostics.TraceEventType.Critical, 0, "msg:{0}", "arg1");
+                               log.Close ();
+                               data = 
Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename);
+                               
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename);
+
+                               Assert.AreEqual 
("nunit\tCritical\t0\tmsg:arg1\r\n", data, "#05");
+                       }
+                       
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               log.Filter = new 
System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All);
+                               string filename = log.FullLogFileName;
+                               string data;
+                               System.Diagnostics.TraceEventCache cache = new 
System.Diagnostics.TraceEventCache ();
+                               
+                               log.TraceOutputOptions = 
System.Diagnostics.TraceOptions.DateTime | 
System.Diagnostics.TraceOptions.LogicalOperationStack | 
System.Diagnostics.TraceOptions.ProcessId | 
System.Diagnostics.TraceOptions.ThreadId | 
System.Diagnostics.TraceOptions.Timestamp;
+                               log.TraceData (cache, "nunit", 
System.Diagnostics.TraceEventType.Critical, 0, null);
+                               log.Close ();
+                               data = 
Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename);
+                               
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename);
+                               
+                               Assert.AreEqual ("nunit\tCritical\t0\t\t\"\"\t" 
+ cache.DateTime.ToString ("u", CultureInfo.InvariantCulture) + "\t" + 
cache.ProcessId + "\t" + cache.ThreadId + "\t" + cache.Timestamp + 
System.Environment.NewLine, data, "#06");
+                       }
+
+
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               log.Filter = new 
System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All);
+                               log.IncludeHostName = true;
+                               
+                               string filename = log.FullLogFileName;
+                               string data;
+                               System.Diagnostics.TraceEventCache cache = new 
System.Diagnostics.TraceEventCache ();
+
+                               log.TraceOutputOptions = 
System.Diagnostics.TraceOptions.DateTime | 
System.Diagnostics.TraceOptions.LogicalOperationStack | 
System.Diagnostics.TraceOptions.ProcessId | 
System.Diagnostics.TraceOptions.ThreadId | 
System.Diagnostics.TraceOptions.Timestamp;
+                               log.TraceData (cache, "nunit", 
System.Diagnostics.TraceEventType.Critical, 0, null);
+                               log.Close ();
+                               data = 
Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename);
+                               
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename);
+
+                               Assert.AreEqual ("nunit\tCritical\t0\t\t\"\"\t" 
+ cache.DateTime.ToString ("u", CultureInfo.InvariantCulture) + "\t" + 
cache.ProcessId + "\t" + cache.ThreadId + "\t" + cache.Timestamp + "\t" + 
Environment.MachineName + System.Environment.NewLine, data, "#07");
+                       }
+               }
+               
+               [Test]
+               public void AppendTest ()
+               {
+
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               log.Filter = new 
System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All);
+                               log.Append = false;
+                               string filename = log.FullLogFileName;
+                               string data;
+                               System.Diagnostics.TraceEventCache cache = new 
System.Diagnostics.TraceEventCache ();
+
+                               log.TraceData (cache, "nunit", 
System.Diagnostics.TraceEventType.Critical, 0, null);
+                               log.Close ();
+                               data = 
Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename);
+
+                               Assert.AreEqual ("nunit\tCritical\t0\t\r\n", 
data, "#01");      
+                       }
+
+
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               log.Filter = new 
System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All);
+                               log.Append = true;
+                               string filename = log.FullLogFileName;
+                               string data;
+                               System.Diagnostics.TraceEventCache cache = new 
System.Diagnostics.TraceEventCache ();
+
+                               log.TraceData (cache, "nunit", 
System.Diagnostics.TraceEventType.Critical, 0, null);
+                               log.Close ();
+                               data = 
Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename);
+
+                               Assert.AreEqual ("nunit\tCritical\t0\t\r\n" + 
"nunit\tCritical\t0\t\r\n", data, "#02");
+                       }
+
+                       using (FileLogTraceListener log = new 
FileLogTraceListener ()) {
+                               log.Filter = new 
System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All);
+                               log.Append = false;
+                               string filename = log.FullLogFileName;
+                               string data;
+                               System.Diagnostics.TraceEventCache cache = new 
System.Diagnostics.TraceEventCache ();
+
+                               log.TraceData (cache, "nunit", 
System.Diagnostics.TraceEventType.Critical, 0, null);
+                               log.Close ();
+                               data = 
Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename);
+
+                               Assert.AreEqual ("nunit\tCritical\t0\t\r\n", 
data, "#03");
+                               
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename);
+                       }
+                       
+                       
+               }
+               
+       }
+       
+       class Derived : FileLogTraceListener
+       {
+               protected override string [] GetSupportedAttributes ()
+               {
+                       return base.GetSupportedAttributes ();
+               }
+               
+               public string [] GetAttribs ()
+               {
+                       return GetSupportedAttributes ();
+               }
+       }
+}
+#endif
\ No newline at end of file

Added: trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/LogTest.cs
===================================================================
--- trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/LogTest.cs    
2007-01-15 09:13:19 UTC (rev 71008)
+++ trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.Logging/LogTest.cs    
2007-01-15 09:14:21 UTC (rev 71009)
@@ -0,0 +1,230 @@
+// LogTest.cs - NUnit Test Cases for Microsoft.VisualBasic.Logging.Log
+//
+// Rolf Bjarne Kvinge  ([EMAIL PROTECTED])
+//
+// 
+// Copyright (C) 2007 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 NET_2_0
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NUnit.Framework;
+using Microsoft.VisualBasic.Logging;
+
+namespace MonoTests.Microsoft_VisualBasic.Logging
+{
+       [TestFixture]
+       public class LoggingTest
+       {
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void TestWriteExNull1 ()
+               {
+                       Log log = new Log ();
+                       log.WriteException (null);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void TestWriteExNull2 ()
+               {
+                       Log log = new Log ();
+                       log.WriteException (null, 
System.Diagnostics.TraceEventType.Information, "");
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void TestWriteExNull3 ()
+               {
+                       Log log = new Log ();
+                       log.WriteException (null, 
System.Diagnostics.TraceEventType.Information, "", 0);
+               }
+
+               [Test]
+               public void TestWriteEx1 ()
+               {
+                       Log log = new Log ();
+                       string em = "ExceptionMessage";
+                       string ai = "AdditionalInformation";
+                       Exception ex = new Exception (em);
+                       System.IO.StringWriter writer = new 
System.IO.StringWriter();
+                       
+                       log.TraceSource.Listeners.Clear();
+                       log.TraceSource.Listeners.Add (new 
System.Diagnostics.TextWriterTraceListener (writer));
+                       log.TraceSource.Switch.Level = 
System.Diagnostics.SourceLevels.All;
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteException (ex, 
System.Diagnostics.TraceEventType.Information, "");
+                       Assert.AreEqual ("DefaultSource Information: 0 : 
ExceptionMessage" + System.Environment.NewLine, writer.ToString (), "#01");
+                       
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteException (ex, 
System.Diagnostics.TraceEventType.Error, ai);
+                       Assert.AreEqual (string.Format("DefaultSource Error: 2 
: {0} {1}" + System.Environment.NewLine, em, ai), writer.ToString (), "#02");
+                       
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteException (ex, 
System.Diagnostics.TraceEventType.Warning, ai, 200);
+                       Assert.AreEqual (string.Format ("DefaultSource Warning: 
200 : {0} {1}" + System.Environment.NewLine, em, ai), writer.ToString (), 
"#03");
+                       
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteException (ex);
+                       Assert.AreEqual (string.Format ("DefaultSource Error: 2 
: {0}" + System.Environment.NewLine, em, ai), writer.ToString (), "#04");
+
+
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteException (ex, 
System.Diagnostics.TraceEventType.Critical, null);
+                       Assert.AreEqual (string.Format ("DefaultSource 
Critical: 3 : {0}" + System.Environment.NewLine, em, ai), writer.ToString (), 
"#10");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteException (ex, 
System.Diagnostics.TraceEventType.Error, null);
+                       Assert.AreEqual (string.Format ("DefaultSource Error: 2 
: {0}" + System.Environment.NewLine, em, ai), writer.ToString (), "#11");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteException (ex, 
System.Diagnostics.TraceEventType.Information, null);
+                       Assert.AreEqual (string.Format ("DefaultSource 
Information: 0 : {0}" + System.Environment.NewLine, em, ai), writer.ToString 
(), "#12");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteException (ex, 
System.Diagnostics.TraceEventType.Resume, null);
+                       Assert.AreEqual (string.Format ("DefaultSource Resume: 
7 : {0}" + System.Environment.NewLine, em, ai), writer.ToString (), "#13");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteException (ex, 
System.Diagnostics.TraceEventType.Start, null);
+                       Assert.AreEqual (string.Format ("DefaultSource Start: 4 
: {0}" + System.Environment.NewLine, em, ai), writer.ToString (), "#14");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteException (ex, 
System.Diagnostics.TraceEventType.Stop, null);
+                       Assert.AreEqual (string.Format ("DefaultSource Stop: 5 
: {0}" + System.Environment.NewLine, em, ai), writer.ToString (), "#15");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteException (ex, 
System.Diagnostics.TraceEventType.Suspend, null);
+                       Assert.AreEqual (string.Format ("DefaultSource Suspend: 
6 : {0}" + System.Environment.NewLine, em, ai), writer.ToString (), "#16");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteException (ex, 
System.Diagnostics.TraceEventType.Transfer, null);
+                       Assert.AreEqual (string.Format ("DefaultSource 
Transfer: 9 : {0}" + System.Environment.NewLine, em, ai), writer.ToString (), 
"#17");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteException (ex, 
System.Diagnostics.TraceEventType.Verbose, null);
+                       Assert.AreEqual (string.Format ("DefaultSource Verbose: 
8 : {0}" + System.Environment.NewLine, em, ai), writer.ToString (), "#18");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteException (ex, 
System.Diagnostics.TraceEventType.Warning, null);
+                       Assert.AreEqual (string.Format ("DefaultSource Warning: 
1 : {0}" + System.Environment.NewLine, em, ai), writer.ToString (), "#19");
+               }
+
+
+               [Test]
+               public void TestWriteEntry1 ()
+               {
+                       Log log = new Log ();
+                       string msg = "AdditionalInformation";
+                       
+                       System.IO.StringWriter writer = new 
System.IO.StringWriter ();
+
+                       log.TraceSource.Listeners.Clear ();
+                       log.TraceSource.Listeners.Add (new 
System.Diagnostics.TextWriterTraceListener (writer));
+                       log.TraceSource.Switch.Level = 
System.Diagnostics.SourceLevels.All;
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteEntry (msg);
+                       Assert.AreEqual ("DefaultSource Information: 0 : 
AdditionalInformation" + System.Environment.NewLine, writer.ToString (), "#01");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteEntry (msg, 
System.Diagnostics.TraceEventType.Error);
+                       Assert.AreEqual (string.Format ("DefaultSource Error: 2 
: {0}" + System.Environment.NewLine, msg), writer.ToString (), "#02");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteEntry (msg, 
System.Diagnostics.TraceEventType.Warning, 200);
+                       Assert.AreEqual (string.Format ("DefaultSource Warning: 
200 : {0}" + System.Environment.NewLine, msg), writer.ToString (), "#03");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteEntry (msg, 
System.Diagnostics.TraceEventType.Suspend);
+                       Assert.AreEqual (string.Format ("DefaultSource Suspend: 
6 : {0}" + System.Environment.NewLine, msg), writer.ToString (), "#04");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteEntry (null);
+                       Assert.AreEqual (string.Format ("DefaultSource 
Information: 0 : " + System.Environment.NewLine), writer.ToString (), "#05");   
 
+                                       
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteEntry (msg, 
System.Diagnostics.TraceEventType.Critical);
+                       Assert.AreEqual (string.Format ("DefaultSource 
Critical: 3 : {0}" + System.Environment.NewLine, msg), writer.ToString (), 
"#10");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteEntry (msg, 
System.Diagnostics.TraceEventType.Error);
+                       Assert.AreEqual (string.Format ("DefaultSource Error: 2 
: {0}" + System.Environment.NewLine, msg), writer.ToString (), "#11");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteEntry (msg, 
System.Diagnostics.TraceEventType.Information);
+                       Assert.AreEqual (string.Format ("DefaultSource 
Information: 0 : {0}" + System.Environment.NewLine, msg), writer.ToString (), 
"#12");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteEntry (msg, 
System.Diagnostics.TraceEventType.Resume);
+                       Assert.AreEqual (string.Format ("DefaultSource Resume: 
7 : {0}" + System.Environment.NewLine, msg), writer.ToString (), "#13");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteEntry (msg, 
System.Diagnostics.TraceEventType.Start);
+                       Assert.AreEqual (string.Format ("DefaultSource Start: 4 
: {0}" + System.Environment.NewLine, msg), writer.ToString (), "#14");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteEntry (msg, 
System.Diagnostics.TraceEventType.Stop);
+                       Assert.AreEqual (string.Format ("DefaultSource Stop: 5 
: {0}" + System.Environment.NewLine, msg), writer.ToString (), "#15");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteEntry (msg, 
System.Diagnostics.TraceEventType.Suspend);
+                       Assert.AreEqual (string.Format ("DefaultSource Suspend: 
6 : {0}" + System.Environment.NewLine, msg), writer.ToString (), "#16");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteEntry (msg, 
System.Diagnostics.TraceEventType.Transfer);
+                       Assert.AreEqual (string.Format ("DefaultSource 
Transfer: 9 : {0}" + System.Environment.NewLine, msg), writer.ToString (), 
"#17");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteEntry (msg, 
System.Diagnostics.TraceEventType.Verbose);
+                       Assert.AreEqual (string.Format ("DefaultSource Verbose: 
8 : {0}" + System.Environment.NewLine, msg), writer.ToString (), "#18");
+
+                       writer.GetStringBuilder ().Length = 0;
+                       log.WriteEntry (msg, 
System.Diagnostics.TraceEventType.Warning);
+                       Assert.AreEqual (string.Format ("DefaultSource Warning: 
1 : {0}" + System.Environment.NewLine, msg), writer.ToString (), "#19");
+               }
+               
+               [Test]
+               public void TestDefaults ()
+               {
+                       Log log = new Log ();
+                       Assert.AreEqual ("FileLog", 
log.DefaultFileLogWriter.Name, "#01");
+                       Assert.AreEqual ("DefaultSource", log.TraceSource.Name, 
"#02");
+                       Assert.AreEqual (2, log.TraceSource.Listeners.Count, 
"#03");
+                       Assert.AreEqual ("Default", getObjects 
(log.TraceSource.Listeners) [0].Name, "#04");
+                       Assert.AreEqual ("FileLog", getObjects 
(log.TraceSource.Listeners) [1].Name, "#05");
+                       Assert.AreEqual ("DefaultTraceListener", getObjects 
(log.TraceSource.Listeners) [0].GetType ().Name, "#06");
+                       Assert.AreEqual ("FileLogTraceListener", getObjects 
(log.TraceSource.Listeners) [1].GetType ().Name, "#07");
+                       Assert.AreEqual 
(System.Diagnostics.SourceLevels.Information, log.TraceSource.Switch.Level, 
"#08");
+               }
+               
+               private System.Diagnostics.TraceListener [] getObjects 
(System.Collections.IEnumerable en)
+               {
+                       return Helper.getObjects < 
System.Diagnostics.TraceListener > (en);
+               }
+       }
+}
+#endif
\ No newline at end of file

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to