// ---------------------------------------------------------------------------
// TPresCondValidity::ParseFromXMLTimeString()
// ---------------------------------------------------------------------------
//    
TInt TPresCondValidity::ParseFromXMLTimeString(const TDesC& aXMLTimeString, 
                                                         TTime& aUTCDateTime)
    {
    OPENG_DP(D_OPENG_LIT( " TPresCondValidity::ParseFromXMLTimeString()" ) );
    OPENG_DP(D_OPENG_LIT( "     ParseFromXMLTimeString aXMLTimeString = %S"), 
                                                                &aXMLTimeString);

    TInt err(KErrNone);
    
    // Initializing the locale
    TLocale myLocale, systemLocale;
    myLocale.Refresh();
    systemLocale.Refresh();
    myLocale.SetDateFormat(EDateJapanese);
    myLocale.SetDateSeparator('-',1);
    myLocale.SetDateSeparator('-',2);
    myLocale.SetDateSeparator('T',3);
    
    myLocale.SetTimeFormat(ETime24);
    myLocale.SetTimeSeparator(':',1);
    myLocale.SetTimeSeparator(':',2);
    myLocale.SetTimeSeparator(' ',3);
    myLocale.Set();

    TTime myTime;
    TTime myUTCtime;
    TChar uTCtimeSign(aXMLTimeString[23]); // 23 is ascii T
    
   
    // parsing main time
    TBuf<KPresDateTimeBufLength> dateTimeBuffer(aXMLTimeString);
    dateTimeBuffer.Delete(KPresDTWithoutUTCLength-1,6);
    dateTimeBuffer.Replace(KPresDTSeperatorPos,1,KPresSpaceString);
    myTime.Parse(dateTimeBuffer);
    
    // parsing utc time
    TBuf<KPresDateTimeBufLength> uTCbuffer(aXMLTimeString);
    uTCbuffer.Delete(0,KPresDTWithoutUTCLength);
    myUTCtime.Parse(uTCbuffer);
    TDateTime uTCDateTime = myUTCtime.DateTime();
    
    // adding or substracting utc from main time
    if(uTCtimeSign=='+') // if diff is positive
        {
        aUTCDateTime = myTime - TTimeIntervalHours(uTCDateTime.Hour());
        aUTCDateTime = aUTCDateTime - TTimeIntervalMinutes(uTCDateTime.Minute());            
        }
    else if(uTCtimeSign=='-')
        {
        aUTCDateTime = myTime + TTimeIntervalHours(uTCDateTime.Hour());
        aUTCDateTime = aUTCDateTime + TTimeIntervalMinutes(uTCDateTime.Minute());            
        }
    else
        err = KErrArgument;
    
    // putting the system locale back
    systemLocale.Set();
    return err;    
    }
Beispiel #2
0
static void TestSoundControlL()
{
    TheAlarmTest.Test().Next(_L("Test sound control"));

    TheAlarmTest.TestClearStoreL();

    ret = TheAlarmTest.Session().SetAlarmSoundState(EAlarmGlobalSoundStateOff);
    TheAlarmTest(ret == KErrNone, __LINE__);

    TAlarmGlobalSoundState soundState;
    ret = TheAlarmTest.Session().GetAlarmSoundState(soundState);
    TheAlarmTest(ret == KErrNone && soundState == EAlarmGlobalSoundStateOff, __LINE__);

    time.HomeTime();
    time += TTimeIntervalMinutes(1);
    ret = TheAlarmTest.Session().SetAlarmSoundsSilentUntil(time);
    TheAlarmTest(ret == KErrNone, __LINE__);

    ret = TheAlarmTest.Session().CancelAlarmSilence();
    TheAlarmTest(ret == KErrNone, __LINE__);

    ret = TheAlarmTest.Session().SetAlarmSoundsSilentFor(1);
    TheAlarmTest(ret == KErrNone, __LINE__);

    ret = TheAlarmTest.Session().GetAlarmSoundsSilentUntil(time);
    TheAlarmTest(ret == KErrNone, __LINE__);

    if (!TheAlarmTest.Session().AlarmSoundsTemporarilySilenced())
    {
        User::Leave(KErrGeneral);
    }
}
void CBBListenerImpl::Acked(TUint id)
{
	CALLSTACKITEM_N(_CL("CBBListenerImpl"), _CL("Acked"));

	iTimer->Wait(KMaxAckInterval);
	TRequestStatus s;
	if (id!=0) {
		iBBClient.Delete(id, s);
		User::WaitForRequest(s);
#ifdef __WINS__
		TBuf<100> msg=_L("deleted ");
		msg.AppendNum(id); msg.Append(_L(": "));
		msg.AppendNum(s.Int());
		RDebug::Print(msg);
#endif
	}
	if (iPreviousAck + TTimeIntervalMinutes(1) < GetTime()) {
		TBBTime t(KLastAck);
		iPreviousAck=GetTime();
		t()=iPreviousAck;
		TTime expires=Time::MaxTTime();
		CC_TRAPD(err, PutTupleL(KStatusTuple, KLastAck, &t, expires));
	}
	iUnackedCount--;
	if (iPendingStop && iUnackedCount==0) {
		if (!iStopTimer) iStopTimer=CTimeOut::NewL(*this);
		iStopTimer->Wait(10);
	}
}
//*************************************************************************************
void CConsoleAlarmAlertSession::GetUserTimeL(const RMessage2& aMessage)
	{
	TTime time;
	time.HomeTime();
	time+=TTimeIntervalMinutes(iConsole->GetTimeInterval());
	TPtrC8 pTime((TUint8 *)&time,sizeof(TTime));
	aMessage.WriteL(KSlot0,pTime);
	}
