commonappservices/alarmserver/Test/TAlarmInfo.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 1997-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 "ASTstAlarmTest.h"
       
    17 
       
    18 // System includes
       
    19 #include <asclisoundplay.h>
       
    20 
       
    21 // Constants
       
    22 
       
    23 // Type definitions
       
    24 typedef CArrayFixFlat<TASCliSoundPlayDefinition> CPlayIntervalArray;
       
    25 
       
    26 // This define appears in ASSrvSoundSettings.cpp (KAlarmCycleStartOffsetMinutes)
       
    27 // update it if it changes there!
       
    28 #define KDefaultAlarmCycleStartOffsetMinutes	{0,1,2,3,5,10,20,30,45,60,90,120,180,240,KErrNotFound};
       
    29 #define KNewAlarmCycleStartOffsetMinutes		{0,10,20,30,50,100,200,300,450,600,900,1200,1800,2400, 3000, 4000, 5000, 10000,KErrNotFound};
       
    30 
       
    31 static void testPrintAlarmL()
       
    32 //
       
    33 //	Print details about alarm
       
    34 //
       
    35 	{
       
    36 	
       
    37 	TheAlarmTest.Test().Next(_L("Test printing details about alarms"));
       
    38 	TInt num;
       
    39 	//
       
    40 	num = TheAlarmTest.CountOrphanedAlarmsL();
       
    41 	TheAlarmTest.Test().Printf(_L("\tThe number of orphan alarms is %d\n"), num);
       
    42 	//
       
    43 	num = TheAlarmTest.Session().AlarmCountByState(EAlarmStateNotified);
       
    44 	TheAlarmTest.Test().Printf(_L("\tThe number of review alarms is %d\n"), num);
       
    45 	//
       
    46 	num = TheAlarmTest.Session().AlarmCountByState(EAlarmStateWaitingToNotify);
       
    47 	TheAlarmTest.Test().Printf(_L("\tThe number of unacknowledged alarms is %d\n"),num);
       
    48 	//
       
    49 	num = TheAlarmTest.Session().NumberOfAlarmsActiveInQueue();
       
    50 	TheAlarmTest.Test().Printf(_L("\tThe number of next alarms is %d\n"),num);
       
    51 	//
       
    52 	
       
    53 	
       
    54 	TheAlarmTest.Test().Next(_L("Clearing all alarms"));
       
    55 	TheAlarmTest.TestClearStoreL();
       
    56 	}
       
    57 
       
    58 static void resetSoundArrayToDefaultValuesL()
       
    59 	{
       
    60 	// Initialise sound array with default values
       
    61 	CPlayIntervalArray* array = new(ELeave) CPlayIntervalArray(20);
       
    62 	CleanupStack::PushL(array);
       
    63 
       
    64 	// Populate the new array to replace the default
       
    65 	const TInt minuteCycle[]=KDefaultAlarmCycleStartOffsetMinutes;
       
    66 	TInt i = 0;
       
    67 	TInt offset = minuteCycle[i];
       
    68 	while (offset != KErrNotFound)
       
    69 		{
       
    70 		const TASCliSoundPlayDefinition item(offset, KDefaultSoundPlayDurationInSeconds);
       
    71 		array->AppendL(item);
       
    72 		offset = minuteCycle[++i];
       
    73 		}
       
    74 
       
    75 	// Try setting the sound details
       
    76 	TheAlarmTest.Session().SetAlarmPlayIntervalsL(*array);
       
    77 
       
    78 	CleanupStack::PopAndDestroy(array);
       
    79 	}
       
    80 
       
    81 
       
    82 static void testDefaultSoundInfoL()
       
    83 //
       
    84 //	Get default sound info details
       
    85 //
       
    86 	{
       
    87 	TheAlarmTest.Test().Next(_L("Test the default sound play intervals"));
       
    88 	// When the server is started, the alarm sound intervals should currently be
       
    89 	// set to their defaults defined in KDefaultAlarmCycleStartOffsetMinutes
       
    90 
       
    91 	// Initialise sound array with default values
       
    92 	CPlayIntervalArray* array = new(ELeave) CPlayIntervalArray(20);
       
    93 	CleanupStack::PushL(array);
       
    94 
       
    95 	// Get default sound intervals
       
    96 	TheAlarmTest.Session().GetAlarmPlayIntervalsL(*array);
       
    97 
       
    98 	// Check that the default values are correct
       
    99 	const TInt minuteCycle[]=KDefaultAlarmCycleStartOffsetMinutes;
       
   100 	TInt i = 0;
       
   101 	TInt offset = minuteCycle[i];
       
   102 	while (offset != KErrNotFound)
       
   103 		{
       
   104 		const TASCliSoundPlayDefinition& item = array->At(i);
       
   105 		TheAlarmTest(item.Offset().Int() == offset, __LINE__);
       
   106 		TheAlarmTest(item.Duration().Int() == KDefaultSoundPlayDurationInSeconds, __LINE__);
       
   107 		offset = minuteCycle[++i];
       
   108 		}
       
   109 	CleanupStack::PopAndDestroy(array);
       
   110 	}
       
   111 
       
   112 
       
   113 static void testSettingSoundInfoL()
       
   114 //
       
   115 //	Get and set the sound info details
       
   116 //
       
   117 	{
       
   118 	TheAlarmTest.Test().Next(_L("Test setting the sound play intervals"));
       
   119 	// When the server is started, the alarm sound intervals should currently be
       
   120 	// set to their defaults defined in KDefaultAlarmCycleStartOffsetMinutes
       
   121 
       
   122 	// Initialise sound array with default values
       
   123 	CPlayIntervalArray* array = new(ELeave) CPlayIntervalArray(20);
       
   124 	CleanupStack::PushL(array);
       
   125 
       
   126 	// Populate the new array to replace the default
       
   127 	const TInt minuteCycle[]=KNewAlarmCycleStartOffsetMinutes;
       
   128 	TInt i = 0;
       
   129 	TInt offset = minuteCycle[i];
       
   130 	while (offset != KErrNotFound)
       
   131 		{
       
   132 		const TASCliSoundPlayDefinition item(offset, KDefaultSoundPlayDurationInSeconds);
       
   133 		array->AppendL(item);
       
   134 		offset = minuteCycle[++i];
       
   135 		}
       
   136 
       
   137 	// Try setting the sound details
       
   138 	TheAlarmTest.Session().SetAlarmPlayIntervalsL(*array);
       
   139 
       
   140 	// Fetch the details back again.
       
   141 	CPlayIntervalArray* array2 = new(ELeave) CPlayIntervalArray(20);
       
   142 	CleanupStack::PushL(array2);
       
   143 	TheAlarmTest.Session().GetAlarmPlayIntervalsL(*array2);
       
   144 
       
   145 	// Test that there are the same number of entries
       
   146 	TheAlarmTest(array->Count() == array2->Count(), __LINE__);
       
   147 
       
   148 	// Test entries are the same
       
   149 	TInt count = array->Count();
       
   150 	for(TInt j=0; j<count; j++)
       
   151 		{
       
   152 		const TASCliSoundPlayDefinition& item = array->At(j);
       
   153 		const TASCliSoundPlayDefinition& item2 = array2->At(j);
       
   154 		TheAlarmTest(item.Offset().Int() == item2.Offset().Int(), __LINE__);
       
   155 		TheAlarmTest(item.Duration().Int() == item2.Duration().Int(), __LINE__);
       
   156 		}
       
   157 
       
   158 	CleanupStack::PopAndDestroy(2);
       
   159 	}
       
   160 
       
   161 
       
   162 static void testSettingSoundInfoBadValuesL()
       
   163 //
       
   164 //	Attempt to set the sound interval array to invalid values.
       
   165 //
       
   166 	{
       
   167 	TheAlarmTest.Test().Next(_L("Test setting sound play intervals to invalid values"));
       
   168 
       
   169 	// Initialise sound array with default values
       
   170 	CPlayIntervalArray* array = new(ELeave) CPlayIntervalArray(20);
       
   171 	CleanupStack::PushL(array);
       
   172 
       
   173 	// Try setting the sound details to an empty array
       
   174 	TRAPD(err, TheAlarmTest.Session().SetAlarmPlayIntervalsL(*array));
       
   175 	TheAlarmTest(err == KErrArgument, __LINE__);
       
   176 
       
   177 	// Try setting the sound intervals to an array which doesn't contain an entry
       
   178 	// with an offset of zero
       
   179 	const TASCliSoundPlayDefinition item(1, KDefaultSoundPlayDurationInSeconds); // offset of 1 min
       
   180 	array->AppendL(item);
       
   181 	TRAP(err, TheAlarmTest.Session().SetAlarmPlayIntervalsL(*array));
       
   182 	TheAlarmTest(err == KErrArgument, __LINE__);
       
   183 	CleanupStack::PopAndDestroy(array);
       
   184 	}
       
   185 	
       
   186 /**
       
   187 @SYMTestCaseID PIM-TALARMINFO-0001
       
   188 */
       
   189 static void doTestsL()
       
   190 	{
       
   191 
       
   192 	TheAlarmTest.Start(_L("@SYMTestCaseID PIM-TALARMINFO-0001 Connecting to server"));
       
   193 
       
   194 	const TInt KGmtOffset = 3600;
       
   195 	_LIT(KTime, "20040730:050000.000000"); //Summertime
       
   196 	TInt err = User::SetUTCTimeAndOffset(TTime(KTime), KGmtOffset);
       
   197 	TheAlarmTest(err == KErrNone, __LINE__);
       
   198 
       
   199 	const TInt r = TheAlarmTest.Session().Connect();
       
   200 	TheAlarmTest(r == KErrNone, __LINE__);
       
   201 
       
   202 	testPrintAlarmL();
       
   203 	testDefaultSoundInfoL();
       
   204 	testSettingSoundInfoL();
       
   205 	testSettingSoundInfoBadValuesL();
       
   206 
       
   207 	resetSoundArrayToDefaultValuesL();
       
   208 	TheAlarmTest.TestClearStoreL();
       
   209 
       
   210 	TheAlarmTest.EndL();
       
   211 	}
       
   212 
       
   213 
       
   214 GLDEF_C TInt E32Main()
       
   215 //
       
   216 // Test the alarm server.
       
   217 //
       
   218     {
       
   219 	__UHEAP_MARK;
       
   220 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   221 	if	(!cleanup)
       
   222 		return KErrNoMemory;
       
   223 
       
   224 	TheAlarmTest.Title();
       
   225 	TheAlarmTest.TestStartServers();
       
   226 	//
       
   227 	TRAPD(error, doTestsL());
       
   228 	TheAlarmTest(error == KErrNone, __LINE__);
       
   229 	TheAlarmTest.Session().Close();
       
   230 	TheAlarmTest.Test().Close();
       
   231 	ASTstAlarmTest::Close();
       
   232 
       
   233 	delete cleanup;
       
   234 	__UHEAP_MARKEND;
       
   235 	return KErrNone;
       
   236     }