aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Chang <vichang@google.com>2022-05-12 17:04:30 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-05-12 17:04:30 +0000
commitce045c90a8f370319a48d6b2c501ddb33c19e27a (patch)
treebc03c114e40d944423bdf0c4b5db7114f8850643
parentef059f258f8c469aee2d82e8ac3cad0a9f9f7715 (diff)
parente6265e886fea734f6cc838ce5e96ce4d9853e58d (diff)
downloadlibcore-ce045c90a8f370319a48d6b2c501ddb33c19e27a.tar.gz
Add tests for java.sql APIs am: e6265e886f
Original change: https://googleplex-android-review.googlesource.com/c/platform/libcore/+/18234476 Change-Id: I9f0e9656231065410d92dd1ac301e7a6f3a53334 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--luni/src/test/java/libcore/java/sql/BatchUpdateExceptionTest.java41
-rw-r--r--luni/src/test/java/libcore/java/sql/DriverManagerTest.java61
-rw-r--r--luni/src/test/java/libcore/java/sql/DriverTest.java10
-rw-r--r--luni/src/test/java/libcore/java/sql/SQLClientInfoExceptionTest.java47
-rw-r--r--luni/src/test/java/libcore/java/sql/SQLPermissionTest.java35
5 files changed, 194 insertions, 0 deletions
diff --git a/luni/src/test/java/libcore/java/sql/BatchUpdateExceptionTest.java b/luni/src/test/java/libcore/java/sql/BatchUpdateExceptionTest.java
new file mode 100644
index 00000000000..862a977382e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/sql/BatchUpdateExceptionTest.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.sql;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import java.sql.BatchUpdateException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class BatchUpdateExceptionTest {
+
+ @Test
+ public void testConstructor() {
+ String reason = "exception reason";
+ Throwable cause = new RuntimeException();
+ int[] updateCounts = {9, 5, 6};
+ BatchUpdateException exception = new BatchUpdateException(reason, updateCounts, cause);
+ assertEquals(reason, exception.getMessage());
+ assertArrayEquals(updateCounts, exception.getUpdateCounts());
+ assertSame(cause, exception.getCause());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/sql/DriverManagerTest.java b/luni/src/test/java/libcore/java/sql/DriverManagerTest.java
new file mode 100644
index 00000000000..f06da7be70c
--- /dev/null
+++ b/luni/src/test/java/libcore/java/sql/DriverManagerTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.sql;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+import java.sql.DriverManager;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class DriverManagerTest {
+
+ @Test
+ public void testSetLoginTimeout() {
+ int originalTimeout = DriverManager.getLoginTimeout();
+
+ try {
+ int timeout = 9999;
+ DriverManager.setLoginTimeout(timeout);
+ assertEquals(timeout, DriverManager.getLoginTimeout());
+ } finally {
+ DriverManager.setLoginTimeout(originalTimeout);
+ }
+ }
+
+ @Test
+ public void testSetLogWriter() {
+ PrintWriter originalWriter = DriverManager.getLogWriter();
+
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintWriter writer = new PrintWriter(baos);
+ DriverManager.setLogWriter(writer);
+ assertSame(writer, DriverManager.getLogWriter());
+ String msg = "secret message";
+ DriverManager.println(msg);
+ assertEquals(msg + "\n", baos.toString());
+ } finally {
+ DriverManager.setLogWriter(originalWriter);
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/sql/DriverTest.java b/luni/src/test/java/libcore/java/sql/DriverTest.java
index 59d13bd7558..69ba859bade 100644
--- a/luni/src/test/java/libcore/java/sql/DriverTest.java
+++ b/luni/src/test/java/libcore/java/sql/DriverTest.java
@@ -16,6 +16,7 @@
package libcore.java.sql;
+import java.util.Collections;
import junit.framework.TestCase;
import SQLite.JDBCDriver;
@@ -68,6 +69,15 @@ public final class DriverTest extends TestCase {
assertFalse(getDriver().jdbcCompliant());
}
+ public void testGetDrivers() {
+ for (Driver driver : Collections.list(DriverManager.getDrivers())) {
+ if (driver instanceof JDBCDriver) {
+ return;
+ }
+ }
+ fail("DriverManager.getDrivers() doesn't return a Sqlite JDBC driver.");
+ }
+
private Driver getDriver() throws SQLException {
Driver driver = DriverManager.getDriver(SQLITE_JDBC_URL);
assertNotNull(driver);
diff --git a/luni/src/test/java/libcore/java/sql/SQLClientInfoExceptionTest.java b/luni/src/test/java/libcore/java/sql/SQLClientInfoExceptionTest.java
new file mode 100644
index 00000000000..82da1840e76
--- /dev/null
+++ b/luni/src/test/java/libcore/java/sql/SQLClientInfoExceptionTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.sql;
+
+import static org.junit.Assert.assertEquals;
+
+import java.sql.ClientInfoStatus;
+import java.sql.SQLClientInfoException;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class SQLClientInfoExceptionTest {
+
+ @Test
+ public void testConstructor() {
+ String reason = "secret reason";
+ String sqlState = "random SQL state";
+ int vendorCode = 1234;
+ Map<String, ClientInfoStatus> failedProps = new HashMap<String, ClientInfoStatus>() {{
+ put("key1", ClientInfoStatus.REASON_VALUE_TRUNCATED);
+ }};
+ SQLClientInfoException exception = new SQLClientInfoException(reason, sqlState,
+ vendorCode, failedProps);
+ assertEquals(reason, exception.getMessage());
+ assertEquals(sqlState, exception.getSQLState());
+ assertEquals(vendorCode, exception.getErrorCode());
+ assertEquals(failedProps, exception.getFailedProperties());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/sql/SQLPermissionTest.java b/luni/src/test/java/libcore/java/sql/SQLPermissionTest.java
new file mode 100644
index 00000000000..0a0e81280f4
--- /dev/null
+++ b/luni/src/test/java/libcore/java/sql/SQLPermissionTest.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.sql;
+
+import static org.junit.Assert.assertEquals;
+
+import java.sql.SQLPermission;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class SQLPermissionTest {
+
+ @Test
+ public void testConstructor() {
+ SQLPermission permission = new SQLPermission("name", "action");
+ assertEquals("", permission.getName());
+ assertEquals("", permission.getActions());
+ }
+}