diff options
-rw-r--r-- | framework/src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | framework/src/tests/CMakeLists.txt | 15 | ||||
-rw-r--r-- | framework/src/tests/folderlistmodeltest.cpp | 70 |
3 files changed, 86 insertions, 0 deletions
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt index 9d4e238e..a5b2f6bc 100644 --- a/framework/src/CMakeLists.txt +++ b/framework/src/CMakeLists.txt | |||
@@ -71,6 +71,7 @@ install(TARGETS frameworkplugin DESTINATION ${FRAMEWORK_INSTALL_DIR}) | |||
71 | 71 | ||
72 | set(BUILD_TESTING ON) | 72 | set(BUILD_TESTING ON) |
73 | 73 | ||
74 | add_subdirectory(tests) | ||
74 | add_subdirectory(domain/mime/tests) | 75 | add_subdirectory(domain/mime/tests) |
75 | add_subdirectory(domain/mime/mimetreeparser) | 76 | add_subdirectory(domain/mime/mimetreeparser) |
76 | add_subdirectory(domain/settings/tests) | 77 | add_subdirectory(domain/settings/tests) |
diff --git a/framework/src/tests/CMakeLists.txt b/framework/src/tests/CMakeLists.txt new file mode 100644 index 00000000..fb2e2ead --- /dev/null +++ b/framework/src/tests/CMakeLists.txt | |||
@@ -0,0 +1,15 @@ | |||
1 | include_directories( | ||
2 | ${CMAKE_CURRENT_BINARY_DIR} | ||
3 | ${CMAKE_CURRENT_SOURCE_DIR}/.. | ||
4 | ) | ||
5 | |||
6 | find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Core Test Gui) | ||
7 | |||
8 | add_executable(folderlistmodeltest folderlistmodeltest.cpp) | ||
9 | add_test(folderlistmodeltest folderlistmodeltest) | ||
10 | target_link_libraries(folderlistmodeltest | ||
11 | Qt5::Core | ||
12 | Qt5::Test | ||
13 | Qt5::Gui | ||
14 | kubeframework | ||
15 | ) | ||
diff --git a/framework/src/tests/folderlistmodeltest.cpp b/framework/src/tests/folderlistmodeltest.cpp new file mode 100644 index 00000000..da84d432 --- /dev/null +++ b/framework/src/tests/folderlistmodeltest.cpp | |||
@@ -0,0 +1,70 @@ | |||
1 | #include <QTest> | ||
2 | #include <QDebug> | ||
3 | #include <QStandardItemModel> | ||
4 | #include "krecursivefilterproxymodel.h" | ||
5 | #include "folderlistmodel.h" | ||
6 | |||
7 | class TestModel : public KRecursiveFilterProxyModel { | ||
8 | public: | ||
9 | |||
10 | TestModel() | ||
11 | :KRecursiveFilterProxyModel() | ||
12 | { | ||
13 | auto model = QSharedPointer<QStandardItemModel>::create(); | ||
14 | setSourceModel(model.data()); | ||
15 | mModel = model; | ||
16 | } | ||
17 | |||
18 | bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE | ||
19 | { | ||
20 | return left.data(Qt::DisplayRole).toString() < right.data(Qt::DisplayRole).toString(); | ||
21 | } | ||
22 | |||
23 | bool acceptRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE | ||
24 | { | ||
25 | auto index = sourceModel()->index(sourceRow, 0, sourceParent); | ||
26 | return index.data(Qt::DisplayRole).toString().contains("accept"); | ||
27 | } | ||
28 | |||
29 | QSharedPointer<QStandardItemModel> mModel; | ||
30 | }; | ||
31 | |||
32 | bool contains(QAbstractItemModel &model, const QModelIndex &parent, QString s) | ||
33 | { | ||
34 | for (int row = 0; row < model.rowCount(parent); row++) { | ||
35 | auto idx = model.index(row, 0, parent); | ||
36 | if (idx.data(Qt::DisplayRole).toString() == s) { | ||
37 | return true; | ||
38 | } | ||
39 | if (contains(model, idx, s)) { | ||
40 | return true; | ||
41 | } | ||
42 | } | ||
43 | return false; | ||
44 | } | ||
45 | |||
46 | class FolderlistModelTest : public QObject | ||
47 | { | ||
48 | Q_OBJECT | ||
49 | private slots: | ||
50 | |||
51 | void initTestCase() | ||
52 | { | ||
53 | } | ||
54 | |||
55 | void testRecursiveFilterModel() | ||
56 | { | ||
57 | TestModel model; | ||
58 | auto root = new QStandardItem{"acceptroot"}; | ||
59 | model.mModel->appendRow(root); | ||
60 | auto item = new QStandardItem{"accept1"}; | ||
61 | root->appendRow(item); | ||
62 | item->appendRow(new QStandardItem{"accept11"}); | ||
63 | QVERIFY(contains(model, {}, "acceptroot")); | ||
64 | QVERIFY(contains(model, {}, "accept1")); | ||
65 | QVERIFY(contains(model, {}, "accept11")); | ||
66 | } | ||
67 | }; | ||
68 | |||
69 | QTEST_MAIN(FolderlistModelTest) | ||
70 | #include "folderlistmodeltest.moc" | ||