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 .
20 import java
.util
.ArrayList
;
22 import share
.ComplexTest
;
23 import share
.DescEntry
;
24 import share
.DescGetter
;
25 import share
.LogWriter
;
26 import util
.DynamicClassLoader
;
28 import complexlib
.ComplexTestCase
;
33 public class ComplexDescGetter
extends DescGetter
36 ComplexTest testClass
;
38 /** Creates new ComplexDescGetter */
39 public ComplexDescGetter()
44 public DescEntry
[] getDescriptionFor(String entry
, String DescPath
,
48 if (entry
.startsWith("-sce"))
50 DescEntry
[] entries
= getScenario(entry
.substring(5), null, debug
);
54 else if (entry
.startsWith("-o"))
56 DescEntry dEntry
= getDescriptionForSingleJob(entry
.substring(3), null, debug
);
59 return new DescEntry
[]
65 System
.out
.println("Could not get a testjob with parameter '" + entry
+ "'");
70 protected DescEntry
getDescriptionForSingleJob(String className
, String descPath
, boolean debug
)
72 DynamicClassLoader dcl
= new DynamicClassLoader();
73 String methodNames
[] = null;
77 System
.out
.println("Searching Class: " + className
);
80 int index
= className
.indexOf("::");
84 // case2: method(param1,param2)
85 // case3: method1(param1,param2),method2(param1,param2)
86 String method
= className
.substring(index
+ 2);
87 className
= className
.substring(0, index
);
88 ArrayList
<String
> methods
= new ArrayList
<String
>();
90 String
[] split
= method
.split("(?<=\\)),(?=\\w+)");
92 for (int i
= 0; i
< split
.length
; i
++)
94 String meth
= split
[i
];
96 if (meth
.endsWith("()"))
98 meth
= meth
.substring(0, meth
.length() - 2);
104 methodNames
= new String
[methods
.size()];
105 methodNames
= methods
.toArray(methodNames
);
108 // create an instance
111 testClass
= (ComplexTestCase
) dcl
.getInstance(className
);
113 catch (java
.lang
.IllegalArgumentException e
)
115 System
.out
.println("Error while getting description for test '" + className
+ "' as a Complex test.");
118 catch (java
.lang
.ClassCastException e
)
120 System
.out
.println("The given class '" + className
+ "' is not a Complex test.");
127 System
.out
.println("Got test: " + ((Object
) testClass
).toString());
130 String testObjectName
= className
;
131 String
[] testMethodNames
= null;
133 if (testMethodNames
== null)
135 testMethodNames
= testClass
.getTestMethodNames();
137 if (methodNames
!= null)
139 testMethodNames
= methodNames
;
142 DescEntry dEntry
= createTestDesc(testObjectName
, className
, testMethodNames
, null);
148 * Creates a description exntry for the given parameter
149 * @param testObjectName the name of the object
150 * @param className the class name of the class to load
151 * @param testMethodNames list of all methods to test
153 * @return filled description entry
155 public DescEntry
createTestDesc(String testObjectName
, String className
, String
[] testMethodNames
, LogWriter log
)
158 DescEntry dEntry
= new DescEntry();
160 dEntry
.entryName
= testObjectName
;
161 dEntry
.longName
= className
;
162 dEntry
.isOptional
= false;
163 dEntry
.EntryType
= "unit";
164 dEntry
.isToTest
= true;
166 dEntry
.SubEntryCount
= testMethodNames
.length
;
167 dEntry
.SubEntries
= new DescEntry
[dEntry
.SubEntryCount
];
168 for (int i
= 0; i
< dEntry
.SubEntryCount
; i
++)
170 DescEntry aEntry
= new DescEntry();
171 aEntry
.entryName
= testMethodNames
[i
];
172 aEntry
.longName
= testObjectName
+ "::" + aEntry
.entryName
;
173 aEntry
.isOptional
= false;
174 aEntry
.EntryType
= "method";
175 aEntry
.isToTest
= true;
176 dEntry
.SubEntries
[i
] = aEntry
;
183 protected String
[] createScenario(String descPath
, String job
, boolean debug
)
185 return new String
[] {};