tzservices/tzserver/test/component/t_databaseupdate.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 #include <e32test.h>
       
    17 #include "testserver.h"
       
    18 #include <vtzrules.h>
       
    19 
       
    20 _LIT8(KEuropeLondon, "Europe/London");
       
    21 _LIT8(KEuropeParis, "Europe/Paris");
       
    22 _LIT(KTzDatabaseToBeCopied, "z:\\testresourcefiles\\tzdb.dbz");
       
    23 _LIT(KTzDatabaseCopiedToFlash, "c:\\private\\1020383e\\tzdb.dbz");
       
    24 _LIT(KTzDatabaseToBeDeleted, "c:\\private\\1020383e\\tzdb.dbz");
       
    25 
       
    26 RTest test (_L("t_databaseupdate"));
       
    27 
       
    28 /**
       
    29 @SYMTestCaseID      PIM-APPSERV-TZ-TZS-ECL-0001
       
    30 @SYMTestCaseDesc    The purpose of this test is to verify the use of eclipsed system
       
    31 					TZ rules database.  
       
    32 @SYMTestActions     1.	Use the RTz API to obtain a copy of the first TZ rule (preUpdateRule)
       
    33 						for a given time zone.
       
    34 					2.	Copy a system TZ rules database that modifies the TZ rule obtained in 
       
    35 						action 1 to the appropriate location the C: drive.
       
    36 					3.	Use the RTz API to obtain a copy of the first TZ rule (postUpdateRule) 
       
    37 						for the same time zone used in action 2.
       
    38 
       
    39 @SYMTestExpectedResults     The preUpdateRule object is not the same as the postUpdateRule object.
       
    40 @SYMREQ                     REQ9952
       
    41 @SYMTestType                CT
       
    42 @SYMTestPriority            1
       
    43 */
       
    44 LOCAL_C void TestRulesInTzDatabaseL()
       
    45     {
       
    46    	RTz tz;
       
    47   	CleanupClosePushL(tz);
       
    48   	User::LeaveIfError(tz.Connect());
       
    49     	
       
    50   	CTzId* tzId = CTzId::NewL(KEuropeLondon);
       
    51   	CleanupStack::PushL(tzId);
       
    52   	tz.SetTimeZoneL(*tzId);
       
    53   	
       
    54   	TDateTime startDateTime(2008,EJanuary,0,0,0,0,0);
       
    55 	TDateTime endDateTime(2008,EDecember,30,23,59,59,0);
       
    56    	CTzRules* tzRules = tz.GetTimeZoneRulesL(*tzId,startDateTime,endDateTime,ETzUtcTimeReference);
       
    57   	CleanupStack::PushL(tzRules);
       
    58     	
       
    59    	TInt count = tzRules->Count();
       
    60 	test.Printf(_L(" @SYMTestCaseID PIM-APPSERV-TZ-TZS-ECL-0001"));
       
    61    	test.Printf(_L("The number of rules found in default database are %d\n"), count);
       
    62   	
       
    63    	CleanupStack::PopAndDestroy(tzRules);
       
    64     tz.Close();
       
    65   	
       
    66    	RPIMTestServer serv;	
       
    67 	CleanupClosePushL(serv);
       
    68 	TInt err = serv.Connect();
       
    69 	if (err != KErrNone)
       
    70 		{
       
    71 		_LIT(KErrTestServerConnection, "Couldn't connect to PIMTestServer\n");
       
    72 		test.Printf(KErrTestServerConnection);
       
    73 		User::Leave(err);
       
    74 		}
       
    75 	TRAP(err, serv.CopyFileL(KTzDatabaseToBeCopied, KTzDatabaseCopiedToFlash));
       
    76 	if (err != KErrNone)
       
    77 		{
       
    78 		_LIT(KErrCopyFiles, "Couldn't copy database file\n");
       
    79 		test.Printf(KErrCopyFiles);
       
    80 		User::Leave(err);
       
    81 		}
       
    82 
       
    83 	User::LeaveIfError(tz.Connect());
       
    84 	
       
    85 	CTzId* parisId = CTzId::NewL(KEuropeParis);
       
    86 	CleanupStack::PushL(parisId);
       
    87 	tz.SetTimeZoneL(*parisId);
       
    88 	CleanupStack::PopAndDestroy(parisId);
       
    89   	
       
    90  	tz.SetTimeZoneL(*tzId);
       
    91   	CTzRules* tzRulesFlash = tz.GetTimeZoneRulesL(*tzId,startDateTime,endDateTime,ETzUtcTimeReference);
       
    92   	CleanupStack::PushL(tzRulesFlash);
       
    93    	  	
       
    94    	TInt countFlash = tzRulesFlash->Count();
       
    95   	test.Printf(_L("The number of rules found in the database on flash are %d\n"), countFlash);
       
    96   		
       
    97   	test(count != countFlash);
       
    98 	
       
    99 	serv.DeleteFileL(KTzDatabaseToBeDeleted);
       
   100 	tz.SwiObsBeginL();
       
   101 	tz.SwiObsFileChangedL(RTz::EFilterTzPrivate);
       
   102 	tz.SwiObsEndL();
       
   103 	
       
   104 	CleanupStack::PopAndDestroy(tzRulesFlash);
       
   105 	CleanupStack::PopAndDestroy(&serv);   	
       
   106   	CleanupStack::PopAndDestroy(tzId);
       
   107    	CleanupStack::PopAndDestroy(&tz);    	   	
       
   108 	}
       
   109 
       
   110 /**
       
   111 @SYMTestCaseID      PIM-DATABASEUPDATE-0001
       
   112 @SYMTestCaseDesc    The purpose of this test is to verify that eclipsing is taken into account
       
   113 					even if the time zone server is running.  
       
   114 @SYMTestActions     1.	Use the RTz API to obtain a copy of the first TZ rule (preUpdateRule)
       
   115 						for a given time zone.
       
   116 					2.	Copy a system TZ rules database that modifies the TZ rule obtained in 
       
   117 						action 1 to the appropriate location the C: drive. The server is still
       
   118 						running when this happens.
       
   119 					3.	Use the RTz API to obtain a copy of the first TZ rule (postUpdateRule) 
       
   120 						for the same time zone used in action 2.
       
   121 
       
   122 @SYMTestExpectedResults     The preUpdateRule object is not the same as the postUpdateRule object.
       
   123 @SYMREQ                     REQ9952
       
   124 @SYMTestType                CT
       
   125 @SYMTestPriority            1
       
   126 */
       
   127 LOCAL_C void TestRulesInTzDatabaseLiveUpdateL()
       
   128     {
       
   129     RTz tz;
       
   130   	CleanupClosePushL(tz);
       
   131   	User::LeaveIfError(tz.Connect());
       
   132   	
       
   133   	CTzId* tzId = CTzId::NewL(KEuropeLondon);
       
   134   	CleanupStack::PushL(tzId);
       
   135   	tz.SetTimeZoneL(*tzId);
       
   136   	
       
   137   	TDateTime startDateTime(2008,EJanuary,0,0,0,0,0);
       
   138 	TDateTime endDateTime(2008,EDecember,30,23,59,59,0);
       
   139    	CTzRules* tzRules = tz.GetTimeZoneRulesL(*tzId,startDateTime,endDateTime,ETzUtcTimeReference);
       
   140   	CleanupStack::PushL(tzRules);
       
   141     TInt count = tzRules->Count();
       
   142    	test.Printf(_L("The number of rules found in default database are %d\n"), count);
       
   143   	CleanupStack::PopAndDestroy(tzRules);
       
   144   	
       
   145   	RPIMTestServer serv;	
       
   146 	CleanupClosePushL(serv);
       
   147 	TInt err = serv.Connect();
       
   148 	if (err != KErrNone)
       
   149 		{
       
   150 		_LIT(KErrTestServerConnection, "Couldn't connect to PIMTestServer\n");
       
   151 		test.Printf(KErrTestServerConnection);
       
   152 		User::Leave(err);
       
   153 		}
       
   154 	TRAP(err, serv.CopyFileL(KTzDatabaseToBeCopied, KTzDatabaseCopiedToFlash));
       
   155 	if (err != KErrNone)
       
   156 		{
       
   157 		_LIT(KErrCopyFiles, "Couldn't copy database file\n");
       
   158 		test.Printf(KErrCopyFiles);
       
   159 		User::Leave(err);
       
   160 		}
       
   161 	tz.SwiObsBeginL();
       
   162 	tz.SwiObsFileChangedL(RTz::EFilterTzPrivate);
       
   163 	tz.SwiObsEndL();
       
   164    	
       
   165 	CTzRules* tzRulesFlash = tz.GetTimeZoneRulesL(*tzId,startDateTime,endDateTime,ETzUtcTimeReference);
       
   166   	CleanupStack::PushL(tzRulesFlash);
       
   167    	  	
       
   168    	TInt countFlash = tzRulesFlash->Count();
       
   169 	test.Printf(_L(" @SYMTestCaseID PIM-DATABASEUPDATE-0001 "));
       
   170   	test.Printf(_L("The number of rules found in the database on flash are %d\n"), countFlash);
       
   171   		
       
   172   	test(count != countFlash);
       
   173 	
       
   174 	serv.DeleteFileL(KTzDatabaseToBeDeleted);
       
   175 	
       
   176 	CleanupStack::PopAndDestroy(tzRulesFlash);
       
   177 	CleanupStack::PopAndDestroy(&serv);   	
       
   178   	CleanupStack::PopAndDestroy(tzId);
       
   179 	CleanupStack::PopAndDestroy(&tz);    	
       
   180     }
       
   181 
       
   182 LOCAL_C void DoStartL()
       
   183 	{
       
   184 	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
       
   185 	CleanupStack::PushL(scheduler);
       
   186 	
       
   187 	CActiveScheduler::Install(scheduler);
       
   188 
       
   189 	TestRulesInTzDatabaseL();
       
   190 	TestRulesInTzDatabaseLiveUpdateL();
       
   191 	
       
   192 	// Delete active scheduler
       
   193 	CleanupStack::PopAndDestroy(scheduler);	
       
   194 	}
       
   195 
       
   196 //  Global Functions
       
   197 	
       
   198 	
       
   199 GLDEF_C TInt E32Main()
       
   200 	{
       
   201 	// Create cleanup stack
       
   202 	__UHEAP_MARK;
       
   203 	test.Start(_L("Starting Test t_databaseupdate"));
       
   204 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   205 
       
   206 	// Run application code inside TRAP harness.
       
   207 	TRAPD(mainError, DoStartL());
       
   208 	
       
   209 	test(mainError == KErrNone);
       
   210 	
       
   211 	delete cleanup;
       
   212 	test.End();
       
   213 	test.Close();
       
   214 	__UHEAP_MARKEND;
       
   215 	return KErrNone;
       
   216 	}
       
   217