File: ExceptionFilteringTests.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 (155 lines) | stat: -rw-r--r-- 5,714 bytes parent folder | download | duplicates (4)
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
Imports NUnit.Framework

<TestFixture()> _
Public Class ExceptionFilteringTests

    <Test()> _
    Public Sub ExceptionFilter_EmptyFilter()
        Try
            Throw New ArgumentException
            Assert.Fail("{0} was not thrown", Type.GetType("System.ArgumentException"))
        Catch e1 As ArgumentException
            ' pass
        Catch e2 As Exception
            Assert.Fail("Catched {0} intead of {1}", e2.GetType, Type.GetType("System.ArgumentException"))
        End Try
    End Sub

    <Test()> _
    Public Sub ExceptionFilter_Filter1()
        Dim filter1 As Boolean = True
        Dim filter2 As Boolean = False
        Try
            Throw New ArgumentException
            Assert.Fail("{0} was not thrown", Type.GetType("System.ArgumentException"))
        Catch e1 As ArgumentException When filter1
            'pass
        Catch e2 As ArgumentException When filter2
            Assert.Fail("Exception catched, but filter is {0}", filter2)
        Catch e2 As ArgumentException
            Assert.Fail("Exception catched, but there is no filter")
        Catch e3 As Exception
            Assert.Fail("Catched {0} intead of {1}", e3.GetType, Type.GetType("System.ArgumentException"))
        End Try
    End Sub

    <Test()> _
    Public Sub ExceptionFilter_Filter2()
        Try
            Throw New ArgumentException
            Assert.Fail("{0} was not thrown", Type.GetType("System.ArgumentException"))
        Catch e1 As ArgumentException When FilterTrue()
            'pass
        Catch e2 As ArgumentException When FilterFalse()
            Assert.Fail("Exception catched, but filter is {0}", FilterFalse())
        Catch e2 As ArgumentException
            Assert.Fail("Exception catched, but there is no filter")
        Catch e3 As Exception
            Assert.Fail("Catched {0} intead of {1}", e3.GetType, Type.GetType("System.ArgumentException"))
        End Try
    End Sub

    <Test(), Category("TargetJvmNotWorking")> _
    Public Sub ExceptionFilter_FilterThrow()
        Try
            Throw New ArgumentException
            Assert.Fail("{0} was not thrown", Type.GetType("System.ArgumentException"))
        Catch e1 As ArgumentException When FilterThrow()
            Assert.Fail("Exception catched, inspite of filter exception thrown.")
        Catch e2 As ArgumentException
            ' recatch and pass
        Catch e3 As Exception
            Assert.Fail("Catched {0} intead of {1}", e3.GetType, Type.GetType("System.ArgumentException"))
        End Try
    End Sub

    <Test()> _
    Public Sub ExceptionFilter_Filter3()
        Dim visitedFinally As Boolean = False
        Try
            Throw New ArgumentException
            Assert.Fail("{0} was not thrown", Type.GetType("System.ArgumentException"))
        Catch e1 As ArgumentException When FilterTrue()
            'pass
        Catch e2 As ArgumentException When FilterFalse()
            Assert.Fail("Exception catched, but filter is {0}", FilterFalse())
        Catch e2 As ArgumentException
            Assert.Fail("Exception catched, but there is no filter")
        Catch e3 As Exception
            Assert.Fail("Catched {0} intead of {1}", e3.GetType, Type.GetType("System.ArgumentException"))
        Finally
            visitedFinally = True
        End Try

        If Not visitedFinally Then
            Assert.Fail("Finally block was not called")
        End If
    End Sub

    <Test()> _
    Public Sub ExceptionFilter_FilterNested1()
        Try

            Dim visitedFinally As Boolean = False
            Try
                Throw New ArgumentException
                Assert.Fail("{0} was not thrown", Type.GetType("System.ArgumentException"))
            Catch e1 As ArgumentException When FilterTrue()
                'pass
            Catch e2 As ArgumentException When FilterFalse()
                Assert.Fail("Exception catched, but filter is {0}", FilterFalse())
            Catch e2 As ArgumentException
                Assert.Fail("Exception catched, but there is no filter")
            Catch e3 As Exception
                Assert.Fail("Catched {0} intead of {1}", e3.GetType, Type.GetType("System.ArgumentException"))
            Finally
                visitedFinally = True
            End Try

            Throw New IndexOutOfRangeException

        Catch e4 As IndexOutOfRangeException When FilterTrue()
            ' pass
        Catch e3 As Exception
            Assert.Fail("Catched {0} intead of {1}", e3.GetType, Type.GetType("System.IndexOutOfRangeException"))
        End Try
    End Sub

    <Test()> _
    Public Sub ExceptionFilter_FilterNested2()
        Try

            Dim visitedFinally As Boolean = False
            Try
                Throw New ArgumentException
                Assert.Fail("{0} was not thrown", Type.GetType("System.ArgumentException"))
            Catch e1 As ArgumentException When FilterTrue()
                Throw
            Catch e3 As Exception
                Assert.Fail("Catched {0} intead of {1}", e3.GetType, Type.GetType("System.ArgumentException"))
            Finally
                visitedFinally = True
            End Try

            Assert.Fail("Exception was not rethrown.")

        Catch e4 As ArgumentException When FilterTrue()
            ' catch rethrown exception and pass
        Catch e3 As Exception
            Assert.Fail("Catched {0} intead of {1}", e3.GetType, Type.GetType("System.ArgumentException"))
        End Try
    End Sub

    Public Function FilterTrue()
        Return True
    End Function

    Public Function FilterFalse()
        Return False
    End Function

    Public Function FilterThrow()
        Throw New IndexOutOfRangeException
    End Function

End Class