|
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 // __ACTION_INFO_BEGIN__ |
|
15 // [Action Name] |
|
16 // LaunchAutoSend |
|
17 // [Action Parameters] |
|
18 // TMsvId smtpServiceId <input>: Value of the Smtp Service Id. |
|
19 // [Action Description] |
|
20 // Launches LaunchAutoSend.exe passing SMTP Service Id as parameter. |
|
21 // The LaunchAutoSend.exe is developed for performing the Capability checking implemented |
|
22 // in the AutoSend.exe. LaunchAutoSend.exe in turn launches the AutoSend.exe and |
|
23 // returns the result of the AutoSend.exe execution to this Test Action. |
|
24 // The LaunchAutoSend.exe is expected to be present under C:\System\Programs\ directory |
|
25 // The Test Action checks the AutoSend exe's completion result and verifies it with |
|
26 // the expected value that is provided as an input to the Test Action |
|
27 // [APIs Used] |
|
28 // RProcess::Create |
|
29 // RProcess::Resume |
|
30 // RProcess::Close |
|
31 // __ACTION_INFO_END__ |
|
32 // |
|
33 // |
|
34 |
|
35 // System includes |
|
36 #include <msvstd.h> |
|
37 #include <e32std.h> |
|
38 #include <imcmutil.h> |
|
39 #include <e32cmn.h> |
|
40 |
|
41 // User includes |
|
42 #include "CMtfTestActionLaunchAutoSend.h" |
|
43 #include "CMtfTestCase.h" |
|
44 #include "CMtfTestActionParameters.h" |
|
45 |
|
46 class TDummyMsvSessionObserver: public MMsvSessionObserver |
|
47 { |
|
48 public: |
|
49 void HandleSessionEventL(TMsvSessionEvent,TAny*,TAny*,TAny*) {}; |
|
50 }; |
|
51 |
|
52 // Path of the LaunchAutoSend.exe |
|
53 _LIT(KMsvLaunchAutoSend, "LaunchAutoSend.exe"); |
|
54 |
|
55 // UID of LaunchAutoSend.exe |
|
56 const TUid KMsvLaunchAutoSendExeUid = {0x10204283}; |
|
57 |
|
58 /** |
|
59 Function : NewL |
|
60 Description : |
|
61 @internalTechnology |
|
62 @param : aTestCase :Reference to the Test case |
|
63 @param : aActionParams :Test Action parameters |
|
64 @return : CMtfTestAction* :a base class pointer to the newly created object |
|
65 @pre none |
|
66 @post none |
|
67 */ |
|
68 CMtfTestAction* CMtfTestActionLaunchAutoSend::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
69 { |
|
70 CMtfTestActionLaunchAutoSend* self = new (ELeave) CMtfTestActionLaunchAutoSend(aTestCase); |
|
71 CleanupStack::PushL(self); |
|
72 self->ConstructL(aActionParameters); |
|
73 CleanupStack::Pop(self); |
|
74 return self; |
|
75 } |
|
76 |
|
77 |
|
78 /** |
|
79 Function : CMtfTestActionLaunchAutoSend |
|
80 Description : Constructor |
|
81 @internalTechnology |
|
82 @param : aTestCase - CMtfTestCase for the CMtfTestAction base class |
|
83 @pre none |
|
84 @post none |
|
85 */ |
|
86 CMtfTestActionLaunchAutoSend::CMtfTestActionLaunchAutoSend(CMtfTestCase& aTestCase) |
|
87 : CMtfSynchronousTestAction(aTestCase) |
|
88 { |
|
89 } |
|
90 |
|
91 |
|
92 /** |
|
93 Function : ~CMtfTestActionLaunchAutoSend |
|
94 Description : Destructor |
|
95 @internalTechnology |
|
96 */ |
|
97 CMtfTestActionLaunchAutoSend::~CMtfTestActionLaunchAutoSend() |
|
98 { |
|
99 } |
|
100 |
|
101 |
|
102 /** |
|
103 Function : ExecuteActionL |
|
104 Description : Starts the LaunchAutoSend.exe, and waits for the completion of the |
|
105 process. The process's exit reason is then compared with the expected value, fails |
|
106 the test if the process's exit reason does not match with the expected value. |
|
107 @internalTechnology |
|
108 @param : none |
|
109 @return : void |
|
110 @pre : LauchAutoSend.exe is available in c:\system\programs\ directory |
|
111 @post none |
|
112 */ |
|
113 void CMtfTestActionLaunchAutoSend::ExecuteActionL() |
|
114 { |
|
115 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionLaunchAutoSend); |
|
116 // Get Test Action input parameters |
|
117 |
|
118 // SMTP Service Id |
|
119 TMsvId paramSmtpServiceId = ObtainValueParameterL<TMsvId>(TestCase(), ActionParameters().Parameter(0)); |
|
120 // Expected result |
|
121 TInt paramExpectedResult = ObtainValueParameterL<TInt>(TestCase(), ActionParameters().Parameter(1)); |
|
122 //LaunchAutoSend Exe name if new one is created with different capabilites |
|
123 HBufC* paramLaunchAutoSendExeName = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(2), NULL); |
|
124 |
|
125 // Check to see if enforcement is on - only if not expecting KErrNone... |
|
126 if( paramExpectedResult != KErrNone ) |
|
127 { |
|
128 if( PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) ) |
|
129 { |
|
130 // Enforment on - check that the SMTP required capabilities are actually |
|
131 // being enforced. |
|
132 TDummyMsvSessionObserver dummyObserver; |
|
133 |
|
134 CMsvSession* sess = CMsvSession::OpenSyncL(dummyObserver); |
|
135 CleanupStack::PushL(sess); |
|
136 |
|
137 // inf.iCaps should be the TCapabilitySet of the creator process. |
|
138 TCapabilitySet caps; |
|
139 sess->GetMtmRequiredCapabilitiesL(KUidMsgTypeSMTP, caps); |
|
140 CleanupStack::PopAndDestroy(sess); |
|
141 |
|
142 // Now this is a bit of a HACK, but can't think of a better way... |
|
143 // The current possibilities for SMPT capabilities are Network Services |
|
144 // and Local Services. Check each is in the SMTP capabilities and if so |
|
145 // see if it is enforced. |
|
146 if( caps.HasCapability(ECapabilityNetworkServices) && |
|
147 !PlatSec::IsCapabilityEnforced(ECapabilityNetworkServices) ) |
|
148 { |
|
149 // SMTP requires Network Services but this is not enforced - change |
|
150 // expected value to be KErrNone. |
|
151 TestCase().INFO_PRINTF4(_L("Test Action %S : Network Services not enforced - expected return value changed to %d from %d"), &KTestActionLaunchAutoSend, KErrNone, paramExpectedResult); |
|
152 paramExpectedResult = KErrNone; |
|
153 } |
|
154 else if( caps.HasCapability(ECapabilityLocalServices) && |
|
155 !PlatSec::IsCapabilityEnforced(ECapabilityLocalServices) ) |
|
156 { |
|
157 // SMTP requires Local Services but this is not enforced - change |
|
158 // expected value to be KErrNone. |
|
159 TestCase().INFO_PRINTF4(_L("Test Action %S : Local Services not enforced - expected return value changed to %d from %d"), &KTestActionLaunchAutoSend, KErrNone, paramExpectedResult); |
|
160 paramExpectedResult = KErrNone; |
|
161 } |
|
162 } |
|
163 else |
|
164 { |
|
165 // Enforcement off - change expected value to be KErrNone. |
|
166 TestCase().INFO_PRINTF4(_L("Test Action %S : PlatSec Enforcement OFF - expected return value changed to %d from %d"), &KTestActionLaunchAutoSend, KErrNone, paramExpectedResult); |
|
167 paramExpectedResult = KErrNone; |
|
168 } |
|
169 } |
|
170 |
|
171 TBuf<20> cmdString; |
|
172 cmdString.Num(paramSmtpServiceId, EDecimal); |
|
173 |
|
174 // Return KErrNotSupported in case of Wins |
|
175 TInt returnValue = KErrNotSupported; |
|
176 |
|
177 TRequestStatus status = KRequestPending; |
|
178 |
|
179 RProcess process; |
|
180 if (paramLaunchAutoSendExeName) |
|
181 { |
|
182 User::LeaveIfError(process.Create(*paramLaunchAutoSendExeName, cmdString, TUidType(KNullUid, KNullUid, KMsvLaunchAutoSendExeUid))); |
|
183 } |
|
184 else |
|
185 { |
|
186 User::LeaveIfError(process.Create(KMsvLaunchAutoSend, cmdString, TUidType(KNullUid, KNullUid, KMsvLaunchAutoSendExeUid))); |
|
187 } |
|
188 TestCase().INFO_PRINTF2(_L("RProcess::Create() is successful %S "), &KTestActionLaunchAutoSend); |
|
189 |
|
190 // Make the process eligible for execution |
|
191 process.Logon(status); |
|
192 process.Resume(); |
|
193 |
|
194 // Wait for the process completion |
|
195 User::WaitForRequest(status); |
|
196 |
|
197 // Check the exit reason of the process |
|
198 returnValue = (process.ExitType() == EExitPanic)? KErrGeneral: status.Int(); |
|
199 |
|
200 process.Close(); |
|
201 |
|
202 TestCase().INFO_PRINTF4(_L("Test Action %S completed with %d, while expected %d "), &KTestActionLaunchAutoSend,returnValue, paramExpectedResult); |
|
203 if(returnValue != paramExpectedResult) |
|
204 { |
|
205 TestCase().SetTestStepResult(EFail); |
|
206 } |
|
207 |
|
208 TestCase().ActionCompletedL(*this); |
|
209 } |