|
1 // Copyright (c) 2000-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 // common code shared between the test classes: |
|
15 // CWapPushSIMessageTest |
|
16 // CWapPushSLMessageTest |
|
17 // CWapPushMMMessageTest |
|
18 // |
|
19 // |
|
20 |
|
21 #include "pushtests.h" |
|
22 #include "dummywapstack.h" |
|
23 #include <push/cwappushmsgutils.h> |
|
24 |
|
25 |
|
26 _LIT(KTextFinished,"All finished"); |
|
27 |
|
28 |
|
29 /** all derived classes use this RunL to move between the states listed. |
|
30 starts up setting up required test enbvironment, then creates a test |
|
31 message which is simualted as a push. This 'push' stage can be repeated |
|
32 for multiple messages and once all messages passed finishes up. */ |
|
33 void CWapPushBaseMessageTest::RunL() |
|
34 { |
|
35 switch (iState) |
|
36 { |
|
37 case EInitialisation: |
|
38 { |
|
39 // Create WAP Stack passing MDummyWapStackObserver derived instance |
|
40 // Create Connection Manager, once WAP stack setup |
|
41 iWapStack = CDummyWapStack::NewL(*this); |
|
42 iConnMan = CConnectionManager::NewL(*this); |
|
43 NumberTestCasesToRun(); |
|
44 iHasMsgBeenCompleted=EFalse; |
|
45 iHasTestBeenCompleted=EFalse; |
|
46 MoveToNextState(); |
|
47 return; |
|
48 } |
|
49 case EWaitForPush: |
|
50 { |
|
51 // wait for callback to move to the next state |
|
52 if (iHasTestBeenCompleted) |
|
53 MoveToNextState(); |
|
54 return; |
|
55 } |
|
56 case EFinished: |
|
57 { |
|
58 Printf(KTextFinished); |
|
59 SetPriority(EPriorityIdle); |
|
60 MoveToNextState(); |
|
61 return; |
|
62 } |
|
63 default: |
|
64 // Finished |
|
65 ConfirmMessagesSavedL(); |
|
66 iEngine->TestCompleted(iStatus.Int()); |
|
67 return; |
|
68 } |
|
69 }; |
|
70 |
|
71 TInt CWapPushBaseMessageTest::RunError(TInt aError) |
|
72 { |
|
73 TBuf<80> buf; |
|
74 _LIT(KComment, "!! Error - %d in RunError()"); |
|
75 buf.Format(KComment, aError); |
|
76 |
|
77 iEngine->Printf(buf, TestName()); |
|
78 iState = EFinished; |
|
79 iEngine->TestCompleted(aError); |
|
80 return KErrNone; |
|
81 } |
|
82 |
|
83 /** destructor */ |
|
84 CWapPushBaseMessageTest::~CWapPushBaseMessageTest() |
|
85 { |
|
86 delete iConnMan; |
|
87 delete iWapStack; |
|
88 } |
|
89 |
|
90 /** cancel any active request and clean up before returning to main test |
|
91 harness |
|
92 */ |
|
93 void CWapPushBaseMessageTest::DoCancel() |
|
94 { |
|
95 delete iConnMan; |
|
96 delete iWapStack; |
|
97 iEngine->TestCompleted(KErrCancel); |
|
98 } |
|
99 |
|
100 /** increment the value of iState and set active to create call to RunL |
|
101 with new state value |
|
102 */ |
|
103 void CWapPushBaseMessageTest::MoveToNextState() |
|
104 { |
|
105 iState = (TState)(iState+1); |
|
106 CompleteOwnRequest(); |
|
107 } |
|
108 |
|
109 /** set this object active */ |
|
110 void CWapPushBaseMessageTest::CompleteOwnRequest() |
|
111 { |
|
112 TRequestStatus* stat = &iStatus; |
|
113 User::RequestComplete(stat,KErrNone); |
|
114 if (!IsActive()) |
|
115 SetActive(); |
|
116 } |
|
117 |
|
118 /** sets base test name. |
|
119 @param void |
|
120 @return string - the test name |
|
121 */ |
|
122 const TDesC& CWapPushBaseMessageTest::TestName() |
|
123 { |
|
124 _LIT(KTextBaseMessageTest,"Base Message Test"); |
|
125 return KTextBaseMessageTest; |
|
126 } |
|
127 |
|
128 |
|
129 /** |
|
130 called by DummyWapStack and returns the push message which is |
|
131 created by the call to PrepareTestMessageL. The message is |
|
132 then passed through to aDummyCLConn which accepts as much of |
|
133 the message as possible and if this is not equal to the whole |
|
134 message then issues a rerquest for the rest of the message which |
|
135 retruns here. |
|
136 @param CDummyWSPCLConn |
|
137 @return void |
|
138 |
|
139 if all tests have completed - move to the next test state and complete own req |
|
140 if all of msg received - move to next message |
|
141 |
|
142 Each derived class should have its own implementation of PrepareTestMessage |
|
143 which will be called from this method. This will allow a variable number of |
|
144 test cases to be used to test the push aspect of the dummy wap stack. |
|
145 */ |
|
146 void CWapPushBaseMessageTest::DWSOUnitWaitPushL(CDummyWSPCLConn& aDummyCLConn) |
|
147 { |
|
148 if (iHasTestBeenCompleted) |
|
149 { |
|
150 CompleteOwnRequest(); |
|
151 return; |
|
152 } |
|
153 |
|
154 PrepareTestMessageL(iCurrentTestCase); |
|
155 |
|
156 aDummyCLConn.CompleteUnitWaitPushL(iBodyBuf, iHeadersBuf); // asynch |
|
157 |
|
158 iHasMsgBeenCompleted=aDummyCLConn.HasMsgBeenCompleted(); |
|
159 |
|
160 if (iHasMsgBeenCompleted) |
|
161 { |
|
162 iHasMsgBeenCompleted=EFalse; |
|
163 iCurrentTestCase++; |
|
164 } |
|
165 |
|
166 iHasTestBeenCompleted = (iCurrentTestCase >= iNumberOfTestCases); |
|
167 } |
|
168 |
|
169 /** |
|
170 display error message |
|
171 @param string |
|
172 @param line number |
|
173 */ |
|
174 void CWapPushBaseMessageTest::DWSOError(const TDesC& aDes, TInt /*aLineNum*/) |
|
175 { |
|
176 // TO DO: format message + ? |
|
177 |
|
178 // simply display error message for now |
|
179 iEngine->Printf(TestName(),aDes); |
|
180 } |
|
181 |
|
182 /** |
|
183 Wap Stack Server closing... |
|
184 */ |
|
185 void CWapPushBaseMessageTest::DWSOServerShutDown() |
|
186 { |
|
187 _LIT(KWPSLServerShutdown,"Wap stack server closing down"); |
|
188 iEngine->Printf(TestName(), KWPSLServerShutdown); |
|
189 } |
|
190 |
|
191 /** |
|
192 * Cancel pushwait operation |
|
193 */ |
|
194 void CWapPushBaseMessageTest::DWSOCancelUnitWaitPush(CDummyWSPCLConn& /*aDummyCLConn*/) |
|
195 { |
|
196 Cancel(); // CActive closes open requests |
|
197 // ignore aDummyCLConn (not sure why being passed in) |
|
198 } |
|
199 |
|
200 /** placeholder method - does nothing */ |
|
201 void CWapPushBaseMessageTest::DWSOConnect(CDummyWSPCOConn&) |
|
202 { |
|
203 } |
|
204 |
|
205 /** placeholder method - does nothing */ |
|
206 void CWapPushBaseMessageTest::DWSOGetEventL(CDummyWSPCOConn&) |
|
207 { |
|
208 } |
|
209 |
|
210 /** placeholder method - does nothing */ |
|
211 void CWapPushBaseMessageTest::DWSOCancelGetEvent(CDummyWSPCOConn&) |
|
212 { |
|
213 } |
|
214 |
|
215 /** placeholder method - does nothing */ |
|
216 void CWapPushBaseMessageTest::DWSOAckTransaction(CDummyWSPCOTrans&) |
|
217 { |
|
218 } |
|
219 |
|
220 /** indicates number of test cases to run which should be implimented |
|
221 in a suitable switch statement in derieved class method: |
|
222 PrepareTestMessages() |
|
223 */ |
|
224 void CWapPushBaseMessageTest::NumberTestCasesToRun() |
|
225 { |
|
226 // default - override for derived classes |
|
227 iNumberOfTestCases = 1; |
|
228 } |
|
229 |
|
230 |
|
231 |
|
232 |