Files
libreoffice/qadevOOo/tests/java/mod/_svtools/AccessibleBrowseBox.java

203 lines
6.7 KiB
Java
Raw Normal View History

2003-01-27 17:20:08 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2003-01-27 17:20:08 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2003-01-27 17:20:08 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2003-01-27 17:20:08 +00:00
*
* This file is part of OpenOffice.org.
2003-01-27 17:20:08 +00:00
*
* 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.
2003-01-27 17:20:08 +00:00
*
* 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).
2003-01-27 17:20:08 +00:00
*
* 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.
2003-01-27 17:20:08 +00:00
*
************************************************************************/
package mod._svtools;
import java.io.PrintWriter;
import lib.StatusException;
import lib.TestCase;
import lib.TestEnvironment;
import lib.TestParameters;
import util.AccessibilityTools;
import util.DesktopTools;
import util.SOfficeFactory;
import com.sun.star.accessibility.AccessibleRole;
import com.sun.star.accessibility.XAccessible;
2003-01-27 17:20:08 +00:00
import com.sun.star.awt.XWindow;
import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.XController;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XDispatch;
import com.sun.star.frame.XDispatchProvider;
import com.sun.star.frame.XFrame;
import com.sun.star.frame.XModel;
import com.sun.star.lang.XMultiServiceFactory;
2003-01-27 17:20:08 +00:00
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
import com.sun.star.util.URL;
2008-09-30 07:44:27 +00:00
import com.sun.star.view.XSelectionSupplier;
2003-01-27 17:20:08 +00:00
public class AccessibleBrowseBox extends TestCase {
2008-09-30 07:44:27 +00:00
static XDesktop the_Desk;
static XTextDocument xTextDoc;
2003-01-27 17:20:08 +00:00
/**
* Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
*/
protected void initialize(TestParameters Param, PrintWriter log) {
the_Desk = (XDesktop) UnoRuntime.queryInterface(
2008-09-30 07:44:27 +00:00
XDesktop.class, DesktopTools.createDesktop((XMultiServiceFactory) Param.getMSF()));
2003-01-27 17:20:08 +00:00
}
/**
* Disposes the document, if exists, created in
* <code>createTestEnvironment</code> method.
*/
2008-09-30 07:44:27 +00:00
protected void cleanup(TestParameters Param, PrintWriter log) {
2003-01-27 17:20:08 +00:00
log.println("disposing xTextDoc");
if (xTextDoc != null) {
xTextDoc.dispose();
}
}
/**
* Called to create an instance of <code>TestEnvironment</code> with an
* object to test and related objects. Subclasses should implement this
* method to provide the implementation and related objects. The method is
* called from <code>getTestEnvironment()</code>.
*
* @param tParam test parameters
* @param log writer to log information while testing
*
* @see TestEnvironment
* @see #getTestEnvironment()
*/
protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
2008-09-30 07:44:27 +00:00
log.println("creating a test environment");
2003-01-27 17:20:08 +00:00
2008-09-30 07:44:27 +00:00
if (xTextDoc != null) {
xTextDoc.dispose(); // get a soffice factory object
}
SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) tParam.getMSF());
2003-01-27 17:20:08 +00:00
try {
2008-09-30 07:44:27 +00:00
log.println("creating a text document");
2003-01-27 17:20:08 +00:00
xTextDoc = SOF.createTextDoc(null);
2008-09-30 07:44:27 +00:00
} catch (com.sun.star.uno.Exception e) {
2003-01-27 17:20:08 +00:00
// Some exception occures.FAILED
2008-09-30 07:44:27 +00:00
e.printStackTrace(log);
throw new StatusException("Couldn't create document", e);
2003-01-27 17:20:08 +00:00
}
shortWait();
2008-09-30 07:44:27 +00:00
XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class, xTextDoc);
2003-01-27 17:20:08 +00:00
XController secondController = aModel1.getCurrentController();
2008-09-30 07:44:27 +00:00
XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface(XDispatchProvider.class,
secondController);
2003-01-27 17:20:08 +00:00
XDispatch getting = null;
2008-09-30 07:44:27 +00:00
log.println("opening DatasourceBrowser");
2003-01-27 17:20:08 +00:00
URL the_url = new URL();
the_url.Complete = ".component:DB/DataSourceBrowser";
2008-09-30 07:44:27 +00:00
getting = aProv.queryDispatch(the_url, "_beamer", 12);
2003-01-27 17:20:08 +00:00
PropertyValue[] noArgs = new PropertyValue[0];
2008-09-30 07:44:27 +00:00
getting.dispatch(the_url, noArgs);
2003-01-27 17:20:08 +00:00
shortWait();
XFrame the_frame1 = the_Desk.getCurrentFrame();
if (the_frame1 == null) {
log.println("Current frame was not found !!!");
}
2008-09-30 07:44:27 +00:00
XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
2003-01-27 17:20:08 +00:00
the_frame2.setName("DatasourceBrowser");
XInterface oObj = null;
2008-09-30 07:44:27 +00:00
final XSelectionSupplier xSelect = (XSelectionSupplier) UnoRuntime.queryInterface(
XSelectionSupplier.class, the_frame2.getController());
PropertyValue[] params = new PropertyValue[]{new PropertyValue(), new PropertyValue(), new PropertyValue()};
params[0].Name = "DataSourceName";
params[0].Value = "Bibliography";
params[1].Name = "CommandType";
params[1].Value = new Integer(com.sun.star.sdb.CommandType.TABLE);
params[2].Name = "Command";
params[2].Value = "biblio";
final PropertyValue[] fParams = params;
2003-01-27 17:20:08 +00:00
shortWait();
AccessibilityTools at = new AccessibilityTools();
XWindow xWindow = secondController.getFrame().getContainerWindow();
2003-01-27 17:20:08 +00:00
XAccessible xRoot = at.getAccessibleObject(xWindow);
at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
2003-01-27 17:20:08 +00:00
2008-09-30 07:44:27 +00:00
oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL, "", "AccessibleBrowseBox");
2003-01-27 17:20:08 +00:00
2008-09-30 07:44:27 +00:00
log.println("ImplementationName: " + util.utils.getImplName(oObj));
2003-01-27 17:20:08 +00:00
2008-09-30 07:44:27 +00:00
TestEnvironment tEnv = new TestEnvironment(oObj);
2003-01-27 17:20:08 +00:00
tEnv.addObjRelation("EventProducer",
2008-09-30 07:44:27 +00:00
new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
2003-01-27 17:20:08 +00:00
public void fireEvent() {
try {
2008-09-30 07:44:27 +00:00
xSelect.select(fParams);
} catch (com.sun.star.uno.Exception e) {
2003-01-27 17:20:08 +00:00
e.printStackTrace();
}
}
});
return tEnv;
}
/**
2008-09-30 07:44:27 +00:00
* Sleeps for 0.5 sec. to allow StarOffice to react on <code>
* reset</code> call.
*/
2003-01-27 17:20:08 +00:00
private void shortWait() {
try {
2008-09-30 07:44:27 +00:00
Thread.sleep(5000);
;
2003-01-27 17:20:08 +00:00
} catch (InterruptedException e) {
2008-09-30 07:44:27 +00:00
System.out.println("While waiting :" + e);
2003-01-27 17:20:08 +00:00
}
}
}