diff --git a/plugins/dockers/storyboarddocker/storyboardModel.h b/plugins/dockers/storyboarddocker/storyboardModel.h index 0675fce2c9..e677dfd7f0 100644 --- a/plugins/dockers/storyboarddocker/storyboardModel.h +++ b/plugins/dockers/storyboarddocker/storyboardModel.h @@ -1,64 +1,65 @@ /* * Copyright (c) 2020 Saurabh Kumar * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef STORYBOARD_MODEL #define STORYBOARD_MODEL #include #include /* The main storyboard model. */ class StoryboardModel : public QAbstractListModel { Q_OBJECT public: //if we don't need this constructor change it StoryboardModel(QObject *parent = 0); int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; Qt::ItemFlags flags(const QModelIndex &index) const override; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) override; //for removing and inserting rows bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()); bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()); //for removing and inserting column bool insertColumns(int position, int Columns, const QModelIndex &index = QModelIndex()); bool removeColumns(int position, int Columns, const QModelIndex &index = QModelIndex()); //for drag and drop Qt::DropActions supportedDropActions() const override; Qt::DropActions supportedDragActions() const override; + int commentCount(); private: struct Private; const QScopedPointer m_d; }; #endif \ No newline at end of file diff --git a/plugins/dockers/storyboarddocker/tests/CMakeLists.txt b/plugins/dockers/storyboarddocker/tests/CMakeLists.txt index d7f708fd04..de932c2a0b 100644 --- a/plugins/dockers/storyboarddocker/tests/CMakeLists.txt +++ b/plugins/dockers/storyboarddocker/tests/CMakeLists.txt @@ -1,18 +1,19 @@ set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_SOURCE_DIR}/libs/ui/tests ${CMAKE_CURRENT_BINARY_DIR}/.. ) macro_add_unittest_definitions() ecm_add_test( storyboardModelTest.cpp ../storyboardModel.cpp + ../commentModel.cpp ${CMAKE_SOURCE_DIR}/libs/ui/tests/modeltest.cpp TEST_NAME kritastoryboardmodeltest NAME_PREFIX "plugins-dockers-storyboarddocker-" LINK_LIBRARIES kritastoryboarddocker kritaui Qt5::Test ) \ No newline at end of file diff --git a/plugins/dockers/storyboarddocker/tests/storyboardModelTest.cpp b/plugins/dockers/storyboarddocker/tests/storyboardModelTest.cpp index 6c83bbdfd6..3bb7ff7956 100644 --- a/plugins/dockers/storyboarddocker/tests/storyboardModelTest.cpp +++ b/plugins/dockers/storyboarddocker/tests/storyboardModelTest.cpp @@ -1,41 +1,125 @@ /* * Copyright (c) 2020 Saurabh Kumar * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "storyboardModelTest.h" #include #include #include "storyboardModel.h" -#include "modeltest.h" +#include "commentModel.h" -void StoryboardModelTest::testModel() +void StoryboardModelTest::init() { - QStringList list; - list<<"cats"<<"dogs"<<"birds"; - QCOMPARE(1,1); + m_commentModel = new CommentModel(0); + m_storyboardModel = new StoryboardModel(0); + QCOMPARE(m_storyboardModel->columnCount(), 1); + m_commentModel->insertRows(m_storyboardModel->rowCount(),1); + QCOMPARE(m_commentModel->rowCount(), 1); +} + +void StoryboardModelTest::cleanup() +{ + delete m_storyboardModel; + delete m_commentModel; +} + +void StoryboardModelTest::testAddComment() +{ + int commentStoryboard = m_storyboardModel->commentCount(); + int rowsComment = m_commentModel->rowCount(); + + QCOMPARE(commentStoryboard, rowsComment); + + m_commentModel->insertRows(m_commentModel->rowCount(),1); + auto tester = new QAbstractItemModelTester(m_storyboardModel, 0); + auto tester = new QAbstractItemModelTester(m_commentModel, 0); + + QCOMPARE(rowsComment + 1, m_commentModel->rowCount()); + + QCOMPARE(m_storyboardModel->commentCount(), m_commentModel->rowCount()); +} + +void StoryboardModelTest::testRemoveComment() +{ + int commentStoryboard = m_storyboardModel->commentCount(); + int rowsComment = m_commentModel->rowCount(); + + QCOMPARE(commentStoryboard, rowsComment); + + m_commentModel->removeRows(m_commentModel->rowCount(),1); + + auto tester = new QAbstractItemModelTester(m_storyboardModel, 0); + auto tester = new QAbstractItemModelTester(m_commentModel, 0); + + QCOMPARE(rowsComment - 1, m_commentModel->rowCount()); + QCOMPARE(m_storyboardModel->commentCount(), m_commentModel->rowCount()); +} - StoryboardModel *model = new StoryboardModel(list, this); - //new ModelTest(model, this); - auto tester = new QAbstractItemModelTester(model, 0); +void StoryboardModelTest::testCommentNameChanged() +{ + QModelIndex index = m_commentModel->createIndex(m_commentModel->rowCount(),m_commentModel->columnCount()); + QVariant value = QVariant(QString("newValue")); + m_commentModel->setData(index, value); + auto tester = new QAbstractItemModelTester(m_commentModel, 0); +} + +void StoryboardModelTest::testCommentVisibilityChanged() +{ + +} + +void StoryboardModelTest::testFrameAdded() +{ + m_storyboardModel->insertRows(m_storyboardModel->rowCount(),1); + auto tester = new QAbstractItemModelTester(m_storyboardModel, 0); +} - delete model; +void StoryboardModelTest::testFrameRemoved() +{ + m_storyboardModel->removeRows(m_storyboardModel->rowCount(),1); + auto tester = new QAbstractItemModelTester(m_storyboardModel, 0); +} + +void StoryboardModelTest::testFrameChanged() +{ + QModelIndex index = m_commentModel->createIndex(m_storyboardModel->rowCount(),m_storyboardModel->columnCount()); + QVariant value = QVariant(100); + m_stroyboardModel->setData(index, value, StoryboardModel::FrameRole); + auto tester = new QAbstractItemModelTester(m_storyboardModel, 0); + //should we have multiple custom roles to differentiate between what data is coming in?? +} +void StoryboardModelTest::testDurationChanged() +{ + QModelIndex index = m_commentModel->createIndex(m_storyboardModel->rowCount(),m_storyboardModel->columnCount()); + QVariant value = QVariant(100); + m_stroyboardModel->setData(index, value, StoryboardModel::DurationRole); + auto tester = new QAbstractItemModelTester(m_storyboardModel, 0); +} + +void StoryboardModelTest::testCommentChanged() +{ + QModelIndex index = m_commentModel->createIndex(m_storyboardModel->rowCount(),m_storyboardModel->columnCount()); + QVariant value = QVariant(100); + m_stroyboardModel->setData(index, value, StoryboardModel::CommentRole); + auto tester = new QAbstractItemModelTester(m_storyboardModel, 0); + //should we store different comments in different columns?? } QTEST_MAIN(StoryboardModelTest) diff --git a/plugins/dockers/storyboarddocker/tests/storyboardModelTest.h b/plugins/dockers/storyboarddocker/tests/storyboardModelTest.h index 0eb4136da5..952bc683b7 100644 --- a/plugins/dockers/storyboarddocker/tests/storyboardModelTest.h +++ b/plugins/dockers/storyboarddocker/tests/storyboardModelTest.h @@ -1,32 +1,53 @@ /* * Copyright (c) 2020 Saurabh Kumar * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __STORYBOARD_MODEL_TEST_H #define __STORYBOARD_MODEL_TEST_H #include +class CommentModel; +class StoryboardModel; + class StoryboardModelTest : public QObject { Q_OBJECT private Q_SLOTS: - //list of test functions - void testModel(); + void init(); + void cleanup(); + + //interaction with comment model + void testAddComment() + void testRemoveComment(); + void testCommentNameChanged(); + void testCommentVisibilityChanged(); + + //"storyboard model only" tests + void testFrameAdded(); + void testFrameRemoved(); + void testFrameChanged(); + void testDurationChanged(); + void testCommentChanged(); + +private: + CommentModel *m_commentModel; + StoryboardModel *m_storyboardModel; + }; #endif /* __STORYBOARD_MODEL_TEST_H */