Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestAuxUtilities.java @ 327:3f09b8c19142
Tests for Revlog.Inspectors
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Tue, 04 Oct 2011 07:24:44 +0200 |
| parents | d68dcb3b5f49 |
| children | a37ce7145c3f |
comparison
equal
deleted
inserted
replaced
| 326:d42a45a2c9d6 | 327:3f09b8c19142 |
|---|---|
| 26 import org.tmatesoft.hg.core.HgCatCommand; | 26 import org.tmatesoft.hg.core.HgCatCommand; |
| 27 import org.tmatesoft.hg.core.Nodeid; | 27 import org.tmatesoft.hg.core.Nodeid; |
| 28 import org.tmatesoft.hg.internal.ArrayHelper; | 28 import org.tmatesoft.hg.internal.ArrayHelper; |
| 29 import org.tmatesoft.hg.repo.HgChangelog; | 29 import org.tmatesoft.hg.repo.HgChangelog; |
| 30 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; | 30 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
| 31 import org.tmatesoft.hg.repo.HgDataFile; | |
| 31 import org.tmatesoft.hg.repo.HgManifest; | 32 import org.tmatesoft.hg.repo.HgManifest; |
| 32 import org.tmatesoft.hg.repo.HgManifest.Flags; | 33 import org.tmatesoft.hg.repo.HgManifest.Flags; |
| 33 import org.tmatesoft.hg.repo.HgRepository; | 34 import org.tmatesoft.hg.repo.HgRepository; |
| 34 import org.tmatesoft.hg.util.Adaptable; | 35 import org.tmatesoft.hg.util.Adaptable; |
| 35 import org.tmatesoft.hg.util.ByteChannel; | 36 import org.tmatesoft.hg.util.ByteChannel; |
| 211 Assert.fail("Command execution shall not fail silently, exception shall propagate"); | 212 Assert.fail("Command execution shall not fail silently, exception shall propagate"); |
| 212 } catch (CancelledException ex) { | 213 } catch (CancelledException ex) { |
| 213 // good! | 214 // good! |
| 214 } | 215 } |
| 215 } | 216 } |
| 217 | |
| 218 @Test | |
| 219 public void testRevlogInspectors() throws Exception { // FIXME move to better place | |
| 220 HgRepository repository = Configuration.get().find("branches-1"); // any repo | |
| 221 repository.getChangelog().walk(0, TIP, new HgChangelog.RevisionInspector() { | |
| 222 | |
| 223 public void next(int localRevision, Nodeid revision, int linkedRevision) { | |
| 224 Assert.assertEquals(localRevision, linkedRevision); | |
| 225 } | |
| 226 }); | |
| 227 final HgDataFile fileNode = repository.getFileNode("file1"); | |
| 228 fileNode.walk(0, TIP, new HgDataFile.RevisionInspector() { | |
| 229 int i = 0; | |
| 230 | |
| 231 public void next(int localRevision, Nodeid revision, int linkedRevision) { | |
| 232 Assert.assertEquals(i++, localRevision); | |
| 233 Assert.assertEquals(fileNode.getChangesetLocalRevision(localRevision), linkedRevision); | |
| 234 Assert.assertEquals(fileNode.getRevision(localRevision), revision); | |
| 235 } | |
| 236 }); | |
| 237 fileNode.walk(0, TIP, new HgDataFile.ParentInspector() { | |
| 238 int i = 0; | |
| 239 Nodeid[] all = new Nodeid[fileNode.getRevisionCount()]; | |
| 240 | |
| 241 public void next(int localRevision, Nodeid revision, int parent1, int parent2, Nodeid nidParent1, Nodeid nidParent2) { | |
| 242 Assert.assertEquals(i++, localRevision); | |
| 243 all[localRevision] = revision; | |
| 244 Assert.assertNotNull(revision); | |
| 245 Assert.assertFalse(localRevision == 0 && (parent1 != -1 || parent2 != -1)); | |
| 246 Assert.assertFalse(localRevision > 0 && parent1 == -1 && parent2 == -1); | |
| 247 if (parent1 != -1) { | |
| 248 Assert.assertNotNull(nidParent1); | |
| 249 // deliberately ==, not asserEquals to ensure same instance | |
| 250 Assert.assertTrue(nidParent1 == all[parent1]); | |
| 251 } | |
| 252 if (parent2 != -1) { | |
| 253 Assert.assertNotNull(nidParent2); | |
| 254 Assert.assertTrue(nidParent2 == all[parent2]); | |
| 255 } | |
| 256 } | |
| 257 }); | |
| 258 } | |
| 216 } | 259 } |
