1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package complex.indeterminateState; 29 30 import com.sun.star.accessibility.AccessibleRole; 31 import com.sun.star.accessibility.AccessibleStateType; 32 import com.sun.star.accessibility.XAccessible; 33 import com.sun.star.accessibility.XAccessibleContext; 34 import com.sun.star.accessibility.XAccessibleStateSet; 35 import com.sun.star.awt.FontWeight; 36 import com.sun.star.awt.XWindow; 37 import com.sun.star.beans.XPropertySet; 38 import com.sun.star.frame.XController; 39 import com.sun.star.frame.XModel; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.text.XText; 42 import com.sun.star.text.XTextDocument; 43 import com.sun.star.text.XTextRange; 44 import com.sun.star.text.XTextViewCursorSupplier; 45 import com.sun.star.uno.UnoRuntime; 46 import com.sun.star.uno.XInterface; 47 import org.junit.After; 48 import org.junit.AfterClass; 49 import org.junit.Before; 50 import org.junit.BeforeClass; 51 import org.junit.Test; 52 import org.openoffice.test.OfficeConnection; 53 import util.AccessibilityTools; 54 import util.DesktopTools; 55 import util.SOfficeFactory; 56 import static org.junit.Assert.*; 57 58 /** 59 */ 60 public class CheckIndeterminateState { 61 /* 62 * Test the indeterminate state of AccessibleToolBarItem 63 * The used tools are in project qadevOOo/runner 64 */ 65 @Test public void checkToolBoxItem() throws Exception { 66 XModel aModel = (XModel) 67 UnoRuntime.queryInterface(XModel.class, document); 68 69 XController xController = aModel.getCurrentController(); 70 71 XText text = document.getText(); 72 text.setString("normal"); 73 XTextRange end = text.getEnd(); 74 end.setString("bold"); 75 UnoRuntime.queryInterface(XPropertySet.class, end).setPropertyValue( 76 "CharWeight", FontWeight.BOLD); 77 UnoRuntime.queryInterface(XTextViewCursorSupplier.class, xController). 78 getViewCursor().gotoRange(text, false); 79 80 XInterface oObj = null; 81 82 AccessibilityTools at = new AccessibilityTools(); 83 XWindow xWindow = at.getCurrentContainerWindow(getFactory(), aModel); 84 XAccessible xRoot = at.getAccessibleObject(xWindow); 85 86 oObj = at.getAccessibleObjectForRole(xRoot, 87 AccessibleRole.TOGGLE_BUTTON, "Bold"); 88 assertNotNull("Found a TOGGLE_BUTTON", oObj); 89 90 XAccessibleContext oContext = (XAccessibleContext) 91 UnoRuntime.queryInterface(XAccessibleContext.class, oObj); 92 93 XAccessibleStateSet oSet = oContext.getAccessibleStateSet(); 94 95 assertTrue("The 'INDETERMINATE' state is not set.",oSet.contains(AccessibleStateType.INDETERMINATE)); 96 } 97 98 @Before public void setUpDocument() throws com.sun.star.uno.Exception { 99 document = SOfficeFactory.getFactory(getFactory()).createTextDoc(null); 100 } 101 102 @After public void tearDownDocument() { 103 DesktopTools.closeDoc(document); 104 } 105 106 private XTextDocument document = null; 107 108 @BeforeClass public static void setUpConnection() throws Exception { 109 connection.setUp(); 110 } 111 112 @AfterClass public static void tearDownConnection() 113 throws InterruptedException, com.sun.star.uno.Exception 114 { 115 connection.tearDown(); 116 } 117 118 private static final OfficeConnection connection = new OfficeConnection(); 119 120 private static final XMultiServiceFactory getFactory() { 121 return UnoRuntime.queryInterface( 122 XMultiServiceFactory.class, 123 connection.getComponentContext().getServiceManager()); 124 } 125 } 126