|
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 mpmediawallview. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <hbmainwindow.h> |
|
19 #include <hbapplication.h> |
|
20 #include <hbview.h> |
|
21 #include <QSignalSpy> |
|
22 |
|
23 #include "unittest_mpmediawallview.h" |
|
24 #include "stub/inc/mpplaybackdata.h" |
|
25 |
|
26 // Do this so we can access all member variables. |
|
27 #define private public |
|
28 #include "mpmediawallview.h" |
|
29 #undef private |
|
30 |
|
31 // Do this so we can access all memeber functions |
|
32 #include "../../src/mpmediawallview.cpp" |
|
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 HbApplication app(argc, argv); |
|
40 HbMainWindow window; |
|
41 |
|
42 TestMpMediaWallView tv; |
|
43 |
|
44 if ( argc > 1 ) { |
|
45 return QTest::qExec( &tv, argc, argv); |
|
46 } |
|
47 else { |
|
48 char *pass[3]; |
|
49 pass[0] = argv[0]; |
|
50 pass[1] = "-o"; |
|
51 pass[2] = "c:\\data\\unittest_mpmediawallview.txt"; |
|
52 |
|
53 return QTest::qExec(&tv, 3, pass); |
|
54 } |
|
55 } |
|
56 |
|
57 //Constructor |
|
58 TestMpMediaWallView::TestMpMediaWallView() |
|
59 : mTest(0) |
|
60 { |
|
61 |
|
62 } |
|
63 |
|
64 //Destructor |
|
65 TestMpMediaWallView::~TestMpMediaWallView() |
|
66 { |
|
67 delete mTest; |
|
68 } |
|
69 |
|
70 /*! |
|
71 Called before the first testfunction is executed. |
|
72 */ |
|
73 void TestMpMediaWallView::initTestCase() |
|
74 { |
|
75 |
|
76 } |
|
77 |
|
78 /*! |
|
79 Called after the last testfunction was executed. |
|
80 */ |
|
81 void TestMpMediaWallView::cleanupTestCase() |
|
82 { |
|
83 QCoreApplication::processEvents(); |
|
84 } |
|
85 |
|
86 /*! |
|
87 Called before each testfunction is executed. |
|
88 */ |
|
89 void TestMpMediaWallView::init() |
|
90 { |
|
91 mTest = new MpMediaWallView(); |
|
92 } |
|
93 |
|
94 /*! |
|
95 Called after every testfunction. |
|
96 */ |
|
97 void TestMpMediaWallView::cleanup() |
|
98 { |
|
99 delete mTest; |
|
100 mTest = 0; |
|
101 } |
|
102 |
|
103 /*! |
|
104 Test InitializeView |
|
105 */ |
|
106 void TestMpMediaWallView::testInitializeView() |
|
107 { |
|
108 |
|
109 QVERIFY(!mTest->mEngine); |
|
110 QVERIFY(!mTest->mCollectionData); |
|
111 QVERIFY(!mTest->mModel); |
|
112 QVERIFY(!mTest->mAlbumCover); |
|
113 QVERIFY(!mTest->mTrackList); |
|
114 QVERIFY(!mTest->mPlaybackData); |
|
115 QVERIFY(!mTest->mPauseIcon); |
|
116 QVERIFY(!mTest->mPlayIcon); |
|
117 QVERIFY(!mTest->mPlayPauseContainer); |
|
118 |
|
119 //test member variables are initialized |
|
120 mTest->initializeView(); |
|
121 QVERIFY(mTest->mEngine); |
|
122 QVERIFY(mTest->mCollectionData); |
|
123 QVERIFY(mTest->mModel); |
|
124 QVERIFY(mTest->mAlbumCover); |
|
125 QVERIFY(mTest->mTrackList); |
|
126 QVERIFY(mTest->mPlaybackData); |
|
127 QVERIFY(mTest->mPauseIcon); |
|
128 QVERIFY(mTest->mPlayIcon); |
|
129 QVERIFY(mTest->mPlayPauseContainer); |
|
130 |
|
131 } |
|
132 |
|
133 /*! |
|
134 Test ActivateView |
|
135 */ |
|
136 void TestMpMediaWallView::testActivateView() |
|
137 { |
|
138 |
|
139 //Create playbackdata and set to playing state |
|
140 mTest->mPlaybackData = new MpPlaybackData(); |
|
141 mTest->mPlaybackData->setPlaybackState(MpPlaybackData::Playing); |
|
142 |
|
143 mTest->mIconUpdateNedded=false; |
|
144 mTest->mActivated=false; |
|
145 |
|
146 mTest->activateView(); |
|
147 QCOMPARE(mTest->mActivated, true ); |
|
148 } |
|
149 |
|
150 /*! |
|
151 Test DeActivateView |
|
152 */ |
|
153 void TestMpMediaWallView::testDeactivateView() |
|
154 { |
|
155 mTest->initializeView(); |
|
156 mTest->mActivated = true; |
|
157 mTest->mShowingSongsList = true; |
|
158 mTest->setUpListAnimation(); |
|
159 mTest->deactivateView(); |
|
160 QCOMPARE(mTest->mActivated, false); |
|
161 QCOMPARE(mTest->mShowingSongsList, false); |
|
162 |
|
163 } |
|
164 |
|
165 /*! |
|
166 Test SendToBackground |
|
167 */ |
|
168 void TestMpMediaWallView::testSendToBackground() |
|
169 { |
|
170 //test that signal gets emitted |
|
171 QSignalSpy spy( mTest, SIGNAL(command(int)) ); |
|
172 mTest->sendToBackground(); |
|
173 QCOMPARE(spy.count(), 1); |
|
174 QCOMPARE(spy.at(0).at(0), QVariant(MpCommon::SendToBackground)); |
|
175 |
|
176 } |
|
177 |
|
178 /*! |
|
179 Test ContextOpened |
|
180 */ |
|
181 /* test case fails because potential problem in docml |
|
182 void TestMpMediaWallView::testContextOpened() |
|
183 { |
|
184 |
|
185 mTest->mCollectionData = new MpMpxCollectionData(); |
|
186 mTest->mDocumentLoader = new MpMediaWallDocumentLoader(); |
|
187 |
|
188 QVERIFY(mTest->mCollectionData->context() == QVariant(ECollectionContextUnknown)); |
|
189 mTest->contextOpened(ECollectionContextArtists); |
|
190 QVERIFY(mTest->mCollectionData->context() == QVariant(ECollectionContextAlbumsMediaWall)); |
|
191 |
|
192 //test loading 'empty' section, docml loading fails because initialize not called |
|
193 QVERIFY(!mTest->mNoMusic); |
|
194 mTest->contextOpened(ECollectionContextAlbumsMediaWall); |
|
195 QVERIFY(mTest->mNoMusic); |
|
196 } |
|
197 */ |
|
198 |
|
199 /*! |
|
200 Test ContextOpened |
|
201 */ |
|
202 void TestMpMediaWallView::testContextOpened() |
|
203 { |
|
204 //test loading 'empty' |
|
205 mTest->initializeView(); |
|
206 mTest->contextOpened(ECollectionContextAlbumsMediaWall); |
|
207 //test loading 'mediawall' |
|
208 mTest->mCollectionData->setCount(3); |
|
209 mTest->contextOpened(ECollectionContextAlbumsMediaWall); |
|
210 } |
|
211 |
|
212 /*! |
|
213 Test ContainerContentsChanged |
|
214 */ |
|
215 void TestMpMediaWallView::testContainerContentsChanged() |
|
216 { |
|
217 //test containerContetstsChanged calls opencallection when library not updating |
|
218 mTest->initializeView(); |
|
219 QVERIFY(mTest->mEngine->mOpenCollectionCalled == 1); |
|
220 mTest->containerContentsChanged(); |
|
221 QVERIFY(mTest->mEngine->mOpenCollectionCalled == 2); |
|
222 mTest->libraryAboutToUpdate(); |
|
223 mTest->containerContentsChanged(); |
|
224 QVERIFY(mTest->mEngine->mOpenCollectionCalled == 2); |
|
225 } |
|
226 |
|
227 /*! |
|
228 Test LibraryUpdated |
|
229 */ |
|
230 void TestMpMediaWallView::testLibraryUpdated() |
|
231 { |
|
232 //test libraryupdated changes flag and calls opencallection |
|
233 mTest->initializeView(); |
|
234 mTest->mEngine->mOpenCollectionCalled=0; |
|
235 mTest->mLibraryUpdating=true; |
|
236 mTest->libraryUpdated(); |
|
237 QVERIFY(mTest->mLibraryUpdating == false); |
|
238 QVERIFY(mTest->mEngine->mOpenCollectionCalled == 1); |
|
239 } |
|
240 |
|
241 /*! |
|
242 Test UpdatePlayPauseAction |
|
243 */ |
|
244 void TestMpMediaWallView::testUpdatePlayPauseAction() |
|
245 { |
|
246 //test icon gets updated correctly |
|
247 mTest->initializeView(); |
|
248 mTest->mActivated = true; |
|
249 |
|
250 mTest->mPlaybackData->setPlaybackState( MpPlaybackData::Paused ); |
|
251 mTest->updatePlayPauseAction(); |
|
252 HbIcon temp = mTest->mPlayPauseAction->icon(); |
|
253 QVERIFY( mTest->mPlayPauseAction->icon() == HbIcon( "qtg_mono_play" )); |
|
254 |
|
255 mTest->mPlaybackData->setPlaybackState( MpPlaybackData::Playing ); |
|
256 mTest->updatePlayPauseAction(); |
|
257 QVERIFY( mTest->mPlayPauseAction->icon() == HbIcon( "qtg_mono_pause" )); |
|
258 |
|
259 mTest->mPlaybackData->setPlaybackState( MpPlaybackData::Stopped ); |
|
260 mTest->updatePlayPauseAction(); |
|
261 QVERIFY( mTest->mPlayPauseAction->icon() == HbIcon( "qtg_mono_play" )); |
|
262 } |