tdf#133913 - create variable with Variant/Type in StepLOADNC

During the loading of numeric constants in StepLOADNC, create variables
of type Variant and convert them to the requested type, i.e.
Variant/Type in order to prevent type conversion errors, when they are
passed to a method with variant parameter types.

Change-Id: I2ab0111b5b53dd2de9523ba7cf12bd2519d050b0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96402
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Andreas Heinisch 2020-06-15 22:44:27 +02:00 committed by Mike Kaganski
parent f51ea6c297
commit 0f6e012057
5 changed files with 60 additions and 28 deletions

View file

@ -0,0 +1,34 @@
'
' This file is part of the LibreOffice project.
'
' This Source Code Form is subject to the terms of the Mozilla Public
' License, v. 2.0. If a copy of the MPL was not distributed with this
' file, You can obtain one at http://mozilla.org/MPL/2.0/.
'
' assigns a numeric constant (integer) to a parameter of type variant
Function assignInteger( numericConstant ) As String
numericConstant = 1
assignInteger = TypeName( numericConstant )
End Function
' assigns a numeric constant (long) to a parameter of type variant
Function assignLong( numericConstant ) As String
numericConstant = 32768
assignLong = TypeName( numericConstant )
End Function
Function doUnitTest() As Integer
' tdf#133913 - check if numeric constants are converted correctly to
' their respective types, if they are passed as arguments to a function
' with variant parameter types.
On Error GoTo errorHandler
If (assignInteger( 1 ) = "Integer" And assignLong( 1 ) = "Long") Then
doUnitTest = 1
Else
doUnitTest = 0
End If
Exit Function
errorHandler:
doUnitTest = 0
End Function

View file

