incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From devin...@apache.org
Subject svn commit: r1172450 - in /incubator/odf/trunk/validator: ./ nbproject/ test-resources/ test/ test/org/ test/org/odftoolkit/ test/org/odftoolkit/odfvalidator/
Date Mon, 19 Sep 2011 05:37:11 GMT
Author: devinhan
Date: Mon Sep 19 05:37:11 2011
New Revision: 1172450

URL: http://svn.apache.org/viewvc?rev=1172450&view=rev
Log:
changeset:   19:86081cf73879
user:        Michael Stahl <mst@openoffice.org>
date:        Tue Nov 23 11:34:14 2010 +0100
add a JUnit test for new package checks:
 disable previous "test" target in build.xml.
 put runtime libraries and test resource directory on test run classpath.
 add test documents.

Added:
    incubator/odf/trunk/validator/test/
    incubator/odf/trunk/validator/test-resources/
    incubator/odf/trunk/validator/test-resources/testInvalidPkg1.odt   (with props)
    incubator/odf/trunk/validator/test-resources/testInvalidPkg2.odt   (with props)
    incubator/odf/trunk/validator/test-resources/testInvalidPkg3.odt   (with props)
    incubator/odf/trunk/validator/test/org/
    incubator/odf/trunk/validator/test/org/odftoolkit/
    incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/
    incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/InvalidPackageTest.java
Modified:
    incubator/odf/trunk/validator/build.xml
    incubator/odf/trunk/validator/nbproject/project.properties

Modified: incubator/odf/trunk/validator/build.xml
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/build.xml?rev=1172450&r1=1172449&r2=1172450&view=diff
==============================================================================
--- incubator/odf/trunk/validator/build.xml (original)
+++ incubator/odf/trunk/validator/build.xml Mon Sep 19 05:37:11 2011
@@ -201,7 +201,7 @@
         </xslt >
     </target>
 
-    
+    <!--
     <target name="test" depends="jar" description="Test ODFValidator">
         <condition property="mathml.dtd.option" value="" else="-d">
             <istrue value="${use.mathml2.xsd}"/>
@@ -214,8 +214,12 @@
             <arg value="${testdocs.dir}"/>
         </java>
     </target>
-    
-    
+    -->
+
+    <!-- running the tests needs the built jar, so add a dependence here -->
+    <target name="-post-compile-test" depends="jar"/>
+    <target name="-post-compile-test-single" depends="jar"/>
+
 </project>
 
 

Modified: incubator/odf/trunk/validator/nbproject/project.properties
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/nbproject/project.properties?rev=1172450&r1=1172449&r2=1172450&view=diff
==============================================================================
--- incubator/odf/trunk/validator/nbproject/project.properties (original)
+++ incubator/odf/trunk/validator/nbproject/project.properties Mon Sep 19 05:37:11 2011
@@ -25,6 +25,7 @@ file.reference.isorelax-jaxp-bridge-1.0.
 file.reference.isorelax.jar=lib/isorelax.jar
 file.reference.msv.jar=lib/msv.jar
 file.reference.odfdom.jar=lib/odfdom.jar
+file.reference.odfvalidator-test-resources=test-resources
 file.reference.relaxngDatatype.jar=lib/relaxngDatatype.jar
 file.reference.xercesImpl.jar=lib/xercesImpl.jar
 file.reference.xsdlib.jar=lib/xsdlib.jar
@@ -72,7 +73,9 @@ run.classpath=\
 run.jvmargs=-Djavax.xml.validation.SchemaFactory:http://relaxng.org/ns/structure/1.0=org.iso_relax.verifier.jaxp.validation.RELAXNGSchemaFactoryImpl
 -Dorg.iso_relax.verifier.VerifierFactoryLoader=com.sun.msv.verifier.jarv.FactoryLoaderImpl
 run.test.classpath=\
     ${javac.test.classpath}:\
-    ${build.test.classes.dir}
+    ${run.classpath}:\
+    ${build.test.classes.dir}:\
+    ${file.reference.odfvalidator-test-resources}
 source.encoding=UTF-8
 src.dir=src
 test.src.dir=test

