# HG changeset patch # User Artem Tikhomirov # Date 1317705884 -7200 # Node ID 3f09b8c1914237be2c685fbeffcfda72c2cb9572 # Parent d42a45a2c9d63e6666744abc9218762cf650d56f Tests for Revlog.Inspectors diff -r d42a45a2c9d6 -r 3f09b8c19142 src/org/tmatesoft/hg/repo/Revlog.java --- a/src/org/tmatesoft/hg/repo/Revlog.java Tue Oct 04 06:28:01 2011 +0200 +++ b/src/org/tmatesoft/hg/repo/Revlog.java Tue Oct 04 07:24:44 2011 +0200 @@ -270,6 +270,7 @@ @Experimental public interface ParentInspector extends Inspector { + // XXX document whether parentX is -1 or a constant (BAD_REVISION? or dedicated?) void next(int localRevision, Nodeid revision, int parent1, int parent2, Nodeid nidParent1, Nodeid nidParent2); } diff -r d42a45a2c9d6 -r 3f09b8c19142 test/org/tmatesoft/hg/test/TestAuxUtilities.java --- a/test/org/tmatesoft/hg/test/TestAuxUtilities.java Tue Oct 04 06:28:01 2011 +0200 +++ b/test/org/tmatesoft/hg/test/TestAuxUtilities.java Tue Oct 04 07:24:44 2011 +0200 @@ -28,6 +28,7 @@ import org.tmatesoft.hg.internal.ArrayHelper; import org.tmatesoft.hg.repo.HgChangelog; import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; +import org.tmatesoft.hg.repo.HgDataFile; import org.tmatesoft.hg.repo.HgManifest; import org.tmatesoft.hg.repo.HgManifest.Flags; import org.tmatesoft.hg.repo.HgRepository; @@ -213,4 +214,46 @@ // good! } } + + @Test + public void testRevlogInspectors() throws Exception { // FIXME move to better place + HgRepository repository = Configuration.get().find("branches-1"); // any repo + repository.getChangelog().walk(0, TIP, new HgChangelog.RevisionInspector() { + + public void next(int localRevision, Nodeid revision, int linkedRevision) { + Assert.assertEquals(localRevision, linkedRevision); + } + }); + final HgDataFile fileNode = repository.getFileNode("file1"); + fileNode.walk(0, TIP, new HgDataFile.RevisionInspector() { + int i = 0; + + public void next(int localRevision, Nodeid revision, int linkedRevision) { + Assert.assertEquals(i++, localRevision); + Assert.assertEquals(fileNode.getChangesetLocalRevision(localRevision), linkedRevision); + Assert.assertEquals(fileNode.getRevision(localRevision), revision); + } + }); + fileNode.walk(0, TIP, new HgDataFile.ParentInspector() { + int i = 0; + Nodeid[] all = new Nodeid[fileNode.getRevisionCount()]; + + public void next(int localRevision, Nodeid revision, int parent1, int parent2, Nodeid nidParent1, Nodeid nidParent2) { + Assert.assertEquals(i++, localRevision); + all[localRevision] = revision; + Assert.assertNotNull(revision); + Assert.assertFalse(localRevision == 0 && (parent1 != -1 || parent2 != -1)); + Assert.assertFalse(localRevision > 0 && parent1 == -1 && parent2 == -1); + if (parent1 != -1) { + Assert.assertNotNull(nidParent1); + // deliberately ==, not asserEquals to ensure same instance + Assert.assertTrue(nidParent1 == all[parent1]); + } + if (parent2 != -1) { + Assert.assertNotNull(nidParent2); + Assert.assertTrue(nidParent2 == all[parent2]); + } + } + }); + } }