001: /*
002: * ====================================================================
003: *
004: * The Apache Software License, Version 1.1
005: *
006: * Copyright (c) 1999-2003 The Apache Software Foundation.
007: * All rights reserved.
008: *
009: * Redistribution and use in source and binary forms, with or without
010: * modification, are permitted provided that the following conditions
011: * are met:
012: *
013: * 1. Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * 2. Redistributions in binary form must reproduce the above copyright
017: * notice, this list of conditions and the following disclaimer in
018: * the documentation and/or other materials provided with the
019: * distribution.
020: *
021: * 3. The end-user documentation included with the redistribution, if
022: * any, must include the following acknowledgement:
023: * "This product includes software developed by the
024: * Apache Software Foundation (http://www.apache.org/)."
025: * Alternately, this acknowledgement may appear in the software itself,
026: * if and wherever such third-party acknowledgements normally appear.
027: *
028: * 4. The names "The Jakarta Project", "Commons", and "Apache Software
029: * Foundation" must not be used to endorse or promote products derived
030: * from this software without prior written permission. For written
031: * permission, please contact apache@apache.org.
032: *
033: * 5. Products derived from this software may not be called "Apache"
034: * nor may "Apache" appear in their names without prior written
035: * permission of the Apache Software Foundation.
036: *
037: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
038: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
039: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
040: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
041: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
042: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
043: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
044: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
045: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
046: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
047: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
048: * SUCH DAMAGE.
049: * ====================================================================
050: *
051: * This software consists of voluntary contributions made by many
052: * individuals on behalf of the Apache Software Foundation. For more
053: * information on the Apache Software Foundation, please see
054: * <http://www.apache.org/>.
055: *
056: */
057:
058: package org.apache.commons.jrcs.rcs;
059:
060: import junit.framework.Test;
061: import junit.framework.TestCase;
062: import junit.framework.TestSuite;
063:
064: import org.apache.commons.jrcs.diff.Diff;
065:
066: public class ChangeDeltaTest extends TestCase {
067: private Archive archive = null;
068:
069: String[] v1 = new String[] { "1", "2", "3", "4", };
070: Object[] v2 = new String[] { "a0", "1",
071: // deleted two lines
072: // added three lines
073: "a1", "a2", "a3", "4" };
074:
075: public ChangeDeltaTest(String name) {
076: super (name);
077: }
078:
079: protected void setUp() throws Exception {
080: archive = new Archive(v1, "original");
081: super .setUp();
082: }
083:
084: protected void tearDown() throws Exception {
085: archive = null;
086: super .tearDown();
087: }
088:
089: public static Test suite() {
090: return new TestSuite(ArchiveTest.class);
091: }
092:
093: public void testChangeDelta() throws Exception {
094: archive.addRevision(v2, "applied change delta");
095: archive.addRevision(v1, "back to original");
096:
097: String[] rcsFile = (String[]) Diff.stringToArray(archive
098: .toString());
099: for (int i = 0; i < rcsFile.length && i < expectedFile.length; i++) {
100: if (!rcsFile[i].startsWith("date"))
101: assertEquals("line " + i, expectedFile[i], rcsFile[i]);
102: }
103: assertEquals("file size", expectedFile.length, rcsFile.length);
104: }
105:
106: public void testFileSave() throws Exception {
107: this .testChangeDelta();
108: String filePath = System.getProperty("user.home")
109: + java.io.File.separator + "jrcs_test.rcs";
110: archive.save(filePath);
111:
112: Archive newArc = new Archive(filePath);
113: new java.io.File(filePath).delete();
114:
115: String[] rcsFile = (String[]) Diff.stringToArray(newArc
116: .toString());
117: for (int i = 0; i < rcsFile.length && i < expectedFile.length; i++) {
118: if (!rcsFile[i].startsWith("date"))
119: assertEquals("line " + i, expectedFile[i], rcsFile[i]);
120: }
121: assertEquals("file size", expectedFile.length, rcsFile.length);
122:
123: assertEquals(archive.toString(), newArc.toString());
124: }
125:
126: String[] expectedFile = {
127: "head\t1.3;", // 0
128: "access;", // 1
129: "symbols;", // 2
130: "locks; strict;", // 3
131: "comment\t@# @;", // 4
132: "", // 5
133: "", // 6
134: "1.3", // 7
135: "date\t2002.09.28.12.55.36;\tauthor juanca;\tstate Exp;",
136: "branches;", // 9
137: "next\t1.2;", //10
138: "", //11
139: "1.2", //12
140: "date\t2002.09.28.12.53.53;\tauthor juanca;\tstate Exp;",
141: "branches;", //14
142: "next\t1.1;", //15
143: "", //16
144: "1.1", //17
145: "date\t2002.09.28.12.52.55;\tauthor juanca;\tstate Exp;",
146: "branches;", //19
147: "next\t;", //20
148: "", //21
149: "", //22
150: "desc", //23
151: "@@", //24
152: "", //25
153: "", //26
154: "1.3", //27
155: "log", //28
156: "@back to original", //29
157: "@", //30
158: "text", //31
159: "@1", //32
160: "2", //33
161: "3", //34
162: "4", //35
163: "@", //36
164: "", //37
165: "", //38
166: "1.2", //39
167: "log", //40
168: "@applied change delta", //41
169: "@", //42
170: "text", //43
171: "@a0 1", //44
172: "a0", //45
173: "d2 2", //46
174: "a3 3", //47
175: "a1", //48
176: "a2", //49
177: "a3", //50
178: "@", //51
179: "", //52
180: "", //53
181: "1.1", //54
182: "log", //55
183: "@original", //56
184: "@", //57
185: "text", "@d1 1", "d3 3", "a5 2", "2", "3", "@" };
186: }
|