First public contribution.
1 // Copyright (c) 1999-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\server\t_appins.cpp
25 #define WIN32_LEAN_AND_MEAN
26 #pragma warning (disable:4201) // warning C4201: nonstandard extension used : nameless struct/union
27 #pragma warning (default:4201) // warning C4201: nonstandard extension used : nameless struct/union
36 GLDEF_D RTest test(_L("T_APPINS"));
37 LOCAL_D RFs TheNotifyFs; // Fileserver session to receive/request change notification
41 What this test is for:
42 Tests bug fix for the bug which doesn't notify drive D: when files are installed onto it
48 // Test notification when session path of notification session is set to be explicitly different
49 // from the drive and directory into which files and directories are created
53 path=_L("?:\\F32-TST\\T_APPINS\\");
55 TInt r=TheNotifyFs.SessionPath(gSessionPath);
59 r=RFs::DriveToChar(RemovableDrive,driveChar);
62 if (gSessionPath[0]=='C')
63 (gSessionPath[0] == (TText)gDriveToTest)? (path[0] = (TText)driveChar):(path[0] = (TText)gDriveToTest);
64 else if (gSessionPath[0]=='Y')
66 else if (gSessionPath[0]=='X')
69 path[0]='C'; //invalid drive numbers shouldn't reach here, must be filtered out from t_main
72 TRequestStatus statEntry(KRequestPending);
73 TRequestStatus statFile(KRequestPending);
74 TRequestStatus statDir(KRequestPending);
75 TRequestStatus statWild(KRequestPending);
76 TRequestStatus statWilder(KRequestPending);
79 test((r==KErrNone)||(r==KErrNotFound)||(r==KErrPathNotFound));
81 test.Printf(_L("Notify Session Path %S\n"),&gSessionPath);
83 // Submit notify change requests (requesting ahead)
84 test.Printf(_L("Create a directory %S\n"),&path);
85 TheNotifyFs.NotifyChange(ENotifyEntry,statEntry,path);
86 TheNotifyFs.NotifyChange(ENotifyFile,statFile,path);
87 TheNotifyFs.NotifyChange(ENotifyDir,statDir,path);
88 TheNotifyFs.NotifyChange(ENotifyEntry,statWild,_L("?:\\F32-TST\\T_APPINS\\"));
89 TheNotifyFs.NotifyChange(ENotifyEntry,statWilder,_L("*:\\"));
92 test((r==KErrNone)||(r==KErrAlreadyExists));
93 User::WaitForAnyRequest();
94 test(statEntry==KErrNone);
95 test(statFile==KErrNone);
96 test(statDir==KErrNone);
97 test(statWild==KErrNone);
98 test(statWilder==KErrNone);
100 // Resubmit notify change requests (requesting ahead)
101 test.Next(_L("Create a file in the directory"));
102 TheNotifyFs.NotifyChange(ENotifyEntry,statEntry,path);
103 TheNotifyFs.NotifyChange(ENotifyFile,statFile,path);
104 TheNotifyFs.NotifyChange(ENotifyDir,statDir,path);
105 TheNotifyFs.NotifyChange(ENotifyEntry,statWild,_L("?:\\F32-TST\\T_APPINS\\"));
106 TheNotifyFs.NotifyChange(ENotifyFile,statWilder,_L("*:\\"));
110 filePath+=_L("TestFile.app");
112 r=file.Replace(TheFs,filePath,EFileRead|EFileWrite);
114 User::WaitForAnyRequest();
116 test (statEntry==KErrNone);
117 test(statFile==KErrNone);
118 test(statDir==KRequestPending);
119 test(statWild==KErrNone);
120 test(statWilder==KErrNone);
122 // Resubmit notify change requests
123 test.Next(_L("Remove the file from the directory"));
124 TheNotifyFs.NotifyChange(ENotifyEntry,statEntry,path);
125 TheNotifyFs.NotifyChange(ENotifyFile,statFile,path);
126 TheNotifyFs.NotifyChange(ENotifyDir,statWild,_L("?:\\F32-TST\\T_APPINS\\"));
127 TheNotifyFs.NotifyChange(ENotifyEntry,statWilder,_L("*:\\"));
129 r=TheFs.Delete(filePath);
131 User::WaitForAnyRequest();
132 test (statEntry==KErrNone);
133 test(statFile==KErrNone);
134 test(statDir==KRequestPending);
135 test(statWild==KRequestPending);
136 test(statWilder==KErrNone);
138 // Resubmit notify change requests
139 test.Next(_L("Remove the directory"));
140 TheNotifyFs.NotifyChange(ENotifyEntry,statEntry,path);
141 TheNotifyFs.NotifyChange(ENotifyFile,statFile,path);
142 // TheNotifyFs.NotifyChange(ENotifyEntry,statWild,_L("?:\\F32-TST\\T_APPINS\\"));
143 TheNotifyFs.NotifyChange(ENotifyFile,statWilder,_L("*:\\"));
147 User::WaitForAnyRequest();
148 test (statEntry==KErrNone);
149 test(statFile==KRequestPending);
150 test(statDir==KErrNone);
151 test(statWild==KErrNone);
152 test(statWilder==KRequestPending);
154 // In case any outstanding notification requests exist
155 TheNotifyFs.NotifyChangeCancel();
160 // Test notification when session path of the notification session is implicitly different
161 // to the drive and directory into which files and directories are created
164 TFileName sessionPath;
165 sessionPath=_L("?:\\F32-TST\\");
168 TInt err=RFs::DriveToChar(RemovableDrive,driveChar);
171 if (gSessionPath[0]=='C')
172 (gSessionPath[0] == (TText)gDriveToTest)? (sessionPath[0] = (TText)driveChar):(sessionPath[0] = (TText)gDriveToTest);
173 else if (gSessionPath[0]=='Y')
175 else if (gSessionPath[0]=='X')
178 sessionPath[0]='C'; //invalid drive numbers shouldn't reach here, must be filtered out from t_main
181 TInt r=TheFs.SetSessionPath(sessionPath);
185 path=_L("\\F32-TST\\T_APPINS\\"); // Takes drive implicitly from associated session path
188 test((r==KErrNone)||(r==KErrNotFound)||(r==KErrPathNotFound));
190 TRequestStatus statEntry(KRequestPending);
191 TRequestStatus statFile(KRequestPending);
192 TRequestStatus statDir(KRequestPending);
193 TRequestStatus statWild(KRequestPending);
194 TRequestStatus statWilder(KRequestPending);
196 test.Printf(_L("Notify Session Path %S\n"),&gSessionPath);
197 test.Printf(_L("File Creation Session Path %S\n"),&sessionPath);
199 // Submit notify change requests (requesting ahead)
200 test.Printf(_L("Create a directory %S\n"),&path);
202 TheNotifyFs.NotifyChange(ENotifyEntry,statEntry,path); // Watches drive associated with
203 TheNotifyFs.NotifyChange(ENotifyFile,statFile,path);
204 TheNotifyFs.NotifyChange(ENotifyDir,statDir,path);
205 TheNotifyFs.NotifyChange(ENotifyEntry,statWild,_L("?:\\F32-TST\\T_APPINS\\"));
206 TheNotifyFs.NotifyChange(ENotifyAll,statWilder,_L("*:\\"));
208 r=TheFs.MkDir(path); // Creates the directory on the drive
209 test((r==KErrNone)||(r==KErrAlreadyExists)); // associated with TheFs session path
210 test (statEntry==KRequestPending);
211 test(statFile==KRequestPending);
212 test(statDir==KRequestPending); // No notification because it's watching a different drive!
213 test(statWild==KErrNone); // BUG FIX TEST
214 test(statWilder==KErrNone);
216 // Don't need to resubmit notify change requests
217 test.Next(_L("Create a file in the directory"));
218 TheNotifyFs.NotifyChange(ENotifyFile,statWild,_L("?:\\F32-TST\\T_APPINS\\"));
219 TheNotifyFs.NotifyChange(ENotifyFile,statWilder,_L("*:\\"));
223 filePath+=_L("TestFile.app");
225 r=file.Replace(TheFs,filePath,EFileRead|EFileWrite);
229 test (statEntry==KRequestPending); // No notification!
230 test(statFile==KRequestPending);
231 test(statDir==KRequestPending);
232 test(statWild==KErrNone);
233 test(statWilder==KErrNone);
235 // No need to resubmit notify change requests
236 TheNotifyFs.NotifyChange(ENotifyEntry,statWild,_L("?:\\F32-TST\\T_APPINS\\"));
237 TheNotifyFs.NotifyChange(ENotifyDir,statWilder,_L("*:\\"));
239 r=TheFs.Delete(filePath);
241 // Still no notification
242 test (statEntry==KRequestPending);
243 test(statFile==KRequestPending);
244 test(statDir==KRequestPending);
245 test(statWild==KErrNone);
246 test(statWilder==KRequestPending);
248 // No need to resubmit notify change requests
249 test.Next(_L("Remove the directory"));
250 TheNotifyFs.NotifyChange(ENotifyDir,statWild,_L("?:\\F32-TST\\T_APPINS\\"));
251 // TheNotifyFs.NotifyChange(ENotifyDir,statWilder,_L("*:\\"));
254 // Still no notification
255 test (statEntry==KRequestPending);
256 test(statFile==KRequestPending);
257 test(statDir==KRequestPending);
258 test(statWild==KErrNone);
259 test(statWilder==KErrNone);
261 // Cancel the outstanding requests
262 TheNotifyFs.NotifyChangeCancel();
267 // Test notification when session path of the notification session is set to be the
268 // same as the drive and directory into which files and directories are created
272 path=_L("\\F32-TST\\T_APPINS\\");
273 TInt r=TheFs.RmDir(path);
274 test((r==KErrNone)||(r==KErrNotFound)||(r==KErrPathNotFound));
276 TRequestStatus statEntry(KRequestPending);
277 TRequestStatus statFile(KRequestPending);
278 TRequestStatus statDir(KRequestPending);
279 TRequestStatus statWild(KRequestPending);
280 TRequestStatus statWilder(KRequestPending);
282 test.Printf(_L("Session Path %S\n"),&gSessionPath);
283 // Set the session path of the session which creates the file/directory to be
284 // the same as the notification session's session path
285 r=TheFs.SetSessionPath(gSessionPath);
288 // Submit notify change requests (requesting ahead)
289 test.Printf(_L("Create a directory %S\n"),&path);
290 TheNotifyFs.NotifyChange(ENotifyEntry,statEntry,path);
291 TheNotifyFs.NotifyChange(ENotifyFile,statFile,path);
292 TheNotifyFs.NotifyChange(ENotifyDir,statDir,path);
293 TheNotifyFs.NotifyChange(ENotifyEntry,statWild,_L("?:\\F32-TST\\"));
294 TheNotifyFs.NotifyChange(ENotifyEntry,statWilder,_L("*:\\"));
297 test((r==KErrNone)||(r==KErrAlreadyExists));
298 User::WaitForAnyRequest();
299 test (statEntry==KErrNone);
300 test(statFile==KErrNone);
301 test(statDir==KErrNone);
302 test(statWild==KErrNone);
303 test(statWilder==KErrNone);
305 // Resubmit notify change requests (requesting ahead)
306 test.Next(_L("Create a file in the directory"));
307 TheNotifyFs.NotifyChange(ENotifyEntry,statEntry,path);
308 TheNotifyFs.NotifyChange(ENotifyFile,statFile,path);
309 TheNotifyFs.NotifyChange(ENotifyDir,statDir,path);
310 TheNotifyFs.NotifyChange(ENotifyEntry,statWild,_L("?:\\F32-TST\\"));
311 TheNotifyFs.NotifyChange(ENotifyEntry,statWilder,_L("*:\\"));
316 filePath+=_L("TestFile.app");
318 r=file.Replace(TheFs,filePath,EFileRead|EFileWrite);
320 User::WaitForAnyRequest();
322 test (statEntry==KErrNone);
323 test(statFile==KErrNone);
324 test(statDir==KRequestPending);
325 test(statWild==KErrNone);
326 test(statWilder==KErrNone);
328 // Resubmit notify change requests
329 test.Next(_L("Remove the file from the directory"));
330 TheNotifyFs.NotifyChange(ENotifyEntry,statEntry,path);
331 TheNotifyFs.NotifyChange(ENotifyFile,statFile,path);
332 TheNotifyFs.NotifyChange(ENotifyEntry,statWild,_L("?:\\F32-TST\\"));
333 TheNotifyFs.NotifyChange(ENotifyEntry,statWilder,_L("*:\\"));
335 r=TheFs.Delete(filePath);
337 User::WaitForAnyRequest();
338 test (statEntry==KErrNone);
339 test(statFile==KErrNone);
340 test(statDir==KRequestPending);
341 test(statWild==KErrNone);
342 test(statWilder==KErrNone);
344 // Resubmit notify change requests
345 test.Next(_L("Remove the directory"));
346 TheNotifyFs.NotifyChange(ENotifyEntry,statEntry,path);
347 TheNotifyFs.NotifyChange(ENotifyFile,statFile,path);
348 TheNotifyFs.NotifyChange(ENotifyEntry,statWild,_L("?:\\F32-TST\\"));
349 TheNotifyFs.NotifyChange(ENotifyEntry,statWilder,_L("*:\\"));
353 User::WaitForAnyRequest();
354 test (statEntry==KErrNone);
355 test(statFile==KRequestPending);
356 test(statDir==KErrNone);
357 test(statWild==KErrNone);
358 test(statWilder==KErrNone);
360 // Cancel any outstanding notification change requests
361 TheNotifyFs.NotifyChangeCancel();
364 #if !defined(__WINS__)
368 // Test notification when session path is set to be different from the drive and directory
369 // into which files and directories are created
373 TBuf<23> pathBuf=_L("?:\\F32-TST\\T_APPINS\\");
376 TInt r=RFs::DriveToChar(RemovableDrive,driveChar);
379 if (gDriveToTest =='C')
380 pathBuf[0]=driveChar;
382 pathBuf[0] =gDriveToTest;
386 test((r==KErrNone)||(r==KErrNotFound)||(r==KErrPathNotFound));
389 result=TheFs.MkDir(_L("C:\\SILLY\\"));
390 test((result==KErrNone)||(result==KErrAlreadyExists));
391 result=TheFs.MkDir(_L("C:\\SILLY\\SILLIER\\"));
392 test((result==KErrNone)||(result==KErrAlreadyExists));
393 result=TheFs.MkDir(_L("C:\\SILLY\\SILLIER\\SILLIEST\\"));
394 test((result==KErrNone)||(result==KErrAlreadyExists));
396 result=TheNotifyFs.SetSessionPath(_L("C:\\SILLY\\SILLIER\\SILLIEST\\"));
397 test(result==KErrNone);
399 result=TheNotifyFs.SessionPath(gSessionPath);
400 test(result==KErrNone);
401 test.Printf(_L("Session Path %S\n"),&gSessionPath);
403 TRequestStatus statEntry(KRequestPending);
404 TRequestStatus statFile(KRequestPending);
405 TRequestStatus statDir(KRequestPending);
407 // Submit notify change requests (requesting ahead)
408 test.Printf(_L("Create a directory %S\n"),&path);
409 TheNotifyFs.NotifyChange(ENotifyEntry,statEntry,path);
410 TheNotifyFs.NotifyChange(ENotifyFile,statFile,path);
411 TheNotifyFs.NotifyChange(ENotifyDir,statDir,path);
414 test((r==KErrNone)||(r==KErrAlreadyExists));
415 User::WaitForAnyRequest();
416 test (statEntry==KErrNone);
417 test(statFile==KErrNone);
418 test(statDir==KErrNone);
420 // Resubmit notify change requests (requesting ahead)
421 test.Next(_L("Create a file in the directory"));
422 TheNotifyFs.NotifyChange(ENotifyEntry,statEntry,path);
423 TheNotifyFs.NotifyChange(ENotifyFile,statFile,path);
424 TheNotifyFs.NotifyChange(ENotifyDir,statDir,path);
428 filePath+=_L("TestFile.app");
430 r=file.Replace(TheFs,filePath,EFileRead|EFileWrite);
432 User::WaitForAnyRequest();
434 test (statEntry==KErrNone);
435 test(statFile==KErrNone);
436 test(statDir==KRequestPending);
438 // Resubmit notify change requests
439 test.Next(_L("Remove the file from the directory"));
440 TheNotifyFs.NotifyChange(ENotifyEntry,statEntry,path);
441 TheNotifyFs.NotifyChange(ENotifyFile,statFile,path);
443 r=TheFs.Delete(filePath);
445 User::WaitForAnyRequest();
446 test (statEntry==KErrNone);
447 test(statFile==KErrNone);
448 test(statDir==KRequestPending);
450 // Resubmit notify change requests
451 test.Next(_L("Remove the directory"));
452 TheNotifyFs.NotifyChange(ENotifyEntry,statEntry,path);
453 TheNotifyFs.NotifyChange(ENotifyFile,statFile,path);
456 User::WaitForAnyRequest();
457 test (statEntry==KErrNone);
458 test(statFile==KRequestPending);
459 test(statDir==KErrNone);
461 result=TheFs.RmDir(_L("C:\\SILLY\\SILLIER\\SILLIEST\\"));
462 test((result==KErrNone)||(result==KErrAlreadyExists));
463 result=TheFs.RmDir(_L("C:\\SILLY\\SILLIER\\"));
464 test((result==KErrNone)||(result==KErrAlreadyExists));
465 result=TheFs.RmDir(_L("C:\\SILLY\\"));
466 test((result==KErrNone)||(result==KErrAlreadyExists));
470 LOCAL_C void DoTests()
480 GLDEF_D void CallTestsL(void)
490 TBuf<13> dirBuf=_L("?:\\F32-TST\\");
493 if (IsSessionDriveLFFS(TheFs,driveLetter))
495 test.Printf(_L("DoTestsL(): Skipped: test does not run on LFFS.\n"));
499 test.Start(_L("Testing filesystem"));
500 TInt r=TheNotifyFs.Connect();
502 TFileName sessionPath;
504 test(HAL::Get(HAL::EMachineUid,uid)==KErrNone);
505 if(uid==HAL::EMachineUid_Cogent || uid==HAL::EMachineUid_IQ80310 || uid==HAL::EMachineUid_X86PC)
507 test.Printf(_L("WARNING: d: not tested on cogent or IQ80310 \n"));
511 #if !defined(__WINS__)
513 r=TheFs.MkDir(_L("C:\\F32-TST\\"));
514 test((r==KErrNone)||(r==KErrAlreadyExists));
516 if(KErrNone == TheFs.DriveList(drvList))
519 //should be successful, otherwise it means a system w/o any drive!!!
520 for(i=0;i<KMaxDrives;i++)
522 TDriveInfo driveInfo;
524 && (KErrNone == TheFs.Drive(driveInfo, i))
525 && (driveInfo.iType == EMediaHardDisk)
526 && (driveInfo.iDriveAtt & KDriveAttRemovable))
529 test.Printf(_L("RemovableDrive = %d\n"),RemovableDrive);
535 test.Printf(_L("No Removable media found! Testing discontinued.\n"));
536 User::Exit(KErrNone);
541 test.Printf(_L("No Drive found! Testing discontinued.\n"));
542 User::Exit(KErrNone);
545 r=RFs::DriveToChar(RemovableDrive,driveChar);
548 if(gDriveToTest == 'C')
549 dirBuf[0] = (TText)driveChar;
551 dirBuf[0] = (TText)gDriveToTest;
553 r=TheFs.MkDir(dirBuf);
554 if ((r!=KErrNone)||(r!=KErrAlreadyExists))
556 test.Printf(_L("TEST REQUIRES A CF CARD - "));
557 //test.Printf(_L("PUT A VALID CARD IN AND PRESS A KEY..."));
559 r=TheFs.MkDir(dirBuf);
561 test((r==KErrNone)||(r==KErrAlreadyExists));
563 // Set the notification session path to the test directory on C drive
564 sessionPath=_L("C:\\F32-TST\\");
565 r=TheNotifyFs.SetSessionPath(sessionPath);
570 test.Printf(_L("Error: %d\n"),r);
574 // Set the notification session path to the test directory on gDriveToTest
575 if(gDriveToTest == 'C')
576 sessionPath[0] = (TText)driveChar;
578 sessionPath[0] = (TText)gDriveToTest;
581 r=TheNotifyFs.SetSessionPath(sessionPath);
587 test.Printf(_L("Error: %d\n"),r);
590 #elif defined (__WINS__)
591 r=TheFs.MkDir(_L("X:\\F32-TST\\"));
592 test((r==KErrNone)||(r==KErrAlreadyExists));
593 r=TheFs.MkDir(_L("Y:\\F32-TST\\"));
594 test((r==KErrNone)||(r==KErrAlreadyExists));
595 // Set session path to test directory on Y drive
596 r=TheNotifyFs.SetSessionPath(_L("Y:\\F32-TST\\"));
600 test.Printf(_L("Error: %d\n"),r);
604 //we have no X drive on eka2 yet
605 // Set session path to test directory on X drive
606 // r=TheNotifyFs.SetSessionPath(_L("X:\\F32-TST\\"));
607 // test(r==KErrNone);
608 // TRAP(r,DoTests());
611 test.Printf(_L("Error: %d\n"),r);