| author | John Imhofe | 
| Mon, 22 Feb 2010 14:56:39 +0000 | |
| changeset 17 | c1574200dd96 | 
| parent 4 | 56f325a607ea | 
| child 43 | c1f20ce4abcf | 
| permissions | -rw-r--r-- | 
| 0 | 1 | // Copyright (c) 2008-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 | // f32test\server\t_notifier.cpp | |
| 15 | // | |
| 16 | // | |
| 17 | ||
| 18 | #include <f32file.h> | |
| 19 | #include <e32test.h> | |
| 20 | #include <e32svr.h> | |
| 21 | #include <hal.h> | |
| 22 | #include "t_server.h" | |
| 23 | #include "t_chlffs.h" | |
| 24 | #include "t_notify_plugin.h" | |
| 25 | ||
| 26 | const TInt KNotificationHeaderSize = (sizeof(TUint16)*2)+(sizeof(TUint)); | |
| 27 | const TInt KMinNotificationBufferSize = 2*KNotificationHeaderSize + 2*KMaxFileName; | |
| 28 | ||
| 29 | ||
| 30 | RTest test(_L("T_NOTIFIER"));
 | |
| 31 | const TInt KMaxHeapSize = 0x800000; | |
| 32 | TInt globalDriveNum; | |
| 33 | ||
| 34 | void DismountPlugin() | |
| 35 | 	{
 | |
| 36 | TheFs.DismountPlugin(KNotifyPluginName); | |
| 37 | TheFs.RemovePlugin(KNotifyPluginFileName); | |
| 38 | } | |
| 39 | ||
| 40 | inline void safe_test(RTest& aTest, TInt aError, TInt aLine, TText* aName) | |
| 41 | 	{
 | |
| 42 | if(aError!=KErrNone) | |
| 43 | 		{
 | |
| 44 | 		test.Printf(_L(": ERROR : %d received on line %d\n"),aError,aLine);
 | |
| 45 | DismountPlugin(); | |
| 46 | aTest.operator()(aError==KErrNone,aLine,(TText*)aName); | |
| 47 | } | |
| 48 | } | |
| 49 | ||
| 50 | // Used by TestMultipleNotificationsL() to show which line the function is called from | |
| 51 | inline void safe_test(RTest& aTest, TInt aError, TInt aLine, TInt aLineCall) | |
| 52 | 	{
 | |
| 53 | if(aError != KErrNone) | |
| 54 | 		{
 | |
| 55 | 		aTest.Printf(_L(": ERROR : %d received on line %d\n"), aError, aLine);
 | |
| 56 | 		aTest.Printf(_L(": ERROR : Function called from line number: %d\n"), aLineCall);
 | |
| 57 | aTest.operator()(aError == KErrNone, aLine); | |
| 58 | } | |
| 59 | } | |
| 60 | ||
| 61 | // Prints out the filename | |
| 62 | #define ExpandMe(X) L ## X | |
| 63 | #define Expand(X) ExpandMe(X) | |
| 64 | ||
| 65 | namespace t_notification | |
| 66 | 	{
 | |
| 67 | enum EOperation | |
| 68 | 		{
 | |
| 69 | //TFsNotification::ECreate | |
| 70 | EFileReplace, | |
| 71 | EFileCreate, | |
| 72 | EFileCreate_subs, //Create files in subdir, watch subdirs | |
| 73 | EFileCreate_subs_nowatch, //Create files in subdir, do not monitor subdirs | |
| 74 | EFileCreate_txt_nowatch, //Create .txt files in subdir, do not monitor subdirs | |
| 75 | EFileCreate_txt, //Create .txt files | |
| 76 | EFsMkDir, //Create directory | |
| 77 | //TFsNotification::EAttribute | |
| 78 | EFileSetAtt, | |
| 79 | EFileSetAtt_subs, //Set attributes in subdir | |
| 80 | EFileSet, | |
| 81 | EFsSetEntry, | |
| 82 | //TFsNotification::ERename | |
| 83 | EFsReplace, //Replace file | |
| 84 | EFsRename, //Rename file | |
| 85 | EFsRename_dir, //Rename directory | |
| 86 | EFileRename, | |
| 87 | EFileRename_wild, //Rename file using wildcard name | |
| 88 | //TFsNotification::EDelete | |
| 89 | EFsDelete, //Delete file | |
| 90 | EFsRmDir, //Remove directory | |
| 91 | EFsRmDir_nonEmpty, //Remove non-empty directory, which will return KErrInUse | |
| 92 | EFsRmDir_wild, //Remove subdirectory using wildcard name | |
| 93 | //TFsNotification::EFileChange | |
| 94 | EFileWrite, | |
| 95 | EFileWrite_samesize, //Write to file without changing its size | |
| 96 | EFileWrite_async, //Asynchronous write | |
| 97 | EFileSetSize, | |
| 98 | //TFsNotification::EVolumeName | |
| 99 | ESetVolumeLabel, | |
| 100 | //TFsNotification::EDriveName | |
| 101 | ESetDriveName, | |
| 102 | //TFsNotification::EMediaChange | |
| 103 | EMount, | |
| 104 | EDismount, | |
| 105 | EMountScan, | |
| 106 | EMountDismount, | |
| 107 | EFormat, | |
| 108 | EMediaCardRemoval, | |
| 109 | EMediaCardInsertion, | |
| 110 | ERawDiskWrite, | |
| 111 | //Multiple Filters | |
| 112 | EAllOps1, //Create/Replace and Delete | |
| 113 | EAllOps2, //Create/Replace, FileChange(Write) and Delete | |
| 114 | EAllOps3, //Create/Replace, FileChange(SetSize) and Delete | |
| 115 | EAllOps4, //Create/Replace, Attribute(SetAtt) and Delete | |
| 116 | EAllOps5, //Create/Replace and Rename | |
| 117 | EAllOps6, //VolumeName and DriveName | |
| 118 | ECFileManMove //Create filex in monitored directory, write 4, move to unmonitored, setsize 8, move back, delete | |
| 119 | }; | |
| 120 | } | |
| 121 | ||
| 122 | // Package filename and semaphore for thread | |
| 123 | struct SThreadPackage | |
| 124 | 	{
 | |
| 125 | TFileName iFileName; | |
| 126 | RSemaphore iBarrier; | |
| 127 | }; | |
| 128 | ||
| 129 | struct SThreadPackageDualSemaphore | |
| 130 | 	{
 | |
| 131 | TFileName iFileName; | |
| 132 | RSemaphore iBarrier; | |
| 133 | RSemaphore iBarrier2; | |
| 134 | }; | |
| 135 | ||
| 136 | struct SThreadPackage2 | |
| 137 | 	{
 | |
| 138 | TInt iTestCase; | |
| 139 | RSemaphore iBarrier; | |
| 140 | }; | |
| 141 | ||
| 142 | // Used by TestMultipleNotificationsL | |
| 143 | struct SThreadPackageMultiple | |
| 144 | 	{
 | |
| 145 | TFileName iString; //Commonly stores the filename | |
| 146 | TFileName iFileName; //Commonly stores the path (not inc filename) | |
| 147 | RSemaphore iBarrier; | |
| 148 | t_notification::EOperation iOperation; | |
| 149 | TFsNotification::TFsNotificationType iNotifyType; | |
| 150 | TInt iIterations; //# of times to 'do' something | |
| 151 | TInt iMaxNotifications; //# of notifications expected | |
| 152 | TInt iBufferSize; | |
| 153 | TInt iLineCall; //Line where the function is called from | |
| 154 | }; | |
| 155 | ||
| 156 | void PrintLine() | |
| 157 | 	{
 | |
| 158 | 	test.Printf(_L("======================================================================\n"));
 | |
| 159 | } | |
| 160 | ||
| 161 | ||
| 162 | // We should receive an EMediaChange notification even though we did not register for it | |
| 163 | void TestMediaCardNotificationWhenNotRegisteredForIt() | |
| 164 | 	{
 | |
| 165 | RFs fs; | |
| 166 | TInt r = fs.Connect(); | |
| 167 | test(r==KErrNone); | |
| 168 | ||
| 169 | CFsNotify* notify = NULL; | |
| 170 | TRAP(r,notify= CFsNotify::NewL(fs,KMinNotificationBufferSize)); | |
| 171 | ||
| 172 | TBuf<40> path; | |
| 173 | path.Append((TChar)gDriveToTest); | |
| 174 | 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 175 | ||
| 176 | TBuf<20> filename; | |
| 177 | 	filename.Append(_L("media.change1"));
 | |
| 178 | ||
| 179 | r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename); | |
| 180 | test(r==KErrNone); | |
| 181 | ||
| 182 | TRequestStatus status; | |
| 183 | r = notify->RequestNotifications(status); | |
| 184 | test(r==KErrNone); | |
| 185 | ||
| 186 | 	test.Printf(_L("*****************************************************************\n"));
 | |
| 187 | 	test.Printf(_L("Waiting 10 seconds.\n"));
 | |
| 188 | 	test.Printf(_L("This is a MANUAL test, it requires the removal of the media card.\n"));
 | |
| 189 | 	test.Printf(_L("PLEASE REMOVE THE MEDIA CARD. (DriveNumber %d)\n"),globalDriveNum);
 | |
| 190 | 	test.Printf(_L("Or press Ctrl + F5 on the emulator.\n"));
 | |
| 191 | 	test.Printf(_L("*****************************************************************\n"));
 | |
| 192 | RTimer timer1; | |
| 193 | r = timer1.CreateLocal(); | |
| 194 | test(r == KErrNone); | |
| 195 | TRequestStatus timeout; | |
| 196 | TTimeIntervalMicroSeconds32 time = 10000000; | |
| 197 | timer1.After(timeout,time); | |
| 198 | User::WaitForRequest(timeout,status); | |
| 199 | test(status.Int() != KRequestPending); | |
| 200 | timer1.Cancel(); | |
| 201 | timer1.Close(); | |
| 202 | ||
| 203 | const TFsNotification* notification = notify->NextNotification(); | |
| 204 | test(notification != NULL); | |
| 205 | TFsNotification::TFsNotificationType type = notification->NotificationType(); | |
| 206 | test(type == TFsNotification::EMediaChange); | |
| 207 | TBuf<2> drive; | |
| 208 | drive.Append((TChar)gDriveToTest); | |
| 209 | 	drive.Append(_L(":"));
 | |
| 210 | TPtrC drivePtr; | |
| 211 | r = notification->Path(drivePtr); | |
| 212 | test(r==KErrNone); | |
| 213 | r = drivePtr.Compare(drive); | |
| 214 | test(r==0); | |
| 215 | ||
| 216 | 	test.Printf(_L("*****************************************************************\n"));
 | |
| 217 | 	test.Printf(_L("Waiting 10 seconds.\n"));
 | |
| 218 | 	test.Printf(_L("This is a MANUAL test, it requires the insertion of the media card.\n"));
 | |
| 219 | 	test.Printf(_L("PLEASE INSERT THE MEDIA CARD. (DriveNumber %d)\n"),globalDriveNum);
 | |
| 220 | 	test.Printf(_L("Or press Ctrl + F5 on the emulator.\n"));
 | |
| 221 | 	test.Printf(_L("*****************************************************************\n"));
 | |
| 222 | ||
| 223 | notification = notify->NextNotification(); | |
| 224 | if(notification == NULL) | |
| 225 | 		{
 | |
| 226 | notify->RequestNotifications(status); | |
| 227 | RTimer timer2; | |
| 228 | r = timer2.CreateLocal(); | |
| 229 | test(r == KErrNone); | |
| 230 | TRequestStatus timeout2; | |
| 231 | timer2.After(timeout2,time); | |
| 232 | User::WaitForRequest(timeout2,status); | |
| 233 | test(status.Int() != KRequestPending); | |
| 234 | notification = notify->NextNotification(); | |
| 235 | timer2.Cancel(); | |
| 236 | timer2.Close(); | |
| 237 | } | |
| 238 | test(notification != NULL); | |
| 239 | type = notification->NotificationType(); | |
| 240 | test(type == TFsNotification::EMediaChange); | |
| 241 | ||
| 242 | delete notify; | |
| 243 | fs.Close(); | |
| 244 | } | |
| 245 | ||
| 246 | // Creates two sessions, removes the first one | |
| 247 | // and then checks if the second one still works | |
| 248 | TInt TestClientRemovalL() | |
| 249 | 	{
 | |
| 250 | RFs fs; | |
| 251 | TInt r = fs.Connect(); | |
| 252 | test(r==KErrNone); | |
| 253 | ||
| 254 | CFsNotify* notify1 = NULL; | |
| 255 | CFsNotify* notify2 = NULL; | |
| 256 | TRAP(r,notify1= CFsNotify::NewL(fs,KMinNotificationBufferSize); | |
| 257 | notify2= CFsNotify::NewL(fs,KMinNotificationBufferSize); | |
| 258 | ); | |
| 259 | if(r!=KErrNone) | |
| 260 | 		{
 | |
| 261 | delete notify1; | |
| 262 | delete notify2; | |
| 263 | test(r==KErrNone); | |
| 264 | } | |
| 265 | ||
| 266 | TBuf<40> path; | |
| 267 | path.Append((TChar)gDriveToTest); | |
| 268 | 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 269 | ||
| 270 | TBuf<15> filename; | |
| 271 | 	filename.Append(_L("create.file"));
 | |
| 272 | ||
| 273 | TBuf<40> fullname; | |
| 274 | fullname.Append(path); | |
| 275 | fullname.Append(filename); | |
| 276 | ||
| 277 | r = notify1->AddNotification((TUint)TFsNotification::ECreate,path,filename); | |
| 278 | test(r==KErrNone); | |
| 279 | r = notify2->AddNotification((TUint)TFsNotification::ECreate,path,filename); | |
| 280 | test(r==KErrNone); | |
| 281 | ||
| 282 | delete notify1; //Delete notify1 and ensure we still get notification on notify2 | |
| 283 | ||
| 284 | TRequestStatus status; | |
| 285 | r = notify2->RequestNotifications(status); | |
| 286 | test(r==KErrNone); | |
| 287 | ||
| 288 | RFile file; | |
| 289 | file.Replace(fs,fullname,EFileWrite); //Replace produces Create notification | |
| 290 | file.Close(); | |
| 291 | ||
| 292 | RTimer tim; | |
| 293 | r = tim.CreateLocal(); | |
| 294 | test(r==KErrNone); | |
| 295 | ||
| 296 | TRequestStatus timStatus; | |
| 297 | TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds | |
| 298 | tim.After(timStatus,time); | |
| 299 | ||
| 300 | User::WaitForRequest(status,timStatus); | |
| 301 | test(status!=KRequestPending); | |
| 302 | ||
| 303 | r = fs.Delete(fullname); | |
| 304 | test(r==KErrNone); | |
| 305 | ||
| 306 | delete notify2; | |
| 307 | tim.Close(); | |
| 308 | fs.Close(); | |
| 309 | return KErrNone; | |
| 310 | } | |
| 311 | ||
| 312 | /* | |
| 313 | * This tests that u can set and receive notifications in the root | |
| 314 | * of a drive. | |
| 315 | * | |
| 316 | * (something which was apparently not possible on RFs::NotifyChange) | |
| 317 | */ | |
| 318 | TInt TestRootDriveNotifications() | |
| 319 | 	{
 | |
| 320 | 	test.Next(_L("TestRootDriveNotifications"));
 | |
| 321 | RFs fs; | |
| 322 | fs.Connect(); | |
| 323 | ||
| 324 | CFsNotify* notify = NULL; | |
| 325 | ||
| 326 | TRAPD(r,notify = CFsNotify::NewL(fs,KMinNotificationBufferSize);); | |
| 327 | test(r==KErrNone); | |
| 328 | test(notify!=NULL); | |
| 329 | ||
| 330 | TBuf<40> path; | |
| 331 | path.Append((TChar)gDriveToTest); | |
| 332 | 	path.Append(_L(":\\"));
 | |
| 333 | ||
| 334 | TBuf<15> filename; | |
| 335 | 	filename.Append(_L("*"));
 | |
| 336 | ||
| 337 | r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename); | |
| 338 | test(r==KErrNone); | |
| 339 | ||
| 340 | TRequestStatus status; | |
| 341 | r = notify->RequestNotifications(status); | |
| 342 | test(r==KErrNone); | |
| 343 | ||
| 344 | RFile file; | |
| 345 | TBuf<40> filePath; | |
| 346 | filePath.Append((TChar)gDriveToTest); | |
| 347 | 	filePath.Append(_L(":\\file.root"));
 | |
