|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Unit test for MpPlaybackWidget |
|
15 * |
|
16 */ |
|
17 #include <QSignalSpy> |
|
18 #include <QTime> |
|
19 #include "unittest_mpplaybackwidget.h" |
|
20 #include "mpplaybackdata.h" |
|
21 #include "mpalbumcoverwidget.h" |
|
22 #include <hblabel.h> |
|
23 #include <hbprogressslider.h> |
|
24 |
|
25 /* |
|
26 * formatDuration() cannot be tested as it is private slot |
|
27 */ |
|
28 |
|
29 // Do this so we can access all member variables. |
|
30 #define private public |
|
31 #include "mpplaybackwidget.h" |
|
32 #undef private |
|
33 |
|
34 /*! |
|
35 Make our test case a stand-alone executable that runs all the test functions. |
|
36 */ |
|
37 int main(int argc, char *argv[]) |
|
38 { |
|
39 QApplication app(argc, argv); |
|
40 TestMpPlaybackWidget tv; |
|
41 |
|
42 if ( argc > 1 ) { |
|
43 return QTest::qExec( &tv, argc, argv); |
|
44 } |
|
45 else { |
|
46 char *pass[3]; |
|
47 pass[0] = argv[0]; |
|
48 pass[1] = "-o"; |
|
49 pass[2] = "c:\\data\\unittest_mpplaybackwidget.txt"; |
|
50 |
|
51 return QTest::qExec(&tv, 3, pass); |
|
52 } |
|
53 } |
|
54 |
|
55 TestMpPlaybackWidget::TestMpPlaybackWidget() |
|
56 : mTest(0) |
|
57 { |
|
58 } |
|
59 |
|
60 TestMpPlaybackWidget::~TestMpPlaybackWidget() |
|
61 { |
|
62 delete mTest; |
|
63 } |
|
64 |
|
65 /*! |
|
66 Called before the first testfunction is executed. |
|
67 */ |
|
68 void TestMpPlaybackWidget::initTestCase() |
|
69 { |
|
70 } |
|
71 |
|
72 /*! |
|
73 Called after the last testfunction was executed. |
|
74 */ |
|
75 void TestMpPlaybackWidget::cleanupTestCase() |
|
76 { |
|
77 } |
|
78 |
|
79 /*! |
|
80 Called before each testfunction is executed. |
|
81 */ |
|
82 void TestMpPlaybackWidget::init() |
|
83 { |
|
84 mTest = new MpPlaybackWidget( new MpPlaybackData() ); |
|
85 } |
|
86 |
|
87 /*! |
|
88 Called after every testfunction. |
|
89 */ |
|
90 void TestMpPlaybackWidget::cleanup() |
|
91 { |
|
92 delete mTest; |
|
93 mTest = 0; |
|
94 } |
|
95 |
|
96 /*! |
|
97 test repeatChanged |
|
98 */ |
|
99 void TestMpPlaybackWidget::testRepeatChanged() |
|
100 { |
|
101 mTest->repeatChanged( true ); |
|
102 QVERIFY( mTest->mRepeatIndicator->isVisible() == true ); |
|
103 |
|
104 mTest->repeatChanged( false ); |
|
105 QVERIFY( mTest->mRepeatIndicator->isVisible() == false ); |
|
106 } |
|
107 |
|
108 /*! |
|
109 test playbackInfoChanged |
|
110 */ |
|
111 void TestMpPlaybackWidget::testPlaybackInfoChanged() |
|
112 { |
|
113 QSignalSpy spy( mTest, SIGNAL( signalPlaybackInfoChanged() ) ); |
|
114 mTest->playbackInfoChanged(); |
|
115 |
|
116 QVERIFY( mTest->mSongTitle->plainText() == "title" ); |
|
117 QVERIFY( mTest->mArtistName->plainText() == "artist" ); |
|
118 QVERIFY( mTest->mAlbumName->plainText() == "album" ); |
|
119 QVERIFY( mTest->mRealAudioIndicator->isVisible() == false ); |
|
120 QVERIFY( spy.count() == 1 ); |
|
121 spy.clear(); |
|
122 } |
|
123 |
|
124 /*! |
|
125 test durationChanged |
|
126 */ |
|
127 void TestMpPlaybackWidget::testDurationChanged() |
|
128 { |
|
129 mTest->durationChanged(); |
|
130 |
|
131 QVERIFY( mTest->mProgressBar->maximum() == 20 ); |
|
132 QVERIFY( mTest->mProgressBar->progressValue() == 0 ); |
|
133 QVERIFY( mTest->mProgressBar->sliderValue() == 0 ); |
|
134 QVERIFY( mTest->mProgressBar->isEnabled() == true ); |
|
135 } |
|
136 |
|
137 /*! |
|
138 test positionChanged |
|
139 */ |
|
140 void TestMpPlaybackWidget::testPositionChanged() |
|
141 { |
|
142 mTest->positionChanged(); |
|
143 mTest->mProgreesBarDragging = false; |
|
144 |
|
145 QVERIFY( mTest->mProgressBar->progressValue() == 10 ); |
|
146 QVERIFY( mTest->mProgressBar->sliderValue() == 10 ); |
|
147 // formatDuration is tested seperately |
|
148 } |
|
149 |
|
150 /*! |
|
151 test albumArtChanged |
|
152 */ |
|
153 void TestMpPlaybackWidget::testAlbumArtChanged() |
|
154 { |
|
155 mTest->albumArtChanged(); |
|
156 |
|
157 QVERIFY( mTest->mAlbumArt->mIcon == mTest->mPlaybackData->mAlbumArt ); |
|
158 QVERIFY( mTest->mAlbumArt->isEnabled() == true ); |
|
159 } |
|
160 |
|
161 |
|
162 // End of file |