Commit 95df1d41 authored by Volker Krause's avatar Volker Krause
Browse files

Add basic test for the schema model

parent ef88f729
......@@ -7,6 +7,7 @@ set(analyzer_lib_srcs
rest/serverinfo.cpp
model/productmodel.cpp
model/schemamodel.cpp
)
add_library(UserFeedbackAnalyzer STATIC ${analyzer_lib_srcs})
......@@ -25,7 +26,6 @@ set(analyzer_srcs
ratioset.cpp
ratiosetaggregationmodel.cpp
sample.cpp
schemamodel.cpp
schemaeditwidget.cpp
schemaentryitemeditorfactory.cpp
schemaentrytypecombobox.cpp
......
......@@ -105,7 +105,10 @@ QVariant SchemaModel::headerData(int section, Qt::Orientation orientation, int r
Qt::ItemFlags SchemaModel::flags(const QModelIndex &index) const
{
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
const auto baseFlags = QAbstractTableModel::flags(index);
if (index.isValid())
return baseFlags | Qt::ItemIsEditable;
return baseFlags;
}
bool SchemaModel::setData(const QModelIndex &index, const QVariant &value, int role)
......
......@@ -40,7 +40,7 @@ public:
void addEntry(const QString &name);
void deleteEntry(int row);
int rowCount(const QModelIndex &parent) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
......
......@@ -18,9 +18,9 @@
#include "schemaeditwidget.h"
#include "ui_schemaeditwidget.h"
#include <model/schemamodel.h>
#include <core/product.h>
#include "schemaentryitemeditorfactory.h"
#include "schemamodel.h"
#include <QDebug>
#include <QMessageBox>
......
......@@ -5,3 +5,7 @@ add_test(NAME productapitest COMMAND productapitest)
add_executable(productmodeltest productmodeltest.cpp ${CMAKE_SOURCE_DIR}/3rdparty/qt/modeltest.cpp)
target_link_libraries(productmodeltest Qt5::Test UserFeedbackAnalyzer)
add_test(NAME productmodeltest COMMAND productmodeltest)
add_executable(schemamodeltest schemamodeltest.cpp ${CMAKE_SOURCE_DIR}/3rdparty/qt/modeltest.cpp)
target_link_libraries(schemamodeltest Qt5::Test UserFeedbackAnalyzer)
add_test(NAME schemamodeltest COMMAND schemamodeltest)
/*
Copyright (C) 2016 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program 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 General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <model/schemamodel.h>
#include <3rdparty/qt/modeltest.h>
#include <QDebug>
#include <QtTest/qtest.h>
#include <QObject>
#include <QSignalSpy>
#include <QStandardPaths>
using namespace UserFeedback::Analyzer;
class SchemaModelTest : public QObject
{
Q_OBJECT
private slots:
void initTestCase()
{
QStandardPaths::setTestModeEnabled(true);
}
void testSchemaModel()
{
SchemaModel model;
ModelTest modelTest(&model);
model.setProduct(Product());
QCOMPARE(model.rowCount(), 0);
Product p;
p.setName(QStringLiteral("org.kde.UserFeedback.UnitTest"));
model.setProduct(p);
QCOMPARE(model.rowCount(), 0);
QVector<SchemaEntry> schema;
SchemaEntry entry;
entry.setName(QStringLiteral("entry1"));
schema.push_back(entry);
p.setSchema(schema);
model.setProduct(p);
QCOMPARE(model.rowCount(), schema.size());
}
};
QTEST_MAIN(SchemaModelTest)
#include "schemamodeltest.moc"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment