sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// f32test\server\t_swapfilesystem.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <f32file.h>
|
sl@0
|
19 |
#include <e32test.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
_LIT(KTestString,"t_swapfilesystem");
|
sl@0
|
22 |
|
sl@0
|
23 |
LOCAL_D RTest test(KTestString);
|
sl@0
|
24 |
|
sl@0
|
25 |
LOCAL_D RFs TheFs;
|
sl@0
|
26 |
|
sl@0
|
27 |
LOCAL_D TChar gDriveToTest;
|
sl@0
|
28 |
|
sl@0
|
29 |
_LIT(KFsNameComposite,"Composite");
|
sl@0
|
30 |
_LIT(KFsNameFat, "Fat");
|
sl@0
|
31 |
|
sl@0
|
32 |
//---------------------------------------------------------------------------------------------
|
sl@0
|
33 |
//! @SYMTestCaseID PBASE-T_SWAPFSYS-0602
|
sl@0
|
34 |
//! @SYMTestCaseDesc Swap current file system with current file system
|
sl@0
|
35 |
//! @SYMDEF DEF101639 RFs::SwapFileSystem is not tested by f32test
|
sl@0
|
36 |
//! @SYMTestPriority Medium
|
sl@0
|
37 |
//! @SYMTestActions 1. Get name of the file system currently mounted on the drive
|
sl@0
|
38 |
//! 2. Swap current file system with the same one
|
sl@0
|
39 |
//! @SYMTestExpectedResults 1. Error code KErrAlreadyExists if Composite file is
|
sl@0
|
40 |
//! current file system
|
sl@0
|
41 |
//! 2. Error code KErrNotSupported if the drive is Z as on this drive,
|
sl@0
|
42 |
//! only composite file system can be swapped only once
|
sl@0
|
43 |
//! 3. Error codes KErrNone, KErrNotSupported or KErrInUse, otherwise.
|
sl@0
|
44 |
//---------------------------------------------------------------------------------------------
|
sl@0
|
45 |
|
sl@0
|
46 |
LOCAL_C TInt TestSwapFSCurrent(TChar aDriveLetter)
|
sl@0
|
47 |
//
|
sl@0
|
48 |
// If no file system is mounted / error in getting file system name, skip the test
|
sl@0
|
49 |
//
|
sl@0
|
50 |
{
|
sl@0
|
51 |
TInt err = KErrNone;
|
sl@0
|
52 |
TInt driveNumber;
|
sl@0
|
53 |
TFileName curFSName;
|
sl@0
|
54 |
TFileName newFSName;
|
sl@0
|
55 |
|
sl@0
|
56 |
test.Next(_L("\nSwap current file system with same file system"));
|
sl@0
|
57 |
|
sl@0
|
58 |
test.Printf(_L("\nTest is run on drive %c"),TUint(aDriveLetter));
|
sl@0
|
59 |
|
sl@0
|
60 |
err = TheFs.CharToDrive(aDriveLetter, driveNumber);
|
sl@0
|
61 |
if(KErrNone != err)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
test.Printf(_L("\nInvalid drive"));
|
sl@0
|
64 |
test(EFalse);
|
sl@0
|
65 |
}
|
sl@0
|
66 |
|
sl@0
|
67 |
// Find current file system name
|
sl@0
|
68 |
err = TheFs.FileSystemName(curFSName,driveNumber);
|
sl@0
|
69 |
if(KErrNone != err)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
test.Printf(_L("\nSkipping current test as File System is NOT mounted / error in getting the name."));
|
sl@0
|
72 |
return (err);
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
test.Printf(_L("\nName of the file system currently mounted on this drive is %s"),curFSName.Ptr());
|
sl@0
|
76 |
|
sl@0
|
77 |
newFSName = curFSName;
|
sl@0
|
78 |
|
sl@0
|
79 |
test.Printf(_L("\nName of the file system to be mounted on this drive is %s"),newFSName.Ptr());
|
sl@0
|
80 |
|
sl@0
|
81 |
err = TheFs.SwapFileSystem(curFSName,newFSName,driveNumber);
|
sl@0
|
82 |
|
sl@0
|
83 |
test.Printf(_L("\nError code is %d"),err);
|
sl@0
|
84 |
|
sl@0
|
85 |
if(curFSName.CompareF(KFsNameComposite) == 0)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
// This is unique case:
|
sl@0
|
88 |
// Swap Composite (current) with Composite (new)
|
sl@0
|
89 |
test(KErrAlreadyExists == err);
|
sl@0
|
90 |
}
|
sl@0
|
91 |
else if(driveNumber == EDriveZ)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
// This is another such case:
|
sl@0
|
94 |
// On Z Drive, only Swap with Composite is allowed
|
sl@0
|
95 |
test(KErrNotSupported == err);
|
sl@0
|
96 |
}
|
sl@0
|
97 |
else
|
sl@0
|
98 |
{
|
sl@0
|
99 |
// Other / generic cases
|
sl@0
|
100 |
test(KErrNone == err ||
|
sl@0
|
101 |
KErrNotSupported == err ||
|
sl@0
|
102 |
KErrInUse == err );
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
test.Printf(_L("\nCurrent test is completed."));
|
sl@0
|
106 |
|
sl@0
|
107 |
return (KErrNone);
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
//---------------------------------------------------------------------------------------------
|
sl@0
|
111 |
//! @SYMTestCaseID PBASE-T_SWAPFSYS-0603
|
sl@0
|
112 |
//! @SYMTestCaseDesc Swap current file system with FAT file system
|
sl@0
|
113 |
//! @SYMDEF DEF101639 RFs::SwapFileSystem is not tested by f32test
|
sl@0
|
114 |
//! @SYMTestPriority Medium
|
sl@0
|
115 |
//! @SYMTestActions 1. Get name of the file system currently mounted on the drive
|
sl@0
|
116 |
//! 2. Swap the current file system with FAT file system
|
sl@0
|
117 |
//! @SYMTestExpectedResults 1. Error code KErrNotSupported on drive Z
|
sl@0
|
118 |
//! 2. Error codes KErrNone, KErrNotSupported or KErrInUse, otherwise
|
sl@0
|
119 |
//---------------------------------------------------------------------------------------------
|
sl@0
|
120 |
LOCAL_C TInt TestSwapFSFat(TChar aDriveLetter)
|
sl@0
|
121 |
//
|
sl@0
|
122 |
// It is always assumed that FAT is always available!!
|
sl@0
|
123 |
// If no file system is mounted / error in getting file system name, skip the test
|
sl@0
|
124 |
//
|
sl@0
|
125 |
{
|
sl@0
|
126 |
TInt err = KErrNone;
|
sl@0
|
127 |
TInt driveNumber;
|
sl@0
|
128 |
TFileName curFSName;
|
sl@0
|
129 |
TFileName newFSName;
|
sl@0
|
130 |
|
sl@0
|
131 |
test.Next(_L("\nSwap current file system with FAT File System"));
|
sl@0
|
132 |
|
sl@0
|
133 |
test.Printf(_L("\nTest is run on drive %c"),TUint(aDriveLetter));
|
sl@0
|
134 |
err = TheFs.CharToDrive(aDriveLetter, driveNumber);
|
sl@0
|
135 |
if(KErrNone != err)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
test.Printf(_L("\nInvalid drive"));
|
sl@0
|
138 |
test(EFalse);
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
// Find current file system name
|
sl@0
|
142 |
err = TheFs.FileSystemName(curFSName,driveNumber);
|
sl@0
|
143 |
if(KErrNone != err)
|
sl@0
|
144 |
{
|
sl@0
|
145 |
test.Printf(_L("\nSkipping current test as File System is NOT mounted / error in getting the name."));
|
sl@0
|
146 |
return (err);
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
test.Printf(_L("\nName of the file system currently mounted on this drive is %s"),curFSName.Ptr());
|
sl@0
|
150 |
|
sl@0
|
151 |
newFSName = KFsNameFat;
|
sl@0
|
152 |
|
sl@0
|
153 |
test.Printf(_L("\nName of the file system to be mounted on this drive is %s"),newFSName.Ptr());
|
sl@0
|
154 |
|
sl@0
|
155 |
err = TheFs.SwapFileSystem(curFSName,newFSName,driveNumber);
|
sl@0
|
156 |
|
sl@0
|
157 |
test.Printf(_L("\nError code is %d"),err);
|
sl@0
|
158 |
|
sl@0
|
159 |
if(driveNumber == EDriveZ)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
// This is unique case:
|
sl@0
|
162 |
// On Z Drive, only Swap with Composite is allowed
|
sl@0
|
163 |
test(KErrNotSupported == err);
|
sl@0
|
164 |
}
|
sl@0
|
165 |
else
|
sl@0
|
166 |
{
|
sl@0
|
167 |
// Other / generic cases
|
sl@0
|
168 |
test(KErrNone == err ||
|
sl@0
|
169 |
KErrNotSupported == err ||
|
sl@0
|
170 |
KErrInUse == err );
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|
sl@0
|
173 |
test.Printf(_L("\nCurrent test is completed."));
|
sl@0
|
174 |
|
sl@0
|
175 |
return (KErrNone);
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
|
sl@0
|
179 |
//---------------------------------------------------------------------------------------------
|
sl@0
|
180 |
//! @SYMTestCaseID PBASE-T_SWAPFSYS-0604
|
sl@0
|
181 |
//! @SYMTestCaseDesc Swap current file system with Composite File System
|
sl@0
|
182 |
//! @SYMDEF DEF101639 RFs::SwapFileSystem is not tested by f32test
|
sl@0
|
183 |
//! @SYMTestPriority Medium
|
sl@0
|
184 |
//! @SYMTestActions 1. Add Composite file system to the file server
|
sl@0
|
185 |
//! to know its availability
|
sl@0
|
186 |
//! 2. Get the current file system name mounted on the test drive
|
sl@0
|
187 |
//! 3. Swap the current file system with Composite file system
|
sl@0
|
188 |
//! @SYMTestExpectedResults 1. KErrNotFound is composite file system is not available
|
sl@0
|
189 |
//! 2. Error codes KErrAlreadyExists, KErrInUse or KErrNone, on drive Z
|
sl@0
|
190 |
//! 3. Error codes KErrNotSupported, KErrAlreadyExists or KErrInUse,
|
sl@0
|
191 |
//! on other drives
|
sl@0
|
192 |
//---------------------------------------------------------------------------------------------
|
sl@0
|
193 |
LOCAL_C TInt TestSwapFSComposite(TChar aDriveLetter)
|
sl@0
|
194 |
//
|
sl@0
|
195 |
// If no file system is mounted / error in getting file system name, skip the test
|
sl@0
|
196 |
//
|
sl@0
|
197 |
{
|
sl@0
|
198 |
TInt err = KErrNone;
|
sl@0
|
199 |
TInt driveNumber;
|
sl@0
|
200 |
TFileName curFSName;
|
sl@0
|
201 |
TFileName newFSName;
|
sl@0
|
202 |
TBool compFSAvailable = EFalse;
|
sl@0
|
203 |
|
sl@0
|
204 |
test.Next(_L("\nSwap current file system with Composite File System"));
|
sl@0
|
205 |
|
sl@0
|
206 |
test.Printf(_L("\nTest is run on drive is %c"),TUint(aDriveLetter));
|
sl@0
|
207 |
err = TheFs.CharToDrive(aDriveLetter, driveNumber);
|
sl@0
|
208 |
if(KErrNone != err)
|
sl@0
|
209 |
{
|
sl@0
|
210 |
test.Printf(_L("\nInvalid drive"));
|
sl@0
|
211 |
test(EFalse);
|
sl@0
|
212 |
}
|
sl@0
|
213 |
|
sl@0
|
214 |
err = TheFs.AddFileSystem(_L("ecomp.fsy"));
|
sl@0
|
215 |
|
sl@0
|
216 |
if (KErrNone == err || KErrAlreadyExists == err)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
compFSAvailable = ETrue;
|
sl@0
|
219 |
}
|
sl@0
|
220 |
|
sl@0
|
221 |
// Find current file system name
|
sl@0
|
222 |
err = TheFs.FileSystemName(curFSName,driveNumber);
|
sl@0
|
223 |
if(KErrNone != err)
|
sl@0
|
224 |
{
|
sl@0
|
225 |
test.Printf(_L("\nFile System NOT mounted. Quiting current test"));
|
sl@0
|
226 |
return (err);
|
sl@0
|
227 |
}
|
sl@0
|
228 |
|
sl@0
|
229 |
test.Printf(_L("\nName of the file system currently mounted on this drive is %s"),curFSName.Ptr());
|
sl@0
|
230 |
|
sl@0
|
231 |
newFSName = KFsNameComposite;
|
sl@0
|
232 |
|
sl@0
|
233 |
test.Printf(_L("\nName of the file system to be mounted on this drive is %s"),newFSName.Ptr());
|
sl@0
|
234 |
|
sl@0
|
235 |
err = TheFs.SwapFileSystem(curFSName,newFSName,driveNumber);
|
sl@0
|
236 |
|
sl@0
|
237 |
test.Printf(_L("\nError code is %d"),err);
|
sl@0
|
238 |
|
sl@0
|
239 |
if(compFSAvailable)
|
sl@0
|
240 |
{
|
sl@0
|
241 |
//Composite is available!!
|
sl@0
|
242 |
if(driveNumber == EDriveZ)
|
sl@0
|
243 |
{
|
sl@0
|
244 |
test(KErrAlreadyExists == err ||
|
sl@0
|
245 |
KErrInUse == err ||
|
sl@0
|
246 |
KErrNone == err );
|
sl@0
|
247 |
}
|
sl@0
|
248 |
else
|
sl@0
|
249 |
{
|
sl@0
|
250 |
test(KErrNotSupported == err ||
|
sl@0
|
251 |
KErrAlreadyExists == err ||
|
sl@0
|
252 |
KErrInUse == err );
|
sl@0
|
253 |
}
|
sl@0
|
254 |
}
|
sl@0
|
255 |
else
|
sl@0
|
256 |
{
|
sl@0
|
257 |
//Composote NOT available!!
|
sl@0
|
258 |
test(KErrNotFound == err);
|
sl@0
|
259 |
}
|
sl@0
|
260 |
|
sl@0
|
261 |
test.Printf(_L("\nCurrent test is completed."));
|
sl@0
|
262 |
|
sl@0
|
263 |
return (KErrNone);
|
sl@0
|
264 |
}
|
sl@0
|
265 |
|
sl@0
|
266 |
LOCAL_C void ParseCommandArguments()
|
sl@0
|
267 |
//
|
sl@0
|
268 |
//
|
sl@0
|
269 |
//
|
sl@0
|
270 |
{
|
sl@0
|
271 |
TBuf<0x100> cmd;
|
sl@0
|
272 |
User::CommandLine(cmd);
|
sl@0
|
273 |
TLex lex(cmd);
|
sl@0
|
274 |
TPtrC token=lex.NextToken();
|
sl@0
|
275 |
TFileName thisfile=RProcess().FileName();
|
sl@0
|
276 |
if (token.MatchF(thisfile)==0)
|
sl@0
|
277 |
{
|
sl@0
|
278 |
token.Set(lex.NextToken());
|
sl@0
|
279 |
}
|
sl@0
|
280 |
test.Printf(_L("CLP=%S"),&token);
|
sl@0
|
281 |
|
sl@0
|
282 |
if(token.Length()!=0)
|
sl@0
|
283 |
{
|
sl@0
|
284 |
gDriveToTest=token[0];
|
sl@0
|
285 |
gDriveToTest.UpperCase();
|
sl@0
|
286 |
}
|
sl@0
|
287 |
else
|
sl@0
|
288 |
gDriveToTest='C';
|
sl@0
|
289 |
}
|
sl@0
|
290 |
|
sl@0
|
291 |
|
sl@0
|
292 |
GLDEF_C TInt E32Main()
|
sl@0
|
293 |
//
|
sl@0
|
294 |
//
|
sl@0
|
295 |
//
|
sl@0
|
296 |
{
|
sl@0
|
297 |
TInt err;
|
sl@0
|
298 |
|
sl@0
|
299 |
test.Title();
|
sl@0
|
300 |
|
sl@0
|
301 |
err = TheFs.Connect();
|
sl@0
|
302 |
|
sl@0
|
303 |
test(KErrNone == err);
|
sl@0
|
304 |
|
sl@0
|
305 |
ParseCommandArguments();
|
sl@0
|
306 |
|
sl@0
|
307 |
#if defined(__WINS__)
|
sl@0
|
308 |
// The emulator z: drive maps onto the PCs local file system
|
sl@0
|
309 |
// and swapping / unmounting it is not allowed.
|
sl@0
|
310 |
// Hence, skip the test on emulated Z: drive.
|
sl@0
|
311 |
if (gDriveToTest != 'Z')
|
sl@0
|
312 |
{
|
sl@0
|
313 |
TestSwapFSCurrent(gDriveToTest);
|
sl@0
|
314 |
TestSwapFSFat(gDriveToTest);
|
sl@0
|
315 |
TestSwapFSComposite(gDriveToTest);
|
sl@0
|
316 |
}
|
sl@0
|
317 |
#else
|
sl@0
|
318 |
TestSwapFSCurrent(gDriveToTest);
|
sl@0
|
319 |
TestSwapFSFat(gDriveToTest);
|
sl@0
|
320 |
TestSwapFSComposite(gDriveToTest);
|
sl@0
|
321 |
#endif
|
sl@0
|
322 |
|
sl@0
|
323 |
TheFs.Close();
|
sl@0
|
324 |
|
sl@0
|
325 |
test.Printf(_L("t_swapfilesystem completed successfully"));
|
sl@0
|
326 |
|
sl@0
|
327 |
test.Close();
|
sl@0
|
328 |
|
sl@0
|
329 |
return KErrNone;
|
sl@0
|
330 |
}
|