Beispiel #5
0
LOCAL_C void TestFilteringL()
{
    _LIT(KProgressIndicator,".");
    test.Printf(KProgressIndicator);

    CCntFilter* filter = CCntFilter::NewL();
    CleanupStack::PushL(filter);

    filter->SetContactFilterTypeCard(ETrue);
    TTime time;
    time.UniversalTime();
    time-=TTimeIntervalMinutes(20); // changes in the last 20 mins
    filter->SetFilterDateTime(time);
    filter->SetIncludeNewContacts(ETrue);
    CntTest->Db()->FilterDatabaseL(*filter);
    test(filter->iIds->Count()==KTotalNumRecords);

// modified contact
    User::After(4000000);	// Let time pass to distinguish between mod  / new
    // this may still fail if the device is running too slow (e.g. under a heavy load)

    filter->Reset();
    time.UniversalTime();
    filter->SetFilterDateTime(time);
    filter->SetIncludeModifiedContacts(ETrue);
    CntTest->Db()->FilterDatabaseL(*filter);
    test(filter->iIds->Count()==0);

    CContactItem* contact = CntTest->Db()->OpenContactLX(5);
    CleanupStack::PushL(contact);
    contact->IncAccessCount();
    CntTest->Db()->CommitContactL(*contact);
    CleanupStack::PopAndDestroy(contact);
    CleanupStack::Pop(); // contact.Close()

    CntTest->Db()->FilterDatabaseL(*filter);
    test(filter->iIds->Count()==1);

// deleted contact
    filter->Reset();
    filter->SetFilterDateTime(time); // same time as for modified
    filter->SetIncludeDeletedContacts(ETrue);
    CntTest->Db()->FilterDatabaseL(*filter);
    test(filter->iIds->Count()==0);

    CntTest->Db()->DeleteContactL(5);
    CntTest->Db()->FilterDatabaseL(*filter);
    TInt deletedContactCount = filter->iIds->Count();
    test(deletedContactCount ==1);

#ifdef _DEBUG
    CContactIdArray* deletedCntArray = CntTest->Db()->DeletedContactsLC();
    test(deletedCntArray->Count()==deletedContactCount);
    CleanupStack::PopAndDestroy(deletedCntArray );
#endif

    CleanupStack::PopAndDestroy(filter);
}
// -----------------------------------------------------------------------------
// CPIMAgnToDoAdapter::AlarmOffsetL
// Calculates PIM alarm offset for native Calendar entry
// The offset calculation is done by calculating the difference between the
// due date and the alarm offset. After we know the alarm date and time we
// calculate difference between calender specific todo due date (which now is
// 00:00)
//
// For example:
//
// If our due time is 23:00 and the alarm offset is 900 seconds before it.
// Then the alarm should launch at 22:45 at the same day. So, the offset which
// we have to write to the native alarm is the difference between 00:00 and 22:45
// which is a negative value because the alarm rises in the future. This all is
// done because the calendar understands only the date of the due date and not the
// exact time of it. The time is ignored and set to 00:00 by default.
// -----------------------------------------------------------------------------
//
TTimeIntervalMinutes CPIMAgnToDoAdapter::AlarmOffsetL(
    const MPIMItemData& aItemData, CCalEntry& aEntry)
{
    JELOG2(EPim);
    // Note that start time must be set before alarm can be calculated
    // Add start to the item so alarm can be properly converted. The
    // native entry does not accept alarm value if start is not present
    // Due has been already set to default time (current home time) if
    // ToDo due field is not present in the field so start should be present
    if (!aItemData.CountValues(EPIMToDoDue))
    {
        User::Leave(KErrArgument);
    }
    else
    {
        ConvertDateToAgnL(EPIMToDoDue, 0, aEntry, aItemData);
    }

    __ASSERT_DEBUG(aEntry.StartTimeL().TimeUtcL() != Time::NullTTime(),
                   User::Panic(KPIMPanicCategory, EPIMPanicInvalidState));

    // Get alarm value from the Java item. There should be only one alarm
    // value supported by the PIM API because native entries do not support
    // multiple alarm values.
    const TPIMFieldData alarmData = aItemData.ValueL(EPIMToDoExtAlarm, 0);
    TInt value = alarmData.IntegerValue();

    // Count the alarm value from the start date of the event
    TTime entryStart = aEntry.StartTimeL().TimeLocalL();
    const TPIMFieldData dateData = aItemData.ValueL(EPIMToDoDue, 0);
    TPIMDate dueDate(dateData.DateValue());
    ConvertTimeL(dueDate, EPIMDateLocal);
    TTimeIntervalSeconds temp(0);
    User::LeaveIfError(entryStart.SecondsFrom(dueDate, temp));

    // Add difference between PIM API start and start which has been
    // converted to the item (in case if the date has been changed, it is
    // reflected here)
    value += temp.Int();

    // Check that if the alarm has passed to the following day. In this case,
    // the alarm is transferred back to 12 o'clock of the current start date
    TTime alarmTime(entryStart - TTimeIntervalSeconds(value));
    // Temporary date. This date is used when calculating if the alarm
    // value has passed to the following date.
    TTime startOfNextDay(StartOfDay(dueDate + TTimeIntervalDays(1)));
    if (alarmTime >= startOfNextDay)
    {
        alarmTime = StartOfDay(entryStart);
        alarmTime += TTimeIntervalSeconds(KPIMDefaultAlarmInterval);
        User::LeaveIfError(entryStart.SecondsFrom(alarmTime, temp));
        value = temp.Int();
    }
    // Convert seconds to minutes
    return TTimeIntervalMinutes(value / KPIMSecondsInMinute);
}
void CLocaLogicImpl::UpdateStats(const TDesC& aNodeName,
	const CBBBtDeviceList* devices, const TTime& aAtTime)
{
	const TBBBtDeviceInfo* info=0;
	for (info=devices->First(); info; info=devices->Next()) {
		if (info->iMajorClass()==0x02 ||
			info->iMajorClass()==0x01) {
		} else {
			continue;
		}
		TDevStats s;
		iDevStats->GetStatsL(*info, aNodeName, s);
		if (aAtTime > s.iLastSeen ) {
			TInt span=0;
			if (s.iFirstSeen==TTime(0)) s.iFirstSeen=aAtTime;
			if (s.iLastSeen + TTimeIntervalMinutes(3) < aAtTime) {
				s.iPreviousVisitBegin=s.iVisitBegin;
				s.iPreviousVisitEnd=s.iLastSeen;
				s.iVisitBegin=aAtTime;
				s.iCountStay++;
				span=1;
			} else {
				TTimeIntervalMinutes prev_span;
				s.iLastSeen.MinutesFrom(s.iVisitBegin, prev_span);
				if (prev_span.Int()==0) prev_span=1;
				else prev_span=TTimeIntervalMinutes(prev_span.Int()+1);
				s.iSumStay-=prev_span.Int();
				s.iSquareSumStay-=(prev_span.Int()*prev_span.Int());
				TTimeIntervalMinutes this_span;
				aAtTime.MinutesFrom(s.iVisitBegin, this_span);
				span=this_span.Int() + 1;
			}
			s.iLastSeen=aAtTime;
			s.iSumStay+=span;
			s.iSquareSumStay+=span*span;
			if (span > s.iMaxStay) s.iMaxStay=span;
			iDevStats->SetStatsL(*info, aNodeName, s);
		}
	}
}
Beispiel #8
0
LOCAL_C void SimpleFilterTestL()
{
    CCntFilter* filter = CCntFilter::NewL();
    CleanupStack::PushL(filter);
    filter->SetContactFilterTypeCard(ETrue);
    TTime time;
    time.UniversalTime();
    time-=TTimeIntervalMinutes(20); // changes in the last 20 mins
    filter->SetFilterDateTime(time);
    filter->SetIncludeNewContacts(ETrue);
    CntTest->Db()->FilterDatabaseL(*filter);
    test(filter->iIds->Count()==KTotalNumRecords);
    CleanupStack::PopAndDestroy(filter);
}
Beispiel #9
0
static void TestStartUpAndShutDownUtcL()
{
#ifdef _DEBUG
#ifdef __WINS__
    TheAlarmTest.Test().Next(_L("Test start up and shut down with UTC Alarms"));

    TheAlarmTest.Session().__DbgShutDownServer();
    TheAlarmTest.TestStartServers();
    TheAlarmTest.TestClearStoreL();

    time.HomeTime();
    time += TTimeIntervalMinutes(5);
    id = AddUtcAlarm(time);

    TheAlarmTest.Test().Printf(_L("\nDebug only - shutting down server\n"));
    TheAlarmTest.Session().__DbgShutDownServer();
    User::After(3 * 1000000);

    TheAlarmTest.TestStartServers();

    TAlarmId nextDueId;
    ret = TheAlarmTest.Session().GetNextDueAlarmId(nextDueId);
    TheAlarmTest(ret == KErrNone && nextDueId == id, __LINE__);

    time -= TTimeIntervalMinutes(1);
    id = AddUtcAlarm(time);

    TheAlarmTest.Session().__DbgShutDownServer();
    User::After(3 * 1000000);

    TheAlarmTest.TestStartServers();

    ret = TheAlarmTest.Session().GetNextDueAlarmId(nextDueId);
    TheAlarmTest(ret == KErrNone && nextDueId == id, __LINE__);
#endif
#endif
}
void CTzUserDataTest::CachedUserTimeZoneL(RTz& aRTz, TTest aWhatToTest)
	{
	test.Next(_L("Conver times - Server Response to Changes"));
	TInt offset = 60;
	TTime utctime (TDateTime(2000, EMay, 0, 0, 0, 0, 0));
	
	//Convert a given time from UTC to local time using the user-defined time zone
	TTime localtime = utctime ;
	CreateUserTzAndSetCurrentTimeToL(aRTz, offset, offset);
	aRTz.ConvertToLocalTime(localtime);
	TTimeIntervalMinutes minutes;
	localtime.MinutesFrom(utctime, minutes);
	test (minutes == TTimeIntervalMinutes(offset));
	
	localtime = utctime;

	//Convert a given time from UTC to local time when the corrent tz rule is updated 
	if(aWhatToTest==EUpdateCachedTz)
		{
		offset = 120;
		UpdateCurrentTzL(aRTz, offset, offset);
		}
	else if(aWhatToTest==EDeleteCachedTz)
		{
		//Delete the current tz rule which result in system time reverting to the default time zone. 
		DeleteCurrentTzL(aRTz);
		//Convert a given time from UTC to local time using an existing time zone which is the defaut time zone.
		CTzRules* currentRules = aRTz.GetTimeZoneRulesL(0, 9999,ETzUtcTimeReference );
		CleanupStack::PushL(currentRules);
		offset = currentRules->GetOffsetL(utctime, ETzUtcTimeReference);
		CleanupStack::PopAndDestroy(currentRules);
		}
	
	aRTz.ConvertToLocalTime(localtime);
	localtime.MinutesFrom(utctime, minutes);
	test (minutes == TTimeIntervalMinutes(offset));
	}
