tzservices/tzserver/test/component/t_tzdatachangenotification.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "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 
       
    17 #include <e32base.h>
       
    18 #include <e32test.h>
       
    19 #include <e32property.h>
       
    20 #include <tz.h>
       
    21 #include <tzupdate.h>
       
    22 #include "testserver.h"
       
    23 
       
    24 
       
    25 _LIT(KSrcTzRulesDb, "z:\\testresourcefiles\\tzdb.dbz");
       
    26 _LIT(KDestTzRulesDb, "c:\\private\\1020383e\\tzdb.dbz");
       
    27 
       
    28 _LIT(KSrcTzUserDb, "z:\\testresourcefiles\\tz_userdata_empty.db");
       
    29 _LIT(KDestTzUserDb, "c:\\private\\1020383e\\SQLite__tzuserdata.db");
       
    30 
       
    31 _LIT(KSrcTzLocRscDir, "z:\\testresourcefiles\\");
       
    32 _LIT(KDestTzLocRscDir, "c:\\resource\\timezonelocalization\\");
       
    33 
       
    34 _LIT(KTimeStampFile, "c:\\private\\1020383e\\timestamps");
       
    35 
       
    36 _LIT(KSrcTzLocRscFile1, "z:\\testresourcefiles\\timezonegroups.r01");
       
    37 _LIT(KSrcTzLocRscFile2, "z:\\testresourcefiles\\timezonegroups.r02");
       
    38 _LIT(KSrcTzLocRscFile3, "z:\\testresourcefiles\\timezonegroups.rsc");
       
    39 _LIT(KSrcTzLocRscFile4, "z:\\testresourcefiles\\timezones.r01");
       
    40 _LIT(KSrcTzLocRscFile5, "z:\\testresourcefiles\\timezones.r02");
       
    41 _LIT(KSrcTzLocRscFile6, "z:\\testresourcefiles\\timezones.rsc");
       
    42 
       
    43 _LIT(KDestTzLocRscFile1, "c:\\resource\\timezonelocalization\\timezonegroups.r01");
       
    44 _LIT(KDestTzLocRscFile2, "c:\\resource\\timezonelocalization\\timezonegroups.r02");
       
    45 _LIT(KDestTzLocRscFile3, "c:\\resource\\timezonelocalization\\timezonegroups.rsc");
       
    46 _LIT(KDestTzLocRscFile4, "c:\\resource\\timezonelocalization\\timezones.r01");
       
    47 _LIT(KDestTzLocRscFile5, "c:\\resource\\timezonelocalization\\timezones.r02");
       
    48 _LIT(KDestTzLocRscFile6, "c:\\resource\\timezonelocalization\\timezones.rsc");
       
    49 
       
    50 
       
    51 RTest test(_L("TZ Data Change Notification Test Suite"));
       
    52 
       
    53 
       
    54 /**
       
    55 Timer used to detect if a test case times out.
       
    56 */
       
    57 class CTestTimeOut : public CTimer
       
    58 	{
       
    59 public:
       
    60     static CTestTimeOut* NewL();
       
    61 	
       
    62 	void Start(TInt aTimeOut);
       
    63 	void Stop();
       
    64 	TBool TimedOut();
       
    65 	
       
    66 private:
       
    67 	CTestTimeOut();
       
    68 	void ConstructL();
       
    69 
       
    70     // From CActive.
       
    71     void RunL();
       
    72 
       
    73 private:
       
    74 	TBool iTimedOut;
       
    75 	};
       
    76 
       
    77 
       
    78 CTestTimeOut* CTestTimeOut::NewL()
       
    79     {
       
    80     CTestTimeOut* self = new(ELeave) CTestTimeOut();
       
    81     CleanupStack::PushL(self);
       
    82     self->ConstructL();
       
    83     CleanupStack::Pop(self);
       
    84     return self;
       
    85     }
       
    86 
       
    87 
       
    88 CTestTimeOut::CTestTimeOut()
       
    89 	:
       
    90 	CTimer(EPriorityStandard)
       
    91 	{
       
    92 	CActiveScheduler::Add(this);
       
    93 	iTimedOut = EFalse;
       
    94 	}
       
    95 
       
    96 
       
    97 void CTestTimeOut::ConstructL()
       
    98 	{
       
    99 	CTimer::ConstructL();
       
   100 	}
       
   101 	
       
   102 	
       
   103 void CTestTimeOut::Start(TInt aTimeOut)
       
   104 	{
       
   105 	iTimedOut = EFalse;
       
   106 	Cancel();
       
   107 	After(aTimeOut);
       
   108 	}
       
   109 
       
   110 void CTestTimeOut::Stop()
       
   111 	{
       
   112 	Cancel();
       
   113 	}
       
   114 
       
   115 TBool CTestTimeOut::TimedOut()
       
   116 	{
       
   117 	return iTimedOut;
       
   118 	}
       
   119 
       
   120 	
       
   121 void CTestTimeOut::RunL()
       
   122 	{
       
   123 	iTimedOut = ETrue;
       
   124 	CActiveScheduler::Stop();
       
   125 	}
       
   126 		
       
   127 
       
   128 /**
       
   129 Watches for a change to the given NTzUpdate::TPropertyKeys property.  The
       
   130 property key should only be NTzUpdate::ETzRulesChange or NTzUpdate::ETzNames-
       
   131 Change.
       
   132 */
       
   133 class CTzDataChangeObserver : public CActive
       
   134     {
       
   135 public:
       
   136     static CTzDataChangeObserver* NewL(NTzUpdate::TPropertyKeys
       
   137     	aChangePropertyKey);
       
   138     ~CTzDataChangeObserver();
       
   139 
       
   140 	void Start();
       
   141 	void Stop();
       
   142     TTime TimeOfChange();
       
   143     
       
   144 private:
       
   145     // From CActive.
       
   146     void RunL();
       
   147     void DoCancel();
       
   148 	
       
   149     CTzDataChangeObserver(NTzUpdate::TPropertyKeys aChangePropertyKey);
       
   150     void ConstructL();
       
   151 
       
   152     void RespondToChange();
       
   153 	
       
   154 private:
       
   155     NTzUpdate::TPropertyKeys iChangePropertyKey;
       
   156     RProperty iChangeProperty;
       
   157     TTime iTimeOfChange;
       
   158     };
       
   159 
       
   160 
       
   161 CTzDataChangeObserver* CTzDataChangeObserver::NewL(NTzUpdate::TPropertyKeys
       
   162 	aChangePropertyKey)
       
   163     {
       
   164     CTzDataChangeObserver* self =
       
   165     	new(ELeave) CTzDataChangeObserver(aChangePropertyKey);
       
   166     CleanupStack::PushL(self);
       
   167     self->ConstructL();
       
   168     CleanupStack::Pop(self);
       
   169     return self;
       
   170     }
       
   171 
       
   172 
       
   173 CTzDataChangeObserver::CTzDataChangeObserver(NTzUpdate::TPropertyKeys
       
   174 	aChangePropertyKey)
       
   175     :
       
   176     CActive(CActive::EPriorityStandard),
       
   177     iChangePropertyKey(aChangePropertyKey)
       
   178     {
       
   179     CActiveScheduler::Add(this);
       
   180     iTimeOfChange = Time::NullTTime();
       
   181     }
       
   182 
       
   183 
       
   184 void CTzDataChangeObserver::ConstructL()
       
   185     {
       
   186     User::LeaveIfError(iChangeProperty.Attach(NTzUpdate::KPropertyCategory,
       
   187     	iChangePropertyKey));
       
   188     }
       
   189 
       
   190 
       
   191 CTzDataChangeObserver::~CTzDataChangeObserver()
       
   192     {
       
   193     Cancel();    
       
   194     iChangeProperty.Close();
       
   195     }
       
   196 
       
   197 
       
   198 void CTzDataChangeObserver::Start()
       
   199     {
       
   200     iChangeProperty.Subscribe(iStatus);
       
   201 	SetActive();
       
   202 	}
       
   203 
       
   204 
       
   205 void CTzDataChangeObserver::Stop()
       
   206     {
       
   207 	Cancel();
       
   208 	}
       
   209 
       
   210 
       
   211 void CTzDataChangeObserver::RespondToChange()
       
   212     {
       
   213     TPckgBuf<TTime> changeBuf;
       
   214     TInt err = iChangeProperty.Get(changeBuf);
       
   215     if (err == KErrNone)
       
   216         {
       
   217         iTimeOfChange = changeBuf();
       
   218         }
       
   219     }
       
   220 
       
   221 
       
   222 TTime CTzDataChangeObserver::TimeOfChange()
       
   223     {
       
   224     return iTimeOfChange;
       
   225     }
       
   226 
       
   227 
       
   228 void CTzDataChangeObserver::RunL()
       
   229     {	
       
   230     if (iStatus.Int() == KErrNone)
       
   231         {
       
   232 		RespondToChange();
       
   233 		CActiveScheduler::Stop();
       
   234         }
       
   235     }
       
   236 
       
   237 
       
   238 void CTzDataChangeObserver::DoCancel()
       
   239     {
       
   240     iChangeProperty.Cancel();
       
   241     }
       
   242 
       
   243 
       
   244 /**
       
   245 Base class for TZ data change notification test cases.
       
   246 */
       
   247 class CTzDataChangeNotificationTestCase : public CBase
       
   248 	{
       
   249 public:
       
   250     ~CTzDataChangeNotificationTestCase();
       
   251 
       
   252 	void TestChangeNotificationL();
       
   253 	
       
   254 protected:
       
   255     CTzDataChangeNotificationTestCase();
       
   256     void ConstructL(NTzUpdate::TPropertyKeys aChangePropertyKey);
       
   257 
       
   258 private:
       
   259     	    	
       
   260 	void TearDownL();
       
   261 
       
   262 	void PrintTime(const TDesC& aDesc, const TTime& aTime);
       
   263 	virtual void SetUpL();
       
   264 	virtual void TriggerChangeNotificationL() = 0;
       
   265 	virtual void TidyUpAfterChangeNotificationL() = 0;
       
   266 
       
   267 protected:
       
   268 	RTz iTzServer;
       
   269 	RPIMTestServer iTestServer;
       
   270 	
       
   271 private:
       
   272 	CTestTimeOut* iTestTimeOut;
       
   273 	CTzDataChangeObserver* iTzDataChangeObserver;
       
   274 	};
       
   275 
       
   276 
       
   277 CTzDataChangeNotificationTestCase::CTzDataChangeNotificationTestCase()
       
   278     {
       
   279 	// Nothing to do.
       
   280     }
       
   281 
       
   282 
       
   283 void CTzDataChangeNotificationTestCase::ConstructL(NTzUpdate::TPropertyKeys
       
   284 	aChangePropertyKey)
       
   285     {
       
   286 	iTestTimeOut = CTestTimeOut::NewL();
       
   287 	iTzDataChangeObserver = CTzDataChangeObserver::NewL(aChangePropertyKey);
       
   288     }
       
   289 
       
   290 
       
   291 CTzDataChangeNotificationTestCase::~CTzDataChangeNotificationTestCase()
       
   292     {
       
   293 	delete iTestTimeOut;
       
   294 	delete iTzDataChangeObserver;
       
   295     }
       
   296 
       
   297 
       
   298 void CTzDataChangeNotificationTestCase::SetUpL()
       
   299 	{
       
   300 	User::LeaveIfError(iTzServer.Connect());
       
   301 	User::LeaveIfError(iTestServer.Connect());
       
   302 	}
       
   303 
       
   304 
       
   305 void CTzDataChangeNotificationTestCase::TearDownL()
       
   306 	{
       
   307 	iTestServer.Close();
       
   308 	iTzServer.Close();
       
   309 	}
       
   310 
       
   311 
       
   312 void CTzDataChangeNotificationTestCase::PrintTime(const TDesC& aDesc,
       
   313 	const TTime& aTime)
       
   314 	{
       
   315 	TDateTime dt = aTime.DateTime();
       
   316 	test.Printf(_L("%S: %02d:%02d:%02d:%06d\n"), &aDesc, dt.Hour(), dt.Minute(),
       
   317 		dt.Second(), dt.MicroSecond());
       
   318 	}
       
   319 	
       
   320 	
       
   321 void CTzDataChangeNotificationTestCase::TestChangeNotificationL()
       
   322 	{
       
   323 	SetUpL();
       
   324 
       
   325 	TTime timeBeforeChangeNotification;
       
   326 	timeBeforeChangeNotification.UniversalTime();
       
   327 
       
   328 	_LIT(KTimeBeforeChangeNotification, "Time before change notification");
       
   329 	PrintTime(KTimeBeforeChangeNotification, timeBeforeChangeNotification);
       
   330 
       
   331 	iTzDataChangeObserver->Start();
       
   332 
       
   333 	TriggerChangeNotificationL();
       
   334 	
       
   335 	const TInt KTestTimeOut = 50000000 /* microseconds */;
       
   336 	iTestTimeOut->Start(KTestTimeOut);
       
   337 
       
   338 	// The thread will be blocked after this call until either the test times
       
   339 	// out or the change in the observed property occurs. 
       
   340 	CActiveScheduler::Start();
       
   341 
       
   342 	iTzDataChangeObserver->Stop();
       
   343 	iTestTimeOut->Stop();
       
   344 	
       
   345 	TidyUpAfterChangeNotificationL();
       
   346 
       
   347 	test(iTestTimeOut->TimedOut() == EFalse);
       
   348 
       
   349 	TTime timeOfPropertyChange = iTzDataChangeObserver->TimeOfChange();
       
   350 	_LIT(KTimeOfPropertyChange, "Time of property change");
       
   351 	PrintTime(KTimeOfPropertyChange, timeOfPropertyChange);
       
   352 
       
   353 	// We have received a change to the property - sanity check that the time
       
   354 	// of the property change is later than the time of the event which
       
   355 	// initiated the change.
       
   356 	test(timeOfPropertyChange > timeBeforeChangeNotification);
       
   357 
       
   358 	TearDownL();
       
   359 	}
       
   360 	
       
   361 	
       
   362 /**
       
   363 @SYMTestCaseID 	PIM-APPSERV-TZ-TZS-CN-0001
       
   364 	
       
   365 @SYMTestCaseDesc
       
   366 	The purpose of this test is to verify that a change to the system TZ rules
       
   367 	database causes a change in value of the TZ rules change property.
       
   368 
       
   369 @SYMTestActions
       
   370 	1. Subscribe to the TZ rules change property.
       
   371 	2. Copy a system TZ rules database to the appropriate location on the C:
       
   372 	   drive.
       
   373 
       
   374 @SYMTestExpectedResults
       
   375 	The TZ rules change property changes value.
       
   376 	
       
   377 @SYMREQ
       
   378 	REQ9950, REQ9951
       
   379 
       
   380 @SYMTestType
       
   381 	CT
       
   382 
       
   383 @SYMTestPriority
       
   384 	1
       
   385 */
       
   386 class CTestSysTzRulesDbChangeNotification : public CTzDataChangeNotificationTestCase
       
   387 	{
       
   388 public:
       
   389     static CTestSysTzRulesDbChangeNotification* NewL();
       
   390     ~CTestSysTzRulesDbChangeNotification();
       
   391 
       
   392 protected:
       
   393 	CTestSysTzRulesDbChangeNotification();
       
   394 	void ConstructL();
       
   395 
       
   396 private:
       
   397 	void TriggerChangeNotificationL();
       
   398 	void TidyUpAfterChangeNotificationL();
       
   399 	};
       
   400 
       
   401 
       
   402 CTestSysTzRulesDbChangeNotification* CTestSysTzRulesDbChangeNotification::NewL()
       
   403     {
       
   404     CTestSysTzRulesDbChangeNotification* self =
       
   405     	new(ELeave) CTestSysTzRulesDbChangeNotification();
       
   406     CleanupStack::PushL(self);
       
   407     self->ConstructL();
       
   408     CleanupStack::Pop(self);
       
   409     return self;
       
   410     }
       
   411 
       
   412 
       
   413 CTestSysTzRulesDbChangeNotification::CTestSysTzRulesDbChangeNotification()
       
   414 	{
       
   415 	// Nothing to do.
       
   416 	}
       
   417 
       
   418 
       
   419 void CTestSysTzRulesDbChangeNotification::ConstructL()
       
   420     {
       
   421 	CTzDataChangeNotificationTestCase::ConstructL(NTzUpdate::ETzRulesChange);
       
   422 	}
       
   423 
       
   424 
       
   425 CTestSysTzRulesDbChangeNotification::~CTestSysTzRulesDbChangeNotification()
       
   426 	{
       
   427 	// Nothing to do.
       
   428 	}
       
   429 
       
   430 
       
   431 void CTestSysTzRulesDbChangeNotification::TriggerChangeNotificationL()
       
   432 	{
       
   433 	// By copying the TZ rules database to the C: drive a change in the
       
   434 	// NTzUpdate::ETzRulesChange property should occur. 
       
   435 	iTestServer.CopyFileL(KSrcTzRulesDb, KDestTzRulesDb);
       
   436 	iTzServer.SwiObsBeginL();
       
   437 	iTzServer.SwiObsFileChangedL(RTz::EFilterTzPrivate);
       
   438 	iTzServer.SwiObsEndL();
       
   439 	}
       
   440 
       
   441 
       
   442 void CTestSysTzRulesDbChangeNotification::TidyUpAfterChangeNotificationL()
       
   443 	{
       
   444 	iTestServer.DeleteFileL(KDestTzRulesDb);
       
   445 	}
       
   446 
       
   447 
       
   448 /**
       
   449 @SYMTestCaseID 	PIM-APPSERV-TZ-TZS-CN-0002
       
   450 	
       
   451 @SYMTestCaseDesc
       
   452 	The purpose of this test is to verify that a change to the system TZ
       
   453 	localization resources causes a change in value of the TZ names change
       
   454 	property.
       
   455 	
       
   456 @SYMTestActions
       
   457 	1. Subscribe to the TZ names change property.
       
   458 	2. Copy system TZ localization resources to the appropriate location on the
       
   459 	   C: drive.
       
   460 
       
   461 @SYMTestExpectedResults
       
   462 	The TZ names change property changes value.
       
   463 	
       
   464 @SYMREQ
       
   465 	REQ9950, REQ9951
       
   466 
       
   467 @SYMTestType
       
   468 	CT
       
   469 
       
   470 @SYMTestPriority
       
   471 	1
       
   472 */
       
   473 class CTestSysTzLocRscChangeNotification : public CTzDataChangeNotificationTestCase
       
   474 	{
       
   475 public:
       
   476     static CTestSysTzLocRscChangeNotification* NewL();
       
   477     ~CTestSysTzLocRscChangeNotification();
       
   478 
       
   479 protected:
       
   480 	CTestSysTzLocRscChangeNotification();
       
   481 	void ConstructL();
       
   482 
       
   483 private:
       
   484 	void TriggerChangeNotificationL();
       
   485 	void TidyUpAfterChangeNotificationL();
       
   486 	};
       
   487 
       
   488 
       
   489 CTestSysTzLocRscChangeNotification* CTestSysTzLocRscChangeNotification::NewL()
       
   490     {
       
   491     CTestSysTzLocRscChangeNotification* self =
       
   492     	new(ELeave) CTestSysTzLocRscChangeNotification();
       
   493     CleanupStack::PushL(self);
       
   494     self->ConstructL();
       
   495     CleanupStack::Pop(self);
       
   496     return self;
       
   497     }
       
   498 
       
   499 
       
   500 CTestSysTzLocRscChangeNotification::CTestSysTzLocRscChangeNotification()
       
   501 	{
       
   502 	// Nothing to do.
       
   503 	}
       
   504 
       
   505 
       
   506 void CTestSysTzLocRscChangeNotification::ConstructL()
       
   507     {
       
   508 	CTzDataChangeNotificationTestCase::ConstructL(NTzUpdate::ETzNamesChange);
       
   509 	}
       
   510 
       
   511 
       
   512 CTestSysTzLocRscChangeNotification::~CTestSysTzLocRscChangeNotification()
       
   513 	{
       
   514 	// Nothing to do.
       
   515 	}
       
   516 
       
   517 
       
   518 void CTestSysTzLocRscChangeNotification::TriggerChangeNotificationL()
       
   519 	{
       
   520 	// By copying the TZ localization resources to the C: drive a change in the
       
   521 	// NTzUpdate::ETzNamesChange property should occur. 
       
   522 	iTestServer.CopyFileL(KSrcTzLocRscFile1, KDestTzLocRscFile1);
       
   523 	iTestServer.CopyFileL(KSrcTzLocRscFile2, KDestTzLocRscFile2);
       
   524 	iTestServer.CopyFileL(KSrcTzLocRscFile3, KDestTzLocRscFile3);
       
   525 	iTestServer.CopyFileL(KSrcTzLocRscFile4, KDestTzLocRscFile4);
       
   526 	iTestServer.CopyFileL(KSrcTzLocRscFile5, KDestTzLocRscFile5);
       
   527 	iTestServer.CopyFileL(KSrcTzLocRscFile6, KDestTzLocRscFile6);
       
   528 	iTzServer.SwiObsBeginL();
       
   529 	iTzServer.SwiObsFileChangedL(RTz::EFilterResourceTimezonelocalization);
       
   530 	iTzServer.SwiObsEndL();
       
   531 	}
       
   532 
       
   533 
       
   534 void CTestSysTzLocRscChangeNotification::TidyUpAfterChangeNotificationL()
       
   535 	{
       
   536 	//Close the server, otherwise can't delete the resource file
       
   537 	iTestServer.CloseTzSession();
       
   538 	iTzServer.Close();
       
   539 	iTestServer.DeleteFileL(KDestTzLocRscFile1);
       
   540 	iTestServer.DeleteFileL(KDestTzLocRscFile2);
       
   541 	iTestServer.DeleteFileL(KDestTzLocRscFile3);
       
   542 	iTestServer.DeleteFileL(KDestTzLocRscFile4);
       
   543 	iTestServer.DeleteFileL(KDestTzLocRscFile5);
       
   544 	iTestServer.DeleteFileL(KDestTzLocRscFile6);
       
   545 	iTestServer.DeleteDirL(KDestTzLocRscDir);
       
   546 	}
       
   547 
       
   548 /* This class wraps test cases that a change to the system TZ DB, the user defined
       
   549  * DB or the syststem TZ location resource files during the TZ server is disconnected.
       
   550  * When such a change happened, the TZ server should publish NTzUpdate::ETzRulesChange or
       
   551  * NTzUpdate::ETzNamesChange or both depending on the nature of the change.
       
   552  */
       
   553 class CTestTzServerStartChangeNotification : public CTzDataChangeNotificationTestCase
       
   554 	{
       
   555 private:
       
   556 	enum TFileModification
       
   557 		{
       
   558 		EInstalled,
       
   559 		EUninstalled
       
   560 		};
       
   561 public:
       
   562 
       
   563     static CTestTzServerStartChangeNotification* NewL(NTzUpdate::TPropertyKeys aChangePropertyKey, const TDesC& aFileCopySrc, const TDesC& aFileCopyDest);
       
   564     static CTestTzServerStartChangeNotification* NewL(NTzUpdate::TPropertyKeys aChangePropertyKey, const TDesC& aFileDelete);
       
   565      ~CTestTzServerStartChangeNotification();
       
   566      void SetUpL();
       
   567 protected:
       
   568 	CTestTzServerStartChangeNotification(NTzUpdate::TPropertyKeys aChangePropertyKey, TFileModification aFileModification);
       
   569 	void ConstructL(const TDesC& aFileCopySrc, const TDesC& aFileCopyDest);
       
   570 
       
   571 private:
       
   572 
       
   573 	void TriggerChangeNotificationL();
       
   574 	void TidyUpAfterChangeNotificationL();
       
   575 	
       
   576 	NTzUpdate::TPropertyKeys iPropertyKeys; //an expected pub&sub key to be published by the TZ server
       
   577 	HBufC* iFileSource;	//a file path to copy from
       
   578 	HBufC* iFileDestination; //a file path to copy to
       
   579 	TFileModification iFileModification;//Flag indicates whether it tests file has been installed or uninstalled.
       
   580 	};
       
   581 
       
   582 /** This is for the test case that a file (files) is (are) installed (copied) to C: drice
       
   583 @param aChangePropertyKey an expected Pub&Sub propery key which will be published when the server is connected.
       
   584 @param aFileCopySrc a file path to copy from
       
   585 @param aFileCopyDest a file path to copy to
       
   586 */
       
   587 CTestTzServerStartChangeNotification* CTestTzServerStartChangeNotification::NewL(NTzUpdate::TPropertyKeys aChangePropertyKey, const TDesC& aFileCopySrc, const TDesC& aFileCopyDest)
       
   588     {
       
   589     CTestTzServerStartChangeNotification* self =
       
   590     	new(ELeave) CTestTzServerStartChangeNotification(aChangePropertyKey, EInstalled);
       
   591     CleanupStack::PushL(self);
       
   592     self->ConstructL(aFileCopySrc, aFileCopyDest);
       
   593     CleanupStack::Pop(self);
       
   594     return self;
       
   595     }
       
   596 
       
   597 /** This is for the test case that a file (files) is(are) uninstalled (deleted) from C: drive
       
   598 @param aChangePropertyKey an expected Pub&Sub propery key which will be published when the server is connected.
       
   599 @param aFileDelete a file path to delete
       
   600 */
       
   601 CTestTzServerStartChangeNotification* CTestTzServerStartChangeNotification::NewL(NTzUpdate::TPropertyKeys	aChangePropertyKey, const TDesC& aFileDelete)
       
   602     {
       
   603     CTestTzServerStartChangeNotification* self =
       
   604     	new(ELeave) CTestTzServerStartChangeNotification(aChangePropertyKey, EUninstalled);
       
   605     CleanupStack::PushL(self);
       
   606     self->ConstructL(KNullDesC, aFileDelete);
       
   607     CleanupStack::Pop(self);
       
   608     return self;
       
   609     }
       
   610 
       
   611 CTestTzServerStartChangeNotification::CTestTzServerStartChangeNotification(NTzUpdate::TPropertyKeys aChangePropertyKey, TFileModification aFileModification)
       
   612 	:iPropertyKeys(aChangePropertyKey), iFileModification(aFileModification)
       
   613 	{
       
   614 	}
       
   615 
       
   616 
       
   617 void CTestTzServerStartChangeNotification::ConstructL(const TDesC& aFileCopySrc, const TDesC& aFileCopyDest)
       
   618     {
       
   619 	CTzDataChangeNotificationTestCase::ConstructL(iPropertyKeys);
       
   620 	iFileSource = aFileCopySrc.AllocL();
       
   621 	iFileDestination = aFileCopyDest.AllocL();
       
   622 	}
       
   623 
       
   624 CTestTzServerStartChangeNotification::~CTestTzServerStartChangeNotification()
       
   625 	{
       
   626 	delete iFileSource;
       
   627 	delete iFileDestination;
       
   628 	}
       
   629 
       
   630 void CTestTzServerStartChangeNotification::SetUpL()
       
   631 	{
       
   632 	User::LeaveIfError(iTestServer.Connect());
       
   633 	}
       
   634 
       
   635 void CTestTzServerStartChangeNotification::TriggerChangeNotificationL()
       
   636 	{
       
   637 	iTestServer.CloseTzSession();
       
   638 
       
   639 	//When deleting a TZ DB or resource files to the C: drive before the TZ server is connectted, 
       
   640 	//the TZ server should publish the change when it is started
       
   641 	if(*iFileDestination != KDestTzLocRscDir)
       
   642 		{
       
   643 		iTestServer.DeleteFileL(*iFileDestination);
       
   644 		}
       
   645 	else
       
   646 		{
       
   647 		iTestServer.DeleteFileL(KDestTzLocRscFile1);
       
   648 		iTestServer.DeleteFileL(KDestTzLocRscFile2);
       
   649 		iTestServer.DeleteFileL(KDestTzLocRscFile3);
       
   650 		iTestServer.DeleteFileL(KDestTzLocRscFile4);
       
   651 		iTestServer.DeleteFileL(KDestTzLocRscFile5);
       
   652 		iTestServer.DeleteFileL(KDestTzLocRscFile6);
       
   653 
       
   654 		iTestServer.DeleteDirL(KDestTzLocRscDir);
       
   655 		}
       
   656 	
       
   657 	//When copying a TZ DB or resource files to the C: drive before the TZ server is connectted, 
       
   658 	//the TZ server should publish the change when it is started
       
   659 	if(iFileModification == EInstalled)
       
   660 		{
       
   661 		//Delete the file which contains the time stamps to test the situation when the time stamps are not vailable first time 
       
   662 		iTestServer.DeleteFileL(KTimeStampFile);
       
   663 		if(*iFileDestination == KDestTzLocRscDir)
       
   664 			{
       
   665 			iTestServer.CopyFileL(KSrcTzLocRscFile1, KDestTzLocRscFile1);
       
   666 			iTestServer.CopyFileL(KSrcTzLocRscFile2, KDestTzLocRscFile2);
       
   667 			iTestServer.CopyFileL(KSrcTzLocRscFile3, KDestTzLocRscFile3);
       
   668 			iTestServer.CopyFileL(KSrcTzLocRscFile4, KDestTzLocRscFile4);
       
   669 			iTestServer.CopyFileL(KSrcTzLocRscFile5, KDestTzLocRscFile5);
       
   670 			iTestServer.CopyFileL(KSrcTzLocRscFile6, KDestTzLocRscFile6);
       
   671 			}
       
   672 		else
       
   673 			{
       
   674 			iTestServer.CopyFileL(*iFileSource, *iFileDestination);
       
   675 			}
       
   676 		}
       
   677 	
       
   678 	// The resolution of file modified time on hardware is one second.
       
   679 	// so make sure we wait at least that before connecting the the tz server again.
       
   680 	User::After(2000000);
       
   681 	User::LeaveIfError(iTzServer.Connect());
       
   682 	}
       
   683 
       
   684 void CTestTzServerStartChangeNotification::TidyUpAfterChangeNotificationL()
       
   685 	{//Nothing to do - all data has been cleaned during uninstall testing.
       
   686 	}
       
   687 
       
   688 /**
       
   689 TZ Data Change Notification Test Suite
       
   690 
       
   691 The purpose of the following Test Cases is to verify the client notification
       
   692 behaviour of the TZ Server component when changes are made to TZ data.
       
   693 */
       
   694 class CTzDataChangeNotificationTestSuite : public CBase
       
   695 	{
       
   696 public:
       
   697 	static CTzDataChangeNotificationTestSuite* NewLC();
       
   698 	~CTzDataChangeNotificationTestSuite();
       
   699 	
       
   700 	void RunTestsL();
       
   701 	
       
   702 private:
       
   703 	CTzDataChangeNotificationTestSuite();
       
   704 	void ConstructL();
       
   705 
       
   706 private:
       
   707 	// Test cases.
       
   708 	CTestSysTzRulesDbChangeNotification* sysTzRulesDbTestCase;
       
   709 	CTestSysTzLocRscChangeNotification* sysTzLocRscTestCase;
       
   710 	
       
   711 	CTestTzServerStartChangeNotification* tzServerStartTzRuleInstall;
       
   712 	CTestTzServerStartChangeNotification* tzServerStartTzRuleUninstall;
       
   713 	CTestTzServerStartChangeNotification* tzServerStartUserRuleInstall;
       
   714 	CTestTzServerStartChangeNotification* tzServerStartUserRuleUninstall;
       
   715 	CTestTzServerStartChangeNotification* tzServerStartUseNameInstall;
       
   716 	CTestTzServerStartChangeNotification* tzServerStartUseNameUninstall;
       
   717 	CTestTzServerStartChangeNotification* tzServerStartLocRscInstall;
       
   718 	CTestTzServerStartChangeNotification* tzServerStartLocRscUninstall;
       
   719 	};
       
   720 		
       
   721 
       
   722 CTzDataChangeNotificationTestSuite* CTzDataChangeNotificationTestSuite::NewLC()
       
   723 	{
       
   724 	CTzDataChangeNotificationTestSuite* self =
       
   725 		new(ELeave) CTzDataChangeNotificationTestSuite();
       
   726 	CleanupStack::PushL(self);
       
   727 	self->ConstructL();		
       
   728 	return self;
       
   729 	}
       
   730 
       
   731 
       
   732 CTzDataChangeNotificationTestSuite::CTzDataChangeNotificationTestSuite()
       
   733 	{
       
   734 	}
       
   735 
       
   736 
       
   737 void CTzDataChangeNotificationTestSuite::ConstructL()
       
   738 	{
       
   739 	sysTzRulesDbTestCase = CTestSysTzRulesDbChangeNotification::NewL();
       
   740 	sysTzLocRscTestCase = CTestSysTzLocRscChangeNotification::NewL();
       
   741 	
       
   742 	tzServerStartTzRuleInstall = CTestTzServerStartChangeNotification::NewL(NTzUpdate::ETzRulesChange, KSrcTzRulesDb, KDestTzRulesDb);
       
   743 	tzServerStartTzRuleUninstall = CTestTzServerStartChangeNotification::NewL(NTzUpdate::ETzRulesChange, KDestTzRulesDb);
       
   744 	tzServerStartUserRuleInstall = CTestTzServerStartChangeNotification::NewL(NTzUpdate::ETzRulesChange, KSrcTzUserDb, KDestTzUserDb);
       
   745 	tzServerStartUserRuleUninstall = CTestTzServerStartChangeNotification::NewL(NTzUpdate::ETzRulesChange, KDestTzUserDb);
       
   746 	tzServerStartUseNameInstall = CTestTzServerStartChangeNotification::NewL(NTzUpdate::ETzNamesChange, KSrcTzUserDb, KDestTzUserDb);
       
   747 	tzServerStartUseNameUninstall = CTestTzServerStartChangeNotification::NewL(NTzUpdate::ETzNamesChange, KDestTzUserDb);
       
   748 	tzServerStartLocRscInstall = CTestTzServerStartChangeNotification::NewL(NTzUpdate::ETzNamesChange, KSrcTzLocRscDir, KDestTzLocRscDir);
       
   749 	tzServerStartLocRscUninstall = CTestTzServerStartChangeNotification::NewL(NTzUpdate::ETzNamesChange, KDestTzLocRscDir);
       
   750 	}
       
   751 
       
   752 
       
   753 CTzDataChangeNotificationTestSuite::~CTzDataChangeNotificationTestSuite()
       
   754 	{
       
   755 	delete sysTzRulesDbTestCase;
       
   756 	delete sysTzLocRscTestCase;
       
   757 	delete tzServerStartTzRuleInstall;
       
   758 	delete tzServerStartTzRuleUninstall;
       
   759 	delete tzServerStartUserRuleInstall;
       
   760 	delete tzServerStartUserRuleUninstall;
       
   761 	delete tzServerStartUseNameInstall;
       
   762 	delete tzServerStartUseNameUninstall;
       
   763 	delete tzServerStartLocRscInstall;
       
   764 	delete tzServerStartLocRscUninstall;
       
   765 	}
       
   766 
       
   767 
       
   768 void CTzDataChangeNotificationTestSuite::RunTestsL()
       
   769 	{
       
   770 	test.Title();
       
   771 
       
   772 	
       
   773 	test.Start(_L("@SYMTestCaseID PIM-APPSERV-TZ-TZS-CN-0001  Test notification of system TZ rules database change."));
       
   774 	sysTzRulesDbTestCase->TestChangeNotificationL();
       
   775 
       
   776 	test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZ-TZS-CN-0002 Test notification of system TZ localization resources change."));
       
   777 	sysTzLocRscTestCase->TestChangeNotificationL();
       
   778 
       
   779 	
       
   780 	test.Next(_L("Test notification when the time zone server connected"));
       
   781 	//The following CTestTzServerStartChangeNotificationtest test cases are to verify that the TZ server will publish a NTzUpdate::ETzRulesChange or
       
   782 	//NTzUpdate::ETzNamesChange if a change of the system TZ DB or the user defined DB or the syststem TZ location resource files 
       
   783 	//happened when the TZ server is not connected.
       
   784 
       
   785 	// A system TZ DB is copied to the C: when the server is not connected, NTzUpdate::ETzRulesChange should be publised
       
   786 	test.Printf(_L("A system TZ DB is copied to the C:- expect for NTzUpdate::ETzRulesChange"));
       
   787 	tzServerStartTzRuleInstall->TestChangeNotificationL();
       
   788 	// A system TZ DB is removed from the C: when the server is not connected, NTzUpdate::ETzRulesChange should be publised
       
   789 	test.Printf(_L("A system TZ DB is removed from the C:- expect for NTzUpdate::ETzRulesChange"));
       
   790 	tzServerStartTzRuleUninstall->TestChangeNotificationL();
       
   791 	// A user defined DB is copied to the C: when the server is not connected, NTzUpdate::ETzRulesChange should be publised
       
   792 	test.Printf(_L("A user defined DB is copied to the C: - expect for NTzUpdate::ETzRulesChange"));
       
   793 	tzServerStartUserRuleInstall->TestChangeNotificationL();
       
   794 	// A user defined DB is removed from the C: when the server is not connected, NTzUpdate::ETzRulesChange should be publised
       
   795 	test.Printf(_L("A user defined DB is removed from the C: - expect for NTzUpdate::ETzRulesChange"));
       
   796 	tzServerStartUserRuleUninstall->TestChangeNotificationL();
       
   797 	// A user defined DB is copied to the C: when the server is not connected, NTzUpdate::ETzNamesChange should be publised
       
   798 	test.Printf(_L("A user defined DB is copied to the C:- expect for NTzUpdate::ETzNamesChange"));
       
   799 	tzServerStartUseNameInstall->TestChangeNotificationL();
       
   800 	// A user defined DB is remove from the C: when the server is not connected, NTzUpdate::ETzNamesChange should be publised
       
   801 	test.Printf(_L("A user defined DB is removed from the C:- expect for NTzUpdate::ETzNamesChange"));
       
   802 	tzServerStartUseNameUninstall->TestChangeNotificationL();
       
   803 	// Some localization files are copied to the C: when the server is not connected, NTzUpdate::ETzNamesChange should be publised
       
   804 	test.Printf(_L("Some localization files are copied to the C:- expect for NTzUpdate::ETzNamesChange"));
       
   805 	tzServerStartLocRscInstall->TestChangeNotificationL();
       
   806 	// Some localization files are removed from the C: when the server is not connected, NTzUpdate::ETzNamesChange should be publised
       
   807 	test.Printf(_L("Some localization files are removed from the C:- expect for NTzUpdate::ETzNamesChange"));
       
   808 	tzServerStartLocRscUninstall->TestChangeNotificationL();
       
   809 	test.End();
       
   810 	}
       
   811 
       
   812 
       
   813 static void DoTestsL()
       
   814 	{
       
   815 	CTzDataChangeNotificationTestSuite* testSuite =
       
   816 		CTzDataChangeNotificationTestSuite::NewLC();
       
   817 	
       
   818 	//Have to kill agenda server to make sure no session is connected to the TZ server
       
   819 	RPIMTestServer serv;
       
   820 	User::LeaveIfError(serv.Connect());
       
   821 	CleanupClosePushL(serv);
       
   822 	serv.CloseTzSession();
       
   823 	_LIT(KAgendaServer,"agsvexe*");
       
   824 	TRAP_IGNORE(serv.KillProcessL(KAgendaServer));
       
   825 	_LIT(KTzServer,"Tzserver*");
       
   826 	TRAP_IGNORE(serv.KillProcessL(KTzServer));
       
   827 	CleanupStack::PopAndDestroy(&serv);
       
   828 
       
   829 	testSuite->RunTestsL();
       
   830 	
       
   831 	CleanupStack::PopAndDestroy(testSuite);
       
   832 	}
       
   833 
       
   834 
       
   835 TInt E32Main()
       
   836     {
       
   837 	__UHEAP_MARK;
       
   838 
       
   839 	CTrapCleanup* trapCleanup = CTrapCleanup::New();
       
   840 	if(!trapCleanup)
       
   841 		{
       
   842 		return KErrNoMemory;
       
   843 		}
       
   844 
       
   845 	CActiveScheduler* scheduler = new CActiveScheduler;
       
   846 	if(!scheduler)
       
   847 		{
       
   848 		return KErrNoMemory;
       
   849 		}
       
   850 	CActiveScheduler::Install(scheduler);	
       
   851 
       
   852 	TRAPD(ret, DoTestsL());
       
   853 	test.Printf(_L("Trapped return value from DoTestsL(): %d\n"), ret);
       
   854 	test(ret == KErrNone);
       
   855 	
       
   856 	test.Close();
       
   857 	
       
   858 	delete scheduler;
       
   859 	delete trapCleanup;	
       
   860 
       
   861 	__UHEAP_MARKEND;
       
   862 
       
   863 	return (KErrNone);
       
   864     }