File: TestView.vb

package info (click to toggle)
mono-basic 2.10-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 22,964 kB
  • sloc: cs: 34,086; xml: 7,804; makefile: 471; sh: 317
file content (116 lines) | stat: -rw-r--r-- 4,349 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
' 
' Visual Basic.Net Compiler
' Copyright (C) 2004 - 2010 Rolf Bjarne Kvinge, RKvinge@novell.com
' 
' 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
' 

Friend Class TestView
    Private m_HashTable As New Generic.Dictionary(Of Test, ListViewItem)
    Private m_Form As frmMain

    Sub New(ByVal Form As frmMain)
        m_Form = Form
    End Sub

    Function GetListViewItem(ByVal Test As Test) As ListViewItem
        If m_HashTable.ContainsKey(Test) = False Then
            m_HashTable.Add(Test, CreateListViewItem(Test))
            AddHandler Test.Executed, AddressOf Update
            AddHandler Test.Executing, AddressOf UpdateRunning
            AddHandler Test.Changed, AddressOf Update
        End If
        Return m_HashTable.Item(Test)
    End Function

    Private Function CreateListViewItem(ByVal Test As Test) As ListViewItem
        Dim newItem As New ListViewItem()
        newItem.Text = Test.Name
        newItem.Tag = Test

        newItem.ImageIndex = m_Form.GetIconIndex(rt.Test.Results.NotRun)
        newItem.SubItems.Add("")
        newItem.SubItems.Add("")
        newItem.SubItems.Add("")
        newItem.SubItems.Add("")
        newItem.SubItems.Add(Test.KnownFailure)

        Update(newItem)

        Return newItem
    End Function

    Private Sub Update(ByVal Test As Test)
        Update(m_HashTable.Item(Test))
    End Sub

    Private Delegate Sub UpdateDelegate(ByVal Item As ListViewItem)
    Private Delegate Sub UpdateRunningDelegate(ByVal Item As Test)

    Private Sub UpdateRunning(ByVal Test As Test)
        Try
            Dim Item As ListViewItem = m_HashTable.Item(Test)

            If Item.ListView IsNot Nothing AndAlso Item.ListView.InvokeRequired Then
                Item.ListView.BeginInvoke(New UpdateRunningDelegate(AddressOf UpdateRunning), Test)
                Return
            End If

            Item.ImageIndex = m_Form.GetIconIndex(Test.Result)
            Item.SubItems(1).Text = ""
            Item.SubItems(2).Text = "Running..."
            Item.SubItems(3).Text = ""
            Item.SubItems(4).Text = ""
            Item.SubItems(5).Text = Test.KnownFailure
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub Update(ByVal Item As ListViewItem)
        Try
            Dim test As Test = DirectCast(Item.Tag, Test)

            If Item.ListView IsNot Nothing AndAlso Item.ListView.InvokeRequired Then
                Item.ListView.BeginInvoke(New UpdateDelegate(AddressOf Update), Item)
                Return
            End If

            Const datetimeformat As String = "dd/MM/yyyy HH:mm"
            Dim testresult As Test.Results
            If test.Result = rt.Test.Results.NotRun Then
                testresult = rt.Test.Results.NotRun
            Else
                testresult = test.Result
            End If
            If test.LastRun.Date <> Date.MinValue Then
                Item.SubItems(4).Text = test.LastRun.ToString(datetimeformat)
            End If
            Item.ImageIndex = m_Form.GetIconIndex(testresult)
            Item.SubItems(2).Text = test.Category

            Item.SubItems(1).Text = test.Result.ToString
            If test.FailedVerificationMessage <> "" Then
                Dim idx As Integer = test.FailedVerificationMessage.IndexOf(vbNewLine)
                If idx < 0 Then idx = test.FailedVerificationMessage.Length
                Item.SubItems(3).Text = test.FailedVerificationMessage.Substring(0, idx)
            Else
                Item.SubItems(3).Text = ""
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class