[Libreoffice-commits] core.git: basic/qa

Alain Romedenne (via logerrit) logerrit at kemper.freedesktop.org
Mon Mar 29 13:30:17 UTC 2021


 basic/qa/basic_coverage/test_typelen_method.vb  |   54 +++++++++++--
 basic/qa/basic_coverage/test_typename_method.vb |   73 ++++++++++++++++--
 basic/qa/basic_coverage/test_vartype_method.vb  |   95 ++++++++++++++++++++++--
 3 files changed, 201 insertions(+), 21 deletions(-)

New commits:
commit 08151f4827cc954188243f06660076534bc30c1f
Author:     Alain Romedenne <alain.romedenne at libreoffice.org>
AuthorDate: Wed Feb 17 15:50:50 2021 +0100
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Mon Mar 29 15:29:39 2021 +0200

    TypeName, VarType, TypeLen Basic QA test cases
    
    1- exhibiting array type names
    2- highlighting supplemental libO Basic constants
    3- precising data types internal representations
    
    I intend to document in help:
    
    1- primitive data types array names: Boolean(), Byte(), … as IsArray() function does not provide such info
    2- Publish extra Basic constants for already published values:
      - V_OBJECT=9, V_BOOLEAN=11, V_VARIANT=12, V_BYTE=17
      - not necessarily V_ARRAY=8192, V_ERROR=10
    
    The latter is conditioned to the creation of an enhancement request.
    
    FYI, published Vartype() values and constants for VBA and other Basic-like languages:
    
    https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/vartype-function
    https://docs.xojo.com/VarType
    https://help.hcltechsw.com/dom_designer/9.0.1/appdev/LSAZ_DATATYPE_FUNCTION.html
    
    Change-Id: I51bac3caf555d94e91de7c6d624b3fca9e73a673
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111042
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/basic/qa/basic_coverage/test_typelen_method.vb b/basic/qa/basic_coverage/test_typelen_method.vb
index 4684790078c5..a9ebb01446bb 100644
--- a/basic/qa/basic_coverage/test_typelen_method.vb
+++ b/basic/qa/basic_coverage/test_typelen_method.vb
@@ -6,11 +6,51 @@
 ' file, You can obtain one at http://mozilla.org/MPL/2.0/.
 '
 
-Function doUnitTest as Integer
-    ' TYPELEN
-    If ( TypeLen("Hello") <> 5 ) Then
-        doUnitTest = 0
-    Else
-        doUnitTest = 1
-    End If
+Dim int16 As Integer,   int32 As Long,    flt32 As Single, flt64 As Double, _
+    curr  As Currency,  dat   As Date,    str   As String,                  _
+    myErr As Variant,   var   As Variant, byt3  As Byte,   bool  As Boolean
+
+Dim int_%, long_&, single_!, double_#, currency_@, string_$, array_
+
+Function doUnitTest
+    ' TypeLen()
+
+    dat = #02/17/2012# : myErr = CVErr("errMsg")
+    assert( TypeLen(int16) = 2 , "TypeLen(int16) is not 2")
+    assert( TypeLen(int32) = 4 , "TypeLen(int32) is not 4")
+    assert( TypeLen(flt32) = 4 , "TypeLen(flt32) is not 4" )
+    assert( TypeLen(flt64) = 8 , "TypeLen(flt64) is not 8" )
+    assert( TypeLen(curr)  = 8 , "TypeLen(curr) is not 8" )
+    assert( TypeLen(dat)   = 8 , "TypeLen(dat) is not 8" )
+    assert( TypeLen(str)   = 0 , "TypeLen(str) is not 0" ) ' when empty
+    assert( TypeLen(myErr) = 2 , "TypeLen(myErr) is not 2" )
+    assert( TypeLen(bool)  = 1 , "TypeLen(bool) is not 1" )
+    assert( TypeLen(var)   = 0 , "TypeLen(var) is not 0" ) ' when empty
+    assert( TypeLen(byt3)  = 1 , "TypeLen(byt3) is not 1" )
+
+    assert( TypeLen(int_)      = 2 , "TypeLen(int_) is not 2" )
+    assert( TypeLen(long_)     = 4 , "TypeLen(long_) is not 4" )
+    assert( TypeLen(single_)   = 4 , "TypeLen(single_) is not 4" )
+    assert( TypeLen(double_)   = 8 , "TypeLen(double_) is not 8" )
+    assert( TypeLen(currency_) = 8 , "TypeLen(currency_) is not 8" )
+    assert( TypeLen(string_)   = 0 , "TypeLen(string_) is not 0" )
+
+    If FailedAssertion Then
+        doUnitTest = "test_typelen_method.vb fails" + messages
+        Exit Function
+    EndIf
+    doUnitTest = 1 ' All checks passed
 End Function
