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
;
22 import java
.util
.Random
;
24 import lib
.StatusException
;
26 import lib
.TestEnvironment
;
27 import lib
.TestParameters
;
28 import util
.SOfficeFactory
;
30 import com
.sun
.star
.container
.XNameAccess
;
31 import com
.sun
.star
.lang
.XComponent
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
37 public class ScFunctionDescriptionObj
extends TestCase
{
38 private XSpreadsheetDocument xSheetDoc
= null;
41 protected void initialize( TestParameters tParam
, PrintWriter log
) {
42 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
45 log
.println( "creating a Spreadsheet document" );
46 xSheetDoc
= SOF
.createCalcDoc(null);
47 } catch ( com
.sun
.star
.uno
.Exception e
) {
48 // Some exception occurs.FAILED
49 e
.printStackTrace( log
);
50 throw new StatusException( "Couldn't create document", e
);
56 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
57 log
.println( " disposing xSheetDoc " );
58 XComponent oComp
= UnoRuntime
.
59 queryInterface (XComponent
.class, xSheetDoc
) ;
60 util
.DesktopTools
.closeDoc(oComp
);
65 * creating a Testenvironment for the interfaces to be tested
68 public synchronized TestEnvironment
createTestEnvironment(
69 TestParameters Param
, PrintWriter log
)
70 throws StatusException
{
72 XInterface oObj
= null;
74 // creation of testobject here
75 // first we write what we are intend to do to log file
76 log
.println( "Creating a test environment" );
79 log
.println("Getting test object ") ;
81 XMultiServiceFactory oDocMSF
= Param
.getMSF();
83 XInterface FDs
= (XInterface
)oDocMSF
.
84 createInstance("com.sun.star.sheet.FunctionDescriptions");
85 XNameAccess NA
= UnoRuntime
.queryInterface
86 (XNameAccess
.class, FDs
);
88 String names
[] = NA
.getElementNames();
89 Random rnd
= new Random();
90 int idx
= rnd
.nextInt(names
.length
);
92 oObj
= (XInterface
)NA
.getByName(names
[idx
]);
94 log
.println("Creating object - " +
95 ((oObj
== null) ?
"FAILED" : "OK"));
97 } catch (Exception e
) {
98 e
.printStackTrace(log
) ;
99 throw new StatusException
100 ("Error getting test object from spreadsheet document",e
) ;
103 TestEnvironment tEnv
= new TestEnvironment( oObj
);
105 // Other parameters required for interface tests