| 1 |
' This file is part of the LibreOffice project. |
| 2 |
' |
| 3 |
' This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
' License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
' file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 |
' |
| 7 |
|
| 8 |
Option Explicit |
| 9 |
|
| 10 |
Function doUnitTest() As String |
| 11 |
TestUtil.TestInit |
| 12 |
verify_CallByName |
| 13 |
doUnitTest = TestUtil.GetResult() |
| 14 |
End Function |
| 15 |
|
| 16 |
Sub verify_CallByName() |
| 17 |
Const _Get = 2, _Let = 4, _Method = 1, _Set = 8 |
| 18 |
|
| 19 |
On Error GoTo errorHandler |
| 20 |
|
| 21 |
' Basic modules are Objects |
| 22 |
TestUtil.AssertEqual(CallByName(TestUtil, "failCount", _Get), 0, "CallByName(TestUtil, ""failCount"", _Get") |
| 23 |
TestUtil.AssertEqual(CallByName(TestUtil, "passCount", _Get), 1, "CallByName(TestUtil, ""passCount"", _Get") |
| 24 |
TestUtil.AssertEqual(CallByName(TestUtil, "GetResult", _Method), "OK", "CallByName(TestUtil, ""GetResult"", _Method") |
| 25 |
|
| 26 |
' Collection instances |
| 27 |
Dim c As New Collection |
| 28 |
c.Add(100, "1st") : c.Add(101) |
| 29 |
TestUtil.AssertEqual(CallByName(c,"Count", _Get), 2, "CallByName(c,""Count"", _Get)") |
| 30 |
c.Remove(2) |
| 31 |
TestUtil.AssertEqual(CallByName(callType:=_Get, object:=c, procName:="Count"), 1, _ |
| 32 |
"CallByName(callType:=_Get, object:=c, procName:=""Count"")") |
| 33 |
|
| 34 |
' ClassModule instances or UNO services are 'CallByNamable' objects too! |
| 35 |
' see https://help.libreoffice.org/7.4/en-US/text/sbasic/shared/CallByName.html?DbPAR=BASIC#bm_id3150669 |
| 36 |
' for more _Let and _Set examples |
| 37 |
|
| 38 |
Exit Sub |
| 39 |
errorHandler: |
| 40 |
TestUtil.ReportErrorHandler("verify_CallByName", Err, Error$, Erl) |
| 41 |
Resume Next |
| 42 |
|
| 43 |
End Sub |