File indexing completed on 2024-04-14 14:26:29

0001 /*
0002  * Copyright 2013  Alex Merry <alex.merry@kdemail.net>
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a copy
0005  * of this software and associated documentation files (the "Software"), to deal
0006  * in the Software without restriction, including without limitation the rights
0007  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0008  * copies of the Software, and to permit persons to whom the Software is
0009  * furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
0017  * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
0018  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0019  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0020  *
0021  * Except as contained in this notice, the name of the X Consortium shall not be
0022  * used in advertising or otherwise to promote the sale, use or other dealings
0023  * in this Software without prior written authorization from the X Consortium.
0024  */
0025 
0026 #include "testview.h"
0027 #include <QSignalSpy>
0028 #include <QScopedPointer>
0029 #include <QTest>
0030 
0031 class ViewTest : public QWidget
0032 {
0033     Q_OBJECT
0034 
0035 private Q_SLOTS:
0036     void init()
0037     {
0038         view = new TestView(this);
0039     }
0040     void cleanup()
0041     {
0042         delete view;
0043         view = nullptr;
0044     }
0045 
0046     void testParent();
0047     void testDefaultVideoWidget();
0048     void testSetVideoWidget();
0049     void testSetButtons();
0050 
0051 private:
0052     TestView *view;
0053 };
0054 
0055 using namespace KMediaPlayer;
0056 
0057 void ViewTest::testParent()
0058 {
0059     QCOMPARE(view->parent(), this);
0060 }
0061 
0062 void ViewTest::testDefaultVideoWidget()
0063 {
0064     QCOMPARE(view->videoWidget(), static_cast<QWidget *>(nullptr));
0065 }
0066 
0067 void ViewTest::testSetVideoWidget()
0068 {
0069     QScopedPointer<QWidget> widget(new QWidget(this));
0070 
0071     view->setVideoWidgetWrapper(widget.data());
0072     QCOMPARE(view->videoWidget(), widget.data());
0073 
0074     view->setVideoWidgetWrapper(nullptr);
0075     QCOMPARE(view->videoWidget(), static_cast<QWidget *>(nullptr));
0076 }
0077 
0078 void ViewTest::testSetButtons()
0079 {
0080     QSignalSpy spy(view, SIGNAL(buttonsChanged(KMediaPlayer::View::Buttons)));
0081 
0082     View::Buttons expButtons = View::Stop | View::Pause;
0083     view->setButtons(expButtons);
0084     QCOMPARE(spy.count(), 1);
0085     QList<QVariant> arguments = spy.takeFirst();
0086     QCOMPARE(arguments.count(), 1);
0087     QCOMPARE(arguments.at(0).value<View::Buttons>(), expButtons);
0088     QCOMPARE(view->buttons(), expButtons);
0089 
0090     expButtons |= View::Play;
0091     view->toggleButton(View::Play);
0092     QCOMPARE(spy.count(), 1);
0093     arguments = spy.takeFirst();
0094     QCOMPARE(arguments.count(), 1);
0095     QCOMPARE(arguments.at(0).value<View::Buttons>(), expButtons);
0096     QCOMPARE(view->buttons(), expButtons);
0097 
0098     expButtons = View::Stop | View::Pause;
0099     view->toggleButton(View::Play);
0100     QCOMPARE(spy.count(), 1);
0101     arguments = spy.takeFirst();
0102     QCOMPARE(arguments.count(), 1);
0103     QCOMPARE(arguments.at(0).value<View::Buttons>(), expButtons);
0104     QCOMPARE(view->buttons(), expButtons);
0105 
0106     expButtons = View::Stop;
0107     view->hideButton(View::Pause);
0108     QCOMPARE(spy.count(), 1);
0109     arguments = spy.takeFirst();
0110     QCOMPARE(arguments.count(), 1);
0111     QCOMPARE(arguments.at(0).value<View::Buttons>(), expButtons);
0112     QCOMPARE(view->buttons(), expButtons);
0113 
0114     expButtons |= View::Seeker;
0115     view->showButton(View::Seeker);
0116     QCOMPARE(spy.count(), 1);
0117     arguments = spy.takeFirst();
0118     QCOMPARE(arguments.count(), 1);
0119     QCOMPARE(arguments.at(0).value<View::Buttons>(), expButtons);
0120     QCOMPARE(view->buttons(), expButtons);
0121 
0122     // showing an already-visible button
0123     view->showButton(View::Stop);
0124     QCOMPARE(view->buttons(), expButtons);
0125 
0126     // hiding an already-hidden button
0127     view->hideButton(View::Play);
0128     QCOMPARE(view->buttons(), expButtons);
0129 }
0130 
0131 QTEST_MAIN(ViewTest)
0132 
0133 #include "viewtest.moc"
0134 #include "moc_testview.cpp"
0135