tzservices/tzloc/test/rtest/t_localizationuserdata.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 <e32std.h>
       
    18 #include <e32des16.h>
       
    19 #include <e32test.h>
       
    20 #include <tzlocalizer.h> 
       
    21 #include <tzlocalizationdatatypes.h>
       
    22 #include <tz.h>
       
    23 #include <vtzrules.h>
       
    24 #include "testserver.h"
       
    25 #include <e32math.h>
       
    26 #include <tzlocalizedcityrecord.h>
       
    27 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    28 #include <tzusernames.h>
       
    29 #include <tzuserdefineddata.h>
       
    30 #endif
       
    31 
       
    32 
       
    33 class CTzLocalizationUserDataSuite : public CBase
       
    34 	{
       
    35 public:
       
    36     static CTzLocalizationUserDataSuite* NewLC();
       
    37 	~CTzLocalizationUserDataSuite();
       
    38 	void TestLocalizedTimeZoneL();
       
    39 	void TestLocalizedTimeZoneWithLocalizeIDL();
       
    40 	void TestLocalizedCityL();
       
    41 	void TestDefaultCityL();
       
    42 	void TestCityGroupL();
       
    43 	void TestCityArrayL();
       
    44 	void TestCurrentTimeZoneL();
       
    45 	void TestFindTimeZoneL();
       
    46 	void TestUserDataModificationL(CTzLocalizedTimeZone::TTzFrequentlyUsedZone aTimeZone);
       
    47 	void TestUserDataDeletionL();
       
    48 	void TestUserDataDeletionCityImpactL();
       
    49 	void TestUserDefinedTimeZoneL();
       
    50 
       
    51 private:
       
    52 	CTzLocalizationUserDataSuite();
       
    53 	void ConstructL();
       
    54 	void ResetTzUserDataL();
       
    55 
       
    56 	CTzId* CreateTimeZoneL();
       
    57 	CTzUserNames* CreateUserRuleAndGetNamesLC(TInt& aTimeZoneId);
       
    58 	void TestFindTimeZoneByNameL(TInt aTimeZoneId, const CTzUserNames& aNames,const TDesC& aNameToFind);
       
    59 	
       
    60 	CTzRules* CreateRulesLC();
       
    61 	CTzUserNames* CreateNamesLC();
       
    62 
       
    63 	TBool CompareLocalizedCity(TInt aTimeZoneId, const CTzUserNames& aNames, const CTzLocalizedCity& aCity);
       
    64 	TBool CompareTimeZoneNames(TInt aTimezoneId, const CTzUserNames& aNames, const CTzLocalizedTimeZone& aLocalizedTimeZone);
       
    65 	TBool CompareLocalizedCityGroup(const CTzUserNames& aNames, const CTzLocalizedCityGroup& aCityGroup);
       
    66 	TBool FindCityInArrayL(const CTzLocalizedCityArray& aCityArray, TInt aTimeZoneId, const CTzUserNames& aNames);
       
    67 	TBool CompareLocalizedCity(const CTzLocalizedCity& aCity, const CTzLocalizedCity& aCityToCompare);
       
    68 	TBool CompareTimeZoneName(const CTzLocalizedTimeZone& aTimeZone, const CTzLocalizedTimeZone& aTimeZoneToCompare);
       
    69 	
       
    70 	void CreateString(TDes& aString);
       
    71 	TBool TestTimeZoneShortStandardNameL(CTzLocalizer& aTzLocalizer, const TDesC& aShortStandardName);
       
    72 	
       
    73 private:
       
    74 	CTzLocalizer* 	iLocalizer;
       
    75 	RTz				iTzSession;
       
    76 	CTzUserData*	iUserData;
       
    77 	TInt64 			iSeed;
       
    78 	};
       
    79 
       
    80 
       
    81 _LIT(KTestName,"t_localizationuserdata");
       
    82 _LIT(KPerFile1,"c:\\private\\100012a5\\DBS_2000836D_DBS_DSC.db");
       
    83 _LIT(KPerFile2,"c:\\private\\100012a5\\DBS_10206A8B_TzLocalization.db");
       
    84 	
       
    85 _LIT(KUserAddedCity1Name, "UserAddedCity1");
       
    86 _LIT(KUserAddedCity2Name, "UserAddedCity2");
       
    87 _LIT(KUserAddedCity3Name, "UserAddedCity3");
       
    88 
       
    89 
       
    90 const TInt KLondonTzId = 2592;
       
    91 const TInt KParisTzId = 2656;
       
    92 
       
    93 
       
    94 RTest test(KTestName);
       
    95 
       
    96 
       
    97 LOCAL_D void ResetAndDestroyTzIdArray(TAny* aPtr)
       
    98 	{
       
    99 	RPointerArray<CTzId>* ids = static_cast<RPointerArray<CTzId>*>(aPtr);
       
   100 	if (ids)
       
   101 		{
       
   102 		ids->ResetAndDestroy();
       
   103 		}
       
   104 	}
       
   105 
       
   106 
       
   107 CTzLocalizationUserDataSuite* CTzLocalizationUserDataSuite::NewLC()
       
   108 	{
       
   109 	CTzLocalizationUserDataSuite* self = new (ELeave) CTzLocalizationUserDataSuite();
       
   110 	CleanupStack::PushL(self);
       
   111 	self->ConstructL();
       
   112 	return (self);
       
   113 	}
       
   114 
       
   115 
       
   116 CTzLocalizationUserDataSuite::CTzLocalizationUserDataSuite():iSeed(100)
       
   117 	{
       
   118 	}
       
   119 
       
   120 
       
   121 void CTzLocalizationUserDataSuite::ConstructL()
       
   122 	{
       
   123 	iLocalizer = CTzLocalizer::NewL();
       
   124 	iLocalizer->SetDataSource(CTzLocalizer::ETzDataSourceSystem|CTzLocalizer::ETzDataSourceUser);
       
   125 	iLocalizer->SetTimeZoneL(KLondonTzId);
       
   126 	
       
   127 	User::LeaveIfError(iTzSession.Connect());
       
   128 	iUserData = CTzUserData::NewL(iTzSession);
       
   129 	}
       
   130 
       
   131 
       
   132 CTzLocalizationUserDataSuite::~CTzLocalizationUserDataSuite()	
       
   133 	{
       
   134 	TRAP_IGNORE(iLocalizer->SetTimeZoneL(KLondonTzId));
       
   135 	delete iLocalizer;
       
   136 	delete iUserData;
       
   137 	iTzSession.Close();
       
   138 	}
       
   139 
       
   140 
       
   141 CTzUserNames* CTzLocalizationUserDataSuite::CreateUserRuleAndGetNamesLC(TInt& aTimeZoneId)
       
   142 	{
       
   143 	CTzId* tzid = CreateTimeZoneL();
       
   144 	CleanupStack::PushL(tzid);
       
   145 	CTzUserNames* names = iUserData->ReadNamesL(*tzid);
       
   146 	aTimeZoneId = tzid->TimeZoneNumericID();
       
   147 	CleanupStack::PopAndDestroy(tzid);
       
   148 	CleanupStack::PushL(names);
       
   149 	return names;
       
   150 	}
       
   151 
       
   152 
       
   153 TBool CTzLocalizationUserDataSuite::CompareTimeZoneNames(TInt aTimeZoneId, const CTzUserNames& aNames, const CTzLocalizedTimeZone& aLocalizedTimeZone)
       
   154 	{
       
   155 	if (aTimeZoneId != aLocalizedTimeZone.TimeZoneId())
       
   156 		{
       
   157 		return EFalse; 
       
   158 		}
       
   159 	if (aNames.StandardName() !=  aLocalizedTimeZone.StandardName())
       
   160 		{
       
   161 		return EFalse; 
       
   162 		}
       
   163 	if (aNames.ShortStandardName() != aLocalizedTimeZone.ShortStandardName())
       
   164 		{
       
   165 		return EFalse;
       
   166 		}
       
   167 	if (aNames.DaylightSaveName() != aLocalizedTimeZone.DaylightName())
       
   168 		{
       
   169 		return EFalse;
       
   170 		}
       
   171 	if (aNames.ShortDaylightSaveName() != aLocalizedTimeZone.ShortDaylightName())
       
   172 		{
       
   173 		return EFalse;
       
   174 		}
       
   175 	
       
   176 	return ETrue;
       
   177 	}
       
   178 
       
   179 
       
   180 TBool CTzLocalizationUserDataSuite::CompareLocalizedCity(TInt aTimeZoneId, const CTzUserNames& aNames, const CTzLocalizedCity& aCity)
       
   181 	{	
       
   182 	if (aNames.CityName() != aCity.Name())
       
   183 		{
       
   184 		return EFalse;
       
   185 		}
       
   186 	if (aTimeZoneId != aCity.TimeZoneId())
       
   187 		{
       
   188 		return EFalse;
       
   189 		}
       
   190 	if (aCity.GroupId()!=0)
       
   191 		{
       
   192 		return EFalse;
       
   193 		}
       
   194 		
       
   195 	return ETrue;
       
   196 	}
       
   197 
       
   198 
       
   199 TBool CTzLocalizationUserDataSuite::CompareLocalizedCityGroup(const CTzUserNames& aNames, const CTzLocalizedCityGroup& aCityGroup)
       
   200 	{	
       
   201 	if (aNames.RegionName() != aCityGroup.Name())
       
   202 		{
       
   203 		return EFalse;
       
   204 		}
       
   205 	if (aCityGroup.Id()!=0)
       
   206 		{
       
   207 		return EFalse;
       
   208 		}
       
   209 		
       
   210 	return ETrue;
       
   211 	}
       
   212 
       
   213 	
       
   214 TBool CTzLocalizationUserDataSuite::CompareLocalizedCity(const CTzLocalizedCity& aCity, const CTzLocalizedCity& aCityToCompare)
       
   215 	{
       
   216 	if(aCity.TimeZoneId() != aCityToCompare.TimeZoneId() )
       
   217 		{
       
   218 		return EFalse;
       
   219 		}
       
   220 	if(aCity.GroupId() != aCityToCompare.GroupId())
       
   221 		{
       
   222 		return EFalse;
       
   223 		}
       
   224 	if(aCity.Name() != aCityToCompare.Name())
       
   225 		{
       
   226 		return EFalse;
       
   227 		}
       
   228 	return ETrue;
       
   229 	}
       
   230 
       
   231 
       
   232 TBool CTzLocalizationUserDataSuite::CompareTimeZoneName(const CTzLocalizedTimeZone& aTimeZone, const CTzLocalizedTimeZone& aTimeZoneToCompare)
       
   233 	{
       
   234 	if(aTimeZone.StandardName() != aTimeZoneToCompare.StandardName())
       
   235 		{
       
   236 		return EFalse;
       
   237 		}
       
   238 	if(aTimeZone.ShortStandardName() != aTimeZoneToCompare.ShortStandardName())
       
   239 		{
       
   240 		return EFalse;
       
   241 		}
       
   242 	if(aTimeZone.DaylightName() != aTimeZoneToCompare.DaylightName())
       
   243 		{
       
   244 		return EFalse;
       
   245 		}
       
   246 	if(aTimeZone.ShortDaylightName() != aTimeZoneToCompare.ShortDaylightName())
       
   247 		{
       
   248 		return EFalse;
       
   249 		}
       
   250 	return ETrue;	
       
   251 	}
       
   252 	
       
   253 	
       
   254 CTzId* CTzLocalizationUserDataSuite::CreateTimeZoneL()
       
   255 	{	
       
   256 	//Create a user defined rule - CTzRules.
       
   257 	TTime dston (TDateTime(2005, EMarch, 0, 0, 0, 0, 0)); 
       
   258 	TTime dstoff (TDateTime(2005, ESeptember, 0, 0, 0, 0, 0));
       
   259 	TMonth monthOn = dston.DateTime().Month();
       
   260 	TInt dayOn = dston.DateTime().Day();
       
   261 	TMonth monthOff = dstoff.DateTime().Month();
       
   262 	TInt dayOff = dstoff.DateTime().Day();
       
   263 	
       
   264 	TTzRule dstOff(0, 9999, 0, 0, monthOn,  ETzFixedDate, dayOn,  0, ETzWallTimeReference, 0);
       
   265 	TTzRule dstOn (0, 9999, 0, 0, monthOff, ETzFixedDate, dayOff, 0, ETzWallTimeReference, 0);
       
   266 
       
   267 	CTzRules* rules = CTzRules::NewL(0, KMaxTUint);
       
   268 	CleanupStack::PushL(rules);
       
   269 	rules->AddRuleL(dstOff);
       
   270 	rules->AddRuleL(dstOn);
       
   271 	
       
   272 	//Create a user defined rule names- CTzUserNames.
       
   273 	_LIT(KStandardName, "UserTzName");
       
   274 	_LIT(KShortName, "UserTzSh");
       
   275 	_LIT(KDaylightSaveName, "UserDLSaveName");
       
   276 	_LIT(KShortDaylightSaveName, "UserShDLS");
       
   277 	_LIT(KCityNameName, "UserCityName");
       
   278 	_LIT(KRegionName, "UserRegionName");
       
   279 	
       
   280 	CTzUserNames* names = CTzUserNames::NewLC(KStandardName(), KShortName(), KDaylightSaveName(), KShortDaylightSaveName(), KCityNameName(), KRegionName());
       
   281 	//Add the rule to the database
       
   282 	CTzId* tzid = iUserData->CreateL(*rules, *names);
       
   283 	CleanupStack::PopAndDestroy(2, rules);
       
   284 	return tzid;
       
   285 	}
       
   286 
       
   287 
       
   288 void CTzLocalizationUserDataSuite::ResetTzUserDataL()
       
   289 	{
       
   290 	RPointerArray<CTzId> ids;
       
   291 	CleanupStack::PushL(TCleanupItem(ResetAndDestroyTzIdArray, &ids));
       
   292 	iUserData->GetTzIdsL(ids);
       
   293 	TInt count = ids.Count();
       
   294 	for (TInt ii=0; ii<count; ++ii)
       
   295 		{
       
   296 		iUserData->DeleteL(*ids[ii]);	
       
   297 		}
       
   298 	CleanupStack::PopAndDestroy(&ids);	
       
   299 	}
       
   300 
       
   301 
       
   302 TBool CTzLocalizationUserDataSuite::FindCityInArrayL(const CTzLocalizedCityArray& aCityArray, TInt aTimeZoneId, const CTzUserNames& aNames)
       
   303 	{
       
   304 	TBool found = EFalse;
       
   305 	const TInt count = aCityArray.Count();
       
   306 	for(TInt ii=0; ii<count; ++ii)
       
   307 		{
       
   308 		if(CompareLocalizedCity(aTimeZoneId, aNames, aCityArray.At(ii)))
       
   309 			{
       
   310 			found = ETrue;
       
   311 			break;
       
   312 			}
       
   313 		}
       
   314 	return found;
       
   315 	}
       
   316 
       
   317 
       
   318 void CTzLocalizationUserDataSuite::TestFindTimeZoneByNameL(TInt aTimeZoneId, const CTzUserNames& aNames,const TDesC& aNameToFind)
       
   319 	{
       
   320 	CTzLocalizedTimeZone* timeZone = iLocalizer->FindTimeZoneByNameL(aNameToFind);
       
   321 	CleanupStack::PushL(timeZone);
       
   322 	test(CompareTimeZoneNames(aTimeZoneId, aNames, *timeZone));
       
   323 	CleanupStack::PopAndDestroy(timeZone);
       
   324 	}
       
   325 
       
   326 
       
   327 /**
       
   328 @SYMTestCaseID	PIM-APPSERV-TZL-TZN-0001
       
   329 	
       
   330 @SYMTestCaseDesc
       
   331 	The purpose of this test is to verify that the localized time zone names for
       
   332 	a user defined time zone is correct.
       
   333 	
       
   334 @SYMTestActions     
       
   335 	1.	Create a user defined zone and store the returned time zone identifier.
       
   336 	2.	Get the localized time zone information for the user defined time zone
       
   337 		identifier obtained in action 1. 
       
   338 
       
   339 @SYMTestExpectedResults
       
   340 	The following information is the same as that used to create the user
       
   341 	defined time zone in action 1:
       
   342 
       
   343 	- Standard time zone name
       
   344  	- Short standard time zone name
       
   345  	- Standard daylight saving time name
       
   346  	- Short daylight saving time name
       
   347 
       
   348 @SYMTestType: 	CT
       
   349 	
       
   350 @SYMTestPriority: 1
       
   351 */
       
   352 
       
   353 
       
   354 
       
   355 void CTzLocalizationUserDataSuite::TestLocalizedTimeZoneL()
       
   356 	{
       
   357 	test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZL-TZN-0001 Test Localized Time Zone"));
       
   358 	TInt tzid = 0;
       
   359 	CTzUserNames* names = CreateUserRuleAndGetNamesLC(tzid);
       
   360 	CTzLocalizedTimeZone* locTimezone = iLocalizer->GetLocalizedTimeZoneL(tzid);
       
   361 	CleanupStack::PushL(locTimezone);
       
   362 	test(CompareTimeZoneNames(tzid, *names, *locTimezone));
       
   363 	CleanupStack::PopAndDestroy(2, names);
       
   364 	ResetTzUserDataL();
       
   365 	}
       
   366 
       
   367 
       
   368 	
       
   369 void CTzLocalizationUserDataSuite::TestLocalizedTimeZoneWithLocalizeIDL()
       
   370 	{
       
   371 	test.Next(_L("Test Localized Time Zone"));
       
   372 	TInt tzid = 0;
       
   373 	CTzUserNames* names = CreateUserRuleAndGetNamesLC(tzid);
       
   374 	CTzLocalizedCity* city = iLocalizer->GetDefaultCityL(tzid);
       
   375 	CleanupStack::PushL(city);
       
   376 	CTzLocalizedTimeZone* locTimezone = iLocalizer->GetLocalizedTimeZoneL(*city);
       
   377 	CleanupStack::PopAndDestroy(city);
       
   378 	CleanupStack::PushL(locTimezone);
       
   379 	test(CompareTimeZoneNames(tzid, *names, *locTimezone));
       
   380 	CleanupStack::PopAndDestroy(2, names);
       
   381 	ResetTzUserDataL();
       
   382 	}
       
   383 
       
   384 
       
   385 /**
       
   386 @SYMTestCaseID PIM-APPSERV-TZL-TZN-0002
       
   387 	
       
   388 @SYMTestCaseDesc
       
   389 	The purpose of this test is to verify that the localized city information
       
   390 	for a user defined time zone is correct.
       
   391 
       
   392 @SYMTestActions     
       
   393 	1.	Create a user defined zone and store the returned time zone identifier.
       
   394 	2.	Get the localized city information for the user defined zone identifier
       
   395 		obtained in action 1. 
       
   396 
       
   397 @SYMTestExpectedResults
       
   398 	The following information is the same as that used to create the user
       
   399 	defined time zone in action 1:
       
   400 
       
   401 	- City name
       
   402  	- Time zone identifier
       
   403  	- Group identifier (0 for all user defined time zones)
       
   404  
       
   405 @SYMTestType
       
   406 	CT
       
   407 	
       
   408 @SYMTestPriority
       
   409 	1
       
   410 */
       
   411 
       
   412 
       
   413 void CTzLocalizationUserDataSuite::TestLocalizedCityL()
       
   414 	{
       
   415 	test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZL-TZN-0002 Test Localized City"));
       
   416 	TInt tzid = 0;
       
   417 	CTzUserNames* names = CreateUserRuleAndGetNamesLC(tzid);
       
   418 	CTzLocalizedCityArray* locCityArray = iLocalizer->GetCitiesL(tzid);
       
   419 	CleanupStack::PushL(locCityArray);
       
   420 	test(CompareLocalizedCity(tzid, *names, locCityArray->At(0)));
       
   421 	CleanupStack::PopAndDestroy(2, names);
       
   422 	ResetTzUserDataL();
       
   423 	}
       
   424 
       
   425 
       
   426 /**
       
   427 @SYMTestCaseID PIM-APPSERV-TZL-TZN-0003
       
   428 	
       
   429 @SYMTestCaseDesc
       
   430 	The purpose of this test is to verify that the default localized city
       
   431 	information for a user defined time zone is correct.
       
   432 	
       
   433 @SYMTestActions     
       
   434 	1.	Create a user defined zone and store the returned time zone identifier.
       
   435 	2.	Get the default localized city information for the user defined zone
       
   436 		identifier obtained in action 1. 
       
   437 
       
   438 @SYMTestExpectedResults
       
   439 	The following information is the same as that used to create the user
       
   440 	defined time zone in action 1:
       
   441 
       
   442 	 - City name
       
   443  	- Time zone identifier
       
   444  	- Group identifier (0 for all user defined time zones)
       
   445  
       
   446 @SYMTestType
       
   447 	CT
       
   448 
       
   449 @SYMTestPriority
       
   450 	1
       
   451 */
       
   452 
       
   453 
       
   454 void CTzLocalizationUserDataSuite::TestDefaultCityL()
       
   455 	{
       
   456 	test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZL-TZN-0003  Test Default City"));
       
   457 	TInt tzid = 0;
       
   458 	CTzUserNames* names = CreateUserRuleAndGetNamesLC(tzid);
       
   459 	CTzLocalizedCity*  defaultCity = iLocalizer->GetDefaultCityL(tzid);
       
   460 	CleanupStack::PushL(defaultCity);
       
   461 	test(CompareLocalizedCity(tzid, *names, *defaultCity));
       
   462 	CleanupStack::PopAndDestroy(2, names);
       
   463 	ResetTzUserDataL();
       
   464 	}
       
   465 
       
   466 
       
   467 /**
       
   468 @SYMTestCaseID PIM-APPSERV-TZL-TZN-0004
       
   469 	
       
   470 @SYMTestCaseDesc
       
   471 	The purpose of this test is to verify that the localized city group
       
   472 	information for a user defined time zone fails as expected.
       
   473 
       
   474 @SYMTestActions     
       
   475 	1.	Create a user defined zone and store the returned time zone identifier.
       
   476 	2.	Verify that the localized city group information for a user defined time
       
   477 		zone fails as expected. 
       
   478 
       
   479 @SYMTestExpectedResults
       
   480 	The localized city group information cannot be obtained (the call leaves
       
   481 	with KErrArgument).
       
   482  
       
   483 @SYMTestType
       
   484 	CT
       
   485 	
       
   486 @SYMTestPriority
       
   487 	1
       
   488 */
       
   489 
       
   490 
       
   491 void CTzLocalizationUserDataSuite::TestCityGroupL()
       
   492 	{
       
   493 	test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZL-TZN-0004 Test City Group"));
       
   494 	TInt tzid = 0;
       
   495 	CTzUserNames* names = CreateUserRuleAndGetNamesLC(tzid);
       
   496 	CTzLocalizedCityArray* locCityArray = iLocalizer->GetCitiesL(tzid);
       
   497 	CleanupStack::PushL(locCityArray);
       
   498 	TRAPD(err, iLocalizer->GetCityGroupL(locCityArray->At(0).GroupId())); 
       
   499 	test(err == KErrArgument);
       
   500 	CleanupStack::PopAndDestroy(2, names);
       
   501 	ResetTzUserDataL();
       
   502 	}
       
   503 
       
   504 
       
   505 /**
       
   506 @SYMTestCaseID 	PIM-APPSERV-TZL-TZN-0005
       
   507 	
       
   508 @SYMTestCaseDesc
       
   509 	The purpose of this test is to verify that the localized city array
       
   510 	information for user defined time zones is correct.
       
   511 	
       
   512 @SYMTestActions     
       
   513 	1.	Create two user defined time zones.
       
   514 	2.	Get the localized city array information for the user defined time zone
       
   515 		group identifier (always 0).
       
   516 
       
   517 @SYMTestExpectedResults
       
   518 	The localized city array contains the two city names used to create the user
       
   519 	defined time zones in action 1.
       
   520  
       
   521 @SYMTestType
       
   522 	CT
       
   523 
       
   524 @SYMTestPriority
       
   525 	1
       
   526 */
       
   527 
       
   528 
       
   529 void CTzLocalizationUserDataSuite::TestCityArrayL()
       
   530 	{
       
   531 	test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZL-TZN-0005 Test City Array"));
       
   532 
       
   533 	TInt grouplessId = 0;
       
   534 	CTzLocalizedCityArray* cities = iLocalizer->GetCitiesInGroupL(grouplessId);
       
   535 	const TInt originalCount = cities->Count();
       
   536 	delete cities;
       
   537 
       
   538 	TInt tzid1 = 0;
       
   539 	CTzUserNames* names1 = CreateUserRuleAndGetNamesLC(tzid1);
       
   540 
       
   541 	TInt tzid2 = 0;
       
   542 	CTzUserNames* names2 = CreateUserRuleAndGetNamesLC(tzid2);
       
   543 	
       
   544 	cities = iLocalizer->GetCitiesInGroupL(grouplessId);
       
   545 	CleanupStack::PushL(cities);
       
   546 
       
   547 	test(cities->Count() == (2 + originalCount));
       
   548 	test(FindCityInArrayL(*cities, tzid1, *names1));
       
   549 	test(FindCityInArrayL(*cities, tzid1, *names2));
       
   550 	
       
   551 	CleanupStack::PopAndDestroy(3);
       
   552 	}
       
   553 
       
   554 
       
   555 /**
       
   556 @SYMTestCaseID PIM-APPSERV-TZL-TZN-0006
       
   557 	
       
   558 @SYMTestCaseDesc
       
   559 	Verify that the current time zone can be set to a user defined time zone.
       
   560 
       
   561 @SYMTestActions     
       
   562 	1.	Create a user defined time zone and store the returned time zone
       
   563 		identifier.
       
   564 	2.	Set the current time using the user defined time zone identifier stored
       
   565 		in action 1.
       
   566 	3.	Get the time zone identifier for the current time zone from the TZ
       
   567 		Server.
       
   568 
       
   569 @SYMTestExpectedResults
       
   570 	The time zone identifier obtained in action 1 is the same as the time zone
       
   571 	identifier obtained in action 3.
       
   572  
       
   573 @SYMTestType
       
   574 	CT
       
   575 
       
   576 @SYMTestPriority
       
   577 	1
       
   578 */
       
   579 
       
   580 
       
   581 void CTzLocalizationUserDataSuite::TestCurrentTimeZoneL()
       
   582 	{
       
   583 	test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZL-TZN-0006 Test Current Time Zone"));
       
   584 	TInt tzid = 0;
       
   585 	CTzUserNames* names = CreateUserRuleAndGetNamesLC(tzid);
       
   586 	iLocalizer->SetTimeZoneL(tzid);
       
   587 	CTzLocalizedTimeZone* currentTz = iLocalizer->GetFrequentlyUsedZoneL(CTzLocalizedTimeZone::ECurrentZone);
       
   588 	CleanupStack::PushL(currentTz);
       
   589 	test(CompareTimeZoneNames(tzid, *names, *currentTz));
       
   590 	CleanupStack::PopAndDestroy(2, names);
       
   591 	ResetTzUserDataL();		
       
   592 	}
       
   593 
       
   594 
       
   595 /**
       
   596 @SYMTestCaseID PIM-APPSERV-TZL-TZN-0010
       
   597 	
       
   598 @SYMTestCaseDesc
       
   599 	The purpose of this test is to verify that time zone name, city name and
       
   600 	city group name for a user defined time zone can be found.
       
   601 	
       
   602 @SYMTestActions     
       
   603 	1.	Create a user defined time zone and store the returned time zone
       
   604 		identifier.
       
   605 	2.	Find the user defined time zone by long/short standard time name and
       
   606 		long short daylight saving time names. [1]
       
   607 	3.	Find the user defined time zone by city name, searching both in all time
       
   608 		zones and the specific time zone identified by the time zone identifier
       
   609 		obtained in action 1. [2]
       
   610 	4.	Find the user defined time zone by city group name. [3]
       
   611 
       
   612 @SYMTestExpectedResults
       
   613 	[1], [2], [3] User defined time zone is found
       
   614  
       
   615 @SYMTestType
       
   616 	CT
       
   617 	
       
   618 @SYMTestPriority
       
   619 	1
       
   620 */
       
   621 
       
   622 
       
   623 void CTzLocalizationUserDataSuite::TestFindTimeZoneL()
       
   624 	{
       
   625 	test.Next(_L("@SYMTestCaseID PIM-APPSERV-TZL-TZN-0010 Test Find Time Zone"));
       
   626 	TInt tzid = 0;
       
   627 	CTzUserNames* names = CreateUserRuleAndGetNamesLC(tzid);
       
   628 	TestFindTimeZoneByNameL(tzid,*names,names->StandardName());
       
   629 	TestFindTimeZoneByNameL(tzid,*names,names->ShortStandardName());
       
   630 	TestFindTimeZoneByNameL(tzid,*names,names->DaylightSaveName());
       
   631 	TestFindTimeZoneByNameL(tzid,*names,names->ShortDaylightSaveName());
       
   632 	CTzLocalizedCity* city = iLocalizer->FindCityByNameL(names->CityName());
       
   633 	CleanupStack::PushL(city);
       
   634 	test(CompareLocalizedCity(tzid, *names, *city));
       
   635 	CleanupStack::PopAndDestroy(city);
       
   636 	
       
   637 	city = iLocalizer->FindCityByNameL(names->CityName(), tzid);
       
   638 	CleanupStack::PushL(city);
       
   639 	test(CompareLocalizedCity(tzid, *names, *city));
       
   640 	CleanupStack::PopAndDestroy(city);
       
   641 	
       
   642 	CTzLocalizedCityGroup* group = iLocalizer->FindCityGroupByNameL(names->RegionName());
       
   643 	CleanupStack::PushL(group);
       
   644 	test(CompareLocalizedCityGroup(*names, *group));
       
   645 	CleanupStack::PopAndDestroy(group);
       
   646 	
       
   647 	CleanupStack::PopAndDestroy(names);
       
   648 	}
       
   649 
       
   650 
       
   651 CTzRules* CTzLocalizationUserDataSuite::CreateRulesLC()
       
   652 	{
       
   653 	TTime dston (TDateTime(2005, EMarch, 0, 0, 0, 0, 0)); 
       
   654 	TTime dstoff (TDateTime(2005, ESeptember, 0, 0, 0, 0, 0));
       
   655 	TMonth monthOn = dston.DateTime().Month();
       
   656 	TInt dayOn = dston.DateTime().Day();
       
   657 	TMonth monthOff = dstoff.DateTime().Month();
       
   658 	TInt dayOff = dstoff.DateTime().Day();
       
   659 	
       
   660 	TTzRule dstOff(0, 9999, 0, 0, monthOn,  ETzFixedDate, dayOn,  0, ETzWallTimeReference, 0);
       
   661 	TTzRule dstOn (0, 9999, 0, 0, monthOff, ETzFixedDate, dayOff, 0, ETzWallTimeReference, 0);
       
   662 
       
   663 	CTzRules* rules = CTzRules::NewL(0, KMaxTUint);
       
   664 	CleanupStack::PushL(rules);
       
   665 	rules->AddRuleL(dstOff);
       
   666 	rules->AddRuleL(dstOn);
       
   667 	
       
   668 	return rules;
       
   669 	}
       
   670 
       
   671 
       
   672 void CTzLocalizationUserDataSuite::CreateString(TDes& aString)
       
   673 	{
       
   674 	for (TInt i(0) ; i < 10 ; ++i)
       
   675 		{
       
   676 		// Add random upper and lower case letters
       
   677 		aString.Append( 'A' + (Math::Rand(iSeed) % 26) );
       
   678 		}
       
   679 	}
       
   680 
       
   681 	
       
   682 CTzUserNames* CTzLocalizationUserDataSuite::CreateNamesLC()
       
   683 	{	
       
   684 	TBuf<10> stdName;
       
   685 	CreateString(stdName);
       
   686 	TBuf<10> shortStdName;
       
   687 	CreateString(shortStdName);
       
   688 	TBuf<10> dstName;
       
   689 	CreateString(dstName);
       
   690 	TBuf<10> shortDstName;
       
   691 	CreateString(shortDstName);
       
   692 	TBuf<10> cityName;
       
   693 	CreateString(cityName);
       
   694 	TBuf<10> regionName;
       
   695 	CreateString(regionName);
       
   696 
       
   697 	return CTzUserNames::NewLC(stdName, shortStdName, dstName, shortDstName, cityName, regionName);
       
   698 	}
       
   699 
       
   700 
       
   701 /**
       
   702 @SYMTestCaseID  PIM-APPSERV-TLOCALIZATIONUSERDATA-0002
       
   703 		
       
   704 @SYMTestCaseDesc
       
   705 	The purpose of this test is to verify that an update to user-defined rules
       
   706 	is reflected in the frequently used zone database.
       
   707 	
       
   708 @SYMTestActions		
       
   709 	1.  Create a user-defined time zone and set it as the frequently used zone.
       
   710 	2.  Update the time zone rule.
       
   711 	3.  Read the frequently used city and zone and test against the ones
       
   712 		expected.
       
   713 
       
   714 @SYMTestExpectedResults
       
   715 	The frequently used zone read from the database should be the one expected.
       
   716 
       
   717 @SYMTestType
       
   718 	CT
       
   719 
       
   720 @SYMTestPriority
       
   721 	1
       
   722 */
       
   723 
       
   724 
       
   725 void CTzLocalizationUserDataSuite::TestUserDataModificationL(CTzLocalizedTimeZone::TTzFrequentlyUsedZone aFrequentlyUsedZone)
       
   726 	{
       
   727 	test.Next(_L("@SYMTestCaseID PIM-APPSERV-TLOCALIZATIONUSERDATA-0002 Test frequently used zone database after user data modification"));
       
   728 
       
   729 	//Create user-defined time zone
       
   730 	CTzRules* rules = CreateRulesLC();
       
   731 	CTzUserNames* names = CreateNamesLC();
       
   732 	CTzId* tzId = iUserData->CreateL(*rules, *names);
       
   733 	TInt tzid = tzId->TimeZoneNumericID();
       
   734 	delete tzId;
       
   735 	CleanupStack::PopAndDestroy(names);
       
   736 
       
   737 	// Associate the user-defined zone with the given frequently used zone.
       
   738 	iLocalizer->SetFrequentlyUsedZoneL(tzid, aFrequentlyUsedZone);
       
   739 		
       
   740 	//Create a new user-defined name
       
   741 	CTzUserNames* names2 = CreateNamesLC();
       
   742 	
       
   743 	//Update the time zone
       
   744 	CTzId* id = CTzId::NewL(tzid);
       
   745 	CleanupStack::PushL(id);
       
   746 	iUserData->UpdateL(*id, *rules, *names2);
       
   747 	
       
   748 	switch(aFrequentlyUsedZone)
       
   749 		{
       
   750 	case CTzLocalizedTimeZone::EHomeZone:
       
   751 	case CTzLocalizedTimeZone::EInterestZone:
       
   752 		{
       
   753 		CTzLocalizedCity* city = iLocalizer->GetFrequentlyUsedZoneCityL(aFrequentlyUsedZone);
       
   754 		test(CompareLocalizedCity(tzid, *names2, *city));
       
   755 		delete city;
       
   756 		
       
   757 		CTzLocalizedTimeZone* timeZone = iLocalizer->GetFrequentlyUsedZoneL(aFrequentlyUsedZone);
       
   758 		test(CompareTimeZoneNames(tzid, *names2, *timeZone));
       
   759 		delete timeZone;
       
   760 		break;	
       
   761 		}
       
   762 		
       
   763 	case CTzLocalizedTimeZone::ECurrentZone:
       
   764 		{
       
   765 		//Extract zone information, same zone should be returned by GetFrequentlyUsedZoneL below.
       
   766 		CTzLocalizedTimeZone* zoneToCompareWith = iLocalizer->GetLocalizedTimeZoneL(KParisTzId);
       
   767 		CleanupStack::PushL(zoneToCompareWith);
       
   768 		//Extract zone information, same city should be returned by GetFrequentlyUsedZoneCityL below.
       
   769 		CTzLocalizedCity* cityToCompareWith = iLocalizer->GetDefaultCityL(KParisTzId);
       
   770 		CleanupStack::PushL(cityToCompareWith);
       
   771 		
       
   772 		iLocalizer->SetTimeZoneL(KParisTzId);
       
   773 		CTzLocalizedCity* freqUsedCity = iLocalizer->GetFrequentlyUsedZoneCityL(aFrequentlyUsedZone);
       
   774 		test(CompareLocalizedCity(*freqUsedCity, *cityToCompareWith));
       
   775 		delete freqUsedCity;
       
   776 		
       
   777 		CTzLocalizedTimeZone* freqUsedZone = iLocalizer->GetFrequentlyUsedZoneL(aFrequentlyUsedZone);
       
   778 		test(CompareTimeZoneName(*freqUsedZone, *zoneToCompareWith));
       
   779 		delete freqUsedZone;
       
   780 		CleanupStack::PopAndDestroy(2,zoneToCompareWith);
       
   781 		break;
       
   782 		}
       
   783 	default:
       
   784 		{
       
   785 		User::Invariant();
       
   786 		break;
       
   787 		}
       
   788 		
       
   789 		}
       
   790 		
       
   791 	CleanupStack::PopAndDestroy(3, rules);
       
   792 	ResetTzUserDataL();
       
   793 	}
       
   794 
       
   795 
       
   796 /**
       
   797 @SYMTestCaseID  PIM-APPSERV-TLOCALIZATIONUSERDATA-0003
       
   798 		
       
   799 @SYMTestCaseDesc
       
   800 	The purpose of this test is to verify that a deletion to the user-defined 
       
   801 	rules is reflected in the frequently used zone database.
       
   802 	
       
   803 @SYMTestActions
       
   804 	1.  Create a user-defined time zone and set it as the frequently used zone of
       
   805 		interest.
       
   806 	2.  Create another user-defined time zone and set it as the frequently used
       
   807 		home zone.
       
   808 	3.  Delete the time zone created in Step 2.
       
   809 	4.  Read the frequently used city and zone and test whether against the ones
       
   810 		expected.
       
   811 
       
   812 @SYMTestExpectedResults
       
   813 	The frequently used city and zone read from the database should be the ones
       
   814 	expected.
       
   815 
       
   816 @SYMTestType
       
   817 	CT
       
   818 
       
   819 @SYMTestPriority
       
   820 	1
       
   821 */
       
   822 
       
   823 
       
   824 void CTzLocalizationUserDataSuite::TestUserDataDeletionL()
       
   825 	{
       
   826 	test.Next(_L("@SYMTestCaseID PIM-APPSERV-TLOCALIZATIONUSERDATA-0003 Test frequently used zone database after user data deletion"));
       
   827 	// Add a user-defined time zone as a frequently used zone of interest	
       
   828 	CTzRules* rulesInterest = CreateRulesLC();
       
   829 	CTzUserNames* namesInterest = CreateNamesLC();
       
   830 	CTzId* tzIdInterest = iUserData->CreateL(*rulesInterest, *namesInterest);
       
   831 	TInt tzidInterest = tzIdInterest->TimeZoneNumericID();
       
   832 	delete tzIdInterest;
       
   833 	
       
   834 	//Extract zone information, same city should be returned by GetFrequentlyUsedZoneCityL below.	
       
   835 	CTzLocalizedCity* cityToCompareWith = iLocalizer->GetDefaultCityL(KLondonTzId);
       
   836 	CleanupStack::PushL(cityToCompareWith);
       
   837 	
       
   838 	//Extract zone information, same zone should be returned by GetFrequentlyUsedZoneL below.
       
   839 	CTzLocalizedTimeZone* zoneToCompareWith = iLocalizer->GetLocalizedTimeZoneL(KLondonTzId);
       
   840 	CleanupStack::PushL(zoneToCompareWith);
       
   841 	
       
   842 	iLocalizer->SetFrequentlyUsedZoneL(tzidInterest, CTzLocalizedTimeZone::EInterestZone);
       
   843 	
       
   844 	CTzRules* rulesHome = CreateRulesLC();
       
   845 	CTzUserNames* namesHome = CreateNamesLC();
       
   846 	CTzId* tzId = iUserData->CreateL(*rulesHome, *namesHome);
       
   847 	TInt tzidHome = tzId->TimeZoneNumericID();
       
   848 	delete tzId;
       
   849 
       
   850 	// Add rule to frequently used zones
       
   851 	iLocalizer->SetFrequentlyUsedZoneL(tzidHome, CTzLocalizedTimeZone::EHomeZone);
       
   852 		
       
   853 	CTzId* id = CTzId::NewL(tzidHome);
       
   854 	CleanupStack::PushL(id);
       
   855 	iUserData->DeleteL(*id);
       
   856 	CleanupStack::PopAndDestroy(id);
       
   857 		
       
   858 	CTzLocalizedCity* city = iLocalizer->GetFrequentlyUsedZoneCityL(CTzLocalizedTimeZone::EHomeZone);
       
   859 	//Check if the frequently used city read from the database is same as the one expected
       
   860 	test(CompareLocalizedCity(*city, *cityToCompareWith));
       
   861 	delete city;
       
   862 	
       
   863 	CTzLocalizedCity* cityInterest = iLocalizer->GetFrequentlyUsedZoneCityL(CTzLocalizedTimeZone::EInterestZone);
       
   864 	//Check if the frequently used city of interest read from the database is same as the one expected
       
   865 	test(CompareLocalizedCity(tzidInterest, *namesInterest, *cityInterest));
       
   866 	delete cityInterest;
       
   867 		
       
   868 	CTzLocalizedTimeZone* timeZone = iLocalizer->GetFrequentlyUsedZoneL(CTzLocalizedTimeZone::EHomeZone);
       
   869 	//Check if the frequently used zone read from the database is same as the one expected
       
   870 	test(CompareTimeZoneName(*timeZone, *zoneToCompareWith));
       
   871 	delete timeZone;
       
   872 	
       
   873 	CTzLocalizedTimeZone* timeZoneInterest = iLocalizer->GetFrequentlyUsedZoneL(CTzLocalizedTimeZone::EInterestZone);
       
   874 	//Check if the frequently used zone of interest read from the database is same as the one expected
       
   875 	test(CompareTimeZoneNames(tzidInterest, *namesInterest, *timeZoneInterest));
       
   876 	
       
   877 	delete timeZoneInterest;
       
   878 	ResetTzUserDataL();
       
   879 	CleanupStack::PopAndDestroy(6, rulesInterest);
       
   880 	}
       
   881 
       
   882 
       
   883 /**
       
   884 @SYMTestCaseID PIM-APPSERV-TLOCALIZATIONUSERDATA-0004
       
   885 	
       
   886 @SYMTestCaseDesc
       
   887 	The purpose of this test is to verify that a deletion to the user-defined 
       
   888 	rules is reflected in the city database		
       
   889 
       
   890 @SYMTestActions
       
   891 	1.  Create a user-defined time zone.
       
   892 	2.  Add three cities to the time zone.
       
   893 	3.  Read the number of cities.
       
   894 	4.  Delete one of the cities.
       
   895 	5.  Read the number of cities after deletion.
       
   896 
       
   897 @SYMTestExpectedResults
       
   898 	The number of cities in Step 3 should be 3 and in Step 5 should be 2.
       
   899 	
       
   900 @SYMTestType
       
   901 	CT
       
   902 	
       
   903 @SYMTestPriority
       
   904 	1
       
   905 */
       
   906 
       
   907 
       
   908 void CTzLocalizationUserDataSuite::TestUserDataDeletionCityImpactL()
       
   909 	{
       
   910 	test.Next(_L("@SYMTestCaseID PIM-APPSERV-TLOCALIZATIONUSERDATA-0004 Test city database after user data deletion\n"));
       
   911 	CTzRules* rules = CreateRulesLC();
       
   912 	CTzUserNames* names = CreateNamesLC();
       
   913 	CTzId* tzId = iUserData->CreateL(*rules, *names);
       
   914 	CleanupStack::PopAndDestroy(names);
       
   915 	CleanupStack::PopAndDestroy(rules);
       
   916 	TInt tzid = tzId->TimeZoneNumericID();
       
   917 	delete tzId;
       
   918 	//Add 3 user-defined cities to the city database	
       
   919 	test.Printf(_L("Add 3 cities to the city database\n"));
       
   920 	CTzLocalizedCity* userCity = iLocalizer->AddCityL(tzid, KUserAddedCity1Name);
       
   921 	delete userCity;
       
   922 	CTzRules* rules2 = CreateRulesLC();
       
   923 	CTzUserNames* names2 = CreateNamesLC();
       
   924 	CTzId* tzId1 = iUserData->CreateL(*rules2, *names2);
       
   925 	CleanupStack::PopAndDestroy(2,rules2);
       
   926 	tzid = tzId1->TimeZoneNumericID();
       
   927 	delete tzId1;
       
   928 	CTzLocalizedCity* userCity1 = iLocalizer->AddCityL(tzid, KUserAddedCity2Name);
       
   929 	delete userCity1;
       
   930 
       
   931 	CTzRules* rules3 = CreateRulesLC();	
       
   932 	CTzUserNames* names3 = CreateNamesLC();
       
   933 	CTzId* tzId2 = iUserData->CreateL(*rules3, *names3);
       
   934 	CleanupStack::PopAndDestroy(2,rules3);
       
   935 	tzid = tzId2->TimeZoneNumericID();
       
   936 	delete tzId2;
       
   937 
       
   938 	CTzLocalizedCity* userCity2 = iLocalizer->AddCityL(tzid, KUserAddedCity3Name);
       
   939 	delete userCity2;
       
   940 	//Read the number of cities
       
   941 	RPointerArray<CTzLocalizedCityRecord> cityRecords;
       
   942 	iTzSession.LocalizationReadCitiesL(cityRecords);
       
   943 	test.Printf(_L("Check if the number of cities read is correct\n"));
       
   944 	test(cityRecords.Count() == 3);
       
   945 	cityRecords.ResetAndDestroy();
       
   946 	cityRecords.Close();
       
   947 	//Delete a city from the city database
       
   948 	CTzId* id = CTzId::NewL(tzid);
       
   949 	CleanupStack::PushL(id);
       
   950 	test.Printf(_L("Delete a city from the database\n"));
       
   951 	iUserData->DeleteL(*id);
       
   952 	CleanupStack::PopAndDestroy(id);
       
   953 	//Read the number of cities again
       
   954 	RPointerArray<CTzLocalizedCityRecord> cityRecords2;
       
   955 	iTzSession.LocalizationReadCitiesL(cityRecords2);
       
   956 	test.Printf(_L("Again, check if the number of cities read is correct\n"));
       
   957 	test(cityRecords2.Count() == 2);
       
   958 	cityRecords2.ResetAndDestroy();
       
   959 	cityRecords2.Close();
       
   960 		
       
   961 	ResetTzUserDataL();
       
   962 	}
       
   963 
       
   964 
       
   965 TBool CTzLocalizationUserDataSuite::TestTimeZoneShortStandardNameL(CTzLocalizer& aTzLocalizer, const TDesC& aShortStandardName)
       
   966 	{
       
   967 	CTzLocalizedTimeZone* localizedTimeZone = aTzLocalizer.GetFrequentlyUsedZoneL(CTzLocalizedTimeZone::ECurrentZone);
       
   968 	CleanupStack::PushL(localizedTimeZone);
       
   969 	HBufC* shortStandardName(localizedTimeZone->ShortStandardName().AllocLC());
       
   970 	test.Printf(_L("The short standard name is %S\n"), shortStandardName);
       
   971 	TBool compare = (shortStandardName->Des() == aShortStandardName);
       
   972 	CleanupStack::PopAndDestroy(shortStandardName);
       
   973 	CleanupStack::PopAndDestroy(localizedTimeZone);
       
   974 	return compare;
       
   975 	}
       
   976 
       
   977 
       
   978 
       
   979 void CTzLocalizationUserDataSuite::TestUserDefinedTimeZoneL()
       
   980 	{
       
   981 	test.Next(_L("Test user defined zone\n"));
       
   982 	_LIT(KUserStandardName, "Southark Standard Time");
       
   983 	_LIT(KUserShortStandardName, "SST");
       
   984 	_LIT(KUserDaylightName, "WorkingDay");
       
   985 	_LIT(KUserShortDaylightName, "WD");
       
   986 	_LIT(KRegionName, "Sarf");
       
   987 	_LIT(KCityName, "MobiCity");
       
   988 	_LIT(KCity2Name, "East end");
       
   989 	CTzRules* rules = CreateRulesLC();
       
   990 	CTzUserNames* names = CTzUserNames::NewLC(KUserStandardName(), KUserShortStandardName(), KUserDaylightName(), KUserShortDaylightName(), KCityName(), KRegionName() );
       
   991 	CTzId* tzId = iUserData->CreateL(*rules, *names);
       
   992 	CleanupStack::PopAndDestroy(names);
       
   993 	CleanupStack::PopAndDestroy(rules);
       
   994 	TInt tzid = tzId->TimeZoneNumericID();
       
   995 
       
   996 	RTz tz;
       
   997 	CleanupClosePushL(tz);
       
   998 	User::LeaveIfError(tz.Connect());
       
   999 	//Create a localizer and get frequently used zone
       
  1000 	CTzLocalizer* localizer = CTzLocalizer::NewLC();
       
  1001 	localizer->SetTimeZoneL(tzid);
       
  1002 
       
  1003     //use the utility test function here for the short standard name
       
  1004 	test (TestTimeZoneShortStandardNameL(*localizer, KUserShortStandardName()));
       
  1005 
       
  1006 	CTzLocalizedCity* localizedCity = localizer->GetFrequentlyUsedZoneCityL(CTzLocalizedTimeZone::ECurrentZone);
       
  1007 	CleanupStack::PushL(localizedCity);
       
  1008 	test(localizedCity->Name() == KCityName());
       
  1009 	test(localizedCity->TimeZoneId() ==  (TUint16) tzid);
       
  1010 	CleanupStack::PopAndDestroy(localizedCity);
       
  1011 
       
  1012 	//
       
  1013 	// Test the AddCityL() and RemoveCityL() APIs.
       
  1014 	//
       
  1015 
       
  1016 	// Try adding the same city.
       
  1017 	TRAPD(errSame, localizer->AddCityL(tzid, KCityName, 0));
       
  1018 	test(errSame == KErrAlreadyExists);
       
  1019 
       
  1020 	// Try adding and removing a different city.
       
  1021 	CTzLocalizedCity* differentCity = NULL;
       
  1022 	TRAPD(errDifferent, differentCity = localizer->AddCityL(tzid, KCity2Name, 0));
       
  1023 	test(errDifferent == KErrNone);
       
  1024 	TRAPD(errDelete, localizer->RemoveCityL(differentCity));
       
  1025 	test(errDelete == KErrNone);
       
  1026 
       
  1027     //Get the CTzLocalizedCity and keep it to use it later on.
       
  1028 	CTzLocalizedCity* localizedGetCity = localizer->GetFrequentlyUsedZoneCityL(CTzLocalizedTimeZone::ECurrentZone);
       
  1029 	CleanupStack::PushL(localizedGetCity);
       
  1030 	test(localizedGetCity->Name() == KCityName());
       
  1031 
       
  1032     //Set the time zone to London using a tzId.
       
  1033 	localizer->SetFrequentlyUsedZoneL(KLondonTzId, CTzLocalizedTimeZone::ECurrentZone);
       
  1034 	//Test the short standard name for compliance
       
  1035     test (TestTimeZoneShortStandardNameL(*localizer, _L("GMT")));
       
  1036 
       
  1037     // Set the frequently used zone using the previously retrieved CTzLocalizedCity of Southwark.
       
  1038 	localizer->SetFrequentlyUsedZoneL(*localizedGetCity, CTzLocalizedTimeZone::ECurrentZone);
       
  1039 	CleanupStack::PopAndDestroy(localizedGetCity);
       
  1040 
       
  1041     //Get the frequently used zone and check that short standard name is as expected.
       
  1042 	test (TestTimeZoneShortStandardNameL(*localizer, KUserShortStandardName()));
       
  1043 
       
  1044     //Set the frequently used time zone back to london, this time using the CTzLocalizedTimeZone API
       
  1045 	CTzLocalizedTimeZone* londonLocalizedTimeZone = localizer->GetLocalizedTimeZoneL(KLondonTzId);
       
  1046 	CleanupStack::PushL(londonLocalizedTimeZone);
       
  1047 	localizer->SetFrequentlyUsedZoneL(*londonLocalizedTimeZone, CTzLocalizedTimeZone::ECurrentZone);
       
  1048     //Test that the short standard name is again GMT
       
  1049 	test (TestTimeZoneShortStandardNameL(*localizer, _L("GMT")));
       
  1050 	CleanupStack::PopAndDestroy(londonLocalizedTimeZone);
       
  1051 
       
  1052 	CleanupStack::PopAndDestroy(localizer);
       
  1053 	CleanupStack::PopAndDestroy(&tz);
       
  1054 	delete tzId;
       
  1055 	}
       
  1056 
       
  1057 /**
       
  1058 @SYMTestCaseID PIM-APPSERV-TLOCALIZATIONUSERDATA-0001
       
  1059 */	
       
  1060 static void DoTestsL()
       
  1061 	{
       
  1062 	test.Title();
       
  1063 
       
  1064 	test.Start(_L("@SYMTestCaseID PIM-APPSERV-TLOCALIZATIONUSERDATA-0001 User defined time zone test suite"));
       
  1065 
       
  1066 	RPIMTestServer serv;	
       
  1067 	CleanupClosePushL(serv);
       
  1068 	User::LeaveIfError(serv.Connect());
       
  1069 	serv.CloseTzSession();
       
  1070 	_LIT(KAgendaServer,"agsvexe*");
       
  1071 	TRAP_IGNORE(serv.KillProcessL(KAgendaServer));
       
  1072 	_LIT(KTzServer,"Tzserver*");
       
  1073 	TRAP_IGNORE(serv.KillProcessL(KTzServer));
       
  1074 	serv.DeleteFileL(KPerFile1);
       
  1075 	serv.DeleteFileL(KPerFile2);
       
  1076 
       
  1077 	CTzLocalizationUserDataSuite* loctest = CTzLocalizationUserDataSuite::NewLC();
       
  1078 	loctest->TestUserDefinedTimeZoneL();
       
  1079 	loctest->TestLocalizedTimeZoneL();
       
  1080 	loctest->TestLocalizedTimeZoneWithLocalizeIDL();
       
  1081 	loctest->TestLocalizedCityL();
       
  1082 	loctest->TestDefaultCityL();
       
  1083 	loctest->TestCityGroupL();
       
  1084 	loctest->TestCityArrayL();
       
  1085 	loctest->TestCurrentTimeZoneL();
       
  1086 	loctest->TestFindTimeZoneL();
       
  1087 	loctest->TestUserDataModificationL(CTzLocalizedTimeZone::EHomeZone);
       
  1088 	loctest->TestUserDataModificationL(CTzLocalizedTimeZone::ECurrentZone);
       
  1089 	loctest->TestUserDataModificationL(CTzLocalizedTimeZone::EInterestZone);
       
  1090 	loctest->TestUserDataDeletionL();
       
  1091 	loctest->TestUserDataDeletionCityImpactL();
       
  1092 	CleanupStack::PopAndDestroy(loctest);
       
  1093 	
       
  1094 	TRAP_IGNORE(serv.KillProcessL(KTzServer));
       
  1095 
       
  1096 	//delete persistent file
       
  1097 	serv.DeleteFileL(KPerFile1);
       
  1098 	serv.DeleteFileL(KPerFile2);
       
  1099 	
       
  1100 	CleanupStack::PopAndDestroy(&serv);
       
  1101 
       
  1102 	test.End();
       
  1103 	}
       
  1104 
       
  1105 
       
  1106 TInt E32Main()
       
  1107     {
       
  1108 	__UHEAP_MARK;
       
  1109 
       
  1110 	CTrapCleanup* trapCleanup = CTrapCleanup::New();
       
  1111 	if(!trapCleanup)
       
  1112 		{
       
  1113 		return KErrNoMemory;
       
  1114 		}
       
  1115 
       
  1116 	CActiveScheduler* scheduler = new CActiveScheduler;
       
  1117 	if(!scheduler)
       
  1118 		{
       
  1119 		return KErrNoMemory;
       
  1120 		}
       
  1121 	CActiveScheduler::Install(scheduler);	
       
  1122 
       
  1123 	TRAPD(ret, DoTestsL());
       
  1124 	test.Printf(_L("Trapped return value from DoTestsL(): %d\n"), ret);
       
  1125 	test(ret == KErrNone);
       
  1126 	
       
  1127 	test.Close();
       
  1128 
       
  1129 	delete scheduler;
       
  1130 	delete trapCleanup;	
       
  1131 
       
  1132 	__UHEAP_MARKEND;
       
  1133 
       
  1134 	return (KErrNone);
       
  1135     }