summaryrefslogtreecommitdiff
path: root/basic/qa/vba_tests
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-06-29 02:44:13 +1000
committerMike Kaganski <mike.kaganski@collabora.com>2018-06-29 21:06:12 +0200
commit0f7a7c8e719dab6b79e24285b907b5be17f39fc8 (patch)
tree539bf96b35bb087d42ae975d6ef1d7f34a1d77bc /basic/qa/vba_tests
parent2871d455ca0fefca64aaad0906a8e7739dbc88bb (diff)
tdf#118218: Implement FormatNumber VBA function
The existing unit test (previously non-functional because of defunct success condition) is fixed and extended. Change-Id: I2544f865144b25f51a5f0941e5d961f246f41c4b Reviewed-on: https://gerrit.libreoffice.org/56610 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'basic/qa/vba_tests')
-rw-r--r--basic/qa/vba_tests/formatnumber.vb43
1 files changed, 34 insertions, 9 deletions
diff --git a/basic/qa/vba_tests/formatnumber.vb b/basic/qa/vba_tests/formatnumber.vb
index 3132e58edb54..060d1342cb98 100644
--- a/basic/qa/vba_tests/formatnumber.vb
+++ b/basic/qa/vba_tests/formatnumber.vb
@@ -8,7 +8,7 @@ Dim result As String
Function doUnitTest() As String
result = verify_testFormatNumber()
-If failCount <> 0 And passCount > 0 Then
+If failCount <> 0 Or passCount = 0 Then
doUnitTest = result
Else
doUnitTest = "OK"
@@ -25,20 +25,45 @@ Function verify_testFormatNumber() As String
result = "Test Results" & Chr$(10) & "============" & Chr$(10)
Dim testName As String
- Dim date1, date2
- testName = "Test FormatNumber function"
+ Dim str1 As String, str2 As String
On Error GoTo errorHandler
- date2 = "42778.00"
- date1 = FormatNumber("12.2", 2, vbFalse, vbFalse, vbFalse)
- TestLog_ASSERT date1 = date2, "the return FormatNumber is: " & date1
+ testName = "Test 1: positive, 2 decimals"
+ str2 = "12.20"
+ str1 = FormatNumber("12.2", 2, vbFalse, vbFalse, vbFalse)
+ TestLog_ASSERT str1 = str2, testName, "FormatNumber returned: " & str1
+
+ testName = "Test 2: negative, 20 decimals, use leading zero"
+ str2 = "-0.20000000000000000000"
+ str1 = FormatNumber("-.2", 20, vbTrue, vbFalse, vbFalse)
+ TestLog_ASSERT str1 = str2, testName, "FormatNumber returned: " & str1
+
+ testName = "Test 3: negative, 20 decimals, no leading zero"
+ str2 = "-.20000000000000000000"
+ str1 = FormatNumber("-0.2", 20, vbFalse, vbFalse, vbFalse)
+ TestLog_ASSERT str1 = str2, testName, "FormatNumber returned: " & str1
+
+ testName = "Test 4: negative, no leading zero, use parens"
+ str2 = "(.20)"
+ str1 = FormatNumber("-0.2", -1, vbFalse, vbTrue, vbFalse)
+ TestLog_ASSERT str1 = str2, testName, "FormatNumber returned: " & str1
+
+ testName = "Test 5: negative, default leading zero, use parens"
+ str2 = "(0.20)"
+ str1 = FormatNumber("-0.2", -1, vbUseDefault, vbTrue, vbFalse)
+ TestLog_ASSERT str1 = str2, testName, "FormatNumber returned: " & str1
+
+ testName = "Test 6: group digits"
+ str2 = "-12,345,678.00"
+ str1 = FormatNumber("-12345678", -1, vbUseDefault, vbUseDefault, vbTrue)
+ TestLog_ASSERT str1 = str2, testName, "FormatNumber returned: " & str1
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
verify_testFormatNumber = result
Exit Function
errorHandler:
- TestLog_ASSERT (False), testName & ": hit error handler"
+ TestLog_ASSERT False, testName & ": hit error handler"
End Function
Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String)
@@ -48,10 +73,10 @@ Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional tes
Else
Dim testMsg As String
If Not IsMissing(testId) Then
- testMsg = testMsg + " : " + testId
+ testMsg = testId & " "
End If
If Not IsMissing(testComment) And Not (testComment = "") Then
- testMsg = testMsg + " (" + testComment + ")"
+ testMsg = testMsg + "(" + testComment + ")"
End If
result = result & Chr$(10) & " Failed: " & testMsg