Cover more properties in the QAction test

Expand the getSetCheck to include all properties, and add a test to
verify the fallback logic for the tooltip property.

Use the meta object system to set and check properties in the
tooltip-test to verify that things don't break when migrating to
the new property system.

Change-Id: I56355e8b436ede46701a124a9241ed26d2c706c5
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Volker Hilsheimer 2020-07-16 13:40:15 +02:00
parent bc98bc6890
commit 044ca0b8a8

View File

@ -50,6 +50,8 @@ private slots:
void setText();
void setIconText_data() { setText_data(); }
void setIconText();
void setToolTip_data();
void setToolTip();
#if QT_CONFIG(shortcut)
void setStandardKeys();
void task200823_tooltip();
@ -79,11 +81,81 @@ void tst_QAction::getSetCheck()
QAction obj1(nullptr);
auto var1 = new QActionGroup(nullptr);
obj1.setActionGroup(var1);
QCOMPARE(var1, obj1.actionGroup());
QCOMPARE(obj1.actionGroup(), var1);
obj1.setActionGroup(nullptr);
QCOMPARE(obj1.actionGroup(), nullptr);
delete var1;
QCOMPARE(obj1.isCheckable(), false);
QCOMPARE(obj1.isChecked(), false);
obj1.setCheckable(true);
QCOMPARE(obj1.isCheckable(), true);
obj1.setChecked(true);
QCOMPARE(obj1.isChecked(), true);
obj1.setCheckable(false);
QCOMPARE(obj1.isCheckable(), false);
QCOMPARE(obj1.isChecked(), false);
QCOMPARE(obj1.isEnabled(), true);
obj1.setEnabled(false);
QCOMPARE(obj1.isEnabled(), false);
QCOMPARE(obj1.icon(), QIcon());
QIcon themeIcon = QIcon::fromTheme("messagebox_info");
if (!themeIcon.isNull()) {
obj1.setIcon(themeIcon);
QCOMPARE(obj1.icon(), themeIcon);
}
QString statusTip("StatusTip");
obj1.setStatusTip(statusTip);
QCOMPARE(obj1.statusTip(), statusTip);
QString whatsThis("WhatsThis");
obj1.setWhatsThis(whatsThis);
QCOMPARE(obj1.whatsThis(), whatsThis);
QFont font;
font.setBold(true);
obj1.setFont(font);
QCOMPARE(obj1.font(), font);
#if QT_CONFIG(shortcut)
QCOMPARE(obj1.shortcut(), QKeySequence());
QKeySequence quit(Qt::CTRL | Qt::Key_Q);
obj1.setShortcut(quit);
QCOMPARE(obj1.shortcut(), quit);
QCOMPARE(obj1.shortcutContext(), Qt::WindowShortcut);
obj1.setShortcutContext(Qt::ApplicationShortcut);
QCOMPARE(obj1.shortcutContext(), Qt::ApplicationShortcut);
QCOMPARE(obj1.autoRepeat(), true);
obj1.setAutoRepeat(false);
QCOMPARE(obj1.autoRepeat(), false);
#endif
QCOMPARE(obj1.isVisible(), true);
obj1.setVisible(false);
QCOMPARE(obj1.isChecked(), false);
QCOMPARE(obj1.menuRole(), QAction::TextHeuristicRole);
obj1.setMenuRole(QAction::PreferencesRole);
QCOMPARE(obj1.menuRole(), QAction::PreferencesRole);
// default value for those depends on application attributes and/or style
obj1.setIconVisibleInMenu(true);
QCOMPARE(obj1.isIconVisibleInMenu(), true);
obj1.setIconVisibleInMenu(false);
QCOMPARE(obj1.isIconVisibleInMenu(), false);
obj1.setShortcutVisibleInContextMenu(true);
QCOMPARE(obj1.isShortcutVisibleInContextMenu(), true);
obj1.setShortcutVisibleInContextMenu(false);
QCOMPARE(obj1.isShortcutVisibleInContextMenu(), false);
QCOMPARE(obj1.priority(), QAction::NormalPriority);
obj1.setPriority(QAction::LowPriority);
QCOMPARE(obj1.priority(), QAction::LowPriority);
@ -126,6 +198,53 @@ void tst_QAction::setIconText()
QCOMPARE(action.text(), textFromIconText);
}
void tst_QAction::setToolTip_data()
{
QTest::addColumn<QByteArrayList>("properties");
QTest::addColumn<QStringList>("values");
QTest::addColumn<QStringList>("expectedToolTips");
QTest::newRow("Tooltip")
<< QByteArrayList{"toolTip", "toolTip", "toolTip"}
<< QStringList{"ToolTip", "Tool&Tip", "Tool && Tip"}
<< QStringList{"ToolTip", "Tool&Tip", "Tool && Tip"};
QTest::newRow("Only text")
<< QByteArrayList{"text", "text", "text", "text", "toolTip", "toolTip"}
<< QStringList {"Text", "Te&xt2", "Find && Replace", "O&pen File...", "ToolTip", QString()}
<< QStringList{"Text", "Text2", "Find & Replace", "Open File", "ToolTip", "Open File"};
QTest::newRow("Only iconText")
<< QByteArrayList{"iconText", "iconText", "iconText", "toolTip", "toolTip"}
<< QStringList{"Icon Text", "Find && Replace", "Icon&Text", "ToolTip", QString()}
<< QStringList{"Icon Text", "Find & Replace", "IconText", "ToolTip", "IconText"};
QTest::newRow("Text and iconText")
<< QByteArrayList{"iconText", "text", "iconText", "text", "iconText"}
<< QStringList{"Icon", "Text", "Icon2", QString(), "Icon3"}
<< QStringList{"Icon", "Text", "Text", "Icon2", "Icon3"};
QTest::newRow("All and nothing")
<< QByteArrayList{"text", "iconText", "toolTip", "text", "iconText", "toolTip", "text", "text", "iconText", "iconText", "text"}
<< QStringList {"Te&xt", "I&&con", "ToolTip", "Text", "Icon", QString(), "Te&&xt2", QString(), "I&&con2", QString(), "Text"}
<< QStringList {"Text", "Text", "ToolTip", "ToolTip", "ToolTip", "Text", "Te&xt2", "Icon", "I&con2", QString(), "Text"};
}
void tst_QAction::setToolTip()
{
QFETCH(QByteArrayList, properties);
QFETCH(QStringList, values);
QFETCH(QStringList, expectedToolTips);
QCOMPARE(properties.count(), values.count());
QCOMPARE(properties.count(), expectedToolTips.count());
QAction action(nullptr);
for (int i = 0; i < properties.count(); ++i) {
const auto property = properties.at(i);
const auto value = values.at(i);
const auto expectedToolTip = expectedToolTips.at(i);
action.setProperty(property, value);
QCOMPARE(action.toolTip(), expectedToolTip);
}
}
#if QT_CONFIG(shortcut)
//basic testing of standard keys