|
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 // TE_WatcherUnitBase.cpp |
|
15 // Telephony Watchers Unit Test base test code. |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 */ |
|
22 |
|
23 #include "TE_TelWatchersUnitBase.h" |
|
24 #include "TE_TelWatchersUnitWatcherLog.h" |
|
25 #include "simtsy.h" |
|
26 |
|
27 CTelWatchersUnitTestStep::CTelWatchersUnitTestStep() |
|
28 { |
|
29 // NOP |
|
30 } // CTelWatchersUnitTestStep::CTelWatchersUnitTestStep |
|
31 |
|
32 |
|
33 CTelWatchersUnitTestStep::~CTelWatchersUnitTestStep() |
|
34 { |
|
35 // NOP |
|
36 } // CTelWatchersUnitTestStep::~CTelWatchersUnitTestStep |
|
37 |
|
38 |
|
39 TVerdict CTelWatchersUnitTestStep::doTestStepPreambleL() |
|
40 { |
|
41 // |
|
42 // Mark for memory leaks!!! |
|
43 // |
|
44 __UHEAP_MARK; |
|
45 |
|
46 // |
|
47 // Create an Active Scheduler... |
|
48 // |
|
49 iScheduler = new(ELeave) CActiveScheduler(); |
|
50 CActiveScheduler::Install(iScheduler); |
|
51 |
|
52 TInt err; |
|
53 |
|
54 // |
|
55 // Create the File Server and CWatcherLog objects used by some tests... |
|
56 // |
|
57 err = iFs.Connect(); |
|
58 TESTCHECKL(err, KErrNone); |
|
59 |
|
60 // Use the telephony watcher implementation of watcher logger (from UnitTestWatcherLog.cpp) |
|
61 // even though the implementation from watcher.lib is expected |
|
62 iWatcherLog = new (ELeave) CWatcherLog(Logger()); |
|
63 |
|
64 return TestStepResult(); |
|
65 } // CTelWatchersUnitTestStep::doTestStepPreambleL |
|
66 |
|
67 |
|
68 TVerdict CTelWatchersUnitTestStep::doTestStepPostambleL() |
|
69 { |
|
70 delete iWatcherLog; |
|
71 iWatcherLog = NULL; |
|
72 |
|
73 iFs.Close(); |
|
74 |
|
75 delete iScheduler; |
|
76 iScheduler = NULL; |
|
77 |
|
78 // |
|
79 // Check the heap for memory leaks... |
|
80 // |
|
81 __UHEAP_MARKEND; |
|
82 |
|
83 return TestStepResult(); |
|
84 } // CTelWatchersUnitTestStep::doTestStepPostambleL |
|
85 |
|
86 |
|
87 void CTelWatchersUnitTestStep::PauseToRunActiveSchedulerL(TInt aSeconds) |
|
88 { |
|
89 INFO_PRINTF2(_L(" Pausing %d seconds to run Active Scheduler."), aSeconds); |
|
90 |
|
91 CTimedStopScheduler* pauser = new(ELeave) CTimedStopScheduler(); |
|
92 CleanupStack::PushL(pauser); |
|
93 pauser->ConstructL(); |
|
94 pauser->AfterSeconds(aSeconds); |
|
95 CleanupStack::PopAndDestroy(pauser); |
|
96 |
|
97 INFO_PRINTF1(_L(" Pause completed.")); |
|
98 } // CTelWatchersUnitTestStep::PauseToRunActiveSchedulerL |
|
99 |
|
100 CWatcherObserverPS::CWatcherObserverPS() |
|
101 :CActive(CActive::EPriorityHigh) |
|
102 { |
|
103 iProperty = 0; |
|
104 CActiveScheduler::Add(this); |
|
105 } |
|
106 |
|
107 CWatcherObserverPS::~CWatcherObserverPS() |
|
108 { |
|
109 Cancel(); |
|
110 } |
|
111 |
|
112 void CWatcherObserverPS::DoCancel() |
|
113 { //-- cancel subscription to the property |
|
114 if(iProperty) |
|
115 { |
|
116 iProperty->Cancel(); |
|
117 } |
|
118 } |
|
119 |
|
120 /** |
|
121 * Bind an integer property to this observer. Then we can get property value and wait for its change |
|
122 * |
|
123 * @param aProp - pointer to the property. The property object must be definer and attached to. |
|
124 * |
|
125 * @see WaitForPropertyChangeL |
|
126 * @see GetPropertyValue |
|
127 * |
|
128 */ |
|
129 void CWatcherObserverPS::BindProperty(RProperty *aProp) |
|
130 { |
|
131 iProperty = aProp; |
|
132 } |
|
133 |
|
134 |
|
135 /** |
|
136 * Issue request for waiting for a property change. The property must be set by BindProperty method |
|
137 * |
|
138 * @see BindProperty |
|
139 * @note This function can leave if the property is not set before. |
|
140 */ |
|
141 void CWatcherObserverPS::WaitForPropertyChangeL() |
|
142 { |
|
143 _LIT(KPropObserverPanic, "CWatcherObserver::IssueRequest()"); |
|
144 __ASSERT_ALWAYS(iProperty , User::Panic(KPropObserverPanic, KErrGeneral)); |
|
145 __ASSERT_ALWAYS(!IsActive(), User::Panic(KPropObserverPanic, KErrGeneral)); |
|
146 |
|
147 iProperty->Cancel(); |
|
148 iProperty->Subscribe(iStatus); |
|
149 SetActive(); |
|
150 CActiveScheduler::Start(); |
|
151 } |
|
152 |
|
153 /** |
|
154 * Get integer property value |
|
155 * |
|
156 * @param aVal - reference to the variable |
|
157 * |
|
158 * @return standart error codes |
|
159 */ |
|
160 TInt CWatcherObserverPS::GetPropertyValue(TInt &aVal) |
|
161 { |
|
162 if(iProperty) |
|
163 { |
|
164 return iProperty->Get(aVal); |
|
165 } |
|
166 |
|
167 return KErrNotFound; |
|
168 } |
|
169 |
|
170 |
|
171 CTimedStopScheduler::CTimedStopScheduler() |
|
172 : CTimer(CActive::EPriorityStandard) |
|
173 { |
|
174 CActiveScheduler::Add(this); |
|
175 } // CTimedStopScheduler::CTimedStopScheduler |
|
176 |
|
177 |
|
178 CTimedStopScheduler::~CTimedStopScheduler() |
|
179 { |
|
180 Cancel(); |
|
181 } // CTimedStopScheduler::~CTimedStopScheduler |
|
182 |
|
183 |
|
184 void CTimedStopScheduler::ConstructL() |
|
185 { |
|
186 CTimer::ConstructL(); |
|
187 } // CTimedStopScheduler::ConstructL |
|
188 |
|
189 |
|
190 void CTimedStopScheduler::AfterSeconds(TInt aTime) |
|
191 { |
|
192 After(TTimeIntervalMicroSeconds32(aTime * 1000000)); |
|
193 CActiveScheduler::Start(); |
|
194 } // CTimedStopScheduler::AfterSeconds |
|
195 |
|
196 |
|
197 void CTimedStopScheduler::RunL() |
|
198 { |
|
199 CActiveScheduler::Stop(); |
|
200 } // CTimedStopScheduler::RunL |
|
201 |
|
202 void CTelWatchersUnitTestStep::SetSimTsyTestNumberL(TInt aTestNumber) |
|
203 { |
|
204 TInt res = RProperty::Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,aTestNumber); |
|
205 if (res==KErrNotFound) |
|
206 { |
|
207 User::LeaveIfError(RProperty::Define(KUidPSSimTsyCategory,KPSSimTsyTestNumber, RProperty::EInt, aTestNumber)); |
|
208 } |
|
209 else |
|
210 { |
|
211 User::LeaveIfError(res); |
|
212 } |
|
213 } // CTelWatchersIntTestStep::SetSimTsyTestNumberL |
|
214 |
|
215 void CTelWatchersUnitTestStep::CheckSimTsyTestNumberL(TInt aTestNumber) |
|
216 { |
|
217 INFO_PRINTF2(_L("Checking SIMTSY config number to be %d..."), aTestNumber); |
|
218 |
|
219 // Ensure that the test number has been set properly |
|
220 RProperty testNumberInUseProperty; |
|
221 User::LeaveIfError(testNumberInUseProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumberInUse)); |
|
222 CleanupClosePushL(testNumberInUseProperty); |
|
223 |
|
224 TInt testNumberInUseCheck; |
|
225 User::LeaveIfError(testNumberInUseProperty.Get(KUidPSSimTsyCategory, KPSSimTsyTestNumberInUse,testNumberInUseCheck)); |
|
226 if (aTestNumber != testNumberInUseCheck) |
|
227 { |
|
228 INFO_PRINTF2(_L("Incorrect SIMTSY config number (%d)..."), testNumberInUseCheck); |
|
229 User::Leave(KErrNotFound); |
|
230 } |
|
231 |
|
232 CleanupStack::PopAndDestroy(&testNumberInUseProperty); |
|
233 } // CTelWatchersIntTestStep::CheckSimTsyTestNumberL |