You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by ss...@apache.org on 2020/04/06 13:37:10 UTC

svn commit: r1876186 - /xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java

Author: ssteiner
Date: Mon Apr  6 13:37:10 2020
New Revision: 1876186

URL: http://svn.apache.org/viewvc?rev=1876186&view=rev
Log:
Fix test on Windows

Modified:
    xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java

Modified: xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java?rev=1876186&r1=1876185&r2=1876186&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java (original)
+++ xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java Mon Apr  6 13:37:10 2020
@@ -19,6 +19,8 @@
 
 package org.apache.xmlgraphics.util.io;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -31,6 +33,8 @@ import org.junit.Test;
 
 import static org.junit.Assert.fail;
 
+import org.apache.commons.io.IOUtils;
+
 /**
  * This test validates that the Base64 encoder/decoders work properly.
  *
@@ -39,7 +43,7 @@ import static org.junit.Assert.fail;
 public class Base64TestCase {
 
     private void innerBase64Test(String action, URL in, URL ref) throws Exception {
-        InputStream inIS = in.openStream();
+        InputStream inIS = dos2Unix(in);
 
         if (action.equals("ROUND")) {
             ref = in;
@@ -47,7 +51,7 @@ public class Base64TestCase {
             fail("Bad action string");
         }
 
-        InputStream refIS = ref.openStream();
+        InputStream refIS = dos2Unix(ref);
 
         if (action.equals("ENCODE") || action.equals("ROUND")) {
             // We need to encode the incomming data
@@ -74,6 +78,21 @@ public class Base64TestCase {
         }
     }
 
+    private InputStream dos2Unix(URL url) throws IOException {
+        InputStream is = url.openStream();
+        byte[] data = IOUtils.toByteArray(is);
+        if (data.length > 1 && data[data.length - 1] == '\n') {
+            ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            for (byte b : data) {
+                if (b != '\r') {
+                    bos.write(b);
+                }
+            }
+            return new ByteArrayInputStream(bos.toByteArray());
+        }
+        return new ByteArrayInputStream(data);
+    }
+
     private void innerBase64Test(String action, String in, String ref) throws Exception {
         final String baseURL = "file:src/test/resources/org/apache/xmlgraphics/util/io/";
         innerBase64Test(action, new URL(baseURL + in), new URL(baseURL + ref));



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org