sl@0
|
1 |
// Copyright (c) 2004-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 "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 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
/**
|
sl@0
|
17 |
@file
|
sl@0
|
18 |
@internalTechnology
|
sl@0
|
19 |
*/
|
sl@0
|
20 |
|
sl@0
|
21 |
// System Include
|
sl@0
|
22 |
#include <escapeutils.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
// User Includes
|
sl@0
|
25 |
#include "TestFileUriServer.h"
|
sl@0
|
26 |
#include "TestCreateFileStep.h"
|
sl@0
|
27 |
#include "TestGetFileNameFromUriStep.h"
|
sl@0
|
28 |
#include "TestGenerateFileUriStep.h"
|
sl@0
|
29 |
#include "TestDeleteFileStep.h"
|
sl@0
|
30 |
#include "TestForAllFilesStep.h"
|
sl@0
|
31 |
|
sl@0
|
32 |
// The system-wide unique name for the test-server
|
sl@0
|
33 |
_LIT(KServerName, "TestFileUriServer");
|
sl@0
|
34 |
|
sl@0
|
35 |
TBuf<KMaxDrives> CTestFileUriServer::iRemovableDrives(KNullDesC);
|
sl@0
|
36 |
|
sl@0
|
37 |
/**
|
sl@0
|
38 |
Static factory constructor. Creates and returns instance of the test server
|
sl@0
|
39 |
@return A pointer to the newly created CTestFileUriServer object
|
sl@0
|
40 |
*/
|
sl@0
|
41 |
CTestFileUriServer* CTestFileUriServer::NewL()
|
sl@0
|
42 |
{
|
sl@0
|
43 |
// Construct the server
|
sl@0
|
44 |
CTestFileUriServer* server = new(ELeave) CTestFileUriServer();
|
sl@0
|
45 |
CleanupStack::PushL(server);
|
sl@0
|
46 |
|
sl@0
|
47 |
// CServer base class call
|
sl@0
|
48 |
// Name the server using the system-wide unique string
|
sl@0
|
49 |
// Clients use this to create server sessions.
|
sl@0
|
50 |
server->StartL(KServerName);
|
sl@0
|
51 |
|
sl@0
|
52 |
CleanupStack::Pop(server);
|
sl@0
|
53 |
return server;
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
|
sl@0
|
57 |
#if (!defined EKA2)
|
sl@0
|
58 |
|
sl@0
|
59 |
/**
|
sl@0
|
60 |
Creates the Active Scheduler, then creates the test-server, synchronises the
|
sl@0
|
61 |
thread with the client and then enters the active scheduler.
|
sl@0
|
62 |
|
sl@0
|
63 |
This is EKA1 version of MainL(). Uses sempahore to sync with client
|
sl@0
|
64 |
as Rendezvous calls are not available
|
sl@0
|
65 |
*/
|
sl@0
|
66 |
LOCAL_C void MainL()
|
sl@0
|
67 |
{
|
sl@0
|
68 |
// Create and install the active scheduler.
|
sl@0
|
69 |
CActiveScheduler* sched = NULL;
|
sl@0
|
70 |
sched = new(ELeave) CActiveScheduler;
|
sl@0
|
71 |
CleanupStack::PushL(sched);
|
sl@0
|
72 |
CActiveScheduler::Install(sched);
|
sl@0
|
73 |
|
sl@0
|
74 |
// Create the server inside trap harness
|
sl@0
|
75 |
CTestFileUriServer *server = NULL;
|
sl@0
|
76 |
TRAPD(err, server = CTestFileUriServer::NewL());
|
sl@0
|
77 |
if (!err)
|
sl@0
|
78 |
{
|
sl@0
|
79 |
CleanupStack::PushL(server);
|
sl@0
|
80 |
RSemaphore sem;
|
sl@0
|
81 |
|
sl@0
|
82 |
// The client API of TestExecute will already have created the
|
sl@0
|
83 |
// semaphore and will be waiting on it.
|
sl@0
|
84 |
User::LeaveIfError(sem.OpenGlobal(KServerName));
|
sl@0
|
85 |
|
sl@0
|
86 |
CleanupStack::Pop(server);
|
sl@0
|
87 |
|
sl@0
|
88 |
// Signal the client
|
sl@0
|
89 |
sem.Signal();
|
sl@0
|
90 |
sem.Close();
|
sl@0
|
91 |
|
sl@0
|
92 |
// Enter the active scheduler
|
sl@0
|
93 |
sched->Start();
|
sl@0
|
94 |
}
|
sl@0
|
95 |
CleanupStack::Pop(sched);
|
sl@0
|
96 |
delete server;
|
sl@0
|
97 |
delete sched;
|
sl@0
|
98 |
}
|
sl@0
|
99 |
#else
|
sl@0
|
100 |
/**
|
sl@0
|
101 |
EKA2 version of MainL()
|
sl@0
|
102 |
Uses the new Rendezvous call isntead of the older semaphore.
|
sl@0
|
103 |
*/
|
sl@0
|
104 |
LOCAL_C void MainL()
|
sl@0
|
105 |
{
|
sl@0
|
106 |
// For platform security
|
sl@0
|
107 |
#if (defined __DATA_CAGING__)
|
sl@0
|
108 |
RProcess().DataCaging(RProcess::EDataCagingOn);
|
sl@0
|
109 |
RProcess().SecureApi(RProcess::ESecureApiOn);
|
sl@0
|
110 |
#endif
|
sl@0
|
111 |
CActiveScheduler* sched = NULL;
|
sl@0
|
112 |
sched = new(ELeave) CActiveScheduler;
|
sl@0
|
113 |
CActiveScheduler::Install(sched);
|
sl@0
|
114 |
CTestFileUriServer* server = NULL;
|
sl@0
|
115 |
|
sl@0
|
116 |
// Create the test-server
|
sl@0
|
117 |
TRAPD(err, server = CTestFileUriServer::NewL());
|
sl@0
|
118 |
|
sl@0
|
119 |
if(!err)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
// Sync with the client and enter the active scheduler
|
sl@0
|
122 |
RProcess::Rendezvous(KErrNone);
|
sl@0
|
123 |
sched->Start();
|
sl@0
|
124 |
}
|
sl@0
|
125 |
delete server;
|
sl@0
|
126 |
delete sched;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
#endif // #if (!defined EKA2)
|
sl@0
|
129 |
|
sl@0
|
130 |
|
sl@0
|
131 |
#if (defined __WINS__ && !defined EKA2)
|
sl@0
|
132 |
/**
|
sl@0
|
133 |
DLL entry-point for EKA1 emulator builds.
|
sl@0
|
134 |
*/
|
sl@0
|
135 |
GLDEF_C TInt E32Dll(enum TDllReason /*aDllReason*/)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
return KErrNone;
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
#else
|
sl@0
|
141 |
/**
|
sl@0
|
142 |
Exe entry point code, for EKA1 hardware and EKA2 builds.
|
sl@0
|
143 |
*/
|
sl@0
|
144 |
GLDEF_C TInt E32Main()
|
sl@0
|
145 |
{
|
sl@0
|
146 |
__UHEAP_MARK;
|
sl@0
|
147 |
CTrapCleanup *cleanup = CTrapCleanup::New();
|
sl@0
|
148 |
if (cleanup == NULL)
|
sl@0
|
149 |
{
|
sl@0
|
150 |
return KErrNoMemory;
|
sl@0
|
151 |
}
|
sl@0
|
152 |
TInt err = KErrNone;
|
sl@0
|
153 |
TRAP(err, MainL());
|
sl@0
|
154 |
delete cleanup;
|
sl@0
|
155 |
__UHEAP_MARKEND;
|
sl@0
|
156 |
return KErrNone;
|
sl@0
|
157 |
}
|
sl@0
|
158 |
#endif // #if (defined __WINS__ && !defined EKA2)
|
sl@0
|
159 |
|
sl@0
|
160 |
#if (defined __WINS__ && !defined EKA2)
|
sl@0
|
161 |
/**
|
sl@0
|
162 |
For EKA1 emulator builds. This function is called when the thread is first
|
sl@0
|
163 |
resumed. Has the standard thread entry siganture.
|
sl@0
|
164 |
*/
|
sl@0
|
165 |
TInt ThreadFunc (TAny* /*aParam*/)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
__UHEAP_MARK;
|
sl@0
|
168 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
sl@0
|
169 |
if (cleanup == NULL)
|
sl@0
|
170 |
{
|
sl@0
|
171 |
return KErrNoMemory;
|
sl@0
|
172 |
}
|
sl@0
|
173 |
TInt err = KErrNone;
|
sl@0
|
174 |
TRAP(err, MainL());
|
sl@0
|
175 |
delete cleanup;
|
sl@0
|
176 |
__UHEAP_MARKEND;
|
sl@0
|
177 |
return KErrNone;
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
/**
|
sl@0
|
181 |
For EKA1 emulator builds. Creates and starts a thread for the server to run.
|
sl@0
|
182 |
*/
|
sl@0
|
183 |
EXPORT_C TInt NewServer()
|
sl@0
|
184 |
{
|
sl@0
|
185 |
_LIT(KThread, "Thread");
|
sl@0
|
186 |
RThread thread;
|
sl@0
|
187 |
|
sl@0
|
188 |
// Name the thread as "<Server-Name>Thread" making it hopefully unique
|
sl@0
|
189 |
TBuf<KMaxTestExecuteNameLength> threadName(KServerName);
|
sl@0
|
190 |
threadName.Append(KThread);
|
sl@0
|
191 |
|
sl@0
|
192 |
const TInt KMaxHeapSize = 0x1000000;
|
sl@0
|
193 |
|
sl@0
|
194 |
// Create the thread
|
sl@0
|
195 |
TInt err = thread.Create(threadName, ThreadFunc, KDefaultStackSize,
|
sl@0
|
196 |
KMinHeapSize, KMaxHeapSize, NULL, EOwnerProcess);
|
sl@0
|
197 |
if (err != KErrNone)
|
sl@0
|
198 |
{
|
sl@0
|
199 |
return err;
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
// Start the thread -> effectively calls ThreadFunc
|
sl@0
|
203 |
thread.Resume();
|
sl@0
|
204 |
|
sl@0
|
205 |
thread.Close();
|
sl@0
|
206 |
return KErrNone;
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
#endif // #if (defined __WINS__ && !defined EKA2)
|
sl@0
|
210 |
|
sl@0
|
211 |
|
sl@0
|
212 |
/**
|
sl@0
|
213 |
Base class pure virtual
|
sl@0
|
214 |
@return - Instance of the test step
|
sl@0
|
215 |
*/
|
sl@0
|
216 |
CTestStep* CTestFileUriServer::CreateTestStep(const TDesC& aStepName)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
CTestStep *testStep = NULL;
|
sl@0
|
219 |
|
sl@0
|
220 |
if (aStepName == KTestCreateFileStep)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
testStep = new (ELeave) CTestCreateFileStep;
|
sl@0
|
223 |
}
|
sl@0
|
224 |
else if (aStepName == KTestGetFileNameFromUriStep)
|
sl@0
|
225 |
{
|
sl@0
|
226 |
testStep = new (ELeave) CTestGetFileNameFromUriStep;
|
sl@0
|
227 |
}
|
sl@0
|
228 |
else if (aStepName == KTestGenerateFileUriStep)
|
sl@0
|
229 |
{
|
sl@0
|
230 |
testStep = new (ELeave) CTestGenerateFileUriStep;
|
sl@0
|
231 |
}
|
sl@0
|
232 |
else if (aStepName == KTestDeleteFileStep)
|
sl@0
|
233 |
{
|
sl@0
|
234 |
testStep = new (ELeave) CTestDeleteFileStep;
|
sl@0
|
235 |
}
|
sl@0
|
236 |
else if (aStepName == KTestForAllFilesStep)
|
sl@0
|
237 |
{
|
sl@0
|
238 |
testStep = new (ELeave) CTestForAllFilesStep();
|
sl@0
|
239 |
}
|
sl@0
|
240 |
return testStep;
|
sl@0
|
241 |
}
|
sl@0
|
242 |
|
sl@0
|
243 |
/**
|
sl@0
|
244 |
Returns the equivalent drive number of a drive
|
sl@0
|
245 |
*/
|
sl@0
|
246 |
void CTestFileUriServer::GetDriveNumber(const TDesC& aDrive, TDriveNumber& aDriveNum)
|
sl@0
|
247 |
{
|
sl@0
|
248 |
TBuf<1> driveLetter(aDrive.Left(1));
|
sl@0
|
249 |
driveLetter.LowerCase();
|
sl@0
|
250 |
aDriveNum = static_cast <TDriveNumber> (driveLetter[0] - KLetterA);
|
sl@0
|
251 |
}
|
sl@0
|
252 |
|
sl@0
|
253 |
/**
|
sl@0
|
254 |
Checks whether a specific drive is a removable drive
|
sl@0
|
255 |
*/
|
sl@0
|
256 |
TInt CTestFileUriServer::IsRemovableDrive(const TDriveNumber& aDriveNum, TBool& aResult)
|
sl@0
|
257 |
{
|
sl@0
|
258 |
TInt err = KErrNone;
|
sl@0
|
259 |
TDriveInfo driveInfo;
|
sl@0
|
260 |
RFs fs;
|
sl@0
|
261 |
aResult = EFalse;
|
sl@0
|
262 |
err = fs.Connect();
|
sl@0
|
263 |
if(err == KErrNone)
|
sl@0
|
264 |
{
|
sl@0
|
265 |
err = fs.Drive(driveInfo, aDriveNum);
|
sl@0
|
266 |
if (err == KErrNone && driveInfo.iDriveAtt & KDriveAttRemovable)
|
sl@0
|
267 |
{
|
sl@0
|
268 |
aResult = ETrue;
|
sl@0
|
269 |
}
|
sl@0
|
270 |
fs.Close();
|
sl@0
|
271 |
}
|
sl@0
|
272 |
return err;
|
sl@0
|
273 |
}
|
sl@0
|
274 |
|
sl@0
|
275 |
/**
|
sl@0
|
276 |
Replaces the drive placeholder <drive> with the actual drive
|
sl@0
|
277 |
*/
|
sl@0
|
278 |
HBufC16* CTestFileUriServer::CheckAndFillDriveNameL(const TPtrC& aFileUri, const TPtrC& aDrive)
|
sl@0
|
279 |
{
|
sl@0
|
280 |
HBufC16* expectedUriWithDrive = aFileUri.AllocL();
|
sl@0
|
281 |
TInt placeHolderPos = aFileUri.Find(KDrivePlaceHolder);
|
sl@0
|
282 |
if(placeHolderPos >= KErrNone)
|
sl@0
|
283 |
{
|
sl@0
|
284 |
if(aDrive == KExtMedia)
|
sl@0
|
285 |
{// Create a descriptor that is big enough
|
sl@0
|
286 |
// Just in case ReAllocL leaves
|
sl@0
|
287 |
CleanupStack::PushL(expectedUriWithDrive);
|
sl@0
|
288 |
expectedUriWithDrive = expectedUriWithDrive->ReAllocL(aFileUri.Length() + (KExtMedia().Length() - KDrivePlaceHolder().Length()));
|
sl@0
|
289 |
CleanupStack::Pop(); // expectedUriWithDrive
|
sl@0
|
290 |
}
|
sl@0
|
291 |
expectedUriWithDrive->Des().Replace(placeHolderPos, KDrivePlaceHolder().Length(), aDrive);
|
sl@0
|
292 |
}
|
sl@0
|
293 |
return expectedUriWithDrive;
|
sl@0
|
294 |
}
|
sl@0
|
295 |
|
sl@0
|
296 |
/**
|
sl@0
|
297 |
Private function used to find the remobale drives and populate iRemovableDrives
|
sl@0
|
298 |
*/
|
sl@0
|
299 |
TInt CTestFileUriServer::PopulateRemovableDrivesBuf(const RFs& aFs)
|
sl@0
|
300 |
{
|
sl@0
|
301 |
TInt err = KErrNone;
|
sl@0
|
302 |
TDriveInfo driveInfo;
|
sl@0
|
303 |
TInt driveNum;
|
sl@0
|
304 |
for (driveNum = EDriveA; driveNum <= EDriveZ; driveNum++)
|
sl@0
|
305 |
{
|
sl@0
|
306 |
// Populate iRemovableDrives with all removable drives in alphabetical order
|
sl@0
|
307 |
err = aFs.Drive(driveInfo, driveNum);
|
sl@0
|
308 |
if (err == KErrNone && (driveInfo.iDriveAtt & KDriveAttRemovable))
|
sl@0
|
309 |
{
|
sl@0
|
310 |
iRemovableDrives.Append(TInt16('a' + driveNum));
|
sl@0
|
311 |
}
|
sl@0
|
312 |
}
|
sl@0
|
313 |
return err;
|
sl@0
|
314 |
}
|
sl@0
|
315 |
|
sl@0
|
316 |
/**
|
sl@0
|
317 |
Searches whether a file with same name and path exists in any other removable drive
|
sl@0
|
318 |
*/
|
sl@0
|
319 |
TInt CTestFileUriServer::FirstRemovableDriveWithSameFileName(const TDesC& aFileName, TBuf<1>& aCorrectDrive)
|
sl@0
|
320 |
{
|
sl@0
|
321 |
aCorrectDrive = aFileName.Left(1);
|
sl@0
|
322 |
TInt err = KErrNone;
|
sl@0
|
323 |
RFs fs;
|
sl@0
|
324 |
if((err = fs.Connect()) != KErrNone)
|
sl@0
|
325 |
{
|
sl@0
|
326 |
return err;
|
sl@0
|
327 |
}
|
sl@0
|
328 |
|
sl@0
|
329 |
if(iRemovableDrives == KNullDesC)
|
sl@0
|
330 |
{
|
sl@0
|
331 |
if((err = PopulateRemovableDrivesBuf(fs)) != KErrNone)
|
sl@0
|
332 |
{
|
sl@0
|
333 |
return err;
|
sl@0
|
334 |
}
|
sl@0
|
335 |
}
|
sl@0
|
336 |
TInt index;
|
sl@0
|
337 |
HBufC* tempFileName = NULL;
|
sl@0
|
338 |
if((tempFileName = aFileName.Alloc()) == NULL)
|
sl@0
|
339 |
{
|
sl@0
|
340 |
return KErrGeneral;
|
sl@0
|
341 |
}
|
sl@0
|
342 |
for(index = 0; index < iRemovableDrives.Length(); ++index)
|
sl@0
|
343 |
{
|
sl@0
|
344 |
TUint attValue;
|
sl@0
|
345 |
// change the drive in the filename and check whether such a file exists
|
sl@0
|
346 |
tempFileName->Des()[0] = iRemovableDrives[index];
|
sl@0
|
347 |
err = fs.Att(tempFileName->Des(), attValue);
|
sl@0
|
348 |
if(err == KErrNone)
|
sl@0
|
349 |
{
|
sl@0
|
350 |
aCorrectDrive[0] = iRemovableDrives[index];
|
sl@0
|
351 |
break;
|
sl@0
|
352 |
}
|
sl@0
|
353 |
}
|
sl@0
|
354 |
if(index >= iRemovableDrives.Length())
|
sl@0
|
355 |
{// File not found on any removable drive
|
sl@0
|
356 |
aCorrectDrive = KNullDesC;
|
sl@0
|
357 |
}
|
sl@0
|
358 |
delete tempFileName;
|
sl@0
|
359 |
fs.Close();
|
sl@0
|
360 |
return KErrNone;
|
sl@0
|
361 |
}
|
sl@0
|
362 |
|
sl@0
|
363 |
/**
|
sl@0
|
364 |
Obtains the private directory of the application and appends it along with the
|
sl@0
|
365 |
relative filename and drive to create the fully qualified filename
|
sl@0
|
366 |
*/
|
sl@0
|
367 |
TInt CTestFileUriServer::CreateFullyQualifiedName(const TPtrC& aRelativeName, const TPtrC& aDrive, TFileName& aFullyQualifiedName)
|
sl@0
|
368 |
{
|
sl@0
|
369 |
RFs fs;
|
sl@0
|
370 |
TInt err = fs.Connect();
|
sl@0
|
371 |
if(err != KErrNone)
|
sl@0
|
372 |
{
|
sl@0
|
373 |
return err;
|
sl@0
|
374 |
}
|
sl@0
|
375 |
// Get private dir name
|
sl@0
|
376 |
err = fs.PrivatePath(aFullyQualifiedName);
|
sl@0
|
377 |
fs.Close();
|
sl@0
|
378 |
if(err != KErrNone)
|
sl@0
|
379 |
{
|
sl@0
|
380 |
return err;
|
sl@0
|
381 |
}
|
sl@0
|
382 |
// Construct fully-qualified filename
|
sl@0
|
383 |
aFullyQualifiedName.Insert(0, KDriveSeparator);
|
sl@0
|
384 |
aFullyQualifiedName.Insert(0, aDrive);
|
sl@0
|
385 |
TInt position = 0;
|
sl@0
|
386 |
// If backslash already exists dont include again
|
sl@0
|
387 |
if(aRelativeName.Left(1) == KBackSlash)
|
sl@0
|
388 |
{
|
sl@0
|
389 |
++position;
|
sl@0
|
390 |
}
|
sl@0
|
391 |
aFullyQualifiedName.Append(aRelativeName.Right(aRelativeName.Length() - position));
|
sl@0
|
392 |
return KErrNone;
|
sl@0
|
393 |
}
|