author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 15 Mar 2010 12:45:50 +0200 | |
branch | RCL_3 |
changeset 21 | e7d2d738d3c2 |
parent 6 | 0173bcd7697c |
child 43 | c1f20ce4abcf |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// Unit tests for the CMassStorageFileSystem class |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
/** |
|
19 |
@file |
|
20 |
@internalTechnology |
|
21 |
*/ |
|
22 |
||
23 |
#include <f32file.h> |
|
21
e7d2d738d3c2
Revision: 201010
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
24 |
#include <f32fsys.h> |
0 | 25 |
#include <e32test.h> |
26 |
#include "t_ms_main.h" |
|
27 |
#include "t_ms_common.h" |
|
28 |
#include "cmassstoragefilesystem.h" |
|
29 |
#include "cmassstoragemountcb.h" |
|
30 |
||
31 |
// a: Acutally error code; e: Expected error code |
|
32 |
#define LOG_AND_TEST(a, e) {if (a!=e) {test.Printf(_L("%d\n\r"), a); test(EFalse);}} |
|
33 |
||
34 |
_LIT(KMsFsyName, "MassStorageFileSystem"); |
|
35 |
LOCAL_D TChar driveLetter; |
|
36 |
||
37 |
LOCAL_D TBusLocalDrive* localDrive=NULL; |
|
38 |
||
39 |
LOCAL_C void ParseCommandArguments() |
|
40 |
// |
|
41 |
// Parses the command line arguments |
|
42 |
// |
|
43 |
{ |
|
44 |
TBuf<0x100> cmd; |
|
45 |
User::CommandLine(cmd); |
|
46 |
TLex lex(cmd); |
|
47 |
||
48 |
TPtrC token; |
|
49 |
token.Set(lex.NextToken()); |
|
50 |
if (token.Length() != 0) |
|
51 |
{ |
|
52 |
driveLetter = token[0]; |
|
53 |
driveLetter.UpperCase(); |
|
54 |
test.Printf(_L("CmdLine Param=%S"),&token); |
|
55 |
} |
|
56 |
else |
|
57 |
{ |
|
58 |
test.Printf(_L("Not enough command line arguments")); |
|
59 |
test(EFalse); |
|
60 |
} |
|
61 |
} |
|
62 |
||
63 |
LOCAL_C void doMsFsUnitTest() |
|
64 |
{ |
|
65 |
__UHEAP_MARK; |
|
66 |
ParseCommandArguments(); |
|
67 |
||
68 |
RFs fs; |
|
69 |
||
70 |
TInt err; |
|
71 |
TInt driveNumber; |
|
72 |
err = fs.CharToDrive(driveLetter, driveNumber); |
|
73 |
test(KErrNone == err); |
|
74 |
fs.Close(); |
|
75 |
||
76 |
test.Printf(_L("Checking if drive %d is removable\n\r"), driveNumber); |
|
77 |
TBool removable = isDriveRemovable(driveNumber); |
|
78 |
if (!removable) |
|
79 |
{ |
|
80 |
test.Printf(_L("This test is not supported on the specified drive\n\t")); |
|
81 |
return; |
|
82 |
} |
|
83 |
||
84 |
CMassStorageFileSystem* msfs = CMassStorageFileSystem::NewL(); |
|
85 |
||
86 |
test.Printf(_L("Calling Install\n\r")); |
|
87 |
err = msfs->Install(); |
|
88 |
test(err == KErrNone); |
|
89 |
||
90 |
test.Printf(_L("Comparing name\n\r")); |
|
91 |
TName name = msfs->Name(); |
|
92 |
test.Printf(_L("Name is %S\n\r"), &name); |
|
93 |
test(name == KMsFsyName); |
|
94 |
||
95 |
test.Printf(_L("Checking version\n\r")); |
|
96 |
TVersion ver(1, 0, 0); |
|
97 |
test(msfs->QueryVersionSupported(ver)); |
|
98 |
||
99 |
test.Printf(_L("Checking IsExtensionSupported\n\r")); |
|
100 |
test(msfs->IsExtensionSupported()); |
|
101 |
||
102 |
test.Printf(_L("Checking NewMountL\n\r")); |
|
103 |
//In this case new mount should leave because the controller thread is not started |
|
104 |
TRAP(err, msfs->NewMountL()); |
|
105 |
LOG_AND_TEST(err, KErrNotReady); |
|
106 |
||
107 |
test.Printf(_L("Calling unsupported functions\n\r")); |
|
108 |
TRAP(err, msfs->NewFileL()); |
|
109 |
test(err == KErrNotReady); |
|
110 |
||
111 |
TRAP(err, msfs->NewDirL()); |
|
112 |
test(err == KErrNotReady); |
|
113 |
||
114 |
TRAP(err, msfs->NewFormatL()); |
|
115 |
test(err == KErrNotReady); |
|
116 |
||
117 |
TBuf<1> buf; |
|
118 |
err = msfs->DefaultPath(buf); |
|
119 |
test(err == KErrNotSupported); |
|
120 |
||
121 |
TDriveList list; |
|
122 |
err = msfs->DriveList(list); |
|
123 |
test(err == KErrNotSupported); |
|
124 |
||
125 |
test.Printf(_L("Deleting file system object\n\r")); |
|
126 |
msfs->Close(); |
|
127 |
||
128 |
delete msfs; |
|
129 |
delete localDrive; |
|
130 |
||
131 |
__UHEAP_MARKEND; |
|
132 |
||
133 |
test.Printf(_L("MSFS unit test ===>PASS\n")); |
|
134 |
} |
|
135 |
||
136 |
||
137 |
GLDEF_C void t_ms_fsunit() |
|
138 |
// |
|
139 |
// Do all tests |
|
140 |
// |
|
141 |
{ |
|
142 |
doMsFsUnitTest(); |
|
143 |
} |
|
144 |
||
145 |
//========================================================= |
|
146 |
||
147 |
EXPORT_C TInt CFsObject::SetName(const TDesC *aName) |
|
148 |
||
149 |
{ |
|
150 |
User::Free(iName); |
|
151 |
iName=NULL; |
|
152 |
if (aName!=NULL) |
|
153 |
{ |
|
154 |
iName=aName->Alloc(); |
|
155 |
if (iName==NULL) |
|
156 |
return(KErrNoMemory); |
|
157 |
} |
|
158 |
return(KErrNone); |
|
159 |
} |
|
160 |
||
161 |
EXPORT_C TName CFsObject::Name() const |
|
162 |
||
163 |
{ |
|
164 |
if (iName) |
|
165 |
return(*iName); |
|
166 |
return(NULL); |
|
167 |
} |
|
168 |
EXPORT_C CFsObject::CFsObject() |
|
169 |
||
170 |
{ |
|
171 |
iAccessCount=1; |
|
172 |
} |
|
173 |
||
174 |
EXPORT_C CFsObject::~CFsObject() |
|
175 |
{ |
|
176 |
if(iName) |
|
177 |
User::Free(iName); |
|
178 |
iName=NULL; |
|
179 |
} |
|
180 |
||
181 |
EXPORT_C TBool CFsObject::IsCorrectThread() |
|
182 |
{ |
|
183 |
return(ETrue); |
|
184 |
} |
|
185 |
||
186 |
EXPORT_C void CFsObject::Close() |
|
187 |
{ |
|
188 |
if(iName) |
|
189 |
User::Free(iName); |
|
190 |
iName = NULL; |
|
191 |
} |
|
192 |
||
193 |
EXPORT_C TInt CFsObject::Open() |
|
194 |
{ |
|
195 |
return KErrNone; |
|
196 |
} |
|
197 |
//------------------------------------ |
|
198 |
CFileSystem::CFileSystem(void) |
|
199 |
{ |
|
200 |
} |
|
201 |
CFileSystem::~CFileSystem(void) |
|
202 |
{ |
|
203 |
} |
|
204 |
||
205 |
||
206 |
TInt CFileSystem::DefaultPath(TDes& /*aPath*/) const |
|
207 |
{ |
|
208 |
return KErrNone; |
|
209 |
} |
|
210 |
||
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
211 |
EXPORT_C void CFileSystem::DriveInfo(TDriveInfo& aInfo, TInt aDriveNumber) const |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
212 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
213 |
} |
0 | 214 |
|
215 |
EXPORT_C TBool CFileSystem::IsExtensionSupported() const |
|
216 |
{ |
|
217 |
return(EFalse); |
|
218 |
} |
|
219 |
||
220 |
EXPORT_C TBool CFileSystem::QueryVersionSupported(const TVersion& aVer) const |
|
221 |
{ |
|
222 |
||
223 |
return(User::QueryVersionSupported(iVersion,aVer)); |
|
224 |
} |
|
225 |
||
226 |
EXPORT_C TInt CFileSystem::Remove() |
|
227 |
{ |
|
228 |
||
229 |
return(KErrNone); |
|
230 |
} |
|
231 |
||
232 |
//-------------------------------------------------- |
|
233 |
EXPORT_C TBool IsValidLocalDriveMapping(TInt /*aDrive*/) |
|
234 |
// |
|
235 |
// Is the drive number to local drive mapping valid? |
|
236 |
// |
|
237 |
{ |
|
238 |
||
239 |
return(ETrue); |
|
240 |
} |
|
241 |
||
242 |
||
243 |
||
244 |
EXPORT_C TBusLocalDrive& GetLocalDrive(TInt aLocalDrive) |
|
245 |
{ |
|
246 |
||
247 |
TBusLocalDrive* dd=new(ELeave) TBusLocalDrive; |
|
248 |
TBool mediaCh; |
|
249 |
||
250 |
dd->Connect(aLocalDrive, mediaCh); |
|
251 |
localDrive = dd; |
|
252 |
return *dd; |
|
253 |
||
254 |
||
255 |
} |
|
256 |
||
257 |
EXPORT_C TBool DriveNumberToLocalDriveNumber(TInt aDrive) |
|
258 |
{ |
|
259 |
return aDrive; |
|
260 |
} |
|
261 |
||
262 |
//--------------------------------------------- |
|
263 |
EXPORT_C CLocDrvMountCB::CLocDrvMountCB() {} |
|
264 |
||
265 |
EXPORT_C CLocDrvMountCB::~CLocDrvMountCB() |
|
266 |
||
267 |
{ |
|
268 |
if(iProxyDrive) |
|
269 |
delete(iProxyDrive); |
|
270 |
} |
|
271 |
||
272 |
//----------------------------------- |
|
273 |
EXPORT_C CMountCB::CMountCB() |
|
274 |
: iMountQ(_FOFF(CFileCB,iMountLink)) |
|
275 |
{ |
|
276 |
||
277 |
} |
|
278 |
||
279 |
/** |
|
280 |
Destructor. |
|
281 |
||
282 |
Frees resources before destroying the object. |
|
283 |
*/ |
|
284 |
EXPORT_C CMountCB::~CMountCB() |
|
285 |
{ |
|
286 |
delete iVolumeName; |
|
287 |
} |
|
288 |
||
289 |
//------------------------------------- |
|
290 |
CFsDispatchObject::CFsDispatchObject() |
|
291 |
||
292 |
:iDriveNumber(-1) |
|
293 |
{} |
|
294 |
||
295 |
CFsDispatchObject::~CFsDispatchObject() |
|
296 |
{ |
|
297 |
} |
|
298 |
int CFsDispatchObject::IsCorrectThread(void) |
|
299 |
{ |
|
300 |
return ETrue; |
|
301 |
} |
|
302 |
||
303 |
EXPORT_C void CFsDispatchObject::Close() |
|
304 |
{ |
|
305 |
} |
|
306 |
||
307 |
EXPORT_C void CMountCB::IsFileInRom(const TDesC& /*aFileName*/,TUint8*& aFileStart) |
|
308 |
{ |
|
309 |
aFileStart=NULL; |
|
310 |
} |
|
311 |
||
312 |
int CLocDrvMountCB::CreateLocalDrive(class TBusLocalDrive &) |
|
313 |
||
314 |
{ |
|
315 |
return KErrNone; |
|
316 |
} |
|
317 |
void CLocDrvMountCB::DismountedLocalDrive(void) |
|
318 |
{ |
|
319 |
} |
|
320 |
||
321 |
EXPORT_C void WriteToDisk(const TDesC& /*aFileName*/, const TDesC8& /*aBuf*/) |
|
322 |
{ |
|
323 |
} |
|
324 |
||
325 |
// Implement the GetInterface methods here as these are usually |
|
326 |
// exported by EFILE, but these unit tests don't link to it. |
|
327 |
||
328 |
TInt CMountCB::GetInterface(TInt /*aInterfaceId*/, TAny*& /*aInterface*/, TAny* /*aInput*/) |
|
329 |
{ |
|
330 |
return KErrNotSupported; |
|
331 |
} |
|
332 |
||
333 |
TInt CFileSystem::GetInterface(TInt /*aInterfaceId*/, TAny*& /*aInterface*/, TAny* /*aInput*/) |
|
334 |
{ |
|
335 |
return KErrNotSupported; |
|
336 |
} |
|
337 |