diff --git a/declarativeimports/core/CMakeLists.txt b/declarativeimports/core/CMakeLists.txt index 49f2914e1..f488f0d0d 100644 --- a/declarativeimports/core/CMakeLists.txt +++ b/declarativeimports/core/CMakeLists.txt @@ -30,3 +30,5 @@ target_link_libraries(corebindingsplugin ${KDE4_PLASMA_LIBS} ${QT_QTSCRIPT_LIBRA install(TARGETS corebindingsplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/core) install(FILES qmldir DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/core) + +add_subdirectory(tests) diff --git a/declarativeimports/core/tests/CMakeLists.txt b/declarativeimports/core/tests/CMakeLists.txt new file mode 100644 index 000000000..c1df83c14 --- /dev/null +++ b/declarativeimports/core/tests/CMakeLists.txt @@ -0,0 +1,18 @@ +INCLUDE_DIRECTORIES( + ${corebindings_SOURCE_DIR} + ) + +kde4_add_unit_test(sortfiltermodeltest + sortfiltermodeltest.cpp + ${corebindings_SOURCE_DIR}/dataengineconsumer.cpp + ${corebindings_SOURCE_DIR}/datamodel.cpp + ${corebindings_SOURCE_DIR}/datasource.cpp + ) + +qt4_automoc(sortfiltermodeltest.cpp) + +target_link_libraries(sortfiltermodeltest + ${KDE4_PLASMA_LIBS} + ${QT_QTGUI_LIBRARY} + ${QT_QTTEST_LIBRARY} + ) diff --git a/declarativeimports/core/tests/sortfiltermodeltest.cpp b/declarativeimports/core/tests/sortfiltermodeltest.cpp new file mode 100644 index 000000000..7e7ee795e --- /dev/null +++ b/declarativeimports/core/tests/sortfiltermodeltest.cpp @@ -0,0 +1,76 @@ +/* + * Copyright 2012 Aurélien Gâteau + * + * 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 Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include + +#include + +// KDE +#include + +// Qt +#include +#include + +using namespace Plasma; + +QTEST_KDEMAIN(SortFilterModelTest, GUI) + +void SortFilterModelTest::setModel() +{ + // TODO: Actually test model change + QStandardItemModel model; + + SortFilterModel filterModel; + QSignalSpy spy(&filterModel, SIGNAL(sourceModelChanged(QObject*))); + + filterModel.setModel(&model); + QCOMPARE(spy.count(), 1); + QList arguments = spy.takeFirst(); + QCOMPARE(arguments.at(0).value(), static_cast(&model)); + + filterModel.setModel(&model); + QCOMPARE(spy.count(), 0); +} + +void SortFilterModelTest::setEmptyModel() +{ + SortFilterModel filterModel; + QStandardItemModel model; + filterModel.setModel(&model); + QCOMPARE(filterModel.sourceModel(), static_cast(&model)); + filterModel.setModel(0); + QCOMPARE(filterModel.sourceModel(), static_cast(0)); +} + +void SortFilterModelTest::setFilterRegExp() +{ + // TODO: Actually test filtering + SortFilterModel filterModel; + QSignalSpy spy(&filterModel, SIGNAL(filterRegExpChanged(QString))); + + filterModel.setFilterRegExp("foo"); + QCOMPARE(spy.count(), 1); + QList arguments = spy.takeFirst(); + QCOMPARE(arguments.at(0).toString(), QString("foo")); + + filterModel.setFilterRegExp("foo"); + QCOMPARE(spy.count(), 0); +} + +#include diff --git a/declarativeimports/core/tests/sortfiltermodeltest.h b/declarativeimports/core/tests/sortfiltermodeltest.h new file mode 100644 index 000000000..653c00177 --- /dev/null +++ b/declarativeimports/core/tests/sortfiltermodeltest.h @@ -0,0 +1,35 @@ +/* + * Copyright 2012 Aurélien Gâteau + * + * 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 Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef SORTFILTERMODELTEST_H +#define SORTFILTERMODELTEST_H + +// Qt +#include + +class SortFilterModelTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void setFilterRegExp(); + void setModel(); + void setEmptyModel(); +}; + +#endif /* SORTFILTERMODELTEST_H */