1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
34 public class ShowTargets
36 /** Creates a new instance of ShowTargets */
41 public static void main( String
[] args
)
43 java
.util
.Vector targets
= new java
.util
.Vector();
44 java
.util
.Vector descs
= new java
.util
.Vector();
47 descs
.add( "runs all complex tests in this module" );
49 int maxTargetLength
= 3;
51 for ( int i
= 0; i
< args
.length
; ++i
)
53 String completePotentialClassName
= args
[i
].replace( '/', '.' );
56 if ( completePotentialClassName
.endsWith( ".TestCase" ) )
58 if ( completePotentialClassName
.endsWith( ".TestSkeleton" ) )
62 Class potentialTestClass
= null;
63 try { potentialTestClass
= Class
.forName( completePotentialClassName
); }
64 catch( java
.lang
.ClassNotFoundException e
)
69 // see if it is derived from complexlib.ComplexTestCase
70 Class superClass
= potentialTestClass
.getSuperclass();
71 while ( superClass
!= null )
73 if ( superClass
.getName().equals( "complexlib.ComplexTestCase" ) )
75 String bareClassName
= completePotentialClassName
.substring( completePotentialClassName
.lastIndexOf( '.' ) + 1 );
76 String target
= "run_" + bareClassName
;
77 targets
.add( target
);
78 descs
.add( getShortTestDescription( potentialTestClass
) );
80 if ( maxTargetLength
< target
.length() )
81 maxTargetLength
= target
.length();
84 superClass
= superClass
.getSuperclass();
88 System
.out
.println( "possible targets:" );
89 for ( int i
=0; i
<targets
.size(); ++i
)
92 String target
= (String
)targets
.get(i
);
94 System
.out
.print( " " + target
);
95 for ( int s
= maxTargetLength
- target
.length(); s
>0; --s
)
96 System
.out
.print( " " );
98 System
.out
.println( " (" + (String
)descs
.get(i
) + ")" );
102 /** determines if the test denoted by a given Class is an interactive test
104 static private boolean isInteractiveTest( Class testClass
)
106 java
.lang
.reflect
.Method interactiveTestMethod
= null;
107 try { interactiveTestMethod
= testClass
.getMethod( "isInteractiveTest", new Class
[]{} ); }
108 catch( Exception e
) { }
110 if ( interactiveTestMethod
!= null )
114 Boolean result
= (Boolean
)interactiveTestMethod
.invoke( null, new Object
[]{} );
115 return result
.booleanValue();
117 catch( Exception e
) { }
122 static private String
getShortTestDescription( Class _testClass
)
124 java
.lang
.reflect
.Method getShortDescriptionMethod
= null;
125 try { getShortDescriptionMethod
= _testClass
.getMethod( "getShortTestDescription", new Class
[]{} ); }
126 catch( Exception e
) { }
128 if ( getShortDescriptionMethod
!= null )
132 return (String
)getShortDescriptionMethod
.invoke( null, new Object
[]{} );
134 catch( Exception e
) { }
136 return "no description provided by the test";