merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwXTextTables.java
blobe5591aafc99f18629951de378b769bfe075d293f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXTextTables.java,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sw;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.text.XTextTable;
44 import com.sun.star.text.XTextTablesSupplier;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
48 /**
50 * initial description
51 * @see com.sun.star.container.XElementAccess
52 * @see com.sun.star.container.XIndexAccess
53 * @see com.sun.star.container.XNameAccess
56 public class SwXTextTables extends TestCase {
57 XTextDocument xTextDoc;
59 protected void initialize( TestParameters tParam, PrintWriter log ) {
60 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
62 try {
63 log.println( "creating a textdocument" );
64 xTextDoc = SOF.createTextDoc( null );
65 } catch ( com.sun.star.uno.Exception e ) {
66 // Some exception occures.FAILED
67 e.printStackTrace( log );
68 throw new StatusException( "Couldn't create document", e );
72 protected void cleanup( TestParameters tParam, PrintWriter log ) {
73 log.println( " disposing xTextDoc " );
74 util.DesktopTools.closeDoc(xTextDoc);
78 /**
79 * creating a Testenvironment for the interfaces to be tested
81 * @param tParam class which contains additional test parameters
82 * @param log class to log the test state and result
84 * @return Status class
86 * @see TestParameters
87 * @see PrintWriter
89 public synchronized TestEnvironment createTestEnvironment
90 (TestParameters tParam, PrintWriter log) {
92 XInterface oObj = null;
93 int nRow = 4;
94 int nCol = 5;
97 // creation of testobject here
98 // first we write what we are intend to do to log file
99 log.println( "creating a test environment" );
101 // get a soffice factory object
102 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
104 // create testobject here
105 TestEnvironment tEnv = null;
106 XTextTable oTable = null;
107 try {
108 oTable = SOF.createTextTable( xTextDoc );
109 SOF.insertTextContent(xTextDoc, oTable );
111 catch( Exception uE ) {
112 uE.printStackTrace( log );
113 throw new StatusException("Couldn't create TextTable : "
114 + uE.getMessage(), uE);
117 // Number two
118 XTextTable oTable2 = null;
119 try {
120 oTable2 = SOF.createTextTable( xTextDoc );
121 SOF.insertTextContent(xTextDoc, oTable2 );
123 catch( Exception uE ) {
124 uE.printStackTrace( log );
125 throw new StatusException("Couldn't create TextTable two: "
126 + uE.getMessage(), uE);
129 XMultiServiceFactory msf = (XMultiServiceFactory)
130 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
131 XTextTablesSupplier oTTSupp = (XTextTablesSupplier)
132 UnoRuntime.queryInterface(XTextTablesSupplier.class, msf);
133 oObj = oTTSupp.getTextTables();
135 if ( oTable != null ) {
136 log.println("Creating instance...");
137 tEnv = new TestEnvironment(oObj);
140 log.println( "adding TextDocument as mod relation to environment" );
141 tEnv.addObjRelation( "TEXTDOC", xTextDoc );
142 tEnv.addObjRelation( "ROW", new Integer( nRow ) );
143 tEnv.addObjRelation( "COL", new Integer( nCol ) );
144 try {
145 tEnv.addObjRelation( "INST", SOF.createTextTable( xTextDoc ));
147 catch( Exception uE ) {
148 uE.printStackTrace( log );
149 throw new StatusException("Couldn't create TextTable : "
150 + uE.getMessage(), uE);
153 return tEnv;
154 } // finish method getTestEnvironment
156 } // finish class SwXTextTables