Mercurial > jhg
annotate test/org/tmatesoft/hg/test/TestByteChannel.java @ 130:7567f4a42fe5
Correct contact address
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 16 Feb 2011 20:33:31 +0100 |
parents | b1d6208fb517 |
children | aa1629f36482 |
rev | line source |
---|---|
115
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011 TMate Software Ltd |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
130
7567f4a42fe5
Correct contact address
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
121
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
115
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.test; |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import java.util.Arrays; |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import org.junit.Assert; |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import org.tmatesoft.hg.core.RepositoryFacade; |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import org.tmatesoft.hg.internal.ByteArrayChannel; |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import org.tmatesoft.hg.repo.HgDataFile; |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 /** |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 * |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 * @author Artem Tikhomirov |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 * @author TMate Software Ltd. |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 */ |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 public class TestByteChannel { |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 public static void main(String[] args) throws Exception { |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 RepositoryFacade rf = new RepositoryFacade(); |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 rf.init(); |
121
b1d6208fb517
Conditionally apply filters to file content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
116
diff
changeset
|
36 HgDataFile file = rf.getRepository().getFileNode("src/org/tmatesoft/hg/internal/KeywordFilter.java"); |
116
5d13dcaaff39
Test content of each and every revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
115
diff
changeset
|
37 for (int i = file.getRevisionCount() - 1; i >= 0; i--) { |
5d13dcaaff39
Test content of each and every revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
115
diff
changeset
|
38 System.out.print("Content for revision:" + i); |
5d13dcaaff39
Test content of each and every revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
115
diff
changeset
|
39 compareContent(file, i); |
5d13dcaaff39
Test content of each and every revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
115
diff
changeset
|
40 System.out.println(" OK"); |
5d13dcaaff39
Test content of each and every revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
115
diff
changeset
|
41 } |
5d13dcaaff39
Test content of each and every revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
115
diff
changeset
|
42 //CatCommand cmd = rf.createCatCommand(); |
5d13dcaaff39
Test content of each and every revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
115
diff
changeset
|
43 } |
5d13dcaaff39
Test content of each and every revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
115
diff
changeset
|
44 |
5d13dcaaff39
Test content of each and every revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
115
diff
changeset
|
45 private static void compareContent(HgDataFile file, int rev) throws Exception { |
115
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 byte[] oldAccess = file.content(rev); |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 ByteArrayChannel ch = new ByteArrayChannel(); |
121
b1d6208fb517
Conditionally apply filters to file content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
116
diff
changeset
|
48 file.content(rev, ch, false); |
115
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 byte[] newAccess = ch.toArray(); |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 Assert.assertArrayEquals(oldAccess, newAccess); |
116
5d13dcaaff39
Test content of each and every revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
115
diff
changeset
|
51 // don't trust anyone (even JUnit) |
5d13dcaaff39
Test content of each and every revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
115
diff
changeset
|
52 if (!Arrays.equals(oldAccess, newAccess)) { |
5d13dcaaff39
Test content of each and every revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
115
diff
changeset
|
53 throw new RuntimeException("Failed:" + rev); |
5d13dcaaff39
Test content of each and every revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
115
diff
changeset
|
54 } |
115
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 } |
c0cc2535462c
Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 } |