From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- qadevOOo/tests/java/ifc/sdbc/_ResultSet.java | 40 ++ qadevOOo/tests/java/ifc/sdbc/_RowSet.java | 72 +++ qadevOOo/tests/java/ifc/sdbc/_XCloseable.java | 85 +++ qadevOOo/tests/java/ifc/sdbc/_XColumnLocate.java | 76 +++ qadevOOo/tests/java/ifc/sdbc/_XDataSource.java | 105 ++++ qadevOOo/tests/java/ifc/sdbc/_XDriver.java | 205 +++++++ qadevOOo/tests/java/ifc/sdbc/_XDriverManager.java | 152 +++++ .../tests/java/ifc/sdbc/_XIsolatedConnection.java | 111 ++++ qadevOOo/tests/java/ifc/sdbc/_XParameters.java | 564 +++++++++++++++++ qadevOOo/tests/java/ifc/sdbc/_XResultSet.java | 497 +++++++++++++++ .../java/ifc/sdbc/_XResultSetMetaDataSupplier.java | 60 ++ .../tests/java/ifc/sdbc/_XResultSetUpdate.java | 255 ++++++++ qadevOOo/tests/java/ifc/sdbc/_XRow.java | 527 ++++++++++++++++ qadevOOo/tests/java/ifc/sdbc/_XRowSet.java | 192 ++++++ qadevOOo/tests/java/ifc/sdbc/_XRowUpdate.java | 683 +++++++++++++++++++++ .../tests/java/ifc/sdbc/_XWarningsSupplier.java | 130 ++++ 16 files changed, 3754 insertions(+) create mode 100644 qadevOOo/tests/java/ifc/sdbc/_ResultSet.java create mode 100644 qadevOOo/tests/java/ifc/sdbc/_RowSet.java create mode 100644 qadevOOo/tests/java/ifc/sdbc/_XCloseable.java create mode 100644 qadevOOo/tests/java/ifc/sdbc/_XColumnLocate.java create mode 100644 qadevOOo/tests/java/ifc/sdbc/_XDataSource.java create mode 100644 qadevOOo/tests/java/ifc/sdbc/_XDriver.java create mode 100644 qadevOOo/tests/java/ifc/sdbc/_XDriverManager.java create mode 100644 qadevOOo/tests/java/ifc/sdbc/_XIsolatedConnection.java create mode 100644 qadevOOo/tests/java/ifc/sdbc/_XParameters.java create mode 100644 qadevOOo/tests/java/ifc/sdbc/_XResultSet.java create mode 100644 qadevOOo/tests/java/ifc/sdbc/_XResultSetMetaDataSupplier.java create mode 100644 qadevOOo/tests/java/ifc/sdbc/_XResultSetUpdate.java create mode 100644 qadevOOo/tests/java/ifc/sdbc/_XRow.java create mode 100644 qadevOOo/tests/java/ifc/sdbc/_XRowSet.java create mode 100644 qadevOOo/tests/java/ifc/sdbc/_XRowUpdate.java create mode 100644 qadevOOo/tests/java/ifc/sdbc/_XWarningsSupplier.java (limited to 'qadevOOo/tests/java/ifc/sdbc') diff --git a/qadevOOo/tests/java/ifc/sdbc/_ResultSet.java b/qadevOOo/tests/java/ifc/sdbc/_ResultSet.java new file mode 100644 index 000000000..56724524e --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_ResultSet.java @@ -0,0 +1,40 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import lib.MultiPropertyTest; + +/** +* Testing com.sun.star.sdbc.ResultSet +* service properties : +*

+* Properties testing is automated by lib.MultiPropertyTest. +* @see com.sun.star.sdbc.ResultSet +*/ +public class _ResultSet extends MultiPropertyTest { + + +} // finish class _ResultSet + diff --git a/qadevOOo/tests/java/ifc/sdbc/_RowSet.java b/qadevOOo/tests/java/ifc/sdbc/_RowSet.java new file mode 100644 index 000000000..fae52a637 --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_RowSet.java @@ -0,0 +1,72 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import lib.MultiPropertyTest; + +import com.sun.star.uno.Any; + + +/** +* Testing com.sun.star.sdbc.RowSet +* service properties : +*

+* Properties testing is automated by lib.MultiPropertyTest. +* @see com.sun.star.sdbc.RowSet +*/ +public class _RowSet extends MultiPropertyTest { + + /** + * Redefined method returns object, that contains changed property value. + */ + public void _TypeMap() { + boolean result = false; + try { + Any TypeMap = (Any) oObj.getPropertyValue("TypeMap"); + String TypeName = TypeMap.getType().getTypeName(); + String expected = "com.sun.star.container.XNameAccess"; + result = TypeName.equals(expected); + if (! result ) { + log.println("Expected Type is "+expected); + log.println("but the returned is "+TypeName); + } + } catch(com.sun.star.lang.WrappedTargetException e) { + log.println("Exception " + e.getMessage()); + } catch(com.sun.star.beans.UnknownPropertyException e) { + log.println("Exception " + e.getMessage()); + } + + tRes.tested("TypeMap",result); + } + +} // finish class _RowSet + diff --git a/qadevOOo/tests/java/ifc/sdbc/_XCloseable.java b/qadevOOo/tests/java/ifc/sdbc/_XCloseable.java new file mode 100644 index 000000000..efd39fd1f --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_XCloseable.java @@ -0,0 +1,85 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import lib.MultiMethodTest; +import lib.StatusException; + +import com.sun.star.sdbc.SQLException; +import com.sun.star.sdbc.XCloseable; +import com.sun.star.sdbc.XResultSet; +import com.sun.star.uno.UnoRuntime; + +/** +* Testing com.sun.star.sdbc.XCloseable +* interface methods : +*

+* After test object must be recreated. +* @see com.sun.star.sdbc.XCloseable +*/ +public class _XCloseable extends MultiMethodTest { + + // oObj filled by MultiMethodTest + public XCloseable oObj = null ; + + /** + * Closes row set. If the component implements the interface + * com.sun.star.sdbc.XResultSet then tries to move + * the cursor to the first row in the result set. + * Has OK status if no exceptions were thrown during first call and + * if expected SQL exception was thrown during cursor moving. + */ + public void _close() throws StatusException { + boolean res = false; + try { + oObj.close(); + res = true; + } catch (SQLException e) { + log.println("Unexpected SQL Exception occurred:" + e) ; + res = false; + } + + XResultSet resSet = UnoRuntime.queryInterface(XResultSet.class, oObj); + + if (resSet != null) { + try { + resSet.first(); + log.println("Expected SQLException not occurred !"); + res = false; + } catch(SQLException e) { + log.println("Expected SQLException occurred"); + res = true; + } + } + + tRes.tested("close()", res); + } + + /** + * Forces environment recreation. + */ + @Override + public void after() { + disposeEnvironment() ; + } + +} // finish class _XCloseable + diff --git a/qadevOOo/tests/java/ifc/sdbc/_XColumnLocate.java b/qadevOOo/tests/java/ifc/sdbc/_XColumnLocate.java new file mode 100644 index 000000000..f1d57c5b7 --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_XColumnLocate.java @@ -0,0 +1,76 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; + +import com.sun.star.sdbc.SQLException; +import com.sun.star.sdbc.XColumnLocate; + +/** +/** +* Testing com.sun.star.sdbc.XColumnLocate +* interface methods : +*

+* The test required the following relations : +*

+* @see com.sun.star.sdbc.XColumnLocate +*/ +public class _XColumnLocate extends MultiMethodTest { + + // oObj filled by MultiMethodTest + public XColumnLocate oObj = null ; + + /** + * Using column name from object relation trying to find out + * the index of this column.

+ * Has OK status if column index returned by method equals to 1, + * FAILED otherwise. + */ + public void _findColumn() { + boolean result = false ; + String colName = (String) tEnv.getObjRelation("XColumnLocate.ColumnName") ; + + if (colName == null) { + throw new StatusException( + Status.failed("Object relation 'XColumnLocate.ColumnName' " + + "for this interface not found")); + } + + try { + int colIdx = oObj.findColumn(colName) ; + result = colIdx == 1 ; + } catch (SQLException e) { + log.println("Exception occurred:"); + e.printStackTrace(log); + result = false; + } + + tRes.tested("findColumn()", result); + } + +} // finish class _XColumnLocate + diff --git a/qadevOOo/tests/java/ifc/sdbc/_XDataSource.java b/qadevOOo/tests/java/ifc/sdbc/_XDataSource.java new file mode 100644 index 000000000..304ea7ded --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_XDataSource.java @@ -0,0 +1,105 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import lib.MultiMethodTest; + +import com.sun.star.sdbc.XConnection; +import com.sun.star.sdbc.XDataSource; + +/** +* Testing com.sun.star.sdbc.XDataSource +* interface methods : +*

+* @see com.sun.star.sdbc.XDataSource +*/ +public class _XDataSource extends MultiMethodTest { + // oObj filled by MultiMethodTest + public XDataSource oObj = null; + + /** + * Calls the method and checks returned value. + * Has OK status if exception wasn't thrown and + * if returned value isn't null. + */ + public void _getConnection() { + boolean res = true; + + try { + XConnection connection = oObj.getConnection("", ""); + res = connection != null; + } catch(com.sun.star.sdbc.SQLException e) { + log.println("Unexpected exception:"); + e.printStackTrace(log); + res = false; + } + + tRes.tested("getConnection()", res); + } + + /** + * Sets new timeout, compares with timeout returned by the method + * getLoginTimeout(). + * Has OK status if exception wasn't thrown and if timeout values are equal. + */ + public void _setLoginTimeout() { + requiredMethod("getLoginTimeout()"); + boolean res = true; + + try { + final int TO = 111; + log.println("setLoginTimeout(" + TO + ")"); + oObj.setLoginTimeout(TO); + int timeout = oObj.getLoginTimeout(); + res = timeout == TO; + log.println("getLoginTimeout(): " + timeout); + } catch(com.sun.star.sdbc.SQLException e) { + log.println("Unexpected exception:"); + e.printStackTrace(log); + res = false; + } + + tRes.tested("setLoginTimeout()", res); + } + + /** + * Calls the method and checks returned value. + * Has OK status if exception wasn't thrown and + * if returned value is equal to zero. + */ + public void _getLoginTimeout() { + boolean res = true; + + try { + int timeout = oObj.getLoginTimeout(); + log.println("getLoginTimeout(): " + timeout); + res = timeout == 0; + } catch(com.sun.star.sdbc.SQLException e) { + log.println("Unexpected exception:"); + e.printStackTrace(log); + res = false; + } + + tRes.tested("getLoginTimeout()", res); + } +} \ No newline at end of file diff --git a/qadevOOo/tests/java/ifc/sdbc/_XDriver.java b/qadevOOo/tests/java/ifc/sdbc/_XDriver.java new file mode 100644 index 000000000..4b0eb147f --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_XDriver.java @@ -0,0 +1,205 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.sdbc.DriverPropertyInfo; +import com.sun.star.sdbc.SQLException; +import com.sun.star.sdbc.XConnection; +import com.sun.star.sdbc.XDriver; + +/** +* Testing com.sun.star.sdbc.XDriver +* interface methods : +*

+* Required object relations : +*

+* @see com.sun.star.sdbc.XDriver +*/ +public class _XDriver extends MultiMethodTest { + // oObj filled by MultiMethodTest + public XDriver oObj = null; + String url = null; + String wrongUrl = null; + String nbu = null; + PropertyValue[] info = null; + + /** + * Retrieves relations. + * @throw StatusException If any relation not found. + */ + @Override + protected void before() { + nbu = (String) tEnv.getObjRelation("NoBadURL"); + url = (String)tEnv.getObjRelation("XDriver.URL"); + if (url == null) { + throw new StatusException(Status.failed( + "Couldn't get relation 'XDriver.URL'")); + } + wrongUrl = (String)tEnv.getObjRelation("XDriver.UNSUITABLE_URL"); + if (wrongUrl == null) { + throw new StatusException(Status.failed( + "Couldn't get relation 'XDriver.WRONG_URL'")); + } + info = (PropertyValue[])tEnv.getObjRelation("XDriver.INFO"); + if (info == null) { + throw new StatusException(Status.failed( + "Couldn't get relation 'XDriver.INFO'")); + } + } + + /** + * Connects to 'XDriver.URL', + * to 'XDriver.UNSUITABLE_URL' and to wrong URL using + * 'XDriver.INFO'. + * Has OK status if the method returns not null for 'XDriver.URL', + * null for 'XDriver.UNSUITABLE_URL' and + * exception was thrown during the call with a wrong URL. + */ + public void _connect() { + boolean res = true; + + try { + log.println("Trying to connect to " + url); + XConnection connection = oObj.connect(url, info); + res = (connection != null); + log.println("Connected? " + res); + log.println("Trying to connect to " + wrongUrl); + connection = oObj.connect(wrongUrl, info); + res &= (connection == null); + log.println("Connected? " + !res); + } catch(SQLException e) { + log.println("Unexpected exception"); + res &= false; + } + + if (nbu==null) { + try { + String badUrl = url + "bla"; + log.println("Trying to connect to " + badUrl); + oObj.connect(badUrl, info); + res &= false; + log.println("Expected exception isn't thrown"); + } catch(SQLException e) { + log.println("Expected exception"); + res &= true; + } + } + + tRes.tested("connect()", res); + } + + /** + * Calls the method for 'XDriver.URL' and + * for 'XDriver.UNSUITABLE_URL'. + * Has OK status if the method returns true for 'XDriver.URL' + * and false for 'XDriver.UNSUITABLE_URL'. + */ + public void _acceptsURL() { + boolean res = false; + + try { + res = oObj.acceptsURL(url); + log.println("Accepts " + url + "? " + res); + res &= !oObj.acceptsURL(wrongUrl); + log.println("Accepts " + wrongUrl + "? " + !res); + } catch(SQLException e) { + log.println("Unexpected exception"); + e.printStackTrace(log); + res = false; + } + + tRes.tested("acceptsURL()", res); + } + + /** + * Calls the method with passed 'XDriver.URL' and + * 'XDriver.INFO'. Prints obtained driver properties info + * to log. + * Has OK status if returned value isn't null. + */ + public void _getPropertyInfo() { + requiredMethod("acceptsURL()"); + boolean res = false; + DriverPropertyInfo[] dpi = null; + try { + dpi = oObj.getPropertyInfo(url, info); + } catch(SQLException e) { + log.println("Unexpected exception"); + e.printStackTrace(log); + res = false; + } + + if (dpi != null) { + res = true; + log.println("Driver properties info:"); + for(int i = 0; i < dpi.length; i++) { + log.println("Property: " + dpi[i].Name); + log.println("Description: " + dpi[i].Description); + log.println("IsRequired? " + dpi[i].IsRequired); + log.println("Value: " + dpi[i].Value); + log.println("Choices: "); + for(int j = 0; j < dpi[i].Choices.length; j++) { + log.println("\t" + dpi[i].Choices[j]); + } + } + } + + tRes.tested("getPropertyInfo()", res); + } + + /** + * Calls the method. + * Has OK status if returned value is greater than or is equal to 1. + */ + public void _getMajorVersion() { + int majorVer = oObj.getMajorVersion(); + boolean res = majorVer >= 1; + log.println("Major version " + majorVer); + tRes.tested("getMajorVersion()", res); + } + + /** + * Calls the method. + * Has OK status if returned value is greater than or is equal to 0. + */ + public void _getMinorVersion() { + int minorVer = oObj.getMinorVersion(); + boolean res = minorVer >= 0; + log.println("Minor version " + minorVer); + tRes.tested("getMinorVersion()", res); + } +} \ No newline at end of file diff --git a/qadevOOo/tests/java/ifc/sdbc/_XDriverManager.java b/qadevOOo/tests/java/ifc/sdbc/_XDriverManager.java new file mode 100644 index 000000000..57477b4a7 --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_XDriverManager.java @@ -0,0 +1,152 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.sdbc.XConnection; +import com.sun.star.sdbc.XDriverManager; + +/** +* Testing com.sun.star.sdbc.XDriverManager +* interface methods : +*

+* Required object relations : +*

+* @see com.sun.star.sdbc.XDriverManager +*/ +public class _XDriverManager extends MultiMethodTest { + // oObj filled by MultiMethodTest + public XDriverManager oObj = null; + String sdbcURL = null; + String jdbcURL = null; + PropertyValue[] jdbcINFO = null; + + /** + * Retrieves the required object relations. + */ + @Override + protected void before() { + sdbcURL = (String)tEnv.getObjRelation("SDBC.URL"); + if (sdbcURL == null) { + throw new StatusException( + Status.failed("Couldn't get relation 'SDBC.URL'")); + } + jdbcURL = (String)tEnv.getObjRelation("JDBC.URL"); + if (jdbcURL == null) { + throw new StatusException( + Status.failed("Couldn't get relation 'JDBC.URL'")); + } + jdbcINFO = (PropertyValue[])tEnv.getObjRelation("JDBC.INFO"); + if (jdbcINFO == null) { + throw new StatusException( + Status.failed("Couldn't get relation 'JDBC.INFO'")); + } + } + + /** + * Calls the method with the url received from the relation + * SDBC.URL. + * Has OK status if exception wasn't thrown and + * if returned value isn't null. + */ + public void _getConnection() { + boolean res = true; + + try { + log.println("getConnection(" + sdbcURL + ")"); + XConnection connection = oObj.getConnection(sdbcURL); + res = connection != null; + } catch(com.sun.star.sdbc.SQLException e) { + log.println("Unexpected exception"); + e.printStackTrace(log); + res = false; + } + + tRes.tested("getConnection()", res); + } + + /** + * Calls the method with the url received from the relation + * JDBC.URL and with info received from the relation + * JDBC.INFO. + * Has OK status if exception wasn't thrown and + * if returned value isn't null. + */ + public void _getConnectionWithInfo() { + boolean res = true; + + try { + log.println("getConnectionWithInfo(" + jdbcURL + ")"); + XConnection connection = + oObj.getConnectionWithInfo(jdbcURL, jdbcINFO); + res = connection != null; + } catch(com.sun.star.sdbc.SQLException e) { + log.println("Unexpected exception"); + e.printStackTrace(log); + res = false; + } + + tRes.tested("getConnectionWithInfo()", res); + } + + /** + * Calls the method and checks returned value. + * Has OK status if timeout that was set and timeout that was returned by + * the method getLoginTimeout() are equal. + */ + public void _setLoginTimeout() { + requiredMethod("getLoginTimeout()"); + final int TO = 111; + log.println("setLoginTimeout(" + TO + ")"); + oObj.setLoginTimeout(TO); + int timeout = oObj.getLoginTimeout(); + log.println("getLoginTimeout(): " + timeout); + tRes.tested("setLoginTimeout()", timeout == TO); + } + + /** + * Calls the method. + */ + public void _getLoginTimeout() { + int timeout = oObj.getLoginTimeout(); + log.println("getLoginTimeout(): " + timeout); + + tRes.tested("getLoginTimeout()", true); + } +} \ No newline at end of file diff --git a/qadevOOo/tests/java/ifc/sdbc/_XIsolatedConnection.java b/qadevOOo/tests/java/ifc/sdbc/_XIsolatedConnection.java new file mode 100644 index 000000000..64af7feb5 --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_XIsolatedConnection.java @@ -0,0 +1,111 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import lib.MultiMethodTest; +import lib.StatusException; + +import com.sun.star.sdbc.XConnection; +import com.sun.star.sdbc.XIsolatedConnection; +import com.sun.star.task.XInteractionHandler; + +/** + * Testing com.sun.star.sdb.XCompletedConnection + * interface methods : + *

+* The following object relations required : +*

+* @see com.sun.star.sdb.XIsolatedConnection +* @see com.sun.star.task.XInteractionHandler +* @see com.sun.star.sdbc.XConnection +*/ +public class _XIsolatedConnection extends MultiMethodTest { + + // oObj filled by MultiMethodTest + public XIsolatedConnection oObj = null ; + + /** + * Test call the method with handler passed as object relation. + * Then value returned is checked.

+ * Has OK status if not null value returned. < > + * FAILED if exception occurred, null value returned or object + * relation was not found. + */ + public void _getIsolatedConnectionWithCompletion() throws StatusException { + XInteractionHandler handler = (XInteractionHandler) + tEnv.getObjRelation("XCompletedConnection.Handler") ; + + if (handler == null) { + log.println("Required object relation not found !") ; + tRes.tested("getIsolatedConnectionWithCompletion()", false) ; + return ; + } + + XConnection con = null ; + try { + con = oObj.getIsolatedConnectionWithCompletion(handler) ; + } catch (com.sun.star.sdbc.SQLException e) { + throw new StatusException("Exception while method calling", e) ; + } + + tRes.tested("getIsolatedConnectionWithCompletion()", con != null) ; + } + + /** + * Test call the method with handler passed as object relation. + * Then value returned is checked.

+ * Has OK status if not null value returned. < > + * FAILED if exception occurred, null value returned or object + * relation was not found. + */ + public void _getIsolatedConnection() throws StatusException { + String[] userSettings = (String[]) + tEnv.getObjRelation("UserAndPassword") ; + + String user = null; + String pwd = null; + + if (userSettings[0] != null) + user = userSettings[0].equals("")?"":userSettings[0]; + else + user = ""; + if (userSettings[1] != null) + pwd = userSettings[1].equals("")?"":userSettings[1]; + else + pwd = ""; + + log.println("Testing \"getIsolatedConnection('user', 'password')\"\n" + + "with user = '" + user + "'; password = '" + pwd + "'"); + XConnection con = null ; + try { + con = oObj.getIsolatedConnection(user, pwd) ; + } catch (com.sun.star.sdbc.SQLException e) { + throw new StatusException("Exception while method calling", e) ; + } + + tRes.tested("getIsolatedConnection()", con != null) ; + } +} // finish class _XIsolatedConnection + diff --git a/qadevOOo/tests/java/ifc/sdbc/_XParameters.java b/qadevOOo/tests/java/ifc/sdbc/_XParameters.java new file mode 100644 index 000000000..4284931fe --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_XParameters.java @@ -0,0 +1,564 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import java.util.List; + +import lib.MultiMethodTest; +import lib.Status; + +import com.sun.star.io.XDataInputStream; +import com.sun.star.io.XInputStream; +import com.sun.star.io.XTextInputStream; +import com.sun.star.sdbc.DataType; +import com.sun.star.sdbc.SQLException; +import com.sun.star.sdbc.XParameters; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.util.Date; +import com.sun.star.util.DateTime; +import com.sun.star.util.Time; + +/** +/** +* Testing com.sun.star.sdbc.XParameters +* interface methods : +*

+* Object relations required : +*

+* @see com.sun.star.sdbc.XParameters +*/ +public class _XParameters extends MultiMethodTest { + + // oObj filled by MultiMethodTest + public XParameters oObj = null ; + + private List data = null ; + + /** + * Gets object relation + */ + @Override + public void before() { + data = (List) tEnv.getObjRelation("XParameters.ParamValues") ; + if (data == null) { + log.println("!!! Relation not found !!!") ; + } + } + + /** + * Sets String parameter (if exists) to SQL NULL value.

+ * Has OK status if no exceptions occurred. + */ + public void _setNull() { + boolean result = true ; + int idx = findParamOfType(String.class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.setNull(idx, DataType.VARCHAR) ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setNull()", result) ; + } + + public void _setObjectNull() { + /* + !!! TO DO !!! + */ + tRes.tested("setObjectNull()", Status.skipped(true)) ; + } + + /** + * Sets String parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setString() { + boolean result = true ; + int idx = findParamOfType(String.class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.setString(idx, "XParameters") ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setString()", result) ; + } + + /** + * Sets parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setBoolean() { + boolean result = true ; + int idx = findParamOfType(Boolean.class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.setBoolean(idx, true) ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setBoolean()", result) ; + } + + /** + * Sets parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setByte() { + boolean result = true ; + int idx = findParamOfType(Byte.class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.setByte(idx, (byte)122) ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setByte()", result) ; + } + + /** + * Sets parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setShort() { + boolean result = true ; + int idx = findParamOfType(Short.class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.setShort(idx, (short)133) ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setShort()", result) ; + } + + /** + * Sets parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setInt() { + boolean result = true ; + int idx = findParamOfType(Integer.class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.setInt(idx, 13300) ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setInt()", result) ; + } + + /** + * Sets parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setLong() { + boolean result = true ; + int idx = findParamOfType(Long.class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.setLong(idx, 13362453) ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setLong()", result) ; + } + + /** + * Sets parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setFloat() { + boolean result = true ; + int idx = findParamOfType(Float.class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.setFloat(idx, (float)133.55) ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setFloat()", result) ; + } + + /** + * Sets parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setDouble() { + boolean result = true ; + int idx = findParamOfType(Double.class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.setDouble(idx, 133) ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setDouble()", result) ; + } + + /** + * Sets parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setBytes() { + boolean result = true ; + int idx = findParamOfType(byte[].class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.setBytes(idx, new byte[] {5}) ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setBytes()", result) ; + } + + /** + * Sets parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setDate() { + boolean result = true ; + int idx = findParamOfType(Date.class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.setDate( + idx, new Date ((short)19, (short)1, (short)1979)) ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setDate()", result) ; + } + + /** + * Sets parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setTime() { + boolean result = true ; + int idx = findParamOfType(Time.class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.setTime( + idx, new Time((short)1,(short)2,(short)3,(short)44, false)); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setTime()", result) ; + } + + /** + * Sets parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setTimestamp() { + boolean result = true ; + int idx = findParamOfType(DateTime.class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.setTimestamp(idx, new DateTime((short)1,(short)2,(short)3, + (short)4, (short)19, (short)1, (short)1979, false)) ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setTimestamp()", result) ; + } + + /** + * Sets parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setBinaryStream() { + boolean result = true ; + int idx = findParamOfType(XDataInputStream.class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + Object oStream = tParam.getMSF(). + createInstance("com.sun.star.io.DataInputStream") ; + XInputStream xStream = UnoRuntime.queryInterface + (XInputStream.class, oStream); + + oObj.setBinaryStream(idx, xStream, 2) ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } catch (com.sun.star.uno.Exception e) { + log.println("Unexpected exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setBinaryStream()", result) ; + } + + /** + * Sets parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setCharacterStream() { + boolean result = true ; + int idx = findParamOfType(XTextInputStream.class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + Object oStream = tParam.getMSF() + .createInstance("com.sun.star.io.TextInputStream") ; + XInputStream xStream = UnoRuntime.queryInterface + (XInputStream.class, oStream); + + oObj.setCharacterStream(idx, xStream, 2) ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } catch (com.sun.star.uno.Exception e) { + log.println("Unexpected exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setCharacterStream()", result) ; + } + + /** + * Sets parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setObject() { + boolean result = true ; + int idx = findParamOfType(Object[].class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + Object obj = tParam.getMSF(). + createInstance("com.sun.star.io.Pipe") ; + + oObj.setObject(idx, obj) ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } catch (com.sun.star.uno.Exception e) { + log.println("Unexpected exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setObject()", result) ; + } + + /** + * Sets parameter (if exists) to new value.

+ * Has OK status if no exceptions occurred. + */ + public void _setObjectWithInfo() { + boolean result = true ; + int idx = findParamOfType(Object[].class) ; + if (idx < 0) log.println("Type not found in relation: not tested"); + else { + try { + Object obj = tParam.getMSF(). + createInstance("com.sun.star.io.Pipe") ; + + oObj.setObjectWithInfo(idx, obj, DataType.OBJECT, 0) ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } catch (com.sun.star.uno.Exception e) { + log.println("Unexpected exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("setObjectWithInfo()", result) ; + } + + public void _setRef() { + /* + !!! TO DO !!! + */ + tRes.tested("setRef()", Status.skipped(true)) ; + } + public void _setBlob() { + /* + !!! TO DO !!! + */ + tRes.tested("setBlob()", Status.skipped(true)) ; + } + public void _setClob() { + /* + !!! TO DO !!! + */ + tRes.tested("setClob()", Status.skipped(true)) ; + } + public void _setArray() { + /* + !!! TO DO !!! + */ + tRes.tested("setArray()", Status.skipped(true)) ; + } + + /** + * Calls method.

+ * Has OK status if no exceptions occurred. + */ + public void _clearParameters() { + boolean result = true ; + try { + oObj.clearParameters() ; + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + + tRes.tested("clearParameters()", result) ; + } + + + /** + * Finds in relation vector index of parameter of the appropriate + * type. + */ + private int findParamOfType(Class clz) { + for (int i = 0; i < data.size(); i++) + if (clz.isInstance(data.get(i))) return i + 1 ; + return -1 ; + } + +} // finish class _XParameters + + diff --git a/qadevOOo/tests/java/ifc/sdbc/_XResultSet.java b/qadevOOo/tests/java/ifc/sdbc/_XResultSet.java new file mode 100644 index 000000000..a2114d7d0 --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_XResultSet.java @@ -0,0 +1,497 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import lib.MultiMethodTest; + +import com.sun.star.sdbc.SQLException; +import com.sun.star.sdbc.XResultSet; +import com.sun.star.sdbc.XRow; +import com.sun.star.sdbc.XRowUpdate; +import com.sun.star.uno.UnoRuntime; + +/** +/** +* Testing com.sun.star.sdbc.XResultSet +* interface methods : +*

    +*
  • next()
  • +*
  • isBeforeFirst()
  • +*
  • isAfterLast()
  • +*
  • isFirst()
  • +*
  • isLast()
  • +*
  • beforeFirst()
  • +*
  • afterLast()
  • +*
  • first()
  • +*
  • last()
  • +*
  • getRow()
  • +*
  • absolute()
  • +*
  • relative()
  • +*
  • previous()
  • +*
  • refreshRow()
  • +*
  • rowUpdated()
  • +*
  • rowInserted()
  • +*
  • rowDeleted()
  • +*
  • getStatement()
  • +*

+* This test needs the following object relations : +*

    +*
  • 'XResultSet.hasStatement' (optional of type +* Object): +* it the relation exists than getStatement method +* must not return null
  • +*

      +* Test places DB cursor to different positions and then checks +* its current position.

      +* Test is NOT multithread compliant.

      +* @see com.sun.star.sdbc.XResultSet +*/ +public class _XResultSet extends MultiMethodTest { + + // oObj filled by MultiMethodTest + public XResultSet oObj = null ; + + /** + * Positions the cursor to the first row. + * Forces method tests to be executed in definite order. + */ + @Override + public void before() { + try { + oObj.last() ; + log.println("Totally number of rows is " + oObj.getRow()) ; + oObj.first() ; + } catch (SQLException e) { + log.println("Ignored exception :") ; + e.printStackTrace(log); + } + + executeMethod("isBeforeFirst()") ; + executeMethod("isAfterLast()") ; + executeMethod("isLast()") ; + executeMethod("isFirst()") ; + executeMethod("next()") ; + executeMethod("previous()") ; + } + + /** + * Places the cursor before the first row.

      + * Has OK status if no exceptions were thrown. + */ + public void _beforeFirst() { + try { + oObj.beforeFirst() ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + tRes.tested("beforeFirst()", false) ; + return ; + } + tRes.tested("beforeFirst()", true) ; + } + + /** + * The method is called immediately after beforeFirst + * method test.

      + * Has OK status if method returns true.

      + * The following method tests are to be completed successfully before : + *

        + *
      • beforeFirst : to position cursor before + * the first row.
      • + *
      + */ + public void _isBeforeFirst() { + requiredMethod("beforeFirst()") ; + + boolean result = true ; + + try { + result = oObj.isBeforeFirst() ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + result = false ; + } + tRes.tested("isBeforeFirst()", result) ; + } + + /** + * Places the cursor after the last row.

      + * Has OK status if no exceptions were thrown. + */ + public void _afterLast() { + try { + oObj.afterLast() ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + tRes.tested("afterLast()", false) ; + return ; + } + tRes.tested("afterLast()", true) ; + } + + /** + * The method is called immediately after afterLast + * method test.

      + * Has OK status if method returns true

      + * The following method tests are to be completed successfully before : + *

        + *
      • afterLast : to position cursor after + * the last row.
      • + *
      + */ + public void _isAfterLast() { + requiredMethod("afterLast()") ; + + boolean result = true ; + + try { + result = oObj.isAfterLast() ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + result = false ; + } + tRes.tested("isAfterLast()", result) ; + } + + /** + * Places the cursor on the first row.

      + * Has OK status if no exceptions were thrown. + */ + public void _first() { + try { + oObj.first() ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + tRes.tested("first()", false) ; + return ; + } + tRes.tested("first()", true) ; + } + + /** + * The method is called immediately after first + * method test.

      + * Has OK status if method returns true.

      + * The following method tests are to be completed successfully before : + *

        + *
      • first : to position cursor on + * the first row.
      • + *
      + */ + public void _isFirst() { + requiredMethod("first()") ; + + boolean result = true ; + + try { + result = oObj.isFirst() ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + result = false ; + } + tRes.tested("isFirst()", result) ; + } + + /** + * Places the cursor on the last row.

      + * Has OK status if no exceptions were thrown. + */ + public void _last() { + try { + oObj.last() ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + tRes.tested("last()", false) ; + return ; + } + tRes.tested("last()", true) ; + } + + /** + * The method is called immediately after last + * method test.

      + * Has OK status if method returns true.

      + * The following method tests are to be completed successfully before : + *

        + *
      • last : to position cursor on + * the last row.
      • + *
      + */ + public void _isLast() { + requiredMethod("last()") ; + boolean result = true ; + + try { + result = oObj.isLast() ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + result = false ; + } + tRes.tested("isLast()", result) ; + } + + /** + * Places the cursor on the row number 1.

      + * Has OK status if no exceptions were thrown. + */ + public void _absolute() { + boolean result = true ; + + try { + oObj.absolute(1) ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + result = false ; + } + tRes.tested("absolute()", result) ; + } + + /** + * The method is called immediately after absolute + * method test.

      + * Has OK status if method returns 1.

      + * The following method tests are to be completed successfully before : + *

        + *
      • absolute : to position cursor on + * the row number 1.
      • + *
      + */ + public void _getRow() { + requiredMethod("absolute()"); + boolean result = true; + + try { + result &= oObj.getRow() == 1; + } catch (SQLException e) { + log.println("Exception occurred:"); + e.printStackTrace(log); + result = false; + } + + tRes.tested("getRow()", result); + } + + /** + * Positions the cursor to the next row. Current row + * number is retrieved before and after method call.

      + * Has OK status if current row number increases + * by 1 after method call. + */ + public void _next() { + boolean result = true ; + + try { + int prevRow = oObj.getRow() ; + oObj.next() ; + + log.println("Row was : " + prevRow + ", row is : " + oObj.getRow()); + result &= prevRow + 1 == oObj.getRow() ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + result = false ; + } + tRes.tested("next()", result) ; + } + + /** + * Positions the cursor to the previous row. Current row + * number is retrieved before and after method call.

      + * Has OK status if current row number decreases + * by 1 after method call. + */ + public void _previous() { + boolean result = true ; + + try { + int prevRow = oObj.getRow() ; + oObj.previous() ; + + log.println("Row was : " + prevRow + ", row is : " + oObj.getRow()); + result &= prevRow - 1 == oObj.getRow() ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + result = false ; + } + tRes.tested("previous()", result) ; + } + + /** + * Positions the cursor relatively by 2 rows forward. + * Current row number is retrieved before and after method call.

      + * Has OK status if current row number increases + * by 2 after method call. + */ + public void _relative() { + boolean result = true ; + + try { + oObj.first() ; + int prevRow = oObj.getRow() ; + oObj.relative(2) ; + + log.println("Row was : " + prevRow + ", row is : " + oObj.getRow()); + + result &= prevRow + 2 == oObj.getRow() ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + result = false ; + } + tRes.tested("relative()", result) ; + } + + /** + * If component supports XRow and XRowUpdate then: + * test saves current value of string field, updates string, + * calls refreshRow() and checks that value of + * string field was refetched from DB + * else: just calls method.

      + * Has OK status if no exceptions were thrown and value after + * refreshRow() equals to saved value. + */ + public void _refreshRow() { + XRowUpdate xRowUpdate = UnoRuntime.queryInterface(XRowUpdate.class, oObj); + XRow xRow = UnoRuntime.queryInterface(XRow.class, oObj); + + if (xRowUpdate == null || xRow == null) { + log.println("Test must be modified because XRow or XRowUpdate is't supported"); + log.println("Only call method"); + try { + oObj.refreshRow() ; + tRes.tested("refreshRow()", true) ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + tRes.tested("refreshRow()", false) ; + } + } else { + log.println("Testing of refreshRow()..."); + try { + String oldValue = xRow.getString(util.DBTools.TST_STRING); + log.println("Old value: " + oldValue); + xRowUpdate.updateString(util.DBTools.TST_STRING, + "Test method refreshRow"); + log.println("New value: " + + xRow.getString(util.DBTools.TST_STRING)); + oObj.refreshRow(); + String valAfterRefresh = + xRow.getString(util.DBTools.TST_STRING); + log.println("Value after refresh: " + valAfterRefresh); + tRes.tested("refreshRow()", valAfterRefresh.equals(oldValue)); + } catch(SQLException e) { + log.println("Exception occurred :"); + e.printStackTrace(log); + tRes.tested("refreshRow()", false); + } + } + } + + /** + * Just the method is called.

      + * Has OK status if no exceptions were thrown. + */ + public void _rowUpdated() { + + try { + oObj.rowUpdated(); + tRes.tested("rowUpdated()", true) ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + tRes.tested("rowUpdated()", false) ; + } + } + + /** + * Just the method is called.

      + * Has OK status if no exceptions were thrown. + */ + public void _rowInserted() { + try { + oObj.rowInserted(); + tRes.tested("rowInserted()", true) ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + tRes.tested("rowInserted()", false) ; + } + } + + /** + * Just the method is called.

      + * Has OK status if no exceptions were thrown. + */ + public void _rowDeleted() { + try { + oObj.rowDeleted(); + tRes.tested("rowDeleted()", true) ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + tRes.tested("rowDeleted()", false) ; + } + } + + /** + * Just the method is called.

      + * Has OK status if the statement returned isn't null or + * the relation exists that informs that statement absent (e.g. for + * MetaData row set). + */ + public void _getStatement() { + try { + boolean hasStatement = + tEnv.getObjRelation("XResultSet.hasStatement") != null ; + Object res = oObj.getStatement() ; + tRes.tested("getStatement()", + (hasStatement && res != null) || !hasStatement) ; + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + tRes.tested("getStatement()", false) ; + } + } + + /** + * Moves the cursor to the first row to avoid affection to + * the following interfaces tests + */ + @Override + public void after() { + log.println("Finally moving cursor to the first row ..."); + try { + oObj.first(); + } catch (SQLException e) { + log.println("Exception occurred :") ; + e.printStackTrace(log) ; + } + } + +} // finish class _XResultSet + diff --git a/qadevOOo/tests/java/ifc/sdbc/_XResultSetMetaDataSupplier.java b/qadevOOo/tests/java/ifc/sdbc/_XResultSetMetaDataSupplier.java new file mode 100644 index 000000000..0a721b368 --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_XResultSetMetaDataSupplier.java @@ -0,0 +1,60 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import lib.MultiMethodTest; + +import com.sun.star.sdbc.XResultSetMetaData; +import com.sun.star.sdbc.XResultSetMetaDataSupplier; + +/** +* Testing com.sun.star.sdbc.XResultSetMetaDataSupplier +* interface methods : +*

        +*
      • getMetaData()
      • +*

      +* Test is multithread compliant.

      +* @see com.sun.star.sdbc.XResultSetMetaDataSupplier +*/ +public class _XResultSetMetaDataSupplier extends MultiMethodTest { + + // oObj filled by MultiMethodTest + public XResultSetMetaDataSupplier oObj = null ; + + /** + * Tries to get the ResultSetMetaData of the Object
      + * an XResultSetMetaData is returned.
      + * The test is OK if a not null ResultSetMetaData is returned + */ + public void _getMetaData() { + + try { + XResultSetMetaData the_Meta = oObj.getMetaData(); + if (the_Meta == null) log.println("'getMetaData()' returns NULL"); + tRes.tested("getMetaData()",the_Meta != null); + } catch (com.sun.star.sdbc.SQLException e) { + log.println("Exception while checking 'createResultSet()'"); + e.printStackTrace(log); + tRes.tested("getMetaData()",false); + } + + } +} // finish class _XResultSetMetaDataSupplier + + diff --git a/qadevOOo/tests/java/ifc/sdbc/_XResultSetUpdate.java b/qadevOOo/tests/java/ifc/sdbc/_XResultSetUpdate.java new file mode 100644 index 000000000..372373910 --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_XResultSetUpdate.java @@ -0,0 +1,255 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import lib.MultiMethodTest; +import lib.StatusException; + +import com.sun.star.sdbc.SQLException; +import com.sun.star.sdbc.XResultSetUpdate; +import com.sun.star.sdbc.XRowUpdate; +import com.sun.star.uno.UnoRuntime; + +/** +/** +* Testing com.sun.star.sdbc.XResultSetUpdate +* interface methods : +*

        +*
      • insertRow()
      • +*
      • updateRow()
      • +*
      • deleteRow()
      • +*
      • cancelRowUpdates()
      • +*
      • moveToInsertRow()
      • +*
      • moveToCurrentRow()
      • +*

      +* The test requires the following object relations : +*

        +*
      • 'XResultSetUpdate.UpdateTester' +* inner UpdateTester interface implementation : +* is used for checking test results. See interface +* documentation for more information.
      • +*
      +* The test is not designed for multithreaded testing.

      +* After it's execution environment must be recreated. +* @see com.sun.star.sdbc.XResultSetUpdate +*/ +public class _XResultSetUpdate extends MultiMethodTest { + + // oObj filled by MultiMethodTest + public XResultSetUpdate oObj = null ; + + private UpdateTester tester = null ; + + /** + * Interface contains some methods for checking + * test results. It's implementation must be passed + * to this test. + */ + public interface UpdateTester { + /** + * @return Current number of rows. + */ + int rowCount() throws SQLException ; + /** + * Updates some data in the current row but doesn't commit + * changes to the source. + */ + void update() throws SQLException ; + /** + * Checks if updates made by method update was + * committed to the data source. + */ + boolean wasUpdated() throws SQLException ; + /** + * Returns current row number. Really it must returns value + * < 1 if the current position is on insert row. + */ + int currentRow() throws SQLException ; + } + + /** + * Retrieves relation. + * @throw StatusException If relation not found. + */ + @Override + public void before() throws StatusException { + tester = (UpdateTester)tEnv.getObjRelation + ("XResultSetUpdate.UpdateTester") ; + + if (tester == null) { + log.println("Required relation not found !!!") ; + throw new StatusException("Required relation not found !!!", + new NullPointerException()) ; + } + } + + /** + * Calls method when the cursor position is on existing row. + * Checks total number of rows before and after method call.

      + * Executes moveToCurrentRow method test before to + * be sure that cursor is not on the insert row.

      + * Has OK status if after method execution number of rows decreased + * by one. + */ + public void _deleteRow() { + executeMethod("moveToCurrentRow()") ; + + //temporary to avoid SOffice hanging + executeMethod("updateRow()") ; + executeMethod("cancelRowUpdates()") ; + + boolean result = true ; + try { + int rowsBefore = tester.rowCount() ; + oObj.deleteRow() ; + int rowsAfter = tester.rowCount() ; + + result = rowsBefore == rowsAfter + 1 ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("deleteRow()", result) ; + } + + /** + * Using relation methods first updates some data in the current + * row, then calls updateRow method to commit data. + * Then checks if the data changed was committed.

      + * Executes moveToCurrentRow method test before to + * be sure that cursor is not on the insert row.

      + * Has OK status if data in the source was changed. + */ + public void _updateRow() { + executeMethod("moveToCurrentRow()") ; + boolean result = true ; + try { + tester.update() ; + oObj.updateRow() ; + + result = tester.wasUpdated() ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + tRes.tested("updateRow()", result) ; + } + + /** + * Using relation methods first updates some data in the current + * row, then calls cancelRowUpdates method. + * Then checks if the data changed was not committed.

      + * Executes moveToCurrentRow method test before to + * be sure that cursor is not on the insert row.

      + * Has OK status if data in the source was not changed. + */ + public void _cancelRowUpdates() { + executeMethod("moveToCurrentRow()") ; + boolean result = true ; + try { + tester.update() ; + oObj.cancelRowUpdates() ; + + result = !tester.wasUpdated() ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + tRes.tested("cancelRowUpdates()", result) ; + } + + /** + * Tries to move cursor to insert row. Then checks current row + * number. It must be less than 1. (0 as I know)

      + */ + public void _moveToInsertRow() { + boolean result = true ; + try { + oObj.moveToInsertRow() ; + + result = tester.currentRow() < 1 ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + tRes.tested("moveToInsertRow()", result) ; + } + + /** + * Returns cursor from insert row back to previous row.

      + * moveToInsertRow method test must be executed + * first for positioning cursor to insert row.

      + * Has OK status if after method call current row number is + * above 0. + */ + public void _moveToCurrentRow() { + boolean result = true ; + try { + oObj.moveToCurrentRow() ; + + result = tester.currentRow() >= 1 ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + tRes.tested("moveToCurrentRow()", result) ; + } + + /** + * Moves cursor to the insert row, then calls the method + * insertRow. Before and after call stores + * total number of rows.

      + * Has OK status if after method call rows number increases + * by one. + */ + public void _insertRow() { + executeMethod("moveToInsertRow()") ; + boolean result = true ; + try { + oObj.moveToCurrentRow(); + int rowsBefore = tester.rowCount() ; + oObj.moveToInsertRow() ; + XRowUpdate rowU = UnoRuntime.queryInterface(XRowUpdate.class, oObj); + rowU.updateString(1,"open"); + rowU.updateInt(2,5); + rowU.updateDouble(5,3.4); + rowU.updateBoolean(10,true); + oObj.insertRow() ; + oObj.moveToCurrentRow(); + int rowsAfter = tester.rowCount() ; + result = rowsBefore + 1 == rowsAfter ; + } catch (SQLException e) { + e.printStackTrace(log) ; + log.println("******"+e.getMessage()); + result = false ; + } + tRes.tested("insertRow()", result) ; + } + + /** + * Forces environment to be recreated. + */ + @Override + public void after() { + //disposeEnvironment() ; + } +} // finish class _XResultSetUpdate + + diff --git a/qadevOOo/tests/java/ifc/sdbc/_XRow.java b/qadevOOo/tests/java/ifc/sdbc/_XRow.java new file mode 100644 index 000000000..70a60b0cf --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_XRow.java @@ -0,0 +1,527 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import java.util.List; + +import lib.MultiMethodTest; + +import com.sun.star.io.XDataInputStream; +import com.sun.star.io.XTextInputStream; +import com.sun.star.sdbc.SQLException; +import com.sun.star.sdbc.XArray; +import com.sun.star.sdbc.XBlob; +import com.sun.star.sdbc.XClob; +import com.sun.star.sdbc.XRef; +import com.sun.star.sdbc.XRow; +import com.sun.star.util.Date; +import com.sun.star.util.DateTime; +import com.sun.star.util.Time; + +/** +* Testing com.sun.star.sdbc.XRow +* interface methods : +*

        +*
      • wasNull()
      • +*
      • getString()
      • +*
      • getBoolean()
      • +*
      • getByte()
      • +*
      • getShort()
      • +*
      • getInt()
      • +*
      • getLong()
      • +*
      • getFloat()
      • +*
      • getDouble()
      • +*
      • getBytes()
      • +*
      • getDate()
      • +*
      • getTime()
      • +*
      • getTimestamp()
      • +*
      • getBinaryStream()
      • +*
      • getCharacterStream()
      • +*
      • getObject()
      • +*
      • getRef()
      • +*
      • getBlob()
      • +*
      • getClob()
      • +*
      • getArray()
      • +*

      +* +* This interface is full tested in XRowUpdate interface test. Here +* only exceptions checked. +*

      +* +* Object relations required : +*

        +*
      • 'CurrentRowData' : (may be used in other +* interface tests) is a java.util.Vector object +* that contains column types and values in current row. Each +* element of vector corresponds to appropriate column (element +* with index 0 to column 1, 1 -> 2, etc.).

        +* The following XRow methods correspond to classes +* in Vector : +*

          +*
        • getBinaryStream - +* com.sun.star.io.XDataInputStream class.
        • +*
        • getCharacterStream - +* com.sun.star.io.XTextInputStream class.
        • +*
        • getObject - +* java.lang.Object[] class, the element with +* index 0 must be used.
        • +*
        +* Other methods uses types they return (i.e. String +* for getString method, com.sun.star.sdbc.XRef +* for getRef method). +*
      • +*
      +* @see com.sun.star.sdbc.XRaw +* @see ifc.sdbc._XRowUpdate +*/ +public class _XRow extends MultiMethodTest { + + // oObj filled by MultiMethodTest + public XRow oObj = null ; + private List data = null ; + private static final boolean notNullRes = true; + + /** + * Retrieves object relation first. + */ + @Override + public void before() { + data = (List) tEnv.getObjRelation("CurrentRowData") ; + } + + /** + * Always has OK status. + */ + public void _wasNull() { + executeMethod("getString()") ; + executeMethod("getBoolean()") ; + executeMethod("getByte()") ; + executeMethod("getShort()") ; + executeMethod("getInt()") ; + executeMethod("getLong()") ; + executeMethod("getFloat()") ; + executeMethod("getDouble()") ; + executeMethod("getBytes()") ; + executeMethod("getDate()") ; + executeMethod("getTime()") ; + executeMethod("getTimestamp()") ; + executeMethod("getBinaryStream()") ; + executeMethod("getCharacterStream()") ; + executeMethod("getObject()") ; + executeMethod("getRef()") ; + executeMethod("getBlob()") ; + executeMethod("getClob()") ; + executeMethod("getArray()") ; + + tRes.tested("wasNull()", notNullRes) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getString() { + boolean result = true ; + int col = findColumnOfType(String.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getString(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getString()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getBoolean() { + boolean result = true ; + int col = findColumnOfType(Boolean.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getBoolean(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getBoolean()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getByte() { + boolean result = true ; + int col = findColumnOfType(Byte.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getByte(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getByte()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getShort() { + boolean result = true ; + int col = findColumnOfType(Short.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getShort(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getShort()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getInt() { + boolean result = true ; + int col = findColumnOfType(Integer.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getInt(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getInt()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getLong() { + boolean result = true ; + int col = findColumnOfType(Long.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getLong(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getLong()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getFloat() { + boolean result = true ; + int col = findColumnOfType(Float.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getFloat(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getFloat()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getDouble() { + boolean result = true ; + int col = findColumnOfType(Double.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getDouble(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getDouble()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getBytes() { + boolean result = true ; + int col = findColumnOfType(byte[].class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getBytes(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getBytes()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getDate() { + boolean result = true ; + int col = findColumnOfType(Date.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getDate(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getDate()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getTime() { + boolean result = true ; + int col = findColumnOfType(Time.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getTime(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getTime()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getTimestamp() { + boolean result = true ; + int col = findColumnOfType(DateTime.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getTimestamp(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getTimestamp()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getBinaryStream() { + boolean result = true ; + int col = findColumnOfType(XDataInputStream.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getBinaryStream(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getBinaryStream()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getCharacterStream() { + boolean result = true ; + int col = findColumnOfType(XTextInputStream.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getCharacterStream(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getCharacterStream()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getObject() { + boolean result = true ; + int col = findColumnOfType(Object[].class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getObject(col, null); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getObject()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getRef() { + boolean result = true ; + int col = findColumnOfType(XRef.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getRef(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getRef()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getBlob() { + boolean result = true ; + int col = findColumnOfType(XBlob.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getBlob(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getBlob()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getClob() { + boolean result = true ; + int col = findColumnOfType(XClob.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getClob(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getClob()", result) ; + } + + /** + * Has OK status if no exceptions occurred in method call. + */ + public void _getArray() { + boolean result = true ; + int col = findColumnOfType(XArray.class) ; + if (col < 0) log.println("Type not found in relation: not tested"); + else { + try { + oObj.getArray(col); + } catch (SQLException e) { + log.println("Unexpected SQL exception:") ; + log.println(e) ; + result = false ; + } + } + + tRes.tested("getArray()", result) ; + } + + /** + * Finds in relation vector index of column of the appropriate + * type. + */ + protected int findColumnOfType(Class clz) { + + for (int i = 0; i < data.size(); i++) + if (clz.isInstance(data.get(i))) return i + 1 ; + return -1 ; + } +} // finish class _XRow + + diff --git a/qadevOOo/tests/java/ifc/sdbc/_XRowSet.java b/qadevOOo/tests/java/ifc/sdbc/_XRowSet.java new file mode 100644 index 000000000..cda9da30b --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_XRowSet.java @@ -0,0 +1,192 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import ifc.sdb._XRowSetApproveBroadcaster; +import lib.MultiMethodTest; +import lib.StatusException; + +import com.sun.star.lang.EventObject; +import com.sun.star.sdbc.SQLException; +import com.sun.star.sdbc.XRowSet; +import com.sun.star.sdbc.XRowSetListener; + +/** +* Testing com.sun.star.sdbc.XRowSet +* interface methods : +*
        +*
      • execute()
      • +*
      • addRowSetListener()
      • +*
      • removeRowSetListener()
      • +*

      +* Required object relations : +*

        +*
      • 'XRowSetApproveBroadcaster.ApproveChecker': +* implementation of inner interface +* ifs.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker +* which can move cursor within a rowset, change row, and change the +* whole rowset.
      • +*

      +* It is better to recreate the object after test, because of unknown +* actions made by RowSetApproveChecker interface implementation. +* @see com.sun.star.sdbc.XRowSet +* @see ifc.sdb._XRowSetApproveBroadcaster +*/ +public class _XRowSet extends MultiMethodTest { + + // oObj filled by MultiMethodTest + public XRowSet oObj = null ; + private _XRowSetApproveBroadcaster.RowSetApproveChecker checker = null ; + private final TestListener listener = new TestListener() ; + + private static class TestListener implements XRowSetListener { + public boolean cursorMoved = false ; + public boolean rowChanged = false ; + public boolean rowSetChanged = false ; + + public void reset() { + cursorMoved = false ; + rowChanged = false ; + rowSetChanged = false ; + } + public void cursorMoved(EventObject ev) { + cursorMoved = true ; + } + public void rowChanged(EventObject ev) { + rowChanged = true ; + } + public void rowSetChanged(EventObject ev) { + rowSetChanged = true ; + } + public void disposing(EventObject ev) {} + } + + /** + * Retrieves relation. + * @throw StatusException If relation not found. + */ + @Override + public void before() throws StatusException { + checker = (_XRowSetApproveBroadcaster.RowSetApproveChecker) + tEnv.getObjRelation("XRowSetApproveBroadcaster.ApproveChecker") ; + + if (checker == null) { + log.println("Required relation not found !!!") ; + throw new StatusException("Required relation not found !!!", + new NullPointerException()) ; + } + } + + /** + * Reexecutes the RowSet and checks that listener was called.

      + * Has OK status if no exceptions were raised and listener was called. + */ + public void _execute() { + requiredMethod("addRowSetListener()"); + listener.reset(); + try { + oObj.execute() ; + } catch (SQLException e) { + log.println("Exception occurred :" + e) ; + } + + tRes.tested("execute()", listener.rowSetChanged); + } + + /** + * Adds listener and calls methods moveCursor, changeRow, + * changeRowSet of the relation and then checks if appropriate + * methods of the listener were called.

      + * Has OK status if all listener methods were called. + */ + public void _addRowSetListener() { + boolean result = true ; + + oObj.addRowSetListener(listener) ; + + checker.moveCursor() ; + result &= listener.cursorMoved ; + if (!listener.cursorMoved) + log.println("cursorMoved event wasn't called") ; + listener.reset() ; + + checker.changeRow() ; + result &= listener.rowChanged ; + if (!listener.rowChanged) + log.println("rowChanged event wasn't called") ; + listener.reset() ; + + checker.changeRowSet() ; + result &= listener.rowSetChanged ; + if (!listener.rowSetChanged) + log.println("rowSetChanged event wasn't called") ; + listener.reset() ; + + tRes.tested("addRowSetListener()", result) ; + } + + /* + * Removes listener added before, and checks for no listener + * methods were called on response to rowSet manipulations.

      + * Methods to be successfully completed before : + *

        + *
      • addRowSetListener()
      • + *

      + * Has OK status if no listeners methods were called. + */ + public void _removeRowSetListener() { + requiredMethod("addRowSetListener()") ; + + boolean result = true ; + + oObj.removeRowSetListener(listener) ; + + checker.moveCursor() ; + if (listener.cursorMoved) { + log.println("cursorMoved is erroneously set"); + result = false; + } + listener.reset() ; + + checker.changeRow() ; + if (listener.rowChanged) { + log.println("rowChanged is erroneously set"); + result = false; + } + listener.reset() ; + + checker.changeRowSet() ; + if (listener.rowSetChanged) { + log.println("rowSetChanged is erroneously set"); + result = false; + } + + tRes.tested("removeRowSetListener()", result) ; + } + + /** + * Disposes test environment. + */ + @Override + public void after() { + disposeEnvironment() ; + } + +} // finish class _XRowSet + diff --git a/qadevOOo/tests/java/ifc/sdbc/_XRowUpdate.java b/qadevOOo/tests/java/ifc/sdbc/_XRowUpdate.java new file mode 100644 index 000000000..e57b2f062 --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_XRowUpdate.java @@ -0,0 +1,683 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import java.util.List; + +import lib.MultiMethodTest; +import lib.Status; +import util.utils; +import util.ValueComparer; + +import com.sun.star.io.XDataInputStream; +import com.sun.star.io.XInputStream; +import com.sun.star.io.XTextInputStream; +import com.sun.star.sdbc.SQLException; +import com.sun.star.sdbc.XRow; +import com.sun.star.sdbc.XRowUpdate; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.util.Date; +import com.sun.star.util.DateTime; +import com.sun.star.util.Time; + +/** +* Testing com.sun.star.sdbc.XRowUpdate +* interface methods : +*

        +*
      • updateNull()
      • +*
      • updateBoolean()
      • +*
      • updateByte()
      • +*
      • updateShort()
      • +*
      • updateInt()
      • +*
      • updateLong()
      • +*
      • updateFloat()
      • +*
      • updateDouble()
      • +*
      • updateString()
      • +*
      • updateBytes()
      • +*
      • updateDate()
      • +*
      • updateTime()
      • +*
      • updateTimestamp()
      • +*
      • updateBinaryStream()
      • +*
      • updateCharacterStream()
      • +*
      • updateObject()
      • +*
      • updateNumericObject()
      • +*

      +* Object relations required : +*

        +*
      • 'CurrentRowData' : (may be used in other +* interface tests) is a java.util.Vector object +* that contains column types and values in current row. Each +* element of vector corresponds to appropriate column (element +* with index 0 to column 1, 1 -> 2, etc.).

        +* The following XRowUpdate methods correspond to classes +* in Vector : +*

          +*
        • setBinaryStream - +* com.sun.star.io.XDataInputStream class.
        • +*
        • setCharacterStream - +* com.sun.star.io.XTextInputStream class.
        • +*
        • setObject - +* java.lang.Object[] class, the element with +* index 0 must be used.
        • +*
        +* Other methods uses types they return (i.e. String +* for setString method, com.sun.star.sdbc.XRef +* for setRef method). +*
      • +*
      • 'XRowUpdate.XRow' : implementation of +* com.sun.star.sdbc.XRow interface for checking updated data. +*
      • +*

      +* The test damages the object, so it is recreated finally. +* @see com.sun.star.sdbc.XRowUpdate +* @see com.sun.star.sdbc.XRow +*/ +public class _XRowUpdate extends MultiMethodTest { + + // oObj filled by MultiMethodTest + public XRowUpdate oObj = null ; + + private List rowData = null ; + private XRow row = null ; + + /** + * Gets relations. + */ + @Override + public void before() { + rowData = (List) tEnv.getObjRelation("CurrentRowData") ; + if (rowData == null) { + log.println("!!! 'CurrentRowData' relation not found !!!") ; + } + row = (XRow) tEnv.getObjRelation("XRowUpdate.XRow") ; + if (rowData == null) { + log.println("!!! 'XRowUpdate.XRow' relation not found !!!") ; + } + } + + /** + * Try to set NULL value for each column. Then using XRow + * relation check if NULL was really set.

      + * Has OK status if for every column NULL value was successfully set. + * @see com.sun.star.sdbc.XRow + */ + public void _updateNull() { + boolean result = true ; + for (int i = 0; i < rowData.size(); i++) { + if (rowData.get(i) == null) continue ; + log.print(" Setting NULL at column #" + (i+1) + " ...") ; + try { + oObj.updateNull(i + 1) ; + + if (rowData.get(i) instanceof String) row.getString(i + 1) ; + if (rowData.get(i) instanceof Boolean) row.getBoolean(i + 1) ; + if (rowData.get(i) instanceof Byte) row.getByte(i + 1) ; + if (rowData.get(i) instanceof Short) row.getShort(i + 1) ; + if (rowData.get(i) instanceof Integer) row.getInt(i + 1) ; + if (rowData.get(i) instanceof Long) row.getLong(i + 1) ; + if (rowData.get(i) instanceof Float) row.getFloat(i + 1) ; + if (rowData.get(i) instanceof Double) row.getDouble(i + 1) ; + if (rowData.get(i) instanceof byte[]) row.getBytes(i + 1) ; + if (rowData.get(i) instanceof Date) row.getDate(i + 1) ; + if (rowData.get(i) instanceof Time) row.getTime(i + 1) ; + if (rowData.get(i) instanceof DateTime) + row.getTimestamp(i + 1) ; + if (rowData.get(i) instanceof XDataInputStream) + row.getBinaryStream(i + 1) ; + if (rowData.get(i) instanceof XTextInputStream) + row.getCharacterStream(i + 1) ; + + if (!row.wasNull()) { + log.println("FAILED") ; + log.println("Not NULL was returned !!!") ; + result = false ; + } else { + log.println("OK") ; + } + } catch (SQLException e) { + log.println("FAILED") ; + e.printStackTrace(log) ; + result = false ; + } + } + + tRes.tested("updateNull()", result) ; + } + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateBoolean() { + boolean result = true ; + int idx = findColumnOfType(Boolean.class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateBoolean()", Status.skipped(true)) ; + return ; + } + + try { + boolean newVal = !row.getBoolean(idx) ; + oObj.updateBoolean(idx, newVal) ; + boolean getVal = row.getBoolean(idx) ; + result = newVal == getVal ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateBoolean()", result) ; + } + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateByte() { + boolean result = true ; + int idx = findColumnOfType(Byte.class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateByte()", Status.skipped(true)) ; + return ; + } + + try { + byte newVal = (byte) (row.getByte(idx) + 1) ; + oObj.updateByte(idx, newVal) ; + byte getVal = row.getByte(idx) ; + result = newVal == getVal ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateByte()", result) ; + } + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateShort() { + boolean result = true ; + int idx = findColumnOfType(Short.class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateShort()", Status.skipped(true)) ; + return ; + } + + try { + short newVal = (short) (row.getShort(idx) + 1) ; + oObj.updateShort(idx, newVal) ; + short getVal = row.getShort(idx) ; + result = newVal == getVal ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateShort()", result) ; + } + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateInt() { + boolean result = true ; + int idx = findColumnOfType(Integer.class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateInt()", Status.skipped(true)) ; + return ; + } + + try { + int newVal = 1 + row.getInt(idx) ; + oObj.updateInt(idx, newVal) ; + int getVal = row.getInt(idx) ; + result = newVal == getVal ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateInt()", result) ; + } + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateLong() { + boolean result = true ; + int idx = findColumnOfType(Long.class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateLong()", Status.skipped(true)) ; + return ; + } + + try { + long newVal = 1 + row.getLong(idx) ; + oObj.updateLong(idx, newVal) ; + long getVal = row.getLong(idx) ; + result = newVal == getVal ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateLong()", result) ; + } + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateFloat() { + boolean result = true ; + int idx = findColumnOfType(Float.class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateFloat()", Status.skipped(true)) ; + return ; + } + + try { + float newVal = (float) (1.1 + row.getFloat(idx)); + oObj.updateFloat(idx, newVal) ; + float getVal = row.getFloat(idx) ; + result = newVal == getVal ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateFloat()", result) ; + } + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateDouble() { + boolean result = true ; + int idx = findColumnOfType(Double.class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateDouble()", Status.skipped(true)) ; + return ; + } + + try { + double newVal = 1.1 + row.getDouble(idx) ; + oObj.updateDouble(idx, newVal) ; + double getVal = row.getDouble(idx) ; + result = utils.approxEqual(newVal, getVal); + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateDouble()", result) ; + } + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateString() { + boolean result = true ; + int idx = findColumnOfType(String.class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateString()", Status.skipped(true)) ; + return ; + } + + try { + String newVal = "_" + row.getString(idx) ; + oObj.updateString(idx, newVal) ; + String getVal = row.getString(idx) ; + result = newVal.equals(getVal) ; + log.println("New value = '" + newVal + "', get value = '" + + getVal + "'") ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateString()", result) ; + } + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateBytes() { + boolean result = true ; + int idx = findColumnOfType(byte[].class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateBytes()", Status.skipped(true)) ; + return ; + } + + try { + byte[] newVal = row.getBytes(idx) ; + if (newVal == null || newVal.length == 0) { + newVal = new byte[] {34, 111, 98} ; + } else { + newVal = new byte[] {(byte) (newVal[0] + 1), 111, 98} ; + } + oObj.updateBytes(idx, newVal) ; + byte[] getVal = row.getBytes(idx) ; + result = ValueComparer.equalValue(newVal, getVal) ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateBytes()", result) ; + } + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateDate() { + boolean result = true ; + int idx = findColumnOfType(Date.class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateDate()", Status.skipped(true)) ; + return ; + } + + try { + Date newVal = row.getDate(idx) ; + newVal.Year ++ ; + oObj.updateDate(idx, newVal) ; + Date getVal = row.getDate(idx) ; + result = ValueComparer.equalValue(newVal, getVal) ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateDate()", result) ; + } + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateTime() { + boolean result = true ; + int idx = findColumnOfType(Time.class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateTime()", Status.skipped(true)) ; + return ; + } + + try { + Time newVal = row.getTime(idx) ; + newVal.Seconds ++ ; + oObj.updateTime(idx, newVal) ; + Time getVal = row.getTime(idx) ; + result = ValueComparer.equalValue(newVal, getVal) ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateTime()", result) ; + } + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateTimestamp() { + boolean result = true ; + int idx = findColumnOfType(DateTime.class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateTimestamp()", Status.skipped(true)) ; + return ; + } + + try { + DateTime newVal = row.getTimestamp(idx) ; + newVal.Year ++ ; + oObj.updateTimestamp(idx, newVal) ; + DateTime getVal = row.getTimestamp(idx) ; + result = ValueComparer.equalValue(newVal, getVal) ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateTimestamp()", result) ; + } + + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateBinaryStream() { + boolean result = true ; + int idx = findColumnOfType(XDataInputStream.class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateBinaryStream()", Status.skipped(true)) ; + return ; + } + + try { + Object oStream = tParam.getMSF(). + createInstance("com.sun.star.io.DataInputStream") ; + XInputStream newVal = UnoRuntime.queryInterface + (XInputStream.class, oStream); + + oObj.updateBinaryStream(idx, newVal, 0) ; + XInputStream getVal = row.getBinaryStream(idx) ; + result = UnoRuntime.areSame(newVal, getVal) ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } catch (com.sun.star.uno.Exception e) { + log.println("Unexpected exception:") ; + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateBinaryStream()", result) ; + } + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateCharacterStream() { + boolean result = true ; + int idx = findColumnOfType(XTextInputStream.class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateCharacterStream()", Status.skipped(true)) ; + return ; + } + + try { + Object oStream = tParam.getMSF(). + createInstance("com.sun.star.io.TextInputStream") ; + XInputStream newVal = UnoRuntime.queryInterface + (XInputStream.class, oStream); + + oObj.updateCharacterStream(idx, newVal, 0) ; + XInputStream getVal = row.getCharacterStream(idx) ; + result = UnoRuntime.areSame(newVal, getVal) ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } catch (com.sun.star.uno.Exception e) { + log.println("Unexpected exception:") ; + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateCharacterStream()", result) ; + } + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateObject() { + boolean result = true ; + int idx = findColumnOfType(Object[].class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateObject()", Status.skipped(true)) ; + return ; + } + + try { + Object newVal = tParam.getMSF(). + createInstance("com.sun.star.io.Pipe") ; + + oObj.updateObject(idx, newVal) ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } catch (com.sun.star.uno.Exception e) { + log.println("Unexpected exception:") ; + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateObject()", result) ; + } + + /** + * Updates column with the appropriate type (if exists) and then + * checks result with interface XRow.

      + * Has OK status if column successfully updated, ahd the same + * result returned. + */ + public void _updateNumericObject() { + boolean result = true ; + int idx = findColumnOfType(Object[].class) ; + + if (idx < 0) { + log.println("Required type not found") ; + tRes.tested("updateNumericObject()", Status.skipped(true)) ; + return ; + } + + try { + Object newVal = tParam.getMSF(). + createInstance("com.sun.star.io.Pipe") ; + + oObj.updateNumericObject(idx, newVal, 0) ; + } catch (SQLException e) { + e.printStackTrace(log) ; + result = false ; + } catch (com.sun.star.uno.Exception e) { + log.println("Unexpected exception:") ; + e.printStackTrace(log) ; + result = false ; + } + + tRes.tested("updateNumericObject()", result) ; + } + + /** + * Finds in relation vector index of column of the appropriate + * type. + */ + protected int findColumnOfType(Class clz) { + + for (int i = 0; i < rowData.size(); i++) + if (clz.isInstance(rowData.get(i))) return i + 1 ; + return -1 ; + } + + /** + * Disposes environment. + */ + @Override + public void after() { + disposeEnvironment() ; + } + +} // finish class _XRow + + diff --git a/qadevOOo/tests/java/ifc/sdbc/_XWarningsSupplier.java b/qadevOOo/tests/java/ifc/sdbc/_XWarningsSupplier.java new file mode 100644 index 000000000..1758ccb1b --- /dev/null +++ b/qadevOOo/tests/java/ifc/sdbc/_XWarningsSupplier.java @@ -0,0 +1,130 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you 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 . + */ + +package ifc.sdbc; + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; +import util.DBTools; +import util.utils; + +import com.sun.star.sdbc.SQLException; +import com.sun.star.sdbc.XResultSetUpdate; +import com.sun.star.sdbc.XRow; +import com.sun.star.sdbc.XRowUpdate; +import com.sun.star.sdbc.XWarningsSupplier; +import com.sun.star.uno.UnoRuntime; + +/** +* Testing com.sun.star.sdbc.XWarningsSupplier +* interface methods : +*

        +*
      • getWarnings()
      • +*
      • clearWarnings()
      • +*

      +* @see com.sun.star.sdbc.XWarningsSupplier +*/ +public class _XWarningsSupplier extends MultiMethodTest { + + // oObj filled by MultiMethodTest + public XWarningsSupplier oObj = null ; + + /** + * Updates value of int column by value '9999999999999999'. + * Calls method and checks returned value.

      + * Has OK status if the method return not empty value. + */ + public void _getWarnings() { + final XRowUpdate rowUpdate = UnoRuntime.queryInterface(XRowUpdate.class, oObj); + final XResultSetUpdate resultSetUpdate = UnoRuntime.queryInterface(XResultSetUpdate.class, rowUpdate); + final XRow row = UnoRuntime.queryInterface(XRow.class, resultSetUpdate); + if ( row == null) + throw new StatusException(Status.failed("Test must be modified")); + + // not sure what the below test was intended to test, but it actually fails with an SQLException (which is + // correct for what is done there), and thus makes the complete interface test fail (which is not correct) + // So, for the moment, just let the test succeed all the time - until issue #i84235# is fixed + + if ( false ) + { + int oldVal = 0, newVal = 0; + String valToSet = "9999999999999999"; + try + { + oldVal = row.getInt(DBTools.TST_INT); + rowUpdate.updateString(DBTools.TST_INT, valToSet); + resultSetUpdate.updateRow(); + newVal = row.getInt(DBTools.TST_INT); + } + catch(com.sun.star.sdbc.SQLException e) + { + log.println("Unexpected SQL exception"); + e.printStackTrace(log); + tRes.tested("getWarnings()", false); + return; + } + + log.println("Old INT value: " + oldVal); + log.println("Value that was set: " + valToSet); + log.println("New INT value: " + newVal); + + boolean res = false; + + try + { + Object warns = oObj.getWarnings(); + res = (!utils.isVoid(warns)); + } + catch (SQLException e) + { + log.println("Exception occurred :"); + e.printStackTrace(log); + tRes.tested("getWarnings()", res); + return; + } + tRes.tested("getWarnings()", res); + } + else + tRes.tested( "getWarnings()", true ); + } + + /** + * Calls method and checks value returned by the method + * getWarnings().

      + * Has OK status if the method getWarnings() return void value. + */ + public void _clearWarnings() { + executeMethod("getWarnings()"); + boolean res = false; + + try { + oObj.clearWarnings(); + Object warns = oObj.getWarnings(); + res = utils.isVoid(warns); + } catch (SQLException e) { + log.println("Exception occurred :"); + e.printStackTrace(log); + tRes.tested("clearWarnings()", res); + return; + } + + tRes.tested("clearWarnings()", res); + } + +} -- cgit v1.2.3