1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <swmodeltestbase.hxx>
11 #include <AccessibilityCheck.hxx>
12 #include <AccessibilityIssue.hxx>
13 #include <OnlineAccessibilityCheck.hxx>
15 #include <vcl/scheduler.hxx>
16 #include <comphelper/propertysequence.hxx>
18 #include <comphelper/scopeguard.hxx>
19 #include <officecfg/Office/Common.hxx>
21 class AccessibilityCheckTest
: public SwModelTestBase
24 AccessibilityCheckTest()
25 : SwModelTestBase(u
"/sw/qa/core/accessibilitycheck/data/"_ustr
)
30 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testCheckDocumentIssues
)
32 createSwDoc("DocumentTest.odt");
33 SwDoc
* pDoc
= getSwDoc();
34 sw::AccessibilityCheck
aCheck(pDoc
);
36 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
37 CPPUNIT_ASSERT_EQUAL(size_t(2), aIssues
.size());
38 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DOCUMENT_LANGUAGE
, aIssues
[0]->m_eIssueID
);
39 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::WARNLEV
, aIssues
[0]->m_eIssueLvl
);
40 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DOCUMENT_TITLE
, aIssues
[1]->m_eIssueID
);
43 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testTableSplitMergeAndAltText
)
45 createSwDoc("AccessibilityTests1.odt");
46 SwDoc
* pDoc
= getSwDoc();
47 sw::AccessibilityCheck
aCheck(pDoc
);
49 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
50 CPPUNIT_ASSERT_EQUAL(size_t(6), aIssues
.size());
52 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::NO_ALT_GRAPHIC
, aIssues
[0]->m_eIssueID
);
53 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::ERRORLEV
, aIssues
[0]->m_eIssueLvl
);
54 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TABLE_MERGE_SPLIT
, aIssues
[1]->m_eIssueID
);
55 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TABLE_MERGE_SPLIT
, aIssues
[2]->m_eIssueID
);
56 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TABLE_MERGE_SPLIT
, aIssues
[3]->m_eIssueID
);
57 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TABLE_MERGE_SPLIT
, aIssues
[4]->m_eIssueID
);
58 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::WARNLEV
, aIssues
[4]->m_eIssueLvl
);
59 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::NO_ALT_SHAPE
, aIssues
[5]->m_eIssueID
);
60 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::ERRORLEV
, aIssues
[5]->m_eIssueLvl
);
63 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testCheckParagraphIssues
)
65 // Tests whether formatting issues are detected when the whole paragraph has them instead of
66 // some text inside the paragraph
67 createSwDoc("ParagraphTest.odt");
68 SwDoc
* pDoc
= getSwDoc();
69 sw::AccessibilityCheck
aCheck(pDoc
);
71 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
72 CPPUNIT_ASSERT_EQUAL(size_t(1), aIssues
.size());
73 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[0]->m_eIssueID
);
76 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testCheckBackgroundImage
)
78 createSwDoc("BackgroundImageTest.odt");
79 SwDoc
* pDoc
= getSwDoc();
80 sw::AccessibilityCheck
aCheck(pDoc
);
82 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
83 CPPUNIT_ASSERT_EQUAL(size_t(1), aIssues
.size());
84 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DOCUMENT_BACKGROUND
, aIssues
[0]->m_eIssueID
);
85 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::WARNLEV
, aIssues
[0]->m_eIssueLvl
);
88 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testCheckLinkedImage
)
90 createSwDoc("LinkedImageTest.fodt");
91 SwDoc
* pDoc
= getSwDoc();
92 sw::AccessibilityCheck
aCheck(pDoc
);
94 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
95 CPPUNIT_ASSERT_EQUAL(size_t(4), aIssues
.size());
96 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::LINKED_GRAPHIC
, aIssues
[1]->m_eIssueID
);
97 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::WARNLEV
, aIssues
[1]->m_eIssueLvl
);
100 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testCheckNewlineSpace
)
102 createSwDoc("NewlineTest.odt");
103 SwDoc
* pDoc
= getSwDoc();
104 sw::AccessibilityCheck
aCheck(pDoc
);
106 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
107 CPPUNIT_ASSERT_EQUAL(size_t(4), aIssues
.size());
108 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[0]->m_eIssueID
);
109 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_NEW_LINES
, aIssues
[1]->m_eIssueID
);
110 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[2]->m_eIssueID
);
111 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_NEW_LINES
, aIssues
[3]->m_eIssueID
);
112 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::WARNLEV
, aIssues
[3]->m_eIssueLvl
);
115 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testEmptyLineBetweenNumberings
)
117 createSwDoc("EmptyNumSpace.odt");
118 SwDoc
* pDoc
= getSwDoc();
119 sw::AccessibilityCheck
aCheck(pDoc
);
121 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
122 CPPUNIT_ASSERT_EQUAL(size_t(1), aIssues
.size());
123 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_EMPTY_NUM_PARA
, aIssues
[0]->m_eIssueID
);
124 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::WARNLEV
, aIssues
[0]->m_eIssueLvl
);
127 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testCheckSpacebarSpace
)
129 createSwDoc("SpaceTest.odt");
130 SwDoc
* pDoc
= getSwDoc();
131 sw::AccessibilityCheck
aCheck(pDoc
);
133 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
134 CPPUNIT_ASSERT_EQUAL(size_t(3), aIssues
.size());
135 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[0]->m_eIssueID
);
136 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_SPACES
, aIssues
[1]->m_eIssueID
);
137 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[2]->m_eIssueID
);
140 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testHyperlinks
)
142 createSwDoc("HyperlinkTest.odt");
143 SwDoc
* pDoc
= getSwDoc();
144 sw::AccessibilityCheck
aCheck(pDoc
);
146 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
147 CPPUNIT_ASSERT_EQUAL(size_t(5), aIssues
.size());
148 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::HYPERLINK_SHORT
, aIssues
[0]->m_eIssueID
);
149 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::WARNLEV
, aIssues
[0]->m_eIssueLvl
);
150 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::HYPERLINK_NO_NAME
, aIssues
[1]->m_eIssueID
);
151 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::HYPERLINK_IS_TEXT
, aIssues
[2]->m_eIssueID
);
152 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::WARNLEV
, aIssues
[2]->m_eIssueLvl
);
153 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::HYPERLINK_NO_NAME
, aIssues
[3]->m_eIssueID
);
154 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::WARNLEV
, aIssues
[3]->m_eIssueLvl
);
155 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[4]->m_eIssueID
);
158 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testCheckHighlightedText
)
160 createSwDoc("HighlightTest.odt");
161 SwDoc
* pDoc
= getSwDoc();
162 sw::AccessibilityCheck
aCheck(pDoc
);
164 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
165 CPPUNIT_ASSERT_EQUAL(size_t(3), aIssues
.size());
166 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[0]->m_eIssueID
);
167 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[1]->m_eIssueID
);
168 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[2]->m_eIssueID
);
171 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testNumberingCheck
)
173 createSwDoc("AccessibilityTests_NumberingCheck.odt");
174 SwDoc
* pDoc
= getSwDoc();
175 sw::AccessibilityCheck
aCheck(pDoc
);
177 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
178 CPPUNIT_ASSERT_EQUAL(size_t(5), aIssues
.size());
179 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::MANUAL_NUMBERING
, aIssues
[0]->m_eIssueID
);
180 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::MANUAL_NUMBERING
, aIssues
[1]->m_eIssueID
);
181 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::MANUAL_NUMBERING
, aIssues
[2]->m_eIssueID
);
182 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::MANUAL_NUMBERING
, aIssues
[3]->m_eIssueID
);
183 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::MANUAL_NUMBERING
, aIssues
[4]->m_eIssueID
);
184 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::WARNLEV
, aIssues
[4]->m_eIssueLvl
);
187 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testCheckFakeFootnote
)
189 createSwDoc("FakeFootnoteTest.odt");
190 SwDoc
* pDoc
= getSwDoc();
191 sw::AccessibilityCheck
aCheck(pDoc
);
193 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
194 CPPUNIT_ASSERT_EQUAL(size_t(6), aIssues
.size());
195 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[0]->m_eIssueID
);
196 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::FAKE_FOOTNOTE
, aIssues
[1]->m_eIssueID
);
197 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::WARNLEV
, aIssues
[1]->m_eIssueLvl
);
198 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[2]->m_eIssueID
);
199 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::FAKE_FOOTNOTE
, aIssues
[3]->m_eIssueID
);
200 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::WARNLEV
, aIssues
[3]->m_eIssueLvl
);
201 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[4]->m_eIssueID
);
202 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[5]->m_eIssueID
);
203 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::WARNLEV
, aIssues
[5]->m_eIssueLvl
);
206 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testCheckFakeCaption
)
208 createSwDoc("FakeCaptionTest.odt");
209 SwDoc
* pDoc
= getSwDoc();
210 sw::AccessibilityCheck
aCheck(pDoc
);
212 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
213 CPPUNIT_ASSERT_EQUAL(size_t(1), aIssues
.size());
214 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::FAKE_CAPTION
, aIssues
[0]->m_eIssueID
);
215 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::WARNLEV
, aIssues
[0]->m_eIssueLvl
);
218 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testCheckTableFormatting
)
220 createSwDoc("TableFormattingTest.odt");
221 SwDoc
* pDoc
= getSwDoc();
222 sw::AccessibilityCheck
aCheck(pDoc
);
224 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
225 CPPUNIT_ASSERT_EQUAL(size_t(1), aIssues
.size());
226 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TABLE_FORMATTING
, aIssues
[0]->m_eIssueID
);
227 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::WARNLEV
, aIssues
[0]->m_eIssueLvl
);
230 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testCheckTabsFormatting
)
232 createSwDoc("TabsTest.odt");
233 SwDoc
* pDoc
= getSwDoc();
234 sw::AccessibilityCheck
aCheck(pDoc
);
236 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
237 CPPUNIT_ASSERT_EQUAL(size_t(10), aIssues
.size());
238 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_TABS
, aIssues
[0]->m_eIssueID
);
239 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[1]->m_eIssueID
);
240 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_TABS
, aIssues
[2]->m_eIssueID
);
241 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[3]->m_eIssueID
);
242 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_TABS
, aIssues
[4]->m_eIssueID
);
243 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[5]->m_eIssueID
);
244 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_TABS
, aIssues
[6]->m_eIssueID
);
245 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[7]->m_eIssueID
);
246 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_TABS
, aIssues
[8]->m_eIssueID
);
247 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[9]->m_eIssueID
);
250 //tdf#156550 - Accessibility sidebar complains about TOC hyperlinks
251 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testCheckTOCHyperlink
)
253 createSwDoc("TOCHyperlinkTest.odt");
254 SwDoc
* pDoc
= getSwDoc();
255 sw::AccessibilityCheck
aCheck(pDoc
);
257 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
258 // Without the fix in place, this test would have failed with
259 // - Expected: 0 (No Detected HYPERLINK_IS_TEXT Issues)
260 // - Actual : 4 (Number of TOC Hyperlinks)
261 CPPUNIT_ASSERT_EQUAL(size_t(0), aIssues
.size());
264 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testDeleteHeader
)
266 // Delete Header from doc and check if we have less Direct format warning
267 createSwDoc("DeleteHeader.odt");
268 SwDoc
* pDoc
= getSwDoc();
270 sw::AccessibilityCheck
aCheck(pDoc
);
271 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
273 CPPUNIT_ASSERT_EQUAL(size_t(8), aIssues
.size());
274 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DOCUMENT_TITLE
, aIssues
[0]->m_eIssueID
);
275 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueLevel::ERRORLEV
, aIssues
[0]->m_eIssueLvl
);
276 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_NEW_LINES
, aIssues
[1]->m_eIssueID
);
277 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_NEW_LINES
, aIssues
[2]->m_eIssueID
);
278 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_NEW_LINES
, aIssues
[3]->m_eIssueID
);
279 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_NEW_LINES
, aIssues
[4]->m_eIssueID
);
280 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_NEW_LINES
, aIssues
[5]->m_eIssueID
);
281 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_NEW_LINES
, aIssues
[6]->m_eIssueID
);
282 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_NEW_LINES
, aIssues
[7]->m_eIssueID
);
284 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
285 CPPUNIT_ASSERT(pWrtShell
);
288 pWrtShell
->ChangeHeaderOrFooter(u
"Default Page Style", true, false, false);
289 pWrtShell
->GetWin()->GrabFocusToDocument();
291 // re-check A11Y issues
292 sw::AccessibilityCheck
aReCheck(pDoc
);
293 auto& aResultIssues
= aReCheck
.getIssueCollection().getIssues();
297 aResultIssues
= aReCheck
.getIssueCollection().getIssues();
298 CPPUNIT_ASSERT_EQUAL(size_t(3), aResultIssues
.size());
299 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DOCUMENT_TITLE
, aResultIssues
[0]->m_eIssueID
);
300 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_NEW_LINES
, aResultIssues
[1]->m_eIssueID
);
301 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_NEW_LINES
, aResultIssues
[2]->m_eIssueID
);
304 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testStylesWithHeader
)
306 // Check direct formats, char/para styles and not allowed page styles
307 createSwDoc("PageCharParaStyles.odt");
308 SwDoc
* pDoc
= getSwDoc();
310 sw::AccessibilityCheck
aCheck(pDoc
);
311 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
313 CPPUNIT_ASSERT_EQUAL(size_t(5), aIssues
.size());
314 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DOCUMENT_TITLE
, aIssues
[0]->m_eIssueID
);
315 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[1]->m_eIssueID
);
316 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[2]->m_eIssueID
);
317 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[3]->m_eIssueID
);
318 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[4]->m_eIssueID
);
321 // Text contrast tests
322 // see https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html
323 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testCheckTextContrast
)
325 // first test doc has these issues:
326 // * normal text with contrast < 4.5
327 // * large text with contrast < 3.0
328 // * bold text with font size 13 (i.e. not considered large) with contrast < 4.5
329 createSwDoc("ContrastTestFail.odt");
330 SwDoc
* pDoc
= getSwDoc();
331 sw::AccessibilityCheck
aCheck(pDoc
);
333 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
334 CPPUNIT_ASSERT_EQUAL(size_t(3), aIssues
.size());
335 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_CONTRAST
, aIssues
[0]->m_eIssueID
);
336 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_CONTRAST
, aIssues
[1]->m_eIssueID
);
337 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_CONTRAST
, aIssues
[2]->m_eIssueID
);
339 // second test doc has large text with contrast between 3.0 and 4.5,
340 // which is sufficient for large text
341 // both of these are considered large text according to the spec:
342 // * non-bold text font with size 18
343 // * bold text with font size 14
344 createSwDoc("ContrastTestOK.odt");
345 SwDoc
* pDocOK
= getSwDoc();
346 sw::AccessibilityCheck
aCheckOK(pDocOK
);
348 auto& aIssuesOK
= aCheckOK
.getIssueCollection().getIssues();
349 CPPUNIT_ASSERT_EQUAL(size_t(0), aIssuesOK
.size());
354 std::vector
<std::shared_ptr
<sfx::AccessibilityIssue
>>
355 scanAccessibilityIssuesOnNodes(SwDoc
* pDocument
)
357 std::vector
<std::shared_ptr
<sfx::AccessibilityIssue
>> aIssues
;
358 auto const& pNodes
= pDocument
->GetNodes();
359 for (SwNodeOffset
n(0); n
< pNodes
.Count(); ++n
)
361 SwNode
* pNode
= pNodes
[n
];
362 auto& pCollection
= pNode
->getAccessibilityCheckStatus().pCollection
;
365 for (auto& pIssue
: pCollection
->getIssues())
367 aIssues
.push_back(pIssue
);
374 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testCheckTabsinTOC
)
376 createSwDoc("Tabs-in-TOC.odt");
377 SwDoc
* pDoc
= getSwDoc();
378 sw::AccessibilityCheck
aCheck(pDoc
);
380 auto& aIssues
= aCheck
.getIssueCollection().getIssues();
381 CPPUNIT_ASSERT_EQUAL(size_t(0), aIssues
.size());
384 void checkIssuePosition(std::shared_ptr
<sfx::AccessibilityIssue
> const& pIssue
, int nLine
,
385 sal_Int32 nStart
, sal_Int32 nEnd
, SwNodeOffset nIndex
)
387 auto* pSwIssue
= static_cast<sw::AccessibilityIssue
*>(pIssue
.get());
389 OString sFailMessage
= OString::Concat("Start doesn't match at line: ")
390 + OString::Concat(OString::number(nLine
));
391 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailMessage
.getStr(), nStart
, pSwIssue
->getStart());
394 = OString::Concat("End doesn't match at line: ") + OString::Concat(OString::number(nLine
));
395 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailMessage
.getStr(), nEnd
, pSwIssue
->getEnd());
397 sFailMessage
= OString::Concat("Offset doesn't match at line: ")
398 + OString::Concat(OString::number(nLine
));
399 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailMessage
.getStr(), nIndex
, pSwIssue
->getNode()->GetIndex());
402 } // end anonymous ns
404 CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest
, testOnlineNodeSplitAppend
)
406 // Checks the a11y checker is setting the a11y issues to the nodes
407 // correctly when splitting and appending nodes (through undo), which
408 // happen on editing all the time.
409 // When a node is split, it can happen that both nodes get a11y issues
410 // if the node splits the area of direct formatting.
412 createSwDoc("OnlineCheck.odt");
413 SwDoc
* pDoc
= getSwDoc();
414 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
415 CPPUNIT_ASSERT(pWrtShell
);
417 // Enable online a11y checker
419 auto pBatch(comphelper::ConfigurationChanges::create());
420 officecfg::Office::Common::Accessibility::OnlineAccessibilityCheck::set(true, pBatch
);
423 comphelper::ScopeGuard
g([] {
424 auto pBatch(comphelper::ConfigurationChanges::create());
425 officecfg::Office::Common::Accessibility::OnlineAccessibilityCheck::set(false, pBatch
);
429 Scheduler::ProcessEventsToIdle();
431 // Check we have 2 a11y issue
432 CPPUNIT_ASSERT_EQUAL(sal_Int32(2),
433 pDoc
->getOnlineAccessibilityCheck()->getNumberOfAccessibilityIssues());
434 auto aIssues
= scanAccessibilityIssuesOnNodes(pDoc
);
435 CPPUNIT_ASSERT_EQUAL(size_t(2), aIssues
.size());
436 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[0]->m_eIssueID
);
437 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[1]->m_eIssueID
);
438 checkIssuePosition(aIssues
[0], __LINE__
, 0, 32, SwNodeOffset(9));
439 checkIssuePosition(aIssues
[1], __LINE__
, 33, 136, SwNodeOffset(9));
441 // Position the cursor and hit "enter" (trigger split-node action)
442 pWrtShell
->Right(SwCursorSkipMode::Chars
, /*bSelect=*/false, 33, /*bBasicCall=*/false);
443 pWrtShell
->SplitNode();
446 CPPUNIT_ASSERT_EQUAL(u
"He heard quiet steps behind him. "_ustr
, getParagraph(1)->getString());
447 CPPUNIT_ASSERT_EQUAL(u
"That didn't bode well. Who could be following him this late at "
448 "night and in this deadbeat part of town?"_ustr
,
449 getParagraph(2)->getString());
450 CPPUNIT_ASSERT_EQUAL(sal_Int32(2),
451 pDoc
->getOnlineAccessibilityCheck()->getNumberOfAccessibilityIssues());
453 aIssues
= scanAccessibilityIssuesOnNodes(pDoc
);
454 CPPUNIT_ASSERT_EQUAL(size_t(2), aIssues
.size());
455 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[0]->m_eIssueID
);
456 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[1]->m_eIssueID
);
457 checkIssuePosition(aIssues
[0], __LINE__
, 0, 32, SwNodeOffset(9));
458 checkIssuePosition(aIssues
[1], __LINE__
, 0, 103, SwNodeOffset(10));
460 // Position cursor and split again
461 pWrtShell
->Down(/*bSelect*/ false, /*nCount*/ 0);
462 pWrtShell
->Right(SwCursorSkipMode::Chars
, /*bSelect=*/false, 23, /*bBasicCall=*/false);
463 pWrtShell
->SplitNode();
466 CPPUNIT_ASSERT_EQUAL(u
"He heard quiet steps behind him. "_ustr
, getParagraph(1)->getString());
467 CPPUNIT_ASSERT_EQUAL(u
"That didn't bode well. "_ustr
, getParagraph(2)->getString());
468 CPPUNIT_ASSERT_EQUAL(
469 u
"Who could be following him this late at night and in this deadbeat part of town?"_ustr
,
470 getParagraph(3)->getString());
471 CPPUNIT_ASSERT_EQUAL(sal_Int32(3),
472 pDoc
->getOnlineAccessibilityCheck()->getNumberOfAccessibilityIssues());
473 aIssues
= scanAccessibilityIssuesOnNodes(pDoc
);
474 CPPUNIT_ASSERT_EQUAL(size_t(3), aIssues
.size());
475 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[0]->m_eIssueID
);
476 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[1]->m_eIssueID
);
477 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[2]->m_eIssueID
);
478 checkIssuePosition(aIssues
[0], __LINE__
, 0, 32, SwNodeOffset(9));
479 checkIssuePosition(aIssues
[1], __LINE__
, 0, 23, SwNodeOffset(10));
480 checkIssuePosition(aIssues
[2], __LINE__
, 0, 80, SwNodeOffset(11));
482 // Undo second change
483 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
484 CPPUNIT_ASSERT_EQUAL(u
"He heard quiet steps behind him. "_ustr
, getParagraph(1)->getString());
485 CPPUNIT_ASSERT_EQUAL(u
"That didn't bode well. Who could be following him this late at "
486 "night and in this deadbeat part of town?"_ustr
,
487 getParagraph(2)->getString());
488 CPPUNIT_ASSERT_EQUAL(sal_Int32(2),
489 pDoc
->getOnlineAccessibilityCheck()->getNumberOfAccessibilityIssues());
490 aIssues
= scanAccessibilityIssuesOnNodes(pDoc
);
491 CPPUNIT_ASSERT_EQUAL(size_t(2), aIssues
.size());
492 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[0]->m_eIssueID
);
493 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[1]->m_eIssueID
);
494 checkIssuePosition(aIssues
[0], __LINE__
, 0, 32, SwNodeOffset(9));
495 checkIssuePosition(aIssues
[1], __LINE__
, 0, 103, SwNodeOffset(10));
498 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
499 CPPUNIT_ASSERT_EQUAL(sal_Int32(2),
500 pDoc
->getOnlineAccessibilityCheck()->getNumberOfAccessibilityIssues());
501 CPPUNIT_ASSERT_EQUAL(
502 u
"He heard quiet steps behind him. That didn't bode well. Who could be following "
503 "him this late at night and in this deadbeat part of town?"_ustr
,
504 getParagraph(1)->getString());
505 aIssues
= scanAccessibilityIssuesOnNodes(pDoc
);
506 CPPUNIT_ASSERT_EQUAL(size_t(2), aIssues
.size());
507 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[0]->m_eIssueID
);
508 CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DIRECT_FORMATTING
, aIssues
[1]->m_eIssueID
);
509 checkIssuePosition(aIssues
[0], __LINE__
, 0, 32, SwNodeOffset(9));
510 checkIssuePosition(aIssues
[1], __LINE__
, 33, 136, SwNodeOffset(9));
513 CPPUNIT_PLUGIN_IMPLEMENT();
515 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */