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 com.sun.star.sheet.XPrintAreas;
30 import com.sun.star.table.CellRangeAddress;
31 import lib.MultiMethodTest;
32 import lib.Status;
33 import lib.StatusException;
34 import util.ValueComparer;
35 
36 /**
37  *
38  */
39 public class _XPrintAreas extends MultiMethodTest {
40     public XPrintAreas oObj = null;
41     CellRangeAddress address = null;
42     CellRangeAddress subaddress = null;
43     CellRangeAddress titleColumns;
44     CellRangeAddress titleRows;
45 
46     public void before() {
47         address = (CellRangeAddress)tEnv.getObjRelation("CellRangeAddress");
48         subaddress = (CellRangeAddress)tEnv.getObjRelation("CellRangeSubAddress");
49         if (address == null)
50             throw new StatusException(Status.failed("Object relation CellRangeAddress not found"));
51         if (subaddress == null)
52             throw new StatusException(Status.failed("Object relation CellRangeSubAddress not found"));
53     }
54 
55     public void _getPrintAreas() {
56         requiredMethod("getPrintTitleColumns()");
57         requiredMethod("getPrintTitleRows()");
58         executeMethod("getTitleColumns()");
59         executeMethod("getTitleRows()");
60         CellRangeAddress[] printAreas = oObj.getPrintAreas();
61         CellRangeAddress[] setValue = new CellRangeAddress[]{address};
62         boolean ret = ValueComparer.equalValue(printAreas, setValue);
63         // delete the print area
64         oObj.setPrintAreas(null);
65         printAreas = oObj.getPrintAreas();
66         ret &= printAreas.length == 0;
67 
68 		tRes.tested("getPrintAreas()", ret);
69 	}
70 
71 	public void _getPrintTitleColumns() {
72         requiredMethod("setPrintTitleColumns()");
73         tRes.tested("getPrintTitleColumns()", !oObj.getPrintTitleColumns());
74     }
75 
76     public void _getPrintTitleRows() {
77         requiredMethod("setPrintTitleRows()");
78         tRes.tested("getPrintTitleRows()", !oObj.getPrintTitleRows());
79     }
80 
81     public void _getTitleColumns() {
82         requiredMethod("setTitleColumns()");
83         CellRangeAddress setValue = oObj.getTitleColumns();
84         tRes.tested("getTitleColumns()", ValueComparer.equalValue(setValue,titleColumns));
85     }
86 
87     public void _getTitleRows() {
88         requiredMethod("setTitleRows()");
89         CellRangeAddress setValue = oObj.getTitleRows();
90         tRes.tested("getTitleRows()", ValueComparer.equalValue(setValue,titleRows));
91     }
92 
93     public void _setPrintAreas() {
94         boolean ret = false;
95         CellRangeAddress[]setValue = new CellRangeAddress[]{subaddress};
96         oObj.setPrintAreas(setValue);
97         CellRangeAddress[]newVal = oObj.getPrintAreas();
98         ret = ValueComparer.equalValue(newVal, setValue);
99         setValue = new CellRangeAddress[]{address};
100         oObj.setPrintAreas(setValue);
101         newVal = oObj.getPrintAreas();
102         ret &= ValueComparer.equalValue(newVal, setValue);
103         tRes.tested("setPrintAreas()", ret);
104     }
105 
106     public void _setPrintTitleColumns() {
107         requiredMethod("setTitleColumns()");
108         boolean ret = false;
109         boolean value = oObj.getPrintTitleColumns();
110         oObj.setPrintTitleColumns(!value);
111         ret = value != oObj.getPrintTitleColumns();
112         oObj.setPrintTitleColumns(false);
113         tRes.tested("setPrintTitleColumns()", ret);
114     }
115 
116     public void _setPrintTitleRows() {
117         requiredMethod("setTitleRows()");
118         boolean ret = false;
119         boolean value = oObj.getPrintTitleRows();
120         oObj.setPrintTitleRows(!value);
121         ret = value != oObj.getPrintTitleRows();
122         oObj.setPrintTitleRows(false);
123         tRes.tested("setPrintTitleRows()", ret);
124     }
125 
126     public void _setTitleColumns() {
127         requiredMethod("setPrintAreas()");
128         boolean ret = false;
129         CellRangeAddress newVal = oObj.getTitleColumns();
130         ret = ValueComparer.equalValue(newVal, new CellRangeAddress((short)0, 0, 0, 0, 0));
131         // use first row of range as title column
132         titleColumns = new CellRangeAddress();
133         titleColumns.Sheet = address.Sheet;
134         titleColumns.StartColumn = address.StartColumn;
135         titleColumns.StartRow = address.StartRow;
136         titleColumns.EndColumn = address.EndColumn;
137         titleColumns.EndRow = address.StartRow;
138         oObj.setTitleColumns(titleColumns);
139         tRes.tested("setTitleColumns()", ret);
140     }
141 
142     public void _setTitleRows() {
143         requiredMethod("setPrintAreas()");
144         boolean ret = false;
145         CellRangeAddress newVal = oObj.getTitleRows();
146         ret = ValueComparer.equalValue(newVal, new CellRangeAddress((short)0, 0, 0, 0, 0));
147         // use first column of range as title row
148         titleRows = new CellRangeAddress();
149         titleRows.Sheet = address.Sheet;
150         titleRows.StartColumn = address.StartColumn;
151         titleRows.StartRow = address.StartRow;
152         titleRows.EndColumn = address.StartColumn;
153         titleRows.EndRow = address.EndRow;
154         oObj.setTitleColumns(titleRows);
155         tRes.tested("setTitleRows()", ret);
156     }
157 
158 }
159