android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / qa / extras / accessibility / accessible_relation_set.cxx
blobfcee6d965a24a4f3217a16b8648efb000075010d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0
20 #include <test/unoapi_test.hxx>
22 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
23 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
24 #include <com/sun/star/accessibility/AccessibleRole.hpp>
25 #include <com/sun/star/accessibility/XAccessibleText.hpp>
26 #include <com/sun/star/accessibility/XAccessible.hpp>
27 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
28 #include <com/sun/star/frame/XController.hpp>
29 #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
30 #include <com/sun/star/awt/XWindow.hpp>
31 #include <com/sun/star/frame/XModel.hpp>
32 #include <com/sun/star/text/XText.hpp>
33 #include <com/sun/star/text/XTextDocument.hpp>
34 #include <com/sun/star/text/XTextCursor.hpp>
35 #include <com/sun/star/text/ControlCharacter.hpp>
37 #include <test/a11y/AccessibilityTools.hxx>
39 using namespace com::sun::star;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::accessibility;
42 using namespace css::lang;
44 class AccessibleRelationSet : public UnoApiTest
46 public:
47 AccessibleRelationSet()
48 : UnoApiTest("")
52 void init(uno::Reference<css::accessibility::XAccessible>& para1,
53 uno::Reference<css::accessibility::XAccessible>& para2,
54 uno::Reference<css::accessibility::XAccessible>& para3);
55 void contents_flows_to_and_from();
57 CPPUNIT_TEST_SUITE(AccessibleRelationSet);
58 CPPUNIT_TEST(contents_flows_to_and_from);
59 CPPUNIT_TEST_SUITE_END();
62 void AccessibleRelationSet::init(uno::Reference<css::accessibility::XAccessible>& para1,
63 uno::Reference<css::accessibility::XAccessible>& para2,
64 uno::Reference<css::accessibility::XAccessible>& para3)
66 mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
67 uno::Reference<text::XTextDocument> xTextDoc(mxComponent, uno::UNO_QUERY);
69 css::uno::Reference<text::XText> oText(xTextDoc->getText(), uno::UNO_SET_THROW);
71 css::uno::Reference<text::XTextCursor> oCursor = oText->createTextCursor();
73 for (int i = 0; i < 5; i++)
75 oText->insertString(oCursor, "Paragraph Number: " + OUString::number(i), false);
76 oText->insertControlCharacter(oCursor, text::ControlCharacter::PARAGRAPH_BREAK, false);
79 css::uno::Reference<css::frame::XModel> aModel(xTextDoc, uno::UNO_QUERY_THROW);
80 css::uno::Reference<css::frame::XController> xController(aModel->getCurrentController());
82 css::uno::Reference<css::accessibility::XAccessibleContext> ctx;
83 uno::Reference<frame::XFrame> xFrame(xController->getFrame(), uno::UNO_SET_THROW);
84 uno::Reference<awt::XWindow> xWindow(xFrame->getComponentWindow(), uno::UNO_SET_THROW);
86 css::uno::Reference<css::accessibility::XAccessible> xRoot(xWindow, uno::UNO_QUERY_THROW);
87 ctx = AccessibilityTools::getAccessibleObjectForRole(xRoot, AccessibleRole::DOCUMENT_TEXT);
88 CPPUNIT_ASSERT_MESSAGE("Couldn't get AccessibleRole.DOCUMENT_TEXT object", ctx.is());
89 para1 = ctx->getAccessibleChild(0);
90 para2 = ctx->getAccessibleChild(1);
91 para3 = ctx->getAccessibleChild(2);
94 void AccessibleRelationSet::contents_flows_to_and_from()
96 //contents_flows_to
98 css::uno::Reference<css::accessibility::XAccessible> para1;
99 css::uno::Reference<css::accessibility::XAccessible> para2;
100 css::uno::Reference<css::accessibility::XAccessible> para3;
102 init(para1, para2, para3);
103 css::uno::Reference<css::accessibility::XAccessibleContext> oObj(para1, uno::UNO_QUERY_THROW);
104 css::uno::Reference<css::accessibility::XAccessibleRelationSet> set
105 = oObj->getAccessibleRelationSet();
107 css::uno::Reference<css::accessibility::XAccessibleText> atarget;
109 if (set.is())
111 CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct count of relations", sal_Int32(1),
112 set->getRelationCount());
113 sal_Int16 firstrelation = set->getRelation(0).RelationType;
114 css::uno::Reference<css::accessibility::XAccessibleText> adummy(
115 set->getRelation(0).TargetSet[0], uno::UNO_QUERY_THROW);
116 atarget = adummy;
117 CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct relation type for paragraph 0",
118 AccessibilityTools::getRelationTypeName(
119 accessibility::AccessibleRelationType::CONTENT_FLOWS_TO),
120 AccessibilityTools::getRelationTypeName(firstrelation));
122 css::uno::Reference<css::accessibility::XAccessibleText> paraText2(para2,
123 uno::UNO_QUERY_THROW);
124 CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct target paragraph", atarget->getText(),
125 paraText2->getText());
128 //contents_flows_from()
129 css::uno::Reference<css::accessibility::XAccessibleContext> oObj2(para2, uno::UNO_QUERY_THROW);
130 css::uno::Reference<css::accessibility::XAccessibleRelationSet> set2
131 = oObj2->getAccessibleRelationSet();
133 sal_Int16 relationtypes[2] = { accessibility::AccessibleRelationType::INVALID,
134 accessibility::AccessibleRelationType::INVALID };
135 css::uno::Reference<css::accessibility::XAccessibleText> atargets[2];
137 if (set2.is())
139 CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct count of relations", sal_Int32(2),
140 set2->getRelationCount());
141 sal_Int16 tmprelation = set2->getRelation(0).RelationType;
142 if (tmprelation == accessibility::AccessibleRelationType::CONTENT_FLOWS_FROM)
144 css::uno::Reference<css::accessibility::XAccessibleText> adummy(
145 set2->getRelation(0).TargetSet[0], uno::UNO_QUERY_THROW);
146 atargets[0] = adummy;
147 relationtypes[0] = tmprelation;
149 else if (tmprelation == accessibility::AccessibleRelationType::CONTENT_FLOWS_TO)
151 css::uno::Reference<css::accessibility::XAccessibleText> adummy(
152 set2->getRelation(0).TargetSet[0], uno::UNO_QUERY_THROW);
153 atargets[1] = adummy;
154 relationtypes[1] = tmprelation;
156 else
158 CPPUNIT_FAIL("didn't gain correct relation type");
160 tmprelation = set2->getRelation(1).RelationType;
161 if (tmprelation == accessibility::AccessibleRelationType::CONTENT_FLOWS_FROM)
163 css::uno::Reference<css::accessibility::XAccessibleText> adummy(
164 set2->getRelation(1).TargetSet[0], uno::UNO_QUERY_THROW);
165 atargets[0] = adummy;
166 relationtypes[0] = tmprelation;
168 else if (tmprelation == accessibility::AccessibleRelationType::CONTENT_FLOWS_TO)
170 css::uno::Reference<css::accessibility::XAccessibleText> adummy(
171 set2->getRelation(1).TargetSet[0], uno::UNO_QUERY_THROW);
172 atargets[1] = adummy;
173 relationtypes[1] = tmprelation;
175 else
177 CPPUNIT_FAIL("didn't gain correct relation type");
181 CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct relation type for paragraph 1",
182 AccessibilityTools::getRelationTypeName(
183 accessibility::AccessibleRelationType::CONTENT_FLOWS_FROM),
184 AccessibilityTools::getRelationTypeName(relationtypes[0]));
186 css::uno::Reference<css::accessibility::XAccessibleText> paraText1(para1, uno::UNO_QUERY_THROW);
187 CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct target paragraph", atargets[0]->getText(),
188 paraText1->getText());
190 CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct relation type for paragraph 3",
191 AccessibilityTools::getRelationTypeName(
192 accessibility::AccessibleRelationType::CONTENT_FLOWS_TO),
193 AccessibilityTools::getRelationTypeName(relationtypes[1]));
195 css::uno::Reference<css::accessibility::XAccessibleText> paraText3(para3, uno::UNO_QUERY_THROW);
196 CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct target paragraph", atargets[1]->getText(),
197 paraText3->getText());
200 CPPUNIT_TEST_SUITE_REGISTRATION(AccessibleRelationSet);
202 CPPUNIT_PLUGIN_IMPLEMENT();
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */