1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_notifier.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,4522 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// f32test\server\t_notifier.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <f32file.h>
1.22 +#include <e32test.h>
1.23 +#include <e32svr.h>
1.24 +#include <hal.h>
1.25 +#include "t_server.h"
1.26 +#include "t_chlffs.h"
1.27 +#include "t_notify_plugin.h"
1.28 +
1.29 +const TInt KNotificationHeaderSize = (sizeof(TUint16)*2)+(sizeof(TUint));
1.30 +const TInt KMinNotificationBufferSize = 2*KNotificationHeaderSize + 2*KMaxFileName;
1.31 +
1.32 +
1.33 +RTest test(_L("T_NOTIFIER"));
1.34 +const TInt KMaxHeapSize = 0x800000;
1.35 +TInt globalDriveNum;
1.36 +
1.37 +void DismountPlugin()
1.38 + {
1.39 + TheFs.DismountPlugin(KNotifyPluginName);
1.40 + TheFs.RemovePlugin(KNotifyPluginFileName);
1.41 + }
1.42 +
1.43 +inline void safe_test(RTest& aTest, TInt aError, TInt aLine, TText* aName)
1.44 + {
1.45 + if(aError!=KErrNone)
1.46 + {
1.47 + test.Printf(_L(": ERROR : %d received on line %d\n"),aError,aLine);
1.48 + DismountPlugin();
1.49 + aTest.operator()(aError==KErrNone,aLine,(TText*)aName);
1.50 + }
1.51 + }
1.52 +
1.53 +// Used by TestMultipleNotificationsL() to show which line the function is called from
1.54 +inline void safe_test(RTest& aTest, TInt aError, TInt aLine, TInt aLineCall)
1.55 + {
1.56 + if(aError != KErrNone)
1.57 + {
1.58 + aTest.Printf(_L(": ERROR : %d received on line %d\n"), aError, aLine);
1.59 + aTest.Printf(_L(": ERROR : Function called from line number: %d\n"), aLineCall);
1.60 + aTest.operator()(aError == KErrNone, aLine);
1.61 + }
1.62 + }
1.63 +
1.64 +// Prints out the filename
1.65 +#define ExpandMe(X) L ## X
1.66 +#define Expand(X) ExpandMe(X)
1.67 +
1.68 +namespace t_notification
1.69 + {
1.70 + enum EOperation
1.71 + {
1.72 + //TFsNotification::ECreate
1.73 + EFileReplace,
1.74 + EFileCreate,
1.75 + EFileCreate_subs, //Create files in subdir, watch subdirs
1.76 + EFileCreate_subs_nowatch, //Create files in subdir, do not monitor subdirs
1.77 + EFileCreate_txt_nowatch, //Create .txt files in subdir, do not monitor subdirs
1.78 + EFileCreate_txt, //Create .txt files
1.79 + EFsMkDir, //Create directory
1.80 + //TFsNotification::EAttribute
1.81 + EFileSetAtt,
1.82 + EFileSetAtt_subs, //Set attributes in subdir
1.83 + EFileSet,
1.84 + EFsSetEntry,
1.85 + //TFsNotification::ERename
1.86 + EFsReplace, //Replace file
1.87 + EFsRename, //Rename file
1.88 + EFsRename_dir, //Rename directory
1.89 + EFileRename,
1.90 + EFileRename_wild, //Rename file using wildcard name
1.91 + //TFsNotification::EDelete
1.92 + EFsDelete, //Delete file
1.93 + EFsRmDir, //Remove directory
1.94 + EFsRmDir_nonEmpty, //Remove non-empty directory, which will return KErrInUse
1.95 + EFsRmDir_wild, //Remove subdirectory using wildcard name
1.96 + //TFsNotification::EFileChange
1.97 + EFileWrite,
1.98 + EFileWrite_samesize, //Write to file without changing its size
1.99 + EFileWrite_async, //Asynchronous write
1.100 + EFileSetSize,
1.101 + //TFsNotification::EVolumeName
1.102 + ESetVolumeLabel,
1.103 + //TFsNotification::EDriveName
1.104 + ESetDriveName,
1.105 + //TFsNotification::EMediaChange
1.106 + EMount,
1.107 + EDismount,
1.108 + EMountScan,
1.109 + EMountDismount,
1.110 + EFormat,
1.111 + EMediaCardRemoval,
1.112 + EMediaCardInsertion,
1.113 + ERawDiskWrite,
1.114 + //Multiple Filters
1.115 + EAllOps1, //Create/Replace and Delete
1.116 + EAllOps2, //Create/Replace, FileChange(Write) and Delete
1.117 + EAllOps3, //Create/Replace, FileChange(SetSize) and Delete
1.118 + EAllOps4, //Create/Replace, Attribute(SetAtt) and Delete
1.119 + EAllOps5, //Create/Replace and Rename
1.120 + EAllOps6, //VolumeName and DriveName
1.121 + ECFileManMove //Create filex in monitored directory, write 4, move to unmonitored, setsize 8, move back, delete
1.122 + };
1.123 + }
1.124 +
1.125 +// Package filename and semaphore for thread
1.126 +struct SThreadPackage
1.127 + {
1.128 + TFileName iFileName;
1.129 + RSemaphore iBarrier;
1.130 + };
1.131 +
1.132 +struct SThreadPackageDualSemaphore
1.133 + {
1.134 + TFileName iFileName;
1.135 + RSemaphore iBarrier;
1.136 + RSemaphore iBarrier2;
1.137 + };
1.138 +
1.139 +struct SThreadPackage2
1.140 + {
1.141 + TInt iTestCase;
1.142 + RSemaphore iBarrier;
1.143 + };
1.144 +
1.145 +// Used by TestMultipleNotificationsL
1.146 +struct SThreadPackageMultiple
1.147 + {
1.148 + TFileName iString; //Commonly stores the filename
1.149 + TFileName iFileName; //Commonly stores the path (not inc filename)
1.150 + RSemaphore iBarrier;
1.151 + t_notification::EOperation iOperation;
1.152 + TFsNotification::TFsNotificationType iNotifyType;
1.153 + TInt iIterations; //# of times to 'do' something
1.154 + TInt iMaxNotifications; //# of notifications expected
1.155 + TInt iBufferSize;
1.156 + TInt iLineCall; //Line where the function is called from
1.157 + };
1.158 +
1.159 +void PrintLine()
1.160 + {
1.161 + test.Printf(_L("======================================================================\n"));
1.162 + }
1.163 +
1.164 +
1.165 +// We should receive an EMediaChange notification even though we did not register for it
1.166 +void TestMediaCardNotificationWhenNotRegisteredForIt()
1.167 + {
1.168 + RFs fs;
1.169 + TInt r = fs.Connect();
1.170 + test(r==KErrNone);
1.171 +
1.172 + CFsNotify* notify = NULL;
1.173 + TRAP(r,notify= CFsNotify::NewL(fs,KMinNotificationBufferSize));
1.174 +
1.175 + TBuf<40> path;
1.176 + path.Append((TChar)gDriveToTest);
1.177 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.178 +
1.179 + TBuf<20> filename;
1.180 + filename.Append(_L("media.change1"));
1.181 +
1.182 + r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
1.183 + test(r==KErrNone);
1.184 +
1.185 + TRequestStatus status;
1.186 + r = notify->RequestNotifications(status);
1.187 + test(r==KErrNone);
1.188 +
1.189 + test.Printf(_L("*****************************************************************\n"));
1.190 + test.Printf(_L("Waiting 10 seconds.\n"));
1.191 + test.Printf(_L("This is a MANUAL test, it requires the removal of the media card.\n"));
1.192 + test.Printf(_L("PLEASE REMOVE THE MEDIA CARD. (DriveNumber %d)\n"),globalDriveNum);
1.193 + test.Printf(_L("Or press Ctrl + F5 on the emulator.\n"));
1.194 + test.Printf(_L("*****************************************************************\n"));
1.195 + RTimer timer1;
1.196 + r = timer1.CreateLocal();
1.197 + test(r == KErrNone);
1.198 + TRequestStatus timeout;
1.199 + TTimeIntervalMicroSeconds32 time = 10000000;
1.200 + timer1.After(timeout,time);
1.201 + User::WaitForRequest(timeout,status);
1.202 + test(status.Int() != KRequestPending);
1.203 + timer1.Cancel();
1.204 + timer1.Close();
1.205 +
1.206 + const TFsNotification* notification = notify->NextNotification();
1.207 + test(notification != NULL);
1.208 + TFsNotification::TFsNotificationType type = notification->NotificationType();
1.209 + test(type == TFsNotification::EMediaChange);
1.210 + TBuf<2> drive;
1.211 + drive.Append((TChar)gDriveToTest);
1.212 + drive.Append(_L(":"));
1.213 + TPtrC drivePtr;
1.214 + r = notification->Path(drivePtr);
1.215 + test(r==KErrNone);
1.216 + r = drivePtr.Compare(drive);
1.217 + test(r==0);
1.218 +
1.219 + test.Printf(_L("*****************************************************************\n"));
1.220 + test.Printf(_L("Waiting 10 seconds.\n"));
1.221 + test.Printf(_L("This is a MANUAL test, it requires the insertion of the media card.\n"));
1.222 + test.Printf(_L("PLEASE INSERT THE MEDIA CARD. (DriveNumber %d)\n"),globalDriveNum);
1.223 + test.Printf(_L("Or press Ctrl + F5 on the emulator.\n"));
1.224 + test.Printf(_L("*****************************************************************\n"));
1.225 +
1.226 + notification = notify->NextNotification();
1.227 + if(notification == NULL)
1.228 + {
1.229 + notify->RequestNotifications(status);
1.230 + RTimer timer2;
1.231 + r = timer2.CreateLocal();
1.232 + test(r == KErrNone);
1.233 + TRequestStatus timeout2;
1.234 + timer2.After(timeout2,time);
1.235 + User::WaitForRequest(timeout2,status);
1.236 + test(status.Int() != KRequestPending);
1.237 + notification = notify->NextNotification();
1.238 + timer2.Cancel();
1.239 + timer2.Close();
1.240 + }
1.241 + test(notification != NULL);
1.242 + type = notification->NotificationType();
1.243 + test(type == TFsNotification::EMediaChange);
1.244 +
1.245 + delete notify;
1.246 + fs.Close();
1.247 + }
1.248 +
1.249 +// Creates two sessions, removes the first one
1.250 +// and then checks if the second one still works
1.251 +TInt TestClientRemovalL()
1.252 + {
1.253 + RFs fs;
1.254 + TInt r = fs.Connect();
1.255 + test(r==KErrNone);
1.256 +
1.257 + CFsNotify* notify1 = NULL;
1.258 + CFsNotify* notify2 = NULL;
1.259 + TRAP(r,notify1= CFsNotify::NewL(fs,KMinNotificationBufferSize);
1.260 + notify2= CFsNotify::NewL(fs,KMinNotificationBufferSize);
1.261 + );
1.262 + if(r!=KErrNone)
1.263 + {
1.264 + delete notify1;
1.265 + delete notify2;
1.266 + test(r==KErrNone);
1.267 + }
1.268 +
1.269 + TBuf<40> path;
1.270 + path.Append((TChar)gDriveToTest);
1.271 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.272 +
1.273 + TBuf<15> filename;
1.274 + filename.Append(_L("create.file"));
1.275 +
1.276 + TBuf<40> fullname;
1.277 + fullname.Append(path);
1.278 + fullname.Append(filename);
1.279 +
1.280 + r = notify1->AddNotification((TUint)TFsNotification::ECreate,path,filename);
1.281 + test(r==KErrNone);
1.282 + r = notify2->AddNotification((TUint)TFsNotification::ECreate,path,filename);
1.283 + test(r==KErrNone);
1.284 +
1.285 + delete notify1; //Delete notify1 and ensure we still get notification on notify2
1.286 +
1.287 + TRequestStatus status;
1.288 + r = notify2->RequestNotifications(status);
1.289 + test(r==KErrNone);
1.290 +
1.291 + RFile file;
1.292 + file.Replace(fs,fullname,EFileWrite); //Replace produces Create notification
1.293 + file.Close();
1.294 +
1.295 + RTimer tim;
1.296 + r = tim.CreateLocal();
1.297 + test(r==KErrNone);
1.298 +
1.299 + TRequestStatus timStatus;
1.300 + TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
1.301 + tim.After(timStatus,time);
1.302 +
1.303 + User::WaitForRequest(status,timStatus);
1.304 + test(status!=KRequestPending);
1.305 +
1.306 + r = fs.Delete(fullname);
1.307 + test(r==KErrNone);
1.308 +
1.309 + delete notify2;
1.310 + tim.Close();
1.311 + fs.Close();
1.312 + return KErrNone;
1.313 + }
1.314 +
1.315 +/*
1.316 + * This tests that u can set and receive notifications in the root
1.317 + * of a drive.
1.318 + *
1.319 + * (something which was apparently not possible on RFs::NotifyChange)
1.320 + */
1.321 +TInt TestRootDriveNotifications()
1.322 + {
1.323 + test.Next(_L("TestRootDriveNotifications"));
1.324 + RFs fs;
1.325 + fs.Connect();
1.326 +
1.327 + CFsNotify* notify = NULL;
1.328 +
1.329 + TRAPD(r,notify = CFsNotify::NewL(fs,KMinNotificationBufferSize););
1.330 + test(r==KErrNone);
1.331 + test(notify!=NULL);
1.332 +
1.333 + TBuf<40> path;
1.334 + path.Append((TChar)gDriveToTest);
1.335 + path.Append(_L(":\\"));
1.336 +
1.337 + TBuf<15> filename;
1.338 + filename.Append(_L("*"));
1.339 +
1.340 + r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
1.341 + test(r==KErrNone);
1.342 +
1.343 + TRequestStatus status;
1.344 + r = notify->RequestNotifications(status);
1.345 + test(r==KErrNone);
1.346 +
1.347 + RFile file;
1.348 + TBuf<40> filePath;
1.349 + filePath.Append((TChar)gDriveToTest);
1.350 + filePath.Append(_L(":\\file.root"));
1.351 + r = file.Replace(fs,filePath,EFileRead);
1.352 + test(r==KErrNone);
1.353 + file.Close();
1.354 +
1.355 + TRequestStatus s2;
1.356 + RTimer tim;
1.357 + test(tim.CreateLocal()==KErrNone);
1.358 + TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
1.359 + tim.After(s2,time);
1.360 + User::WaitForRequest(status,s2);
1.361 + test(status!=KRequestPending);
1.362 +
1.363 + delete notify;
1.364 + notify = NULL;
1.365 + tim.Close();
1.366 + fs.Close();
1.367 + return KErrNone;
1.368 + }
1.369 +
1.370 +/*
1.371 + * Creates and deletes loads of CFsNotify objects and makes sure they're all
1.372 + * cleaned up afterwards.
1.373 + */
1.374 +TInt TestNewDeleteCFsNotify(TInt aIterations)
1.375 + {
1.376 + RPointerArray<CFsNotify> array;
1.377 + TInt inArray = 0;
1.378 + TInt r = KErrNone;
1.379 + for(TInt i = 0; i < aIterations; i++)
1.380 + {
1.381 + CFsNotify* notify = NULL;
1.382 + TRAP(r,notify = CFsNotify::NewL(TheFs,500));
1.383 + if(r==KErrNone)
1.384 + {
1.385 + test(notify!=NULL);
1.386 + r = array.Append(notify);
1.387 + if(r==KErrNone)
1.388 + {
1.389 + inArray++;
1.390 + }
1.391 + else
1.392 + {
1.393 + delete notify;
1.394 + break;
1.395 + }
1.396 + }
1.397 + else
1.398 + {
1.399 + break;
1.400 + }
1.401 + }
1.402 +
1.403 + for(TInt j = inArray-1; j >= 0; j--)
1.404 + {
1.405 + CFsNotify* notify = (CFsNotify*)array[j];
1.406 + array.Remove(j);
1.407 + delete notify;
1.408 + }
1.409 +
1.410 + array.Reset();
1.411 + array.Close();
1.412 + return KErrNone;
1.413 + }
1.414 +
1.415 +
1.416 +/*
1.417 + * Creates a file
1.418 + * Used in SimpleTest1L(), TestTwoDoersL() TestTwoWatchersL(), TestCancelNotificationL()
1.419 + */
1.420 +TInt SimpleSingleNotificationTFDoer(TAny* aAny)
1.421 + {
1.422 + SThreadPackageDualSemaphore pkgDoer = *(SThreadPackageDualSemaphore*)aAny;
1.423 + RTest simpleTestDoer(_L("SimpleSingleNotificationTFDoer"));
1.424 + simpleTestDoer.Start(_L("SimpleSingleNotificationTFDoer"));
1.425 + TBuf<40> path;
1.426 + path.Append(gDriveToTest);
1.427 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.428 + path.Append(pkgDoer.iFileName);
1.429 +
1.430 + //Delete file so we definitely get a create notification
1.431 + RFs fs;
1.432 + TInt r = fs.Connect();
1.433 + safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.434 + r = fs.Delete(path);
1.435 + if(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound)
1.436 + r = KErrNone;
1.437 + safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.438 + r = fs.MkDirAll(path);
1.439 + if(r==KErrNone || r==KErrAlreadyExists)
1.440 + r = KErrNone;
1.441 + safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.442 +
1.443 + simpleTestDoer.Printf(_L("SimpleSingleNotificationTFDoer - Create File %S\n"),&path);
1.444 + //Create file
1.445 + RFile file;
1.446 + r = file.Create(fs,path,EFileWrite);
1.447 + safe_test(simpleTestDoer,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.448 + file.Close();
1.449 +
1.450 + fs.Close();
1.451 + simpleTestDoer.End();
1.452 + simpleTestDoer.Close();
1.453 + return KErrNone;
1.454 + }
1.455 +
1.456 +/*
1.457 + * Watches 1 file creation
1.458 + * Used in SimpleTest1L()
1.459 + */
1.460 +TInt SimpleSingleNotificationTFWatcher(TAny* aAny)
1.461 + {
1.462 + CTrapCleanup* cleanup;
1.463 + cleanup = CTrapCleanup::New();
1.464 + RThread thread;
1.465 + TUint64 threadId = thread.Id().Id();
1.466 +
1.467 + SThreadPackage pkgDoer = *(SThreadPackage*)aAny;
1.468 + RSemaphore& simpleBarrierTest = pkgDoer.iBarrier;
1.469 +
1.470 + RTest simpleTestWatcher(_L("SimpleSingleNotificationTFWatcher"));
1.471 + simpleTestWatcher.Start(_L("SimpleSingleNotificationTFWatcher"));
1.472 +
1.473 + RFs fs;
1.474 + fs.Connect();
1.475 +
1.476 + simpleTestWatcher.Printf(_L("SimpleSingleNotificationTFWatcher(%d) - Create CFsNotify\n"),threadId);
1.477 + CFsNotify* notify = NULL;
1.478 + TRAPD(r,notify = CFsNotify::NewL(fs,100); );
1.479 + safe_test(simpleTestWatcher,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.480 + TBuf<40> path;
1.481 + path.Append(gDriveToTest);
1.482 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
1.483 +
1.484 + TBuf<20> filename;
1.485 + filename.Append(pkgDoer.iFileName);
1.486 +
1.487 + TBuf<40> fullname;
1.488 + fullname.Append(path);
1.489 + fullname.Append(filename);
1.490 +
1.491 + simpleTestWatcher.Printf(_L("SimpleSingleNotificationTFWatcher - Add Notification for %S\n"),&path);
1.492 + r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
1.493 + safe_test(simpleTestWatcher,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.494 + TRequestStatus status;
1.495 + simpleTestWatcher.Printf(_L("SimpleSingleNotificationTFWatcher(%d) - Request Notifications\n"),threadId);
1.496 + r = notify->RequestNotifications(status);
1.497 + safe_test(simpleTestWatcher,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.498 +
1.499 + simpleBarrierTest.Signal();
1.500 +
1.501 + simpleTestWatcher.Printf(_L("SimpleSingleNotificationTFWatcher(%d) - Wait for status to return\n"),threadId);
1.502 + User::WaitForRequest(status);
1.503 +
1.504 + simpleTestWatcher.Printf(_L("(%d) NextNotification\n"),threadId);
1.505 + const TFsNotification* notification = notify->NextNotification();
1.506 + //Test notification is not null.
1.507 + //We should be getting 1 notification.
1.508 + if(notification == NULL)
1.509 + safe_test(simpleTestWatcher,KErrNotFound,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.510 +
1.511 + simpleTestWatcher.Printf(_L("(%d) - Notification Type\n"),threadId);
1.512 + TFsNotification::TFsNotificationType notificationType = ((TFsNotification*)notification)->NotificationType();
1.513 + if(notificationType != TFsNotification::ECreate)
1.514 + safe_test(simpleTestWatcher,KErrGeneral,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.515 + simpleTestWatcher.Printf(_L("(%d) - Notification Path\n"),threadId);
1.516 + TPtrC _pathC;
1.517 + ((TFsNotification*)notification)->Path(_pathC);
1.518 + simpleTestWatcher.Printf(_L("Notification Path = %S\n"),&_pathC);
1.519 + TBuf<40> _path;
1.520 + _path.Copy(_pathC);
1.521 + if(_path.Match(fullname)!=KErrNone)
1.522 + safe_test(simpleTestWatcher,KErrBadName,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.523 +
1.524 + /*
1.525 + TInt driveNumber = 0;
1.526 + TInt gDriveNum = -1;
1.527 + notification->DriveNumber(driveNumber);
1.528 + RFs::CharToDrive(_pathC[0],gDriveNum);
1.529 + if(driveNumber != gDriveNum)
1.530 + safe_test(simpleTestWatcher,KErrBadHandle,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.531 +
1.532 + TUid uid;
1.533 + TUint32 realUID = 0x76543210;
1.534 + r = notification->UID(uid);
1.535 + safe_test(simpleTestWatcher,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.536 + safe_test(simpleTestWatcher,(realUID == uid.iUid)==1,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.537 + */
1.538 + delete notify;
1.539 + fs.Close();
1.540 + simpleTestWatcher.End();
1.541 + simpleTestWatcher.Close();
1.542 + delete cleanup;
1.543 + return KErrNone;
1.544 + }
1.545 +
1.546 +/*
1.547 + * SimpleTest1L - Runs a simple Create test, gets 1 notification, calls type, path etc and exits
1.548 + * Two threads: 1 watcher, 1 doer
1.549 + */
1.550 +TInt SimpleCreateTestL()
1.551 + {
1.552 + test.Next(_L("SimpleTest"));
1.553 + RFs fs;
1.554 + fs.Connect();
1.555 + _LIT(KFileName,"simple.create");
1.556 + SThreadPackage pkgDoer;
1.557 + pkgDoer.iFileName = KFileName;
1.558 +
1.559 + SThreadPackage watcherPkg;
1.560 + watcherPkg.iFileName = KFileName;
1.561 + User::LeaveIfError(pkgDoer.iBarrier.CreateLocal(0));
1.562 + User::LeaveIfError(watcherPkg.iBarrier.CreateLocal(0));
1.563 + RThread watcher;
1.564 + RThread doer;
1.565 + watcher.Create(_L("Simple1WatcherThread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcherPkg);
1.566 + doer.Create(_L("Simple1DoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer);
1.567 + watcher.Resume();
1.568 + watcherPkg.iBarrier.Wait(); //Wait till Watcher has requested notification
1.569 + doer.Resume();
1.570 +
1.571 + TRequestStatus status;
1.572 + doer.Logon(status);
1.573 + User::WaitForRequest(status);
1.574 + test.Printf(_L("SimpleCreateTest - Doer Exit Reason = %d\n"),doer.ExitReason());
1.575 + safe_test(test,doer.ExitReason(),__LINE__,(TText*)Expand("t_notifier.cpp"));
1.576 +
1.577 + RDebug::Print(_L("Line %d"),__LINE__);
1.578 +
1.579 +
1.580 + watcher.Logon(status);
1.581 + RTimer timer1;
1.582 + TInt r = timer1.CreateLocal();
1.583 + safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.584 + TRequestStatus timeout;
1.585 + TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
1.586 + timer1.After(timeout,time);
1.587 + User::WaitForRequest(timeout,status);
1.588 + test(status.Int() != KRequestPending);
1.589 + timer1.Cancel();
1.590 + timer1.Close();
1.591 +
1.592 +
1.593 +// User::WaitForRequest(status);
1.594 + test.Printf(_L("SimpleCreateTest - Watcher Exit Reason = %d\n"),watcher.ExitReason());
1.595 + safe_test(test,watcher.ExitReason(),__LINE__,(TText*)Expand("t_notifier.cpp"));
1.596 +
1.597 + CLOSE_AND_WAIT(doer);
1.598 + CLOSE_AND_WAIT(watcher);
1.599 +
1.600 + pkgDoer.iBarrier.Close();
1.601 + watcherPkg.iBarrier.Close();
1.602 + fs.Close();
1.603 + return KErrNone;
1.604 + }
1.605 +
1.606 +// Doer thread for TestMultipleNotificationsL
1.607 +TInt MultipleNotificationTFDoer(TAny* aAny)
1.608 + {
1.609 + RDebug::Print(_L("MultipleNotificationTFDoer - Start, Line %d"), __LINE__);
1.610 + SThreadPackageMultiple pkgDoer = *(SThreadPackageMultiple*)aAny;
1.611 + RTest multipleTestDoer(_L("MultipleNotificationTFDoer"));
1.612 + multipleTestDoer.Start(_L("Multi-Doer"));
1.613 + multipleTestDoer.Printf(_L("MultipleNotificationTFDoer - Line %d"),__LINE__);
1.614 + TBuf<40> basepath;
1.615 + basepath.Append(gDriveToTest);
1.616 + basepath.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.617 +
1.618 + RThread thread;
1.619 + RDebug::Print(_L("MultipleNotificationTFDoer - Line %d"), __LINE__);
1.620 + TUint64 threadID = thread.Id().Id();
1.621 + RDebug::Print(_L("MultipleNotificationTFDoer - Line %d"), __LINE__);
1.622 +
1.623 + //Delete file so we definitely get a create notification
1.624 + RFs fs;
1.625 + TInt r = fs.Connect();
1.626 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.627 +
1.628 + TEntry entry;
1.629 + TBool wildcard = EFalse;
1.630 + TBuf<40> _path;
1.631 + _path.Append(basepath);
1.632 + _path.Append(pkgDoer.iFileName);
1.633 + _path.Append(pkgDoer.iString);
1.634 + r = fs.Entry(_path, entry);
1.635 + if (pkgDoer.iNotifyType != TFsNotification::EMediaChange &&
1.636 + pkgDoer.iNotifyType != TFsNotification::EDriveName &&
1.637 + pkgDoer.iNotifyType != TFsNotification::EVolumeName &&
1.638 + pkgDoer.iOperation != t_notification::EAllOps6)
1.639 + {
1.640 + if (r == KErrBadName)
1.641 + {
1.642 + wildcard = ETrue;
1.643 + }
1.644 + if(r != KErrNone && r != KErrPathNotFound && r != KErrNotFound && r != KErrBadName)
1.645 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.646 + if (r == KErrNone && !entry.IsDir() && pkgDoer.iOperation != t_notification::EFsDelete && !wildcard &&
1.647 + pkgDoer.iOperation != t_notification::EFsRmDir && pkgDoer.iOperation != t_notification::EFsRmDir_nonEmpty)
1.648 + {
1.649 + r = fs.Delete(_path);
1.650 + if(r != KErrNone && r != KErrPathNotFound && r != KErrNotFound)
1.651 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.652 + }
1.653 + r = fs.MkDirAll(basepath);
1.654 + if(r != KErrNone && r != KErrAlreadyExists)
1.655 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.656 + }
1.657 +
1.658 + multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
1.659 +
1.660 + switch(pkgDoer.iOperation)
1.661 + {
1.662 + case t_notification::EFileReplace:
1.663 + {
1.664 + RFile file;
1.665 + //Generate Notification
1.666 + multipleTestDoer.Printf(_L("File Replace - (%d)\n"),threadID);
1.667 + r = file.Replace(fs,_path,EFileWrite); //RFile::Replace -> TFsNotification::ECreate
1.668 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.669 + file.Close();
1.670 +
1.671 + r = fs.Delete(_path);
1.672 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.673 + break;
1.674 + }
1.675 + case t_notification::EFileCreate:
1.676 + case t_notification::EFileCreate_txt_nowatch:
1.677 + case t_notification::EFileCreate_txt:
1.678 + case t_notification::EAllOps1:
1.679 + {
1.680 + multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
1.681 + if(wildcard)
1.682 + {
1.683 + for (TInt i = 0; i < pkgDoer.iIterations; i++)
1.684 + {
1.685 + multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
1.686 + RFile file;
1.687 + TBuf<40> path;
1.688 + path.Append(basepath);
1.689 + path.AppendNum(i);
1.690 + if(pkgDoer.iOperation == t_notification::EFileCreate_txt)
1.691 + {
1.692 + //Create file with different extension (no notification)
1.693 + path.Append(_L(".wrg"));
1.694 + fs.Delete(path);
1.695 + multipleTestDoer.Printf(_L("File Create (wrong extension) - %S (%d)\n"),&path,threadID);
1.696 + r = file.Create(fs, path, EFileWrite);
1.697 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.698 + //Change path to contain file with correct extension (notification occurs)
1.699 + path.Replace(path.Length()-3,3,_L("txt"));
1.700 + }
1.701 + else if(pkgDoer.iOperation == t_notification::EFileCreate_txt_nowatch)
1.702 + {
1.703 + path.Append(_L(".txt"));
1.704 + }
1.705 + fs.Delete(path);
1.706 +
1.707 + multipleTestDoer.Printf(_L("File Create - %S (%d)\n"),&path,threadID);
1.708 + r = file.Create(fs, path, EFileWrite);
1.709 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.710 + file.Close();
1.711 + r = fs.Delete(path);
1.712 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.713 + }
1.714 + }
1.715 + else
1.716 + {
1.717 + multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
1.718 + for(TInt i = 0; i < pkgDoer.iIterations; i++)
1.719 + {
1.720 + multipleTestDoer.Printf(_L("MultipleNotificationTFDoer (%d) - Line %d"),threadID,__LINE__);
1.721 + RFile file;
1.722 + multipleTestDoer.Printf(_L("File Create - %S (%d)\n"),&_path,threadID);
1.723 + r = file.Create(fs,_path,EFileWrite);
1.724 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.725 + file.Close();
1.726 + r = fs.Delete(_path);
1.727 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.728 + }
1.729 + }
1.730 + break;
1.731 + }
1.732 + case t_notification::EFileCreate_subs:
1.733 + case t_notification::EFileCreate_subs_nowatch:
1.734 + {
1.735 + if (wildcard)
1.736 + {
1.737 + for (TInt i = 0; i < pkgDoer.iIterations; i++)
1.738 + {
1.739 + RFile file;
1.740 + TBuf<40> path;
1.741 + path.Append(basepath);
1.742 + path.Append(_L("SubDir\\"));
1.743 + r = fs.MkDirAll(path);
1.744 + if(r != KErrNone && r != KErrAlreadyExists)
1.745 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.746 + path.AppendNum(i);
1.747 + fs.Delete(path);
1.748 + multipleTestDoer.Printf(_L("File Create - %S (%d)\n"),&path,threadID);
1.749 + r = file.Create(fs, path, EFileWrite);
1.750 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.751 + file.Close();
1.752 + r = fs.Delete(path);
1.753 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.754 + }
1.755 + }
1.756 + break;
1.757 + }
1.758 + case t_notification::EFileWrite:
1.759 + case t_notification::EAllOps2:
1.760 + {
1.761 + //Works on single file
1.762 + RFile file;
1.763 + TBuf<40> path;
1.764 + path.Append(basepath);
1.765 + path.Append(pkgDoer.iFileName);
1.766 + path.Append(pkgDoer.iString);
1.767 + r = file.Replace(fs,path,EFileWrite);
1.768 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.769 + for(TInt i = 0; i < pkgDoer.iIterations; i++)
1.770 + {
1.771 + multipleTestDoer.Printf(_L("File Write - %S (%d)\n"),&path,threadID);
1.772 + r = file.Write(4*i,_L8("abcd"));
1.773 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.774 + //If cache is enabled, a notification is received only when the cache is flushed
1.775 + //We flush the file to make this a general test
1.776 + multipleTestDoer.Printf(_L("File Flush - (%d)\n"),threadID);
1.777 + r = file.Flush();
1.778 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.779 + }
1.780 + file.Close();
1.781 + r = fs.Delete(path);
1.782 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.783 + break;
1.784 + }
1.785 + case t_notification::EFileWrite_samesize:
1.786 + {
1.787 + RFile file;
1.788 + TBuf<40> path;
1.789 + path.Append(basepath);
1.790 + path.Append(pkgDoer.iFileName);
1.791 + path.Append(pkgDoer.iString);
1.792 + r = file.Replace(fs,path,EFileWrite);
1.793 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.794 + multipleTestDoer.Printf(_L("File Write - %S (%d)\n"),&path,threadID);
1.795 + r = file.Write(0,_L8("abcd"));
1.796 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.797 +
1.798 + //If cache is enabled, a notification is received only when the cache is flushed
1.799 + //We flush the file to make this a general test
1.800 + multipleTestDoer.Printf(_L("File Flush - (%d)\n"),threadID);
1.801 + r = file.Flush();
1.802 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.803 +
1.804 + for(TInt i = 0; i < pkgDoer.iIterations; i++)
1.805 + {
1.806 + TBuf<2> toWrite;
1.807 + toWrite.AppendNum(i);
1.808 + multipleTestDoer.Printf(_L("File Write - %S (%d)\n"),&path,threadID);
1.809 + r = file.Write(0,(TDesC8&)toWrite);
1.810 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.811 + multipleTestDoer.Printf(_L("File Flush - (%d)\n"),threadID);
1.812 + r = file.Flush();
1.813 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.814 + }
1.815 + file.Close();
1.816 + r = fs.Delete(path);
1.817 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.818 + break;
1.819 + }
1.820 + case t_notification::EFileWrite_async:
1.821 + {
1.822 + RFile file;
1.823 + TBuf<40> path;
1.824 + path.Append(basepath);
1.825 + path.Append(pkgDoer.iFileName);
1.826 + path.Append(pkgDoer.iString);
1.827 + r = file.Replace(fs,path,EFileWrite);
1.828 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.829 + for(TInt i = 0; i < pkgDoer.iIterations; i++)
1.830 + {
1.831 + TRequestStatus status;
1.832 + file.Write(52*i, _L8("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), status);
1.833 + User::WaitForRequest(status);
1.834 + multipleTestDoer.Printf(_L("File Write Async - %S (%d)\n"),&path,threadID);
1.835 + TInt fileSize;
1.836 + file.Size(fileSize);
1.837 + multipleTestDoer.Printf(_L("File Write Async - FileSize: %d\n"),fileSize);
1.838 + multipleTestDoer.Printf(_L("File Flush - (%d)\n"),threadID);
1.839 + r = file.Flush();
1.840 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.841 + }
1.842 + file.Close();
1.843 + r = fs.Delete(path);
1.844 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.845 + break;
1.846 + }
1.847 + case t_notification::EFileSetSize:
1.848 + case t_notification::EAllOps3:
1.849 + {
1.850 + //Works on single file
1.851 + RFile file;
1.852 + TBuf<40> path;
1.853 + path.Append(basepath);
1.854 + path.Append(pkgDoer.iFileName);
1.855 + path.Append(pkgDoer.iString);
1.856 + r = file.Replace(fs,path,EFileWrite);
1.857 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.858 +
1.859 + //Increase file size
1.860 + for(TInt i = 0; i < pkgDoer.iIterations; i++)
1.861 + {
1.862 + r = file.SetSize(4*(i+1));
1.863 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.864 + multipleTestDoer.Printf(_L("File Set Size - %d (%d)\n"),4*(i+1),threadID);
1.865 + }
1.866 +
1.867 + //Decrease file size
1.868 + for(TInt j = pkgDoer.iIterations - 2; j >= 0; j--)
1.869 + {
1.870 + r = file.SetSize(4*(j+1));
1.871 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.872 + multipleTestDoer.Printf(_L("File Set Size - %d (%d)\n"),4*(j+1),threadID);
1.873 + }
1.874 +
1.875 + file.Close();
1.876 + r = fs.Delete(path);
1.877 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.878 + break;
1.879 + }
1.880 + case t_notification::EFsReplace:
1.881 + {
1.882 + TBuf<45> path;
1.883 + path.Append(basepath);
1.884 + path.Append(pkgDoer.iFileName);
1.885 + path.Append(pkgDoer.iString);
1.886 + path.AppendNum(0);
1.887 +
1.888 + RFile tempFile;
1.889 + multipleTestDoer.Printf(_L("RFs Replace (Create temp file) - (%d)\n"),threadID);
1.890 + r = tempFile.Replace(fs,_path,EFileWrite);
1.891 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.892 + tempFile.Close();
1.893 +
1.894 + multipleTestDoer.Printf(_L("RFs Replace - (%d)\n"),threadID);
1.895 + r = fs.Replace(_path,path); //RFs::Replace -> TFsNotification::ERename
1.896 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.897 +
1.898 + r = fs.Delete(path);
1.899 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.900 + break;
1.901 + }
1.902 + case t_notification::EFsRename:
1.903 + {
1.904 + TBuf<45> path;
1.905 + path.Append(basepath);
1.906 + path.Append(pkgDoer.iFileName);
1.907 + path.Append(pkgDoer.iString);
1.908 + path.AppendNum(0);
1.909 +
1.910 + RFile file;
1.911 + r = file.Replace(fs,_path,EFileWrite);
1.912 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.913 + file.Close();
1.914 +
1.915 + multipleTestDoer.Printf(_L("RFs Rename - (%d)\n"),threadID);
1.916 + r = fs.Rename(_path,path);
1.917 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.918 +
1.919 + r = fs.Delete(path);
1.920 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.921 + break;
1.922 + }
1.923 + case t_notification::EFileRename:
1.924 + case t_notification::EFileRename_wild:
1.925 + case t_notification::EAllOps5:
1.926 + {
1.927 + TBuf<45> path;
1.928 + path.Append(basepath);
1.929 + if (!wildcard)
1.930 + {
1.931 + path.Append(pkgDoer.iFileName);
1.932 + path.Append(pkgDoer.iString);
1.933 + }
1.934 + path.AppendNum(0);
1.935 +
1.936 + //Delete new path to ensure it does not exist
1.937 + r = fs.Delete(path);
1.938 + if(r != KErrNone && r != KErrNotFound && r != KErrPathNotFound)
1.939 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.940 +
1.941 + if (wildcard)
1.942 + {
1.943 + _path.Delete(_path.Length()-1,1);
1.944 + _path.AppendNum(9);
1.945 + }
1.946 +
1.947 + RFile file;
1.948 + r = file.Replace(fs, _path, EFileWrite);
1.949 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.950 +
1.951 + if (wildcard)
1.952 + {
1.953 + for(TInt i = 1; i <= pkgDoer.iIterations; i++)
1.954 + {
1.955 + path.Delete(path.Length()-1,1);
1.956 + path.AppendNum(i);
1.957 + multipleTestDoer.Printf(_L("File Rename - %S (%d)\n"),&path,threadID);
1.958 + r = file.Rename(path);
1.959 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.960 + }
1.961 + }
1.962 + else
1.963 + {
1.964 + multipleTestDoer.Printf(_L("File Rename - (%d)\n"),threadID);
1.965 + r = file.Rename(path);
1.966 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.967 + }
1.968 +
1.969 + file.Close();
1.970 + r = fs.Delete(path);
1.971 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.972 + break;
1.973 + }
1.974 + case t_notification::EFsRename_dir:
1.975 + {
1.976 + r = fs.MkDirAll(_path);
1.977 + if(r != KErrNone && r != KErrAlreadyExists)
1.978 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.979 +
1.980 + TBuf<45> newPath;
1.981 + newPath.Copy(_path);
1.982 + newPath.Delete(newPath.Length()-1,1);
1.983 + newPath.AppendNum(0);
1.984 + newPath.Append(KPathDelimiter);
1.985 +
1.986 + //Delete new path to ensure it does not exist
1.987 + r = fs.RmDir(newPath);
1.988 + if(r != KErrNone && r != KErrNotFound && r != KErrPathNotFound)
1.989 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.990 +
1.991 + multipleTestDoer.Printf(_L("RFs Rename Dir - (%d)\n"),threadID);
1.992 + r = fs.Rename(_path,newPath);
1.993 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.994 + break;
1.995 + }
1.996 + case t_notification::EFsDelete:
1.997 + {
1.998 + if (wildcard)
1.999 + {
1.1000 + for(TInt i = 0; i < pkgDoer.iIterations; i++)
1.1001 + {
1.1002 + //Create/replace file
1.1003 + RFile file;
1.1004 + TBuf<40> path;
1.1005 + path.Append(basepath);
1.1006 + r = fs.MkDirAll(path);
1.1007 + if(r != KErrNone && r != KErrAlreadyExists)
1.1008 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1009 + path.AppendNum(i);
1.1010 + path.Append(_L(".txt"));
1.1011 + r = file.Replace(fs,path,EFileWrite);
1.1012 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1013 + file.Close();
1.1014 +
1.1015 + //Delete file
1.1016 + multipleTestDoer.Printf(_L("RFs Delete - %S (%d)\n"),&path,threadID);
1.1017 + r = fs.Delete(path);
1.1018 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1019 +
1.1020 + //Create file with a different extension which should not produce notifications
1.1021 + path.AppendNum(i);
1.1022 + r = file.Replace(fs,path,EFileWrite);
1.1023 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1024 + file.Close();
1.1025 +
1.1026 + //Delete that file
1.1027 + multipleTestDoer.Printf(_L("RFs Delete - %S (%d)\n"),&path,threadID);
1.1028 + r = fs.Delete(path);
1.1029 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1030 + }
1.1031 + }
1.1032 + else
1.1033 + {
1.1034 + RFile file;
1.1035 + r = file.Replace(fs,_path,EFileWrite); //Make sure file exists
1.1036 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1037 + file.Close();
1.1038 +
1.1039 + multipleTestDoer.Printf(_L("RFs Delete - (%d)\n"),threadID);
1.1040 + r = fs.Delete(_path);
1.1041 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1042 + }
1.1043 + break;
1.1044 + }
1.1045 + case t_notification::EFileSet:
1.1046 + {
1.1047 + RFile file;
1.1048 + r = file.Replace(fs,_path,EFileWrite);
1.1049 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1050 +
1.1051 + multipleTestDoer.Printf(_L("File Set - (%d)\n"),threadID);
1.1052 + r = file.Set(TTime(0),KEntryAttHidden,KEntryAttReadOnly);
1.1053 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1054 +
1.1055 + file.Close();
1.1056 + break;
1.1057 + }
1.1058 + case t_notification::EFileSetAtt:
1.1059 + case t_notification::EAllOps4:
1.1060 + {
1.1061 + RFile file;
1.1062 + r = file.Replace(fs,_path,EFileWrite);
1.1063 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1064 +
1.1065 + multipleTestDoer.Printf(_L("File SetAtt - (%d)\n"),threadID);
1.1066 + r = file.SetAtt(KEntryAttHidden,KEntryAttReadOnly);
1.1067 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1068 +
1.1069 + file.Close();
1.1070 + r = fs.Delete(_path);
1.1071 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1072 + break;
1.1073 + }
1.1074 + case t_notification::EFileSetAtt_subs:
1.1075 + {
1.1076 + if (wildcard)
1.1077 + {
1.1078 + TBuf<40> path;
1.1079 + path.Append(basepath);
1.1080 + path.Append(_L("SubDir\\"));
1.1081 + r = fs.MkDirAll(path);
1.1082 + if(r != KErrNone && r != KErrAlreadyExists)
1.1083 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1084 +
1.1085 + //Create/replace files and set their attributes
1.1086 + for(TInt i = 0; i < pkgDoer.iIterations; i++)
1.1087 + {
1.1088 + RFile file;
1.1089 + TBuf<40> dirPath;
1.1090 + dirPath.Append(path);
1.1091 + dirPath.AppendNum(i);
1.1092 + dirPath.Append(_L(".ext"));
1.1093 + r = file.Replace(fs, dirPath, EFileWrite);
1.1094 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1095 +
1.1096 + multipleTestDoer.Printf(_L("File SetAtt Subs - %d.ext - (%d)\n"),i,threadID);
1.1097 + r = file.SetAtt(KEntryAttHidden,KEntryAttReadOnly);
1.1098 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1099 +
1.1100 + file.Close();
1.1101 + r = fs.Delete(dirPath);
1.1102 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1103 + }
1.1104 + }
1.1105 + break;
1.1106 + }
1.1107 + case t_notification::EFsSetEntry:
1.1108 + {
1.1109 + RFile file;
1.1110 + r = file.Replace(fs,_path,EFileWrite);
1.1111 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1112 + file.Close();
1.1113 +
1.1114 + multipleTestDoer.Printf(_L("RFs SetEntry - (%d)\n"),threadID);
1.1115 + r = fs.SetEntry(_path,TTime(0),KEntryAttHidden,KEntryAttReadOnly);
1.1116 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1117 + break;
1.1118 + }
1.1119 + case t_notification::EDismount:
1.1120 + {
1.1121 + multipleTestDoer.Printf(_L("DismountFileSystem - (%d)\n"),threadID);
1.1122 + r = fs.DismountFileSystem(pkgDoer.iFileName,globalDriveNum);
1.1123 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1124 + break;
1.1125 + }
1.1126 + case t_notification::EMount:
1.1127 + {
1.1128 + multipleTestDoer.Printf(_L("MountFileSystem - (%d)\n"),threadID);
1.1129 + r = fs.MountFileSystem(pkgDoer.iFileName,globalDriveNum);
1.1130 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1131 + break;
1.1132 + }
1.1133 + case t_notification::EMountScan:
1.1134 + {
1.1135 + multipleTestDoer.Printf(_L("DismountFileSystem - (%d)\n"),threadID);
1.1136 + r = fs.DismountFileSystem(pkgDoer.iFileName,globalDriveNum);
1.1137 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1138 + TBool isMount;
1.1139 + multipleTestDoer.Printf(_L("MountFileSystemAndScan - (%d)\n"),threadID);
1.1140 + r = fs.MountFileSystemAndScan(pkgDoer.iFileName,globalDriveNum,isMount);
1.1141 + if(!isMount)
1.1142 + safe_test(multipleTestDoer,KErrGeneral,__LINE__,pkgDoer.iLineCall);
1.1143 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1144 + break;
1.1145 + }
1.1146 + case t_notification::EMountDismount:
1.1147 + {
1.1148 + for(TInt i = 0; i < pkgDoer.iIterations; i++)
1.1149 + {
1.1150 + multipleTestDoer.Printf(_L("DismountFileSystem - (%d)\n"),threadID);
1.1151 + r = fs.DismountFileSystem(pkgDoer.iFileName,globalDriveNum);
1.1152 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1153 +
1.1154 + multipleTestDoer.Printf(_L("MountFileSystem - (%d)\n"),threadID);
1.1155 + r = fs.MountFileSystem(pkgDoer.iFileName,globalDriveNum);
1.1156 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1157 + }
1.1158 + break;
1.1159 + }
1.1160 + case t_notification::EFormat:
1.1161 + {
1.1162 + RFormat format;
1.1163 + TInt count = -1;
1.1164 + TBuf<2> driveDes;
1.1165 + driveDes.Append(pkgDoer.iFileName);
1.1166 + driveDes.Append((TChar)':');
1.1167 + format.Open(fs,driveDes,EQuickFormat,count);
1.1168 + multipleTestDoer.Printf(_L("Format - (%d)\n"),threadID);
1.1169 + while(count != 0)
1.1170 + {
1.1171 + format.Next(count);
1.1172 + }
1.1173 + format.Close();
1.1174 +
1.1175 + break;
1.1176 + }
1.1177 + case t_notification::EMediaCardRemoval:
1.1178 + case t_notification::EMediaCardInsertion:
1.1179 + {
1.1180 + //These are MANUAL tests, they require the removal/insertion of the media card
1.1181 + //Instructions are given out in the watcher thread
1.1182 + break;
1.1183 + }
1.1184 + case t_notification::ESetDriveName:
1.1185 + {
1.1186 + for(TInt i = 0; i < pkgDoer.iIterations; i++)
1.1187 + {
1.1188 + multipleTestDoer.Printf(_L("SetDriveName - MyDrive\n"));
1.1189 + _LIT(KDriveName,"MyDrive");
1.1190 + r = fs.SetDriveName(globalDriveNum,KDriveName);
1.1191 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1192 +
1.1193 + multipleTestDoer.Printf(_L("SetDriveName - MyDrive2\n"));
1.1194 + _LIT(KDriveName2,"MyDrive2");
1.1195 + r = fs.SetDriveName(globalDriveNum,KDriveName2);
1.1196 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1197 + }
1.1198 + break;
1.1199 + }
1.1200 + case t_notification::ERawDiskWrite:
1.1201 + {
1.1202 + RRawDisk rawdisk;
1.1203 + TInt drive = 0;
1.1204 + TBuf<1> driveDes;
1.1205 + driveDes.Append(pkgDoer.iFileName);
1.1206 + RFs::CharToDrive(pkgDoer.iFileName[0],drive);
1.1207 + r = rawdisk.Open(fs,drive);
1.1208 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1209 +
1.1210 + //Read some data
1.1211 + TBuf8<10> readData;
1.1212 + r = rawdisk.Read(0,readData);
1.1213 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1214 +
1.1215 + //Write it back
1.1216 + TPtrC8 dataPtr(readData);
1.1217 + r = rawdisk.Write((TInt64)0,dataPtr);
1.1218 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1219 + rawdisk.Close();
1.1220 + break;
1.1221 + }
1.1222 + case t_notification::ESetVolumeLabel:
1.1223 + {
1.1224 + for(TInt i = 0; i < pkgDoer.iIterations; i++)
1.1225 + {
1.1226 + multipleTestDoer.Printf(_L("SetVolumeLabel - MyVolume\n"));
1.1227 + _LIT(KVolumeLabel,"MyVolume");
1.1228 + r = fs.SetVolumeLabel(KVolumeLabel,globalDriveNum);
1.1229 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1230 +
1.1231 + multipleTestDoer.Printf(_L("SetVolumeLabel - MyVolume2\n"));
1.1232 + _LIT(KVolumeLabel2,"MyVolume2");
1.1233 + r = fs.SetVolumeLabel(KVolumeLabel2,globalDriveNum);
1.1234 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1235 + }
1.1236 + break;
1.1237 + }
1.1238 + case t_notification::EFsRmDir:
1.1239 + {
1.1240 + r = fs.MkDirAll(_path); //Make sure directory exists
1.1241 + if(r != KErrNone && r != KErrAlreadyExists)
1.1242 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1243 + multipleTestDoer.Printf(_L("RFs RmDir - Remove directory\n"));
1.1244 + r = fs.RmDir(_path);
1.1245 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1246 + break;
1.1247 + }
1.1248 + case t_notification::EFsRmDir_wild:
1.1249 + {
1.1250 + if (wildcard)
1.1251 + {
1.1252 + TBuf<40> path;
1.1253 + path.Append(basepath);
1.1254 + path.Append(_L("SubDir\\"));
1.1255 + r = fs.MkDirAll(path);
1.1256 + if(r != KErrNone && r != KErrAlreadyExists)
1.1257 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1258 +
1.1259 + multipleTestDoer.Printf(_L("RFs RmDir - Remove directory\n"));
1.1260 + r = fs.RmDir(path);
1.1261 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1262 + break;
1.1263 + }
1.1264 + }
1.1265 + case t_notification::EFsRmDir_nonEmpty:
1.1266 + case t_notification::EFsMkDir:
1.1267 + {
1.1268 + TBuf<50> path;
1.1269 + path.Append(_path);
1.1270 + path.Append(pkgDoer.iFileName); //Append another sub-directory
1.1271 + multipleTestDoer.Printf(_L("RFs RmDir \n"));
1.1272 + r=fs.RmDir(path);
1.1273 + if(r != KErrNone && r != KErrPathNotFound && r != KErrNotFound)
1.1274 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1275 + r=fs.RmDir(_path);
1.1276 + if(r != KErrNone && r != KErrPathNotFound && r != KErrNotFound)
1.1277 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1278 +
1.1279 + multipleTestDoer.Printf(_L("RFs MkDir \n"));
1.1280 + r=fs.MkDir(path);
1.1281 + multipleTestDoer (r==KErrPathNotFound);
1.1282 + r=fs.MkDir(_path);
1.1283 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1284 + r=fs.MkDir(path);
1.1285 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1286 +
1.1287 + multipleTestDoer.Printf(_L("RFs RmDir nonEmpty - Full path: %S"),&_path);
1.1288 + r = fs.RmDir(_path);
1.1289 + if(r != KErrInUse)
1.1290 + safe_test(multipleTestDoer,KErrGeneral,__LINE__,pkgDoer.iLineCall);
1.1291 +
1.1292 + r = fs.RmDir(path);
1.1293 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1294 +
1.1295 + multipleTestDoer.Printf(_L("RFs EFsRmDir_nonEmpty - Full path: %S"),&_path);
1.1296 + r = fs.RmDir(_path);
1.1297 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1298 +
1.1299 + break;
1.1300 + }
1.1301 + case t_notification::EAllOps6:
1.1302 + {
1.1303 + //Set drive name to TestDrive
1.1304 + multipleTestDoer.Printf(_L("SetDriveName - TestDrive\n"));
1.1305 + _LIT(KDriveName,"TestDrive");
1.1306 + r = fs.SetDriveName(globalDriveNum,KDriveName);
1.1307 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1308 + //Set volume label to TestVolume
1.1309 + multipleTestDoer.Printf(_L("SetVolumeLabel - TestVolume\n"));
1.1310 + _LIT(KVolumeLabel,"TestVolume");
1.1311 + r = fs.SetVolumeLabel(KVolumeLabel,globalDriveNum);
1.1312 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1313 + break;
1.1314 + }
1.1315 + case t_notification::ECFileManMove:
1.1316 + {
1.1317 + CTrapCleanup* cleanup;
1.1318 + cleanup = CTrapCleanup::New();
1.1319 +
1.1320 + multipleTestDoer.Printf(_L("Doer - ECFileManMove_part1\n"));
1.1321 +
1.1322 + //Stage 1 - Create File & write some data
1.1323 + RFile file;
1.1324 + r = file.Replace(fs,_path,EFileWrite);
1.1325 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1326 + r = file.SetSize(4);
1.1327 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1328 + file.Close();
1.1329 +
1.1330 + CFileMan* cfman = NULL;
1.1331 + TRAP(r, cfman = CFileMan::NewL(fs);)
1.1332 + test(r == KErrNone);
1.1333 + test(cfman != NULL);
1.1334 + TBuf<40> unmonitored_path;
1.1335 + unmonitored_path.Append(gDriveToTest);
1.1336 + unmonitored_path.Append(_L(":\\F32-TST\\"));
1.1337 + unmonitored_path.Append(pkgDoer.iString);
1.1338 +
1.1339 + //Stage 2 - Move to unmonitored Dir
1.1340 + //Rename 1
1.1341 + r = cfman->Move(_path,unmonitored_path);
1.1342 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1343 +
1.1344 + //SetSize (size := 8)
1.1345 + RFile file2;
1.1346 + r = file2.Open(fs,unmonitored_path,EFileWrite);
1.1347 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1348 + r = file2.SetSize(8);
1.1349 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1350 + file2.Flush();
1.1351 + file2.Close();
1.1352 +
1.1353 + //Stage 3 - Move back to monitored Dir
1.1354 + //Rename 2
1.1355 + r = cfman->Move(unmonitored_path,_path);
1.1356 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1357 +
1.1358 + //Stage 4 - Delete
1.1359 + //Delete
1.1360 + r = cfman->Delete(_path);
1.1361 + safe_test(multipleTestDoer,r,__LINE__,pkgDoer.iLineCall);
1.1362 +
1.1363 + delete cleanup;
1.1364 + delete cfman;
1.1365 + break;
1.1366 + }
1.1367 + default:
1.1368 + {
1.1369 + break;
1.1370 + }
1.1371 + }
1.1372 +
1.1373 + fs.Close();
1.1374 + multipleTestDoer.End();
1.1375 + multipleTestDoer.Close();
1.1376 + return KErrNone;
1.1377 + }
1.1378 +
1.1379 +/*
1.1380 + * Test process Capabilites tries to set up filters on the
1.1381 + * the private folder for uid 01234567.
1.1382 + * This function returns the results to trying to add filters on the specified path.
1.1383 + *
1.1384 + * There are three MMP files:
1.1385 + * t_notifier_nocaps.mmp, t_notifier_allfiles.mmp, t_notifier_belongs.mmp
1.1386 + *
1.1387 + * t_notifier_nocaps.mmp -
1.1388 + * This process does not have any capabilites, so should not be allowed to set the filter.
1.1389 + * t_notifier_allfiles.mmp -
1.1390 + * This process has ALLFILES capability, so should
1.1391 + * t_notifier_belongs.mmp -
1.1392 + * This process is process with UID 01234567 so this should work too.
1.1393 + *
1.1394 + * See: f32test\server\t_notifier_caps.cpp
1.1395 + */
1.1396 +TInt TestProcessCapabilities(const TDesC& aProcessName)
1.1397 + {
1.1398 + RProcess process;
1.1399 + TUidType uid;
1.1400 + TPtrC command((TText*)&gDriveToTest,1);
1.1401 + TInt r = process.Create(aProcessName,command,uid);
1.1402 + test(r==KErrNone);
1.1403 + process.Resume();
1.1404 + TRequestStatus s1;
1.1405 + TRequestStatus s2;
1.1406 + RTimer tim;
1.1407 + r = tim.CreateLocal();
1.1408 + test(r==KErrNone);
1.1409 + TTimeIntervalMicroSeconds32 delay = 5000000; //5 seconds
1.1410 + tim.After(s1,delay);
1.1411 + process.Logon(s2);
1.1412 + User::WaitForRequest(s1,s2);
1.1413 + test(s2.Int()!=KRequestPending);
1.1414 + r = process.ExitReason();
1.1415 + process.Close();
1.1416 + return r;
1.1417 + }
1.1418 +
1.1419 +/*
1.1420 + * Creates a file and writes to it twice.
1.1421 + * Used in TestTwoNotificationsL().
1.1422 + */
1.1423 +TInt TwoNotificationsTFDoer(TAny* aAny)
1.1424 + {
1.1425 + RTest testDoer(_L("TestTwoNotificationsThreadFunctionDoer"));
1.1426 + testDoer.Start(_L("TestTwoNotificationsThreadFunctionDoer"));
1.1427 +
1.1428 + SThreadPackageMultiple package = *(SThreadPackageMultiple*)aAny;
1.1429 + TBuf<40> path;
1.1430 + path.Append(gDriveToTest);
1.1431 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
1.1432 + path.Append(package.iFileName);
1.1433 +
1.1434 + //Delete file so we definitely get a create notification
1.1435 + RFs fs;
1.1436 + TInt r = fs.Connect();
1.1437 + testDoer(r==KErrNone);
1.1438 + r = fs.Delete(path);
1.1439 + testDoer(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound);
1.1440 + r = fs.MkDirAll(path);
1.1441 + testDoer(r==KErrNone || r==KErrAlreadyExists);
1.1442 +
1.1443 + testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Create File %S\n"),&path);
1.1444 + //Create file
1.1445 + RFile file;
1.1446 + r = file.Create(fs,path,EFileWrite);
1.1447 + testDoer(r == KErrNone);
1.1448 +
1.1449 + testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Size File 1 %S\n"),&path);
1.1450 + TInt fileSize = 0;
1.1451 + r = file.Size(fileSize);
1.1452 + testDoer(r == KErrNone);
1.1453 + testDoer(fileSize==0);
1.1454 +
1.1455 + testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Write File 1 %S\n"),&path);
1.1456 + r = file.Write(_L8("1234"));
1.1457 + testDoer(r == KErrNone);
1.1458 + testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Size File 2 %S\n"),&path);
1.1459 + r = file.Size(fileSize);
1.1460 + testDoer(r == KErrNone);
1.1461 + test(fileSize==4);
1.1462 +
1.1463 + testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Write File 2 %S\n"),&path);
1.1464 + r = file.Write(_L8("5678"));
1.1465 + testDoer(r == KErrNone);
1.1466 + testDoer.Printf(_L("TestTwoNotificationsThreadFunctionDoer - Size File 3 %S\n"),&path);
1.1467 + r = file.Size(fileSize);
1.1468 + testDoer(r == KErrNone);
1.1469 + test(fileSize==8);
1.1470 +
1.1471 + file.Close();
1.1472 +
1.1473 + fs.Close();
1.1474 + testDoer.End();
1.1475 + testDoer.Close();
1.1476 + return KErrNone;
1.1477 + }
1.1478 +
1.1479 + /*
1.1480 + * The following enum are for the CFileMan test
1.1481 + */
1.1482 + enum TCFsManEnum
1.1483 + {
1.1484 + ECFManCreate1 = 0x01,
1.1485 + ECFManWrite1 = 0x02,
1.1486 + ECFManDelete1 = 0x04,
1.1487 + ECFManCreate2 = 0x08,
1.1488 + ECFManSetSize1 = 0x10,
1.1489 + ECFManWrite2 = 0x20,
1.1490 + ECFManAtt1 = 0x40,
1.1491 + ECFManDelete2 = 0x80,
1.1492 + //Either a create, copy, delete (above - not supported in test)
1.1493 + //or rename operation (below)
1.1494 + ECFManRename1 = 0x100,
1.1495 + ECFManRename2 = 0x200
1.1496 + };
1.1497 +
1.1498 +/*
1.1499 + * Used by MultipleNotificationsTFWatcher() to test the notifications.
1.1500 + */
1.1501 +void HandleMultipleNotifications(RTest& aTest, SThreadPackageMultiple& aPackage, CFsNotify* notify, TDesC& aFullname)
1.1502 + {
1.1503 + RThread thread;
1.1504 + TUint64 threadID = thread.Id().Id();
1.1505 + TInt numNotifications = 0;
1.1506 + TInt64 fileSize = 0;
1.1507 + TBool overflow = EFalse;
1.1508 +
1.1509 + TInt scratch = 0;
1.1510 +
1.1511 + for(TInt i = 0; i < aPackage.iMaxNotifications; ) //Outer-loop to control when we should exit
1.1512 + {
1.1513 + aTest.Printf(_L("(%d) - NextNotification\n"),threadID);
1.1514 + const TFsNotification* notification = notify->NextNotification();
1.1515 + while(notification != NULL)
1.1516 + {
1.1517 + numNotifications++;
1.1518 + aTest.Printf(_L("NumNotifications = %d\n"),numNotifications);
1.1519 + //Test notification is not null.
1.1520 + //We should be getting 1 notification.
1.1521 + aTest(notification != NULL);
1.1522 +
1.1523 + aTest.Printf(_L("(%d) - Notification Type\n"),threadID);
1.1524 + TFsNotification::TFsNotificationType notificationType = notification->NotificationType();
1.1525 + aTest(notificationType & aPackage.iNotifyType ||
1.1526 + notificationType & TFsNotification::EOverflow);
1.1527 +
1.1528 + aTest.Printf(_L("Notification Type = %u - (%d)\n"),notificationType,threadID);
1.1529 +
1.1530 + if(notificationType != TFsNotification::EOverflow)
1.1531 + {
1.1532 + aTest.Printf(_L("(%d) - Notification Path\n"),threadID);
1.1533 + TPtrC _pathC;
1.1534 + ((TFsNotification*) notification)->Path(_pathC);
1.1535 + aTest.Printf(_L("%S - (%d)\n"),&_pathC,threadID);
1.1536 +
1.1537 + if(aPackage.iOperation == t_notification::ECFileManMove
1.1538 + && (scratch == (ECFManWrite1 | ECFManCreate1)))
1.1539 + {
1.1540 + TChar drive = gDriveToTest;
1.1541 + TBuf<40> unmodified_path;
1.1542 + unmodified_path.Append(drive);
1.1543 + unmodified_path.Append(_L(":\\F32-TST\\"));
1.1544 + unmodified_path.Append(_L("cf1le.man"));
1.1545 + ((TFsNotification*) notification)->NewName(_pathC);
1.1546 + TInt matches = _pathC.Match(unmodified_path);
1.1547 + safe_test(aTest,matches,__LINE__,aPackage.iLineCall);
1.1548 + }
1.1549 + else if((scratch == (ECFManWrite1 | ECFManCreate1 | ECFManRename1)))
1.1550 + {
1.1551 + ((TFsNotification*) notification)->NewName(_pathC);
1.1552 + safe_test(aTest,_pathC.Match(aFullname),__LINE__,aPackage.iLineCall);
1.1553 + }
1.1554 + else
1.1555 + {
1.1556 + safe_test(aTest,_pathC.Match(aFullname),__LINE__,aPackage.iLineCall);
1.1557 + }
1.1558 + }
1.1559 + else
1.1560 + {
1.1561 + aTest.Printf(_L("(%d) - OVERFLOW\n"),threadID);
1.1562 + //Overflow
1.1563 + overflow = ETrue;
1.1564 + return;
1.1565 + }
1.1566 +
1.1567 + //notificationType will only be of 1 type
1.1568 + if(notificationType == TFsNotification::EFileChange)
1.1569 + {
1.1570 + if(!(((aPackage.iNotifyType & TFsNotification::EFileChange) == TFsNotification::EFileChange) &&
1.1571 + (aPackage.iOperation == t_notification::EFileWrite ||
1.1572 + aPackage.iOperation == t_notification::EFileWrite_async ||
1.1573 + aPackage.iOperation == t_notification::EFileWrite_samesize ||
1.1574 + aPackage.iOperation == t_notification::EFileSetSize ||
1.1575 + aPackage.iOperation == t_notification::ECFileManMove ||
1.1576 + aPackage.iOperation == t_notification::EAllOps2 ||
1.1577 + aPackage.iOperation == t_notification::EAllOps3)))
1.1578 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1579 +
1.1580 + if (aPackage.iOperation == t_notification::ECFileManMove)
1.1581 + {
1.1582 + ((TFsNotification*) notification)->FileSize(fileSize);
1.1583 + //File just been created and written to.
1.1584 + if(fileSize == 4)
1.1585 + {
1.1586 + scratch |= ECFManWrite1;
1.1587 + }
1.1588 + else if(fileSize == 8)
1.1589 + {
1.1590 + scratch |= ECFManWrite2;
1.1591 + }
1.1592 + }
1.1593 + else if (aPackage.iNotifyType == TFsNotification::EFileChange)
1.1594 + {
1.1595 + ((TFsNotification*) notification)->FileSize(fileSize);
1.1596 + aTest.Printf(_L("Filesize - %d (%d)\n"),fileSize,threadID);
1.1597 + //A notification is received every time the size is changed
1.1598 + //due to the flushing
1.1599 + if (aPackage.iOperation == t_notification::EFileWrite_async)
1.1600 + {
1.1601 + //We write 52 letters
1.1602 + if(fileSize != 52*(i+1))
1.1603 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1604 + }
1.1605 + else if (aPackage.iOperation == t_notification::EFileWrite_samesize)
1.1606 + {
1.1607 + //Only 4 letters in file
1.1608 + if(fileSize != 4)
1.1609 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1610 + }
1.1611 + else if (i < aPackage.iIterations)
1.1612 + {
1.1613 + //We write/increase size by 4 letters/bytes
1.1614 + if(fileSize != 4*(i+1))
1.1615 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1616 + }
1.1617 + else
1.1618 + {
1.1619 + //We decrease size by 4 bytes
1.1620 + if(fileSize != 4*(aPackage.iMaxNotifications-i))
1.1621 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1622 + }
1.1623 + }
1.1624 + }
1.1625 + else if(notificationType == TFsNotification::ECreate)
1.1626 + {
1.1627 + if(!(((aPackage.iNotifyType & TFsNotification::ECreate) == TFsNotification::ECreate) &&
1.1628 + (aPackage.iOperation == t_notification::EFileCreate ||
1.1629 + aPackage.iOperation == t_notification::EFileReplace ||
1.1630 + aPackage.iOperation == t_notification::EFileCreate_subs ||
1.1631 + aPackage.iOperation == t_notification::EFileCreate_subs_nowatch ||
1.1632 + aPackage.iOperation == t_notification::EFileCreate_txt_nowatch ||
1.1633 + aPackage.iOperation == t_notification::EFileCreate_txt ||
1.1634 + aPackage.iOperation == t_notification::EFsMkDir ||
1.1635 + aPackage.iOperation == t_notification::ECFileManMove ||
1.1636 + aPackage.iOperation == t_notification::EAllOps1 ||
1.1637 + aPackage.iOperation == t_notification::EAllOps2 ||
1.1638 + aPackage.iOperation == t_notification::EAllOps3 ||
1.1639 + aPackage.iOperation == t_notification::EAllOps4 ||
1.1640 + aPackage.iOperation == t_notification::EAllOps5)))
1.1641 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1642 + if (aPackage.iOperation == t_notification::EFileCreate_txt)
1.1643 + {
1.1644 + //Check filename is of correct extension
1.1645 + TPtrC _path;
1.1646 + ((TFsNotification*) notification)->Path(_path);
1.1647 + TBuf<5> _ext;
1.1648 + _ext.Append(_L(".txt"));
1.1649 + TBuf<5> ext;
1.1650 + ext.Append(_path.Right(4));
1.1651 + safe_test(aTest,ext.Match(_ext),__LINE__,aPackage.iLineCall);
1.1652 + }
1.1653 + else if (aPackage.iOperation == t_notification::ECFileManMove)
1.1654 + {
1.1655 + if(scratch & ECFManCreate1)
1.1656 + {
1.1657 + scratch |= ECFManCreate2; //File created second time
1.1658 + }
1.1659 + else
1.1660 + {
1.1661 + scratch |= ECFManCreate1; //File created first time
1.1662 + }
1.1663 + }
1.1664 + }
1.1665 + else if(notificationType == TFsNotification::EDelete)
1.1666 + {
1.1667 + if(!(((aPackage.iNotifyType & TFsNotification::EDelete) == TFsNotification::EDelete) &&
1.1668 + (aPackage.iOperation == t_notification::EFsDelete ||
1.1669 + aPackage.iOperation == t_notification::EFsRmDir ||
1.1670 + aPackage.iOperation == t_notification::EFsRmDir_nonEmpty ||
1.1671 + aPackage.iOperation == t_notification::EFsRmDir_wild ||
1.1672 + aPackage.iOperation == t_notification::ECFileManMove ||
1.1673 + aPackage.iOperation == t_notification::EAllOps1 ||
1.1674 + aPackage.iOperation == t_notification::EAllOps2 ||
1.1675 + aPackage.iOperation == t_notification::EAllOps3 ||
1.1676 + aPackage.iOperation == t_notification::EAllOps4)))
1.1677 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1678 +
1.1679 + if(aPackage.iOperation == t_notification::ECFileManMove)
1.1680 + {
1.1681 + if(scratch & ECFManDelete1)
1.1682 + {
1.1683 + scratch |= ECFManDelete2;
1.1684 + }
1.1685 + else
1.1686 + {
1.1687 + scratch |= ECFManDelete1;
1.1688 + }
1.1689 + }
1.1690 + }
1.1691 + else if(notificationType == TFsNotification::ERename)
1.1692 + {
1.1693 + if(!(((aPackage.iNotifyType & TFsNotification::ERename) == TFsNotification::ERename) &&
1.1694 + (aPackage.iOperation == t_notification::EFileRename ||
1.1695 + aPackage.iOperation == t_notification::EFileRename_wild ||
1.1696 + aPackage.iOperation == t_notification::EFsReplace ||
1.1697 + aPackage.iOperation == t_notification::ECFileManMove ||
1.1698 + aPackage.iOperation == t_notification::EFsRename ||
1.1699 + aPackage.iOperation == t_notification::EFsRename_dir ||
1.1700 + aPackage.iOperation == t_notification::EAllOps5)))
1.1701 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1702 + TPtrC newnameC;
1.1703 + ((TFsNotification*)notification)->NewName(newnameC);
1.1704 + aTest.Printf(_L("%S - (%d)\n"),&newnameC,threadID);
1.1705 +
1.1706 + TPtrC _pathC;
1.1707 + ((TFsNotification*) notification)->Path(_pathC);
1.1708 +
1.1709 + TBuf<40> _path;
1.1710 + _path.Copy(_pathC);
1.1711 +
1.1712 + if (aPackage.iOperation == t_notification::EFsRename_dir)
1.1713 + {
1.1714 + _path.Delete(_path.Length()-1,1);
1.1715 + _path.AppendNum(0);
1.1716 + _path.Append(KPathDelimiter);
1.1717 + }
1.1718 + else if (aPackage.iOperation == t_notification::EFileRename_wild)
1.1719 + {
1.1720 + _path.Delete(_path.Length()-1,1);
1.1721 + _path.AppendNum(numNotifications);
1.1722 + }
1.1723 + else
1.1724 + {
1.1725 + _path.AppendNum(0);
1.1726 + }
1.1727 +
1.1728 + if(aPackage.iOperation != t_notification::ECFileManMove)
1.1729 + {
1.1730 + safe_test(aTest,newnameC.Match(_path),__LINE__,aPackage.iLineCall);
1.1731 + }
1.1732 + else if(scratch & ECFManRename1)
1.1733 + {
1.1734 + scratch |= ECFManRename2;
1.1735 + }
1.1736 + else
1.1737 + {
1.1738 + scratch |= ECFManRename1;
1.1739 + }
1.1740 +
1.1741 + }
1.1742 + else if(notificationType == TFsNotification::EAttribute)
1.1743 + {
1.1744 + if(!(((aPackage.iNotifyType & TFsNotification::EAttribute) == TFsNotification::EAttribute) &&
1.1745 + (aPackage.iOperation == t_notification::EFsSetEntry ||
1.1746 + aPackage.iOperation == t_notification::EFileSet ||
1.1747 + aPackage.iOperation == t_notification::EFileSetAtt ||
1.1748 + aPackage.iOperation == t_notification::EFileSetAtt_subs ||
1.1749 + aPackage.iOperation == t_notification::ECFileManMove ||
1.1750 + aPackage.iOperation == t_notification::EAllOps4)))
1.1751 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1752 + TUint setAtt = 0;
1.1753 + TUint clearAtt = 0;
1.1754 + ((TFsNotification*) notification)->Attributes(setAtt, clearAtt);
1.1755 +
1.1756 + if(aPackage.iOperation == t_notification::ECFileManMove)
1.1757 + {
1.1758 + scratch |= ECFManAtt1;
1.1759 + }
1.1760 + else
1.1761 + {
1.1762 + if(setAtt != KEntryAttHidden)
1.1763 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1764 + if(clearAtt != KEntryAttReadOnly)
1.1765 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1766 + }
1.1767 + }
1.1768 + else if(notificationType == TFsNotification::EMediaChange)
1.1769 + {
1.1770 + if(!(((aPackage.iNotifyType & TFsNotification::EMediaChange) == TFsNotification::EMediaChange) &&
1.1771 + (aPackage.iOperation == t_notification::EMount ||
1.1772 + aPackage.iOperation == t_notification::EMountScan ||
1.1773 + aPackage.iOperation == t_notification::EDismount ||
1.1774 + aPackage.iOperation == t_notification::EMountDismount ||
1.1775 + aPackage.iOperation == t_notification::EMediaCardInsertion ||
1.1776 + aPackage.iOperation == t_notification::EMediaCardRemoval ||
1.1777 + aPackage.iOperation == t_notification::EFormat ||
1.1778 + aPackage.iOperation == t_notification::ECFileManMove ||
1.1779 + aPackage.iOperation == t_notification::ERawDiskWrite)))
1.1780 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1781 + }
1.1782 + else if(notificationType == TFsNotification::EDriveName)
1.1783 + {
1.1784 + if(!(((aPackage.iNotifyType & TFsNotification::EDriveName) == TFsNotification::EDriveName) &&
1.1785 + (aPackage.iOperation == t_notification::ESetDriveName ||
1.1786 + aPackage.iOperation == t_notification::EAllOps6)))
1.1787 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1788 + }
1.1789 + else if(notificationType == TFsNotification::EVolumeName)
1.1790 + {
1.1791 + if(!(((aPackage.iNotifyType & TFsNotification::EVolumeName) == TFsNotification::EVolumeName) &&
1.1792 + (aPackage.iOperation == t_notification::ESetVolumeLabel ||
1.1793 + aPackage.iOperation == t_notification::EAllOps6)))
1.1794 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1795 +
1.1796 + TPtrC newnameC;
1.1797 + ((TFsNotification*)notification)->NewName(newnameC);
1.1798 + aTest.Printf(_L("New volume name: %S - (%d)\n"),&newnameC,threadID);
1.1799 + }
1.1800 +
1.1801 + i++;
1.1802 + notification = notify->NextNotification();
1.1803 + if (notification == NULL)
1.1804 + aTest.Printf(_L("Notification is NULL - (%d)\n"),threadID);
1.1805 + }
1.1806 +
1.1807 + if(i==1) //First iteration will only ever get 1 notification
1.1808 + {
1.1809 + if(numNotifications != 1)
1.1810 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1811 + }
1.1812 +
1.1813 + if(numNotifications < aPackage.iMaxNotifications && !overflow) //Ensure we get all of the notifications we expected
1.1814 + {
1.1815 + TRequestStatus status;
1.1816 + notify->RequestNotifications(status);
1.1817 + User::WaitForRequest(status);
1.1818 + }
1.1819 + }
1.1820 +
1.1821 + //0x307 = create1 | write1 | delete1 | rename1 | rename2
1.1822 + if(aPackage.iOperation == t_notification::ECFileManMove && (scratch != 0x307))
1.1823 + {
1.1824 + aTest.Printf(_L("CFileManMove test failure - scratch = 0x%x"),scratch);
1.1825 + safe_test(aTest,KErrGeneral,__LINE__,aPackage.iLineCall);
1.1826 + }
1.1827 +
1.1828 + }
1.1829 +
1.1830 +/*
1.1831 + * Watches for changes in files/directories.
1.1832 + * Used in TestMultipleNotificationsL().
1.1833 + */
1.1834 +TInt MultipleNotificationsTFWatcher(TAny* aAny)
1.1835 + {
1.1836 + CTrapCleanup* cleanup;
1.1837 + cleanup = CTrapCleanup::New();
1.1838 +
1.1839 + RThread thread;
1.1840 + TUint64 threadID = thread.Id().Id();
1.1841 +
1.1842 + SThreadPackageMultiple package = *(SThreadPackageMultiple*) aAny;
1.1843 + RTest multipleWatcherTest(_L("MultipleNotificationsTFWatcher"));
1.1844 + multipleWatcherTest.Start(_L("MultipleNotificationsTFWatcher"));
1.1845 +
1.1846 + RFs fs;
1.1847 + fs.Connect();
1.1848 +
1.1849 + multipleWatcherTest.Printf(_L("MultipleNotificationsTFWatcher (%d) - Create CFsNotify\n"),threadID);
1.1850 + CFsNotify* notify = NULL;
1.1851 + TRAPD(r,notify = CFsNotify::NewL(fs,package.iBufferSize));
1.1852 + safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall);
1.1853 + TBuf<40> path;
1.1854 + TBuf<20> filename;
1.1855 + if(package.iNotifyType != TFsNotification::EMediaChange &&
1.1856 + package.iNotifyType != TFsNotification::EDriveName &&
1.1857 + package.iNotifyType != TFsNotification::EVolumeName &&
1.1858 + package.iOperation != t_notification::EAllOps6)
1.1859 + {
1.1860 + path.Append(gDriveToTest);
1.1861 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
1.1862 + path.Append(package.iFileName);
1.1863 + filename.Append(package.iString);
1.1864 + }
1.1865 + else
1.1866 + {
1.1867 + path.Append((TChar)globalDriveNum+(TChar)'A');
1.1868 + path.Append(_L(":"));
1.1869 + }
1.1870 + TBuf<40> fullname;
1.1871 + fullname.Append(path);
1.1872 + fullname.Append(filename);
1.1873 +
1.1874 + if (package.iNotifyType == TFsNotification::EVolumeName ||
1.1875 + package.iOperation == t_notification::EAllOps6)
1.1876 + {
1.1877 + //Ensure volume has no label
1.1878 + multipleWatcherTest.Printf(_L("Set volume label to nothing\n"));
1.1879 + r = fs.SetVolumeLabel(_L(""),globalDriveNum);
1.1880 + safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall);
1.1881 + }
1.1882 +
1.1883 + if (package.iNotifyType == TFsNotification::EDriveName ||
1.1884 + package.iOperation == t_notification::EAllOps6)
1.1885 + {
1.1886 + //Ensure drive has no name
1.1887 + multipleWatcherTest.Printf(_L("Set drive name to nothing\n"));
1.1888 + r = fs.SetDriveName(globalDriveNum,_L(""));
1.1889 + safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall);
1.1890 + }
1.1891 +
1.1892 + multipleWatcherTest.Printf(_L("MultipleNotificationsTFWatcher - Add Notification for path %S\n"),&path);
1.1893 + multipleWatcherTest.Printf(_L("Add Notification for type %u - (%d)\n"),(TUint)package.iNotifyType,threadID);
1.1894 + r = notify->AddNotification((TUint)package.iNotifyType,path,filename);
1.1895 + safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall);
1.1896 +
1.1897 + TRequestStatus status;
1.1898 + multipleWatcherTest.Printf(_L("(%d) - Request Notifications\n"),threadID);
1.1899 + r = notify->RequestNotifications(status);
1.1900 + safe_test(multipleWatcherTest,r,__LINE__,package.iLineCall);
1.1901 +
1.1902 + if (package.iOperation == t_notification::EMediaCardRemoval)
1.1903 + {
1.1904 + multipleWatcherTest.Printf(_L("*****************************************************************\n"));
1.1905 + multipleWatcherTest.Printf(_L("Waiting 10 seconds.\n"));
1.1906 + multipleWatcherTest.Printf(_L("This is a MANUAL test, it requires the removal of the media card.\n"));
1.1907 + multipleWatcherTest.Printf(_L("PLEASE REMOVE THE MEDIA CARD. (DriveNumber %d)\n"),globalDriveNum);
1.1908 + multipleWatcherTest.Printf(_L("Or press Ctrl + F5 on the emulator.\n"));
1.1909 + multipleWatcherTest.Printf(_L("*****************************************************************\n"));
1.1910 + }
1.1911 + if (package.iOperation == t_notification::EMediaCardInsertion)
1.1912 + {
1.1913 + multipleWatcherTest.Printf(_L("*******************************************************************\n"));
1.1914 + multipleWatcherTest.Printf(_L("Waiting 10 seconds.\n"));
1.1915 + multipleWatcherTest.Printf(_L("This is a MANUAL test, it requires the insertion of the media card.\n"));
1.1916 + multipleWatcherTest.Printf(_L("PLEASE INSERT THE MEDIA CARD. (DriveNumber %d)\n"),globalDriveNum);
1.1917 + multipleWatcherTest.Printf(_L("*******************************************************************\n"));
1.1918 + }
1.1919 +
1.1920 + multipleWatcherTest.Printf(_L("(%d) - Signal Test thread to start Doer thread\n"),threadID);
1.1921 + package.iBarrier.Signal();
1.1922 + User::WaitForRequest(status);
1.1923 +
1.1924 + multipleWatcherTest.Printf(_L("(%d) - MultipleNotificationsTFWatcher Line %d\n"),threadID,__LINE__);
1.1925 +
1.1926 + //Handles the notifications
1.1927 + HandleMultipleNotifications(multipleWatcherTest, package, notify, (TDesC&)fullname);
1.1928 +
1.1929 + multipleWatcherTest.Printf(_L("(%d) - MultipleNotificationsTFWatcher Line %d\n"),threadID,__LINE__);
1.1930 +
1.1931 + delete notify;
1.1932 + fs.Close();
1.1933 + multipleWatcherTest.End();
1.1934 + multipleWatcherTest.Close();
1.1935 + delete cleanup;
1.1936 + return KErrNone;
1.1937 + }
1.1938 +
1.1939 +/*
1.1940 + * TestTwoNotificationsL - Tests File Write, 1 Doer writes to a file twice.
1.1941 + * 1 Watcher watches for file write changes. Just so happens that the second one overflows.
1.1942 + */
1.1943 +TInt TestTwoNotificationsL()
1.1944 + {
1.1945 + test.Next(_L("TestTwoNotifications"));
1.1946 +
1.1947 + RFs fs;
1.1948 + fs.Connect();
1.1949 + RSemaphore twoNotificationsDoerBar;
1.1950 + SThreadPackageMultiple package;
1.1951 + _LIT(KFileName,"file0.write");
1.1952 + package.iIterations = 10;
1.1953 + package.iOperation = t_notification::EFileWrite;
1.1954 + package.iNotifyType = TFsNotification::EFileChange;
1.1955 + package.iFileName = KFileName;
1.1956 + package.iBufferSize = 100; //Should get changed to KMin... in CFsNotify::NewL
1.1957 +
1.1958 + User::LeaveIfError(twoNotificationsDoerBar.CreateLocal(0));
1.1959 + User::LeaveIfError(package.iBarrier.CreateLocal(0));
1.1960 + RThread watcher;
1.1961 + RThread doer;
1.1962 +
1.1963 + TInt r = watcher.Create(_L("TestTwoNotificationsWatcherThread"),MultipleNotificationsTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
1.1964 + test(r==KErrNone);
1.1965 + r = doer.Create(_L("TestTwoNotificationsDoerThread"),TwoNotificationsTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
1.1966 + test(r==KErrNone);
1.1967 + test.Next(_L("TestTwoNotifications - Resume Watcher"));
1.1968 + watcher.Resume();
1.1969 + test.Next(_L("TestTwoNotifications - Wait for Watcher to be ready"));
1.1970 + package.iBarrier.Wait(); //Wait till Watcher has requested notification
1.1971 + test.Next(_L("TestTwoNotifications - Resume Doer"));
1.1972 + doer.Resume();
1.1973 +
1.1974 + test.Next(_L("TestTwoNotifications - Wait for doer thread death"));
1.1975 + TRequestStatus status;
1.1976 + doer.Logon(status);
1.1977 + User::WaitForRequest(status);
1.1978 + test(doer.ExitReason()==KErrNone);
1.1979 +
1.1980 + test.Next(_L("TestTwoNotifications - Wait for watcher thread death"));
1.1981 + watcher.Logon(status);
1.1982 + User::WaitForRequest(status);
1.1983 + test(watcher.ExitReason()==KErrNone);
1.1984 +
1.1985 + CLOSE_AND_WAIT(doer);
1.1986 + CLOSE_AND_WAIT(watcher);
1.1987 +
1.1988 + twoNotificationsDoerBar.Close();
1.1989 + package.iBarrier.Close();
1.1990 + fs.Close();
1.1991 +
1.1992 + return KErrNone;
1.1993 + }
1.1994 +
1.1995 +
1.1996 +/*
1.1997 + * Watch two threads to receive two notifications.
1.1998 + * Used in TestTwoDoersL().
1.1999 + */
1.2000 +TInt TestTwoDoersWatcher(TAny* aAny)
1.2001 + {
1.2002 + CTrapCleanup* cleanup;
1.2003 + cleanup = CTrapCleanup::New();
1.2004 +
1.2005 + RSemaphore& twoThreadsBarrier = *(RSemaphore*)aAny;
1.2006 + RTest twoThreadsWatcherTest(_L("TwoThreadsWatcher"));
1.2007 + twoThreadsWatcherTest.Start(_L("TwoThreadsWatcher"));
1.2008 +
1.2009 + RFs fs;
1.2010 + fs.Connect();
1.2011 +
1.2012 + twoThreadsWatcherTest.Next(_L("Create CFsNotify"));
1.2013 + CFsNotify* notify = NULL;
1.2014 + TRAPD(r,notify = CFsNotify::NewL(fs,200));
1.2015 + twoThreadsWatcherTest(r == KErrNone);
1.2016 +
1.2017 + TBuf<40> path1;
1.2018 + TBuf<20> filename1;
1.2019 + TBuf<40> path2;
1.2020 + TBuf<20> filename2;
1.2021 + path1.Append(gDriveToTest);
1.2022 + path2.Append(gDriveToTest);
1.2023 + path1.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.2024 + filename1.Append(_L("file1.create"));
1.2025 + path2.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.2026 + filename2.Append(_L("file2.create"));
1.2027 + TBuf<40> fullname1;
1.2028 + fullname1.Append(path1);
1.2029 + fullname1.Append(filename1);
1.2030 + TBuf<40> fullname2;
1.2031 + fullname2.Append(path2);
1.2032 + fullname2.Append(filename2);
1.2033 +
1.2034 + twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - Add Notification for %S\n"),&path1);
1.2035 + r = notify->AddNotification((TUint)TFsNotification::ECreate,path1,filename1);
1.2036 + twoThreadsWatcherTest(r == KErrNone);
1.2037 +
1.2038 + twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - Add Notification for %S\n"),&path2);
1.2039 + r = notify->AddNotification((TUint)TFsNotification::ECreate,path2,filename2);
1.2040 + twoThreadsWatcherTest(r == KErrNone);
1.2041 +
1.2042 + TRequestStatus status;
1.2043 + twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Request Notifications"));
1.2044 + r = notify->RequestNotifications(status);
1.2045 + twoThreadsWatcherTest(r == KErrNone);
1.2046 +
1.2047 + twoThreadsBarrier.Signal(); //Signal Doer threads to start
1.2048 + User::WaitForRequest(status);
1.2049 +
1.2050 + // We should be getting 2 notifications
1.2051 + // Test notifications are not null and check notification types and paths
1.2052 + // 1st notification:
1.2053 + twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - First Notification"));
1.2054 + const TFsNotification* notification = notify->NextNotification();
1.2055 + twoThreadsWatcherTest(notification != NULL);
1.2056 + twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - First Notification Type"));
1.2057 + TFsNotification::TFsNotificationType notificationType = ((TFsNotification*)notification)->NotificationType();
1.2058 + twoThreadsWatcherTest(notificationType == TFsNotification::ECreate);
1.2059 + twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - First Notification Path"));
1.2060 + TPtrC _pathC;
1.2061 + ((TFsNotification*)notification)->Path(_pathC);
1.2062 + twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - First Notification Path returned %S\n"),&_pathC);
1.2063 + TBuf<40> _path;
1.2064 + _path.Copy(_pathC);
1.2065 + //We can't guarantee which thread ran first so check that it was either path1 or path2
1.2066 + twoThreadsWatcherTest(_path.Match(fullname1) == KErrNone || _path.Match(fullname2) == KErrNone);
1.2067 +
1.2068 + // 2nd notification:
1.2069 + twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Second Notification"));
1.2070 + notification = notify->NextNotification();
1.2071 + // Check if next notification exists
1.2072 + if (!notification)
1.2073 + {
1.2074 + notify->RequestNotifications(status);
1.2075 + User::WaitForRequest(status);
1.2076 + notification = notify->NextNotification();
1.2077 + }
1.2078 + twoThreadsWatcherTest(notification != NULL);
1.2079 + twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Second Notification Type"));
1.2080 + notificationType = ((TFsNotification*)notification)->NotificationType();
1.2081 + twoThreadsWatcherTest(notificationType == TFsNotification::ECreate);
1.2082 + twoThreadsWatcherTest.Next(_L("TwoThreadsWatcher - Second Notification Path"));
1.2083 + ((TFsNotification*)notification)->Path(_pathC);
1.2084 + twoThreadsWatcherTest.Printf(_L("TwoThreadsWatcher - Second Notification Path returned %S\n"),&_pathC);
1.2085 + _path.Copy(_pathC);
1.2086 + twoThreadsWatcherTest(_path.Match(fullname1) == KErrNone || _path.Match(fullname2) == KErrNone);
1.2087 +
1.2088 + delete notify;
1.2089 + fs.Close();
1.2090 + twoThreadsWatcherTest.End();
1.2091 + twoThreadsWatcherTest.Close();
1.2092 + delete cleanup;
1.2093 + return KErrNone;
1.2094 + }
1.2095 +
1.2096 +/*
1.2097 + * TestTwoDoersL - Two Doer threads create a file each and there's one Watcher
1.2098 + * which expects two notifications (one from each Doer).
1.2099 + */
1.2100 +TInt TestTwoDoersL()
1.2101 + {
1.2102 + test.Next(_L("TestTwoDoers"));
1.2103 +
1.2104 + RFs fs;
1.2105 + fs.Connect();
1.2106 +
1.2107 + _LIT(KFileName1,"file1.create");
1.2108 + _LIT(KFileName2,"file2.create");
1.2109 + RSemaphore simpleBarrierTest;
1.2110 + SThreadPackage pkgDoer1;
1.2111 + SThreadPackage pkgDoer2;
1.2112 + pkgDoer1.iFileName = KFileName1;
1.2113 + pkgDoer2.iFileName = KFileName2;
1.2114 +
1.2115 + User::LeaveIfError(pkgDoer1.iBarrier.CreateLocal(0));
1.2116 + User::LeaveIfError(pkgDoer2.iBarrier.CreateLocal(0));
1.2117 + User::LeaveIfError(simpleBarrierTest.CreateLocal(0));
1.2118 + RThread watcher;
1.2119 + RThread doer1;
1.2120 + RThread doer2;
1.2121 +
1.2122 + watcher.Create(_L("TestTwoDoers-WatcherThread"),TestTwoDoersWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&simpleBarrierTest);
1.2123 + doer1.Create(_L("TestTwoDoers-DoerThread1"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer1);
1.2124 + doer2.Create(_L("TestTwoDoers-DoerThread2"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer2);
1.2125 + watcher.Resume();
1.2126 + simpleBarrierTest.Wait(); //Wait until Watcher has created CFsNotify
1.2127 +
1.2128 + doer1.Resume();
1.2129 + doer2.Resume();
1.2130 +
1.2131 + test.Next(_L("TestTwoDoers - Wait for doer1 thread death"));
1.2132 + TRequestStatus status;
1.2133 + doer1.Logon(status);
1.2134 + User::WaitForRequest(status);
1.2135 + test(doer1.ExitReason()==KErrNone);
1.2136 +
1.2137 + test.Next(_L("TestTwoDoers - Wait for doer2 thread death"));
1.2138 + doer2.Logon(status);
1.2139 + User::WaitForRequest(status);
1.2140 + test(doer2.ExitReason()==KErrNone);
1.2141 +
1.2142 + test.Next(_L("TestTwoDoers - Wait for watcher thread death"));
1.2143 + watcher.Logon(status);
1.2144 + RTimer timer1;
1.2145 + TInt r = timer1.CreateLocal();
1.2146 + safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.2147 + TRequestStatus timeout;
1.2148 + TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
1.2149 + timer1.After(timeout,time);
1.2150 + User::WaitForRequest(timeout,status);
1.2151 + test(status.Int() != KRequestPending);
1.2152 + timer1.Cancel();
1.2153 + timer1.Close();
1.2154 + //User::WaitForRequest(status);
1.2155 + test(watcher.ExitReason()==KErrNone);
1.2156 +
1.2157 + CLOSE_AND_WAIT(doer1);
1.2158 + CLOSE_AND_WAIT(doer2);
1.2159 + CLOSE_AND_WAIT(watcher);
1.2160 +
1.2161 + pkgDoer1.iBarrier.Close();
1.2162 + pkgDoer2.iBarrier.Close();
1.2163 + simpleBarrierTest.Close();
1.2164 + fs.Close();
1.2165 + return KErrNone;
1.2166 + }
1.2167 +
1.2168 +/*
1.2169 + * TestTwoWatchersL - Uses two watcher threads and one doer thread to test that running
1.2170 + * two distinct sub sessions at the same time (both watch the same file).
1.2171 + */
1.2172 +TInt TestTwoWatchersL()
1.2173 + {
1.2174 + test.Next(_L("TestTwoWatchers"));
1.2175 + RFs fs;
1.2176 + fs.Connect();
1.2177 + _LIT(KFileName,"file.creat3");
1.2178 + SThreadPackage pkgDoer;
1.2179 + pkgDoer.iFileName = KFileName;
1.2180 +
1.2181 + SThreadPackage watcherPkg;
1.2182 + watcherPkg.iFileName = KFileName;
1.2183 +
1.2184 + User::LeaveIfError(pkgDoer.iBarrier.CreateLocal(0));
1.2185 + User::LeaveIfError(watcherPkg.iBarrier.CreateLocal(0));
1.2186 + RThread watcher;
1.2187 + RThread watcher2;
1.2188 + RThread doer;
1.2189 + watcher.Create(_L("TestTwoWatchersWatcherThread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcherPkg);
1.2190 + watcher2.Create(_L("TestTwoWatchersWatcher2Thread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcherPkg);
1.2191 + doer.Create(_L("TestTwoWatchersDoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&pkgDoer);
1.2192 + watcher.Resume();
1.2193 + watcher2.Resume();
1.2194 + watcherPkg.iBarrier.Wait(); //Wait till both watchers have requested notification
1.2195 + watcherPkg.iBarrier.Wait();
1.2196 + doer.Resume();
1.2197 +
1.2198 + test.Printf(_L("Wait for DOER to terminate , Line %d"),__LINE__);
1.2199 + TRequestStatus status;
1.2200 + doer.Logon(status);
1.2201 + User::WaitForRequest(status);
1.2202 + test(doer.ExitReason()==KErrNone);
1.2203 +
1.2204 + test.Printf(_L("Wait for WATCHER to terminate , Line %d"),__LINE__);
1.2205 + watcher.Logon(status);
1.2206 + RTimer timer1;
1.2207 + TInt r = timer1.CreateLocal();
1.2208 + safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.2209 + TRequestStatus timeout;
1.2210 + TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
1.2211 + timer1.After(timeout,time);
1.2212 + User::WaitForRequest(timeout,status);
1.2213 + test(status.Int() != KRequestPending);
1.2214 + timer1.Cancel();
1.2215 + timer1.Close();
1.2216 +// User::WaitForRequest(status);
1.2217 + test(watcher.ExitReason()==KErrNone);
1.2218 +
1.2219 + test.Printf(_L("Wait for WATCHER2 to terminate , Line %d"),__LINE__);
1.2220 + watcher2.Logon(status);
1.2221 + RTimer timer2;
1.2222 + r = timer2.CreateLocal();
1.2223 + safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.2224 + TRequestStatus timeout2;
1.2225 + timer2.After(timeout2,time);
1.2226 + User::WaitForRequest(timeout2,status);
1.2227 + test(status.Int() != KRequestPending);
1.2228 + timer2.Cancel();
1.2229 + timer2.Close();
1.2230 + //User::WaitForRequest(status);
1.2231 + test(watcher2.ExitReason()==KErrNone);
1.2232 +
1.2233 + CLOSE_AND_WAIT(doer);
1.2234 + CLOSE_AND_WAIT(watcher);
1.2235 + CLOSE_AND_WAIT(watcher2);
1.2236 +
1.2237 + pkgDoer.iBarrier.Close();
1.2238 + watcherPkg.iBarrier.Close();
1.2239 + fs.Close();
1.2240 + return KErrNone;
1.2241 + }
1.2242 +
1.2243 +
1.2244 +/*
1.2245 + * TestTwoWatchersTwoDoersL - Two watcher threads watches two different doer threads.
1.2246 + */
1.2247 +TInt TestTwoWatchersTwoDoersL()
1.2248 + {
1.2249 + test.Next(_L("TestTwoWatchersTwoDoers"));
1.2250 + RFs fs;
1.2251 + fs.Connect();
1.2252 + _LIT(KFileName1,"f1le.create");
1.2253 + _LIT(KFileName2,"f2le.create");
1.2254 + SThreadPackage package1;
1.2255 + package1.iFileName = KFileName1;
1.2256 +
1.2257 + SThreadPackage package2;
1.2258 + package2.iFileName = KFileName2;
1.2259 +
1.2260 + User::LeaveIfError(package1.iBarrier.CreateLocal(0));
1.2261 + User::LeaveIfError(package2.iBarrier.CreateLocal(0));
1.2262 + RThread watcher;
1.2263 + RThread watcher2;
1.2264 + RThread doer;
1.2265 + RThread doer2;
1.2266 + watcher.Create(_L("TestTwoWatchersTwoDoersWatcherThread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package1);
1.2267 + doer.Create(_L("TestTwoWatchersTwoDoersDoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package1);
1.2268 +
1.2269 + watcher2.Create(_L("TestTwoWatchersTwoDoersWatcher2Thread"),SimpleSingleNotificationTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package2);
1.2270 + doer2.Create(_L("TestTwoWatchersTwoDoersDoer2Thread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package2);
1.2271 + watcher.Resume();
1.2272 + watcher2.Resume();
1.2273 + package1.iBarrier.Wait(); //Wait till both watchers have requested notification
1.2274 + package2.iBarrier.Wait();
1.2275 + doer.Resume();
1.2276 + doer2.Resume();
1.2277 +
1.2278 + test.Printf(_L("Wait for DOER to terminate , Line %d"),__LINE__);
1.2279 + TRequestStatus status;
1.2280 + doer.Logon(status);
1.2281 + User::WaitForRequest(status);
1.2282 + test(doer.ExitReason()==KErrNone);
1.2283 +
1.2284 + test.Printf(_L("Wait for DOER2 to terminate , Line %d"),__LINE__);
1.2285 + doer2.Logon(status);
1.2286 + User::WaitForRequest(status);
1.2287 + test(doer2.ExitReason()==KErrNone);
1.2288 +
1.2289 + test.Printf(_L("Wait for WATCHER to terminate , Line %d"),__LINE__);
1.2290 + watcher.Logon(status);
1.2291 + RTimer timer1;
1.2292 + TInt r = timer1.CreateLocal();
1.2293 + safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.2294 + TRequestStatus timeout;
1.2295 + TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
1.2296 + timer1.After(timeout,time);
1.2297 + User::WaitForRequest(timeout,status);
1.2298 + test(status.Int() != KRequestPending);
1.2299 + timer1.Cancel();
1.2300 + timer1.Close();
1.2301 + test(watcher.ExitReason()==KErrNone);
1.2302 +
1.2303 + test.Printf(_L("Wait for WATCHER2 to terminate , Line %d"),__LINE__);
1.2304 + watcher2.Logon(status);
1.2305 + RTimer timer2;
1.2306 + r = timer2.CreateLocal();
1.2307 + safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.2308 + TRequestStatus timeout2;
1.2309 + timer2.After(timeout2,time);
1.2310 + User::WaitForRequest(timeout2,status);
1.2311 + test(status.Int() != KRequestPending);
1.2312 + timer2.Cancel();
1.2313 + timer2.Close();
1.2314 + test(watcher2.ExitReason()==KErrNone);
1.2315 +
1.2316 + CLOSE_AND_WAIT(doer);
1.2317 + CLOSE_AND_WAIT(doer2);
1.2318 + CLOSE_AND_WAIT(watcher);
1.2319 + CLOSE_AND_WAIT(watcher2);
1.2320 +
1.2321 + package1.iBarrier.Close();
1.2322 + package2.iBarrier.Close();
1.2323 + fs.Close();
1.2324 + return KErrNone;
1.2325 + }
1.2326 +
1.2327 +
1.2328 +/*
1.2329 + * Multi-purpose test
1.2330 + *
1.2331 + * If aFailureExpected is ETrue, it is expected that the watcher thread is not terminated normally,
1.2332 + * due to the notification(s) not being sent.
1.2333 + * Since this function is called many times, aLineCall is used to show the line where it is called from.
1.2334 + * See SThreadPackageMultiple.
1.2335 + */
1.2336 +TInt TestMultipleNotificationsL(const TDesC& aFilename, const TDesC& aString, TInt aIterations,
1.2337 + TInt aMaxNotifications, t_notification::EOperation aOperation,
1.2338 + TUint aNotifyType, TInt aBufferSize, TBool aFailureExpected, TInt aLineCall)
1.2339 + {
1.2340 + test.Next(_L("TestMultipleNotifications"));
1.2341 +
1.2342 + RFs fs;
1.2343 + fs.Connect();
1.2344 + SThreadPackageMultiple package;
1.2345 + package.iIterations = aIterations;
1.2346 + package.iMaxNotifications = aMaxNotifications;
1.2347 + package.iOperation = aOperation;
1.2348 + package.iNotifyType = (TFsNotification::TFsNotificationType)aNotifyType;
1.2349 + package.iString = aString;
1.2350 + package.iFileName = aFilename;
1.2351 + package.iBufferSize = aBufferSize;
1.2352 + package.iLineCall = aLineCall;
1.2353 +
1.2354 + User::LeaveIfError(package.iBarrier.CreateLocal(0));
1.2355 + RThread watcher;
1.2356 + RThread doer;
1.2357 + RTimer tim;
1.2358 + User::LeaveIfError(tim.CreateLocal());
1.2359 +
1.2360 + TInt r = watcher.Create(_L("TestMultipleNotificationsWatcherThread"),MultipleNotificationsTFWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
1.2361 + safe_test(test,r,__LINE__,package.iLineCall);
1.2362 + r = doer.Create(_L("TestMultipleNotificationsDoerThread"),MultipleNotificationTFDoer,KDefaultStackSize*2,KMinHeapSize,KMaxHeapSize,&package);
1.2363 + safe_test(test,r,__LINE__,package.iLineCall);
1.2364 + test.Next(_L("TestMultipleNotifications - Resume Watcher"));
1.2365 + watcher.Resume();
1.2366 + test.Next(_L("TestMultipleNotifications - Wait for Watcher to be ready"));
1.2367 + package.iBarrier.Wait(); //Wait till Watcher has requested notification
1.2368 + test.Next(_L("TestMultipleNotifications - Resume Doer"));
1.2369 + doer.Resume();
1.2370 +
1.2371 + test.Next(_L("TestMultipleNotifications - Wait for doer thread death"));
1.2372 + TRequestStatus status;
1.2373 + doer.Logon(status);
1.2374 + User::WaitForRequest(status);
1.2375 + test.Printf(_L("TestMultipleNotifications - Doer Exit Reason %d\n"),doer.ExitReason());
1.2376 + safe_test(test,doer.ExitReason(),__LINE__,package.iLineCall);
1.2377 +
1.2378 + TRequestStatus timStatus;
1.2379 + TTimeIntervalMicroSeconds32 timeout;
1.2380 + if (aFailureExpected && !(package.iOperation == t_notification::EMediaCardInsertion ||
1.2381 + package.iOperation == t_notification::EMediaCardRemoval))
1.2382 + {
1.2383 + timeout = 1500000; //1.5 seconds, we don't want to wait too long if we expect it to fail
1.2384 + }
1.2385 + else
1.2386 + {
1.2387 + timeout = 10000000; //10 seconds
1.2388 + }
1.2389 + tim.After(timStatus,timeout);
1.2390 +
1.2391 + test.Next(_L("TestMultipleNotifications - Wait for watcher thread death or timeout"));
1.2392 + watcher.Logon(status);
1.2393 + User::WaitForRequest(status,timStatus);
1.2394 + if(!(status != KRequestPending || aFailureExpected))
1.2395 + safe_test(test,KErrGeneral,__LINE__,package.iLineCall);
1.2396 +
1.2397 + test.Printf(_L("TestMultipleNotifications - Watcher Exit Reason %d\n"),watcher.ExitReason());
1.2398 + safe_test(test,watcher.ExitReason(),__LINE__,package.iLineCall);
1.2399 +
1.2400 + CLOSE_AND_WAIT(doer);
1.2401 +
1.2402 + if(status == KRequestPending)
1.2403 + {
1.2404 + watcher.Kill(KErrTimedOut);
1.2405 + test.Printf(_L("TestMultipleNotifications - Watcher timed out\n"));
1.2406 + }
1.2407 + CLOSE_AND_WAIT(watcher);
1.2408 +
1.2409 + package.iBarrier.Close();
1.2410 + fs.Close();
1.2411 + tim.Close();
1.2412 + test.Printf(_L("----------------------------------------------------------------------\n"));
1.2413 + return KErrNone;
1.2414 + }
1.2415 +
1.2416 +TInt TestMultipleNotificationsL(const TDesC& aFilename, const TDesC& aString, TInt aIterations,
1.2417 + TInt aMaxNotifications, t_notification::EOperation aOperation,
1.2418 + TFsNotification::TFsNotificationType aNotifyType, TInt aBufferSize,
1.2419 + TBool aFailureExpected, TInt aLineCall)
1.2420 + {
1.2421 + return TestMultipleNotificationsL(aFilename, aString, aIterations, aMaxNotifications, aOperation,
1.2422 + (TUint)aNotifyType, aBufferSize, aFailureExpected, aLineCall);
1.2423 + }
1.2424 +
1.2425 +TInt TestMultipleNotificationsL(const TDesC& aFilename, TInt aIterations, TInt aMaxNotifications,
1.2426 + t_notification::EOperation aOperation, TUint aNotifyType, TInt aBufferSize,
1.2427 + TBool aFailureExpected, TInt aLineCall)
1.2428 + {
1.2429 + return TestMultipleNotificationsL(aFilename,_L(""), aIterations, aMaxNotifications, aOperation, aNotifyType,
1.2430 + aBufferSize, aFailureExpected, aLineCall);
1.2431 + }
1.2432 +
1.2433 +
1.2434 +// Watcher for TestAddRemoveNotificationL()
1.2435 +TInt TestAddRemoveNotificationWatcher(TAny* aAny)
1.2436 + {
1.2437 + CTrapCleanup* cleanup;
1.2438 + cleanup = CTrapCleanup::New();
1.2439 + RThread thread;
1.2440 + TUint64 threadId = thread.Id().Id();
1.2441 +
1.2442 + SThreadPackage pkgDoer = *(SThreadPackage*)aAny;
1.2443 + RSemaphore& addRemoveBarrier = pkgDoer.iBarrier;
1.2444 +
1.2445 + RTest addRemoveWatcherTest(_L("TestAddRemoveNotificationWatcher"));
1.2446 + addRemoveWatcherTest.Start(_L("TestAddRemoveNotificationWatcher"));
1.2447 +
1.2448 + RFs fs;
1.2449 + fs.Connect();
1.2450 +
1.2451 + addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - Create CFsNotify\n"),threadId);
1.2452 + CFsNotify* notify = NULL;
1.2453 + TRAPD(r,notify = CFsNotify::NewL(fs,100); );
1.2454 + addRemoveWatcherTest( r == KErrNone);
1.2455 + TBuf<40> path;
1.2456 + TBuf<20> filename;
1.2457 + path.Append(gDriveToTest);
1.2458 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
1.2459 + filename.Append(pkgDoer.iFileName);
1.2460 +
1.2461 + addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher - Add Notification for %S\n"),&path);
1.2462 + r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
1.2463 + addRemoveWatcherTest(r==KErrNone);
1.2464 + addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - Remove Notifications\n"),threadId);
1.2465 + r = notify->RemoveNotifications();
1.2466 + addRemoveWatcherTest(r==KErrNone);
1.2467 + addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - Request Notifications\n"),threadId);
1.2468 + TRequestStatus status;
1.2469 + r = notify->RequestNotifications(status);
1.2470 + addRemoveWatcherTest(r==KErrNone);
1.2471 + addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher status = %d"),status.Int());
1.2472 + addRemoveBarrier.Signal();
1.2473 +
1.2474 + addRemoveWatcherTest.Printf(_L("TestAddRemoveNotificationWatcher(%d) - NextNotification\n"),threadId);
1.2475 + //We should not be getting any notifications as the notification request has been removed
1.2476 + const TFsNotification* notification = notify->NextNotification();
1.2477 + addRemoveWatcherTest(notification == NULL);
1.2478 +
1.2479 + delete notify;
1.2480 + fs.Close();
1.2481 + addRemoveWatcherTest.End();
1.2482 + addRemoveWatcherTest.Close();
1.2483 + delete cleanup;
1.2484 + return KErrNone;
1.2485 + }
1.2486 +
1.2487 +
1.2488 +/*
1.2489 + * TestAddRemoveNotificationL - Watcher adds and removes notification request.
1.2490 + * Any changes by doer thread should not be detected.
1.2491 + */
1.2492 +TInt TestAddRemoveNotificationL()
1.2493 + {
1.2494 + test.Next(_L("TestAddRemoveNotification"));
1.2495 + RFs fs;
1.2496 + fs.Connect();
1.2497 +
1.2498 + SThreadPackage package;
1.2499 + _LIT(KFileName,"noFile.create");
1.2500 + package.iFileName = KFileName;
1.2501 +
1.2502 + User::LeaveIfError(package.iBarrier.CreateLocal(0));
1.2503 + RThread watcher;
1.2504 + RThread doer;
1.2505 +
1.2506 + watcher.Create(_L("TestAddRemoveNotification-WatcherThread"),TestAddRemoveNotificationWatcher,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
1.2507 + doer.Create(_L("TestAddRemoveNotification-DoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
1.2508 + watcher.Resume();
1.2509 +
1.2510 + test.Printf(_L("TestAddRemoveNotification - Wait until Watcher has created CFsNotify\n"));
1.2511 + package.iBarrier.Wait(); //Wait until Watcher has created CFsNotify
1.2512 + doer.Resume();
1.2513 +
1.2514 + test.Next(_L("TestAddRemoveNotification - Wait for doer thread death"));
1.2515 + TRequestStatus status;
1.2516 + doer.Logon(status);
1.2517 + User::WaitForRequest(status);
1.2518 + test(doer.ExitReason()==KErrNone);
1.2519 +
1.2520 + test.Next(_L("TestAddRemoveNotification - Wait for watcher thread death"));
1.2521 + watcher.Logon(status);
1.2522 + RTimer timer1;
1.2523 + TInt r = timer1.CreateLocal();
1.2524 + safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.2525 + TRequestStatus timeout;
1.2526 + TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
1.2527 + timer1.After(timeout,time);
1.2528 + User::WaitForRequest(timeout,status);
1.2529 + test(status.Int() != KRequestPending);
1.2530 + timer1.Cancel();
1.2531 + timer1.Close();
1.2532 + test.Printf(_L("Test - Watcher Exit Reason %d\n"),watcher.ExitReason());
1.2533 + test(watcher.ExitReason()==KErrNone);
1.2534 +
1.2535 + CLOSE_AND_WAIT(doer);
1.2536 + CLOSE_AND_WAIT(watcher);
1.2537 +
1.2538 + package.iBarrier.Close();
1.2539 + fs.Close();
1.2540 + return KErrNone;
1.2541 + }
1.2542 +
1.2543 +
1.2544 +/*
1.2545 + * Adds and cancels notification request.
1.2546 + * Used in TestCancelNotificationL().
1.2547 + */
1.2548 +TInt TestCancelNotificationWatcher(TAny* aAny)
1.2549 + {
1.2550 + CTrapCleanup* cleanup;
1.2551 + cleanup = CTrapCleanup::New();
1.2552 +
1.2553 + RTest cancelNotificationsWatcherTest(_L("TestCancelNotificationWatcher"));
1.2554 + cancelNotificationsWatcherTest.Start(_L("TestCancelNotificationWatcher"));
1.2555 +
1.2556 + RThread thread;
1.2557 + TUint64 threadId = thread.Id().Id();
1.2558 +
1.2559 + SThreadPackageDualSemaphore pkgDoer = *(SThreadPackageDualSemaphore*)aAny;
1.2560 + RSemaphore& addRemoveBarrier = pkgDoer.iBarrier;
1.2561 + RSemaphore& addRemoveBarrier2 = pkgDoer.iBarrier2;
1.2562 +
1.2563 + RFs fs;
1.2564 + fs.Connect();
1.2565 +
1.2566 + cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Create CFsNotify\n"),threadId);
1.2567 + CFsNotify* notify = NULL;
1.2568 + TRAPD(r,notify = CFsNotify::NewL(fs,100); );
1.2569 + cancelNotificationsWatcherTest(r == KErrNone);
1.2570 + TBuf<40> path;
1.2571 + TBuf<20> filename;
1.2572 + path.Append(gDriveToTest);
1.2573 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
1.2574 + filename.Append(pkgDoer.iFileName);
1.2575 +
1.2576 + cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher - Add Notification for %S\n"),&path);
1.2577 + r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
1.2578 + cancelNotificationsWatcherTest(r==KErrNone);
1.2579 + cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Request Notifications\n"),threadId);
1.2580 + TRequestStatus status;
1.2581 + r = notify->RequestNotifications(status);
1.2582 + cancelNotificationsWatcherTest(r==KErrNone);
1.2583 +
1.2584 + cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Cancel Notifications\n"),threadId);
1.2585 + r = notify->CancelNotifications(status);
1.2586 + cancelNotificationsWatcherTest(r==KErrNone);
1.2587 +
1.2588 + cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Signal W1 - Start doer\n"),threadId);
1.2589 + addRemoveBarrier.Signal(); //W1 - Start doer
1.2590 +
1.2591 + cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Wait S1 - doer complete\n"),threadId);
1.2592 + addRemoveBarrier2.Wait(); //S1 - Wait for doer to have created file
1.2593 +
1.2594 + cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - NextNotification\n"),threadId);
1.2595 + //We should not be getting any notifications as the notification request has been removed
1.2596 + const TFsNotification* notification = notify->NextNotification();
1.2597 + cancelNotificationsWatcherTest(notification == NULL);
1.2598 +
1.2599 + delete notify;
1.2600 + fs.Close();
1.2601 + cancelNotificationsWatcherTest.Printf(_L("TestCancelNotificationWatcher(%d) - Complete\n"),threadId);
1.2602 + cancelNotificationsWatcherTest.End();
1.2603 + cancelNotificationsWatcherTest.Close();
1.2604 + delete cleanup;
1.2605 + return KErrNone;
1.2606 + }
1.2607 +
1.2608 +
1.2609 +/*
1.2610 + * TestCancelNotificationL - Watcher adds and cancels notification request.
1.2611 + */
1.2612 +TInt TestCancelNotificationL()
1.2613 + {
1.2614 + test.Next(_L("TestCancelNotification"));
1.2615 + RFs fs;
1.2616 + fs.Connect();
1.2617 +
1.2618 + SThreadPackageDualSemaphore package;
1.2619 + _LIT(KFileName,"cancel.create");
1.2620 + package.iFileName = KFileName;
1.2621 +
1.2622 + User::LeaveIfError(package.iBarrier.CreateLocal(0));
1.2623 + User::LeaveIfError(package.iBarrier2.CreateLocal(0));
1.2624 + RThread watcher;
1.2625 + RThread doer;
1.2626 +
1.2627 + TInt r = watcher.Create(_L("TestCancelNotification-WatcherThread"),TestCancelNotificationWatcher,KDefaultStackSize*2,KMinHeapSize,KMaxHeapSize,&package);
1.2628 + test(r == KErrNone);
1.2629 + r = doer.Create(_L("TestCancelNotification-DoerThread"),SimpleSingleNotificationTFDoer,KDefaultStackSize*2,KMinHeapSize,KMaxHeapSize,&package);
1.2630 + test(r == KErrNone);
1.2631 + test.Printf(_L("TestCancelNotificationL - Watcher.Resume()"));
1.2632 + watcher.Resume();
1.2633 + test.Printf(_L("TestCancelNotificationL - Waiting on package.iBarrier.Wait()"));
1.2634 + package.iBarrier.Wait(); //W1 - Wait until Watcher has created CFsNotify
1.2635 + test.Printf(_L("TestCancelNotificationL -Doer Resume"));
1.2636 + TRequestStatus status;
1.2637 + doer.Logon(status);
1.2638 + doer.Resume();
1.2639 +
1.2640 + test.Next(_L("TestCancelNotification - Wait for doer thread death"));
1.2641 + User::WaitForRequest(status);
1.2642 + test(doer.ExitReason()==KErrNone);
1.2643 +
1.2644 + package.iBarrier2.Signal(); //S1
1.2645 +
1.2646 + test.Next(_L("TestCancelNotification - Wait for watcher thread death"));
1.2647 + watcher.Logon(status);
1.2648 +
1.2649 + RTimer tim;
1.2650 + r = tim.CreateLocal();
1.2651 + test(r==KErrNone);
1.2652 +
1.2653 + TRequestStatus timStatus;
1.2654 + TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
1.2655 + tim.After(timStatus,time);
1.2656 +
1.2657 + User::WaitForRequest(status,timStatus);
1.2658 + test(status!=KRequestPending);
1.2659 + test(watcher.ExitReason()==KErrNone);
1.2660 +
1.2661 + CLOSE_AND_WAIT(doer);
1.2662 + CLOSE_AND_WAIT(watcher);
1.2663 +
1.2664 + package.iBarrier.Close();
1.2665 + package.iBarrier2.Close();
1.2666 + fs.Close();
1.2667 + tim.Close();
1.2668 + return KErrNone;
1.2669 + }
1.2670 +
1.2671 +/*
1.2672 + * Test that if we close the session
1.2673 + * before closing the subsession (deleting CFsNotify)
1.2674 + * that everything is A-Ok.
1.2675 + */
1.2676 +TInt TestSessionCloseTF(TAny* aTestCase)
1.2677 + {
1.2678 + CTrapCleanup* cleanup;
1.2679 + cleanup = CTrapCleanup::New();
1.2680 +
1.2681 + TRAPD(r,
1.2682 + RFs fs;
1.2683 + fs.Connect();
1.2684 + RDebug::Printf("TestSessionClose\n");
1.2685 +
1.2686 + SThreadPackage2 package = *(SThreadPackage2*)aTestCase;
1.2687 + package.iBarrier.Signal();
1.2688 +
1.2689 + switch(package.iTestCase)
1.2690 + {
1.2691 + case 1:
1.2692 + {
1.2693 + RDebug::Printf("TestSessionCloseTF - Case 1 - NewL\n");
1.2694 + CFsNotify* notify = CFsNotify::NewL(fs,KMinNotificationBufferSize);
1.2695 + User::LeaveIfNull(notify);
1.2696 +
1.2697 + RDebug::Printf("TestSessionCloseTF - Case 1 - Fs.Close\n");
1.2698 + fs.Close();
1.2699 +
1.2700 + TBuf<45> path;
1.2701 + path.Append((TChar)gDriveToTest);
1.2702 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.2703 +
1.2704 + TBuf<20> filename;
1.2705 + filename.Append(_L("session.close"));
1.2706 +
1.2707 + CleanupStack::PushL(notify);
1.2708 +
1.2709 + RDebug::Printf("TestSessionCloseTF - Case 1 - Add Notification - Panic Expected\n");
1.2710 + r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
1.2711 + User::LeaveIfError(r);
1.2712 +
1.2713 + RDebug::Printf("TestSessionCloseTF - Case 1 - After Session Close\n");
1.2714 + fs.Close();
1.2715 + CleanupStack::Pop(notify);
1.2716 +
1.2717 + RDebug::Printf("TestSessionCloseTF - Case 1 - After Delete Notify\n");
1.2718 + delete notify;
1.2719 + break;
1.2720 + }
1.2721 + case 2:
1.2722 + {
1.2723 + RDebug::Printf("TestSessionCloseTF - Case 2 - NewL\n");
1.2724 + CFsNotify* notify = CFsNotify::NewL(fs,KMinNotificationBufferSize);
1.2725 + User::LeaveIfNull(notify);
1.2726 +
1.2727 + TBuf<45> path;
1.2728 + path.Append((TChar)gDriveToTest);
1.2729 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.2730 + TBuf<20> filename;
1.2731 + filename.Append(_L("session.close"));
1.2732 +
1.2733 + RDebug::Printf("TestSessionCloseTF - Case 2 - Add Notification\n");
1.2734 + r = notify->AddNotification((TUint)TFsNotification::ECreate,path,filename);
1.2735 + test(r==KErrNone);
1.2736 +
1.2737 + RDebug::Printf("TestSessionCloseTF - Case 2 - Fs.Close\n");
1.2738 + fs.Close();
1.2739 +
1.2740 + CleanupStack::PushL(notify);
1.2741 + TRequestStatus status;
1.2742 + RDebug::Printf("TestSessionCloseTF - Case 2 - Request Notification - Panic Expected\n");
1.2743 + r = notify->RequestNotifications(status);
1.2744 + CleanupStack::Pop(notify);
1.2745 +
1.2746 + RDebug::Printf("TestSessionCloseTF - Case 2 - After Delete Notify\n");
1.2747 + delete notify;
1.2748 + break;
1.2749 + }
1.2750 + default:
1.2751 + {
1.2752 + break;
1.2753 + }
1.2754 + }
1.2755 + );
1.2756 + delete cleanup;
1.2757 + return r;
1.2758 + }
1.2759 +
1.2760 +/*
1.2761 + * Test that if we close the session
1.2762 + * before closing the subsession (deleting CFsNotify)
1.2763 + * that everything is A-Ok.
1.2764 + */
1.2765 +void TestSessionClose(TInt aTestCase)
1.2766 + {
1.2767 + RSemaphore sem;
1.2768 + User::LeaveIfError(sem.CreateLocal(0));
1.2769 +
1.2770 + SThreadPackage2 package;
1.2771 + package.iTestCase = aTestCase;
1.2772 + package.iBarrier = sem;
1.2773 +
1.2774 + RThread thread;
1.2775 + thread.Create(_L("TestSessionClose"),TestSessionCloseTF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&package);
1.2776 +
1.2777 + thread.Resume();
1.2778 + sem.Wait();
1.2779 +
1.2780 + TRequestStatus status;
1.2781 + thread.Logon(status);
1.2782 + User::WaitForRequest(status);
1.2783 + test.Printf(_L("Kern-Exec 0 is EXPECTED\n"));
1.2784 + TInt err = thread.ExitReason();
1.2785 + test(err == KErrNone);
1.2786 + TExitType et = thread.ExitType();
1.2787 + test(et == EExitPanic);
1.2788 + CLOSE_AND_WAIT(thread);
1.2789 + sem.Close();
1.2790 + }
1.2791 +
1.2792 +const TInt KNotificationOverflowIterationLimit = 7;
1.2793 +
1.2794 +/*
1.2795 + * Does stuff for TestOverflowL
1.2796 + * Synchronises such that watchers have seen 1 change.
1.2797 + * Then fills their buffers up to KNotificationOverflowIterationLimit.
1.2798 + *
1.2799 + */
1.2800 +TInt TestOverflowDoerTF(TAny* aAny)
1.2801 + {
1.2802 + RFs fs;
1.2803 + fs.Connect();
1.2804 +
1.2805 + SThreadPackage& package = *(SThreadPackage*) aAny;
1.2806 +
1.2807 + TBuf<45> path;
1.2808 + path.Append((TChar)gDriveToTest);
1.2809 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.2810 + path.Append(package.iFileName);
1.2811 +
1.2812 + fs.MkDirAll(path);
1.2813 +
1.2814 + RFile file;
1.2815 + TInt r = file.Replace(fs,path,EFileWrite);
1.2816 + User::LeaveIfError(r);
1.2817 +
1.2818 + //Perform first set size.
1.2819 + r = file.SetSize(1);
1.2820 + User::LeaveIfError(r);
1.2821 +
1.2822 + //Wait until both watchers have received this change.
1.2823 + package.iBarrier.Wait();
1.2824 +
1.2825 + for(TInt i = 0; i< KNotificationOverflowIterationLimit; i++)
1.2826 + {
1.2827 + file.SetSize(i);
1.2828 + }
1.2829 +
1.2830 + file.Close();
1.2831 + fs.Close();
1.2832 + return KErrNone;
1.2833 + }
1.2834 +
1.2835 +/*
1.2836 + * Thread function used as part of TestOverflowL
1.2837 + * Counts the number of notifications and ensures it the correct number before overflow is received#
1.2838 + */
1.2839 +TInt TestOverflowWatcher1TF(TAny* aAny)
1.2840 + {
1.2841 + CTrapCleanup* cleanup;
1.2842 + cleanup = CTrapCleanup::New();
1.2843 +
1.2844 + RTest overflowTest(_L("TestOverflowWatcher1TF"));
1.2845 + overflowTest.Start(_L("TestOverflowWatcher1TF"));
1.2846 +
1.2847 + SThreadPackage& package = *(SThreadPackage*) aAny;
1.2848 + RFs fs;
1.2849 + fs.Connect();
1.2850 + TBuf<45> path;
1.2851 + TBuf<20> filename;
1.2852 + path.Append((TChar)gDriveToTest);
1.2853 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.2854 + filename.Append(package.iFileName);
1.2855 +
1.2856 + TRequestStatus status;
1.2857 + CFsNotify* notify = NULL;
1.2858 +
1.2859 + //This notification's size is 80.
1.2860 + //80*7 = 560.
1.2861 + // -4 means we should get 6 notifications
1.2862 + //Except the first one will still be in the buffer
1.2863 + // (as we've not called RequestNotification yet) so we'll only actually get 5.
1.2864 + TRAPD(r, notify = CFsNotify::NewL(fs,(80*7)-4));
1.2865 + test(r == KErrNone);
1.2866 + User::LeaveIfNull(notify);
1.2867 + notify->AddNotification(TFsNotification::EFileChange,path,filename);
1.2868 + notify->RequestNotifications(status);
1.2869 +
1.2870 + //Signal that we are ready for doer to start (W1)
1.2871 + package.iBarrier.Signal();
1.2872 +
1.2873 + //We wait for the 1 notification (doer only does 1 at first)
1.2874 + User::WaitForRequest(status);
1.2875 +
1.2876 + overflowTest.Next(_L("Overflow- Get First Notification (Start framework)"));
1.2877 + const TFsNotification *notification = notify->NextNotification();
1.2878 +
1.2879 + TFsNotification::TFsNotificationType type = notification->NotificationType();
1.2880 + overflowTest.Printf(_L("Overflow - First Notification Type = %d\n"),type);
1.2881 +
1.2882 + //Signal the test thread (W2)
1.2883 + package.iBarrier.Signal();
1.2884 + //Wait for Signal to continue (W3);
1.2885 + package.iBarrier.Wait();
1.2886 +
1.2887 + notify->RequestNotifications(status);
1.2888 + User::WaitForRequest(status);
1.2889 +
1.2890 + TInt count = 0;
1.2891 + overflowTest.Next(_L("Overflow- Get the rest of the notifications"));
1.2892 + notification = notify->NextNotification();
1.2893 + while(notification != NULL)
1.2894 + {
1.2895 +
1.2896 + type = notification->NotificationType();
1.2897 + overflowTest.Printf(_L("Overflow - NotificationType = %d\n"),type);
1.2898 + if(type & TFsNotification::EOverflow)
1.2899 + {
1.2900 + delete notify;
1.2901 + fs.Close();
1.2902 + overflowTest.Printf(_L("Overflow +- Count = %d\n"),count);
1.2903 + overflowTest.End();
1.2904 + overflowTest.Close();
1.2905 + return count;
1.2906 + }
1.2907 +
1.2908 + notification = notify->NextNotification();
1.2909 + count++;
1.2910 + }
1.2911 + overflowTest.Printf(_L("Overflow -- Count = %d\n"),count);
1.2912 +
1.2913 + overflowTest.End();
1.2914 + overflowTest.Close();
1.2915 + delete notify;
1.2916 + delete cleanup;
1.2917 + fs.Close();
1.2918 + return -1;
1.2919 + }
1.2920 +
1.2921 +
1.2922 +/*
1.2923 + * Overflow test
1.2924 + * As some of the tests above assume sucess if they receive an overflow
1.2925 + * we need to ensure that overflow works properly!
1.2926 + */
1.2927 +TInt TestOverflowL()
1.2928 + {
1.2929 + /*
1.2930 + * The scheme used is as follows:
1.2931 + * 1 Doer thread which is setting the size of a file, over and over.
1.2932 + * 1 watcher thread.
1.2933 + *
1.2934 + * The doer thread does 1 operation then waits on a signal.
1.2935 + * The watcher thread requests notification and receives 1 notification.
1.2936 + * It then signals the Doer thread.
1.2937 + *
1.2938 + * The doer thread continues doing setsize until the number of notifications
1.2939 + * should have overflowed.
1.2940 + *
1.2941 + * The watcher Waits for a signal from doer (that all of the notifications have been sent).
1.2942 + * The watcher's last notification should be an overflow
1.2943 + */
1.2944 + test.Next(_L("TestOverflow"));
1.2945 + RFs fs;
1.2946 + TInt r = fs.Connect();
1.2947 + test(r == KErrNone);
1.2948 + _LIT(KFileName,"over.flow");
1.2949 + SThreadPackage doerPkg;
1.2950 + doerPkg.iFileName = KFileName;
1.2951 +
1.2952 + SThreadPackage watcher1Pkg;
1.2953 + watcher1Pkg.iFileName = KFileName;
1.2954 +
1.2955 + User::LeaveIfError(doerPkg.iBarrier.CreateLocal(0));
1.2956 + User::LeaveIfError(watcher1Pkg.iBarrier.CreateLocal(0));
1.2957 + RThread watcher1;
1.2958 + RThread doer;
1.2959 + watcher1.Create(_L("TestOverflowWatcher1Thread"),TestOverflowWatcher1TF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcher1Pkg);
1.2960 + doer.Create(_L("TestOverflowDoerThread"),TestOverflowDoerTF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&doerPkg);
1.2961 + watcher1.Resume();
1.2962 +
1.2963 + //Wait until Request has been requested. (W1)
1.2964 + watcher1Pkg.iBarrier.Wait();
1.2965 +
1.2966 + doer.Resume();
1.2967 +
1.2968 + //Wait till watcher has received first notification (W2)
1.2969 + watcher1Pkg.iBarrier.Wait();
1.2970 +
1.2971 + //Signal the doer that it is free to continue
1.2972 + //doing the rest of the operations
1.2973 + doerPkg.iBarrier.Signal();
1.2974 +
1.2975 + test.Next(_L("TestOverflow - Wait for doer thread death"));
1.2976 + TRequestStatus status;
1.2977 + doer.Logon(status);
1.2978 + User::WaitForRequest(status);
1.2979 + test(doer.ExitReason()==KErrNone);
1.2980 + CLOSE_AND_WAIT(doer);
1.2981 +
1.2982 + //Wait until doer has finished doing notifications
1.2983 + //thus the watcher should receive an overflow
1.2984 + // (W3)
1.2985 + watcher1Pkg.iBarrier.Signal();
1.2986 +
1.2987 + RTimer tim;
1.2988 + r = tim.CreateLocal();
1.2989 + test(r==KErrNone);
1.2990 + TRequestStatus timStatus;
1.2991 +
1.2992 + test.Next(_L("TestOverflow - Wait for watcher1 thread death"));
1.2993 + TTimeIntervalMicroSeconds32 interval = 10000000; //10 seconds
1.2994 + tim.After(timStatus,interval);
1.2995 + watcher1.Logon(status);
1.2996 + User::WaitForRequest(status,timStatus);
1.2997 + test(status != KRequestPending);
1.2998 + /*
1.2999 + * The number of notifications returned here should be 5.
1.3000 + * This is because :
1.3001 + *
1.3002 + * The first notification means that the buffer has lost 80 (the size of this
1.3003 + * particular notification). Even though the client has read it becase they've not called
1.3004 + * RequestNotification the server doesn't know that yet so that's why it's 5 not 6.
1.3005 + *
1.3006 + * That leaves 556 - 80. Which means only 5 notifications will fit.
1.3007 + */
1.3008 + TInt count = watcher1.ExitReason();
1.3009 + test(count==5);
1.3010 +
1.3011 + CLOSE_AND_WAIT(watcher1);
1.3012 + watcher1Pkg.iBarrier.Close();
1.3013 + doerPkg.iBarrier.Close();
1.3014 + fs.Close();
1.3015 + tim.Close();
1.3016 + return KErrNone;
1.3017 + }
1.3018 +
1.3019 +/*
1.3020 + * Does stuff for TestPostOverflowL
1.3021 + * Synchronises such that watchers have seen 1 change.
1.3022 + * Then fills their buffers up to KNotificationOverflowIterationLimit.
1.3023 + * Then continues to request changes and akes sure that it gets 3 non-overflow notifications
1.3024 + * For DEF140387.
1.3025 + */
1.3026 +TInt TestPostOverflowDoerTF(TAny* aAny)
1.3027 + {
1.3028 + RFs fs;
1.3029 + fs.Connect();
1.3030 +
1.3031 + SThreadPackage& package = *(SThreadPackage*) aAny;
1.3032 +
1.3033 + TBuf<45> path;
1.3034 + path.Append((TChar)gDriveToTest);
1.3035 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.3036 + path.Append(package.iFileName);
1.3037 +
1.3038 + fs.MkDirAll(path);
1.3039 +
1.3040 + RFile file;
1.3041 + TInt r = file.Replace(fs,path,EFileWrite);
1.3042 + User::LeaveIfError(r);
1.3043 +
1.3044 + //Perform first set size.
1.3045 + r = file.SetSize(1);
1.3046 + User::LeaveIfError(r);
1.3047 +
1.3048 + //Wait until both watchers have received this change.
1.3049 + //D-W-1
1.3050 + package.iBarrier.Wait();
1.3051 +
1.3052 + for(TInt i = 0; i< KNotificationOverflowIterationLimit; i++)
1.3053 + {
1.3054 + file.SetSize(i);
1.3055 + }
1.3056 +
1.3057 + file.Close();
1.3058 + fs.Close();
1.3059 + return KErrNone;
1.3060 + }
1.3061 +
1.3062 +TInt HandlePostOverflow(SThreadPackage& aPackage, CFsNotify* aNotify)
1.3063 + {
1.3064 + TRequestStatus status;
1.3065 + TInt r = aNotify->RequestNotifications(status);
1.3066 + test(r == KErrNone);
1.3067 + //Signal that overflow has been found (W4)
1.3068 + aPackage.iBarrier.Signal();
1.3069 +
1.3070 + User::WaitForRequest(status);
1.3071 +
1.3072 + const TFsNotification* notification = NULL;
1.3073 + TInt count = 1;
1.3074 +
1.3075 + notification = aNotify->NextNotification();
1.3076 + test(notification != NULL);
1.3077 +
1.3078 + //3 set sizes will be done (Sx)
1.3079 + aPackage.iBarrier.Wait();
1.3080 +
1.3081 + while(count < 3)
1.3082 + {
1.3083 + TUint type = notification->NotificationType();
1.3084 + if(type & TFsNotification::EOverflow)
1.3085 + {
1.3086 + return KErrOverflow;
1.3087 + }
1.3088 + notification = aNotify->NextNotification();
1.3089 + if(notification == NULL)
1.3090 + {
1.3091 + r = aNotify->RequestNotifications(status);
1.3092 + test(r == KErrNone);
1.3093 + User::WaitForRequest(status);
1.3094 + notification = aNotify->NextNotification();
1.3095 + }
1.3096 + test(notification != NULL);
1.3097 + count++;
1.3098 + }
1.3099 + return count;
1.3100 + }
1.3101 +
1.3102 +
1.3103 +/*
1.3104 + * Thread function used as part of TestOverflowL
1.3105 + * Counts the number of notifications and ensures it the correct number before overflow is received#
1.3106 + */
1.3107 +TInt TestPostOverflowWatcher1TF(TAny* aAny)
1.3108 + {
1.3109 + CTrapCleanup* cleanup;
1.3110 + cleanup = CTrapCleanup::New();
1.3111 +
1.3112 + RTest overflowTest(_L("TestOverflowWatcher1TF"));
1.3113 + overflowTest.Start(_L("TestOverflowWatcher1TF"));
1.3114 +
1.3115 + SThreadPackage& package = *(SThreadPackage*) aAny;
1.3116 + RFs fs;
1.3117 + fs.Connect();
1.3118 + TBuf<45> path;
1.3119 + TBuf<20> filename;
1.3120 + path.Append((TChar)gDriveToTest);
1.3121 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.3122 + filename.Append(package.iFileName);
1.3123 +
1.3124 + TRequestStatus status;
1.3125 + CFsNotify* notify = NULL;
1.3126 +
1.3127 + //This notification's size is 80.
1.3128 + //80*7 = 560.
1.3129 + // -4 means we should get 6 notifications
1.3130 + //Except the first one will still be in the buffer
1.3131 + // (as we've not called RequestNotification yet) so we'll only actually get 5.
1.3132 + TRAPD(r, notify = CFsNotify::NewL(fs,(80*7)-4));
1.3133 + test(r == KErrNone);
1.3134 + User::LeaveIfNull(notify);
1.3135 + notify->AddNotification(TFsNotification::EFileChange,path,filename);
1.3136 + notify->RequestNotifications(status);
1.3137 +
1.3138 + //Signal that we are ready for doer to start (W1)
1.3139 + package.iBarrier.Signal();
1.3140 +
1.3141 + //We wait for the 1 notification (doer only does 1 at first)
1.3142 + User::WaitForRequest(status);
1.3143 +
1.3144 + overflowTest.Next(_L("Overflow- Get First Notification (Start framework)"));
1.3145 + const TFsNotification *notification = notify->NextNotification();
1.3146 +
1.3147 + TFsNotification::TFsNotificationType type = notification->NotificationType();
1.3148 + overflowTest.Printf(_L("Overflow - First Notification Type = %d\n"),type);
1.3149 +
1.3150 + //Signal the test thread (W2)
1.3151 + package.iBarrier.Signal();
1.3152 + //Wait for Signal to continue (W3);
1.3153 + package.iBarrier.Wait();
1.3154 +
1.3155 + notify->RequestNotifications(status);
1.3156 + User::WaitForRequest(status);
1.3157 +
1.3158 + TInt handlePostOverflow = 0;
1.3159 + TInt count = 0;
1.3160 + overflowTest.Next(_L("Overflow- Get the rest of the notifications"));
1.3161 + notification = notify->NextNotification();
1.3162 + while(notification != NULL)
1.3163 + {
1.3164 +
1.3165 + type = notification->NotificationType();
1.3166 + overflowTest.Printf(_L("Overflow - NotificationType = %d\n"),type);
1.3167 + if(type & TFsNotification::EOverflow)
1.3168 + {
1.3169 + overflowTest.Printf(_L("Overflow +- Count = %d\n"),count);
1.3170 + if(handlePostOverflow)
1.3171 + {
1.3172 + count = HandlePostOverflow(package,notify);
1.3173 + }
1.3174 + delete notify;
1.3175 + fs.Close();
1.3176 + overflowTest.End();
1.3177 + overflowTest.Close();
1.3178 + return count;
1.3179 + }
1.3180 + notification = notify->NextNotification();
1.3181 + count++;
1.3182 +
1.3183 + if(count==5)
1.3184 + handlePostOverflow = 1;
1.3185 + }
1.3186 + overflowTest.Printf(_L("Overflow -- Count = %d\n"),count);
1.3187 +
1.3188 + overflowTest.End();
1.3189 + overflowTest.Close();
1.3190 + delete notify;
1.3191 + delete cleanup;
1.3192 + fs.Close();
1.3193 + return -1;
1.3194 + }
1.3195 +
1.3196 +
1.3197 +TInt TestPostOverflowNotifications()
1.3198 + {
1.3199 + test.Next(_L("TestPostOverflowNotifications"));
1.3200 + RFs fs;
1.3201 + TInt r = fs.Connect();
1.3202 + test(r == KErrNone);
1.3203 + _LIT(KFileName,"post.over");
1.3204 + SThreadPackage doerPkg;
1.3205 + doerPkg.iFileName = KFileName;
1.3206 +
1.3207 + SThreadPackage watcher1Pkg;
1.3208 + watcher1Pkg.iFileName = KFileName;
1.3209 +
1.3210 + User::LeaveIfError(doerPkg.iBarrier.CreateLocal(0));
1.3211 + User::LeaveIfError(watcher1Pkg.iBarrier.CreateLocal(0));
1.3212 + RThread watcher1;
1.3213 + RThread doer;
1.3214 + watcher1.Create(_L("TestPostOverflowWatcher1Thread"),TestPostOverflowWatcher1TF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&watcher1Pkg);
1.3215 + doer.Create(_L("TestPostOverflowDoerThread"),TestPostOverflowDoerTF,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,&doerPkg);
1.3216 + watcher1.Resume();
1.3217 +
1.3218 + //Wait until Request has been requested. (W1)
1.3219 + watcher1Pkg.iBarrier.Wait();
1.3220 +
1.3221 + doer.Resume();
1.3222 +
1.3223 + //Wait till watcher has received first notification (W2)
1.3224 + watcher1Pkg.iBarrier.Wait();
1.3225 +
1.3226 + //Signal the doer that it is free to continue
1.3227 + //doing the rest of the operations (D-W-1)
1.3228 + doerPkg.iBarrier.Signal();
1.3229 +
1.3230 + test.Next(_L("TestOverflow - Wait for doer thread death"));
1.3231 + TRequestStatus status;
1.3232 + doer.Logon(status);
1.3233 + User::WaitForRequest(status);
1.3234 + test(doer.ExitReason()==KErrNone);
1.3235 + CLOSE_AND_WAIT(doer);
1.3236 +
1.3237 + //Wait until doer has finished doing notifications
1.3238 + //thus the watcher should receive an overflow
1.3239 + // (W3)
1.3240 + watcher1Pkg.iBarrier.Signal();
1.3241 +
1.3242 +
1.3243 + //wait for the watcher to have processed the first overflow
1.3244 + //and to have requested notification.
1.3245 + //Then we will perform some actions here
1.3246 + // The watcher will wait on the semaphore until we are doing
1.3247 + // doing all the operations we want to do
1.3248 + // then it should process next notification
1.3249 + watcher1Pkg.iBarrier.Wait(); //W4
1.3250 +
1.3251 + TBuf<45> path;
1.3252 + path.Append((TChar)gDriveToTest);
1.3253 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.3254 + path.Append(watcher1Pkg.iFileName);
1.3255 + RFile file;
1.3256 + r = file.Open(fs,path,EFileWrite);
1.3257 + test(r==KErrNone);
1.3258 +
1.3259 + r = file.SetSize(1);
1.3260 + test(r==KErrNone);
1.3261 + r = file.SetSize(2);
1.3262 + test(r==KErrNone);
1.3263 + r = file.SetSize(3);
1.3264 + test(r==KErrNone);
1.3265 + file.Close();
1.3266 +
1.3267 + watcher1Pkg.iBarrier.Signal(); // Signal post operations complete (Sx)
1.3268 +
1.3269 + RTimer tim;
1.3270 + r = tim.CreateLocal();
1.3271 + test(r==KErrNone);
1.3272 + TRequestStatus timStatus;
1.3273 +
1.3274 + test.Next(_L("TestOverflow - Wait for watcher1 thread death"));
1.3275 + TTimeIntervalMicroSeconds32 interval = 10000000; //10 seconds
1.3276 + tim.After(timStatus,interval);
1.3277 + watcher1.Logon(status);
1.3278 + User::WaitForRequest(status,timStatus);
1.3279 + test(status != KRequestPending);
1.3280 + /*
1.3281 + * The number of notifications returned here should be 3.
1.3282 + * This is because :
1.3283 + *
1.3284 + * The first notification means that the buffer has lost 80 (the size of this
1.3285 + * particular notification). Even though the client has read it becase they've not called
1.3286 + * RequestNotification the server doesn't know that yet so that's why it's 5 not 6.
1.3287 + *
1.3288 + * That leaves 556 - 80. Which means only 5 notifications will fit.
1.3289 + *
1.3290 + * Then overflow occurs.
1.3291 + *
1.3292 + * Then count is reset and 3 more operations are performed.
1.3293 + */
1.3294 + TInt count = watcher1.ExitReason();
1.3295 + test(count==3);
1.3296 +
1.3297 + CLOSE_AND_WAIT(watcher1);
1.3298 + watcher1Pkg.iBarrier.Close();
1.3299 + doerPkg.iBarrier.Close();
1.3300 + fs.Close();
1.3301 + tim.Close();
1.3302 + return KErrNone;
1.3303 + }
1.3304 +
1.3305 +/*
1.3306 + * Call AddNotification with a file without a path nor drive
1.3307 + */
1.3308 +void TestNonDriveFilters()
1.3309 + {
1.3310 + test.Next(_L("TestNonDriveFilters"));
1.3311 + RFs fs;
1.3312 + TInt r = fs.Connect();
1.3313 + test(r==KErrNone);
1.3314 +
1.3315 + TDriveList drives;
1.3316 + r = fs.DriveList(drives);
1.3317 + test(r==KErrNone);
1.3318 +
1.3319 + CFsNotify* notify = NULL;
1.3320 + TRAP(r,notify= CFsNotify::NewL(fs,KMinNotificationBufferSize));
1.3321 +
1.3322 + TBuf<20> testfile;
1.3323 + testfile.Append(_L("test.file"));
1.3324 +
1.3325 + r = notify->AddNotification((TUint)TFsNotification::ECreate,_L(""),testfile);
1.3326 + test(r==KErrNone);
1.3327 +
1.3328 + TRequestStatus status;
1.3329 + r = notify->RequestNotifications(status);
1.3330 + test(r==KErrNone);
1.3331 +
1.3332 + TBuf<40> path;
1.3333 + path.Append((TChar)gDriveToTest);
1.3334 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.3335 +
1.3336 + TBuf<40> fullname;
1.3337 + fullname.Append(path);
1.3338 + fullname.Append(testfile);
1.3339 +
1.3340 + RFile file;
1.3341 + r = fs.MkDirAll(path);
1.3342 + test(r==KErrNone || r==KErrAlreadyExists);
1.3343 + r = file.Replace(fs,fullname,EFileWrite);
1.3344 + test(r==KErrNone);
1.3345 + file.Close();
1.3346 +
1.3347 + fs.Delete(fullname);
1.3348 +
1.3349 + TChar testDrive = (TChar)gDriveToTest;
1.3350 + testDrive.UpperCase();
1.3351 +
1.3352 + //Also create the file on another drive;
1.3353 + for(TInt i = 0; i < KMaxDrives; i++)
1.3354 + {
1.3355 + TChar drive = drives[i];
1.3356 + if(drive == testDrive)
1.3357 + continue;
1.3358 +
1.3359 + if(drive)
1.3360 + {
1.3361 + TText16 drive16 = (TText16)(i+(TChar)'A');
1.3362 + fullname.operator [](0) = drive16;
1.3363 + break;
1.3364 + }
1.3365 + }
1.3366 +
1.3367 + r = fs.MkDirAll(fullname);
1.3368 + test(r==KErrNone || r==KErrAlreadyExists);
1.3369 + r = file.Replace(fs,fullname,EFileWrite);
1.3370 + test(r==KErrNone);
1.3371 + file.Close();
1.3372 +
1.3373 + RTimer timer1;
1.3374 + r = timer1.CreateLocal();
1.3375 + test(r == KErrNone);
1.3376 + TRequestStatus timeout;
1.3377 + TTimeIntervalMicroSeconds32 time = 10000000; //10 seconds
1.3378 + timer1.After(timeout,time);
1.3379 + User::WaitForRequest(timeout,status);
1.3380 + test(status.Int() != KRequestPending);
1.3381 + timer1.Cancel();
1.3382 + timer1.Close();
1.3383 +
1.3384 + const TFsNotification* notification = notify->NextNotification();
1.3385 + test(notification != NULL);
1.3386 + TPtrC _path;
1.3387 + r = notification->Path(_path);
1.3388 + test(r==KErrNone);
1.3389 + TChar driveletter = _path[0];
1.3390 + driveletter.UpperCase();
1.3391 + test(driveletter == (TChar)gDriveToTest);
1.3392 +
1.3393 + if(notification = notify->NextNotification(), notification==NULL)
1.3394 + {
1.3395 + TRequestStatus status2;
1.3396 + r = notify->RequestNotifications(status2);
1.3397 + test(r==KErrNone);
1.3398 +
1.3399 + RTimer timer2;
1.3400 + r = timer2.CreateLocal();
1.3401 + test(r == KErrNone);
1.3402 + TRequestStatus timeout2;
1.3403 + TTimeIntervalMicroSeconds32 time2 = 10000000; //10 seconds
1.3404 + timer2.After(timeout2,time2);
1.3405 + User::WaitForRequest(timeout2,status2);
1.3406 + test(status2.Int() != KRequestPending);
1.3407 + timer2.Cancel();
1.3408 + timer2.Close();
1.3409 +
1.3410 + notification = notify->NextNotification();
1.3411 + }
1.3412 + test(notification != NULL);
1.3413 + r = notification->Path(_path);
1.3414 + test(r==KErrNone);
1.3415 + driveletter = _path[0];
1.3416 + driveletter.UpperCase();
1.3417 + test(driveletter == (TChar)'C');
1.3418 +
1.3419 + delete notify;
1.3420 + fs.Close();
1.3421 + }
1.3422 +
1.3423 +// Negative testing for directory without *
1.3424 +// We receive no notifications for files changed under the directory
1.3425 +void NegativeTestDirStar()
1.3426 + {
1.3427 + RFs fs;
1.3428 + TInt r = fs.Connect();
1.3429 + test(r==KErrNone);
1.3430 +
1.3431 + CFsNotify* notify = NULL;
1.3432 + TRAP(r,notify= CFsNotify::NewL(fs,KMinNotificationBufferSize));
1.3433 +
1.3434 + TBuf<40> path;
1.3435 + path.Append((TChar)gDriveToTest);
1.3436 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.3437 + r = fs.MkDirAll(path);
1.3438 + test(r == KErrNone || r == KErrAlreadyExists);
1.3439 +
1.3440 + r = notify->AddNotification((TUint)TFsNotification::ECreate,path,_L(""));
1.3441 + test(r==KErrNone);
1.3442 +
1.3443 + TRequestStatus status;
1.3444 + r = notify->RequestNotifications(status);
1.3445 + test(r==KErrNone);
1.3446 +
1.3447 + TBuf<40> filename;
1.3448 + filename.Append((TChar)gDriveToTest);
1.3449 + filename.Append(_L(":\\F32-TST\\T_NOTIFIER\\dir.star"));
1.3450 +
1.3451 + RFile file;
1.3452 + r = file.Replace(fs,filename,EFileWrite);
1.3453 + test(r==KErrNone);
1.3454 + file.Close();
1.3455 +
1.3456 + RTimer timer1;
1.3457 + r = timer1.CreateLocal();
1.3458 + test(r == KErrNone);
1.3459 + TRequestStatus timeout;
1.3460 + TTimeIntervalMicroSeconds32 time = 2000000; //2 seconds
1.3461 + timer1.After(timeout,time);
1.3462 + User::WaitForRequest(timeout,status);
1.3463 + test(status.Int() == KRequestPending);
1.3464 + timer1.Cancel();
1.3465 + timer1.Close();
1.3466 +
1.3467 + const TFsNotification* notification = notify->NextNotification();
1.3468 + test(notification == NULL);
1.3469 +
1.3470 + delete notify;
1.3471 + fs.Close();
1.3472 + }
1.3473 +
1.3474 +/*
1.3475 + * Negative Testing
1.3476 + */
1.3477 +void NegativeTests()
1.3478 + {
1.3479 + test.Next(_L("Negative Tests"));
1.3480 + //1
1.3481 + test.Printf(_L("NegativeTests() A\n"));
1.3482 + RFs fs;
1.3483 + CFsNotify* notify = NULL;
1.3484 + TInt r = fs.Connect();
1.3485 + test(r == KErrNone);
1.3486 + TRAP(r,notify = CFsNotify::NewL(fs,0));
1.3487 + test(notify != NULL);
1.3488 + delete notify;
1.3489 + notify = NULL;
1.3490 +
1.3491 + //2
1.3492 + test.Printf(_L("NegativeTests() B\n"));
1.3493 + TRAP(r,notify = CFsNotify::NewL(fs,-1));
1.3494 + test(notify != NULL);
1.3495 + delete notify;
1.3496 + notify = NULL;
1.3497 +
1.3498 + test.Printf(_L("NegativeTests() C\n"));
1.3499 + TRAP(r,notify = CFsNotify::NewL(fs,KMaxTInt));
1.3500 + test(r==KErrArgument);
1.3501 + test(notify==NULL);
1.3502 +
1.3503 + //3
1.3504 + test.Printf(_L("NegativeTests() D\n"));
1.3505 + TBuf<40> path;
1.3506 + path.Append((TChar)gDriveToTest);
1.3507 + path.Append(_L(":\\F32-TST\\T_NOTIFIER\\"));
1.3508 + TBuf<20> filename;
1.3509 + filename.Append(_L("file.txt"));
1.3510 + TRAP(r,notify = CFsNotify::NewL(fs,KMinNotificationBufferSize));
1.3511 + test(r==KErrNone);
1.3512 + test(notify!=NULL);
1.3513 + r = notify->AddNotification(0,path,filename);
1.3514 + test(r == KErrArgument);
1.3515 +
1.3516 + test.Printf(_L("NegativeTests() E\n"));
1.3517 + r = notify->AddNotification((TUint)0x8000,path,filename); //invalid value
1.3518 + test(r == KErrArgument);
1.3519 +
1.3520 + test.Printf(_L("NegativeTests() F\n"));
1.3521 + TBuf<40> invalidPath;
1.3522 + invalidPath.Append(_L("1:\\*"));
1.3523 + r = notify->AddNotification((TUint)TFsNotification::ECreate,invalidPath,filename);
1.3524 + test(r == KErrNotFound || r == KErrPathNotFound);
1.3525 +
1.3526 + //4
1.3527 + test.Printf(_L("NegativeTests() G\n"));
1.3528 + TRequestStatus wrongStatus;
1.3529 + wrongStatus = KRequestPending;
1.3530 + r = notify->RequestNotifications(wrongStatus);
1.3531 + test(r == KErrInUse);
1.3532 +
1.3533 + test.Printf(_L("NegativeTests() H\n"));
1.3534 + TRequestStatus status;
1.3535 + r = notify->RequestNotifications(status);
1.3536 + test(r==KErrNone);
1.3537 + r = notify->CancelNotifications(wrongStatus);
1.3538 + test(r == KErrInUse);
1.3539 +
1.3540 + delete notify;
1.3541 + notify = NULL;
1.3542 + fs.Close();
1.3543 + }
1.3544 +
1.3545 +
1.3546 +/*
1.3547 + * RPlugin devired.
1.3548 + * Doesn't actually do anything special.
1.3549 + * Can probably be deleted.
1.3550 + */
1.3551 +class MyRPlugin : public RPlugin
1.3552 + {
1.3553 +public:
1.3554 + void DoRequest(TInt aReqNo,TRequestStatus& aStatus) const;
1.3555 + void DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1) const;
1.3556 + void DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1,TDes8& a2) const;
1.3557 + TInt DoControl(TInt aFunction) const;
1.3558 + TInt DoControl(TInt aFunction,TDes8& a1) const;
1.3559 + TInt DoControl(TInt aFunction,TDes8& a1,TDes8& a2) const;
1.3560 + void DoCancel(TUint aReqMask) const;
1.3561 + };
1.3562 +
1.3563 +void MyRPlugin::DoRequest(TInt aReqNo,TRequestStatus& aStatus) const
1.3564 + {
1.3565 + RPlugin::DoRequest(aReqNo,aStatus);
1.3566 + }
1.3567 +void MyRPlugin::DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1) const
1.3568 + {
1.3569 + RPlugin::DoRequest(aReqNo,aStatus,a1);
1.3570 + }
1.3571 +void MyRPlugin::DoRequest(TInt aReqNo,TRequestStatus& aStatus,TDes8& a1,TDes8& a2) const
1.3572 + {
1.3573 + RPlugin::DoRequest(aReqNo,aStatus,a1,a2);
1.3574 + }
1.3575 +TInt MyRPlugin::DoControl(TInt aFunction) const
1.3576 + {
1.3577 + return RPlugin::DoControl(aFunction);
1.3578 + }
1.3579 +TInt MyRPlugin::DoControl(TInt aFunction,TDes8& a1) const
1.3580 + {
1.3581 + return RPlugin::DoControl(aFunction,a1);
1.3582 + }
1.3583 +TInt MyRPlugin::DoControl(TInt aFunction,TDes8& a1,TDes8& a2) const
1.3584 + {
1.3585 + return RPlugin::DoControl(aFunction,a1,a2);
1.3586 + }
1.3587 +void MyRPlugin::DoCancel(TUint aReqMask) const
1.3588 + {
1.3589 + RPlugin::DoCancel(aReqMask);
1.3590 + }
1.3591 +
1.3592 +/*
1.3593 + * This tests that when file server plugins perform operations that
1.3594 + * the framework doesn't notify about them
1.3595 + */
1.3596 +TInt TestNotificationsWithFServPlugins()
1.3597 + {
1.3598 + TInt r = TheFs.AddPlugin(KNotifyPluginFileName);
1.3599 + test(r==KErrNone || r==KErrAlreadyExists);
1.3600 + r = TheFs.MountPlugin(KNotifyPluginName,(TUint)gDriveToTest.GetUpperCase() - 65);
1.3601 + if (r == KErrNotSupported)
1.3602 + {
1.3603 + test.Printf(_L("Plugins are not supported on pagable drives.\nSkipping test.\n"));
1.3604 + safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.3605 + }
1.3606 +
1.3607 + MyRPlugin rplugin;
1.3608 + TPckgBuf<TChar> drivePckg(gDriveToTest);
1.3609 +
1.3610 + test.Next(_L("Open RPlugin connection for NotifyPlugin"));
1.3611 + r = rplugin.Open(TheFs,KNotifyPos);
1.3612 + safe_test(test,r,__LINE__,(TText*)Expand("t_notify_plugin.cpp"));
1.3613 +
1.3614 + test.Next(_L("Send drive letter to test down to plugin"));
1.3615 + r = rplugin.DoControl(KPluginSetDrive,drivePckg);
1.3616 + safe_test(test,r,__LINE__,(TText*)Expand("t_notify_plugin.cpp"));
1.3617 + rplugin.Close();
1.3618 +
1.3619 + r = SimpleCreateTestL();
1.3620 + safe_test(test,r,__LINE__,(TText*)Expand("t_notifier.cpp"));
1.3621 +
1.3622 + DismountPlugin();
1.3623 + return KErrNone;
1.3624 + }
1.3625 +
1.3626 +/*
1.3627 + * This test is testing the use cases
1.3628 + * and for negative testing of SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION
1.3629 + *
1.3630 + * Performance tests can be found in test t_notify_perf
1.3631 + */
1.3632 +void CallTestsL()
1.3633 + {
1.3634 + CTrapCleanup* cleanup;
1.3635 + cleanup = CTrapCleanup::New();
1.3636 +
1.3637 + globalDriveNum = gDriveToTest - (TChar)'A';
1.3638 +
1.3639 + PrintLine();
1.3640 + test.Start(_L("T_NOTIFIER Test Start"));
1.3641 + TInt r = KErrNone;
1.3642 +
1.3643 + //=========================================================================================
1.3644 + //! @SYMTestCaseID PBASE-T_NOTIFY-2443
1.3645 + //! @SYMTestType CIT
1.3646 + //! @SYMREQ PREQ1847
1.3647 + //! @SYMTestCaseDesc Simple Tests/User Heap Tests
1.3648 + //! @SYMTestStatus Implemented
1.3649 + //=========================================================================================
1.3650 + //
1.3651 + // 1. Create and delete many CFsNotify objects
1.3652 + //
1.3653 + PrintLine();
1.3654 + test.Next(_L("CFsNotify Creation and Delete Tests"));
1.3655 + //Creates and Deletes 1 CFsNotify
1.3656 + __UHEAP_MARK;
1.3657 + r = TestNewDeleteCFsNotify(1);
1.3658 + __UHEAP_MARKEND;
1.3659 + test(r==KErrNone);
1.3660 + //Creates and Deletes 50 CFsNotifys
1.3661 + __UHEAP_MARK;
1.3662 + r = TestNewDeleteCFsNotify(50);
1.3663 + __UHEAP_MARKEND;
1.3664 + test(r==KErrNone);
1.3665 + test.Printf(_L("------- End of User Heap Tests ---------------------------------------\n"));
1.3666 + //
1.3667 + // 2. Add notification for creating a file
1.3668 + // Create that file
1.3669 + //
1.3670 + PrintLine();
1.3671 + __UHEAP_MARK;
1.3672 + r = SimpleCreateTestL();
1.3673 + __UHEAP_MARKEND;
1.3674 + test(r==KErrNone);
1.3675 + test.Printf(_L("------- End of CFsNotify Creation and Delete Tests -------------------\n"));
1.3676 + //
1.3677 + // 3. Add notification at the root of a drive
1.3678 + // Create a file in that drive
1.3679 + //
1.3680 + PrintLine();
1.3681 + TestRootDriveNotifications();
1.3682 + test.Printf(_L("------- End of RootDriveNotifications Test ---------------------------\n"));
1.3683 + //
1.3684 + // 4. Add notification for a filename without a drive
1.3685 + // Create that file in the current drive
1.3686 + // Create that file in another drive
1.3687 + //
1.3688 + PrintLine();
1.3689 + TestNonDriveFilters();
1.3690 + test.Printf(_L("------- End of TestNonDriveFilters Test ------------------------------\n"));
1.3691 + //
1.3692 + // 5. Add notifications for 2 file creations
1.3693 + // Create 2 clients
1.3694 + // The clients create a file each
1.3695 + //
1.3696 + PrintLine();
1.3697 + __UHEAP_MARK;
1.3698 + r = TestTwoDoersL();
1.3699 + __UHEAP_MARKEND;
1.3700 + test(r==KErrNone);
1.3701 + test.Printf(_L("------- End of TwoDoers Test -----------------------------------------\n"));
1.3702 + //
1.3703 + // 6. Create 2 file server sessions
1.3704 + // Add a notification on each session for the same specific file creation
1.3705 + // Create that file
1.3706 + //
1.3707 + PrintLine();
1.3708 + __UHEAP_MARK;
1.3709 + r = TestTwoWatchersL();
1.3710 + __UHEAP_MARKEND;
1.3711 + test(r==KErrNone);
1.3712 + test.Printf(_L("------- End of TwoWatchers Test --------------------------------------\n"));
1.3713 + //
1.3714 + // 7. Create 2 file server sessions and 2 clients
1.3715 + // Add a notification on each session for different file creations
1.3716 + // Clients create a file each
1.3717 + //
1.3718 + PrintLine();
1.3719 + __UHEAP_MARK;
1.3720 + r = TestTwoWatchersTwoDoersL();
1.3721 + __UHEAP_MARKEND;
1.3722 + test(r==KErrNone);
1.3723 + test.Printf(_L("------- End of TwoWatchersTwoDoers Test ------------------------------\n"));
1.3724 + //
1.3725 + // 8. Add notification for a specific file creation
1.3726 + // Cancel the notification request
1.3727 + // Create that file
1.3728 + //
1.3729 + PrintLine();
1.3730 + __UHEAP_MARK;
1.3731 + r = TestCancelNotificationL();
1.3732 + __UHEAP_MARKEND;
1.3733 + test(r==KErrNone);
1.3734 + test.Printf(_L("------- End of CancelNotification Test -------------------------------\n"));
1.3735 + //
1.3736 + // 9. Create 2 file server sessions
1.3737 + // Add a notification on each session for the same specific file creation
1.3738 + // Delete the first notification
1.3739 + // Create that file
1.3740 + //
1.3741 + PrintLine();
1.3742 + test.Next(_L("TestClientRemoval"));
1.3743 + __UHEAP_MARK;
1.3744 + r = TestClientRemovalL();
1.3745 + __UHEAP_MARKEND;
1.3746 + test(r==KErrNone);
1.3747 + test.Printf(_L("------- End of TestClientRemoval Test --------------------------------\n"));
1.3748 + //
1.3749 + // 10. Create a CFsNotify object
1.3750 + // Close the session before closing the subsession
1.3751 + // Add notification and request notifications
1.3752 + //
1.3753 + PrintLine();
1.3754 + __UHEAP_MARK;
1.3755 + // Close session after creating the object
1.3756 + TestSessionClose(1);
1.3757 + __UHEAP_MARKEND;
1.3758 + __UHEAP_MARK;
1.3759 + // Close session after adding the notification
1.3760 + TestSessionClose(2);
1.3761 + __UHEAP_MARKEND;
1.3762 + test.Printf(_L("------- End of TestSessionClose Test ---------------------------------\n"));
1.3763 +
1.3764 +
1.3765 + //=========================================================================================
1.3766 + //! @SYMTestCaseID PBASE-T_NOTIFY-2444
1.3767 + //! @SYMTestType UT
1.3768 + //! @SYMREQ PREQ1847
1.3769 + //! @SYMTestCaseDesc File/Directory Create and Replace – Single File Server Session
1.3770 + //! @SYMTestStatus Implemented
1.3771 + //!
1.3772 + //! TFsNotificationType ECreate
1.3773 + //=========================================================================================
1.3774 + //
1.3775 + // RFile::Create
1.3776 + // 1. Add notification for a specific file creation
1.3777 + // Create that file
1.3778 + //
1.3779 + PrintLine();
1.3780 + test.Next(_L("EFileCreate Tests"));
1.3781 + _LIT(KFilename3,"file.create");
1.3782 + r = TestMultipleNotificationsL(_L(""),KFilename3,5,5,t_notification::EFileCreate,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3783 + test(r==KErrNone);
1.3784 + test.Printf(_L("------- End of EFileCreate Tests -------------------------------------\n"));
1.3785 + //
1.3786 + // RFs::MkDir
1.3787 + // 2. Add notification for a specific directory creation
1.3788 + // Create that directory
1.3789 + //
1.3790 + PrintLine();
1.3791 + test.Next(_L("EFsMkDir Test"));
1.3792 + _LIT(KDirName1,"dirCreate\\");
1.3793 + r = TestMultipleNotificationsL(KDirName1,_L(""),1,1,t_notification::EFsMkDir,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3794 + test(r==KErrNone);
1.3795 + test.Printf(_L("------- End of EFsMkDir Test -----------------------------------------\n"));
1.3796 + //
1.3797 + // RFile::Replace
1.3798 + // 3. Add notification for a specific file creation
1.3799 + // Replace that file
1.3800 + //
1.3801 + PrintLine();
1.3802 + test.Next(_L("EFileReplace Test"));
1.3803 + r = TestMultipleNotificationsL(_L(""),KFilename3,1,1,t_notification::EFileReplace,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3804 + test(r==KErrNone);
1.3805 + test.Printf(_L("------- End of EFileReplace Test -------------------------------------\n"));
1.3806 + //
1.3807 + // 4. Add notification for a specific file creation
1.3808 + // Remove that notification
1.3809 + // Create that file
1.3810 + //
1.3811 + PrintLine();
1.3812 + __UHEAP_MARK;
1.3813 + r = TestAddRemoveNotificationL();
1.3814 + __UHEAP_MARKEND;
1.3815 + test(r==KErrNone);
1.3816 + test.Printf(_L("------- End of Add and Remove Notification Test ----------------------\n"));
1.3817 + //
1.3818 + // Wildcard Create Tests
1.3819 + // 5. Add notification for file creation using wildcard name
1.3820 + // Add notification for file/directory wildcard including subdirectories
1.3821 + // Create number of files and directories that match each notification
1.3822 + //
1.3823 + PrintLine();
1.3824 + test.Next(_L("Wildcard Create Tests"));
1.3825 + //
1.3826 + // Wildcard Name
1.3827 + _LIT(KWildcardName1,"*");
1.3828 + r = TestMultipleNotificationsL(_L(""),KWildcardName1,1,1,t_notification::EFileCreate,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3829 + test(r==KErrNone);
1.3830 + r = TestMultipleNotificationsL(KWildcardName1,KWildcardName1,1,1,t_notification::EFileCreate_subs,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3831 + test(r==KErrNone);
1.3832 + r = TestMultipleNotificationsL(KWildcardName1,KWildcardName1,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)ETrue,__LINE__);
1.3833 + test(r==KErrNone);
1.3834 + //
1.3835 + // Wildcard including Subdirectories
1.3836 + _LIT(KWildcardName2,"*\\");
1.3837 + r = TestMultipleNotificationsL(KWildcardName2,KWildcardName1,1,1,t_notification::EFileCreate,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)ETrue,__LINE__);
1.3838 + test(r==KErrNone);
1.3839 + r = TestMultipleNotificationsL(KWildcardName2,KWildcardName1,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3840 + test(r==KErrNone);
1.3841 + _LIT(KDirName2,"SubDir\\");
1.3842 + _LIT(KWildcardName3,"?");
1.3843 + r = TestMultipleNotificationsL(KDirName2,KWildcardName3,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3844 + test(r==KErrNone);
1.3845 + //
1.3846 + // Wildcard Type
1.3847 + _LIT(KWildcardName4,"*.*");
1.3848 + r = TestMultipleNotificationsL(_L(""),KWildcardName4,1,1,t_notification::EFileCreate_txt_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3849 + test(r==KErrNone);
1.3850 + r = TestMultipleNotificationsL(_L(""),KWildcardName4,1,1,t_notification::EFileCreate_subs_nowatch,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)ETrue,__LINE__);
1.3851 + test(r==KErrNone);
1.3852 + //
1.3853 + // 6. Add notification for file creation for a specific type
1.3854 + // Create file with that type
1.3855 + // Create file with different type
1.3856 + //
1.3857 + _LIT(KWildcardName5,"*.txt");
1.3858 + r = TestMultipleNotificationsL(_L(""),KWildcardName5,1,1,t_notification::EFileCreate_txt,TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3859 + test(r==KErrNone);
1.3860 + test.Printf(_L("------- End of Wildcard Create Tests ---------------------------------\n"));
1.3861 +
1.3862 +
1.3863 + //=============================================================================
1.3864 + //! @SYMTestCaseID PBASE-T_NOTIFY-2445
1.3865 + //! @SYMTestType UT
1.3866 + //! @SYMREQ PREQ1847
1.3867 + //! @SYMTestCaseDesc File Attribute Change – Single File Server Session
1.3868 + //! @SYMTestStatus Implemented
1.3869 + //
1.3870 + // TFsNotificationType EAttribute
1.3871 + //=============================================================================
1.3872 + //
1.3873 + // RFile::SetAtt, RFile::Set and RFs::SetEntry
1.3874 + // 1. Add notification for a specific file attribute change
1.3875 + // Change the attribute for that file
1.3876 + //
1.3877 + PrintLine();
1.3878 + test.Next(_L("Attribute Tests"));
1.3879 + _LIT(KFilename4,"file.setatts");
1.3880 + r = TestMultipleNotificationsL(_L(""),KFilename4,1,1,t_notification::EFileSetAtt,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3881 + test(r==KErrNone);
1.3882 + r = TestMultipleNotificationsL(_L(""),KFilename4,1,1,t_notification::EFileSet,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3883 + test(r==KErrNone);
1.3884 + r = TestMultipleNotificationsL(_L(""),KFilename4,1,1,t_notification::EFsSetEntry,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3885 + test(r==KErrNone);
1.3886 + //
1.3887 + // Wildcard Attribute Test including subdirectories
1.3888 + // 2. Add notification for file attribute change using wildcard name
1.3889 + // Create number of files that match the notification
1.3890 + // Change attributes of some files
1.3891 + //
1.3892 + r = TestMultipleNotificationsL(KWildcardName2,_L("*"),3,3,t_notification::EFileSetAtt_subs,TFsNotification::EAttribute,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3893 + test(r==KErrNone);
1.3894 + test.Printf(_L("------- End of Attribute Tests ---------------------------------------\n"));
1.3895 +
1.3896 +
1.3897 + //=============================================================================
1.3898 + //! @SYMTestCaseID PBASE-T_NOTIFY-2446
1.3899 + //! @SYMTestType UT
1.3900 + //! @SYMREQ PREQ1847
1.3901 + //! @SYMTestCaseDesc File/Directory Rename – Single File Server Session
1.3902 + //! @SYMTestStatus Implemented
1.3903 + //
1.3904 + // TFsNotificationType ERename
1.3905 + //=============================================================================
1.3906 + //
1.3907 + // RFs::Replace, RFs::Rename and RFile::Rename
1.3908 + // 1. Add notification for a specific file rename change
1.3909 + // Rename that file
1.3910 + //
1.3911 + PrintLine();
1.3912 + test.Next(_L("Rename Tests"));
1.3913 + _LIT(KFilename5,"file.rename");
1.3914 + r = TestMultipleNotificationsL(_L(""),KFilename5,1,1,t_notification::EFsReplace,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3915 + test(r==KErrNone);
1.3916 + r = TestMultipleNotificationsL(_L(""),KFilename5,1,1,t_notification::EFsRename,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3917 + test(r==KErrNone);
1.3918 + r = TestMultipleNotificationsL(_L(""),KFilename5,1,1,t_notification::EFileRename,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3919 + test(r==KErrNone);
1.3920 + //
1.3921 + // 2. Add notification for a specific directory rename
1.3922 + // Rename that directory
1.3923 + //
1.3924 + _LIT(KDirName3,"dirRename\\");
1.3925 + r = TestMultipleNotificationsL(KDirName3,_L(""),1,1,t_notification::EFsRename_dir,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3926 + test(r==KErrNone);
1.3927 + //
1.3928 + // 3. Add notification for file rename using wildcard name
1.3929 + // Create file that match the notification
1.3930 + // Repeatedly rename the file
1.3931 + //
1.3932 + r = TestMultipleNotificationsL(_L(""),KWildcardName1,3,3,t_notification::EFileRename_wild,TFsNotification::ERename,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3933 + test(r==KErrNone);
1.3934 + test.Printf(_L("------- End of Rename Tests ------------------------------------------\n"));
1.3935 +
1.3936 +
1.3937 + //=============================================================================
1.3938 + //! @SYMTestCaseID PBASE-T_NOTIFY-2447
1.3939 + //! @SYMTestType UT
1.3940 + //! @SYMREQ PREQ1847
1.3941 + //! @SYMTestCaseDesc File/Directory Delete – Single File Server Session
1.3942 + //! @SYMTestStatus Implemented
1.3943 + //
1.3944 + // TFsNotificationType EDelete
1.3945 + //=============================================================================
1.3946 + //
1.3947 + // RFs::Delete
1.3948 + // 1. Add notification for a specific file delete
1.3949 + // Delete that file
1.3950 + //
1.3951 + PrintLine();
1.3952 + test.Next(_L("EFsDelete Test"));
1.3953 + _LIT(KFilename6,"file.delete");
1.3954 + r = TestMultipleNotificationsL(_L(""),KFilename6,1,1,t_notification::EFsDelete,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3955 + test(r==KErrNone);
1.3956 + //
1.3957 + // RFs::RmDir
1.3958 + // 2. Add notification for a specific directory delete
1.3959 + // Delete that directory
1.3960 + //
1.3961 + PrintLine();
1.3962 + test.Next(_L("EFsRmDir Tests"));
1.3963 + _LIT(KDirName4,"dirRemove\\");
1.3964 + r = TestMultipleNotificationsL(KDirName4,_L(""),1,1,t_notification::EFsRmDir,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3965 + test(r==KErrNone);
1.3966 + //
1.3967 + // This test should not receive any notifications because a non-empty directory cannot be removed
1.3968 + // 3. Add notification for specific directory delete
1.3969 + // Create files inside that directory
1.3970 + // Delete the directory
1.3971 + //
1.3972 + _LIT(KDirName5,"dirRmNonEmp\\");
1.3973 + r = TestMultipleNotificationsL(KDirName5,_L(""),1,1,t_notification::EFsRmDir_nonEmpty,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)ETrue,__LINE__);
1.3974 + test(r==KErrNone);
1.3975 + //
1.3976 + // Wildcard Name ("*")
1.3977 + // 4. Add notification for directory delete using wildcard name
1.3978 + // Create directory that match the notification
1.3979 + // Delete that directory
1.3980 + //
1.3981 + r = TestMultipleNotificationsL(KWildcardName1,_L(""),1,1,t_notification::EFsRmDir_wild,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3982 + test(r==KErrNone);
1.3983 + //
1.3984 + // Wildcard Type ("*.txt")
1.3985 + // Creates files with different types and should only receive notifications from "*.txt" file deletions
1.3986 + // 5. Add notification for file deletes using wildcard type
1.3987 + // Create number of files that match the notification
1.3988 + // Delete those files
1.3989 + //
1.3990 + r = TestMultipleNotificationsL(_L(""),KWildcardName4,3,3,t_notification::EFsDelete,TFsNotification::EDelete,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.3991 + test(r==KErrNone);
1.3992 + test.Printf(_L("------- End of Delete Tests ------------------------------------------\n"));
1.3993 +
1.3994 +
1.3995 + //======================================================================
1.3996 + //! @SYMTestCaseID PBASE-T_NOTIFY-2448
1.3997 + //! @SYMTestType UT
1.3998 + //! @SYMREQ PREQ1847
1.3999 + //! @SYMTestCaseDesc File Change – Single File Server Session
1.4000 + //! @SYMTestStatus Implemented
1.4001 + //
1.4002 + // TFsNotificationType EFileChange
1.4003 + //======================================================================
1.4004 + //
1.4005 + // File Write
1.4006 + // If caching is enabled, notifications are received only when the file cache is flushed
1.4007 + // We flush everytime we do a write to ensure the tests work regardless of cache
1.4008 + //
1.4009 + // 1. Add notification for a specific file change
1.4010 + // Create the file
1.4011 + // Write to that file
1.4012 + //
1.4013 + PrintLine();
1.4014 + test.Next(_L("EFileWrite Tests"));
1.4015 + _LIT(KFilename7,"file.write");
1.4016 + __UHEAP_MARK;
1.4017 + r = TestMultipleNotificationsL(_L(""),KFilename7,7,7,t_notification::EFileWrite,TFsNotification::EFileChange,3*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4018 + __UHEAP_MARKEND;
1.4019 + test(r==KErrNone);
1.4020 + //
1.4021 + // 2. Add notification for a specific file change
1.4022 + // Write to the specified file a number of times without changing its size
1.4023 + //
1.4024 + // Four letters are written to a file, then the first letter in the file is replaced aIterations times
1.4025 + // aMaxNotifications = 1 + aIterations
1.4026 + //
1.4027 + r = TestMultipleNotificationsL(_L(""),KFilename7,3,4,t_notification::EFileWrite_samesize,TFsNotification::EFileChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4028 + test(r==KErrNone);
1.4029 + test.Printf(_L("------- End of EFileWrite Tests --------------------------------------\n"));
1.4030 + //
1.4031 + // 3. Add notification for a specific file change
1.4032 + // Write to that file asynchronously
1.4033 + //
1.4034 + PrintLine();
1.4035 + test.Next(_L("EFileWrite_async Tests"));
1.4036 + _LIT(KFilename8,"async.write");
1.4037 + __UHEAP_MARK;
1.4038 + r = TestMultipleNotificationsL(_L(""),KFilename8,4,4,t_notification::EFileWrite_async,TFsNotification::EFileChange,2*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4039 + __UHEAP_MARKEND;
1.4040 + test(r==KErrNone);
1.4041 + test.Printf(_L("------- End of EFileWrite_async Tests --------------------------------\n"));
1.4042 + //
1.4043 + // File Set Size
1.4044 + // 4. Add notification for a specific file change
1.4045 + // Both increase and decrease the file sizes a number of times
1.4046 + //
1.4047 + // The file size is increased aIterations times, and decreased (aIterations - 1) times
1.4048 + // aMaxNotifications = 2*aIterations - 1
1.4049 + //
1.4050 + PrintLine();
1.4051 + test.Next(_L("EFileSetSize Tests"));
1.4052 + _LIT(KFilename9,"file.setsize");
1.4053 + r = TestMultipleNotificationsL(_L(""),KFilename9,5,9,t_notification::EFileSetSize,TFsNotification::EFileChange,3*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4054 + test(r==KErrNone);
1.4055 + test.Printf(_L("------- End of EFileSetSize Tests ------------------------------------\n"));
1.4056 +
1.4057 +
1.4058 + //
1.4059 + PrintLine();
1.4060 + test.Next(_L("CFileMan Tests"));
1.4061 + _LIT(KFilenameCFMan,"cf1le.man");
1.4062 + TUint notificationTypes = (TUint)TFsNotification::ECreate|TFsNotification::EFileChange|TFsNotification::EAttribute|TFsNotification::EDelete|TFsNotification::ERename;
1.4063 + r = TestMultipleNotificationsL(_L(""),KFilenameCFMan,1,5,t_notification::ECFileManMove,notificationTypes,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4064 + test(r==KErrNone);
1.4065 + test.Printf(_L("------- End of CFileMan Tests -------------------------------------\n"));
1.4066 +
1.4067 +
1.4068 + //========================================================================================
1.4069 + //! @SYMTestCaseID PBASE-T_NOTIFY-2449
1.4070 + //! @SYMTestType UT
1.4071 + //! @SYMREQ PREQ1847
1.4072 + //! @SYMTestCaseDesc File System Mounted/Dismounted, Media Card Removal/Insertion,
1.4073 + // RawDisk Write – Single File Server Session
1.4074 + //! @SYMTestStatus Implemented
1.4075 + //
1.4076 + // TFsNotificationType EMediaChange
1.4077 + //========================================================================================
1.4078 + //
1.4079 + // RFs::DismountFileSystem
1.4080 + // 1. Add notification for media change
1.4081 + // Dismount the file system
1.4082 + //
1.4083 + PrintLine();
1.4084 + test.Next(_L("Mount Tests"));
1.4085 + TFullName filesystemName;
1.4086 + r = TheFs.FileSystemName(filesystemName,globalDriveNum);
1.4087 + test(r==KErrNone);
1.4088 + r = TestMultipleNotificationsL(filesystemName,1,1,t_notification::EDismount,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4089 + test(r==KErrNone);
1.4090 + //
1.4091 + // RFs::MountFileSystem
1.4092 + // 2. Add notification for media change
1.4093 + // Mount the file system
1.4094 + //
1.4095 + r = TestMultipleNotificationsL(filesystemName,1,1,t_notification::EMount,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4096 + test(r==KErrNone);
1.4097 + //
1.4098 + // Repeatedly mount and dismount the file system
1.4099 + // 3. Add notification for media change
1.4100 + // Repeatedly dismount and mount the file system
1.4101 + //
1.4102 + // The file system is dismounted and mounted aIterations times
1.4103 + // aMaxNotifications = 2*aIterations
1.4104 + //
1.4105 + r = TestMultipleNotificationsL(filesystemName,5,10,t_notification::EMountDismount,TFsNotification::EMediaChange,3*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4106 + test(r==KErrNone);
1.4107 + //
1.4108 + // RFs::MountFileSystemAndScan
1.4109 + // 4. Add notification for media change
1.4110 + // Mount and scan the file system
1.4111 + //
1.4112 + // The file system is dismounted and mounted aIterations times
1.4113 + // aMaxNotifications = 2*aIterations
1.4114 + //
1.4115 +//#ifndef __WINS__
1.4116 +// r = TestMultipleNotificationsL(filesystemName,1,2,t_notification::EMountScan,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4117 +// test(r==KErrNone);
1.4118 +//#endif
1.4119 + test.Printf(_L("------- End of Mount Tests -------------------------------------------\n"));
1.4120 + TDriveInfo drvInfo;
1.4121 + TInt driveNum;
1.4122 + TheFs.CharToDrive(gDriveToTest,driveNum);
1.4123 + r = TheFs.Drive(drvInfo,driveNum);
1.4124 + test (r == KErrNone);
1.4125 + TPtrC driveDes((TText*)&gDriveToTest,1);
1.4126 + //
1.4127 + // Manual Tests - Will only run on removable drives
1.4128 + //
1.4129 +/* if(drvInfo.iDriveAtt & KDriveAttRemovable)
1.4130 + {
1.4131 + //
1.4132 + // 5. Add notification for media change
1.4133 + // Remove media card manually
1.4134 + //
1.4135 + PrintLine();
1.4136 + test.Next(_L("Media Card Removal/Insertion Tests"));
1.4137 + r = TestMultipleNotificationsL(driveDes,1,1,t_notification::EMediaCardRemoval,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4138 + test(r==KErrNone);
1.4139 + //
1.4140 + // 6. Add notification for media change
1.4141 + // Insert media card manually
1.4142 + //
1.4143 + r = TestMultipleNotificationsL(driveDes,1,1,t_notification::EMediaCardInsertion,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4144 + test(r==KErrNone);
1.4145 + test.Printf(_L("------- End of Media Card Removal/Insertion Tests --------------------\n"));
1.4146 + //
1.4147 + // We should receive an EMediaChange notification even though we did not register for it
1.4148 + // 7. Do not add notification for media change
1.4149 + // Remove and insert media card manually
1.4150 + //
1.4151 + PrintLine();
1.4152 + TestMediaCardNotificationWhenNotRegisteredForIt();
1.4153 + test.Printf(_L("------- End of TestMediaCardNotificationWhenNotRegisteredForIt -------\n"));
1.4154 + }
1.4155 +*/ //
1.4156 + // RRawDisk::Write
1.4157 + // 8. Add notification for media change
1.4158 + // Write directly to the media
1.4159 + //
1.4160 +#ifdef __WINS__
1.4161 + if(gDriveToTest-(TChar)'A' != 2)
1.4162 +#endif
1.4163 + {
1.4164 + PrintLine();
1.4165 + test.Next(_L("RRawDisk::Write Tests"));
1.4166 + r = TestMultipleNotificationsL(driveDes,1,1,t_notification::ERawDiskWrite,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4167 + test(r==KErrNone);
1.4168 + test.Printf(_L("------- End of RRawDisk::Write Test ------------------------------ \n"));
1.4169 + }
1.4170 +
1.4171 +
1.4172 + //===============================================================================
1.4173 + //! @SYMTestCaseID PBASE-T_NOTIFY-2450
1.4174 + //! @SYMTestType UT
1.4175 + //! @SYMREQ PREQ1847
1.4176 + //! @SYMTestCaseDesc Drive Name Modification – Single File Server Session
1.4177 + //! @SYMTestStatus Implemented
1.4178 + //
1.4179 + // TFsNotificationType EDriveName
1.4180 + //===============================================================================
1.4181 + //
1.4182 + // RFs::SetDriveName
1.4183 + // The drive name is renamed 2*aIterations times
1.4184 + // aMaxNotifications = 2*aIterations
1.4185 + //
1.4186 + // 1. Add notification for a specific drive name change
1.4187 + // Change the drive name
1.4188 + //
1.4189 + PrintLine();
1.4190 + test.Next(_L("DriveName Test"));
1.4191 + r = TestMultipleNotificationsL(driveDes,1,2,t_notification::ESetDriveName,TFsNotification::EDriveName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4192 + test(r==KErrNone);
1.4193 + //
1.4194 + // 2. Add notification for a specific drive name change
1.4195 + // Repeatedly rename the drive
1.4196 + //
1.4197 + r = TestMultipleNotificationsL(driveDes,3,6,t_notification::ESetDriveName,TFsNotification::EDriveName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4198 + test(r==KErrNone);
1.4199 + test.Printf(_L("------- End of DriveName Test ----------------------------------------\n"));
1.4200 +
1.4201 +
1.4202 + //================================================================================
1.4203 + //! @SYMTestCaseID PBASE-T_NOTIFY-2451
1.4204 + //! @SYMTestType UT
1.4205 + //! @SYMREQ PREQ1847
1.4206 + //! @SYMTestCaseDesc Volume Name Modification – Single File Server Session
1.4207 + //! @SYMTestStatus Implemented
1.4208 + //
1.4209 + // TFsNotificationType EVolumeName
1.4210 + //================================================================================
1.4211 + //
1.4212 + // RFs::SetVolumeLabel - Does not run on WINS
1.4213 + // The volume name is renamed 2*aIterations times
1.4214 + // aMaxNotifications = 2*aIterations
1.4215 + //
1.4216 +#ifndef __WINS__
1.4217 + PrintLine();
1.4218 + test.Next(_L("VolumeName Test"));
1.4219 + //
1.4220 + // 1. Add notification for a specific volume name change
1.4221 + // Change the volume name
1.4222 + //
1.4223 + r = TestMultipleNotificationsL(driveDes,1,2,t_notification::ESetVolumeLabel,TFsNotification::EVolumeName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4224 + test(r==KErrNone);
1.4225 + //
1.4226 + // 2. Add notification for a specific volume name change
1.4227 + // Repeatedly rename the volume
1.4228 + //
1.4229 + r = TestMultipleNotificationsL(driveDes,3,6,t_notification::ESetVolumeLabel,TFsNotification::EVolumeName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4230 + test(r==KErrNone);
1.4231 + test.Printf(_L("------- End of VolumeName Test ---------------------------------------\n"));
1.4232 +#endif
1.4233 +
1.4234 +
1.4235 + //=============================================================================
1.4236 + //! @SYMTestCaseID PBASE-T_NOTIFY-2452
1.4237 + //! @SYMTestType UT
1.4238 + //! @SYMREQ PREQ1847
1.4239 + //! @SYMTestCaseDesc All Operations Filter – Single File Server Session
1.4240 + //! @SYMTestStatus Implemented
1.4241 + //
1.4242 + // TFsNotificationType EAllOps
1.4243 + //=============================================================================
1.4244 + PrintLine();
1.4245 + test.Next(_L("AllOps Tests"));
1.4246 + //
1.4247 + // 1. Add notification for all operations
1.4248 + // Create a file
1.4249 + // Delete the file
1.4250 + //
1.4251 + // EAllOps1: A file is created and deleted aIterations times
1.4252 + // aMaxNotification = 2*aIterations
1.4253 + //
1.4254 + _LIT(KFilename10,"file.allops");
1.4255 + r = TestMultipleNotificationsL(_L(""),KFilename10,4,8,t_notification::EAllOps1,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4256 + test(r==KErrNone);
1.4257 + //
1.4258 + // 2. Add notification for all operations
1.4259 + // Create a file
1.4260 + // Write to the file
1.4261 + // Delete the file
1.4262 + //
1.4263 + // EAllOps2: A file is created, written to aIterations times and then deleted
1.4264 + // aMaxNotification = 2 + aIterations (See File Write Tests)
1.4265 + //
1.4266 + r = TestMultipleNotificationsL(_L(""),KFilename10,4,6,t_notification::EAllOps2,(TUint)TFsNotification::EAllOps,2*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4267 + test(r==KErrNone);
1.4268 + //
1.4269 + // 3. Add notification for all operations
1.4270 + // Create a file
1.4271 + // Change the file size
1.4272 + // Delete the file
1.4273 + //
1.4274 + // EAllOps3: A file is created, its size is increased size aIterations times, decreased (aIterations - 1) times
1.4275 + // and then deleted
1.4276 + // aMaxNotifications = 1 + 2*aIterations
1.4277 + //
1.4278 + r = TestMultipleNotificationsL(_L(""),KFilename10,4,9,t_notification::EAllOps3,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize*2,(TBool)EFalse,__LINE__);
1.4279 + test(r==KErrNone);
1.4280 + //
1.4281 + // 4. Add notification for all operations
1.4282 + // Create a file
1.4283 + // Change the file attribute
1.4284 + // Delete the file
1.4285 + //
1.4286 + // EAllOps4: A file is created, its attribute is changed and the file is deleted
1.4287 + // aMaxNotification = 3
1.4288 + //
1.4289 + r = TestMultipleNotificationsL(_L(""),KFilename10,1,3,t_notification::EAllOps4,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4290 + test(r==KErrNone);
1.4291 + //
1.4292 + // 5. Add notification for all operations
1.4293 + // Create a file
1.4294 + // Rename the file
1.4295 + //
1.4296 + // EAllOps5: A file is created and renamed
1.4297 + // aMaxNotification = 2
1.4298 + //
1.4299 + r = TestMultipleNotificationsL(_L(""),KFilename10,1,2,t_notification::EAllOps5,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4300 + test(r==KErrNone);
1.4301 + //
1.4302 + // 6. Add notification for all operations
1.4303 + // Change drive name
1.4304 + // Change volume name
1.4305 + //
1.4306 + // SetVolumeLabel does not run on WINS
1.4307 + // EAllOps6: The drive and volume names are changed
1.4308 + // aMaxNotification = 2
1.4309 + //
1.4310 +#ifndef __WINS__
1.4311 + r = TestMultipleNotificationsL(driveDes,1,2,t_notification::EAllOps6,(TUint)TFsNotification::EAllOps,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4312 + test(r==KErrNone);
1.4313 +#endif
1.4314 + test.Printf(_L("------- End of AllOps Tests ------------------------------------------\n"));
1.4315 +
1.4316 +
1.4317 + //=============================================================================
1.4318 + //! @SYMTestCaseID PBASE-T_NOTIFY-2453
1.4319 + //! @SYMTestType UT
1.4320 + //! @SYMREQ PREQ1847
1.4321 + //! @SYMTestCaseDesc Multiple Filters – Single File Server Session
1.4322 + //! @SYMTestStatus Implemented
1.4323 + //=============================================================================
1.4324 + PrintLine();
1.4325 + test.Next(_L("Multiple-Filter Tests"));
1.4326 + //
1.4327 + // TFsNotification::ECreate | TFsNotification::EDelete
1.4328 + // 1. Add notification for create and delete for a specific file
1.4329 + // Create that file
1.4330 + // Delete the file
1.4331 + //
1.4332 + // A file is created and deleted aIterations times
1.4333 + // aMaxNotification = 2*aIterations
1.4334 + //
1.4335 + _LIT(KFilename11,"file.mulfil");
1.4336 + r = TestMultipleNotificationsL(_L(""),KFilename11,3,6,t_notification::EAllOps1,TFsNotification::ECreate | TFsNotification::EDelete,2*KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4337 + test(r==KErrNone);
1.4338 + //
1.4339 + // TFsNotification::EDelete | TFsNotification::ECreate | TFsNotification::EFileChange
1.4340 + // 2. Add notification for create, file change and delete for a specific file
1.4341 + // Create a file
1.4342 + // Change the file size
1.4343 + // Delete the file
1.4344 + //
1.4345 + // A file is created, its size is increased size aIterations times, decreased (aIterations - 1) times
1.4346 + // and then deleted
1.4347 + // aMaxNotifications = 1 + 2*aIterations
1.4348 + //
1.4349 + r = TestMultipleNotificationsL(_L(""),KFilename11,4,9,t_notification::EAllOps3,TFsNotification::EDelete | TFsNotification::ECreate | TFsNotification::EFileChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4350 + test(r==KErrNone);
1.4351 + //
1.4352 + // TFsNotification::EAttribute | TFsNotification::EDelete | TFsNotification::ECreate
1.4353 + // 3. Add notification for create, attribute change and delete for a specific file
1.4354 + // Create a file
1.4355 + // Change the file attribute
1.4356 + // Delete the file
1.4357 + //
1.4358 + // A file is created, its attribute is changed and the file is deleted
1.4359 + // aMaxNotification = 3
1.4360 + //
1.4361 + r = TestMultipleNotificationsL(_L(""),KFilename11,1,3,t_notification::EAllOps4,TFsNotification::EAttribute | TFsNotification::EDelete | TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4362 + test(r==KErrNone);
1.4363 + //
1.4364 + // TFsNotification::ERename | TFsNotification::ECreate
1.4365 + // 4. Add notification for create and rename for a specific file
1.4366 + // Create a file
1.4367 + // Rename the file
1.4368 + //
1.4369 + // A file is created and renamed
1.4370 + // aMaxNotification = 2
1.4371 + //
1.4372 + r = TestMultipleNotificationsL(_L(""),KFilename11,1,2,t_notification::EAllOps5,TFsNotification::ERename | TFsNotification::ECreate,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4373 + test(r==KErrNone);
1.4374 + //
1.4375 + // TFsNotification::EVolumeName | TFsNotification::EDriveName
1.4376 + // 5. Add notification for drive and volume name change for a specific drive
1.4377 + // Change drive name
1.4378 + // Change volume name
1.4379 + //
1.4380 + // SetVolumeLabel does not run on WINS
1.4381 + // The drive and volume names are changed
1.4382 + // aMaxNotification = 2
1.4383 + //
1.4384 +#ifndef __WINS__
1.4385 + r = TestMultipleNotificationsL(driveDes,1,2,t_notification::EAllOps6,TFsNotification::EVolumeName | TFsNotification::EDriveName,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4386 + test(r==KErrNone);
1.4387 +#endif
1.4388 + test.Printf(_L("------- End of Multiple-Filter Tests ---------------------------------\n"));
1.4389 +
1.4390 +
1.4391 + //==============================================================================
1.4392 + //! @SYMTestCaseID PBASE-T_NOTIFY-2454
1.4393 + //! @SYMTestType UT
1.4394 + //! @SYMREQ PREQ1847
1.4395 + //! @SYMTestCaseDesc Overflow Notification – Single File Server Session
1.4396 + //! @SYMTestStatus Implemented
1.4397 + //==============================================================================
1.4398 + //
1.4399 + // 1. Add notification with a small buffer size, for a specific file change
1.4400 + // Change the file size once
1.4401 + // 2. Make continuous file size changes to the file
1.4402 + // 3. When overflow notification occurs, delete the notification
1.4403 + //
1.4404 + PrintLine();
1.4405 + r = TestOverflowL();
1.4406 + test(r==KErrNone);
1.4407 +
1.4408 + //For DEF140387
1.4409 + PrintLine();
1.4410 + r= TestPostOverflowNotifications();
1.4411 + test(r==KErrNone);
1.4412 + test.Printf(_L("------- End of Overflow Test -----------------------------------------\n"));
1.4413 +
1.4414 +
1.4415 + //============================================================================
1.4416 + //! @SYMTestCaseID PBASE-T_NOTIFY-2455
1.4417 + //! @SYMTestType CIT
1.4418 + //! @SYMREQ PREQ1847
1.4419 + //! @SYMTestCaseDesc API Negative Testing – Single File Server Session
1.4420 + //! @SYMTestStatus Implemented
1.4421 + //============================================================================
1.4422 + // 1.
1.4423 + // a-CFsNotify class creation with zero buffer size
1.4424 + //
1.4425 + // 2.
1.4426 + // b-CFsNotify class creation with negative buffer size
1.4427 + // c-CFsNotify class creation with buffer size that is too large
1.4428 + //
1.4429 + // 3.
1.4430 + // d-Call AddNotification with aNotiififcationType zero
1.4431 + // e-Call AddNotification with aNotiififcationType invalid
1.4432 + // f-Call AddNotification with many different invalid paths
1.4433 + //
1.4434 + // 4.
1.4435 + // g-Call RequestNotifications with status that is already in use
1.4436 + // h-Call CancelNotifications with wrong status
1.4437 + //
1.4438 + PrintLine();
1.4439 + __UHEAP_MARK;
1.4440 + NegativeTests();
1.4441 + __UHEAP_MARKEND;
1.4442 + //
1.4443 + // 5.
1.4444 + // i-Negative testing for directory without *
1.4445 + //
1.4446 + test.Printf(_L("NegativeTests() I\n"));
1.4447 + NegativeTestDirStar();
1.4448 + test.Printf(_L("------- End of Negative Tests ----------------------------------------\n"));
1.4449 +
1.4450 +
1.4451 + //=============================================================================
1.4452 + //! @SYMTestCaseID PBASE-T_NOTIFY-2461
1.4453 + //! @SYMTestType CIT
1.4454 + //! @SYMREQ PREQ1847
1.4455 + //! @SYMTestCaseDesc Plugin Tests
1.4456 + //! @SYMTestStatus
1.4457 + //=============================================================================
1.4458 + PrintLine();
1.4459 + r = TestNotificationsWithFServPlugins();
1.4460 + test(r==KErrNone);
1.4461 + test.Printf(_L("------- End of Plugin Tests ------------------------------------------\n"));
1.4462 +
1.4463 +
1.4464 + //======================================================================
1.4465 + //! @SYMTestCaseID PBASE-T_NOTIFY-2459
1.4466 + //! @SYMTestType UT
1.4467 + //! @SYMREQ PREQ1847
1.4468 + //! @SYMTestCaseDesc Drive Formatting – Single File Server Session
1.4469 + //! @SYMTestStatus Implemented
1.4470 + //
1.4471 + // TFsNotificationType EMediaChange
1.4472 + //======================================================================
1.4473 + //
1.4474 + // RFormat
1.4475 + // We do these last so that we can be sure to have deleted anything we've inadvertently not deleted
1.4476 + //
1.4477 + // 1. Add notification for media change of a specific drive
1.4478 + // Format the drive
1.4479 + //
1.4480 +#ifdef __WINS__
1.4481 + if(gDriveToTest-(TChar)'A' != 2)
1.4482 +#endif
1.4483 + {
1.4484 + PrintLine();
1.4485 + test.Next(_L("Format Tests"));
1.4486 + r = TestMultipleNotificationsL(driveDes,1,1,t_notification::EFormat,TFsNotification::EMediaChange,KMinNotificationBufferSize,(TBool)EFalse,__LINE__);
1.4487 + test(r==KErrNone);
1.4488 + test.Printf(_L("------- End of Format Tests ------------------------------------------\n"));
1.4489 + }
1.4490 +
1.4491 +
1.4492 + //======================================================================
1.4493 + //! @SYMTestCaseID PBASE-T_NOTIFY-2460
1.4494 + //! @SYMTestType UT
1.4495 + //! @SYMREQ PREQ1847
1.4496 + //! @SYMTestCaseDesc Notifications for Data Caged Areas
1.4497 + //! @SYMTestStatus Implemented
1.4498 + //======================================================================
1.4499 + //
1.4500 + // Create a private folder for a specified uid
1.4501 + // Add notification filter using the following processes:
1.4502 + // 1. A process with no capability
1.4503 + // 2. A process with all capabilities
1.4504 + // 3. A process with the specified uid
1.4505 + //
1.4506 + PrintLine();
1.4507 + test.Next(_L("Test T_NOTIFIER_NOCAPS.EXE"));
1.4508 + r = TestProcessCapabilities(_L("T_NOTIFIER_NOCAPS.EXE"));
1.4509 + test(r == KErrPermissionDenied); //Failure on emulator -> Did you forget to do a wintest?
1.4510 +
1.4511 + test.Next(_L("Test T_NOTIFIER_ALLFILES.EXE"));
1.4512 + r = TestProcessCapabilities(_L("T_NOTIFIER_ALLFILES.EXE"));
1.4513 + test(r == KErrNone);
1.4514 +
1.4515 + test.Next(_L("Test T_NOTIFIER_BELONGS.EXE"));
1.4516 + r = TestProcessCapabilities(_L("T_NOTIFIER_BELONGS.EXE"));
1.4517 + test(r == KErrNone);
1.4518 + test.Printf(_L("------- End of Data-Caging Tests -------------------------------------\n"));
1.4519 +
1.4520 +
1.4521 + test.End();
1.4522 + test.Close();
1.4523 + delete cleanup;
1.4524 + } //End of CallTestsL
1.4525 +