| 1 |
' |
| 2 |
' This file is part of the LibreOffice project. |
| 3 |
' |
| 4 |
' This Source Code Form is subject to the terms of the Mozilla Public |
| 5 |
' License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 |
' file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 7 |
' |
| 8 |
|
| 9 |
Option Explicit |
| 10 |
|
| 11 |
Function doUnitTest() As String |
| 12 |
TestUtil.TestInit |
| 13 |
Call verify_Collection |
| 14 |
doUnitTest = TestUtil.GetResult() |
| 15 |
End Function |
| 16 |
|
| 17 |
Sub verify_Collection() |
| 18 |
try: On Error GoTo catch |
| 19 |
|
| 20 |
Dim c As New Collection, planet as String, ndx As Integer |
| 21 |
|
| 22 |
TestUtil.assertEqual(c.Count, 0,"c.Count") |
| 23 |
|
| 24 |
' Let's collect Solar system planets from closest to SUN, |
| 25 |
' ranking them alphabetically using before/after keywords, |
| 26 |
' in order to validate various Add() method syntax variations. |
| 27 |
c.Add("Mercury") |
| 28 |
c.Add("Venus", "♀") |
| 29 |
c.Add("Earth", "♁", before:=1) |
| 30 |
TestUtil.assertEqual(c.Count, 3,"c.Count") |
| 31 |
TestUtil.assertEqual(c.Item(1), "Earth","c.Item(1)") |
| 32 |
TestUtil.assertEqual(c.Item("♁"), "Earth","c.Item(""♁"")") |
| 33 |
TestUtil.assertEqual(c.Item(3), "Venus","c.Item(3)") |
| 34 |
TestUtil.assertEqual(c.Item("♀"), "Venus","c.Item(""♀"")") |
| 35 |
|
| 36 |
c.Add("Mars", "♂", after:="♁") |
| 37 |
c.Add("Jupiter", after:="♁") |
| 38 |
c.Add("Saturn", before:=5) |
| 39 |
TestUtil.assertEqual(c.Count, 6,"c.Count") |
| 40 |
TestUtil.assertEqual(c.Item(2), "Jupiter","c.Item(2)") |
| 41 |
TestUtil.assertEqual(c.Item(3), "Mars","c.Item(3)") |
| 42 |
TestUtil.assertEqual(c.Item("♂"), "Mars","c.Item(""♂"")") |
| 43 |
TestUtil.assertEqual(c.Item(5), "Saturn","c.Item(5)") |
| 44 |
TestUtil.assertEqual(c.Item(6), "Venus","c.Item(6)") |
| 45 |
|
| 46 |
c.Add("Uranus", before:="♀") |
| 47 |
c.Add("Neptune", "♆", after:=4) |
| 48 |
TestUtil.assertEqual(c.Count, 8,"c.Count") |
| 49 |
TestUtil.assertEqual(c.Item(7), "Uranus","c.Item(7)") |
| 50 |
TestUtil.assertEqual(c.Item(5), "Neptune","c.Item(5)") |
| 51 |
TestUtil.assertEqual(c.Item("♆"), "Neptune","c.Item(""♆"")") |
| 52 |
TestUtil.assertEqual(c.Item(6), "Saturn","c.Item(6)") |
| 53 |
|
| 54 |
c.remove(4) |
| 55 |
c.remove("♁") |
| 56 |
|
| 57 |
TestUtil.assertEqual(c.Count, 6,"c.Count") |
| 58 |
|
| 59 |
For ndx = c.Count to 1 Step -1 |
| 60 |
c.Remove(ndx) |
| 61 |
Next ndx |
| 62 |
|
| 63 |
TestUtil.assertEqual(c.Count, 0,"c.Count") |
| 64 |
|
| 65 |
finally: |
| 66 |
Exit Sub |
| 67 |
|
| 68 |
catch: |
| 69 |
TestUtil.ReportErrorHandler("verify_Collection", Err, Error$, Erl) |
| 70 |
Resume Next |
| 71 |
End Sub |