juanco      2002/09/28 08:57:11

  Modified:    jrcs     plain_ant_build.xml
               jrcs/src/java/org/apache/commons/jrcs/diff ChangeDelta.java
                        Diff.java Revision.java
               jrcs/src/java/org/apache/commons/jrcs/rcs Archive.java
                        Node.java Phrases.java
               jrcs/src/test/org/apache/commons/jrcs/diff DiffTest.java
               jrcs/src/test/org/apache/commons/jrcs/rcs ArchiveTest.java
  Added:       jrcs/src/test/org/apache/commons/jrcs AllTests.java
               jrcs/src/test/org/apache/commons/jrcs/rcs
                        ChangeDeltaTest.java
  Log:
  Fixed ChangeDelta to make the gerated RCS text be compatibe with RCS/CVS. Added
  a test case for that.
  
  The code was adding the wrong line ending character in several places. Fixed.
  
  Archive.save() was not operational. Fixed it, and added a test case.
  
  Revision  Changes    Path
  1.2       +6 -4      jakarta-commons-sandbox/jrcs/plain_ant_build.xml
  
  Index: plain_ant_build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jrcs/plain_ant_build.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- plain_ant_build.xml       17 Jun 2002 16:33:40 -0000      1.1
  +++ plain_ant_build.xml       28 Sep 2002 15:57:10 -0000      1.2
  @@ -116,7 +116,7 @@
     <property file="build.properties" />
   
     <property name="app.name" value="jrcs" />
  -  <property name="version"  value="0.1.2" />
  +  <property name="version"  value="0.1.4" />
   
     <property name="src.dir"   value="${basedir}/src" />
     <property name="java.dir"  value="${src.dir}/java" />
  @@ -196,6 +196,7 @@
         javacchome="${javacc.lib.dir}" 
                optimizetokenmanager="true"
       />
  +    <echo message="parser built" />  
     </target>
   
     <target name="rcs" depends="prepare,diff,parser">
  @@ -260,7 +261,7 @@
       <javadoc packagenames="org.apache.commons.jrcs.*"
                sourcepath="${java.dir}" 
                destdir="${javadoc}" 
  -             classpath="${libs}"
  +             classpath="${libs};classes"
                                 author="true"
                version="true" 
                private="yes"
  @@ -270,7 +271,8 @@
                bottom="Copyright 2002 the Apache Software Foundation&lt;br&gt;
                        Copyright &#169; 1999-2001 Juancarlo A&#241;ez, Caracas, 
Venezuela.&lt;br&gt;
                                         All rights reserved&lt;br&gt;.
  -                                                     
http://www.suigeneris.org/jrcs";>
  +                     http://www.suigeneris.org/jrcs";
  +            >
       </javadoc>
     </target>
   
  
  
  
  1.2       +2 -2      
jakarta-commons-sandbox/jrcs/src/java/org/apache/commons/jrcs/diff/ChangeDelta.java
  
  Index: ChangeDelta.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jrcs/src/java/org/apache/commons/jrcs/diff/ChangeDelta.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ChangeDelta.java  28 May 2002 16:45:44 -0000      1.1
  +++ ChangeDelta.java  28 Sep 2002 15:57:10 -0000      1.2
  @@ -116,7 +116,7 @@
           s.append(original.size());
           s.append(EOL);
           s.append("a");
  -        s.append(original.rcsfrom());
  +        s.append(original.rcsto());
           s.append(" ");
           s.append(revised.size());
           s.append(EOL);
  
  
  
  1.3       +15 -6     
