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