|
1 // Copyright (c) 2001-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 // System includes |
|
15 // |
|
16 // |
|
17 |
|
18 // Local includes |
|
19 // |
|
20 #include "cchatengine.h" |
|
21 #include "cchatmethodinvocation.h" |
|
22 #include "cchattdesc8validator.h" |
|
23 #include "cchattboolvalidator.h" |
|
24 #include "cchattintvalidator.h" |
|
25 #include "t_wspeventdriver/tdriverpanic.h" |
|
26 |
|
27 // Class signatures |
|
28 // |
|
29 #include "cdriverdatasupplier.h" |
|
30 |
|
31 |
|
32 // Constants used in this file |
|
33 // |
|
34 |
|
35 |
|
36 /** Implementation of class 'CDriverDataSupplier'. This class validates TWspReason parameter values, |
|
37 in method invocations from the unit under test. |
|
38 */ |
|
39 |
|
40 |
|
41 EXPORT_C |
|
42 CDriverDataSupplier* CDriverDataSupplier::NewL(CChatEngine& aChatEngine) |
|
43 { |
|
44 CDriverDataSupplier* me = new(ELeave)CDriverDataSupplier(aChatEngine); |
|
45 CleanupStack::PushL(me); |
|
46 me->ConstructL(); |
|
47 CleanupStack::Pop(me); |
|
48 return me; |
|
49 } |
|
50 |
|
51 CDriverDataSupplier::~CDriverDataSupplier() |
|
52 { |
|
53 delete iBuffer; |
|
54 } |
|
55 |
|
56 EXPORT_C |
|
57 void CDriverDataSupplier::CleanUp(TAny* aDataSupplierItem) |
|
58 { |
|
59 delete STATIC_CAST(CDriverDataSupplier*, aDataSupplierItem); |
|
60 } |
|
61 |
|
62 TBool CDriverDataSupplier::GetNextDataPart(TPtrC8& aDataPart) |
|
63 { |
|
64 TBool retVal = EFalse; |
|
65 TRAPD(err, retVal = GetNextDataPartL(aDataPart)) |
|
66 if(err!=KErrNone) |
|
67 TDriverPanic::Panic(TDriverPanic::EMemoryAllocError); |
|
68 |
|
69 return retVal; |
|
70 } |
|
71 |
|
72 void CDriverDataSupplier::ReleaseData() |
|
73 { |
|
74 TRAPD(err, ReleaseDataL()) |
|
75 if(err!=KErrNone) |
|
76 TDriverPanic::Panic(TDriverPanic::EMemoryAllocError); |
|
77 } |
|
78 |
|
79 TInt CDriverDataSupplier::OverallDataSize() |
|
80 { |
|
81 TInt retVal = KErrNone; |
|
82 TRAPD(err, retVal = OverallDataSizeL()) |
|
83 if(err!=KErrNone) |
|
84 TDriverPanic::Panic(TDriverPanic::EMemoryAllocError); |
|
85 |
|
86 return retVal; |
|
87 } |
|
88 |
|
89 TInt CDriverDataSupplier::Reset() |
|
90 { |
|
91 TInt retVal = KErrNone; |
|
92 TRAPD(err, retVal = ResetL()) |
|
93 if(err!=KErrNone) |
|
94 TDriverPanic::Panic(TDriverPanic::EMemoryAllocError); |
|
95 |
|
96 return retVal; |
|
97 } |
|
98 |
|
99 TBool CDriverDataSupplier::GetNextDataPartL(TPtrC8& aDataPart) |
|
100 { |
|
101 // represent this method invocation |
|
102 _LIT(KThisMethod, "MHTTPDataSupplier::GetNextDataPart"); |
|
103 CChatMethodInvocation* methodCalled = CChatMethodInvocation::NewL(iChatEngine, KThisMethod()); |
|
104 CleanupStack::PushL(methodCalled); |
|
105 |
|
106 // test the invocation against what's expected by the chat script |
|
107 iChatEngine.TestExpectation(*methodCalled); |
|
108 |
|
109 // get parameters for the 'out' parameter and the return code |
|
110 _LIT(KParamADataPart, "aDataPart"); |
|
111 const CChatParameter* param_aDataPart = methodCalled->GetParameter(KParamADataPart()); |
|
112 if (!param_aDataPart) |
|
113 { |
|
114 iChatEngine.WriteComment(CChatEngine::ELogTerse, _L("PANIC: Invocation on MHTTPDataSupplier::GetNextDataPart() failed because required parameter 'aDataPart' was not provided in the script.")); |
|
115 TDriverPanic::Panic(TDriverPanic::EParameterMissingInScript); |
|
116 } |
|
117 |
|
118 _LIT(KReturnCode, ":RETURN:"); |
|
119 const CChatParameter* param_retCode = methodCalled->GetParameter(KReturnCode()); |
|
120 if (!param_retCode) |
|
121 { |
|
122 iChatEngine.WriteComment(CChatEngine::ELogTerse, _L("PANIC: Invocation on MHTTPDataSupplier::GetNextDataPart() failed because required parameter ':RETURN:' was not provided in the script.")); |
|
123 TDriverPanic::Panic(TDriverPanic::EParameterMissingInScript); |
|
124 } |
|
125 |
|
126 // create validators for these parameters in order to convert them |
|
127 CChatTDesC8Validator* vtor_aDataPart = CChatTDesC8Validator::NewL(*param_aDataPart); |
|
128 CleanupStack::PushL(vtor_aDataPart); |
|
129 CChatTBoolValidator* vtor_retCode = CChatTBoolValidator::NewL(*param_retCode); |
|
130 CleanupStack::PushL(vtor_retCode); |
|
131 |
|
132 // Keep a copy of the out parameter and keep the return code |
|
133 iBuffer = vtor_aDataPart->DesC8Value().AllocL(); |
|
134 aDataPart.Set(*iBuffer); |
|
135 TBool retVal = vtor_retCode->BooleanValue(); |
|
136 |
|
137 // clean up unwanted validators |
|
138 CleanupStack::PopAndDestroy(3, methodCalled); |
|
139 |
|
140 return retVal; |
|
141 } |
|
142 |
|
143 void CDriverDataSupplier::ReleaseDataL() |
|
144 { |
|
145 // represent this method invocation |
|
146 _LIT(KThisMethod, "MHTTPDataSupplier::ReleaseData"); |
|
147 CChatMethodInvocation* methodCalled = CChatMethodInvocation::NewL(iChatEngine, KThisMethod()); |
|
148 |
|
149 // test the invocation against what's expected by the chat script |
|
150 iChatEngine.TestExpectation(*methodCalled); |
|
151 |
|
152 // release the buffer we held in GetNextDataPart, and clean up |
|
153 delete iBuffer; |
|
154 iBuffer = NULL; |
|
155 delete methodCalled; |
|
156 } |
|
157 |
|
158 TInt CDriverDataSupplier::OverallDataSizeL() |
|
159 { |
|
160 // represent this method invocation |
|
161 _LIT(KThisMethod, "MHTTPDataSupplier::OverallDataSize"); |
|
162 CChatMethodInvocation* methodCalled = CChatMethodInvocation::NewL(iChatEngine, KThisMethod()); |
|
163 CleanupStack::PushL(methodCalled); |
|
164 // test the invocation against what's expected by the chat script |
|
165 iChatEngine.TestExpectation(*methodCalled); |
|
166 |
|
167 // get parameters for the 'out' parameter and the return code |
|
168 _LIT(KReturnCode, ":RETURN:"); |
|
169 const CChatParameter* param_retCode = methodCalled->GetParameter(KReturnCode()); |
|
170 if (!param_retCode) |
|
171 { |
|
172 iChatEngine.WriteComment(CChatEngine::ELogTerse, _L("PANIC: Invocation on MHTTPDataSupplier::OverallDataSize() failed because required parameter ':RETURN:' was not provided in the script.")); |
|
173 TDriverPanic::Panic(TDriverPanic::EParameterMissingInScript); |
|
174 } |
|
175 |
|
176 // create validators for these parameters in order to convert them |
|
177 CChatTIntValidator* vtor_retCode = CChatTIntValidator::NewL(*param_retCode); |
|
178 CleanupStack::PushL(vtor_retCode); |
|
179 |
|
180 // Keep the return code |
|
181 TInt retVal = vtor_retCode->IntValue(); |
|
182 |
|
183 // clean up unwanted validators |
|
184 CleanupStack::PopAndDestroy(vtor_retCode); |
|
185 CleanupStack::PopAndDestroy(methodCalled); |
|
186 return retVal; |
|
187 } |
|
188 |
|
189 TInt CDriverDataSupplier::ResetL() |
|
190 { |
|
191 // represent this method invocation |
|
192 _LIT(KThisMethod, "MHTTPDataSupplier::Reset"); |
|
193 CChatMethodInvocation* methodCalled = CChatMethodInvocation::NewL(iChatEngine, KThisMethod()); |
|
194 CleanupStack::PushL(methodCalled); |
|
195 |
|
196 // test the invocation against what's expected by the chat script |
|
197 iChatEngine.TestExpectation(*methodCalled); |
|
198 |
|
199 // get parameters for the 'out' parameter and the return code |
|
200 _LIT(KReturnCode, ":RETURN:"); |
|
201 const CChatParameter* param_retCode = methodCalled->GetParameter(KReturnCode()); |
|
202 if (!param_retCode) |
|
203 { |
|
204 iChatEngine.WriteComment(CChatEngine::ELogTerse, _L("PANIC: Invocation on MHTTPDataSupplier::Reset() failed because required parameter ':RETURN:' was not provided in the script.")); |
|
205 TDriverPanic::Panic(TDriverPanic::EParameterMissingInScript); |
|
206 } |
|
207 |
|
208 // create validators for these parameters in order to convert them |
|
209 CChatTIntValidator* vtor_retCode = CChatTIntValidator::NewL(*param_retCode); |
|
210 CleanupStack::PushL(vtor_retCode); |
|
211 |
|
212 // Keep the return code |
|
213 TInt retVal = vtor_retCode->IntValue(); |
|
214 |
|
215 // clean up unwanted validators |
|
216 CleanupStack::PopAndDestroy(2, methodCalled); |
|
217 return retVal; |
|
218 } |
|
219 |
|
220 CDriverDataSupplier::CDriverDataSupplier(CChatEngine& aChatEngine) |
|
221 : iChatEngine(aChatEngine) |
|
222 { |
|
223 } |
|
224 |
|
225 void CDriverDataSupplier::ConstructL() |
|
226 { |
|
227 } |
|
228 |
|
229 |