|
1 /* |
|
2 * Copyright (c) 2008-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Conflict checker unit and module tests |
|
15 * Version : %version: e002sa33#4 % |
|
16 * |
|
17 * Copyright ? 2008-2008 Nokia. All rights reserved. |
|
18 */ |
|
19 |
|
20 |
|
21 #include "UT_CESMRConflictChecker.h" |
|
22 |
|
23 // SYSTEM INCLUDES |
|
24 #include <EUnitMacros.h> |
|
25 #include <EUnitDecorators.h> |
|
26 |
|
27 #include <aknutils.h> |
|
28 #include <calsession.h> |
|
29 #include <calinstance.h> |
|
30 #include <calinstanceview.h> |
|
31 |
|
32 // USER INCLUDES |
|
33 #include "cesmrconflictchecker.h" |
|
34 #include "cesmrcaldbmgr.h" |
|
35 |
|
36 // CONSTANTS |
|
37 |
|
38 // LOCAL DEFINITIONS |
|
39 |
|
40 namespace { |
|
41 |
|
42 _LIT(KTimeFormat,"%F%Y/%M/%D,%H:%T:%S"); |
|
43 |
|
44 // Conflicting entry's start time (yyyymmdd::hhmmss). |
|
45 _LIT( KConflictingCalendarEntryStartTime, "20091100:140000" ); |
|
46 //-TODO:luo _LIT( KConflictingCalendarEntryStartTime, "20090000:150000" ); |
|
47 // Conflicting entry's end time (yyyymmdd::hhmmss). |
|
48 _LIT( KConflictingCalendarEntryEndTime, "20091100:150000"); |
|
49 //-TODO:luo _LIT( KConflictingCalendarEntryEndTime, "20090000:170000"); |
|
50 // Calendar entry's location for conflicting entries. |
|
51 _LIT( KCalendarEntryTrueValue, "1" ); |
|
52 |
|
53 // Recurrent event start and end time. |
|
54 _LIT( KRecurrentCalendarEntryStartTime, "20091100:140000" ); |
|
55 _LIT( KRecurrentCalendarEntryEndTime, "20091100:150000" ); |
|
56 |
|
57 // Time range for fetching recurrent event instances. |
|
58 _LIT( KRecurrentEntryTimeRangeStartTime, "20091100:000000" ); |
|
59 _LIT( KRecurrentEntryTimeRangeEndTime, "20091106:000000" ); |
|
60 |
|
61 // Calendar database filename. |
|
62 _LIT( KCalendarDatabaseFilePath, "c:calendar3");//"c:Calendar_test_conflictchecker" ); |
|
63 // Calendar entry UID. |
|
64 _LIT8( KCalendarEntryUid, "UT_ConflictChecker" ); |
|
65 } |
|
66 |
|
67 // - Construction ------------------------------------------------------------ |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // UT_CESMRConflictChecker::NewL |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 UT_CESMRConflictChecker* UT_CESMRConflictChecker::NewL() |
|
74 { |
|
75 UT_CESMRConflictChecker* self = UT_CESMRConflictChecker::NewLC(); |
|
76 CleanupStack::Pop(); |
|
77 return self; |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // UT_CESMRConflictChecker::NewLC |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 UT_CESMRConflictChecker* UT_CESMRConflictChecker::NewLC() |
|
85 { |
|
86 UT_CESMRConflictChecker* self = new( ELeave ) UT_CESMRConflictChecker(); |
|
87 CleanupStack::PushL( self ); |
|
88 self->ConstructL(); |
|
89 return self; |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // UT_CESMRConflictChecker::~UT_CESMRConflictChecker |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 UT_CESMRConflictChecker::~UT_CESMRConflictChecker() |
|
97 { |
|
98 delete iWait; |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // UT_CESMRConflictChecker::UT_CESMRConflictChecker |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 UT_CESMRConflictChecker::UT_CESMRConflictChecker() |
|
106 { |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // UT_CESMRConflictChecker::ConstructL |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 void UT_CESMRConflictChecker::ConstructL() |
|
114 { |
|
115 CEUnitTestSuiteClass::ConstructL(); |
|
116 iWait = new ( ELeave) CActiveSchedulerWait(); |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // UT_CESMRConflictChecker::HandleCalEngStatus |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 void UT_CESMRConflictChecker::HandleCalEngStatus( TMRUtilsCalEngStatus aStatus ) |
|
124 { |
|
125 iWait->AsyncStop(); |
|
126 } |
|
127 |
|
128 // - Test methods ----------------------------------------------------------- |
|
129 |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // UT_CESMRConflictChecker::SetupL |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 void UT_CESMRConflictChecker::SetupL() |
|
136 { |
|
137 __UHEAP_MARK; |
|
138 iCalSession = CCalSession::NewL(); |
|
139 iCalSession->OpenL( KCalendarDatabaseFilePath ); |
|
140 iCalDbManager = CESMRCalDbMgr::NewL( *iCalSession, *this ); |
|
141 iWait->Start(); |
|
142 iConflictChecker = CESMRConflictChecker::NewL( *iCalDbManager ); |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // UT_CESMRConflictChecker::Teardown |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 void UT_CESMRConflictChecker::Teardown() |
|
150 { |
|
151 delete iConflictChecker; |
|
152 delete iCalDbManager; |
|
153 delete iCalSession; |
|
154 __UHEAP_MARKEND; |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // UT_CESMRConflictChecker::T_Global_NewL |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 void UT_CESMRConflictChecker::T_Global_NewL() |
|
162 { |
|
163 delete iConflictChecker; |
|
164 iConflictChecker = NULL; |
|
165 |
|
166 __UHEAP_MARK; |
|
167 iConflictChecker = CESMRConflictChecker::NewL( *iCalDbManager ); |
|
168 delete iConflictChecker; |
|
169 __UHEAP_MARKEND; |
|
170 |
|
171 iConflictChecker = NULL; |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // UT_CESMRConflictChecker::T_Global_FindConflictsL |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 void UT_CESMRConflictChecker::T_Global_FindConflictsL() |
|
179 { |
|
180 // Create reference calendar entry. |
|
181 HBufC8* entryUidBufC = KCalendarEntryUid().AllocLC(); |
|
182 CCalEntry* calEntry = CCalEntry::NewL( CCalEntry::EAppt, entryUidBufC, CCalEntry::EMethodRequest, 0 ); |
|
183 CleanupStack::Pop( entryUidBufC ); |
|
184 entryUidBufC = NULL; |
|
185 |
|
186 TTime startTime, endTime; |
|
187 TCalTime startCalTime, endCalTime; |
|
188 |
|
189 startTime.Set( KConflictingCalendarEntryStartTime ); |
|
190 endTime.Set( KConflictingCalendarEntryEndTime ); |
|
191 |
|
192 TBuf<32> sTime; |
|
193 TBuf<32> eTime; |
|
194 startTime.FormatL( sTime, KTimeFormat ); |
|
195 endTime.FormatL( eTime, KTimeFormat ); |
|
196 |
|
197 startCalTime.SetTimeLocalL( startTime ); |
|
198 endCalTime.SetTimeLocalL( endTime ); |
|
199 |
|
200 calEntry->SetStartAndEndTimeL( startCalTime, endCalTime ); |
|
201 |
|
202 // Fetch conflicting entries. |
|
203 RPointerArray<CCalEntry> conflictList; |
|
204 CleanupClosePushL( conflictList ); |
|
205 |
|
206 iConflictChecker->FindConflictsL( *calEntry, conflictList ); |
|
207 delete calEntry; |
|
208 calEntry = NULL; |
|
209 |
|
210 // Check that correct number of entries is returned. |
|
211 EUNIT_ASSERT_DESC( conflictList.Count() == 4, |
|
212 "Incorrect number of calendar entries." ); |
|
213 |
|
214 // Verify list of conflicting entries. |
|
215 TBool testFailed = EFalse; |
|
216 while ( conflictList.Count() ) |
|
217 { |
|
218 // If entry's location is something else than '1'. |
|
219 if ( conflictList[ 0 ]->LocationL().Compare( KCalendarEntryTrueValue ) ) |
|
220 { |
|
221 testFailed = ETrue; |
|
222 } |
|
223 |
|
224 // Remove entry from array. |
|
225 delete conflictList[ 0 ]; |
|
226 conflictList.Remove( 0 ); |
|
227 } |
|
228 |
|
229 // Check that correct entries were returned. |
|
230 EUNIT_ASSERT_DESC( !testFailed, |
|
231 "Incorrect calendar entry/ies returned."); |
|
232 |
|
233 CleanupStack::PopAndDestroy(); // conflictList |
|
234 } |
|
235 |
|
236 // --------------------------------------------------------------------------- |
|
237 // UT_CESMRConflictChecker::T_Global_FindInstancesForEntryL |
|
238 // --------------------------------------------------------------------------- |
|
239 // |
|
240 void UT_CESMRConflictChecker::T_Global_FindInstancesForEntryL() |
|
241 { |
|
242 // First retrieve one instace of recurrent event. |
|
243 RPointerArray<CCalInstance> instanceList; |
|
244 MESMRCalDbMgr& dbMgr = *iCalDbManager; |
|
245 CCalInstanceView* instanceView = dbMgr.NormalDbInstanceView(); |
|
246 CalCommon::TCalViewFilter calViewFilter( CalCommon::EIncludeAppts ); |
|
247 |
|
248 TTime startTime, endTime; |
|
249 TCalTime startCalTime, endCalTime; |
|
250 |
|
251 startTime.Set( KRecurrentCalendarEntryStartTime ); |
|
252 endTime.Set( KRecurrentCalendarEntryEndTime ); |
|
253 |
|
254 TBuf<32> sTime; |
|
255 TBuf<32> eTime; |
|
256 startTime.FormatL( sTime, KTimeFormat ); |
|
257 endTime.FormatL( eTime, KTimeFormat ); |
|
258 |
|
259 startCalTime.SetTimeLocalL( startTime ); |
|
260 endCalTime.SetTimeLocalL( endTime ); |
|
261 |
|
262 instanceView->FindInstanceL( |
|
263 instanceList, |
|
264 calViewFilter, |
|
265 CalCommon::TCalTimeRange( startCalTime, endCalTime ) ); |
|
266 |
|
267 EUNIT_ASSERT_DESC( instanceList.Count() == 2, |
|
268 "Incorrect number of instances returned."); |
|
269 |
|
270 CCalEntry& calEntry = instanceList[0]->Entry(); |
|
271 |
|
272 // Set time range. |
|
273 startTime.Set( KRecurrentEntryTimeRangeStartTime ); |
|
274 endTime.Set( KRecurrentEntryTimeRangeEndTime ); |
|
275 |
|
276 startCalTime.SetTimeLocalL( startTime ); |
|
277 endCalTime.SetTimeLocalL( endTime ); |
|
278 |
|
279 // Fetch recurrent event instances. |
|
280 RPointerArray<CCalEntry> entryList; |
|
281 iConflictChecker->FindInstancesForEntryL( startTime, endTime, calEntry, entryList ); |
|
282 |
|
283 EUNIT_ASSERT_DESC( entryList.Count() == 6, |
|
284 "Incorrect number of calendar entry instances returned."); |
|
285 |
|
286 // Clear entry/instance lists. |
|
287 while ( instanceList.Count() ) |
|
288 { |
|
289 delete instanceList[ 0 ]; |
|
290 instanceList.Remove( 0 ); |
|
291 } |
|
292 while ( entryList.Count() ) |
|
293 { |
|
294 delete entryList[ 0 ]; |
|
295 entryList.Remove( 0 ); |
|
296 } |
|
297 instanceList.Close(); |
|
298 entryList.Close(); |
|
299 } |
|
300 |
|
301 // - EUnit test table -------------------------------------------------------- |
|
302 |
|
303 EUNIT_BEGIN_TEST_TABLE( |
|
304 UT_CESMRConflictChecker, |
|
305 "CESMRConflictChecker unit and module tests.", |
|
306 "UNIT" ) |
|
307 |
|
308 EUNIT_TEST( |
|
309 "NewL", |
|
310 "CESMRConflictChecker", |
|
311 "NewL", |
|
312 "FUNCTIONALITY", |
|
313 SetupL, T_Global_NewL, Teardown ) |
|
314 |
|
315 EUNIT_TEST( |
|
316 "FindConflictsL", |
|
317 "CESMRConflictChecker", |
|
318 "FindConflictsL", |
|
319 "FUNCTIONALITY", |
|
320 SetupL, T_Global_FindConflictsL, Teardown ) |
|
321 |
|
322 EUNIT_TEST( |
|
323 "FindInstancesForEntryL", |
|
324 "CESMRConflictChecker", |
|
325 "FindInstancesForEntryL", |
|
326 "FUNCTIONALITY", |
|
327 SetupL, T_Global_FindInstancesForEntryL, Teardown ) |
|
328 |
|
329 EUNIT_END_TEST_TABLE |