Debian Codegraph @

basic/qa/basic_coverage/test_variant_arg_used_as_obj.bas

raw
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 verify_VariantArgUsedAsObj
14 doUnitTest = TestUtil.GetResult()
15 End Function
16
17 Sub verify_VariantArgUsedAsObj
18 On Error GoTo errorHandler
19
20 Dim aResult
21 ' Without the fix, the following line would fail, triggering errorHandler reporting
22 ' "91: Object variable not set."
23 aResult = aFuncWithVarArg(0)
24 TestUtil.AssertEqualStrict(aResult, "Integer", "aResult")
25
26 Exit Sub
27 errorHandler:
28 TestUtil.ReportErrorHandler("verify_VariantArgUsedAsObj", Err, Error$, Erl)
29 End Sub
30
31 Function aFuncWithVarArg(arg)
32 ' The 'arg' is implicitly Variant; and its following use as object (after a check),
33 ' i.e. accessing its method using dot notation, must not change the declaration type
34 If IsObject(arg) Then
35 arg.some_func()
36 End If
37 aFuncWithVarArg = TypeName(arg)
38 End Function