|
1 // Copyright (c) 1999-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 // System includes |
|
17 #include <e32base.h> |
|
18 #include <e32test.h> |
|
19 #include <f32file.h> |
|
20 |
|
21 // User includes |
|
22 #include "TServerSessionEngine.h" |
|
23 |
|
24 // Literal constants |
|
25 _LIT(KTest, "server session engine test"); |
|
26 |
|
27 // Constants |
|
28 const TAlarmCategory KASCliCategoryTest = { 0x101F5031 }; |
|
29 |
|
30 // Globals |
|
31 static RTest TheTest(KTest); |
|
32 |
|
33 |
|
34 void Test1L(CTestServerSessionEngine* aSessionEngine) |
|
35 { |
|
36 TheTest.Next(_L("Test 1")); |
|
37 //****************************************************************************** |
|
38 // Test1 tests |
|
39 // |
|
40 // AlarmAddL |
|
41 // AlarmDeleteL |
|
42 // AlarmCountByCategory |
|
43 // AlarmCountByState |
|
44 // AlarmIdListByStateLC |
|
45 //****************************************************************************** |
|
46 aSessionEngine->ClearAlarmStoreL(); |
|
47 |
|
48 RArray<TAlarmId> alarmIds; |
|
49 CleanupClosePushL(alarmIds); |
|
50 |
|
51 //add 10 alarms (category KASCliCategoryClock) |
|
52 for(TInt ii=1; ii<=10; ii++) |
|
53 { |
|
54 TInt secondsFromNow = (ii)*2; |
|
55 TAlarmId id = aSessionEngine->AddAlarmWithSpecificTimeL(secondsFromNow); |
|
56 alarmIds.AppendL(id); |
|
57 |
|
58 TInt numberOfAlarms = aSessionEngine->Engine().AlarmCountByCategory(KASCliCategoryClock); |
|
59 TheTest(numberOfAlarms == ii, __LINE__); |
|
60 } |
|
61 |
|
62 //check states of alarms |
|
63 TInt alarmCount=0; |
|
64 //states should be: |
|
65 // 10 x EAlarmStateQueued |
|
66 alarmCount = aSessionEngine->Engine().AlarmCountByState(EAlarmStateQueued); |
|
67 TheTest(alarmCount == 10, __LINE__); |
|
68 |
|
69 //wait for alarm to expire |
|
70 aSessionEngine->AwaitNotificationL(); |
|
71 CActiveScheduler::Start(); |
|
72 //states should be: |
|
73 // 1 x EAlarmStateNotifying |
|
74 // 9 x EAlarmStateQueued |
|
75 alarmCount = aSessionEngine->Engine().AlarmCountByState(EAlarmStateNotifying); |
|
76 TheTest(alarmCount == 1, __LINE__); |
|
77 alarmCount = aSessionEngine->Engine().AlarmCountByState(EAlarmStateQueued); |
|
78 TheTest(alarmCount == 9, __LINE__); |
|
79 |
|
80 //wait for another alarm to expire |
|
81 CActiveScheduler::Start(); |
|
82 //states should be: |
|
83 // 1 x EAlarmStateNotifying |
|
84 // 1 x EAlarmStateWaitingToNotify |
|
85 // 8 x EAlarmStateQueued |
|
86 alarmCount = aSessionEngine->Engine().AlarmCountByState(EAlarmStateNotifying); |
|
87 TheTest(alarmCount == 1, __LINE__); |
|
88 alarmCount = aSessionEngine->Engine().AlarmCountByState(EAlarmStateWaitingToNotify); |
|
89 TheTest(alarmCount == 1, __LINE__); |
|
90 alarmCount = aSessionEngine->Engine().AlarmCountByState(EAlarmStateQueued); |
|
91 TheTest(alarmCount == 8, __LINE__); |
|
92 |
|
93 //last 8 alarms in our array should correspond to array of alarms with state queued |
|
94 RArray<TAlarmId>* alarmsWithStateQueued = aSessionEngine->Engine().AlarmIdListByStateLC(EAlarmStateQueued); |
|
95 for(TInt jj=0; jj<8; jj++) |
|
96 { |
|
97 TheTest(alarmIds[jj+2] == (*alarmsWithStateQueued)[jj], __LINE__); |
|
98 } |
|
99 alarmsWithStateQueued->Close(); |
|
100 CleanupStack::PopAndDestroy(alarmsWithStateQueued); |
|
101 |
|
102 //delete all alarms individually |
|
103 for(TInt count=alarmIds.Count(); count>0; count--) |
|
104 { |
|
105 aSessionEngine->Engine().AlarmDeleteL(alarmIds[count-1]); |
|
106 } |
|
107 CleanupStack::PopAndDestroy();//alarmIds |
|
108 } |
|
109 |
|
110 |
|
111 void Test2L(CTestServerSessionEngine* aSessionEngine) |
|
112 { |
|
113 TheTest.Next(_L("Test 2")); |
|
114 //****************************************************************************** |
|
115 // Test2 tests |
|
116 // |
|
117 // AlarmDetailsL |
|
118 // AlarmCategoryL |
|
119 // SetAlarmStatusByCategoryL |
|
120 // AlarmCountByCategory |
|
121 // DeleteAllAlarmsByCategoryL |
|
122 // AlarmCategoryListLC |
|
123 // AlarmIdListByCategoryLC |
|
124 // SetAlarmStatusL |
|
125 // AlarmStatus |
|
126 //****************************************************************************** |
|
127 aSessionEngine->ClearAlarmStoreL(); |
|
128 |
|
129 //add 5 alarms with category KASCliCategoryClock |
|
130 for(TInt ii=0; ii<5; ii++) |
|
131 { |
|
132 aSessionEngine->AddAlarmWithSpecificCategoryL(KASCliCategoryClock); |
|
133 } |
|
134 |
|
135 //get list of categories - should contain only KASCliCategoryClock |
|
136 RArray<TAlarmCategory>* alarmCategories = aSessionEngine->Engine().AlarmCategoryListLC(); |
|
137 |
|
138 TheTest(alarmCategories->Count() == 1 && (*alarmCategories)[0] == KASCliCategoryClock, __LINE__); |
|
139 alarmCategories->Close(); |
|
140 CleanupStack::PopAndDestroy(alarmCategories); |
|
141 |
|
142 //add 5 alarms with category KASCliCategoryTest |
|
143 for(TInt jj=0; jj<5; jj++) |
|
144 { |
|
145 aSessionEngine->AddAlarmWithSpecificCategoryL(KASCliCategoryTest); |
|
146 } |
|
147 |
|
148 RArray<TAlarmCategory>* alarmCategories2 = aSessionEngine->Engine().AlarmCategoryListLC(); |
|
149 TheTest(alarmCategories2->Count() == 2, __LINE__); |
|
150 alarmCategories2->Close(); |
|
151 CleanupStack::PopAndDestroy(alarmCategories2); |
|
152 |
|
153 //add another 10 alarms with category KASCliCategoryClock |
|
154 for(TInt kk=0; kk<10; kk++) |
|
155 { |
|
156 aSessionEngine->AddAlarmWithSpecificCategoryL(KASCliCategoryClock); |
|
157 } |
|
158 |
|
159 //get alarms with category KASCliCategoryClock |
|
160 RArray<TAlarmId>* alarms = aSessionEngine->Engine().AlarmIdListByCategoryLC(KASCliCategoryClock); |
|
161 TInt count = alarms->Count(); |
|
162 TheTest(count == 15, __LINE__); |
|
163 //check each alarm has category KASCliCategoryClock |
|
164 for(TInt mm=0; mm<15; mm++) |
|
165 { |
|
166 //directly |
|
167 TheTest(aSessionEngine->Engine().AlarmCategoryL((*alarms)[mm]) == KASCliCategoryClock, __LINE__); |
|
168 //indirectly |
|
169 TASSrvAlarm alarm(aSessionEngine->ServerWideData()); |
|
170 aSessionEngine->Engine().AlarmDetailsL((*alarms)[mm], alarm); |
|
171 TheTest(alarm.Category() == KASCliCategoryClock, __LINE__); |
|
172 } |
|
173 alarms->Close(); |
|
174 CleanupStack::PopAndDestroy(alarms); |
|
175 |
|
176 //should now have 15 alarms with category KASCliCategoryClock and 5 with category KASCliCategoryTest |
|
177 TheTest(aSessionEngine->Engine().AlarmCountByCategory(KASCliCategoryClock)==15 && |
|
178 aSessionEngine->Engine().AlarmCountByCategory(KASCliCategoryTest)==5, __LINE__); |
|
179 //disable all KASCliCategoryClock alarms |
|
180 aSessionEngine->Engine().SetAlarmStatusByCategoryL(KASCliCategoryClock, EAlarmStatusDisabled); |
|
181 TheTest(aSessionEngine->Engine().NumberOfActiveAlarmsInQueue()==5, __LINE__); |
|
182 //try to delete all KASCliCategoryTest orphaned alarms (should be none) |
|
183 aSessionEngine->Engine().DeleteAllAlarmsByCategoryL(KASCliCategoryTest, ETrue); |
|
184 TheTest(aSessionEngine->Engine().NumberOfActiveAlarmsInQueue()==5, __LINE__); |
|
185 //delete all KASCliCategoryTest alarms |
|
186 aSessionEngine->Engine().DeleteAllAlarmsByCategoryL(KASCliCategoryTest, EFalse); |
|
187 TheTest(aSessionEngine->Engine().NumberOfActiveAlarmsInQueue()==0, __LINE__); |
|
188 //re-enable the KASCliCategoryClock alarms |
|
189 aSessionEngine->Engine().SetAlarmStatusByCategoryL(KASCliCategoryClock, EAlarmStatusEnabled); |
|
190 TheTest(aSessionEngine->Engine().NumberOfActiveAlarmsInQueue()==15, __LINE__); |
|
191 //create a new enabled alarm |
|
192 TAlarmId id = aSessionEngine->AddAlarmWithSpecificCategoryL(KASCliCategoryClock); |
|
193 TheTest(aSessionEngine->Engine().NumberOfActiveAlarmsInQueue()==16, __LINE__); |
|
194 //check status |
|
195 TheTest(aSessionEngine->Engine().AlarmStatusL(id) == EAlarmStatusEnabled, __LINE__); |
|
196 //disable it |
|
197 aSessionEngine->Engine().SetAlarmStatusL(id, EAlarmStatusDisabled); |
|
198 TheTest(aSessionEngine->Engine().NumberOfActiveAlarmsInQueue()==15, __LINE__); |
|
199 TheTest(aSessionEngine->Engine().AlarmStatusL(id) == EAlarmStatusDisabled, __LINE__); |
|
200 |
|
201 //delete all remaining alarms |
|
202 aSessionEngine->Engine().DeleteAllAlarmsByCategoryL(KASCliCategoryClock, EFalse); |
|
203 TheTest(aSessionEngine->Engine().NumberOfActiveAlarmsInQueue()==0, __LINE__); |
|
204 } |
|
205 |
|
206 |
|
207 static void doTestsL() |
|
208 { |
|
209 // this is a WINS test only, because it tests the functionality of the alarm server |
|
210 // engine directly. The tests are repeated in TClientSession which exercises the same |
|
211 // functionality through a client session |
|
212 |
|
213 #ifdef __WINS__ |
|
214 CTestServerSessionEngine* sessionEngine = CTestServerSessionEngine::NewLC(); |
|
215 // |
|
216 TheTest.Next(_L("Start tests")); |
|
217 Test1L(sessionEngine); |
|
218 Test2L(sessionEngine); |
|
219 |
|
220 CleanupStack::PopAndDestroy(sessionEngine); |
|
221 #else |
|
222 TheTest.Printf(_L("\nThis is a WINS test only\n")); |
|
223 #endif |
|
224 } |
|
225 |
|
226 /** |
|
227 @SYMTestCaseID PIM-TSERVERSESSIONENGINEMAIN-0001 |
|
228 */ |
|
229 TInt E32Main() |
|
230 { |
|
231 __UHEAP_MARK; |
|
232 // |
|
233 TheTest.Title(); |
|
234 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
235 if (!cleanup) |
|
236 return KErrNoMemory; |
|
237 // |
|
238 TheTest.Start(_L("@SYMTestCaseID PIM-TSERVERSESSIONENGINEMAIN-0001")); |
|
239 // |
|
240 TRAPD(err, doTestsL()); |
|
241 TheTest(err == KErrNone, __LINE__); |
|
242 |
|
243 delete cleanup; |
|
244 TheTest.End(); |
|
245 TheTest.Close(); |
|
246 |
|
247 __UHEAP_MARKEND; |
|
248 return KErrNone; |
|
249 } |