@ -40,13 +40,13 @@ Function verify_testOptionalsBasic() As String
TestLog_ASSERT TestOptDouble(), 0, "TestOptDouble()"
TestLog_ASSERT TestOptDouble(123.4), 123.4, "TestOptDouble(123.4)"
TestLog_ASSERT TestOptDouble(, 567.8), 567.8, "TestOptDouble(, 567.8)"
TestLog_ASSERT Format(TestOptDouble(123.4, 567.8), "0.0"), 691.2, "TestOptDouble(123.4, 567.8)"
TestLog_ASSERT CDbl(Format(TestOptDouble(123.4, 567.8), "0.0")), 691.2, "TestOptDouble(123.4, 567.8)"
' optionals with double datatypes (ByRef and ByVal)
TestLog_ASSERT TestOptDoubleByRefByVal(), 0, "TestOptDouble()"
TestLog_ASSERT TestOptDoubleByRefByVal(123.4), 123.4, "TestOptDouble(123.4)"
TestLog_ASSERT TestOptDoubleByRefByVal(, 567.8), 567.8, "TestOptDoubleByRefByVal(, 567.8)"
TestLog_ASSERT Format(TestOptDoubleByRefByVal(123.4, 567.8), "0.0"), 691.2, "TestOptDoubleByRefByVal(123.4, 567.8)"
TestLog_ASSERT CDbl(Format(TestOptDoubleByRefByVal(123.4, 567.8), "0.0")), 691.2, "TestOptDoubleByRefByVal(123.4, 567.8)"
' optionals with integer datatypes
TestLog_ASSERT TestOptInteger(), 0, "TestOptInteger()"
@ -81,14 +81,14 @@ Function verify_testOptionalsBasic() As String
cB.Add (567.8)
TestLog_ASSERT TestOptObject(), 0, "TestOptObject()"
TestLog_ASSERT TestOptObject(cA), 579, "TestOptObject(A)"
TestLog_ASSERT Format(TestOptObject(, cB), "0.0"), 691.2, "TestOptObject(, B)"
TestLog_ASSERT Format(TestOptObject(cA, cB), "0.0"), 1270.2, "TestOptObject(A, B)"
TestLog_ASSERT CDbl(Format(TestOptObject(, cB), "0.0")), 691.2, "TestOptObject(, B)"
TestLog_ASSERT CDbl(Format(TestOptObject(cA, cB), "0.0")), 1270.2, "TestOptObject(A, B)"
' optionals with object datatypes (ByRef and ByVal)
TestLog_ASSERT TestOptObjectByRefByVal(), 0, "TestOptObjectByRefByVal()"
TestLog_ASSERT TestOptObjectByRefByVal(cA), 579, "TestOptObjectByRefByVal(A)"
TestLog_ASSERT Format(TestOptObjectByRefByVal(, cB), "0.0"), 691.2, "TestOptObjectByRefByVal(, B)"
TestLog_ASSERT Format(TestOptObjectByRefByVal(cA, cB), "0.0"), 1270.2, "TestOptObjectByRefByVal(A, B)"
TestLog_ASSERT CDbl(Format(TestOptObjectByRefByVal(, cB), "0.0")), 691.2, "TestOptObjectByRefByVal(, B)"
TestLog_ASSERT CDbl(Format(TestOptObjectByRefByVal(cA, cB), "0.0")), 1270.2, "TestOptObjectByRefByVal(A, B)"
' optionals with array datatypes
Dim aA(0 To 1) As Integer
@ -99,14 +99,14 @@ Function verify_testOptionalsBasic() As String
aB(1) = 567.8
TestLog_ASSERT TestOptArray(), 0, "TestOptArray()"
TestLog_ASSERT TestOptArray(aA), 579, "TestOptArray(A)"
TestLog_ASSERT Format(TestOptArray(, aB), "0.0"), 691.2, "TestOptArray(, B)"
TestLog_ASSERT Format(TestOptArray(aA, aB), "0.0"), 1270.2, "TestOptArray(A, B)"
TestLog_ASSERT CDbl(Format(TestOptArray(, aB), "0.0")), 691.2, "TestOptArray(, B)"
TestLog_ASSERT CDbl(Format(TestOptArray(aA, aB), "0.0")), 1270.2, "TestOptArray(A, B)"
' optionals with array datatypes (ByRef and ByVal)
TestLog_ASSERT TestOptArrayByRefByVal(), 0, "TestOptArrayByRefByVal()"
TestLog_ASSERT TestOptArrayByRefByVal(aA), 579, "TestOptArrayByRefByVal(A)"
TestLog_ASSERT Format(TestOptArrayByRefByVal(, aB), "0.0"), 691.2, "TestOptArrayByRefByVal(, B)"
TestLog_ASSERT Format(TestOptArrayByRefByVal(aA, aB), "0.0"), 1270.2, "TestOptArrayByRefByVal(A, B)"
TestLog_ASSERT CDbl(Format(TestOptArrayByRefByVal(, aB), "0.0")), 691.2, "TestOptArrayByRefByVal(, B)"
TestLog_ASSERT CDbl(Format(TestOptArrayByRefByVal(aA, aB), "0.0")), 1270.2, "TestOptArrayByRefByVal(A, B)"
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
verify_testOptionalsBasic = result

View file

