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