1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <com/sun/star/accessibility/AccessibleTextType.hpp>
11 #include <com/sun/star/accessibility/XAccessibleText.hpp>
12 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
14 #include <test/a11y/swaccessibletestbase.hxx>
17 using namespace accessibility
;
19 // Checks fetching multi-unit characters
20 CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase
, TestUnicodeSP
)
22 loadFromSrc(u
"/sw/qa/extras/accessibility/testdocuments/unicode.fodf");
24 auto xContext
= getDocumentAccessibleContext()->getAccessibleChild(0)->getAccessibleContext();
26 uno::Reference
<XAccessibleText
> para(xContext
, uno::UNO_QUERY_THROW
);
27 auto segment
= para
->getTextAtIndex(0, AccessibleTextType::CHARACTER
);
28 CPPUNIT_ASSERT_EQUAL(OUString(u
"\U0001f0a1"), segment
.SegmentText
);
29 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), segment
.SegmentStart
);
30 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), segment
.SegmentEnd
);
32 segment
= para
->getTextBeforeIndex(2, AccessibleTextType::CHARACTER
);
33 CPPUNIT_ASSERT_EQUAL(OUString(u
"\U0001f0a1"), segment
.SegmentText
);
34 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), segment
.SegmentStart
);
35 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), segment
.SegmentEnd
);
37 segment
= para
->getTextBehindIndex(0, AccessibleTextType::CHARACTER
);
38 CPPUNIT_ASSERT_EQUAL(OUString(u
"\U0001f0ae"), segment
.SegmentText
);
39 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), segment
.SegmentStart
);
40 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), segment
.SegmentEnd
);
43 // Checks getTextBehindIndex() with multi-unit characters
44 CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase
, TestUnicodeSPBehindIndex
)
46 loadFromSrc(u
"/sw/qa/extras/accessibility/testdocuments/unicode.fodf");
48 auto xContext
= getDocumentAccessibleContext()->getAccessibleChild(0)->getAccessibleContext();
50 uno::Reference
<XAccessibleText
> para(xContext
, uno::UNO_QUERY_THROW
);
51 auto nChCount
= para
->getCharacterCount();
53 // verify bounds are properly handled
54 CPPUNIT_ASSERT_THROW(para
->getTextBehindIndex(-1, AccessibleTextType::CHARACTER
),
55 lang::IndexOutOfBoundsException
);
56 CPPUNIT_ASSERT_THROW(para
->getTextBehindIndex(nChCount
+ 1, AccessibleTextType::CHARACTER
),
57 lang::IndexOutOfBoundsException
);
59 auto segment
= para
->getTextBehindIndex(nChCount
, AccessibleTextType::CHARACTER
);
60 CPPUNIT_ASSERT_EQUAL(OUString(u
""), segment
.SegmentText
);
61 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), segment
.SegmentStart
);
62 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), segment
.SegmentEnd
);
64 segment
= para
->getTextBehindIndex(nChCount
- 2, AccessibleTextType::CHARACTER
);
65 CPPUNIT_ASSERT_EQUAL(OUString(u
""), segment
.SegmentText
);
66 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), segment
.SegmentStart
);
67 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), segment
.SegmentEnd
);
69 segment
= para
->getTextBehindIndex(nChCount
- 4, AccessibleTextType::CHARACTER
);
70 CPPUNIT_ASSERT_EQUAL(OUString(u
"\U0001f0ab"), segment
.SegmentText
);
71 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), segment
.SegmentStart
);
72 CPPUNIT_ASSERT_EQUAL(sal_Int32(8), segment
.SegmentEnd
);
74 // verify bounds behave the same with single unit characters, just as a validation
75 xContext
= getNextFlowingSibling(xContext
);
76 CPPUNIT_ASSERT(xContext
.is());
77 para
.set(xContext
, uno::UNO_QUERY_THROW
);
79 nChCount
= para
->getCharacterCount();
81 CPPUNIT_ASSERT_THROW(para
->getTextBehindIndex(-1, AccessibleTextType::CHARACTER
),
82 lang::IndexOutOfBoundsException
);
83 CPPUNIT_ASSERT_THROW(para
->getTextBehindIndex(nChCount
+ 1, AccessibleTextType::CHARACTER
),
84 lang::IndexOutOfBoundsException
);
86 segment
= para
->getTextBehindIndex(nChCount
, AccessibleTextType::CHARACTER
);
87 CPPUNIT_ASSERT_EQUAL(OUString(u
""), segment
.SegmentText
);
88 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), segment
.SegmentStart
);
89 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), segment
.SegmentEnd
);
91 segment
= para
->getTextBehindIndex(nChCount
- 1, AccessibleTextType::CHARACTER
);
92 CPPUNIT_ASSERT_EQUAL(OUString(u
""), segment
.SegmentText
);
93 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), segment
.SegmentStart
);
94 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), segment
.SegmentEnd
);
96 segment
= para
->getTextBehindIndex(nChCount
- 2, AccessibleTextType::CHARACTER
);
97 CPPUNIT_ASSERT_EQUAL(OUString(u
"j"), segment
.SegmentText
);
98 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), segment
.SegmentStart
);
99 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), segment
.SegmentEnd
);
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */