1*86250549SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*86250549SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*86250549SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*86250549SAndrew Rist * distributed with this work for additional information 6*86250549SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*86250549SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*86250549SAndrew Rist * "License"); you may not use this file except in compliance 9*86250549SAndrew Rist * with the License. You may obtain a copy of the License at 10*86250549SAndrew Rist * 11*86250549SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*86250549SAndrew Rist * 13*86250549SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*86250549SAndrew Rist * software distributed under the License is distributed on an 15*86250549SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*86250549SAndrew Rist * KIND, either express or implied. See the License for the 17*86250549SAndrew Rist * specific language governing permissions and limitations 18*86250549SAndrew Rist * under the License. 19*86250549SAndrew Rist * 20*86250549SAndrew Rist *************************************************************/ 21*86250549SAndrew Rist 22*86250549SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package complex.indeterminateState; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleRole; 27cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleStateType; 28cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible; 29cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext; 30cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleStateSet; 31cdf0e10cSrcweir import com.sun.star.awt.FontWeight; 32cdf0e10cSrcweir import com.sun.star.awt.XWindow; 33cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 34cdf0e10cSrcweir import com.sun.star.frame.XController; 35cdf0e10cSrcweir import com.sun.star.frame.XModel; 36cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 37cdf0e10cSrcweir import com.sun.star.text.XText; 38cdf0e10cSrcweir import com.sun.star.text.XTextDocument; 39cdf0e10cSrcweir import com.sun.star.text.XTextRange; 40cdf0e10cSrcweir import com.sun.star.text.XTextViewCursorSupplier; 41cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 42cdf0e10cSrcweir import com.sun.star.uno.XInterface; 43cdf0e10cSrcweir import org.junit.After; 44cdf0e10cSrcweir import org.junit.AfterClass; 45cdf0e10cSrcweir import org.junit.Before; 46cdf0e10cSrcweir import org.junit.BeforeClass; 47cdf0e10cSrcweir import org.junit.Test; 48cdf0e10cSrcweir import org.openoffice.test.OfficeConnection; 49cdf0e10cSrcweir import util.AccessibilityTools; 50cdf0e10cSrcweir import util.DesktopTools; 51cdf0e10cSrcweir import util.SOfficeFactory; 52cdf0e10cSrcweir import static org.junit.Assert.*; 53cdf0e10cSrcweir 54cdf0e10cSrcweir /** 55cdf0e10cSrcweir */ 56cdf0e10cSrcweir public class CheckIndeterminateState { 57cdf0e10cSrcweir /* 58cdf0e10cSrcweir * Test the indeterminate state of AccessibleToolBarItem 59cdf0e10cSrcweir * The used tools are in project qadevOOo/runner 60cdf0e10cSrcweir */ 61cdf0e10cSrcweir @Test public void checkToolBoxItem() throws Exception { 62cdf0e10cSrcweir XModel aModel = (XModel) 63cdf0e10cSrcweir UnoRuntime.queryInterface(XModel.class, document); 64cdf0e10cSrcweir 65cdf0e10cSrcweir XController xController = aModel.getCurrentController(); 66cdf0e10cSrcweir 67cdf0e10cSrcweir XText text = document.getText(); 68cdf0e10cSrcweir text.setString("normal"); 69cdf0e10cSrcweir XTextRange end = text.getEnd(); 70cdf0e10cSrcweir end.setString("bold"); 71cdf0e10cSrcweir UnoRuntime.queryInterface(XPropertySet.class, end).setPropertyValue( 72cdf0e10cSrcweir "CharWeight", FontWeight.BOLD); 73cdf0e10cSrcweir UnoRuntime.queryInterface(XTextViewCursorSupplier.class, xController). 74cdf0e10cSrcweir getViewCursor().gotoRange(text, false); 75cdf0e10cSrcweir 76cdf0e10cSrcweir XInterface oObj = null; 77cdf0e10cSrcweir 78cdf0e10cSrcweir AccessibilityTools at = new AccessibilityTools(); 79cdf0e10cSrcweir XWindow xWindow = at.getCurrentContainerWindow(getFactory(), aModel); 80cdf0e10cSrcweir XAccessible xRoot = at.getAccessibleObject(xWindow); 81cdf0e10cSrcweir 82cdf0e10cSrcweir oObj = at.getAccessibleObjectForRole(xRoot, 83cdf0e10cSrcweir AccessibleRole.TOGGLE_BUTTON, "Bold"); 84cdf0e10cSrcweir assertNotNull("Found a TOGGLE_BUTTON", oObj); 85cdf0e10cSrcweir 86cdf0e10cSrcweir XAccessibleContext oContext = (XAccessibleContext) 87cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessibleContext.class, oObj); 88cdf0e10cSrcweir 89cdf0e10cSrcweir XAccessibleStateSet oSet = oContext.getAccessibleStateSet(); 90cdf0e10cSrcweir 91cdf0e10cSrcweir assertTrue("The 'INDETERMINATE' state is not set.",oSet.contains(AccessibleStateType.INDETERMINATE)); 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir @Before public void setUpDocument() throws com.sun.star.uno.Exception { 95cdf0e10cSrcweir document = SOfficeFactory.getFactory(getFactory()).createTextDoc(null); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir @After public void tearDownDocument() { 99cdf0e10cSrcweir DesktopTools.closeDoc(document); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir private XTextDocument document = null; 103cdf0e10cSrcweir 104cdf0e10cSrcweir @BeforeClass public static void setUpConnection() throws Exception { 105cdf0e10cSrcweir connection.setUp(); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir @AfterClass public static void tearDownConnection() 109cdf0e10cSrcweir throws InterruptedException, com.sun.star.uno.Exception 110cdf0e10cSrcweir { 111cdf0e10cSrcweir connection.tearDown(); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir private static final OfficeConnection connection = new OfficeConnection(); 115cdf0e10cSrcweir 116cdf0e10cSrcweir private static final XMultiServiceFactory getFactory() { 117cdf0e10cSrcweir return UnoRuntime.queryInterface( 118cdf0e10cSrcweir XMultiServiceFactory.class, 119cdf0e10cSrcweir connection.getComponentContext().getServiceManager()); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir } 122