+
+Sub DEV_TEST
+    MsgBox doUnitTest
+End Sub
+
+Dim failedAssertion As Boolean, messages As String
+
+Sub assert(expression As Boolean, errMessage As String)
+    If ( Not expression ) Then
+       messages = messages + Chr(10) + ErrMessage
+       failedAssertion = True
+    EndIf
+End Sub
diff --git a/basic/qa/basic_coverage/test_typename_method.vb b/basic/qa/basic_coverage/test_typename_method.vb
index eba2d86c404b..ec9dbb408ac5 100644
--- a/basic/qa/basic_coverage/test_typename_method.vb
+++ b/basic/qa/basic_coverage/test_typename_method.vb
@@ -5,12 +5,71 @@
 ' 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/.
 '
+Type UDF ' User defined type
+    l As Object
+    s as String
+End Type
+Dim myUDF as UDF
 
-Function doUnitTest as Integer
-    ' TYPENAME
-    If ( TypeName("Hello") <> "String" ) Then
-        doUnitTest = 0
-    Else
-        doUnitTest = 1
-    End If
+Dim int16 As Integer,   int32 As Long,    flt32 As Single, flt64 As Double, _
+    curr  As Currency,  dat   As Date,    str   As String, obj   As Object, _
+    myErr As Variant,   var   As Variant, byt3  As Byte,   bool  As Boolean
+
+Dim int_%, long_&, single_!, double_#, currency_@, string_$, array_
+
+Dim intArray()  As Integer,  lngArray(5) As Long, sngArray!() As Single, dblArray#(8)   As Double, _
+    curArray@() As Currency, datArray()  As Date, strArray$() As String, objArray(5,15) As Object, _
+    varArray()  As Variant,  byteArray() As Byte, boolArray() As Boolean
+
+Function doUnitTest ' TypeName()
+
+    myErr = CVErr(0.56E-41)
+    assert( TypeName(int16) = "Integer" , "TypeName(int16) is not ""Integer""")
+    assert( TypeName(int32) = "Long"    , "TypeName(int32) is not ""Long""")
+    assert( TypeName(flt32) = "Single"  , "TypeName(flt32) is not ""Single""" )
+    assert( TypeName(flt64) = "Double"  , "TypeName(flt64) is not ""Double""" )
+    assert( TypeName(curr)  = "Currency", "TypeName(curr) is not ""Currency""" )
+    assert( TypeName(dat)   = "Date"    , "TypeName(dat) is not ""Date""" )
+    assert( TypeName(byt3)  = "Byte"    , "TypeName(byt3) is not ""Byte""" )
+    assert( TypeName(MyErr) = "Error"   , "TypeName(MyErr) is not ""Error""" )
+    assert( TypeName(bool)  = "Boolean" , "TypeName(bool) is not ""Boolean""" )
+    assert( TypeName(str)   = "String"  , "TypeName(str) is not ""String""" )
+    assert( TypeName(obj)   = "Object"  , "TypeName(obj) is not ""Object""" )
+    assert( TypeName(myUDF) = "Object"  , "TypeName(myUDF) is not ""Object""" )
+    assert( TypeName(var)   = "Empty"   , "TypeName(var) is not ""Empty""" )
+
+    assert( TypeName(int_)      = "Integer" , "TypeName(int_) is not ""Integer""" )
+    assert( TypeName(long_)     = "Long"    , "TypeName(long_) is not ""Long""" )
+    assert( TypeName(single_)   = "Single"  , "TypeName(single_) is not ""Single""" )
+    assert( TypeName(double_)   = "Double"  , "TypeName(double_) is not ""Double""" )
+    assert( TypeName(currency_) = "Currency", "TypeName(currency_) is not ""Currency""" )
+    assert( TypeName(string_)   = "String"  , "TypeName(string_) is not ""String""" )
+
+    assert( TypeName(intArray)  = "Integer()" , "TypeName(intArray) is not ""Integer()""" )
+    assert( TypeName(lngArray)  = "Long()"    , "TypeName(lngArray) is not ""Long()""" )
+    assert( TypeName(sngArray)  = "Single()"  , "TypeName(sngArray) is not ""Single()""" )
+    assert( TypeName(dblArray)  = "Double()"  , "TypeName(dblArray) is not ""Double()""" )
+    assert( TypeName(curArray)  = "Currency()", "TypeName(curArray) is not ""Currency()""" )
+    assert( TypeName(datArray)  = "Date()"    , "TypeName(datArray) is not ""Date()""" )
+    assert( TypeName(strArray)  = "String()"  , "TypeName(strArray) is not ""String()""" )
+    assert( TypeName(objArray)  = "Object()"  , "TypeName(objArray) is not ""Object()""" )
+    assert( TypeName(boolArray) = "Boolean()" , "TypeName(boolArray) is not ""Boolean()""" )
+    assert( TypeName(varArray)  = "Variant()" , "TypeName(varArray) is not ""Variant()""" )
+    assert( TypeName(byteArray) = "Byte()"    , "TypeName(byteArray) is not ""Byte()""" )
+    If FailedAssertion Then
+        doUnitTest = "test_typename_method.vb failed" + messages
+        Exit Function
+    EndIf
+    doUnitTest = 1 ' All checks passed
 End Function