jakarta-commons-sandbox/jrcs/src/java/org/apache/commons/jrcs/diff/Diff.java
  
  Index: Diff.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jrcs/src/java/org/apache/commons/jrcs/diff/Diff.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Diff.java 28 Sep 2002 01:01:13 -0000      1.2
  +++ Diff.java 28 Sep 2002 15:57:10 -0000      1.3
  @@ -76,7 +76,7 @@
    *
    * <p>Text is represented as <code>Object[]</code> because
    * the diff engine is capable of handling more than plain ascci. In fact,
  - * arrays of any type that implements 
  + * arrays of any type that implements
    * {@link java.lang.Object#hashCode hashCode()} and
    * {@link java.lang.Object#equals equals()}
    * correctly can be subject to differencing using this
  @@ -92,6 +92,7 @@
   {
   
       public static final String NL = System.getProperty("line.separator");
  +    public static final String RCS_EOL = "\n";
   
   
       static final int NOT_FOUND_i = -2;
  @@ -150,7 +151,8 @@
           return i;
       }
   
  -    public Revision diff(Object[] rev) throws DifferentiationFailedException
  +    public Revision diff(Object[] rev)
  +        throws DifferentiationFailedException
       {
           Map eqs = buildEqSet(orig, rev);
           int[] indx = buildIndex(eqs, orig, NOT_FOUND_i);
  @@ -201,9 +203,16 @@
               {/* void */
               }
           }
  -        if (!compare(deltas.patch(orig), rev))
  +        try
           {
  -            throw new DifferentiationFailedException();
  +            if (!compare(deltas.patch(orig), rev))
  +            {
  +                throw new DifferentiationFailedException();
  +            }
  +        }
  +        catch(PatchFailedException e)
  +        {
  +          throw new DifferentiationFailedException(e.getMessage());
           }
           return deltas;
       }
  @@ -248,7 +257,7 @@
   
       /**
        * Converts an array of {@link Object Object} to a string
  -     * using {@link Diff#NL Diff.NL} 
  +     * using {@link Diff#NL Diff.NL}
        * as the line separator.
        * @param o the array of objects.
        */
  
  
  
  1.2       +4 -4      
jakarta-commons-sandbox/jrcs/src/java/org/apache/commons/jrcs/diff/Revision.java
  
  Index: Revision.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jrcs/src/java/org/apache/commons/jrcs/diff/Revision.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Revision.java     28 May 2002 16:45:45 -0000      1.1
  +++ Revision.java     28 Sep 2002 15:57:10 -0000      1.2
  @@ -80,7 +80,7 @@
   
       List deltas_ = new LinkedList();
   
  -    
  +
       /**
        * Creates an empty Revision.
        */
  @@ -137,7 +137,7 @@
       /**
        * Applies the series of deltas in this revision as patches to
        * the given text.
  -     * @param src the text to patch, which the method doesn't change. 
  +     * @param src the text to patch, which the method doesn't change.
        * @return the resulting text after the patches have been applied.
        * @throws PatchFailedException if any of the patches cannot be applied.
        */
  @@ -215,7 +215,7 @@
       }
   
       /**
  -     * Converts this delta into its RCS style string representation 
  +     * Converts this delta into its RCS style string representation
        * using the default line separator.
        */
       public String toRCSString()
  
  
  
  1.2       +34 -24    
