vcl uitest: Add support for toolbar items

Add new class ToolBoxItemUIObject that provides
access to information about ToolBox (toolbar)
items in UI tests.
Initially, report the item's text and enabled
state. (This can be extended as needed if there
is a need in the future.)

Extend ToolBoxUIObject to report the ToolBox
items as children in addition to those children
retrieved via the WindowUIObject base class logic.

This will be used in an upcoming commit in
sw/qa/uitest/table/tdf146145.py to port
that test away from depending on a11y implementation
details that are about to change.

Change-Id: I6064ad3481e1cef694762c321e244097d8c3029b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185774
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
Michael Weghorn
2025-05-28 09:19:43 +02:00
parent 3cf9ebf584
commit b95f8892a1
5 changed files with 103 additions and 0 deletions
+1
View File
@@ -570,6 +570,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/pdf/Matrix3 \
vcl/source/pdf/XmpMetadata \
vcl/source/uitest/logger \
vcl/source/uitest/toolboxitemuiobject \
vcl/source/uitest/toolboxuiobject \
vcl/source/uitest/uiobject \
vcl/source/uitest/uitest \
+30
View File
@@ -0,0 +1,30 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <vcl/toolbox.hxx>
#include <vcl/uitest/uiobject.hxx>
class ToolBoxItemUIObject final : public UIObject
{
private:
VclPtr<ToolBox> m_pToolBox;
ToolBoxItemId m_nId;
public:
ToolBoxItemUIObject(const VclPtr<ToolBox>& pToolBox, ToolBoxItemId nId);
virtual ~ToolBoxItemUIObject() override;
virtual StringMap get_state() override;
virtual bool equals(const UIObject& rOther) const override;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
+4
View File
@@ -30,6 +30,10 @@ public:
virtual OUString get_action(VclEventId nEvent) const override;
std::set<OUString> get_children() const override;
std::unique_ptr<UIObject> get_child(const OUString& rID) override;
private:
virtual OUString get_name() const override;
};
+37
View File
@@ -0,0 +1,37 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <uitest/toolboxitemuiobject.hxx>
ToolBoxItemUIObject::ToolBoxItemUIObject(const VclPtr<ToolBox>& pToolBox, ToolBoxItemId nId)
: m_pToolBox(pToolBox)
, m_nId(nId)
{
}
ToolBoxItemUIObject::~ToolBoxItemUIObject() {}
StringMap ToolBoxItemUIObject::get_state()
{
StringMap aMap{ { u"Enabled"_ustr, OUString::boolean(m_pToolBox->IsItemEnabled(m_nId)) },
{ u"Text"_ustr, m_pToolBox->GetItemText(m_nId) } };
return aMap;
}
bool ToolBoxItemUIObject::equals(const UIObject& rOther) const
{
const ToolBoxItemUIObject* pOther = dynamic_cast<const ToolBoxItemUIObject*>(&rOther);
if (!pOther)
return false;
return m_pToolBox == pOther->m_pToolBox && m_nId == pOther->m_nId;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
+31
View File
@@ -7,10 +7,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <uitest/toolboxitemuiobject.hxx>
#include <uitest/toolboxuiobject.hxx>
#include <o3tl/string_view.hxx>
#include <vcl/toolbox.hxx>
constexpr OUString TOOLBOX_ITEM_ID_PREFIX = u"toolboxitem-"_ustr;
ToolBoxUIObject::ToolBoxUIObject(const VclPtr<ToolBox>& xToolBox)
: WindowUIObject(xToolBox)
, mxToolBox(xToolBox)
@@ -59,6 +63,33 @@ StringMap ToolBoxUIObject::get_state()
return aMap;
}
std::set<OUString> ToolBoxUIObject::get_children() const
{
std::set<OUString> aChildren = WindowUIObject::get_children();
const size_t nItemCount = mxToolBox->GetItemCount();
for (size_t i = 0; i < nItemCount; ++i)
{
const OUString sId
= TOOLBOX_ITEM_ID_PREFIX + OUString::number(sal_uInt16(mxToolBox->GetItemId(i)));
aChildren.insert(sId);
}
return aChildren;
}
std::unique_ptr<UIObject> ToolBoxUIObject::get_child(const OUString& rID)
{
if (rID.startsWith(TOOLBOX_ITEM_ID_PREFIX))
{
const sal_Int32 nPrefixLength = TOOLBOX_ITEM_ID_PREFIX.getLength();
const ToolBoxItemId nItemId(o3tl::toInt32(rID.subView(nPrefixLength)));
return std::make_unique<ToolBoxItemUIObject>(mxToolBox, nItemId);
}
return WindowUIObject::get_child(rID);
}
OUString ToolBoxUIObject::get_name() const { return u"ToolBoxUIObject"_ustr; }
std::unique_ptr<UIObject> ToolBoxUIObject::create(vcl::Window* pWindow)