merge from trunk revisions 58933, 58935, 58936
[mono.git] / mcs / nunit20 / util / SummaryVisitor.cs
1 #region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
2 /************************************************************************************
3 '
4 ' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
5 ' Copyright © 2000-2003 Philip A. Craig
6 '
7 ' This software is provided 'as-is', without any express or implied warranty. In no 
8 ' event will the authors be held liable for any damages arising from the use of this 
9 ' software.
10
11 ' Permission is granted to anyone to use this software for any purpose, including 
12 ' commercial applications, and to alter it and redistribute it freely, subject to the 
13 ' following restrictions:
14 '
15 ' 1. The origin of this software must not be misrepresented; you must not claim that 
16 ' you wrote the original software. If you use this software in a product, an 
17 ' acknowledgment (see the following) in the product documentation is required.
18 '
19 ' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
20 ' or Copyright © 2000-2003 Philip A. Craig
21 '
22 ' 2. Altered source versions must be plainly marked as such, and must not be 
23 ' misrepresented as being the original software.
24 '
25 ' 3. This notice may not be removed or altered from any source distribution.
26 '
27 '***********************************************************************************/
28 #endregion
29
30 namespace NUnit.Util
31 {
32         using System;
33         using NUnit.Core;
34
35         /// <summary>
36         /// Summary description for SiummaryVisitor.
37         /// </summary>
38         public class SummaryVisitor : ResultVisitor
39         {
40                 private int totalCount;
41                 private int failureCount;
42                 private int testsNotRun;
43                 private int suitesNotRun;
44                 
45                 private double time;
46                 private string name;
47                 private bool initialized;
48
49                 public SummaryVisitor()
50                 {
51                         totalCount = 0;
52                         initialized = false;
53                 }
54
55                 public void Visit(TestCaseResult caseResult) 
56                 {
57                         SetNameandTime(caseResult.Name, caseResult.Time);
58
59                         if(caseResult.Executed)
60                         {
61                                 totalCount++;
62                                 if(caseResult.IsFailure)
63                                         failureCount++;
64                         }
65                         else
66                                 testsNotRun++;
67                 }
68
69                 public void Visit(TestSuiteResult suiteResult) 
70                 {
71                         SetNameandTime(suiteResult.Name, suiteResult.Time);
72
73                         
74                         
75                         foreach (TestResult result in suiteResult.Results)
76                         {
77                                 result.Accept(this);
78                         }
79                         
80                         if(!suiteResult.Executed)
81                                 suitesNotRun++;
82                 }
83
84                 public double Time
85                 {
86                         get { return time; }
87                 }
88
89                 private void SetNameandTime(string name, double time)
90                 {
91                         if(!initialized)
92                         {
93                                 this.time = time;
94                                 this.name = name;
95                                 initialized = true;
96                         }
97                 }
98
99                 public bool Success
100                 {
101                         get { return (failureCount == 0); }
102                 }
103
104                 public int Count
105                 {
106                         get { return totalCount; }
107                 }
108
109                 public int Failures
110                 {
111                         get { return failureCount; }
112                 }
113
114                 public int TestsNotRun
115                 {
116                         get { return testsNotRun; }
117                 }
118
119                 public int SuitesNotRun
120                 {
121                         get { return suitesNotRun; }
122                 }
123
124                 public string Name
125                 {
126                         get { return name; }
127                 }
128         }
129 }