2 ' This file is part of the LibreOffice project.
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/.
11 Function doUnitTest() As String
13 Call verify_Collection
14 doUnitTest
= TestUtil
.GetResult()
17 Sub verify_Collection()
18 try
: On Error GoTo catch
20 Dim c
As New Collection
, planet
as String, ndx
As Integer
22 TestUtil
.assertEqual(c
.Count
, 0,"c.Count")
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.
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(""♀"")")
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)")
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)")
57 TestUtil
.assertEqual(c
.Count
, 6,"c.Count")
59 For ndx
= c
.Count
to 1 Step
-1
63 TestUtil
.assertEqual(c
.Count
, 0,"c.Count")
69 TestUtil
.ReportErrorHandler("verify_Collection", Err
, Error$, Erl
)