sw: test online a11y check - splitting and joining nodes

Change-Id: I9be3df3a4c00e7f1bbfc4f2462c8cf9a0f813f9d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142656
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
Tomaž Vajngerl 2022-11-13 22:27:54 +09:00 committed by Tomaž Vajngerl
parent f078937179
commit e7f78c3123
4 changed files with 178 additions and 2 deletions

View file

@ -26,11 +26,12 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_core_accessibilitycheck, \
sfx \
subsequenttest \
sw \
swqahelper \
swqahelper \
test \
unotest \
utl \
tl \
vcl \
))
$(eval $(call gb_CppunitTest_use_externals,sw_core_accessibilitycheck,\

View file

@ -9,6 +9,14 @@
#include <swmodeltestbase.hxx>
#include <AccessibilityCheck.hxx>
#include <AccessibilityIssue.hxx>
#include <OnlineAccessibilityCheck.hxx>
#include <wrtsh.hxx>
#include <vcl/scheduler.hxx>
#include <comphelper/propertysequence.hxx>
#include <comphelper/scopeguard.hxx>
#include <officecfg/Office/Common.hxx>
class AccessibilityCheckTest : public SwModelTestBase
{
@ -195,6 +203,169 @@ CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest, testCheckTabsFormatting)
CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_FORMATTING, aIssues[3]->m_eIssueID);
}
namespace
{
std::vector<std::shared_ptr<sfx::AccessibilityIssue>>
scanAccessibilityIssuesOnNodes(SwDoc* pDocument)
{
std::vector<std::shared_ptr<sfx::AccessibilityIssue>> aIssues;
auto const& pNodes = pDocument->GetNodes();
for (SwNodeOffset n(0); n < pNodes.Count(); ++n)
{
SwNode* pNode = pNodes[n];
auto& pCollection = pNode->getAccessibilityCheckStatus().pCollection;
if (pCollection)
{
for (auto& pIssue : pCollection->getIssues())
{
aIssues.push_back(pIssue);
}
}
}
return aIssues;
}
void checkIssuePosition(std::shared_ptr<sfx::AccessibilityIssue> const& pIssue, int nLine,
sal_Int32 nStart, sal_Int32 nEnd, SwNodeOffset nIndex)
{
auto* pSwIssue = static_cast<sw::AccessibilityIssue*>(pIssue.get());
OString sFailMessage = OString::Concat("Start doesn't match at line: ")
+ OString::Concat(OString::number(nLine));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailMessage.getStr(), nStart, pSwIssue->getStart());
sFailMessage
= OString::Concat("End doesn't match at line: ") + OString::Concat(OString::number(nLine));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailMessage.getStr(), nEnd, pSwIssue->getEnd());
sFailMessage = OString::Concat("Offset doesn't match at line: ")
+ OString::Concat(OString::number(nLine));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailMessage.getStr(), nIndex, pSwIssue->getNode()->GetIndex());
}
} // end anonymous ns
CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest, testOnlineNodeSplitAppend)
{
// Checks the a11y checker is setting the a11y issues to the nodes
// correctly when splitting and appending nodes (through undo), which
// happen on editing all the time.
// When a node is split, it can happen that both nodes get a11y issues
// if the node splits the area of direct formatting.
createSwDoc("OnlineCheck.odt");
SwDoc* pDoc = getSwDoc();
CPPUNIT_ASSERT(pDoc);
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
// Enable online a11y checker
{
auto pBatch(comphelper::ConfigurationChanges::create());
officecfg::Office::Common::Accessibility::OnlineAccessibilityCheck::set(true, pBatch);
pBatch->commit();
}
comphelper::ScopeGuard g([] {
auto pBatch(comphelper::ConfigurationChanges::create());
officecfg::Office::Common::Accessibility::OnlineAccessibilityCheck::set(false, pBatch);
pBatch->commit();
});
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(sal_Int32(0),
pDoc->getOnlineAccessibilityCheck()->getNumberOfAccessibilityIssues());
// Trigger a11y checker
pWrtShell->Down(/*bSelect*/ false, /*nCount*/ 0);
// Check we have 1 a11y issue
CPPUNIT_ASSERT_EQUAL(sal_Int32(2),
pDoc->getOnlineAccessibilityCheck()->getNumberOfAccessibilityIssues());
auto aIssues = scanAccessibilityIssuesOnNodes(pDoc);
CPPUNIT_ASSERT_EQUAL(size_t(2), aIssues.size());
CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_FORMATTING, aIssues[0]->m_eIssueID);
CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_FORMATTING, aIssues[1]->m_eIssueID);
checkIssuePosition(aIssues[0], __LINE__, 0, 32, SwNodeOffset(9));
checkIssuePosition(aIssues[1], __LINE__, 33, 136, SwNodeOffset(9));
// Position the cursor and hit "enter" (trigger split-node action)
pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 33, /*bBasicCall=*/false);
pWrtShell->SplitNode();
// Check the result
CPPUNIT_ASSERT_EQUAL(OUString("He heard quiet steps behind him. "),
getParagraph(1)->getString());
CPPUNIT_ASSERT_EQUAL(OUString("That didn't bode well. Who could be following him this late at "
"night and in this deadbeat part of town?"),
getParagraph(2)->getString());
CPPUNIT_ASSERT_EQUAL(sal_Int32(2),
pDoc->getOnlineAccessibilityCheck()->getNumberOfAccessibilityIssues());
aIssues = scanAccessibilityIssuesOnNodes(pDoc);
CPPUNIT_ASSERT_EQUAL(size_t(2), aIssues.size());
CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_FORMATTING, aIssues[0]->m_eIssueID);
CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_FORMATTING, aIssues[1]->m_eIssueID);
checkIssuePosition(aIssues[0], __LINE__, 0, 32, SwNodeOffset(9));
checkIssuePosition(aIssues[1], __LINE__, 0, 103, SwNodeOffset(10));
// Position cursor and split again
pWrtShell->Down(/*bSelect*/ false, /*nCount*/ 0);
pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 23, /*bBasicCall=*/false);
pWrtShell->SplitNode();
// Check the result
CPPUNIT_ASSERT_EQUAL(OUString("He heard quiet steps behind him. "),
getParagraph(1)->getString());
CPPUNIT_ASSERT_EQUAL(OUString("That didn't bode well. "), getParagraph(2)->getString());
CPPUNIT_ASSERT_EQUAL(
OUString(
"Who could be following him this late at night and in this deadbeat part of town?"),
getParagraph(3)->getString());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3),
pDoc->getOnlineAccessibilityCheck()->getNumberOfAccessibilityIssues());
aIssues = scanAccessibilityIssuesOnNodes(pDoc);
CPPUNIT_ASSERT_EQUAL(size_t(3), aIssues.size());
CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_FORMATTING, aIssues[0]->m_eIssueID);
CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_FORMATTING, aIssues[1]->m_eIssueID);
CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_FORMATTING, aIssues[2]->m_eIssueID);
checkIssuePosition(aIssues[0], __LINE__, 0, 32, SwNodeOffset(9));
checkIssuePosition(aIssues[1], __LINE__, 0, 23, SwNodeOffset(10));
checkIssuePosition(aIssues[2], __LINE__, 0, 80, SwNodeOffset(11));
// Undo second change
dispatchCommand(mxComponent, ".uno:Undo", {});
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(OUString("He heard quiet steps behind him. "),
getParagraph(1)->getString());
CPPUNIT_ASSERT_EQUAL(OUString("That didn't bode well. Who could be following him this late at "
"night and in this deadbeat part of town?"),
getParagraph(2)->getString());
CPPUNIT_ASSERT_EQUAL(sal_Int32(2),
pDoc->getOnlineAccessibilityCheck()->getNumberOfAccessibilityIssues());
aIssues = scanAccessibilityIssuesOnNodes(pDoc);
CPPUNIT_ASSERT_EQUAL(size_t(2), aIssues.size());
CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_FORMATTING, aIssues[0]->m_eIssueID);
CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_FORMATTING, aIssues[1]->m_eIssueID);
checkIssuePosition(aIssues[0], __LINE__, 0, 32, SwNodeOffset(9));
checkIssuePosition(aIssues[1], __LINE__, 0, 103, SwNodeOffset(10));
// Undo first change
dispatchCommand(mxComponent, ".uno:Undo", {});
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(sal_Int32(2),
pDoc->getOnlineAccessibilityCheck()->getNumberOfAccessibilityIssues());
CPPUNIT_ASSERT_EQUAL(
OUString("He heard quiet steps behind him. That didn't bode well. Who could be following "
"him this late at night and in this deadbeat part of town?"),
getParagraph(1)->getString());
aIssues = scanAccessibilityIssuesOnNodes(pDoc);
CPPUNIT_ASSERT_EQUAL(size_t(2), aIssues.size());
CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_FORMATTING, aIssues[0]->m_eIssueID);
CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_FORMATTING, aIssues[1]->m_eIssueID);
checkIssuePosition(aIssues[0], __LINE__, 0, 32, SwNodeOffset(9));
checkIssuePosition(aIssues[1], __LINE__, 33, 136, SwNodeOffset(9));
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Binary file not shown.

View file

@ -25,7 +25,7 @@ enum class IssueObject
TEXT,
};
class AccessibilityIssue final : public sfx::AccessibilityIssue
class SW_DLLPUBLIC AccessibilityIssue final : public sfx::AccessibilityIssue
{
private:
IssueObject m_eIssueObject;
@ -58,6 +58,10 @@ public:
bool canGotoIssue() const override;
void gotoIssue() const override;
sal_Int32 getStart() { return m_nStart; }
sal_Int32 getEnd() { return m_nEnd; }
SwNode* getNode() { return m_pNode; }
};
} // end sw namespace