File indexing completed on 2024-05-12 05:40:47

0001 /***************************************************************************
0002  *  Copyright (C) 2020 by Renaud Guezennec                                 *
0003  *   http://www.rolisteam.org/contact                   *
0004  *                                                                         *
0005  *   rolisteam is free software; you can redistribute it and/or modify     *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #include "controller/view_controller/mediacontrollerbase.h"
0021 #include "controller/view_controller/vectorialmapcontroller.h"
0022 #include "model/contentmodel.h"
0023 #include <QAbstractItemModelTester>
0024 #include <QtTest/QtTest>
0025 #include <memory>
0026 
0027 class ContentModelTest : public QObject
0028 {
0029     Q_OBJECT
0030 public:
0031     ContentModelTest();
0032 
0033 private slots:
0034     void init();
0035 
0036     void testFilteredData();
0037 
0038 private:
0039     std::unique_ptr<ContentModel> m_model;
0040     std::unique_ptr<FilteredContentModel> m_filteredModel;
0041 };
0042 
0043 ContentModelTest::ContentModelTest() {}
0044 
0045 void ContentModelTest::init()
0046 {
0047     m_model.reset(new ContentModel());
0048     m_filteredModel.reset(new FilteredContentModel(Core::ContentType::VECTORIALMAP));
0049 
0050     new QAbstractItemModelTester(m_model.get());
0051 
0052     m_filteredModel->setSourceModel(m_model.get());
0053     new QAbstractItemModelTester(m_filteredModel.get());
0054 }
0055 
0056 void ContentModelTest::testFilteredData()
0057 {
0058     m_model->appendMedia(new VectorialMapController("mapid"));
0059 
0060     auto i= m_model->rowCount();
0061 
0062     QVERIFY(i == 1);
0063 
0064     auto ctrl= m_model->data(m_model->index(0, 0), ContentModel::ControllerRole).value<MediaControllerBase*>();
0065 
0066     QVERIFY(ctrl != nullptr);
0067 
0068     auto vmapCtrl= dynamic_cast<VectorialMapController*>(ctrl);
0069 
0070     QVERIFY(vmapCtrl != nullptr);
0071 
0072     auto j= m_filteredModel->rowCount();
0073 
0074     QVERIFY(j == 1);
0075 
0076     auto base= m_filteredModel->contentController<VectorialMapController*>();
0077 
0078     QVERIFY(base.size() == 1);
0079 
0080     auto first= base.at(0);
0081 
0082     QVERIFY(first != nullptr);
0083 }
0084 QTEST_MAIN(ContentModelTest);
0085 
0086 #include "tst_contentmodel.moc"