incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From svanteschub...@apache.org
Subject svn commit: r1702611 - in /incubator/odf/trunk/validator/src/test: java/org/odftoolkit/odfvalidator/InvalidPackageTest.java java/org/odftoolkit/odfvalidator/OdfValidatorTestBase.java resources/ resources/encrypted-with-pwd_hello.odt
Date Sat, 12 Sep 2015 10:41:19 GMT
Author: svanteschubert
Date: Sat Sep 12 10:41:19 2015
New Revision: 1702611

URL: http://svn.apache.org/r1702611
Log:
Encrypted test file for validator with expected exception, plus error message for none existent
test file

Added:
    incubator/odf/trunk/validator/src/test/resources/encrypted-with-pwd_hello.odt   (with
props)
Modified:
    incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java
    incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/OdfValidatorTestBase.java
    incubator/odf/trunk/validator/src/test/resources/   (props changed)

Modified: incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java?rev=1702611&r1=1702610&r2=1702611&view=diff
==============================================================================
--- incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java
(original)
+++ incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java
Sat Sep 12 10:41:19 2015
@@ -21,6 +21,8 @@
  ************************************************************************/
 package org.odftoolkit.odfvalidator;
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import junit.framework.Assert;
 import org.junit.Test;
 
@@ -107,4 +109,20 @@ public class InvalidPackageTest extends
 		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: 2 errors, no warnings"));
 	}
+
+	@Test
+	public void validateEncryptedODT() {
+		String output = "";
+		try {
+            // password: hello
+            String name = "encrypted-with-pwd_hello.odt";
+			output = doValidation(name, null);
+		} catch (Throwable t) {
+                StringWriter errors = new StringWriter();
+                t.printStackTrace(new PrintWriter(errors));
+			Assert.fail(t.toString() + "\n" + errors.toString());
+		}
+		Assert.assertTrue(output.contains("Fatal: ZIP entry 'mimetype': only DEFLATED entries can
have EXT descriptor"));
+        java.util.logging.Logger.getLogger(getClass().getName()).info("Test result:\n"+ output);
+	}
 }

Modified: incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/OdfValidatorTestBase.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/OdfValidatorTestBase.java?rev=1702611&r1=1702610&r2=1702611&view=diff
==============================================================================
--- incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/OdfValidatorTestBase.java
(original)
+++ incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/OdfValidatorTestBase.java
Sat Sep 12 10:41:19 2015
@@ -25,6 +25,7 @@ package org.odftoolkit.odfvalidator;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.PrintStream;
+import java.util.logging.Level;
 import org.junit.Ignore;
 
 @Ignore
@@ -38,14 +39,17 @@ public class OdfValidatorTestBase {
         ByteArrayOutputStream aOut = new ByteArrayOutputStream();
         PrintStream aPOut = new PrintStream(aOut);
         InputStream aIn = getClass().getClassLoader().getResourceAsStream(aFileName);
+        if(aIn == null){
+            java.util.logging.Logger.getLogger(OdfValidatorTestBase.class.getName()).log(Level.SEVERE,
"The input document '" + aFileName + "' could not be found!");
+        }
         aValidator.validateStream(aPOut, aIn, aFileName, OdfValidatorMode.VALIDATE, null);
         return aOut.toString();
     }
 
     String doValidation(String aFileName, OdfVersion aVersion, OdfValidatorMode odfValidatorMode)
throws Exception {
-        return doValidation(aFileName, aVersion, odfValidatorMode, false);				
-	}		
-	
+        return doValidation(aFileName, aVersion, odfValidatorMode, false);
+	}
+
     String doValidation(String aFileName, OdfVersion aVersion, OdfValidatorMode odfValidatorMode,
boolean htmlOutput) throws Exception {
         ODFValidator aValidator = new ODFValidator(null, Logger.LogLevel.INFO, htmlOutput,
aVersion, true);
         ByteArrayOutputStream aOut = new ByteArrayOutputStream();
@@ -55,8 +59,8 @@ public class OdfValidatorTestBase {
 		try {
 			aValidator.validateStream(aPOut, aIn, aFileName, odfValidatorMode, filter);
 		} catch (Exception e) {
-			e.printStackTrace(aPOut);			
+			e.printStackTrace(aPOut);
 		}
-        return aOut.toString();							
-	}				
+        return aOut.toString();
+	}
 }

Propchange: incubator/odf/trunk/validator/src/test/resources/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Sep 12 10:41:19 2015
@@ -0,0 +1 @@
+.~lock.helloEncrypted.odt#

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

Propchange: incubator/odf/trunk/validator/src/test/resources/encrypted-with-pwd_hello.odt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message