Debian Codegraph @

basic/qa/basic_coverage/test_date_passed_to_uno.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_DatePassedToUno
14 doUnitTest = TestUtil.GetResult()
15 End Function
16
17 Sub verify_DatePassedToUno
18 On Error GoTo errorHandler
19
20 ' Given a date variable, and passing it to an UNO interface method (i.e., going through
21 ' the Basic-to-UNO conversion), in the absence of VBASupport mode, the date value must
22 ' be converted to a number, not to a struct / empty interface
23 Dim aDate as Date
24 aDate = #2025-01-23T12:00#
25
26 Dim aUnoObject as Object
27 aUnoObject = CreateUnoListener("XTypeConverter_", "com.sun.star.script.XTypeConverter")
28
29 Dim aConvResult
30 ' Without the fix, the following line would fail, triggering errorHandler reporting
31 ' "91: Object variable not set."
32 aConvResult = aUnoObject.convertToSimpleType(aDate, com.sun.star.uno.TypeClass.STRING)
33 ' If 'Option VBASupport 1' were used, the following line would fail with "Wrong input
34 ' type: Date", because the value would be marshalled using oleautomation::Date struct
35 TestUtil.AssertEqualStrict(aConvResult, "45680.5", "aConvResult")
36
37 Exit Sub
38 errorHandler:
39 TestUtil.ReportErrorHandler("verify_DatePassedToUno", Err, Error$, Erl)
40 End Sub
41
42 Function XTypeConverter_convertToSimpleType(aFrom, aDestinationType)
43 If IsNumeric(aFrom) Then
44 XTypeConverter_convertToSimpleType = CStr(aFrom)
45 Else
46 XTypeConverter_convertToSimpleType = "Wrong input type: " & TypeName(aFrom)
47 End If
48 End Function