Merge pull request #1225 from strawd/bug22307
[mono.git] / mcs / class / System / Test / System.Diagnostics / DelimitedListTraceListenerTest.cs
1 //
2 // DelimitedListTraceListenerTest.cs
3 //
4 // Author:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //
7 // Copyright (C) 2007 Novell, Inc.
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if !MOBILE
32
33 using NUnit.Framework;
34 using System;
35 using System.IO;
36 using System.Diagnostics;
37 using System.Threading;
38
39 namespace MonoTests.System.Diagnostics
40 {
41         [TestFixture]
42         public class DelimitedListTraceListenerTest
43         {
44                 string sample1 = "sample\n";
45
46                 string sample2 = ";Error;4;;;;;;;;\n";
47
48                 string sample3 = "\"bulldog\";Error;5;;;;;;;;\n\"bulldog\";Error;3;\"test event arg:arg1\";;;;;;;\n";
49
50                 string sample4 = ";Error;2;;;;;;;;\n;Error;3;;;;;;;;\n";
51
52                 string sample5 = ";Error;7;;\"XYZ\";;;;;;\n;Error;7;;\"ABC\",\"DEF\",\"123\";;;;;;\n";
53
54                 string sample6 = "\"my name is \"\"tricky\"\"\";Transfer;0;\"hoge;hoge, relatedActivityId=00000000-0000-0000-0000-000000000000\";;;;;;;\n";
55
56                 string sample7 = "Fail: error summary error details\n";
57
58                 [Test]
59                 public void WriteLine1 ()
60                 {
61                         StringWriter sw = new StringWriter ();
62                         DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
63                         x.WriteLine ("sample");
64                         x.Close ();
65                         Assert.AreEqual (sample1, sw.ToString ().Replace ("\r\n", "\n"));
66                 }
67
68                 [Test]
69                 public void TraceEvent1 ()
70                 {
71                         StringWriter sw = new StringWriter ();
72                         DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
73                         x.TraceEvent (null, null, TraceEventType.Error, 4, null);
74                         x.Close ();
75                         Assert.AreEqual (sample2, sw.ToString ().Replace ("\r\n", "\n"));
76                 }
77
78                 [Test]
79                 public void TraceEvent2 ()
80                 {
81                         StringWriter sw = new StringWriter ();
82                         DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
83                         x.TraceEvent (null, "bulldog", TraceEventType.Error, 5);
84                         x.TraceEvent (null, "bulldog", TraceEventType.Error, 3, "test event arg:{0}", "arg1");
85                         x.Close ();
86                         Assert.AreEqual (sample3, sw.ToString ().Replace ("\r\n", "\n"));
87                 }
88
89                 [Test]
90                 public void TraceDataWithCache1 ()
91                 {
92                         StringWriter sw = new StringWriter ();
93                         DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
94                         Trace.CorrelationManager.StartLogicalOperation ("op1"); // ... irrelevant?
95                         TraceEventCache cc = new TraceEventCache ();
96                         x.TraceData (cc, null, TraceEventType.Error, 2);
97                         x.TraceData (cc, null, TraceEventType.Error, 3);
98                         Trace.CorrelationManager.StopLogicalOperation ();
99                         x.Close ();
100                         Assert.AreEqual (sample4, sw.ToString ().Replace ("\r\n", "\n"));
101                 }
102
103                 [Test]
104                 public void TraceDataWithCache2 ()
105                 {
106                         StringWriter sw = new StringWriter ();
107                         DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
108                         TraceEventCache cc = new TraceEventCache ();
109                         x.TraceData (cc, null, TraceEventType.Error, 7, "XYZ");
110                         x.TraceData (cc, null, TraceEventType.Error, 7, "ABC", "DEF", 123);
111                         x.Close ();
112                         Assert.AreEqual (sample5, sw.ToString ().Replace ("\r\n", "\n"));
113                 }
114
115                 [Test]
116                 public void TraceTransfer1 ()
117                 {
118                         StringWriter sw = new StringWriter ();
119                         DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
120                         x.TraceTransfer (null, "my name is \"tricky\"", 0, "hoge;hoge", Guid.Empty);
121                         x.Close ();
122                         Assert.AreEqual (sample6, sw.ToString ().Replace ("\r\n", "\n"));
123                 }
124
125                 [Test]
126                 [Category ("NotWorking")]
127                 public void Fail1 ()
128                 {
129                         StringWriter sw = new StringWriter ();
130                         DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
131                         TraceEventCache cc = new TraceEventCache ();
132                         x.Fail ("error summary", "error details");
133                         x.Close ();
134                         Assert.AreEqual (sample7, sw.ToString ().Replace ("\r\n", "\n"));
135                 }
136         }
137 }
138
139 #endif