1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package net.sf.statcvs.input;
25
26 import java.io.IOException;
27 import java.io.StringReader;
28
29 import junit.framework.TestCase;
30 import net.sf.statcvs.model.Repository;
31 import net.sf.statcvs.model.Revision;
32 import net.sf.statcvs.model.VersionedFile;
33 import net.sf.statcvs.util.LookaheadReader;
34
35 /**
36 * @author Anja Jentzsch
37 * @author Richard Cyganiak
38 * @version $Id: FileBlockParserTest.java,v 1.21 2002/08/26 20:54:12 cyganiak Exp $
39 */
40 public class FileBlockParserTest extends TestCase {
41
42 private static final String REVISION_DELIMITER = "----------------------------\n";
43 private static final String FILE_DELIMITER = "=============================================================================\n";
44
45 /**
46 * Constructor for FileBlockParserTest.
47 * @param arg0 input
48 */
49 public FileBlockParserTest(final String arg0) {
50 super(arg0);
51 }
52
53 /**
54 * @see TestCase#setUp()
55 */
56 protected void setUp() throws Exception {
57 super.setUp();
58 }
59
60 /**
61 * TODO: move to ParserTest
62 * Method testIsCheckIn.
63 * @throws Exception on error
64 */
65 public void testIsCheckIn() throws Exception {
66 String log = "";
67 log += "RCS file: /home/CVSROOT/TEST/testfile,v\n";
68 log += "Working file: testfile\n";
69 log += "head: 1.3\n";
70 log += "branch:\n";
71 log += "locks: strict\n";
72 log += "access list:\n";
73 log += "symbolic names:\n";
74 log += "keyword substitution: kv\n";
75 log += "total revisions: 1; selected revisions: 1\n";
76 log += "description:\n";
77 log += REVISION_DELIMITER;
78 log += "revision 1.2\n";
79 log += "date: 2002/05/26 15:22:52; author: autor2; state: Exp; lines: +3 -2\n";
80 log += "abc\n";
81 log += REVISION_DELIMITER;
82 log += "revision 1.1\n";
83 log += "date: 2002/05/25 09:52:07; author: ewender; state: Exp;\n";
84 log += "comment text\n";
85 log += FILE_DELIMITER;
86 final VersionedFile file = parseString(log);
87 assertNotNull("file was null", file);
88 assertTrue("rev 1.2 is no checkin", !file.getLatestRevision().isInitialRevision());
89 assertTrue("rev 1.1 is a checkin", file.getInitialRevision().isInitialRevision());
90 assertEquals(2, file.getRevisions().size());
91 }
92
93 /**
94 * TODO: move to FileBuilderTest (=LinesOfCodeTest)
95 * Tests a file that was added on another branch. It should be removed.
96 * @throws Exception on error
97 */
98 public void testFileOnOtherBranch() throws Exception {
99 String log = "";
100 log += "RCS file: /home/bude/cyganiak/cvstest/test/Attic/testfile2,v\n";
101 log += "Working file: testfile2\n";
102 log += "head: 1.1\n";
103 log += "branch:\n";
104 log += "locks: strict\n";
105 log += "access list:\n";
106 log += "symbolic names:\n";
107 log += " branch: 1.1.0.2\n";
108 log += "keyword substitution: kv\n";
109 log += "total revisions: 2; selected revisions: 2\n";
110 log += "description:\n";
111 log += REVISION_DELIMITER;
112 log += "revision 1.1\n";
113 log += "date: 2003/05/02 21:33:31; author: cyganiak; state: dead;\n";
114 log += "branches: 1.1.2;\n";
115 log += "file testfile2 was initially added on branch branch.\n";
116 log += REVISION_DELIMITER;
117 log += "revision 1.1.2.1\n";
118 log += "date: 2003/05/02 21:33:31; author: cyganiak; state: Exp; lines: +1 -0\n";
119 log += "asdf\n";
120 log += FILE_DELIMITER;
121 final Builder builder = new Builder(null, null, null, null);
122 final LookaheadReader lookahead = new LookaheadReader(new StringReader(log));
123 lookahead.nextLine();
124 new CvsFileBlockParser(lookahead, builder, false).parse();
125 final Repository repo = builder.createCvsContent();
126 assertTrue(repo.isEmpty());
127 }
128
129 /**
130 * TODO: move to ParserTest
131 * CVSNT has a slightly different logfile format: After the "lines: +x -y"
132 * part of each revision, there will be a ";" and maybe more fields.
133 * @throws Exception on error
134 */
135 public void testCVSNTLog() throws Exception {
136 String log = "";
137 log += "RCS file: k:/cvsroot/Ellison/index.html,v\n";
138 log += "Working file: index.html\n";
139 log += "head: 1.1\n";
140 log += "branch: 1.1.1\n";
141 log += "locks: strict\n";
142 log += "access list:\n";
143 log += "symbolic names:\n";
144 log += "release_2003_03_31: 1.1.1.1.0.2\n";
145 log += "start: 1.1.1.1\n";
146 log += "Ellison: 1.1.1\n";
147 log += "keyword substitution: kv\n";
148 log += "total revisions: 2;selected revisions: 2\n";
149 log += "description:\n";
150 log += "----------------------------\n";
151 log += "revision 1.2\n";
152 log += "date: 2002/06/04 13:49:00; author: kdavis; state: Exp; lines: +3 -2;\n";
153 log += "branches: 1.1.1;\n";
154 log += "Initial revision\n";
155 log += "----------------------------\n";
156 log += "revision 1.1\n";
157 log += "date: 2002/06/04 13:48:00; author: kdavis; state: Exp;\n";
158 log += "Initial import.\n";
159 log += FILE_DELIMITER;
160 final VersionedFile file = parseString(log);
161 final Revision rev = file.getLatestRevision();
162 assertEquals(2, rev.getReplacedLines());
163 assertEquals(1, rev.getLinesDelta());
164 assertEquals(2, file.getRevisions().size());
165 }
166
167 private VersionedFile parseString(final String log) throws LogSyntaxException, IOException {
168 final Builder builder = new Builder(null, null, null, null);
169 final LookaheadReader lookahead = new LookaheadReader(new StringReader(log));
170 lookahead.nextLine();
171 new CvsFileBlockParser(lookahead, builder, false).parse();
172 final Repository content = builder.createCvsContent();
173 return (VersionedFile) content.getFiles().first();
174 }
175 }