35
|
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 mpcollectiontbonelistdatamodel
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QAbstractItemModel>
|
|
19 |
#include <QSignalSpy>
|
|
20 |
#include <QMetaType>
|
|
21 |
#include <QTranslator>
|
|
22 |
#include <QLocale>
|
|
23 |
|
|
24 |
#include <hbicon.h>
|
|
25 |
#include <hbnamespace.h>
|
|
26 |
|
|
27 |
#include "unittest_mpcollectiontbonelistdatamodel.h"
|
|
28 |
#include "unittest_helper.h"
|
|
29 |
#include "stub/inc/mpmpxcollectiondata.h"
|
55
|
30 |
#include "stub/inc/mpplaybackdata.h"
|
35
|
31 |
|
|
32 |
// Do this so we can access all member variables.
|
|
33 |
#define private public
|
|
34 |
#include "mpcollectiontbonelistdatamodel.h"
|
|
35 |
#undef private
|
|
36 |
|
|
37 |
/*!
|
|
38 |
Make our test case a stand-alone executable that runs all the test functions.
|
|
39 |
*/
|
|
40 |
int main(int argc, char *argv[])
|
|
41 |
{
|
|
42 |
QApplication app(argc, argv);
|
|
43 |
TestMpCollectionTBoneListDataModel tv;
|
|
44 |
|
|
45 |
if ( argc > 1 ) {
|
|
46 |
return QTest::qExec( &tv, argc, argv);
|
|
47 |
}
|
|
48 |
else {
|
|
49 |
char *pass[3];
|
|
50 |
pass[0] = argv[0];
|
|
51 |
pass[1] = "-o";
|
|
52 |
pass[2] = "c:\\data\\unittest_mpcollectiontbonelistdatamodel.txt";
|
|
53 |
|
|
54 |
return QTest::qExec(&tv, 3, pass);
|
|
55 |
}
|
|
56 |
}
|
|
57 |
|
|
58 |
TestMpCollectionTBoneListDataModel::TestMpCollectionTBoneListDataModel()
|
|
59 |
: mTest(0),
|
|
60 |
mHelper(0),
|
|
61 |
mStubData(0),
|
55
|
62 |
mStubPlaybackData(0),
|
35
|
63 |
mMpTranslator(0)
|
|
64 |
{
|
|
65 |
}
|
|
66 |
|
|
67 |
TestMpCollectionTBoneListDataModel::~TestMpCollectionTBoneListDataModel()
|
|
68 |
{
|
|
69 |
delete mTest;
|
|
70 |
delete mHelper;
|
|
71 |
delete mStubData;
|
55
|
72 |
delete mStubPlaybackData;
|
35
|
73 |
delete mMpTranslator;
|
|
74 |
}
|
|
75 |
|
|
76 |
/*!
|
|
77 |
Called before the first testfunction is executed.
|
|
78 |
*/
|
|
79 |
void TestMpCollectionTBoneListDataModel::initTestCase()
|
|
80 |
{
|
|
81 |
QString lang = QLocale::system().name();
|
|
82 |
QString path = QString("z:/resource/qt/translations/");
|
|
83 |
bool translatorLoaded = false;
|
|
84 |
|
|
85 |
mMpTranslator = new QTranslator(this);
|
|
86 |
translatorLoaded = mMpTranslator->load(path + "musicplayer_" + lang);
|
|
87 |
if ( translatorLoaded ) {
|
|
88 |
qApp->installTranslator(mMpTranslator);
|
|
89 |
}
|
|
90 |
|
|
91 |
mStubData = new MpMpxCollectionData();
|
55
|
92 |
mStubPlaybackData = new MpPlaybackData();
|
35
|
93 |
mHelper = new TestHelper();
|
|
94 |
}
|
|
95 |
|
|
96 |
/*!
|
|
97 |
Called after the last testfunction was executed.
|
|
98 |
*/
|
|
99 |
void TestMpCollectionTBoneListDataModel::cleanupTestCase()
|
|
100 |
{
|
|
101 |
delete mStubData;
|
|
102 |
mStubData = 0;
|
55
|
103 |
delete mStubPlaybackData;
|
|
104 |
mStubPlaybackData = 0;
|
35
|
105 |
delete mHelper;
|
|
106 |
mHelper = 0;
|
|
107 |
}
|
|
108 |
|
|
109 |
/*!
|
|
110 |
Called before each testfunction is executed.
|
|
111 |
*/
|
|
112 |
void TestMpCollectionTBoneListDataModel::init()
|
|
113 |
{
|
55
|
114 |
mTest = new MpCollectionTBoneListDataModel(mStubData, mStubPlaybackData);
|
35
|
115 |
mTest->mCollectionData->mItemDataReturn = true;
|
|
116 |
}
|
|
117 |
|
|
118 |
/*!
|
|
119 |
Called after every testfunction.
|
|
120 |
*/
|
|
121 |
void TestMpCollectionTBoneListDataModel::cleanup()
|
|
122 |
{
|
|
123 |
delete mTest;
|
|
124 |
mTest = 0;
|
|
125 |
}
|
|
126 |
|
|
127 |
/*!
|
|
128 |
Tests correct cleanup of member variables.
|
|
129 |
*/
|
|
130 |
void TestMpCollectionTBoneListDataModel::testMemberCleanup()
|
|
131 |
{
|
|
132 |
cleanup();
|
|
133 |
int count = MpMpxCollectionData::getInitCounter();
|
|
134 |
init();
|
|
135 |
cleanup();
|
|
136 |
QCOMPARE(MpMpxCollectionData::getInitCounter(), count);
|
|
137 |
}
|
|
138 |
|
|
139 |
/*!
|
|
140 |
Tests refreshModel() request.
|
|
141 |
*/
|
|
142 |
void TestMpCollectionTBoneListDataModel::testRefreshModel()
|
|
143 |
{
|
|
144 |
mTest->mCollectionData->mAlbumSongCount = 10;
|
|
145 |
mTest->refreshModel();
|
|
146 |
QModelIndex modelIndex = mHelper->indexFor(1);
|
|
147 |
// Verify that:
|
|
148 |
// - It sets correct row count
|
|
149 |
QCOMPARE(mTest->rowCount(modelIndex), 10);
|
|
150 |
}
|
|
151 |
|
|
152 |
/*!
|
|
153 |
Tests data() request.
|
|
154 |
*/
|
|
155 |
void TestMpCollectionTBoneListDataModel::testData()
|
|
156 |
{
|
|
157 |
QModelIndex modelIndex = mHelper->indexFor(1);
|
|
158 |
|
|
159 |
// Qt::DisplayRole
|
|
160 |
QVariant data = mTest->data(modelIndex, Qt::DisplayRole);
|
|
161 |
QCOMPARE(data.canConvert(QVariant::StringList), true);
|
|
162 |
QStringList dataList = data.toStringList();
|
|
163 |
QCOMPARE(dataList.count(), 1);
|
|
164 |
QCOMPARE(dataList.at(0), QString("Title1"));
|
|
165 |
}
|
|
166 |
|
|
167 |
/*!
|
|
168 |
Tests data() request with no data available.
|
|
169 |
*/
|
|
170 |
void TestMpCollectionTBoneListDataModel::testDataNoData()
|
|
171 |
{
|
|
172 |
mTest->mCollectionData->mItemDataReturn = false;
|
|
173 |
|
|
174 |
QModelIndex modelIndex = mHelper->indexFor(1);
|
|
175 |
|
|
176 |
// Qt::DisplayRole
|
|
177 |
QVariant data = mTest->data(modelIndex, Qt::DisplayRole);
|
|
178 |
QCOMPARE(data.canConvert(QVariant::StringList), true);
|
|
179 |
QStringList dataList = data.toStringList();
|
|
180 |
QCOMPARE(dataList.count(), 1);
|
|
181 |
QCOMPARE(dataList.at(0), hbTrId("txt_mus_other_unknown4"));
|
|
182 |
}
|
|
183 |
|
|
184 |
/*!
|
|
185 |
Tests data() request for a role it doesn't support.
|
|
186 |
Make sure it doesn't crash.
|
|
187 |
*/
|
|
188 |
void TestMpCollectionTBoneListDataModel::testDataAnyOtherRole()
|
|
189 |
{
|
|
190 |
QModelIndex modelIndex = mHelper->indexFor(1);
|
|
191 |
|
|
192 |
// Qt::DecorationRole
|
|
193 |
QVariant data = mTest->data(modelIndex, Qt::DecorationRole);
|
|
194 |
QCOMPARE(data.isValid(), false);
|
|
195 |
}
|
|
196 |
|
55
|
197 |
/*!
|
|
198 |
Tests fileCorrupted()
|
|
199 |
*/
|
|
200 |
void TestMpCollectionTBoneListDataModel::testFileCorrupted()
|
|
201 |
{
|
|
202 |
QSignalSpy spy(mTest, SIGNAL(dataChanged( QModelIndex, QModelIndex )));
|
|
203 |
mTest->mRowCount = 4;
|
|
204 |
mTest->fileCorrupted(2);
|
|
205 |
QCOMPARE(mStubData->mHasAlbumSongProperty, true);
|
|
206 |
mTest->fileCorrupted(0);
|
|
207 |
QCOMPARE(mStubData->mReloadAlbumContent, true);
|
|
208 |
mTest->fileCorrupted(1);
|
|
209 |
QCOMPARE(mStubData->mCorruptedIndex.value(0), 1);
|
|
210 |
QCOMPARE(spy.count(), 1);
|
|
211 |
|
|
212 |
}
|
|
213 |
|
|
214 |
void TestMpCollectionTBoneListDataModel::testEnablePlaybackIndicatorEnable()
|
|
215 |
{
|
|
216 |
mStubPlaybackData->mPlaybackState = MpPlaybackData::Playing;
|
|
217 |
mTest->enablePlaybackIndicatorEnable(true);
|
|
218 |
QCOMPARE( mTest->mPlaybackActive, true);
|
|
219 |
QCOMPARE( mTest->mPlaybackIndicatorEnabled, true);
|
|
220 |
mTest->enablePlaybackIndicatorEnable(false);
|
|
221 |
QCOMPARE( mTest->mPlaybackActive, false);
|
|
222 |
QCOMPARE( mTest->mPlaybackIndicatorEnabled, false);
|
|
223 |
|
|
224 |
}
|