update dev300-m58
[ooovba.git] / connectivity / qa / drivers / hsqldb / DriverTest.java
blob5e0c91d2cbfe73b4cb7cb588bc2c3cc12af990f1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DriverTest.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package qa.drivers.hsqldb;
32 import com.sun.star.awt.XWindow;
33 import com.sun.star.frame.XModel;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.util.XCloseable;
37 import com.sun.star.sdbc.*;
38 import com.sun.star.beans.PropertyValue;
39 import com.sun.star.container.XNameAccess;
40 import com.sun.star.sdbc.XDataSource;
41 import com.sun.star.frame.XStorable;
43 import com.sun.star.lang.*;
44 import com.sun.star.document.XDocumentSubStorageSupplier;
45 import complexlib.ComplexTestCase;
47 import java.io.PrintWriter;
49 import util.utils;
50 import java.util.*;
51 import java.io.*;
52 import org.hsqldb.jdbcDriver;
53 import qa.drivers.hsqldb.DatabaseMetaData;
54 import org.hsqldb.lib.StopWatch;
55 import com.sun.star.sdbc.*;
56 import com.sun.star.container.XNameAccess;
57 import com.sun.star.uno.UnoRuntime;
58 import com.sun.star.beans.PropertyValue;
59 import com.sun.star.beans.PropertyState;
60 import com.sun.star.lang.XMultiServiceFactory;
61 import com.sun.star.embed.XStorage;
63 public class DriverTest extends ComplexTestCase {
66 public String[] getTestMethodNames() {
67 return new String[] { "test" };
70 public String getTestObjectName() {
71 return "DriverTest";
74 public void assurePublic(String sMessage,boolean check){
75 addResult(sMessage,check);
78 public void test(){
79 mThreadTimeOut = 10000000;
80 XDataSource ds = null;
81 System.gc();
82 try {
83 XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class,((XMultiServiceFactory)param.getMSF()).createInstance("com.sun.star.sdb.DatabaseContext"));
84 ds = (XDataSource)UnoRuntime.queryInterface(XDataSource.class,xNameAccess.getByName("file:///g:/test.odb"));
85 } catch(Exception ex) {
86 throw new RuntimeException("factory: unable to construct data source" );
89 try{
90 XDocumentSubStorageSupplier doc = (XDocumentSubStorageSupplier)UnoRuntime.queryInterface(XDocumentSubStorageSupplier.class,ds);
91 XStorage stor = doc.getDocumentSubStorage("database",4);
92 try{
93 if ( stor.isStreamElement("db.log") )
94 stor.removeElement("db.log");
95 } catch(Exception e){}
96 try{
97 if ( stor.isStreamElement("db.properties") )
98 stor.removeElement("db.properties");
99 } catch(Exception e){}
100 try{
101 if ( stor.isStreamElement("db.script") )
102 stor.removeElement("db.script");
103 } catch(Exception e){}
104 try{
105 if ( stor.isStreamElement("db.script.new") )
106 stor.removeElement("db.script.new");
107 } catch(Exception e){}
108 XStorable mod = (XStorable)UnoRuntime.queryInterface(XStorable.class,ds);
109 mod.store();
110 XComponent xComp = (XComponent)UnoRuntime.queryInterface(XComponent.class,stor);
111 if ( xComp != null )
112 xComp.dispose();
113 } catch(Exception e){}
115 com.sun.star.beans.PropertyValue[] info = null;
116 XDriver drv = null;
117 try{
118 XDocumentSubStorageSupplier doc = (XDocumentSubStorageSupplier)UnoRuntime.queryInterface(XDocumentSubStorageSupplier.class,ds);
119 XModel mod = (XModel)UnoRuntime.queryInterface(XModel.class,ds);
120 XStorage stor = doc.getDocumentSubStorage("database",4);
121 info = new com.sun.star.beans.PropertyValue[]{
122 new com.sun.star.beans.PropertyValue("Storage",0,stor,PropertyState.DIRECT_VALUE)
123 ,new com.sun.star.beans.PropertyValue("URL",0,mod.getURL(),PropertyState.DIRECT_VALUE)
125 drv = (XDriver)UnoRuntime.queryInterface(XDriver.class,((XMultiServiceFactory)param.getMSF()).createInstance("com.sun.star.sdbcx.comp.hsqldb.Driver"));
128 TestCacheSize test = new TestCacheSize(((XMultiServiceFactory)param.getMSF()),info,drv);
130 StopWatch sw = new StopWatch();
132 try{
133 test.setUp();
134 test.testFillUp();
135 test.checkResults();
136 test.tearDown();
137 System.out.println("Total Test Time: " + sw.elapsedTime());
138 } catch(Exception e){}
140 try{
141 XStorable mod2 = (XStorable)UnoRuntime.queryInterface(XStorable.class,ds);
142 mod2.store();
143 } catch(Exception e){}
144 }catch(Exception e){}
146 public void test2(){
147 mThreadTimeOut = 10000000;
148 System.gc();
150 com.sun.star.beans.PropertyValue[] info = null;
151 XDriver drv = null;
152 try{
153 info = new com.sun.star.beans.PropertyValue[]{
154 new com.sun.star.beans.PropertyValue("JavaDriverClass",0,"org.hsqldb.jdbcDriver",PropertyState.DIRECT_VALUE)
155 ,new com.sun.star.beans.PropertyValue("ParameterNameSubstitution",0,new Boolean(false),PropertyState.DIRECT_VALUE)
157 drv = (XDriver)UnoRuntime.queryInterface(XDriver.class,((XMultiServiceFactory)param.getMSF()).createInstance("com.sun.star.comp.sdbc.JDBCDriver"));
158 TestCacheSize test = new TestCacheSize(((XMultiServiceFactory)param.getMSF()),info,drv);
159 test.setURL("jdbc:hsqldb:g:\\hsql\\db");
162 StopWatch sw = new StopWatch();
164 try{
165 test.setUp();
166 test.testFillUp();
167 test.checkResults();
168 test.tearDown();
169 System.out.println("Total Test Time: " + sw.elapsedTime());
170 } catch(Exception e){}
171 }catch(Exception e){}