X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=test%2Fjalview%2Fbin%2Fargparser%2FArgParserTest.java;h=ca63e44aa31ff64cb075a6eafe86946aa5c45043;hb=0ccaf35f7e6a5cc62d4f433b39d574d0aa4b2d26;hp=6d7f88fa643f8e475db9b5b3e26f5a99af190c1d;hpb=0f54185e0cdf79411f0e5085c5515ae559c9129d;p=jalview.git diff --git a/test/jalview/bin/argparser/ArgParserTest.java b/test/jalview/bin/argparser/ArgParserTest.java index 6d7f88f..ca63e44 100644 --- a/test/jalview/bin/argparser/ArgParserTest.java +++ b/test/jalview/bin/argparser/ArgParserTest.java @@ -7,10 +7,12 @@ import java.util.Properties; import org.testng.Assert; import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import jalview.bin.Cache; +import jalview.gui.Desktop; @Test(singleThreaded = true) public class ArgParserTest @@ -21,6 +23,13 @@ public class ArgParserTest Cache.loadProperties("test/jalview/testProps.jvprops"); } + @AfterMethod(alwaysRun = true) + public void tearDown() + { + if (Desktop.instance != null) + Desktop.instance.closeAll_actionPerformed(null); + } + @Test(groups = "Functional", dataProvider = "argLines") public void parseArgsTest(String commandLineArgs, Arg a, String other) { @@ -35,7 +44,7 @@ public class ArgParserTest { String[] args = commandLineArgs.split("\\s+"); ArgParser argparser = new ArgParser(args); - ArgValuesMap avm = argparser.linkedArgs(linkedId); + ArgValuesMap avm = argparser.getLinkedArgs(linkedId); ArgValue av = avm.getArgValue(a); SubVals sv = av.getSubVals(); String testString = null; @@ -63,11 +72,11 @@ public class ArgParserTest public void parseAutoIndexAndSubstitutionsTest(String commandLineArgs, String linkedId, Arg a, String filename) { - // { "--open=filename0 --increment --open=filename1", "JALVIEW:1", Arg.OPEN, - // "filename1" }, + // { "--append=filename0 --new --append=filename1", "JALVIEW:1", + // Arg.OPEN, "filename1" }, String[] args = commandLineArgs.split("\\s+"); ArgParser argparser = new ArgParser(args); - ArgValuesMap avm = argparser.linkedArgs(linkedId); + ArgValuesMap avm = argparser.getLinkedArgs(linkedId); ArgValue av = avm.getArgValue(a); Assert.assertEquals(av.getValue(), filename); } @@ -88,7 +97,7 @@ public class ArgParserTest } else if (a == Arg.ARGFILE) { - List filenames = b.getList(a); + List filenames = b.getValueList(a); boolean found = false; for (String s : filenames) { @@ -118,7 +127,7 @@ public class ArgParserTest BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args); Assert.assertTrue(b.contains(a)); - Assert.assertFalse(b.contains(Arg.OPEN)); + Assert.assertFalse(b.contains(Arg.APPEND)); if (a == Arg.PROPS) { Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS)); @@ -141,11 +150,11 @@ public class ArgParserTest public Object[][] argLines() { return new Object[][] { { - "--open=test/jalview/bin/argparser/testfiles/test1.fa --props=test/jalview/bin/argparser/testfiles/testProps.jvprops", + "--append=test/jalview/bin/argparser/testfiles/test1.fa --props=test/jalview/bin/argparser/testfiles/testProps.jvprops", Arg.PROPS, "true" }, - { "--debug --open=test/jalview/bin/argparser/testfiles/test1.fa", + { "--debug --append=test/jalview/bin/argparser/testfiles/test1.fa", Arg.DEBUG, null }, - { "--open=test/jalview/bin/argparser/testfiles/test1.fa --headless", + { "--append=test/jalview/bin/argparser/testfiles/test1.fa --headless", Arg.HEADLESS, null }, { "--argfile test/jalview/bin/argparser/testfiles/argfile0.txt", @@ -175,38 +184,73 @@ public class ArgParserTest @DataProvider(name = "argSubValsAndLinkedIds") public Object[][] argSubValsAndLinkedIds() { - return new Object[][] { { - "--debug --open=[hi]test/jalview/bin/argparser/testfiles/test1.fa", - "JALVIEW:0", Arg.OPEN, "hi", "true", true }, - { "--open[linkedId1]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", - "linkedId1", Arg.OPEN, "new", "true", true }, - { "--open[linkedId2]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", - "linkedId2", Arg.OPEN, "hello", "world", true }, - { "--open[linkedId3]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", - "linkedId3", Arg.OPEN, "GETINDEX", "1", true }, - { "--open[linkedId4]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --open[linkedId5]=[notnew;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", - "linkedId5", Arg.OPEN, "new", "true", false }, - { "--open[linkedId5]=[new;hello=worlddomination;1]test/jalview/bin/argparser/testfiles/test1.fa --open[linkedId2]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", - "linkedId5", Arg.OPEN, "hello", "world", false }, - { "--open[linkedId6]=[new;hello=world;0]test/jalview/bin/argparser/testfiles/test1.fa --open[linkedId7]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", - "linkedId7", Arg.OPEN, "GETINDEX", "0", false }, }; + return new Object[][] { + // + /* + */ + { "--debug --append=[hi]test/jalview/bin/argparser/testfiles/test1.fa", + "JALVIEW:0", Arg.APPEND, "hi", "true", true }, + { "--append[linkedId1]=[new,hello=world,1]test/jalview/bin/argparser/testfiles/test1.fa --headless", + "linkedId1", Arg.APPEND, "new", "true", true }, + { "--append[linkedId2]=[new,hello=world,1]test/jalview/bin/argparser/testfiles/test1.fa --headless", + "linkedId2", Arg.APPEND, "hello", "world", true }, + { "--append[linkedId3]=[new,hello=world,1]test/jalview/bin/argparser/testfiles/test1.fa --headless", + "linkedId3", Arg.APPEND, "GETINDEX", "1", true }, + { "--append[linkedId4]=[new,hello=world,1]test/jalview/bin/argparser/testfiles/test1.fa --append[linkedId5]=[notnew;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", + "linkedId5", Arg.APPEND, "new", "true", false }, + { "--append[linkedId5]=[new,hello=worlddomination,1]test/jalview/bin/argparser/testfiles/test1.fa --append[linkedId2]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", + "linkedId5", Arg.APPEND, "hello", "world", false }, + { "--append[linkedId6]=[new,hello=world,0]test/jalview/bin/argparser/testfiles/test1.fa --append[linkedId7]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", + "linkedId7", Arg.APPEND, "GETINDEX", "0", false }, + /* + */ + // + }; } @DataProvider(name = "argAutoIndexAndSubstitutions") public Object[][] argAutoIndexAndSubstitutions() { - return new Object[][] { { "--open=filename0 --open=filename1", - "JALVIEW:0", Arg.OPEN, "filename0" }, - { "--open=filename0 --increment --open=filename1", "JALVIEW:1", - Arg.OPEN, "filename1" }, - { "--open=filename0 --increment --increment --open=filename2", - "JALVIEW:0", Arg.OPEN, "filename0" }, - { "--open=filename0 --increment --increment --open=filename2", - "JALVIEW:2", Arg.OPEN, "filename2" }, - { "--open[linkA-{n}]=filenameA0 --open[linkA-{++n}]=filenameA1", + return new Object[][] { + // + /* + */ + { "--append=filename0 --append=filename1", "JALVIEW:0", Arg.APPEND, + "filename0" }, + { "--append=filename0 --new --append=filename1", "JALVIEW:1", + Arg.APPEND, "filename1" }, + { "--append=filename0 --new --new --append=filename2", "JALVIEW:0", + Arg.APPEND, "filename0" }, + { "--append=filename0 --new --new --append=filename2", "JALVIEW:2", + Arg.APPEND, "filename2" }, + { "--append[linkA-{n}]=filenameA0 --append[linkA-{++n}]=filenameA1", + "linkA-0", Arg.APPEND, "filenameA0" }, + { "--append[linkB-{n}]=filenameB0 --append[linkB-{++n}]=filenameB1", + "linkB-1", Arg.APPEND, "filenameB1" }, + { "--append[linkC-{n}]=filenameC0 --image[linkC-{n}]=outputC{n}.txt", + "linkC-0", Arg.IMAGE, "outputC{n}.txt" }, + { "--append[linkD-{n}]=filenameD0 --substitutions --image[linkD-{n}]=outputD{n}.txt", + "linkD-0", Arg.IMAGE, "outputD0.txt" }, + { "--append[linkE-{n}]=filenameE0 --substitutions --image[linkE-{n}]=output-E{n}.txt --nil[{++n}] --image[linkE-{n}]=outputE{n}.txt", + "linkE-0", Arg.IMAGE, "output-E0.txt" }, + { "--append[linkF-{n}]=filenameF0 --substitutions --image[linkF-{n}]=output-F{n}.txt --nil[{++n}] --image[linkF-{n}]=outputF{n}.txt", + "linkF-1", Arg.IMAGE, "outputF1.txt" }, + { "--append[linkG-{n}]=filenameG0 --substitutions --image[linkG-{n}]=output-G{n}.txt --nil[{++n}] --nosubstitutions --image[linkG-{n}]=outputG{n}.txt", + "linkG-1", Arg.IMAGE, "outputG{n}.txt" }, + { "--append[linkH-{n}]=filenameH0 --substitutions --image[linkH-{n}]=output-H{n}.txt --nil[{++n}] --nosubstitutions --image[linkH-{n}]=outputH{n}.txt", + "linkH-0", Arg.IMAGE, "output-H0.txt" }, + { "--open=filename0 --append=filename1", "JALVIEW:0", Arg.OPEN, + "filename0" }, + { "--open=filename0 --new --append=filename1", "JALVIEW:1", + Arg.APPEND, "filename1" }, + { "--open=filename0 --new --new --append=filename2", "JALVIEW:0", + Arg.OPEN, "filename0" }, + { "--open=filename0 --new --new --append=filename2", "JALVIEW:2", + Arg.APPEND, "filename2" }, + { "--open[linkA-{n}]=filenameA0 --append[linkA-{++n}]=filenameA1", "linkA-0", Arg.OPEN, "filenameA0" }, - { "--open[linkB-{n}]=filenameB0 --open[linkB-{++n}]=filenameB1", - "linkB-1", Arg.OPEN, "filenameB1" }, + { "--open[linkB-{n}]=filenameB0 --append[linkB-{++n}]=filenameB1", + "linkB-1", Arg.APPEND, "filenameB1" }, { "--open[linkC-{n}]=filenameC0 --image[linkC-{n}]=outputC{n}.txt", "linkC-0", Arg.IMAGE, "outputC{n}.txt" }, { "--open[linkD-{n}]=filenameD0 --substitutions --image[linkD-{n}]=outputD{n}.txt", @@ -218,7 +262,12 @@ public class ArgParserTest { "--open[linkG-{n}]=filenameG0 --substitutions --image[linkG-{n}]=output-G{n}.txt --nil[{++n}] --nosubstitutions --image[linkG-{n}]=outputG{n}.txt", "linkG-1", Arg.IMAGE, "outputG{n}.txt" }, { "--open[linkH-{n}]=filenameH0 --substitutions --image[linkH-{n}]=output-H{n}.txt --nil[{++n}] --nosubstitutions --image[linkH-{n}]=outputH{n}.txt", - "linkH-0", Arg.IMAGE, "output-H0.txt" }, }; + "linkH-0", Arg.IMAGE, "output-H0.txt" }, + /* + */ + + // + }; } @DataProvider(name = "argFiles") @@ -228,4 +277,67 @@ public class ArgParserTest "--argfile=test/jalview/bin/argparser/testfiles/argfile0.txt --open=shouldntbeabootstrap", Arg.ARGFILE, "test/jalview/bin/argfiles/testfiles/test1.fa" } }; } + + @Test(groups = "Functional", dataProvider = "allLinkedIdsData") + public void allLinkedIdsTest(String commandLineArgs, Arg a, + String[] values, String[] nonvalues) + { + String[] args = commandLineArgs.split("\\s+"); + ArgParser argparser = new ArgParser(args); + + int num = values.length; + List linkedIds = argparser.getLinkedIds(); + Assert.assertEquals(linkedIds.size(), num, + "Wrong number of linkedIds: " + linkedIds.toString()); + for (int i = 0; i < num; i++) + { + String value = values[i]; + String linkedId = linkedIds.get(i); + ArgValuesMap avm = argparser.getLinkedArgs(linkedId); + if (value == null) + { + Assert.assertTrue(avm.containsArg(a), + "Arg value for " + a.argString() + + " not applied correctly to linkedId '" + linkedId + + "'"); + } + else + { + ArgValues avs = avm.getArgValues(a); + ArgValue av = avs.getArgValue(); + String v = av.getValue(); + value = new File(value).getAbsolutePath(); + Assert.assertEquals(v, value, "Arg value for " + a.argString() + + " not applied correctly to linkedId '" + linkedId + "'"); + } + } + + } + + @DataProvider(name = "allLinkedIdsData") + public Object[][] allLinkedIdsData() + { + return new Object[][] { + // + /* + */ + { "--open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --image={dirname}/{basename}.png --close", + Arg.CLOSE, new String[] + { null, null, null }, + null }, + { "--open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --output={dirname}/{basename}.stk --close", + Arg.OUTPUT, new String[] + { "test/jalview/bin/argparser/testfiles/test1.stk", + "test/jalview/bin/argparser/testfiles/test2.stk", + "test/jalview/bin/argparser/testfiles/test3.stk", }, + null }, + { "--open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --image={dirname}/{basename}.png --close", + Arg.IMAGE, new String[] + { "test/jalview/bin/argparser/testfiles/test1.png", + "test/jalview/bin/argparser/testfiles/test2.png", + "test/jalview/bin/argparser/testfiles/test3.png", }, + null }, + // + }; + } }