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