comparison test/org/tmatesoft/hg/test/TestByteChannel.java @ 157:d5268ca7715b

Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 09 Mar 2011 05:22:17 +0100
parents 3959bffb14e9
children b015f3918120
comparison
equal deleted inserted replaced
156:643ddec3be36 157:d5268ca7715b
14 * the terms of a license other than GNU General Public License 14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.test; 17 package org.tmatesoft.hg.test;
18 18
19 import java.util.Arrays; 19 import static org.junit.Assert.assertArrayEquals;
20 20
21 import org.junit.Assert; 21 import org.junit.Assert;
22 import org.tmatesoft.hg.core.HgRepoFacade; 22 import org.junit.Test;
23 import org.tmatesoft.hg.internal.ByteArrayChannel; 23 import org.tmatesoft.hg.internal.ByteArrayChannel;
24 import org.tmatesoft.hg.repo.HgDataFile; 24 import org.tmatesoft.hg.repo.HgDataFile;
25 import org.tmatesoft.hg.repo.HgRepository;
25 26
26 /** 27 /**
27 * 28 *
28 * @author Artem Tikhomirov 29 * @author Artem Tikhomirov
29 * @author TMate Software Ltd. 30 * @author TMate Software Ltd.
30 */ 31 */
31 public class TestByteChannel { 32 public class TestByteChannel {
32 33
34 private HgRepository repo;
35
33 public static void main(String[] args) throws Exception { 36 public static void main(String[] args) throws Exception {
34 HgRepoFacade rf = new HgRepoFacade(); 37 // HgRepoFacade rf = new HgRepoFacade();
35 rf.init(); 38 // rf.init();
36 HgDataFile file = rf.getRepository().getFileNode("src/org/tmatesoft/hg/internal/KeywordFilter.java"); 39 // HgDataFile file = rf.getRepository().getFileNode("src/org/tmatesoft/hg/internal/KeywordFilter.java");
37 for (int i = file.getLastRevision(); i >= 0; i--) { 40 // for (int i = file.getLastRevision(); i >= 0; i--) {
38 System.out.print("Content for revision:" + i); 41 // System.out.print("Content for revision:" + i);
39 compareContent(file, i); 42 // compareContent(file, i);
40 System.out.println(" OK"); 43 // System.out.println(" OK");
41 } 44 // }
42 //CatCommand cmd = rf.createCatCommand(); 45 //CatCommand cmd = rf.createCatCommand();
43 } 46 }
44 47
45 private static void compareContent(HgDataFile file, int rev) throws Exception { 48 // private static void compareContent(HgDataFile file, int rev) throws Exception {
46 byte[] oldAccess = file.content(rev); 49 // byte[] oldAccess = file.content(rev);
50 // ByteArrayChannel ch = new ByteArrayChannel();
51 // file.content(rev, ch);
52 // byte[] newAccess = ch.toArray();
53 // Assert.assertArrayEquals(oldAccess, newAccess);
54 // // don't trust anyone (even JUnit)
55 // if (!Arrays.equals(oldAccess, newAccess)) {
56 // throw new RuntimeException("Failed:" + rev);
57 // }
58 // }
59
60 @Test
61 public void testContent() throws Exception {
62 repo = Configuration.get().find("log-1");
63 final byte[] expectedContent = new byte[] { 'a', ' ', 13, 10 };
47 ByteArrayChannel ch = new ByteArrayChannel(); 64 ByteArrayChannel ch = new ByteArrayChannel();
48 file.content(rev, ch, false); 65 repo.getFileNode("dir/b").content(0, ch);
49 byte[] newAccess = ch.toArray(); 66 assertArrayEquals(expectedContent, ch.toArray());
50 Assert.assertArrayEquals(oldAccess, newAccess); 67 repo.getFileNode("d").content(HgRepository.TIP, ch = new ByteArrayChannel() );
51 // don't trust anyone (even JUnit) 68 assertArrayEquals(expectedContent, ch.toArray());
52 if (!Arrays.equals(oldAccess, newAccess)) { 69 }
53 throw new RuntimeException("Failed:" + rev); 70
54 } 71 @Test
72 public void testStripMetadata() throws Exception {
73 repo = Configuration.get().find("log-1");
74 ByteArrayChannel ch = new ByteArrayChannel();
75 HgDataFile dir_b = repo.getFileNode("dir/b");
76 Assert.assertTrue(dir_b.isCopy());
77 Assert.assertEquals("b", dir_b.getCopySourceName().toString());
78 Assert.assertEquals("e44751cdc2d14f1eb0146aa64f0895608ad15917", dir_b.getCopySourceRevision().toString());
79 dir_b.content(0, ch);
80 // assert rawContent has 1 10 ... 1 10
81 assertArrayEquals("a \r\n".getBytes(), ch.toArray());
82 //
83 // try once again to make sure metadata records/extracts correct offsets
84 dir_b.content(0, ch = new ByteArrayChannel());
85 assertArrayEquals("a \r\n".getBytes(), ch.toArray());
55 } 86 }
56 } 87 }