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: ComplexDescGetter.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 complexlib
.ComplexTestCase
;
33 import util
.DynamicClassLoader
;
34 import share
.DescEntry
;
35 import share
.DescGetter
;
36 import share
.ComplexTest
;
37 import java
.util
.Vector
;
38 import share
.LogWriter
;
43 public class ComplexDescGetter
extends DescGetter
46 ComplexTest testClass
;
48 /** Creates new ComplexDescGetter */
49 public ComplexDescGetter()
54 public DescEntry
[] getDescriptionFor(String entry
, String DescPath
,
58 if (entry
.startsWith("-sce"))
60 DescEntry
[] entries
= getScenario(entry
.substring(5), null, debug
);
64 else if (entry
.startsWith("-o"))
66 DescEntry dEntry
= getDescriptionForSingleJob(entry
.substring(3), null, debug
);
69 return new DescEntry
[]
75 System
.out
.println("Could not get a testjob with parameter '" + entry
+ "'");
80 protected DescEntry
getDescriptionForSingleJob(String className
, String descPath
, boolean debug
)
82 DynamicClassLoader dcl
= new DynamicClassLoader();
83 String methodNames
[] = null;
87 System
.out
.println("Searching Class: " + className
);
90 int index
= className
.indexOf("::");
94 // case2: method(param1,param2)
95 // case3: method1(param1,param2),method2(param1,param2)
96 String method
= className
.substring(index
+ 2);
97 className
= className
.substring(0, index
);
98 Vector methods
= new Vector();
100 String
[] split
= method
.split("(?<=\\)),(?=\\w+)");
102 for (int i
= 0; i
< split
.length
; i
++)
104 String meth
= split
[i
];
106 if (meth
.endsWith("()"))
108 meth
= meth
.substring(0, meth
.length() - 2);
114 methodNames
= new String
[methods
.size()];
115 methodNames
= (String
[]) methods
.toArray(methodNames
);
118 // create an instance
121 testClass
= (ComplexTestCase
) dcl
.getInstance(className
);
123 catch (java
.lang
.IllegalArgumentException e
)
125 System
.out
.println("Error while getting description for test '" + className
+ "' as a Complex test.");
128 catch (java
.lang
.ClassCastException e
)
130 System
.out
.println("The given class '" + className
+ "' is not a Complex test.");
137 System
.out
.println("Got test: " + ((Object
) testClass
).toString());
140 String testObjectName
= className
;
141 String
[] testMethodNames
= null;
143 if (testMethodNames
== null)
145 testMethodNames
= testClass
.getTestMethodNames();
147 if (methodNames
!= null)
149 testMethodNames
= methodNames
;
152 DescEntry dEntry
= createTestDesc(testObjectName
, className
, testMethodNames
, null);
158 * Creates a description exntry for the given parameter
159 * @param testObjectName the name of the object
160 * @param className the class name of the class to load
161 * @param testMethodNames list of all methods to test
163 * @return filled description entry
165 public DescEntry
createTestDesc(String testObjectName
, String className
, String
[] testMethodNames
, LogWriter log
)
168 DescEntry dEntry
= new DescEntry();
170 dEntry
.entryName
= testObjectName
;
171 dEntry
.longName
= className
;
172 dEntry
.isOptional
= false;
173 dEntry
.EntryType
= "unit";
174 dEntry
.isToTest
= true;
176 dEntry
.SubEntryCount
= testMethodNames
.length
;
177 dEntry
.SubEntries
= new DescEntry
[dEntry
.SubEntryCount
];
178 for (int i
= 0; i
< dEntry
.SubEntryCount
; i
++)
180 DescEntry aEntry
= new DescEntry();
181 aEntry
.entryName
= testMethodNames
[i
];
182 aEntry
.longName
= testObjectName
+ "::" + aEntry
.entryName
;
183 aEntry
.isOptional
= false;
184 aEntry
.EntryType
= "method";
185 aEntry
.isToTest
= true;
186 dEntry
.SubEntries
[i
] = aEntry
;
193 protected String
[] createScenario(String descPath
, String job
, boolean debug
)
195 return new String
[] {};