1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
/* This file is part of the dbusmenu-qt library
Copyright 2010 Canonical
Author: Aurelien Gateau <aurelien.gateau@canonical.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License (LGPL) as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later
version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef TESTUTILS_H
#define TESTUTILS_H
// Local
#include <debug_p.h>
#include <dbusmenutypes_p.h>
// Qt
#include <QObject>
#include <QMenu>
#include <QVariant>
class ManualSignalSpy : public QObject, public QList<QVariantList>
{
Q_OBJECT
public Q_SLOTS:
void receiveCall(int value)
{
append(QVariantList() << value);
}
void receiveCall(uint v1, int v2)
{
append(QVariantList() << v1 << v2);
}
void receiveCall(int v1, uint v2)
{
append(QVariantList() << v1 << v2);
}
void receiveCall(DBusMenuItemList itemList, DBusMenuItemKeysList removedPropsList)
{
QVariantList propsIds;
Q_FOREACH(DBusMenuItem item, itemList) {
propsIds << item.id;
}
QVariantList removedPropsIds;
Q_FOREACH(DBusMenuItemKeys props, removedPropsList) {
removedPropsIds << props.id;
}
QVariantList args;
args.push_back(propsIds);
args.push_back(removedPropsIds);
append(args);
}
void receiveCall(const QString& service, const QVariantMap& modifiedProperties, const QStringList& newProperties)
{
QVariantList args;
args.push_back(service);
args.push_back(modifiedProperties);
args.push_back(newProperties);
append(args);
}
};
class MenuFiller : public QObject
{
Q_OBJECT
public:
MenuFiller(QMenu *menu)
: m_menu(menu)
{
connect(m_menu, SIGNAL(aboutToShow()), SLOT(fillMenu()));
}
void addAction(QAction *action)
{
m_actions << action;
}
public Q_SLOTS:
void fillMenu()
{
while (!m_actions.isEmpty()) {
m_menu->addAction(m_actions.takeFirst());
}
}
private:
QMenu *m_menu;
QList<QAction *> m_actions;
};
void waitForDeferredDeletes();
#endif /* TESTUTILS_H */
|