Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAnnotationTextCursor.java
blob81ff087ff5b1d71c3ee9d6493d15ea23ec3ce7b7
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 .
19 package mod._sc;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.container.XIndexAccess;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.sheet.XSheetAnnotation;
32 import com.sun.star.sheet.XSheetAnnotationAnchor;
33 import com.sun.star.sheet.XSpreadsheet;
34 import com.sun.star.sheet.XSpreadsheetDocument;
35 import com.sun.star.sheet.XSpreadsheets;
36 import com.sun.star.table.CellAddress;
37 import com.sun.star.table.XCell;
38 import com.sun.star.table.XCellRange;
39 import com.sun.star.text.XSimpleText;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
44 /**
46 * initial description
47 * @see com.sun.star.beans.XPropertySet
48 * @see com.sun.star.beans.XPropertyState
49 * @see com.sun.star.document.XDocumentInsertable
50 * @see com.sun.star.style.CharacterProperties
51 * @see com.sun.star.style.ParagraphProperties
52 * @see com.sun.star.text.XParagraphCursor
53 * @see com.sun.star.text.XSentenceCursor
54 * @see com.sun.star.text.XTextCursor
55 * @see com.sun.star.text.XTextRange
56 * @see com.sun.star.text.XWordCursor
57 * @see com.sun.star.util.XSortable
60 public class ScAnnotationTextCursor extends TestCase {
62 private XSpreadsheetDocument xSheetDoc = null;
64 @Override
65 protected void initialize( TestParameters tParam, PrintWriter log ) {
66 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
68 try {
69 log.println( "creating a Spreadsheet document" );
70 xSheetDoc = SOF.createCalcDoc(null);
71 } catch ( com.sun.star.uno.Exception e ) {
72 // Some exception occurs.FAILED
73 e.printStackTrace( log );
74 throw new StatusException( "Couldn't create document", e );
79 @Override
80 protected void cleanup( TestParameters tParam, PrintWriter log ) {
81 log.println( " disposing xSheetDoc " );
82 XComponent oComp = UnoRuntime.queryInterface
83 (XComponent.class, xSheetDoc) ;
84 util.DesktopTools.closeDoc(oComp);
88 /**
89 * creating a Testenvironment for the interfaces to be tested
91 @Override
92 public synchronized TestEnvironment createTestEnvironment
93 ( TestParameters Param, PrintWriter log )
94 throws StatusException {
96 XInterface oObj = null;
98 // creation of testobject here
99 // first we write what we are intend to do to log file
100 log.println( "Creating a test environment" );
102 CellAddress cellPos = new CellAddress((short)0, 1, 2);
104 try {
105 log.println("Getting test object ") ;
107 XSpreadsheetDocument xArea = UnoRuntime.queryInterface(XSpreadsheetDocument.class, xSheetDoc);
109 XSpreadsheets oSheets = xArea.getSheets();
111 XIndexAccess XAccess = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
113 XSpreadsheet oSheet = (XSpreadsheet)XAccess.getByIndex(cellPos.Sheet);
115 XCellRange oCRange = UnoRuntime.queryInterface(XCellRange.class, oSheet);
117 XCell oCell = oCRange.getCellByPosition(cellPos.Column, cellPos.Row);
119 XSheetAnnotationAnchor oAnnoA = UnoRuntime.queryInterface(XSheetAnnotationAnchor.class, oCell);
121 XSheetAnnotation oAnno = oAnnoA.getAnnotation();
122 XSimpleText aText = UnoRuntime.queryInterface(XSimpleText.class,oAnno);
123 aText.setString("A nice little Test");
124 oObj = aText.createTextCursor();
126 } catch (Exception e) {
127 e.printStackTrace(log) ;
128 throw new StatusException(
129 "Error getting test object from spreadsheet document",e) ;
132 TestEnvironment tEnv = new TestEnvironment( oObj );
134 // Other parameters required for interface tests
136 return tEnv;
139 } // finish class ScAnnotationTextCursor