diff options
author | Yohann Roussel <yroussel@google.com> | 2014-12-04 14:55:22 +0100 |
---|---|---|
committer | Yohann Roussel <yroussel@google.com> | 2014-12-04 17:46:08 +0100 |
commit | be480ddca0e30896b51876d226ec16ffce4f519f (patch) | |
tree | 19513c07ec4efc1f2910175fe796049aded7a495 /sched/tests | |
parent | 2aaa53567cb50d056676b89ac96a6516c907e565 (diff) | |
download | toolchain_jack-be480ddca0e30896b51876d226ec16ffce4f519f.zip toolchain_jack-be480ddca0e30896b51876d226ec16ffce4f519f.tar.gz toolchain_jack-be480ddca0e30896b51876d226ec16ffce4f519f.tar.bz2 |
Fix command line parsing of empty argument
Without this fix the added test was failing with a
StringIndexOutOfBoundsException.
Change-Id: Ie312d237e6cbf5365b6167168faac6f1f945b755
Diffstat (limited to 'sched/tests')
-rw-r--r-- | sched/tests/com/android/sched/util/config/cli/TokenIteratorTest.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/sched/tests/com/android/sched/util/config/cli/TokenIteratorTest.java b/sched/tests/com/android/sched/util/config/cli/TokenIteratorTest.java index 5b724a0..b741bb2 100644 --- a/sched/tests/com/android/sched/util/config/cli/TokenIteratorTest.java +++ b/sched/tests/com/android/sched/util/config/cli/TokenIteratorTest.java @@ -84,6 +84,63 @@ public class TokenIteratorTest { } @Test + public void testTokenIteratorEmptyArg() { + Location loc = new StringLocation("Default location"); + + try { + test( + new TokenIterator(loc, ""), + new String[] {""}, + new Location[] {loc}); + } catch (NoSuchElementException e) { + fail(); + } catch (WrongPermissionException e) { + fail(); + } catch (NoSuchFileException e) { + fail(); + } catch (NotFileOrDirectoryException e) { + fail(); + } catch (CannotReadException e) { + fail(); + } + } + + @Test + public void testTokenIteratorEmptyArgFile() throws IOException { + Location loc = new StringLocation("Default location"); + File file = File.createTempFile(TokenIteratorTest.class.getSimpleName(), "-1"); + file.deleteOnExit(); + Location floc = new FileLocation(file); + + String fileArg = "@" + file.getAbsolutePath(); + PrintStream printer = new PrintStream(file); + printer.print("\"\""); + printer.close(); + + + try { + test( + new TokenIterator(loc, fileArg), + new String[] {""}, + new Location[] {floc}); + test( + new TokenIterator(loc, fileArg).allowFileReferenceInFile(), + new String[] {""}, + new Location[] {floc}); + } catch (NoSuchElementException e) { + fail(); + } catch (WrongPermissionException e) { + fail(); + } catch (NoSuchFileException e) { + fail(); + } catch (NotFileOrDirectoryException e) { + fail(); + } catch (CannotReadException e) { + fail(); + } + } + + @Test public void testTokenIteratorWithSimpleFile() throws IOException { Location loc = new StringLocation("Default location"); |