|
1 // Copyright (c) 2007-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 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include <sysmonclisess.h> |
|
23 #include <startupproperties.h> |
|
24 #include "testapps.h" |
|
25 #include "tsysmon_stepprocmoninit.h" |
|
26 |
|
27 |
|
28 CStepProcMonInit::CStepProcMonInit() |
|
29 { |
|
30 SetTestStepName(KCTestCaseProcMonInit); |
|
31 } |
|
32 |
|
33 TVerdict CStepProcMonInit::doTestStepL() |
|
34 { |
|
35 DoTestProcL(); |
|
36 DoTestAppL(); |
|
37 DoTestErrArgumentL(); |
|
38 return TestStepResult(); |
|
39 } |
|
40 |
|
41 /** |
|
42 Old Test CaseID APPFWK-SYSMON-0001 |
|
43 New Test CaseID DEVSRVS-SYSSTART-SYSMON-0001 |
|
44 */ |
|
45 |
|
46 |
|
47 void CStepProcMonInit::DoTestProcL() |
|
48 { |
|
49 INFO_PRINTF1(_L("TEST APPFWK-SYSMON-0001A")); |
|
50 INFO_PRINTF1(_L("Going to set a process running")); |
|
51 |
|
52 RProcess process; |
|
53 CleanupClosePushL(process); |
|
54 User::LeaveIfError(process.Create(KTestProcGood, KNullDesC)); |
|
55 ResumeL(process); |
|
56 |
|
57 DoTestMonitorL(process, KTestProcGood); // The test |
|
58 |
|
59 process.Kill(KErrNone); |
|
60 CleanupStack::PopAndDestroy(&process); |
|
61 } |
|
62 |
|
63 /** |
|
64 Bonus-test APPFWK-SYSMON-0001b using an application instead of a process |
|
65 */ |
|
66 void CStepProcMonInit::DoTestAppL() |
|
67 { |
|
68 INFO_PRINTF1(_L("TEST APPFWK-SYSMON-0001B")); |
|
69 |
|
70 // Launch native application using an unconnected RApaLsSession |
|
71 INFO_PRINTF1(_L("Going to set a native application running")); |
|
72 TThreadId threadId; |
|
73 TRequestStatus requestStatus; |
|
74 StartViewlessBgApplicationL(KTestAppGood, threadId, requestStatus); |
|
75 |
|
76 // Test that the application was created, then wait for it to resume |
|
77 RThread thread; |
|
78 RProcess process; |
|
79 CleanupClosePushL(thread); |
|
80 CleanupClosePushL(process); |
|
81 TEST(KErrNone == thread.Open(threadId)); |
|
82 TEST(KErrNone == thread.Process(process)); |
|
83 User::WaitForRequest(requestStatus); |
|
84 |
|
85 // Do the actual testing |
|
86 DoTestMonitorL(process, KTestAppGood); |
|
87 |
|
88 // Cleanup |
|
89 process.Kill(KErrNone); |
|
90 CleanupStack::PopAndDestroy(&process); |
|
91 CleanupStack::PopAndDestroy(&thread); |
|
92 } |
|
93 |
|
94 /** |
|
95 * Calls RSysMonSession::MonitorL twice. the first call is expected to succeed and the second |
|
96 * to fail with KErrAlreadyExists. |
|
97 */ |
|
98 void CStepProcMonInit::DoTestMonitorL(const RProcess& aProcess, const TDesC& aFilename) |
|
99 { |
|
100 RSysMonSession sess; |
|
101 sess.OpenL(); |
|
102 CleanupClosePushL(sess); |
|
103 CStartupProperties* prop = CStartupProperties::NewLC(aFilename, KNullDesC); |
|
104 |
|
105 // Testing consistency assertion of aStartupProperties in RSysMonSession::MonitorL |
|
106 TRAPD(err, sess.MonitorL(*prop, aProcess)); |
|
107 TESTE(err == KErrArgument, err); |
|
108 if(err == KErrArgument) |
|
109 { |
|
110 INFO_PRINTF1(_L("Monitor request with invalid args was refused properly by RSysMonSession::MonitorL")); |
|
111 } |
|
112 |
|
113 prop->SetMonitored(ETrue); |
|
114 prop->SetNoOfRetries(0); // SysMon will not do any restart attempts |
|
115 |
|
116 INFO_PRINTF1(_L("Going to start monitoring")); |
|
117 |
|
118 // monitoring first time should succeed |
|
119 TRAP(err, sess.MonitorL(*prop, aProcess)); |
|
120 TESTEL(err == KErrNone, err); |
|
121 INFO_PRINTF1(_L("First monitor request succeeded")); |
|
122 |
|
123 // a second request should fail |
|
124 TRAP(err, sess.MonitorL(*prop, aProcess)); |
|
125 TESTE(err == KErrAlreadyExists, err); |
|
126 if(err == KErrAlreadyExists) |
|
127 { |
|
128 INFO_PRINTF1(_L("Second monitor request returned KErrAlreadyExists as expected")); |
|
129 } |
|
130 |
|
131 CleanupStack::PopAndDestroy(prop); |
|
132 CleanupStack::PopAndDestroy(&sess); |
|
133 } |
|
134 |
|
135 |
|
136 /* |
|
137 Bonus-test APPFWK-SYSMON-0001C |
|
138 Testing consistency of assertions in RSysMonSession::MonitorL |
|
139 */ |
|
140 void CStepProcMonInit::DoTestErrArgumentL() |
|
141 { |
|
142 INFO_PRINTF1(_L("TEST APPFWK-SYSMON-0001C - validade that sysmon refuse invalid requests")); |
|
143 |
|
144 RProcess process; |
|
145 CleanupClosePushL(process); |
|
146 User::LeaveIfError(process.Create(KTestProcGood, KNullDesC)); |
|
147 ResumeL(process); |
|
148 |
|
149 RSysMonSession sess; |
|
150 sess.OpenL(); |
|
151 CleanupClosePushL(sess); |
|
152 CStartupProperties* prop = CStartupProperties::NewLC(KTestProcGood, KNullDesC); |
|
153 |
|
154 INFO_PRINTF1(_L("Going to check if RSysMonSession::MonitorL correctly refuse monitor with CStartupProperties::Monitor()==EFalse")); |
|
155 TRAPD(err, sess.MonitorL(*prop, process)); |
|
156 TESTE(err == KErrArgument, err); |
|
157 |
|
158 INFO_PRINTF1(_L("Going to check if RSysMonSession::MonitorL correctly refuse monitor with CStartupProperties::Monitor()==True, StartMethod==EFireAndForget and NoOfRetries>0")); |
|
159 prop->SetStartMethod(EFireAndForget); |
|
160 prop->SetMonitored(ETrue); |
|
161 prop->SetNoOfRetries(1); |
|
162 TRAP(err, sess.MonitorL(*prop, process)); |
|
163 TESTE(err == KErrArgument, err); |
|
164 |
|
165 INFO_PRINTF1(_L("Going to check if RSysMonSession::MonitorL correctly refuse monitor with CStartupProperties::StartMethod==EDeferredWaitForStart")); |
|
166 prop->SetStartMethod(EDeferredWaitForStart); |
|
167 prop->SetNoOfRetries(0); |
|
168 TRAP(err, sess.MonitorL(*prop, process)); |
|
169 TESTE(err == KErrArgument, err); |
|
170 |
|
171 INFO_PRINTF1(_L("Going to check if RSysMonSession::MonitorL correctly refuse to restart another exe image than the one it monitors.")); |
|
172 prop->SetStartMethod(EWaitForStart); |
|
173 prop->SetNoOfRetries(1); |
|
174 prop->SetFileParamsL(_L("sdkjfhsdk"), KNullDesC); |
|
175 TRAP(err, sess.MonitorL(*prop, process)); |
|
176 TESTE(err == KErrArgument, err); |
|
177 |
|
178 INFO_PRINTF1(_L("Going to check if RSysMonSession::MonitorL correctly refuse to monitor a dead process.")); |
|
179 prop->SetFileParamsL(KTestProcGood, KNullDesC); |
|
180 process.Kill(KErrNone); |
|
181 TRAP(err, sess.MonitorL(*prop, process)); |
|
182 TESTE(err == KErrDied, err); |
|
183 |
|
184 CleanupStack::PopAndDestroy(prop); |
|
185 CleanupStack::PopAndDestroy(&sess); |
|
186 CleanupStack::PopAndDestroy(&process); |
|
187 } |