1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package complexlib;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir /**
31*cdf0e10cSrcweir  *
32*cdf0e10cSrcweir  * @author fs93730
33*cdf0e10cSrcweir  */
34*cdf0e10cSrcweir public class ShowTargets
35*cdf0e10cSrcweir {
36*cdf0e10cSrcweir     /** Creates a new instance of ShowTargets */
37*cdf0e10cSrcweir     public ShowTargets()
38*cdf0e10cSrcweir     {
39*cdf0e10cSrcweir     }
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir     public static void main( String[] args )
42*cdf0e10cSrcweir     {
43*cdf0e10cSrcweir         java.util.Vector targets = new java.util.Vector();
44*cdf0e10cSrcweir         java.util.Vector descs = new java.util.Vector();
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir         targets.add( "run" );
47*cdf0e10cSrcweir         descs.add( "runs all complex tests in this module" );
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir         int maxTargetLength = 3;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir         for ( int i = 0; i < args.length; ++i )
52*cdf0e10cSrcweir         {
53*cdf0e10cSrcweir             String completePotentialClassName = args[i].replace( '/', '.' );
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir             // filter
56*cdf0e10cSrcweir             if ( completePotentialClassName.endsWith( ".TestCase" ) )
57*cdf0e10cSrcweir                 continue;
58*cdf0e10cSrcweir             if ( completePotentialClassName.endsWith( ".TestSkeleton" ) )
59*cdf0e10cSrcweir                 continue;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir             // get the class
62*cdf0e10cSrcweir             Class potentialTestClass = null;
63*cdf0e10cSrcweir             try { potentialTestClass = Class.forName( completePotentialClassName ); }
64*cdf0e10cSrcweir             catch( java.lang.ClassNotFoundException e )
65*cdf0e10cSrcweir             {
66*cdf0e10cSrcweir                 continue;
67*cdf0e10cSrcweir             }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir             // see if it is derived from complexlib.ComplexTestCase
70*cdf0e10cSrcweir             Class superClass = potentialTestClass.getSuperclass();
71*cdf0e10cSrcweir             while ( superClass != null )
72*cdf0e10cSrcweir             {
73*cdf0e10cSrcweir                 if ( superClass.getName().equals( "complexlib.ComplexTestCase" ) )
74*cdf0e10cSrcweir                 {
75*cdf0e10cSrcweir                     String bareClassName = completePotentialClassName.substring( completePotentialClassName.lastIndexOf( '.' ) + 1 );
76*cdf0e10cSrcweir                     String target = "run_" + bareClassName;
77*cdf0e10cSrcweir                     targets.add( target );
78*cdf0e10cSrcweir                     descs.add( getShortTestDescription( potentialTestClass ) );
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir                     if ( maxTargetLength < target.length() )
81*cdf0e10cSrcweir                         maxTargetLength = target.length();
82*cdf0e10cSrcweir                     break;
83*cdf0e10cSrcweir                 }
84*cdf0e10cSrcweir                 superClass = superClass.getSuperclass();
85*cdf0e10cSrcweir             }
86*cdf0e10cSrcweir         }
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir         System.out.println( "possible targets:" );
89*cdf0e10cSrcweir         for ( int i=0; i<targets.size(); ++i )
90*cdf0e10cSrcweir         {
91*cdf0e10cSrcweir             // target
92*cdf0e10cSrcweir             String target = (String)targets.get(i);
93*cdf0e10cSrcweir             // 'tab'
94*cdf0e10cSrcweir             System.out.print( "  " + target );
95*cdf0e10cSrcweir             for ( int s = maxTargetLength - target.length(); s>0; --s )
96*cdf0e10cSrcweir                 System.out.print( " " );
97*cdf0e10cSrcweir             // description
98*cdf0e10cSrcweir             System.out.println( " (" + (String)descs.get(i) + ")" );
99*cdf0e10cSrcweir         }
100*cdf0e10cSrcweir     }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     /** determines if the test denoted by a given Class is an interactive test
103*cdf0e10cSrcweir      */
104*cdf0e10cSrcweir     static private boolean isInteractiveTest( Class testClass )
105*cdf0e10cSrcweir     {
106*cdf0e10cSrcweir         java.lang.reflect.Method interactiveTestMethod = null;
107*cdf0e10cSrcweir         try { interactiveTestMethod = testClass.getMethod( "isInteractiveTest", new Class[]{} ); }
108*cdf0e10cSrcweir         catch( Exception e ) { }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir         if ( interactiveTestMethod != null )
111*cdf0e10cSrcweir         {
112*cdf0e10cSrcweir             try
113*cdf0e10cSrcweir             {
114*cdf0e10cSrcweir                 Boolean result = (Boolean)interactiveTestMethod.invoke( null, new Object[]{} );
115*cdf0e10cSrcweir                 return result.booleanValue();
116*cdf0e10cSrcweir             }
117*cdf0e10cSrcweir             catch( Exception e ) { }
118*cdf0e10cSrcweir         }
119*cdf0e10cSrcweir         return false;
120*cdf0e10cSrcweir     }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     static private String getShortTestDescription( Class _testClass )
123*cdf0e10cSrcweir     {
124*cdf0e10cSrcweir         java.lang.reflect.Method getShortDescriptionMethod = null;
125*cdf0e10cSrcweir         try { getShortDescriptionMethod = _testClass.getMethod( "getShortTestDescription", new Class[]{} ); }
126*cdf0e10cSrcweir         catch( Exception e ) { }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir         if ( getShortDescriptionMethod != null )
129*cdf0e10cSrcweir         {
130*cdf0e10cSrcweir             try
131*cdf0e10cSrcweir             {
132*cdf0e10cSrcweir                 return (String)getShortDescriptionMethod.invoke( null, new Object[]{} );
133*cdf0e10cSrcweir             }
134*cdf0e10cSrcweir             catch( Exception e ) { }
135*cdf0e10cSrcweir         }
136*cdf0e10cSrcweir         return "no description provided by the test";
137*cdf0e10cSrcweir     }
138*cdf0e10cSrcweir }
139