Changeset View
Changeset View
Standalone View
Standalone View
tests/units/presentation/querytreemodeltest.cpp
Show All 18 Lines | 1 | /* This file is part of Zanshin | |||
---|---|---|---|---|---|
19 | You should have received a copy of the GNU General Public License | 19 | You should have received a copy of the GNU General Public License | ||
20 | along with this program; if not, write to the Free Software | 20 | along with this program; if not, write to the Free Software | ||
21 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | 21 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
22 | USA. | 22 | USA. | ||
23 | */ | 23 | */ | ||
24 | 24 | | |||
25 | #include <testlib/qtest_zanshin.h> | 25 | #include <testlib/qtest_zanshin.h> | ||
26 | 26 | | |||
27 | #include <memory> | ||||
28 | | ||||
27 | #include <QColor> | 29 | #include <QColor> | ||
30 | #include <QMimeData> | ||||
28 | 31 | | |||
29 | #include "utils/mockobject.h" | 32 | #include "utils/mockobject.h" | ||
30 | 33 | | |||
31 | #include "domain/taskqueries.h" | 34 | #include "domain/taskqueries.h" | ||
32 | #include "domain/taskrepository.h" | 35 | #include "domain/taskrepository.h" | ||
33 | #include "presentation/querytreemodel.h" | 36 | #include "presentation/querytreemodel.h" | ||
34 | #include "testlib/modeltest.h" | 37 | #include "testlib/modeltest.h" | ||
35 | 38 | | |||
▲ Show 20 Lines • Show All 786 Lines • ▼ Show 20 Line(s) | 796 | { | |||
822 | }; | 825 | }; | ||
823 | 826 | | |||
824 | Presentation::QueryTreeModel<QColor> model(queryGenerator, flagsFunction, | 827 | Presentation::QueryTreeModel<QColor> model(queryGenerator, flagsFunction, | ||
825 | dataFunction, setDataFunction, | 828 | dataFunction, setDataFunction, | ||
826 | dropFunction, dragFunction); | 829 | dropFunction, dragFunction); | ||
827 | new ModelTest(&model, this); | 830 | new ModelTest(&model, this); | ||
828 | 831 | | |||
829 | // WHEN | 832 | // WHEN | ||
830 | auto data = model.mimeData(QList<QModelIndex>() << model.index(1, 0) << model.index(2, 0)); | 833 | auto data = std::unique_ptr<QMimeData>(model.mimeData(QList<QModelIndex>() << model.index(1, 0) << model.index(2, 0))); | ||
831 | 834 | | |||
832 | // THEN | 835 | // THEN | ||
833 | QVERIFY(data); | 836 | QVERIFY(data.get()); | ||
834 | QVERIFY(model.mimeTypes().contains(QStringLiteral("application/x-zanshin-object"))); | 837 | QVERIFY(model.mimeTypes().contains(QStringLiteral("application/x-zanshin-object"))); | ||
835 | QList<QColor> colors; | 838 | QList<QColor> colors; | ||
836 | colors << Qt::green << Qt::blue; | 839 | colors << Qt::green << Qt::blue; | ||
837 | QCOMPARE(data->colorData().value<QList<QColor>>(), colors); | 840 | QCOMPARE(data->colorData().value<QList<QColor>>(), colors); | ||
838 | } | 841 | } | ||
839 | 842 | | |||
840 | void shouldDropMimeData_data() | 843 | void shouldDropMimeData_data() | ||
841 | { | 844 | { | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 856 | { | |||
891 | }; | 894 | }; | ||
892 | 895 | | |||
893 | Presentation::QueryTreeModel<QColor> model(queryGenerator, flagsFunction, | 896 | Presentation::QueryTreeModel<QColor> model(queryGenerator, flagsFunction, | ||
894 | dataFunction, setDataFunction, | 897 | dataFunction, setDataFunction, | ||
895 | dropFunction, dragFunction); | 898 | dropFunction, dragFunction); | ||
896 | new ModelTest(&model, this); | 899 | new ModelTest(&model, this); | ||
897 | 900 | | |||
898 | // WHEN | 901 | // WHEN | ||
899 | auto data = new QMimeData; | 902 | auto data = std::make_unique<QMimeData>(); | ||
900 | const QModelIndex parent = parentRow >= 0 ? model.index(parentRow, 0) : QModelIndex(); | 903 | const QModelIndex parent = parentRow >= 0 ? model.index(parentRow, 0) : QModelIndex(); | ||
901 | model.dropMimeData(data, Qt::MoveAction, row, column, parent); | 904 | model.dropMimeData(data.get(), Qt::MoveAction, row, column, parent); | ||
902 | 905 | | |||
903 | // THEN | 906 | // THEN | ||
904 | QCOMPARE(dropCalled, callExpected); | 907 | QCOMPARE(dropCalled, callExpected); | ||
905 | if (callExpected) { | 908 | if (callExpected) { | ||
906 | QCOMPARE(droppedData, data); | 909 | QCOMPARE(droppedData, data.get()); | ||
907 | QCOMPARE(colorSeen, parent.data(Presentation::QueryTreeModelBase::ObjectRole).value<QColor>()); | 910 | QCOMPARE(colorSeen, parent.data(Presentation::QueryTreeModelBase::ObjectRole).value<QColor>()); | ||
908 | } | 911 | } | ||
909 | } | 912 | } | ||
910 | 913 | | |||
911 | void shouldPreventCyclesByDragAndDrop() | 914 | void shouldPreventCyclesByDragAndDrop() | ||
912 | { | 915 | { | ||
913 | // GIVEN | 916 | // GIVEN | ||
914 | bool dropCalled = false; | 917 | bool dropCalled = false; | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 964 | Presentation::QueryTreeModel<QString> model(queryGenerator, flagsFunction, | |||
963 | dropFunction, dragFunction); | 966 | dropFunction, dragFunction); | ||
964 | new ModelTest(&model, this); | 967 | new ModelTest(&model, this); | ||
965 | 968 | | |||
966 | const auto indexes = QModelIndexList() << model.index(0, 0) | 969 | const auto indexes = QModelIndexList() << model.index(0, 0) | ||
967 | << model.index(1, 0) | 970 | << model.index(1, 0) | ||
968 | << model.index(1, 0, model.index(1, 0)); | 971 | << model.index(1, 0, model.index(1, 0)); | ||
969 | 972 | | |||
970 | // WHEN | 973 | // WHEN | ||
971 | auto data = model.mimeData(indexes); | 974 | auto data = std::unique_ptr<QMimeData>(model.mimeData(indexes)); | ||
972 | const auto parent = model.index(1, 0, model.index(0, 0, model.index(1, 0))); | 975 | const auto parent = model.index(1, 0, model.index(0, 0, model.index(1, 0))); | ||
973 | model.dropMimeData(data, Qt::MoveAction, -1, -1, parent); | 976 | model.dropMimeData(data.get(), Qt::MoveAction, -1, -1, parent); | ||
974 | 977 | | |||
975 | // THEN | 978 | // THEN | ||
976 | QVERIFY(!dropCalled); | 979 | QVERIFY(!dropCalled); | ||
977 | } | 980 | } | ||
978 | }; | 981 | }; | ||
979 | 982 | | |||
980 | ZANSHIN_TEST_MAIN(QueryTreeModelTest) | 983 | ZANSHIN_TEST_MAIN(QueryTreeModelTest) | ||
981 | 984 | | |||
982 | #include "querytreemodeltest.moc" | 985 | #include "querytreemodeltest.moc" |