File indexing completed on 2021-12-21 13:19:39

0001 /* This file is part of the dbusmenu-qt library
0002    Copyright 2010 Canonical
0003    Author: Aurelien Gateau <aurelien.gateau@canonical.com>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License (LGPL) as published by the Free Software Foundation;
0008    either version 2 of the License, or (at your option) any later
0009    version.
0010 
0011    This library is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014    Library General Public License for more details.
0015 
0016    You should have received a copy of the GNU Library General Public License
0017    along with this library; see the file COPYING.LIB.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019    Boston, MA 02110-1301, USA.
0020 */
0021 #ifndef TESTUTILS_H
0022 #define TESTUTILS_H
0023 
0024 // Local
0025 #include <debug_p.h>
0026 #include <dbusmenutypes_p.h>
0027 
0028 // Qt
0029 #include <QObject>
0030 #include <QMenu>
0031 #include <QVariant>
0032 
0033 class ManualSignalSpy : public QObject, public QList<QVariantList>
0034 {
0035     Q_OBJECT
0036 public Q_SLOTS:
0037     void receiveCall(int value)
0038     {
0039         append(QVariantList() << value);
0040     }
0041 
0042     void receiveCall(uint v1, int v2)
0043     {
0044         append(QVariantList() << v1 << v2);
0045     }
0046 
0047     void receiveCall(int v1, uint v2)
0048     {
0049         append(QVariantList() << v1 << v2);
0050     }
0051 
0052     void receiveCall(DBusMenuItemList itemList, DBusMenuItemKeysList removedPropsList)
0053     {
0054         QVariantList propsIds;
0055         Q_FOREACH(DBusMenuItem item, itemList) {
0056             propsIds << item.id;
0057         }
0058         QVariantList removedPropsIds;
0059         Q_FOREACH(DBusMenuItemKeys props, removedPropsList) {
0060             removedPropsIds << props.id;
0061         }
0062 
0063         QVariantList args;
0064         args.push_back(propsIds);
0065         args.push_back(removedPropsIds);
0066         append(args);
0067     }
0068 
0069     void receiveCall(const QString& service, const QVariantMap& modifiedProperties, const QStringList& newProperties)
0070     {
0071         QVariantList args;
0072         args.push_back(service);
0073         args.push_back(modifiedProperties);
0074         args.push_back(newProperties);
0075         append(args);
0076     }
0077 };
0078 
0079 class MenuFiller : public QObject
0080 {
0081     Q_OBJECT
0082 public:
0083     MenuFiller(QMenu *menu)
0084     : m_menu(menu)
0085     {
0086         connect(m_menu, SIGNAL(aboutToShow()), SLOT(fillMenu()));
0087     }
0088 
0089     void addAction(QAction *action)
0090     {
0091         m_actions << action;
0092     }
0093 
0094 public Q_SLOTS:
0095     void fillMenu()
0096     {
0097         while (!m_actions.isEmpty()) {
0098             m_menu->addAction(m_actions.takeFirst());
0099         }
0100     }
0101 
0102 private:
0103     QMenu *m_menu;
0104     QList<QAction *> m_actions;
0105 };
0106 
0107 void waitForDeferredDeletes();
0108 
0109 #endif /* TESTUTILS_H */