void CTzUserDataTest::TestUtcOffsetL(CTzId& aTzId, const CTzRules& rules, const RArray<TTime>& times, TInt aOffset, RTz& aRTz )
	{
	aRTz.SetTimeZoneL(aTzId);

	TInt count = times.Count();
	
	for(TInt ii=0; ii<count; ++ii)
		{
		test (aOffset == rules.GetOffsetL(times[ii], ETzUtcTimeReference));	
		TTime utc = times[ii];
		aRTz.ConvertToUniversalTime(utc);
		TTimeIntervalMinutes minutes;
		times[ii].MinutesFrom(utc, minutes);
		test (minutes == TTimeIntervalMinutes(aOffset));	
		}
	}
CCntFilter* CPackagerCntFactory::doCreateDefaultCCntFilterL() const
/** Implementation method for constructing a new default CCntFilter object. 

@return a Pointer to the CCntFilter object. */
	{
	CCntFilter* theFilter = CCntFilter::NewLC();
	theFilter->SetContactFilterTypeCard(ETrue);
	TTime time;
	time.UniversalTime();
	time-=TTimeIntervalMinutes(KInterval); // changes in the last KInterval mins
	theFilter->SetFilterDateTime(time);
	theFilter->SetIncludeNewContacts(ETrue);
	theFilter->SetContactFilterTypeALL(ETrue);
	theFilter->iIds = doCreateDefaultCContactIdArrayL();
	CleanupStack::Pop(theFilter);
	return theFilter;
	}	
