|
1 // Copyright (c) 2004-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 "CMtfTestActionSendEMsvGetChildIds.h" |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32base.h> |
|
20 |
|
21 #include <msvstd.h> |
|
22 #include "MCLIENT.H" |
|
23 #include "MSERVER.H" |
|
24 #include "MSVPANIC.H" |
|
25 |
|
26 #include "CMtfTestCase.h" |
|
27 #include "CMtfTestActionParameters.h" |
|
28 |
|
29 #include "IPCCommandForCapsPermissions.h" |
|
30 #include "SendProxyClient.h" |
|
31 #include "SendProxyserver.h" |
|
32 |
|
33 |
|
34 /** |
|
35 Function : NewL |
|
36 Description : |
|
37 @internalTechnology |
|
38 @param : aTestCase - CMtfTestCase for the CMtfTestAction base class |
|
39 @param : aActionParams - CMtfTestActionParameters |
|
40 @return : CMtfTestAction* - a base class pointer to the newly created CMtfTestActionSendEMsvGetChildIds object |
|
41 @pre none |
|
42 @post none |
|
43 */ |
|
44 CMtfTestAction* CMtfTestActionSendEMsvGetChildIds::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
45 { |
|
46 CMtfTestActionSendEMsvGetChildIds* self = new (ELeave) CMtfTestActionSendEMsvGetChildIds(aTestCase); |
|
47 CleanupStack::PushL(self); |
|
48 self->ConstructL(aActionParameters); |
|
49 CleanupStack::Pop(self); |
|
50 return self; |
|
51 } |
|
52 |
|
53 /** |
|
54 Function : CMtfTestActionSendEMsvGetChildIds |
|
55 Description : Constructor |
|
56 @internalTechnology |
|
57 @param : aTestCase - CMtfTestCase for the CMtfTestAction base class |
|
58 @return : N/A |
|
59 @pre none |
|
60 @post none |
|
61 */ |
|
62 CMtfTestActionSendEMsvGetChildIds::CMtfTestActionSendEMsvGetChildIds(CMtfTestCase& aTestCase) : CMtfSynchronousTestAction(aTestCase) |
|
63 { |
|
64 } |
|
65 |
|
66 /** |
|
67 Function : ~CMtfTestActionSendEMsvGetChildIds |
|
68 Description : Destructor |
|
69 @internalTechnology |
|
70 @param : |
|
71 @return : |
|
72 @pre |
|
73 @post |
|
74 */ |
|
75 CMtfTestActionSendEMsvGetChildIds::~CMtfTestActionSendEMsvGetChildIds() |
|
76 { |
|
77 } |
|
78 |
|
79 /** |
|
80 Function : ExecuteActionL |
|
81 Description : Entry point for the this test action in the test framework |
|
82 @internalTechnology |
|
83 @param : none |
|
84 @return : void |
|
85 @pre none |
|
86 @post none |
|
87 */ |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 void CMtfTestActionSendEMsvGetChildIds::ExecuteActionL() |
|
93 { |
|
94 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSendEMsvGetChildIds); |
|
95 // input params |
|
96 TInt numberOfEntries = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(0) ); |
|
97 TMsvId entryId = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1) ); |
|
98 TInt pass = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(2) ); |
|
99 |
|
100 |
|
101 RProxyServerSession RPSS; |
|
102 |
|
103 // Will auto start the server if not started. |
|
104 TInt error = RPSS.Connect(); |
|
105 CleanupClosePushL(RPSS); |
|
106 |
|
107 if (error!=KErrNone) |
|
108 { |
|
109 TestCase().ERR_PRINTF1(_L("CMtfTestActionSendEMsvGetChildIds :: Unable to start proxy server. !")); |
|
110 TestCase().SetTestStepResult(EFail); |
|
111 } |
|
112 else |
|
113 { |
|
114 TInt32 serverCaps; |
|
115 RPSS.GetServerCapabilities(serverCaps); |
|
116 TestCase().INFO_PRINTF2(_L("Proxy Server has capabilities: %x"), serverCaps); |
|
117 |
|
118 // Not sure if this will work. Can't use the same mechanism as RMsvServerSession::GetChildIdsL |
|
119 // since it uses an internal class to package the filter. |
|
120 HBufC8* buffer = HBufC8::NewLC(KMsvSessionBufferLength); |
|
121 if (buffer==NULL) |
|
122 { |
|
123 TestCase().ERR_PRINTF1(_L("CMtfTestActionSendEMsvGetChildIds :: Unable to allocate mem. !")); |
|
124 TestCase().SetTestStepResult(EFail); |
|
125 } |
|
126 |
|
127 error = 0; |
|
128 |
|
129 CMsvEntryFilter* filter = CMsvEntryFilter::NewLC(); |
|
130 TMsvPackedEntryFilterTest package(buffer); |
|
131 error = package.PackFilter(*filter); |
|
132 |
|
133 TPtr8 ptr = buffer->Des(); |
|
134 |
|
135 error=RPSS.SendReceive(EMsvGetChildIds , TIpcArgs(&ptr, entryId)); |
|
136 if (error == KErrNone) |
|
137 { |
|
138 // need to unpack the returned data so we can check the number of returned entries |
|
139 TInt temp1, temp2; |
|
140 TMsvPackedOperation op(buffer); |
|
141 CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection; |
|
142 CleanupStack::PushL(selection); |
|
143 |
|
144 op.UnpackL(*selection, temp1, temp2); |
|
145 TInt temp3 = selection->Count(); |
|
146 if (temp3 != numberOfEntries) |
|
147 { |
|
148 TestCase().ERR_PRINTF3(_L("CMtfTestActionSendEMsvGetChildIds :: Number of entries do not match! Entries found: [%d], Entries expected: [%d]"), temp3, numberOfEntries); |
|
149 error = KErrGeneral; |
|
150 } |
|
151 else |
|
152 { |
|
153 TestCase().INFO_PRINTF1(_L("CMtfTestActionSendEMsvGetChildIds :: Number of entries match !")); |
|
154 } |
|
155 CleanupStack::PopAndDestroy(selection); |
|
156 } |
|
157 IPCCommandReportPassOrFailForCapsPermissions( TestCase(), KMsvServerName, error , pass ); |
|
158 |
|
159 CleanupStack::PopAndDestroy(filter); |
|
160 CleanupStack::PopAndDestroy(buffer); |
|
161 } |
|
162 |
|
163 CleanupStack::Check(&RPSS); |
|
164 CleanupStack::PopAndDestroy(); // RPSS |
|
165 |
|
166 TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSendEMsvGetChildIds); |
|
167 TestCase().ActionCompletedL(*this); |
|
168 } |
|
169 |
|
170 // ******************************************************************************** |
|
171 // *** FUNCTIONALITY DUPLICATED FROM MSGS.DLL *** |
|
172 // ******************************************************************************** |
|
173 // Need to steal this functionality from MSGS.DLL (defined in MSVIPC.CPP/MSVIPC.H |
|
174 // since it's not exported from there, and we need to be able to pack the filter |
|
175 // to call EMsvGetChildIds. |
|
176 |
|
177 GLDEF_C void DoUnpackFilter(TUint8*& aPtr, CMsvEntryFilter& aFilter) |
|
178 // |
|
179 // |
|
180 // |
|
181 { |
|
182 // get the entry from the start of the buffer |
|
183 const CMsvEntryFilter* pFilter = (CMsvEntryFilter*) aPtr; |
|
184 Mem::Copy(&aFilter, pFilter, sizeof(CMsvEntryFilter)); |
|
185 aPtr = Align4(aPtr + sizeof(CMsvEntryFilter)); |
|
186 } |
|
187 |
|
188 |
|
189 GLDEF_C TInt DoPackFilter(const TUint8*& aPtrStart, const TUint8* aPtrEnd, const CMsvEntryFilter& aFilter) |
|
190 // |
|
191 // |
|
192 // |
|
193 { |
|
194 // make sure the entry can fit into the memory area defined by the two pointers |
|
195 TInt size = Align4(sizeof(CMsvEntryFilter)); |
|
196 if ((aPtrStart + size)>aPtrEnd) |
|
197 { |
|
198 aPtrStart += size; |
|
199 return KErrOverflow; |
|
200 } |
|
201 |
|
202 // copy the filter into the memory area |
|
203 Mem::Copy((void*)aPtrStart, &aFilter, size); |
|
204 aPtrStart += size; |
|
205 |
|
206 return KErrNone; |
|
207 } |
|
208 |
|
209 TMsvPackedEntryFilterTest::TMsvPackedEntryFilterTest(HBufC8*& aBuffer): iBuffer(aBuffer) |
|
210 {} |
|
211 |
|
212 TInt TMsvPackedEntryFilterTest::PackFilter(const CMsvEntryFilter& aFilter) |
|
213 { |
|
214 // find the start and end of the buffer |
|
215 const TUint8* pS = iBuffer->Ptr(); |
|
216 const TUint8* pE = PtrAdd(pS, iBuffer->Des().MaxSize()); |
|
217 |
|
218 TInt error = DoPackFilter(pS, pE, aFilter); |
|
219 if (error==KErrNone) |
|
220 { |
|
221 // update the length of the buffer |
|
222 iBuffer->Des().SetLength(pS-iBuffer->Ptr()); |
|
223 } |
|
224 |
|
225 return error; |
|
226 } |
|
227 |
|
228 void TMsvPackedEntryFilterTest::UnpackFilter(CMsvEntryFilter& aFilter) |
|
229 { |
|
230 #if defined(_DEBUG) |
|
231 // check that the buffer contain a valid package |
|
232 const TUint8* dPos = PtrAdd(iBuffer->Ptr(), Align4(sizeof(CMsvEntryFilter))); |
|
233 __ASSERT_DEBUG(dPos <= PtrAdd(iBuffer->Ptr(), iBuffer->Des().MaxLength()), User::Panic(_L("MSGS"), EMsvEntryOverrunBuffer)); |
|
234 #endif |
|
235 TUint8* pS = CONST_CAST(TUint8*, iBuffer->Ptr()); |
|
236 DoUnpackFilter(pS, aFilter); |
|
237 } |
|
238 |