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