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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.lang
.XMultiServiceFactory
;
30 import com
.sun
.star
.text
.XTextDocument
;
31 import com
.sun
.star
.text
.XTextTable
;
32 import com
.sun
.star
.text
.XTextTablesSupplier
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.uno
.XInterface
;
39 * @see com.sun.star.container.XElementAccess
40 * @see com.sun.star.container.XIndexAccess
41 * @see com.sun.star.container.XNameAccess
44 public class SwXTextTables
extends TestCase
{
45 XTextDocument xTextDoc
;
47 protected void initialize( TestParameters tParam
, PrintWriter log
) {
48 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
51 log
.println( "creating a textdocument" );
52 xTextDoc
= SOF
.createTextDoc( null );
53 } catch ( com
.sun
.star
.uno
.Exception e
) {
54 // Some exception occurs.FAILED
55 e
.printStackTrace( log
);
56 throw new StatusException( "Couldn't create document", e
);
60 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
61 log
.println( " disposing xTextDoc " );
62 util
.DesktopTools
.closeDoc(xTextDoc
);
67 * creating a Testenvironment for the interfaces to be tested
69 * @param tParam class which contains additional test parameters
70 * @param log class to log the test state and result
72 * @return Status class
77 public synchronized TestEnvironment createTestEnvironment
78 (TestParameters tParam
, PrintWriter log
) {
80 XInterface oObj
= null;
85 // creation of testobject here
86 // first we write what we are intend to do to log file
87 log
.println( "creating a test environment" );
89 // get a soffice factory object
90 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
92 // create testobject here
93 TestEnvironment tEnv
= null;
94 XTextTable oTable
= null;
96 oTable
= SOfficeFactory
.createTextTable( xTextDoc
);
97 SOfficeFactory
.insertTextContent(xTextDoc
, oTable
);
99 catch( Exception uE
) {
100 uE
.printStackTrace( log
);
101 throw new StatusException("Couldn't create TextTable : "
102 + uE
.getMessage(), uE
);
106 XTextTable oTable2
= null;
108 oTable2
= SOfficeFactory
.createTextTable( xTextDoc
);
109 SOfficeFactory
.insertTextContent(xTextDoc
, oTable2
);
111 catch( Exception uE
) {
112 uE
.printStackTrace( log
);
113 throw new StatusException("Couldn't create TextTable two: "
114 + uE
.getMessage(), uE
);
117 XMultiServiceFactory msf
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
118 XTextTablesSupplier oTTSupp
= UnoRuntime
.queryInterface(XTextTablesSupplier
.class, msf
);
119 oObj
= oTTSupp
.getTextTables();
121 if ( oTable
!= null ) {
122 log
.println("Creating instance...");
123 tEnv
= new TestEnvironment(oObj
);
126 log
.println( "adding TextDocument as mod relation to environment" );
127 tEnv
.addObjRelation( "TEXTDOC", xTextDoc
);
128 tEnv
.addObjRelation( "ROW", new Integer( nRow
) );
129 tEnv
.addObjRelation( "COL", new Integer( nCol
) );
131 tEnv
.addObjRelation( "INST", SOfficeFactory
.createTextTable( xTextDoc
));
133 catch( Exception uE
) {
134 uE
.printStackTrace( log
);
135 throw new StatusException("Couldn't create TextTable : "
136 + uE
.getMessage(), uE
);
140 } // finish method getTestEnvironment
142 } // finish class SwXTextTables