|
1 // Copyright (c) 2003-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 // StartWatchers |
|
17 // [Action Parameters] |
|
18 // RProcess watcher <output-completion>:In case of EKA2 and EKA1 on hardware, output the process that started the watchers. |
|
19 // If watchers are already running, this output parameter will not be returned |
|
20 // or |
|
21 // RThread watcher <output-completion>:In case of EKA1 on emulator, output the thread that started the watchers. |
|
22 // If watchers are already running, this output parameter will not be returned |
|
23 // TBool Started <output-completion> : For all the cases, output ETrue if the watchers were created |
|
24 // by the process or thread in this action, otherwise output EFalse |
|
25 // [Action Description] |
|
26 // If the watchers are not running, starts the watchers. Watchers are started |
|
27 // in their own process for EKA2 and EKA1 on the hardware and in their own thread |
|
28 // for EKA1 on emulator. The action waits for the watchers to start before completing. |
|
29 // At the end of the test case, the watchers are stopped if they were created |
|
30 // by the action. If they were not created by the action, then the watchers |
|
31 // are not stopped. |
|
32 // [APIs Used] |
|
33 // None |
|
34 // __ACTION_INFO_END__ |
|
35 // |
|
36 // |
|
37 |
|
38 /** |
|
39 @file |
|
40 */ |
|
41 |
|
42 #include "CMtfTestActionStartWatchers.h" |
|
43 #include "CMtfTestCase.h" |
|
44 #include "CMtfTestActionParameters.h" |
|
45 #include "TestFrameworkActionsUtils.h" |
|
46 #include "CMtfTestActionUtilsTimer.h" |
|
47 |
|
48 const TInt KWaitForWatchersToStart = 2; |
|
49 const TInt KWaitForWatchersToStartCounter = 5; |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 _LIT(KWatcherExe, "z:\\system\\libs\\watcher.exe"); |
|
55 |
|
56 |
|
57 CMtfTestAction* CMtfTestActionStartWatchers::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
58 { |
|
59 CMtfTestActionStartWatchers* self = new (ELeave) CMtfTestActionStartWatchers(aTestCase); |
|
60 CleanupStack::PushL(self); |
|
61 self->ConstructL(aActionParameters); |
|
62 CleanupStack::Pop(); |
|
63 return self; |
|
64 } |
|
65 |
|
66 |
|
67 CMtfTestActionStartWatchers::CMtfTestActionStartWatchers(CMtfTestCase& aTestCase) |
|
68 : CMtfTestAction(aTestCase) |
|
69 { |
|
70 iCounter = KWaitForWatchersToStartCounter; |
|
71 } |
|
72 |
|
73 |
|
74 CMtfTestActionStartWatchers::~CMtfTestActionStartWatchers() |
|
75 { |
|
76 if(iWatcherStarted) |
|
77 { |
|
78 TestCase().Logger().Write(_L("Kill watchers")); |
|
79 iWatcherProcess.Terminate(0); |
|
80 iWatcherProcess.Close(); |
|
81 } |
|
82 |
|
83 Cancel(); |
|
84 delete iTimer; |
|
85 } |
|
86 |
|
87 void CMtfTestActionStartWatchers::ExecuteActionL() |
|
88 { |
|
89 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionStartWatchers); |
|
90 CActiveScheduler::Add(this); |
|
91 |
|
92 if(TestFrameworkActionsUtils::CheckIfWatchersAlreadyRunningL()) |
|
93 { |
|
94 //Watchers already running, output EFalse to indicate that watchers are not created |
|
95 StoreParameterL<TInt>(TestCase(),iWatcherStarted,ActionParameters().Parameter(1)); |
|
96 TestCase().ActionCompletedL(*this); |
|
97 } |
|
98 else |
|
99 { |
|
100 //Watchers not running, need to be started. |
|
101 //Watchers started in their own process |
|
102 User::LeaveIfError(iWatcherProcess.Create(KWatcherExe, KNullDesC)); |
|
103 iWatcherProcess.Resume(); |
|
104 //iWatcherProcess.Close(); |
|
105 //Wait for the watchers to start |
|
106 iTimer = CMtfTestActionUtilsTimer::NewL(); |
|
107 iTimer->After(KWaitForWatchersToStart,iStatus); |
|
108 SetActive(); |
|
109 } |
|
110 TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionStartWatchers); |
|
111 } |
|
112 |
|
113 |
|
114 void CMtfTestActionStartWatchers::DoCancel() |
|
115 { |
|
116 iTimer->Cancel(); |
|
117 } |
|
118 |
|
119 |
|
120 void CMtfTestActionStartWatchers::RunL() |
|
121 { |
|
122 User::LeaveIfError(iStatus.Int()); |
|
123 |
|
124 if(TestFrameworkActionsUtils::CheckIfWatchersAlreadyRunningL()) |
|
125 { |
|
126 iWatcherStarted = ETrue; |
|
127 |
|
128 StoreParameterL<RProcess>(TestCase(),iWatcherProcess,ActionParameters().Parameter(0)); |
|
129 StoreParameterL<TInt>(TestCase(),iWatcherStarted,ActionParameters().Parameter(1)); |
|
130 TestCase().ActionCompletedL(*this); |
|
131 } |
|
132 else |
|
133 { |
|
134 // Watcheres are not running, restart the timer or decide to leave |
|
135 if(iCounter--) |
|
136 { |
|
137 iTimer->After(KWaitForWatchersToStart,iStatus); |
|
138 SetActive(); |
|
139 } |
|
140 else{ |
|
141 User::Leave(KErrGeneral); |
|
142 } |
|
143 } |
|
144 } |
|
145 |