| 348 | r = file.Replace(fs,filePath,EFileRead); | |
| 349 | test(r==KErrNone); | |
| 350 | file.Close(); | |
| 351 | ||
| 352 | TRequestStatus s2; | |
| 353 | RTimer tim; | |
| 354 | test(tim.CreateLocal()==KErrNone); | |
| 355 | TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds | |
| 356 | tim.After(s2,time); | |
| 357 | User::WaitForRequest(status,s2); | |
| 358 | test(status!=KRequestPending); | |
| 359 | ||
| 360 | delete notify; | |
| 361 | notify = NULL; | |
| 362 | tim.Close(); | |
| 363 | fs.Close(); | |
| 364 | return KErrNone; | |
| 365 | } | |
| 366 | ||
| 367 | /* | |
| 368 | * Creates and deletes loads of CFsNotify objects and makes sure they're all | |
| 369 | * cleaned up afterwards. | |
| 370 | */ | |
| 371 | TInt TestNewDeleteCFsNotify(TInt aIterations) | |
| 372 | 	{
 | |
| 373 | RPointerArray<CFsNotify> array; | |
| 374 | TInt inArray = 0; | |
| 375 | TInt r = KErrNone; | |
| 376 | for(TInt i = 0; i < aIterations; i++) | |
| 377 | 		{
 | |
| 378 | CFsNotify* notify = NULL; | |
| 379 | TRAP(r,notify = CFsNotify::NewL(TheFs,500)); | |
| 380 | if(r==KErrNone) | |
| 381 | 			{
 | |
| 382 | test(notify!=NULL); | |
| 383 | r = array.Append(notify); | |
| 384 | if(r==KErrNone) | |
| 385 | 				{
 | |
| 386 | inArray++; | |
| 387 | } | |
| 388 | else | |
| 389 | 				{
 | |
| 390 | delete notify; | |
| 391 | break; | |
| 392 | } | |
| 393 | } | |
| 394 | else | |
| 395 | 			{
 | |
| 396 | break; | |
| 397 | } | |
| 398 | } | |
| 399 | ||
| 400 | for(TInt j = inArray-1; j >= 0; j--) | |
| 401 | 		{
 | |
| 402 | CFsNotify* notify = (CFsNotify*)array[j]; | |
| 403 | array.Remove(j); | |
| 404 | delete notify; | |
| 405 | } | |
| 406 | ||
| 407 | array.Reset(); | |
| 408 | array.Close(); | |
| 409 | return KErrNone; | |
| 410 | } | |
| 411 | ||
| 412 | ||
| 413 | /* | |
| 414 | * Creates a file | |
| 415 | * Used in SimpleTest1L(), TestTwoDoersL() TestTwoWatchersL(), TestCancelNotificationL() | |
| 416 | */ | |
| 417 | TInt SimpleSingleNotificationTFDoer(TAny* aAny) | |
| 418 | 	{
 | |
| 419 | SThreadPackageDualSemaphore pkgDoer = *(SThreadPackageDualSemaphore*)aAny; | |
| 420 | 	RTest simpleTestDoer(_L("SimpleSingleNotificationTFDoer"));
 | |
| 421 | 	simpleTestDoer.Start(_L("SimpleSingleNotificationTFDoer"));
 | |
| 422 | TBuf<40> path; | |
| 423 | path.Append(gDriveToTest); | |
| 424 | 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 425 | path.Append(pkgDoer.iFileName); | |
| 426 | ||
| 427 | //Delete file so we definitely get a create notification | |
| 428 | RFs fs; | |
| 429 | TInt r = fs.Connect(); | |
| 430 | 	safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 431 | r = fs.Delete(path); | |
| 432 | if(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound) | |
| 433 | r = KErrNone; | |
| 434 | 	safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 435 | r = fs.MkDirAll(path); | |
| 436 | if(r==KErrNone || r==KErrAlreadyExists) | |
| 437 | r = KErrNone; | |
| 438 | 	safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 439 | ||
| 440 | 	simpleTestDoer.Printf(_L("SimpleSingleNotificationTFDoer - Create File %S\n"),&path);
 | |
| 441 | //Create file | |
| 442 | RFile file; | |
| 443 | r = file.Create(fs,path,EFileWrite); | |
| 444 | 	safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 445 | file.Close(); | |
| 446 | ||
| 447 | fs.Close(); | |
| 448 | simpleTestDoer.End(); | |
| 449 | simpleTestDoer.Close(); | |
| 450 | return KErrNone; | |
| 451 | } | |
| 452 | ||
| 453 | /* | |
| 454 | * Watches 1 file creation | |
| 455 | * Used in SimpleTest1L() | |
| 456 | */ | |
| 457 | TInt SimpleSingleNotificationTFWatcher(TAny* aAny) | |
| 458 | 	{
 | |
| 459 | CTrapCleanup* cleanup; | |
| 460 | cleanup = CTrapCleanup::New(); | |
| 461 | RThread thread; | |
| 462 | TUint64 threadId = thread.Id().Id(); | |
| 463 | ||
| 464 | SThreadPackage pkgDoer = *(SThreadPackage*)aAny; | |
| 465 | RSemaphore& simpleBarrierTest = pkgDoer.iBarrier; | |
| 466 | ||
| 467 | 	RTest simpleTestWatcher(_L("SimpleSingleNotificationTFWatcher"));
 | |
| 468 | 	simpleTestWatcher.Start(_L("SimpleSingleNotificationTFWatcher"));
 | |
| 469 | ||
| 470 | RFs fs; | |
| 471 | fs.Connect(); | |
| 472 | ||
| 473 | 	simpleTestWatcher.Printf(_L("SimpleSingleNotificationTFWatcher(%d) - Create CFsNotify\n"),threadId);
 | |
| 474 | CFsNotify* notify = NULL; | |
| 475 | TRAPD(r,notify = CFsNotify::NewL(fs,100); ); | |
| 476 | 	safe_test(simpleTestWatcher,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 477 | TBuf<40> path; | |
| 478 | path.Append(gDriveToTest); | |
| 479 | 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
 | |
| 480 | ||
| 481 | TBuf<20> filename; | |
| 482 | filename.Append(pkgDoer.iFileName); | |
| 483 | ||
| 484 | TBuf<40> fullname; | |
| 485 | fullname.Append(path); | |
| 486 | fullname.Append(filename); | |
| 487 | ||
| 488 | 	simpleTestWatcher.Printf(_L("SimpleSingleNotificationTFWatcher - Add Notification for %S\n"),&path);
 | |
| 489 | r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename); | |
| 490 | 	safe_test(simpleTestWatcher,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 491 | TRequestStatus status; | |
| 492 | 	simpleTestWatcher.Printf(_L("SimpleSingleNotificationTFWatcher(%d) - Request Notifications\n"),threadId);
 | |
| 493 | r = notify->RequestNotifications(status); | |
| 494 | 	safe_test(simpleTestWatcher,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 495 | ||
| 496 | simpleBarrierTest.Signal(); | |
| 497 | ||
| 498 | 	simpleTestWatcher.Printf(_L("SimpleSingleNotificationTFWatcher(%d) - Wait for status to return\n"),threadId);
 | |
| 499 | User::WaitForRequest(status); | |
| 500 | ||
| 501 | 	simpleTestWatcher.Printf(_L("(%d) NextNotification\n"),threadId);
 | |
| 502 | const TFsNotification* notification = notify->NextNotification(); | |
| 503 | //Test notification is not null. | |
| 504 | //We should be getting 1 notification. | |
| 505 | if(notification == NULL) | |
| 506 | 		safe_test(simpleTestWatcher,KErrNotFound,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 507 | ||
| 508 | 	simpleTestWatcher.Printf(_L("(%d) - Notification Type\n"),threadId);
 | |
| 509 | TFsNotification::TFsNotificationType notificationType = ((TFsNotification*)notification)->NotificationType(); | |
| 510 | if(notificationType != TFsNotification::ECreate) | |
| 511 | 		safe_test(simpleTestWatcher,KErrGeneral,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 512 | 	simpleTestWatcher.Printf(_L("(%d) - Notification Path\n"),threadId);
 | |
| 513 | TPtrC _pathC; | |
| 514 | ((TFsNotification*)notification)->Path(_pathC); | |
| 515 | 	simpleTestWatcher.Printf(_L("Notification Path = %S\n"),&_pathC);
 | |
| 516 | TBuf<40> _path; | |
| 517 | _path.Copy(_pathC); | |
| 518 | if(_path.Match(fullname)!=KErrNone) | |
| 519 | 		safe_test(simpleTestWatcher,KErrBadName,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 520 | ||
| 521 | /* | |
| 522 | TInt driveNumber = 0; | |
| 523 | TInt gDriveNum = -1; | |
| 524 | notification->DriveNumber(driveNumber); | |
| 525 | RFs::CharToDrive(_pathC[0],gDriveNum); | |
| 526 | if(driveNumber != gDriveNum) | |
| 527 | 		safe_test(simpleTestWatcher,KErrBadHandle,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 528 | ||
| 529 | TUid uid; | |
| 530 | TUint32 realUID = 0x76543210; | |
| 531 | r = notification->UID(uid); | |
| 532 | 	safe_test(simpleTestWatcher,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 533 | 	safe_test(simpleTestWatcher,(realUID == uid.iUid)==1,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 534 | */ | |
| 535 | delete notify; | |
| 536 | fs.Close(); | |
| 537 | simpleTestWatcher.End(); | |
| 538 | simpleTestWatcher.Close(); | |
| 539 | delete cleanup; | |
| 540 | return KErrNone; | |
| 541 | } | |
| 542 | ||
| 543 | /* | |
| 544 | * SimpleTest1L - Runs a simple Create test, gets 1 notification, calls type, path etc and exits | |
| 545 | * Two threads: 1 watcher, 1 doer | |
| 546 | */ | |
| 547 | TInt SimpleCreateTestL() | |
| 548 | 	{
 | |
| 549 | 	test.Next(_L("SimpleTest"));
 | |
| 550 | RFs fs; | |
| 551 | fs.Connect(); | |
| 552 | _LIT(KFileName,"simple.create"); | |
| 553 | SThreadPackage pkgDoer; | |
| 554 | pkgDoer.iFileName = KFileName; | |
| 555 | ||
| 556 | SThreadPackage watcherPkg; | |
| 557 | watcherPkg.iFileName = KFileName; | |
| 558 | User::LeaveIfError(pkgDoer.iBarrier.CreateLocal(0)); | |
| 559 | User::LeaveIfError(watcherPkg.iBarrier.CreateLocal(0)); | |
| 560 | RThread watcher; | |
| 561 | RThread doer; | |
| 562 | 	watcher.Create(_L("Simple1WatcherThread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcherPkg);
 | |
| 563 | 	doer.Create(_L("Simple1DoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer);
 | |
| 564 | watcher.Resume(); | |
| 565 | watcherPkg.iBarrier.Wait(); //Wait till Watcher has requested notification | |
| 566 | doer.Resume(); | |
| 567 | ||
| 568 | TRequestStatus status; | |
| 569 | doer.Logon(status); | |
| 570 | User::WaitForRequest(status); | |
| 571 | 	test.Printf(_L("SimpleCreateTest - Doer Exit Reason = %d\n"),doer.ExitReason());
 | |
| 572 | 	safe_test(test,doer.ExitReason(),__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 573 | ||
| 574 | 	RDebug::Print(_L("Line %d"),__LINE__);
 | |
| 575 | ||
| 576 | ||
| 577 | watcher.Logon(status); | |
| 578 | RTimer timer1; | |
| 579 | TInt r = timer1.CreateLocal(); | |
| 580 | 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 581 | TRequestStatus timeout; | |
| 582 | TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds | |
| 583 | timer1.After(timeout,time); | |
| 584 | User::WaitForRequest(timeout,status); | |
| 585 | test(status.Int() != KRequestPending); | |
| 586 | timer1.Cancel(); | |
| 587 | timer1.Close(); | |
| 588 | ||
| 589 | ||
| 590 | // User::WaitForRequest(status); | |
| 591 | 	test.Printf(_L("SimpleCreateTest - Watcher Exit Reason = %d\n"),watcher.ExitReason());
 | |
| 592 | 	safe_test(test,watcher.ExitReason(),__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 593 | ||
| 594 | CLOSE_AND_WAIT(doer); | |
| 595 | CLOSE_AND_WAIT(watcher); | |
| 596 | ||
| 597 | pkgDoer.iBarrier.Close(); | |
| 598 | watcherPkg.iBarrier.Close(); | |
| 599 | fs.Close(); | |
| 600 | return KErrNone; | |
| 601 | } | |
| 602 | ||
| 603 | // Doer thread for TestMultipleNotificationsL | |
| 604 | TInt MultipleNotificationTFDoer(TAny* aAny) | |
| 605 | 	{
 | |
| 606 | 	RDebug::Print(_L("MultipleNotificationTFDoer - Start, Line %d"), __LINE__);
 | |
| 607 | SThreadPackageMultiple pkgDoer = *(SThreadPackageMultiple*)aAny; | |
| 608 | 	RTest multipleTestDoer(_L("MultipleNotificationTFDoer"));
 | |
| 609 | 	multipleTestDoer.Start(_L("Multi-Doer"));
 | |
| 610 | 	multipleTestDoer.Printf(_L("MultipleNotificationTFDoer - Line %d"),__LINE__);
 | |
| 611 | TBuf<40> basepath; | |
| 612 | basepath.Append(gDriveToTest); | |
| 613 | 	basepath.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 614 | ||
| 615 | RThread thread; | |
| 616 | 	RDebug::Print(_L("MultipleNotificationTFDoer - Line %d"), __LINE__);
 | |
| 617 | TUint64 threadID = thread.Id().Id(); | |
| 618 | 	RDebug::Print(_L("MultipleNotificationTFDoer - Line %d"), __LINE__);
 | |
| 619 | ||
| 620 | //Delete file so we definitely get a create notification | |
| 621 | RFs fs; | |
| 622 | TInt r = fs.Connect(); | |
| 623 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 624 | ||
| 625 | TEntry entry; | |
| 626 | TBool wildcard = EFalse; | |
| 627 | TBuf<40> _path; | |
| 628 | _path.Append(basepath); | |
| 629 | _path.Append(pkgDoer.iFileName); | |
| 630 | _path.Append(pkgDoer.iString); | |
| 631 | r = fs.Entry(_path, entry); | |
| 632 | if (pkgDoer.iNotifyType != TFsNotification::EMediaChange && | |
| 633 | pkgDoer.iNotifyType != TFsNotification::EDriveName && | |
| 634 | pkgDoer.iNotifyType != TFsNotification::EVolumeName && | |
| 635 | pkgDoer.iOperation != t_notification::EAllOps6) | |
| 636 | 		{
 | |
| 637 | if (r == KErrBadName) | |
| 638 | 			{
 | |
| 639 | wildcard = ETrue; | |
| 640 | } | |
| 641 | if(r != KErrNone && r != KErrPathNotFound && r != KErrNotFound && r != KErrBadName) | |
| 642 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 643 | if (r == KErrNone && !entry.IsDir() && pkgDoer.iOperation != t_notification::EFsDelete && !wildcard && | |
| 644 | pkgDoer.iOperation != t_notification::EFsRmDir && pkgDoer.iOperation != t_notification::EFsRmDir_nonEmpty) | |
| 645 | 			{
 | |
| 646 | r = fs.Delete(_path); | |
| 647 | if(r != KErrNone && r != KErrPathNotFound && r != KErrNotFound) | |
| 648 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 649 | } | |
| 650 | r = fs.MkDirAll(basepath); | |
| 651 | if(r != KErrNone && r != KErrAlreadyExists) | |
| 652 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 653 | } | |
| 654 | ||
| 655 | 	multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
 | |
| 656 | ||
| 657 | switch(pkgDoer.iOperation) | |
| 658 | 		{
 | |
| 659 | case t_notification::EFileReplace: | |
| 660 | 			{
 | |
| 661 | RFile file; | |
| 662 | //Generate Notification | |
| 663 | 			multipleTestDoer.Printf(_L("File Replace - (%d)\n"),threadID);
 | |
| 664 | r = file.Replace(fs,_path,EFileWrite); //RFile::Replace -> TFsNotification::ECreate | |
| 665 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 666 | file.Close(); | |
| 667 | ||
| 668 | r = fs.Delete(_path); | |
| 669 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 670 | break; | |
| 671 | } | |
| 672 | case t_notification::EFileCreate: | |
| 673 | case t_notification::EFileCreate_txt_nowatch: | |
| 674 | case t_notification::EFileCreate_txt: | |
| 675 | case t_notification::EAllOps1: | |
| 676 | 			{
 | |
| 677 | 			multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
 | |
| 678 | if(wildcard) | |
| 679 | 				{
 | |
| 680 | for (TInt i = 0; i < pkgDoer.iIterations; i++) | |
| 681 | 					{
 | |
| 682 | 					multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
 | |
| 683 | RFile file; | |
| 684 | TBuf<40> path; | |
| 685 | path.Append(basepath); | |
| 686 | path.AppendNum(i); | |
| 687 | if(pkgDoer.iOperation == t_notification::EFileCreate_txt) | |
| 688 | 						{
 | |
| 689 | //Create file with different extension (no notification) | |
| 690 | 						path.Append(_L(".wrg"));
 | |
| 691 | fs.Delete(path); | |
| 692 | 						multipleTestDoer.Printf(_L("File Create (wrong extension) - %S (%d)\n"),&path,threadID);
 | |
| 693 | r = file.Create(fs, path, EFileWrite); | |
| 694 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 695 | //Change path to contain file with correct extension (notification occurs) | |
| 696 | 						path.Replace(path.Length()-3,3,_L("txt"));
 | |
| 697 | } | |
| 698 | else if(pkgDoer.iOperation == t_notification::EFileCreate_txt_nowatch) | |
| 699 | 					    {
 | |
| 700 | 					    path.Append(_L(".txt"));
 | |
| 701 | } | |
| 702 | fs.Delete(path); | |
| 703 | ||
| 704 | 					multipleTestDoer.Printf(_L("File Create - %S (%d)\n"),&path,threadID);
 | |
| 705 | r = file.Create(fs, path, EFileWrite); | |
| 706 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 707 | file.Close(); | |
| 708 | r = fs.Delete(path); | |
| 709 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 710 | } | |
| 711 | } | |
| 712 | else | |
| 713 | 				{
 | |
| 714 | 				multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
 | |
| 715 | for(TInt i = 0; i < pkgDoer.iIterations; i++) | |
| 716 | 					{
 | |
| 717 | 					multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
 | |
| 718 | RFile file; | |
| 719 | 					multipleTestDoer.Printf(_L("File Create - %S (%d)\n"),&_path,threadID);
 | |
| 720 | r = file.Create(fs,_path,EFileWrite); | |
| 721 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 722 | file.Close(); | |
| 723 | r = fs.Delete(_path); | |
| 724 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 725 | } | |
| 726 | } | |
| 727 | break; | |
| 728 | } | |
| 729 | case t_notification::EFileCreate_subs: | |
| 730 | case t_notification::EFileCreate_subs_nowatch: | |
| 731 | 			{
 | |
| 732 | if (wildcard) | |
| 733 | 				{
 | |
| 734 | for (TInt i = 0; i < pkgDoer.iIterations; i++) | |
| 735 | 					{
 | |
| 736 | RFile file; | |
| 737 | TBuf<40> path; | |
| 738 | path.Append(basepath); | |
| 739 | 					path.Append(_L("SubDir\\"));
 | |
| 740 | r = fs.MkDirAll(path); | |
| 741 | if(r != KErrNone && r != KErrAlreadyExists) | |
| 742 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 743 | path.AppendNum(i); | |
| 744 | fs.Delete(path); | |
| 745 | 					multipleTestDoer.Printf(_L("File Create - %S (%d)\n"),&path,threadID);
 | |
| 746 | r = file.Create(fs, path, EFileWrite); | |
| 747 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 748 | file.Close(); | |
| 749 | r = fs.Delete(path); | |
| 750 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 751 | } | |
| 752 | } | |
| 753 | break; | |
| 754 | } | |
| 755 | case t_notification::EFileWrite: | |
| 756 | case t_notification::EAllOps2: | |
| 757 | 			{
 | |
| 758 | //Works on single file | |
| 759 | RFile file; | |
| 760 | TBuf<40> path; | |
| 761 | path.Append(basepath); | |
| 762 | path.Append(pkgDoer.iFileName); | |
| 763 | path.Append(pkgDoer.iString); | |
| 764 | r = file.Replace(fs,path,EFileWrite); | |
| 765 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 766 | for(TInt i = 0; i < pkgDoer.iIterations; i++) | |
| 767 | 				{
 | |
| 768 | 				multipleTestDoer.Printf(_L("File Write - %S (%d)\n"),&path,threadID);
 | |
| 769 | 				r = file.Write(4*i,_L8("abcd"));
 | |
| 770 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 771 | //If cache is enabled, a notification is received only when the cache is flushed | |
| 772 | //We flush the file to make this a general test | |
| 773 | 				multipleTestDoer.Printf(_L("File Flush - (%d)\n"),threadID);
 | |
| 774 | r = file.Flush(); | |
| 775 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 776 | } | |
| 777 | file.Close(); | |
| 778 | r = fs.Delete(path); | |
| 779 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 780 | break; | |
| 781 | } | |
| 782 | case t_notification::EFileWrite_samesize: | |
| 783 | 			{
 | |
| 784 | RFile file; | |
| 785 | TBuf<40> path; | |
| 786 | path.Append(basepath); | |
| 787 | path.Append(pkgDoer.iFileName); | |
| 788 | path.Append(pkgDoer.iString); | |
| 789 | r = file.Replace(fs,path,EFileWrite); | |
| 790 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 791 | 			multipleTestDoer.Printf(_L("File Write - %S (%d)\n"),&path,threadID);
 | |
| 792 | 			r = file.Write(0,_L8("abcd"));
 | |
| 793 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 794 | ||
| 795 | //If cache is enabled, a notification is received only when the cache is flushed | |
| 796 | //We flush the file to make this a general test | |
| 797 |             multipleTestDoer.Printf(_L("File Flush - (%d)\n"),threadID);
 | |
| 798 | r = file.Flush(); | |
| 799 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 800 | ||
| 801 | for(TInt i = 0; i < pkgDoer.iIterations; i++) | |
| 802 | 				{
 | |
| 803 | TBuf<2> toWrite; | |
| 804 | toWrite.AppendNum(i); | |
| 805 | 				multipleTestDoer.Printf(_L("File Write - %S (%d)\n"),&path,threadID);
 | |
| 806 | r = file.Write(0,(TDesC8&)toWrite); | |
| 807 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 808 | 				multipleTestDoer.Printf(_L("File Flush - (%d)\n"),threadID);
 | |
| 809 | r = file.Flush(); | |
| 810 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 811 | } | |
| 812 | file.Close(); | |
| 813 | r = fs.Delete(path); | |
| 814 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 815 | break; | |
| 816 | } | |
| 817 | case t_notification::EFileWrite_async: | |
| 818 | 			{
 | |
| 819 | RFile file; | |
| 820 | TBuf<40> path; | |
| 821 | path.Append(basepath); | |
| 822 | path.Append(pkgDoer.iFileName); | |
| 823 | path.Append(pkgDoer.iString); | |
| 824 | r = file.Replace(fs,path,EFileWrite); | |
| 825 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 826 | for(TInt i = 0; i < pkgDoer.iIterations; i++) | |
| 827 | 				{
 | |
| 828 | TRequestStatus status; | |
| 829 | 				file.Write(52*i, _L8("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), status);			
 | |
| 830 | User::WaitForRequest(status); | |
| 831 | 				multipleTestDoer.Printf(_L("File Write Async - %S (%d)\n"),&path,threadID);
 | |
| 832 | TInt fileSize; | |
| 833 | file.Size(fileSize); | |
| 834 | 				multipleTestDoer.Printf(_L("File Write Async - FileSize: %d\n"),fileSize);
 | |
| 835 | 				multipleTestDoer.Printf(_L("File Flush - (%d)\n"),threadID);
 | |
| 836 | r = file.Flush(); | |
| 837 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 838 | } | |
| 839 | file.Close(); | |
| 840 | r = fs.Delete(path); | |
| 841 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 842 | break; | |
| 843 | } | |
| 844 | case t_notification::EFileSetSize: | |
| 845 | case t_notification::EAllOps3: | |
| 846 | 			{
 | |
| 847 | //Works on single file | |
| 848 | RFile file; | |
| 849 | TBuf<40> path; | |
| 850 | path.Append(basepath); | |
| 851 | path.Append(pkgDoer.iFileName); | |
| 852 | path.Append(pkgDoer.iString); | |
| 853 | r = file.Replace(fs,path,EFileWrite); | |
| 854 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 855 | ||
| 856 | //Increase file size | |
| 857 | for(TInt i = 0; i < pkgDoer.iIterations; i++) | |
| 858 | 				{
 | |
| 859 | r = file.SetSize(4*(i+1)); | |
| 860 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 861 | 				multipleTestDoer.Printf(_L("File Set Size - %d (%d)\n"),4*(i+1),threadID);
 | |
| 862 | } | |
| 863 | ||
| 864 | //Decrease file size | |
| 865 | for(TInt j = pkgDoer.iIterations - 2; j >= 0; j--) | |
| 866 | 				{
 | |
| 867 | r = file.SetSize(4*(j+1)); | |
| 868 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 869 | 				multipleTestDoer.Printf(_L("File Set Size - %d (%d)\n"),4*(j+1),threadID);
 | |
| 870 | } | |
| 871 | ||
| 872 | file.Close(); | |
| 873 | r = fs.Delete(path); | |
| 874 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 875 | break; | |
| 876 | } | |
| 877 | case t_notification::EFsReplace: | |
| 878 | 			{
 | |
| 879 | TBuf<45> path; | |
| 880 | path.Append(basepath); | |
| 881 | path.Append(pkgDoer.iFileName); | |
| 882 | path.Append(pkgDoer.iString); | |
| 883 | path.AppendNum(0); | |
| 884 | ||
| 885 | RFile tempFile; | |
| 886 | 			multipleTestDoer.Printf(_L("RFs Replace (Create temp file) - (%d)\n"),threadID);
 | |
| 887 | r = tempFile.Replace(fs,_path,EFileWrite); | |
| 888 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 889 | tempFile.Close(); | |
| 890 | ||
| 891 | 			multipleTestDoer.Printf(_L("RFs Replace - (%d)\n"),threadID);
 | |
| 892 | r = fs.Replace(_path,path); //RFs::Replace -> TFsNotification::ERename | |
| 893 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 894 | ||
| 895 | r = fs.Delete(path); | |
| 896 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 897 | break; | |
| 898 | } | |
| 899 | case t_notification::EFsRename: | |
| 900 | 			{
 | |
| 901 | TBuf<45> path; | |
| 902 | path.Append(basepath); | |
| 903 | path.Append(pkgDoer.iFileName); | |
| 904 | path.Append(pkgDoer.iString); | |
| 905 | path.AppendNum(0); | |
| 906 | ||
| 907 | RFile file; | |
| 908 | r = file.Replace(fs,_path,EFileWrite); | |
| 909 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 910 | file.Close(); | |
| 911 | ||
| 912 | 			multipleTestDoer.Printf(_L("RFs Rename - (%d)\n"),threadID);
 | |
| 913 | r = fs.Rename(_path,path); | |
| 914 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 915 | ||
| 916 | r = fs.Delete(path); | |
| 917 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 918 | break; | |
| 919 | } | |
| 920 | case t_notification::EFileRename: | |
| 921 | case t_notification::EFileRename_wild: | |
| 922 | case t_notification::EAllOps5: | |
| 923 | 			{
 | |
| 924 | TBuf<45> path; | |
| 925 | path.Append(basepath); | |
| 926 | if (!wildcard) | |
| 927 | 				{
 | |
| 928 | path.Append(pkgDoer.iFileName); | |
| 929 | path.Append(pkgDoer.iString); | |
| 930 | } | |
| 931 | path.AppendNum(0); | |
| 932 | ||
| 933 | //Delete new path to ensure it does not exist | |
| 934 | r = fs.Delete(path); | |
| 935 | if(r != KErrNone && r != KErrNotFound && r != KErrPathNotFound) | |
| 936 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 937 | ||
| 938 | if (wildcard) | |
| 939 | 				{
 | |
| 940 | _path.Delete(_path.Length()-1,1); | |
| 941 | _path.AppendNum(9); | |
| 942 | } | |
| 943 | ||
| 944 | RFile file; | |
| 945 | r = file.Replace(fs, _path, EFileWrite); | |
| 946 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 947 | ||
| 948 | if (wildcard) | |
| 949 | 				{
 | |
| 950 | for(TInt i = 1; i <= pkgDoer.iIterations; i++) | |
| 951 | 					{
 | |
| 952 | path.Delete(path.Length()-1,1); | |
| 953 | path.AppendNum(i); | |
| 954 | 					multipleTestDoer.Printf(_L("File Rename - %S (%d)\n"),&path,threadID);
 | |
| 955 | r = file.Rename(path); | |
| 956 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 957 | } | |
| 958 | } | |
| 959 | else | |
| 960 | 				{
 | |
| 961 | 				multipleTestDoer.Printf(_L("File Rename - (%d)\n"),threadID);
 | |
| 962 | r = file.Rename(path); | |
| 963 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 964 | } | |
| 965 | ||
| 966 | file.Close(); | |
| 967 | r = fs.Delete(path); | |
| 968 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 969 | break; | |
| 970 | } | |
| 971 | case t_notification::EFsRename_dir: | |
| 972 | 			{
 | |
| 973 | r = fs.MkDirAll(_path); | |
| 974 | if(r != KErrNone && r != KErrAlreadyExists) | |
| 975 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 976 | ||
| 977 | TBuf<45> newPath; | |
| 978 | newPath.Copy(_path); | |
| 979 | newPath.Delete(newPath.Length()-1,1); | |
| 980 | newPath.AppendNum(0); | |
| 981 | newPath.Append(KPathDelimiter); | |
| 982 | ||
| 983 | //Delete new path to ensure it does not exist | |
| 984 | r = fs.RmDir(newPath); | |
| 985 | if(r != KErrNone && r != KErrNotFound && r != KErrPathNotFound) | |
| 986 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 987 | ||
| 988 | 			multipleTestDoer.Printf(_L("RFs Rename Dir - (%d)\n"),threadID);
 | |
| 989 | r = fs.Rename(_path,newPath); | |
| 990 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 991 | break; | |
| 992 | } | |
| 993 | case t_notification::EFsDelete: | |
| 994 | 			{
 | |
| 995 | if (wildcard) | |
| 996 | 				{
 | |
| 997 | for(TInt i = 0; i < pkgDoer.iIterations; i++) | |
| 998 | 					{
 | |
| 999 | //Create/replace file | |
| 1000 | RFile file; | |
| 1001 | TBuf<40> path; | |
| 1002 | path.Append(basepath); | |
| 1003 | r = fs.MkDirAll(path); | |
| 1004 | if(r != KErrNone && r != KErrAlreadyExists) | |
| 1005 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1006 | path.AppendNum(i); | |
| 1007 | 					path.Append(_L(".txt"));
 | |
| 1008 | r = file.Replace(fs,path,EFileWrite); | |
| 1009 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1010 | file.Close(); | |
| 1011 | ||
| 1012 | //Delete file | |
| 1013 | 					multipleTestDoer.Printf(_L("RFs Delete - %S (%d)\n"),&path,threadID);
 | |
| 1014 | r = fs.Delete(path); | |
| 1015 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1016 | ||
| 1017 | //Create file with a different extension which should not produce notifications | |
| 1018 | path.AppendNum(i); | |
| 1019 | r = file.Replace(fs,path,EFileWrite); | |
| 1020 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1021 | file.Close(); | |
| 1022 | ||
| 1023 | //Delete that file | |
| 1024 | 					multipleTestDoer.Printf(_L("RFs Delete - %S (%d)\n"),&path,threadID);
 | |
| 1025 | r = fs.Delete(path); | |
| 1026 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1027 | } | |
| 1028 | } | |
| 1029 | else | |
| 1030 | 				{
 | |
| 1031 | RFile file; | |
| 1032 | r = file.Replace(fs,_path,EFileWrite); //Make sure file exists | |
| 1033 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1034 | file.Close(); | |
| 1035 | ||
| 1036 | 				multipleTestDoer.Printf(_L("RFs Delete - (%d)\n"),threadID);
 | |
| 1037 | r = fs.Delete(_path); | |
| 1038 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1039 | } | |
| 1040 | break; | |
| 1041 | } | |
| 1042 | case t_notification::EFileSet: | |
| 1043 | 			{
 | |
| 1044 | RFile file; | |
| 1045 | r = file.Replace(fs,_path,EFileWrite); | |
| 1046 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1047 | ||
| 1048 | 			multipleTestDoer.Printf(_L("File Set - (%d)\n"),threadID);
 | |
| 1049 | r = file.Set(TTime(0),KEntryAttHidden,KEntryAttReadOnly); | |
| 1050 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1051 | ||
| 1052 | file.Close(); | |
| 1053 | break; | |
| 1054 | } | |
| 1055 | case t_notification::EFileSetAtt: | |
| 1056 | case t_notification::EAllOps4: | |
| 1057 | 			{
 | |
| 1058 | RFile file; | |
| 1059 | r = file.Replace(fs,_path,EFileWrite); | |
| 1060 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1061 | ||
| 1062 | 			multipleTestDoer.Printf(_L("File SetAtt - (%d)\n"),threadID);
 | |
| 1063 | r = file.SetAtt(KEntryAttHidden,KEntryAttReadOnly); | |
| 1064 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1065 | ||
| 1066 | file.Close(); | |
| 1067 | r = fs.Delete(_path); | |
| 1068 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1069 | break; | |
| 1070 | } | |
| 1071 | case t_notification::EFileSetAtt_subs: | |
| 1072 | 			{
 | |
| 1073 | if (wildcard) | |
| 1074 | 				{
 | |
| 1075 | TBuf<40> path; | |
| 1076 | path.Append(basepath); | |
| 1077 | 				path.Append(_L("SubDir\\"));
 | |
| 1078 | r = fs.MkDirAll(path); | |
| 1079 | if(r != KErrNone && r != KErrAlreadyExists) | |
| 1080 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1081 | ||
| 1082 | //Create/replace files and set their attributes | |
| 1083 | for(TInt i = 0; i < pkgDoer.iIterations; i++) | |
| 1084 | 					{
 | |
| 1085 | RFile file; | |
| 1086 | TBuf<40> dirPath; | |
| 1087 | dirPath.Append(path); | |
| 1088 | dirPath.AppendNum(i); | |
| 1089 | 					dirPath.Append(_L(".ext"));
 | |
| 1090 | r = file.Replace(fs, dirPath, EFileWrite); | |
| 1091 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1092 | ||
| 1093 | 					multipleTestDoer.Printf(_L("File SetAtt Subs - %d.ext - (%d)\n"),i,threadID);
 | |
| 1094 | r = file.SetAtt(KEntryAttHidden,KEntryAttReadOnly); | |
| 1095 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1096 | ||
| 1097 | file.Close(); | |
| 1098 | r = fs.Delete(dirPath); | |
| 1099 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1100 | } | |
| 1101 | } | |
| 1102 | break; | |
| 1103 | } | |
| 1104 | case t_notification::EFsSetEntry: | |
| 1105 | 			{
 | |
| 1106 | RFile file; | |
| 1107 | r = file.Replace(fs,_path,EFileWrite); | |
| 1108 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1109 | file.Close(); | |
| 1110 | ||
| 1111 | 			multipleTestDoer.Printf(_L("RFs SetEntry - (%d)\n"),threadID);
 | |
| 1112 | r = fs.SetEntry(_path,TTime(0),KEntryAttHidden,KEntryAttReadOnly); | |
| 1113 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1114 | break; | |
| 1115 | } | |
| 1116 | case t_notification::EDismount: | |
| 1117 | 			{
 | |
| 1118 | 			multipleTestDoer.Printf(_L("DismountFileSystem - (%d)\n"),threadID);
 | |
| 1119 | r = fs.DismountFileSystem(pkgDoer.iFileName,globalDriveNum); | |
| 1120 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1121 | break; | |
| 1122 | } | |
| 1123 | case t_notification::EMount: | |
| 1124 | 			{
 | |
| 1125 | 			multipleTestDoer.Printf(_L("MountFileSystem - (%d)\n"),threadID);
 | |
| 1126 | r = fs.MountFileSystem(pkgDoer.iFileName,globalDriveNum); | |
| 1127 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1128 | break; | |
| 1129 | } | |
| 1130 | case t_notification::EMountScan: | |
| 1131 | 			{
 | |
| 1132 | 			multipleTestDoer.Printf(_L("DismountFileSystem - (%d)\n"),threadID);
 | |
| 1133 | r = fs.DismountFileSystem(pkgDoer.iFileName,globalDriveNum); | |
| 1134 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1135 | TBool isMount; | |
| 1136 | 			multipleTestDoer.Printf(_L("MountFileSystemAndScan - (%d)\n"),threadID);
 | |
| 1137 | r = fs.MountFileSystemAndScan(pkgDoer.iFileName,globalDriveNum,isMount); | |
| 1138 | if(!isMount) | |
| 1139 | safe_test(multipleTestDoer,KErrGeneral,__LINE__,pkgDoer.iLineCall); | |
| 1140 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1141 | break; | |
| 1142 | } | |
| 1143 | case t_notification::EMountDismount: | |
| 1144 | 			{
 | |
| 1145 | for(TInt i = 0; i < pkgDoer.iIterations; i++) | |
| 1146 | 				{
 | |
| 1147 | 				multipleTestDoer.Printf(_L("DismountFileSystem - (%d)\n"),threadID);
 | |
| 1148 | r = fs.DismountFileSystem(pkgDoer.iFileName,globalDriveNum); | |
| 1149 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1150 | ||
| 1151 | 				multipleTestDoer.Printf(_L("MountFileSystem - (%d)\n"),threadID);
 | |
| 1152 | r = fs.MountFileSystem(pkgDoer.iFileName,globalDriveNum); | |
| 1153 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1154 | } | |
| 1155 | break; | |
| 1156 | } | |
| 1157 | case t_notification::EFormat: | |
| 1158 | 			{
 | |
| 1159 | RFormat format; | |
| 1160 | TInt count = -1; | |
| 1161 | TBuf<2> driveDes; | |
| 1162 | driveDes.Append(pkgDoer.iFileName); | |
| 1163 | driveDes.Append((TChar)':'); | |
| 1164 | format.Open(fs,driveDes,EQuickFormat,count); | |
| 1165 | 			multipleTestDoer.Printf(_L("Format - (%d)\n"),threadID);
 | |
| 1166 | while(count != 0) | |
| 1167 | 				{
 | |
| 1168 | format.Next(count); | |
| 1169 | } | |
| 1170 | format.Close(); | |
| 1171 | ||
| 1172 | break; | |
| 1173 | } | |
| 1174 | case t_notification::EMediaCardRemoval: | |
| 1175 | case t_notification::EMediaCardInsertion: | |
| 1176 | 			{
 | |
| 1177 | //These are MANUAL tests, they require the removal/insertion of the media card | |
| 1178 | //Instructions are given out in the watcher thread | |
| 1179 | break; | |
| 1180 | } | |
| 1181 | case t_notification::ESetDriveName: | |
| 1182 | 			{
 | |
| 1183 | for(TInt i = 0; i < pkgDoer.iIterations; i++) | |
| 1184 | 				{
 | |
| 1185 | 				multipleTestDoer.Printf(_L("SetDriveName - MyDrive\n"));
 | |
| 1186 | _LIT(KDriveName,"MyDrive"); | |
| 1187 | r = fs.SetDriveName(globalDriveNum,KDriveName); | |
| 1188 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1189 | ||
| 1190 | 				multipleTestDoer.Printf(_L("SetDriveName - MyDrive2\n"));
 | |
| 1191 | _LIT(KDriveName2,"MyDrive2"); | |
| 1192 | r = fs.SetDriveName(globalDriveNum,KDriveName2); | |
| 1193 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1194 | } | |
| 1195 | break; | |
| 1196 | } | |
| 1197 | case t_notification::ERawDiskWrite: | |
| 1198 | 			{
 | |
| 1199 | RRawDisk rawdisk; | |
| 1200 | TInt drive = 0; | |
| 1201 | TBuf<1> driveDes; | |
| 1202 | driveDes.Append(pkgDoer.iFileName); | |
| 1203 | RFs::CharToDrive(pkgDoer.iFileName[0],drive); | |
| 1204 | r = rawdisk.Open(fs,drive); | |
| 1205 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1206 | ||
| 1207 | //Read some data | |
| 1208 | TBuf8<10> readData; | |
| 1209 | r = rawdisk.Read(0,readData); | |
| 1210 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1211 | ||
| 1212 | //Write it back | |
| 1213 | TPtrC8 dataPtr(readData); | |
| 1214 | r = rawdisk.Write((TInt64)0,dataPtr); | |
| 1215 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1216 | rawdisk.Close(); | |
| 1217 | break; | |
| 1218 | } | |
| 1219 | case t_notification::ESetVolumeLabel: | |
| 1220 | 			{
 | |
| 1221 | for(TInt i = 0; i < pkgDoer.iIterations; i++) | |
| 1222 | 				{
 | |
| 1223 | 				multipleTestDoer.Printf(_L("SetVolumeLabel - MyVolume\n"));
 | |
| 1224 | _LIT(KVolumeLabel,"MyVolume"); | |
| 1225 | r = fs.SetVolumeLabel(KVolumeLabel,globalDriveNum); | |
| 1226 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1227 | ||
| 1228 | 				multipleTestDoer.Printf(_L("SetVolumeLabel - MyVolume2\n"));
 | |
| 1229 | _LIT(KVolumeLabel2,"MyVolume2"); | |
| 1230 | r = fs.SetVolumeLabel(KVolumeLabel2,globalDriveNum); | |
| 1231 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1232 | } | |
| 1233 | break; | |
| 1234 | } | |
| 1235 | case t_notification::EFsRmDir: | |
| 1236 | 			{
 | |
| 1237 | r = fs.MkDirAll(_path); //Make sure directory exists | |
| 1238 | if(r != KErrNone && r != KErrAlreadyExists) | |
| 1239 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1240 | 			multipleTestDoer.Printf(_L("RFs RmDir - Remove directory\n"));
 | |
| 1241 | r = fs.RmDir(_path); | |
| 1242 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1243 | break; | |
| 1244 | } | |
| 1245 | case t_notification::EFsRmDir_wild: | |
| 1246 | 			{
 | |
| 1247 | if (wildcard) | |
| 1248 | 				{
 | |
| 1249 | TBuf<40> path; | |
| 1250 | path.Append(basepath); | |
| 1251 | 				path.Append(_L("SubDir\\"));
 | |
| 1252 | r = fs.MkDirAll(path); | |
| 1253 | if(r != KErrNone && r != KErrAlreadyExists) | |
| 1254 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1255 | ||
| 1256 | 				multipleTestDoer.Printf(_L("RFs RmDir - Remove directory\n"));
 | |
| 1257 | r = fs.RmDir(path); | |
| 1258 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1259 | break; | |
| 1260 | } | |
| 1261 | } | |
| 1262 | case t_notification::EFsRmDir_nonEmpty: | |
| 1263 | case t_notification::EFsMkDir: | |
| 1264 | 			{
 | |
| 1265 | TBuf<50> path; | |
| 1266 | path.Append(_path); | |
| 1267 | path.Append(pkgDoer.iFileName); //Append another sub-directory | |
| 1268 | 			multipleTestDoer.Printf(_L("RFs RmDir \n"));
 | |
| 1269 | r=fs.RmDir(path); | |
| 1270 | if(r != KErrNone && r != KErrPathNotFound && r != KErrNotFound) | |
| 1271 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1272 | r=fs.RmDir(_path); | |
| 1273 | if(r != KErrNone && r != KErrPathNotFound && r != KErrNotFound) | |
| 1274 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1275 | ||
| 1276 | 			multipleTestDoer.Printf(_L("RFs MkDir \n"));
 | |
| 1277 | r=fs.MkDir(path); | |
| 1278 | multipleTestDoer (r==KErrPathNotFound); | |
| 1279 | r=fs.MkDir(_path); | |
| 1280 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1281 | r=fs.MkDir(path); | |
| 1282 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1283 | ||
| 1284 | 			multipleTestDoer.Printf(_L("RFs RmDir nonEmpty - Full path: %S"),&_path);
 | |
| 1285 | r = fs.RmDir(_path); | |
| 1286 | if(r != KErrInUse) | |
| 1287 | safe_test(multipleTestDoer,KErrGeneral,__LINE__,pkgDoer.iLineCall); | |
| 1288 | ||
| 1289 | r = fs.RmDir(path); | |
| 1290 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1291 | ||
| 1292 | 			multipleTestDoer.Printf(_L("RFs EFsRmDir_nonEmpty - Full path: %S"),&_path);
 | |
| 1293 | r = fs.RmDir(_path); | |
| 1294 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1295 | ||
| 1296 | break; | |
| 1297 | } | |
| 1298 | case t_notification::EAllOps6: | |
| 1299 | 			{
 | |
| 1300 | //Set drive name to TestDrive | |
| 1301 | 			multipleTestDoer.Printf(_L("SetDriveName - TestDrive\n"));
 | |
| 1302 | _LIT(KDriveName,"TestDrive"); | |
| 1303 | r = fs.SetDriveName(globalDriveNum,KDriveName); | |
| 1304 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1305 | //Set volume label to TestVolume | |
| 1306 | 			multipleTestDoer.Printf(_L("SetVolumeLabel - TestVolume\n"));
 | |
| 1307 | _LIT(KVolumeLabel,"TestVolume"); | |
| 1308 | r = fs.SetVolumeLabel(KVolumeLabel,globalDriveNum); | |
| 1309 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1310 | break; | |
| 1311 | } | |
| 1312 | case t_notification::ECFileManMove: | |
| 1313 | 		    {
 | |
| 1314 | CTrapCleanup* cleanup; | |
| 1315 | cleanup = CTrapCleanup::New(); | |
| 1316 | ||
| 1317 | 		    multipleTestDoer.Printf(_L("Doer - ECFileManMove_part1\n"));
 | |
| 1318 | ||
| 1319 | //Stage 1 - Create File & write some data | |
| 1320 | RFile file; | |
| 1321 | r = file.Replace(fs,_path,EFileWrite); | |
| 1322 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1323 | r = file.SetSize(4); | |
| 1324 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1325 | file.Close(); | |
| 1326 | ||
| 1327 | CFileMan* cfman = NULL; | |
| 1328 | TRAP(r, cfman = CFileMan::NewL(fs);) | |
| 1329 | test(r == KErrNone); | |
| 1330 | test(cfman != NULL); | |
| 1331 | TBuf<40> unmonitored_path; | |
| 1332 | unmonitored_path.Append(gDriveToTest); | |
| 1333 |             unmonitored_path.Append(_L(":\\F32-TST\\"));
 | |
| 1334 | unmonitored_path.Append(pkgDoer.iString); | |
| 1335 | ||
| 1336 | //Stage 2 - Move to unmonitored Dir | |
| 1337 | //Rename 1 | |
| 1338 | r = cfman->Move(_path,unmonitored_path); | |
| 1339 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1340 | ||
| 1341 | //SetSize (size := 8) | |
| 1342 | RFile file2; | |
| 1343 | r = file2.Open(fs,unmonitored_path,EFileWrite); | |
| 1344 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1345 | r = file2.SetSize(8); | |
| 1346 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1347 | file2.Flush(); | |
| 1348 | file2.Close(); | |
| 1349 | ||
| 1350 | //Stage 3 - Move back to monitored Dir | |
| 1351 | //Rename 2 | |
| 1352 | r = cfman->Move(unmonitored_path,_path); | |
| 1353 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1354 | ||
| 1355 | //Stage 4 - Delete | |
| 1356 | //Delete | |
| 1357 | r = cfman->Delete(_path); | |
| 1358 | safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall); | |
| 1359 | ||
| 1360 | delete cleanup; | |
| 1361 | delete cfman; | |
| 1362 | break; | |
| 1363 | } | |
| 1364 | default: | |
| 1365 | 			{
 | |
| 1366 | break; | |
| 1367 | } | |
| 1368 | } | |
| 1369 | ||
| 1370 | fs.Close(); | |
| 1371 | multipleTestDoer.End(); | |
| 1372 | multipleTestDoer.Close(); | |
| 1373 | return KErrNone; | |
| 1374 | } | |
| 1375 | ||
| 1376 | /* | |
| 1377 | * Test process Capabilites tries to set up filters on the | |
| 1378 | * the private folder for uid 01234567. | |
| 1379 | * This function returns the results to trying to add filters on the specified path. | |
| 1380 | * | |
| 1381 | * There are three MMP files: | |
| 1382 | * t_notifier_nocaps.mmp, t_notifier_allfiles.mmp, t_notifier_belongs.mmp | |
| 1383 | * | |
| 1384 | * t_notifier_nocaps.mmp - | |
| 1385 | * This process does not have any capabilites, so should not be allowed to set the filter. | |
| 1386 | * t_notifier_allfiles.mmp - | |
| 1387 | * This process has ALLFILES capability, so should | |
| 1388 | * t_notifier_belongs.mmp - | |
| 1389 | * This process is process with UID 01234567 so this should work too. | |
| 1390 | * | |
| 1391 | * See: f32test\server\t_notifier_caps.cpp | |
| 1392 | */ | |
| 1393 | TInt TestProcessCapabilities(const TDesC& aProcessName) | |
| 1394 | 	{
 | |
| 1395 | RProcess process; | |
| 1396 | TUidType uid; | |
| 1397 | TPtrC command((TText*)&gDriveToTest,1); | |
| 1398 | TInt r = process.Create(aProcessName,command,uid); | |
| 1399 | test(r==KErrNone); | |
| 1400 | process.Resume(); | |
| 1401 | TRequestStatus s1; | |
| 1402 | TRequestStatus s2; | |
| 1403 | RTimer tim; | |
| 1404 | r = tim.CreateLocal(); | |
| 1405 | test(r==KErrNone); | |
| 1406 | TTimeIntervalMicroSeconds32 delay = 5000000; //5 seconds | |
| 1407 | tim.After(s1,delay); | |
| 1408 | process.Logon(s2); | |
| 1409 | User::WaitForRequest(s1,s2); | |
| 1410 | test(s2.Int()!=KRequestPending); | |
| 1411 | r = process.ExitReason(); | |
| 1412 | process.Close(); | |
| 1413 | return r; | |
| 1414 | } | |
| 1415 | ||
| 1416 | /* | |
| 1417 | * Creates a file and writes to it twice. | |
| 1418 | * Used in TestTwoNotificationsL(). | |
| 1419 | */ | |
| 1420 | TInt TwoNotificationsTFDoer(TAny* aAny) | |
| 1421 | 	{
 | |
| 1422 | 	RTest testDoer(_L("TestTwoNotificationsThreadFunctionDoer"));
 | |
| 1423 | 	testDoer.Start(_L("TestTwoNotificationsThreadFunctionDoer"));
 | |
| 1424 | ||
| 1425 | SThreadPackageMultiple package = *(SThreadPackageMultiple*)aAny; | |
| 1426 | TBuf<40> path; | |
| 1427 | path.Append(gDriveToTest); | |
| 1428 | 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
 | |
| 1429 | path.Append(package.iFileName); | |
| 1430 | ||
| 1431 | //Delete file so we definitely get a create notification | |
| 1432 | RFs fs; | |
| 1433 | TInt r = fs.Connect(); | |
| 1434 | testDoer(r==KErrNone); | |
| 1435 | r = fs.Delete(path); | |
| 1436 | testDoer(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound); | |
| 1437 | r = fs.MkDirAll(path); | |
| 1438 | testDoer(r==KErrNone || r==KErrAlreadyExists); | |
| 1439 | ||
| 1440 | 	testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Create File %S\n"),&path);
 | |
| 1441 | //Create file | |
| 1442 | RFile file; | |
| 1443 | r = file.Create(fs,path,EFileWrite); | |
| 1444 | testDoer(r == KErrNone); | |
| 1445 | ||
| 1446 | 	testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Size File 1 %S\n"),&path);
 | |
| 1447 | TInt fileSize = 0; | |
| 1448 | r = file.Size(fileSize); | |
| 1449 | testDoer(r == KErrNone); | |
| 1450 | testDoer(fileSize==0); | |
| 1451 | ||
| 1452 | 	testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Write File 1 %S\n"),&path);
 | |
| 1453 | 	r = file.Write(_L8("1234"));
 | |
| 1454 | testDoer(r == KErrNone); | |
| 1455 | 	testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Size File 2 %S\n"),&path);
 | |
| 1456 | r = file.Size(fileSize); | |
| 1457 | testDoer(r == KErrNone); | |
| 1458 | test(fileSize==4); | |
| 1459 | ||
| 1460 | 	testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Write File 2 %S\n"),&path);
 | |
| 1461 | 	r = file.Write(_L8("5678"));
 | |
| 1462 | testDoer(r == KErrNone); | |
| 1463 | 	testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Size File 3 %S\n"),&path);
 | |
| 1464 | r = file.Size(fileSize); | |
| 1465 | testDoer(r == KErrNone); | |
| 1466 | test(fileSize==8); | |
| 1467 | ||
| 1468 | file.Close(); | |
| 1469 | ||
| 1470 | fs.Close(); | |
| 1471 | testDoer.End(); | |
| 1472 | testDoer.Close(); | |
| 1473 | return KErrNone; | |
| 1474 | } | |
| 1475 | ||
| 1476 | /* | |
| 1477 | * The following enum are for the CFileMan test | |
| 1478 | */ | |
| 1479 | enum TCFsManEnum | |
| 1480 |         {
 | |
| 1481 | ECFManCreate1 = 0x01, | |
| 1482 | ECFManWrite1 = 0x02, | |
| 1483 | ECFManDelete1 = 0x04, | |
| 1484 | ECFManCreate2 = 0x08, | |
| 1485 | ECFManSetSize1 = 0x10, | |
| 1486 | ECFManWrite2 = 0x20, | |
| 1487 | ECFManAtt1 = 0x40, | |
| 1488 | ECFManDelete2 = 0x80, | |
| 1489 | //Either a create, copy, delete (above - not supported in test) | |
| 1490 | //or rename operation (below) | |
| 1491 | ECFManRename1 = 0x100, | |
| 1492 | ECFManRename2 = 0x200 | |
| 1493 | }; | |
| 1494 | ||
| 1495 | /* | |
| 1496 | * Used by MultipleNotificationsTFWatcher() to test the notifications. | |
| 1497 | */ | |
| 1498 | void HandleMultipleNotifications(RTest& aTest, SThreadPackageMultiple& aPackage, CFsNotify* notify, TDesC& aFullname) | |
| 1499 | 	{
 | |
| 1500 | RThread thread; | |
| 1501 | TUint64 threadID = thread.Id().Id(); | |
| 1502 | TInt numNotifications = 0; | |
| 1503 | TInt64 fileSize = 0; | |
| 1504 | TBool overflow = EFalse; | |
| 1505 | ||
| 1506 | TInt scratch = 0; | |
| 1507 | ||
| 1508 | for(TInt i = 0; i < aPackage.iMaxNotifications; ) //Outer-loop to control when we should exit | |
| 1509 | 		{
 | |
| 1510 | 		aTest.Printf(_L("(%d) - NextNotification\n"),threadID);
 | |
| 1511 | const TFsNotification* notification = notify->NextNotification(); | |
| 1512 | while(notification != NULL) | |
| 1513 | 				{
 | |
| 1514 | numNotifications++; | |
| 1515 | 				aTest.Printf(_L("NumNotifications = %d\n"),numNotifications);
 | |
| 1516 | //Test notification is not null. | |
| 1517 | //We should be getting 1 notification. | |
| 1518 | aTest(notification != NULL); | |
| 1519 | ||
| 1520 | 				aTest.Printf(_L("(%d) - Notification Type\n"),threadID);
 | |
| 1521 | TFsNotification::TFsNotificationType notificationType = notification->NotificationType(); | |
| 1522 | aTest(notificationType & aPackage.iNotifyType || | |
| 1523 | notificationType & TFsNotification::EOverflow); | |
| 1524 | ||
| 1525 | 				aTest.Printf(_L("Notification Type = %u - (%d)\n"),notificationType,threadID);
 | |
| 1526 | ||
| 1527 | if(notificationType != TFsNotification::EOverflow) | |
| 1528 | 					{
 | |
| 1529 | 					aTest.Printf(_L("(%d) - Notification Path\n"),threadID);
 | |
| 1530 | TPtrC _pathC; | |
| 1531 | ((TFsNotification*) notification)->Path(_pathC); | |
| 1532 | 					aTest.Printf(_L("%S - (%d)\n"),&_pathC,threadID);
 | |
| 1533 | ||
| 1534 | if(aPackage.iOperation == t_notification::ECFileManMove | |
| 1535 | && (scratch == (ECFManWrite1 | ECFManCreate1))) | |
| 1536 | 					    {
 | |
| 1537 | TChar drive = gDriveToTest; | |
| 1538 | TBuf<40> unmodified_path; | |
| 1539 | unmodified_path.Append(drive); | |
| 1540 | 					    unmodified_path.Append(_L(":\\F32-TST\\"));
 | |
| 1541 | 					    unmodified_path.Append(_L("cf1le.man"));
 | |
| 1542 | ((TFsNotification*) notification)->NewName(_pathC); | |
| 1543 | TInt matches = _pathC.Match(unmodified_path); | |
| 1544 | safe_test(aTest,matches,__LINE__,aPackage.iLineCall); | |
| 1545 | } | |
| 1546 | else if((scratch == (ECFManWrite1 | ECFManCreate1 | ECFManRename1))) | |
| 1547 | 					    {
 | |
| 1548 | ((TFsNotification*) notification)->NewName(_pathC); | |
| 1549 | safe_test(aTest,_pathC.Match(aFullname),__LINE__,aPackage.iLineCall); | |
| 1550 | } | |
| 1551 | else | |
| 1552 | 					    {
 | |
| 1553 | safe_test(aTest,_pathC.Match(aFullname),__LINE__,aPackage.iLineCall); | |
| 1554 | } | |
| 1555 | } | |
| 1556 | else | |
| 1557 | 					{
 | |
| 1558 | 					aTest.Printf(_L("(%d) - OVERFLOW\n"),threadID);
 | |
| 1559 | //Overflow | |
| 1560 | overflow = ETrue; | |
| 1561 | return; | |
| 1562 | } | |
| 1563 | ||
| 1564 | //notificationType will only be of 1 type | |
| 1565 | if(notificationType == TFsNotification::EFileChange) | |
| 1566 | 				    {
 | |
| 1567 | if(!(((aPackage.iNotifyType & TFsNotification::EFileChange) == TFsNotification::EFileChange) && | |
| 1568 | (aPackage.iOperation == t_notification::EFileWrite || | |
| 1569 | aPackage.iOperation == t_notification::EFileWrite_async || | |
| 1570 | aPackage.iOperation == t_notification::EFileWrite_samesize || | |
| 1571 | aPackage.iOperation == t_notification::EFileSetSize || | |
| 1572 | aPackage.iOperation == t_notification::ECFileManMove || | |
| 1573 | aPackage.iOperation == t_notification::EAllOps2 || | |
| 1574 | aPackage.iOperation == t_notification::EAllOps3))) | |
| 1575 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1576 | ||
| 1577 | if (aPackage.iOperation == t_notification::ECFileManMove) | |
| 1578 |                         {
 | |
| 1579 | ((TFsNotification*) notification)->FileSize(fileSize); | |
| 1580 | //File just been created and written to. | |
| 1581 | if(fileSize == 4) | |
| 1582 |                             {
 | |
| 1583 | scratch |= ECFManWrite1; | |
| 1584 | } | |
| 1585 | else if(fileSize == 8) | |
| 1586 |                             {
 | |
| 1587 | scratch |= ECFManWrite2; | |
| 1588 | } | |
| 1589 | } | |
| 1590 | else if (aPackage.iNotifyType == TFsNotification::EFileChange) | |
| 1591 | 				        {
 | |
| 1592 | ((TFsNotification*) notification)->FileSize(fileSize); | |
| 1593 | 				        aTest.Printf(_L("Filesize - %d (%d)\n"),fileSize,threadID);
 | |
| 1594 | //A notification is received every time the size is changed | |
| 1595 | //due to the flushing | |
| 1596 | if (aPackage.iOperation == t_notification::EFileWrite_async) | |
| 1597 |                             {
 | |
| 1598 | //We write 52 letters | |
| 1599 | if(fileSize != 52*(i+1)) | |
| 1600 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1601 | } | |
| 1602 | else if (aPackage.iOperation == t_notification::EFileWrite_samesize) | |
| 1603 |                             {
 | |
| 1604 | //Only 4 letters in file | |
| 1605 | if(fileSize != 4) | |
| 1606 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1607 | } | |
| 1608 | else if (i < aPackage.iIterations) | |
| 1609 |                             {
 | |
| 1610 | //We write/increase size by 4 letters/bytes | |
| 1611 | if(fileSize != 4*(i+1)) | |
| 1612 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1613 | } | |
| 1614 | else | |
| 1615 |                             {
 | |
| 1616 | //We decrease size by 4 bytes | |
| 1617 | if(fileSize != 4*(aPackage.iMaxNotifications-i)) | |
| 1618 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1619 | } | |
| 1620 | } | |
| 1621 | } | |
| 1622 | else if(notificationType == TFsNotification::ECreate) | |
| 1623 | 					{
 | |
| 1624 | if(!(((aPackage.iNotifyType & TFsNotification::ECreate) == TFsNotification::ECreate) && | |
| 1625 | (aPackage.iOperation == t_notification::EFileCreate || | |
| 1626 | aPackage.iOperation == t_notification::EFileReplace || | |
| 1627 | aPackage.iOperation == t_notification::EFileCreate_subs || | |
| 1628 | aPackage.iOperation == t_notification::EFileCreate_subs_nowatch || | |
| 1629 | aPackage.iOperation == t_notification::EFileCreate_txt_nowatch || | |
| 1630 | aPackage.iOperation == t_notification::EFileCreate_txt || | |
| 1631 | aPackage.iOperation == t_notification::EFsMkDir || | |
| 1632 | aPackage.iOperation == t_notification::ECFileManMove || | |
| 1633 | aPackage.iOperation == t_notification::EAllOps1 || | |
| 1634 | aPackage.iOperation == t_notification::EAllOps2 || | |
| 1635 | aPackage.iOperation == t_notification::EAllOps3 || | |
| 1636 | aPackage.iOperation == t_notification::EAllOps4 || | |
| 1637 | aPackage.iOperation == t_notification::EAllOps5))) | |
| 1638 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1639 | if (aPackage.iOperation == t_notification::EFileCreate_txt) | |
| 1640 | 					    {
 | |
| 1641 | //Check filename is of correct extension | |
| 1642 | TPtrC _path; | |
| 1643 | ((TFsNotification*) notification)->Path(_path); | |
| 1644 | TBuf<5> _ext; | |
| 1645 | 					    _ext.Append(_L(".txt"));
 | |
| 1646 | TBuf<5> ext; | |
| 1647 | ext.Append(_path.Right(4)); | |
| 1648 | safe_test(aTest,ext.Match(_ext),__LINE__,aPackage.iLineCall); | |
| 1649 | } | |
| 1650 | else if (aPackage.iOperation == t_notification::ECFileManMove) | |
| 1651 | 					    {
 | |
| 1652 | if(scratch & ECFManCreate1) | |
| 1653 | 					        {
 | |
| 1654 | scratch |= ECFManCreate2; //File created second time | |
| 1655 | } | |
| 1656 | else | |
| 1657 | 					        {
 | |
| 1658 | scratch |= ECFManCreate1; //File created first time | |
| 1659 | } | |
| 1660 | } | |
| 1661 | } | |
| 1662 | else if(notificationType == TFsNotification::EDelete) | |
| 1663 | 					{
 | |
| 1664 | if(!(((aPackage.iNotifyType & TFsNotification::EDelete) == TFsNotification::EDelete) && | |
| 1665 | (aPackage.iOperation == t_notification::EFsDelete || | |
| 1666 | aPackage.iOperation == t_notification::EFsRmDir || | |
| 1667 | aPackage.iOperation == t_notification::EFsRmDir_nonEmpty || | |
| 1668 | aPackage.iOperation == t_notification::EFsRmDir_wild || | |
| 1669 | aPackage.iOperation == t_notification::ECFileManMove || | |
| 1670 | aPackage.iOperation == t_notification::EAllOps1 || | |
| 1671 | aPackage.iOperation == t_notification::EAllOps2 || | |
| 1672 | aPackage.iOperation == t_notification::EAllOps3 || | |
| 1673 | aPackage.iOperation == t_notification::EAllOps4))) | |
| 1674 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1675 | ||
| 1676 | if(aPackage.iOperation == t_notification::ECFileManMove) | |
| 1677 | 					    {
 | |
| 1678 | if(scratch & ECFManDelete1) | |
| 1679 | 					        {
 | |
| 1680 | scratch |= ECFManDelete2; | |
| 1681 | } | |
| 1682 | else | |
| 1683 | 					        {
 | |
| 1684 | scratch |= ECFManDelete1; | |
| 1685 | } | |
| 1686 | } | |
| 1687 | } | |
| 1688 | else if(notificationType == TFsNotification::ERename) | |
| 1689 | 					{
 | |
| 1690 | if(!(((aPackage.iNotifyType & TFsNotification::ERename) == TFsNotification::ERename) && | |
| 1691 | (aPackage.iOperation == t_notification::EFileRename || | |
| 1692 | aPackage.iOperation == t_notification::EFileRename_wild || | |
| 1693 | aPackage.iOperation == t_notification::EFsReplace || | |
| 1694 | aPackage.iOperation == t_notification::ECFileManMove || | |
| 1695 | aPackage.iOperation == t_notification::EFsRename || | |
| 1696 | aPackage.iOperation == t_notification::EFsRename_dir || | |
| 1697 | aPackage.iOperation == t_notification::EAllOps5))) | |
| 1698 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1699 | TPtrC newnameC; | |
| 1700 | ((TFsNotification*)notification)->NewName(newnameC); | |
| 1701 | 					aTest.Printf(_L("%S - (%d)\n"),&newnameC,threadID);
 | |
| 1702 | ||
| 1703 | TPtrC _pathC; | |
| 1704 | ((TFsNotification*) notification)->Path(_pathC); | |
| 1705 | ||
| 1706 | TBuf<40> _path; | |
| 1707 | _path.Copy(_pathC); | |
| 1708 | ||
| 1709 | if (aPackage.iOperation == t_notification::EFsRename_dir) | |
| 1710 | 						{
 | |
| 1711 | _path.Delete(_path.Length()-1,1); | |
| 1712 | _path.AppendNum(0); | |
| 1713 | _path.Append(KPathDelimiter); | |
| 1714 | } | |
| 1715 | else if (aPackage.iOperation == t_notification::EFileRename_wild) | |
| 1716 | 						{
 | |
| 1717 | _path.Delete(_path.Length()-1,1); | |
| 1718 | _path.AppendNum(numNotifications); | |
| 1719 | } | |
| 1720 | else | |
| 1721 | 						{
 | |
| 1722 | _path.AppendNum(0); | |
| 1723 | } | |
| 1724 | ||
| 1725 | if(aPackage.iOperation != t_notification::ECFileManMove) | |
| 1726 | 					    {
 | |
| 1727 | safe_test(aTest,newnameC.Match(_path),__LINE__,aPackage.iLineCall); | |
| 1728 | } | |
| 1729 | else if(scratch & ECFManRename1) | |
| 1730 | 					    {
 | |
| 1731 | scratch |= ECFManRename2; | |
| 1732 | } | |
| 1733 | else | |
| 1734 | 					    {
 | |
| 1735 | scratch |= ECFManRename1; | |
| 1736 | } | |
| 1737 | ||
| 1738 | } | |
| 1739 | else if(notificationType == TFsNotification::EAttribute) | |
| 1740 | 					{
 | |
| 1741 | if(!(((aPackage.iNotifyType & TFsNotification::EAttribute) == TFsNotification::EAttribute) && | |
| 1742 | (aPackage.iOperation == t_notification::EFsSetEntry || | |
| 1743 | aPackage.iOperation == t_notification::EFileSet || | |
| 1744 | aPackage.iOperation == t_notification::EFileSetAtt || | |
| 1745 | aPackage.iOperation == t_notification::EFileSetAtt_subs || | |
| 1746 | aPackage.iOperation == t_notification::ECFileManMove || | |
| 1747 | aPackage.iOperation == t_notification::EAllOps4))) | |
| 1748 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1749 | TUint setAtt = 0; | |
| 1750 | TUint clearAtt = 0; | |
| 1751 | ((TFsNotification*) notification)->Attributes(setAtt, clearAtt); | |
| 1752 | ||
| 1753 | if(aPackage.iOperation == t_notification::ECFileManMove) | |
| 1754 | 				        {
 | |
| 1755 | scratch |= ECFManAtt1; | |
| 1756 | } | |
| 1757 | else | |
| 1758 | 				        {
 | |
| 1759 | if(setAtt != KEntryAttHidden) | |
| 1760 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1761 | if(clearAtt != KEntryAttReadOnly) | |
| 1762 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1763 | } | |
| 1764 | } | |
| 1765 | else if(notificationType == TFsNotification::EMediaChange) | |
| 1766 | 					{
 | |
| 1767 | if(!(((aPackage.iNotifyType & TFsNotification::EMediaChange) == TFsNotification::EMediaChange) && | |
| 1768 | (aPackage.iOperation == t_notification::EMount || | |
| 1769 | aPackage.iOperation == t_notification::EMountScan || | |
| 1770 | aPackage.iOperation == t_notification::EDismount || | |
| 1771 | aPackage.iOperation == t_notification::EMountDismount || | |
| 1772 | aPackage.iOperation == t_notification::EMediaCardInsertion || | |
| 1773 | aPackage.iOperation == t_notification::EMediaCardRemoval || | |
| 1774 | aPackage.iOperation == t_notification::EFormat || | |
| 1775 | aPackage.iOperation == t_notification::ECFileManMove || | |
| 1776 | aPackage.iOperation == t_notification::ERawDiskWrite))) | |
| 1777 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1778 | } | |
| 1779 | else if(notificationType == TFsNotification::EDriveName) | |
| 1780 | 					{
 | |
| 1781 | if(!(((aPackage.iNotifyType & TFsNotification::EDriveName) == TFsNotification::EDriveName) && | |
| 1782 | (aPackage.iOperation == t_notification::ESetDriveName || | |
| 1783 | aPackage.iOperation == t_notification::EAllOps6))) | |
| 1784 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1785 | } | |
| 1786 | else if(notificationType == TFsNotification::EVolumeName) | |
| 1787 | 					{
 | |
| 1788 | if(!(((aPackage.iNotifyType & TFsNotification::EVolumeName) == TFsNotification::EVolumeName) && | |
| 1789 | (aPackage.iOperation == t_notification::ESetVolumeLabel || | |
| 1790 | aPackage.iOperation == t_notification::EAllOps6))) | |
| 1791 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1792 | ||
| 1793 | TPtrC newnameC; | |
| 1794 | ((TFsNotification*)notification)->NewName(newnameC); | |
| 1795 | 					aTest.Printf(_L("New volume name: %S - (%d)\n"),&newnameC,threadID);
 | |
| 1796 | } | |
| 1797 | ||
| 1798 | i++; | |
| 1799 | notification = notify->NextNotification(); | |
| 1800 | if (notification == NULL) | |
| 1801 | 					aTest.Printf(_L("Notification is NULL - (%d)\n"),threadID);
 | |
| 1802 | } | |
| 1803 | ||
| 1804 | if(i==1) //First iteration will only ever get 1 notification | |
| 1805 | 			{
 | |
| 1806 | if(numNotifications != 1) | |
| 1807 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1808 | } | |
| 1809 | ||
| 1810 | if(numNotifications < aPackage.iMaxNotifications && !overflow) //Ensure we get all of the notifications we expected | |
| 1811 | 			{
 | |
| 1812 | TRequestStatus status; | |
| 1813 | notify->RequestNotifications(status); | |
| 1814 | User::WaitForRequest(status); | |
| 1815 | } | |
| 1816 | } | |
| 1817 | ||
| 1818 | //0x307 = create1 | write1 | delete1 | rename1 | rename2 | |
| 1819 | if(aPackage.iOperation == t_notification::ECFileManMove && (scratch != 0x307)) | |
| 1820 | 	    {
 | |
| 1821 | 	    aTest.Printf(_L("CFileManMove test failure - scratch = 0x%x"),scratch);
 | |
| 1822 | safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall); | |
| 1823 | } | |
| 1824 | ||
| 1825 | } | |
| 1826 | ||
| 1827 | /* | |
| 1828 | * Watches for changes in files/directories. | |
| 1829 | * Used in TestMultipleNotificationsL(). | |
| 1830 | */ | |
| 1831 | TInt MultipleNotificationsTFWatcher(TAny* aAny) | |
| 1832 | 	{
 | |
| 1833 | CTrapCleanup* cleanup; | |
| 1834 | cleanup = CTrapCleanup::New(); | |
| 1835 | ||
| 1836 | RThread thread; | |
| 1837 | TUint64 threadID = thread.Id().Id(); | |
| 1838 | ||
| 1839 | SThreadPackageMultiple package = *(SThreadPackageMultiple*) aAny; | |
| 1840 | 	RTest multipleWatcherTest(_L("MultipleNotificationsTFWatcher"));
 | |
| 1841 | 	multipleWatcherTest.Start(_L("MultipleNotificationsTFWatcher"));
 | |
| 1842 | ||
| 1843 | RFs fs; | |
| 1844 | fs.Connect(); | |
| 1845 | ||
| 1846 | 	multipleWatcherTest.Printf(_L("MultipleNotificationsTFWatcher (%d) - Create CFsNotify\n"),threadID);
 | |
| 1847 | CFsNotify* notify = NULL; | |
| 1848 | TRAPD(r,notify = CFsNotify::NewL(fs,package.iBufferSize)); | |
| 1849 | safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall); | |
| 1850 | TBuf<40> path; | |
| 1851 | TBuf<20> filename; | |
| 1852 | if(package.iNotifyType != TFsNotification::EMediaChange && | |
| 1853 | package.iNotifyType != TFsNotification::EDriveName && | |
| 1854 | package.iNotifyType != TFsNotification::EVolumeName && | |
| 1855 | package.iOperation != t_notification::EAllOps6) | |
| 1856 | 		{
 | |
| 1857 | path.Append(gDriveToTest); | |
| 1858 | 		path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
 | |
| 1859 | path.Append(package.iFileName); | |
| 1860 | filename.Append(package.iString); | |
| 1861 | } | |
| 1862 | else | |
| 1863 | 		{
 | |
| 1864 | path.Append((TChar)globalDriveNum+(TChar)'A'); | |
| 1865 | 		path.Append(_L(":"));
 | |
| 1866 | } | |
| 1867 | TBuf<40> fullname; | |
| 1868 | fullname.Append(path); | |
| 1869 | fullname.Append(filename); | |
| 1870 | ||
| 1871 | if (package.iNotifyType == TFsNotification::EVolumeName || | |
| 1872 | package.iOperation == t_notification::EAllOps6) | |
| 1873 | 		{
 | |
| 1874 | //Ensure volume has no label | |
| 1875 | 		multipleWatcherTest.Printf(_L("Set volume label to nothing\n"));
 | |
| 1876 | 		r = fs.SetVolumeLabel(_L(""),globalDriveNum);
 | |
| 1877 | safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall); | |
| 1878 | } | |
| 1879 | ||
| 1880 | if (package.iNotifyType == TFsNotification::EDriveName || | |
| 1881 | package.iOperation == t_notification::EAllOps6) | |
| 1882 | 		{
 | |
| 1883 | //Ensure drive has no name | |
| 1884 | 		multipleWatcherTest.Printf(_L("Set drive name to nothing\n"));
 | |
| 1885 | 		r = fs.SetDriveName(globalDriveNum,_L(""));
 | |
| 1886 | safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall); | |
| 1887 | } | |
| 1888 | ||
| 1889 | 	multipleWatcherTest.Printf(_L("MultipleNotificationsTFWatcher - Add Notification for path %S\n"),&path);
 | |
| 1890 | 	multipleWatcherTest.Printf(_L("Add Notification for type %u - (%d)\n"),(TUint)package.iNotifyType,threadID);	
 | |
| 1891 | r = notify->AddNotification((TUint)package.iNotifyType,path,filename); | |
| 1892 | safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall); | |
| 1893 | ||
| 1894 | TRequestStatus status; | |
| 1895 | 	multipleWatcherTest.Printf(_L("(%d) - Request Notifications\n"),threadID);
 | |
| 1896 | r = notify->RequestNotifications(status); | |
| 1897 | safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall); | |
| 1898 | ||
| 1899 | if (package.iOperation == t_notification::EMediaCardRemoval) | |
| 1900 | 		{
 | |
| 1901 | 		multipleWatcherTest.Printf(_L("*****************************************************************\n"));
 | |
| 1902 | 		multipleWatcherTest.Printf(_L("Waiting 10 seconds.\n"));
 | |
| 1903 | 		multipleWatcherTest.Printf(_L("This is a MANUAL test, it requires the removal of the media card.\n"));
 | |
| 1904 | 		multipleWatcherTest.Printf(_L("PLEASE REMOVE THE MEDIA CARD. (DriveNumber %d)\n"),globalDriveNum);
 | |
| 1905 | 		multipleWatcherTest.Printf(_L("Or press Ctrl + F5 on the emulator.\n"));
 | |
| 1906 | 		multipleWatcherTest.Printf(_L("*****************************************************************\n"));
 | |
| 1907 | } | |
| 1908 | if (package.iOperation == t_notification::EMediaCardInsertion) | |
| 1909 | 		{
 | |
| 1910 | 		multipleWatcherTest.Printf(_L("*******************************************************************\n"));
 | |
| 1911 | 		multipleWatcherTest.Printf(_L("Waiting 10 seconds.\n"));
 | |
| 1912 | 		multipleWatcherTest.Printf(_L("This is a MANUAL test, it requires the insertion of the media card.\n"));
 | |
| 1913 | 		multipleWatcherTest.Printf(_L("PLEASE INSERT THE MEDIA CARD. (DriveNumber %d)\n"),globalDriveNum);
 | |
| 1914 | 		multipleWatcherTest.Printf(_L("*******************************************************************\n"));
 | |
| 1915 | } | |
| 1916 | ||
| 1917 | 	multipleWatcherTest.Printf(_L("(%d) - Signal Test thread to start Doer thread\n"),threadID);
 | |
| 1918 | package.iBarrier.Signal(); | |
| 1919 | User::WaitForRequest(status); | |
| 1920 | ||
| 1921 | 	multipleWatcherTest.Printf(_L("(%d) - MultipleNotificationsTFWatcher Line %d\n"),threadID,__LINE__);
 | |
| 1922 | ||
| 1923 | //Handles the notifications | |
| 1924 | HandleMultipleNotifications(multipleWatcherTest, package, notify, (TDesC&)fullname); | |
| 1925 | ||
| 1926 | 	multipleWatcherTest.Printf(_L("(%d) - MultipleNotificationsTFWatcher Line %d\n"),threadID,__LINE__);
 | |
| 1927 | ||
| 1928 | delete notify; | |
| 1929 | fs.Close(); | |
| 1930 | multipleWatcherTest.End(); | |
| 1931 | multipleWatcherTest.Close(); | |
| 1932 | delete cleanup; | |
| 1933 | return KErrNone; | |
| 1934 | } | |
| 1935 | ||
| 1936 | /* | |
| 1937 | * TestTwoNotificationsL - Tests File Write, 1 Doer writes to a file twice. | |
| 1938 | * 1 Watcher watches for file write changes. Just so happens that the second one overflows. | |
| 1939 | */ | |
| 1940 | TInt TestTwoNotificationsL() | |
| 1941 | 	{
 | |
| 1942 | 	test.Next(_L("TestTwoNotifications"));
 | |
| 1943 | ||
| 1944 | RFs fs; | |
| 1945 | fs.Connect(); | |
| 1946 | RSemaphore twoNotificationsDoerBar; | |
| 1947 | SThreadPackageMultiple package; | |
| 1948 | _LIT(KFileName,"file0.write"); | |
| 1949 | package.iIterations = 10; | |
| 1950 | package.iOperation = t_notification::EFileWrite; | |
| 1951 | package.iNotifyType = TFsNotification::EFileChange; | |
| 1952 | package.iFileName = KFileName; | |
| 1953 | package.iBufferSize = 100; //Should get changed to KMin... in CFsNotify::NewL | |
| 1954 | ||
| 1955 | User::LeaveIfError(twoNotificationsDoerBar.CreateLocal(0)); | |
| 1956 | User::LeaveIfError(package.iBarrier.CreateLocal(0)); | |
| 1957 | RThread watcher; | |
| 1958 | RThread doer; | |
| 1959 | ||
| 1960 | 	TInt r = watcher.Create(_L("TestTwoNotificationsWatcherThread"),MultipleNotificationsTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
 | |
| 1961 | test(r==KErrNone); | |
| 1962 | 	r = doer.Create(_L("TestTwoNotificationsDoerThread"),TwoNotificationsTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
 | |
| 1963 | test(r==KErrNone); | |
| 1964 | 	test.Next(_L("TestTwoNotifications - Resume Watcher"));
 | |
| 1965 | watcher.Resume(); | |
| 1966 | 	test.Next(_L("TestTwoNotifications - Wait for Watcher to be ready"));
 | |
| 1967 | package.iBarrier.Wait(); //Wait till Watcher has requested notification | |
| 1968 | 	test.Next(_L("TestTwoNotifications - Resume Doer"));
 | |
| 1969 | doer.Resume(); | |
| 1970 | ||
| 1971 | 	test.Next(_L("TestTwoNotifications - Wait for doer thread death"));
 | |
| 1972 | TRequestStatus status; | |
| 1973 | doer.Logon(status); | |
| 1974 | User::WaitForRequest(status); | |
| 1975 | test(doer.ExitReason()==KErrNone); | |
| 1976 | ||
| 1977 | 	test.Next(_L("TestTwoNotifications - Wait for watcher thread death"));
 | |
| 1978 | watcher.Logon(status); | |
| 1979 | User::WaitForRequest(status); | |
| 1980 | test(watcher.ExitReason()==KErrNone); | |
| 1981 | ||
| 1982 | CLOSE_AND_WAIT(doer); | |
| 1983 | CLOSE_AND_WAIT(watcher); | |
| 1984 | ||
| 1985 | twoNotificationsDoerBar.Close(); | |
| 1986 | package.iBarrier.Close(); | |
| 1987 | fs.Close(); | |
| 1988 | ||
| 1989 | return KErrNone; | |
| 1990 | } | |
| 1991 | ||
| 1992 | ||
| 1993 | /* | |
| 1994 | * Watch two threads to receive two notifications. | |
| 1995 | * Used in TestTwoDoersL(). | |
| 1996 | */ | |
| 1997 | TInt TestTwoDoersWatcher(TAny* aAny) | |
| 1998 | 	{
 | |
| 1999 | CTrapCleanup* cleanup; | |
| 2000 | cleanup = CTrapCleanup::New(); | |
| 2001 | ||
| 2002 | RSemaphore& twoThreadsBarrier = *(RSemaphore*)aAny; | |
| 2003 | 	RTest twoThreadsWatcherTest(_L("TwoThreadsWatcher"));
 | |
| 2004 | 	twoThreadsWatcherTest.Start(_L("TwoThreadsWatcher"));
 | |
| 2005 | ||
| 2006 | RFs fs; | |
| 2007 | fs.Connect(); | |
| 2008 | ||
| 2009 | 	twoThreadsWatcherTest.Next(_L("Create CFsNotify"));
 | |
| 2010 | CFsNotify* notify = NULL; | |
| 2011 | TRAPD(r,notify = CFsNotify::NewL(fs,200)); | |
| 2012 | twoThreadsWatcherTest(r == KErrNone); | |
| 2013 | ||
| 2014 | TBuf<40> path1; | |
| 2015 | TBuf<20> filename1; | |
| 2016 | TBuf<40> path2; | |
| 2017 | TBuf<20> filename2; | |
| 2018 | path1.Append(gDriveToTest); | |
| 2019 | path2.Append(gDriveToTest); | |
| 2020 | 	path1.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 2021 | 	filename1.Append(_L("file1.create"));
 | |
| 2022 | 	path2.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 2023 | 	filename2.Append(_L("file2.create"));
 | |
| 2024 | TBuf<40> fullname1; | |
| 2025 | fullname1.Append(path1); | |
| 2026 | fullname1.Append(filename1); | |
| 2027 | TBuf<40> fullname2; | |
| 2028 | fullname2.Append(path2); | |
| 2029 | fullname2.Append(filename2); | |
| 2030 | ||
| 2031 | 	twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - Add Notification for %S\n"),&path1);
 | |
| 2032 | r = notify->AddNotification((TUint)TFsNotification::ECreate,path1,filename1); | |
| 2033 | twoThreadsWatcherTest(r == KErrNone); | |
| 2034 | ||
| 2035 | 	twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - Add Notification for %S\n"),&path2);
 | |
| 2036 | r = notify->AddNotification((TUint)TFsNotification::ECreate,path2,filename2); | |
| 2037 | twoThreadsWatcherTest(r == KErrNone); | |
| 2038 | ||
| 2039 | TRequestStatus status; | |
| 2040 | 	twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Request Notifications"));
 | |
| 2041 | r = notify->RequestNotifications(status); | |
| 2042 | twoThreadsWatcherTest(r == KErrNone); | |
| 2043 | ||
| 2044 | twoThreadsBarrier.Signal(); //Signal Doer threads to start | |
| 2045 | User::WaitForRequest(status); | |
| 2046 | ||
| 2047 | // We should be getting 2 notifications | |
| 2048 | // Test notifications are not null and check notification types and paths | |
| 2049 | // 1st notification: | |
| 2050 | 	twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - First Notification"));
 | |
| 2051 | const TFsNotification* notification = notify->NextNotification(); | |
| 2052 | twoThreadsWatcherTest(notification != NULL); | |
| 2053 | 	twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - First Notification Type"));
 | |
| 2054 | TFsNotification::TFsNotificationType notificationType = ((TFsNotification*)notification)->NotificationType(); | |
| 2055 | twoThreadsWatcherTest(notificationType == TFsNotification::ECreate); | |
| 2056 | 	twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - First Notification Path"));
 | |
| 2057 | TPtrC _pathC; | |
| 2058 | ((TFsNotification*)notification)->Path(_pathC); | |
| 2059 | 	twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - First Notification Path returned %S\n"),&_pathC);
 | |
| 2060 | TBuf<40> _path; | |
| 2061 | _path.Copy(_pathC); | |
| 2062 | //We can't guarantee which thread ran first so check that it was either path1 or path2 | |
| 2063 | twoThreadsWatcherTest(_path.Match(fullname1) == KErrNone || _path.Match(fullname2) == KErrNone); | |
| 2064 | ||
| 2065 | // 2nd notification: | |
| 2066 | 	twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Second Notification"));
 | |
| 2067 | notification = notify->NextNotification(); | |
| 2068 | // Check if next notification exists | |
| 2069 | if (!notification) | |
| 2070 | 		{
 | |
| 2071 | notify->RequestNotifications(status); | |
| 2072 | User::WaitForRequest(status); | |
| 2073 | notification = notify->NextNotification(); | |
| 2074 | } | |
| 2075 | twoThreadsWatcherTest(notification != NULL); | |
| 2076 | 	twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Second Notification Type"));
 | |
| 2077 | notificationType = ((TFsNotification*)notification)->NotificationType(); | |
| 2078 | twoThreadsWatcherTest(notificationType == TFsNotification::ECreate); | |
| 2079 | 	twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Second Notification Path"));
 | |
| 2080 | ((TFsNotification*)notification)->Path(_pathC); | |
| 2081 | 	twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - Second Notification Path returned %S\n"),&_pathC);
 | |
| 2082 | _path.Copy(_pathC); | |
| 2083 | twoThreadsWatcherTest(_path.Match(fullname1) == KErrNone || _path.Match(fullname2) == KErrNone); | |
| 2084 | ||
| 2085 | delete notify; | |
| 2086 | fs.Close(); | |
| 2087 | twoThreadsWatcherTest.End(); | |
| 2088 | twoThreadsWatcherTest.Close(); | |
| 2089 | delete cleanup; | |
| 2090 | return KErrNone; | |
| 2091 | } | |
| 2092 | ||
| 2093 | /* | |
| 2094 | * TestTwoDoersL - Two Doer threads create a file each and there's one Watcher | |
| 2095 | * which expects two notifications (one from each Doer). | |
| 2096 | */ | |
| 2097 | TInt TestTwoDoersL() | |
| 2098 | 	{
 | |
| 2099 | 	test.Next(_L("TestTwoDoers"));
 | |
| 2100 | ||
| 2101 | RFs fs; | |
| 2102 | fs.Connect(); | |
| 2103 | ||
| 2104 | _LIT(KFileName1,"file1.create"); | |
| 2105 | _LIT(KFileName2,"file2.create"); | |
| 2106 | RSemaphore simpleBarrierTest; | |
| 2107 | SThreadPackage pkgDoer1; | |
| 2108 | SThreadPackage pkgDoer2; | |
| 2109 | pkgDoer1.iFileName = KFileName1; | |
| 2110 | pkgDoer2.iFileName = KFileName2; | |
| 2111 | ||
| 2112 | User::LeaveIfError(pkgDoer1.iBarrier.CreateLocal(0)); | |
| 2113 | User::LeaveIfError(pkgDoer2.iBarrier.CreateLocal(0)); | |
| 2114 | User::LeaveIfError(simpleBarrierTest.CreateLocal(0)); | |
| 2115 | RThread watcher; | |
| 2116 | RThread doer1; | |
| 2117 | RThread doer2; | |
| 2118 | ||
| 2119 | 	watcher.Create(_L("TestTwoDoers-WatcherThread"),TestTwoDoersWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&simpleBarrierTest);
 | |
| 2120 | 	doer1.Create(_L("TestTwoDoers-DoerThread1"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer1);
 | |
| 2121 | 	doer2.Create(_L("TestTwoDoers-DoerThread2"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer2);
 | |
| 2122 | watcher.Resume(); | |
| 2123 | simpleBarrierTest.Wait(); //Wait until Watcher has created CFsNotify | |
| 2124 | ||
| 2125 | doer1.Resume(); | |
| 2126 | doer2.Resume(); | |
| 2127 | ||
| 2128 | 	test.Next(_L("TestTwoDoers - Wait for doer1 thread death"));
 | |
| 2129 | TRequestStatus status; | |
| 2130 | doer1.Logon(status); | |
| 2131 | User::WaitForRequest(status); | |
| 2132 | test(doer1.ExitReason()==KErrNone); | |
| 2133 | ||
| 2134 | 	test.Next(_L("TestTwoDoers - Wait for doer2 thread death"));
 | |
| 2135 | doer2.Logon(status); | |
| 2136 | User::WaitForRequest(status); | |
| 2137 | test(doer2.ExitReason()==KErrNone); | |
| 2138 | ||
| 2139 | 	test.Next(_L("TestTwoDoers - Wait for watcher thread death"));
 | |
| 2140 | watcher.Logon(status); | |
| 2141 | RTimer timer1; | |
| 2142 | TInt r = timer1.CreateLocal(); | |
| 2143 | 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 2144 | TRequestStatus timeout; | |
| 2145 | TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds | |
| 2146 | timer1.After(timeout,time); | |
| 2147 | User::WaitForRequest(timeout,status); | |
| 2148 | test(status.Int() != KRequestPending); | |
| 2149 | timer1.Cancel(); | |
| 2150 | timer1.Close(); | |
| 2151 | //User::WaitForRequest(status); | |
| 2152 | test(watcher.ExitReason()==KErrNone); | |
| 2153 | ||
| 2154 | CLOSE_AND_WAIT(doer1); | |
| 2155 | CLOSE_AND_WAIT(doer2); | |
| 2156 | CLOSE_AND_WAIT(watcher); | |
| 2157 | ||
| 2158 | pkgDoer1.iBarrier.Close(); | |
| 2159 | pkgDoer2.iBarrier.Close(); | |
| 2160 | simpleBarrierTest.Close(); | |
| 2161 | fs.Close(); | |
| 2162 | return KErrNone; | |
| 2163 | } | |
| 2164 | ||
| 2165 | /* | |
| 2166 | * TestTwoWatchersL - Uses two watcher threads and one doer thread to test that running | |
| 2167 | * two distinct sub sessions at the same time (both watch the same file). | |
| 2168 | */ | |
| 2169 | TInt TestTwoWatchersL() | |
| 2170 | 	{
 | |
| 2171 | 	test.Next(_L("TestTwoWatchers"));
 | |
| 2172 | RFs fs; | |
| 2173 | fs.Connect(); | |
| 2174 | _LIT(KFileName,"file.creat3"); | |
| 2175 | SThreadPackage pkgDoer; | |
| 2176 | pkgDoer.iFileName = KFileName; | |
| 2177 | ||
| 2178 | SThreadPackage watcherPkg; | |
| 2179 | watcherPkg.iFileName = KFileName; | |
| 2180 | ||
| 2181 | User::LeaveIfError(pkgDoer.iBarrier.CreateLocal(0)); | |
| 2182 | User::LeaveIfError(watcherPkg.iBarrier.CreateLocal(0)); | |
| 2183 | RThread watcher; | |
| 2184 | RThread watcher2; | |
| 2185 | RThread doer; | |
| 2186 | 	watcher.Create(_L("TestTwoWatchersWatcherThread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcherPkg);
 | |
| 2187 | 	watcher2.Create(_L("TestTwoWatchersWatcher2Thread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcherPkg);
 | |
| 2188 | 	doer.Create(_L("TestTwoWatchersDoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer);
 | |
| 2189 | watcher.Resume(); | |
| 2190 | watcher2.Resume(); | |
| 2191 | watcherPkg.iBarrier.Wait(); //Wait till both watchers have requested notification | |
| 2192 | watcherPkg.iBarrier.Wait(); | |
| 2193 | doer.Resume(); | |
| 2194 | ||
| 2195 | 	test.Printf(_L("Wait for DOER to terminate , Line %d"),__LINE__);
 | |
| 2196 | TRequestStatus status; | |
| 2197 | doer.Logon(status); | |
| 2198 | User::WaitForRequest(status); | |
| 2199 | test(doer.ExitReason()==KErrNone); | |
| 2200 | ||
| 2201 | 	test.Printf(_L("Wait for WATCHER to terminate , Line %d"),__LINE__);
 | |
| 2202 | watcher.Logon(status); | |
| 2203 | RTimer timer1; | |
| 2204 | TInt r = timer1.CreateLocal(); | |
| 2205 | 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 2206 | TRequestStatus timeout; | |
| 2207 | TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds | |
| 2208 | timer1.After(timeout,time); | |
| 2209 | User::WaitForRequest(timeout,status); | |
| 2210 | test(status.Int() != KRequestPending); | |
| 2211 | timer1.Cancel(); | |
| 2212 | timer1.Close(); | |
| 2213 | // User::WaitForRequest(status); | |
| 2214 | test(watcher.ExitReason()==KErrNone); | |
| 2215 | ||
| 2216 | 	test.Printf(_L("Wait for WATCHER2 to terminate , Line %d"),__LINE__);
 | |
| 2217 | watcher2.Logon(status); | |
| 2218 | RTimer timer2; | |
| 2219 | r = timer2.CreateLocal(); | |
| 2220 | 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 2221 | TRequestStatus timeout2; | |
| 2222 | timer2.After(timeout2,time); | |
| 2223 | User::WaitForRequest(timeout2,status); | |
| 2224 | test(status.Int() != KRequestPending); | |
| 2225 | timer2.Cancel(); | |
| 2226 | timer2.Close(); | |
| 2227 | //User::WaitForRequest(status); | |
| 2228 | test(watcher2.ExitReason()==KErrNone); | |
| 2229 | ||
| 2230 | CLOSE_AND_WAIT(doer); | |
| 2231 | CLOSE_AND_WAIT(watcher); | |
| 2232 | CLOSE_AND_WAIT(watcher2); | |
| 2233 | ||
| 2234 | pkgDoer.iBarrier.Close(); | |
| 2235 | watcherPkg.iBarrier.Close(); | |
| 2236 | fs.Close(); | |
| 2237 | return KErrNone; | |
| 2238 | } | |
| 2239 | ||
| 2240 | ||
| 2241 | /* | |
| 2242 | * TestTwoWatchersTwoDoersL - Two watcher threads watches two different doer threads. | |
| 2243 | */ | |
| 2244 | TInt TestTwoWatchersTwoDoersL() | |
| 2245 | 	{
 | |
| 2246 | 	test.Next(_L("TestTwoWatchersTwoDoers"));
 | |
| 2247 | RFs fs; | |
| 2248 | fs.Connect(); | |
| 2249 | _LIT(KFileName1,"f1le.create"); | |
| 2250 | _LIT(KFileName2,"f2le.create"); | |
| 2251 | SThreadPackage package1; | |
| 2252 | package1.iFileName = KFileName1; | |
| 2253 | ||
| 2254 | SThreadPackage package2; | |
| 2255 | package2.iFileName = KFileName2; | |
| 2256 | ||
| 2257 | User::LeaveIfError(package1.iBarrier.CreateLocal(0)); | |
| 2258 | User::LeaveIfError(package2.iBarrier.CreateLocal(0)); | |
| 2259 | RThread watcher; | |
| 2260 | RThread watcher2; | |
| 2261 | RThread doer; | |
| 2262 | RThread doer2; | |
| 2263 | 	watcher.Create(_L("TestTwoWatchersTwoDoersWatcherThread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package1);
 | |
| 2264 | 	doer.Create(_L("TestTwoWatchersTwoDoersDoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package1);
 | |
| 2265 | ||
| 2266 | 	watcher2.Create(_L("TestTwoWatchersTwoDoersWatcher2Thread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package2);
 | |
| 2267 | 	doer2.Create(_L("TestTwoWatchersTwoDoersDoer2Thread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package2);
 | |
| 2268 | watcher.Resume(); | |
| 2269 | watcher2.Resume(); | |
| 2270 | package1.iBarrier.Wait(); //Wait till both watchers have requested notification | |
| 2271 | package2.iBarrier.Wait(); | |
| 2272 | doer.Resume(); | |
| 2273 | doer2.Resume(); | |
| 2274 | ||
| 2275 | 	test.Printf(_L("Wait for DOER to terminate , Line %d"),__LINE__);
 | |
| 2276 | TRequestStatus status; | |
| 2277 | doer.Logon(status); | |
| 2278 | User::WaitForRequest(status); | |
| 2279 | test(doer.ExitReason()==KErrNone); | |
| 2280 | ||
| 2281 | 	test.Printf(_L("Wait for DOER2 to terminate , Line %d"),__LINE__);
 | |
| 2282 | doer2.Logon(status); | |
| 2283 | User::WaitForRequest(status); | |
| 2284 | test(doer2.ExitReason()==KErrNone); | |
| 2285 | ||
| 2286 | 	test.Printf(_L("Wait for WATCHER to terminate , Line %d"),__LINE__);
 | |
| 2287 | watcher.Logon(status); | |
| 2288 | RTimer timer1; | |
| 2289 | TInt r = timer1.CreateLocal(); | |
| 2290 | 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 2291 | TRequestStatus timeout; | |
| 2292 | TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds | |
| 2293 | timer1.After(timeout,time); | |
| 2294 | User::WaitForRequest(timeout,status); | |
| 2295 | test(status.Int() != KRequestPending); | |
| 2296 | timer1.Cancel(); | |
| 2297 | timer1.Close(); | |
| 2298 | test(watcher.ExitReason()==KErrNone); | |
| 2299 | ||
| 2300 | 	test.Printf(_L("Wait for WATCHER2 to terminate , Line %d"),__LINE__);
 | |
| 2301 | watcher2.Logon(status); | |
| 2302 | RTimer timer2; | |
| 2303 | r = timer2.CreateLocal(); | |
| 2304 | 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 2305 | TRequestStatus timeout2; | |
| 2306 | timer2.After(timeout2,time); | |
| 2307 | User::WaitForRequest(timeout2,status); | |
| 2308 | test(status.Int() != KRequestPending); | |
| 2309 | timer2.Cancel(); | |
| 2310 | timer2.Close(); | |
| 2311 | test(watcher2.ExitReason()==KErrNone); | |
| 2312 | ||
| 2313 | CLOSE_AND_WAIT(doer); | |
| 2314 | CLOSE_AND_WAIT(doer2); | |
| 2315 | CLOSE_AND_WAIT(watcher); | |
| 2316 | CLOSE_AND_WAIT(watcher2); | |
| 2317 | ||
| 2318 | package1.iBarrier.Close(); | |
| 2319 | package2.iBarrier.Close(); | |
| 2320 | fs.Close(); | |
| 2321 | return KErrNone; | |
| 2322 | } | |
| 2323 | ||
| 2324 | ||
| 2325 | /* | |
| 2326 | * Multi-purpose test | |
| 2327 | * | |
| 2328 | * If aFailureExpected is ETrue, it is expected that the watcher thread is not terminated normally, | |
| 2329 | * due to the notification(s) not being sent. | |
| 2330 | * Since this function is called many times, aLineCall is used to show the line where it is called from. | |
| 2331 | * See SThreadPackageMultiple. | |
| 2332 | */ | |
| 2333 | TInt TestMultipleNotificationsL(const TDesC& aFilename, const TDesC& aString, TInt aIterations, | |
| 2334 | TInt aMaxNotifications, t_notification::EOperation aOperation, | |
| 2335 | TUint aNotifyType, TInt aBufferSize, TBool aFailureExpected, TInt aLineCall) | |
| 2336 | 	{
 | |
| 2337 | 	test.Next(_L("TestMultipleNotifications"));
 | |
| 2338 | ||
| 2339 | RFs fs; | |
| 2340 | fs.Connect(); | |
| 2341 | SThreadPackageMultiple package; | |
| 2342 | package.iIterations = aIterations; | |
| 2343 | package.iMaxNotifications = aMaxNotifications; | |
| 2344 | package.iOperation = aOperation; | |
| 2345 | package.iNotifyType = (TFsNotification::TFsNotificationType)aNotifyType; | |
| 2346 | package.iString = aString; | |
| 2347 | package.iFileName = aFilename; | |
| 2348 | package.iBufferSize = aBufferSize; | |
| 2349 | package.iLineCall = aLineCall; | |
| 2350 | ||
| 2351 | User::LeaveIfError(package.iBarrier.CreateLocal(0)); | |
| 2352 | RThread watcher; | |
| 2353 | RThread doer; | |
| 2354 | RTimer tim; | |
| 2355 | User::LeaveIfError(tim.CreateLocal()); | |
| 2356 | ||
| 2357 | 	TInt r = watcher.Create(_L("TestMultipleNotificationsWatcherThread"),MultipleNotificationsTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
 | |
| 2358 | safe_test(test,r,__LINE__,package.iLineCall); | |
| 2359 | 	r = doer.Create(_L("TestMultipleNotificationsDoerThread"),MultipleNotificationTFDoer,KDefaultStackSize*2,KMinHeapSize,KMaxHeapSize,&package);
 | |
| 2360 | safe_test(test,r,__LINE__,package.iLineCall); | |
| 2361 | 	test.Next(_L("TestMultipleNotifications - Resume Watcher"));
 | |
| 2362 | watcher.Resume(); | |
| 2363 | 	test.Next(_L("TestMultipleNotifications - Wait for Watcher to be ready"));
 | |
| 2364 | package.iBarrier.Wait(); //Wait till Watcher has requested notification | |
| 2365 | 	test.Next(_L("TestMultipleNotifications - Resume Doer"));
 | |
| 2366 | doer.Resume(); | |
| 2367 | ||
| 2368 | 	test.Next(_L("TestMultipleNotifications - Wait for doer thread death"));
 | |
| 2369 | TRequestStatus status; | |
| 2370 | doer.Logon(status); | |
| 2371 | User::WaitForRequest(status); | |
| 2372 | 	test.Printf(_L("TestMultipleNotifications - Doer Exit Reason %d\n"),doer.ExitReason());
 | |
| 2373 | safe_test(test,doer.ExitReason(),__LINE__,package.iLineCall); | |
| 2374 | ||
| 2375 | TRequestStatus timStatus; | |
| 2376 | TTimeIntervalMicroSeconds32 timeout; | |
| 2377 | if (aFailureExpected && !(package.iOperation == t_notification::EMediaCardInsertion || | |
| 2378 | package.iOperation == t_notification::EMediaCardRemoval)) | |
| 2379 | 		{
 | |
| 2380 | timeout = 1500000; //1.5 seconds, we don't want to wait too long if we expect it to fail | |
| 2381 | } | |
| 2382 | else | |
| 2383 | 		{
 | |
| 2384 | timeout = 10000000; //10 seconds | |
| 2385 | } | |
| 2386 | tim.After(timStatus,timeout); | |
| 2387 | ||
| 2388 | 	test.Next(_L("TestMultipleNotifications - Wait for watcher thread death or timeout"));
 | |
| 2389 | watcher.Logon(status); | |
| 2390 | User::WaitForRequest(status,timStatus); | |
| 2391 | if(!(status != KRequestPending || aFailureExpected)) | |
| 2392 | safe_test(test,KErrGeneral,__LINE__,package.iLineCall); | |
| 2393 | ||
| 2394 | 	test.Printf(_L("TestMultipleNotifications - Watcher Exit Reason %d\n"),watcher.ExitReason());
 | |
| 2395 | safe_test(test,watcher.ExitReason(),__LINE__,package.iLineCall); | |
| 2396 | ||
| 2397 | CLOSE_AND_WAIT(doer); | |
| 2398 | ||
| 2399 | if(status == KRequestPending) | |
| 2400 | 		{
 | |
| 2401 | watcher.Kill(KErrTimedOut); | |
| 2402 | 		test.Printf(_L("TestMultipleNotifications - Watcher timed out\n"));
 | |
| 2403 | } | |
| 2404 | CLOSE_AND_WAIT(watcher); | |
| 2405 | ||
| 2406 | package.iBarrier.Close(); | |
| 2407 | fs.Close(); | |
| 2408 | tim.Close(); | |
| 2409 | 	test.Printf(_L("----------------------------------------------------------------------\n"));
 | |
| 2410 | return KErrNone; | |
| 2411 | } | |
| 2412 | ||
| 2413 | TInt TestMultipleNotificationsL(const TDesC& aFilename, const TDesC& aString, TInt aIterations, | |
| 2414 | TInt aMaxNotifications, t_notification::EOperation aOperation, | |
| 2415 | TFsNotification::TFsNotificationType aNotifyType, TInt aBufferSize, | |
| 2416 | TBool aFailureExpected, TInt aLineCall) | |
| 2417 | 	{
 | |
| 2418 | return TestMultipleNotificationsL(aFilename, aString, aIterations, aMaxNotifications, aOperation, | |
| 2419 | (TUint)aNotifyType, aBufferSize, aFailureExpected, aLineCall); | |
| 2420 | } | |
| 2421 | ||
| 2422 | TInt TestMultipleNotificationsL(const TDesC& aFilename, TInt aIterations, TInt aMaxNotifications, | |
| 2423 | t_notification::EOperation aOperation, TUint aNotifyType, TInt aBufferSize, | |
| 2424 | TBool aFailureExpected, TInt aLineCall) | |
| 2425 | 	{
 | |
| 2426 | 	return TestMultipleNotificationsL(aFilename,_L(""), aIterations, aMaxNotifications, aOperation, aNotifyType,
 | |
| 2427 | aBufferSize, aFailureExpected, aLineCall); | |
| 2428 | } | |
| 2429 | ||
| 2430 | ||
| 2431 | // Watcher for TestAddRemoveNotificationL() | |
| 2432 | TInt TestAddRemoveNotificationWatcher(TAny* aAny) | |
| 2433 | 	{
 | |
| 2434 | CTrapCleanup* cleanup; | |
| 2435 | cleanup = CTrapCleanup::New(); | |
| 2436 | RThread thread; | |
| 2437 | TUint64 threadId = thread.Id().Id(); | |
| 2438 | ||
| 2439 | SThreadPackage pkgDoer = *(SThreadPackage*)aAny; | |
| 2440 | RSemaphore& addRemoveBarrier = pkgDoer.iBarrier; | |
| 2441 | ||
| 2442 | 	RTest addRemoveWatcherTest(_L("TestAddRemoveNotificationWatcher"));
 | |
| 2443 | 	addRemoveWatcherTest.Start(_L("TestAddRemoveNotificationWatcher"));
 | |
| 2444 | ||
| 2445 | RFs fs; | |
| 2446 | fs.Connect(); | |
| 2447 | ||
| 2448 | 	addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - Create CFsNotify\n"),threadId);
 | |
| 2449 | CFsNotify* notify = NULL; | |
| 2450 | TRAPD(r,notify = CFsNotify::NewL(fs,100); ); | |
| 2451 | addRemoveWatcherTest( r == KErrNone); | |
| 2452 | TBuf<40> path; | |
| 2453 | TBuf<20> filename; | |
| 2454 | path.Append(gDriveToTest); | |
| 2455 | 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
 | |
| 2456 | filename.Append(pkgDoer.iFileName); | |
| 2457 | ||
| 2458 | 	addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher - Add Notification for %S\n"),&path);
 | |
| 2459 | r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename); | |
| 2460 | addRemoveWatcherTest(r==KErrNone); | |
| 2461 | 	addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - Remove Notifications\n"),threadId);
 | |
| 2462 | r = notify->RemoveNotifications(); | |
| 2463 | addRemoveWatcherTest(r==KErrNone); | |
| 2464 | 	addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - Request Notifications\n"),threadId);
 | |
| 2465 | TRequestStatus status; | |
| 2466 | r = notify->RequestNotifications(status); | |
| 2467 | addRemoveWatcherTest(r==KErrNone); | |
| 2468 | 	addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher status = %d"),status.Int());
 | |
| 2469 | addRemoveBarrier.Signal(); | |
| 2470 | ||
| 2471 | 	addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - NextNotification\n"),threadId);
 | |
| 2472 | //We should not be getting any notifications as the notification request has been removed | |
| 2473 | const TFsNotification* notification = notify->NextNotification(); | |
| 2474 | addRemoveWatcherTest(notification == NULL); | |
| 2475 | ||
| 2476 | delete notify; | |
| 2477 | fs.Close(); | |
| 2478 | addRemoveWatcherTest.End(); | |
| 2479 | addRemoveWatcherTest.Close(); | |
| 2480 | delete cleanup; | |
| 2481 | return KErrNone; | |
| 2482 | } | |
| 2483 | ||
| 2484 | ||
| 2485 | /* | |
| 2486 | * TestAddRemoveNotificationL - Watcher adds and removes notification request. | |
| 2487 | * Any changes by doer thread should not be detected. | |
| 2488 | */ | |
| 2489 | TInt TestAddRemoveNotificationL() | |
| 2490 | 	{
 | |
| 2491 | 	test.Next(_L("TestAddRemoveNotification"));
 | |
| 2492 | RFs fs; | |
| 2493 | fs.Connect(); | |
| 2494 | ||
| 2495 | SThreadPackage package; | |
| 2496 | _LIT(KFileName,"noFile.create"); | |
| 2497 | package.iFileName = KFileName; | |
| 2498 | ||
| 2499 | User::LeaveIfError(package.iBarrier.CreateLocal(0)); | |
| 2500 | RThread watcher; | |
| 2501 | RThread doer; | |
| 2502 | ||
| 2503 | 	watcher.Create(_L("TestAddRemoveNotification-WatcherThread"),TestAddRemoveNotificationWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
 | |
| 2504 | 	doer.Create(_L("TestAddRemoveNotification-DoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
 | |
| 2505 | watcher.Resume(); | |
| 2506 | ||
| 2507 | 	test.Printf(_L("TestAddRemoveNotification - Wait until Watcher has created CFsNotify\n"));
 | |
| 2508 | package.iBarrier.Wait(); //Wait until Watcher has created CFsNotify | |
| 2509 | doer.Resume(); | |
| 2510 | ||
| 2511 | 	test.Next(_L("TestAddRemoveNotification - Wait for doer thread death"));
 | |
| 2512 | TRequestStatus status; | |
| 2513 | doer.Logon(status); | |
| 2514 | User::WaitForRequest(status); | |
| 2515 | test(doer.ExitReason()==KErrNone); | |
| 2516 | ||
| 2517 | 	test.Next(_L("TestAddRemoveNotification - Wait for watcher thread death"));
 | |
| 2518 | watcher.Logon(status); | |
| 2519 | RTimer timer1; | |
| 2520 | TInt r = timer1.CreateLocal(); | |
| 2521 | 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 2522 | TRequestStatus timeout; | |
| 2523 | TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds | |
| 2524 | timer1.After(timeout,time); | |
| 2525 | User::WaitForRequest(timeout,status); | |
| 2526 | test(status.Int() != KRequestPending); | |
| 2527 | timer1.Cancel(); | |
| 2528 | timer1.Close(); | |
| 2529 | 	test.Printf(_L("Test - Watcher Exit Reason %d\n"),watcher.ExitReason());
 | |
| 2530 | test(watcher.ExitReason()==KErrNone); | |
| 2531 | ||
| 2532 | CLOSE_AND_WAIT(doer); | |
| 2533 | CLOSE_AND_WAIT(watcher); | |
| 2534 | ||
| 2535 | package.iBarrier.Close(); | |
| 2536 | fs.Close(); | |
| 2537 | return KErrNone; | |
| 2538 | } | |
| 2539 | ||
| 2540 | ||
| 2541 | /* | |
| 2542 | * Adds and cancels notification request. | |
| 2543 | * Used in TestCancelNotificationL(). | |
| 2544 | */ | |
| 2545 | TInt TestCancelNotificationWatcher(TAny* aAny) | |
| 2546 | 	{
 | |
| 2547 | CTrapCleanup* cleanup; | |
| 2548 | cleanup = CTrapCleanup::New(); | |
| 2549 | ||
| 2550 | 	RTest cancelNotificationsWatcherTest(_L("TestCancelNotificationWatcher"));
 | |
| 2551 | 	cancelNotificationsWatcherTest.Start(_L("TestCancelNotificationWatcher"));
 | |
| 2552 | ||
| 2553 | RThread thread; | |
| 2554 | TUint64 threadId = thread.Id().Id(); | |
| 2555 | ||
| 2556 | SThreadPackageDualSemaphore pkgDoer = *(SThreadPackageDualSemaphore*)aAny; | |
| 2557 | RSemaphore& addRemoveBarrier = pkgDoer.iBarrier; | |
| 2558 | RSemaphore& addRemoveBarrier2 = pkgDoer.iBarrier2; | |
| 2559 | ||
| 2560 | RFs fs; | |
| 2561 | fs.Connect(); | |
| 2562 | ||
| 2563 | 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Create CFsNotify\n"),threadId);
 | |
| 2564 | CFsNotify* notify = NULL; | |
| 2565 | TRAPD(r,notify = CFsNotify::NewL(fs,100); ); | |
| 2566 | cancelNotificationsWatcherTest(r == KErrNone); | |
| 2567 | TBuf<40> path; | |
| 2568 | TBuf<20> filename; | |
| 2569 | path.Append(gDriveToTest); | |
| 2570 | 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
 | |
| 2571 | filename.Append(pkgDoer.iFileName); | |
| 2572 | ||
| 2573 | 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher - Add Notification for %S\n"),&path);
 | |
| 2574 | r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename); | |
| 2575 | cancelNotificationsWatcherTest(r==KErrNone); | |
| 2576 | 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Request Notifications\n"),threadId);
 | |
| 2577 | TRequestStatus status; | |
| 2578 | r = notify->RequestNotifications(status); | |
| 2579 | cancelNotificationsWatcherTest(r==KErrNone); | |
| 2580 | ||
| 2581 | 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Cancel Notifications\n"),threadId);
 | |
| 2582 | r = notify->CancelNotifications(status); | |
| 2583 | cancelNotificationsWatcherTest(r==KErrNone); | |
| 2584 | ||
| 2585 | 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Signal W1 - Start doer\n"),threadId);
 | |
| 2586 | addRemoveBarrier.Signal(); //W1 - Start doer | |
| 2587 | ||
| 2588 | 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Wait S1 - doer complete\n"),threadId);
 | |
| 2589 | addRemoveBarrier2.Wait(); //S1 - Wait for doer to have created file | |
| 2590 | ||
| 2591 | 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - NextNotification\n"),threadId);
 | |
| 2592 | //We should not be getting any notifications as the notification request has been removed | |
| 2593 | const TFsNotification* notification = notify->NextNotification(); | |
| 2594 | cancelNotificationsWatcherTest(notification == NULL); | |
| 2595 | ||
| 2596 | delete notify; | |
| 2597 | fs.Close(); | |
| 2598 | 	cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Complete\n"),threadId);
 | |
| 2599 | cancelNotificationsWatcherTest.End(); | |
| 2600 | cancelNotificationsWatcherTest.Close(); | |
| 2601 | delete cleanup; | |
| 2602 | return KErrNone; | |
| 2603 | } | |
| 2604 | ||
| 2605 | ||
| 2606 | /* | |
| 2607 | * TestCancelNotificationL - Watcher adds and cancels notification request. | |
| 2608 | */ | |
| 2609 | TInt TestCancelNotificationL() | |
| 2610 | 	{
 | |
| 2611 | 	test.Next(_L("TestCancelNotification"));
 | |
| 2612 | RFs fs; | |
| 2613 | fs.Connect(); | |
| 2614 | ||
| 2615 | SThreadPackageDualSemaphore package; | |
| 2616 | _LIT(KFileName,"cancel.create"); | |
| 2617 | package.iFileName = KFileName; | |
| 2618 | ||
| 2619 | User::LeaveIfError(package.iBarrier.CreateLocal(0)); | |
| 2620 | User::LeaveIfError(package.iBarrier2.CreateLocal(0)); | |
| 2621 | RThread watcher; | |
| 2622 | RThread doer; | |
| 2623 | ||
| 2624 | 	TInt r = watcher.Create(_L("TestCancelNotification-WatcherThread"),TestCancelNotificationWatcher,KDefaultStackSize*2,KMinHeapSize,KMaxHeapSize,&package);
 | |
| 2625 | test(r == KErrNone); | |
| 2626 | 	r = doer.Create(_L("TestCancelNotification-DoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize*2,KMinHeapSize,KMaxHeapSize,&package);
 | |
| 2627 | test(r == KErrNone); | |
| 2628 | 	test.Printf(_L("TestCancelNotificationL - Watcher.Resume()"));
 | |
| 2629 | watcher.Resume(); | |
| 2630 | 	test.Printf(_L("TestCancelNotificationL - Waiting on package.iBarrier.Wait()"));
 | |
| 2631 | package.iBarrier.Wait(); //W1 - Wait until Watcher has created CFsNotify | |
| 2632 | 	test.Printf(_L("TestCancelNotificationL -Doer Resume"));
 | |
| 2633 | TRequestStatus status; | |
| 2634 | doer.Logon(status); | |
| 2635 | doer.Resume(); | |
| 2636 | ||
| 2637 | 	test.Next(_L("TestCancelNotification - Wait for doer thread death"));
 | |
| 2638 | User::WaitForRequest(status); | |
| 2639 | test(doer.ExitReason()==KErrNone); | |
| 2640 | ||
| 2641 | package.iBarrier2.Signal(); //S1 | |
| 2642 | ||
| 2643 | 	test.Next(_L("TestCancelNotification - Wait for watcher thread death"));
 | |
| 2644 | watcher.Logon(status); | |
| 2645 | ||
| 2646 | RTimer tim; | |
| 2647 | r = tim.CreateLocal(); | |
| 2648 | test(r==KErrNone); | |
| 2649 | ||
| 2650 | TRequestStatus timStatus; | |
| 2651 | TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds | |
| 2652 | tim.After(timStatus,time); | |
| 2653 | ||
| 2654 | User::WaitForRequest(status,timStatus); | |
| 2655 | test(status!=KRequestPending); | |
| 2656 | test(watcher.ExitReason()==KErrNone); | |
| 2657 | ||
| 2658 | CLOSE_AND_WAIT(doer); | |
| 2659 | CLOSE_AND_WAIT(watcher); | |
| 2660 | ||
| 2661 | package.iBarrier.Close(); | |
| 2662 | package.iBarrier2.Close(); | |
| 2663 | fs.Close(); | |
| 2664 | tim.Close(); | |
| 2665 | return KErrNone; | |
| 2666 | } | |
| 2667 | ||
| 2668 | /* | |
| 2669 | * Test that if we close the session | |
| 2670 | * before closing the subsession (deleting CFsNotify) | |
| 2671 | * that everything is A-Ok. | |
| 2672 | */ | |
| 2673 | TInt TestSessionCloseTF(TAny* aTestCase) | |
| 2674 | 	{
 | |
| 2675 | CTrapCleanup* cleanup; | |
| 2676 | cleanup = CTrapCleanup::New(); | |
| 2677 | ||
| 2678 | TRAPD(r, | |
| 2679 | RFs fs; | |
| 2680 | fs.Connect(); | |
| 2681 | 	RDebug::Printf("TestSessionClose\n");
 | |
| 2682 | ||
| 2683 | SThreadPackage2 package = *(SThreadPackage2*)aTestCase; | |
| 2684 | package.iBarrier.Signal(); | |
| 2685 | ||
| 2686 | switch(package.iTestCase) | |
| 2687 | 		{
 | |
| 2688 | case 1: | |
| 2689 | 			{
 | |
| 2690 | 			RDebug::Printf("TestSessionCloseTF - Case 1 - NewL\n");
 | |
| 2691 | CFsNotify* notify = CFsNotify::NewL(fs,KMinNotificationBufferSize); | |
| 2692 | User::LeaveIfNull(notify); | |
| 2693 | ||
| 2694 | 			RDebug::Printf("TestSessionCloseTF - Case 1 - Fs.Close\n");
 | |
| 2695 | fs.Close(); | |
| 2696 | ||
| 2697 | TBuf<45> path; | |
| 2698 | path.Append((TChar)gDriveToTest); | |
| 2699 | 			path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 2700 | ||
| 2701 | TBuf<20> filename; | |
| 2702 | 			filename.Append(_L("session.close"));
 | |
| 2703 | ||
| 2704 | CleanupStack::PushL(notify); | |
| 2705 | ||
| 2706 | 			RDebug::Printf("TestSessionCloseTF - Case 1 - Add Notification - Panic Expected\n");
 | |
| 2707 | r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename); | |
| 2708 | User::LeaveIfError(r); | |
| 2709 | ||
| 2710 | 			RDebug::Printf("TestSessionCloseTF - Case 1 - After Session Close\n");
 | |
| 2711 | fs.Close(); | |
| 2712 | CleanupStack::Pop(notify); | |
| 2713 | ||
| 2714 | 			RDebug::Printf("TestSessionCloseTF - Case 1 - After Delete Notify\n");
 | |
| 2715 | delete notify; | |
| 2716 | break; | |
| 2717 | } | |
| 2718 | case 2: | |
| 2719 | 			{
 | |
| 2720 | 			RDebug::Printf("TestSessionCloseTF - Case 2 - NewL\n");
 | |
| 2721 | CFsNotify* notify = CFsNotify::NewL(fs,KMinNotificationBufferSize); | |
| 2722 | User::LeaveIfNull(notify); | |
| 2723 | ||
| 2724 | TBuf<45> path; | |
| 2725 | path.Append((TChar)gDriveToTest); | |
| 2726 | 			path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 2727 | TBuf<20> filename; | |
| 2728 | 			filename.Append(_L("session.close"));
 | |
| 2729 | ||
| 2730 | 			RDebug::Printf("TestSessionCloseTF - Case 2 - Add Notification\n");
 | |
| 2731 | r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename); | |
| 2732 | test(r==KErrNone); | |
| 2733 | ||
| 2734 | 			RDebug::Printf("TestSessionCloseTF - Case 2 - Fs.Close\n");
 | |
| 2735 | fs.Close(); | |
| 2736 | ||
| 2737 | CleanupStack::PushL(notify); | |
| 2738 | TRequestStatus status; | |
| 2739 | 			RDebug::Printf("TestSessionCloseTF - Case 2 - Request Notification - Panic Expected\n");
 | |
| 2740 | r = notify->RequestNotifications(status); | |
| 2741 | CleanupStack::Pop(notify); | |
| 2742 | ||
| 2743 | 			RDebug::Printf("TestSessionCloseTF - Case 2 - After Delete Notify\n");
 | |
| 2744 | delete notify; | |
| 2745 | break; | |
| 2746 | } | |
| 2747 | default: | |
| 2748 | 			{
 | |
| 2749 | break; | |
| 2750 | } | |
| 2751 | } | |
| 2752 | ); | |
| 2753 | delete cleanup; | |
| 2754 | return r; | |
| 2755 | } | |
| 2756 | ||
| 2757 | /* | |
| 2758 | * Test that if we close the session | |
| 2759 | * before closing the subsession (deleting CFsNotify) | |
| 2760 | * that everything is A-Ok. | |
| 2761 | */ | |
| 2762 | void TestSessionClose(TInt aTestCase) | |
| 2763 | 	{
 | |
| 2764 | RSemaphore sem; | |
| 2765 | User::LeaveIfError(sem.CreateLocal(0)); | |
| 2766 | ||
| 2767 | SThreadPackage2 package; | |
| 2768 | package.iTestCase = aTestCase; | |
| 2769 | package.iBarrier = sem; | |
| 2770 | ||
| 2771 | RThread thread; | |
| 2772 | 	thread.Create(_L("TestSessionClose"),TestSessionCloseTF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
 | |
| 2773 | ||
| 2774 | thread.Resume(); | |
| 2775 | sem.Wait(); | |
| 2776 | ||
| 2777 | TRequestStatus status; | |
| 2778 | thread.Logon(status); | |
| 2779 | User::WaitForRequest(status); | |
| 2780 | 	test.Printf(_L("Kern-Exec 0 is EXPECTED\n"));
 | |
| 2781 | TInt err = thread.ExitReason(); | |
| 2782 | test(err == KErrNone); | |
| 2783 | TExitType et = thread.ExitType(); | |
| 2784 | test(et == EExitPanic); | |
| 2785 | CLOSE_AND_WAIT(thread); | |
| 2786 | sem.Close(); | |
| 2787 | } | |
| 2788 | ||
| 2789 | const TInt KNotificationOverflowIterationLimit = 7; | |
| 2790 | ||
| 2791 | /* | |
| 2792 | * Does stuff for TestOverflowL | |
| 2793 | * Synchronises such that watchers have seen 1 change. | |
| 2794 | * Then fills their buffers up to KNotificationOverflowIterationLimit. | |
| 2795 | * | |
| 2796 | */ | |
| 2797 | TInt TestOverflowDoerTF(TAny* aAny) | |
| 2798 | 	{
 | |
| 2799 | RFs fs; | |
| 2800 | fs.Connect(); | |
| 2801 | ||
| 2802 | SThreadPackage& package = *(SThreadPackage*) aAny; | |
| 2803 | ||
| 2804 | TBuf<45> path; | |
| 2805 | path.Append((TChar)gDriveToTest); | |
| 2806 | 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 2807 | path.Append(package.iFileName); | |
| 2808 | ||
| 2809 | fs.MkDirAll(path); | |
| 2810 | ||
| 2811 | RFile file; | |
| 2812 | TInt r = file.Replace(fs,path,EFileWrite); | |
| 2813 | User::LeaveIfError(r); | |
| 2814 | ||
| 2815 | //Perform first set size. | |
| 2816 | r = file.SetSize(1); | |
| 2817 | User::LeaveIfError(r); | |
| 2818 | ||
| 2819 | //Wait until both watchers have received this change. | |
| 2820 | package.iBarrier.Wait(); | |
| 2821 | ||
| 2822 | for(TInt i = 0; i< KNotificationOverflowIterationLimit; i++) | |
| 2823 | 		{
 | |
| 2824 | file.SetSize(i); | |
| 2825 | } | |
| 2826 | ||
| 2827 | file.Close(); | |
| 2828 | fs.Close(); | |
| 2829 | return KErrNone; | |
| 2830 | } | |
| 2831 | ||
| 2832 | /* | |
| 2833 | * Thread function used as part of TestOverflowL | |
| 2834 | * Counts the number of notifications and ensures it the correct number before overflow is received# | |
| 2835 | */ | |
| 2836 | TInt TestOverflowWatcher1TF(TAny* aAny) | |
| 2837 | 	{
 | |
| 2838 | CTrapCleanup* cleanup; | |
| 2839 | cleanup = CTrapCleanup::New(); | |
| 2840 | ||
| 2841 | 	RTest overflowTest(_L("TestOverflowWatcher1TF"));
 | |
| 2842 | 	overflowTest.Start(_L("TestOverflowWatcher1TF"));
 | |
| 2843 | ||
| 2844 | SThreadPackage& package = *(SThreadPackage*) aAny; | |
| 2845 | RFs fs; | |
| 2846 | fs.Connect(); | |
| 2847 | TBuf<45> path; | |
| 2848 | TBuf<20> filename; | |
| 2849 | path.Append((TChar)gDriveToTest); | |
| 2850 | 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 2851 | filename.Append(package.iFileName); | |
| 2852 | ||
| 2853 | TRequestStatus status; | |
| 2854 | CFsNotify* notify = NULL; | |
| 2855 | ||
| 2856 | //This notification's size is 80. | |
| 2857 | //80*7 = 560. | |
| 2858 | // -4 means we should get 6 notifications | |
| 2859 | //Except the first one will still be in the buffer | |
| 2860 | // (as we've not called RequestNotification yet) so we'll only actually get 5. | |
| 2861 | TRAPD(r, notify = CFsNotify::NewL(fs,(80*7)-4)); | |
| 2862 | test(r == KErrNone); | |
| 2863 | User::LeaveIfNull(notify); | |
| 2864 | notify->AddNotification(TFsNotification::EFileChange,path,filename); | |
| 2865 | notify->RequestNotifications(status); | |
| 2866 | ||
| 2867 | //Signal that we are ready for doer to start (W1) | |
| 2868 | package.iBarrier.Signal(); | |
| 2869 | ||
| 2870 | //We wait for the 1 notification (doer only does 1 at first) | |
| 2871 | User::WaitForRequest(status); | |
| 2872 | ||
| 2873 | 	overflowTest.Next(_L("Overflow- Get First Notification (Start framework)"));
 | |
| 2874 | const TFsNotification *notification = notify->NextNotification(); | |
| 2875 | ||
| 2876 | TFsNotification::TFsNotificationType type = notification->NotificationType(); | |
| 2877 | 	overflowTest.Printf(_L("Overflow - First Notification Type = %d\n"),type);
 | |
| 2878 | ||
| 2879 | //Signal the test thread (W2) | |
| 2880 | package.iBarrier.Signal(); | |
| 2881 | //Wait for Signal to continue (W3); | |
| 2882 | package.iBarrier.Wait(); | |
| 2883 | ||
| 2884 | notify->RequestNotifications(status); | |
| 2885 | User::WaitForRequest(status); | |
| 2886 | ||
| 2887 | TInt count = 0; | |
| 2888 | 	overflowTest.Next(_L("Overflow- Get the rest of the notifications"));
 | |
| 2889 | notification = notify->NextNotification(); | |
| 2890 | while(notification != NULL) | |
| 2891 | 		{
 | |
| 2892 | ||
| 2893 | type = notification->NotificationType(); | |
| 2894 | 		overflowTest.Printf(_L("Overflow - NotificationType = %d\n"),type);
 | |
| 2895 | if(type & TFsNotification::EOverflow) | |
| 2896 | 			{
 | |
| 2897 | delete notify; | |
| 2898 | fs.Close(); | |
| 2899 | 			overflowTest.Printf(_L("Overflow +- Count = %d\n"),count);
 | |
| 2900 | overflowTest.End(); | |
| 2901 | overflowTest.Close(); | |
| 2902 | return count; | |
| 2903 | } | |
| 2904 | ||
| 2905 | notification = notify->NextNotification(); | |
| 2906 | count++; | |
| 2907 | } | |
| 2908 | 	overflowTest.Printf(_L("Overflow -- Count = %d\n"),count);
 | |
| 2909 | ||
| 2910 | overflowTest.End(); | |
| 2911 | overflowTest.Close(); | |
| 2912 | delete notify; | |
| 2913 | delete cleanup; | |
| 2914 | fs.Close(); | |
| 2915 | return -1; | |
| 2916 | } | |
| 2917 | ||
| 2918 | ||
| 2919 | /* | |
| 2920 | * Overflow test | |
| 2921 | * As some of the tests above assume sucess if they receive an overflow | |
| 2922 | * we need to ensure that overflow works properly! | |
| 2923 | */ | |
| 2924 | TInt TestOverflowL() | |
| 2925 | 	{
 | |
| 2926 | /* | |
| 2927 | * The scheme used is as follows: | |
| 2928 | * 1 Doer thread which is setting the size of a file, over and over. | |
| 2929 | * 1 watcher thread. | |
| 2930 | * | |
| 2931 | * The doer thread does 1 operation then waits on a signal. | |
| 2932 | * The watcher thread requests notification and receives 1 notification. | |
| 2933 | * It then signals the Doer thread. | |
| 2934 | * | |
| 2935 | * The doer thread continues doing setsize until the number of notifications | |
| 2936 | * should have overflowed. | |
| 2937 | * | |
| 2938 | * The watcher Waits for a signal from doer (that all of the notifications have been sent). | |
| 2939 | * The watcher's last notification should be an overflow | |
| 2940 | */ | |
| 2941 | 	test.Next(_L("TestOverflow"));
 | |
| 2942 | RFs fs; | |
| 2943 | TInt r = fs.Connect(); | |
| 2944 | test(r == KErrNone); | |
| 2945 | _LIT(KFileName,"over.flow"); | |
| 2946 | SThreadPackage doerPkg; | |
| 2947 | doerPkg.iFileName = KFileName; | |
| 2948 | ||
| 2949 | SThreadPackage watcher1Pkg; | |
| 2950 | watcher1Pkg.iFileName = KFileName; | |
| 2951 | ||
| 2952 | User::LeaveIfError(doerPkg.iBarrier.CreateLocal(0)); | |
| 2953 | User::LeaveIfError(watcher1Pkg.iBarrier.CreateLocal(0)); | |
| 2954 | RThread watcher1; | |
| 2955 | RThread doer; | |
| 2956 | 	watcher1.Create(_L("TestOverflowWatcher1Thread"),TestOverflowWatcher1TF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcher1Pkg);
 | |
| 2957 | 	doer.Create(_L("TestOverflowDoerThread"),TestOverflowDoerTF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&doerPkg);
 | |
| 2958 | watcher1.Resume(); | |
| 2959 | ||
| 2960 | //Wait until Request has been requested. (W1) | |
| 2961 | watcher1Pkg.iBarrier.Wait(); | |
| 2962 | ||
| 2963 | doer.Resume(); | |
| 2964 | ||
| 2965 | //Wait till watcher has received first notification (W2) | |
| 2966 | watcher1Pkg.iBarrier.Wait(); | |
| 2967 | ||
| 2968 | //Signal the doer that it is free to continue | |
| 2969 | //doing the rest of the operations | |
| 2970 | doerPkg.iBarrier.Signal(); | |
| 2971 | ||
| 2972 | 	test.Next(_L("TestOverflow - Wait for doer thread death"));
 | |
| 2973 | TRequestStatus status; | |
| 2974 | doer.Logon(status); | |
| 2975 | User::WaitForRequest(status); | |
| 2976 | test(doer.ExitReason()==KErrNone); | |
| 2977 | CLOSE_AND_WAIT(doer); | |
| 2978 | ||
| 2979 | //Wait until doer has finished doing notifications | |
| 2980 | //thus the watcher should receive an overflow | |
| 2981 | // (W3) | |
| 2982 | watcher1Pkg.iBarrier.Signal(); | |
| 2983 | ||
| 2984 | RTimer tim; | |
| 2985 | r = tim.CreateLocal(); | |
| 2986 | test(r==KErrNone); | |
| 2987 | TRequestStatus timStatus; | |
| 2988 | ||
| 2989 | 	test.Next(_L("TestOverflow - Wait for watcher1 thread death"));
 | |
| 2990 | TTimeIntervalMicroSeconds32 interval = 10000000; //10 seconds | |
| 2991 | tim.After(timStatus,interval); | |
| 2992 | watcher1.Logon(status); | |
| 2993 | User::WaitForRequest(status,timStatus); | |
| 2994 | test(status != KRequestPending); | |
| 2995 | /* | |
| 2996 | * The number of notifications returned here should be 5. | |
| 2997 | * This is because : | |
| 2998 | * | |
| 2999 | * The first notification means that the buffer has lost 80 (the size of this | |
| 3000 | * particular notification). Even though the client has read it becase they've not called | |
| 3001 | * RequestNotification the server doesn't know that yet so that's why it's 5 not 6. | |
| 3002 | * | |
| 3003 | * That leaves 556 - 80. Which means only 5 notifications will fit. | |
| 3004 | */ | |
| 3005 | TInt count = watcher1.ExitReason(); | |
| 3006 | test(count==5); | |
| 3007 | ||
| 3008 | CLOSE_AND_WAIT(watcher1); | |
| 3009 | watcher1Pkg.iBarrier.Close(); | |
| 3010 | doerPkg.iBarrier.Close(); | |
| 3011 | fs.Close(); | |
| 3012 | tim.Close(); | |
| 3013 | return KErrNone; | |
| 3014 | } | |
| 3015 | ||
| 3016 | /* | |
| 3017 | * Does stuff for TestPostOverflowL | |
| 3018 | * Synchronises such that watchers have seen 1 change. | |
| 3019 | * Then fills their buffers up to KNotificationOverflowIterationLimit. | |
| 3020 | * Then continues to request changes and akes sure that it gets 3 non-overflow notifications | |
| 3021 | * For DEF140387. | |
| 3022 | */ | |
| 3023 | TInt TestPostOverflowDoerTF(TAny* aAny) | |
| 3024 |     {
 | |
| 3025 | RFs fs; | |
| 3026 | fs.Connect(); | |
| 3027 | ||
| 3028 | SThreadPackage& package = *(SThreadPackage*) aAny; | |
| 3029 | ||
| 3030 | TBuf<45> path; | |
| 3031 | path.Append((TChar)gDriveToTest); | |
| 3032 |     path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 3033 | path.Append(package.iFileName); | |
| 3034 | ||
| 3035 | fs.MkDirAll(path); | |
| 3036 | ||
| 3037 | RFile file; | |
| 3038 | TInt r = file.Replace(fs,path,EFileWrite); | |
| 3039 | User::LeaveIfError(r); | |
| 3040 | ||
| 3041 | //Perform first set size. | |
| 3042 | r = file.SetSize(1); | |
| 3043 | User::LeaveIfError(r); | |
| 3044 | ||
| 3045 | //Wait until both watchers have received this change. | |
| 3046 | //D-W-1 | |
| 3047 | package.iBarrier.Wait(); | |
| 3048 | ||
| 3049 | for(TInt i = 0; i< KNotificationOverflowIterationLimit; i++) | |
| 3050 |         {
 | |
| 3051 | file.SetSize(i); | |
| 3052 | } | |
| 3053 | ||
| 3054 | file.Close(); | |
| 3055 | fs.Close(); | |
| 3056 | return KErrNone; | |
| 3057 | } | |
| 3058 | ||
| 3059 | TInt HandlePostOverflow(SThreadPackage& aPackage, CFsNotify* aNotify) | |
| 3060 |     {
 | |
| 3061 | TRequestStatus status; | |
| 3062 | TInt r = aNotify->RequestNotifications(status); | |
| 3063 | test(r == KErrNone); | |
| 3064 | //Signal that overflow has been found (W4) | |
| 3065 | aPackage.iBarrier.Signal(); | |
| 3066 | ||
| 3067 | User::WaitForRequest(status); | |
| 3068 | ||
| 3069 | const TFsNotification* notification = NULL; | |
| 3070 | TInt count = 1; | |
| 3071 | ||
| 3072 | notification = aNotify->NextNotification(); | |
| 3073 | test(notification != NULL); | |
| 3074 | ||
| 3075 | //3 set sizes will be done (Sx) | |
| 3076 | aPackage.iBarrier.Wait(); | |
| 3077 | ||
| 3078 | while(count < 3) | |
| 3079 |         {
 | |
| 3080 | TUint type = notification->NotificationType(); | |
| 3081 | if(type & TFsNotification::EOverflow) | |
| 3082 |             {
 | |
| 3083 | return KErrOverflow; | |
| 3084 | } | |
| 3085 | notification = aNotify->NextNotification(); | |
| 3086 | if(notification == NULL) | |
| 3087 |             {
 | |
| 3088 | r = aNotify->RequestNotifications(status); | |
| 3089 | test(r == KErrNone); | |
| 3090 | User::WaitForRequest(status); | |
| 3091 | notification = aNotify->NextNotification(); | |
| 3092 | } | |
| 3093 | test(notification != NULL); | |
| 3094 | count++; | |
| 3095 | } | |
| 3096 | return count; | |
| 3097 | } | |
| 3098 | ||
| 3099 | ||
| 3100 | /* | |
| 3101 | * Thread function used as part of TestOverflowL | |
| 3102 | * Counts the number of notifications and ensures it the correct number before overflow is received# | |
| 3103 | */ | |
| 3104 | TInt TestPostOverflowWatcher1TF(TAny* aAny) | |
| 3105 |     {
 | |
| 3106 | CTrapCleanup* cleanup; | |
| 3107 | cleanup = CTrapCleanup::New(); | |
| 3108 | ||
| 3109 |     RTest overflowTest(_L("TestOverflowWatcher1TF"));
 | |
| 3110 |     overflowTest.Start(_L("TestOverflowWatcher1TF"));
 | |
| 3111 | ||
| 3112 | SThreadPackage& package = *(SThreadPackage*) aAny; | |
| 3113 | RFs fs; | |
| 3114 | fs.Connect(); | |
| 3115 | TBuf<45> path; | |
| 3116 | TBuf<20> filename; | |
| 3117 | path.Append((TChar)gDriveToTest); | |
| 3118 |     path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 3119 | filename.Append(package.iFileName); | |
| 3120 | ||
| 3121 | TRequestStatus status; | |
| 3122 | CFsNotify* notify = NULL; | |
| 3123 | ||
| 3124 | //This notification's size is 80. | |
| 3125 | //80*7 = 560. | |
| 3126 | // -4 means we should get 6 notifications | |
| 3127 | //Except the first one will still be in the buffer | |
| 3128 | // (as we've not called RequestNotification yet) so we'll only actually get 5. | |
| 3129 | TRAPD(r, notify = CFsNotify::NewL(fs,(80*7)-4)); | |
| 3130 | test(r == KErrNone); | |
| 3131 | User::LeaveIfNull(notify); | |
| 3132 | notify->AddNotification(TFsNotification::EFileChange,path,filename); | |
| 3133 | notify->RequestNotifications(status); | |
| 3134 | ||
| 3135 | //Signal that we are ready for doer to start (W1) | |
| 3136 | package.iBarrier.Signal(); | |
| 3137 | ||
| 3138 | //We wait for the 1 notification (doer only does 1 at first) | |
| 3139 | User::WaitForRequest(status); | |
| 3140 | ||
| 3141 |     overflowTest.Next(_L("Overflow- Get First Notification (Start framework)"));
 | |
| 3142 | const TFsNotification *notification = notify->NextNotification(); | |
| 3143 | ||
| 3144 | TFsNotification::TFsNotificationType type = notification->NotificationType(); | |
| 3145 |     overflowTest.Printf(_L("Overflow - First Notification Type = %d\n"),type);
 | |
| 3146 | ||
| 3147 | //Signal the test thread (W2) | |
| 3148 | package.iBarrier.Signal(); | |
| 3149 | //Wait for Signal to continue (W3); | |
| 3150 | package.iBarrier.Wait(); | |
| 3151 | ||
| 3152 | notify->RequestNotifications(status); | |
| 3153 | User::WaitForRequest(status); | |
| 3154 | ||
| 3155 | TInt handlePostOverflow = 0; | |
| 3156 | TInt count = 0; | |
| 3157 |     overflowTest.Next(_L("Overflow- Get the rest of the notifications"));
 | |
| 3158 | notification = notify->NextNotification(); | |
| 3159 | while(notification != NULL) | |
| 3160 |         {
 | |
| 3161 | ||
| 3162 | type = notification->NotificationType(); | |
| 3163 |         overflowTest.Printf(_L("Overflow - NotificationType = %d\n"),type);
 | |
| 3164 | if(type & TFsNotification::EOverflow) | |
| 3165 |             {
 | |
| 3166 |             overflowTest.Printf(_L("Overflow +- Count = %d\n"),count);
 | |
| 3167 | if(handlePostOverflow) | |
| 3168 |                 {
 | |
| 3169 | count = HandlePostOverflow(package,notify); | |
| 3170 | } | |
| 3171 | delete notify; | |
| 3172 | fs.Close(); | |
| 3173 | overflowTest.End(); | |
| 3174 | overflowTest.Close(); | |
| 3175 | return count; | |
| 3176 | } | |
| 3177 | notification = notify->NextNotification(); | |
| 3178 | count++; | |
| 3179 | ||
| 3180 | if(count==5) | |
| 3181 | handlePostOverflow = 1; | |
| 3182 | } | |
| 3183 |     overflowTest.Printf(_L("Overflow -- Count = %d\n"),count);
 | |
| 3184 | ||
| 3185 | overflowTest.End(); | |
| 3186 | overflowTest.Close(); | |
| 3187 | delete notify; | |
| 3188 | delete cleanup; | |
| 3189 | fs.Close(); | |
| 3190 | return -1; | |
| 3191 | } | |
| 3192 | ||
| 3193 | ||
| 3194 | TInt TestPostOverflowNotifications() | |
| 3195 |     {
 | |
| 3196 |     test.Next(_L("TestPostOverflowNotifications"));
 | |
| 3197 | RFs fs; | |
| 3198 | TInt r = fs.Connect(); | |
| 3199 | test(r == KErrNone); | |
| 3200 | _LIT(KFileName,"post.over"); | |
| 3201 | SThreadPackage doerPkg; | |
| 3202 | doerPkg.iFileName = KFileName; | |
| 3203 | ||
| 3204 | SThreadPackage watcher1Pkg; | |
| 3205 | watcher1Pkg.iFileName = KFileName; | |
| 3206 | ||
| 3207 | User::LeaveIfError(doerPkg.iBarrier.CreateLocal(0)); | |
| 3208 | User::LeaveIfError(watcher1Pkg.iBarrier.CreateLocal(0)); | |
| 3209 | RThread watcher1; | |
| 3210 | RThread doer; | |
| 3211 |     watcher1.Create(_L("TestPostOverflowWatcher1Thread"),TestPostOverflowWatcher1TF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcher1Pkg);
 | |
| 3212 |     doer.Create(_L("TestPostOverflowDoerThread"),TestPostOverflowDoerTF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&doerPkg);
 | |
| 3213 | watcher1.Resume(); | |
| 3214 | ||
| 3215 | //Wait until Request has been requested. (W1) | |
| 3216 | watcher1Pkg.iBarrier.Wait(); | |
| 3217 | ||
| 3218 | doer.Resume(); | |
| 3219 | ||
| 3220 | //Wait till watcher has received first notification (W2) | |
| 3221 | watcher1Pkg.iBarrier.Wait(); | |
| 3222 | ||
| 3223 | //Signal the doer that it is free to continue | |
| 3224 | //doing the rest of the operations (D-W-1) | |
| 3225 | doerPkg.iBarrier.Signal(); | |
| 3226 | ||
| 3227 |     test.Next(_L("TestOverflow - Wait for doer thread death"));
 | |
| 3228 | TRequestStatus status; | |
| 3229 | doer.Logon(status); | |
| 3230 | User::WaitForRequest(status); | |
| 3231 | test(doer.ExitReason()==KErrNone); | |
| 3232 | CLOSE_AND_WAIT(doer); | |
| 3233 | ||
| 3234 | //Wait until doer has finished doing notifications | |
| 3235 | //thus the watcher should receive an overflow | |
| 3236 | // (W3) | |
| 3237 | watcher1Pkg.iBarrier.Signal(); | |
| 3238 | ||
| 3239 | ||
| 3240 | //wait for the watcher to have processed the first overflow | |
| 3241 | //and to have requested notification. | |
| 3242 | //Then we will perform some actions here | |
| 3243 | // The watcher will wait on the semaphore until we are doing | |
| 3244 | // doing all the operations we want to do | |
| 3245 | // then it should process next notification | |
| 3246 | watcher1Pkg.iBarrier.Wait(); //W4 | |
| 3247 | ||
| 3248 | TBuf<45> path; | |
| 3249 | path.Append((TChar)gDriveToTest); | |
| 3250 |     path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 3251 | path.Append(watcher1Pkg.iFileName); | |
| 3252 | RFile file; | |
| 3253 | r = file.Open(fs,path,EFileWrite); | |
| 3254 | test(r==KErrNone); | |
| 3255 | ||
| 3256 | r = file.SetSize(1); | |
| 3257 | test(r==KErrNone); | |
| 3258 | r = file.SetSize(2); | |
| 3259 | test(r==KErrNone); | |
| 3260 | r = file.SetSize(3); | |
| 3261 | test(r==KErrNone); | |
| 3262 | file.Close(); | |
| 3263 | ||
| 3264 | watcher1Pkg.iBarrier.Signal(); // Signal post operations complete (Sx) | |
| 3265 | ||
| 3266 | RTimer tim; | |
| 3267 | r = tim.CreateLocal(); | |
| 3268 | test(r==KErrNone); | |
| 3269 | TRequestStatus timStatus; | |
| 3270 | ||
| 3271 |     test.Next(_L("TestOverflow - Wait for watcher1 thread death"));
 | |
| 3272 | TTimeIntervalMicroSeconds32 interval = 10000000; //10 seconds | |
| 3273 | tim.After(timStatus,interval); | |
| 3274 | watcher1.Logon(status); | |
| 3275 | User::WaitForRequest(status,timStatus); | |
| 3276 | test(status != KRequestPending); | |
| 3277 | /* | |
| 3278 | * The number of notifications returned here should be 3. | |
| 3279 | * This is because : | |
| 3280 | * | |
| 3281 | * The first notification means that the buffer has lost 80 (the size of this | |
| 3282 | * particular notification). Even though the client has read it becase they've not called | |
| 3283 | * RequestNotification the server doesn't know that yet so that's why it's 5 not 6. | |
| 3284 | * | |
| 3285 | * That leaves 556 - 80. Which means only 5 notifications will fit. | |
| 3286 | * | |
| 3287 | * Then overflow occurs. | |
| 3288 | * | |
| 3289 | * Then count is reset and 3 more operations are performed. | |
| 3290 | */ | |
| 3291 | TInt count = watcher1.ExitReason(); | |
| 3292 | test(count==3); | |
| 3293 | ||
| 3294 | CLOSE_AND_WAIT(watcher1); | |
| 3295 | watcher1Pkg.iBarrier.Close(); | |
| 3296 | doerPkg.iBarrier.Close(); | |
| 3297 | fs.Close(); | |
| 3298 | tim.Close(); | |
| 3299 | return KErrNone; | |
| 3300 | } | |
| 3301 | ||
| 3302 | /* | |
| 3303 | * Call AddNotification with a file without a path nor drive | |
| 3304 | */ | |
| 3305 | void TestNonDriveFilters() | |
| 3306 | 	{
 | |
| 3307 | 	test.Next(_L("TestNonDriveFilters"));
 | |
| 3308 | RFs fs; | |
| 3309 | TInt r = fs.Connect(); | |
| 3310 | test(r==KErrNone); | |
| 3311 | ||
| 3312 | TDriveList drives; | |
| 3313 | r = fs.DriveList(drives); | |
| 3314 | test(r==KErrNone); | |
| 3315 | ||
| 3316 | CFsNotify* notify = NULL; | |
| 3317 | TRAP(r,notify= CFsNotify::NewL(fs,KMinNotificationBufferSize)); | |
| 3318 | ||
| 3319 | TBuf<20> testfile; | |
| 3320 | 	testfile.Append(_L("test.file"));
 | |
| 3321 | ||
| 3322 | 	r = notify->AddNotification((TUint)TFsNotification::ECreate,_L(""),testfile);
 | |
| 3323 | test(r==KErrNone); | |
| 3324 | ||
| 3325 | TRequestStatus status; | |
| 3326 | r = notify->RequestNotifications(status); | |
| 3327 | test(r==KErrNone); | |
| 3328 | ||
| 3329 | TBuf<40> path; | |
| 3330 | path.Append((TChar)gDriveToTest); | |
| 3331 | 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 3332 | ||
| 3333 | TBuf<40> fullname; | |
| 3334 | fullname.Append(path); | |
| 3335 | fullname.Append(testfile); | |
| 3336 | ||
| 3337 | RFile file; | |
| 3338 | r = fs.MkDirAll(path); | |
| 3339 | test(r==KErrNone || r==KErrAlreadyExists); | |
| 3340 | r = file.Replace(fs,fullname,EFileWrite); | |
| 3341 | test(r==KErrNone); | |
| 3342 | file.Close(); | |
| 3343 | ||
| 3344 | fs.Delete(fullname); | |
| 3345 | ||
| 3346 | TChar testDrive = (TChar)gDriveToTest; | |
| 3347 | testDrive.UpperCase(); | |
| 3348 | ||
| 3349 | //Also create the file on another drive; | |
| 3350 | for(TInt i = 0; i < KMaxDrives; i++) | |
| 3351 | 		{
 | |
| 3352 | TChar drive = drives[i]; | |
| 3353 | if(drive == testDrive) | |
| 3354 | continue; | |
| 3355 | ||
| 3356 | if(drive) | |
| 3357 | 			{
 | |
| 3358 | TText16 drive16 = (TText16)(i+(TChar)'A'); | |
| 3359 | fullname.operator [](0) = drive16; | |
| 3360 | break; | |
| 3361 | } | |
| 3362 | } | |
| 3363 | ||
| 3364 | r = fs.MkDirAll(fullname); | |
| 3365 | test(r==KErrNone || r==KErrAlreadyExists); | |
| 3366 | r = file.Replace(fs,fullname,EFileWrite); | |
| 3367 | test(r==KErrNone); | |
| 3368 | file.Close(); | |
| 3369 | ||
| 3370 | RTimer timer1; | |
| 3371 | r = timer1.CreateLocal(); | |
| 3372 | test(r == KErrNone); | |
| 3373 | TRequestStatus timeout; | |
| 3374 | TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds | |
| 3375 | timer1.After(timeout,time); | |
| 3376 | User::WaitForRequest(timeout,status); | |
| 3377 | test(status.Int() != KRequestPending); | |
| 3378 | timer1.Cancel(); | |
| 3379 | timer1.Close(); | |
| 3380 | ||
| 3381 | const TFsNotification* notification = notify->NextNotification(); | |
| 3382 | test(notification != NULL); | |
| 3383 | TPtrC _path; | |
| 3384 | r = notification->Path(_path); | |
| 3385 | test(r==KErrNone); | |
| 3386 | TChar driveletter = _path[0]; | |
| 3387 | driveletter.UpperCase(); | |
| 3388 | test(driveletter == (TChar)gDriveToTest); | |
| 3389 | ||
| 3390 | if(notification = notify->NextNotification(), notification==NULL) | |
| 3391 | 		{
 | |
| 3392 | TRequestStatus status2; | |
| 3393 | r = notify->RequestNotifications(status2); | |
| 3394 | test(r==KErrNone); | |
| 3395 | ||
| 3396 | RTimer timer2; | |
| 3397 | r = timer2.CreateLocal(); | |
| 3398 | test(r == KErrNone); | |
| 3399 | TRequestStatus timeout2; | |
| 3400 | TTimeIntervalMicroSeconds32 time2 = 10000000; //10 seconds | |
| 3401 | timer2.After(timeout2,time2); | |
| 3402 | User::WaitForRequest(timeout2,status2); | |
| 3403 | test(status2.Int() != KRequestPending); | |
| 3404 | timer2.Cancel(); | |
| 3405 | timer2.Close(); | |
| 3406 | ||
| 3407 | notification = notify->NextNotification(); | |
| 3408 | } | |
| 3409 | test(notification != NULL); | |
| 3410 | r = notification->Path(_path); | |
| 3411 | test(r==KErrNone); | |
| 3412 | driveletter = _path[0]; | |
| 3413 | driveletter.UpperCase(); | |
| 3414 | test(driveletter == (TChar)'C'); | |
| 3415 | ||
| 3416 | delete notify; | |
| 3417 | fs.Close(); | |
| 3418 | } | |
| 3419 | ||
| 3420 | // Negative testing for directory without * | |
| 3421 | // We receive no notifications for files changed under the directory | |
| 3422 | void NegativeTestDirStar() | |
| 3423 | 	{
 | |
| 3424 | RFs fs; | |
| 3425 | TInt r = fs.Connect(); | |
| 3426 | test(r==KErrNone); | |
| 3427 | ||
| 3428 | CFsNotify* notify = NULL; | |
| 3429 | TRAP(r,notify= CFsNotify::NewL(fs,KMinNotificationBufferSize)); | |
| 3430 | ||
| 3431 | TBuf<40> path; | |
| 3432 | path.Append((TChar)gDriveToTest); | |
| 3433 | 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 3434 | r = fs.MkDirAll(path); | |
| 3435 | test(r == KErrNone || r == KErrAlreadyExists); | |
| 3436 | ||
| 3437 | 	r = notify->AddNotification((TUint)TFsNotification::ECreate,path,_L(""));
 | |
| 3438 | test(r==KErrNone); | |
| 3439 | ||
| 3440 | TRequestStatus status; | |
| 3441 | r = notify->RequestNotifications(status); | |
| 3442 | test(r==KErrNone); | |
| 3443 | ||
| 3444 | TBuf<40> filename; | |
| 3445 | filename.Append((TChar)gDriveToTest); | |
| 3446 | 	filename.Append(_L(":\\F32-TST\\T_NOTIFIER\\dir.star"));
 | |
| 3447 | ||
| 3448 | RFile file; | |
| 3449 | r = file.Replace(fs,filename,EFileWrite); | |
| 3450 | test(r==KErrNone); | |
| 3451 | file.Close(); | |
| 3452 | ||
| 3453 | RTimer timer1; | |
| 3454 | r = timer1.CreateLocal(); | |
| 3455 | test(r == KErrNone); | |
| 3456 | TRequestStatus timeout; | |
| 3457 | TTimeIntervalMicroSeconds32 time = 2000000; //2 seconds | |
| 3458 | timer1.After(timeout,time); | |
| 3459 | User::WaitForRequest(timeout,status); | |
| 3460 | test(status.Int() == KRequestPending); | |
| 3461 | timer1.Cancel(); | |
| 3462 | timer1.Close(); | |
| 3463 | ||
| 3464 | const TFsNotification* notification = notify->NextNotification(); | |
| 3465 | test(notification == NULL); | |
| 3466 | ||
| 3467 | delete notify; | |
| 3468 | fs.Close(); | |
| 3469 | } | |
| 3470 | ||
| 3471 | /* | |
| 3472 | * Negative Testing | |
| 3473 | */ | |
| 3474 | void NegativeTests() | |
| 3475 | 	{
 | |
| 3476 | 	test.Next(_L("Negative Tests"));
 | |
| 3477 | //1 | |
| 3478 | 	test.Printf(_L("NegativeTests() A\n"));
 | |
| 3479 | RFs fs; | |
| 3480 | CFsNotify* notify = NULL; | |
| 3481 | TInt r = fs.Connect(); | |
| 3482 | test(r == KErrNone); | |
| 3483 | TRAP(r,notify = CFsNotify::NewL(fs,0)); | |
| 3484 | test(notify != NULL); | |
| 3485 | delete notify; | |
| 3486 | notify = NULL; | |
| 3487 | ||
| 3488 | //2 | |
| 3489 | 	test.Printf(_L("NegativeTests() B\n"));
 | |
| 3490 | TRAP(r,notify = CFsNotify::NewL(fs,-1)); | |
| 3491 | test(notify != NULL); | |
| 3492 | delete notify; | |
| 3493 | notify = NULL; | |
| 3494 | ||
| 3495 | 	test.Printf(_L("NegativeTests() C\n"));
 | |
| 3496 | TRAP(r,notify = CFsNotify::NewL(fs,KMaxTInt)); | |
| 3497 | test(r==KErrArgument); | |
| 3498 | test(notify==NULL); | |
| 3499 | ||
| 3500 | //3 | |
| 3501 | 	test.Printf(_L("NegativeTests() D\n"));
 | |
| 3502 | TBuf<40> path; | |
| 3503 | path.Append((TChar)gDriveToTest); | |
| 3504 | 	path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
 | |
| 3505 | TBuf<20> filename; | |
| 3506 | 	filename.Append(_L("file.txt"));
 | |
| 3507 | TRAP(r,notify = CFsNotify::NewL(fs,KMinNotificationBufferSize)); | |
| 3508 | test(r==KErrNone); | |
| 3509 | test(notify!=NULL); | |
| 3510 | r = notify->AddNotification(0,path,filename); | |
| 3511 | test(r == KErrArgument); | |
| 3512 | ||
| 3513 | 	test.Printf(_L("NegativeTests() E\n"));
 | |
| 3514 | r = notify->AddNotification((TUint)0x8000,path,filename); //invalid value | |
| 3515 | test(r == KErrArgument); | |
| 3516 | ||
| 3517 | 	test.Printf(_L("NegativeTests() F\n"));
 | |
| 3518 | TBuf<40> invalidPath; | |
| 3519 | 	invalidPath.Append(_L("1:\\*"));
 | |
| 3520 | r = notify->AddNotification((TUint)TFsNotification::ECreate,invalidPath,filename); | |
| 3521 | test(r == KErrNotFound || r == KErrPathNotFound); | |
| 3522 | ||
| 3523 | //4 | |
| 3524 | 	test.Printf(_L("NegativeTests() G\n"));
 | |
| 3525 | TRequestStatus wrongStatus; | |
| 3526 | wrongStatus = KRequestPending; | |
| 3527 | r = notify->RequestNotifications(wrongStatus); | |
| 3528 | test(r == KErrInUse); | |
| 3529 | ||
| 3530 | 	test.Printf(_L("NegativeTests() H\n"));
 | |
| 3531 | TRequestStatus status; | |
| 3532 | r = notify->RequestNotifications(status); | |
| 3533 | test(r==KErrNone); | |
| 3534 | r = notify->CancelNotifications(wrongStatus); | |
| 3535 | test(r == KErrInUse); | |
| 3536 | ||
| 3537 | delete notify; | |
| 3538 | notify = NULL; | |
| 3539 | fs.Close(); | |
| 3540 | } | |
| 3541 | ||
| 3542 | ||
| 3543 | /* | |
| 3544 | * RPlugin devired. | |
| 3545 | * Doesn't actually do anything special. | |
| 3546 | * Can probably be deleted. | |
| 3547 | */ | |
| 3548 | class MyRPlugin : public RPlugin | |
| 3549 | 	{
 | |
| 3550 | public: | |
| 3551 | void DoRequest(TInt aReqNo,TRequestStatus& aStatus) const; | |
| 3552 | void DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1) const; | |
| 3553 | void DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1,TDes8& a2) const; | |
| 3554 | TInt DoControl(TInt aFunction) const; | |
| 3555 | TInt DoControl(TInt aFunction,TDes8& a1) const; | |
| 3556 | TInt DoControl(TInt aFunction,TDes8& a1,TDes8& a2) const; | |
| 3557 | void DoCancel(TUint aReqMask) const; | |
| 3558 | }; | |
| 3559 | ||
| 3560 | void MyRPlugin::DoRequest(TInt aReqNo,TRequestStatus& aStatus) const | |
| 3561 | 	{
 | |
| 3562 | RPlugin::DoRequest(aReqNo,aStatus); | |
| 3563 | } | |
| 3564 | void MyRPlugin::DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1) const | |
| 3565 | 	{
 | |
| 3566 | RPlugin::DoRequest(aReqNo,aStatus,a1); | |
| 3567 | } | |
| 3568 | void MyRPlugin::DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1,TDes8& a2) const | |
| 3569 | 	{
 | |
| 3570 | RPlugin::DoRequest(aReqNo,aStatus,a1,a2); | |
| 3571 | } | |
| 3572 | TInt MyRPlugin::DoControl(TInt aFunction) const | |
| 3573 | 	{
 | |
| 3574 | return RPlugin::DoControl(aFunction); | |
| 3575 | } | |
| 3576 | TInt MyRPlugin::DoControl(TInt aFunction,TDes8& a1) const | |
| 3577 | 	{
 | |
| 3578 | return RPlugin::DoControl(aFunction,a1); | |
| 3579 | } | |
| 3580 | TInt MyRPlugin::DoControl(TInt aFunction,TDes8& a1,TDes8& a2) const | |
| 3581 | 	{
 | |
| 3582 | return RPlugin::DoControl(aFunction,a1,a2); | |
| 3583 | } | |
| 3584 | void MyRPlugin::DoCancel(TUint aReqMask) const | |
| 3585 | 	{
 | |
| 3586 | RPlugin::DoCancel(aReqMask); | |
| 3587 | } | |
| 3588 | ||
| 3589 | /* | |
| 3590 | * This tests that when file server plugins perform operations that | |
| 3591 | * the framework doesn't notify about them | |
| 3592 | */ | |
| 3593 | TInt TestNotificationsWithFServPlugins() | |
| 3594 | 	{
 | |
| 3595 | TInt r = TheFs.AddPlugin(KNotifyPluginFileName); | |
| 3596 | test(r==KErrNone || r==KErrAlreadyExists); | |
| 3597 | r = TheFs.MountPlugin(KNotifyPluginName,(TUint)gDriveToTest.GetUpperCase() - 65); | |
| 3598 | if (r == KErrNotSupported) | |
| 3599 | 		{
 | |
| 3600 | 		test.Printf(_L("Plugins are not supported on pagable drives.\nSkipping test.\n"));
 | |
| 3601 | 		safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 3602 | } | |
| 3603 | ||
| 3604 | MyRPlugin rplugin; | |
| 3605 | TPckgBuf<TChar> drivePckg(gDriveToTest); | |
| 3606 | ||
| 3607 | 	test.Next(_L("Open RPlugin connection for NotifyPlugin"));
 | |
| 3608 | r = rplugin.Open(TheFs,KNotifyPos); | |
| 3609 | 	safe_test(test,r,__LINE__,(TText*)Expand("t_notify_plugin.cpp"));
 | |
| 3610 | ||
| 3611 | 	test.Next(_L("Send drive letter to test down to plugin"));
 | |
| 3612 | r = rplugin.DoControl(KPluginSetDrive,drivePckg); | |
| 3613 | 	safe_test(test,r,__LINE__,(TText*)Expand("t_notify_plugin.cpp"));
 | |
| 3614 | rplugin.Close(); | |
| 3615 | ||
| 3616 | r = SimpleCreateTestL(); | |
| 3617 | 	safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
 | |
| 3618 | ||
| 3619 | DismountPlugin(); | |
| 3620 | return KErrNone; | |
| 3621 | } | |
| 3622 | ||
| 3623 | /* | |
| 3624 | * This test is testing the use cases | |
| 3625 | * and for negative testing of SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION | |
| 3626 | * | |
| 3627 | * Performance tests can be found in test t_notify_perf | |
| 3628 | */ | |
| 3629 | void CallTestsL() | |
| 3630 | 	{
 | |
| 3631 | CTrapCleanup* cleanup; | |
| 3632 | cleanup = CTrapCleanup::New(); | |
| 3633 | ||
| 3634 | globalDriveNum = gDriveToTest - (TChar)'A'; | |
| 3635 | ||
| 3636 | PrintLine(); | |
| 3637 | 	test.Start(_L("T_NOTIFIER Test Start"));
 | |
| 3638 | TInt r = KErrNone; | |
| 3639 | ||
| 3640 | //========================================================================================= | |
| 3641 | //! @SYMTestCaseID PBASE-T_NOTIFY-2443 | |
| 3642 | //! @SYMTestType CIT | |
| 3643 | //! @SYMREQ PREQ1847 | |
| 3644 | //! @SYMTestCaseDesc Simple Tests/User Heap Tests | |
| 3645 | //! @SYMTestStatus Implemented | |
| 3646 | //========================================================================================= | |
| 3647 | // | |
| 3648 | // 1. Create and delete many CFsNotify objects | |
| 3649 | // | |
| 3650 | PrintLine(); | |
| 3651 | 	test.Next(_L("CFsNotify Creation and Delete Tests"));
 | |
| 3652 | //Creates and Deletes 1 CFsNotify | |
| 3653 | __UHEAP_MARK; | |
| 3654 | r = TestNewDeleteCFsNotify(1); | |
| 3655 | __UHEAP_MARKEND; | |
| 3656 | test(r==KErrNone); | |
| 3657 | //Creates and Deletes 50 CFsNotifys | |
| 3658 | __UHEAP_MARK; | |
| 3659 | r = TestNewDeleteCFsNotify(50); | |
| 3660 | __UHEAP_MARKEND; | |
| 3661 | test(r==KErrNone); | |
| 3662 | 	test.Printf(_L("------- End of User Heap Tests ---------------------------------------\n"));
 | |
| 3663 | // | |
| 3664 | // 2. Add notification for creating a file | |
| 3665 | // Create that file | |
| 3666 | // | |
| 3667 | PrintLine(); | |
| 3668 | __UHEAP_MARK; | |
| 3669 | r = SimpleCreateTestL(); | |
| 3670 | __UHEAP_MARKEND; | |
| 3671 | test(r==KErrNone); | |
| 3672 | 	test.Printf(_L("------- End of CFsNotify Creation and Delete Tests -------------------\n"));
 | |
| 3673 | // | |
| 3674 | // 3. Add notification at the root of a drive | |
| 3675 | // Create a file in that drive | |
| 3676 | // | |
| 3677 | PrintLine(); | |
| 3678 | TestRootDriveNotifications(); | |
| 3679 | 	test.Printf(_L("------- End of RootDriveNotifications Test ---------------------------\n"));
 | |
| 3680 | // | |
| 3681 | // 4. Add notification for a filename without a drive | |
| 3682 | // Create that file in the current drive | |
| 3683 | // Create that file in another drive | |
| 3684 | // | |
| 3685 | PrintLine(); | |
| 3686 | TestNonDriveFilters(); | |
| 3687 | 	test.Printf(_L("------- End of TestNonDriveFilters Test ------------------------------\n"));
 | |
| 3688 | // | |
| 3689 | // 5. Add notifications for 2 file creations | |
| 3690 | // Create 2 clients | |
| 3691 | // The clients create a file each | |
| 3692 | // | |
| 3693 | PrintLine(); | |
| 3694 | __UHEAP_MARK; | |
| 3695 | r = TestTwoDoersL(); | |
| 3696 | __UHEAP_MARKEND; | |
| 3697 | test(r==KErrNone); | |
| 3698 | 	test.Printf(_L("------- End of TwoDoers Test -----------------------------------------\n"));
 | |
| 3699 | // | |
| 3700 | // 6. Create 2 file server sessions | |
| 3701 | // Add a notification on each session for the same specific file creation | |
| 3702 | // Create that file | |
| 3703 | // | |
| 3704 | PrintLine(); | |
| 3705 | __UHEAP_MARK; | |
| 3706 | r = TestTwoWatchersL(); | |
| 3707 | __UHEAP_MARKEND; | |
| 3708 | test(r==KErrNone); | |
| 3709 | 	test.Printf(_L("------- End of TwoWatchers Test --------------------------------------\n"));
 | |
| 3710 | // | |
| 3711 | // 7. Create 2 file server sessions and 2 clients | |
| 3712 | // Add a notification on each session for different file creations | |
| 3713 | // Clients create a file each | |
| 3714 | // | |
| 3715 | PrintLine(); | |
| 3716 | __UHEAP_MARK; | |
| 3717 | r = TestTwoWatchersTwoDoersL(); | |
| 3718 | __UHEAP_MARKEND; | |
| 3719 | test(r==KErrNone); | |
| 3720 | 	test.Printf(_L("------- End of TwoWatchersTwoDoers Test ------------------------------\n"));
 | |
| 3721 | // | |
| 3722 | // 8. Add notification for a specific file creation | |
| 3723 | // Cancel the notification request | |
| 3724 | // Create that file | |
| 3725 | // | |
| 3726 | PrintLine(); | |
| 3727 | __UHEAP_MARK; | |
| 3728 | r = TestCancelNotificationL(); | |
| 3729 | __UHEAP_MARKEND; | |
| 3730 | test(r==KErrNone); | |
| 3731 | 	test.Printf(_L("------- End of CancelNotification Test -------------------------------\n"));
 | |
| 3732 | // | |
| 3733 | // 9. Create 2 file server sessions | |
| 3734 | // Add a notification on each session for the same specific file creation | |
| 3735 | // Delete the first notification | |
| 3736 | // Create that file | |
| 3737 | // | |
| 3738 | PrintLine(); | |
| 3739 | 	test.Next(_L("TestClientRemoval"));
 | |
| 3740 | __UHEAP_MARK; | |
| 3741 | r = TestClientRemovalL(); | |
| 3742 | __UHEAP_MARKEND; | |
| 3743 | test(r==KErrNone); | |
| 3744 | 	test.Printf(_L("------- End of TestClientRemoval Test --------------------------------\n"));
 | |
| 3745 | // | |
| 3746 | // 10. Create a CFsNotify object | |
| 3747 | // Close the session before closing the subsession | |
| 3748 | // Add notification and request notifications | |
| 3749 | // | |
| 3750 | PrintLine(); | |
| 3751 | __UHEAP_MARK; | |
| 3752 | // Close session after creating the object | |
| 3753 | TestSessionClose(1); | |
| 3754 | __UHEAP_MARKEND; | |
| 3755 | __UHEAP_MARK; | |
| 3756 | // Close session after adding the notification | |
| 3757 | TestSessionClose(2); | |
| 3758 | __UHEAP_MARKEND; | |
| 3759 | 	test.Printf(_L("------- End of TestSessionClose Test ---------------------------------\n"));
 | |
| 3760 | ||
| 3761 | ||
| 3762 | //========================================================================================= | |
| 3763 | //! @SYMTestCaseID PBASE-T_NOTIFY-2444 | |
| 3764 | //! @SYMTestType UT | |
| 3765 | //! @SYMREQ PREQ1847 | |
| 3766 | //! @SYMTestCaseDesc File/Directory Create and Replace – Single File Server Session | |
| 3767 | //! @SYMTestStatus Implemented | |
| 3768 | //! | |
| 3769 | //! TFsNotificationType ECreate | |
| 3770 | //========================================================================================= | |
| 3771 | // | |
| 3772 | // RFile::Create | |
| 3773 | // 1. Add notification for a specific file creation | |
| 3774 | // Create that file | |
| 3775 | // | |
| 3776 | PrintLine(); | |
| 3777 | 	test.Next(_L("EFileCreate Tests"));
 | |
| 3778 | _LIT(KFilename3,"file.create"); | |
| 3779 | 	r = TestMultipleNotificationsL(_L(""),KFilename3,5,5,t_notification::EFileCreate,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3780 | test(r==KErrNone); | |
| 3781 | 	test.Printf(_L("------- End of EFileCreate Tests -------------------------------------\n"));
 | |
| 3782 | // | |
| 3783 | // RFs::MkDir | |
| 3784 | // 2. Add notification for a specific directory creation | |
| 3785 | // Create that directory | |
| 3786 | // | |
| 3787 | PrintLine(); | |
| 3788 | 	test.Next(_L("EFsMkDir Test"));
 | |
| 3789 | _LIT(KDirName1,"dirCreate\\"); | |
| 3790 | 	r = TestMultipleNotificationsL(KDirName1,_L(""),1,1,t_notification::EFsMkDir,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3791 | test(r==KErrNone); | |
| 3792 | 	test.Printf(_L("------- End of EFsMkDir Test -----------------------------------------\n"));
 | |
| 3793 | // | |
| 3794 | // RFile::Replace | |
| 3795 | // 3. Add notification for a specific file creation | |
| 3796 | // Replace that file | |
| 3797 | // | |
| 3798 | PrintLine(); | |
| 3799 | 	test.Next(_L("EFileReplace Test"));
 | |
| 3800 | 	r = TestMultipleNotificationsL(_L(""),KFilename3,1,1,t_notification::EFileReplace,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3801 | test(r==KErrNone); | |
| 3802 | 	test.Printf(_L("------- End of EFileReplace Test -------------------------------------\n"));
 | |
| 3803 | // | |
| 3804 | // 4. Add notification for a specific file creation | |
| 3805 | // Remove that notification | |
| 3806 | // Create that file | |
| 3807 | // | |
| 3808 | PrintLine(); | |
| 3809 | __UHEAP_MARK; | |
| 3810 | r = TestAddRemoveNotificationL(); | |
| 3811 | __UHEAP_MARKEND; | |
| 3812 | test(r==KErrNone); | |
| 3813 | 	test.Printf(_L("------- End of Add and Remove Notification Test ----------------------\n"));
 | |
| 3814 | // | |
| 3815 | // Wildcard Create Tests | |
| 3816 | // 5. Add notification for file creation using wildcard name | |
| 3817 | // Add notification for file/directory wildcard including subdirectories | |
| 3818 | // Create number of files and directories that match each notification | |
| 3819 | // | |
| 3820 | PrintLine(); | |
| 3821 | 	test.Next(_L("Wildcard Create Tests"));
 | |
| 3822 | // | |
| 3823 | // Wildcard Name | |
| 3824 | _LIT(KWildcardName1,"*"); | |
| 3825 | 	r = TestMultipleNotificationsL(_L(""),KWildcardName1,1,1,t_notification::EFileCreate,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3826 | test(r==KErrNone); | |
| 3827 | r = TestMultipleNotificationsL(KWildcardName1,KWildcardName1,1,1,t_notification::EFileCreate_subs,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 3828 | test(r==KErrNone); | |
| 3829 | r = TestMultipleNotificationsL(KWildcardName1,KWildcardName1,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)ETrue,__LINE__); | |
| 3830 | test(r==KErrNone); | |
| 3831 | // | |
| 3832 | // Wildcard including Subdirectories | |
| 3833 | _LIT(KWildcardName2,"*\\"); | |
| 3834 | r = TestMultipleNotificationsL(KWildcardName2,KWildcardName1,1,1,t_notification::EFileCreate,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)ETrue,__LINE__); | |
| 3835 | test(r==KErrNone); | |
| 3836 | r = TestMultipleNotificationsL(KWildcardName2,KWildcardName1,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 3837 | test(r==KErrNone); | |
| 3838 | _LIT(KDirName2,"SubDir\\"); | |
| 3839 | _LIT(KWildcardName3,"?"); | |
| 3840 | r = TestMultipleNotificationsL(KDirName2,KWildcardName3,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 3841 | test(r==KErrNone); | |
| 3842 | // | |
| 3843 | // Wildcard Type | |
| 3844 | _LIT(KWildcardName4,"*.*"); | |
| 3845 | 	r = TestMultipleNotificationsL(_L(""),KWildcardName4,1,1,t_notification::EFileCreate_txt_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3846 | test(r==KErrNone); | |
| 3847 | 	r = TestMultipleNotificationsL(_L(""),KWildcardName4,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)ETrue,__LINE__);
 | |
| 3848 | test(r==KErrNone); | |
| 3849 | // | |
| 3850 | // 6. Add notification for file creation for a specific type | |
| 3851 | // Create file with that type | |
| 3852 | // Create file with different type | |
| 3853 | // | |
| 3854 | _LIT(KWildcardName5,"*.txt"); | |
| 3855 | 	r = TestMultipleNotificationsL(_L(""),KWildcardName5,1,1,t_notification::EFileCreate_txt,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3856 | test(r==KErrNone); | |
| 3857 | 	test.Printf(_L("------- End of Wildcard Create Tests ---------------------------------\n"));
 | |
| 3858 | ||
| 3859 | ||
| 3860 | //============================================================================= | |
| 3861 | //! @SYMTestCaseID PBASE-T_NOTIFY-2445 | |
| 3862 | //! @SYMTestType UT | |
| 3863 | //! @SYMREQ PREQ1847 | |
| 3864 | //! @SYMTestCaseDesc File Attribute Change – Single File Server Session | |
| 3865 | //! @SYMTestStatus Implemented | |
| 3866 | // | |
| 3867 | // TFsNotificationType EAttribute | |
| 3868 | //============================================================================= | |
| 3869 | // | |
| 3870 | // RFile::SetAtt, RFile::Set and RFs::SetEntry | |
| 3871 | // 1. Add notification for a specific file attribute change | |
| 3872 | // Change the attribute for that file | |
| 3873 | // | |
| 3874 | PrintLine(); | |
| 3875 | 	test.Next(_L("Attribute Tests"));
 | |
| 3876 | _LIT(KFilename4,"file.setatts"); | |
| 3877 | 	r = TestMultipleNotificationsL(_L(""),KFilename4,1,1,t_notification::EFileSetAtt,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3878 | test(r==KErrNone); | |
| 3879 | 	r = TestMultipleNotificationsL(_L(""),KFilename4,1,1,t_notification::EFileSet,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3880 | test(r==KErrNone); | |
| 3881 | 	r = TestMultipleNotificationsL(_L(""),KFilename4,1,1,t_notification::EFsSetEntry,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3882 | test(r==KErrNone); | |
| 3883 | // | |
| 3884 | // Wildcard Attribute Test including subdirectories | |
| 3885 | // 2. Add notification for file attribute change using wildcard name | |
| 3886 | // Create number of files that match the notification | |
| 3887 | // Change attributes of some files | |
| 3888 | // | |
| 3889 | 	r = TestMultipleNotificationsL(KWildcardName2,_L("*"),3,3,t_notification::EFileSetAtt_subs,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3890 | test(r==KErrNone); | |
| 3891 | 	test.Printf(_L("------- End of Attribute Tests ---------------------------------------\n"));
 | |
| 3892 | ||
| 3893 | ||
| 3894 | //============================================================================= | |
| 3895 | //! @SYMTestCaseID PBASE-T_NOTIFY-2446 | |
| 3896 | //! @SYMTestType UT | |
| 3897 | //! @SYMREQ PREQ1847 | |
| 3898 | //! @SYMTestCaseDesc File/Directory Rename – Single File Server Session | |
| 3899 | //! @SYMTestStatus Implemented | |
| 3900 | // | |
| 3901 | // TFsNotificationType ERename | |
| 3902 | //============================================================================= | |
| 3903 | // | |
| 3904 | // RFs::Replace, RFs::Rename and RFile::Rename | |
| 3905 | // 1. Add notification for a specific file rename change | |
| 3906 | // Rename that file | |
| 3907 | // | |
| 3908 | PrintLine(); | |
| 3909 | 	test.Next(_L("Rename Tests"));
 | |
| 3910 | _LIT(KFilename5,"file.rename"); | |
| 3911 | 	r = TestMultipleNotificationsL(_L(""),KFilename5,1,1,t_notification::EFsReplace,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3912 | test(r==KErrNone); | |
| 3913 | 	r = TestMultipleNotificationsL(_L(""),KFilename5,1,1,t_notification::EFsRename,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3914 | test(r==KErrNone); | |
| 3915 | 	r = TestMultipleNotificationsL(_L(""),KFilename5,1,1,t_notification::EFileRename,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3916 | test(r==KErrNone); | |
| 3917 | // | |
| 3918 | // 2. Add notification for a specific directory rename | |
| 3919 | // Rename that directory | |
| 3920 | // | |
| 3921 | _LIT(KDirName3,"dirRename\\"); | |
| 3922 | 	r = TestMultipleNotificationsL(KDirName3,_L(""),1,1,t_notification::EFsRename_dir,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3923 | test(r==KErrNone); | |
| 3924 | // | |
| 3925 | // 3. Add notification for file rename using wildcard name | |
| 3926 | // Create file that match the notification | |
| 3927 | // Repeatedly rename the file | |
| 3928 | // | |
| 3929 | 	r = TestMultipleNotificationsL(_L(""),KWildcardName1,3,3,t_notification::EFileRename_wild,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3930 | test(r==KErrNone); | |
| 3931 | 	test.Printf(_L("------- End of Rename Tests ------------------------------------------\n"));
 | |
| 3932 | ||
| 3933 | ||
| 3934 | //============================================================================= | |
| 3935 | //! @SYMTestCaseID PBASE-T_NOTIFY-2447 | |
| 3936 | //! @SYMTestType UT | |
| 3937 | //! @SYMREQ PREQ1847 | |
| 3938 | //! @SYMTestCaseDesc File/Directory Delete – Single File Server Session | |
| 3939 | //! @SYMTestStatus Implemented | |
| 3940 | // | |
| 3941 | // TFsNotificationType EDelete | |
| 3942 | //============================================================================= | |
| 3943 | // | |
| 3944 | // RFs::Delete | |
| 3945 | // 1. Add notification for a specific file delete | |
| 3946 | // Delete that file | |
| 3947 | // | |
| 3948 | PrintLine(); | |
| 3949 | 	test.Next(_L("EFsDelete Test"));
 | |
| 3950 | _LIT(KFilename6,"file.delete"); | |
| 3951 | 	r = TestMultipleNotificationsL(_L(""),KFilename6,1,1,t_notification::EFsDelete,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3952 | test(r==KErrNone); | |
| 3953 | // | |
| 3954 | // RFs::RmDir | |
| 3955 | // 2. Add notification for a specific directory delete | |
| 3956 | // Delete that directory | |
| 3957 | // | |
| 3958 | PrintLine(); | |
| 3959 | 	test.Next(_L("EFsRmDir Tests"));
 | |
| 3960 | _LIT(KDirName4,"dirRemove\\"); | |
| 3961 | 	r = TestMultipleNotificationsL(KDirName4,_L(""),1,1,t_notification::EFsRmDir,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3962 | test(r==KErrNone); | |
| 3963 | // | |
| 3964 | // This test should not receive any notifications because a non-empty directory cannot be removed | |
| 3965 | // 3. Add notification for specific directory delete | |
| 3966 | // Create files inside that directory | |
| 3967 | // Delete the directory | |
| 3968 | // | |
| 3969 | _LIT(KDirName5,"dirRmNonEmp\\"); | |
| 3970 |     r = TestMultipleNotificationsL(KDirName5,_L(""),1,1,t_notification::EFsRmDir_nonEmpty,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)ETrue,__LINE__);
 | |
| 3971 | test(r==KErrNone); | |
| 3972 | // | |
| 3973 |     // Wildcard Name ("*")
 | |
| 3974 | // 4. Add notification for directory delete using wildcard name | |
| 3975 | // Create directory that match the notification | |
| 3976 | // Delete that directory | |
| 3977 | // | |
| 3978 |     r = TestMultipleNotificationsL(KWildcardName1,_L(""),1,1,t_notification::EFsRmDir_wild,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3979 | test(r==KErrNone); | |
| 3980 | // | |
| 3981 |     // Wildcard Type ("*.txt")
 | |
| 3982 | // Creates files with different types and should only receive notifications from "*.txt" file deletions | |
| 3983 | // 5. Add notification for file deletes using wildcard type | |
| 3984 | // Create number of files that match the notification | |
| 3985 | // Delete those files | |
| 3986 | // | |
| 3987 |     r = TestMultipleNotificationsL(_L(""),KWildcardName4,3,3,t_notification::EFsDelete,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 3988 | test(r==KErrNone); | |
| 3989 |     test.Printf(_L("------- End of Delete Tests ------------------------------------------\n"));
 | |
| 3990 | ||
| 3991 | ||
| 3992 | //====================================================================== | |
| 3993 | //! @SYMTestCaseID PBASE-T_NOTIFY-2448 | |
| 3994 | //! @SYMTestType UT | |
| 3995 | //! @SYMREQ PREQ1847 | |
| 3996 | //! @SYMTestCaseDesc File Change – Single File Server Session | |
| 3997 | //! @SYMTestStatus Implemented | |
| 3998 | // | |
| 3999 | // TFsNotificationType EFileChange | |
| 4000 | //====================================================================== | |
| 4001 | // | |
| 4002 | // File Write | |
| 4003 | // If caching is enabled, notifications are received only when the file cache is flushed | |
| 4004 | // We flush everytime we do a write to ensure the tests work regardless of cache | |
| 4005 | // | |
| 4006 | // 1. Add notification for a specific file change | |
| 4007 | // Create the file | |
| 4008 | // Write to that file | |
| 4009 | // | |
| 4010 | PrintLine(); | |
| 4011 | 	test.Next(_L("EFileWrite Tests"));
 | |
| 4012 | _LIT(KFilename7,"file.write"); | |
| 4013 | __UHEAP_MARK; | |
| 4014 | 	r = TestMultipleNotificationsL(_L(""),KFilename7,7,7,t_notification::EFileWrite,TFsNotification::EFileChange,3*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 4015 | __UHEAP_MARKEND; | |
| 4016 | test(r==KErrNone); | |
| 4017 | // | |
| 4018 | // 2. Add notification for a specific file change | |
| 4019 | // Write to the specified file a number of times without changing its size | |
| 4020 | // | |
| 4021 | // Four letters are written to a file, then the first letter in the file is replaced aIterations times | |
| 4022 | // aMaxNotifications = 1 + aIterations | |
| 4023 | // | |
| 4024 | 	r = TestMultipleNotificationsL(_L(""),KFilename7,3,4,t_notification::EFileWrite_samesize,TFsNotification::EFileChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 4025 | test(r==KErrNone); | |
| 4026 | 	test.Printf(_L("------- End of EFileWrite Tests --------------------------------------\n"));
 | |
| 4027 | // | |
| 4028 | // 3. Add notification for a specific file change | |
| 4029 | // Write to that file asynchronously | |
| 4030 | // | |
| 4031 | PrintLine(); | |
| 4032 | 	test.Next(_L("EFileWrite_async Tests"));
 | |
| 4033 | _LIT(KFilename8,"async.write"); | |
| 4034 | __UHEAP_MARK; | |
| 4035 | 	r = TestMultipleNotificationsL(_L(""),KFilename8,4,4,t_notification::EFileWrite_async,TFsNotification::EFileChange,2*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 4036 | __UHEAP_MARKEND; | |
| 4037 | test(r==KErrNone); | |
| 4038 | 	test.Printf(_L("------- End of EFileWrite_async Tests --------------------------------\n"));	
 | |
| 4039 | // | |
| 4040 | // File Set Size | |
| 4041 | // 4. Add notification for a specific file change | |
| 4042 | // Both increase and decrease the file sizes a number of times | |
| 4043 | // | |
| 4044 | // The file size is increased aIterations times, and decreased (aIterations - 1) times | |
| 4045 | // aMaxNotifications = 2*aIterations - 1 | |
| 4046 | // | |
| 4047 | PrintLine(); | |
| 4048 | 	test.Next(_L("EFileSetSize Tests"));
 | |
| 4049 | _LIT(KFilename9,"file.setsize"); | |
| 4050 | 	r = TestMultipleNotificationsL(_L(""),KFilename9,5,9,t_notification::EFileSetSize,TFsNotification::EFileChange,3*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 4051 | test(r==KErrNone); | |
| 4052 | 	test.Printf(_L("------- End of EFileSetSize Tests ------------------------------------\n"));
 | |
| 4053 | ||
| 4054 | ||
| 4055 | // | |
| 4056 | PrintLine(); | |
| 4057 | 	test.Next(_L("CFileMan Tests"));
 | |
| 4058 | _LIT(KFilenameCFMan,"cf1le.man"); | |
| 4059 | TUint notificationTypes = (TUint)TFsNotification::ECreate|TFsNotification::EFileChange|TFsNotification::EAttribute|TFsNotification::EDelete|TFsNotification::ERename; | |
| 4060 | 	r = TestMultipleNotificationsL(_L(""),KFilenameCFMan,1,5,t_notification::ECFileManMove,notificationTypes,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 4061 | test(r==KErrNone); | |
| 4062 | 	test.Printf(_L("------- End of CFileMan Tests -------------------------------------\n"));
 | |
| 4063 | ||
| 4064 | ||
| 4065 | //======================================================================================== | |
| 4066 | //! @SYMTestCaseID PBASE-T_NOTIFY-2449 | |
| 4067 | //! @SYMTestType UT | |
| 4068 | //! @SYMREQ PREQ1847 | |
| 4069 | //! @SYMTestCaseDesc File System Mounted/Dismounted, Media Card Removal/Insertion, | |
| 4070 | // RawDisk Write – Single File Server Session | |
| 4071 | //! @SYMTestStatus Implemented | |
| 4072 | // | |
| 4073 | // TFsNotificationType EMediaChange | |
| 4074 | //======================================================================================== | |
| 4075 | // | |
| 4076 | // RFs::DismountFileSystem | |
| 4077 | // 1. Add notification for media change | |
| 4078 | // Dismount the file system | |
| 4079 | // | |
| 4080 | PrintLine(); | |
| 4081 | 	test.Next(_L("Mount Tests"));
 | |
| 4082 | TFullName filesystemName; | |
| 4083 | r = TheFs.FileSystemName(filesystemName,globalDriveNum); | |
| 4084 | test(r==KErrNone); | |
| 4085 | r = TestMultipleNotificationsL(filesystemName,1,1,t_notification::EDismount,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 4086 | test(r==KErrNone); | |
| 4087 | // | |
| 4088 | // RFs::MountFileSystem | |
| 4089 | // 2. Add notification for media change | |
| 4090 | // Mount the file system | |
| 4091 | // | |
| 4092 | r = TestMultipleNotificationsL(filesystemName,1,1,t_notification::EMount,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 4093 | test(r==KErrNone); | |
| 4094 | // | |
| 4095 | // Repeatedly mount and dismount the file system | |
| 4096 | // 3. Add notification for media change | |
| 4097 | // Repeatedly dismount and mount the file system | |
| 4098 | // | |
| 4099 | // The file system is dismounted and mounted aIterations times | |
| 4100 | // aMaxNotifications = 2*aIterations | |
| 4101 | // | |
| 4102 | r = TestMultipleNotificationsL(filesystemName,5,10,t_notification::EMountDismount,TFsNotification::EMediaChange,3*KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 4103 | test(r==KErrNone); | |
| 4104 | // | |
| 4105 | // RFs::MountFileSystemAndScan | |
| 4106 | // 4. Add notification for media change | |
| 4107 | // Mount and scan the file system | |
| 4108 | // | |
| 4109 | // The file system is dismounted and mounted aIterations times | |
| 4110 | // aMaxNotifications = 2*aIterations | |
| 4111 | // | |
| 4112 | //#ifndef __WINS__ | |
| 4113 | // r = TestMultipleNotificationsL(filesystemName,1,2,t_notification::EMountScan,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 4114 | // test(r==KErrNone); | |
| 4115 | //#endif | |
| 4116 | 	test.Printf(_L("------- End of Mount Tests -------------------------------------------\n"));
 | |
| 4117 | TDriveInfo drvInfo; | |
| 4118 | TInt driveNum; | |
| 4119 | TheFs.CharToDrive(gDriveToTest,driveNum); | |
| 4120 | r = TheFs.Drive(drvInfo,driveNum); | |
| 4121 | test (r == KErrNone); | |
| 4122 | TPtrC driveDes((TText*)&gDriveToTest,1); | |
| 4123 | // | |
| 4124 | // Manual Tests - Will only run on removable drives | |
| 4125 | // | |
| 4126 | /* if(drvInfo.iDriveAtt & KDriveAttRemovable) | |
| 4127 | 		{
 | |
| 4128 | // | |
| 4129 | // 5. Add notification for media change | |
| 4130 | // Remove media card manually | |
| 4131 | // | |
| 4132 | PrintLine(); | |
| 4133 | 		test.Next(_L("Media Card Removal/Insertion Tests"));
 | |
| 4134 | r = TestMultipleNotificationsL(driveDes,1,1,t_notification::EMediaCardRemoval,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 4135 | test(r==KErrNone); | |
| 4136 | // | |
| 4137 | // 6. Add notification for media change | |
| 4138 | // Insert media card manually | |
| 4139 | // | |
| 4140 | r = TestMultipleNotificationsL(driveDes,1,1,t_notification::EMediaCardInsertion,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 4141 | test(r==KErrNone); | |
| 4142 | 		test.Printf(_L("------- End of Media Card Removal/Insertion Tests --------------------\n"));
 | |
| 4143 | // | |
| 4144 | // We should receive an EMediaChange notification even though we did not register for it | |
| 4145 | // 7. Do not add notification for media change | |
| 4146 | // Remove and insert media card manually | |
| 4147 | // | |
| 4148 | PrintLine(); | |
| 4149 | TestMediaCardNotificationWhenNotRegisteredForIt(); | |
| 4150 | 		test.Printf(_L("------- End of TestMediaCardNotificationWhenNotRegisteredForIt -------\n"));
 | |
| 4151 | } | |
| 4152 | */ // | |
| 4153 | // RRawDisk::Write | |
| 4154 | // 8. Add notification for media change | |
| 4155 | // Write directly to the media | |
| 4156 | // | |
| 4157 | #ifdef __WINS__ | |
| 4158 | if(gDriveToTest-(TChar)'A' != 2) | |
| 4159 | #endif | |
| 4160 |         {
 | |
| 4161 | PrintLine(); | |
| 4162 |         test.Next(_L("RRawDisk::Write Tests"));
 | |
| 4163 | r = TestMultipleNotificationsL(driveDes,1,1,t_notification::ERawDiskWrite,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 4164 | test(r==KErrNone); | |
| 4165 |         test.Printf(_L("------- End of RRawDisk::Write Test ------------------------------  \n"));
 | |
| 4166 | } | |
| 4167 | ||
| 4168 | ||
| 4169 | //=============================================================================== | |
| 4170 | //! @SYMTestCaseID PBASE-T_NOTIFY-2450 | |
| 4171 | //! @SYMTestType UT | |
| 4172 | //! @SYMREQ PREQ1847 | |
| 4173 | //! @SYMTestCaseDesc Drive Name Modification – Single File Server Session | |
| 4174 | //! @SYMTestStatus Implemented | |
| 4175 | // | |
| 4176 | // TFsNotificationType EDriveName | |
| 4177 | //=============================================================================== | |
| 4178 | // | |
| 4179 | // RFs::SetDriveName | |
| 4180 | // The drive name is renamed 2*aIterations times | |
| 4181 | // aMaxNotifications = 2*aIterations | |
| 4182 | // | |
| 4183 | // 1. Add notification for a specific drive name change | |
| 4184 | // Change the drive name | |
| 4185 | // | |
| 4186 | PrintLine(); | |
| 4187 | 	test.Next(_L("DriveName Test"));
 | |
| 4188 | r = TestMultipleNotificationsL(driveDes,1,2,t_notification::ESetDriveName,TFsNotification::EDriveName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 4189 | test(r==KErrNone); | |
| 4190 | // | |
| 4191 | // 2. Add notification for a specific drive name change | |
| 4192 | // Repeatedly rename the drive | |
| 4193 | // | |
| 4194 | r = TestMultipleNotificationsL(driveDes,3,6,t_notification::ESetDriveName,TFsNotification::EDriveName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 4195 | test(r==KErrNone); | |
| 4196 | 	test.Printf(_L("------- End of DriveName Test ----------------------------------------\n"));
 | |
| 4197 | ||
| 4198 | ||
| 4199 | //================================================================================ | |
| 4200 | //! @SYMTestCaseID PBASE-T_NOTIFY-2451 | |
| 4201 | //! @SYMTestType UT | |
| 4202 | //! @SYMREQ PREQ1847 | |
| 4203 | //! @SYMTestCaseDesc Volume Name Modification – Single File Server Session | |
| 4204 | //! @SYMTestStatus Implemented | |
| 4205 | // | |
| 4206 | // TFsNotificationType EVolumeName | |
| 4207 | //================================================================================ | |
| 4208 | // | |
| 4209 | // RFs::SetVolumeLabel - Does not run on WINS | |
| 4210 | // The volume name is renamed 2*aIterations times | |
| 4211 | // aMaxNotifications = 2*aIterations | |
| 4212 | // | |
| 4213 | #ifndef __WINS__ | |
| 4214 | PrintLine(); | |
| 4215 | 	test.Next(_L("VolumeName Test"));
 | |
| 4216 | // | |
| 4217 | // 1. Add notification for a specific volume name change | |
| 4218 | // Change the volume name | |
| 4219 | // | |
| 4220 | r = TestMultipleNotificationsL(driveDes,1,2,t_notification::ESetVolumeLabel,TFsNotification::EVolumeName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 4221 | test(r==KErrNone); | |
| 4222 | // | |
| 4223 | // 2. Add notification for a specific volume name change | |
| 4224 | // Repeatedly rename the volume | |
| 4225 | // | |
| 4226 | r = TestMultipleNotificationsL(driveDes,3,6,t_notification::ESetVolumeLabel,TFsNotification::EVolumeName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 4227 | test(r==KErrNone); | |
| 4228 | 	test.Printf(_L("------- End of VolumeName Test ---------------------------------------\n"));
 | |
| 4229 | #endif | |
| 4230 | ||
| 4231 | ||
| 4232 | //============================================================================= | |
| 4233 | //! @SYMTestCaseID PBASE-T_NOTIFY-2452 | |
| 4234 | //! @SYMTestType UT | |
| 4235 | //! @SYMREQ PREQ1847 | |
| 4236 | //! @SYMTestCaseDesc All Operations Filter – Single File Server Session | |
| 4237 | //! @SYMTestStatus Implemented | |
| 4238 | // | |
| 4239 | // TFsNotificationType EAllOps | |
| 4240 | //============================================================================= | |
| 4241 | PrintLine(); | |
| 4242 | 	test.Next(_L("AllOps Tests"));
 | |
| 4243 | // | |
| 4244 | // 1. Add notification for all operations | |
| 4245 | // Create a file | |
| 4246 | // Delete the file | |
| 4247 | // | |
| 4248 | // EAllOps1: A file is created and deleted aIterations times | |
| 4249 | // aMaxNotification = 2*aIterations | |
| 4250 | // | |
| 4251 | _LIT(KFilename10,"file.allops"); | |
| 4252 | 	r = TestMultipleNotificationsL(_L(""),KFilename10,4,8,t_notification::EAllOps1,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 4253 | test(r==KErrNone); | |
| 4254 | // | |
| 4255 | // 2. Add notification for all operations | |
| 4256 | // Create a file | |
| 4257 | // Write to the file | |
| 4258 | // Delete the file | |
| 4259 | // | |
| 4260 | // EAllOps2: A file is created, written to aIterations times and then deleted | |
| 4261 | // aMaxNotification = 2 + aIterations (See File Write Tests) | |
| 4262 | // | |
| 4263 | 	r = TestMultipleNotificationsL(_L(""),KFilename10,4,6,t_notification::EAllOps2,(TUint)TFsNotification::EAllOps,2*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 4264 | test(r==KErrNone); | |
| 4265 | // | |
| 4266 | // 3. Add notification for all operations | |
| 4267 | // Create a file | |
| 4268 | // Change the file size | |
| 4269 | // Delete the file | |
| 4270 | // | |
| 4271 | // EAllOps3: A file is created, its size is increased size aIterations times, decreased (aIterations - 1) times | |
| 4272 | // and then deleted | |
| 4273 | // aMaxNotifications = 1 + 2*aIterations | |
| 4274 | // | |
| 4 
56f325a607ea
Revision: 200951
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
0diff
changeset | 4275 | 	r = TestMultipleNotificationsL(_L(""),KFilename10,4,9,t_notification::EAllOps3,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize*2,(TBool)EFalse,__LINE__);
 | 
| 0 | 4276 | test(r==KErrNone); | 
| 4277 | // | |
| 4278 | // 4. Add notification for all operations | |
| 4279 | // Create a file | |
| 4280 | // Change the file attribute | |
| 4281 | // Delete the file | |
| 4282 | // | |
| 4283 | // EAllOps4: A file is created, its attribute is changed and the file is deleted | |
| 4284 | // aMaxNotification = 3 | |
| 4285 | // | |
| 4286 | 	r = TestMultipleNotificationsL(_L(""),KFilename10,1,3,t_notification::EAllOps4,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 4287 | test(r==KErrNone); | |
| 4288 | // | |
| 4289 | // 5. Add notification for all operations | |
| 4290 | // Create a file | |
| 4291 | // Rename the file | |
| 4292 | // | |
| 4293 | // EAllOps5: A file is created and renamed | |
| 4294 | // aMaxNotification = 2 | |
| 4295 | // | |
| 4296 | 	r = TestMultipleNotificationsL(_L(""),KFilename10,1,2,t_notification::EAllOps5,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 4297 | test(r==KErrNone); | |
| 4298 | // | |
| 4299 | // 6. Add notification for all operations | |
| 4300 | // Change drive name | |
| 4301 | // Change volume name | |
| 4302 | // | |
| 4303 | // SetVolumeLabel does not run on WINS | |
| 4304 | // EAllOps6: The drive and volume names are changed | |
| 4305 | // aMaxNotification = 2 | |
| 4306 | // | |
| 4307 | #ifndef __WINS__ | |
| 4308 | r = TestMultipleNotificationsL(driveDes,1,2,t_notification::EAllOps6,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 4309 | test(r==KErrNone); | |
| 4310 | #endif | |
| 4311 | 	test.Printf(_L("------- End of AllOps Tests ------------------------------------------\n"));
 | |
| 4312 | ||
| 4313 | ||
| 4314 | //============================================================================= | |
| 4315 | //! @SYMTestCaseID PBASE-T_NOTIFY-2453 | |
| 4316 | //! @SYMTestType UT | |
| 4317 | //! @SYMREQ PREQ1847 | |
| 4318 | //! @SYMTestCaseDesc Multiple Filters – Single File Server Session | |
| 4319 | //! @SYMTestStatus Implemented | |
| 4320 | //============================================================================= | |
| 4321 | PrintLine(); | |
| 4322 | 	test.Next(_L("Multiple-Filter Tests"));
 | |
| 4323 | // | |
| 4324 | // TFsNotification::ECreate | TFsNotification::EDelete | |
| 4325 | // 1. Add notification for create and delete for a specific file | |
| 4326 | // Create that file | |
| 4327 | // Delete the file | |
| 4328 | // | |
| 4329 | // A file is created and deleted aIterations times | |
| 4330 | // aMaxNotification = 2*aIterations | |
| 4331 | // | |
| 4332 | _LIT(KFilename11,"file.mulfil"); | |
| 4333 | 	r = TestMultipleNotificationsL(_L(""),KFilename11,3,6,t_notification::EAllOps1,TFsNotification::ECreate | TFsNotification::EDelete,2*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 4334 | test(r==KErrNone); | |
| 4335 | // | |
| 4336 | // TFsNotification::EDelete | TFsNotification::ECreate | TFsNotification::EFileChange | |
| 4337 | // 2. Add notification for create, file change and delete for a specific file | |
| 4338 | // Create a file | |
| 4339 | // Change the file size | |
| 4340 | // Delete the file | |
| 4341 | // | |
| 4342 | // A file is created, its size is increased size aIterations times, decreased (aIterations - 1) times | |
| 4343 | // and then deleted | |
| 4344 | // aMaxNotifications = 1 + 2*aIterations | |
| 4345 | // | |
| 4 
56f325a607ea
Revision: 200951
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
0diff
changeset | 4346 | 	r = TestMultipleNotificationsL(_L(""),KFilename11,4,9,t_notification::EAllOps3,TFsNotification::EDelete | TFsNotification::ECreate | TFsNotification::EFileChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | 
| 0 | 4347 | test(r==KErrNone); | 
| 4348 | // | |
| 4349 | // TFsNotification::EAttribute | TFsNotification::EDelete | TFsNotification::ECreate | |
| 4350 | // 3. Add notification for create, attribute change and delete for a specific file | |
| 4351 | // Create a file | |
| 4352 | // Change the file attribute | |
| 4353 | // Delete the file | |
| 4354 | // | |
| 4355 | // A file is created, its attribute is changed and the file is deleted | |
| 4356 | // aMaxNotification = 3 | |
| 4357 | // | |
| 4358 | 	r = TestMultipleNotificationsL(_L(""),KFilename11,1,3,t_notification::EAllOps4,TFsNotification::EAttribute | TFsNotification::EDelete | TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 4359 | test(r==KErrNone); | |
| 4360 | // | |
| 4361 | // TFsNotification::ERename | TFsNotification::ECreate | |
| 4362 | // 4. Add notification for create and rename for a specific file | |
| 4363 | // Create a file | |
| 4364 | // Rename the file | |
| 4365 | // | |
| 4366 | // A file is created and renamed | |
| 4367 | // aMaxNotification = 2 | |
| 4368 | // | |
| 4369 | 	r = TestMultipleNotificationsL(_L(""),KFilename11,1,2,t_notification::EAllOps5,TFsNotification::ERename | TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
 | |
| 4370 | test(r==KErrNone); | |
| 4371 | // | |
| 4372 | // TFsNotification::EVolumeName | TFsNotification::EDriveName | |
| 4373 | // 5. Add notification for drive and volume name change for a specific drive | |
| 4374 | // Change drive name | |
| 4375 | // Change volume name | |
| 4376 | // | |
| 4377 | // SetVolumeLabel does not run on WINS | |
| 4378 | // The drive and volume names are changed | |
| 4379 | // aMaxNotification = 2 | |
| 4380 | // | |
| 4381 | #ifndef __WINS__ | |
| 4382 | r = TestMultipleNotificationsL(driveDes,1,2,t_notification::EAllOps6,TFsNotification::EVolumeName | TFsNotification::EDriveName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 4383 | test(r==KErrNone); | |
| 4384 | #endif | |
| 4385 | 	test.Printf(_L("------- End of Multiple-Filter Tests ---------------------------------\n"));
 | |
| 4386 | ||
| 4387 | ||
| 4388 | //============================================================================== | |
| 4389 | //! @SYMTestCaseID PBASE-T_NOTIFY-2454 | |
| 4390 | //! @SYMTestType UT | |
| 4391 | //! @SYMREQ PREQ1847 | |
| 4392 | //! @SYMTestCaseDesc Overflow Notification – Single File Server Session | |
| 4393 | //! @SYMTestStatus Implemented | |
| 4394 | //============================================================================== | |
| 4395 | // | |
| 4396 | // 1. Add notification with a small buffer size, for a specific file change | |
| 4397 | // Change the file size once | |
| 4398 | // 2. Make continuous file size changes to the file | |
| 4399 | // 3. When overflow notification occurs, delete the notification | |
| 4400 | // | |
| 4401 | PrintLine(); | |
| 4402 | r = TestOverflowL(); | |
| 4403 | test(r==KErrNone); | |
| 4404 | ||
| 4405 | //For DEF140387 | |
| 4406 | PrintLine(); | |
| 4407 | r= TestPostOverflowNotifications(); | |
| 4408 | test(r==KErrNone); | |
| 4409 | 	test.Printf(_L("------- End of Overflow Test -----------------------------------------\n"));
 | |
| 4410 | ||
| 4411 | ||
| 4412 | //============================================================================ | |
| 4413 | //! @SYMTestCaseID PBASE-T_NOTIFY-2455 | |
| 4414 | //! @SYMTestType CIT | |
| 4415 | //! @SYMREQ PREQ1847 | |
| 4416 | //! @SYMTestCaseDesc API Negative Testing – Single File Server Session | |
| 4417 | //! @SYMTestStatus Implemented | |
| 4418 | //============================================================================ | |
| 4419 | // 1. | |
| 4420 | // a-CFsNotify class creation with zero buffer size | |
| 4421 | // | |
| 4422 | // 2. | |
| 4423 | // b-CFsNotify class creation with negative buffer size | |
| 4424 | // c-CFsNotify class creation with buffer size that is too large | |
| 4425 | // | |
| 4426 | // 3. | |
| 4427 | // d-Call AddNotification with aNotiififcationType zero | |
| 4428 | // e-Call AddNotification with aNotiififcationType invalid | |
| 4429 | // f-Call AddNotification with many different invalid paths | |
| 4430 | // | |
| 4431 | // 4. | |
| 4432 | // g-Call RequestNotifications with status that is already in use | |
| 4433 | // h-Call CancelNotifications with wrong status | |
| 4434 | // | |
| 4435 | PrintLine(); | |
| 4436 | __UHEAP_MARK; | |
| 4437 | NegativeTests(); | |
| 4438 | __UHEAP_MARKEND; | |
| 4439 | // | |
| 4440 | // 5. | |
| 4441 | // i-Negative testing for directory without * | |
| 4442 | // | |
| 4443 | 	test.Printf(_L("NegativeTests() I\n"));
 | |
| 4444 | NegativeTestDirStar(); | |
| 4445 | 	test.Printf(_L("------- End of Negative Tests ----------------------------------------\n"));
 | |
| 4446 | ||
| 4447 | ||
| 4448 | //============================================================================= | |
| 4449 | //! @SYMTestCaseID PBASE-T_NOTIFY-2461 | |
| 4450 | //! @SYMTestType CIT | |
| 4451 | //! @SYMREQ PREQ1847 | |
| 4452 | //! @SYMTestCaseDesc Plugin Tests | |
| 4453 | //! @SYMTestStatus | |
| 4454 | //============================================================================= | |
| 4455 | PrintLine(); | |
| 4456 | r = TestNotificationsWithFServPlugins(); | |
| 4457 | test(r==KErrNone); | |
| 4458 | 	test.Printf(_L("------- End of Plugin Tests ------------------------------------------\n"));
 | |
| 4459 | ||
| 4460 | ||
| 4461 | //====================================================================== | |
| 4462 | //! @SYMTestCaseID PBASE-T_NOTIFY-2459 | |
| 4463 | //! @SYMTestType UT | |
| 4464 | //! @SYMREQ PREQ1847 | |
| 4465 | //! @SYMTestCaseDesc Drive Formatting – Single File Server Session | |
| 4466 | //! @SYMTestStatus Implemented | |
| 4467 | // | |
| 4468 | // TFsNotificationType EMediaChange | |
| 4469 | //====================================================================== | |
| 4470 | // | |
| 4471 | // RFormat | |
| 4472 | // We do these last so that we can be sure to have deleted anything we've inadvertently not deleted | |
| 4473 | // | |
| 4474 | // 1. Add notification for media change of a specific drive | |
| 4475 | // Format the drive | |
| 4476 | // | |
| 4477 | #ifdef __WINS__ | |
| 4478 | if(gDriveToTest-(TChar)'A' != 2) | |
| 4479 | #endif | |
| 4480 | 		{
 | |
| 4481 | PrintLine(); | |
| 4482 | 		test.Next(_L("Format Tests"));
 | |
| 4483 | r = TestMultipleNotificationsL(driveDes,1,1,t_notification::EFormat,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__); | |
| 4484 | test(r==KErrNone); | |
| 4485 | 		test.Printf(_L("------- End of Format Tests ------------------------------------------\n"));
 | |
| 4486 | } | |
| 4487 | ||
| 4488 | ||
| 4489 | //====================================================================== | |
| 4490 | //! @SYMTestCaseID PBASE-T_NOTIFY-2460 | |
| 4491 | //! @SYMTestType UT | |
| 4492 | //! @SYMREQ PREQ1847 | |
| 4493 | //! @SYMTestCaseDesc Notifications for Data Caged Areas | |
| 4494 | //! @SYMTestStatus Implemented | |
| 4495 | //====================================================================== | |
| 4496 | // | |
| 4497 | // Create a private folder for a specified uid | |
| 4498 | // Add notification filter using the following processes: | |
| 4499 | // 1. A process with no capability | |
| 4500 | // 2. A process with all capabilities | |
| 4501 | // 3. A process with the specified uid | |
| 4502 | // | |
| 4503 | PrintLine(); | |
| 4504 | 	test.Next(_L("Test T_NOTIFIER_NOCAPS.EXE"));
 | |
| 4505 | 	r = TestProcessCapabilities(_L("T_NOTIFIER_NOCAPS.EXE"));
 | |
| 4506 | test(r == KErrPermissionDenied); //Failure on emulator -> Did you forget to do a wintest? | |
| 4507 | ||
| 4508 | 	test.Next(_L("Test T_NOTIFIER_ALLFILES.EXE"));
 | |
| 4509 | 	r = TestProcessCapabilities(_L("T_NOTIFIER_ALLFILES.EXE"));
 | |
| 4510 | test(r == KErrNone); | |
| 4511 | ||
| 4512 | 	test.Next(_L("Test T_NOTIFIER_BELONGS.EXE"));
 | |
| 4513 | 	r = TestProcessCapabilities(_L("T_NOTIFIER_BELONGS.EXE"));
 | |
| 4514 | test(r == KErrNone); | |
| 4515 | 	test.Printf(_L("------- End of Data-Caging Tests -------------------------------------\n"));
 | |
| 4516 | ||
| 4517 | ||
| 4518 | test.End(); | |
| 4519 | test.Close(); | |
| 4520 | delete cleanup; | |
| 4521 | } //End of CallTestsL | |
| 4522 |