|
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" |
|
30 |
|
31 // Do this so we can access all member variables. |
|
32 #define private public |
|
33 #include "mpcollectiontbonelistdatamodel.h" |
|
34 #undef private |
|
35 |
|
36 /*! |
|
37 Make our test case a stand-alone executable that runs all the test functions. |
|
38 */ |
|
39 int main(int argc, char *argv[]) |
|
40 { |
|
41 QApplication app(argc, argv); |
|
42 TestMpCollectionTBoneListDataModel 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_mpcollectiontbonelistdatamodel.txt"; |
|
52 |
|
53 return QTest::qExec(&tv, 3, pass); |
|
54 } |
|
55 } |
|
56 |
|
57 TestMpCollectionTBoneListDataModel::TestMpCollectionTBoneListDataModel() |
|
58 : mTest(0), |
|
59 mHelper(0), |
|
60 mStubData(0), |
|
61 mMpTranslator(0) |
|
62 { |
|
63 } |
|
64 |
|
65 TestMpCollectionTBoneListDataModel::~TestMpCollectionTBoneListDataModel() |
|
66 { |
|
67 delete mTest; |
|
68 delete mHelper; |
|
69 delete mStubData; |
|
70 delete mMpTranslator; |
|
71 } |
|
72 |
|
73 /*! |
|
74 Called before the first testfunction is executed. |
|
75 */ |
|
76 void TestMpCollectionTBoneListDataModel::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 mStubData = new MpMpxCollectionData(); |
|
89 mHelper = new TestHelper(); |
|
90 } |
|
91 |
|
92 /*! |
|
93 Called after the last testfunction was executed. |
|
94 */ |
|
95 void TestMpCollectionTBoneListDataModel::cleanupTestCase() |
|
96 { |
|
97 delete mStubData; |
|
98 mStubData = 0; |
|
99 delete mHelper; |
|
100 mHelper = 0; |
|
101 } |
|
102 |
|
103 /*! |
|
104 Called before each testfunction is executed. |
|
105 */ |
|
106 void TestMpCollectionTBoneListDataModel::init() |
|
107 { |
|
108 mTest = new MpCollectionTBoneListDataModel(mStubData); |
|
109 mTest->mCollectionData->mItemDataReturn = true; |
|
110 } |
|
111 |
|
112 /*! |
|
113 Called after every testfunction. |
|
114 */ |
|
115 void TestMpCollectionTBoneListDataModel::cleanup() |
|
116 { |
|
117 delete mTest; |
|
118 mTest = 0; |
|
119 } |
|
120 |
|
121 /*! |
|
122 Tests correct cleanup of member variables. |
|
123 */ |
|
124 void TestMpCollectionTBoneListDataModel::testMemberCleanup() |
|
125 { |
|
126 cleanup(); |
|
127 int count = MpMpxCollectionData::getInitCounter(); |
|
128 init(); |
|
129 cleanup(); |
|
130 QCOMPARE(MpMpxCollectionData::getInitCounter(), count); |
|
131 } |
|
132 |
|
133 /*! |
|
134 Tests refreshModel() request. |
|
135 */ |
|
136 void TestMpCollectionTBoneListDataModel::testRefreshModel() |
|
137 { |
|
138 mTest->mCollectionData->mAlbumSongCount = 10; |
|
139 mTest->refreshModel(); |
|
140 QModelIndex modelIndex = mHelper->indexFor(1); |
|
141 // Verify that: |
|
142 // - It sets correct row count |
|
143 QCOMPARE(mTest->rowCount(modelIndex), 10); |
|
144 } |
|
145 |
|
146 /*! |
|
147 Tests data() request. |
|
148 */ |
|
149 void TestMpCollectionTBoneListDataModel::testData() |
|
150 { |
|
151 QModelIndex modelIndex = mHelper->indexFor(1); |
|
152 |
|
153 // Qt::DisplayRole |
|
154 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
|
155 QCOMPARE(data.canConvert(QVariant::StringList), true); |
|
156 QStringList dataList = data.toStringList(); |
|
157 QCOMPARE(dataList.count(), 1); |
|
158 QCOMPARE(dataList.at(0), QString("Title1")); |
|
159 } |
|
160 |
|
161 /*! |
|
162 Tests data() request with no data available. |
|
163 */ |
|
164 void TestMpCollectionTBoneListDataModel::testDataNoData() |
|
165 { |
|
166 mTest->mCollectionData->mItemDataReturn = false; |
|
167 |
|
168 QModelIndex modelIndex = mHelper->indexFor(1); |
|
169 |
|
170 // Qt::DisplayRole |
|
171 QVariant data = mTest->data(modelIndex, Qt::DisplayRole); |
|
172 QCOMPARE(data.canConvert(QVariant::StringList), true); |
|
173 QStringList dataList = data.toStringList(); |
|
174 QCOMPARE(dataList.count(), 1); |
|
175 QCOMPARE(dataList.at(0), hbTrId("txt_mus_other_unknown4")); |
|
176 } |
|
177 |
|
178 /*! |
|
179 Tests data() request for a role it doesn't support. |
|
180 Make sure it doesn't crash. |
|
181 */ |
|
182 void TestMpCollectionTBoneListDataModel::testDataAnyOtherRole() |
|
183 { |
|
184 QModelIndex modelIndex = mHelper->indexFor(1); |
|
185 |
|
186 // Qt::DecorationRole |
|
187 QVariant data = mTest->data(modelIndex, Qt::DecorationRole); |
|
188 QCOMPARE(data.isValid(), false); |
|
189 } |
|
190 |