Changeset: 45036f1bbbd8 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/45036f1bbbd8
Modified Files:
src/test/java/JDBC_API_Tester.java
src/test/java/org/monetdb/jdbc/ApiTests.java
Branch: default
Log Message:
Convert Test_Rbooleans() -> ApiTest#testBoolean_*()
diffs (208 lines):
diff --git a/src/test/java/JDBC_API_Tester.java
b/src/test/java/JDBC_API_Tester.java
--- a/src/test/java/JDBC_API_Tester.java
+++ b/src/test/java/JDBC_API_Tester.java
@@ -1419,98 +1419,6 @@ public final class JDBC_API_Tester exten
}
@Test
- public void Test_Rbooleans() {
- sb.setLength(0); // clear the output log buffer
-
- Statement stmt = null;
- ResultSet rs = null;
- try {
- con.setAutoCommit(false);
- // >> false: auto commit should be off now
- sb.append("0.
false\t").append(con.getAutoCommit()).append("\n");
-
- stmt = con.createStatement();
- int updates = stmt.executeUpdate(
- "CREATE TABLE Test_Rbooleans (" +
- " id int, tiny_int tinyint, small_int smallint,
medium_int mediumint, \"integer\" int, big_int bigint," +
- " a_real real, a_float float, a_double double,
a_decimal decimal(8,2), a_numeric numeric(8)," +
- " bool boolean, a_char char(4), b_char char(5),
a_varchar varchar(20), PRIMARY KEY (id) )");
- if (updates != 0)
- sb.append("1a. Expected 0 got
").append(updates).append(" instead\n");
-
- // all falses
- updates = stmt.executeUpdate("INSERT INTO
Test_Rbooleans VALUES
(1,0,0,0,0,0,0.0,0.0,0.0,0.0,0,false,'fals','false','false')");
- // all trues
- updates += stmt.executeUpdate("INSERT INTO
Test_Rbooleans VALUES (2,1,1,1,1,1,1.0,1.0,1.0,1.0,1,true,'true','true
','true')");
- // sneakier
- updates += stmt.executeUpdate("INSERT INTO
Test_Rbooleans VALUES
(3,2,3,4,5,6,7.1,8.2,9.3,10.4,11,true,'TrUe','fAlSe','true/false')");
- updates += stmt.executeUpdate("INSERT INTO
Test_Rbooleans VALUES (4,2,3,4,5,6,7.1,8.2,9.3,10.4,11,true,'t ','f
','TRUE ')");
- if (updates != 4)
- sb.append("1b. Expected 4 got
").append(updates).append(" instead\n");
-
- rs = stmt.executeQuery("SELECT * FROM Test_Rbooleans
ORDER BY id ASC");
-
- // all should give false
- rs.next();
- sb.append("1. ").append(rs.getInt("id")).append(",
").append(rs.getBoolean("tiny_int"))
- .append(",
").append(rs.getBoolean("small_int")).append(",
").append(rs.getBoolean("medium_int"))
- .append(",
").append(rs.getBoolean("integer")).append(",
").append(rs.getBoolean("big_int"))
- .append(", ").append(rs.getBoolean("a_real")).append(",
").append(rs.getBoolean("a_double"))
- .append(",
").append(rs.getBoolean("a_decimal")).append(",
").append(rs.getBoolean("a_numeric"))
- .append(", ").append(rs.getBoolean("bool")).append(",
").append(rs.getBoolean("a_char"))
- .append(", ").append(rs.getBoolean("b_char")).append(",
").append(rs.getBoolean("a_varchar")).append("\n");
-
- // all should give true except the one before last
- rs.next();
- sb.append("2. ").append(rs.getInt("id")).append(",
").append(rs.getBoolean("tiny_int"))
- .append(",
").append(rs.getBoolean("small_int")).append(",
").append(rs.getBoolean("medium_int"))
- .append(",
").append(rs.getBoolean("integer")).append(",
").append(rs.getBoolean("big_int"))
- .append(", ").append(rs.getBoolean("a_real")).append(",
").append(rs.getBoolean("a_double"))
- .append(",
").append(rs.getBoolean("a_decimal")).append(",
").append(rs.getBoolean("a_numeric"))
- .append(", ").append(rs.getBoolean("bool")).append(",
").append(rs.getBoolean("a_char"))
- .append(", ").append(rs.getBoolean("b_char")).append(",
").append(rs.getBoolean("a_varchar")).append("\n");
-
- // should give true for all but the last two
- rs.next();
- sb.append("3. ").append(rs.getInt("id")).append(",
").append(rs.getBoolean("tiny_int"))
- .append(",
").append(rs.getBoolean("small_int")).append(",
").append(rs.getBoolean("medium_int"))
- .append(",
").append(rs.getBoolean("integer")).append(",
").append(rs.getBoolean("big_int"))
- .append(", ").append(rs.getBoolean("a_real")).append(",
").append(rs.getBoolean("a_double"))
- .append(",
").append(rs.getBoolean("a_decimal")).append(",
").append(rs.getBoolean("a_numeric"))
- .append(", ").append(rs.getBoolean("bool")).append(",
").append(rs.getBoolean("a_char"))
- .append(", ").append(rs.getBoolean("b_char")).append(",
").append(rs.getBoolean("a_varchar")).append("\n");
-
- // should give true for all but the last three
- rs.next();
- sb.append("4. ").append(rs.getInt("id")).append(",
").append(rs.getBoolean("tiny_int"))
- .append(",
").append(rs.getBoolean("small_int")).append(",
").append(rs.getBoolean("medium_int"))
- .append(",
").append(rs.getBoolean("integer")).append(",
").append(rs.getBoolean("big_int"))
- .append(", ").append(rs.getBoolean("a_real")).append(",
").append(rs.getBoolean("a_double"))
- .append(",
").append(rs.getBoolean("a_decimal")).append(",
").append(rs.getBoolean("a_numeric"))
- .append(", ").append(rs.getBoolean("bool")).append(",
").append(rs.getBoolean("a_char"))
- .append(", ").append(rs.getBoolean("b_char")).append(",
").append(rs.getBoolean("a_varchar")).append("\n");
- rs.next();
-
- con.rollback();
- con.setAutoCommit(true);
- // >> true: auto commit was just switched on
- sb.append("0.
true\t").append(con.getAutoCommit()).append("\n");
- } catch (SQLException e) {
- sb.append("FAILED:
").append(e.getMessage()).append("\n");
- }
-
- closeStmtResSet(stmt, rs);
-
- compareExpectedOutput("Test_Rbooleans",
- "0. false false\n" +
- "1. 1, false, false, false, false, false, false, false,
false, false, false, false, false, false\n" +
- "2. 2, true, true, true, true, true, true, true, true,
true, true, true, false, true\n" +
- "3. 3, true, true, true, true, true, true, true, true,
true, true, true, false, false\n" +
- "4. 4, true, true, true, true, true, true, true, true,
true, true, false, false, false\n" +
- "0. true true\n");
- }
-
- @Test
public void Test_Rmetadata() {
sb.setLength(0); // clear the output log buffer
diff --git a/src/test/java/org/monetdb/jdbc/ApiTests.java
b/src/test/java/org/monetdb/jdbc/ApiTests.java
--- a/src/test/java/org/monetdb/jdbc/ApiTests.java
+++ b/src/test/java/org/monetdb/jdbc/ApiTests.java
@@ -1375,4 +1375,102 @@ public class ApiTests {
}
}
}
+
+ @Test
+ public void testBoolean_tinyint() throws SQLException {
+ startScratchTransaction();
+ testBooleans("tinyint", "(0), (1), (2), (2)", false, true,
true, true);
+ }
+
+ @Test
+ public void testBoolean_smallint() throws SQLException {
+ startScratchTransaction();
+ testBooleans("smallint", "(0), (1), (3), (3)", false, true,
true, true);
+ }
+
+ @Test
+ public void testBoolean_mediumint() throws SQLException {
+ startScratchTransaction();
+ testBooleans("mediumint", "(0), (1), (4), (4)", false, true,
true, true);
+ }
+
+ @Test
+ public void testBoolean_int() throws SQLException {
+ startScratchTransaction();
+ testBooleans("int", "(0), (1), (5), (5)", false, true, true,
true);
+ }
+
+ @Test
+ public void testBoolean_bigint() throws SQLException {
+ startScratchTransaction();
+ testBooleans("bigint", "(0), (1), (6), (6)", false, true, true,
true);
+ }
+
+ @Test
+ public void testBoolean_real() throws SQLException {
+ startScratchTransaction();
+ testBooleans("real", "(0.0), (1.0), (7.1), (7.1)", false, true,
true, true);
+ }
+
+ @Test
+ public void testBoolean_float() throws SQLException {
+ startScratchTransaction();
+ testBooleans("float", "(0.0), (1.0), (8.2), (8.2)", false,
true, true, true);
+ }
+
+ @Test
+ public void testBoolean_double() throws SQLException {
+ startScratchTransaction();
+ testBooleans("double", "(0.0), (1.0), (9.3), (9.3)", false,
true, true, true);
+ }
+
+ @Test
+ public void testBoolean_decimal_8_2() throws SQLException {
+ startScratchTransaction();
+ testBooleans("decimal(8,2)", "(0.0), (1.0), (10.4), (10.4)",
false, true, true, true);
+ }
+
+ @Test
+ public void testBoolean_numeric_8() throws SQLException {
+ startScratchTransaction();
+ testBooleans("numeric(8)", "(0), (1), (11), (11)", false, true,
true, true);
+ }
+
+ @Test
+ public void testBoolean_boolean() throws SQLException {
+ startScratchTransaction();
+ testBooleans("boolean", "(false), (true), (true), (true)",
false, true, true, true);
+ }
+
+ @Test
+ public void testBoolean_char4() throws SQLException {
+ startScratchTransaction();
+ testBooleans("char(4)", "('fals'), ('true'), ('TrUe'), ('t
')", false, true, true, false);
+ }
+
+ @Test
+ public void testBoolean_char5() throws SQLException {
+ startScratchTransaction();
+ testBooleans("char(5)", "('false'), ('true '), ('fAlSe'), ('f
')", false, false, false, false);
+ }
+
+ @Test
+ public void testBoolean_varchar() throws SQLException {
+ startScratchTransaction();
+ testBooleans("varchar(20)", "('false'), ('true'),
('true/false'), ('TRUE ')", false, true, false, false);
+ }
+
+ private void testBooleans(String typeDecl, String values, boolean...
booleans) throws SQLException {
+ stmt.execute("DROP TABLE IF EXISTS foo");
+ stmt.execute("CREATE TABLE foo(id SERIAL, value " + typeDecl +
")");
+ stmt.execute("INSERT INTO foo(value) VALUES " + values);
+
+ try (ResultSet rs = stmt.executeQuery("SELECT value FROM foo"))
{
+ for (int i = 0; i < booleans.length; i++) {
+ assertTrue(rs.next(), "row " + i + " (0-based)
should exist");
+ assertEquals(booleans[i], rs.getBoolean(1));
+ }
+ assertFalse(rs.next(), "row " + booleans.length + "
(0-based) should not exist");
+ }
+ }
}
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]