mirror of
https://github.com/postgres/postgres.git
synced 2025-08-28 18:48:04 +03:00
JDBC encoding additions.
Here's a patch against the current CVS. The changes from the previous patch are mostly related to the changed interface for PG_Stream. Anders Bengtsson
This commit is contained in:
57
src/interfaces/jdbc/org/postgresql/test/EncodingTest.java
Normal file
57
src/interfaces/jdbc/org/postgresql/test/EncodingTest.java
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
package org.postgresql.test.jdbc2;
|
||||
|
||||
import junit.framework.*;
|
||||
import org.postgresql.core.Encoding;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Tests for the Encoding class.
|
||||
*
|
||||
* $Id: EncodingTest.java,v 1.1 2001/07/21 18:52:11 momjian Exp $
|
||||
*/
|
||||
|
||||
|
||||
public class EncodingTest extends TestCase {
|
||||
|
||||
public EncodingTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void testCreation() throws Exception {
|
||||
Encoding encoding;
|
||||
encoding = Encoding.getEncoding("UNICODE", null);
|
||||
assertEquals("UTF", encoding.name().substring(0, 3).toUpperCase());
|
||||
encoding = Encoding.getEncoding("SQL_ASCII", null);
|
||||
assert(encoding.name().toUpperCase().indexOf("ASCII") != -1);
|
||||
assertEquals("When encoding is unknown the default encoding should be used",
|
||||
Encoding.defaultEncoding(),
|
||||
Encoding.getEncoding("UNKNOWN", null));
|
||||
encoding = Encoding.getEncoding("SQL_ASCII", "utf-8");
|
||||
assert("Encoding passed in by the user should be preferred",
|
||||
encoding.name().toUpperCase().indexOf("UTF") != -1);
|
||||
}
|
||||
|
||||
public void testTransformations() throws Exception {
|
||||
Encoding encoding = Encoding.getEncoding("UNICODE", null);
|
||||
assertEquals("ab", encoding.decode(new byte[] { 97, 98 }));
|
||||
|
||||
assertEquals(2, encoding.encode("ab").length);
|
||||
assertEquals(97, encoding.encode("a")[0]);
|
||||
assertEquals(98, encoding.encode("b")[0]);
|
||||
|
||||
encoding = Encoding.defaultEncoding();
|
||||
assertEquals("a".getBytes()[0], encoding.encode("a")[0]);
|
||||
assertEquals(new String(new byte[] { 97 }),
|
||||
encoding.decode(new byte[] { 97 }));
|
||||
}
|
||||
|
||||
public void testReader() throws Exception {
|
||||
Encoding encoding = Encoding.getEncoding("SQL_ASCII", null);
|
||||
InputStream stream = new ByteArrayInputStream(new byte[] { 97, 98 });
|
||||
Reader reader = encoding.getDecodingReader(stream);
|
||||
assertEquals(97, reader.read());
|
||||
assertEquals(98, reader.read());
|
||||
assertEquals(-1, reader.read());
|
||||
}
|
||||
}
|
@@ -195,6 +195,7 @@ public class JDBC2Tests extends TestSuite {
|
||||
suite.addTestSuite(DriverTest.class);
|
||||
suite.addTestSuite(ConnectionTest.class);
|
||||
suite.addTestSuite(DatabaseMetaDataTest.class);
|
||||
suite.addTestSuite(EncodingTest.class);
|
||||
|
||||
// Connectivity/Protocols
|
||||
|
||||
|
Reference in New Issue
Block a user