/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*************************************************************/
package complex.dataPilot;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XIndexAccess;
import com.sun.star.container.XNamed;
import com.sun.star.sheet.DataPilotFieldOrientation;
import com.sun.star.sheet.XDataPilotDescriptor;
import com.sun.star.table.CellRangeAddress;
import com.sun.star.uno.UnoRuntime;
// import lib.MultiMethodTest;
// import lib.Status;
//import lib.StatusException;
import lib.TestParameters;
// import share.LogWriter;
/**
* Testing com.sun.star.sheet.XDataPilotDescriptor
* interface methods :
*
getTag()
setTag()
getSourceRange()
setSourceRange()
getFilterDescriptor()
getDataPilotFields()
getColumnFields()
getRowFields()
getPageFields()
getDataFields()
getHiddenFields()
* This test needs the following object relations : *
'FIELDSAMOUNT'
(of type Integer
):
* to have number of fields
* @see com.sun.star.sheet.XDataPilotDescriptor
*/
public class _XDataPilotDescriptor {
public XDataPilotDescriptor oObj = null;
CellRangeAddress CRA = new CellRangeAddress((short)1, 0, 0, 5, 5);
CellRangeAddress oldCRA = null ;
String sTag = new String ("XDataPilotDescriptor_Tag");
String fieldsNames[];
int fieldsAmount = 0;
int tEnvFieldsAmount = 0;
/**
* The test parameters
*/
private TestParameters param = null;
/**
* The log writer
*/
// private LogWriter log = null;
/**
* Constructor: gets the object to test, a logger and the test parameters
* @param xObj The test object
* @param param The test parameters
*/
public _XDataPilotDescriptor(XDataPilotDescriptor xObj/*,
LogWriter log*/, TestParameters param) {
oObj = xObj;
// this.log = log;
this.param = param;
}
/**
* Retrieves object relations.
* @return
*/
public boolean before() {
Integer amount = (Integer)param.get("FIELDSAMOUNT");
if (amount == null) {
System.out.println("Relation 'FIELDSAMOUNT' not found");
return false;
}
tEnvFieldsAmount = amount.intValue();
return true;
}
/**
* Test calls the method and compares returned value with value that was set
* in method setSourceRange()
.
* Has OK status if all fields of cell range addresses are equal.
* The following method tests are to be completed successfully before : *
setSourceRange()
: to have current source range * Has OK status if the method successfully returns.
* The following method tests are to be executed before : *
getColumnFields()
getRowFields()
getDataFields()
getHiddenFields()
getPageFields()
setTag()
.
* Has OK status if returned value is equal to value that was set
* by method setTag()
.
* The following method tests are to be completed successfully before : *
setTag()
: to have current tag * Has OK status if the method successfully returns.
* @return
*/
public boolean _setTag(){
oObj.setTag(sTag);
return true;
}
/**
* Test calls the method , checks returned value, compares
* number of fields goten from returned value and obtained by object
* relation 'FIELDSAMOUNT'
and set property
* Orientation
to one of DataPilotFieldOrientation values.
* Has OK status if returned value isn't null, number of fields * goten from returned value is less than number of fields obtained by relation * and no exceptions were thrown.
* @return
*/
public boolean _getDataPilotFields(){
boolean bResult = true;
XIndexAccess IA = null;
IA = oObj.getDataPilotFields();
if (IA == null) {
System.out.println("Returned value is null.");
return false;
} else {System.out.println("getDataPilotFields returned not Null value -- OK");}
fieldsAmount = IA.getCount();
if (fieldsAmount < tEnvFieldsAmount) {
System.out.println("Number of fields is less than number goten by relation.");
return false;
} else {System.out.println("count of returned fields -- OK");}
fieldsNames = new String[tEnvFieldsAmount];
int i = -1 ;
int cnt = 0 ;
while (++i < fieldsAmount) {
Object field;
try {
field = IA.getByIndex(i);
} catch(com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace();
return false;
} catch(com.sun.star.lang.IndexOutOfBoundsException e) {
e.printStackTrace();
return false;
}
XNamed named = UnoRuntime.queryInterface(XNamed.class, field);
String name = named.getName();
System.out.println("Field : '" + name + "' ... ") ;
if (!name.equals("Data")) {
fieldsNames[cnt] = name ;
XPropertySet props =
UnoRuntime.queryInterface(XPropertySet.class, field);
try {
switch (cnt % 5) {
case 0 :
props.setPropertyValue("Orientation",
DataPilotFieldOrientation.COLUMN);
System.out.println(" Column") ;
break;
case 1 :
props.setPropertyValue("Orientation",
DataPilotFieldOrientation.ROW);
System.out.println(" Row") ;
break;
case 2 :
props.setPropertyValue("Orientation",
DataPilotFieldOrientation.DATA);
System.out.println(" Data") ;
break;
case 3 :
props.setPropertyValue("Orientation",
DataPilotFieldOrientation.HIDDEN);
System.out.println(" Hidden") ;
break;
case 4 :
props.setPropertyValue("Orientation",
DataPilotFieldOrientation.PAGE);
System.out.println(" Page") ;
props.setPropertyValue("CurrentPage", "20");
break;
} } catch (com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace();
return false;
} catch (com.sun.star.lang.IllegalArgumentException e) {
e.printStackTrace();
return false;
} catch (com.sun.star.beans.PropertyVetoException e) {
e.printStackTrace();
return false;
} catch (com.sun.star.beans.UnknownPropertyException e) {
e.printStackTrace();
return false;
}
if (++cnt > 4)
{
break;
}
}
else
{
return false;
}
}
return bResult;
}
/**
* Test calls the method and checks returned collection using the method
* CheckNames()
.
* Has OK status if the method CheckNames()
returns true
* and no exceptions were thrown.
* The following method tests are to be completed successfully before : *
getDataPilotFields()
: to have array of field names CheckNames()
.
* Has OK status if the method CheckNames()
returned true
* and no exceptions were thrown.
* The following method tests are to be completed successfully before : *
getDataPilotFields()
: to have array of field names CheckNames()
.
* Has OK status if the method CheckNames()
returned true
* and no exceptions were thrown.
* The following method tests are to be completed successfully before : *
getDataPilotFields()
: to have array of field names CheckNames()
.
* Has OK status if the method CheckNames()
returned true
* and no exceptions were thrown.
* The following method tests are to be completed successfully before : *
getDataPilotFields()
: to have array of field names * The following method tests are to be completed successfully before : *
getDataPilotFields()
: to have array of field names * Has OK status if returned value isn't null * and no exceptions were thrown.
* @return
*/
public boolean _getFilterDescriptor(){
boolean bResult = oObj.getFilterDescriptor() != null;
return bResult;
}
/**
* Method checks that the field with index rem
exists
* in the array IA
.
* @param IA collection of elements that support interface XNamed
* @param rem index of field in the array of field names that was stored in
* the method getDataPilotFields()
* @return true if required field name exists in passed collection;
* false otherwise
* @see com.sun.star.container.XNamed
*/
private boolean CheckNames(XIndexAccess IA, int rem) {
String name = null;
if (IA == null) {
System.out.println("Null retruned.") ;
return false ;
}
if (fieldsNames[rem] == null) {
System.out.println("No fields were set to this orientation - cann't check result") ;
return true ;
}
if (IA.getCount() == 0) {
System.out.println("No fields found. Must be at least '"
+ fieldsNames[rem] + "'") ;
return false ;
}
try {
System.out.println("Fields returned ") ;
for (int i = 0; i < IA.getCount(); i++) {
Object field = IA.getByIndex(i);
XNamed named = UnoRuntime.queryInterface
(XNamed.class, field);
name = named.getName();
System.out.println(" " + name) ;
if (fieldsNames[rem].equals(name)) {
System.out.println(" - OK") ;
return true ;
}
}
} catch (com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace();
return false ;
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
e.printStackTrace();
return false ;
}
System.out.println(" - FAILED (field " + fieldsNames[rem] + " was not found.") ;
return false ;
}
/**
* Recreates object(to back old orientations of the fields).
*
protected void after() {
disposeEnvironment();
}*/
}