|
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 <conpics.h> |
|
18 #include <e32test.h> |
|
19 |
|
20 #include <calrrule.h> |
|
21 #include <calentryview.h> |
|
22 |
|
23 #include "caltestlib.h" |
|
24 |
|
25 RTest test(_L("TFAILADD")); |
|
26 |
|
27 static const TInt KMyError(-12345); |
|
28 |
|
29 _LIT(KTestCalendarFile, "tfailadd"); |
|
30 |
|
31 class CTestApp : public CBase |
|
32 { |
|
33 public: |
|
34 static CTestApp* NewL(); |
|
35 ~CTestApp(); |
|
36 |
|
37 void FillEntryL(CCalEntry& aEntry); |
|
38 void TestFailL(CCalEntry::TType aEntryType); |
|
39 |
|
40 void StoreEntryL(const CCalEntry* aEntry); |
|
41 |
|
42 private: |
|
43 void ConstructL(); |
|
44 |
|
45 private: |
|
46 CCalTestLibrary* iCalTestLib; |
|
47 |
|
48 }; |
|
49 |
|
50 CTestApp* CTestApp::NewL() |
|
51 { |
|
52 CTestApp* self = new(ELeave) CTestApp; |
|
53 CleanupStack::PushL(self); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop(self); |
|
56 return self; |
|
57 } |
|
58 |
|
59 void CTestApp::ConstructL() |
|
60 { |
|
61 iCalTestLib = CCalTestLibrary::NewL(); |
|
62 } |
|
63 |
|
64 CTestApp::~CTestApp() |
|
65 { |
|
66 delete iCalTestLib; |
|
67 } |
|
68 |
|
69 void CTestApp::StoreEntryL(const CCalEntry* aEntry) |
|
70 { |
|
71 iCalTestLib->ReplaceFileL(KTestCalendarFile); |
|
72 iCalTestLib->OpenFileL(KTestCalendarFile); |
|
73 |
|
74 RPointerArray<CCalEntry> entryArray; |
|
75 CleanupClosePushL(entryArray); |
|
76 entryArray.AppendL(aEntry); |
|
77 TInt numSuc; |
|
78 iCalTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc); |
|
79 test(numSuc == entryArray.Count()); |
|
80 CleanupStack::PopAndDestroy(&entryArray); |
|
81 } |
|
82 |
|
83 void CTestApp::FillEntryL(CCalEntry& aEntry) |
|
84 { |
|
85 switch (aEntry.EntryTypeL()) |
|
86 { |
|
87 case CCalEntry::EAppt: |
|
88 { |
|
89 aEntry.SetSummaryL(_L("appt")); |
|
90 |
|
91 // the appt spans midnight |
|
92 iCalTestLib->SetEntryStartAndEndTimeL(&aEntry, TTime(TDateTime(1995,EJanuary,0,20,15,0,0)), TTime(TDateTime(1995,EJanuary,1,5,15,0,0)) ); |
|
93 |
|
94 // it repeats every 2 days and has and exception |
|
95 TCalRRule rRuleAppt(TCalRRule::EDaily); |
|
96 TCalTime dtStartAppt; |
|
97 dtStartAppt.SetTimeLocalL(TTime(TDateTime(1995,EJanuary,0,0,0,0,0))); |
|
98 TCalTime untilAppt; |
|
99 untilAppt.SetTimeLocalL(TTime(TDateTime(1995,EJanuary,9,0,0,0,0))); |
|
100 rRuleAppt.SetDtStart(dtStartAppt); |
|
101 rRuleAppt.SetUntil(untilAppt); |
|
102 rRuleAppt.SetInterval(2); |
|
103 aEntry.SetRRuleL(rRuleAppt); |
|
104 |
|
105 TCalTime exception; |
|
106 exception.SetTimeLocalL(TTime(TDateTime(1995,EJanuary,4,0,0,0,0))); |
|
107 RArray<TCalTime> exceptions; |
|
108 CleanupClosePushL(exceptions); |
|
109 exceptions.AppendL(exception); |
|
110 aEntry.SetExceptionDatesL(exceptions); |
|
111 CleanupStack::PopAndDestroy(&exceptions); |
|
112 break; |
|
113 } |
|
114 case CCalEntry::EEvent: |
|
115 { |
|
116 aEntry.SetSummaryL(_L("event")); |
|
117 iCalTestLib->SetEntryStartAndEndTimeL(&aEntry, TTime(TDateTime(1995,EJanuary,0,0,0,0,0)), TTime(TDateTime(1995,EJanuary,0,0,0,0,0))); |
|
118 break; |
|
119 } |
|
120 case CCalEntry::EAnniv: |
|
121 { |
|
122 aEntry.SetSummaryL(_L("anniv")); |
|
123 iCalTestLib->SetEntryStartAndEndTimeL(&aEntry, TTime(TDateTime(1995,EJanuary,0,0,0,0,0)), TTime(TDateTime(1995,EJanuary,0,0,0,0,0))); // !!! WHAT'S THIS FOR ??? |
|
124 |
|
125 TCalRRule rRuleAnniv(TCalRRule::EYearly); |
|
126 TCalTime dtStartAnniv; |
|
127 dtStartAnniv.SetTimeLocalL(TTime(TDateTime(1994,EJanuary,0,0,0,0,0))); |
|
128 TCalTime untilAnniv; |
|
129 untilAnniv.SetTimeLocalL(TCalTime::MaxTime()); |
|
130 rRuleAnniv.SetDtStart(dtStartAnniv); |
|
131 rRuleAnniv.SetUntil(untilAnniv); |
|
132 rRuleAnniv.SetInterval(1); |
|
133 aEntry.SetRRuleL(rRuleAnniv); |
|
134 break; |
|
135 } |
|
136 case CCalEntry::ETodo: |
|
137 { |
|
138 aEntry.SetSummaryL(_L("todo")); |
|
139 aEntry.SetPriorityL(1); |
|
140 break; |
|
141 } |
|
142 } |
|
143 } |
|
144 |
|
145 void CTestApp::TestFailL(CCalEntry::TType aEntryType) |
|
146 { |
|
147 TInt failAt(0); |
|
148 |
|
149 FOREVER |
|
150 { |
|
151 //When session is disconnected, it loses information present in CAgnTlsProxy |
|
152 //If not connected, It would cause panic when other clientside APIs try to make us of the CAgnTlsProxy object. |
|
153 //This call below makes sure that such a case does not affect this tests goal. |
|
154 iCalTestLib->ConnectAgendaServerL(); |
|
155 |
|
156 HBufC8* guid = NULL; |
|
157 CCalEntry* entry = iCalTestLib->CreateCalEntryL(aEntryType, guid); |
|
158 CleanupStack::PushL(entry); |
|
159 FillEntryL(*entry); |
|
160 |
|
161 iCalTestLib->FileSession().SetErrorCondition(KMyError, ++failAt); |
|
162 TRAPD(error, StoreEntryL(entry)); |
|
163 iCalTestLib->FileSession().SetErrorCondition(KErrNone); |
|
164 |
|
165 if (error == KErrNone) |
|
166 { |
|
167 // the store was successful |
|
168 CleanupStack::PopAndDestroy(entry); |
|
169 break; |
|
170 } |
|
171 else |
|
172 { |
|
173 // if the store failed it should fail with our error code |
|
174 test(error == KMyError); |
|
175 } |
|
176 CleanupStack::PopAndDestroy(entry); |
|
177 } |
|
178 } |
|
179 |
|
180 |
|
181 |
|
182 static void doMainL() |
|
183 { |
|
184 #ifndef _DEBUG |
|
185 |
|
186 test.Next(_L("TFAILADD does not run on UREL builds. Test not run.")); |
|
187 |
|
188 #else |
|
189 CTestApp* testApp = CTestApp::NewL(); |
|
190 CleanupStack::PushL(testApp); |
|
191 |
|
192 test.Next(_L("Test1 - Add Appointment")); |
|
193 |
|
194 testApp->TestFailL(CCalEntry::EAppt); |
|
195 |
|
196 test.Next(_L("Test2 - Add Event")); |
|
197 |
|
198 testApp->TestFailL(CCalEntry::EEvent); |
|
199 |
|
200 test.Next(_L("Test3 - Add Anniversary")); |
|
201 |
|
202 testApp->TestFailL(CCalEntry::EAnniv); |
|
203 |
|
204 test.Next(_L("Test4 - Add Todo")); |
|
205 |
|
206 testApp->TestFailL(CCalEntry::ETodo); |
|
207 |
|
208 CleanupStack::PopAndDestroy(testApp); |
|
209 #endif |
|
210 } |
|
211 |
|
212 /** |
|
213 |
|
214 @SYMTestCaseID PIM-TFAILADD-0001 |
|
215 |
|
216 */ |
|
217 |
|
218 TInt E32Main() |
|
219 { |
|
220 __UHEAP_MARK; |
|
221 test.Start(_L("@SYMTESTCaseID:PIM-TFAILADD-0001 TFAILADD.CPP")); |
|
222 |
|
223 test.Title(); |
|
224 CTrapCleanup* theCleanup = CTrapCleanup::New(); |
|
225 CActiveScheduler* scheduler = new CActiveScheduler; |
|
226 CActiveScheduler::Install(scheduler); |
|
227 TRAPD(ret,doMainL()); |
|
228 delete scheduler; |
|
229 test(ret==KErrNone); |
|
230 delete theCleanup; |
|
231 test.End(); |
|
232 test.Close(); |
|
233 __UHEAP_MARKEND; |
|
234 return(KErrNone); |
|
235 } |
|
236 |