ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs ManifestTest.java
Date Thu, 14 Feb 2002 00:22:22 GMT
conor       02/02/13 16:22:22

  Modified:    src/etc/testcases/taskdefs manifest.xml
               src/main/org/apache/tools/ant/taskdefs Manifest.java
               src/testcases/org/apache/tools/ant BuildFileTest.java
               src/testcases/org/apache/tools/ant/taskdefs
                        ManifestTest.java
  Log:
  Improve coverage of manifest unit tests
  
  Revision  Changes    Path
  1.4       +25 -0     jakarta-ant/src/etc/testcases/taskdefs/manifest.xml
  
  Index: manifest.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/manifest.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -u -r1.3 -r1.4
  --- manifest.xml	12 Dec 2001 14:52:35 -0000	1.3
  +++ manifest.xml	14 Feb 2002 00:22:22 -0000	1.4
  @@ -6,10 +6,16 @@
   
     <target name="test1">
       <jar file="mftest1.jar" manifest="manifests/test1.mf"/>
  +    <unjar src="mftest1.jar" dest="manifests">
  +      <include name="META-INF/MANIFEST.MF"/>
  +    </unjar>
     </target>
     
     <target name="test2">
       <jar file="mftest2.jar" manifest="manifests/test2.mf"/>
  +    <unjar src="mftest2.jar" dest="manifests">
  +      <include name="META-INF/MANIFEST.MF"/>
  +    </unjar>
     </target>
     
     <target name="test3">
  @@ -41,6 +47,9 @@
           </section>
         </manifest>
       </jar>
  +    <unjar src="mftest8.jar" dest="manifests">
  +      <include name="META-INF/MANIFEST.MF"/>
  +    </unjar>
     </target>
   
     <target name="test9">
  @@ -98,12 +107,27 @@
           <attribute name="class-Path" value="Test4"/>
         </manifest>
       </jar>
  +    <unjar src="mftest14.jar" dest="manifests">
  +      <include name="META-INF/MANIFEST.MF"/>
  +    </unjar>
     </target>
   
     <target name="testNoFile">
       <manifest />
     </target>
   
  +  <target name="testLongLine">
  +    <jar file="mftestLongLine.jar">
  +      <manifest>
  +        <attribute name="Class-path" 
  +                   value="${test.longline}"/>
  +      </manifest>
  +    </jar>
  +    <unjar src="mftestLongLine.jar" dest="manifests">
  +      <include name="META-INF/MANIFEST.MF"/>
  +    </unjar>
  +  </target>
  +
     <target name="testReplace">
       <copy file="manifests/test2.mf" toFile="mftest.mf" />
       <manifest file="mftest.mf" />
  @@ -120,5 +144,6 @@
       <delete>
         <fileset dir="." includes="mftest*"/>
       </delete>
  +    <delete dir="manifests/META-INF"/>
     </target>
   </project>
  
  
  
  1.18      +55 -5     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Manifest.java
  
  Index: Manifest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Manifest.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -w -u -r1.17 -r1.18
  --- Manifest.java	21 Jan 2002 09:18:56 -0000	1.17
  +++ Manifest.java	14 Feb 2002 00:22:22 -0000	1.18
  @@ -392,6 +392,18 @@
           }
   
           /**
  +         * Get a attribute of the section
  +         *
  +         * @param attributeName the name of the attribute
  +         * @return a Manifest.Attribute instance if the attribute is 
  +         *         single-valued, otherwise a Vector of Manifest.Attribute 
  +         *         instances.
  +         */
  +        public Object getAttribute(String attributeName) {
  +            return attributes.get(attributeName.toLowerCase());
  +        }
  +        
  +        /**
            * Get the value of the attribute with the name given.
            *
            * @param attributeName the name of the attribute to be returned.
  @@ -497,8 +509,8 @@
               for (Enumeration e = attributes.keys(); e.hasMoreElements();) {
                   String attributeName = (String)e.nextElement();
                   Object attributeValue  = attributes.get(attributeName);
  -                Object rshAttributeValue = rhsSection.attributes.get(attributeName);
  -                if (!attributeValue.equals(rshAttributeValue)) {
  +                Object rhsAttributeValue = rhsSection.attributes.get(attributeName);
  +                if (!attributeValue.equals(rhsAttributeValue)) {
                       return false;
                   }
               }
  @@ -599,7 +611,7 @@
           if (section.getName() == null) {
               throw new BuildException("Sections must have a name");
           }
  -        sections.put(section.getName().toLowerCase(), section);
  +        sections.put(section.getName(), section);
       }
   
       public void addConfiguredAttribute(Attribute attribute) throws ManifestException {
  @@ -624,7 +636,7 @@
               Section ourSection = (Section)sections.get(sectionName);
               Section otherSection = (Section)other.sections.get(sectionName);
               if (ourSection == null) {
  -                sections.put(sectionName.toLowerCase(), otherSection);
  +                sections.put(sectionName, otherSection);
               }
               else {
                   ourSection.merge(otherSection);
  @@ -725,7 +737,7 @@
   
           for (Enumeration e = sections.elements(); e.hasMoreElements();) {
               Section section = (Section)e.nextElement();
  -            Section rhsSection = (Section)rhsManifest.sections.get(section.getName().toLowerCase());
  +            Section rhsSection = (Section)rhsManifest.sections.get(section.getName());
               if (!section.equals(rhsSection)) {
                   return false;
               }
  @@ -752,6 +764,44 @@
           mode = m;
       }
   
  +    /**
  +     * Get the version of the manifest
  +     *
  +     * @return the manifest's version string
  +     */
  +    public String getManifestVersion() {
  +        return manifestVersion;
  +    }
  +    
  +    /**
  +     * Get the main section of the manifest
  +     *
  +     * @return the main section of the manifest
  +     */
  +    public Section getMainSection() {
  +        return mainSection;
  +    }
  +
  +    /**
  +     * Get a particular section from the manifest
  +     *
  +     * @param name the name of the section desired.
  +     * @return the specified section or null if that section 
  +     * does not exist in the manifest
  +     */
  +    public Section getSection(String name) {
  +        return (Section)sections.get(name);
  +    }
  +    
  +    /**
  +     * Get the section names in this manifest.
  +     *
  +     * @return an Enumeration of section names
  +     */
  +    public Enumeration getSectionNames() {
  +        return sections.keys();
  +    }
  +    
       /**
        * Create or update the Manifest when used as a task.
        */
  
  
  
  1.9       +9 -0      jakarta-ant/src/testcases/org/apache/tools/ant/BuildFileTest.java
  
  Index: BuildFileTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/BuildFileTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -w -u -r1.8 -r1.9
  --- BuildFileTest.java	9 Feb 2002 23:23:23 -0000	1.8
  +++ BuildFileTest.java	14 Feb 2002 00:22:22 -0000	1.9
  @@ -243,6 +243,15 @@
           
       }
       
  +    /**
  +     * Get the project which has been configured for a test.
  +     *
  +     * @return the Project instance for this test.
  +     */
  +    protected Project getProject() {
  +        return project;
  +    }
  +    
       protected File getProjectDir() {
           return project.getBaseDir();
       }
  
  
  
  1.4       +56 -9     jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java
  
  Index: ManifestTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -u -r1.3 -r1.4
  --- ManifestTest.java	12 Dec 2001 14:52:35 -0000	1.3
  +++ ManifestTest.java	14 Feb 2002 00:22:22 -0000	1.4
  @@ -58,7 +58,9 @@
   import java.io.FileReader;
   import java.io.IOException;
   import java.util.Date;
  +import java.util.Vector;
   import org.apache.tools.ant.BuildFileTest;
  +import org.apache.tools.ant.Project;
   
   /**
    * Testcase for the Manifest class used in the jar task. 
  @@ -67,6 +69,15 @@
    */
   public class ManifestTest extends BuildFileTest {
   
  +    public static final String EXPANDED_MANIFEST
  +        = "src/etc/testcases/taskdefs/manifests/META-INF/MANIFEST.MF";
  +
  +    public static final String LONG_LINE
  +        = "AReallyLongLineToTestLineBreakingInManifests-ACapabilityWhich" + 
  +          "IsSureToLeadToHundredsOfQuestionsAboutWhyAntMungesManifests" +
  +          "OfCourseTheAnswerIsThatIsWhatTheSpecRequiresAndIfAnythingHas" +
  +          "AProblemWithThatItIsNotABugInAnt";
  +        
       public ManifestTest(String name) {
           super(name);
       }
  @@ -82,15 +93,21 @@
       /**
        * Empty manifest - is OK 
        */
  -    public void test1() {
  +    public void test1() throws ManifestException, IOException {
           executeTarget("test1");
  +        Manifest manifest = getManifest(EXPANDED_MANIFEST);
  +        String version = manifest.getManifestVersion();
  +        assertEquals("Manifest was not created with correct version - ", "1.0", version);
       }
       
       /**
        * Simple Manifest with version 2.0
        */
  -    public void test2() {
  +    public void test2() throws ManifestException, IOException {
           executeTarget("test2");
  +        Manifest manifest = getManifest(EXPANDED_MANIFEST);
  +        String version = manifest.getManifestVersion();
  +        assertEquals("Manifest was not created with correct version - ", "2.0", version);
       }
       
       /**
  @@ -143,8 +160,16 @@
       /**
        * Inline manifest - OK
        */
  -    public void test8() {
  +    public void test8() throws IOException, ManifestException {
           executeTarget("test8");
  +        Manifest manifest = getManifest(EXPANDED_MANIFEST);
  +        Manifest.Section mainSection = manifest.getMainSection();
  +        String classpath = mainSection.getAttributeValue("class-path");
  +        assertEquals("Class-Path attribute was not set correctly - ", "fubar", classpath);
  +        
  +        Manifest.Section testSection = manifest.getSection("Test");
  +        String testAttr = testSection.getAttributeValue("TestAttr");
  +        assertEquals("TestAttr attribute was not set correctly - ", "Test", testAttr);
       }
        
       /**
  @@ -190,8 +215,30 @@
       /**
        * Inline manifest - OK since classpath entries can be duplicated.
        */
  -    public void test14() {
  +    public void test14() throws IOException, ManifestException {
           executeTarget("test14");
  +        Manifest manifest = getManifest(EXPANDED_MANIFEST);
  +        Manifest.Section mainSection = manifest.getMainSection();
  +        String classpath = mainSection.getAttributeValue("class-path");
  +        assertEquals("Class-Path attribute was not set correctly - ", 
  +            "Test1 Test2 Test3 Test4", classpath);
  +        Object classPathAttr = mainSection.getAttribute("class-PATH");
  +        assertTrue("Class path attribute should be a Vector", classPathAttr instanceof
Vector);            
  +    }
  +     
  +    /**
  +     * Tets long line wrapping
  +     */
  +    public void testLongLine() throws IOException, ManifestException {
  +        Project project = getProject();
  +        project.setUserProperty("test.longline", LONG_LINE);
  +        executeTarget("testLongLine");
  +
  +        Manifest manifest = getManifest(EXPANDED_MANIFEST);
  +        Manifest.Section mainSection = manifest.getMainSection();
  +        String classpath = mainSection.getAttributeValue("class-path");
  +        assertEquals("Class-Path attribute was not set correctly - ", 
  +            LONG_LINE, classpath);
       }
        
       /**
  @@ -206,7 +253,7 @@
        */
       public void testReplace() throws IOException, ManifestException {
           executeTarget("testReplace");
  -        Manifest mf = getManifest();
  +        Manifest mf = getManifest("src/etc/testcases/taskdefs/mftest.mf");
           assertNotNull(mf);
           assertEquals(Manifest.getDefaultManifest(), mf);
       }
  @@ -216,7 +263,7 @@
        */
       public void testUpdate() throws IOException, ManifestException {
           executeTarget("testUpdate");
  -        Manifest mf = getManifest();
  +        Manifest mf = getManifest("src/etc/testcases/taskdefs/mftest.mf");
           assertNotNull(mf);
           assertTrue(!Manifest.getDefaultManifest().equals(mf));
           String mfAsString = mf.toString();
  @@ -228,8 +275,8 @@
       /**
        * Reads mftest.mf.
        */
  -    private Manifest getManifest() throws IOException, ManifestException {
  -        FileReader r = new FileReader("src/etc/testcases/taskdefs/mftest.mf");
  +    private Manifest getManifest(String filename) throws IOException, ManifestException
{
  +        FileReader r = new FileReader(filename);
           try {
               return new Manifest(r);
           } finally {
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message