Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestStatus.java @ 397:5e95b0da26f2 smartgit3
Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 23 Feb 2012 15:31:57 +0100 |
parents | cdea37239b01 |
children | fdc1db8f7f61 |
comparison
equal
deleted
inserted
replaced
393:728708de3597 | 397:5e95b0da26f2 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 TMate Software Ltd | 2 * Copyright (c) 2011-2012 TMate Software Ltd |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or modify | 4 * This program is free software; you can redistribute it and/or modify |
5 * it under the terms of the GNU General Public License as published by | 5 * it under the terms of the GNU General Public License as published by |
6 * the Free Software Foundation; version 2 of the License. | 6 * the Free Software Foundation; version 2 of the License. |
7 * | 7 * |
20 import static org.junit.Assert.assertEquals; | 20 import static org.junit.Assert.assertEquals; |
21 import static org.junit.Assert.assertTrue; | 21 import static org.junit.Assert.assertTrue; |
22 import static org.tmatesoft.hg.core.HgStatus.Kind.*; | 22 import static org.tmatesoft.hg.core.HgStatus.Kind.*; |
23 import static org.tmatesoft.hg.repo.HgRepository.TIP; | 23 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
24 | 24 |
25 import java.io.File; | |
25 import java.util.ArrayList; | 26 import java.util.ArrayList; |
26 import java.util.Collection; | 27 import java.util.Collection; |
27 import java.util.Collections; | 28 import java.util.Collections; |
28 import java.util.HashMap; | 29 import java.util.HashMap; |
29 import java.util.LinkedHashMap; | 30 import java.util.LinkedHashMap; |
525 StatusCollector sc = new StatusCollector(); | 526 StatusCollector sc = new StatusCollector(); |
526 cmd.execute(sc); | 527 cmd.execute(sc); |
527 // shall pass without exception | 528 // shall pass without exception |
528 assertTrue(sc.getErrors().isEmpty()); | 529 assertTrue(sc.getErrors().isEmpty()); |
529 } | 530 } |
531 | |
532 /** | |
533 * Issue 24: IllegalArgumentException in FilterDataAccess | |
534 * There were two related defects in RevlogStream | |
535 * a) for compressedLen == 0, a byte was read and FilterDataAccess (of length 0, but it didn't help too much) was created - first byte happen to be 0. | |
536 * Patch was not applied (userDataAccess.isEmpty() check thanks to Issue 22) | |
537 * b) That FilterDataAccess (with 0 size represents patch more or less relevantly, but didn't represent actual revision) get successfully | |
538 * reassigned as lastUserData for the next iteration. And at the next step attempt to apply patch recorded in the next revision failed | |
539 * because baseRevisionData is 0 length FilterDataAccess | |
540 * | |
541 * Sample: | |
542 * status-5/file1 has 3 revisions, second is zero-length patch: | |
543 * Index Offset Packed Actual Base Rev | |
544 * 0: 0 8 7 0 | |
545 * DATA | |
546 * 1: 8 0 7 0 | |
547 * NO DATA | |
548 * 2: 8 14 6 0 | |
549 * PATCH | |
550 */ | |
551 @Test | |
552 public void testZeroLengthPatchAgainstNonEmptyBaseRev() throws Exception{ | |
553 repo = Configuration.get().find("status-5"); | |
554 // pretend we modified file in the working copy | |
555 // for HgWorkingCopyStatusCollector to go and retrieve its content from repository | |
556 File f1 = new File(repo.getWorkingDir(), "file1"); | |
557 f1.setLastModified(System.currentTimeMillis()); | |
558 // | |
559 HgStatusCommand cmd = new HgStatusCommand(repo); | |
560 cmd.all(); | |
561 StatusCollector sc = new StatusCollector(); | |
562 cmd.execute(sc); | |
563 // shall pass without exception | |
564 // | |
565 for (Map.Entry<Path,Status> e : sc.getErrors().entrySet()) { | |
566 System.out.printf("%s : (%s %s)\n", e.getKey(), e.getValue().getKind(), e.getValue().getMessage()); | |
567 } | |
568 assertTrue(sc.getErrors().isEmpty()); | |
569 } | |
570 | |
571 /** | |
572 * Issue 26: UnsupportedOperationException when patching empty base revision | |
573 * | |
574 * Sample: | |
575 * status-5/file2 has 3 revisions, second is patch (complete revision content in a form of the patch) for empty base revision: | |
576 * Index Offset Packed Actual Base Rev | |
577 * 0: 0 0 0 0 | |
578 * NO DATA | |
579 * 1: 0 20 7 0 | |
580 * PATCH: 0..0, 7:garbage | |
581 * 2: 20 16 7 0 | |
582 */ | |
583 @Test | |
584 public void testPatchZeroLengthBaseRevision() throws Exception { | |
585 repo = Configuration.get().find("status-5"); | |
586 // touch the file to force content retrieval | |
587 File f2 = new File(repo.getWorkingDir(), "file2"); | |
588 f2.setLastModified(System.currentTimeMillis()); | |
589 // | |
590 HgStatusCommand cmd = new HgStatusCommand(repo); | |
591 cmd.all(); | |
592 StatusCollector sc = new StatusCollector(); | |
593 cmd.execute(sc); | |
594 // shall pass without exception | |
595 // | |
596 for (Map.Entry<Path,Status> e : sc.getErrors().entrySet()) { | |
597 System.out.printf("%s : (%s %s)\n", e.getKey(), e.getValue().getKind(), e.getValue().getMessage()); | |
598 } | |
599 assertTrue(sc.getErrors().isEmpty()); | |
600 } | |
530 | 601 |
531 | 602 |
532 /* | 603 /* |
533 * With warm-up of previous tests, 10 runs, time in milliseconds | 604 * With warm-up of previous tests, 10 runs, time in milliseconds |
534 * 'hg status -A': Native client total 953 (95 per run), Java client 94 (9) | 605 * 'hg status -A': Native client total 953 (95 per run), Java client 94 (9) |