Mercurial > hg4j
diff 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 |
line wrap: on
line diff
--- a/test/org/tmatesoft/hg/test/TestByteChannel.java Wed Mar 02 01:06:09 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestByteChannel.java Wed Mar 09 05:22:17 2011 +0100 @@ -16,12 +16,13 @@ */ package org.tmatesoft.hg.test; -import java.util.Arrays; +import static org.junit.Assert.assertArrayEquals; import org.junit.Assert; -import org.tmatesoft.hg.core.HgRepoFacade; +import org.junit.Test; import org.tmatesoft.hg.internal.ByteArrayChannel; import org.tmatesoft.hg.repo.HgDataFile; +import org.tmatesoft.hg.repo.HgRepository; /** * @@ -30,27 +31,57 @@ */ public class TestByteChannel { + private HgRepository repo; + public static void main(String[] args) throws Exception { - HgRepoFacade rf = new HgRepoFacade(); - rf.init(); - HgDataFile file = rf.getRepository().getFileNode("src/org/tmatesoft/hg/internal/KeywordFilter.java"); - for (int i = file.getLastRevision(); i >= 0; i--) { - System.out.print("Content for revision:" + i); - compareContent(file, i); - System.out.println(" OK"); - } +// HgRepoFacade rf = new HgRepoFacade(); +// rf.init(); +// HgDataFile file = rf.getRepository().getFileNode("src/org/tmatesoft/hg/internal/KeywordFilter.java"); +// for (int i = file.getLastRevision(); i >= 0; i--) { +// System.out.print("Content for revision:" + i); +// compareContent(file, i); +// System.out.println(" OK"); +// } //CatCommand cmd = rf.createCatCommand(); } - private static void compareContent(HgDataFile file, int rev) throws Exception { - byte[] oldAccess = file.content(rev); +// private static void compareContent(HgDataFile file, int rev) throws Exception { +// byte[] oldAccess = file.content(rev); +// ByteArrayChannel ch = new ByteArrayChannel(); +// file.content(rev, ch); +// byte[] newAccess = ch.toArray(); +// Assert.assertArrayEquals(oldAccess, newAccess); +// // don't trust anyone (even JUnit) +// if (!Arrays.equals(oldAccess, newAccess)) { +// throw new RuntimeException("Failed:" + rev); +// } +// } + + @Test + public void testContent() throws Exception { + repo = Configuration.get().find("log-1"); + final byte[] expectedContent = new byte[] { 'a', ' ', 13, 10 }; ByteArrayChannel ch = new ByteArrayChannel(); - file.content(rev, ch, false); - byte[] newAccess = ch.toArray(); - Assert.assertArrayEquals(oldAccess, newAccess); - // don't trust anyone (even JUnit) - if (!Arrays.equals(oldAccess, newAccess)) { - throw new RuntimeException("Failed:" + rev); - } + repo.getFileNode("dir/b").content(0, ch); + assertArrayEquals(expectedContent, ch.toArray()); + repo.getFileNode("d").content(HgRepository.TIP, ch = new ByteArrayChannel() ); + assertArrayEquals(expectedContent, ch.toArray()); + } + + @Test + public void testStripMetadata() throws Exception { + repo = Configuration.get().find("log-1"); + ByteArrayChannel ch = new ByteArrayChannel(); + HgDataFile dir_b = repo.getFileNode("dir/b"); + Assert.assertTrue(dir_b.isCopy()); + Assert.assertEquals("b", dir_b.getCopySourceName().toString()); + Assert.assertEquals("e44751cdc2d14f1eb0146aa64f0895608ad15917", dir_b.getCopySourceRevision().toString()); + dir_b.content(0, ch); + // assert rawContent has 1 10 ... 1 10 + assertArrayEquals("a \r\n".getBytes(), ch.toArray()); + // + // try once again to make sure metadata records/extracts correct offsets + dir_b.content(0, ch = new ByteArrayChannel()); + assertArrayEquals("a \r\n".getBytes(), ch.toArray()); } }