xref: /AOO41X/main/qadevOOo/tests/java/mod/_sc/ScAnnotationTextCursor.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 
28 package mod._sc;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.SOfficeFactory;
37 
38 import com.sun.star.container.XIndexAccess;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.sheet.XSheetAnnotation;
42 import com.sun.star.sheet.XSheetAnnotationAnchor;
43 import com.sun.star.sheet.XSpreadsheet;
44 import com.sun.star.sheet.XSpreadsheetDocument;
45 import com.sun.star.sheet.XSpreadsheets;
46 import com.sun.star.table.CellAddress;
47 import com.sun.star.table.XCell;
48 import com.sun.star.table.XCellRange;
49 import com.sun.star.text.XSimpleText;
50 import com.sun.star.uno.UnoRuntime;
51 import com.sun.star.uno.XInterface;
52 
53 
54 /**
55  *
56  * initial description
57  * @see com.sun.star.beans.XPropertySet
58  * @see com.sun.star.beans.XPropertyState
59  * @see com.sun.star.document.XDocumentInsertable
60  * @see com.sun.star.style.CharacterProperties
61  * @see com.sun.star.style.ParagraphProperties
62  * @see com.sun.star.text.XParagraphCursor
63  * @see com.sun.star.text.XSentenceCursor
64  * @see com.sun.star.text.XTextCursor
65  * @see com.sun.star.text.XTextRange
66  * @see com.sun.star.text.XWordCursor
67  * @see com.sun.star.util.XSortable
68  *
69  */
70 public class ScAnnotationTextCursor extends TestCase {
71 
72     static XSpreadsheetDocument xSheetDoc = null;
73 
74     protected void initialize( TestParameters tParam, PrintWriter log ) {
75         SOfficeFactory SOF = SOfficeFactory.getFactory(  (XMultiServiceFactory) tParam.getMSF() );
76 
77         try {
78             log.println( "creating a Spreadsheet document" );
79             xSheetDoc = SOF.createCalcDoc(null);
80         } catch ( com.sun.star.uno.Exception e ) {
81             // Some exception occures.FAILED
82             e.printStackTrace( log );
83             throw new StatusException( "Couldn't create document", e );
84         }
85 
86     }
87 
88     protected void cleanup( TestParameters tParam, PrintWriter log ) {
89         log.println( "    disposing xSheetDoc " );
90         XComponent oComp = (XComponent) UnoRuntime.queryInterface
91             (XComponent.class, xSheetDoc) ;
92         util.DesktopTools.closeDoc(oComp);
93     }
94 
95 
96     /**
97      *    creating a Testenvironment for the interfaces to be tested
98      */
99     public synchronized TestEnvironment createTestEnvironment
100             ( TestParameters Param, PrintWriter log )
101             throws StatusException {
102 
103         XInterface oObj = null;
104 
105         // creation of testobject here
106         // first we write what we are intend to do to log file
107         log.println( "Creating a test environment" );
108 
109         CellAddress cellPos = new CellAddress((short)0, 1, 2);
110 
111         try {
112             log.println("Getting test object ") ;
113 
114             XSpreadsheetDocument xArea = (XSpreadsheetDocument)
115                 UnoRuntime.queryInterface(XSpreadsheetDocument.class, xSheetDoc);
116 
117             XSpreadsheets oSheets = (XSpreadsheets) xArea.getSheets();
118 
119             XIndexAccess XAccess = (XIndexAccess)
120                         UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
121 
122             XSpreadsheet oSheet = (XSpreadsheet)XAccess.getByIndex(cellPos.Sheet);
123 
124             XCellRange oCRange = (XCellRange)
125                             UnoRuntime.queryInterface(XCellRange.class, oSheet);
126 
127             XCell oCell = oCRange.getCellByPosition(cellPos.Column, cellPos.Row);
128 
129             XSheetAnnotationAnchor oAnnoA = (XSheetAnnotationAnchor)
130                 UnoRuntime.queryInterface(XSheetAnnotationAnchor.class, oCell);
131 
132             XSheetAnnotation oAnno = oAnnoA.getAnnotation();
133             XSimpleText aText = (XSimpleText)
134                             UnoRuntime.queryInterface(XSimpleText.class,oAnno);
135             aText.setString("A nice little Test");
136             oObj = aText.createTextCursor();
137 
138         } catch (Exception e) {
139             e.printStackTrace(log) ;
140             throw new StatusException(
141                     "Error getting test object from spreadsheet document",e) ;
142         }
143 
144         TestEnvironment tEnv = new TestEnvironment( oObj );
145 
146         // Other parameters required for interface tests
147 
148         return tEnv;
149     }
150 
151 }    // finish class ScAnnotationTextCursor
152 
153