Beispiel #13
0
static void TestOtherFunctionalityUtcL()
{
    TheAlarmTest.Test().Next(_L("Test other functionality"));

    TheAlarmTest.TestClearStoreL();

    time.HomeTime();
    time += TTimeIntervalMinutes(1);
    id = AddUtcAlarm(time);
    time -= TTimeIntervalSeconds(30);
    id = AddUtcAlarm(time);

    ret = TheAlarmTest.Session().SetAlarmStatusByCategory(KASCliCategoryClock, EAlarmStatusEnabled);
    TheAlarmTest(ret == KErrNone, __LINE__);

    ret = TheAlarmTest.Session().GetAlarmCountForCategory(KASCliCategoryClock);
    TheAlarmTest(ret == 2, __LINE__);

    RArray<TAlarmCategory> categories;
    TheAlarmTest.Session().GetAvailableCategoryListL(categories);
    TheAlarmTest(categories.Count() == 1, __LINE__);
    categories.Reset();

    RArray<TAlarmId> ids;
    TheAlarmTest.Session().GetAlarmIdListForCategoryL(KASCliCategoryClock, ids);
    TheAlarmTest(ids.Count() == 2, __LINE__);
    ids.Reset();

    ret = TheAlarmTest.Session().AlarmCountByState(EAlarmStateQueued);
    TheAlarmTest(ret == 2, __LINE__);

    TheAlarmTest.Session().GetAlarmIdListL(ids);
    TheAlarmTest(ids.Count() == 2, __LINE__);
    ids.Reset();

    TAlarmId nextDueId;
    ret = TheAlarmTest.Session().GetNextDueAlarmId(nextDueId);
    TheAlarmTest(ret == KErrNone && nextDueId == id, __LINE__);

    ret = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
    TheAlarmTest(ret == 2, __LINE__);

    ret = TheAlarmTest.Session().AlarmDeleteAllByCategory(KASCliCategoryClock, EFalse);
    TheAlarmTest(ret == KErrNone, __LINE__);
}
void CTest_UserPics::testUserPics()
{
	auto_ptr<HBufC8> contents( ReadContentsL( _L("c:\\unittestfiles\\buddy.mbm" ) ) );	
	auto_ptr<CBBUserPic> pic( new (ELeave) CBBUserPic() );
	_LIT(KNick, "harrihoo");
 	pic->iNick() = KNick();
 	pic->iPhoneNumberHash() = _L8("abaa");
 	pic->iMbm.Zero();
	pic->iMbm.Append(*contents);
	
	
	TTime now = GetTime();
	BBSession()->PutL( KUserPicTuple, KNick, pic.get(), now + TTimeIntervalMinutes(2) );
	
	TestUtils::WaitForActiveSchedulerStopL(1);
	
	TS_ASSERT( iUserPics->GetIconIndexL(KNick) != -1);
}
Beispiel #15
0
static void TestUtcAlarmDataFunctionalityL()
{
    TheAlarmTest.Test().Next(_L("Test alarm data functionality"));

    time.HomeTime();
    time += TTimeIntervalMinutes(1);
    id = AddUtcAlarm(time);

    _LIT8(KAlarmData, "some 8-bit data to attach to the alarm");

    ret = TheAlarmTest.Session().AlarmDataAttachL(id, KAlarmData());
    TheAlarmTest(ret == KErrNone, __LINE__);
    ret = TheAlarmTest.Session().AlarmDataSize(id);
    TheAlarmTest(ret > 0, __LINE__);

    HBufC8* temp = HBufC8::NewLC(KAlarmData().Size());
    TPtr8 pData(temp->Des());
    ret = TheAlarmTest.Session().GetAlarmData(id, pData);
    TheAlarmTest(ret == KErrNone, __LINE__);
    TheAlarmTest(pData.CompareC(KAlarmData()) == 0, __LINE__);
    CleanupStack::PopAndDestroy(temp);
}
Beispiel #16
0
static void TestAlarmFunctionalityL()
{
    TheAlarmTest.Test().Next(_L("Test alarm functionality"));

    TheAlarmTest.TestClearStoreL();

    time.HomeTime();
    time += TTimeIntervalMinutes(1);
    id = AddAlarm(time);
    TASShdAlarm alarm;
    ret = TheAlarmTest.Session().GetAlarmDetails(id, alarm);
    TheAlarmTest(ret == KErrNone, __LINE__);
    TAlarmCategory category;
    ret = TheAlarmTest.Session().GetAlarmCategory(id, category);
    TheAlarmTest(ret == KErrNone, __LINE__);
    TheAlarmTest(category == KASCliCategoryClock, __LINE__);
    ret = TheAlarmTest.Session().SetAlarmStatus(id, EAlarmStatusDisabled);
    TheAlarmTest(ret == KErrNone, __LINE__);
    TAlarmStatus status;
    ret = TheAlarmTest.Session().GetAlarmStatus(id, status);
    TheAlarmTest(ret == KErrNone, __LINE__);
    TheAlarmTest(status == EAlarmStatusDisabled, __LINE__);
}
Beispiel #17
0
TInt CSpecialLog::UpdateL(TBool aForced)
{
	if (NULL == iFs)
		return KErrNotReady;

	if (EInitializing == iState)	// No need to flush during loading.
		return KErrNone;

	iState = EUnsaved;

	TTime now;
	TTimeIntervalMinutes diff;
	now.UniversalTime();

	// Check flush interval.
	if (!aForced && (now.MinutesFrom(iTimeLastSave, diff), diff < TTimeIntervalMinutes(KSpecialLogInterval)))
		return KErrNone;

	// Update time of last save.
	iTimeLastSave = now;

	return SaveL();
}
void AppendTimeDifference(TDes8& aInto, TTime from, TTime now)
{
	CALLSTACKITEM_N(_CL("CLocaLogicImpl"), _CL("~CLocaLogicImpl"));


	if (from > now) {
		TTime s=from;
		from=now;
		now=s;
	}
	for(;;) {
		TTimeIntervalMinutes mins;
		if (now.MinutesFrom(from, mins)!=KErrNone) {
			mins=61;
		} 
		TTimeIntervalHours hours;
		if (now.HoursFrom(from, hours)!=KErrNone) {
			hours=25;
		} 
		TTimeIntervalDays days;
		days=now.DaysFrom(from);
		if (mins < TTimeIntervalMinutes(60)) {
			aInto.AppendNum(mins.Int());
			aInto.Append(_L8(" minutes "));
			break;
		} else if ( hours < TTimeIntervalDays(24)) {
			aInto.AppendNum(hours.Int());
			aInto.Append(_L8(" hours "));
			from+=TTimeIntervalHours(hours);
		} else {
			aInto.AppendNum(days.Int());
			aInto.Append(_L8(" days "));
			from+=TTimeIntervalDays(days);
		}
	}
}
Beispiel #19
0
static void as_ttime (const struct tm& p, TTime& res, TBool normalise=EFalse)
{
    TDateTime dt;
    TInt err = dt.Set(p.tm_year+1900, (enum TMonth)p.tm_mon, p.tm_mday-1,
                      p.tm_hour, p.tm_min, p.tm_sec, 0);
    if (err == KErrNone)
    {
        res = dt;
        return;
    }
    if (!normalise)
    {
        res = TInt64(-1);
        return;
    }
    // Try to normalise things (for mktime)
    dt.Set(p.tm_year+1900, EJanuary, 0, 0, 0, 0, 0);
    res = dt;
    res += TTimeIntervalMonths (p.tm_mon);
    res += TTimeIntervalDays   (p.tm_mday-1);
    res += TTimeIntervalHours  (p.tm_hour);
    res += TTimeIntervalMinutes(p.tm_min);
    res += TTimeIntervalSeconds(p.tm_sec);
}
bool base_tests(MApp_context& ctx, MOutput& aOutput, int retest)
{
	int retest_count=1;

#define RECREATE	{ CleanupStack::PopAndDestroy(); CCurrentLoc* loc=CCurrentLoc::NewL(ctx, cellid_names); CleanupStack::PushL(loc); loc->add_sinkL(l); }
#define RETEST(interval) { now+=TTimeIntervalMinutes(interval); test_time=now; if(retest==0 || retest_count==retest) { RECREATE  l->Expect(prev_e); test_time-=TTimeIntervalMinutes(interval); } ++retest_count; }

	CGenericIntMap* cellid_names=CGenericIntMap::NewL();
	CleanupStack::PushL(cellid_names);
	cellid_names->SetDeletor(delete_bufc);

	TTime test_time;

	int i;
	for (i=1; i<100; i++) {
		TBuf<10> ib;
		ib.AppendNum(i);
		cellid_names->AddDataL(i, (void*)ib.AllocL());
	}
	
	CTestLog *l=CTestLog::NewL(aOutput);
	CleanupStack::PushL(l);

	CCurrentLoc* loc=CCurrentLoc::NewL(ctx, cellid_names);
	CleanupStack::PushL(loc);

	loc->add_sinkL(l);

	now=TTime(1);

	loc->EmptyLog();

	_LIT(cell, "1, 1, T");

	CTestLog::TExpectItem prev_e;

	aOutput.Print(_L("start at a base\n"));
	prev_e=l->Expect(Mlogger::VALUE, _L("base"), _L("last: "), TTime(0));
	l->Expect(Mlogger::VALUE, _L("base"), _L("1"), now);
	loc->now_at_location(cell, 1, true, true, now);
	l->GotP();

	aOutput.Print(_L("move out\n"));
	now+=TTimeIntervalMinutes(15);
	prev_e=l->Expect(Mlogger::VALUE, _L("base"), _L("last: 1"), now);
	loc->now_at_location(cell, 2, false, true, now);
	l->GotP();
	RETEST(0)
	loc->now_at_location(cell, 2, false, true, now);
	l->GotP();

	aOutput.Print(_L("come to another non-base cell\n"));
	RETEST(1)
	loc->now_at_location(cell, 3, false, true, now);

	aOutput.Print(_L("come to a new base\n"));
	RETEST(10)
	l->Expect(Mlogger::VALUE, _L("base"), _L("4"), now);
	loc->now_at_location(cell, 4, true, true, now);
	l->GotP();
	aOutput.Print(_L("stay in base, different cell\n"));
	RETEST(1)
	loc->now_at_location(cell, 5, true, false, now);

	aOutput.Print(_L("move out\n"));
	RETEST(15)
	TTime ppprev=now;
	prev_e=l->Expect(Mlogger::VALUE, _L("base"), _L("last: 4"), test_time);
	loc->now_at_location(cell, 6, false, true, now);
	l->GotP();
	aOutput.Print(_L("move out 2\n"));
	RETEST(5)
	loc->now_at_location(cell, 7, false, true, now);

	aOutput.Print(_L("notice this cell is a base\n"));
	TTime pprev=now;
	RETEST(0)
	l->Expect(Mlogger::VALUE, _L("base"), _L("7"), now);
	loc->now_at_location(cell, 7, true, false, now);
	l->GotP();

	aOutput.Print(_L("move out\n"));
	RETEST(15)
	TTime prev=test_time;
	prev_e=l->Expect(Mlogger::VALUE, _L("base"), _L("last: 7"), test_time);
	loc->now_at_location(cell, 8, false, true, now);
	RETEST(5)
	loc->now_at_location(cell, 9, false, true, now);
	l->GotP();

	aOutput.Print(_L("come to a base\n"));
	RETEST(10)
	l->Expect(Mlogger::VALUE, _L("base"), _L("10"), now);
	loc->now_at_location(cell, 10, true, true, now);
	l->GotP();
	aOutput.Print(_L("leave quickly\n"));
	RETEST(1)
	prev_e=l->Expect(Mlogger::VALUE, _L("base"), _L("last: 7"), prev);
	loc->now_at_location(cell, 11, false, true, now);
	l->GotP();

	aOutput.Print(_L("come back to previous after long time\n"));
	RETEST(1)
	l->Expect(Mlogger::VALUE, _L("base"), _L("7"), now);
	loc->now_at_location(cell, 7, true, true, now);
	l->GotP();
	now+=TTimeIntervalMinutes(20);
	loc->now_at_location(cell, 7, true, false, now);

	aOutput.Print(_L("leave\n"));
	RETEST(30)
	pprev=test_time;
	prev_e=l->Expect(Mlogger::VALUE, _L("base"), _L("last: 7"), test_time);
	loc->now_at_location(cell, 12, false, true, now);
	l->GotP();
	aOutput.Print(_L("enter new base\n"));
	RETEST(30)
	prev=now;
	l->Expect(Mlogger::VALUE, _L("base"), _L("13"), now);
	loc->now_at_location(cell, 13, true, true, now);
	l->GotP();
	now+=TTimeIntervalMinutes(20);
	loc->now_at_location(cell, 13, true, false, now);
	aOutput.Print(_L("leave\n"));
	RETEST(10)
	prev_e=l->Expect(Mlogger::VALUE, _L("base"), _L("last: 13"), now);
	loc->now_at_location(cell, 14, false, true, now);
	l->GotP();
	aOutput.Print(_L("come back quickly\n"));
	RETEST(8)
	prev_e=l->Expect(Mlogger::VALUE, _L("base"), _L("last: 7"), pprev);
	l->Expect(Mlogger::VALUE, _L("base"), _L("13"), prev);
	loc->now_at_location(cell, 13, true, true, now);
	l->GotP();
	now+=TTimeIntervalMinutes(20);
	loc->now_at_location(cell, 13, true, false, now);
	aOutput.Print(_L("move out, to another base\n"));
	RETEST(10)
	prev_e=l->Expect(Mlogger::VALUE, _L("base"), _L("last: 13"), now);
	l->Expect(Mlogger::VALUE, _L("base"), _L("15"), now);
	loc->now_at_location(cell, 15, true, true, now);
	l->GotP();
	aOutput.Print(_L("come back quickly\n"));
	RETEST(8)
	prev_e=l->Expect(Mlogger::VALUE, _L("base"), _L("last: 7"), pprev);
	l->Expect(Mlogger::VALUE, _L("base"), _L("13"), prev);
	loc->now_at_location(cell, 13, true, true, now);
	l->GotP();

	RECREATE
	prev=now;
	now+=TTimeIntervalMinutes(30);
	l->Expect(prev_e);
	l->Expect(Mlogger::VALUE, _L("base"), _L("last: 13"), prev);
	loc->now_at_location(cell, 16, false, true, now);
	l->GotP();

	CleanupStack::PopAndDestroy(3);

	if (retest>0 && retest_count <= retest) return false;
	return true;
}
void CTestAgendaAddAppt::AddEntriesL( void )
	{
	TInt	count=1;
	if ( !GetIntFromConfig(ConfigSection(), KCount, count) )
		count=1;

	TBuf<KMaxTestExecuteCommandLength>	tempStore;
	TInt	year;
	TInt	month;
	TInt	day;
	TInt	hour;
	TInt	minute;
	TInt	duration;
	TInt	alarm;
	TPtrC	ptrAlarmSound;
	TPtrC	ptrMessage;
	TBuf<KMaxDateStringLength> dateString;
	_LIT(KDateString,"%*E%*D%X%*N%*Y %1 %2 '%3");

	RPointerArray<CCalEntry> array;
    CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &array));

	for (TInt entry=0; entry<count && TestStepResult() == EPass; )
		{
		TTime	today;
		today.HomeTime();

		tempStore.Format(KYear(), ++entry);
		if ( !GetIntFromConfig(ConfigSection(), tempStore, year) )
			year=today.DateTime().Year();

		tempStore.Format(KMonth(), entry);
		if ( !GetIntFromConfig(ConfigSection(), tempStore, month) )
			month=today.DateTime().Month();

		tempStore.Format(KDay(), entry);
		if ( !GetIntFromConfig(ConfigSection(), tempStore, day) )
			day=today.DateTime().Day();
		else
			--day;

		tempStore.Format(KHour(), entry);
		if ( !GetIntFromConfig(ConfigSection(), tempStore, hour) )
			hour=today.DateTime().Hour();

		tempStore.Format(KMinute(), entry);
		if ( !GetIntFromConfig(ConfigSection(), tempStore, minute) )
			minute=0;

		tempStore.Format(KDuration(), entry);
		if ( !GetIntFromConfig(ConfigSection(), tempStore, duration) )
			duration=30;

		tempStore.Format(KMessage(), entry);
		GetStringFromConfig(ConfigSection(), tempStore, ptrMessage);

		TTime		startTime(TDateTime(year, TMonth(month-1+EJanuary), day, hour, minute,0,0));
		startTime.FormatL(dateString,KDateString);
	  	INFO_PRINTF2(_L("Start date is  %S"), &dateString);

		TTime		endTime = startTime + TTimeIntervalMinutes(duration);
		endTime.FormatL(dateString,KDateString);
	  	INFO_PRINTF2(_L("End date is  %S"), &dateString);

		
		HBufC8* uid = HBufC8::NewLC(255);
		TPtr8 uidP = uid->Des();
		uidP.Append(count);
		
		CCalEntry* calEntry = CCalEntry::NewL(CCalEntry::EAppt, uid, CCalEntry::EMethodNone, 0);
		
		CleanupStack::Pop(); //uid
		CleanupStack::PushL(calEntry);
		
		TCalTime calStartTime, calEndTime;
		
		calStartTime.SetTimeLocalL(startTime);
		calEndTime.SetTimeLocalL(endTime);
		
		calEntry->SetStartAndEndTimeL(calStartTime, calEndTime);
		
		tempStore.Format(KAlarm(), entry);
		if ( GetIntFromConfig(ConfigSection(), tempStore, alarm) )
			{
			TTimeIntervalMinutes	currentTime((hour*60) + minute);
			TTimeIntervalMinutes	alarmTime(currentTime.Int());
			
			CCalAlarm* calAlarm = CCalAlarm::NewL();
			CleanupStack::PushL(calAlarm);
			
			calAlarm->SetTimeOffset(alarmTime);
			
			tempStore.Format(KAlarmSound(), entry);
			if ( GetStringFromConfig(ConfigSection(), tempStore, ptrAlarmSound) )
				calAlarm->SetAlarmSoundNameL(ptrAlarmSound);
			else
				calAlarm->SetAlarmSoundNameL(_L("Bells"));
			
			calEntry->SetAlarmL(calAlarm);
			CleanupStack::PopAndDestroy(); //calAlarm
			}
		//Store in the array
		array.AppendL(calEntry);
		
		CleanupStack::Pop(); //calEntry
		}
		INFO_PRINTF1(_L("About to store appointments now"));
		TInt success(0);
		TRAPD(storeError, iCalEntryViewBase->StoreL(array, success));
		INFO_PRINTF2(_L("Store result is %d"), storeError);
		if (success != count && storeError == KErrNone)
		    {
			SetTestStepResult(EFail);
		    } 
		
		CleanupStack::PopAndDestroy(&array);
		
	}
