Skip to content
Permalink
Browse files

[misc] correct test of wrongly constructed utf8 String

  • Loading branch information...
rusher committed Feb 6, 2019
1 parent bda246d commit 5ebad185356256f31a672e0700a9361e20250ac0
52 pom.xml
@@ -58,7 +58,7 @@
<artifactId>mariadb-java-client</artifactId>
<packaging>jar</packaging>
<name>mariadb-java-client</name>
<version>1.8.0</version>
<version>1.8.0-SNAPSHOT</version>
<description>JDBC driver for MariaDB and MySQL</description>
<url>https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/</url>

@@ -72,7 +72,7 @@
<driver.version.major>1</driver.version.major>
<driver.version.minor>8</driver.version.minor>
<driver.version.patch>0</driver.version.patch>
<driver.version.qualifier></driver.version.qualifier>
<driver.version.qualifier>-SNAPSHOT</driver.version.qualifier>
</properties>

<licenses>
@@ -238,30 +238,30 @@
</replacements>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>git</executable>
<arguments>
<argument>archive</argument>
<argument>--format</argument>
<argument>tar.gz</argument>
<argument>--output</argument>
<argument>${project.name}-jre6.tar.gz</argument>
<argument>develop-jre6</argument>
</arguments>
</configuration>
</plugin>
<!--<plugin>-->
<!--<groupId>org.codehaus.mojo</groupId>-->
<!--<artifactId>exec-maven-plugin</artifactId>-->
<!--<version>1.6.0</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<phase>install</phase>-->
<!--<goals>-->
<!--<goal>exec</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--<configuration>-->
<!--<executable>git</executable>-->
<!--<arguments>-->
<!--<argument>archive</argument>-->
<!--<argument>&#45;&#45;format</argument>-->
<!--<argument>tar.gz</argument>-->
<!--<argument>&#45;&#45;output</argument>-->
<!--<argument>${project.name}-jre6.tar.gz</argument>-->
<!--<argument>develop-jre6</argument>-->
<!--</arguments>-->
<!--</configuration>-->
<!--</plugin>-->

<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -53,9 +53,9 @@
package org.mariadb.jdbc.internal.util.constant;

public final class Version {
public static final String version = "1.8.0";
public static final String version = "1.8.0-SNAPSHOT";
public static final int majorVersion = 1;
public static final int minorVersion = 8;
public static final int patchVersion = 0;
public static final String qualifier = "";
public static final String qualifier = "-SNAPSHOT";
}
@@ -85,6 +85,7 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mariadb.jdbc.internal.com.read.Buffer;

public class DatatypeTest extends BaseTest {

@@ -102,7 +103,7 @@ public static void initClass() throws SQLException {
createTable("objecttest", "int_test int primary key not null, string_test varchar(30), "
+ "timestamp_test timestamp, serial_test blob");
createTable("bintest",
"id int not null primary key auto_increment, bin1 varbinary(300), bin2 varbinary(300)");
"id int not null primary key auto_increment, bin1 varbinary(300), bin2 varbinary(300), str1 varchar(256)");
createTable("bigdectest", "id int not null primary key auto_increment, bd decimal",
"engine=innodb");
createTable("bytetest", "id int not null primary key auto_increment, a int", "engine=innodb");
@@ -606,16 +607,17 @@ public void binTest() throws SQLException, IOException {
}
ByteArrayInputStream bais = new ByteArrayInputStream(allBytes);
PreparedStatement ps = sharedConnection
.prepareStatement("insert into bintest (bin1,bin2) values (?,?)");
.prepareStatement("insert into bintest (bin1,bin2, str1) values (?,?,?)");
ps.setBytes(1, allBytes);
ps.setBinaryStream(2, bais);
ps.setString(3, new String(allBytes, StandardCharsets.UTF_8) );
ps.execute();

try (ResultSet rs = getResultSet("select bin1,bin2 from bintest", false)) {
try (ResultSet rs = getResultSet("select bin1,bin2,str1 from bintest", false)) {
binTestResult(rs, allBytes);
}

try (ResultSet rs = getResultSet("select bin1,bin2 from bintest", true)) {
try (ResultSet rs = getResultSet("select bin1,bin2,str1 from bintest", true)) {
binTestResult(rs, allBytes);
}
}
@@ -629,15 +631,18 @@ private void binTestResult(ResultSet rs, byte[] allBytes) throws SQLException, I
int read = is.read();
assertEquals(i, read);
}
assertEquals(rs.getString(1), new String(allBytes, StandardCharsets.UTF_8));

is = rs.getBinaryStream(2);

for (int i = 0; i < 256; i++) {
int read = is.read();
assertEquals(i, read);
}
assertEquals(rs.getString(2), new String(allBytes, StandardCharsets.UTF_8));

assertEquals(new String(rs.getBytes(1), StandardCharsets.UTF_8), new String(allBytes, StandardCharsets.UTF_8));
assertEquals(new String(rs.getBytes(2), StandardCharsets.UTF_8), new String(allBytes, StandardCharsets.UTF_8));
assertEquals(rs.getString(3), new String(allBytes, StandardCharsets.UTF_8));

} else {
fail("Must have result !");
}

0 comments on commit 5ebad18

Please sign in to comment.
You can’t perform that action at this time.