Mercurial > hg4j
changeset 327:3f09b8c19142
Tests for Revlog.Inspectors
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 04 Oct 2011 07:24:44 +0200 |
parents | d42a45a2c9d6 |
children | a674b8590362 |
files | src/org/tmatesoft/hg/repo/Revlog.java test/org/tmatesoft/hg/test/TestAuxUtilities.java |
diffstat | 2 files changed, 44 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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); }
--- 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]); + } + } + }); + } }