1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="sheet_XCellRangeMovement" script:language="StarBasic">
4
5
6'*************************************************************************
7'
8' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9'
10' Copyright 2000, 2010 Oracle and/or its affiliates.
11'
12' OpenOffice.org - a multi-platform office productivity suite
13'
14' This file is part of OpenOffice.org.
15'
16' OpenOffice.org is free software: you can redistribute it and/or modify
17' it under the terms of the GNU Lesser General Public License version 3
18' only, as published by the Free Software Foundation.
19'
20' OpenOffice.org is distributed in the hope that it will be useful,
21' but WITHOUT ANY WARRANTY; without even the implied warranty of
22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23' GNU Lesser General Public License version 3 for more details
24' (a copy is included in the LICENSE file that accompanied this code).
25'
26' You should have received a copy of the GNU Lesser General Public License
27' version 3 along with OpenOffice.org.  If not, see
28' <http://www.openoffice.org/license.html>
29' for a copy of the LGPLv3 License.
30'
31'*************************************************************************
32*****
33'*************************************************************************
34
35
36
37
38
39Sub RunTest()
40
41'*************************************************************************
42' INTERFACE:
43' com.sun.star.sheet.XCellRangeMovement
44'*************************************************************************
45On Error Goto ErrHndl
46    Dim bOK As Boolean
47
48    Out.Log("Prepearing test...")
49    for i = 0 to 5
50        for j = 0 to 5
51            oObj.getCellByPosition(j, i).Value = i * 6 + j
52        next j
53    next i
54
55    Test.StartMethod("insertCells()")
56    bOK = true
57    Dim newCellAddress As New com.sun.star.table.CellRangeAddress
58    newCellAddress.Sheet = 0
59    newCellAddress.StartColumn = 1
60    newCellAddress.StartRow = 1
61    newCellAddress.EndColumn = 1
62    newCellAddress.EndRow = 1
63    oObj.insertCells(newCellAddress, com.sun.star.sheet.CellInsertMode.DOWN)
64    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
65    bOK = bOK AND oObj.getCellByPosition(2, 2).Value = 14
66    bOK = bOK AND oObj.getCellByPosition(1, 2).Value = 7
67    bOK = bOK AND oObj.getCellByPosition(0, 2).Value = 12
68
69    oObj.insertCells(newCellAddress, com.sun.star.sheet.CellInsertMode.RIGHT)
70    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
71    bOK = bOK AND oObj.getCellByPosition(3, 0).Value = 3
72    bOK = bOK AND oObj.getCellByPosition(3, 1).Value = 8
73    bOK = bOK AND oObj.getCellByPosition(3, 2).Value = 15
74
75    oObj.insertCells(newCellAddress, com.sun.star.sheet.CellInsertMode.ROWS)
76    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
77    bOK = bOK AND oObj.getCellByPosition(4, 0).Value = 4
78    bOK = bOK AND oObj.getCellByPosition(4, 1).String = ""
79    bOK = bOK AND oObj.getCellByPosition(4, 2).Value = 9
80
81    oObj.insertCells(newCellAddress, com.sun.star.sheet.CellInsertMode.COLUMNS)
82    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
83    bOK = bOK AND oObj.getCellByPosition(0, 5).Value = 24
84    bOK = bOK AND oObj.getCellByPosition(1, 5).String = ""
85    bOK = bOK AND oObj.getCellByPosition(2, 5).Value = 19
86
87    Test.MethodTested("insertCells()", bOK)
88
89    Test.StartMethod("removeRange()")
90    bOK = true
91    oObj.removeRange(newCellAddress, com.sun.star.sheet.CellDeleteMode.ROWS)
92    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
93    bOK = bOK AND oObj.getCellByPosition(4, 0).Value = 3
94    bOK = bOK AND oObj.getCellByPosition(4, 1).Value = 8
95    bOK = bOK AND oObj.getCellByPosition(4, 2).Value = 15
96
97    oObj.removeRange(newCellAddress, com.sun.star.sheet.CellDeleteMode.COLUMNS)
98    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
99    bOK = bOK AND oObj.getCellByPosition(4, 0).Value = 4
100    bOK = bOK AND oObj.getCellByPosition(4, 1).Value = 9
101    bOK = bOK AND oObj.getCellByPosition(4, 2).Value = 16
102
103    oObj.removeRange(newCellAddress, com.sun.star.sheet.CellDeleteMode.UP)
104    bOK = bOK AND oObj.getCellByPosition(1, 1).Value = 7
105    bOK = bOK AND oObj.getCellByPosition(1, 2).Value = 13
106    bOK = bOK AND oObj.getCellByPosition(1, 3).Value = 19
107    bOK = bOK AND oObj.getCellByPosition(0, 3).Value = 18
108
109    oObj.removeRange(newCellAddress, com.sun.star.sheet.CellDeleteMode.LEFT)
110    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
111    bOK = bOK AND oObj.getCellByPosition(0, 1).Value = 6
112    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
113    bOK = bOK AND oObj.getCellByPosition(2, 1).Value = 8
114
115    Test.MethodTested("removeRange()", bOK)
116
117    Test.StartMethod("moveRange()")
118    bOK = true
119    newCellAddress.Sheet = 0
120    newCellAddress.StartColumn = 0
121    newCellAddress.StartRow = 0
122    newCellAddress.EndColumn = 1
123    newCellAddress.EndRow = 1
124    Dim sCell As New com.sun.star.table.CellAddress
125    sCell.Sheet = 0
126    sCell.Column = 3
127    sCell.Row = 3
128    oObj.moveRange(sCell, newCellAddress)
129
130    bOK = bOK AND oObj.getCellByPosition(0, 0).String = ""
131    bOK = bOK AND oObj.getCellByPosition(1, 0).String = ""
132    bOK = bOK AND oObj.getCellByPosition(0, 1).String = ""
133    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
134
135    bOK = bOK AND oObj.getCellByPosition(3, 3).Value = 0
136    bOK = bOK AND oObj.getCellByPosition(3, 4).Value = 6
137    bOK = bOK AND oObj.getCellByPosition(4, 3).Value = 1
138    bOK = bOK AND oObj.getCellByPosition(4, 4).String = ""
139
140    Test.MethodTested("moveRange()", bOK)
141
142    Test.StartMethod("copyRange()")
143    bOK = true
144    newCellAddress.Sheet = 0
145    newCellAddress.StartColumn = 2
146    newCellAddress.StartRow = 2
147    newCellAddress.EndColumn = 3
148    newCellAddress.EndRow = 3
149    sCell.Sheet = 0
150    sCell.Column = 0
151    sCell.Row = 0
152
153    oObj.copyRange(sCell, newCellAddress)
154
155    bOK = bOK AND oObj.getCellByPosition(0, 0).Value = oObj.getCellByPosition(2, 2).Value
156    bOK = bOK AND oObj.getCellByPosition(0, 1).Value = oObj.getCellByPosition(2, 3).Value
157    bOK = bOK AND oObj.getCellByPosition(1, 0).Value = oObj.getCellByPosition(3, 2).Value
158    bOK = bOK AND oObj.getCellByPosition(1, 1).Value = oObj.getCellByPosition(3, 3).Value
159
160    Test.MethodTested("copyRange()", bOK)
161
162Exit Sub
163ErrHndl:
164    Test.Exception()
165    bOK = false
166    resume next
167End Sub
168</script:module>
169