File: TestList.vb

package info (click to toggle)
mono-basic 2.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 18,852 kB
  • ctags: 809
  • sloc: cs: 8,852; makefile: 516; sh: 307
file content (311 lines) | stat: -rwxr-xr-x 9,469 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
' 
' Visual Basic.Net COmpiler
' Copyright (C) 2004 - 2006 Rolf Bjarne Kvinge, rbjarnek at users.sourceforge.net
' 
' This library is free software; you can redistribute it and/or
' modify it under the terms of the GNU Lesser General Public
' License as published by the Free Software Foundation; either
' version 2.1 of the License, or (at your option) any later version.
' 
' This library is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
' Lesser General Public License for more details.
' 
' You should have received a copy of the GNU Lesser General Public
' License along with this library; if not, write to the Free Software
' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
' 

''' <summary>
''' A list of tests.
''' </summary>
''' <remarks></remarks>
<Serializable()> _
Public Class TestList
    Implements IDisposable
    Implements ICollection
    Implements Generic.IEnumerable(Of Test)

    Private m_List As New Generic.List(Of Test)
    Private m_Hashed As New Generic.Dictionary(Of String, Test)
    Private m_VBCPath As String
    Private m_VBNCPath As String

    Sub AddRange(ByVal Tests As IEnumerable)
        For Each item As Test In Tests
            Add(item)
        Next
    End Sub

    Sub RemoveAt(ByVal index As Integer)
        Dim item As Test
        item = m_List(index)

        m_List.RemoveAt(index)
        m_Hashed.Remove(item.Name)
    End Sub

    ''' <summary>
    ''' Looks up the test on the name. 
    ''' Returns nothing if no test was found.
    ''' </summary>
    ''' <param name="TestName"></param>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Default Overloads ReadOnly Property Item(ByVal TestName As String) As Test
        Get
            If m_Hashed.ContainsKey(TestName) Then
                Return m_Hashed(TestName)
            Else
                Return Nothing
            End If
        End Get
    End Property

    Sub Clear()
        m_List.Clear()
        m_Hashed.Clear()
    End Sub

    Default Overloads ReadOnly Property Item(ByVal Index As Integer) As Test
        Get
            Return m_List(Index)
        End Get
    End Property

    Shadows Function Contains(ByVal Test As Test) As Boolean
        If Contains(Test.Name) Then
            Return True
        Else
            Return m_List.Contains(Test)
        End If
    End Function

    Shadows Function Contains(ByVal TestName As String) As Boolean
        Return m_Hashed.ContainsKey(TestName)
    End Function

    Overridable Shadows Sub Add(ByVal Test As Test)
        If Contains(Test) = False Then
            m_List.Add(Test)
            m_Hashed.Add(Test.Name, Test)
        End If
    End Sub

    ReadOnly Property VBCPath() As String
        Get
            Return m_VBCPath
        End Get
    End Property

    ReadOnly Property VBNCPath() As String
        Get
            Return m_VBNCPath
        End Get
    End Property

    Public Sub New(ByVal CompilerPath As String, ByVal VBCPath As String)
        Me.New()
        m_VBCPath = VBCPath
        m_VBNCPath = CompilerPath
    End Sub

    Sub New()

    End Sub

    ''' <summary>
    ''' The count of tests run
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    ReadOnly Property TestsRun() As Integer
        Get
            Dim result As Integer
            For Each test As Test In Me
                If test.Run Then result += 1
            Next
            Return result
        End Get
    End Property

    ''' <summary>
    ''' The count of successful tests
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    ReadOnly Property TestsSucceded() As Integer
        Get
            Dim result As Integer
            For Each test As Test In Me
                If test.Run AndAlso test.Success = True Then result += 1
            Next
            Return result
        End Get
    End Property

    ''' <summary>
    ''' The total time all tests have been executing.
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    ReadOnly Property ExecutionTime() As TimeSpan
        Get
            Dim result As TimeSpan
            For Each test As Test In Me
                If test.Run Then
                    If test.Statistics Is Nothing Then Continue For
                    result = result + test.TestDuration
                End If
            Next
            Return result
        End Get
    End Property

    ''' <summary>
    ''' The count of failed tests
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    ReadOnly Property TestsFailed() As Integer
        Get
            Dim result As Integer
            For Each test As Test In Me
                If test.Run AndAlso test.Success = False Then result += 1
            Next
            Return result
        End Get
    End Property

    Sub GetTestsCount(ByVal result() As Integer)
        For Each t As Test In Me
            result(t.Result) += 1
        Next
    End Sub

    Function GetTestsCount(ByVal MinResult As Test.Results, ByVal MaxResult As Test.Results) As Integer
        Dim result As Integer
        For Each t As Test In Me
            If t.Result >= MinResult AndAlso t.Result <= MaxResult Then
                result += 1
            ElseIf t.Result = Test.Results.NotRun AndAlso t.OldResult >= MinResult AndAlso t.OldResult <= MaxResult Then
                result += 1
            End If
        Next
        Return result
    End Function

    Function GetTestsMin(Optional ByVal MinResult As Test.Results = Test.Results.NotRun) As TestList
        If MinResult = Test.Results.NotRun Then Return Me
        Dim result As New TestList
        For Each test As Test In Me
            If test.Result >= MinResult Then result.Add(test)
        Next
        Return result
    End Function

    Function GetTestsMax(Optional ByVal MaxResult As Test.Results = Test.Results.NotRun) As TestList
        Dim result As New TestList
        For Each test As Test In Me
            If test.Result <= MaxResult Then result.Add(test)
        Next
        Return result
    End Function

    Function GetTestsRange(ByVal MinResult As Test.Results, ByVal MaxResult As Test.Results) As TestList
        Dim result As New TestList
        For Each test As Test In Me
            If test.Result >= MinResult AndAlso test.Result <= MaxResult Then result.Add(test)
        Next
        Return result
    End Function

    ''' <summary>
    ''' Get all tests that have failed
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetRedTests() As TestList
        Return GetTestsRange(Test.Results.Failed, Test.Results.Failed)
    End Function

    ''' <summary>
    ''' Get all tests that have reached at least level Results.Success
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetGreenTests() As TestList
        Return GetTestsMin(Test.Results.Success)
    End Function

    Function GetNotRunTests() As TestList
        Return GetTestsMax(Test.Results.NotRun)
    End Function

    Function GetRunTests() As TestList
        Return GetTestsRange(Test.Results.Failed, Test.Results.Success)
    End Function

    Private disposed As Boolean = False

    ' IDisposable
    Private Overloads Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposed Then
            If disposing Then
                Try
                    Me.disposed = True
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            End If
        End If
        Me.disposed = True
    End Sub

#Region " IDisposable Support "
    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Overloads Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub

    Protected Overrides Sub Finalize()
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(False)
        MyBase.Finalize()
    End Sub
#End Region

    Public Sub CopyTo(ByVal array As System.Array, ByVal index As Integer) Implements System.Collections.ICollection.CopyTo

    End Sub

    Public ReadOnly Property Count() As Integer Implements System.Collections.ICollection.Count
        Get
            Return m_List.Count
        End Get
    End Property

    Public ReadOnly Property IsSynchronized() As Boolean Implements System.Collections.ICollection.IsSynchronized
        Get
            Return CType(m_List, ICollection).IsSynchronized
        End Get
    End Property

    Public ReadOnly Property SyncRoot() As Object Implements System.Collections.ICollection.SyncRoot
        Get
            Return CType(m_List, ICollection).SyncRoot
        End Get
    End Property

    Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
        Return m_List.GetEnumerator
    End Function

    Public Function GetEnumerator1() As System.Collections.Generic.IEnumerator(Of Test) Implements System.Collections.Generic.IEnumerable(Of Test).GetEnumerator
        Return m_List.GetEnumerator
    End Function
End Class