Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestAuxUtilities.java @ 478:e74580e24feb
Test for subprogress
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 12 Jul 2012 19:11:12 +0200 |
parents | 5c09a9f2e073 |
children | 1ee452f31187 |
comparison
equal
deleted
inserted
replaced
477:9c9d09111aee | 478:e74580e24feb |
---|---|
46 import org.tmatesoft.hg.util.ByteChannel; | 46 import org.tmatesoft.hg.util.ByteChannel; |
47 import org.tmatesoft.hg.util.CancelSupport; | 47 import org.tmatesoft.hg.util.CancelSupport; |
48 import org.tmatesoft.hg.util.CancelledException; | 48 import org.tmatesoft.hg.util.CancelledException; |
49 import org.tmatesoft.hg.util.Pair; | 49 import org.tmatesoft.hg.util.Pair; |
50 import org.tmatesoft.hg.util.Path; | 50 import org.tmatesoft.hg.util.Path; |
51 import org.tmatesoft.hg.util.ProgressSupport; | |
51 | 52 |
52 /** | 53 /** |
53 * | 54 * |
54 * @author Artem Tikhomirov | 55 * @author Artem Tikhomirov |
55 * @author TMate Software Ltd. | 56 * @author TMate Software Ltd. |
82 int indexInOriginal = sortReverse[i]; | 83 int indexInOriginal = sortReverse[i]; |
83 rebuilt[indexInOriginal-1] = sorted[i]; | 84 rebuilt[indexInOriginal-1] = sorted[i]; |
84 } | 85 } |
85 return rebuilt; | 86 return rebuilt; |
86 } | 87 } |
88 | |
89 | |
90 @Test | |
91 public void checkSubProgress() { | |
92 // no repo | |
93 class PS implements ProgressSupport { | |
94 | |
95 @SuppressWarnings("unused") | |
96 public int units; | |
97 public int worked; | |
98 public boolean done = false; | |
99 | |
100 public void start(int totalUnits) { | |
101 units = totalUnits; | |
102 } | |
103 public void worked(int wu) { | |
104 worked += wu; | |
105 } | |
106 public void done() { | |
107 done = true; | |
108 } | |
109 }; | |
110 PS ps = new PS(); | |
111 ps.start(10); | |
112 ProgressSupport.Sub s1 = new ProgressSupport.Sub(ps, 3); | |
113 ProgressSupport.Sub s2 = new ProgressSupport.Sub(ps, 7); | |
114 s1.start(10); | |
115 s1.worked(1); | |
116 s1.worked(1); | |
117 s1.worked(1); | |
118 s1.worked(1); | |
119 // so far s1 consumed 40% of total 3 units | |
120 assertEquals(1, ps.worked); | |
121 s1.done(); | |
122 // now s1 consumed 100% of total 3 units | |
123 assertEquals(3, ps.worked); | |
124 assertFalse(ps.done); | |
125 // | |
126 s2.start(5); | |
127 s2.worked(3); | |
128 // s2 consumed 60% (3/5) of ps's 7 units | |
129 // 3+4 == 3 from s1 + 0.6*7 | |
130 assertEquals(3 + 4, ps.worked); | |
131 s2.worked(2); | |
132 assertEquals(3 + 7, ps.worked); | |
133 assertFalse(ps.done); | |
134 s2.done(); | |
135 //assertTrue(ps.done); | |
136 } | |
137 | |
87 | 138 |
88 static class CancelImpl implements CancelSupport { | 139 static class CancelImpl implements CancelSupport { |
89 private boolean shallStop = false; | 140 private boolean shallStop = false; |
90 public void stop() { | 141 public void stop() { |
91 shallStop = true; | 142 shallStop = true; |