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 private ComplexTest testClass
;
38 /** Creates new ComplexDescGetter */
39 public ComplexDescGetter()
45 public DescEntry
[] getDescriptionFor(String entry
, String DescPath
,
49 if (entry
.startsWith("-sce"))
51 DescEntry
[] entries
= getScenario(entry
.substring(5), null, debug
);
55 else if (entry
.startsWith("-o"))
57 DescEntry dEntry
= getDescriptionForSingleJob(entry
.substring(3), null, debug
);
60 return new DescEntry
[]
66 System
.out
.println("Could not get a testjob with parameter '" + entry
+ "'");
72 protected DescEntry
getDescriptionForSingleJob(String className
, String descPath
, boolean debug
)
74 DynamicClassLoader dcl
= new DynamicClassLoader();
75 String methodNames
[] = null;
79 System
.out
.println("Searching Class: " + className
);
82 int index
= className
.indexOf("::");
86 // case2: method(param1,param2)
87 // case3: method1(param1,param2),method2(param1,param2)
88 String method
= className
.substring(index
+ 2);
89 className
= className
.substring(0, index
);
90 ArrayList
<String
> methods
= new ArrayList
<String
>();
92 String
[] split
= method
.split("(?<=\\)),(?=\\w+)");
94 for (int i
= 0; i
< split
.length
; i
++)
96 String meth
= split
[i
];
98 if (meth
.endsWith("()"))
100 meth
= meth
.substring(0, meth
.length() - 2);
106 methodNames
= methods
.toArray(new String
[methods
.size()]);
109 // create an instance
112 testClass
= (ComplexTestCase
) dcl
.getInstance(className
);
114 catch (java
.lang
.IllegalArgumentException e
)
116 System
.out
.println("Error while getting description for test '" + className
+ "' as a Complex test.");
119 catch (java
.lang
.ClassCastException e
)
121 System
.out
.println("The given class '" + className
+ "' is not a Complex test.");
128 System
.out
.println("Got test: " + ((Object
) testClass
).toString());
131 String testObjectName
= className
;
132 String
[] testMethodNames
= testClass
.getTestMethodNames();
133 if (methodNames
!= null)
135 testMethodNames
= methodNames
;
138 DescEntry dEntry
= createTestDesc(testObjectName
, className
, testMethodNames
, null);
144 * Creates a description entry for the given parameter
145 * @param testObjectName the name of the object
146 * @param className the class name of the class to load
147 * @param testMethodNames list of all methods to test
148 * @return filled description entry
150 private DescEntry
createTestDesc(String testObjectName
, String className
, String
[] testMethodNames
, LogWriter log
)
153 DescEntry dEntry
= new DescEntry();
155 dEntry
.entryName
= testObjectName
;
156 dEntry
.longName
= className
;
157 dEntry
.isOptional
= false;
158 dEntry
.EntryType
= "unit";
159 dEntry
.isToTest
= true;
161 dEntry
.SubEntryCount
= testMethodNames
.length
;
162 dEntry
.SubEntries
= new DescEntry
[dEntry
.SubEntryCount
];
163 for (int i
= 0; i
< dEntry
.SubEntryCount
; i
++)
165 DescEntry aEntry
= new DescEntry();
166 aEntry
.entryName
= testMethodNames
[i
];
167 aEntry
.longName
= testObjectName
+ "::" + aEntry
.entryName
;
168 aEntry
.isOptional
= false;
169 aEntry
.EntryType
= "method";
170 aEntry
.isToTest
= true;
171 dEntry
.SubEntries
[i
] = aEntry
;
179 protected String
[] createScenario(String descPath
, String job
, boolean debug
)
181 return new String
[] {};