comparison test/org/tmatesoft/hg/test/TestAuxUtilities.java @ 448:2e402c12ebc6 smartgit3

Issue 31: Revlog#walk() fails with AIOOBE when start > 0
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 06 Jun 2012 21:23:57 +0200
parents d0e5dc3cae6e
children 7bcfbc255f48
comparison
equal deleted inserted replaced
447:056f724bdc21 448:2e402c12ebc6
243 Assert.fail(ex.toString()); 243 Assert.fail(ex.toString());
244 } 244 }
245 } 245 }
246 }); 246 });
247 class ParentInspectorCheck implements HgDataFile.ParentInspector { 247 class ParentInspectorCheck implements HgDataFile.ParentInspector {
248 private int i; 248 private int i, c;
249 private Nodeid[] all; 249 private Nodeid[] all;
250 private final int start;
250 251
251 public ParentInspectorCheck(int start, int total) { 252 public ParentInspectorCheck(int start, int total) {
252 i = start; 253 this.start = start;
254 i = start; // revision index being iterated
255 c = 0; // index/counter of visited revisions
253 all = new Nodeid[total]; 256 all = new Nodeid[total];
254 } 257 }
255 258
256 public void next(int localRevision, Nodeid revision, int parent1, int parent2, Nodeid nidParent1, Nodeid nidParent2) { 259 public void next(int localRevision, Nodeid revision, int parent1, int parent2, Nodeid nidParent1, Nodeid nidParent2) {
257 Assert.assertEquals(i++, localRevision); 260 Assert.assertEquals(i++, localRevision);
258 all[localRevision] = revision; 261 all[c++] = revision;
259 Assert.assertNotNull(revision); 262 Assert.assertNotNull(revision);
260 Assert.assertFalse(localRevision == 0 && (parent1 != -1 || parent2 != -1)); 263 Assert.assertFalse(localRevision == 0 && (parent1 != -1 || parent2 != -1));
261 Assert.assertFalse(localRevision > 0 && parent1 == -1 && parent2 == -1); 264 Assert.assertFalse(localRevision > 0 && parent1 == -1 && parent2 == -1);
262 if (parent1 != -1) { 265 if (parent1 != -1) {
263 Assert.assertNotNull(nidParent1); 266 Assert.assertNotNull(nidParent1);
264 // deliberately ==, not asserEquals to ensure same instance 267 if (parent1 >= start) {
265 Assert.assertTrue(nidParent1 == all[parent1]); 268 // deliberately ==, not asserEquals to ensure same instance
269 Assert.assertTrue(nidParent1 == all[parent1-start]);
270 }
266 } 271 }
267 if (parent2 != -1) { 272 if (parent2 != -1) {
268 Assert.assertNotNull(nidParent2); 273 Assert.assertNotNull(nidParent2);
269 Assert.assertTrue(nidParent2 == all[parent2]); 274 if (parent2 >= start) {
275 Assert.assertTrue(nidParent2 == all[parent2-start]);
276 }
270 } 277 }
271 } 278 }
272 }; 279 };
273 fileNode.walk(0, TIP, new ParentInspectorCheck(0, fileNode.getRevisionCount())); 280 fileNode.walk(0, TIP, new ParentInspectorCheck(0, fileNode.getRevisionCount()));
274 assert fileNode.getRevisionCount() > 2 : "prereq"; // need at least few revisions 281 assert fileNode.getRevisionCount() > 2 : "prereq"; // need at least few revisions