comparison test/org/tmatesoft/hg/test/TestByteChannel.java @ 116:5d13dcaaff39

Test content of each and every revision
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 03 Feb 2011 23:37:21 +0100
parents c0cc2535462c
children b1d6208fb517
comparison
equal deleted inserted replaced
115:c0cc2535462c 116:5d13dcaaff39
17 package org.tmatesoft.hg.test; 17 package org.tmatesoft.hg.test;
18 18
19 import java.util.Arrays; 19 import java.util.Arrays;
20 20
21 import org.junit.Assert; 21 import org.junit.Assert;
22 import org.tmatesoft.hg.core.CatCommand;
23 import org.tmatesoft.hg.core.RepositoryFacade; 22 import org.tmatesoft.hg.core.RepositoryFacade;
24 import org.tmatesoft.hg.internal.ByteArrayChannel; 23 import org.tmatesoft.hg.internal.ByteArrayChannel;
25 import org.tmatesoft.hg.repo.HgDataFile; 24 import org.tmatesoft.hg.repo.HgDataFile;
26 import org.tmatesoft.hg.repo.HgRepository;
27 25
28 /** 26 /**
29 * 27 *
30 * @author Artem Tikhomirov 28 * @author Artem Tikhomirov
31 * @author TMate Software Ltd. 29 * @author TMate Software Ltd.
33 public class TestByteChannel { 31 public class TestByteChannel {
34 32
35 public static void main(String[] args) throws Exception { 33 public static void main(String[] args) throws Exception {
36 RepositoryFacade rf = new RepositoryFacade(); 34 RepositoryFacade rf = new RepositoryFacade();
37 rf.init(); 35 rf.init();
38 HgDataFile file = rf.getRepository().getFileNode("COPYING"); 36 HgDataFile file = rf.getRepository().getFileNode("TODO");
39 int rev = HgRepository.TIP; 37 for (int i = file.getRevisionCount() - 1; i >= 0; i--) {
38 System.out.print("Content for revision:" + i);
39 compareContent(file, i);
40 System.out.println(" OK");
41 }
42 //CatCommand cmd = rf.createCatCommand();
43 }
44
45 private static void compareContent(HgDataFile file, int rev) throws Exception {
40 byte[] oldAccess = file.content(rev); 46 byte[] oldAccess = file.content(rev);
41 ByteArrayChannel ch = new ByteArrayChannel(); 47 ByteArrayChannel ch = new ByteArrayChannel();
42 file.content(rev, ch); 48 file.content(rev, ch);
43 byte[] newAccess = ch.toArray(); 49 byte[] newAccess = ch.toArray();
44 Assert.assertArrayEquals(oldAccess, newAccess); 50 Assert.assertArrayEquals(oldAccess, newAccess);
45 //CatCommand cmd = rf.createCatCommand(); 51 // don't trust anyone (even JUnit)
52 if (!Arrays.equals(oldAccess, newAccess)) {
53 throw new RuntimeException("Failed:" + rev);
54 }
46 } 55 }
47 } 56 }