void CMtfTestActionUtilsSmsScripts::ReadSmsSettingsFromConfigurationFileL(CMtfTestCase& aTestCase, const TDesC& aSettingsFile, CSmsSettings& aSmsSettings)
	{
	CMtfTestActionUtilsConfigFileParser* scriptFileParser = CMtfTestActionUtilsConfigFileParser::NewL(aSettingsFile);
	CleanupStack::PushL(scriptFileParser);

	TPtrC stringPtr;
	TInt intValue;

	// Service Centre
	if(scriptFileParser->GetFieldAsString(KScriptItemSC, stringPtr) == KErrNone)
		{
		// get the addresses from the config file
		TLex detailsToParse(stringPtr);
		TPtrC scName;
		TPtrC scNumber;
		
		detailsToParse.SkipSpaceAndMark();
		while(!detailsToParse.Eos())
			{
			scName.Set(_L("Unknown")); // default SC name
			
			while(detailsToParse.Peek() != ';' && !detailsToParse.Eos()) // SCs' details separated by semi-colon
				{
				if(detailsToParse.Peek() == ',')  // name and number separated by comma
					{ // has a name specified
					scName.Set(detailsToParse.MarkedToken());
					detailsToParse.Inc();
					detailsToParse.SkipSpaceAndMark();
					}
				else
					detailsToParse.Inc();
				}
			
			scNumber.Set(detailsToParse.MarkedToken());
			
			// add the address to the SCs list
		
			aSmsSettings.AddServiceCenterL(scName, scNumber);
		
		
			detailsToParse.Inc();
			detailsToParse.SkipSpaceAndMark();
			}
		}
	
	// Default Service Centre
	if(scriptFileParser->GetFieldAsInteger(KScriptItemDefaultSC, intValue) == KErrNone)
		{
	
		aSmsSettings.SetDefaultServiceCenter(intValue);
	
		}
		
	// Bearer
	if(scriptFileParser->GetFieldAsString(KScriptItemBearer, stringPtr) == KErrNone)
		{
		CSmsSettings::TMobileSmsBearer smsBearer = ObtainValueParameterL<CSmsSettings::TMobileSmsBearer>(aTestCase, stringPtr);
		aSmsSettings.SetSmsBearer(smsBearer);
		}

	// Encoding
	if(scriptFileParser->GetFieldAsString(KScriptItemEncoding, stringPtr) == KErrNone)
		{
		TSmsDataCodingScheme::TSmsAlphabet characterSet = ObtainValueParameterL<TSmsDataCodingScheme::TSmsAlphabet>(aTestCase, stringPtr);
		aSmsSettings.SetCharacterSet(characterSet);
		}
		
	// Delivery Report
	if(scriptFileParser->GetFieldAsString(KScriptItemDeliveryReport, stringPtr) == KErrNone)
		{
		if (stringPtr.CompareF(_L("NO")) == 0)
			{
			aSmsSettings.SetDeliveryReport(EFalse);
			}
		else if (stringPtr.CompareF(_L("YES")) == 0)
			{
			aSmsSettings.SetDeliveryReport(ETrue);
			}
		}
		
	// Reply quoted
	if(scriptFileParser->GetFieldAsString(KScriptItemReplyQuoted, stringPtr) == KErrNone)
		{
		if (stringPtr.CompareF(_L("NO")) == 0)
			{
			aSmsSettings.SetReplyQuoted(EFalse);
			}
		else if (stringPtr.CompareF(_L("YES")) == 0)
			{
			aSmsSettings.SetReplyQuoted(ETrue);
			}
		}
	
	// Description length
	if(scriptFileParser->GetFieldAsInteger(KScriptItemDescriptionLength, intValue) == KErrNone)
		{
		aSmsSettings.SetDescriptionLength(intValue);
		}
		
		
	// Can Concatenate
	if(scriptFileParser->GetFieldAsString(KScriptItemCanConcatenate, stringPtr) == KErrNone)
		{
		if (stringPtr.CompareF(_L("NO")) == 0)
			{
			aSmsSettings.SetCanConcatenate(EFalse);
			}
		else if (stringPtr.CompareF(_L("YES")) == 0)
			{
			aSmsSettings.SetCanConcatenate(ETrue);
			}
		}
	
	// Reply path
	if(scriptFileParser->GetFieldAsString(KScriptItemReplyPath, stringPtr) == KErrNone)
		{
		if (stringPtr.CompareF(_L("NO")) == 0)
			{
			aSmsSettings.SetReplyPath(EFalse);
			}
		else if (stringPtr.CompareF(_L("YES")) == 0)
			{
			aSmsSettings.SetReplyPath(ETrue);
			}
		}
		
	// Reject duplicate
	if(scriptFileParser->GetFieldAsString(KScriptItemRejectDuplicate, stringPtr) == KErrNone)
		{
		if (stringPtr.CompareF(_L("NO")) == 0)
			{
			aSmsSettings.SetRejectDuplicate(EFalse);
			}
		else if (stringPtr.CompareF(_L("YES")) == 0)
			{
			aSmsSettings.SetRejectDuplicate(ETrue);
			}
		}
		
	// Validity period, value is read in minutes
	if(scriptFileParser->GetFieldAsInteger(KScriptItemValidityPeriod, intValue) == KErrNone)
		{
		aSmsSettings.SetValidityPeriod(TTimeIntervalMinutes(intValue));
		}
		
	// Delivery
	if(scriptFileParser->GetFieldAsString(KScriptItemDelivery, stringPtr) == KErrNone)
		{
		TSmsDelivery delivery = ObtainValueParameterL<TSmsDelivery>(aTestCase, stringPtr);
		aSmsSettings.SetDelivery(delivery);
		}
	
	// Status Report Handling
	if(scriptFileParser->GetFieldAsString(KScriptItemStatusReportHandling, stringPtr) == KErrNone)
		{
		CSmsSettings::TSmsReportHandling statusReportHandling = ObtainValueParameterL<CSmsSettings::TSmsReportHandling>(aTestCase, stringPtr);
		aSmsSettings.SetStatusReportHandling(statusReportHandling);
		}

	// Special Message Handling
	if(scriptFileParser->GetFieldAsString(KScriptItemSpecialMessageHandling, stringPtr) == KErrNone)
		{
		CSmsSettings::TSmsReportHandling specialMessageHandling = ObtainValueParameterL<CSmsSettings::TSmsReportHandling>(aTestCase, stringPtr);
		aSmsSettings.SetSpecialMessageHandling(specialMessageHandling);
		}

	// Commdb action
	if(scriptFileParser->GetFieldAsString(KScriptItemSmsCommdbAction, stringPtr) == KErrNone)
		{
		CSmsSettings::TSmsSettingsCommDbAction commdbAction = ObtainValueParameterL<CSmsSettings::TSmsSettingsCommDbAction>(aTestCase, stringPtr);
		aSmsSettings.SetCommDbAction(commdbAction);
		}
		
	// Sms Bearer Action
	if(scriptFileParser->GetFieldAsString(KScriptItemSmsBearerAction, stringPtr) == KErrNone)
		{
		CSmsSettings::TSmsSettingsCommDbAction smsBearerAction = ObtainValueParameterL<CSmsSettings::TSmsSettingsCommDbAction>(aTestCase, stringPtr);
		aSmsSettings.SetSmsBearerAction(smsBearerAction);
		}

	// Message Conversion
	if(scriptFileParser->GetFieldAsString(KScriptItemSmsMessageConversion, stringPtr) == KErrNone)
		{
		TSmsPIDConversion messageConversion = ObtainValueParameterL<TSmsPIDConversion>(aTestCase, stringPtr);
		aSmsSettings.SetMessageConversion(messageConversion);
		}
	
	// Vailidity Period Format
	if(scriptFileParser->GetFieldAsString(KScriptItemSmsValidityPeriodFormat, stringPtr) == KErrNone)
		{
		TSmsFirstOctet::TSmsValidityPeriodFormat valPeriodFormat = ObtainValueParameterL<TSmsFirstOctet::TSmsValidityPeriodFormat>(aTestCase, stringPtr);
		aSmsSettings.SetValidityPeriodFormat(valPeriodFormat);
		}
	
	// Class2 Folder
	if(scriptFileParser->GetFieldAsString(KScriptItemClass2Folder, stringPtr) == KErrNone)
		{
		// Try to find a folder with that name
		MDummySessionObserver obser;
		CMsvSession* session = CMsvSession::OpenSyncL(obser);
		CleanupStack::PushL(session);
		
		CMsvEntry* entry = CMsvEntry::NewL(*session, KMsvLocalServiceIndexEntryId, TMsvSelectionOrdering(KMsvGroupByStandardFolders||KMsvGroupByType,EMsvSortByNone));
		CleanupStack::PushL(entry);
		entry->SetEntryL(KMsvLocalServiceIndexEntryId); // Search only the local folders

		TMsvSelectionOrdering order;
		order.SetShowInvisibleEntries(ETrue);
		entry->SetSortTypeL(order);

		CMsvEntrySelection* selection = entry->ChildrenL();
		CleanupStack::PushL(selection);

		TBool found = EFalse;
		TInt count = selection->Count();
		for (TInt i=0; i<count; i++) 
			{	
			entry->SetEntryL((*selection)[i]);
			if ((stringPtr.CompareF(entry->Entry().iDescription) == 0) ||
			    (stringPtr.CompareF(entry->Entry().iDetails) == 0))
				{
				found = ETrue;
				break;
				}
			}

		TMsvId entryId = KMsvGlobalInBoxIndexEntryId;
		if (found)
			entryId = entry->Entry().Id();
		else
			User::Leave(KErrNotFound);

		aSmsSettings.SetClass2Folder(entryId); 
		
		CleanupStack::PopAndDestroy(3, session); // selection, entry, session
		}

	//Last Segment Delivery Report
	if(scriptFileParser->GetFieldAsString(KLastSegmentDeliveryReport, stringPtr) == KErrNone)
		{
		if (stringPtr.CompareF(_L("NO")) == 0)
			{
			aSmsSettings.SetLastSegmentDeliveryReport(EFalse);
			}
		else if (stringPtr.CompareF(_L("YES")) == 0)
			{
			aSmsSettings.SetLastSegmentDeliveryReport(ETrue);
			}
		}
	
	CleanupStack::PopAndDestroy(scriptFileParser);
	}