@ -27,15 +27,13 @@ Function verify_testOptionalsCompatible() As String
On Error GoTo errorHandler
' optionals with variant datatypes
' TODO - New bug report? Scanner initializes variable as String. Function returns "123"
' TestLog_ASSERT TestOptVariant(), 123, "TestOptVariant()"
TestLog_ASSERT TestOptVariant(), 123, "TestOptVariant()"
TestLog_ASSERT TestOptVariant(123), 246, "TestOptVariant(123)"
TestLog_ASSERT TestOptVariant(, 456), 456, "TestOptVariant(, 456)"
TestLog_ASSERT TestOptVariant(123, 456), 579, "TestOptVariant(123, 456)"
' optionals with variant datatypes (ByRef and ByVal)
' TODO - New bug report? Scanner initializes variable as String. Function returns "123"
' TestLog_ASSERT TestOptVariantByRefByVal(), 123, "TestOptVariantByRefByVal()"
TestLog_ASSERT TestOptVariantByRefByVal(), 123, "TestOptVariantByRefByVal()"
TestLog_ASSERT TestOptVariantByRefByVal(123), 246, "TestOptVariantByRefByVal(123)"
TestLog_ASSERT TestOptVariantByRefByVal(, 456), 456, "TestOptVariantByRefByVal(, 456)"
TestLog_ASSERT TestOptVariantByRefByVal(123, 456), 579, "TestOptVariantByRefByVal(123, 456)"
@ -44,13 +42,13 @@ Function verify_testOptionalsCompatible() As String
TestLog_ASSERT TestOptDouble(), 123.4, "TestOptDouble()"
TestLog_ASSERT TestOptDouble(123.4), 246.8, "TestOptDouble(123.4)"
TestLog_ASSERT TestOptDouble(, 567.8), 567.8, "TestOptDouble(, 567.8)"
TestLog_ASSERT Format(TestOptDouble(123.4, 567.8), "0.0"), 691.2, "TestOptDouble(123.4, 567.8)"
TestLog_ASSERT CDbl(Format(TestOptDouble(123.4, 567.8), "0.0")), 691.2, "TestOptDouble(123.4, 567.8)"
' optionals with double datatypes (ByRef and ByVal)
TestLog_ASSERT TestOptDoubleByRefByVal(), 123.4, "TestOptDouble()"
TestLog_ASSERT TestOptDoubleByRefByVal(123.4), 246.8, "TestOptDouble(123.4)"
TestLog_ASSERT TestOptDoubleByRefByVal(, 567.8), 567.8, "TestOptDoubleByRefByVal(, 567.8)"
TestLog_ASSERT Format(TestOptDoubleByRefByVal(123.4, 567.8), "0.0"), 691.2, "TestOptDoubleByRefByVal(123.4, 567.8)"
TestLog_ASSERT CDbl(Format(TestOptDoubleByRefByVal(123.4, 567.8), "0.0")), 691.2, "TestOptDoubleByRefByVal(123.4, 567.8)"
' optionals with integer datatypes
TestLog_ASSERT TestOptInteger(), 123, "TestOptInteger()"
@ -85,14 +83,14 @@ Function verify_testOptionalsCompatible() As String
cB.Add (567.8)
TestLog_ASSERT TestOptObject(), 0, "TestOptObject()"
TestLog_ASSERT TestOptObject(cA), 579, "TestOptObject(A)"
TestLog_ASSERT Format(TestOptObject(, cB), "0.0"), 691.2, "TestOptObject(, B)"
TestLog_ASSERT Format(TestOptObject(cA, cB), "0.0"), 1270.2, "TestOptObject(A, B)"
TestLog_ASSERT CDbl(Format(TestOptObject(, cB), "0.0")), 691.2, "TestOptObject(, B)"
TestLog_ASSERT CDbl(Format(TestOptObject(cA, cB), "0.0")), 1270.2, "TestOptObject(A, B)"
' optionals with object datatypes (ByRef and ByVal)
TestLog_ASSERT TestOptObjectByRefByVal(), 0, "TestOptObjectByRefByVal()"
TestLog_ASSERT TestOptObjectByRefByVal(cA), 579, "TestOptObjectByRefByVal(A)"
TestLog_ASSERT Format(TestOptObjectByRefByVal(, cB), "0.0"), 691.2, "TestOptObjectByRefByVal(, B)"
TestLog_ASSERT Format(TestOptObjectByRefByVal(cA, cB), "0.0"), 1270.2, "TestOptObjectByRefByVal(A, B)"
TestLog_ASSERT CDbl(Format(TestOptObjectByRefByVal(, cB), "0.0")), 691.2, "TestOptObjectByRefByVal(, B)"
TestLog_ASSERT CDbl(Format(TestOptObjectByRefByVal(cA, cB), "0.0")), 1270.2, "TestOptObjectByRefByVal(A, B)"
' optionals with array datatypes
Dim aA(0 To 1) As Integer
@ -103,14 +101,14 @@ Function verify_testOptionalsCompatible() As String
aB(1) = 567.8
TestLog_ASSERT TestOptArray(), 0, "TestOptArray()"
TestLog_ASSERT TestOptArray(aA), 579, "TestOptArray(A)"
TestLog_ASSERT Format(TestOptArray(, aB), "0.0"), 691.2, "TestOptArray(, B)"
TestLog_ASSERT Format(TestOptArray(aA, aB), "0.0"), 1270.2, "TestOptArray(A, B)"
TestLog_ASSERT CDbl(Format(TestOptArray(, aB), "0.0")), 691.2, "TestOptArray(, B)"
TestLog_ASSERT CDbl(Format(TestOptArray(aA, aB), "0.0")), 1270.2, "TestOptArray(A, B)"
' optionals with array datatypes (ByRef and ByVal)
TestLog_ASSERT TestOptArrayByRefByVal(), 0, "TestOptArrayByRefByVal()"
TestLog_ASSERT TestOptArrayByRefByVal(aA), 579, "TestOptArrayByRefByVal(A)"
TestLog_ASSERT Format(TestOptArrayByRefByVal(, aB), "0.0"), 691.2, "TestOptArrayByRefByVal(, B)"
TestLog_ASSERT Format(TestOptArrayByRefByVal(aA, aB), "0.0"), 1270.2, "TestOptArrayByRefByVal(A, B)"
TestLog_ASSERT CDbl(Format(TestOptArrayByRefByVal(, aB), "0.0")), 691.2, "TestOptArrayByRefByVal(, B)"
TestLog_ASSERT CDbl(Format(TestOptArrayByRefByVal(aA, aB), "0.0")), 1270.2, "TestOptArrayByRefByVal(A, B)"
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
verify_testOptionalsCompatible = result

