Warning, file /rolisteam/rolisteam/src/tests/auto/controller/tst_imagecontrollertest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 <QtTest/QtTest>
0021 
0022 #include <QSignalSpy>
0023 #include <QUrl>
0024 
0025 #include "controller/view_controller/imagecontroller.h"
0026 #include <memory>
0027 
0028 class ImageControllorTest : public QObject
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     ImageControllorTest();
0034 
0035 private slots:
0036     void init();
0037     void cleanupTestCase();
0038 
0039     void formatTest();
0040     void formatTest_data();
0041 
0042     void zoomTest();
0043 
0044     void proprietyTest();
0045 
0046     void movieTest();
0047 
0048 private:
0049     std::unique_ptr<ImageController> m_ctrl;
0050 };
0051 
0052 ImageControllorTest::ImageControllorTest() {}
0053 
0054 void ImageControllorTest::init()
0055 {
0056     m_ctrl.reset(new ImageController());
0057 }
0058 
0059 void ImageControllorTest::cleanupTestCase() {}
0060 
0061 void ImageControllorTest::proprietyTest()
0062 {
0063     m_ctrl.reset(new ImageController("", "", QUrl("qrc://img/girafe.jpg"), ""));
0064 
0065     m_ctrl->setFitWindow(true);
0066 
0067     QSignalSpy spy1(m_ctrl.get(), &ImageController::fitWindowChanged);
0068     QSignalSpy spy2(m_ctrl.get(), &ImageController::cursorChanged);
0069 
0070     m_ctrl->setFitWindow(false);
0071 
0072     QCOMPARE(spy1.count(), 1);
0073     QCOMPARE(spy2.count(), 1);
0074     QCOMPARE(m_ctrl->cursor(), Qt::OpenHandCursor);
0075     QCOMPARE(m_ctrl->fitWindow(), false);
0076 }
0077 
0078 void ImageControllorTest::formatTest()
0079 {
0080     QFETCH(QString, path);
0081     QFETCH(qreal, ratioV);
0082     QFETCH(qreal, ratioH);
0083     QFETCH(bool, isMovie);
0084 
0085     m_ctrl.reset(new ImageController("", "", path));
0086 
0087     QSignalSpy spy1(m_ctrl.get(), &ImageController::pixmapChanged);
0088     spy1.wait(1000);
0089 
0090     QCOMPARE(m_ctrl->ratioH(), ratioH);
0091 
0092     QCOMPARE(m_ctrl->ratioV(), ratioV);
0093 
0094     QCOMPARE(m_ctrl->isMovie(), isMovie);
0095 }
0096 
0097 void ImageControllorTest::formatTest_data()
0098 {
0099     QTest::addColumn<QString>("path");
0100     QTest::addColumn<qreal>("ratioV");
0101     QTest::addColumn<qreal>("ratioH");
0102     QTest::addColumn<bool>("isMovie");
0103     // QTest::addColumn<bool>("fitWindow");
0104 
0105     QTest::addRow("value 1") << "qrc://img/girafe.jpg" << 1000.0 / 750 << 0.75 << false;
0106     QTest::addRow("value 2") << "qrc://img/girafe3.jpg" << 3264.0 / 2448 << 2448.0 / 3264 << false;
0107     QTest::addRow("value 3") << "qrc://img/lion.jpg" << 1000.0 / 750 << 0.75 << false;
0108     QTest::addRow("value 4") << "qrc://img/lion3.jpg" << 3264.0 / 2448 << 2448.0 / 3264 << false;
0109     QTest::addRow("value 5") << "qrc://img/white.png" << 1126.0 / 271 << 271.0 / 1126 << false;
0110     QTest::addRow("value 6") << "qrc://img/control_life_bar.gif" << 1784.0 / 828 << 828.0 / 1784 << true;
0111 }
0112 
0113 void ImageControllorTest::zoomTest()
0114 {
0115     m_ctrl.reset(new ImageController("", "", QUrl(":/img/girafe.jpg"), ""));
0116 
0117     m_ctrl->setZoomLevel(1.0); // set default value
0118 
0119     QSignalSpy spy1(m_ctrl.get(), &ImageController::zoomLevelChanged);
0120 
0121     m_ctrl->zoomIn();
0122 
0123     QCOMPARE(m_ctrl->zoomLevel(), 1.2);
0124     QCOMPARE(spy1.count(), 1);
0125 
0126     m_ctrl->zoomOut();
0127 
0128     QCOMPARE(m_ctrl->zoomLevel(), 1.0);
0129     QCOMPARE(spy1.count(), 2);
0130 
0131     m_ctrl->zoomIn(0.4);
0132 
0133     QCOMPARE(m_ctrl->zoomLevel(), 1.4);
0134     QCOMPARE(spy1.count(), 3);
0135 
0136     m_ctrl->zoomOut(0.4);
0137 
0138     QCOMPARE(m_ctrl->zoomLevel(), 1.0);
0139     QCOMPARE(spy1.count(), 4);
0140 
0141     m_ctrl->setZoomLevel(2.4);
0142 
0143     QCOMPARE(m_ctrl->zoomLevel(), 2.4);
0144     QCOMPARE(spy1.count(), 5);
0145 
0146     m_ctrl->setZoomLevel(0.5);
0147 
0148     QCOMPARE(m_ctrl->zoomLevel(), 0.5);
0149     QCOMPARE(spy1.count(), 6);
0150 }
0151 
0152 void ImageControllorTest::movieTest()
0153 {
0154     m_ctrl.reset(new ImageController("", "", QUrl("qrc://img/control_life_bar.gif")));
0155 
0156     QVERIFY2(m_ctrl->isMovie(), "Not a movie!!");
0157     QCOMPARE(m_ctrl->status(), ImageController::Playing);
0158 
0159     QSignalSpy spy1(m_ctrl.get(), &ImageController::statusChanged);
0160 
0161     m_ctrl->play(); // play pause are the same
0162 
0163     QCOMPARE(spy1.count(), 1);
0164     QCOMPARE(m_ctrl->status(), ImageController::Paused);
0165 
0166     m_ctrl->play(); // play pause are the same
0167 
0168     QCOMPARE(spy1.count(), 2);
0169     QCOMPARE(m_ctrl->status(), ImageController::Playing);
0170 
0171     m_ctrl->stop();
0172 
0173     QCOMPARE(spy1.count(), 3);
0174     QCOMPARE(m_ctrl->status(), ImageController::Stopped);
0175 }
0176 
0177 QTEST_MAIN(ImageControllorTest);
0178 
0179 #include "tst_imagecontrollertest.moc"