changeset 1438:3e52d36eecdf

TeeOutputStreamTest.java: testPrint and testWriteByteArrayString made dual for linux and windows. Those tests are charset specific. testWriteByteArrayString2 is new test, showing strange issue when strange characters are going into and from byte array. On windows, this test fails, showing, that somewhere in the stack, there is bad encoding or bad offset/lenght used.
author Jiri Vanek <jvanek@redhat.com>
date Thu, 18 May 2017 16:16:05 +0200
parents 85c45a76dddd
children d6264d31d0d6
files ChangeLog tests/netx/unit/net/sourceforge/jnlp/util/logging/TeeOutputStreamTest.java
diffstat 2 files changed, 42 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu May 18 16:12:54 2017 +0200
+++ b/ChangeLog	Thu May 18 16:16:05 2017 +0200
@@ -1,3 +1,11 @@
+2017-05-18  Jiri Vanek <jvanek@redhat.com>
+            Tomáš Votava <tomcacolca@gmail.com>
+
+	* tests/netx/unit/net/sourceforge/jnlp/util/logging/TeeOutputStreamTest.java: testPrint and testWriteByteArrayString
+	made dual for linux and windows. Those tests are charset specific. testWriteByteArrayString2 is new test, showing
+	strange issue when strange characters are going into and from byte array. On windows, this test fails, showing, that somewhere
+	in the stack, there is bad encoding or bad offset/lenght used.
+
 2017-05-18  Jiri Vanek <jvanek@redhat.com>
             Tomáš Votava <tomcacolca@gmail.com>
 
--- a/tests/netx/unit/net/sourceforge/jnlp/util/logging/TeeOutputStreamTest.java	Thu May 18 16:12:54 2017 +0200
+++ b/tests/netx/unit/net/sourceforge/jnlp/util/logging/TeeOutputStreamTest.java	Thu May 18 16:16:05 2017 +0200
@@ -6,6 +6,9 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.nio.charset.Charset;
+import net.sourceforge.jnlp.annotations.KnownToFail;
+import net.sourceforge.jnlp.annotations.WindowsIssue;
 
 import static org.junit.Assert.assertTrue;
 
@@ -28,18 +31,43 @@
     }
 
     @Test
+    @WindowsIssue
     public void testPrint() throws IOException {
-        String s = "नमस्तHello!\r";
-        tos.print(s);
-        assertTrue(tos.getByteArrayOutputStream().toString().equals(s));
+        if (Charset.defaultCharset().toString().toLowerCase().startsWith("windows")) {
+            String s = "ÆÆÆÆÆHello!\r";
+            tos.print(s);
+            assertTrue(tos.getByteArrayOutputStream().toString().equals(s));
+        } else {
+            String s = "नमस्तHello!\r"; //first five symbols are printed as "?" by windows' default character encoding
+            tos.print(s);
+            assertTrue(tos.getByteArrayOutputStream().toString().equals(s));
+        }
+
     }
 
     @Test
+    @WindowsIssue
     public void testWriteByteArrayString() throws IOException {
-        String s = "He\n\n\\llo chào";
-        tos.write(s.getBytes(), 0, s.getBytes().length);
-        assertTrue(tos.getByteArrayOutputStream().toString().equals(s.toString()));
+        if (Charset.defaultCharset().toString().toLowerCase().startsWith("windows")) {
+            String s = "He\n\n\\llo chào";
+            tos.write(s.getBytes(), 0, s.getBytes().length);
+            assertTrue(tos.getByteArrayOutputStream().toString().equals(s));
+        } else {
+            String s = "He\n\n\\llo chào"; //grave accent as "?" by windows' default character encoding
+            tos.write(s.getBytes(), 0, s.getBytes().length);
+            assertTrue(tos.getByteArrayOutputStream().toString().equals(s));
+        }
     }
+
+    @Test
+    @WindowsIssue
+    @KnownToFail
+    public void testWriteByteArrayString2() throws IOException { //last character missing
+        String s = "He\n\n\\llo chào"; //grave accent as "?" by windows' default character encoding
+        tos.write(s.getBytes("utf-8"), 0, s.getBytes().length);
+        assertTrue(tos.getByteArrayOutputStream().toString("utf-8").equals(s));
+    }
+    
     @Test
     public void testWriteByte() throws IOException {
         byte b = 5;