File indexing completed on 2024-05-19 04:01:09

0001 /*
0002     SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #include <model/schemamodel.h>
0008 #include <core/schemaentrytemplates.h>
0009 
0010 #include <QDebug>
0011 #include <QtTest/qtest.h>
0012 #include <QObject>
0013 #include <QSignalSpy>
0014 #include <QStandardPaths>
0015 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
0016 #include <QAbstractItemModelTester>
0017 #endif
0018 
0019 using namespace KUserFeedback::Console;
0020 
0021 class SchemaModelTest : public QObject
0022 {
0023     Q_OBJECT
0024 private Q_SLOTS:
0025     void initTestCase()
0026     {
0027         Q_INIT_RESOURCE(schematemplates);
0028         QStandardPaths::setTestModeEnabled(true);
0029     }
0030 
0031     void testSchemaModel()
0032     {
0033         SchemaModel model;
0034 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
0035         QAbstractItemModelTester modelTest(&model);
0036 #endif
0037 
0038         model.setProduct(Product());
0039         QCOMPARE(model.rowCount(), 0);
0040 
0041         Product p;
0042         p.setName(QStringLiteral("org.kde.UserFeedback.UnitTest"));
0043         model.setProduct(p);
0044         QCOMPARE(model.rowCount(), 0);
0045 
0046         QVector<SchemaEntry> schema;
0047         SchemaEntry entry;
0048         entry.setName(QStringLiteral("entry1"));
0049         schema.push_back(entry);
0050         p.setSchema(schema);
0051         model.setProduct(p);
0052         QCOMPARE(model.rowCount(), schema.size());
0053 
0054         for (const auto &tpl : SchemaEntryTemplates::availableTemplates())
0055             p.addTemplate(tpl);
0056         model.setProduct(p);
0057         QVERIFY(model.rowCount() > 0);
0058     }
0059 };
0060 
0061 QTEST_MAIN(SchemaModelTest)
0062 
0063 #include "schemamodeltest.moc"