Added: incubator/odf/trunk/validator/test-resources/testInvalidPkg1.odt
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/test-resources/testInvalidPkg1.odt?rev=1172450&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/odf/trunk/validator/test-resources/testInvalidPkg1.odt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/odf/trunk/validator/test-resources/testInvalidPkg2.odt
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/test-resources/testInvalidPkg2.odt?rev=1172450&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/odf/trunk/validator/test-resources/testInvalidPkg2.odt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/odf/trunk/validator/test-resources/testInvalidPkg3.odt
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/test-resources/testInvalidPkg3.odt?rev=1172450&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/odf/trunk/validator/test-resources/testInvalidPkg3.odt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/InvalidPackageTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/InvalidPackageTest.java?rev=1172450&view=auto
==============================================================================
--- incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/InvalidPackageTest.java
(added)
+++ incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/InvalidPackageTest.java
Mon Sep 19 05:37:11 2011
@@ -0,0 +1,126 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ *
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.PrintStream;
+import junit.framework.Assert;
+import org.junit.Test;
+
+/** Test some invalid packages.
+ */
+public class InvalidPackageTest {
+    private String doValidation(String file, OdfVersion version) throws Exception
+    {
+            ODFValidator validator = new ODFValidator(null, Logger.LogLevel.INFO, version,
true);
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            PrintStream pout = new PrintStream(out);
+            InputStream is = getClass().getClassLoader().getResourceAsStream(file);
+//            validator.validateFile(pout, f, OdfValidatorMode.VALIDATE, null);
+            validator.validateStream(pout, is, file, OdfValidatorMode.VALIDATE, null);
+//            System.err.println(out.toString());
+            return out.toString();
+    }
+
+    @Test
+    public void validatePackage1() {
+        String output = "";
+        try {
+            String name = "testInvalidPkg1.odt";
+            output = doValidation(name, null);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            Assert.fail(t.toString());
+        }
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/MIMETYPE:Error:The file 'mimetype'
is not the first file in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/MIMETYPE:Error:The file 'mimetype'
shall not be compressed"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/MIMETYPE:Error:There shall
be no extra field for the 'mimetype' file"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/META-INF/manifest.xml:Error:The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt:Info:validation errors found"));
+    }
+
+    @Test
+    public void validatePackage1_V1_1() {
+        String output = "";
+        try {
+            String name = "testInvalidPkg1.odt";
+            output = doValidation(name, OdfVersion.V1_1);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            Assert.fail(t.toString());
+        }
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/MIMETYPE:Warning:The file
'mimetype' is not the first file in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/MIMETYPE:Error:The file 'mimetype'
shall not be compressed"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/MIMETYPE:Error:There shall
be no extra field for the 'mimetype' file"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/META-INF/manifest.xml:Error:The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt:Info:validation errors found"));
+    }
+
+    @Test
+    public void validatePackage2() {
+        String output = "";
+        try {
+            String name = "testInvalidPkg2.odt";
+            output = doValidation(name, null);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            Assert.fail(t.toString());
+        }
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/MIMETYPE:Error:The ODF package
contains no 'mimetype' file"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:Error:The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:Error:The
file 'not_in_manifest' shall be listed in the 'META-INF/manifest.xml' file as it exists in
the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt:Info:validation errors found"));
+    }
+
+    @Test
+    public void validatePackage2_V1_1() {
+        String output = "";
+        try {
+            String name = "testInvalidPkg2.odt";
+            output = doValidation(name, OdfVersion.V1_1);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            Assert.fail(t.toString());
+        }
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/MIMETYPE:Warning:The ODF package
contains no 'mimetype' file"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:Error:The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:Warning:The
file 'not_in_manifest' shall be listed in the 'META-INF/manifest.xml' file as it exists in
the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt:Info:validation errors found"));
+    }
+
+    @Test
+    public void validatePackage3() {
+        String output = "";
+        try {
+            String name = "testInvalidPkg3.odt";
+            output = doValidation(name, null);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            Assert.fail(t.toString());
+        }
+        Assert.assertTrue(output.contains("Error:The ODF package 'testInvalidPkg3.odt' shall
contain the 'META-INF/manifest.xml' file"));
+        Assert.assertTrue(output.contains("testInvalidPkg3.odt:Info:validation errors found"));
+    }
+
+}



Mime
View raw message