+
+Sub DEV_TEST : Print doUnitTest : End Sub
+
+Dim failedAssertion As Boolean, messages As String
+
+Sub assert(expression As Boolean, errMessage As String)
+    if ( Not expression ) Then
+       messages = messages + Chr(10) + ErrMessage
+       failedAssertion = True
+    EndIf
+End Sub
\ No newline at end of file
diff --git a/basic/qa/basic_coverage/test_vartype_method.vb b/basic/qa/basic_coverage/test_vartype_method.vb
index bd45adef00df..9c15d8520a93 100644
--- a/basic/qa/basic_coverage/test_vartype_method.vb
+++ b/basic/qa/basic_coverage/test_vartype_method.vb
@@ -5,12 +5,93 @@
 ' 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/.
 '
+Type UDF ' User defined type
+    l As Object
+    s as String
+End Type
+Dim myUDF As UDF
 
-Function doUnitTest as Integer
-    ' VARTYPE
-    If ( VarType("Hello") <> 8 ) Then
-        doUnitTest = 0
-    Else
-        doUnitTest = 1
-    End If
+Dim int16 As Integer,   int32 As Long,    flt32 As Single, flt64 As Double, _
+    curr  As Currency,  dat   As Date,    str   As String, obj   As Object, _
+    myErr As Variant,   var   As Variant, byt3  As Byte,   bool  As Boolean
+    
+Dim int_%, long_&, single_!, double_#, currency_@, string_$, array_
+
+Dim intArray()  As Integer,  lngArray(5) As Long, sngArray!() As Single, dblArray#(8) As Double, _
+    curArray@() As Currency, datArray()  As Date, strArray$() As String, objArray()   As Object, _
+    varArray()  As Variant,  byteArray() As Byte, boolArray() As Boolean
+
+' Constants that candidate for public exposure
+Private Const V_ARRAY=8192, V_OBJECT=9, V_ERROR=10, V_BOOLEAN=11, V_VARIANT=12, V_BYTE=17
+
+Function doUnitTest
+    ' VarType()
+
+    assert( V_EMPTY = 0   , "V_EMPTY is not 0")
+    assert( V_NULL = 1    , "V_NULL is not 1")
+    assert( V_INTEGER = 2 , "V_INTEGER is not 2")
+    assert( V_LONG = 3    , "V_LONG is not 3")
+    assert( V_SINGLE = 4  , "V_SINGLE is not 4")
+    assert( V_DOUBLE = 5  , "V_DOUBLE is not 5")
+    assert( V_CURRENCY = 6, "V_CURRENCY is not 6")
+    assert( V_DATE = 7    , "V_DATE is not 7")
+    assert( V_STRING = 8  , "V_STRING is not 8")
+
+    assert( VarType(Empty)   = V_EMPTY , "Vartype(Empty) is not V_EMPTY")
+    assert( VarType(Null)    = V_NULL  , "Vartype(Empty) is not V_NULL")
+    assert( VarType(Nothing) = V_OBJECT, "Vartype(Empty) is not V_OBJECT")
+
+    myErr = CVErr("errMsg")
+    assert( VarType(int16) = V_INTEGER , "VarType(int16) is not V_INTEGER")
+    assert( VarType(int32) = V_LONG    , "VarType(int32) is not V_LONG")
+    assert( VarType(flt32) = V_SINGLE  , "VarType(flt32) is not V_SINGLE" )
+    assert( VarType(flt64) = V_DOUBLE  , "VarType(flt64) is not V_DOUBLE" )
+    assert( VarType(curr)  = V_CURRENCY, "VarType(curr) is not V_CURRENCY" )
+    assert( VarType(dat)   = V_DATE    , "VarType(dat) is not V_DATE" )
+    assert( VarType(str)   = V_STRING  , "VarType(str) is not V_STRING" )
+    assert( VarType(obj)   = V_OBJECT  , "VarType(obj) is not V_OBJECT" )
+    assert( VarType(myUDF) = V_OBJECT  , "VarType(myUDF) is not V_OBJECT" )
+    assert( VarType(myErr) = V_ERROR   , "VarType(myErr) is not V_ERROR" )
+    assert( VarType(bool)  = V_BOOLEAN , "VarType(bool) is not V_BOOLEAN" )
+    assert( VarType(var)   = V_EMPTY   , "VarType(var) is not V_EMPTY" )
+    assert( VarType(byt3)  = V_BYTE    , "VarType(byt3) is not V_BYTE" )
+
+    assert( VarType(int_)      = V_INTEGER , "VarType(int_) is not V_INTEGER" )
+    assert( VarType(long_)     = V_LONG    , "VarType(long_) is not V_LONG" )
+    assert( VarType(single_)   = V_SINGLE  , "VarType(single_) is not V_SINGLE" )
+    assert( VarType(double_)   = V_DOUBLE  , "VarType(double_) is not V_CURRENCY" )
+    assert( VarType(currency_) = V_CURRENCY, "VarType(currency_) is not V_CURRENCY" )
+    assert( VarType(string_)   = V_STRING  , "VarType(string_) is not V_STRING" )
+
+    assert( VarType(intArray)  = V_ARRAY+V_INTEGER , "VarType(intArray) is not V_ARRAY+V_INTEGER" )
+    assert( VarType(lngArray)  = V_ARRAY+V_LONG    , "VarType(lngArray) is not V_ARRAY+V_LONG" )
+    assert( VarType(sngArray)  = V_ARRAY+V_SINGLE  , "VarType(sngArray) is not V_ARRAY+V_SINGLE" )
+    assert( VarType(dblArray)  = V_ARRAY+V_DOUBLE  , "VarType(dblArray) is not V_ARRAY+V_DOUBLE" )
+    assert( VarType(curArray)  = V_ARRAY+V_CURRENCY, "VarType(curArray) is not V_ARRAY+V_CURRENCY" )
+    assert( VarType(datArray)  = V_ARRAY+V_DATE    , "VarType(datArray) is not V_ARRAY+V_DATE" )
+    assert( VarType(strArray)  = V_ARRAY+V_STRING  , "VarType(strArray) is not V_ARRAY+V_STRING" )
+    assert( VarType(objArray)  = V_ARRAY+V_OBJECT  , "VarType(objArray) is not V_ARRAY+V_OBJECT" )
+    'assert( VarType(***Array)  = V_ARRAY+V_ERROR  , "VarType(***Array) is not V_ARRAY+V_ERROR" )
+    assert( VarType(boolArray) = V_ARRAY+V_BOOLEAN , "VarType(boolArray) is not V_ARRAY+V_BOOLEAN" )
+    assert( VarType(varArray)  = V_ARRAY+V_VARIANT , "VarType(varArray) is not V_ARRAY+V_VARIANT" )
+    assert( VarType(byteArray) = V_ARRAY+V_BYTE    , "VarType(byteArray) is not V_ARRAY+V_BYTE" )
+
+    If failedAssertion Then
+        doUnitTest = "test_vartype_method.vb fails" + messages
+        Exit Function
+    EndIf
+    doUnitTest = 1 ' All checks passed
 End Function
+
+Sub DEV_TEST
+    MsgBox doUnitTest
+End Sub
+
+Dim failedAssertion As Boolean, messages As String
+
+Sub assert(expression As Boolean, errMessage As String)
+    If ( Not expression ) Then
+       messages = messages + Chr(10) + ErrMessage
+       failedAssertion = True
+    EndIf
+End Sub


More information about the Libreoffice-commits mailing list