changeset 478:e74580e24feb

Test for subprogress
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 12 Jul 2012 19:11:12 +0200
parents 9c9d09111aee
children 59b7c817bc4d
files cmdline/org/tmatesoft/hg/console/Main.java test/org/tmatesoft/hg/test/OutputParser.java test/org/tmatesoft/hg/test/TestAuxUtilities.java
diffstat 3 files changed, 52 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- 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();
--- 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;
 					}
--- 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;