/** Sets the filter start and end date (the data is taken from the ini file TestCalTZChanges.ini) @test */ void CTestCalInterimApiTZChange::SetTimeRangeL() { iField = KFilterStart; TESTL(GetStringFromConfig(ConfigSection(),iField,iPtrFilterStart)); // gets expected start date for filter iField = KFilterEnd; TESTL(GetStringFromConfig(ConfigSection(),iField,iPtrFilterEnd)); // gets expected end date for filter if (iIsFloating) { // To convert Tptrc to TTime TTime filterstartdate; filterstartdate.Set(iPtrFilterStart); SetCalTimeL(filterstartdate, iStartDate, TCalTime::EFloating); TTime filterenddate; filterenddate.Set(iPtrFilterEnd); SetCalTimeL(filterenddate, iEndDate, TCalTime::EFloating); } else { // To convert Tptrc to TTime TTime filterstartdate; filterstartdate.Set(iPtrFilterStart); SetCalTimeL(filterstartdate, iStartDate, TCalTime::EFixedUtc); TTime filterenddate; filterenddate.Set(iPtrFilterEnd); SetCalTimeL(filterenddate, iEndDate, TCalTime::EFixedUtc); } }
/** Base class pure virtual. @return EPass or EFail indicating the result of the test step. */ TVerdict CTestCalInterimApiDeleteEntryByTimeRange::doTestStepL() { TPtrC startTime; TPtrC endTime; TInt filter; TPtrC timeMode; TESTL( GetStringFromConfig(ConfigSection(), KFilterStartDateTime, startTime) ); TESTL( GetStringFromConfig(ConfigSection(), KFilterEndDateTime, endTime) ); TESTL( GetIntFromConfig(ConfigSection(), KFilterType, filter) ); // Dont mind if it is not given in the ini file GetStringFromConfig(ConfigSection(), KTimeMode, timeMode); CCalEntryView* entryView = CCalEntryView::NewL(GetSession(), *this); CleanupStack::PushL(entryView); CActiveScheduler::Start(); // To convert TPtrc to TTime TTime filterStartDateTime; filterStartDateTime.Set(startTime); TTime filterEndDateTime; filterEndDateTime.Set(endTime); // To change TTime as TCalTime TCalTime calStartDateTime; // Sets the time mode to floating or Utc based on the time mode given SetCalTimeL(filterStartDateTime, calStartDateTime, SetTimeMode(timeMode)); TCalTime calEndDateTime; SetCalTimeL(filterEndDateTime, calEndDateTime, SetTimeMode(timeMode)); CalCommon::TCalTimeRange calTimeRange(calStartDateTime, calEndDateTime); TInt numOfTimes(0); do {// When we run multiple instances of this test step concurrently // for testing asynchronous operations, the server returns KErrServerBusy. // If so we try again and again SetTestStepError(KErrNone); entryView->DeleteL(calTimeRange, CalCommon::TCalViewFilter(filter), *this); CActiveScheduler::Start(); ++numOfTimes; //If any error occurs, step result is set to EFail in Completed() //If this is not done then later when test finishes without any error, Test will still fail. if(TestStepError() == KErrLocked) { SetTestStepResult(EPass); } } while((TestStepError() == KErrServerBusy || TestStepError()== KErrLocked) && numOfTimes < 40); CleanupStack::PopAndDestroy(entryView); if(TestStepError() == KErrServerBusy || TestStepError()== KErrLocked) { SetTestStepError(KErrNone); SetTestStepResult(EPass); } return TestStepResult(); }
TBool Util::DaylightSavingsAppliesL(const TTime& utc) { // This algorithm needs the first day of the week to be monday TDay oldStart; TLocale set; oldStart = set.StartOfWeek(); set.SetStartOfWeek(EMonday); set.Set(); TBuf<9> min; TBuf<9> max; utc.FormatL(min, KDaylightSavingsMinFormat); utc.FormatL(max, KDaylightSavingsMaxFormat); // Get times representing the first/last possible day of this // year that daylight savings time change could change on TTime timeMin; User::LeaveIfError(timeMin.Set(min)); TTime timeMax; User::LeaveIfError(timeMax.Set(max)); // Find the last sunday in the respective months TTimeIntervalDays addMin(6 - timeMin.DayNoInWeek()); TTimeIntervalDays addMax(6 - timeMax.DayNoInWeek()); timeMin += addMin; timeMax += addMax; // The change happens at 1AM. TTimeIntervalHours hour(1); timeMin += hour; timeMax += hour; // Now we know which day the change occurs on. // Compare it to what the UTC is. TBool result = ((timeMin <= utc) && (timeMax > utc)); // reset the first week day set.SetStartOfWeek(oldStart); set.Set(); return result; }
/** Fetch the entry and check the properties that are set. @param aGuid Data for fetching the entry. @param aEntryProperties Structure containing the entry properties */ void CTestCalInterimApiFetchEntryAndCheckData::FetchAndCheckDataL(const TPtrC& aGuid, const TInt& aExpectedCount, const TEntryProperties& aEntryProperties, const TPtrC& aTimeMode) { RPointerArray<CCalEntry> entriesFetched; CleanupStack::PushL(TCleanupItem(ResetAndDestroyEntryArray, &entriesFetched)); HBufC8* entryId = HBufC8::NewLC(aGuid.Length()); entryId->Des().Copy(aGuid); iCalEntryView->FetchL(entryId->Des(), entriesFetched); CleanupStack::PopAndDestroy(entryId); TBool matchInRecurrenceId = EFalse; if ( entriesFetched.Count() == aExpectedCount ) { for ( TInt i = 0; i < entriesFetched.Count(); i++ ) { CCalEntry* calEntry = entriesFetched[i]; if ( aEntryProperties.iRecurrenceId == KNullDesC16() ) // Parent Entry { if ( calEntry->RecurrenceIdL().TimeUtcL() == Time::NullTTime() ) { // Checks the data for the parent entry CheckDataL(calEntry, aEntryProperties); } } else // Child Entry { TTime recurrenceIdValue; recurrenceIdValue.Set(aEntryProperties.iRecurrenceId); TCalTime recurrenceId; // Sets the time mode to floating or Utc based on the time mode given SetCalTimeL(recurrenceIdValue, iRecurrenceId, SetTimeMode(aTimeMode)); if (iRecurrenceId.TimeUtcL() == (calEntry->RecurrenceIdL().TimeUtcL()) ) { matchInRecurrenceId = ETrue; // Checks the data for the child entry CheckDataL(calEntry, aEntryProperties); } } } INFO_PRINTF3(KInfoEntryFetched, entriesFetched.Count(), aExpectedCount) ; } else { ERR_PRINTF3(KErrExpectedCount, entriesFetched.Count(), aExpectedCount); SetTestStepResult(EFail); } /* If the recurrence Id doesn't match with the recurrenceId of the child entry then, print a warning message */ if (aEntryProperties.iRecurrenceId != KNullDesC16() && matchInRecurrenceId == 0) { WARN_PRINTF1(KWarnNoMatchInRecurrenceId); } CleanupStack::PopAndDestroy(&entriesFetched); }
TInt64 TimeUtils::GetFiletime(TTime aSymbianTime) { _LIT(KInitialTime,"16010000:000000"); TTime initialTime; initialTime.Set(KInitialTime); TTimeIntervalMicroSeconds interval; interval=aSymbianTime.MicroSecondsFrom(initialTime); return interval.Int64()*10; }
/* * A filetime is a 64-bit value that represents the number of 100-nanosecond intervals * that have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC). * Please also note that in defining KInitialTime the month and day values are offset from zero. * */ TInt64 TimeUtils::GetSymbianTime(TUint64 aFiletime) { _LIT(KFiletimeInitialTime,"16010000:000000"); TTime initialFiletime; initialFiletime.Set(KFiletimeInitialTime); TInt64 interval; interval = initialFiletime.Int64(); TInt64 date = aFiletime/10; return (interval + date); }
// --------------------------------------------------------------------------- // RFotaEngineSession::LastUpdate // --------------------------------------------------------------------------- EXPORT_C TInt RFotaEngineSession::LastUpdate(TTime& aUpdates) { TInt err; FLOG(_L("RFotaEngineSession::LastUpdate >>")); TBuf<15> timestamp; err = SendReceive ( EGetUpdateTimestamp, TIpcArgs(×tamp) ); if ( timestamp.Length() > 0 ) { TInt year = timestamp[0]; TInt month = timestamp[1]; TInt day = timestamp[2]; TInt hour = timestamp[3]; TInt minute = timestamp[4]; aUpdates = TDateTime (year,(TMonth)month,day,hour,minute,0,0 ); } else { aUpdates.Set( _L( "19900327:101010.000000" ) ); err = KErrUnknown; } FLOG(_L("RFotaEngineSession::LastUpdate <<")); return err; }
// ---------------------------------------------------------------------------- // CAknExQueryContainer::ShowMultiLineTimeAndDurationLayoutL // Display of MultiLine Time with Duration Query // ---------------------------------------------------------------------------- void CAknExQueryContainer::ShowMultiLineTimeAndDurationLayoutL( const TInt aResourceId, const TInt aTopResourceId) { iDisplayDialog = ETrue; SetTextToLabelL( R_AKNEXQUERY_OPERATE_MESSAGE ); TBuf<KAknExQueryTextBufLength> bufferRes; iCoeEnv -> ReadResource(bufferRes, aTopResourceId); TTime topDateTime; topDateTime.Set(bufferRes); topDateTime.HomeTime(); TTimeIntervalSeconds bottomDuration = 300; // set timer field to 5 minutes CAknMultiLineDataQueryDialog* dlg = CAknMultiLineDataQueryDialog::NewL( topDateTime, bottomDuration ); dlg->ExecuteLD( aResourceId ); iDisplayDialog = EFalse; }
TVerdict CTestUTCParse::TestTime(TInt aCount,TTime* aTime) { TVerdict result=EFail; TTime currentUtcTime; TTimeIntervalMicroSeconds difference; TTime time; switch(aCount) { case 0: //the expected timestamp is Wed, 30 Apr 1997 10:12:18 +0100 _LIT(KDateCorrect, "19970329:091218.000000"); time.Set(KDateCorrect); result = (time==*aTime? EPass:EFail); if(result==EFail) ERR_PRINTF2(_L("Test %d failed\n"), aCount+1); break; case 1: //there is no received header in this test so the date field should be used insted //the expected timestamp is Wed, 30 Apr 1997 10:02:38 +0100 (BST) _LIT(KDateCorrect55, "19970329:090238.000000"); time.Set(KDateCorrect55); result = (time==*aTime? EPass:EFail); if(result==EFail) ERR_PRINTF2(_L("Test %d failed\n"), aCount+1); break; case 2: //the UTC offset in this test is invalid (+2500) and should be ignored //expected time-stamp is Wed, 30 Apr 1997 10:12:18 +2500 _LIT(KDateCorrect2, "19970329:101218.000000"); time.Set(KDateCorrect2); result = (time==*aTime? EPass:EFail); if(result==EFail) ERR_PRINTF2(_L("Test %d failed\n"), aCount+1); break; case 3: //the UTC offset is invalid in this test and the current UTC time should be used to //time-stamp the entry instead currentUtcTime.UniversalTime(); difference=currentUtcTime.MicroSecondsFrom(*aTime); //the difference should be less than 1 second result = (difference<5000000? EPass:EFail); if(result==EFail) ERR_PRINTF2(_L("Test %d failed\n"), aCount+1); break; case 4: //expected time-stamp is Thu, 3 Mar 2005 15:28:50 +0000 _LIT(KDateCorrect3, "20050202:152850.000000"); time.Set(KDateCorrect3); result = (time==*aTime? EPass:EFail); if(result==EFail) ERR_PRINTF2(_L("Test %d failed\n"), aCount+1); break; case 5: //This is the time-stamp of an embedded entry //expected time-stamp is Thu, 3 Mar 2005 15:27:12 +0000 _LIT(KDateCorrect4, "20050202:152712.000000"); time.Set(KDateCorrect4); result = (time==*aTime? EPass:EFail); if(result==EFail) ERR_PRINTF2(_L("Test %d failed\n"), aCount+1); break; default: break; } return result; }
/** * Delete entries in the calendar file over a wider time Range */ void CTestCalInterimApiModifier::DeleteEntriesByTimeRangeL() { TPtrC timeMode; GetStringFromConfig(ConfigSection(), KFilterTimeMode, timeMode); TPtrC deleteFilterStartTime; GetStringFromConfig(ConfigSection(), KDeleteFilterStartTime, deleteFilterStartTime); TCalTime calStartDateTime; if(deleteFilterStartTime != KNullDesC()) { // Convert TPtrC to TTime TTime startTTime; startTTime.Set(deleteFilterStartTime); if(!timeMode.Compare(KFilterTimeModeLocal)) { calStartDateTime.SetTimeLocalL(startTTime); } else if (!timeMode.Compare(KFilterTimeModeLocalFloating)) { calStartDateTime.SetTimeLocalFloatingL(startTTime); } else { calStartDateTime.SetTimeUtcL(startTTime); } } else { calStartDateTime.SetTimeLocalL(TCalTime::MinTime()); } TCalTime calEndDateTime; TPtrC deleteFilterEndTime; GetStringFromConfig(ConfigSection(), KDeleteFilterEndTime, deleteFilterEndTime); if(deleteFilterEndTime != KNullDesC()) { // Convert TPtrC to TTime TTime endTTime; endTTime.Set(deleteFilterEndTime); if(!timeMode.Compare(KFilterTimeModeLocal)) { calEndDateTime.SetTimeLocalL(endTTime); } else if (!timeMode.Compare(KFilterTimeModeLocalFloating)) { calEndDateTime.SetTimeLocalFloatingL(endTTime); } else { calEndDateTime.SetTimeUtcL(endTTime); } } else { calEndDateTime.SetTimeLocalL(TCalTime::MaxTime()); } CalCommon::TCalTimeRange calTimeRange(calStartDateTime, calEndDateTime); TRAPD(err, iEntryView->DeleteL(calTimeRange, CalCommon::EIncludeAll, *this)); CActiveScheduler::Start(); if(err != KErrNone) { iTestStep->ERR_PRINTF2(KErrDeleteOperation,err); iTestStep->SetTestStepResult(EFail); } }
TTime CTimeUtilities::DecodeL(const TDesC8& aFormattedTime) { TTime aTime; aTime.UniversalTime(); HBufC* aTimeDelay = HBufC::NewLC(aFormattedTime.Length()); TPtr pTimeDelay(aTimeDelay->Des()); pTimeDelay.Copy(aFormattedTime); TInt aLocateResult = pTimeDelay.Locate('T'); if(aLocateResult != KErrNotFound && pTimeDelay.Length() >= 17) { TBuf<8> aDigits; TInt aResult; // Valid jabber:x:delay // Delay Formats: YYYYMMDDTHH:MM:SS.000Z // YYYY-MM-DDTHH:MM:SSZ // TTime Format: YYYYMMDD:HHMMSS.MMMMMM // Remove '-' while((aLocateResult = pTimeDelay.Locate('-')) != KErrNotFound) { pTimeDelay.Delete(aLocateResult, 1); } // Remove ':' while((aLocateResult = pTimeDelay.Locate(':')) != KErrNotFound) { pTimeDelay.Delete(aLocateResult, 1); } // Replace 'T' with ':' pTimeDelay.Replace(pTimeDelay.Locate('T'), 1, _L(":")); // Remove all after '.' if(pTimeDelay.Length() > 15) { pTimeDelay.Delete(15, pTimeDelay.Length()); } pTimeDelay.Append(_L(".")); // Fix Month for conversion aDigits.Zero(); aDigits.Append(TChar(pTimeDelay[4])); aDigits.Append(TChar(pTimeDelay[5])); TLex aLexMonth(aDigits); aLexMonth.Val(aResult); aResult--; aDigits.Format(_L("%02d"), aResult); pTimeDelay.Replace(4, 2, aDigits); // Fix Day for conversion aDigits.Zero(); aDigits.Append(TChar(pTimeDelay[6])); aDigits.Append(TChar(pTimeDelay[7])); TLex aLexDay(aDigits); aLexDay.Val(aResult); aResult--; aDigits.Format(_L("%02d"), aResult); pTimeDelay.Replace(6, 2, aDigits); aTime.Set(pTimeDelay); } CleanupStack::PopAndDestroy(); // aTimeDelay return aTime; }
TVerdict CTPKCS7ValidTest::doTestStepL() { if (TestStepResult() != EPass) { return TestStepResult(); } __UHEAP_MARK; TBool expectedValid; if (GetBoolFromConfig(ConfigSection(),_L("IsValid"), expectedValid) == EFalse) { expectedValid = ETrue; } TInt err; CPKCS7ContentInfo * contentInfo = NULL; TRAP (err, contentInfo = CPKCS7ContentInfo::NewL(iRawData->Des())); if(err == KErrNone) { CPKCS7SignedObject * p7 = NULL; if( contentInfo->ContentType() == KPkcs7SignedData) { TRAP (err, p7 = CPKCS7SignedObject::NewL(*contentInfo)); //expired, and the case where certificate chain root is not on the device if (!expectedValid) { if (err != KErrNone) { SetTestStepResult(EPass); INFO_PRINTF2(_L("Got %d building PKCS7 object"), err); return TestStepResult(); } } if (err != KErrNone) { SetTestStepResult(EFail); INFO_PRINTF2(_L("Got %d building PKCS7 object"), err); } else { CleanupStack::PushL (p7); const RPointerArray<CPKCS7SignerInfo>& signers = p7->SignerInfo(); TBool isValid = EFalse; HBufC8* certificateEncoding = NULL; if(!p7->ValidateSignerL(*signers[0], certificateEncoding)) { INFO_PRINTF1(_L("Couldn't validate signer")); } else { CActiveScheduler* sched = NULL; if (CActiveScheduler::Current() == NULL) { INFO_PRINTF1(_L("Installing scheduler")); sched = new (ELeave) CActiveScheduler(); CleanupStack::PushL (sched); __UHEAP_MARK; CActiveScheduler::Install (sched); } RPointerArray<CX509Certificate> roots (&iRootCertificate, 1); CPKIXCertChain * chain = CPKIXCertChain::NewLC(iFs, *certificateEncoding, roots); TTime tm; _LIT(KDateCorrect1,"20040801:"); TBuf <24> theDate(KDateCorrect1); TInt err=tm.Set(theDate); if(err) { tm.HomeTime(); } CPKIXValidationResult* result = CPKIXValidationResult::NewLC(); CTPKCS7Validator* validator = new (ELeave) CTPKCS7Validator (chain, result, &tm); CleanupStack::PushL (validator); validator->doValidate (); sched->Start (); if (result->Error().iReason == EValidatedOK) { isValid = ETrue; INFO_PRINTF1(_L("Validation success")); } else { INFO_PRINTF2(_L("Validation failed: %d"), result->Error().iReason); } CleanupStack::PopAndDestroy(validator); CleanupStack::PopAndDestroy(result); CleanupStack::PopAndDestroy(chain); if (sched) { CActiveScheduler::Install (NULL); CleanupStack::PopAndDestroy (sched); } } if (certificateEncoding) { CleanupStack::PopAndDestroy(certificateEncoding); } CleanupStack::PopAndDestroy (p7); if (isValid != expectedValid) { SetTestStepResult(EFail); if (expectedValid) { INFO_PRINTF1(_L("Expected valid, got invalid")); } else { INFO_PRINTF1(_L("Expected invalid, got valid")); } } } } } else { SetTestStepResult(EFail); } __UHEAP_MARKEND; return TestStepResult(); }
TVerdict CT_LbsStep_ClearLog::doTestStepL() { SetTestStepResult(EPass); // Create necessary variables for Log reading RFs theFs; CLogClient* client; CLogViewEvent* view; CT_LbsAsyncWaiter* activeWaiter; // Initialise variables TInt ErrorCode = theFs.Connect(); if(ErrorCode) { INFO_PRINTF1(_L("\t Error: Open FileServer failed.")); SetTestStepResult(EFail); } client = CLogClient::NewL(theFs, CActive::EPriorityStandard); view = CLogViewEvent::NewL(*client, CActive::EPriorityStandard); activeWaiter = CT_LbsAsyncWaiter::NewL(); // NEW activeWaiter // Setup a time in the future, before which all events will be deleted _LIT(KDateCorrect1,"20900101:"); TTime time; TBuf <10> theDate(KDateCorrect1); TInt err=time.Set(theDate); // Ensure time has been set correctly if(err != KErrNone) { INFO_PRINTF1(_L("Failed to set time")); } if(err == KErrGeneral) { INFO_PRINTF1(_L("Time syntax is incorrect")); } // Set the filter to view ALL logs CLogFilter* filter = CLogFilter::NewL(); // NEW FILTER CleanupStack::PushL(filter); TBool res = view->SetFilterL(*filter, activeWaiter->iStatus); if (res == EFalse) { INFO_PRINTF1(_L("\t No such events to filter in the view.")); client->Cancel(); } else { // else If there are logs, flush them // Cancel outstanding requests client->Cancel(); activeWaiter->StartAndWait(); if (activeWaiter->iStatus != KErrNone) { INFO_PRINTF2(_L("\t Error: Cancel returned error %d."),activeWaiter->iStatus.Int()); SetTestStepResult(EFail); } // Clear ALL logs client->ClearLog(time, activeWaiter->iStatus); activeWaiter->StartAndWait(); if (activeWaiter->iStatus != KErrNone) { INFO_PRINTF2(_L("\t Error: Clear log returned error %d."),activeWaiter->iStatus.Int()); SetTestStepResult(EFail); } //Confirm log is cleared if(view->CountL() != 0) { INFO_PRINTF2(_L("<FONT><B>ERROR: Log still has %d entries</B></FONT>"),view->CountL()); SetTestStepResult(EFail); } } CleanupStack::PopAndDestroy(filter); // Cleanup everything view->Cancel(); client->Cancel(); delete view; delete client; theFs.Close(); delete activeWaiter; return TestStepResult(); }