tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / basic / qa / basic_coverage / test_With.bas
blobb22e0d94ba1f58605fa9e856bde841c6c7ac71dc
2 ' This file is part of the LibreOffice project.
4 ' This Source Code Form is subject to the terms of the Mozilla Public
5 ' License, v. 2.0. If a copy of the MPL was not distributed with this
6 ' file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 Option Explicit
11 Function doUnitTest as String
12 TestUtil.TestInit
13 test_with
14 doUnitTest = TestUtil.GetResult()
15 End Function
17 Sub DEV_TST : MsgBox doUnitTesT : End Sub
19 Type foo
20 n As Integer
21 s As String
22 End Type
24 Dim get_foo_count As Integer
26 Function get_foo As foo
27 get_foo_count = get_foo_count + 1
28 get_foo = New foo
29 End Function
31 Sub with_in_another_procedure
32 On Local Error GoTo errorHandler
33 ' tdf#162962 "End With" clears the internal variable; it used to fail,
34 ' when several module's procedures used With blocks, using Option Explicit
35 Dim foo_var As New foo
36 With foo_var
37 .n = 6
38 TestUtil.AssertEqual(.n, 6, ".n")
39 End With ' Here (or in similar places in other tests) a "Variable Not Defined" error was generated
41 Exit Sub
42 errorHandler:
43 TestUtil.ReportErrorHandler("with_in_another_procedure", Err, Error$, Erl)
44 End Sub
46 Sub test_with
47 On Local Error GoTo errorHandler
49 Dim fields As String
50 With get_foo()
51 .n = 5
52 .s = "bar"
53 fields = "n = " & .n & " s = " & .s
54 End With
55 ' get_foo must be called only once; before the fix, it failed with
56 ' Number of calls to get_foo returned 4, expected 1
57 TestUtil.AssertEqual(get_foo_count, 1, "Number of calls to get_foo")
58 ' Before the fix, each use of . resulted in creation of a new 'foo' object,
59 ' and previous assignments didn't reflect in the result; it failed with
60 ' Field values returned n = 0 s = , expected n = 5 s = bar
61 TestUtil.AssertEqual(fields, "n = 5 s = bar", "Field values")
63 ' Make sure that With works with the original object, modifies it, and does not destroy
64 Dim foo_var As New foo
65 With foo_var
66 .n = 6
67 .s = "baz"
68 End With
69 fields = "n = " & foo_var.n & " s = " & foo_var.s
70 TestUtil.AssertEqual(fields, "n = 6 s = baz", "Field values of foo_var")
72 ' tdf#163219: make sure that assigning the variable in the block works
73 Set foo_var = Nothing
74 TestUtil.Assert(foo_var Is Nothing, "foo_var Is Nothing")
75 With foo_var
76 foo_var = New foo
77 .n = 7
78 .s = "something"
79 End With
80 TestUtil.AssertEqual(foo_var.n, 7, "foo_var.n")
81 TestUtil.AssertEqual(foo_var.s, "something", "foo_var.s")
83 ' tdf#162935: Test an UNO struct - it used to copy into the With variable, not used by ref
84 Dim uno_struct As New com.sun.star.table.CellRangeAddress
85 With uno_struct
86 .Sheet = 1
87 .StartColumn = 2
88 .StartRow = 3
89 .EndColumn = 4
90 .EndRow = 5
91 End With
92 TestUtil.AssertEqual(uno_struct.Sheet, 1, "uno_struct.Sheet")
93 TestUtil.AssertEqual(uno_struct.StartColumn, 2, "uno_struct.StartColumn")
94 TestUtil.AssertEqual(uno_struct.StartRow, 3, "uno_struct.StartRow")
95 TestUtil.AssertEqual(uno_struct.EndColumn, 4, "uno_struct.EndColumn")
96 TestUtil.AssertEqual(uno_struct.EndRow, 5, "uno_struct.EndRow")
98 with_in_another_procedure() ' test tdf#162962
100 Exit Sub
101 errorHandler:
102 TestUtil.ReportErrorHandler("test_with", Err, Error$, Erl)
103 End Sub