97 DiagnosticCommand arg = new DiagnosticCommand(name, |
98 DiagnosticCommand arg = new DiagnosticCommand(name, |
98 "desc", DiagnosticArgumentType.JLONG, |
99 "desc", DiagnosticArgumentType.JLONG, |
99 false, "0"); |
100 false, "0"); |
100 DiagnosticCommand[] args = {arg}; |
101 DiagnosticCommand[] args = {arg}; |
101 |
102 |
102 wb.parseCommandLine(name + "=10", args); |
103 wb.parseCommandLine(name + "=10", ',', args); |
103 parse(name, "10", name + "=10", args); |
104 parse(name, "10", name + "=10", args); |
104 parse(name, "-5", name + "=-5", args); |
105 parse(name, "-5", name + "=-5", args); |
105 |
106 |
106 //shouldFail(name + "=12m", args); <-- should fail, doesn't |
107 //shouldFail(name + "=12m", args); <-- should fail, doesn't |
107 } |
108 } |
147 parse(name, "myrec", "\"" + name + "\"" + "=myrec,arg=value", args); |
148 parse(name, "myrec", "\"" + name + "\"" + "=myrec,arg=value", args); |
148 // try with both a quoted value and a quoted argument |
149 // try with both a quoted value and a quoted argument |
149 parse(name, "Recording 1", "\"" + name + "\"" + "=\"Recording 1\",arg=value", args); |
150 parse(name, "Recording 1", "\"" + name + "\"" + "=\"Recording 1\",arg=value", args); |
150 } |
151 } |
151 |
152 |
|
153 public void testSingleLetterArg() throws Exception { |
|
154 DiagnosticCommand[] args = new DiagnosticCommand[]{ |
|
155 new DiagnosticCommand("flag", "desc", DiagnosticArgumentType.STRING, true, false, null), |
|
156 new DiagnosticCommand("value", "desc", DiagnosticArgumentType.STRING, true, false, null) |
|
157 }; |
|
158 parse("flag", "flag", "flag v", ' ', args); |
|
159 parse("value", "v", "flag v", ' ', args); |
|
160 } |
|
161 |
152 public void testMemorySize() throws Exception { |
162 public void testMemorySize() throws Exception { |
153 String name = "name"; |
163 String name = "name"; |
154 String defaultValue = "1024"; |
164 String defaultValue = "1024"; |
155 DiagnosticCommand arg = new DiagnosticCommand(name, |
165 DiagnosticCommand arg = new DiagnosticCommand(name, |
156 "desc", DiagnosticArgumentType.MEMORYSIZE, |
166 "desc", DiagnosticArgumentType.MEMORYSIZE, |
174 //shouldFail(name + "=7t", args); <----- should fail, doesn't |
184 //shouldFail(name + "=7t", args); <----- should fail, doesn't |
175 } |
185 } |
176 |
186 |
177 public void parse(String searchName, String expectedValue, |
187 public void parse(String searchName, String expectedValue, |
178 String cmdLine, DiagnosticCommand[] argumentTypes) throws Exception { |
188 String cmdLine, DiagnosticCommand[] argumentTypes) throws Exception { |
|
189 parse(searchName, expectedValue, cmdLine, ',', argumentTypes); |
|
190 } |
|
191 public void parse(String searchName, String expectedValue, |
|
192 String cmdLine, char delim, DiagnosticCommand[] argumentTypes) throws Exception { |
179 //parseCommandLine will return an object array that looks like |
193 //parseCommandLine will return an object array that looks like |
180 //{<name of parsed object>, <of parsed object> ... } |
194 //{<name of parsed object>, <of parsed object> ... } |
181 Object[] res = wb.parseCommandLine(cmdLine, argumentTypes); |
195 Object[] res = wb.parseCommandLine(cmdLine, delim, argumentTypes); |
182 for (int i = 0; i < res.length-1; i+=2) { |
196 for (int i = 0; i < res.length-1; i+=2) { |
183 String parsedName = (String) res[i]; |
197 String parsedName = (String) res[i]; |
184 if (searchName.equals(parsedName)) { |
198 if (searchName.equals(parsedName)) { |
185 String parsedValue = (String) res[i+1]; |
199 String parsedValue = (String) res[i+1]; |
186 if (expectedValue.equals(parsedValue)) { |
200 if (expectedValue.equals(parsedValue)) { |
194 } |
208 } |
195 throw new Exception(searchName + " not found as a parsed Argument!"); |
209 throw new Exception(searchName + " not found as a parsed Argument!"); |
196 } |
210 } |
197 |
211 |
198 private void shouldFail(String argument, DiagnosticCommand[] argumentTypes) throws Exception { |
212 private void shouldFail(String argument, DiagnosticCommand[] argumentTypes) throws Exception { |
|
213 shouldFail(argument, ',', argumentTypes); |
|
214 } |
|
215 private void shouldFail(String argument, char delim, DiagnosticCommand[] argumentTypes) throws Exception { |
199 try { |
216 try { |
200 wb.parseCommandLine(argument, argumentTypes); |
217 wb.parseCommandLine(argument, delim, argumentTypes); |
201 throw new Exception("Parser accepted argument: " + argument); |
218 throw new Exception("Parser accepted argument: " + argument); |
202 } catch (IllegalArgumentException e) { |
219 } catch (IllegalArgumentException e) { |
203 //expected |
220 //expected |
204 } |
221 } |
205 } |
222 } |