Bump for 3.6-28
[LibreOffice.git] / sw / qa / complex / accessibility / AccessibleRelationSet.java
bloba6da2f29115a10df1046b44436d65ba16f0219bf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 package complex.accessibility;
30 import com.sun.star.accessibility.AccessibleRole;
31 import com.sun.star.accessibility.XAccessible;
32 import com.sun.star.accessibility.XAccessibleText;
33 import com.sun.star.accessibility.XAccessibleContext;
34 import com.sun.star.accessibility.XAccessibleRelationSet;
35 import com.sun.star.awt.XWindow;
36 import com.sun.star.frame.XModel;
37 import com.sun.star.lang.IndexOutOfBoundsException;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.text.ControlCharacter;
40 import com.sun.star.text.XText;
41 import com.sun.star.text.XTextCursor;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.uno.UnoRuntime;
44 import org.junit.After;
45 import org.junit.AfterClass;
46 import org.junit.Before;
47 import org.junit.BeforeClass;
48 import org.junit.Test;
49 import org.openoffice.test.OfficeConnection;
50 import util.AccessibilityTools;
51 import util.WriterTools;
52 import static org.junit.Assert.*;
54 public class AccessibleRelationSet {
55 private XAccessible para1 = null;
56 private XAccessible para2 = null;
57 private XAccessible para3 = null;
58 private XTextDocument xTextDoc = null;
59 private final static String[] types = {"INVALID","CONTENT_FLOWS_FROM","CONTENT_FLOWS_TO","CONTROLLED_BY","CONTROLLER_FOR","LABEL_FOR","LABELED_BY","MEMBER_OF","SUB_WINDOW_OF"};
61 @Test public void contents_flows_to() {
62 XAccessibleRelationSet set = getAccessibleRelation(para1);
64 short firstrelation=-1;
65 XAccessibleText atarget=null;
66 if (set != null) {
67 assertEquals(
68 "didn't gain correct count of relations", 1,
69 set.getRelationCount());
70 try {
71 firstrelation = set.getRelation(0).RelationType;
72 Object oTmp = set.getRelation(0).TargetSet[0];
73 atarget = (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, oTmp);
74 } catch (IndexOutOfBoundsException e) {
75 fail("Exception when getting relations "+e);
79 assertEquals(
80 "didn't gain correct relation type for paragraph 0", types[2],
81 types[firstrelation]);
83 XAccessibleText paraTxt2 =
84 (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, para2);
85 assertEquals(
86 "didn't gain correct target paragraph", atarget.getText(),
87 paraTxt2.getText());
90 @Test public void contents_flows_from() {
91 XAccessibleRelationSet set = getAccessibleRelation(para2);
93 short[] relationtypes = new short[2];
94 XAccessibleText[] atargets = new XAccessibleText[2];
95 if (set != null) {
96 assertEquals(
97 "didn't gain correct count of relations", 2,
98 set.getRelationCount());
99 try {
100 short tmprelation = set.getRelation(0).RelationType;
101 if ( tmprelation == 1 )
103 Object oTmp = set.getRelation(0).TargetSet[0];
104 atargets[0] = (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, oTmp);
105 relationtypes[0] = tmprelation;
107 else if ( tmprelation == 2 )
109 Object oTmp = set.getRelation(0).TargetSet[0];
110 atargets[1] = (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, oTmp);
111 relationtypes[1] = tmprelation;
113 else
115 fail("didn't gain correct relation type");
117 tmprelation = set.getRelation(1).RelationType;
118 if ( tmprelation == 1 )
120 Object oTmp = set.getRelation(1).TargetSet[0];
121 atargets[0] = (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, oTmp);
122 relationtypes[0] = tmprelation;
124 else if ( tmprelation == 2 )
126 Object oTmp = set.getRelation(1).TargetSet[0];
127 atargets[1] = (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, oTmp);
128 relationtypes[1] = tmprelation;
130 else
132 fail("didn't gain correct relation type");
134 } catch (IndexOutOfBoundsException e) {
135 fail("Exception when getting relations "+e);
139 assertEquals(
140 "didn't gain correct relation type for paragraph 1", types[1],
141 types[relationtypes[0]]);
143 XAccessibleText paraTxt1 =
144 (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, para1);
145 assertEquals(
146 "didn't gain correct target paragraph", atargets[0].getText(),
147 paraTxt1.getText());
149 assertEquals(
150 "didn't gain correct relation type for paragraph 3", types[2],
151 types[relationtypes[1]]);
153 XAccessibleText paraTxt3 =
154 (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, para3);
155 assertEquals(
156 "didn't gain correct target paragraph", atargets[1].getText(),
157 paraTxt3.getText());
160 @Before public void before()
161 throws com.sun.star.lang.IllegalArgumentException,
162 IndexOutOfBoundsException
164 XMultiServiceFactory factory = UnoRuntime.queryInterface(
165 XMultiServiceFactory.class,
166 connection.getComponentContext().getServiceManager());
168 xTextDoc = WriterTools.createTextDoc(factory);
170 XText oText = xTextDoc.getText();
171 XTextCursor oCursor = oText.createTextCursor();
173 for (int i=0; i<5; i++){
174 oText.insertString( oCursor,"Paragraph Number: " + i, false);
175 oText.insertControlCharacter(
176 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
179 XModel aModel = (XModel)
180 UnoRuntime.queryInterface(XModel.class, xTextDoc);
182 AccessibilityTools at = new AccessibilityTools();
184 XWindow xWindow = at.getCurrentWindow(factory, aModel);
185 XAccessible xRoot = at.getAccessibleObject(xWindow);
187 at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
189 para1 = at.SearchedContext.getAccessibleChild(0);
190 para2 = at.SearchedContext.getAccessibleChild(1);
191 para3 = at.SearchedContext.getAccessibleChild(2);
194 @After public void after() {
195 util.DesktopTools.closeDoc(xTextDoc);
198 public XAccessibleRelationSet getAccessibleRelation(XAccessible xAcc) {
199 XAccessibleContext oObj = (XAccessibleContext)
200 UnoRuntime.queryInterface(XAccessibleContext.class, xAcc);
202 XAccessibleRelationSet set = oObj.getAccessibleRelationSet();
203 return set;
206 @BeforeClass public static void setUpConnection() throws Exception {
207 connection.setUp();
210 @AfterClass public static void tearDownConnection()
211 throws InterruptedException, com.sun.star.uno.Exception
213 connection.tearDown();
216 private static final OfficeConnection connection = new OfficeConnection();