You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by od...@apache.org on 2009/05/01 14:37:33 UTC

svn commit: r770654 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/

Author: odeakin
Date: Fri May  1 12:37:32 2009
New Revision: 770654

URL: http://svn.apache.org/viewvc?rev=770654&view=rev
Log:
Make sure bytes are UTF-8 encoded when making assertion checks

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PrintWriterTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PushbackInputStreamTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/RandomAccessFileTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SequenceInputStreamTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/StreamTokenizerTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/StringBufferInputStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java?rev=770654&r1=770653&r2=770654&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectOutputStreamTest.java Fri May  1 12:37:32 2009
@@ -861,7 +861,7 @@
         ois.readFully(buf);
         ois.close();
         assertEquals("Wrote incorrect bytes value", "HelloWorld", new String(
-                buf, 0, 10));
+                buf, 0, 10, "UTF-8"));
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java?rev=770654&r1=770653&r2=770654&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java Fri May  1 12:37:32 2009
@@ -20,6 +20,7 @@
 import java.io.IOException;
 import java.io.PipedInputStream;
 import java.io.PipedOutputStream;
+import java.io.UnsupportedEncodingException;
 
 import junit.framework.TestCase;
 
@@ -62,7 +63,7 @@
             byte[] buf = new byte[nbytes];
             try {
                 reader.read(buf, 0, nbytes);
-                return new String(buf);
+                return new String(buf, "UTF-8");
             } catch (IOException e) {
                 System.out.println("Exception reading info");
                 return "ERROR";
@@ -134,11 +135,11 @@
     /**
      * @tests java.io.PipedOutputStream#flush()
      */
-    public void test_flush() throws IOException {
+    public void test_flush() throws IOException, UnsupportedEncodingException {
         out = new PipedOutputStream();
         rt = new Thread(reader = new PReader(out));
         rt.start();
-        out.write("HelloWorld".getBytes(), 0, 10);
+        out.write("HelloWorld".getBytes("UTF-8"), 0, 10);
         assertTrue("Bytes written before flush", reader.available() != 0);
         out.flush();
         assertEquals("Wrote incorrect bytes", "HelloWorld", reader.read(10));
@@ -147,11 +148,11 @@
     /**
      * @tests java.io.PipedOutputStream#write(byte[], int, int)
      */
-    public void test_write$BII() throws IOException {
+    public void test_write$BII() throws IOException, UnsupportedEncodingException {
         out = new PipedOutputStream();
         rt = new Thread(reader = new PReader(out));
         rt.start();
-        out.write("HelloWorld".getBytes(), 0, 10);
+        out.write("HelloWorld".getBytes("UTF-8"), 0, 10);
         out.flush();
         assertEquals("Wrote incorrect bytes", "HelloWorld", reader.read(10));
     }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PrintWriterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PrintWriterTest.java?rev=770654&r1=770653&r2=770654&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PrintWriterTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PrintWriterTest.java Fri May  1 12:37:32 2009
@@ -22,6 +22,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.nio.charset.Charset;
 import java.util.Locale;
@@ -586,17 +587,17 @@
 	/**
 	 * @tests java.io.PrintWriter#write(int)
 	 */
-	public void test_writeI() {
+	public void test_writeI() throws IOException {
 		// Test for method void java.io.PrintWriter.write(int)
 		char[] cab = new char[3];
 		pw.write('a');
 		pw.write('b');
 		pw.write('c');
 		pw.flush();
-		bai = new ByteArrayInputStream(bao.toByteArray());
-		cab[0] = (char) bai.read();
-		cab[1] = (char) bai.read();
-		cab[2] = (char) bai.read();
+		InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(bao.toByteArray()));
+		cab[0] = (char) isr.read();
+		cab[1] = (char) isr.read();
+		cab[2] = (char) isr.read();
 		assertTrue("Wrote incorrect ints", cab[0] == 'a' && cab[1] == 'b'
 				&& cab[2] == 'c');
 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PushbackInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PushbackInputStreamTest.java?rev=770654&r1=770653&r2=770654&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PushbackInputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PushbackInputStreamTest.java Fri May  1 12:37:32 2009
@@ -20,6 +20,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.PushbackInputStream;
+import java.io.UnsupportedEncodingException;
 
 public class PushbackInputStreamTest extends junit.framework.TestCase {
 
@@ -130,7 +131,7 @@
 		// Test for method int java.io.PushbackInputStream.read()
 		try {
 			assertTrue("Incorrect byte read", pis.read() == fileString
-					.getBytes()[0]);
+					.getBytes("UTF-8")[0]);
 		} catch (IOException e) {
 			fail("Exception during read test : " + e.getMessage());
 		}
@@ -145,7 +146,7 @@
 		try {
 			byte[] buf = new byte[100];
 			pis.read(buf, 0, buf.length);
-			assertTrue("Incorrect bytes read", new String(buf)
+			assertTrue("Incorrect bytes read", new String(buf, "UTF-8")
 					.equals(fileString.substring(0, 100)));
 		} catch (IOException e) {
 			fail("Exception during read test : " + e.getMessage());
@@ -160,13 +161,13 @@
                 byte[] buf = new byte[50];
                 pis.skip(50);
                 pis.read(buf, 0, buf.length);
-                assertTrue("a) Incorrect bytes read", new String(buf)
+                assertTrue("a) Incorrect bytes read", new String(buf, "UTF-8")
                                 .equals(fileString.substring(50, 100)));
                 pis.unread(buf);
                 pis.skip(25);
                 byte[] buf2 = new byte[25];
                 pis.read(buf2, 0, buf2.length);
-                assertTrue("b) Incorrect bytes read", new String(buf2)
+                assertTrue("b) Incorrect bytes read", new String(buf2, "UTF-8")
                                 .equals(fileString.substring(75, 100)));
 	}
 
@@ -178,11 +179,11 @@
 		try {
 			byte[] buf = new byte[100];
 			pis.read(buf, 0, buf.length);
-			assertTrue("Incorrect bytes read", new String(buf)
+			assertTrue("Incorrect bytes read", new String(buf, "UTF-8")
 					.equals(fileString.substring(0, 100)));
 			pis.unread(buf);
 			pis.read(buf, 0, 50);
-			assertTrue("Failed to unread bytes", new String(buf, 0, 50)
+			assertTrue("Failed to unread bytes", new String(buf, 0, 50, "UTF-8")
 					.equals(fileString.substring(0, 50)));
 		} catch (IOException e) {
 			fail("IOException during unread test : " + e.getMessage());
@@ -197,11 +198,11 @@
 		// int)
 		byte[] buf = new byte[100];
 		pis.read(buf, 0, buf.length);
-		assertTrue("Incorrect bytes read", new String(buf)
+		assertTrue("Incorrect bytes read", new String(buf, "UTF-8")
 				.equals(fileString.substring(0, 100)));
 		pis.unread(buf, 50, 50);
 		pis.read(buf, 0, 50);
-		assertTrue("Failed to unread bytes", new String(buf, 0, 50)
+		assertTrue("Failed to unread bytes", new String(buf, 0, 50, "UTF-8")
 				.equals(fileString.substring(50, 100)));
 		
         // Regression for HARMONY-49
@@ -223,7 +224,7 @@
 		try {
 			int x;
 			assertTrue("Incorrect byte read", (x = pis.read()) == fileString
-					.getBytes()[0]);
+					.getBytes("UTF-8")[0]);
 			pis.unread(x);
 			assertTrue("Failed to unread", pis.read() == x);
 		} catch (IOException e) {
@@ -235,10 +236,10 @@
 	 * Sets up the fixture, for example, open a network connection. This method
 	 * is called before a test is executed.
 	 */
-	protected void setUp() {
+	protected void setUp() throws UnsupportedEncodingException {
 
 		pis = new PushbackInputStream(new ByteArrayInputStream(fileString
-				.getBytes()), 65535);
+				.getBytes("UTF-8")), 65535);
 	}
 
 	/**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/RandomAccessFileTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/RandomAccessFileTest.java?rev=770654&r1=770653&r2=770654&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/RandomAccessFileTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/RandomAccessFileTest.java Fri May  1 12:37:32 2009
@@ -159,7 +159,7 @@
     public void test_read() throws IOException {
         // Test for method int java.io.RandomAccessFile.read()
         FileOutputStream fos = new java.io.FileOutputStream(fileName);
-        fos.write(fileString.getBytes(), 0, fileString.length());
+        fos.write(fileString.getBytes("UTF-8"), 0, fileString.length());
         fos.close();
 
         RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "r");
@@ -274,7 +274,7 @@
         raf.seek(0);
         raf.readFully(buf);
         assertEquals("Incorrect bytes read/written", "HelloWorld", new String(
-                buf, 0, 10));
+                buf, 0, 10, "UTF-8"));
         raf.close();
     }
 
@@ -290,7 +290,7 @@
         raf.seek(0);
         raf.readFully(buf, 0, buf.length);
         assertEquals("Incorrect bytes read/written", "HelloWorld", new String(
-                buf, 0, 10));
+                buf, 0, 10, "UTF-8"));
         try {
             raf.readFully(buf, 0, buf.length);
             fail("Reading past end of buffer did not throw EOFException");
@@ -318,7 +318,7 @@
         // Test for method java.lang.String java.io.RandomAccessFile.readLine()
         RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
         String s = "Goodbye\nCruel\nWorld\n";
-        raf.write(s.getBytes(), 0, s.length());
+        raf.write(s.getBytes("UTF-8"), 0, s.length());
         raf.seek(0);
 
         assertEquals("Goodbye", raf.readLine());
@@ -415,7 +415,7 @@
         raf.seek(0);
         raf.skipBytes(5);
         raf.readFully(buf);
-        assertEquals("Failed to skip bytes", "World", new String(buf, 0, 5));
+        assertEquals("Failed to skip bytes", "World", new String(buf, 0, 5, "UTF-8"));
         raf.close();
     }
 
@@ -670,7 +670,7 @@
         raf.seek(0);
         raf.readFully(buf);
         assertEquals("Incorrect bytes read/written", "HelloWorld", new String(
-                buf, 0, 10));
+                buf, 0, 10, "UTF-8"));
         raf.close();
 
     }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SequenceInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SequenceInputStreamTest.java?rev=770654&r1=770653&r2=770654&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SequenceInputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SequenceInputStreamTest.java Fri May  1 12:37:32 2009
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.SequenceInputStream;
+import java.io.UnsupportedEncodingException;
 import java.util.Enumeration;
 
 public class SequenceInputStreamTest extends junit.framework.TestCase {
@@ -45,7 +46,7 @@
 	 * @tests SequenceInputStream#SequenceInputStream(java.io.InputStream,
 	 *        java.io.InputStream)
 	 */
-	public void test_Constructor_LInputStreamLInputStream_Null() {		
+	public void test_Constructor_LInputStreamLInputStream_Null() throws UnsupportedEncodingException {		
 		try {
 			si = new SequenceInputStream(null , null);
 			fail("should throw NullPointerException");
@@ -54,7 +55,7 @@
 		}
 		
 		//will not throw NullPointerException if the first InputStream is not null
-		InputStream is = new ByteArrayInputStream(s1.getBytes()); 
+		InputStream is = new ByteArrayInputStream(s1.getBytes("UTF-8")); 
 		si = new SequenceInputStream(is , null);
 	}
 
@@ -69,9 +70,9 @@
 
 			int count = 0;
 
-			public StreamEnumerator() {
-				streams[0] = new ByteArrayInputStream(s1.getBytes());
-				streams[1] = new ByteArrayInputStream(s2.getBytes());
+			public StreamEnumerator() throws UnsupportedEncodingException {
+				streams[0] = new ByteArrayInputStream(s1.getBytes("UTF-8"));
+				streams[1] = new ByteArrayInputStream(s2.getBytes("UTF-8"));
 			}
 
 			public boolean hasMoreElements() {
@@ -89,7 +90,7 @@
 			si.read(buf, 0, s1.length());
 			si.read(buf, s1.length(), s2.length());
 			assertTrue("Read incorrect bytes: " + new String(buf), new String(
-					buf).equals(s1 + s2));
+					buf, "UTF-8").equals(s1 + s2));
 		} catch (IOException e) {
 			fail("IOException during read test : " + e.getMessage());
 		}
@@ -148,7 +149,7 @@
 			si.read(buf, 0, s1.length());
 			si.read(buf, s1.length(), s2.length());
 			assertTrue("Read incorrect bytes: " + new String(buf), new String(
-					buf).equals(s1 + s2));
+					buf, "UTF-8").equals(s1 + s2));
 		} catch (IOException e) {
 			fail("IOException during read test : " + e.getMessage());
 		}
@@ -178,9 +179,9 @@
 	 * Sets up the fixture, for example, open a network connection. This method
 	 * is called before a test is executed.
 	 */
-	protected void setUp() {
-		si = new SequenceInputStream(new ByteArrayInputStream(s1.getBytes()),
-				new ByteArrayInputStream(s2.getBytes()));
+	protected void setUp() throws UnsupportedEncodingException {
+		si = new SequenceInputStream(new ByteArrayInputStream(s1.getBytes("UTF-8")),
+				new ByteArrayInputStream(s2.getBytes("UTF-8")));
 	}
 
 	/**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java?rev=770654&r1=770653&r2=770654&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java Fri May  1 12:37:32 2009
@@ -451,7 +451,7 @@
 			ois = new ObjectInputStream(loadStream());
 			ois.readFully(buf);
 			ois.close();
-			assertEquals("Wrote incorrect bytes value", "HelloWorld", new String(buf, 0, 10)
+			assertEquals("Wrote incorrect bytes value", "HelloWorld", new String(buf, 0, 10, "UTF-8")
 					);
 		} catch (IOException e) {
 			fail("IOException serializing data : " + e.getMessage());

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/StreamTokenizerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/StreamTokenizerTest.java?rev=770654&r1=770653&r2=770654&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/StreamTokenizerTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/StreamTokenizerTest.java Fri May  1 12:37:32 2009
@@ -179,7 +179,7 @@
 
 		final PipedInputStream pin = new PipedInputStream();
 		PipedOutputStream pout = new PipedOutputStream(pin);
-		pout.write("hello\n\r\r".getBytes());
+		pout.write("hello\n\r\r".getBytes("UTF-8"));
 		StreamTokenizer s = new StreamTokenizer(pin);
 		s.eolIsSignificant(true);
 		assertTrue("Wrong token 1,1",

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/StringBufferInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/StringBufferInputStreamTest.java?rev=770654&r1=770653&r2=770654&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/StringBufferInputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/StringBufferInputStreamTest.java Fri May  1 12:37:32 2009
@@ -18,6 +18,7 @@
 package org.apache.harmony.luni.tests.java.io;
 
 import java.io.StringBufferInputStream;
+import java.io.UnsupportedEncodingException;
 
 @SuppressWarnings("deprecation")
 public class StringBufferInputStreamTest extends junit.framework.TestCase {
@@ -43,12 +44,12 @@
 	/**
 	 * @tests java.io.StringBufferInputStream#read()
 	 */
-	public void test_read() {
+	public void test_read() throws UnsupportedEncodingException {
 		// Test for method int java.io.StringBufferInputStream.read()
 		byte[] buf = new byte[5];
 		sbis.skip(6);
 		sbis.read(buf, 0, 5);
-		assertEquals("Returned incorrect chars", "World", new String(buf));
+		assertEquals("Returned incorrect chars", "World", new String(buf, "UTF-8"));
 	}
 
 	/**