|
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 #include "t_schsend1.h" |
|
17 #include <msvstd.h> |
|
18 #include <msvids.h> |
|
19 #include <msvuids.h> |
|
20 #include "pigeonservermtm.h" |
|
21 |
|
22 CTrapCleanup* theCleanup; |
|
23 |
|
24 void doMainL(RTest& aTest) |
|
25 { |
|
26 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
27 CleanupStack::PushL(scheduler); |
|
28 CActiveScheduler::Install( scheduler ); |
|
29 |
|
30 CSchSendTest* schSendTest = CSchSendTest::NewL(aTest); |
|
31 CleanupStack::PushL(schSendTest); |
|
32 |
|
33 schSendTest->StartL(); |
|
34 |
|
35 CleanupStack::PopAndDestroy(2); //schSendTest, scheduler |
|
36 |
|
37 aTest.Printf(_L("\nWaiting 5 seconds before closing...\n")); |
|
38 User::After(5000000); |
|
39 } |
|
40 |
|
41 GLDEF_C TInt E32Main() |
|
42 { |
|
43 RTest test(_L("Scheduled Sending Test Harness")); |
|
44 __UHEAP_MARK; |
|
45 test.Title(); |
|
46 test.Start(_L("Scheduled Sending Test Harness")); |
|
47 theCleanup = CTrapCleanup::New(); |
|
48 test(theCleanup !=NULL); |
|
49 TRAPD(error,doMainL(test)); |
|
50 test(error==KErrNone); |
|
51 delete theCleanup; |
|
52 test.Printf(_L("Completed with return code %d"),error); |
|
53 test.End(); |
|
54 test.Close(); |
|
55 __UHEAP_MARKEND; |
|
56 return KErrNone; |
|
57 } |
|
58 |
|
59 CSchSendTest* CSchSendTest::NewL(RTest& aTest) |
|
60 { |
|
61 CSchSendTest* self = new (ELeave) CSchSendTest(aTest); |
|
62 CleanupStack::PushL(self); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop(); //self |
|
65 return self; |
|
66 } |
|
67 |
|
68 CSchSendTest::CSchSendTest(RTest& aTest) |
|
69 : CMsvTestUtils(aTest) |
|
70 { |
|
71 } |
|
72 |
|
73 void CSchSendTest::InstallMtmGroupsL() |
|
74 { |
|
75 } |
|
76 |
|
77 void CSchSendTest::CreateServerMtmRegsL() |
|
78 { |
|
79 //CreateServerMtmRegL(KPigeonMtmUid, _L("Pig"), KUidMsvMtmServerDLL, KUidMsvMtmClientDLL, TMsvTestDllInfo(KUidMsvMtmUiDLL,2), TMsvTestDllInfo(KUidMsvMtmUiDLL,1), KPigeonMtmUid, KDataComponentFileName); |
|
80 } |
|
81 |
|
82 void CSchSendTest::ConstructL() |
|
83 { |
|
84 CTestUtils::ConstructL(); |
|
85 CreateAllTestDirectories(); |
|
86 GoClientSideL(); |
|
87 |
|
88 InstallMtmGroupL(_L("c:\\system\\mtm\\pigmtmu.dat")); |
|
89 |
|
90 iSelection = new(ELeave) CMsvEntrySelection; |
|
91 iSchTestActive = CScheduleTestActive::NewL(*this); |
|
92 } |
|
93 |
|
94 void CSchSendTest::ShowMenuL() |
|
95 { |
|
96 RunAutoL(); |
|
97 } |
|
98 |
|
99 CSchSendTest::~CSchSendTest() |
|
100 { |
|
101 delete iSchTestActive; |
|
102 delete iSelection; |
|
103 } |
|
104 |
|
105 void CSchSendTest::Panic(TInt aPanic) |
|
106 { |
|
107 User::Panic(_L("SchSend Test"), aPanic); |
|
108 } |
|
109 |
|
110 void CSchSendTest::StartL() |
|
111 { |
|
112 TRAPD(err, RunAutoL()); |
|
113 |
|
114 if (err) |
|
115 { |
|
116 if (iCurrentTest) |
|
117 { |
|
118 TestFinish(iCurrentTest, err); |
|
119 } |
|
120 |
|
121 TestHarnessFailed(err); |
|
122 } |
|
123 else |
|
124 { |
|
125 TestHarnessCompleted(); |
|
126 } |
|
127 } |
|
128 |
|
129 void CSchSendTest::RunAutoL() |
|
130 { |
|
131 TestSchedulingMessageL(); |
|
132 } |
|
133 |
|
134 TMsvEntry CSchSendTest::CreateMessageLC(TMsvId aDestFolder, TTime aSendTime, TBool aOffPeak) |
|
135 { |
|
136 SetEntryL(aDestFolder); |
|
137 TMsvEntry entry; |
|
138 entry.iType = KUidMsvMessageEntry; |
|
139 entry.iMtm = KPigeonMtmUid; |
|
140 entry.iServiceId = KMsvLocalServiceIndexEntryId; |
|
141 entry.iDate = aSendTime; |
|
142 entry.SetOffPeak(aOffPeak); |
|
143 CreateEntryL(entry); |
|
144 iMsvSession->CleanupEntryPushL(entry.Id()); |
|
145 SetEntryL(entry.Id()); |
|
146 return entry; |
|
147 } |
|
148 |
|
149 void CSchSendTest::TestSchedulingMessageL() |
|
150 { |
|
151 TTime now; |
|
152 now.HomeTime(); |
|
153 TMsvEntry entry = CreateMessageLC(KMsvGlobalOutBoxIndexEntryId, now); |
|
154 |
|
155 iSelection->Reset(); |
|
156 iSelection->AppendL(entry.Id()); |
|
157 |
|
158 iSchTestActive->TransferCommandSyncL(CPigeonServerMtm::EScheduleAllL, *iSelection); |
|
159 |
|
160 CleanupStack::PopAndDestroy(); //entry |
|
161 } |
|
162 |
|
163 CScheduleTestActive::CScheduleTestActive(CMsvTestUtils& aTest) |
|
164 : CActive(EPriorityStandard), iTest(aTest) |
|
165 { |
|
166 CActiveScheduler::Add(this); |
|
167 } |
|
168 |
|
169 CScheduleTestActive* CScheduleTestActive::NewL(CMsvTestUtils& aTest) |
|
170 { |
|
171 CScheduleTestActive* self = new (ELeave) CScheduleTestActive(aTest); |
|
172 CleanupStack::PushL(self); |
|
173 self->iSession = CMsvSession::OpenSyncL(*self); |
|
174 CleanupStack::Pop(); //self |
|
175 return self; |
|
176 } |
|
177 |
|
178 CScheduleTestActive::~CScheduleTestActive() |
|
179 { |
|
180 Cancel(); |
|
181 delete iSelection; |
|
182 delete iSession; |
|
183 } |
|
184 |
|
185 //Set aStopAtRunL to true to stop the active scheduler. |
|
186 //False will make us wait for someone else to stop it |
|
187 void CScheduleTestActive::TransferCommandSyncL(CPigeonServerMtm::TPigOperation aCommand, const CMsvEntrySelection& aSelection, TBool aStopAtRunL) |
|
188 { |
|
189 iTest.Printf(_L("TransferCommandSyncL Command %d Count %d StopAtRunL %d\n"), aCommand, aSelection.Count(), aStopAtRunL); |
|
190 |
|
191 if (IsActive()) |
|
192 User::Leave(KErrInUse); |
|
193 |
|
194 delete iSelection; |
|
195 iSelection = NULL; |
|
196 iSelection = aSelection.CopyL(); |
|
197 iCommand = aCommand; |
|
198 iStopAtRunL = aStopAtRunL; |
|
199 iStatus = KRequestPending; |
|
200 SetActive(); |
|
201 |
|
202 CMsvOperation* opert = iSession->TransferCommandL (*iSelection, |
|
203 aCommand, |
|
204 _L8("aaaa"), |
|
205 iStatus); |
|
206 |
|
207 CleanupStack::PushL(opert); |
|
208 CActiveScheduler::Start(); // will not return from this until the command is transferred |
|
209 |
|
210 if(iStatus.Int()!=KErrNone) |
|
211 User::Leave(iStatus.Int()); |
|
212 |
|
213 CleanupStack::PopAndDestroy(); //opert |
|
214 } |
|
215 |
|
216 void CScheduleTestActive::RunL() |
|
217 { |
|
218 iTest.Printf(_L("CScheduleTestActive::RunL() iStatus %d\n"), iStatus.Int()); |
|
219 |
|
220 if(iStopAtRunL) |
|
221 { |
|
222 CActiveScheduler::Stop(); |
|
223 return; |
|
224 } |
|
225 |
|
226 switch (iCommand) |
|
227 { |
|
228 case CPigeonServerMtm::EScheduleAllL: |
|
229 case CPigeonServerMtm::EReScheduleAllL: |
|
230 { |
|
231 for(int i = 0; i < iSelection->Count(); i++) |
|
232 { |
|
233 CMsvEntry* entry = iSession->GetEntryL(iSelection->At(i)); |
|
234 CleanupStack::PushL(entry); |
|
235 TInt state = entry->Entry().SendingState(); |
|
236 switch(state) |
|
237 { |
|
238 case KMsvSendStateScheduled: |
|
239 case KMsvSendStateResend: |
|
240 break; |
|
241 default: // The message failed |
|
242 CActiveScheduler::Stop(); |
|
243 break; |
|
244 } |
|
245 CleanupStack::PopAndDestroy(); //entry |
|
246 } |
|
247 |
|
248 break; |
|
249 } |
|
250 default: |
|
251 CActiveScheduler::Stop(); //Added by AA 9/6/2000. Is this correct? |
|
252 break; |
|
253 } |
|
254 } |
|
255 |
|
256 void CScheduleTestActive::HandleSessionEventL(TMsvSessionEvent eventType, TAny* p1, TAny*, TAny*) |
|
257 { |
|
258 if (iStopAtRunL) return; |
|
259 if (eventType != EMsvEntriesCreated) return; |
|
260 |
|
261 CMsvEntrySelection* entries = STATIC_CAST(CMsvEntrySelection*, p1); |
|
262 if(entries->Count() == 0) |
|
263 User::Panic(_L("sch send test"), 23); |
|
264 CMsvEntry* cEntry = iSession->GetEntryL((*entries)[0]); |
|
265 CleanupStack::PushL(cEntry); |
|
266 |
|
267 TMsvEntry entry = cEntry->Entry(); |
|
268 |
|
269 if(entry.iDetails == _L("sch send test")) |
|
270 { |
|
271 iTest.Printf(_L("Scheduled message has been sent\n")); |
|
272 |
|
273 //We found the right message! |
|
274 CActiveScheduler::Stop(); |
|
275 |
|
276 //Delete the new message |
|
277 CMsvOperationWait* wait = CMsvOperationWait::NewLC(); |
|
278 wait->Start(); |
|
279 cEntry->SetEntryL(entry.Parent()); |
|
280 CMsvOperation* op = cEntry->DeleteL(entry.Id(), wait->iStatus); |
|
281 CActiveScheduler::Start(); |
|
282 delete op; |
|
283 CleanupStack::PopAndDestroy(); //wait |
|
284 } |
|
285 |
|
286 CleanupStack::PopAndDestroy(); //cEntry |
|
287 } |