diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -27,6 +27,13 @@ LINK_LIBRARIES KF5::ItemModels Qt5::Test Qt5::Widgets proxymodeltestsuite ) +if (${Qt5Qml_FOUND}) + ecm_add_tests( + kconcatenaterows_qml.cpp + LINK_LIBRARIES KF5::ItemModels Qt5::Test Qt5::Qml + ) +endif() + #we need additional sources for this test, can't use it in ecm_add_tests ecm_add_test(kselectionproxymodel_smoketest.cpp ${proxyModelSmokeTestSources} TEST_NAME "kselectionproxymodel_smoketest" diff --git a/autotests/concatenaterowstest.qml b/autotests/concatenaterowstest.qml new file mode 100644 --- /dev/null +++ b/autotests/concatenaterowstest.qml @@ -0,0 +1,16 @@ +import QtQuick 2.0 +import org.kde.kitemmodels 1.0 + +KConcatenateRowsProxyModel { + id: myModel + ListModel { + ListElement { name: "a" } + ListElement { name: "b" } + } + ListModel { + ListElement { name: "c" } + ListElement { name: "d" } + } +} + + diff --git a/autotests/kconcatenaterows_qml.cpp b/autotests/kconcatenaterows_qml.cpp new file mode 100644 --- /dev/null +++ b/autotests/kconcatenaterows_qml.cpp @@ -0,0 +1,56 @@ +/* + Copyright (C) 2019 David Edmundson + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 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 Lesser 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. +*/ + +#include + +#include +#include + +#include + +#include + +class tst_KConcatenateRowsQml : public QObject +{ + Q_OBJECT +private Q_SLOTS: + void testQmlLoad(); +}; + +void tst_KConcatenateRowsQml::testQmlLoad() +{ + QQmlApplicationEngine app; + app.load(QFINDTESTDATA("concatenaterowstest.qml")); + + QCOMPARE(app.rootObjects().count(), 1); + + auto concatModel = qobject_cast(app.rootObjects().first()); + QVERIFY(concatModel); + + QCOMPARE(concatModel->rowCount(), 4); + + QCOMPARE(concatModel->data(concatModel->index(0, 0)).toString(), "a"); + QCOMPARE(concatModel->data(concatModel->index(1, 0)).toString(), "b"); + QCOMPARE(concatModel->data(concatModel->index(2, 0)).toString(), "c"); + QCOMPARE(concatModel->data(concatModel->index(3, 0)).toString(), "d"); +} + +QTEST_MAIN(tst_KConcatenateRowsQml) + +#include "kconcatenaterows_qml.moc" diff --git a/tests/qml/concatenaterows.qml b/tests/qml/concatenaterows.qml deleted file mode 100644 --- a/tests/qml/concatenaterows.qml +++ /dev/null @@ -1,26 +0,0 @@ -import QtQuick 2.0 -import org.kde.kitemmodels 1.0 - -ListView { - model: KConcatenateRowsProxyModel { - id: myModel - ListModel { - ListElement { name: "a" } - ListElement { name: "b" } - } - ListModel { - ListElement { name: "c" } - ListElement { name: "d" } - } - } - - delegate: Text { - text: model.name - } - - Component.onCompleted : { - console.log(myModel.rowCount()) - } -} - -