diff options
Diffstat (limited to 'connectivity/qa/drivers/dbase')
-rw-r--r-- | connectivity/qa/drivers/dbase/.nbattrs | 10 | ||||
-rw-r--r-- | connectivity/qa/drivers/dbase/DBaseDateFunctions.java | 312 | ||||
-rw-r--r-- | connectivity/qa/drivers/dbase/DBaseDriverTest.java | 97 | ||||
-rw-r--r-- | connectivity/qa/drivers/dbase/DBaseNumericFunctions.java | 405 | ||||
-rwxr-xr-x | connectivity/qa/drivers/dbase/DBaseSqlTests.java | 99 | ||||
-rw-r--r-- | connectivity/qa/drivers/dbase/DBaseStringFunctions.java | 326 | ||||
-rw-r--r-- | connectivity/qa/drivers/dbase/makefile.mk | 68 | ||||
-rw-r--r-- | connectivity/qa/drivers/dbase/test.properties | 4 |
8 files changed, 1321 insertions, 0 deletions
diff --git a/connectivity/qa/drivers/dbase/.nbattrs b/connectivity/qa/drivers/dbase/.nbattrs new file mode 100644 index 000000000000..1ea7ed0bd8e6 --- /dev/null +++ b/connectivity/qa/drivers/dbase/.nbattrs @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE attributes PUBLIC "-//NetBeans//DTD DefaultAttributes 1.0//EN" "http://www.netbeans.org/dtds/attributes-1_0.dtd"> +<attributes version="1.0"> + <fileobject name="DBaseDriverTest.java"> + <attr name="class_dependency_complexlib.ComplexTestCase" stringvalue="DBaseDriverTest"/> + </fileobject> + <fileobject name="makefile.mk"> + <attr name="org.netbeans.modules.text.IsTextFile" boolvalue="true"/> + </fileobject> +</attributes> diff --git a/connectivity/qa/drivers/dbase/DBaseDateFunctions.java b/connectivity/qa/drivers/dbase/DBaseDateFunctions.java new file mode 100644 index 000000000000..7ed50cbd9fd0 --- /dev/null +++ b/connectivity/qa/drivers/dbase/DBaseDateFunctions.java @@ -0,0 +1,312 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: DBaseDateFunctions.java,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package qa.drivers.dbase; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.sdbc.*; +import com.sun.star.beans.XPropertySet; + +import com.sun.star.lang.XMultiServiceFactory; + +public class DBaseDateFunctions +{ + + private final String where = "FROM \"biblio\" \"biblio\" where \"Identifier\" = 'BOR00'"; + private final XMultiServiceFactory m_xORB; + private final DBaseDriverTest testcase; + + public DBaseDateFunctions(final XMultiServiceFactory _xORB, final DBaseDriverTest _testcase) + { + m_xORB = _xORB; + testcase = _testcase; + } + + private void assure(final String s, final boolean b) + { + testcase.assure2(s, b); + } + + public void testFunctions() throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRowSet xRowRes = (XRowSet) UnoRuntime.queryInterface(XRowSet.class, + m_xORB.createInstance("com.sun.star.sdb.RowSet")); + + testcase.getLog().println("starting DateTime function test!"); + // set the properties needed to connect to a database + final XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xRowRes); + xProp.setPropertyValue("DataSourceName", "Bibliography"); + + xProp.setPropertyValue("CommandType", Integer.valueOf(com.sun.star.sdb.CommandType.COMMAND)); + + try + { + curdate(xRowRes); + } + catch (SQLException ex) + { + assure("upper " + ex.getMessage(), false); + throw ex; + } + try + { + curtime(xRowRes); + } + catch (SQLException ex) + { + assure("lower " + ex.getMessage(), false); + throw ex; + } + try + { + dayname(xRowRes); + } + catch (SQLException ex) + { + assure("ascii " + ex.getMessage(), false); + throw ex; + } + try + { + dayofmonth(xRowRes); + } + catch (SQLException ex) + { + assure("char_len " + ex.getMessage(), false); + throw ex; + } + try + { + dayofweek(xRowRes); + } + catch (SQLException ex) + { + assure("concat " + ex.getMessage(), false); + throw ex; + } + try + { + dayofyear(xRowRes); + } + catch (SQLException ex) + { + assure("locate " + ex.getMessage(), false); + throw ex; + } + try + { + hour(xRowRes); + } + catch (SQLException ex) + { + assure("substr " + ex.getMessage(), false); + throw ex; + } + try + { + minute(xRowRes); + } + catch (SQLException ex) + { + assure("ltrim " + ex.getMessage(), false); + throw ex; + } + try + { + month(xRowRes); + } + catch (SQLException ex) + { + assure("rtrim " + ex.getMessage(), false); + throw ex; + } + try + { + monthname(xRowRes); + } + catch (SQLException ex) + { + assure("space " + ex.getMessage(), false); + throw ex; + } + try + { + now(xRowRes); + } + catch (SQLException ex) + { + assure("replace " + ex.getMessage(), false); + throw ex; + } + try + { + quarter(xRowRes); + } + catch (SQLException ex) + { + assure("repeat " + ex.getMessage(), false); + throw ex; + } + try + { + second(xRowRes); + } + catch (SQLException ex) + { + assure("insert " + ex.getMessage(), false); + throw ex; + } + try + { + week(xRowRes); + } + catch (SQLException ex) + { + assure("left " + ex.getMessage(), false); + throw ex; + } + try + { + year(xRowRes); + } + catch (SQLException ex) + { + assure("right " + ex.getMessage(), false); + throw ex; + } + } + + private XRow execute(final XRowSet xRowRes, final String sql) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xRowRes); + xProp.setPropertyValue("Command", "SELECT " + sql + where); + xRowRes.execute(); + final XResultSet xRes = (XResultSet) UnoRuntime.queryInterface(XResultSet.class, xRowRes); + assure("No valid row! ", xRes.next()); + + return (XRow) UnoRuntime.queryInterface(XRow.class, xRes); + } + + private void dayofweek(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "DAYOFWEEK('1998-02-03') "); + assure("DAYOFWEEK('1998-02-03') failed!", row.getInt(1) == 3); + } + + private void dayofmonth(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "DAYOFMONTH('1998-02-03') "); + assure("DAYOFMONTH('1998-02-03') failed!", row.getInt(1) == 3); + } + + private void dayofyear(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "DAYOFYEAR('1998-02-03') "); + assure("DAYOFYEAR('1998-02-03') failed!", row.getInt(1) == 34); + } + + private void month(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "month('1998-02-03') "); + assure("month('1998-02-03') failed!", row.getInt(1) == 2); + } + + private void dayname(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "DAYNAME('1998-02-05') "); + assure("DAYNAME('1998-02-05') failed!", row.getString(1).equals("Thursday")); + } + + private void monthname(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "MONTHNAME('1998-02-05') "); + assure("MONTHNAME('1998-02-05') failed!", row.getString(1).equals("February")); + } + + private void quarter(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "QUARTER('98-01-01'),QUARTER('98-04-01'),QUARTER('98-07-01'),QUARTER('98-10-01') "); + assure("QUARTER('98-01-01') failed!", row.getInt(1) == 1); + assure("QUARTER('98-04-01') failed!", row.getInt(2) == 2); + assure("QUARTER('98-07-01') failed!", row.getInt(3) == 3); + assure("QUARTER('98-10-01') failed!", row.getInt(4) == 4); + } + + private void week(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "WEEK('1998-02-20') "); + assure("WEEK('1998-02-20') failed!", row.getInt(1) == 7); + } + + private void year(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "YEAR('98-02-03') "); + assure("YEAR('98-02-03') failed!", row.getInt(1) == 98); + } + + private void hour(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "HOUR('10:05:03') "); + assure("HOUR('10:05:03') failed!", row.getInt(1) == 10); + } + + private void minute(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "MINUTE('98-02-03 10:05:03') "); + assure("MINUTE('98-02-03 10:05:03') failed!", row.getInt(1) == 5); + } + + private void second(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "SECOND('10:05:03') "); + assure("SECOND('10:05:03') failed!", row.getInt(1) == 3); + } + + private void curdate(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "CURDATE() "); + final com.sun.star.util.Date aDate = row.getDate(1); + testcase.getLog().println("CURDATE() is '" + aDate.Year + "-" + aDate.Month + "-" + aDate.Day + "'"); + } + + private void curtime(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "CURTIME() "); + final com.sun.star.util.Time aTime = row.getTime(1); + testcase.getLog().println("CURTIME() is '" + aTime.Hours + ":" + aTime.Minutes + ":" + aTime.Seconds + "'"); + } + + private void now(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "NOW() "); + final com.sun.star.util.DateTime aTime = row.getTimestamp(1); + testcase.getLog().println("NOW() is '" + aTime.Year + "-" + aTime.Month + "-" + aTime.Day + "'"); + testcase.getLog().println("'" + aTime.Hours + ":" + aTime.Minutes + ":" + aTime.Seconds + "'"); + } +} diff --git a/connectivity/qa/drivers/dbase/DBaseDriverTest.java b/connectivity/qa/drivers/dbase/DBaseDriverTest.java new file mode 100644 index 000000000000..fd15eee54d00 --- /dev/null +++ b/connectivity/qa/drivers/dbase/DBaseDriverTest.java @@ -0,0 +1,97 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: DBaseDriverTest.java,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package qa.drivers.dbase; + +import com.sun.star.sdbc.*; +import com.sun.star.lang.XMultiServiceFactory; +import complexlib.ComplexTestCase; +import java.util.*; +import java.io.*; +import share.LogWriter; +//import complex.connectivity.DBaseStringFunctions; + +public class DBaseDriverTest extends ComplexTestCase +{ + + private static Properties props = new Properties(); + private XDriver m_xDiver; + private String where = "FROM \"biblio\" \"biblio\" where \"Identifier\" = 'BOR00'"; + + static + { + try + { + String propsFile = "test.properties"; + props.load(new FileInputStream(propsFile)); + } + catch (Exception ex) + { + throw new RuntimeException(ex); + } + } + + public String[] getTestMethodNames() + { + return new String[] + { + "Functions" + }; + } + + public String getTestObjectName() + { + return "DBaseDriverTest"; + } + + public void assure2(String s, boolean b) + { + assure(s, b); + } + + public LogWriter getLog() + { + return log; + } + + public void Functions() throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + DBaseStringFunctions aStringTest = new DBaseStringFunctions(((XMultiServiceFactory) param.getMSF()), this); + aStringTest.testFunctions(); + + DBaseNumericFunctions aNumericTest = new DBaseNumericFunctions(((XMultiServiceFactory) param.getMSF()), this); + aNumericTest.testFunctions(); + + DBaseDateFunctions aDateTest = new DBaseDateFunctions(((XMultiServiceFactory) param.getMSF()), this); + aDateTest.testFunctions(); + + DBaseSqlTests aSqlTest = new DBaseSqlTests(((XMultiServiceFactory) param.getMSF()), this); + aSqlTest.testFunctions(); + } +} diff --git a/connectivity/qa/drivers/dbase/DBaseNumericFunctions.java b/connectivity/qa/drivers/dbase/DBaseNumericFunctions.java new file mode 100644 index 000000000000..b31e92653f71 --- /dev/null +++ b/connectivity/qa/drivers/dbase/DBaseNumericFunctions.java @@ -0,0 +1,405 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: DBaseNumericFunctions.java,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package qa.drivers.dbase; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.sdbc.*; +import com.sun.star.beans.XPropertySet; +import com.sun.star.lang.XMultiServiceFactory; + + +public class DBaseNumericFunctions +{ + + private final String where = "FROM \"biblio\" \"biblio\" where \"Identifier\" = 'BOR00'"; + private final XMultiServiceFactory m_xORB; + private final DBaseDriverTest testcase; + + public DBaseNumericFunctions(final XMultiServiceFactory _xORB, final DBaseDriverTest _testcase) + { + m_xORB = _xORB; + testcase = _testcase; + } + + private void assure(final String s, final boolean b) + { + testcase.assure2(s, b); + } + + public void testFunctions() throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRowSet xRowRes = (XRowSet) UnoRuntime.queryInterface(XRowSet.class, + m_xORB.createInstance("com.sun.star.sdb.RowSet")); + + testcase.getLog().println("starting Numeric function test"); + // set the properties needed to connect to a database + final XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xRowRes); + xProp.setPropertyValue("DataSourceName", "Bibliography"); + + xProp.setPropertyValue("CommandType", Integer.valueOf(com.sun.star.sdb.CommandType.COMMAND)); + + try + { + abs(xRowRes); + } + catch (SQLException ex) + { + assure("abs " + ex.getMessage(), false); + throw ex; + } + try + { + acos(xRowRes); + } + catch (SQLException ex) + { + assure("acos " + ex.getMessage(), false); + throw ex; + } + try + { + asin(xRowRes); + } + catch (SQLException ex) + { + assure("asin " + ex.getMessage(), false); + throw ex; + } + try + { + atan(xRowRes); + } + catch (SQLException ex) + { + assure("atan " + ex.getMessage(), false); + throw ex; + } + try + { + atan2(xRowRes); + } + catch (SQLException ex) + { + assure("atan2 " + ex.getMessage(), false); + throw ex; + } + try + { + ceiling(xRowRes); + } + catch (SQLException ex) + { + assure("ceiling " + ex.getMessage(), false); + throw ex; + } + try + { + cos(xRowRes); + } + catch (SQLException ex) + { + assure("cos " + ex.getMessage(), false); + throw ex; + } + try + { + degrees(xRowRes); + } + catch (SQLException ex) + { + assure("degrees " + ex.getMessage(), false); + throw ex; + } + try + { + exp(xRowRes); + } + catch (SQLException ex) + { + assure("exp " + ex.getMessage(), false); + throw ex; + } + try + { + floor(xRowRes); + } + catch (SQLException ex) + { + assure("floor " + ex.getMessage(), false); + throw ex; + } + try + { + log(xRowRes); + } + catch (SQLException ex) + { + assure("log " + ex.getMessage(), false); + throw ex; + } + try + { + log10(xRowRes); + } + catch (SQLException ex) + { + assure("log10 " + ex.getMessage(), false); + throw ex; + } + try + { + mod(xRowRes); + } + catch (SQLException ex) + { + assure("mod " + ex.getMessage(), false); + throw ex; + } + try + { + pi(xRowRes); + } + catch (SQLException ex) + { + assure("pi " + ex.getMessage(), false); + throw ex; + } + try + { + pow(xRowRes); + } + catch (SQLException ex) + { + assure("pow " + ex.getMessage(), false); + throw ex; + } + try + { + radians(xRowRes); + } + catch (SQLException ex) + { + assure("radians " + ex.getMessage(), false); + throw ex; + } + try + { + round(xRowRes); + } + catch (SQLException ex) + { + assure("round " + ex.getMessage(), false); + throw ex; + } + try + { + sign(xRowRes); + } + catch (SQLException ex) + { + assure("sign " + ex.getMessage(), false); + throw ex; + } + try + { + sin(xRowRes); + } + catch (SQLException ex) + { + assure("sin " + ex.getMessage(), false); + throw ex; + } + try + { + sqrt(xRowRes); + } + catch (SQLException ex) + { + assure("sqrt " + ex.getMessage(), false); + throw ex; + } + try + { + tan(xRowRes); + } + catch (SQLException ex) + { + assure("tan " + ex.getMessage(), false); + throw ex; + } + + } + + private XRow execute(final XRowSet xRowRes,final String sql) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xRowRes); + xProp.setPropertyValue("Command", "SELECT " + sql + where); + xRowRes.execute(); + final XResultSet xRes = (XResultSet) UnoRuntime.queryInterface(XResultSet.class, xRowRes); + assure("No valid row! ", xRes.next()); + + return (XRow) UnoRuntime.queryInterface(XRow.class, xRes); + } + + private void abs(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "ABS(2),ABS(-32) "); + assure("ABS(2) failed!", row.getInt(1) == 2); + assure("ABS(-32) failed!", row.getInt(2) == 32); + } + + private void sign(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "SIGN(-32),SIGN(0),SIGN(234) "); + assure("SIGN(-32)failed!", row.getInt(1) == -1); + assure("SIGN(0) failed!", row.getInt(2) == 0); + assure("SIGN(234) failed!", row.getInt(3) == 1); + } + + private void mod(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "MOD(234, 10) "); + assure("MOD(234, 10) failed!", row.getInt(1) == 4); + } + + private void floor(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "FLOOR(1.23),FLOOR(-1.23) "); + assure("FLOOR(1.23) failed!", row.getInt(1) == 1); + assure("FLOOR(-1.23) failed!", row.getInt(2) == -2); + } + + private void ceiling(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "CEILING(1.23),CEILING(-1.23) "); + assure("CEILING(1.23) failed!", row.getInt(1) == 2); + assure("CEILING(-1.23) failed!", row.getInt(2) == -1); + } + + private void round(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "ROUND(-1.23),ROUND(1.298, 1) "); + assure("ROUND(-1.23) failed!", row.getInt(1) == -1); + assure("ROUND(1.298, 1) failed!", row.getDouble(2) == 1.3); + } + + private void exp(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "EXP(2),EXP(-2) "); + assure("EXP(2) failed!", (float) row.getDouble(1) == (float) java.lang.Math.exp(2)); + assure("EXP(-2) failed!", (float) row.getDouble(2) == (float) java.lang.Math.exp(-2)); + } + + private void log(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "LOG(2),LOG(-2) "); + assure("LOG(2) failed!", (float) row.getDouble(1) == (float) java.lang.Math.log(2)); + row.getDouble(2); + assure("LOG(-2) failed!", row.wasNull()); + } + + private void log10(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "LOG10(100) "); + assure("LOG10(100) failed!", row.getDouble(1) == 2.0); + } + + private void pow(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "POWER(2,2) "); + assure("POWER(2,2) failed!", row.getDouble(1) == 4.0); + } + + private void sqrt(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "SQRT(4) "); + assure("SQRT(4) failed!", row.getDouble(1) == 2.0); + } + + private void pi(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "PI() "); + assure("PI() failed!", (float) row.getDouble(1) == (float) java.lang.Math.PI); + } + + private void cos(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "COS(PI()) "); + assure("COS(PI()) failed!", row.getDouble(1) == -1.0); + } + + private void sin(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "SIN(2) "); + assure("SIN(PI()) failed!", (float) row.getDouble(1) == (float) java.lang.Math.sin(2)); + } + + private void tan(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "TAN(PI()+1) "); + assure("TAN(PI()+1) failed!", (float) row.getDouble(1) == (float) java.lang.Math.tan(java.lang.Math.PI + 1.0)); + } + + private void acos(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "ACOS(1) "); + assure("ACOS(1) failed!", (float) row.getDouble(1) == 0.0); + } + + private void asin(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "ASIN(0) "); + assure("ASIN(0) failed!", (float) row.getDouble(1) == (float) java.lang.Math.asin(0.0)); + } + + private void atan(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "ATAN(0) "); + assure("ATAN(0) failed!", row.getDouble(1) == 0.0); + } + + private void atan2(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "ATAN2(0,2) "); + assure("ATAN2(0,2) failed!", (float) row.getDouble(1) == 0.0); + } + + private void degrees(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "DEGREES(PI()) "); + assure("DEGREES(PI()) failed!", row.getDouble(1) == 180.0); + } + + private void radians(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "RADIANS(90) "); + assure("RADIANS(90) failed!", (float) row.getDouble(1) == (float) (java.lang.Math.PI / 2.0)); + } +} diff --git a/connectivity/qa/drivers/dbase/DBaseSqlTests.java b/connectivity/qa/drivers/dbase/DBaseSqlTests.java new file mode 100755 index 000000000000..0151952ad76b --- /dev/null +++ b/connectivity/qa/drivers/dbase/DBaseSqlTests.java @@ -0,0 +1,99 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: DBaseStringFunctions.java,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package qa.drivers.dbase; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.sdbc.*; +import com.sun.star.beans.XPropertySet; +import com.sun.star.lang.XMultiServiceFactory; + +public class DBaseSqlTests +{ + private final XMultiServiceFactory m_xORB; + private final DBaseDriverTest testcase; + + public DBaseSqlTests(final XMultiServiceFactory _xORB,final DBaseDriverTest _testcase) + { + m_xORB = _xORB; + testcase = _testcase; + } + + private void assure(final String s,final boolean b) + { + testcase.assure2(s, b); + } + + public void testFunctions() throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRowSet xRowRes = (XRowSet) UnoRuntime.queryInterface(XRowSet.class, + m_xORB.createInstance("com.sun.star.sdb.RowSet")); + + testcase.getLog().println("starting SQL test"); + // set the properties needed to connect to a database + final XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xRowRes); + xProp.setPropertyValue("DataSourceName", "Bibliography"); + xProp.setPropertyValue("CommandType", Integer.valueOf(com.sun.star.sdb.CommandType.COMMAND)); + + execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where \"Identifier\" like 'B%'"); + execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not \"Identifier\" like 'B%'"); + execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not \"Identifier\" not like 'B%'"); + execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not(0 = 1)"); + execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where 0 = 0"); + execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where (0 = 0)"); + execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where 0 <> 1"); + execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where 0 < 1"); + execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where 2 > 1"); + execute(xRowRes,"1,1+1,'a' + 'b' FROM \"biblio\" \"biblio\" where 2 > 1"); + // execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where (0 = 0) is true"); + // execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not (0 = 0) is not true"); + // execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where 1 between 0 and 2"); + execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not \"Identifier\" is NULL"); + execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where \"Identifier\" is not NULL"); + execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where \"Identifier\" = \"Identifier\""); + execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where not(not(\"Identifier\" = \"Identifier\"))"); + execute(xRowRes,"1 FROM \"biblio\" \"biblio\" where (1 = 1 and 2 = 1) or 3 = 33 or 4 = 44 or ('a' = 'a' and 'b' = 'b')"); + } + + private void execute(final XRowSet xRowRes, String sql) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + try + { + final XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xRowRes); + xProp.setPropertyValue("Command", "SELECT " + sql); + xRowRes.execute(); + } + catch(SQLException e) + { + testcase.getLog().println(sql + " Error: " + e.getMessage()); + } + } + + +} diff --git a/connectivity/qa/drivers/dbase/DBaseStringFunctions.java b/connectivity/qa/drivers/dbase/DBaseStringFunctions.java new file mode 100644 index 000000000000..158a3f8e9489 --- /dev/null +++ b/connectivity/qa/drivers/dbase/DBaseStringFunctions.java @@ -0,0 +1,326 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: DBaseStringFunctions.java,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package qa.drivers.dbase; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.sdbc.*; +import com.sun.star.beans.XPropertySet; +import com.sun.star.lang.XMultiServiceFactory; + +public class DBaseStringFunctions +{ + private String where = "FROM \"biblio\" \"biblio\" where \"Identifier\" = 'BOR00'"; + private final XMultiServiceFactory m_xORB; + private final DBaseDriverTest testcase; + + public DBaseStringFunctions(final XMultiServiceFactory _xORB,final DBaseDriverTest _testcase) + { + m_xORB = _xORB; + testcase = _testcase; + } + + private void assure(final String s,final boolean b) + { + testcase.assure2(s, b); + } + + public void testFunctions() throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRowSet xRowRes = (XRowSet) UnoRuntime.queryInterface(XRowSet.class, + m_xORB.createInstance("com.sun.star.sdb.RowSet")); + + testcase.getLog().println("starting String function test"); + // set the properties needed to connect to a database + final XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xRowRes); + xProp.setPropertyValue("DataSourceName", "Bibliography"); + + xProp.setPropertyValue("CommandType", Integer.valueOf(com.sun.star.sdb.CommandType.COMMAND)); + + try + { + upper(xRowRes); + } + catch (SQLException ex) + { + assure("upper " + ex.getMessage(), false); + throw ex; + } + try + { + lower(xRowRes); + } + catch (SQLException ex) + { + assure("lower " + ex.getMessage(), false); + throw ex; + } + try + { + acsii(xRowRes); + } + catch (SQLException ex) + { + assure("ascii " + ex.getMessage(), false); + throw ex; + } + try + { + char_length(xRowRes); + } + catch (SQLException ex) + { + assure("char_len " + ex.getMessage(), false); + throw ex; + } + try + { + concat(xRowRes); + } + catch (SQLException ex) + { + assure("concat " + ex.getMessage(), false); + throw ex; + } + try + { + chartest(xRowRes); + } + catch (SQLException ex) + { + assure("char " + ex.getMessage(), false); + throw ex; + } + try + { + locate(xRowRes); + } + catch (SQLException ex) + { + assure("locate " + ex.getMessage(), false); + throw ex; + } + try + { + substring(xRowRes); + } + catch (SQLException ex) + { + assure("substr " + ex.getMessage(), false); + throw ex; + } + try + { + ltrim(xRowRes); + } + catch (SQLException ex) + { + assure("ltrim " + ex.getMessage(), false); + throw ex; + } + try + { + rtrim(xRowRes); + } + catch (SQLException ex) + { + assure("rtrim " + ex.getMessage(), false); + throw ex; + } + try + { + space(xRowRes); + } + catch (SQLException ex) + { + assure("space " + ex.getMessage(), false); + throw ex; + } + try + { + replace(xRowRes); + } + catch (SQLException ex) + { + assure("replace " + ex.getMessage(), false); + throw ex; + } + try + { + repeat(xRowRes); + } + catch (SQLException ex) + { + assure("repeat " + ex.getMessage(), false); + throw ex; + } + try + { + insert(xRowRes); + } + catch (SQLException ex) + { + assure("insert " + ex.getMessage(), false); + throw ex; + } + try + { + left(xRowRes); + } + catch (SQLException ex) + { + assure("left " + ex.getMessage(), false); + throw ex; + } + try + { + right(xRowRes); + } + catch (SQLException ex) + { + assure("right " + ex.getMessage(), false); + throw ex; + } + } + + private XRow execute(final XRowSet xRowRes, String sql) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xRowRes); + xProp.setPropertyValue("Command", "SELECT " + sql + where); + xRowRes.execute(); + final XResultSet xRes = (XResultSet) UnoRuntime.queryInterface(XResultSet.class, xRowRes); + assure("No valid row! ", xRes.next()); + + return (XRow) UnoRuntime.queryInterface(XRow.class, xRes); + } + + private void upper(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "upper('test'),UCASE('test') "); + assure("upper('test') failed!", row.getString(1).equals("TEST")); + assure("ucase('test') failed!", row.getString(2).equals("TEST")); + } + + private void lower(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "lower('TEST'),LCASE('TEST') "); + assure("lower('TEST') failed!", row.getString(1).equals("test")); + assure("lcase('TEST') failed!", row.getString(2).equals("test")); + final String temp = where; + where = "FROM \"biblio\" \"biblio\" where LOWER(\"Identifier\") like 'bor%'"; + execute(xRowRes, "lower('TEST'),LCASE('TEST') "); + where = temp; + } + + private void acsii(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "ASCII('2') "); + assure("acsii('2') failed!", row.getInt(1) == 50); + } + + private void char_length(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "char_length('test'),character_length('test'),OCTET_LENGTH('test') "); + assure("char_length('test') failed!", row.getInt(1) == 4); + assure("character_length('test') failed!", row.getInt(2) == 4); + assure("OCTET_LENGTH('test') failed!", row.getInt(3) == 4); + } + + private void concat(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "CONCAT('Hello',' ','World') "); + assure("CONCAT('Hello',' ',,'World') failed!", row.getString(1).equals("Hello World")); + } + + private void locate(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "LOCATE('bar', 'foobarbar') "); + assure("LOCATE('bar', 'foobarbar') failed!", row.getInt(1) == 4); + } + + private void substring(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "SUBSTRING('Quadratically',5) "); + assure("SUBSTRING('Quadratically',5) failed!", row.getString(1).equals("ratically")); + } + + private void ltrim(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "LTRIM(' barbar') "); + assure("LTRIM(' barbar') failed!", row.getString(1).equals("barbar")); + } + + private void rtrim(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "RTRIM('barbar ') "); + assure("RTRIM('barbar ') failed!", row.getString(1).equals("barbar")); + } + + private void space(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "space(6) "); + assure("space(6) failed!", row.getString(1).equals(" ")); + } + + private void replace(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "REPLACE('www.OOo.com', 'w', 'Ww') "); + assure("REPLACE('www.OOo.com', 'w', 'Ww') failed!", row.getString(1).equals("WwWwWw.OOo.com")); + } + + private void repeat(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "REPEAT('OOo', 3) "); + assure("REPEAT('OOo', 3) failed!", row.getString(1).equals("OOoOOoOOo")); + } + + private void insert(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "INSERT('Quadratic', 3, 4, 'What') "); + assure("INSERT('Quadratic', 3, 4, 'What') failed!", row.getString(1).equals("QuWhattic")); + } + + private void left(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "LEFT('foobarbar', 5) "); + assure("LEFT('foobarbar', 5) failed!", row.getString(1).equals("fooba")); + } + + private void right(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "RIGHT('foobarbar', 4) "); + assure("RIGHT('foobarbar', 4) failed!", row.getString(1).equals("rbar")); + } + + private void chartest(final XRowSet xRowRes) throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException + { + final XRow row = execute(xRowRes, "CHAR(ascii('t'),ascii('e'),ascii('s'),ascii('t')) "); + assure("CHAR(ascii('t'),ascii('e'),ascii('s'),ascii('t')) failed!", row.getString(1).equals("test")); + } +} diff --git a/connectivity/qa/drivers/dbase/makefile.mk b/connectivity/qa/drivers/dbase/makefile.mk new file mode 100644 index 000000000000..4544b2a2bc62 --- /dev/null +++ b/connectivity/qa/drivers/dbase/makefile.mk @@ -0,0 +1,68 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.7.60.1 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ = ..$/..$/.. +TARGET = DBaseDriverTest +PRJNAME = connectivity +PACKAGE = qa$/drivers$/dbase + +# --- Settings ----------------------------------------------------- +.INCLUDE: settings.mk + + +#----- compile .java files ----------------------------------------- + +JARFILES = ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar +JAVAFILES =\ + DBaseDateFunctions.java\ + DBaseDriverTest.java\ + DBaseNumericFunctions.java\ + DBaseStringFunctions.java\ + DBaseSqlTests.java + +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +#----- make a jar from compiled files ------------------------------ + +MAXLINELENGTH = 100000 + +JARCLASSDIRS = $(PACKAGE) +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + + +run: $(CLASSDIR)$/$(JARTARGET) + java -cp "$(CLASSPATH)$(PATH_SEPERATOR)$(SOLARBINDIR)$/OOoRunner.jar" org.openoffice.Runner -TestBase java_complex -o qa.drivers.dbase.$(TARGET) + diff --git a/connectivity/qa/drivers/dbase/test.properties b/connectivity/qa/drivers/dbase/test.properties new file mode 100644 index 000000000000..6f301f972d40 --- /dev/null +++ b/connectivity/qa/drivers/dbase/test.properties @@ -0,0 +1,4 @@ +Driver=org.openoffice.comp.drivers.MySQL.Driver +user=testuser +password= +URL=sdbc:mysql:odbc:MYSQL fs-11110 TESTUSER |