1 23 24 29 package com.sun.cli.jmx.cmd; 30 31 import java.util.ArrayList ; 32 import java.util.Iterator ; 33 34 35 36 public class ArgHelperOptionsInfoTest extends junit.framework.TestCase 37 { 38 39 public void 40 testCreate() 41 throws ArgHelper.IllegalOptionException 42 { 43 new ArgHelperOptionsInfo(); 44 new ArgHelperOptionsInfo( "a b c" ); 45 new ArgHelperOptionsInfo( "aa bb,2 cc" ); 46 new ArgHelperOptionsInfo( "long-option-dashed-name" ); 47 new ArgHelperOptionsInfo( "long.option.dotted.name" ); 48 new ArgHelperOptionsInfo( "long_option_underscore_name" ); 49 new ArgHelperOptionsInfo( "long-option_mixed.name" ); 50 } 51 52 53 void 54 checkCreateFailure( String options ) 55 throws ArgHelper.IllegalOptionException 56 { 57 try 58 { 59 new ArgHelperOptionsInfo( options ); 60 fail( "expected failure from option description \"" + options + "\"" ); 61 } 62 catch( Exception e ) 63 { 64 } 66 } 67 68 public void 69 testCreateFailures() 70 throws ArgHelper.IllegalOptionException 71 { 72 final String illegals = "~`!@#$%^&*()+={}[]|\\:;\"'<>?,/"; 73 74 for( int i = 0; i < illegals.length(); ++i ) 75 { 76 checkCreateFailure( "" + illegals.charAt( i ) ); 77 } 78 } 79 80 81 public void 82 testIllegals() 83 throws ArgHelper.IllegalOptionException 84 { 85 final ArgHelperOptionsInfo info = new ArgHelperOptionsInfo( "hello h" ); 86 87 assertEquals( false, info.isLegalOption( "hello" ) ); 88 assertEquals( false, info.isLegalOption( "-hello" ) ); 89 assertEquals( false, info.isLegalOption( "h" ) ); 90 assertEquals( false, info.isLegalOption( "--h" ) ); 91 assertEquals( false, info.isLegalOption( "-" ) ); 92 assertEquals( false, info.isLegalOption( "--" ) ); 93 assertEquals( false, info.isLegalOption( "" ) ); 94 } 95 96 public void 97 testLegals() 98 throws ArgHelper.IllegalOptionException 99 { 100 final ArgHelperOptionsInfo info = new ArgHelperOptionsInfo( "hello --there,3 x,1 -y,1" ); 101 102 assertEquals( true, info.isLegalOption( "--hello" ) ); 103 assertEquals( true, info.isLegalOption( "--there" ) ); 104 assertEquals( true, info.isLegalOption( "-x" ) ); 105 assertEquals( true, info.isLegalOption( "-y" ) ); 106 } 107 108 109 void 110 checkRedundantFailure( String args ) 111 { 112 try 113 { 114 new ArgHelperOptionsInfo( args ); 115 fail( "expected rejection of redundant option" ); 116 } 117 catch( Exception e ) 118 { 119 } 120 } 121 122 public void 123 testRedundant() 124 throws ArgHelper.IllegalOptionException 125 { 126 checkRedundantFailure( "a a" ); 127 checkRedundantFailure( "aa aa" ); 128 checkRedundantFailure( "--aa --aa" ); 129 checkRedundantFailure( "-a -a" ); 130 } 131 132 public void 133 testMixedArgs() 134 throws ArgHelper.IllegalOptionException 135 { 136 final ArgHelperOptionsInfo info = new ArgHelperOptionsInfo( "a b,1 c,2 d,3 --xyz,4" ); 137 138 assertEquals( true, info.isLegalOption( "-a" ) ); 139 assertEquals( false, info.isLegalOption( "--a" ) ); 140 assertEquals( 1, info.getNumValues( "-a" ) ); 141 assertEquals( true, info.isBoolean( "-a" ) ); 142 143 assertEquals( 1, info.getNumValues( "-b" ) ); 144 assertEquals( 2, info.getNumValues( "-c" ) ); 145 assertEquals( 3, info.getNumValues( "-d" ) ); 146 assertEquals( 4, info.getNumValues( "--xyz" ) ); 147 148 } 149 150 151 152 public 153 ArgHelperOptionsInfoTest() 154 { 155 } 156 157 public void 158 setUp() 159 { 160 } 161 162 public void 163 tearDown() 164 { 165 } 166 167 } 168 169 | Popular Tags |