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'  Licensed to the Apache Software Foundation (ASF) under one
9'  or more contributor license agreements.  See the NOTICE file
10'  distributed with this work for additional information
11'  regarding copyright ownership.  The ASF licenses this file
12'  to you under the Apache License, Version 2.0 (the
13'  "License"); you may not use this file except in compliance
14'  with the License.  You may obtain a copy of the License at
15'
16'    http://www.apache.org/licenses/LICENSE-2.0
17'
18'  Unless required by applicable law or agreed to in writing,
19'  software distributed under the License is distributed on an
20'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21'  KIND, either express or implied.  See the License for the
22'  specific language governing permissions and limitations
23'  under the License.
24'
25'*************************************************************************
26
27
28
29
30
31
32
33Sub RunTest()
34
35'*************************************************************************
36' INTERFACE:
37' com.sun.star.sheet.XCellRangeMovement
38'*************************************************************************
39On Error Goto ErrHndl
40    Dim bOK As Boolean
41
42    Out.Log("Prepearing test...")
43    for i = 0 to 5
44        for j = 0 to 5
45            oObj.getCellByPosition(j, i).Value = i * 6 + j
46        next j
47    next i
48
49    Test.StartMethod("insertCells()")
50    bOK = true
51    Dim newCellAddress As New com.sun.star.table.CellRangeAddress
52    newCellAddress.Sheet = 0
53    newCellAddress.StartColumn = 1
54    newCellAddress.StartRow = 1
55    newCellAddress.EndColumn = 1
56    newCellAddress.EndRow = 1
57    oObj.insertCells(newCellAddress, com.sun.star.sheet.CellInsertMode.DOWN)
58    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
59    bOK = bOK AND oObj.getCellByPosition(2, 2).Value = 14
60    bOK = bOK AND oObj.getCellByPosition(1, 2).Value = 7
61    bOK = bOK AND oObj.getCellByPosition(0, 2).Value = 12
62
63    oObj.insertCells(newCellAddress, com.sun.star.sheet.CellInsertMode.RIGHT)
64    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
65    bOK = bOK AND oObj.getCellByPosition(3, 0).Value = 3
66    bOK = bOK AND oObj.getCellByPosition(3, 1).Value = 8
67    bOK = bOK AND oObj.getCellByPosition(3, 2).Value = 15
68
69    oObj.insertCells(newCellAddress, com.sun.star.sheet.CellInsertMode.ROWS)
70    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
71    bOK = bOK AND oObj.getCellByPosition(4, 0).Value = 4
72    bOK = bOK AND oObj.getCellByPosition(4, 1).String = ""
73    bOK = bOK AND oObj.getCellByPosition(4, 2).Value = 9
74
75    oObj.insertCells(newCellAddress, com.sun.star.sheet.CellInsertMode.COLUMNS)
76    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
77    bOK = bOK AND oObj.getCellByPosition(0, 5).Value = 24
78    bOK = bOK AND oObj.getCellByPosition(1, 5).String = ""
79    bOK = bOK AND oObj.getCellByPosition(2, 5).Value = 19
80
81    Test.MethodTested("insertCells()", bOK)
82
83    Test.StartMethod("removeRange()")
84    bOK = true
85    oObj.removeRange(newCellAddress, com.sun.star.sheet.CellDeleteMode.ROWS)
86    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
87    bOK = bOK AND oObj.getCellByPosition(4, 0).Value = 3
88    bOK = bOK AND oObj.getCellByPosition(4, 1).Value = 8
89    bOK = bOK AND oObj.getCellByPosition(4, 2).Value = 15
90
91    oObj.removeRange(newCellAddress, com.sun.star.sheet.CellDeleteMode.COLUMNS)
92    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
93    bOK = bOK AND oObj.getCellByPosition(4, 0).Value = 4
94    bOK = bOK AND oObj.getCellByPosition(4, 1).Value = 9
95    bOK = bOK AND oObj.getCellByPosition(4, 2).Value = 16
96
97    oObj.removeRange(newCellAddress, com.sun.star.sheet.CellDeleteMode.UP)
98    bOK = bOK AND oObj.getCellByPosition(1, 1).Value = 7
99    bOK = bOK AND oObj.getCellByPosition(1, 2).Value = 13
100    bOK = bOK AND oObj.getCellByPosition(1, 3).Value = 19
101    bOK = bOK AND oObj.getCellByPosition(0, 3).Value = 18
102
103    oObj.removeRange(newCellAddress, com.sun.star.sheet.CellDeleteMode.LEFT)
104    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
105    bOK = bOK AND oObj.getCellByPosition(0, 1).Value = 6
106    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
107    bOK = bOK AND oObj.getCellByPosition(2, 1).Value = 8
108
109    Test.MethodTested("removeRange()", bOK)
110
111    Test.StartMethod("moveRange()")
112    bOK = true
113    newCellAddress.Sheet = 0
114    newCellAddress.StartColumn = 0
115    newCellAddress.StartRow = 0
116    newCellAddress.EndColumn = 1
117    newCellAddress.EndRow = 1
118    Dim sCell As New com.sun.star.table.CellAddress
119    sCell.Sheet = 0
120    sCell.Column = 3
121    sCell.Row = 3
122    oObj.moveRange(sCell, newCellAddress)
123
124    bOK = bOK AND oObj.getCellByPosition(0, 0).String = ""
125    bOK = bOK AND oObj.getCellByPosition(1, 0).String = ""
126    bOK = bOK AND oObj.getCellByPosition(0, 1).String = ""
127    bOK = bOK AND oObj.getCellByPosition(1, 1).String = ""
128
129    bOK = bOK AND oObj.getCellByPosition(3, 3).Value = 0
130    bOK = bOK AND oObj.getCellByPosition(3, 4).Value = 6
131    bOK = bOK AND oObj.getCellByPosition(4, 3).Value = 1
132    bOK = bOK AND oObj.getCellByPosition(4, 4).String = ""
133
134    Test.MethodTested("moveRange()", bOK)
135
136    Test.StartMethod("copyRange()")
137    bOK = true
138    newCellAddress.Sheet = 0
139    newCellAddress.StartColumn = 2
140    newCellAddress.StartRow = 2
141    newCellAddress.EndColumn = 3
142    newCellAddress.EndRow = 3
143    sCell.Sheet = 0
144    sCell.Column = 0
145    sCell.Row = 0
146
147    oObj.copyRange(sCell, newCellAddress)
148
149    bOK = bOK AND oObj.getCellByPosition(0, 0).Value = oObj.getCellByPosition(2, 2).Value
150    bOK = bOK AND oObj.getCellByPosition(0, 1).Value = oObj.getCellByPosition(2, 3).Value
151    bOK = bOK AND oObj.getCellByPosition(1, 0).Value = oObj.getCellByPosition(3, 2).Value
152    bOK = bOK AND oObj.getCellByPosition(1, 1).Value = oObj.getCellByPosition(3, 3).Value
153
154    Test.MethodTested("copyRange()", bOK)
155
156Exit Sub
157ErrHndl:
158    Test.Exception()
159    bOK = false
160    resume next
161End Sub
162</script:module>
163