* @see com.sun.star.sheet.XSpreadsheet
*/
protected TestEnvironment createTestEnvironment(TestParameters Param,
PrintWriter log) {
XInterface oObj = null;
XCellRange testRange;
// creation of testobject here
// first we write what we are intend to do to log file
log.println("Creating a test environment");
XSpreadsheets oSpreadsheets = ((XSpreadsheetDocument) UnoRuntime.queryInterface(
XSpreadsheetDocument.class,
xSheetDoc)).getSheets();
XNameAccess oNames = (XNameAccess) UnoRuntime.queryInterface(
XNameAccess.class, oSpreadsheets);
XSpreadsheet oSheet = null;
try {
oSheet = (XSpreadsheet) AnyConverter.toObject(
new Type(XSpreadsheet.class),
oNames.getByName(oNames.getElementNames()[0]));
oObj = oSheet.getCellRangeByPosition(0, 0, 3, 4);
testRange = (XCellRange) UnoRuntime.queryInterface(
XCellRange.class, oObj);
} catch (com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace(log);
throw new StatusException(
"Error getting cell object from spreadsheet document", e);
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
e.printStackTrace(log);
throw new StatusException(
"Error getting cell object from spreadsheet document", e);
} catch (com.sun.star.container.NoSuchElementException e) {
e.printStackTrace(log);
throw new StatusException(
"Error getting cell object from spreadsheet document", e);
} catch (com.sun.star.lang.IllegalArgumentException e) {
e.printStackTrace(log);
throw new StatusException(
"Error getting cell object from spreadsheet document", e);
}
TestEnvironment tEnv = new TestEnvironment(oObj);
tEnv.addObjRelation("SHEET", oSheet);
// add expected results for the XCellRangesQuery interface test
String[]expectedResults = new String[7];
expectedResults[_XCellRangesQuery.QUERYCOLUMNDIFFERENCES] = "Sheet1.B1:C1;Sheet1.B3";
expectedResults[_XCellRangesQuery.QUERYCONTENTCELLS] = "Sheet1.B2:B3";
expectedResults[_XCellRangesQuery.QUERYEMPTYCELLS] = "Sheet1.A1 ... Sheet1.B1 ... Sheet1.B5 ... Sheet1.C3 ... Sheet1.D1";
expectedResults[_XCellRangesQuery.QUERYFORMULACELLS] = "Sheet1.C2";
expectedResults[_XCellRangesQuery.QUERYINTERSECTION] = "Sheet1.D4";
expectedResults[_XCellRangesQuery.QUERYROWDIFFERENCES] = "Sheet1.A2:A4;Sheet1.C2:D4";
expectedResults[_XCellRangesQuery.QUERYVISIBLECELLS] = "Sheet1.A2";
tEnv.addObjRelation("XCellRangesQuery.EXPECTEDRESULTS", expectedResults);
tEnv.addObjRelation("XCellRangesQuery.CREATEENTRIES", Boolean.TRUE);
XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, oObj);
tEnv.addObjRelation("PropSet", PropSet);
// XSearchable: Add a cell to make a seacrchable entry
try {
tEnv.addObjRelation("XSearchable.MAKEENTRYINCELL", new XCell[] {
testRange.getCellByPosition(0,0), testRange.getCellByPosition(0,1)});
}
catch(com.sun.star.lang.IndexOutOfBoundsException e){
e.printStackTrace((PrintWriter)log);
log.println("Cannot make required object relation 'XSearchable.MAKEENTRYINCELL'.");
}
// XCellRangeData
/* Object[][] newData = new Object[5][4];
for (int i=0; i<newData.length; i++) {
for (int j=0; j<newData[i].length; j++) {
newData[i][j] = new Double(i*10+j);
}
}
tEnv.addObjRelation("NewData", newData); */
//Adding relation for util.XSortable
final PrintWriter finalLog = log;
final XCellRange oTable = testRange;
tEnv.addObjRelation("SORTCHECKER",
new ifc.util._XSortable.XSortChecker() {
PrintWriter out = finalLog;
public void setPrintWriter(PrintWriter log) {
out = log;
}
public void prepareToSort() {
try {
oTable.getCellByPosition(0, 0).setValue(4);
oTable.getCellByPosition(0, 1).setFormula("b");
oTable.getCellByPosition(0, 2).setValue(3);
oTable.getCellByPosition(0, 3).setValue(23);
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
out.println("Exception while checking sort");
}
}
public boolean checkSort(boolean isSortNumbering,
boolean isSortAscending) {
out.println("Sort checking...");
boolean res = false;
String[] value = new String[4];
for (int i = 0; i < 4; i++) {
try {
XCell cell = oTable.getCellByPosition(0, i);
value[i] = cell.getFormula();
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
out.println("Exception while checking sort");
}
}