jakarta-commons-sandbox/jrcs/src/java/org/apache/commons/jrcs/rcs/Archive.java
  
  Index: Archive.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jrcs/src/java/org/apache/commons/jrcs/rcs/Archive.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Archive.java      28 May 2002 16:45:47 -0000      1.1
  +++ Archive.java      28 Sep 2002 15:57:11 -0000      1.2
  @@ -84,18 +84,18 @@
    * Handling of RCS/CVS style version control archives.
    *
    *
  - * <p>JRCS is a library that knows how to manipulate the archive files produced 
  - * by the RCS and CVS version control systems. JRCS is not intended to replace 
  + * <p>JRCS is a library that knows how to manipulate the archive files produced
  + * by the RCS and CVS version control systems. JRCS is not intended to replace
    * neither tool. JRCS was written to be able create archive analysis tools
  - * that can do things like identify hot spots in the source code, 
  - * measure the contributions by each developer, 
  + * that can do things like identify hot spots in the source code,
  + * measure the contributions by each developer,
    * or assess how bugs make it in.</p>
    *
    * <p>The reasons why JRCS has the ability do do check-ins and save archives
    * is API symmetry, and to simplify the writing of unit tests.</p>
    *
  - * <p><b>CAVEAT UTILITOR:</b> Do not make modifications to your archives with JRCS. 
  - * There needs to be an important amount of additional testing 
  + * <p><b>CAVEAT UTILITOR:</b> Do not make modifications to your archives with JRCS.
  + * There needs to be an important amount of additional testing
    * before it's safe to do that.</p>
    *
    * <p>The {@link org.apache.commons.jrcs.rcs rcs} package implements the
  @@ -106,24 +106,24 @@
    * <p>The {@link org.apache.commons.jrcs.diff diff} package implements
    * the differencing engine that JRCS uses. The engine has the power of Unix diff,
    * is simple to understand, and can be used independently of the archive handling
  - * functionality. The entry point to the differencing engine is class 
  + * functionality. The entry point to the differencing engine is class
    * {@link org.apache.commons.jrcs.diff.Diff Diff}.</p>
    *
    * <p>Within this library, the word <i>text</i> means a unit of information
    * subject to version control. The word <i>revision</i> means a particular
  - * version of a text. Each <i>revision</i> has a <i>version number</i> 
  + * version of a text. Each <i>revision</i> has a <i>version number</i>
    * associated to it. <i>Version numbers</i> are dot-separated lists of numbers.
    * Version numbers with an odd number of dots indicate revisions, while those
    * with an even number of dots (including zero dots) designate branches.</p>
    *
    * <p>Revisions of a text are represented as <code>Object[]</code> because
    * the diff engine is capable of handling more than plain text. In fact,
  - * arrays of any type that implements 
  + * arrays of any type that implements
    * {@link java.lang.Object#hashCode hashCode()} and
    * {@link java.lang.Object#equals equals()}
    * correctly can be subject to differencing and version control using this
    * library.</p>
  - * 
  + *
    * <p>To create an empty archive use:
    * <code><pre>
    *   Archive archive = new Archive();
  @@ -137,14 +137,14 @@
    * </p>
    *
    * <p>You can also initialize archives from streams.</p>
  - * 
  + *
    * <p>To retreive a revision from an archive use:
    * <code><pre>
    *   String versionNumber = "1.2";
    *   Object[] text = archive.getRevision(versionNumber);
    * </pre></code>
    * </p>
  - * 
  + *
    * <p>You can also retreive revisions in such a way that each item
    * is annotated with the version number of the revision in which it was
    * last changed or added. To retrieve annotated text use:
  @@ -155,7 +155,7 @@
    *       System.out.println(text[i].revision.version);
    * </pre></code>
    * </p>
  - * 
  + *
    * <p>This class is NOT thread safe.</p>
    * @see org.apache.commons.jrcs.diff
    *
  @@ -228,8 +228,7 @@
           // now add the _head node
           this.head = (TrunkNode) newNode(vernum, null);
           this.head.setText(text);
  -        this.head.setLog("Initial revision\n");
  -        this.setDesc(desc);
  +        this.head.setLog(desc);
       }
   
       /**
  @@ -279,7 +278,7 @@
       public void save(OutputStream output)
               throws IOException
       {
  -        new OutputStreamWriter(output).write(toCharArray());
  +        output.write(toByteArray());
       }
   
       /**
  @@ -555,6 +554,17 @@
           return toString(Archive.RCS_NEWLINE).toCharArray();
       }
   
  +    /**
  +     * Return a text image of the archive as a char array.
  +     * This is useful for writing the archive to a file without
  +     * having the characters be interpreted by the writer.
  +     * @return The archive image.
  +     */
  +    public byte[] toByteArray()
  +    {
  +        return toString(Archive.RCS_NEWLINE).getBytes();
  +    }
  +
   
       /**
        * Returns the path from the head node to the node identified
  @@ -1039,12 +1049,12 @@
           String deltaText;
           if (headAdd)
           {
  -            deltaText = Diff.diff(text, head.getText()).toRCSString();
  +            deltaText = Diff.diff(text, head.getText()).toRCSString(RCS_NEWLINE);
           }
           else
           {
               Object[] oldText = path.patch().toArray();
  -            deltaText = Diff.diff(oldText, text).toRCSString();
  +            deltaText = Diff.diff(oldText, text).toRCSString(RCS_NEWLINE);
           }
           if (deltaText.length() == 0)
           {
  @@ -1127,10 +1137,10 @@
       }
   
       /**
  -     * Return the list of nodes between the head revision and 
  +     * Return the list of nodes between the head revision and
        * the root revision.
        */
  -    public Node[] changeLog() 
  +    public Node[] changeLog()
       {
           return changeLog(head.version);
       }
  @@ -1163,10 +1173,10 @@
           {
              throw new NodeNotFoundException(earliest.toString());
           }
  -        
  +
           List result = new LinkedList();
  -        
  -        Node node = last; 
  +
  +        Node node = last;
           while (node != null)
           {
               result.add(0, node);
  
  
  
  1.2       +13 -6     
jakarta-commons-sandbox/jrcs/src/java/org/apache/commons/jrcs/rcs/Node.java
  
  Index: Node.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jrcs/src/java/org/apache/commons/jrcs/rcs/Node.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Node.java 28 May 2002 16:45:52 -0000      1.1
  +++ Node.java 28 Sep 2002 15:57:11 -0000      1.2
  @@ -319,7 +319,11 @@
        */
       protected void setLog(String value)
       {
  -        log = value;
  +      // the last newline belongs to the file format
  +      if(value.endsWith(Archive.RCS_NEWLINE))
  +         log = value.substring(0, value.length()-1);
  +      else
  +         log = value;
       }
   
       /**
  @@ -576,7 +580,7 @@
        */
       public void toString(StringBuffer s)
       {
  -        toString(s, "\n");
  +        toString(s, Archive.RCS_NEWLINE);
       }
   
       /**
  @@ -595,7 +599,7 @@
           s.append(EOL);
           s.append(version.toString() + EOL);
   
  -        s.append("_date");
  +        s.append("date");
           if (date != null)
           {
               DateFormat formatter = dateFormat;
  @@ -667,7 +671,10 @@
           s.append(version.toString() + EOL);
   
           s.append("log" + EOL);
  -        s.append(Archive.quoteString(log));
  +        if (log.length() == 0)
  +          s.append(Archive.quoteString(""));
  +        else // add a newline after the comment
  +          s.append(Archive.quoteString(log + EOL));
           s.append(EOL);
   
           if (phrases != null)
  @@ -676,7 +683,7 @@
           }
   
           s.append("text" + EOL);
  -        s.append(Archive.quoteString(Diff.arrayToString(text) + "\n"));
  +        s.append(Archive.quoteString(Diff.arrayToString(text, EOL) + EOL));
           s.append(EOL);
   
           if (branches != null)
  
  
  
  1.2       +2 -2      
jakarta-commons-sandbox/jrcs/src/java/org/apache/commons/jrcs/rcs/Phrases.java
  
  Index: Phrases.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jrcs/src/java/org/apache/commons/jrcs/rcs/Phrases.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Phrases.java      28 May 2002 16:45:52 -0000      1.1
  +++ Phrases.java      28 Sep 2002 15:57:11 -0000      1.2
  @@ -89,7 +89,7 @@
       public String toString()
       {
           StringBuffer s = new StringBuffer();
  -        toString(s, "\n");
  +        toString(s, Archive.RCS_NEWLINE);
           return s.toString();
       }
   }
  
  
  
  1.1                  
jakarta-commons-sandbox/jrcs/src/test/org/apache/commons/jrcs/AllTests.java
  
  Index: AllTests.java
  ===================================================================
  
  package org.apache.commons.jrcs;
  
  import junit.framework.*;
  
  public class AllTests extends TestCase {
  
    public AllTests(String s) {
      super(s);
    }
  
    public static Test suite() {
      TestSuite suite = new TestSuite();
      suite.addTestSuite(org.apache.commons.jrcs.diff.DiffTest.class);
      suite.addTestSuite(org.apache.commons.jrcs.rcs.ArchiveTest.class);
      suite.addTestSuite(org.apache.commons.jrcs.rcs.ChangeDeltaTest.class);
      suite.addTestSuite(org.apache.commons.jrcs.rcs.KeywordsFormatTest.class);
      //suite.addTestSuite(org.apache.commons.jrcs.rcs.ParsingTest.class);
      return suite;
    }
  }
  
  
  
  1.2       +2 -2      
jakarta-commons-sandbox/jrcs/src/test/org/apache/commons/jrcs/diff/DiffTest.java
  
  Index: DiffTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jrcs/src/test/org/apache/commons/jrcs/diff/DiffTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DiffTest.java     28 May 2002 16:45:43 -0000      1.1
  +++ DiffTest.java     28 Sep 2002 15:57:11 -0000      1.2
  @@ -142,9 +142,9 @@
       assertEquals(ChangeDelta.class, revision.getDelta(0).getClass());
       assertTrue(Diff.compare(revision.patch(original), rev2));
       assertEquals("d7 3" + Diff.NL +
  -                 "a7 2" + Diff.NL +
  +                 "a9 2" + Diff.NL +
                    "[7] seven revised" + Diff.NL +
  -                 "[8] eight revised" + Diff.NL, 
  +                 "[8] eight revised" + Diff.NL,
                    revision.toRCSString());
     }
   
  
  
  
  1.3       +30 -39    
jakarta-commons-sandbox/jrcs/src/test/org/apache/commons/jrcs/rcs/ArchiveTest.java
  
  Index: ArchiveTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jrcs/src/test/org/apache/commons/jrcs/rcs/ArchiveTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ArchiveTest.java  28 Sep 2002 00:23:36 -0000      1.2
  +++ ArchiveTest.java  28 Sep 2002 15:57:11 -0000      1.3
  @@ -109,7 +109,7 @@
           "[8] eight  $" + "State: trash 8 $",
           "[9] nine   $Locker$",
           "[10] ten   $" + "RCSfile: trash #10 $ "
  -                 + "$" + "Revision: trash #10 $ " 
  +                 + "$" + "Revision: trash #10 $ "
                    + "$" +  "Author: trash $",
           ""
       };
  @@ -123,11 +123,11 @@
           "[8] eight  $" + "State: Exp $",
           "[9] nine   $Locker$",
           "[10] ten   $" + "RCSfile: test_file,v $ "
  -                 + "$" + "Revision: 1.2 $ "  
  +                 + "$" + "Revision: 1.2 $ "
                    + "$" +  "Author: " + user + " $",
           ""
       };
  -    
  +
       Object[] v1_3 = new String[]{
           "[1] one changed",
           "[2] two",
  @@ -192,7 +192,7 @@
   
       public void setUp()
       {
  -        archive = new Archive(v1_1, "A simple test file\n");
  +        archive = new Archive(v1_1, "A simple test file");
           archive.setFileName("/a/test/path/test_file,v");
       }
   
  @@ -226,7 +226,7 @@
   
           Node[] log = archive.changeLog();
           assertNotNull("log is null", log);
  -        assertEquals(    1, log.length);    
  +        assertEquals(    1, log.length);
           assertEquals("1.1", log[0].version.toString());
       }
   
  @@ -235,7 +235,7 @@
               RCSException
       {
           testAdd1_1();
  -        archive.addRevision(v1_2, "Added 3.1, deleted 6\n");
  +        archive.addRevision(v1_2, "Added 3.1, deleted 6");
           Object[] rev = archive.getRevision();
           assertEquals("1.2", archive.head.version.toString());
           assertEquals(ToString.arrayToString(v1_2), ToString.arrayToString(rev));
  @@ -249,7 +249,7 @@
   
           Node[] log = archive.changeLog();
           assertNotNull("log is null", log);
  -        assertEquals(    2, log.length);    
  +        assertEquals(    2, log.length);
           assertEquals("1.1", log[0].version.toString());
           assertEquals("1.2", log[1].version.toString());
       }
  @@ -259,7 +259,7 @@
               RCSException
        {
          testAdd1_1();
  -       archive.addRevision(v1_2_with_keywords, "Added revision with keywords\n");
  +       archive.addRevision(v1_2_with_keywords, "Added revision with keywords");
          Object[] rev = archive.getRevision();
   
          assertEquals("1.2", archive.head.version.toString());
  @@ -279,7 +279,7 @@
               RCSException
       {
           testAdd1_2();
  -        archive.addRevision(v1_3, "Changed 1\n");
  +        archive.addRevision(v1_3, "Changed 1");
           Object[] rev = archive.getRevision();
           assertTrue(Diff.compare(v1_3, rev));
           assertNull(archive.addRevision(v1_3, "should not be added"));
  @@ -292,7 +292,7 @@
   
           Node[] log = archive.changeLog();
           assertNotNull("log is null", log);
  -        assertEquals(    3, log.length);    
  +        assertEquals(    3, log.length);
           assertEquals("1.1", log[0].version.toString());
           assertEquals("1.2", log[1].version.toString());
           assertEquals("1.3", log[2].version.toString());
  @@ -303,12 +303,17 @@
               RCSException
       {
           testAdd1_3();
  -        archive.addRevision(v1_2_1_1, "1.2.1", "Added 2.1, changed 4, added 5.1\n");
  +        archive.addRevision(v1_2_1_1, "1.2.1", "Added 2.1, changed 4, added 5.1");
           String filestr = archive.toString();
  -        Object[] file = Diff.stringToArray(filestr);
  -        String diff = Diff.diff(file, sampleFile).toRCSString(Diff.NL);
  -        String delta = ToString.arrayToString(deltaOverDates) + Diff.NL;
  -        assertEquals("delta over dates", delta, diff);
  +        String[] file = (String[]) Diff.stringToArray(filestr);
  +
  +        for(int i = 0; i < sampleFile.length && i < file.length; i++)
  +        {
  +            if(!sampleFile[i].startsWith("date"))
  +                assertEquals("line " + i, sampleFile[i], file[i]);
  +        }
  +        assertEquals("file size", sampleFile.length, file.length);
  +
           Object[] rev = archive.getRevision("1.2.1");
           assertTrue("diffs equal", Diff.compare(v1_2_1_1, rev));
           assertNull("should not be added", archive.addRevision(v1_2_1_1, "1.2.1", 
"should not be added"));
  @@ -327,14 +332,14 @@
   
           Node[] log = archive.changeLog(new Version("1.2.1"));
           assertNotNull("log is null", log);
  -        assertEquals(    3, log.length);    
  +        assertEquals(    3, log.length);
           assertEquals("1.1",     log[0].version.toString());
           assertEquals("1.2",     log[1].version.toString());
           assertEquals("1.2.1.1", log[2].version.toString());
   
           log = archive.changeLog(new Version("1.2.1"), new Version("1.2"));
           assertNotNull("log is null", log);
  -        assertEquals(    2, log.length);    
  +        assertEquals(    2, log.length);
           assertEquals("1.2",     log[0].version.toString());
           assertEquals("1.2.1.1", log[1].version.toString());
       }
  @@ -345,7 +350,7 @@
       {
           testAdd1_3();
           archive.setBranch("1.2.0");
  -        archive.addRevision(v1_2_1_1, "Added 2.1, changed 4\n");
  +        archive.addRevision(v1_2_1_1, "Added 2.1, changed 4");
           String file = archive.toString();
           Object[] rev = archive.getRevision("1.2.1.1");
           assertTrue(Diff.compare(v1_2_1_1, rev));
  @@ -382,7 +387,7 @@
   
           Node[] log = archive.changeLog(new Version("1.2.8"));
           assertNotNull("log is null", log);
  -        assertEquals(    5, log.length);    
  +        assertEquals(    5, log.length);
           assertEquals("1.1",     log[0].version.toString());
           assertEquals("1.2"    , log[1].version.toString());
           assertEquals("1.2.8.2", log[2].version.toString());
  @@ -422,6 +427,7 @@
           archive.addRevision(new String[] { "user" }, "original");
       }
   
  +
       String[] sampleFile = {
           "head\t1.3;",
           "access;",
  @@ -453,8 +459,7 @@
           "",
           "",
           "desc",
  -        "@A simple test file",
  -        "@",
  +        "@@",
           "",
           "",
           "1.3",
  @@ -474,7 +479,7 @@
           "1.2",
           "log",
           "@Added 3.1, deleted 6",
  -        "@",
  +        "@",  // 50
           "text",
           "@d1 1",
           "a1 1",
  @@ -484,7 +489,7 @@
           "",
           "1.2.1.1",
           "log",
  -        "@Added 2.1, changed 4, added 5.1",
  +        "@Added 2.1, changed 4, added 5.1",  //60
           "@",
           "text",
           "@a2 1",
  @@ -494,12 +499,12 @@
           "[4] four changed",
           "a6 1",
           "[5.1]",
  -        "@",
  +        "@", // 70
           "",
           "",
           "1.1",
           "log",
  -        "@Initial revision",
  +        "@A simple test file",
           "@",
           "text",
           "@d4 1",
  @@ -508,18 +513,4 @@
           "@"
       };
   
  -    String[] deltaOverDates = {
  -        "d9 1",
  -        "a9 1",
  -        "date\t99.08.24.16.58.59;\tauthor juanca;\tstate Exp;",
  -        "d14 1",
  -        "a14 1",
  -        "date\t99.08.24.16.57.54;\tauthor juanca;\tstate Exp;",
  -        "d20 1",
  -        "a20 1",
  -        "date\t99.08.24.16.56.51;\tauthor juanca;\tstate Exp;",
  -        "d25 1",
  -        "a25 1",
  -        "date\t99.08.24.17.00.30;\tauthor juanca;\tstate Exp;"
  -    };
   }
  
  
  
  1.1                  
jakarta-commons-sandbox/jrcs/src/test/org/apache/commons/jrcs/rcs/ChangeDeltaTest.java
  
  Index: ChangeDeltaTest.java
  ===================================================================
  package org.apache.commons.jrcs.rcs;
  
  import junit.framework.*;
  import org.apache.commons.jrcs.rcs.*;
  import org.apache.commons.jrcs.diff.*;
  import org.apache.commons.jrcs.util.*;
  
  public class ChangeDeltaTest extends TestCase
  {
      private Archive archive = null;
  
      String[] v1 = new String[]
      {
          "1",
          "2",
          "3",
          "4",
      };
      Object[] v2 = new String[]
      {
          "a0",
          "1",
          // deleted two lines
          // added three lines
          "a1",
          "a2",
          "a3",
          "4"
      };
  
      public ChangeDeltaTest(String name)
      {
          super (name);
      }
  
      protected void setUp()
          throws Exception
      {
          archive = new Archive(v1, "original");
          super.setUp();
      }
  
      protected void tearDown()
          throws Exception
      {
          archive = null;
          super.tearDown();
      }
  
      public static Test suite()
      {
          return new TestSuite(ArchiveTest.class);
      }
  
      public void testChangeDelta()
          throws Exception
      {
          archive.addRevision(v2, "applied change delta");
          archive.addRevision(v1, "back to original");
  
          String[] rcsFile = (String[]) Diff.stringToArray(archive.toString());
          for(int i = 0; i < rcsFile.length && i < expectedFile.length; i++)
          {
              if (! rcsFile[i].startsWith("date"))
                  assertEquals("line " + i, expectedFile[i], rcsFile[i]);
          }
          assertEquals("file size", expectedFile.length, rcsFile.length);
      }
  
      public void testFileSave()
         throws Exception
     {
        this.testChangeDelta();
        String filePath =System.getProperty("user.home") + java.io.File.separator + 
"jrcs_test.rcs";
        archive.save(filePath);
  
        Archive newArc = new Archive(filePath);
        new java.io.File(filePath).delete();
  
        String[] rcsFile = (String[]) Diff.stringToArray(newArc.toString());
        for(int i = 0; i < rcsFile.length && i < expectedFile.length; i++)
        {
            System.err.println(i + " " +rcsFile[i]);
            if (! rcsFile[i].startsWith("date"))
                assertEquals("line " + i, expectedFile[i], rcsFile[i]);
        }
        assertEquals("file size", expectedFile.length, rcsFile.length);
  
        assertEquals(archive.toString(), newArc.toString());
     }
  
  
      String[] expectedFile = {
              "head\t1.3;",          // 0
              "access;",             // 1
              "symbols;",            // 2
              "locks; strict;",      // 3
              "comment\t@# @;",      // 4
              "",                    // 5
              "",                    // 6
              "1.3",                 // 7
              "date\t2002.09.28.12.55.36;\tauthor juanca;\tstate Exp;",
              "branches;",           // 9
              "next\t1.2;",          //10
              "",                    //11
              "1.2",                 //12
              "date\t2002.09.28.12.53.53;\tauthor juanca;\tstate Exp;",
              "branches;",           //14
              "next\t1.1;",          //15
              "",                    //16
              "1.1",                 //17
              "date\t2002.09.28.12.52.55;\tauthor juanca;\tstate Exp;",
              "branches;",           //19
              "next\t;",             //20
              "",                    //21
              "",                    //22
              "desc",                //23
              "@@",                  //24
              "",                    //25
              "",                    //26
              "1.3",                 //27
              "log",                 //28
              "@back to original",   //29
              "@",                   //30
              "text",                //31
              "@1",                  //32
              "2",                   //33
              "3",                   //34
              "4",                   //35
              "@",                   //36
              "",                    //37
              "",                    //38
              "1.2",                 //39
              "log",                 //40
              "@applied change delta",  //41
              "@",                   //42
              "text",                //43
              "@a0 1",               //44
              "a0",                  //45
              "d2 2",                //46
              "a3 3",                //47
              "a1",                  //48
              "a2",                  //49
              "a3",                  //50
              "@",                   //51
              "",                    //52
              "",                    //53
              "1.1",                 //54
              "log",                 //55
              "@original",           //56
              "@",                   //57
              "text",
              "@d1 1",
              "d3 3",
              "a5 2",
              "2",
              "3",
              "@"
      };
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to