File indexing completed on 2024-05-19 05:41:29

0001 /***************************************************************************
0002  *   Copyright (C) 2011 by Renaud Guezennec                                *
0003  *   http://renaudguezennec.homelinux.org/accueil,3.html                   *
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 <QObject>
0021 #include <QtCore/QString>
0022 #include <QtTest/QtTest>
0023 #include <chrono>
0024 #include <data/resourcesnode.h>
0025 
0026 #define COUNT_TURN 2000
0027 /*class TestChapter : public QObject
0028 {
0029 
0030 
0031 public:
0032     TestChapter(QObject* parent= nullptr);
0033 
0034 private Q_SLOTS:
0035 
0036     void initTestCase();
0037 
0038 
0039     void cleanupTestCase();
0040 
0041     void testAddChapterHasChildren();
0042 
0043 
0044     void testSetGetName();
0045 
0046 
0047     void testAddCleverURIToChapter();
0048     void testInsertAtAndIndexOf();
0049     void testClear();
0050 
0051 private:
0052     //Chapter* m_chapter;
0053 };
0054 
0055 TestChapter::TestChapter(QObject* parent) : QObject(parent) {}
0056 
0057 void TestChapter::initTestCase()
0058 {
0059     m_chapter= new Chapter();
0060 }
0061 
0062 void TestChapter::cleanupTestCase()
0063 {
0064     delete m_chapter;
0065 }
0066 void TestChapter::testAddChapterHasChildren()
0067 {
0068     for(int i= 0; i < COUNT_TURN; i++)
0069     {
0070         QString temp("Chapiter %1");
0071         temp= temp.arg(i);
0072         auto child= new Chapter();
0073         child->setName(temp);
0074         m_chapter->addResource(child);
0075     }
0076     QVERIFY2(m_chapter->hasChildren(), "No Children");
0077     QVERIFY2(m_chapter->childrenCount() == COUNT_TURN, "Not the expect children count");
0078 }
0079 void TestChapter::testSetGetName()
0080 {
0081     for(int i= 0; i < COUNT_TURN; i++)
0082     {
0083         QString temp("Chapiter %1");
0084         temp= temp.arg(i);
0085         m_chapter->setName(temp);
0086         QVERIFY2(m_chapter->name() == temp, "Name is not as expected!");
0087     }
0088 }
0089 void TestChapter::testAddCleverURIToChapter()
0090 {
0091     for(int i= 0; i < COUNT_TURN; i++)
0092     {
0093         CleverURI* temp= new CleverURI(Core::ContentType::CHARACTERSHEET);
0094         temp->setContentType(Core::ContentType::CHARACTERSHEET);
0095         QString str("/foo");
0096         temp->setPath(str);
0097         m_chapter->addResource(temp);
0098         QVERIFY2(m_chapter->removeChild(temp), "Removal of CleverURI fails, the item was not in the list");
0099     }
0100     for(int i= 0; i < COUNT_TURN; i++)
0101     {
0102         CleverURI* tempURI= new CleverURI(Core::ContentType::CHARACTERSHEET);
0103         tempURI->setContentType(Core::ContentType::CHARACTERSHEET);
0104         QString str("/foo");
0105         tempURI->setPath(str);
0106         m_chapter->addResource(tempURI);
0107         QVERIFY2(m_chapter->removeChild(tempURI), "Removal of subchapter fails, the item was not in the list");
0108     }
0109 }
0110 
0111 void TestChapter::testInsertAtAndIndexOf()
0112 {
0113     auto seed= std::chrono::high_resolution_clock::now().time_since_epoch().count();
0114     auto rng= std::mt19937(quintptr(this) + seed);
0115     for(int i= 0; i < COUNT_TURN; i++)
0116     {
0117         CleverURI* temp= new CleverURI(Core::ContentType::CHARACTERSHEET);
0118         std::uniform_int_distribution<int> dist(0, m_chapter->childrenCount());
0119         int j= dist(rng);
0120         m_chapter->insertChildAt(j, temp);
0121         QCOMPARE(m_chapter->indexOf(temp), j);
0122     }
0123 }
0124 
0125 void TestChapter::testClear()
0126 {
0127     m_chapter->clear();
0128     QVERIFY2(!m_chapter->hasChildren(), "all Children have not been removed");
0129 }*/
0130 
0131 // QTEST_MAIN(TestChapter);
0132 
0133 //#include "testChapter.moc"