# HG changeset patch # User Artem Tikhomirov # Date 1342113072 -7200 # Node ID e74580e24feb2d282460dbaab2320a93c03f938a # Parent 9c9d09111aeeccc568dbd1bfe7ed886a99501e3b Test for subprogress diff -r 9c9d09111aee -r e74580e24feb cmdline/org/tmatesoft/hg/console/Main.java --- a/cmdline/org/tmatesoft/hg/console/Main.java Thu Jul 12 18:07:51 2012 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Main.java Thu Jul 12 19:11:12 2012 +0200 @@ -106,7 +106,6 @@ public static void main(String[] args) throws Exception { Main m = new Main(args); // m.checkWalkFileRevisions(); -// m.checkSubProgress(); // m.buildFileLog(); // m.testConsoleLog(); // m.testTreeTraversal(); @@ -134,42 +133,6 @@ // hg --debug manifest --rev 150 | grep cmdline/org/tmatesoft/hg/console/Main.java hgRepo.getManifest().walkFileRevisions(Path.create("cmdline/org/tmatesoft/hg/console/Main.java"), new ManifestDump(), 100, 150, 200, 210, 300); } - - // no repo - // FIXME as test, perhaps in TestAuxUtilities - private void checkSubProgress() { - ProgressSupport ps = new ProgressSupport() { - private int units; - - public void start(int totalUnits) { - units = totalUnits; - System.out.printf("%d:", totalUnits); - - } - public void worked(int wu) { - for (int i = 0; i < wu; i++) { - System.out.print(units-- == 0 ? '!' : '.'); - } - } - public void done() { - System.out.println("DONE"); - } - }; - ps.start(10); - ProgressSupport.Sub s1 = new ProgressSupport.Sub(ps, 3); - ProgressSupport.Sub s2 = new ProgressSupport.Sub(ps, 7); - s1.start(10); - s1.worked(1); - s1.worked(2); - s1.worked(3); - s1.worked(4); - s1.done(); - // - s2.start(5); - s2.worked(3); - s2.worked(2); - s2.done(); - } private void buildFileLog() throws Exception { final long start = System.nanoTime(); diff -r 9c9d09111aee -r e74580e24feb test/org/tmatesoft/hg/test/OutputParser.java --- a/test/org/tmatesoft/hg/test/OutputParser.java Thu Jul 12 18:07:51 2012 +0200 +++ b/test/org/tmatesoft/hg/test/OutputParser.java Thu Jul 12 19:11:12 2012 +0200 @@ -71,7 +71,7 @@ public String next() { if (next) { - String rv = m.group(); + String rv = m.group(1); next = m.find(); return rv; } diff -r 9c9d09111aee -r e74580e24feb test/org/tmatesoft/hg/test/TestAuxUtilities.java --- a/test/org/tmatesoft/hg/test/TestAuxUtilities.java Thu Jul 12 18:07:51 2012 +0200 +++ b/test/org/tmatesoft/hg/test/TestAuxUtilities.java Thu Jul 12 19:11:12 2012 +0200 @@ -48,6 +48,7 @@ import org.tmatesoft.hg.util.CancelledException; import org.tmatesoft.hg.util.Pair; import org.tmatesoft.hg.util.Path; +import org.tmatesoft.hg.util.ProgressSupport; /** * @@ -84,6 +85,56 @@ } return rebuilt; } + + + @Test + public void checkSubProgress() { + // no repo + class PS implements ProgressSupport { + + @SuppressWarnings("unused") + public int units; + public int worked; + public boolean done = false; + + public void start(int totalUnits) { + units = totalUnits; + } + public void worked(int wu) { + worked += wu; + } + public void done() { + done = true; + } + }; + PS ps = new PS(); + ps.start(10); + ProgressSupport.Sub s1 = new ProgressSupport.Sub(ps, 3); + ProgressSupport.Sub s2 = new ProgressSupport.Sub(ps, 7); + s1.start(10); + s1.worked(1); + s1.worked(1); + s1.worked(1); + s1.worked(1); + // so far s1 consumed 40% of total 3 units + assertEquals(1, ps.worked); + s1.done(); + // now s1 consumed 100% of total 3 units + assertEquals(3, ps.worked); + assertFalse(ps.done); + // + s2.start(5); + s2.worked(3); + // s2 consumed 60% (3/5) of ps's 7 units + // 3+4 == 3 from s1 + 0.6*7 + assertEquals(3 + 4, ps.worked); + s2.worked(2); + assertEquals(3 + 7, ps.worked); + assertFalse(ps.done); + s2.done(); + //assertTrue(ps.done); + } + static class CancelImpl implements CancelSupport { private boolean shallStop = false;