|
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: |
|
15 * test the file manager internal apis. |
|
16 */ |
|
17 |
|
18 #include "ut_fminternaldrivemodel.h" |
|
19 #include "testclassdatafmdrivelistprovider.h" |
|
20 #include "fmdrivemodel.h" |
|
21 #include <QtTest/QtTest> |
|
22 #include <hbapplication.h> |
|
23 #include "fmutils.h" |
|
24 /*! |
|
25 \class TestFmInternalDriveModel |
|
26 \brief \n |
|
27 class name: FmDriveModel \n |
|
28 class's description: Test the File Manager internal api functions. \n |
|
29 type of test case: unit test\n |
|
30 test cases' number totally: 10 \n |
|
31 */ |
|
32 |
|
33 void TestFmInternalDriveModel::initTestCase() |
|
34 { |
|
35 // translate the related text. |
|
36 QString lang = QLocale::system().name(); |
|
37 QString path = "z:/resource/qt/translations/"; |
|
38 mTranslator.load( path + "filemanager_" + lang ); |
|
39 qApp->installTranslator(&mTranslator); |
|
40 |
|
41 // get all the drives which can be shown, the parameters should be according to the parameter (Options) of FmDriveModel. |
|
42 FmUtils::getDriveList(mDriverList, false); |
|
43 qDebug() << mDriverList; |
|
44 } |
|
45 /*! |
|
46 Test Case Description:\n |
|
47 1. Fucntion Name: \n |
|
48 explicit FmDriveModel( QObject *parent = 0, Options options = 0, |
|
49 FmDriveListProvider *driveListProvider = 0 ); \n |
|
50 2. Case Descrition: test the constructor function. \n |
|
51 3. Input Parameters: \n |
|
52 <1> parent = new QObject(), |
|
53 Options = FmDriveModel::FillWithVolume, |
|
54 driveListProvider = new TestDataClassFmDriveListProvider();\n |
|
55 <2> parent = new QObject(), |
|
56 Options = FmDriveModel::FillWithVolume | FillWithDefaultVolume, |
|
57 driveListProvider = 0 \n |
|
58 <3> parent = new QObject(); |
|
59 Options = FmDriveModel::FillWithVolume | FillWithDefaultVolume |HideUnAvailableDrive, |
|
60 driveListProvider = 0 \n |
|
61 4. Expected result: \n |
|
62 <1> no crash \n |
|
63 <2> no crash \n |
|
64 <3> no crash \n |
|
65 */ |
|
66 void TestFmInternalDriveModel::testConstructor() |
|
67 { |
|
68 QObject *pObject = new QObject(); |
|
69 // the class TestDataClassFmDriveListProvider is a sub class from FmDriveListProvider. |
|
70 TestDataClassFmDriveListProvider *driveListProvider = new TestDataClassFmDriveListProvider(); |
|
71 FmDriveModel *fmDriveModel = new FmDriveModel( pObject,FmDriveModel::FillWithVolume,driveListProvider ); |
|
72 QVERIFY ( fmDriveModel != 0 ); |
|
73 |
|
74 // the drive number in class TestDataClassFmDriveListProvider is "3". |
|
75 QVERIFY ( fmDriveModel->rowCount() == 3 ); |
|
76 delete fmDriveModel; |
|
77 fmDriveModel = 0; |
|
78 |
|
79 fmDriveModel = new FmDriveModel( pObject,FmDriveModel::FillWithVolume | FmDriveModel::FillWithDefaultVolume ,0 ); |
|
80 QVERIFY ( fmDriveModel != 0 ); |
|
81 QVERIFY ( fmDriveModel->rowCount() > 0 ); |
|
82 delete fmDriveModel; |
|
83 fmDriveModel = 0; |
|
84 |
|
85 fmDriveModel = new FmDriveModel( pObject, FmDriveModel::FillWithVolume | FmDriveModel::FillWithDefaultVolume | FmDriveModel::HideUnAvailableDrive ,0 ); |
|
86 QVERIFY ( fmDriveModel != 0 ); |
|
87 QVERIFY ( fmDriveModel->rowCount() > 0 ); |
|
88 |
|
89 delete fmDriveModel; |
|
90 delete pObject; |
|
91 delete driveListProvider; |
|
92 } |
|
93 |
|
94 /*! |
|
95 Test Case Description:\n |
|
96 1. Fucntion Name: int rowCount( const QModelIndex &parent = QModelIndex() ) const; \n |
|
97 2. Case Descrition: Verify it return the right row count. \n |
|
98 3. Input Parameters: \n |
|
99 <1> parent = QModelIndex() \n |
|
100 4. Expected result: \n |
|
101 <1> retColumnCount = 1 \n |
|
102 */ |
|
103 void TestFmInternalDriveModel::testRowCount() |
|
104 { |
|
105 FmDriveModel *fmDriveModel = new FmDriveModel(0); |
|
106 QModelIndex testIndex1 = fmDriveModel->index(1,0); |
|
107 |
|
108 int retRowCount1 = fmDriveModel->rowCount(testIndex1); |
|
109 QVERIFY(retRowCount1 == 0); |
|
110 int retRowCount2 = fmDriveModel->rowCount(); |
|
111 delete fmDriveModel; |
|
112 } |
|
113 |
|
114 /*! |
|
115 Test Case Description:\n |
|
116 1. Fucntion Name: int columnCount( const QModelIndex &parent = QModelIndex() ) const; \n |
|
117 2. Case Descrition: \n |
|
118 3. Input Parameters: \n |
|
119 <1> parent = QModelIndex() \n |
|
120 4. Expected result: \n |
|
121 <1> retColumnCount = 1 \n |
|
122 */ |
|
123 void TestFmInternalDriveModel::testColumnCount() |
|
124 { |
|
125 FmDriveModel *fmDriveModel = new FmDriveModel(0); |
|
126 QModelIndex testIndex = QModelIndex(); |
|
127 int retColumnCount = fmDriveModel->columnCount(testIndex); |
|
128 QVERIFY(retColumnCount == 1); |
|
129 delete fmDriveModel; |
|
130 } |
|
131 |
|
132 /*! |
|
133 Test Case Description:\n |
|
134 1. Fucntion Name: \n |
|
135 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; \n |
|
136 2. Case Descrition: \n |
|
137 3. Input Parameters: \n |
|
138 <1> index = QModelIndex(), role = Qt::DisplayRole \n |
|
139 <2> index = QModelIndex(), role = Qt::UserRole \n |
|
140 <3> index = QModelIndex(), role = Qt::DecorationRole \n |
|
141 <4> index = QModelIndex(), role = Qt::TextAlignmentRole \n |
|
142 4. Expected result: \n |
|
143 <1> retData1 = "C:" \n |
|
144 <2> retData2 = "C:\" \n |
|
145 <3> return the right icon |
|
146 <4> to be delete... |
|
147 */ |
|
148 void TestFmInternalDriveModel::testData() |
|
149 { |
|
150 QObject *pObject = new QObject(); |
|
151 TestDataClassFmDriveListProvider *driveListProvider = new TestDataClassFmDriveListProvider(); |
|
152 |
|
153 FmDriveModel *fmDriveModel = new FmDriveModel( 0 ); |
|
154 QModelIndex index = fmDriveModel->index(0,0); |
|
155 |
|
156 QVariant retData1 = fmDriveModel->data(index, Qt::DisplayRole); |
|
157 QString strTemp1 = retData1.toString(); |
|
158 QVERIFY( strTemp1.trimmed() == "C:" ); |
|
159 |
|
160 // unable to verify the return icon is the right one. |
|
161 QVariant retData3 = fmDriveModel->data(index, Qt::DecorationRole); |
|
162 |
|
163 // need to delete the "if (index.column() == 1 && role == Qt::TextAlignmentRole)", because only one column is defined. |
|
164 QVariant retData4 = fmDriveModel->data(index, Qt::TextAlignmentRole); |
|
165 |
|
166 delete driveListProvider; |
|
167 driveListProvider = 0; |
|
168 delete fmDriveModel; |
|
169 fmDriveModel = 0; |
|
170 } |
|
171 |
|
172 /*! |
|
173 Test Case Description:\n |
|
174 1. Fucntion Name: \n |
|
175 bool indexValid( const QModelIndex &index ) const; \n |
|
176 2. Case Descrition: \n |
|
177 3. Input Parameters: \n |
|
178 <1> index = QModelIndex() \n |
|
179 4. Expected result: \n |
|
180 <1> retBool = true \n |
|
181 */ |
|
182 void TestFmInternalDriveModel::testIndexValid() |
|
183 { |
|
184 FmDriveModel *fmDriveModel = new FmDriveModel(0); |
|
185 QModelIndex aIndex = fmDriveModel->index(0,0); |
|
186 QModelIndex bIndex = fmDriveModel->index(0,1); |
|
187 bool a = fmDriveModel->indexValid(aIndex); |
|
188 QVERIFY(a == true); |
|
189 bool b = fmDriveModel->indexValid(bIndex); |
|
190 QVERIFY(b == true); |
|
191 delete fmDriveModel; |
|
192 fmDriveModel = 0; |
|
193 } |
|
194 |
|
195 /*! |
|
196 Test Case Description:\n |
|
197 1. Fucntion Name: \n |
|
198 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; \n |
|
199 2. Case Descrition: \n |
|
200 3. Input Parameters: \n |
|
201 <1> section = 0, orientation = Qt::Horizontal, role = Qt::DisplayRole \n |
|
202 <2> section = 1, orientation = Qt::Horizontal, role = Qt::DisplayRole \n |
|
203 <3> section = 2, orientation = Qt::Horizontal, role = Qt::DisplayRole \n |
|
204 <4> section = 3, orientation = Qt::Horizontal, role = Qt::DisplayRole \n |
|
205 <5> section = 4, orientation = Qt::Horizontal, role = Qt::DisplayRole \n |
|
206 <6> section = 1, orientation = Qt::Vertical, role = Qt::DisplayRole \n |
|
207 <7> section = 1, orientation = Qt::Horizontal, role = Qt::UserRole \n |
|
208 4. Expected result: \n |
|
209 <1> retHeaderData.toString() = "Name" \n |
|
210 <2> retHeaderData.toString() = "Size" \n |
|
211 <3> retHeaderData.toString() = "Type" \n |
|
212 <4> retHeaderData.toString() = "Date Modified" \n |
|
213 <5> no crash \n |
|
214 <6> no crash \n |
|
215 <7> no crash \n |
|
216 */ |
|
217 void TestFmInternalDriveModel::testHeaderData() |
|
218 { |
|
219 FmDriveModel *fmDriveModel = new FmDriveModel(0); |
|
220 // |
|
221 QVariant retHeaderData1 = fmDriveModel->headerData(0, Qt::Horizontal, Qt::DisplayRole); |
|
222 QVERIFY(retHeaderData1.toString() == "Name"); |
|
223 |
|
224 QVariant retHeaderData2 = fmDriveModel->headerData(1, Qt::Horizontal, Qt::DisplayRole); |
|
225 QVERIFY(retHeaderData2.toString() == "Size"); |
|
226 |
|
227 QVariant retHeaderData3 = fmDriveModel->headerData(2, Qt::Horizontal, Qt::DisplayRole); |
|
228 QVERIFY(retHeaderData3.toString() == "Type"); |
|
229 |
|
230 QVariant retHeaderData4 = fmDriveModel->headerData(3, Qt::Horizontal, Qt::DisplayRole); |
|
231 QVERIFY(retHeaderData4.toString() == "Date Modified"); |
|
232 |
|
233 QVariant retHeaderData5 = fmDriveModel->headerData(4, Qt::Horizontal, Qt::DisplayRole); |
|
234 QVERIFY(retHeaderData5.toString().isEmpty());// ""); |
|
235 |
|
236 #ifdef TO_BE_INVESTIGATE |
|
237 QVariant retHeaderData6 = fmDriveModel->headerData(0, Qt::Vertical, Qt::DisplayRole); |
|
238 QString a = retHeaderData6.toString(); // to be investigated. |
|
239 // QVERIFY(retHeaderData6.toString() == ""); |
|
240 #endif |
|
241 |
|
242 QVariant retHeaderData7 = fmDriveModel->headerData(1, Qt::Horizontal, Qt::UserRole); |
|
243 QVERIFY(retHeaderData7.toString().isEmpty()); //== ""); |
|
244 |
|
245 delete fmDriveModel; |
|
246 fmDriveModel = 0; |
|
247 } |
|
248 |
|
249 /*! |
|
250 Test Case Description:\n |
|
251 1. Fucntion Name: \n |
|
252 QString displayString( const QModelIndex &index ) const; \n |
|
253 2. Case Descrition: Verify the correct display string is shown. \n |
|
254 3. Input Parameters: \n |
|
255 <1> index = QModelIndex() \n |
|
256 4. Expected result: \n |
|
257 <1> retBool = true \n |
|
258 */ |
|
259 void TestFmInternalDriveModel::testDisplayStringWithVolume() |
|
260 { |
|
261 // option = FillWithVolume | FillWithDefaultVolume |
|
262 FmDriveModel *fmDriveModel = new FmDriveModel( 0,FmDriveModel::FillWithVolume | FmDriveModel::FillWithDefaultVolume, 0); |
|
263 |
|
264 for(int i=0; i < mDriverList.count(); i++){ |
|
265 QModelIndex indexValid = fmDriveModel->index(i,0); |
|
266 // get the display string. |
|
267 QVariant retData = fmDriveModel->displayString(indexValid); |
|
268 QVERIFY(retData.toString() == FmUtils::fillDriveVolume(mDriverList[i], true)); |
|
269 } |
|
270 delete fmDriveModel; |
|
271 } |
|
272 |
|
273 /*! |
|
274 Test Case Description:\n |
|
275 1. Fucntion Name: \n |
|
276 QString displayString( const QModelIndex &index ) const; \n |
|
277 2. Case Descrition: Verify the correct display string is shown. \n |
|
278 3. Input Parameters: \n |
|
279 <1> index = QModelIndex() \n |
|
280 4. Expected result: \n |
|
281 <1> retBool = true \n |
|
282 */ |
|
283 void TestFmInternalDriveModel::testDisplayStringWithoutVolume() |
|
284 { |
|
285 FmDriveModel *fmDriveModel = new FmDriveModel(); |
|
286 |
|
287 for(int i=0; i < mDriverList.count(); i++){ |
|
288 QModelIndex indexValid = fmDriveModel->index(i,0); |
|
289 // get the display string. |
|
290 QVariant retData = fmDriveModel->displayString(indexValid); |
|
291 // QString retString = retData.toString(); |
|
292 // qDebug()<<retString; |
|
293 QVERIFY(retData.toString() == FmUtils::removePathSplash( mDriverList[i] )); |
|
294 } |
|
295 delete fmDriveModel; |
|
296 } |
|
297 |
|
298 /*! |
|
299 Test Case Description:\n |
|
300 1. Fucntion Name: \n |
|
301 QString displayString( const QModelIndex &index ) const; \n |
|
302 2. Case Descrition: Verify it doesn't crash when using an invalid index. \n |
|
303 3. Input Parameters: \n |
|
304 <1> index = QModelIndex() \n |
|
305 4. Expected result: \n |
|
306 <1> retString = QString() \n |
|
307 */ |
|
308 void TestFmInternalDriveModel::testDisplayStringEmpty() |
|
309 { |
|
310 FmDriveModel *fmDriveModel = new FmDriveModel(); |
|
311 QModelIndex indexInValid = fmDriveModel->index(-1,0); |
|
312 QVariant retData = fmDriveModel->displayString(indexInValid); |
|
313 QVERIFY(retData.toString() == QString()); |
|
314 } |
|
315 /*! |
|
316 Test Case Description:\n |
|
317 1. Fucntion Name: \n |
|
318 QString driveName( const QModelIndex &index ) const; \n |
|
319 2. Case Descrition: \n |
|
320 3. Input Parameters: \n |
|
321 <1> indexValid = QModelIndex() \n |
|
322 <2> indexInValid = QModelIndex() \n |
|
323 4. Expected result: \n |
|
324 <1> return the rignt drive name. \n |
|
325 <2> no crash. \n |
|
326 */ |
|
327 void TestFmInternalDriveModel::testDriveName() |
|
328 { |
|
329 FmDriveModel *fmDriveModel = new FmDriveModel(); |
|
330 QModelIndex indexValid = fmDriveModel->index(0,0); |
|
331 QModelIndex indexInValid1 = fmDriveModel->index(0,2); |
|
332 QModelIndex indexInValid2 = fmDriveModel->index(18); |
|
333 QModelIndex indexInValid3 = fmDriveModel->index(5,0); |
|
334 QString retDriveName1 = fmDriveModel->driveName(indexValid); |
|
335 QVERIFY(retDriveName1 == "C:/"); |
|
336 QString retDriveName2 = fmDriveModel->driveName(indexInValid1); |
|
337 QVERIFY(retDriveName2.isEmpty()); |
|
338 QString retDriveName3 = fmDriveModel->driveName(indexInValid2); |
|
339 QVERIFY(retDriveName3.isEmpty()); |
|
340 QString retDriveName4 = fmDriveModel->driveName(indexInValid3); |
|
341 QVERIFY(retDriveName4.isEmpty()); |
|
342 delete fmDriveModel; |
|
343 fmDriveModel = 0; |
|
344 } |
|
345 |
|
346 void TestFmInternalDriveModel::cleanupTestCase() |
|
347 { |
|
348 } |
|
349 |
|
350 QTEST_MAIN(TestFmInternalDriveModel) |