bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScUniqueCellFormatsEnumeration.java
blobbc656322b9aa00eae7b5c25e7127c8de87e670c5
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package mod._sc;
20 import com.sun.star.beans.XPropertySet;
21 import com.sun.star.container.XEnumerationAccess;
22 import com.sun.star.container.XIndexAccess;
23 import com.sun.star.sheet.XSpreadsheet;
24 import com.sun.star.sheet.XSpreadsheetDocument;
25 import com.sun.star.sheet.XUniqueCellFormatRangesSupplier;
26 import com.sun.star.table.XCellRange;
27 import com.sun.star.uno.UnoRuntime;
28 import com.sun.star.uno.XInterface;
30 import java.awt.Color;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
39 import util.SOfficeFactory;
42 public class ScUniqueCellFormatsEnumeration extends TestCase {
43 private XSpreadsheetDocument xSheetDoc = null;
44 static XSpreadsheet oSheet = null;
46 /**
47 * Creates Spreadsheet document.
49 @Override
50 protected void initialize(TestParameters tParam, PrintWriter log) {
51 // get a soffice factory object
52 SOfficeFactory SOF = SOfficeFactory.getFactory(
53 tParam.getMSF());
55 try {
56 log.println("creating a sheetdocument");
57 xSheetDoc = SOF.createCalcDoc(null);
58 } catch (com.sun.star.uno.Exception e) {
59 // Some exception occurs.FAILED
60 e.printStackTrace(log);
61 throw new StatusException("Couldn't create document", e);
65 /**
66 * Disposes Spreadsheet document.
68 @Override
69 protected void cleanup(TestParameters tParam, PrintWriter log) {
70 util.DesktopTools.closeDoc(xSheetDoc);
73 @Override
74 protected TestEnvironment createTestEnvironment(TestParameters tParam,
75 PrintWriter log) {
76 log.println("Getting the first sheet");
78 XIndexAccess xIA = UnoRuntime.queryInterface(
79 XIndexAccess.class, xSheetDoc.getSheets());
81 try {
82 oSheet = UnoRuntime.queryInterface(
83 XSpreadsheet.class, xIA.getByIndex(0));
84 } catch (com.sun.star.lang.WrappedTargetException e) {
85 e.printStackTrace(log);
86 throw new StatusException("Couldn't get a spreadsheet", e);
87 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
88 e.printStackTrace(log);
89 throw new StatusException("Couldn't get a spreadsheet", e);
92 changeColor("A1:A5", 0, 255, 0);
93 changeColor("A6:B10", 255, 0, 0);
94 changeColor("B1:B6", 0, 0, 255);
95 changeColor("B7", 0, 255, 0);
96 changeColor("B8:B10", 0, 0, 255);
97 changeColor("C1:C10", 0, 0, 255);
98 changeColor("D1:D10", 0, 255, 0);
100 XUniqueCellFormatRangesSupplier xUCRS = UnoRuntime.queryInterface(
101 XUniqueCellFormatRangesSupplier.class,
102 oSheet);
104 XEnumerationAccess xEnum = UnoRuntime.queryInterface(
105 XEnumerationAccess.class,
106 xUCRS.getUniqueCellFormatRanges());
107 XInterface oObj = xEnum.createEnumeration();
108 log.println("Implementationname: " + util.utils.getImplName(oObj));
110 TestEnvironment tEnv = new TestEnvironment(oObj);
112 tEnv.addObjRelation("ExpectedCount", Integer.valueOf(4));
114 return tEnv;
117 protected void changeColor(String RangeName, int r, int g, int b) {
118 XCellRange xRange = oSheet.getCellRangeByName(RangeName);
119 XPropertySet xPropertySet = UnoRuntime.queryInterface(
120 XPropertySet.class, xRange);
121 Color c = new Color(r, g, b);
122 int c2int = 16777216 + c.hashCode();
124 try {
125 xPropertySet.setPropertyValue("CellBackColor", Integer.valueOf(c2int));
126 } catch (com.sun.star.beans.UnknownPropertyException e) {
127 log.println("Couldn't change CellFormat");
128 } catch (com.sun.star.beans.PropertyVetoException e) {
129 log.println("Couldn't change CellFormat");
130 } catch (com.sun.star.lang.IllegalArgumentException e) {
131 log.println("Couldn't change CellFormat");
132 } catch (com.sun.star.lang.WrappedTargetException e) {
133 log.println("Couldn't change CellFormat");