|
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 <s32file.h> |
|
17 #include <e32test.h> |
|
18 |
|
19 #include <txtrich.h> |
|
20 #include <conpics.h> |
|
21 |
|
22 #include <calentryview.h> |
|
23 #include <calrrule.h> |
|
24 #include <calcategory.h> |
|
25 #include <calcontent.h> |
|
26 #include <caluser.h> |
|
27 #include <calalarm.h> |
|
28 |
|
29 #include "caltestlib.h" |
|
30 #include "caltestoom.h" |
|
31 |
|
32 RTest test(_L("t_testcopy")); |
|
33 |
|
34 static const TTime KStartTime(TDateTime(2005, ENovember, 23, 12, 0, 0, 0)); |
|
35 |
|
36 _LIT(KTestFile, "t_testcopy"); |
|
37 |
|
38 TBufC8<25> _SmallContent(_L8("small content")); |
|
39 TBufC8<25> _MimeType(_L8("mime type")); |
|
40 |
|
41 class CTestApp : public CBase, public MCalTestOomCallBack |
|
42 { |
|
43 public: |
|
44 static CTestApp* NewL(); |
|
45 ~CTestApp(); |
|
46 |
|
47 void SetEntryDetailsL(CCalEntry& aEntry); |
|
48 |
|
49 void TestCopyL(); |
|
50 void OomTestCopyL(); |
|
51 |
|
52 public: // from MCalOomTestCallBack |
|
53 void OomTestL(TType aType, TInt aFailAt); |
|
54 |
|
55 private: |
|
56 void ConstructL(); |
|
57 |
|
58 private: |
|
59 CCalTestLibrary* iCalTestLib; |
|
60 |
|
61 }; |
|
62 |
|
63 CTestApp* CTestApp::NewL() |
|
64 { |
|
65 CTestApp* self = new(ELeave) CTestApp; |
|
66 CleanupStack::PushL(self); |
|
67 self->ConstructL(); |
|
68 CleanupStack::Pop(self); |
|
69 return self; |
|
70 } |
|
71 |
|
72 void CTestApp::ConstructL() |
|
73 { |
|
74 iCalTestLib = CCalTestLibrary::NewL(); |
|
75 iCalTestLib->ReplaceFileL(KTestFile()); |
|
76 iCalTestLib->OpenFileL(KTestFile()); |
|
77 } |
|
78 |
|
79 CTestApp::~CTestApp() |
|
80 { |
|
81 delete iCalTestLib; |
|
82 } |
|
83 |
|
84 void CTestApp::OomTestCopyL() |
|
85 { |
|
86 test.Printf(_L("Starting out of memory test\n")); |
|
87 CCalSession& calSession = iCalTestLib->GetSession(); |
|
88 CalTestOom::OutOfMemoryTestL(*this, EClient, calSession); |
|
89 CalTestOom::OutOfMemoryTestL(*this, EServer, calSession); |
|
90 } |
|
91 |
|
92 void CTestApp::OomTestL(TType /*aType*/, TInt /*aFailAt*/) |
|
93 { |
|
94 test.Printf(_L(".")); |
|
95 TestCopyL(); |
|
96 } |
|
97 |
|
98 void CTestApp::SetEntryDetailsL(CCalEntry& aEntry) |
|
99 { |
|
100 iCalTestLib->SetEntryStartAndEndTimeL(&aEntry, KStartTime, KStartTime + TTimeIntervalHours(1)); |
|
101 |
|
102 // create a repeat rule |
|
103 TCalTime dtStart; |
|
104 dtStart.SetTimeLocalL(KStartTime); |
|
105 TCalTime until; |
|
106 until.SetTimeLocalL(KStartTime + TTimeIntervalDays(7)); |
|
107 |
|
108 TCalRRule rRule(TCalRRule::EDaily); |
|
109 rRule.SetDtStart(dtStart); |
|
110 rRule.SetUntil(until); |
|
111 rRule.SetInterval(1); |
|
112 aEntry.SetRRuleL(rRule); |
|
113 |
|
114 // add an exception |
|
115 RArray<TCalTime> exceptions; |
|
116 CleanupClosePushL(exceptions); |
|
117 TCalTime exception; |
|
118 exception.SetTimeLocalL(KStartTime + TTimeIntervalDays(3)); |
|
119 exceptions.AppendL(exception); |
|
120 aEntry.SetExceptionDatesL(exceptions); |
|
121 CleanupStack::PopAndDestroy(&exceptions); |
|
122 |
|
123 // add an rdate |
|
124 RArray<TCalTime> rDates; |
|
125 CleanupClosePushL(rDates); |
|
126 TCalTime rDate; |
|
127 rDate.SetTimeLocalL(KStartTime + TTimeIntervalDays(3) + TTimeIntervalHours(3)); |
|
128 rDates.AppendL(rDate); |
|
129 aEntry.SetExceptionDatesL(rDates); |
|
130 CleanupStack::PopAndDestroy(&rDates); |
|
131 |
|
132 // add a category predefined and an extended |
|
133 CCalCategory* predefinedCategory = CCalCategory::NewL(CCalCategory::ECalBusiness); |
|
134 aEntry.AddCategoryL(predefinedCategory); |
|
135 CCalCategory* extendedCategory = CCalCategory::NewL(_L("Extended Category")); |
|
136 aEntry.AddCategoryL(extendedCategory); |
|
137 |
|
138 // oom test this |
|
139 aEntry.CategoryListL(); |
|
140 |
|
141 CCalCategory* extendedCategory2 = CCalCategory::NewL(_L("dummy category")); |
|
142 aEntry.AddCategoryL(extendedCategory2); |
|
143 aEntry.DeleteCategoryL(2); |
|
144 |
|
145 // set a different time zone rule |
|
146 // ? |
|
147 |
|
148 // set the description |
|
149 aEntry.SetDescriptionL(_L("The Description")); |
|
150 |
|
151 // set the summary |
|
152 aEntry.SetSummaryL(_L("The Summary")); |
|
153 |
|
154 // set the organizer |
|
155 CCalUser* organizer = CCalUser::NewL(_L("organizer@symbian.com")); |
|
156 aEntry.SetOrganizerL(organizer); |
|
157 |
|
158 // set an attendee |
|
159 CCalAttendee* attendee = CCalAttendee::NewL(_L("attendee@symbian.com")); |
|
160 aEntry.AddAttendeeL(attendee); |
|
161 |
|
162 // set the phone owner |
|
163 RPointerArray<CCalAttendee>& attendList = aEntry.AttendeesL(); |
|
164 aEntry.SetPhoneOwnerL(attendList[0]); |
|
165 |
|
166 // set priority |
|
167 aEntry.SetPriorityL(1); |
|
168 |
|
169 // add an alarm |
|
170 CCalAlarm* alarm = CCalAlarm::NewL(); |
|
171 CleanupStack::PushL(alarm); |
|
172 |
|
173 alarm->SetTimeOffset(15); |
|
174 alarm->SetAlarmSoundNameL(_L("alarm sound")); |
|
175 |
|
176 CCalContent* content = CCalContent::NewL(); |
|
177 CleanupStack::PushL(content); |
|
178 |
|
179 content->SetContentL(_MimeType.AllocLC(), _SmallContent.AllocLC(), CCalContent::EDispositionUnknown); |
|
180 CleanupStack::Pop(2); |
|
181 alarm->SetAlarmAction(content); |
|
182 CleanupStack::Pop(content); |
|
183 aEntry.SetAlarmL(alarm); |
|
184 CleanupStack::PopAndDestroy(alarm); |
|
185 } |
|
186 |
|
187 void CTestApp::TestCopyL() |
|
188 { |
|
189 // create the original entry |
|
190 HBufC8* guidEntry = NULL; |
|
191 CCalEntry* originalEntry = iCalTestLib->CreateCalEntryL(CCalEntry::ETodo, guidEntry); |
|
192 CleanupStack::PushL(originalEntry); |
|
193 SetEntryDetailsL(*originalEntry); |
|
194 |
|
195 HBufC8* guidCopy = NULL; |
|
196 CCalEntry* copiedEntry = iCalTestLib->CreateCalEntryL(CCalEntry::ETodo, guidCopy); |
|
197 CleanupStack::PushL(copiedEntry); |
|
198 |
|
199 // copy and compare the entries |
|
200 copiedEntry->CopyFromL(*originalEntry); |
|
201 test(copiedEntry->CompareL(*originalEntry)); |
|
202 |
|
203 // Save the copy in the DB |
|
204 RPointerArray<CCalEntry> calEntries; |
|
205 CleanupClosePushL(calEntries); |
|
206 calEntries.AppendL(copiedEntry); |
|
207 TInt numSuc; |
|
208 iCalTestLib->SynCGetEntryViewL().StoreL(calEntries, numSuc); |
|
209 CleanupStack::PopAndDestroy(&calEntries); //copiedEntry.Close() |
|
210 CleanupResetAndDestroyPushL(calEntries); |
|
211 |
|
212 // Read the copy out of the DB |
|
213 // and compare the fetched entry with the copy that was stored |
|
214 iCalTestLib->SynCGetEntryViewL().FetchL(copiedEntry->UidL(), calEntries); |
|
215 test(copiedEntry->CompareL(*calEntries[0])); |
|
216 test(originalEntry->CompareL(*calEntries[0])); |
|
217 calEntries.ResetAndDestroy(); |
|
218 |
|
219 // Read the copy out of the DB |
|
220 // copy the the fetched entry and then compare with the original |
|
221 iCalTestLib->SynCGetEntryViewL().FetchL(copiedEntry->UidL(), calEntries); |
|
222 HBufC8* guidCopy2 = NULL; |
|
223 CCalEntry* copiedEntry2 = iCalTestLib->CreateCalEntryL(CCalEntry::ETodo, guidCopy2); |
|
224 CleanupStack::PushL(copiedEntry2); |
|
225 copiedEntry2->CopyFromL(*calEntries[0]); |
|
226 test(copiedEntry2->CompareL(*calEntries[0])); |
|
227 calEntries.ResetAndDestroy(); |
|
228 |
|
229 // cleanup |
|
230 CleanupStack::PopAndDestroy(copiedEntry2); |
|
231 CleanupStack::PopAndDestroy(&calEntries); |
|
232 CleanupStack::PopAndDestroy(copiedEntry); |
|
233 CleanupStack::PopAndDestroy(originalEntry); |
|
234 } |
|
235 |
|
236 static void doMainL() |
|
237 { |
|
238 CTestApp* testApp = CTestApp::NewL(); |
|
239 CleanupStack::PushL(testApp); |
|
240 |
|
241 testApp->TestCopyL(); |
|
242 testApp->OomTestCopyL(); |
|
243 |
|
244 CleanupStack::PopAndDestroy(testApp); |
|
245 } |
|
246 |
|
247 /** |
|
248 |
|
249 @SYMTestCaseID PIM-T-TESTCOPY-0001 |
|
250 |
|
251 */ |
|
252 |
|
253 TInt E32Main() |
|
254 { |
|
255 __UHEAP_MARK; |
|
256 |
|
257 test.Start(_L("@SYMTESTCaseID:PIM-T-TESTCOPY-0001 T_TestCopy")); |
|
258 |
|
259 test.Title(); |
|
260 |
|
261 CTrapCleanup* CleanupTrap = CTrapCleanup::New(); |
|
262 CActiveScheduler* scheduler = new CActiveScheduler; |
|
263 CActiveScheduler::Install(scheduler); |
|
264 |
|
265 TRAPD(ret,doMainL()); |
|
266 test(ret==KErrNone); |
|
267 |
|
268 delete scheduler; |
|
269 delete CleanupTrap; |
|
270 |
|
271 test.End(); |
|
272 test.Close(); |
|
273 |
|
274 __UHEAP_MARKEND; |
|
275 return(KErrNone); |
|
276 } |
|
277 |