diff --git a/autotests/playertest.cpp b/autotests/playertest.cpp index fb8e01e..d46e255 100644 --- a/autotests/playertest.cpp +++ b/autotests/playertest.cpp @@ -1,112 +1,112 @@ /* * Copyright 2013 Alex Merry * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name of the X Consortium shall not be * used in advertising or otherwise to promote the sale, use or other dealings * in this Software without prior written authorization from the X Consortium. */ #include "testplayer.h" #include #include class PlayerTest : public QObject { Q_OBJECT private Q_SLOTS: void init() { player = new TestPlayer(this); } void cleanup() { delete player; - player = 0; + player = nullptr; } void testParent(); void testDefaultState(); void testDefaultLooping(); void testSetState(); void testSetLooping(); private: TestPlayer *player; }; using namespace KMediaPlayer; void PlayerTest::testParent() { QCOMPARE(player->parent(), this); } void PlayerTest::testDefaultState() { QCOMPARE(player->state(), Player::Empty); } void PlayerTest::testDefaultLooping() { QCOMPARE(player->isLooping(), false); } void PlayerTest::testSetState() { QSignalSpy spy(player, SIGNAL(stateChanged(KMediaPlayer::Player::State))); player->setStateWrapper(Player::Play); QCOMPARE(spy.count(), 1); QList arguments = spy.takeFirst(); QCOMPARE(arguments.count(), 1); QCOMPARE(arguments.at(0).value(), Player::Play); QCOMPARE(player->state(), Player::Play); player->setStateWrapper(Player::Empty); QCOMPARE(spy.count(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.count(), 1); QCOMPARE(arguments.at(0).value(), Player::Empty); QCOMPARE(player->state(), Player::Empty); } void PlayerTest::testSetLooping() { QSignalSpy spy(player, SIGNAL(loopingChanged(bool))); player->setLooping(true); QCOMPARE(spy.count(), 1); QList arguments = spy.takeFirst(); QCOMPARE(arguments.count(), 1); QCOMPARE(arguments.at(0).toBool(), true); QCOMPARE(player->isLooping(), true); player->setLooping(false); QCOMPARE(spy.count(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.count(), 1); QCOMPARE(arguments.at(0).toBool(), false); QCOMPARE(player->isLooping(), false); } QTEST_GUILESS_MAIN(PlayerTest) #include "playertest.moc" #include "moc_testplayer.cpp" diff --git a/autotests/testplayer.h b/autotests/testplayer.h index dd5ca89..1443bd4 100644 --- a/autotests/testplayer.h +++ b/autotests/testplayer.h @@ -1,78 +1,78 @@ /* * Copyright 2013 Alex Merry * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name of the X Consortium shall not be * used in advertising or otherwise to promote the sale, use or other dealings * in this Software without prior written authorization from the X Consortium. */ #ifndef TESTPLAYER_H #define TESTPLAYER_H #include class TestPlayer : public KMediaPlayer::Player { Q_OBJECT public: TestPlayer(QObject *parent) : Player(parent) {} KMediaPlayer::View *view() Q_DECL_OVERRIDE { - return 0; + return nullptr; } void pause() Q_DECL_OVERRIDE { } void play() Q_DECL_OVERRIDE { } void stop() Q_DECL_OVERRIDE { } void seek(qlonglong) Q_DECL_OVERRIDE { } bool isSeekable() const Q_DECL_OVERRIDE { return false; } qlonglong position() const Q_DECL_OVERRIDE { return 0L; } bool hasLength() const Q_DECL_OVERRIDE { return false; } qlonglong length() const Q_DECL_OVERRIDE { return 0L; } void setStateWrapper(State state) { // this is protected setState(state); } }; #endif // TESTPLAYER_H diff --git a/autotests/viewtest.cpp b/autotests/viewtest.cpp index 8442eab..06192a7 100644 --- a/autotests/viewtest.cpp +++ b/autotests/viewtest.cpp @@ -1,135 +1,135 @@ /* * Copyright 2013 Alex Merry * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name of the X Consortium shall not be * used in advertising or otherwise to promote the sale, use or other dealings * in this Software without prior written authorization from the X Consortium. */ #include "testview.h" #include #include #include class ViewTest : public QWidget { Q_OBJECT private Q_SLOTS: void init() { view = new TestView(this); } void cleanup() { delete view; - view = 0; + view = nullptr; } void testParent(); void testDefaultVideoWidget(); void testSetVideoWidget(); void testSetButtons(); private: TestView *view; }; using namespace KMediaPlayer; void ViewTest::testParent() { QCOMPARE(view->parent(), this); } void ViewTest::testDefaultVideoWidget() { - QCOMPARE(view->videoWidget(), static_cast(0)); + QCOMPARE(view->videoWidget(), static_cast(nullptr)); } void ViewTest::testSetVideoWidget() { QScopedPointer widget(new QWidget(this)); view->setVideoWidgetWrapper(widget.data()); QCOMPARE(view->videoWidget(), widget.data()); - view->setVideoWidgetWrapper(0); - QCOMPARE(view->videoWidget(), static_cast(0)); + view->setVideoWidgetWrapper(nullptr); + QCOMPARE(view->videoWidget(), static_cast(nullptr)); } void ViewTest::testSetButtons() { QSignalSpy spy(view, SIGNAL(buttonsChanged(KMediaPlayer::View::Buttons))); View::Buttons expButtons = View::Stop | View::Pause; view->setButtons(expButtons); QCOMPARE(spy.count(), 1); QList arguments = spy.takeFirst(); QCOMPARE(arguments.count(), 1); QCOMPARE(arguments.at(0).value(), expButtons); QCOMPARE(view->buttons(), expButtons); expButtons |= View::Play; view->toggleButton(View::Play); QCOMPARE(spy.count(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.count(), 1); QCOMPARE(arguments.at(0).value(), expButtons); QCOMPARE(view->buttons(), expButtons); expButtons = View::Stop | View::Pause; view->toggleButton(View::Play); QCOMPARE(spy.count(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.count(), 1); QCOMPARE(arguments.at(0).value(), expButtons); QCOMPARE(view->buttons(), expButtons); expButtons = View::Stop; view->hideButton(View::Pause); QCOMPARE(spy.count(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.count(), 1); QCOMPARE(arguments.at(0).value(), expButtons); QCOMPARE(view->buttons(), expButtons); expButtons |= View::Seeker; view->showButton(View::Seeker); QCOMPARE(spy.count(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.count(), 1); QCOMPARE(arguments.at(0).value(), expButtons); QCOMPARE(view->buttons(), expButtons); // showing an already-visible button view->showButton(View::Stop); QCOMPARE(view->buttons(), expButtons); // hiding an already-hidden button view->hideButton(View::Play); QCOMPARE(view->buttons(), expButtons); } QTEST_MAIN(ViewTest) #include "viewtest.moc" #include "moc_testview.cpp" diff --git a/src/view.cpp b/src/view.cpp index fedf1d4..3dee643 100644 --- a/src/view.cpp +++ b/src/view.cpp @@ -1,103 +1,103 @@ // Copyright (C) 2002 Neil Stevens // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // Except as contained in this notice, the name(s) of the author(s) shall not be // used in advertising or otherwise to promote the sale, use or other dealings // in this Software without prior written authorization from the author(s). #include "view.h" class KMediaPlayer::View::Private { public: Private() - : videoWidget(0L) + : videoWidget(nullptr) , currentButtons(All) { if (!buttonEnumRegistered) { buttonEnumRegistered = qRegisterMetaType("KMediaPlayer::View::Button"); } if (!buttonsFlagsRegistered) { buttonsFlagsRegistered = qRegisterMetaType("KMediaPlayer::View::Buttons"); } } QWidget *videoWidget; Buttons currentButtons; static bool buttonEnumRegistered; static bool buttonsFlagsRegistered; }; bool KMediaPlayer::View::Private::buttonEnumRegistered = false; bool KMediaPlayer::View::Private::buttonsFlagsRegistered = false; KMediaPlayer::View::View(QWidget *parent) : QWidget(parent) , d(new Private()) { } KMediaPlayer::View::~View() { delete d; } KMediaPlayer::View::Buttons KMediaPlayer::View::buttons() { return d->currentButtons; } void KMediaPlayer::View::setButtons(Buttons buttons) { if (buttons != d->currentButtons) { d->currentButtons = buttons; emit buttonsChanged(buttons); } } bool KMediaPlayer::View::button(Button b) { return d->currentButtons & b; } void KMediaPlayer::View::showButton(Button b) { setButtons(d->currentButtons | b); } void KMediaPlayer::View::hideButton(Button b) { setButtons(d->currentButtons & ~b); } void KMediaPlayer::View::toggleButton(Button b) { setButtons(d->currentButtons ^ b); } void KMediaPlayer::View::setVideoWidget(QWidget *videoWidget) { d->videoWidget = videoWidget; } QWidget *KMediaPlayer::View::videoWidget() { return d->videoWidget; }