commonappservices/alarmserver/Test/unit/src/TEAlarmTestSilentUntilStep.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 //
       
    15 
       
    16 #include "TEAlarmTestSilentUntilStep.h"
       
    17 
       
    18 #include <asclisession.h>
       
    19 
       
    20 _LIT(KSilentUntil, "SilentUntil");
       
    21 _LIT(KInitialTime, "InitialTime");
       
    22 _LIT(KInvalidates, "Invalidates");
       
    23 
       
    24 CTEAlarmTestSilentUntilStep::~CTEAlarmTestSilentUntilStep()
       
    25 	{
       
    26 	}
       
    27 	
       
    28 CTEAlarmTestSilentUntilStep::CTEAlarmTestSilentUntilStep()
       
    29 	{
       
    30 	// MANDATORY Call to base class method to set up the human readable name for logging.
       
    31 	SetTestStepName(KTEAlarmTestSilentUntilStep);
       
    32 	}
       
    33 	
       
    34 TVerdict CTEAlarmTestSilentUntilStep::doTestStepPreambleL()
       
    35 	{
       
    36 	SetTestStepResult(EFail);
       
    37 	
       
    38 	TVerdict verdict = CTEAlarmTestSilentStep::doTestStepPreambleL();
       
    39 	
       
    40 	if(verdict != EPass)
       
    41 		{
       
    42 		SetTestStepResult(verdict);
       
    43 		return TestStepResult();
       
    44 		}
       
    45 		
       
    46 	if(!GetTimeFromConfig(ConfigSection(), KSilentUntil, iSilentUntil)) 
       
    47 		{
       
    48 		SetTestStepResult(ETestSuiteError);
       
    49 		return TestStepResult();
       
    50 		}
       
    51 		
       
    52 	if(!GetTimeFromConfig(ConfigSection(), KInitialTime, iInitialTime))
       
    53 		{
       
    54 		SetTestStepResult(ETestSuiteError);
       
    55 		return TestStepResult();
       
    56 		}
       
    57 	
       
    58 	if(!GetBoolFromConfig(ConfigSection(), KInvalidates, iInvalidated))
       
    59 		{
       
    60 		SetTestStepResult(ETestSuiteError);
       
    61 		return TestStepResult();
       
    62 		}
       
    63 	
       
    64 	SetTestStepResult(EPass);
       
    65 	return TestStepResult();
       
    66 	}
       
    67 
       
    68 TVerdict CTEAlarmTestSilentUntilStep::doTestStepL()
       
    69 	{
       
    70 	if(TestStepResult() != EPass)
       
    71 		{
       
    72 		return TestStepResult();
       
    73 		}
       
    74 	
       
    75 	SetTestStepResult(EFail);
       
    76 	
       
    77 	INFO_PRINTF2(_L("Initial UTC Offset: %d s"), iInitialUTC.Int());
       
    78 		
       
    79 	User::SetUTCOffset(iInitialUTC);
       
    80 	
       
    81 	TBuf<10> buf;
       
    82 	
       
    83 	iInitialTime.FormatL(buf, _L("%H:%T:%S"));
       
    84 	INFO_PRINTF2(_L("Initial UTC Time: %s"), buf.PtrZ());
       
    85 	
       
    86 	TTime oldTime;
       
    87 	oldTime.UniversalTime();
       
    88 	
       
    89 	User::SetUTCTime(iInitialTime);
       
    90 		
       
    91 	RASCliSession session;
       
    92 	
       
    93 	User::LeaveIfError(session.Connect());
       
    94 	CleanupClosePushL(session);
       
    95 	
       
    96 	iSilentUntil.FormatL(buf, _L("%H:%T:%S"));
       
    97 	INFO_PRINTF2(_L("Setting Alarm Sounds Silent Until: %s"), buf.PtrZ());
       
    98 
       
    99 	User::LeaveIfError(session.SetAlarmSoundsSilentUntil(iSilentUntil));
       
   100 	
       
   101 	if (!CheckSilentUntilL(session)) 
       
   102 		{
       
   103 		goto ret;
       
   104 		}
       
   105 
       
   106 	INFO_PRINTF2(_L("Updating UTC Offset: %d s"), iMoveToUTC.Int());	
       
   107 	User::SetUTCOffset(iMoveToUTC);
       
   108 	
       
   109 	// Let the Alarm Server react to the UTC change
       
   110 	User::After(1000000);
       
   111 	
       
   112 	if (!CheckSilentUntilL(session)) 
       
   113 		{
       
   114 		goto ret;
       
   115 		}
       
   116 		
       
   117 	SetTestStepResult(EPass);
       
   118 	
       
   119 	ret:
       
   120 	User::SetUTCTime(oldTime);
       
   121 	CleanupStack::PopAndDestroy();
       
   122 	return TestStepResult();			
       
   123 	}
       
   124 	
       
   125 TVerdict CTEAlarmTestSilentUntilStep::doTestStepPostambleL()
       
   126 	{
       
   127 	SetTestStepResult(CTEAlarmTestSilentStep::doTestStepPostambleL());
       
   128 	return TestStepResult();
       
   129 	}
       
   130 
       
   131 TBool CTEAlarmTestSilentUntilStep::CheckSilentUntilL(const RASCliSession &aSession)
       
   132 	{
       
   133 	TTime getSilentUntil;
       
   134 	TInt ret = aSession.GetAlarmSoundsSilentUntil(getSilentUntil);
       
   135 	
       
   136 	TTime now;
       
   137 	now.HomeTime();
       
   138 	
       
   139 	if ((ret == KErrGeneral) &&
       
   140 		iInvalidated) // UTC offset change invalidates silent period.
       
   141 		{
       
   142 		return ETrue;
       
   143 		}
       
   144 	
       
   145 	User::LeaveIfError(ret);
       
   146 	
       
   147 	TBuf<10> buf;
       
   148 	iSilentUntil.FormatL(buf, _L("%H:%T:%S"));	
       
   149 	
       
   150 	if (iSilentUntil != getSilentUntil)
       
   151 		{
       
   152 		INFO_PRINTF1(_L("SetAlarmSoundsSilentUntil and GetAlarmSoundsSilentUntil doesn't match!"));
       
   153 		INFO_PRINTF2(_L("SetAlarmsSilentUntil: %s"), buf.PtrZ());
       
   154 
       
   155 		getSilentUntil.FormatL(buf, _L("%H:%T:%S"));		
       
   156 		INFO_PRINTF2(_L("GetAlarmsSilentUntil: %s"), buf.PtrZ());
       
   157 		
       
   158 		return EFalse;
       
   159 		}
       
   160 	
       
   161 	INFO_PRINTF1(_L("SetAlarmSoundsSilentUntil and GetAlarmSoundsSilentUntil matches"));	
       
   162 	INFO_PRINTF2(_L("SetAlarmsSilentUntil: %s"), buf.PtrZ());
       
   163 	
       
   164 	getSilentUntil.FormatL(buf, _L("%H:%T:%S"));		
       
   165 	INFO_PRINTF2(_L("GetAlarmsSilentUntil: %s"), buf.PtrZ());
       
   166 		
       
   167 	return ETrue;
       
   168 	}