void CCalAlarmAttachTest::TestDeleteAlarmL()
	{
	
	CCalEntryView &view = iTestLib->SynCGetEntryViewL() ;
	CCalEntryView *calentryview = &view ;
	
	TInt num ;	

	ClearAllAlarmsL() ;	
	
	test.Printf(_L("Going to check deletion of non-snoozed alarms\n")) ;
	
	/* create repeating parent entry	*/

	HBufC8* guid = KGUID3().AllocLC(); // ownership of guid gets transferred
 	CCalEntry *entry = CCalEntry::NewL(CCalEntry::ETodo, guid, CCalEntry::EMethodNone, 0) ;
	CleanupStack::Pop(guid);	
	CleanupStack::PushL(entry) ;
	
	TTime now1;
	now1.UniversalTime();
	now1 += TTimeIntervalSeconds(30);

	TCalTime startTime ;
	TCalTime endTime ;	
	startTime.SetTimeUtcL(now1) ;
	endTime.SetTimeUtcL(now1 + TTimeIntervalSeconds(30)) ;
			
	entry->SetStartAndEndTimeL(startTime, endTime) ;

	TCalRRule rrule(TCalRRule::EDaily) ;
	rrule.SetDtStart(startTime);
	
	TCalTime endRTime ;		
	endRTime.SetTimeUtcL(now1 + TTimeIntervalDays(7)) ;	
	rrule.SetUntil(endRTime);
	rrule.SetInterval(1);	
	entry->SetRRuleL(rrule) ;

	CCalAlarm *alarm = CCalAlarm::NewL() ;
	CleanupStack::PushL(alarm) ;			
	alarm->SetTimeOffset(TTimeIntervalMinutes(0)) ;
	entry->SetAlarmL(alarm) ; //ownership does not get transferred
	
	RPointerArray<CCalEntry> entryarr ;		
	entryarr.AppendL(entry) ; //ownership does not got transferred			
	calentryview->StoreL(entryarr, num) ;
	entryarr.Close() ;		
		
	CleanupStack::PopAndDestroy(alarm) ;	
	CleanupStack::PopAndDestroy(entry) ;	
	
	/* Now let the alarm go off */
	
	RArray< TAlarmId > alarmIdArr ;
	
	iAlarmServer.GetAlarmIdListL(alarmIdArr) ;
	
	TInt cnt = alarmIdArr.Count() ;
	
	test(cnt > 0) ;
	
	TRequestStatus status = 0;
	TAlarmId alarmId = alarmIdArr[0];
	
	alarmIdArr.Close() ;
	
	test.Printf(_L("Waiting one minute for the alarm to go off...\n")) ;
	
	for(;;)
		{
		iAlarmServer.NotifyChange(status, alarmId);
		User::WaitForRequest(status);
		
		PrintEventDetails(status.Int());
		
		if	(status.Int() == EAlarmChangeEventTimerExpired)
			{			
			break; // alarm expired
			}
		}

	/* delete this entry - without snoozing */

	RPointerArray< CCalEntry > calEntryArray ;
	calentryview->FetchL(KGUID3(), calEntryArray) ;
	
	test(calEntryArray.Count() == 1) ;
	
	CCalEntry *entry1 = calEntryArray[0] ;		
	
	entry1->SetCompletedL(ETrue, startTime) ;
		
	calentryview->StoreL(calEntryArray, num) ;
	
	delete entry1 ;	
	calEntryArray.Close() ;
	
	/* now check if the alarm still exists or not */
	
	RArray< TAlarmId > alarmIdArr1 ;
	
	iAlarmServer.GetAlarmIdListL(alarmIdArr1) ;
	
	TInt cnt1 = alarmIdArr1.Count() ;
	
	test(cnt1 < cnt) ;		
	
	if (cnt1 > 0)
		{
		TAlarmId alarmId1 = alarmIdArr1[0];	
		test(alarmId != alarmId1) ;
		}			
	
	alarmIdArr1.Close() ;	
	
	ClearAllAlarmsL() ;
	
	test.Printf(_L("Checking of non snoozed alarms successful\n")) ;
	
	}
