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