bump product version to 5.0.4.1
[LibreOffice.git] / basic / qa / vba_tests / stringplusdouble.vb
blob3f0cbd8ef21b79e8ebceefe378c5aff0cefc7807
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_stringplusdouble()
9 If failCount <> 0 And passCount > 0 Then
10 doUnitTest = result
11 Else
12 doUnitTest = "OK"
13 End If
14 End Function
16 Function verify_stringplusdouble() as String
17 passCount = 0
18 failCount = 0
20 result = "Test Results" & Chr$(10) & "============" & Chr$(10)
22 DSD
23 SSD
24 DSS
25 result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
26 verify_stringplusdouble = result
27 End Function
29 Sub DSD()
30 Dim testName As String
31 testName = "double = string + double"
32 Dim testCompute As String
34 Dim s As String
35 Dim d As Double
36 Dim r As Double
38 On Error GoTo ErrorHandler
40 testCompute = "s = null, d = null, r = s + d"
41 r = s + d
42 TestLog_ASSERT r = -1, testCompute & " .The result is: " & r
44 testCompute = "s = null, d = null, r = s & d"
45 r = s & d
46 TestLog_ASSERT r = 0, testCompute & " .The result is: " & r
48 testCompute = "s = null, d = 20, r = s + d"
49 d = 20
50 r = s + d
51 TestLog_ASSERT r = -1, testCompute & " .The result is: " & r
53 testCompute = "s = null, d = 20, r = s & d"
54 d = 20
55 r = s & d
56 TestLog_ASSERT r = 20, testCompute & " .The result is: " & r
59 ''''''''''''''
60 s = "10"
61 Dim d2 As Double
62 testCompute = "s = '10', d = null, r = s + d"
63 r = s + d2
64 TestLog_ASSERT r = 10, testCompute & " .The result is: " & r
66 testCompute = "s = '10', d = null, r = s & d"
67 r = s & d2
68 TestLog_ASSERT r = 100, testCompute & " .The result is: " & r
70 testCompute = "s = '10', d = 20, r = s + d"
71 d2 = 20
72 r = s + d2
73 TestLog_ASSERT r = 30, testCompute & " .The result is: " & r
75 testCompute = "s = '10', d = 20, r = s & d"
76 d2 = 20
77 r = s & d2
78 TestLog_ASSERT r = 1020, testCompute & " .The result is: " & r
80 ''''''''''''''
81 s = "abc"
82 Dim d3 As Double
83 testCompute = "s = 'abc', d = null, r = s + d"
84 r = s + d3
85 TestLog_ASSERT r = -1, testCompute & " .The result is: " & r
87 testCompute = "s = 'abc', d = null, r = s & d"
88 r = s & d3
89 TestLog_ASSERT r = -1, testCompute & " .The result is: " & r
91 testCompute = "s = 'abc', d = 20, r = s + d"
92 d3 = 20
93 r = s + d3
94 TestLog_ASSERT r = -1, testCompute & " .The result is: " & r
96 testCompute = "s = 'abc', d = 20, r = s & d"
97 d3 = 20
98 r = s & d3
99 TestLog_ASSERT r = -1, testCompute & " .The result is: " & r
101 Exit Sub
103 ErrorHandler:
104 r = -1
105 ' TestLog_Comment "The next compute raises error: " & testCompute
106 Resume Next
107 End Sub
110 Sub SSD()
111 Dim testName As String
112 testName = "string = string + double"
113 Dim testCompute As String
115 Dim s As String
116 Dim d As Double
117 Dim r As String
119 On Error GoTo ErrorHandler
121 testCompute = "s = null, d = null, r = s + d"
122 r = s + d
123 TestLog_ASSERT r = "-1", testCompute & " .The result is: " & r
125 testCompute = "s = null, d = null, r = s & d"
126 r = s & d
127 TestLog_ASSERT r = "0", testCompute & " .The result is: " & r
129 testCompute = "s = null, d = 20, r = s + d"
130 d = 20
131 r = s + d
132 TestLog_ASSERT r = "-1", testCompute & " .The result is: " & r
134 testCompute = "s = null, d = 20, r = s & d"
135 d = 20
136 r = s & d
137 TestLog_ASSERT r = "20", testCompute & " .The result is: " & r
140 ''''''''''''''
141 s = "10"
142 Dim d2 As Double
143 testCompute = "s = '10', d = null, r = s + d"
144 r = s + d2
145 TestLog_ASSERT r = "10", testCompute & " .The result is: " & r
147 testCompute = "s = '10', d = null, r = s & d"
148 r = s & d2
149 TestLog_ASSERT r = "100", testCompute & " .The result is: " & r
151 testCompute = "s = '10', d = 20, r = s + d"
152 d2 = 20
153 r = s + d2
154 TestLog_ASSERT r = "30", testCompute & " .The result is: " & r
156 testCompute = "s = '10', d = 20, r = s & d"
157 d2 = 20
158 r = s & d2
159 TestLog_ASSERT r = "1020", testCompute & " .The result is: " & r
161 ''''''''''''''
162 s = "abc"
163 Dim d3 As Double
164 testCompute = "s = 'abc', d = null, r = s + d"
165 r = s + d3
166 TestLog_ASSERT r = "-1", testCompute & " .The result is: " & r
168 testCompute = "s = 'abc', d = null, r = s & d"
169 r = s & d3
170 TestLog_ASSERT r = "abc0", testCompute & " .The result is: " & r
172 testCompute = "s = 'abc', d = 20, r = s + d"
173 d3 = 20
174 r = s + d3
175 TestLog_ASSERT r = "-1", testCompute & " .The result is: " & r
177 testCompute = "s = 'abc', d = 20, r = s & d"
178 d3 = 20
179 r = s & d3
180 TestLog_ASSERT r = "abc20", testCompute & " .The result is: " & r
181 Exit Sub
183 ErrorHandler:
184 r = "-1"
185 ' TestLog_Comment "The next compute raises error: " & testCompute
186 Resume Next
187 End Sub
189 Sub DSS()
190 Dim testName As String
191 testName = "double = string + string"
192 Dim testCompute As String
194 Dim s As String
195 Dim d As String
196 Dim r As Double
198 On Error GoTo ErrorHandler
200 testCompute = "s = null, d = null, r = s + d"
201 r = s + d
202 TestLog_ASSERT r = -1, testCompute & " .The result is: " & r
204 testCompute = "s = null, d = null, r = s & d"
205 r = s & d
206 TestLog_ASSERT r = -1, testCompute & " .The result is: " & r
208 testCompute = "s = null, d = 20, r = s + d"
209 d = "20"
210 r = s + d
211 TestLog_ASSERT r = 20, testCompute & " .The result is: " & r
213 testCompute = "s = null, d = 20, r = s & d"
214 d = "20"
215 r = s & d
216 TestLog_ASSERT r = 20, testCompute & " .The result is: " & r
219 ''''''''''''''
220 s = "10"
221 Dim d2 As String
222 testCompute = "s = '10', d = null, r = s + d"
223 r = s + d2
224 TestLog_ASSERT r = 10, testCompute & " .The result is: " & r
226 testCompute = "s = '10', d = null, r = s & d"
227 r = s & d2
228 TestLog_ASSERT r = 10, testCompute & " .The result is: " & r
230 testCompute = "s = '10', d = 20, r = s + d"
231 d2 = "20"
232 r = s + d2
233 TestLog_ASSERT r = 1020, testCompute & " .The result is: " & r
235 testCompute = "s = '10', d = 20, r = s & d"
236 d2 = "20"
237 r = s & d2
238 TestLog_ASSERT r = 1020, testCompute & " .The result is: " & r
240 ''''''''''''''
241 s = "abc"
242 Dim d3 As String
243 testCompute = "s = 'abc', d = null, r = s + d"
244 r = s + d3
245 TestLog_ASSERT r = -1, testCompute & " .The result is: " & r
247 testCompute = "s = 'abc', d = null, r = s & d"
248 r = s & d3
249 TestLog_ASSERT r = -1, testCompute & " .The result is: " & r
251 testCompute = "s = 'abc', d = 20, r = s + d"
252 d3 = "20"
253 r = s + d3
254 TestLog_ASSERT r = -1, testCompute & " .The result is: " & r
256 testCompute = "s = 'abc', d = 20, r = s & d"
257 d3 = "20"
258 r = s & d3
259 TestLog_ASSERT r = -1, testCompute & " .The result is: " & r
260 Exit Sub
262 ErrorHandler:
263 r = -1
264 ' TestLog_Comment "The next compute raises error: " & testCompute
265 Resume Next
266 End Sub
270 Sub test2()
271 Dim s As String
272 Dim d As Double
273 s = ""
274 d = s ' fail in MSO
275 MsgBox d
276 End Sub
278 Sub testBolean()
279 Dim a As String
280 Dim b As Boolean
281 Dim c As Boolean
282 Dim d As String
284 b = True
286 a = "1"
287 c = a + b ' c = false
288 MsgBox c
290 d = a + b 'd = 0
291 MsgBox d
292 End Sub
294 Sub testCurrency()
295 Dim a As String
296 Dim b As Currency
297 Dim c As Currency
298 Dim d As String
300 a = "10"
301 b = 30.3
303 c = a + b ' c = 40.3
304 MsgBox c
306 d = a + b ' c =40.3
307 MsgBox d
309 End Sub
311 Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String)
313 If assertion = True Then
314 passCount = passCount + 1
315 Else
316 Dim testMsg As String
317 If Not IsMissing(testId) Then
318 testMsg = testMsg + " : " + testId
319 End If
320 If Not IsMissing(testComment) And Not (testComment = "") Then
321 testMsg = testMsg + " (" + testComment + ")"
322 End If
324 result = result & Chr$(10) & " Failed: " & testMsg
325 failCount = failCount + 1
326 End If
328 End Sub