void GetCurrentStateAndTimeL(TBool& aIsError,
	MNetworkErrorObserver::TErrorDisplay& aMode, TDes& aMessageInto,
	TInt& aWaitSecondsForNext)
{
	MSettings& sett=GetContext()->Settings();
	TTime tried_since=TTime(0);
	TTime last_request=TTime(0), latest_request=TTime(0);
	TTime success=TTime(0);
	TBool enabled=ETrue;
	aWaitSecondsForNext=0;

	sett.GetSettingL(SETTING_LAST_CONNECTION_SUCCESS, success);
	sett.GetSettingL(SETTING_LAST_CONNECTION_ATTEMPT, tried_since);
	sett.GetSettingL(SETTING_LAST_CONNECTION_REQUEST, last_request);
	sett.GetSettingL(SETTING_LATEST_CONNECTION_REQUEST, latest_request);
	sett.GetSettingL(SETTING_PRESENCE_ENABLE, enabled);
#ifdef DEBUG_NWERROR
	MReporting& rep=GetContext()->Reporting();
	{
		TInt prints[] = { SETTING_LAST_CONNECTION_SUCCESS, SETTING_LAST_CONNECTION_ATTEMPT,
			SETTING_LAST_CONNECTION_REQUEST, SETTING_LATEST_CONNECTION_REQUEST,
			SETTING_PRESENCE_ENABLE, -1 };
		rep.UserErrorLog(_L("DEBUG_NWERROR"));
		TBuf<40> msg;
		for (TInt* p=prints; *p>0; p++) {
			msg.Zero(); msg=_L("SETT: ");
			msg.AppendNum(*p);
			rep.UserErrorLog(msg);
			msg.Zero();
			if (sett.GetSettingL(*p, msg)) {
				rep.UserErrorLog(msg);
			} else {
				rep.UserErrorLog(_L("not set"));
			}
		}
	}
#endif
	
	if (!enabled) {
		aIsError=EFalse;
		aMessageInto.Zero();
		aWaitSecondsForNext=0;
		return;
	}
	
	TTime now=GetTime();
	TTimeIntervalSeconds allowed_after_request(70);
	
	aMode=MNetworkErrorObserver::EAmbient;
	if ( success==TTime(0) && last_request!=TTime(0) && last_request + allowed_after_request < now ) {
		aIsError=ETrue;
		aMode=MNetworkErrorObserver::EIntrusive;
	} else if ( last_request + allowed_after_request < now && last_request!=TTime(0) && 
			latest_request!=TTime(0) && success < latest_request 
			&& success + TTimeIntervalMinutes(5) < now ) {
		aIsError=ETrue;
	} else if ( tried_since!=TTime(0) && tried_since +TTimeIntervalMinutes(30) < now ) {
		aIsError=ETrue;
	} else {
		aIsError=EFalse;
	}

	TTimeIntervalSeconds wait; TBool do_wait=EFalse;
	
	if ( (success==TTime(0) || success < last_request) && 
			last_request!=TTime(0) && last_request + allowed_after_request > now ) {
		now.SecondsFrom( last_request + allowed_after_request, wait);
		do_wait=ETrue;
	} else if ( success < latest_request && success + TTimeIntervalMinutes(5) > now ) {
		now.SecondsFrom( success + TTimeIntervalMinutes(5), wait);
		do_wait=ETrue;
	} else if ( tried_since!=TTime(0) && tried_since + TTimeIntervalMinutes(30) < now ) {
		now.SecondsFrom( tried_since + TTimeIntervalMinutes(30), wait);
		do_wait=ETrue;
	}
	if (do_wait) {
		aWaitSecondsForNext=wait.Int();
		// can't be bothered to test which way the SecondsFrom goes
		if (aWaitSecondsForNext<0) aWaitSecondsForNext*=-1;
		if (aWaitSecondsForNext==0) aWaitSecondsForNext=1;
	} else {
		aWaitSecondsForNext=0;
	}
	
#ifdef DEBUG_NWERROR
	{
		TBuf<100> msg=_L("RES: ");
		if (aIsError) msg.Append(_L(" ERR "));
		else msg.Append(_L(" NOERR "));
		msg.Append(_L(" WAIT "));
		msg.AppendNum(aWaitSecondsForNext);
		rep.UserErrorLog(msg);
	}
#endif	

	if (aIsError) {
		aMessageInto.Zero();
		sett.GetSettingL(SETTING_LAST_CONNECTION_ERROR, aMessageInto);
		if (aMessageInto.Length()==0) {
			aMessageInto=_L("Cannot connect to Jaiku");
		}
	}
}