diff options
author | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2009-12-09 22:07:29 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2009-12-09 22:07:29 +0100 |
commit | 954c326ed80405f99dfc19f3dbdef112c9b4ea51 (patch) | |
tree | aa85d5efa8064b108b34a2186982bb7918bf8f4d /dbaccess/qa | |
parent | 54215626ef72aa170a27f468aae57c9b4667cb87 (diff) | |
parent | f17e58864db1476a09cc5156e85f745a9286da63 (diff) |
dba33b: merge CWS head with head resulting from pulling DEV300_m67
Diffstat (limited to 'dbaccess/qa')
-rw-r--r-- | dbaccess/qa/complex/dbaccess/ApplicationController.java | 34 | ||||
-rw-r--r-- | dbaccess/qa/complex/dbaccess/DatabaseDocument.java | 234 | ||||
-rw-r--r-- | dbaccess/qa/complex/dbaccess/TestCase.java | 4 |
3 files changed, 189 insertions, 83 deletions
diff --git a/dbaccess/qa/complex/dbaccess/ApplicationController.java b/dbaccess/qa/complex/dbaccess/ApplicationController.java index fa7615809228..5b2dd1e0e613 100644 --- a/dbaccess/qa/complex/dbaccess/ApplicationController.java +++ b/dbaccess/qa/complex/dbaccess/ApplicationController.java @@ -53,7 +53,7 @@ import java.io.IOException; /** complex test case for Base's application UI */ -public class ApplicationController extends complexlib.ComplexTestCase +public class ApplicationController extends TestCase { private HsqlDatabase m_database; @@ -66,22 +66,6 @@ public class ApplicationController extends complexlib.ComplexTestCase } // -------------------------------------------------------------------------------------------------------- - protected final XComponentContext getComponentContext() - { - XComponentContext context = null; - try - { - final XPropertySet orbProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, getORB()); - context = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, - orbProps.getPropertyValue("DefaultContext")); - } - catch (Exception ex) - { - failed("could not retrieve the ComponentContext"); - } - return context; - } - // -------------------------------------------------------------------------------------------------------- public String[] getTestMethodNames() { @@ -98,12 +82,6 @@ public class ApplicationController extends complexlib.ComplexTestCase } // -------------------------------------------------------------------------------------------------------- - protected final XMultiServiceFactory getORB() - { - return (XMultiServiceFactory) param.getMSF(); - } - - // -------------------------------------------------------------------------------------------------------- private void impl_closeDocument() { if (m_database != null) @@ -143,15 +121,17 @@ public class ApplicationController extends complexlib.ComplexTestCase } // -------------------------------------------------------------------------------------------------------- - public void before() throws Exception, java.lang.Exception + public void before() throws java.lang.Exception { + super.before(); impl_switchToDocument(null); } // -------------------------------------------------------------------------------------------------------- - public void after() + public void after() throws java.lang.Exception { impl_closeDocument(); + super.after(); } // -------------------------------------------------------------------------------------------------------- @@ -161,9 +141,7 @@ public class ApplicationController extends complexlib.ComplexTestCase // then those changes are saved in the old document, actually final String oldDocumentURL = m_database.getDocumentURL(); - final File documentFile = java.io.File.createTempFile(getTestObjectName(), ".odb"); - documentFile.deleteOnExit(); - final String newDocumentURL = URLHelper.getFileURLFromSystemPath(documentFile.getAbsoluteFile()); + final String newDocumentURL = createTempFileURL(); // store the doc in a new location final XStorable storeDoc = UnoRuntime.queryInterface( XStorable.class, m_databaseDocument ); diff --git a/dbaccess/qa/complex/dbaccess/DatabaseDocument.java b/dbaccess/qa/complex/dbaccess/DatabaseDocument.java index 3b00de883319..8ce063bcdb2a 100644 --- a/dbaccess/qa/complex/dbaccess/DatabaseDocument.java +++ b/dbaccess/qa/complex/dbaccess/DatabaseDocument.java @@ -64,6 +64,8 @@ import com.sun.star.lang.XServiceInfo; import com.sun.star.lang.XSingleComponentFactory; import com.sun.star.lang.XTypeProvider; import com.sun.star.script.provider.XScriptProviderSupplier; +import com.sun.star.sdb.XDocumentDataSource; +import com.sun.star.sdbc.XDataSource; import com.sun.star.sdb.XFormDocumentsSupplier; import com.sun.star.sdb.XOfficeDatabaseDocument; import com.sun.star.sdb.XReportDocumentsSupplier; @@ -87,7 +89,6 @@ import java.util.logging.Logger; public class DatabaseDocument extends TestCase implements com.sun.star.document.XDocumentEventListener { - private static final String ONLOAD = "OnLoad"; private static final String _BLANK = "_blank"; private XComponent m_callbackFactory = null; private final ArrayList m_documentEvents = new ArrayList(); @@ -254,6 +255,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. return new String[] { "testLoadable", + "testDocumentRevenants", "testDocumentEvents", "testGlobalEvents" }; @@ -265,7 +267,8 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. return "DatabaseDocument"; } - public void before() + // -------------------------------------------------------------------------------------------------------- + public void before() throws java.lang.Exception { super.before(); @@ -293,10 +296,8 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. } // -------------------------------------------------------------------------------------------------------- - public void after() + public void after() throws java.lang.Exception { - super.after(); - try { // dispose our callback factory. This will automatically remove it from our service @@ -314,6 +315,8 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. e.printStackTrace(System.err); failed("failed to close the test case"); } + + super.after(); } // -------------------------------------------------------------------------------------------------------- @@ -463,6 +466,27 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. } // -------------------------------------------------------------------------------------------------------- + private PropertyValue[] impl_getMarkerLoadArgs() + { + return new PropertyValue[] + { + new PropertyValue( "PickListEntry", 0, false, PropertyState.DIRECT_VALUE ), + new PropertyValue( "TestCase_Marker", 0, "Yes", PropertyState.DIRECT_VALUE ) + }; + } + + // -------------------------------------------------------------------------------------------------------- + private boolean impl_hasMarker( final PropertyValue[] _args ) + { + for ( int i=0; i<_args.length; ++i ) + { + if ( _args[i].Name.equals( "TestCase_Marker" ) && _args[i].Value.equals( "Yes" ) ) + return true; + } + return false; + } + + // -------------------------------------------------------------------------------------------------------- private PropertyValue[] impl_getDefaultLoadArgs() { return new PropertyValue[] @@ -506,7 +530,27 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. } // -------------------------------------------------------------------------------------------------------- - public void testDocumentEvents() throws Exception, IOException + private XModel impl_loadDocument( final String _documentURL, final PropertyValue[] _loadArgs ) throws Exception + { + final XComponentLoader loader = (XComponentLoader) UnoRuntime.queryInterface( XComponentLoader.class, + getORB().createInstance("com.sun.star.frame.Desktop") ); + return (XModel) UnoRuntime.queryInterface( XModel.class, + loader.loadComponentFromURL( _documentURL, _BLANK, 0, _loadArgs ) ); + } + + // -------------------------------------------------------------------------------------------------------- + private void impl_storeDocument( final XModel _document ) throws Exception, IOException + { + // store the document + final String documentURL = FileHelper.getOOoCompatibleFileURL( _document.getURL() ); + final XStorable storeDoc = (XStorable) UnoRuntime.queryInterface( XStorable.class, + _document ); + storeDoc.store(); + + } + + // -------------------------------------------------------------------------------------------------------- + private XModel impl_createDocWithMacro( final String _libName, final String _moduleName, final String _code ) throws Exception, IOException { // create an empty document XModel databaseDoc = impl_createEmptyEmbeddedHSQLDocument(); @@ -515,7 +559,90 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. final XEmbeddedScripts embeddedScripts = (XEmbeddedScripts) UnoRuntime.queryInterface(XEmbeddedScripts.class, databaseDoc); final XStorageBasedLibraryContainer basicLibs = embeddedScripts.getBasicLibraries(); - final XNameContainer newLib = basicLibs.createLibrary("EventHandlers"); + final XNameContainer newLib = basicLibs.createLibrary( _libName ); + newLib.insertByName( _moduleName, _code ); + + return databaseDoc; + } + + // -------------------------------------------------------------------------------------------------------- + /** tests various aspects of database document "revenants" + * + * Well, I do not really have a good term for this ... The point is, database documents are in real + * only *one* aspect of a more complex thing. The second aspect is a data source. Both, in some sense, + * just represent different views on the same thing. For a given database, there's at each time at most + * one data source, and at most one database document. Both have a independent life time, and are + * created when needed. + * In particular, a document can be closed (this is what happens when the last UI window displaying + * this document is closed), and then dies. Now when the other "view", the data source, still exists, + * the the underlying document data is not discarded, but kept alive (else the data source would die + * just because the document dies, which is not desired). If the document is loaded, again, then + * it is re-created, using the data of its previous "incarnation". + * + * This method here tests some of those aspects of a document which should survive the death of one + * instance and re-creation as a revenant. + */ + public void testDocumentRevenants() throws Exception, IOException + { + // create an empty document + XModel databaseDoc = impl_createDocWithMacro( "Lib", "Module", + "Sub Hello\n" + + " MsgBox \"Hello\"\n" + + "End Sub\n" + ); + impl_storeDocument( databaseDoc ); + final String documentURL = databaseDoc.getURL(); + + // at this stage, the marker should not yet be present in the doc's args, else some of the below + // tests become meaningless + assure( "A newly created doc should not have the test case marker", !impl_hasMarker( databaseDoc.getArgs() ) ); + + // obtain the DataSource associated with the document. Keeping this alive + // ensures that the "impl data" of the document is kept alive, too, so when closing + // and re-opening it, this "impl data" must be re-used. + XDocumentDataSource dataSource = (XDocumentDataSource)UnoRuntime.queryInterface( XDocumentDataSource.class, + ((XOfficeDatabaseDocument)UnoRuntime.queryInterface( + XOfficeDatabaseDocument.class, databaseDoc )).getDataSource() ); + + // close and reload the doc + impl_closeDocument(databaseDoc); + databaseDoc = impl_loadDocument( documentURL, impl_getMarkerLoadArgs() ); + // since we just put the marker into the load-call, it should be present at the doc + assure( "The test case marker got lost.", impl_hasMarker( databaseDoc.getArgs() ) ); + + // The basic library should have survived + final XEmbeddedScripts embeddedScripts = (XEmbeddedScripts) UnoRuntime.queryInterface(XEmbeddedScripts.class, + databaseDoc); + final XStorageBasedLibraryContainer basicLibs = embeddedScripts.getBasicLibraries(); + assure( "Baisc lib did not survive reloading a closed document", basicLibs.hasByName( "Lib" ) ); + final XNameContainer lib = (XNameContainer)UnoRuntime.queryInterface( + XNameContainer.class, basicLibs.getByName( "Lib" ) ); + assure( "Basic module did not survive reloading a closed document", lib.hasByName( "Module" ) ); + + // now closing the doc, and obtaining it from the data source, should preserve the marker we put into the load + // args + impl_closeDocument( databaseDoc ); + databaseDoc = (XModel)UnoRuntime.queryInterface( XModel.class, dataSource.getDatabaseDocument() ); + assure( "The test case marker did not survive re-retrieval of the doc from the data source.", + impl_hasMarker( databaseDoc.getArgs() ) ); + + // on the other hand, closing and regurlarly re-loading the doc *without* the marker should indeed + // lose it + impl_closeDocument( databaseDoc ); + databaseDoc = impl_loadDocument( documentURL, impl_getDefaultLoadArgs() ); + assure( "Reloading the document kept the old args, instead of the newly supplied ones.", + !impl_hasMarker( databaseDoc.getArgs() ) ); + + // clean up + impl_closeDocument( databaseDoc ); + } + + // -------------------------------------------------------------------------------------------------------- + public void testDocumentEvents() throws Exception, IOException + { + // create an empty document + final String libName = "EventHandlers"; + final String moduleName = "all"; final String eventHandlerCode = "Option Explicit\n" + "\n" + @@ -531,32 +658,27 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. "\n" + " oCallback.documentEventOccured( oEvent )\n" + "End Sub\n"; - newLib.insertByName("all", eventHandlerCode); + XModel databaseDoc = impl_createDocWithMacro( libName, moduleName, eventHandlerCode ); + final String documentURL = databaseDoc.getURL(); // bind the macro to the OnLoad event - final String macroURI = "vnd.sun.star.script:EventHandlers.all.OnLoad?language=Basic&location=document"; + final String macroURI = "vnd.sun.star.script:" + libName + "." + moduleName + ".OnLoad?language=Basic&location=document"; final XEventsSupplier eventsSupplier = (XEventsSupplier) UnoRuntime.queryInterface(XEventsSupplier.class, databaseDoc); - eventsSupplier.getEvents().replaceByName(ONLOAD, new PropertyValue[] + eventsSupplier.getEvents().replaceByName("OnLoad", new PropertyValue[] { new PropertyValue("EventType", 0, "Script", PropertyState.DIRECT_VALUE), new PropertyValue("Script", 0, macroURI, PropertyState.DIRECT_VALUE) }); // store the document, and close it - final String documentURL = FileHelper.getOOoCompatibleFileURL(databaseDoc.getURL()); - final XStorable storeDoc = (XStorable) UnoRuntime.queryInterface(XStorable.class, - databaseDoc); - storeDoc.store(); - impl_closeDocument(databaseDoc); + impl_storeDocument( databaseDoc ); + impl_closeDocument( databaseDoc ); // ensure the macro security configuration is "ask the user for document macro execution" final int oldSecurityLevel = impl_setMacroSecurityLevel(1); // load it, again - final XComponentLoader loader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, - getORB().createInstance("com.sun.star.frame.Desktop")); - m_loadDocState = STATE_LOADING_DOC; // expected order of states is: // STATE_LOADING_DOC - initialized here @@ -567,13 +689,12 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. // here) is called before the OnLoad notification is received - since the latter happens from within // a Basic macro which is bound to the OnLoad event of the document. - final String context = ONLOAD; + final String context = "OnLoad"; impl_startObservingEvents(context); - databaseDoc = (XModel) UnoRuntime.queryInterface(XModel.class, - loader.loadComponentFromURL(documentURL, _BLANK, 0, impl_getMacroExecLoadArgs())); + databaseDoc = impl_loadDocument( documentURL, impl_getMacroExecLoadArgs() ); impl_stopObservingEvents(m_documentEvents, new String[] { - ONLOAD + "OnLoad" }, context); assureEquals("our provided interaction handler was not called", STATE_ON_LOAD_RECEIVED, m_loadDocState); @@ -659,7 +780,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. impl_stopObservingEvents(m_globalEvents, new String[] { - "OnLoadFinished", "OnViewCreated", "OnFocus", ONLOAD + "OnLoadFinished", "OnViewCreated", "OnFocus", "OnLoad" }, context); // closing a document by API @@ -679,7 +800,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. impl_startObservingEvents("prepare for '" + context + "'"); databaseDoc = (XModel) UnoRuntime.queryInterface(XModel.class, loader.loadComponentFromURL(newURL, _BLANK, 0, impl_getDefaultLoadArgs())); - impl_waitForEvent(m_globalEvents, ONLOAD, 5000); + impl_waitForEvent(m_globalEvents, "OnLoad", 5000); // wait for all events to arrive - OnLoad should be the last one final XDispatchProvider dispatchProvider = (XDispatchProvider) UnoRuntime.queryInterface(XDispatchProvider.class, @@ -716,12 +837,12 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. impl_startObservingEvents("prepare for '" + context + "'"); databaseDoc = (XModel) UnoRuntime.queryInterface(XModel.class, loader.loadComponentFromURL(newURL, _BLANK, 0, impl_getDefaultLoadArgs())); - final int previousOnLoadEventPos = impl_waitForEvent(m_globalEvents, ONLOAD, 5000); + final int previousOnLoadEventPos = impl_waitForEvent(m_globalEvents, "OnLoad", 5000); // ... and another document ... final String otherURL = copyToTempFile(databaseDoc.getURL()); final XModel otherDoc = (XModel) UnoRuntime.queryInterface(XModel.class, loader.loadComponentFromURL(otherURL, _BLANK, 0, impl_getDefaultLoadArgs())); - impl_waitForEvent(m_globalEvents, ONLOAD, 5000, previousOnLoadEventPos + 1); + impl_waitForEvent(m_globalEvents, "OnLoad", 5000, previousOnLoadEventPos + 1); impl_raise(otherDoc); // ... and switch between the two @@ -764,7 +885,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. // -------------------------------------------------------------------------------------------------------- private void impl_startObservingEvents(String _context) { - log.println(" " + _context); + log.println(" " + _context + " {"); synchronized (m_documentEvents) { m_documentEvents.clear(); @@ -778,40 +899,47 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. // -------------------------------------------------------------------------------------------------------- private void impl_stopObservingEvents(ArrayList _actualEvents, String[] _expectedEvents, String _context) { - synchronized (_actualEvents) + try { - int actualEventCount = _actualEvents.size(); - while (actualEventCount < _expectedEvents.length) + synchronized (_actualEvents) { - // well, it's possible not all events already arrived, yet - finally, some of them - // are notified asynchronously - // So, wait a few seconds. - try - { - _actualEvents.wait(5000); - } - catch (InterruptedException ex) + int actualEventCount = _actualEvents.size(); + while (actualEventCount < _expectedEvents.length) { - } + // well, it's possible not all events already arrived, yet - finally, some of them + // are notified asynchronously + // So, wait a few seconds. + try + { + _actualEvents.wait(20000); + } + catch (InterruptedException ex) + { + } - if (actualEventCount == _actualEvents.size()) - // the above wait was left because of the timeout, *not* because an event - // arrived. Okay, we won't wait any longer, this is a failure. - { - break; + if (actualEventCount == _actualEvents.size()) + // the above wait was left because of the timeout, *not* because an event + // arrived. Okay, we won't wait any longer, this is a failure. + { + break; + } + actualEventCount = _actualEvents.size(); } - actualEventCount = _actualEvents.size(); - } - assureEquals("wrong event count for '" + _context + "'", - _expectedEvents.length, _actualEvents.size()); + assureEquals("wrong event count for '" + _context + "'", + _expectedEvents.length, _actualEvents.size()); - for (int i = 0; i < _expectedEvents.length; ++i) - { - assureEquals("wrong event at positon " + (i + 1) + " for '" + _context + "'", - _expectedEvents[i], _actualEvents.get(i)); + for (int i = 0; i < _expectedEvents.length; ++i) + { + assureEquals("wrong event at positon " + (i + 1) + " for '" + _context + "'", + _expectedEvents[i], _actualEvents.get(i)); + } } } + finally + { + log.println(" }"); + } } // -------------------------------------------------------------------------------------------------------- @@ -867,7 +995,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. return; } - if ((_Event.EventName.equals(ONLOAD)) && (m_loadDocState != STATE_NOT_STARTED)) + if ((_Event.EventName.equals("OnLoad")) && (m_loadDocState != STATE_NOT_STARTED)) { assureEquals("OnLoad event must come *after* invocation of the interaction handler / user!", m_loadDocState, STATE_MACRO_EXEC_APPROVED); diff --git a/dbaccess/qa/complex/dbaccess/TestCase.java b/dbaccess/qa/complex/dbaccess/TestCase.java index 8a9594a34305..e331ccc33e7c 100644 --- a/dbaccess/qa/complex/dbaccess/TestCase.java +++ b/dbaccess/qa/complex/dbaccess/TestCase.java @@ -69,12 +69,12 @@ public abstract class TestCase extends complexlib.ComplexTestCase } // -------------------------------------------------------------------------------------------------------- - public void before() + public void before() throws java.lang.Exception { } // -------------------------------------------------------------------------------------------------------- - public void after() + public void after() throws java.lang.Exception { } |