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
|
'
' VBFixedStringAttributeTest.vb
'
' Author:
' Rolf Bjarne Kvinge (RKvinge@novell.com)
'
' Copyright (C) 2009 Novell
'
' Permission is hereby granted, free of charge, to any person obtaining
' a copy of this software and associated documentation files (the
' "Software"), to deal in the Software without restriction, including
' without limitation the rights to use, copy, modify, merge, publish,
' distribute, sublicense, and/or sell copies of the Software, and to
' permit persons to whom the Software is furnished to do so, subject to
' the following conditions:
'
' The above copyright notice and this permission notice shall be
' included in all copies or substantial portions of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
' EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
' MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
' NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
' LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
' OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'
Option Strict On
Imports System
Imports System.Globalization
Imports System.Threading
Imports System.Text
Imports Microsoft.VisualBasic
Imports NUnit.Framework
<TestFixture()> _
Public Class VBFixedArrayAttributeTest
<Test()> _
Public Sub TestCtor()
Dim v As VBFixedArrayAttribute
' first ctor
Try
v = New VBFixedArrayAttribute(-1)
Assert.Fail("Expected ArgumentException - #-01")
Catch ex As ArgumentException
Assert.AreEqual("Arguments to 'VBFixedArrayAttribute' are not valid.", ex.Message, "#-01 msg")
End Try
v = New VBFixedArrayAttribute(0)
Assert.AreEqual(1, v.Length, "#02 Length")
Assert.AreEqual(1, v.Bounds.Length, "#02 Bounds.Length")
Assert.AreEqual(0, v.Bounds(0), "#02 Bounds (0)")
v = New VBFixedArrayAttribute(1)
Assert.AreEqual(2, v.Length, "#03 Length")
Assert.AreEqual(1, v.Bounds.Length, "#03 Bounds.Length")
Assert.AreEqual(1, v.Bounds(0), "#03 Bounds (0)")
v = New VBFixedArrayAttribute(2)
Assert.AreEqual(3, v.Length, "#04 Length")
Assert.AreEqual(1, v.Bounds.Length, "#04 Bounds.Length")
Assert.AreEqual(2, v.Bounds(0), "#04 Bounds (0)")
v = New VBFixedArrayAttribute(Integer.MaxValue)
Try
Assert.AreEqual(Integer.MaxValue, v.Length, "#05 Length")
Assert.Fail("Expected OverflowException - #05 Length overflow")
Catch ex As OverflowException
Assert.AreEqual("Arithmetic operation resulted in an overflow.", ex.Message, "#05 Length ex")
End Try
Assert.AreEqual(1, v.Bounds.Length, "#05 Bounds.Length")
Assert.AreEqual(Integer.MaxValue, v.Bounds(0), "#05 Bounds (0)")
v = New VBFixedArrayAttribute(Integer.MaxValue - 1)
Assert.AreEqual(Integer.MaxValue, v.Length, "#06 Length")
Assert.AreEqual(1, v.Bounds.Length, "#06 Bounds.Length")
Assert.AreEqual(Integer.MaxValue - 1, v.Bounds(0), "#06 Bounds (0)")
' second ctor
v = New VBFixedArrayAttribute(0, 0)
Assert.AreEqual(1, v.Length, "#10 Length")
Assert.AreEqual(2, v.Bounds.Length, "#10 Bounds.Length")
Assert.AreEqual(0, v.Bounds(0), "#10 Bounds (0)")
Assert.AreEqual(0, v.Bounds(1), "#10 Bounds (1)")
Try
v = New VBFixedArrayAttribute(-1, 0)
Assert.Fail("Expected ArgumentException - #11")
Catch ex As ArgumentException
Assert.AreEqual("Arguments to 'VBFixedArrayAttribute' are not valid.", ex.Message, "#-11 msg")
End Try
Try
v = New VBFixedArrayAttribute(0, -1)
Assert.Fail("Expected ArgumentException - #12")
Catch ex As ArgumentException
Assert.AreEqual("Arguments to 'VBFixedArrayAttribute' are not valid.", ex.Message, "#-12 msg")
End Try
Try
v = New VBFixedArrayAttribute(-1, -1)
Assert.Fail("Expected ArgumentException - #13")
Catch ex As ArgumentException
Assert.AreEqual("Arguments to 'VBFixedArrayAttribute' are not valid.", ex.Message, "#-13 msg")
End Try
v = New VBFixedArrayAttribute(1, 0)
Assert.AreEqual(2, v.Length, "#14 Length")
Assert.AreEqual(2, v.Bounds.Length, "#14 Bounds.Length")
Assert.AreEqual(1, v.Bounds(0), "#14 Bounds (0)")
Assert.AreEqual(0, v.Bounds(1), "#14 Bounds (1)")
v = New VBFixedArrayAttribute(1, 1)
Assert.AreEqual(4, v.Length, "#15 Length")
Assert.AreEqual(2, v.Bounds.Length, "#15 Bounds.Length")
Assert.AreEqual(1, v.Bounds(0), "#15 Bounds (0)")
Assert.AreEqual(1, v.Bounds(1), "#15 Bounds (1)")
v = New VBFixedArrayAttribute(1, 3)
Assert.AreEqual(8, v.Length, "#16 Length")
Assert.AreEqual(2, v.Bounds.Length, "#16 Bounds.Length")
Assert.AreEqual(1, v.Bounds(0), "#16 Bounds (0)")
Assert.AreEqual(3, v.Bounds(1), "#16 Bounds (1)")
v = New VBFixedArrayAttribute(7, 3)
Assert.AreEqual(32, v.Length, "#17 Length")
Assert.AreEqual(2, v.Bounds.Length, "#17 Bounds.Length")
Assert.AreEqual(7, v.Bounds(0), "#17 Bounds (0)")
Assert.AreEqual(3, v.Bounds(1), "#17 Bounds (1)")
v = New VBFixedArrayAttribute(Short.MaxValue, Short.MaxValue)
Assert.AreEqual((Short.MaxValue + 1) * (Short.MaxValue + 1), v.Length, "#18 Length")
Assert.AreEqual(2, v.Bounds.Length, "#18 Bounds.Length")
Assert.AreEqual(Short.MaxValue, v.Bounds(0), "#18 Bounds (0)")
Assert.AreEqual(Short.MaxValue, v.Bounds(1), "#18 Bounds (1)")
v = New VBFixedArrayAttribute(Integer.MaxValue - 1, Integer.MaxValue - 1)
Try
Assert.AreEqual(Integer.MaxValue, v.Length, "#19 Length")
Assert.Fail("Expected OverflowException - #19 Length overflow")
Catch ex As OverflowException
Assert.AreEqual("Arithmetic operation resulted in an overflow.", ex.Message, "#19 Length ex")
End Try
Assert.AreEqual(2, v.Bounds.Length, "#19 Bounds.Length")
Assert.AreEqual(Integer.MaxValue - 1, v.Bounds(0), "#19 Bounds (0)")
Assert.AreEqual(Integer.MaxValue - 1, v.Bounds(1), "#19 Bounds (1)")
End Sub
End Class
|