commonappservices/alarmservertest/TestMultipleAlarmsSuite/src/TestAssociatedDataStep.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2005-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 // Contains implementation of CTestAssociatedDataStep class
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology 
       
    21 */
       
    22 
       
    23 // User Include
       
    24 #include "TestAssociatedDataStep.h"
       
    25 #include "DummyAlarmControl.h"
       
    26 
       
    27 // Syatem Includes
       
    28 #include <uikon/eikalsup.h>
       
    29 #include <calalarm.h>
       
    30 
       
    31 /**
       
    32 Constructor. Sets the test step name. Testserver reference passed to make use 
       
    33 of TEF's method of sharing data between test steps
       
    34 @internalTechnology
       
    35 @test
       
    36 */
       
    37 CTestAssociatedDataStep::CTestAssociatedDataStep(CTestMultipleAlarmsServer& aTestServer) 
       
    38 : CTestBaseStep(aTestServer)
       
    39 	{
       
    40 	//Call base class method to set human readable name for test step
       
    41 	SetTestStepName(KTestAssociatedDataStep);
       
    42 	}
       
    43 	
       
    44 /**
       
    45 Destructor
       
    46 @internalTechnology
       
    47 @test
       
    48 */
       
    49 CTestAssociatedDataStep::~CTestAssociatedDataStep()
       
    50 	{
       
    51 	delete iActiveScheduler;
       
    52 	}
       
    53 	
       
    54 /**
       
    55 Base class virtual. Installs the active scheduler
       
    56 @return		EPass or EFail indicating the result of the test step.
       
    57 @internalTechnology
       
    58 @test
       
    59 */
       
    60 TVerdict CTestAssociatedDataStep::doTestStepPreambleL()
       
    61 	{
       
    62 	iActiveScheduler = 	new (ELeave) CActiveScheduler;
       
    63 	CActiveScheduler::Install(iActiveScheduler);
       
    64 	return TestStepResult();
       
    65 	}
       
    66 
       
    67 /**
       
    68 Base class pure virtual.
       
    69 @return		EPass or EFail indicating the result of the test step.
       
    70 @internalTechnology
       
    71 @test
       
    72 */
       
    73 TVerdict CTestAssociatedDataStep::doTestStepL()
       
    74 	{
       
    75 	TPtrC alarmMessage;
       
    76 	if(!ReadStringsFromConfig(ConfigSection(), &KIniAlarmMessage(), &alarmMessage, NULL))
       
    77 		{
       
    78 		IniProblem();
       
    79 		}
       
    80 	else
       
    81 		{
       
    82 		TPtrC typeOfAD;
       
    83 		TRAPD(error, TestAlarmSoundNameL(alarmMessage));
       
    84 		PrintIfError(error);
       
    85 		if(!ReadStringsFromConfig(ConfigSection(), &KIniTypeOfAD(), &typeOfAD, NULL))
       
    86 			{
       
    87 			INFO_PRINTF2(_L("%S field not found in ini. Assuming there is no associated data for the entry"), &KIniTypeOfAD);
       
    88 			}
       
    89 		else
       
    90 			{
       
    91 			TRAP(error, TestAssociatedDataL(alarmMessage, typeOfAD));
       
    92 			PrintIfError(error);
       
    93 			}	
       
    94 		}
       
    95 	return TestStepResult();	
       
    96 	}
       
    97 	
       
    98 /**
       
    99 Retreives the alarm control object and tests the associated data of the alarm 
       
   100 whose message is the one that is passed as parameter
       
   101 @param aAlarmMessage Message to identify the alarm control object
       
   102 @param aTypeOfAD The type of Associated Data, i.e. url or mime
       
   103 @internalTechnology
       
   104 @test
       
   105 */
       
   106 void CTestAssociatedDataStep::TestAssociatedDataL(const TPtrC& aAlarmMessage, const TPtrC& aTypeOfAD)
       
   107 	{
       
   108 	CCalEntryId* entryId = NULL;
       
   109 	if(!GetEntryIdL(aAlarmMessage, entryId))
       
   110 		{
       
   111 		ERR_PRINTF2(_L("No associated data attached with the alarm %S ... Failing the test"), &aAlarmMessage);
       
   112 		SetTestStepResult(EFail);
       
   113 		}
       
   114 	else
       
   115 		{
       
   116 		CCalEntry* calEntry = NULL;
       
   117 		CleanupStack::PushL(entryId);
       
   118 		
       
   119 		TestStoreFileNameL(entryId);
       
   120 		
       
   121 		CCalSession* calSession = CreateAndInitializeCalSessionL(EFalse);
       
   122 		CleanupStack::PushL(calSession);
       
   123 		
       
   124 		if(!GetCalEntryL(entryId, calEntry, calSession))
       
   125 			{
       
   126 			ERR_PRINTF2(_L("The calendar entry was not found for %S. Failing the test..."), &aAlarmMessage);
       
   127 			SetTestStepResult(EFail);
       
   128 			}
       
   129 		else
       
   130 			{
       
   131 			CleanupStack::PushL(calEntry);
       
   132 			CCalAlarm* alarm = calEntry->AlarmL();
       
   133 			if(!alarm->AlarmAction())
       
   134 				{
       
   135 				ERR_PRINTF2(_L("Alarm content is NULL for %S. Failing the test..."), &aAlarmMessage);
       
   136 				SetTestStepResult(EFail);
       
   137 				}
       
   138 			else
       
   139 				{
       
   140 				CleanupStack::PushL(alarm);
       
   141 				DoTestAssociatedDataL(alarm->AlarmAction(), aTypeOfAD);
       
   142 				CleanupStack::PopAndDestroy(alarm);
       
   143 				}	
       
   144 			CleanupStack::PopAndDestroy(calEntry);	
       
   145 			}
       
   146 		CleanupStack::PopAndDestroy(2, entryId);	// calSession and entryId
       
   147 		}	
       
   148 	}
       
   149 	
       
   150 /**
       
   151 Retreives the raw data from the alert server and constructs the CCalEntryId
       
   152 that contains the details about the entry, which owns the alarm corresponding 
       
   153 to the message passed as parameter.
       
   154 @param aAlarmMessage The message associated with the alarm
       
   155 @param aEntryId Pointer to the object that will hold the data describing the 
       
   156 entry
       
   157 @return The sucess or failure. EFalse if entry does not have associated data
       
   158 @internalTechnology
       
   159 @test
       
   160 */
       
   161 TBool CTestAssociatedDataStep::GetEntryIdL(const TPtrC& aAlarmMessage, CCalEntryId*& aEntryId)
       
   162 	{
       
   163 	CDummyAlarmControl* alarmControl = dynamic_cast<CDummyAlarmControl*>(TestServer()->AlarmControlsManager()->GetAlarmControlObjectL(aAlarmMessage));
       
   164 	if(alarmControl->AlarmObject().HasAssociatedData())
       
   165 		{
       
   166 		// Get the data from the supervisor
       
   167 		HBufC8* data = HBufC8::NewL(alarmControl->Supervisor()->AlarmData().Length());
       
   168 		*data = alarmControl->Supervisor()->AlarmData();
       
   169 		CleanupStack::PushL(data);
       
   170 		
       
   171 		aEntryId = CCalEntryId::NewL(data);
       
   172 		
       
   173 		// CCalEntryId takes ownership
       
   174 		CleanupStack::Pop(data);
       
   175 		return ETrue;
       
   176 		}
       
   177 		
       
   178 	return EFalse;
       
   179 	}
       
   180 
       
   181 /**
       
   182 Retreives the calendar entry corresponding to the data contained in the
       
   183 CCalEntryId passed as parameter
       
   184 @param aEntryId The pointer to the object that contains the id details
       
   185 of the entry
       
   186 @param aCalEntry The pointer to hold the cal-entry if found
       
   187 @return The sucess or failure of the find operation
       
   188 @internalTechnology
       
   189 @test
       
   190 */
       
   191 TBool CTestAssociatedDataStep::GetCalEntryL(CCalEntryId* aEntryId, CCalEntry*& aCalEntry, CCalSession* aCalSession)
       
   192 	{
       
   193 	// Get the calendar entry.
       
   194 	RPointerArray<CCalEntry> entryList;
       
   195 	
       
   196 	CCalEntryView* calEntryView = CreateEntryViewL(aCalSession);
       
   197 	CleanupStack::PushL(calEntryView);
       
   198 	
       
   199 	calEntryView->FetchL(aEntryId->IdL(), entryList);
       
   200 	
       
   201 	TBool found = FindCalEntryL(entryList, aEntryId->RecurrenceIdL(), aCalEntry);
       
   202 	
       
   203 	CleanupStack::PopAndDestroy(calEntryView);
       
   204 	return found;
       
   205 	}
       
   206 	
       
   207 /**
       
   208 Not used, to be removed
       
   209 Retreives the data associated with the entry passed as paraemeter
       
   210 @param aCalEntry The pointer to the cal-entry.
       
   211 @return A pointer to the CCalAlarmContent
       
   212 @internalTechnology
       
   213 @test
       
   214 */
       
   215 CCalContent* CTestAssociatedDataStep::GetAlarmContentL(const CCalEntry* aCalEntry)
       
   216 	{
       
   217 	// Get the rich data
       
   218 	return aCalEntry->AlarmL()->AlarmAction();
       
   219 	}
       
   220 	
       
   221 /**
       
   222 Retreives the data associated with the entry passed as paraemeter and checks it
       
   223 @param aAlarmContent The pointer to the rich data.
       
   224 @param aTypeOfAD The type of Associated Data, i.e. url or mime
       
   225 @internalTechnology
       
   226 @test
       
   227 */
       
   228 void CTestAssociatedDataStep::DoTestAssociatedDataL(CCalContent* aAlarmContent , const TPtrC& aTypeOfAD)
       
   229 	{
       
   230 	TPtrC mimeType;
       
   231 	if(ReadStringsFromConfig(ConfigSection(), &KIniContentType(), &mimeType, NULL) == EFalse)
       
   232 		{
       
   233 		IniProblem();
       
   234 		return;
       
   235 		};
       
   236 
       
   237 	HBufC8* content8 = NULL;
       
   238 	CCalContent::TDisposition disposition = CCalContent::EDispositionUnknown;
       
   239 	if(aTypeOfAD.Compare(KIniUrl) == 0)
       
   240 		{
       
   241 		TPtrC url;
       
   242 		if(ReadStringsFromConfig(ConfigSection(), &KIniUrl(), &url, NULL) == EFalse)
       
   243 			{
       
   244 			IniProblem();
       
   245 			return;
       
   246 			};
       
   247 		// Convert read url from unicode to 8-bit data.
       
   248 		content8 = HBufC8::NewL(url.Length());
       
   249 		content8->Des().Copy(url);
       
   250 		disposition = CCalContent::EDispositionUrl;
       
   251 		}
       
   252 	else if(aTypeOfAD.Compare(KIniMime) == KErrNone)
       
   253 		{
       
   254 		TPtrC fileName;
       
   255 		if(ReadStringsFromConfig(ConfigSection(), &KIniFileName(), &fileName, NULL) == EFalse)
       
   256 			{
       
   257 			IniProblem();
       
   258 			return;
       
   259 			};
       
   260 		GetAlarmContentFromFileL(fileName, content8);
       
   261 		disposition = CCalContent::EDispositionInline;
       
   262 		}
       
   263 	CleanupStack::PushL(content8);
       
   264 	
       
   265 	CheckAlarmContentValuesL(aAlarmContent, disposition, mimeType, *content8);
       
   266 	CleanupStack::PopAndDestroy(content8);
       
   267 	}
       
   268 
       
   269 /**
       
   270 Checks data associated with the entry passed as paraemeter against a set of 
       
   271 expected values
       
   272 @param aAlarmContent The reference to a pointer to the rich data
       
   273 @param aExpectedValueType Expected content-value type
       
   274 @param aExpectedContentType Expected content type
       
   275 @param aExpectedDataContent8 Expected data content in an 8-bit descriptor
       
   276 @internalTechnology
       
   277 @test
       
   278 */
       
   279 void CTestAssociatedDataStep::CheckAlarmContentValuesL(CCalContent*& aAlarmContent, CCalContent::TDisposition aExpectedDisposition, const TDesC& aExpectedMimeType, const TDesC8& aExpectedContent)
       
   280 	{
       
   281 	INFO_PRINTF3(_L("Testing content disposition. Expected = %D, Actual = %D."), aExpectedDisposition, aAlarmContent->Disposition());
       
   282 	TEST1(aAlarmContent->Disposition() == aExpectedDisposition, ETrue);
       
   283 	
       
   284 	// Convert 8-bit MIME type to unicode for logging...
       
   285 	HBufC* mimeType = HBufC::NewLC(aAlarmContent->MimeType().Length());
       
   286 	mimeType->Des().Copy(aAlarmContent->MimeType());
       
   287 	INFO_PRINTF3(_L("Testing MIME type. Expected = %S, Actual = %S."), &aExpectedMimeType, mimeType);
       
   288 	TEST1(mimeType->Compare(aExpectedMimeType) == KErrNone, ETrue);
       
   289 	CleanupStack::PopAndDestroy(mimeType);
       
   290 
       
   291 	INFO_PRINTF1(_L("Testing data content"));
       
   292 	TEST1(aAlarmContent->Content().Compare(aExpectedContent) == KErrNone, ETrue);
       
   293 	}
       
   294 
       
   295 /**
       
   296 Finds the calendar entry checking for the sequence no. and recurrence ids
       
   297 @param aEntryList The list of entries to be checked
       
   298 @param aRecurrenceId The recurrence id of the entry
       
   299 @param aFoundEntry The reference to a pointer to the entry which will 
       
   300 be set to point to the found entry
       
   301 @internalTechnology
       
   302 @return Success status
       
   303 @test
       
   304 */
       
   305 TBool CTestAssociatedDataStep::FindCalEntryL(RPointerArray<CCalEntry> aEntryList, const TCalTime& aRecurrenceId, CCalEntry*& aFoundEntry)
       
   306 	{
       
   307 	TInt index = 0;
       
   308 	while(aEntryList.Count() > 0)
       
   309 		{
       
   310 		aFoundEntry = aEntryList[index];
       
   311 		aEntryList.Remove(index);
       
   312 		TCalTime calTime = aFoundEntry->RecurrenceIdL();
       
   313 		if (calTime.TimeUtcL() == aRecurrenceId.TimeUtcL())
       
   314 			{
       
   315 			++index;
       
   316 			}
       
   317 		else
       
   318 			{
       
   319 			delete aFoundEntry;
       
   320 			aFoundEntry = NULL;
       
   321 			}
       
   322 		}
       
   323 	aEntryList.Reset();	
       
   324 	return (aFoundEntry ? ETrue : EFalse);
       
   325 	}
       
   326 
       
   327 /**
       
   328 Tests whether the Store File Name of the calendar entry is as expected
       
   329 @param aEntryId Pointer to the object that has the entry details
       
   330 @internalTechnology
       
   331 @test
       
   332 */
       
   333 void CTestAssociatedDataStep::TestStoreFileNameL(CCalEntryId* aEntryId)
       
   334 	{
       
   335 	TPtrC storeFileName(aEntryId->StoreFileNameL());
       
   336 	INFO_PRINTF3(_L("Testing store file name. Expected = %S, Actual  = %S."), &KTestCalFile, &storeFileName);
       
   337 	TEST1(storeFileName.Compare(KTestCalFile) == KErrNone, ETrue);
       
   338 	}
       
   339 	
       
   340 /**
       
   341 Tests whether the Alarm Sound Name of the alarm is as expected
       
   342 @param aAlarmMessage The message associated with the alarm
       
   343 @internalTechnology
       
   344 @test
       
   345 */
       
   346 void CTestAssociatedDataStep::TestAlarmSoundNameL(const TPtrC& aAlarmMessage)
       
   347 	{
       
   348 	TPtrC alarmSoundName;
       
   349 	CDummyAlarmControl* alarmControl = dynamic_cast<CDummyAlarmControl*>(TestServer()->AlarmControlsManager()->GetAlarmControlObjectL(aAlarmMessage));
       
   350 	
       
   351 	if(ReadStringsFromConfig(ConfigSection(), &KIniAlarmSoundName(), &alarmSoundName, NULL))
       
   352 		{
       
   353 		INFO_PRINTF3(_L("Testing alarm sound name. Expected = %S, Actual  = %S."), &alarmSoundName, &(alarmControl->AlarmSoundName()));
       
   354 		TEST1(alarmSoundName.Compare(alarmControl->AlarmSoundName()) == KErrNone, ETrue);
       
   355 		}
       
   356 	else
       
   357 		{
       
   358 		INFO_PRINTF1(_L("Testing alarm sound name to be NULL descriptor"));
       
   359 		TEST1(KNullDesC().Compare(alarmControl->AlarmSoundName()) == KErrNone, ETrue);
       
   360 		}	
       
   361 	}
       
   362