1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir package ifc.sheet;
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir import helper.LoggingThread;
30*cdf0e10cSrcweir import lib.MultiMethodTest;
31*cdf0e10cSrcweir import lib.Status;
32*cdf0e10cSrcweir import lib.StatusException;
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir import com.sun.star.sheet.XCellSeries;
35*cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheet;
36*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
37*cdf0e10cSrcweir import share.LogWriter;
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir public class _XCellSeries extends MultiMethodTest {
41*cdf0e10cSrcweir     public XCellSeries oObj = null;
42*cdf0e10cSrcweir     protected XSpreadsheet oSheet = null;
43*cdf0e10cSrcweir     protected boolean isSpreadSheet = false;
44*cdf0e10cSrcweir     protected boolean fillAuto = true;
45*cdf0e10cSrcweir     protected boolean forceFillAuto = false;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir     protected void before() {
49*cdf0e10cSrcweir         oSheet = (XSpreadsheet) tEnv.getObjRelation("SHEET");
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir         if (oSheet == null) {
52*cdf0e10cSrcweir             log.println("Object relation oSheet is missing");
53*cdf0e10cSrcweir             log.println("Trying to query the needed Interface");
54*cdf0e10cSrcweir             oSheet = (XSpreadsheet) UnoRuntime.queryInterface(
55*cdf0e10cSrcweir                              XSpreadsheet.class, tEnv.getTestObject());
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir             if (oSheet == null) {
58*cdf0e10cSrcweir                 throw new StatusException(Status.failed(
59*cdf0e10cSrcweir                                                   "Object relation oSheet is missing"));
60*cdf0e10cSrcweir             } else {
61*cdf0e10cSrcweir                 isSpreadSheet = true;
62*cdf0e10cSrcweir             }
63*cdf0e10cSrcweir         }
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir         Boolean myFillAuto = (Boolean) tEnv.getObjRelation("XCELLSERIES_FILLAUTO");
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir         if (myFillAuto != null) fillAuto = myFillAuto.booleanValue();
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir         if (tParam.containsKey("force_fillauto")){
70*cdf0e10cSrcweir             fillAuto = tParam.getBool("force_fillauto");
71*cdf0e10cSrcweir             forceFillAuto = tParam.getBool("force_fillauto");
72*cdf0e10cSrcweir         }
73*cdf0e10cSrcweir     }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir     public void _fillAuto() {
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir         if ((isSpreadSheet && !forceFillAuto) || !fillAuto) {
78*cdf0e10cSrcweir             log.println("This method consumes to much time for a complete SpreadSheet");
79*cdf0e10cSrcweir             log.println("Please use parameter '-force_fillauto true' to force this test");
80*cdf0e10cSrcweir             tRes.tested("fillAuto()",Status.skipped(true));
81*cdf0e10cSrcweir             return;
82*cdf0e10cSrcweir         }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir         boolean res = true;
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir         try {
87*cdf0e10cSrcweir             oSheet.getCellByPosition(0, 0).setValue(2);
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir             log.println(
90*cdf0e10cSrcweir                     "calling oObj.fillAuto(com.sun.star.sheet.FillDirection.TO_RIGHT, 1)");
91*cdf0e10cSrcweir             oObj.fillAuto(com.sun.star.sheet.FillDirection.TO_RIGHT, 1);
92*cdf0e10cSrcweir             oSheet.getCellByPosition(0, 4).setFormula("=sum(A1:D1)");
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir             double getting = oSheet.getCellByPosition(0, 4).getValue();
95*cdf0e10cSrcweir             boolean locres = (getting == 14);
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir             if (!locres) {
98*cdf0e10cSrcweir                 log.println("Operation failed");
99*cdf0e10cSrcweir             } else {
100*cdf0e10cSrcweir                 log.println("Successful");
101*cdf0e10cSrcweir             }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir             res &= locres;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir             log.println(
106*cdf0e10cSrcweir                     "calling oObj.fillAuto(com.sun.star.sheet.FillDirection.TO_BOTTOM, 1)");
107*cdf0e10cSrcweir             oObj.fillAuto(com.sun.star.sheet.FillDirection.TO_BOTTOM, 1);
108*cdf0e10cSrcweir             oSheet.getCellByPosition(4, 0).setFormula("=sum(A1:A4)");
109*cdf0e10cSrcweir             getting = oSheet.getCellByPosition(4, 0).getValue();
110*cdf0e10cSrcweir             locres = (getting == 14);
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir             if (!locres) {
113*cdf0e10cSrcweir                 log.println("Operation failed");
114*cdf0e10cSrcweir             } else {
115*cdf0e10cSrcweir                 log.println("Successful");
116*cdf0e10cSrcweir             }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir             res &= locres;
119*cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
120*cdf0e10cSrcweir             log.println("Couldn't set initial version to cell");
121*cdf0e10cSrcweir             res = false;
122*cdf0e10cSrcweir         }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir         tRes.tested("fillAuto()", res);
125*cdf0e10cSrcweir     }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir     public void _fillSeries() {
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir         if (isSpreadSheet) {
130*cdf0e10cSrcweir             log.println("This method consumes to much time for a complete SpreadSheet");
131*cdf0e10cSrcweir             tRes.tested("fillSeries()",Status.skipped(true));
132*cdf0e10cSrcweir             return;
133*cdf0e10cSrcweir         }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir         boolean res = true;
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir         try {
138*cdf0e10cSrcweir             oSheet.getCellByPosition(0, 0).setValue(2);
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir             LoggingThread logger = new LoggingThread((LogWriter)log, tParam);
141*cdf0e10cSrcweir             logger.start();
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir             log.println(
144*cdf0e10cSrcweir                     "calling oObj.fillSeries(com.sun.star.sheet.FillDirection.TO_RIGHT, com.sun.star.sheet.FillMode.LINEAR, com.sun.star.sheet.FillDateMode.FILL_DATE_DAY, 2, 8)");
145*cdf0e10cSrcweir             oObj.fillSeries(com.sun.star.sheet.FillDirection.TO_RIGHT,
146*cdf0e10cSrcweir                             com.sun.star.sheet.FillMode.LINEAR,
147*cdf0e10cSrcweir                             com.sun.star.sheet.FillDateMode.FILL_DATE_DAY, 2, 8);
148*cdf0e10cSrcweir             oSheet.getCellByPosition(0, 4).setFormula("=sum(A1:D1)");
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir             double getting = oSheet.getCellByPosition(0, 4).getValue();
151*cdf0e10cSrcweir             boolean locres = (getting == 20);
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir             logger.finish();
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir             if (!locres) {
156*cdf0e10cSrcweir                 log.println("Operation failed");
157*cdf0e10cSrcweir             } else {
158*cdf0e10cSrcweir                 log.println("Successful");
159*cdf0e10cSrcweir             }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir             res &= locres;
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir             logger = new LoggingThread((LogWriter)log, tParam);
164*cdf0e10cSrcweir             logger.start();
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir             log.println(
167*cdf0e10cSrcweir                     "calling oObj.fillSeries(com.sun.star.sheet.FillDirection.TO_RIGHT, com.sun.star.sheet.FillMode.GROWTH, com.sun.star.sheet.FillDateMode.FILL_DATE_DAY, 2, 16)");
168*cdf0e10cSrcweir             oObj.fillSeries(com.sun.star.sheet.FillDirection.TO_RIGHT,
169*cdf0e10cSrcweir                             com.sun.star.sheet.FillMode.GROWTH,
170*cdf0e10cSrcweir                             com.sun.star.sheet.FillDateMode.FILL_DATE_DAY, 2,
171*cdf0e10cSrcweir                             16);
172*cdf0e10cSrcweir             oSheet.getCellByPosition(0, 4).setFormula("=sum(A1:D1)");
173*cdf0e10cSrcweir             getting = oSheet.getCellByPosition(0, 4).getValue();
174*cdf0e10cSrcweir             locres = (getting == 30);
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir             logger.finish();
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir             if (!locres) {
179*cdf0e10cSrcweir                 log.println("Operation failed");
180*cdf0e10cSrcweir             } else {
181*cdf0e10cSrcweir                 log.println("Successful");
182*cdf0e10cSrcweir             }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir             res &= locres;
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir             logger = new LoggingThread((LogWriter)log, tParam);
187*cdf0e10cSrcweir             logger.start();
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir             log.println(
190*cdf0e10cSrcweir                     "calling oObj.fillSeries(com.sun.star.sheet.FillDirection.TO_BOTTOM, com.sun.star.sheet.FillMode.LINEAR, com.sun.star.sheet.FillDateMode.FILL_DATE_DAY, 2, 8)");
191*cdf0e10cSrcweir             oObj.fillSeries(com.sun.star.sheet.FillDirection.TO_BOTTOM,
192*cdf0e10cSrcweir                             com.sun.star.sheet.FillMode.LINEAR,
193*cdf0e10cSrcweir                             com.sun.star.sheet.FillDateMode.FILL_DATE_DAY, 2, 8);
194*cdf0e10cSrcweir             oSheet.getCellByPosition(4, 0).setFormula("=sum(A1:A4)");
195*cdf0e10cSrcweir             getting = oSheet.getCellByPosition(4, 0).getValue();
196*cdf0e10cSrcweir             locres = (getting == 20);
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir             logger.finish();
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir             if (!locres) {
201*cdf0e10cSrcweir                 log.println("Operation failed");
202*cdf0e10cSrcweir             } else {
203*cdf0e10cSrcweir                 log.println("Successful");
204*cdf0e10cSrcweir             }
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir             res &= locres;
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir             logger = new LoggingThread((LogWriter)log, tParam);
209*cdf0e10cSrcweir             logger.start();
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir             log.println(
212*cdf0e10cSrcweir                     "calling oObj.fillSeries(com.sun.star.sheet.FillDirection.TO_BOTTOM, com.sun.star.sheet.FillMode.GROWTH, com.sun.star.sheet.FillDateMode.FILL_DATE_DAY, 2, 16)");
213*cdf0e10cSrcweir             oObj.fillSeries(com.sun.star.sheet.FillDirection.TO_BOTTOM,
214*cdf0e10cSrcweir                             com.sun.star.sheet.FillMode.GROWTH,
215*cdf0e10cSrcweir                             com.sun.star.sheet.FillDateMode.FILL_DATE_DAY, 2,
216*cdf0e10cSrcweir                             16);
217*cdf0e10cSrcweir             oSheet.getCellByPosition(4, 0).setFormula("=sum(A1:A4)");
218*cdf0e10cSrcweir             getting = oSheet.getCellByPosition(4, 0).getValue();
219*cdf0e10cSrcweir             locres = (getting == 30);
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir             logger.finish();
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir             if (!locres) {
224*cdf0e10cSrcweir                 log.println("Operation failed");
225*cdf0e10cSrcweir             } else {
226*cdf0e10cSrcweir                 log.println("Successful");
227*cdf0e10cSrcweir             }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir             res &= locres;
230*cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
231*cdf0e10cSrcweir             log.println("Couldn't set initial version to cell");
232*cdf0e10cSrcweir             res = false;
233*cdf0e10cSrcweir         }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir         tRes.tested("fillSeries()", res);
236*cdf0e10cSrcweir     }
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir     /**
239*cdf0e10cSrcweir     * Forces environment recreation.
240*cdf0e10cSrcweir     */
241*cdf0e10cSrcweir     public void after() {
242*cdf0e10cSrcweir         disposeEnvironment();
243*cdf0e10cSrcweir     }
244*cdf0e10cSrcweir }