Bump version to 6.4.7.2.M8
[LibreOffice.git] / basic / qa / vba_tests / cint.vb
blob6c1d53c93c61eba64a61bc8300e82a170d6fdec2
1 Option VBASupport 1
2 Option Explicit
3 Dim passCount As Integer
4 Dim failCount As Integer
5 Dim result As String
7 Function doUnitTest() As String
8 result = verify_testCInt()
9 If failCount <> 0 Or passCount = 0 Then
10 doUnitTest = result
11 Else
12 doUnitTest = "OK"
13 End If
14 End Function
18 Function verify_testCInt() As String
20 passCount = 0
21 failCount = 0
23 result = "Test Results" & Chr$(10) & "============" & Chr$(10)
25 Dim testName As String
26 Dim nr1, nr2 As Integer 'variables for test
27 testName = "Test CInt function"
30 On Error GoTo errorHandler
32 nr2 = -1
33 nr1 = CInt(-1.1)
34 TestLog_ASSERT nr1 = nr2, "the return CInt is: " & nr1
36 nr2 = -1
37 nr1 = CInt(-1.1)
38 TestLog_ASSERT nr1 = nr2, "the return CInt is: " & nr1
40 nr2 = -2
41 nr1 = CInt(-1.9)
42 TestLog_ASSERT nr1 = nr2, "the return CInt is: " & nr1
44 nr2 = 0
45 nr1 = CInt(0.2)
46 TestLog_ASSERT nr1 = nr2, "the return CInt is: " & nr1
48 REM In excel:
49 REM If the fraction is less than or equal to .5, the result will round down.
50 REM If the fraction is greater than .5, the result will round up.
52 REM nr2 = 0
53 REM nr1 = CInt(0.5)
54 REM TestLog_ASSERT nr1 = nr2, "the return CInt is: " & nr1
56 REM nr2 = 2
57 REM nr1 = CInt(1.5)
58 REM TestLog_ASSERT nr1 = nr2, "the return CInt is: " & nr1
60 REM nr2 = 2
61 REM nr1 = CInt(2.5)
62 REM TestLog_ASSERT nr1 = nr2, "the return CInt is: " & nr1
64 nr2 = 11
65 nr1 = CInt(10.51)
66 TestLog_ASSERT nr1 = nr2, "the return CInt is: " & nr1
68 nr2 = 30207
69 nr1 = CInt("&H75FF")
70 TestLog_ASSERT nr1 = nr2, "the return CInt is: " & nr1
72 nr2 = 1876
73 nr1 = CInt("&H754")
74 TestLog_ASSERT nr1 = nr2, "the return CInt is: " & nr1
76 result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
77 verify_testCInt = result
79 Exit Function
80 errorHandler:
81 TestLog_ASSERT (False), testName & ": hit error handler"
82 End Function
84 Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String)
86 If assertion = True Then
87 passCount = passCount + 1
88 Else
89 Dim testMsg As String
90 If Not IsMissing(testId) Then
91 testMsg = testMsg + " : " + testId
92 End If
93 If Not IsMissing(testComment) And Not (testComment = "") Then
94 testMsg = testMsg + " (" + testComment + ")"
95 End If
97 result = result & Chr$(10) & " Failed: " & testMsg
98 failCount = failCount + 1
99 End If
101 End Sub