Warning, file /frameworks/kdesignerplugin/autotests/minimaltest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * Copyright 2014 Alex Merry <alex.merry@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) version 3, or any 0008 * later version accepted by the membership of KDE e.V. (or its 0009 * successor approved by the membership of KDE e.V.), which shall 0010 * act as a proxy defined in Section 6 of version 3 of the license. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public 0018 * License along with this library. If not, see 0019 * <http://www.gnu.org/licenses/>. 0020 */ 0021 0022 #include <QMetaObject> 0023 #include <QPluginLoader> 0024 #include <QTest> 0025 0026 #include <QtUiPlugin/QDesignerCustomWidgetInterface> 0027 0028 static bool widgetLessThan(QDesignerCustomWidgetInterface* w1, QDesignerCustomWidgetInterface* w2) 0029 { 0030 return w1->name() < w2->name(); 0031 } 0032 0033 class MinimalTest : public QObject 0034 { 0035 Q_OBJECT 0036 0037 private Q_SLOTS: 0038 void initTestCase() { 0039 QPluginLoader loader(QStringLiteral(MINIMAL_PLUGIN)); 0040 m_pluginInstance = loader.instance(); 0041 QVERIFY2(m_pluginInstance, qPrintable(loader.errorString())); 0042 m_collection = qobject_cast<QDesignerCustomWidgetCollectionInterface*>(m_pluginInstance); 0043 QVERIFY(m_collection); 0044 m_widgets = m_collection->customWidgets(); 0045 std::sort(m_widgets.begin(), m_widgets.end(), widgetLessThan); 0046 } 0047 0048 void testPluginName() { 0049 QCOMPARE(m_pluginInstance->metaObject()->className(), 0050 "WidgetsPlugin"); 0051 } 0052 0053 void testWidgetList() { 0054 QCOMPARE(m_widgets.count(), 2); 0055 } 0056 0057 void testWidget_data() { 0058 QTest::addColumn<int>("index"); 0059 QTest::addColumn<QString>("name"); 0060 QTest::addColumn<QString>("includefile"); 0061 QTest::addColumn<QString>("domxml"); 0062 0063 QTest::newRow("QCheckBox") 0064 << 0 0065 << "QCheckBox" 0066 << "qcheckbox.h" 0067 << "<widget class=\"QCheckBox\" name=\"qcheckbox\"/>"; 0068 0069 QTest::newRow("QPushButton") 0070 << 1 0071 << "QPushButton" 0072 << "qpushbutton.h" 0073 << "<widget class=\"QPushButton\" name=\"qpushbutton\"/>"; 0074 } 0075 0076 void testWidget() { 0077 QFETCH(int, index); 0078 QFETCH(QString, name); 0079 QFETCH(QString, includefile); 0080 QFETCH(QString, domxml); 0081 0082 QVERIFY(m_widgets.count() > index); 0083 QDesignerCustomWidgetInterface *wiface = m_widgets.at(index); 0084 QVERIFY(wiface); 0085 QCOMPARE(wiface->name(), name); 0086 QCOMPARE(wiface->group(), QString("Custom")); 0087 QCOMPARE(wiface->toolTip(), QString(name + " Widget")); 0088 QCOMPARE(wiface->whatsThis(), QString(name + " Widget")); 0089 QCOMPARE(wiface->includeFile(), includefile); 0090 QVERIFY(!wiface->icon().isNull()); 0091 QVERIFY(!wiface->isContainer()); 0092 QCOMPARE(wiface->codeTemplate(), QString()); 0093 QCOMPARE(wiface->domXml(), domxml); 0094 0095 QVERIFY(!wiface->isInitialized()); 0096 wiface->initialize(nullptr); 0097 0098 QWidget *widget = wiface->createWidget(nullptr); 0099 QVERIFY(widget); 0100 QCOMPARE(widget->metaObject()->className(), 0101 name.toLatin1().constData()); 0102 } 0103 0104 private: 0105 QDesignerCustomWidgetCollectionInterface *m_collection; 0106 QObject *m_pluginInstance; 0107 QList<QDesignerCustomWidgetInterface*> m_widgets; 0108 }; 0109 0110 QTEST_MAIN(MinimalTest) 0111 0112 #include <minimaltest.moc>