Update ooo320-m1
[ooovba.git] / qadevOOo / runner / helper / ComplexDescGetter.java
blobbfc328a49bbe712f2a70cceee4f6b07c5bd7bace
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ComplexDescGetter.java,v $
10 * $Revision: 1.9 $
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 ************************************************************************/
30 package helper;
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;
40 /**
43 public class ComplexDescGetter extends DescGetter
46 ComplexTest testClass;
48 /** Creates new ComplexDescGetter */
49 public ComplexDescGetter()
51 testClass = null;
54 public DescEntry[] getDescriptionFor(String entry, String DescPath,
55 boolean debug)
57 // read scenario file
58 if (entry.startsWith("-sce"))
60 DescEntry[] entries = getScenario(entry.substring(5), null, debug);
61 return entries;
63 // one single job
64 else if (entry.startsWith("-o"))
66 DescEntry dEntry = getDescriptionForSingleJob(entry.substring(3), null, debug);
67 if (dEntry != null)
69 return new DescEntry[]
71 dEntry
75 System.out.println("Could not get a testjob with parameter '" + entry + "'");
76 // no job available
77 return null;
80 protected DescEntry getDescriptionForSingleJob(String className, String descPath, boolean debug)
82 DynamicClassLoader dcl = new DynamicClassLoader();
83 String methodNames[] = null;
85 if (debug)
87 System.out.println("Searching Class: " + className);
90 int index = className.indexOf("::");
91 if (index != -1)
93 // case1: method()
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);
111 methods.add(meth);
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.");
126 return null;
128 catch (java.lang.ClassCastException e)
130 System.out.println("The given class '" + className + "' is not a Complex test.");
131 return null;
135 if (debug)
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);
154 return dEntry;
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
162 * @param log
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;
175 dEntry.Logger = log;
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;
187 dEntry.Logger = log;
190 return dEntry;
193 protected String[] createScenario(String descPath, String job, boolean debug)
195 return new String[] {};