summaryrefslogtreecommitdiffstats
path: root/basic/qa/basic_coverage/test_types_conversion.vb
blob: 68b28b1afc0a12d4329b7c52e5df0a1bd22ad798 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'
' 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/.
'
Option Explicit

Dim nTotalCount As Integer
Dim nPassCount As Integer
Dim nFailCount As Integer

' For the following tests the en-US (English - United States) locale is required
Function doUnitTest() As Integer
    nTotalCount = 0
    nPassCount = 0
    nFailCount = 0

    ' Test implicit conversions from string to number
    Dim nVal As Double
    ' Simple integer
    StartTest()
    nVal = "123"
    AssertTest(nVal = 123)

    ' Negative integer
    StartTest()
    nVal = "-123"
    AssertTest(nVal = -123)

    ' Negative floating-point
    StartTest()
    nVal = "-123.45"
    AssertTest(nVal = -123.45)

    ' Negative floating-point with leading and trailing spaces
    StartTest()
    nVal = " -123.456 "
    AssertTest(nVal = -123.456)

    If LibreOffice6FloatingPointMode() Then
        ' Wrong decimal separator (and not even interpreted as group separator)
         StartTest()
        nVal = " -123,45 "
        AssertTest(nVal = -123)
    Else
        ' Wrong decimal separator (interpreted as group separator)
        StartTest()
        nVal = " -123,456 "
        AssertTest(nVal = -123456)
    End If

    If ((nFailCount > 0) Or (nPassCount <> nTotalCount)) Then
        doUnitTest = 0
    Else
        doUnitTest = 1
    End If
End Function

Sub StartTest()
    nTotalCount = nTotalCount + 1
End Sub

Sub AssertTest(testResult As Boolean)
    If (testResult) Then
        nPassCount = nPassCount + 1
    Else
        nFailCount = nFailCount + 1
    End If
End Sub