1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 package complexlib; 29 30 /** 31 * 32 * @author fs93730 33 */ 34 public class ShowTargets 35 { 36 /** Creates a new instance of ShowTargets */ 37 public ShowTargets() 38 { 39 } 40 41 public static void main( String[] args ) 42 { 43 java.util.Vector targets = new java.util.Vector(); 44 java.util.Vector descs = new java.util.Vector(); 45 46 targets.add( "run" ); 47 descs.add( "runs all complex tests in this module" ); 48 49 int maxTargetLength = 3; 50 51 for ( int i = 0; i < args.length; ++i ) 52 { 53 String completePotentialClassName = args[i].replace( '/', '.' ); 54 55 // filter 56 if ( completePotentialClassName.endsWith( ".TestCase" ) ) 57 continue; 58 if ( completePotentialClassName.endsWith( ".TestSkeleton" ) ) 59 continue; 60 61 // get the class 62 Class potentialTestClass = null; 63 try { potentialTestClass = Class.forName( completePotentialClassName ); } 64 catch( java.lang.ClassNotFoundException e ) 65 { 66 continue; 67 } 68 69 // see if it is derived from complexlib.ComplexTestCase 70 Class superClass = potentialTestClass.getSuperclass(); 71 while ( superClass != null ) 72 { 73 if ( superClass.getName().equals( "complexlib.ComplexTestCase" ) ) 74 { 75 String bareClassName = completePotentialClassName.substring( completePotentialClassName.lastIndexOf( '.' ) + 1 ); 76 String target = "run_" + bareClassName; 77 targets.add( target ); 78 descs.add( getShortTestDescription( potentialTestClass ) ); 79 80 if ( maxTargetLength < target.length() ) 81 maxTargetLength = target.length(); 82 break; 83 } 84 superClass = superClass.getSuperclass(); 85 } 86 } 87 88 System.out.println( "possible targets:" ); 89 for ( int i=0; i<targets.size(); ++i ) 90 { 91 // target 92 String target = (String)targets.get(i); 93 // 'tab' 94 System.out.print( " " + target ); 95 for ( int s = maxTargetLength - target.length(); s>0; --s ) 96 System.out.print( " " ); 97 // description 98 System.out.println( " (" + (String)descs.get(i) + ")" ); 99 } 100 } 101 102 /** determines if the test denoted by a given Class is an interactive test 103 */ 104 static private boolean isInteractiveTest( Class testClass ) 105 { 106 java.lang.reflect.Method interactiveTestMethod = null; 107 try { interactiveTestMethod = testClass.getMethod( "isInteractiveTest", new Class[]{} ); } 108 catch( Exception e ) { } 109 110 if ( interactiveTestMethod != null ) 111 { 112 try 113 { 114 Boolean result = (Boolean)interactiveTestMethod.invoke( null, new Object[]{} ); 115 return result.booleanValue(); 116 } 117 catch( Exception e ) { } 118 } 119 return false; 120 } 121 122 static private String getShortTestDescription( Class _testClass ) 123 { 124 java.lang.reflect.Method getShortDescriptionMethod = null; 125 try { getShortDescriptionMethod = _testClass.getMethod( "getShortTestDescription", new Class[]{} ); } 126 catch( Exception e ) { } 127 128 if ( getShortDescriptionMethod != null ) 129 { 130 try 131 { 132 return (String)getShortDescriptionMethod.invoke( null, new Object[]{} ); 133 } 134 catch( Exception e ) { } 135 } 136 return "no description provided by the test"; 137 } 138 } 139