1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: BasicIfcTest.java,v $
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 ************************************************************************/
32 import lib
.TestResult
;
33 import lib
.TestEnvironment
;
34 import lib
.TestParameters
;
35 import share
.DescEntry
;
36 import share
.LogWriter
;
38 import com
.sun
.star
.lang
.XMultiServiceFactory
;
40 import com
.sun
.star
.beans
.PropertyValue
;
44 * The BASIC interface test
46 public class BasicIfcTest
{
47 /** The BasicHandler **/
48 static BasicHandler oBasicHandler
= null;
49 /** The result orf the test **/
50 protected TestResult tRes
;
51 /** the name of the test **/
52 protected String testName
;
54 /** Constructor with test name.
55 * @param name The name of the test.
57 public BasicIfcTest(String name
) {
63 * @param xTestedEntry Informaton about the interface to test.
64 * @param tEnv The environment of the test.
65 * @param tParam The test parameters.
66 * @return A result of the test.
68 public TestResult
run(DescEntry xTestedEntry
, TestEnvironment tEnv
,
69 TestParameters tParam
) {
73 this.tRes
= new TestResult();
74 LogWriter log
= xTestedEntry
.Logger
;
76 // Get Handler, that was created during object creation.
78 oBasicHandler
= (BasicHandler
)tEnv
.getObjRelation("BasicHandler");
79 } catch (java
.lang
.NullPointerException e
) {
80 log
.println("No Component created");
84 if (!oBasicHandler
.isUptodate((XMultiServiceFactory
)tParam
.getMSF())) {
85 // If Handler uses old MSF (in case of Office's GPF) then don't test
90 boolean objectWasCreated
= ((Boolean
)tEnv
.getObjRelation("objectCreated")).booleanValue();
92 if (objectWasCreated
) {
93 oBasicHandler
.setTestedInterface(this, log
);
95 DescEntry methods
[] = xTestedEntry
.SubEntries
;
97 String names
[] = new String
[methods
.length
+ 1];
98 boolean isOpt
[] = new boolean[methods
.length
+ 1];
99 String other
[] = new String
[1];
101 String aName
= xTestedEntry
.longName
;
102 aName
= aName
.substring(aName
.indexOf("::")+2);
104 int index
= aName
.indexOf("::");
107 names
[0] += aName
.substring(oldIndex
,index
) + ".";
109 index
=aName
.indexOf("::", oldIndex
);
111 names
[0] += aName
.substring(oldIndex
);
112 isOpt
[0] = xTestedEntry
.isOptional
;
114 for (int i
= 1; i
< names
.length
; i
++) {
115 names
[i
] = methods
[i
- 1].entryName
;
116 isOpt
[i
] = methods
[i
- 1].isOptional
;
119 // for reasons of compatibility with JSuite we change the first
120 // character of EntryType to upper case.
121 String eType
= xTestedEntry
.EntryType
;
122 other
[0] = eType
.toUpperCase().charAt(0)+eType
.substring(1);
124 Object params
[] = {names
, isOpt
, other
};
127 PropertyValue Res
= oBasicHandler
.perform("testInterface", params
);
128 sResult
= (String
)Res
.Value
;
129 } catch (BasicException e
) {
131 sResult
= "SKIPPED.FAILED";
133 } else { // if object was not created...
134 sResult
= "SKIPPED.FAILED";
137 // now tRes has all substates: collect them
138 DescEntry
[] subs
= xTestedEntry
.SubEntries
;
139 for (int i
= 0; i
< subs
.length
; i
++) {
140 if (sResult
.equals("SKIPPED.FAILED"))
141 subs
[i
].State
= "SKIPPED.FAILED";
142 else if (sResult
.equals("SKIPPED.OK"))
143 subs
[i
].State
= "SKIPPED.OK";
145 if (tRes
.getStatusFor(subs
[i
].entryName
) == null) {
146 subs
[i
].State
= "SKIPPED.FAILED";
148 subs
[i
].State
= tRes
.getStatusFor(
149 subs
[i
].entryName
).toString();
153 xTestedEntry
.State
= sResult
;
158 * Set the result of the method that is tested.
159 * @param methodName The name of the method.
160 * @param bResult The result of the test.
162 public void methodTested(String methodName
, boolean bResult
) {
163 tRes
.tested(methodName
, bResult
);
167 * @return The name of the interface or the service tested.
169 String
getTestedClassName() {