messagingfw/biomsgfw/BDBTSRC/t_bio_observer.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "BioTest.h"
       
    17 
       
    18 RTest test(_L("Bio Database Observer Tests"));
       
    19 
       
    20 LOCAL_D void TestInstallL(TInt aDrive);
       
    21 
       
    22 const TUid KTestBif = { 0x10009234 };
       
    23 
       
    24 _LIT(KTestDir, "\\test\\bio\\bif\\");
       
    25 _LIT(KBifDir, "\\resource\\messaging\\Bif\\");     
       
    26 _LIT(KTestBif1Src, "testbif1.rsc");
       
    27 _LIT(KTestMbm1Src, "testbif1.mbm");
       
    28 
       
    29 _LIT(KTestBif2Src, "testbif2.rsc");
       
    30 _LIT(KTestMbm2Src, "testbif2.mbm");
       
    31 
       
    32 _LIT(KTestBifDst, "testbif.rsc");
       
    33 _LIT(KTestMbmDst, "testbif.mbm");
       
    34 
       
    35 
       
    36 class CBifObserver : public CBase , public MBifChangeObserver
       
    37 	{
       
    38 public:
       
    39 	void HandleBifChangeL(TBifChangeEvent aEvent, TUid aBioUid);
       
    40 	//
       
    41 public:
       
    42 	TBifChangeEvent iEvent;
       
    43 	TUid iBioUid;
       
    44 	TBool iFlag;
       
    45 	};
       
    46 
       
    47 
       
    48 void CBifObserver::HandleBifChangeL(TBifChangeEvent aEvent, TUid aBioUid)
       
    49 	{
       
    50 	iEvent = aEvent;
       
    51 	iBioUid = aBioUid;
       
    52 	iFlag = ETrue;
       
    53 
       
    54 	CActiveScheduler::Stop();
       
    55 	}
       
    56 
       
    57 
       
    58 LOCAL_C void TestChangeL(TInt aDrive)
       
    59 	{
       
    60 	// Clear the BIF folders
       
    61 	theUtils->ClearBifFoldersL();
       
    62 
       
    63 	// Get the name of the drive
       
    64 	TDriveUnit unit(aDrive);
       
    65 	TPtrC drive(unit.Name());
       
    66 
       
    67 	TParse src;
       
    68 	TParse dst;
       
    69 
       
    70 	// Copy the bif file
       
    71 	theUtils->FindFileL(src, KTestDir, KTestBif1Src);
       
    72 	User::LeaveIfError(dst.Set(drive, &KBifDir, &KTestBifDst));
       
    73 	theUtils->FileSession().MkDirAll(dst.FullName());
       
    74 	User::LeaveIfError(BaflUtils::CopyFile(theUtils->FileSession(), src.FullName(), dst.FullName()));
       
    75 
       
    76 	// Copy the Mbm file
       
    77 	theUtils->FindFileL(src, KTestDir, KTestMbm1Src);
       
    78 	User::LeaveIfError(dst.Set(drive, &KBifDir, &KTestMbmDst));
       
    79 	theUtils->FileSession().MkDirAll(dst.FullName());
       
    80 	User::LeaveIfError(BaflUtils::CopyFile(theUtils->FileSession(), src.FullName(), dst.FullName()));
       
    81 
       
    82 	// Create BIF database
       
    83 	CBIODatabase* db = CBIODatabase::NewLC(theUtils->FileSession());
       
    84 
       
    85 	// Create observer
       
    86 	CBifObserver* obs = new(ELeave)CBifObserver;
       
    87 	CleanupStack::PushL(obs);
       
    88 
       
    89 	CBifChangeObserver* change = CBifChangeObserver::NewL(*obs, theUtils->FileSession());
       
    90 	CleanupStack::PushL(change);
       
    91 	change->Start();
       
    92 
       
    93 	// Check the test BIO is installed
       
    94 	test(theUtils->BifInstalledL(*db, KTestBif));
       
    95 	test(!obs->iFlag);
       
    96 
       
    97 	// Short delay to check that the observer isn't fired
       
    98 	CTestTimer* timer = CTestTimer::NewL();
       
    99 	timer->After(10000000);
       
   100 	CActiveScheduler::Start();
       
   101 	delete timer;
       
   102 
       
   103 	// Check the test BIO is still installed
       
   104 	test(theUtils->BifInstalledL(*db, KTestBif));
       
   105 	test(!obs->iFlag);
       
   106 
       
   107 	// Copy the bif file
       
   108 	theUtils->FindFileL(src, KTestDir, KTestBif2Src);
       
   109 	User::LeaveIfError(dst.Set(drive, &KBifDir, &KTestBifDst));
       
   110 	theUtils->FileSession().MkDirAll(dst.FullName());
       
   111 	User::LeaveIfError(BaflUtils::CopyFile(theUtils->FileSession(), src.FullName(), dst.FullName()));
       
   112 
       
   113 	// Copy the Mbm file
       
   114 	theUtils->FindFileL(src, KTestDir, KTestMbm2Src);
       
   115 	User::LeaveIfError(dst.Set(drive, &KBifDir, &KTestMbmDst));
       
   116 	theUtils->FileSession().MkDirAll(dst.FullName());
       
   117 	User::LeaveIfError(BaflUtils::CopyFile(theUtils->FileSession(), src.FullName(), dst.FullName()));
       
   118 
       
   119 	// Wait for the notification to come through
       
   120 	CActiveScheduler::Start();
       
   121 	test(obs->iFlag);
       
   122 	test(obs->iBioUid == KTestBif);
       
   123 	test(obs->iEvent == MBifChangeObserver::EBifChanged);
       
   124 
       
   125 	CleanupStack::PopAndDestroy(3); // change, obs, db
       
   126 	}
       
   127 
       
   128 
       
   129 LOCAL_C void TestImmediateCancelL()
       
   130 	{
       
   131 	CBifObserver* obs = new(ELeave)CBifObserver;
       
   132 	CleanupStack::PushL(obs);
       
   133 	
       
   134 	CBifChangeObserver* iObserver=CBifChangeObserver::NewL(*obs, theUtils->FileSession());
       
   135 	iObserver->Start();
       
   136 	delete iObserver;
       
   137 	CleanupStack::PopAndDestroy(obs);
       
   138 	}
       
   139 
       
   140 
       
   141 LOCAL_C void TestRemoveL(TInt aDrive)
       
   142 	{
       
   143 	// Clear the BIF folders
       
   144 	theUtils->ClearBifFoldersL();
       
   145 
       
   146 	// Get the name of the drive
       
   147 	TDriveUnit unit(aDrive);
       
   148 	TPtrC drive(unit.Name());
       
   149 
       
   150 	TParse src;
       
   151 	TParse dst;
       
   152 
       
   153 	// Copy the bif file
       
   154 	theUtils->FindFileL(src, KTestDir, KTestBif1Src);
       
   155 	User::LeaveIfError(dst.Set(drive, &KBifDir, &KTestBifDst));
       
   156 	theUtils->FileSession().MkDirAll(dst.FullName());
       
   157 	
       
   158 	User::LeaveIfError(BaflUtils::CopyFile(theUtils->FileSession(), src.FullName(), dst.FullName()));
       
   159 
       
   160 	// Copy the Mbm file
       
   161 	theUtils->FindFileL(src, KTestDir, KTestMbm1Src);
       
   162 	User::LeaveIfError(dst.Set(drive, &KBifDir, &KTestMbmDst));
       
   163 	theUtils->FileSession().MkDirAll(dst.FullName());
       
   164 	User::LeaveIfError(BaflUtils::CopyFile(theUtils->FileSession(), src.FullName(), dst.FullName()));
       
   165 
       
   166 	// Create BIF database
       
   167 	CBIODatabase* db = CBIODatabase::NewLC(theUtils->FileSession());
       
   168 
       
   169 	// Create observer
       
   170 	CBifObserver* obs = new(ELeave)CBifObserver;
       
   171 	CleanupStack::PushL(obs);
       
   172 
       
   173 	CBifChangeObserver* change = CBifChangeObserver::NewL(*obs, theUtils->FileSession());
       
   174 	CleanupStack::PushL(change);
       
   175 	change->Start();
       
   176 
       
   177 	// Check the test BIO is installed
       
   178 	test(theUtils->BifInstalledL(*db, KTestBif));
       
   179 	test(!obs->iFlag);
       
   180 
       
   181 	// Short delay to check that the observer isn't fired
       
   182 	CTestTimer* timer = CTestTimer::NewL();
       
   183 	timer->After(10000000);
       
   184 	CActiveScheduler::Start();
       
   185 	delete timer;
       
   186 
       
   187 	// Check the test BIO is still installed
       
   188 	test(theUtils->BifInstalledL(*db, KTestBif));
       
   189 	test(!obs->iFlag);
       
   190 
       
   191 	// Delete the bif file
       
   192 	User::LeaveIfError(dst.Set(drive, &KBifDir, &KTestBifDst));
       
   193 	User::LeaveIfError(theUtils->FileSession().Delete(dst.FullName()));
       
   194 
       
   195 	// Delete the Mbm file
       
   196 	User::LeaveIfError(dst.Set(drive, &KBifDir, &KTestMbmDst));
       
   197 	User::LeaveIfError(theUtils->FileSession().Delete(dst.FullName()));
       
   198 
       
   199 	// Wait for the notification to come through
       
   200 	CActiveScheduler::Start();
       
   201 	test(obs->iFlag);
       
   202 	test(obs->iBioUid == KTestBif);
       
   203 	test(obs->iEvent == MBifChangeObserver::EBifDeleted);
       
   204 
       
   205 	CleanupStack::PopAndDestroy(); // change
       
   206 	CleanupStack::PopAndDestroy(); // obs
       
   207 	CleanupStack::PopAndDestroy(); // db
       
   208 	}
       
   209 
       
   210 
       
   211 LOCAL_C void doTestsL()
       
   212 	{
       
   213 	theUtils->Start(_L("Installing BIF"));
       
   214 	TestInstallL(EDriveC);
       
   215 	TestInstallL(EDriveD);
       
   216 	theUtils->Complete();
       
   217 
       
   218 	theUtils->Start(_L("Changing BIF"));
       
   219 	TestChangeL(EDriveC);
       
   220 	TestChangeL(EDriveD);
       
   221 	theUtils->Complete();
       
   222 
       
   223 	theUtils->Start(_L("Removing BIF"));
       
   224 	TestRemoveL(EDriveC);
       
   225 	TestRemoveL(EDriveD);
       
   226 	theUtils->Complete();
       
   227 
       
   228 	theUtils->Start(_L("Canceling BioObserver before active scheduler has been run"));
       
   229 	TestImmediateCancelL();
       
   230 	theUtils->Complete();	
       
   231 	}
       
   232 
       
   233 
       
   234 LOCAL_C void TestInstallL(TInt aDrive)
       
   235 	{
       
   236 	// Clear the BIF folders
       
   237 	theUtils->ClearBifFoldersL();
       
   238 
       
   239 	// Create BIF database
       
   240 	CBIODatabase* db = CBIODatabase::NewLC(theUtils->FileSession());
       
   241 
       
   242 	// Create observer
       
   243 	CBifObserver* obs = new(ELeave)CBifObserver;
       
   244 	CleanupStack::PushL(obs);
       
   245 
       
   246 	CBifChangeObserver* change = CBifChangeObserver::NewL(*obs, theUtils->FileSession());
       
   247 	CleanupStack::PushL(change);
       
   248 	change->Start();
       
   249 
       
   250 	// Check the test BIO isn't installed
       
   251 	test(!theUtils->BifInstalledL(*db, KTestBif));
       
   252 	test(!obs->iFlag);
       
   253 
       
   254 	// Short delay to check that the observer isn't fired
       
   255 	CTestTimer* timer = CTestTimer::NewL();
       
   256 	timer->After(10000000);
       
   257 	CActiveScheduler::Start();
       
   258 	delete timer;
       
   259 
       
   260 	// Check the test BIO still isn't installed
       
   261 	test(!theUtils->BifInstalledL(*db, KTestBif));
       
   262 	test(!obs->iFlag);
       
   263 
       
   264 	// Get the name of the drive
       
   265 	TDriveUnit unit(aDrive);
       
   266 	TPtrC drive(unit.Name());
       
   267 
       
   268 	TParse src;
       
   269 	TParse dst;
       
   270 
       
   271 	// Copy the bif file
       
   272 	theUtils->FindFileL(src, KTestDir, KTestBif1Src);
       
   273 	User::LeaveIfError(dst.Set(drive, &KBifDir, &KTestBifDst));
       
   274 	theUtils->FileSession().MkDirAll(dst.FullName());
       
   275 	User::LeaveIfError(BaflUtils::CopyFile(theUtils->FileSession(), src.FullName(), dst.FullName()));
       
   276 
       
   277 	// Copy the Mbm file
       
   278 	theUtils->FindFileL(src, KTestDir, KTestMbm1Src);
       
   279 	User::LeaveIfError(dst.Set(drive, &KBifDir, &KTestMbmDst));
       
   280 	theUtils->FileSession().MkDirAll(dst.FullName());
       
   281 	User::LeaveIfError(BaflUtils::CopyFile(theUtils->FileSession(), src.FullName(), dst.FullName()));
       
   282 
       
   283 	// Wait for the notification to come through
       
   284 	CActiveScheduler::Start();
       
   285 	test(obs->iFlag);
       
   286 	test(obs->iBioUid == KTestBif);
       
   287 	test(obs->iEvent == MBifChangeObserver::EBifAdded);
       
   288 
       
   289 	CleanupStack::PopAndDestroy(3); // change, obs, db
       
   290 	}