|
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 MpMediaWallDocumentLoader |
|
15 */ |
|
16 |
|
17 #include "unittest_mpglobalpopuphandler.h" |
|
18 #include "mpsongscanner.h" |
|
19 #include "mpengine.h" |
|
20 #include <hbpopup.h> |
|
21 #include <hbprogressdialog.h> |
|
22 #include <hbnotificationdialog.h> |
|
23 #include <hblabel.h> |
|
24 #include <QTranslator> |
|
25 #include <QLocale> |
|
26 |
|
27 /* |
|
28 * Following methods were skipped on purpose since theres nothing valuable to test |
|
29 * CloseUsbBlockingNote() |
|
30 * HanldeMTPInfoDialogFinished |
|
31 */ |
|
32 |
|
33 // Do this so we can access all member variables. |
|
34 #define private public |
|
35 #include "mpglobalpopuphandler.h" |
|
36 #undef private |
|
37 |
|
38 #include "../../../src/mpglobalpopuphandler.cpp" |
|
39 |
|
40 /*! |
|
41 Make our test case a stand-alone executable that runs all the test functions. |
|
42 */ |
|
43 int main(int argc, char *argv[]) |
|
44 { |
|
45 QApplication app(argc, argv); |
|
46 TestMpGlobalPopupHandler tv; |
|
47 |
|
48 if ( argc > 1 ) { |
|
49 return QTest::qExec( &tv, argc, argv); |
|
50 } |
|
51 else { |
|
52 char *pass[3]; |
|
53 pass[0] = argv[0]; |
|
54 pass[1] = "-o"; |
|
55 pass[2] = "c:\\data\\unittest_mpglobalpopuphandler.txt"; |
|
56 |
|
57 return QTest::qExec(&tv, 3, pass); |
|
58 } |
|
59 } |
|
60 |
|
61 TestMpGlobalPopupHandler::TestMpGlobalPopupHandler() |
|
62 : mTest(0), |
|
63 mMpTranslator(0) |
|
64 { |
|
65 } |
|
66 |
|
67 TestMpGlobalPopupHandler::~TestMpGlobalPopupHandler() |
|
68 { |
|
69 delete mTest; |
|
70 delete mMpTranslator; |
|
71 } |
|
72 |
|
73 /*! |
|
74 Called before the first testfunction is executed. |
|
75 */ |
|
76 void TestMpGlobalPopupHandler::initTestCase() |
|
77 { |
|
78 QString lang = QLocale::system().name(); |
|
79 QString path = QString("z:/resource/qt/translations/"); |
|
80 bool translatorLoaded = false; |
|
81 |
|
82 mMpTranslator = new QTranslator(this); |
|
83 translatorLoaded = mMpTranslator->load(path + "musicplayer_" + lang); |
|
84 if ( translatorLoaded ) { |
|
85 qApp->installTranslator(mMpTranslator); |
|
86 } |
|
87 } |
|
88 |
|
89 /*! |
|
90 Called after the last testfunction was executed. |
|
91 */ |
|
92 void TestMpGlobalPopupHandler::cleanupTestCase() |
|
93 { |
|
94 } |
|
95 |
|
96 /*! |
|
97 Called before each testfunction is executed. |
|
98 */ |
|
99 void TestMpGlobalPopupHandler::init() |
|
100 { |
|
101 mTest = new MpGlobalPopupHandler( new QObject() ); |
|
102 } |
|
103 |
|
104 /*! |
|
105 Called after every testfunction. |
|
106 */ |
|
107 void TestMpGlobalPopupHandler::cleanup() |
|
108 { |
|
109 delete mTest; |
|
110 mTest = 0; |
|
111 } |
|
112 |
|
113 /*! |
|
114 test handleLibraryAboutToUpdate |
|
115 */ |
|
116 void TestMpGlobalPopupHandler::testHandleLibraryAboutToUpdate() |
|
117 { |
|
118 mTest->mMpSongScanner = 0; |
|
119 mTest->mMpEngine->mSongScanner = new MpSongScanner(); |
|
120 |
|
121 mTest->handleLibraryAboutToUpdate(); |
|
122 QCOMPARE( mTest->mMpSongScanner, mTest->mMpEngine->mSongScanner ); |
|
123 } |
|
124 |
|
125 /*! |
|
126 test scanCountChanged |
|
127 */ |
|
128 void TestMpGlobalPopupHandler::testScanCountChanged() |
|
129 { |
|
130 HbProgressDialog* dialog = new HbProgressDialog( HbProgressDialog::WaitDialog ); |
|
131 dialog->setModal( true ); |
|
132 dialog->setText( QString("") ); |
|
133 dialog->setObjectName( KScanProgressDialog ); |
|
134 |
|
135 mTest->mOutstandingPopup = dialog; |
|
136 |
|
137 mTest->scanCountChanged( 2 ); |
|
138 HbProgressDialog *dialogNew = qobject_cast<HbProgressDialog *>( mTest->mOutstandingPopup ); |
|
139 QCOMPARE( dialogNew->text(), hbTrId( "txt_mus_info_ln_songs_found" , 2 )); |
|
140 |
|
141 } |
|
142 |
|
143 /*! |
|
144 test handleScanFinished |
|
145 */ |
|
146 void TestMpGlobalPopupHandler::testHandleScanFinished() |
|
147 { |
|
148 HbProgressDialog* dialog = new HbProgressDialog( HbProgressDialog::WaitDialog ); |
|
149 dialog->setModal( true ); |
|
150 HbLabel *title = new HbLabel( hbTrId( "testScanCountChanged" ) ); |
|
151 title->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
|
152 |
|
153 dialog->setHeadingWidget( title ); |
|
154 dialog->setText( QString("") ); |
|
155 dialog->setObjectName( KScanProgressDialog ); |
|
156 |
|
157 mTest->mOutstandingPopup = dialog; |
|
158 mTest->handleScanFinished( MpSongScanner::ScanErrorNone, 0 ); |
|
159 QVERIFY( mTest->mOutstandingPopup->objectName() == KScanFinished ); |
|
160 QVERIFY( qobject_cast<HbNotificationDialog *>( mTest->mOutstandingPopup )->title() == hbTrId( "txt_mus_dpophead_refresh_complete" ) ); |
|
161 |
|
162 mTest->mOutstandingPopup = dialog; |
|
163 mTest->handleScanFinished( MpSongScanner::ScanGeneralError, 0 ); |
|
164 QVERIFY( mTest->mOutstandingPopup->objectName() == KScanFinished ); |
|
165 QVERIFY( qobject_cast<HbNotificationDialog *>( mTest->mOutstandingPopup )->title() == hbTrId( "txt_mus_dpophead_refresh_cancelled" ) ); |
|
166 |
|
167 mTest->mOutstandingPopup = dialog; |
|
168 mTest->handleScanFinished( MpSongScanner::ScanErrorDiskFull, 0 ); |
|
169 QVERIFY( mTest->mOutstandingPopup->objectName() == KDiskFullDialog ); |
|
170 |
|
171 } |
|
172 |
|
173 /*! |
|
174 test launchUnableToCotinueDueUsb |
|
175 */ |
|
176 void TestMpGlobalPopupHandler::testLaunchUnableToCotinueDueUsb() |
|
177 { |
|
178 mTest->launchUnableToCotinueDueUsb(); |
|
179 QVERIFY( mTest->mOutstandingPopup->objectName() == KUnableToContinueDueUSB ); |
|
180 } |
|
181 |
|
182 /*! |
|
183 test launchUsbBlockingNote |
|
184 */ |
|
185 void TestMpGlobalPopupHandler::testLaunchUsbBlockingNote() |
|
186 { |
|
187 mTest->launchUsbBlockingNote(); |
|
188 QVERIFY( mTest->mOutstandingPopup->objectName() == KUsbBlockingNote ); |
|
189 } |
|
190 |
|
191 |
|
192 /*! |
|
193 test launchMTPInfoDialog |
|
194 */ |
|
195 void TestMpGlobalPopupHandler::testLaunchMTPInfoDialog() |
|
196 { |
|
197 mTest->launchMTPInfoDialog(); |
|
198 QVERIFY( mTest->mOutstandingPopup->objectName() == KMTPInfoDialog ); |
|
199 } |
|
200 |
|
201 |
|
202 /*! |
|
203 test outstandingPopupClosing |
|
204 */ |
|
205 void TestMpGlobalPopupHandler::testOutstandingPopupClosing() |
|
206 { |
|
207 HbPopup *dialog = new HbPopup(); |
|
208 connect( dialog, SIGNAL( aboutToClose() ), mTest, SLOT( outstandingPopupClosing() ) ); |
|
209 mTest->mOutstandingPopup = dialog; |
|
210 |
|
211 dialog->close(); |
|
212 delete dialog; |
|
213 QVERIFY( mTest->mOutstandingPopup == 0 ); |
|
214 } |
|
215 |
|
216 /*! |
|
217 test launchScanFinishedDialog |
|
218 */ |
|
219 void TestMpGlobalPopupHandler::testLaunchScanFinishedDialog() |
|
220 { |
|
221 mTest->launchScanFinishedDialog( true, 1 ); |
|
222 QVERIFY( mTest->mOutstandingPopup->objectName() == KScanFinished ); |
|
223 QVERIFY( qobject_cast<HbNotificationDialog *>( mTest->mOutstandingPopup )->title() == hbTrId( "txt_mus_dpophead_refresh_complete" ) ); |
|
224 |
|
225 mTest->launchScanFinishedDialog( false, 1 ); |
|
226 QVERIFY( mTest->mOutstandingPopup->objectName() == KScanFinished ); |
|
227 QVERIFY( qobject_cast<HbNotificationDialog *>( mTest->mOutstandingPopup )->title() == hbTrId( "txt_mus_dpophead_refresh_cancelled" ) ); |
|
228 } |
|
229 |
|
230 |
|
231 /*! |
|
232 test launchDiskFullDialog |
|
233 */ |
|
234 |
|
235 void TestMpGlobalPopupHandler::testLaunchDiskFullDialog() |
|
236 { |
|
237 mTest->launchDiskFullDialog(); |
|
238 QVERIFY( mTest->mOutstandingPopup->objectName() == KDiskFullDialog ); |
|
239 } |
|
240 |
|
241 /*! |
|
242 test setOutstandingPopup |
|
243 */ |
|
244 void TestMpGlobalPopupHandler::testSetOutstandingPopup() |
|
245 { |
|
246 HbPopup *dialog = new HbPopup(); |
|
247 mTest->mOutstandingPopup = 0; |
|
248 mTest->setOutstandingPopup( dialog ); |
|
249 QVERIFY( mTest->mOutstandingPopup == dialog ); |
|
250 } |
|
251 |
|
252 |
|
253 // End of file |