File indexing completed on 2024-04-21 15:02:15
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 "testplayer.h" 0027 #include <QSignalSpy> 0028 #include <QTest> 0029 0030 class PlayerTest : public QObject 0031 { 0032 Q_OBJECT 0033 0034 private Q_SLOTS: 0035 void init() 0036 { 0037 player = new TestPlayer(this); 0038 } 0039 void cleanup() 0040 { 0041 delete player; 0042 player = nullptr; 0043 } 0044 0045 void testParent(); 0046 void testDefaultState(); 0047 void testDefaultLooping(); 0048 void testSetState(); 0049 void testSetLooping(); 0050 0051 private: 0052 TestPlayer *player; 0053 }; 0054 0055 using namespace KMediaPlayer; 0056 0057 void PlayerTest::testParent() 0058 { 0059 QCOMPARE(player->parent(), this); 0060 } 0061 0062 void PlayerTest::testDefaultState() 0063 { 0064 QCOMPARE(player->state(), Player::Empty); 0065 } 0066 0067 void PlayerTest::testDefaultLooping() 0068 { 0069 QCOMPARE(player->isLooping(), false); 0070 } 0071 0072 void PlayerTest::testSetState() 0073 { 0074 QSignalSpy spy(player, SIGNAL(stateChanged(KMediaPlayer::Player::State))); 0075 player->setStateWrapper(Player::Play); 0076 QCOMPARE(spy.count(), 1); 0077 QList<QVariant> arguments = spy.takeFirst(); 0078 QCOMPARE(arguments.count(), 1); 0079 QCOMPARE(arguments.at(0).value<Player::State>(), Player::Play); 0080 QCOMPARE(player->state(), Player::Play); 0081 0082 player->setStateWrapper(Player::Empty); 0083 QCOMPARE(spy.count(), 1); 0084 arguments = spy.takeFirst(); 0085 QCOMPARE(arguments.count(), 1); 0086 QCOMPARE(arguments.at(0).value<Player::State>(), Player::Empty); 0087 QCOMPARE(player->state(), Player::Empty); 0088 } 0089 0090 void PlayerTest::testSetLooping() 0091 { 0092 QSignalSpy spy(player, SIGNAL(loopingChanged(bool))); 0093 player->setLooping(true); 0094 QCOMPARE(spy.count(), 1); 0095 QList<QVariant> arguments = spy.takeFirst(); 0096 QCOMPARE(arguments.count(), 1); 0097 QCOMPARE(arguments.at(0).toBool(), true); 0098 QCOMPARE(player->isLooping(), true); 0099 0100 player->setLooping(false); 0101 QCOMPARE(spy.count(), 1); 0102 arguments = spy.takeFirst(); 0103 QCOMPARE(arguments.count(), 1); 0104 QCOMPARE(arguments.at(0).toBool(), false); 0105 QCOMPARE(player->isLooping(), false); 0106 } 0107 0108 QTEST_GUILESS_MAIN(PlayerTest) 0109 0110 #include "playertest.moc" 0111 #include "moc_testplayer.cpp" 0112