View file

@ -28,15 +28,13 @@ Function verify_testOptionalsVba() As String
On Error GoTo errorHandler
' optionals with variant datatypes
' TODO - New bug report? Scanner initializes variable as String. Function returns "123"
' TestLog_ASSERT TestOptVariant(), 123, "TestOptVariant()"
TestLog_ASSERT TestOptVariant(), 123, "TestOptVariant()"
TestLog_ASSERT TestOptVariant(123), 246, "TestOptVariant(123)"
TestLog_ASSERT TestOptVariant(, 456), 456, "TestOptVariant(, 456)"
TestLog_ASSERT TestOptVariant(123, 456), 579, "TestOptVariant(123, 456)"
' optionals with variant datatypes (ByRef and ByVal)
' TODO - New bug report? Scanner initializes variable as String. Function returns "123"
' TestLog_ASSERT TestOptVariantByRefByVal(), 123, "TestOptVariantByRefByVal()"
TestLog_ASSERT TestOptVariantByRefByVal(), 123, "TestOptVariantByRefByVal()"
TestLog_ASSERT TestOptVariantByRefByVal(123), 246, "TestOptVariantByRefByVal(123)"
TestLog_ASSERT TestOptVariantByRefByVal(, 456), 456, "TestOptVariantByRefByVal(, 456)"
TestLog_ASSERT TestOptVariantByRefByVal(123, 456), 579, "TestOptVariantByRefByVal(123, 456)"

View file

@ -2827,6 +2827,8 @@ void SbiRuntime::StepLOADNC( sal_uInt32 nOp1 )
}
SbxVariable* p = new SbxVariable( eType );
p->PutDouble( n );
// tdf#133913 - create variable with Variant/Type in order to prevent type conversion errors
p->ResetFlag( SbxFlagBits::Fixed );
PushVar( p );
}