Mercurial > hg4j
comparison hg4j/src/test/java/org/tmatesoft/hg/test/TestByteChannel.java @ 213:6ec4af642ba8 gradle
Project uses Gradle for build - actual changes
| author | Alexander Kitaev <kitaev@gmail.com> |
|---|---|
| date | Tue, 10 May 2011 10:52:53 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 212:edb2e2829352 | 213:6ec4af642ba8 |
|---|---|
| 1 /* | |
| 2 * Copyright (c) 2011 TMate Software Ltd | |
| 3 * | |
| 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 | |
| 6 * the Free Software Foundation; version 2 of the License. | |
| 7 * | |
| 8 * This program is distributed in the hope that it will be useful, | |
| 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11 * GNU General Public License for more details. | |
| 12 * | |
| 13 * For information on how to redistribute this software under | |
| 14 * the terms of a license other than GNU General Public License | |
| 15 * contact TMate Software at support@hg4j.com | |
| 16 */ | |
| 17 package org.tmatesoft.hg.test; | |
| 18 | |
| 19 import static org.junit.Assert.assertArrayEquals; | |
| 20 | |
| 21 import org.junit.Assert; | |
| 22 import org.junit.Test; | |
| 23 import org.tmatesoft.hg.internal.ByteArrayChannel; | |
| 24 import org.tmatesoft.hg.repo.HgDataFile; | |
| 25 import org.tmatesoft.hg.repo.HgRepository; | |
| 26 | |
| 27 /** | |
| 28 * | |
| 29 * @author Artem Tikhomirov | |
| 30 * @author TMate Software Ltd. | |
| 31 */ | |
| 32 public class TestByteChannel { | |
| 33 | |
| 34 private HgRepository repo; | |
| 35 | |
| 36 public static void main(String[] args) throws Exception { | |
| 37 // HgRepoFacade rf = new HgRepoFacade(); | |
| 38 // rf.init(); | |
| 39 // HgDataFile file = rf.getRepository().getFileNode("src/org/tmatesoft/hg/internal/KeywordFilter.java"); | |
| 40 // for (int i = file.getLastRevision(); i >= 0; i--) { | |
| 41 // System.out.print("Content for revision:" + i); | |
| 42 // compareContent(file, i); | |
| 43 // System.out.println(" OK"); | |
| 44 // } | |
| 45 //CatCommand cmd = rf.createCatCommand(); | |
| 46 } | |
| 47 | |
| 48 // private static void compareContent(HgDataFile file, int rev) throws Exception { | |
| 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 }; | |
| 64 ByteArrayChannel ch = new ByteArrayChannel(); | |
| 65 repo.getFileNode("dir/b").content(0, ch); | |
| 66 assertArrayEquals(expectedContent, ch.toArray()); | |
| 67 repo.getFileNode("d").content(HgRepository.TIP, ch = new ByteArrayChannel() ); | |
| 68 assertArrayEquals(expectedContent, ch.toArray()); | |
| 69 } | |
| 70 | |
| 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()); | |
| 86 } | |
| 87 } |
